Skip to content

Commit

Permalink
Merge pull request #44 from hachibeeDI/enhance/upgrade-packages
Browse files Browse the repository at this point in the history
Enhance/upgrade packages
  • Loading branch information
hachibeeDI authored Feb 20, 2024
2 parents 0c86061 + f24c16a commit bcd4501
Show file tree
Hide file tree
Showing 6 changed files with 1,334 additions and 889 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [18.x]

steps:
- uses: actions/checkout@v1
Expand Down
41 changes: 23 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mayoiga",
"version": "0.1.6",
"version": "0.1.7",
"description": "Type safe hook based form library for React",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -43,27 +43,32 @@
"zod": "^3.20.2"
},
"dependencies": {
"nozuchi": "^0.0.4"
"nozuchi": "^0.0.6"
},
"resolutions": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"@types/react": "^18.2.57"
},
"devDependencies": {
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/node": "^17.0.23",
"@types/react": "^18.2.7",
"@types/use-sync-external-store": "^0.0.3",
"@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.59.8",
"eslint": "^8.41.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-testing-library": "^5.11.0",
"jsdom": "^22.1.0",
"prettier": "^2.8.8",
"@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^14.5.2",
"@types/node": "^20.11.19",
"@types/react": "^18.2.57",
"@types/use-sync-external-store": "^0.0.6",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"eslint": "^8.56.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-testing-library": "^6.2.0",
"jsdom": "^24.0.0",
"prettier": "^3.2.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typedoc": "^0.24.7",
"typescript": "^5.0.4",
"typedoc": "^0.25.8",
"typescript": "^5.3.3",
"use-sync-external-store": "^1.2.0",
"vitest": "^0.31.1",
"zod": "^3.20.2"
"vitest": "^1.3.0",
"zod": "^3.22.4"
}
}
1 change: 1 addition & 0 deletions src/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {render, screen, waitFor} from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import React from 'react';

import {test, expect} from 'vitest';
Expand Down
47 changes: 28 additions & 19 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,13 @@ function createFormStore<StateBeforeValidation extends StateRestriction, Schema
type StateKeys = keyof StateBeforeValidation;

const initialErrors = Object.freeze(
Object.keys(initialState).reduce((buf, k) => {
buf[k as StateKeys] = null;
return buf;
}, {} as any as Err),
Object.keys(initialState).reduce(
(buf, k) => {
buf[k as StateKeys] = null;
return buf;
},
{} as any as Err,
),
);

const fullInitialState: FullState = Object.freeze({
Expand All @@ -137,15 +140,18 @@ function createFormStore<StateBeforeValidation extends StateRestriction, Schema
if (result.success) {
return {...prev, isDirty: true, isValid: true, value: newValue, errors: initialErrors};
}
const newErrors = result.error.issues.reduce((buf, iss) => {
// TODO: should support nested value?
const shallowPath = iss.path[0];
if (shallowPath === undefined) {
const newErrors = result.error.issues.reduce(
(buf, iss) => {
// TODO: should support nested value?
const shallowPath = iss.path[0];
if (shallowPath === undefined) {
return buf;
}
buf[shallowPath as any as StateKeys] = iss.message;
return buf;
}
buf[shallowPath as any as StateKeys] = iss.message;
return buf;
}, {} as any as Err);
},
{} as any as Err,
);

return {...prev, isDirty: true, isValid: false, errors: newErrors, value: newValue};
};
Expand All @@ -165,14 +171,17 @@ function createFormStore<StateBeforeValidation extends StateRestriction, Schema
}),
handleIssues: (issues) => (prev) => {
// FIXME: handle duplication
const newErrors = issues.reduce((buf, iss) => {
const shallowPath = iss.path[0];
if (shallowPath === undefined) {
const newErrors = issues.reduce(
(buf, iss) => {
const shallowPath = iss.path[0];
if (shallowPath === undefined) {
return buf;
}
buf[shallowPath as any as StateKeys] = iss.message;
return buf;
}
buf[shallowPath as any as StateKeys] = iss.message;
return buf;
}, {} as any as Err);
},
{} as any as Err,
);

return {...prev, isDirty: true, isValid: false, errors: newErrors};
},
Expand Down
2 changes: 0 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
"noErrorTruncation": true,

"lib": ["dom", "esnext"],
// TODO: node is for vitest... I should isolate it probably?
"types": ["react/next"],

"rootDir": "./src",
"outDir": "./dist"
Expand Down
Loading

0 comments on commit bcd4501

Please sign in to comment.