@arkyn/server 3.0.1-beta.11 → 3.0.1-beta.13

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.
@@ -1,7 +1,7 @@
1
- import type { Schema } from "zod";
1
+ import type { ZodType } from "zod";
2
2
  type SuccessResponse<T extends FormParseProps> = {
3
3
  success: true;
4
- data: T[1] extends Schema<infer U> ? U : never;
4
+ data: T[1] extends ZodType<infer U> ? U : never;
5
5
  };
6
6
  type ErrorResponse = {
7
7
  success: false;
@@ -14,7 +14,7 @@ type ErrorResponse = {
14
14
  };
15
15
  type FormParseProps = [formData: {
16
16
  [k: string]: any;
17
- }, schema: Schema];
17
+ }, schema: ZodType];
18
18
  type FormParseReturnType<T extends FormParseProps> = SuccessResponse<T> | ErrorResponse;
19
19
  /**
20
20
  * Parses form data using a Zod schema and returns the result.
@@ -1 +1 @@
1
- {"version":3,"file":"formParse.d.ts","sourceRoot":"","sources":["../../src/services/formParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAElC,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,IAAI;IAC/C,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;CAChD,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAChC,WAAW,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACtC,CAAC;AAEF,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAAE,MAAM,EAAE,MAAM,CAAC,CAA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ACP,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAsB5B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -39,10 +39,10 @@
39
39
  function formParse([formData, schema,]) {
40
40
  const zodResponse = schema.safeParse(formData);
41
41
  if (zodResponse.success === false) {
42
- const errorsObject = Object.fromEntries(zodResponse.error.errors.map((item) => [
43
- item.path.join("."),
44
- item.message,
45
- ]));
42
+ const errorsObject = Object.fromEntries(zodResponse.error.issues.map((item) => {
43
+ console.log(item);
44
+ return [item.path.join("."), item.message];
45
+ }));
46
46
  return {
47
47
  success: zodResponse.success,
48
48
  fieldErrors: errorsObject,
@@ -50,7 +50,10 @@ function formParse([formData, schema,]) {
50
50
  };
51
51
  }
52
52
  else {
53
- return { success: zodResponse.success, data: zodResponse.data };
53
+ return {
54
+ success: zodResponse.success,
55
+ data: zodResponse.data,
56
+ };
54
57
  }
55
58
  }
56
59
  export { formParse };
@@ -1,11 +1,11 @@
1
- import { Schema, z } from "zod";
2
- declare class SchemaValidator<T extends Schema> {
1
+ import { ZodType, z } from "zod";
2
+ declare class SchemaValidator<T extends ZodType> {
3
3
  readonly schema: T;
4
4
  functionName: string;
5
5
  callerInfo: string;
6
6
  constructor(schema: T);
7
7
  isValid(data: any): boolean;
8
- safeValidate(data: any): z.SafeParseReturnType<z.infer<T>, z.infer<T>>;
8
+ safeValidate(data: any): z.ZodSafeParseResult<z.infer<T>>;
9
9
  validate(data: any): z.infer<T>;
10
10
  formValidate(data: any, message?: string): z.infer<T>;
11
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"schemaValidator.d.ts","sourceRoot":"","sources":["../../src/services/schemaValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAiBhC,cAAM,eAAe,CAAC,CAAC,SAAS,MAAM;IAIxB,QAAQ,CAAC,MAAM,EAAE,CAAC;IAH9B,YAAY,EAAE,MAAM,CAAC;IACrB,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zod";
1
+ import { ZodType, z } from "zod";
2
2
  import { ServerError } from "../http/badResponses/serverError";
3
3
  import { UnprocessableEntity } from "../http/badResponses/unprocessableEntity";
4
4
  import { formParse } from "./formParse";
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
1
  {
2
2
  "name": "@arkyn/server",
3
- "version": "3.0.1-beta.11",
3
+ "version": "3.0.1-beta.13",
4
4
  "author": "Arkyn | Lucas Gonçalves",
5
5
  "main": "./dist/bundle.js",
6
6
  "module": "./src/index.ts",
7
- "dependencies": {
8
- "@arkyn/shared": "*",
9
- "zod": ">=3.24.2"
10
- },
11
- "devDependencies": {
12
- "bun-types": "latest",
13
- "vitest": "^3.1.1",
14
- "typescript": "^5.8.3"
15
- },
16
- "peerDependencies": {
17
- "@react-router/node": ">=7.6.0"
18
- },
19
- "description": "Server-side utilities for projects.",
7
+ "type": "module",
8
+ "types": "./dist/index.d.ts",
20
9
  "license": "Apache-2.0",
10
+ "description": "Server-side utilities for projects.",
21
11
  "scripts": {
22
12
  "clean": "rm -rf dist",
23
13
  "build": "bun run clean && bunx tsc --project tsconfig.json",
24
14
  "test": "vitest --config vitest.config.ts",
25
15
  "typecheck": "bunx tsc --project tsconfig.json --noEmit"
26
16
  },
27
- "type": "module",
28
- "types": "./dist/index.d.ts"
17
+ "dependencies": {
18
+ "@arkyn/shared": "*",
19
+ "zod": "^4.0.17"
20
+ },
21
+ "devDependencies": {
22
+ "bun-types": "latest",
23
+ "vitest": "^3.2.4",
24
+ "typescript": "^5.9.2"
25
+ },
26
+ "peerDependencies": {
27
+ "@react-router/node": "^7.6.2"
28
+ }
29
29
  }
@@ -1,8 +1,8 @@
1
- import type { Schema } from "zod";
1
+ import type { ZodType } from "zod";
2
2
 
3
3
  type SuccessResponse<T extends FormParseProps> = {
4
4
  success: true;
5
- data: T[1] extends Schema<infer U> ? U : never;
5
+ data: T[1] extends ZodType<infer U> ? U : never;
6
6
  };
7
7
 
8
8
  type ErrorResponse = {
@@ -11,7 +11,7 @@ type ErrorResponse = {
11
11
  fieldErrors: { [x: string]: string };
12
12
  };
13
13
 
14
- type FormParseProps = [formData: { [k: string]: any }, schema: Schema];
14
+ type FormParseProps = [formData: { [k: string]: any }, schema: ZodType];
15
15
 
16
16
  type FormParseReturnType<T extends FormParseProps> =
17
17
  | SuccessResponse<T>
@@ -64,10 +64,10 @@ function formParse<T extends FormParseProps>([
64
64
 
65
65
  if (zodResponse.success === false) {
66
66
  const errorsObject = Object.fromEntries(
67
- zodResponse.error.errors.map((item) => [
68
- item.path.join("."),
69
- item.message,
70
- ])
67
+ zodResponse.error.issues.map((item) => {
68
+ console.log(item);
69
+ return [item.path.join("."), item.message];
70
+ })
71
71
  );
72
72
 
73
73
  return {
@@ -76,7 +76,10 @@ function formParse<T extends FormParseProps>([
76
76
  fields: formData,
77
77
  };
78
78
  } else {
79
- return { success: zodResponse.success, data: zodResponse.data };
79
+ return {
80
+ success: zodResponse.success,
81
+ data: zodResponse.data as T[1] extends ZodType<infer U> ? U : never,
82
+ };
80
83
  }
81
84
  }
82
85
 
@@ -1,4 +1,4 @@
1
- import { Schema, z } from "zod";
1
+ import { ZodType, z } from "zod";
2
2
 
3
3
  import { ServerError } from "../http/badResponses/serverError";
4
4
  import { UnprocessableEntity } from "../http/badResponses/unprocessableEntity";
@@ -15,7 +15,7 @@ function formatErrorMessage(error: z.ZodError) {
15
15
  return [title, ...lines].join("\n");
16
16
  }
17
17
 
18
- class SchemaValidator<T extends Schema> {
18
+ class SchemaValidator<T extends ZodType> {
19
19
  functionName: string;
20
20
  callerInfo: string;
21
21
 
@@ -29,7 +29,7 @@ class SchemaValidator<T extends Schema> {
29
29
  return this.schema.safeParse(data).success;
30
30
  }
31
31
 
32
- safeValidate(data: any): z.SafeParseReturnType<z.infer<T>, z.infer<T>> {
32
+ safeValidate(data: any): z.ZodSafeParseResult<z.infer<T>> {
33
33
  return this.schema.safeParse(data);
34
34
  }
35
35
 
@@ -59,7 +59,7 @@ class SchemaValidator<T extends Schema> {
59
59
  );
60
60
  }
61
61
 
62
- return formParsed.data;
62
+ return formParsed.data as z.infer<T>;
63
63
  }
64
64
  }
65
65
 
package/tsconfig.json CHANGED
@@ -16,6 +16,6 @@
16
16
  "types": ["bun-types"],
17
17
  "verbatimModuleSyntax": true
18
18
  },
19
- "exclude": ["node_modules", "dist"],
20
- "include": ["src/**/*.ts"]
19
+ "exclude": ["dist", "node_modules", "**/__test__"],
20
+ "include": ["src/**/*.ts", "src/**/*.ts"]
21
21
  }