@railway-ts/use-form 0.1.32 → 0.1.34

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/docs/API.md CHANGED
@@ -531,7 +531,7 @@ resetForm(): void
531
531
  Returns the error message for a field path, gated on user interaction.
532
532
 
533
533
  - **Leaf paths**: returns the error iff the field itself has been touched.
534
- - **Group / parent paths**: returns the error iff *any* descendant field has been
534
+ - **Group / parent paths**: returns the error iff _any_ descendant field has been
535
535
  touched. Cross-field validation errors that schemas attach to a non-leaf path
536
536
  (e.g. `S.refineAt("confirm", v => v.password === v.confirm, …)` or
537
537
  `S.refineAt("r2", …)` over a tuple) surface naturally on the group container,
@@ -579,7 +579,7 @@ const schema = S.chain(
579
579
 
580
580
  The descendant scan uses a path-prefix check that guards against sibling
581
581
  collisions — `r2` does not match a touch on `r20`. `getFieldError` never
582
- aggregates *across* paths: it only returns an error attached at the queried
582
+ aggregates _across_ paths: it only returns an error attached at the queried
583
583
  path, gated on touch of the path or any of its descendants.
584
584
 
585
585
  ### getFieldId
@@ -9,8 +9,8 @@ A guided walkthrough. Each step introduces one concept, building to a complete f
9
9
  Every `useForm` starts with a **schema** -- an object that describes what your form data looks like and how to validate it. The schema is the single source of truth: it defines both the validation rules and the TypeScript types at the same time.
10
10
 
11
11
  ```tsx
12
- import { useForm } from '@railway-ts/use-form';
13
12
  import { object, string, required, chain, nonEmpty, type InferSchemaType } from '@railway-ts/pipelines/schema';
13
+ import { useForm } from '@railway-ts/use-form';
14
14
 
15
15
  // 1. Define a schema
16
16
  const loginSchema = object({
@@ -56,7 +56,7 @@ function LoginForm() {
56
56
 
57
57
  The form validates and submits, but the inputs aren't wired up yet. That's the next step.
58
58
 
59
- > **Want the full theory on schemas, Result types, and pipelines?** See the [@railway-ts/pipelines Getting Started](https://github.com/sakobu/railway-ts-pipelines/blob/main/docs/GETTING_STARTED.md). You don't need to read it first -- we'll explain enough here to follow along.
59
+ > **Want the full theory on schemas, Result types, and pipelines?** See the [@railway-ts/pipelines Getting Started](https://github.com/sakobu/railway-ts/blob/main/packages/pipelines/docs/GETTING_STARTED.md). You don't need to read it first -- we'll explain enough here to follow along.
60
60
 
61
61
  ---
62
62
 
@@ -140,7 +140,7 @@ If a user submits with an empty email and a 3-character password, they see both
140
140
 
141
141
  Under the hood, validators return a `Result` -- either `Ok` with the validated value, or `Err` with an array of errors. You don't need to work with `Result` directly for basic forms (the hook handles it), but it's there when you want more control. See [Pattern-Matching Submit Results](./RECIPES.md#pattern-matching-submit-results) for an example.
142
142
 
143
- > **Deep dive:** The [@railway-ts/pipelines Getting Started](https://github.com/sakobu/railway-ts-pipelines/blob/main/docs/GETTING_STARTED.md) explains `Result`, `chain`, `pipe`, and the full validation model.
143
+ > **Deep dive:** The [@railway-ts/pipelines Getting Started](https://github.com/sakobu/railway-ts/blob/main/packages/pipelines/docs/GETTING_STARTED.md) explains `Result`, `chain`, `pipe`, and the full validation model.
144
144
 
145
145
  ---
146
146
 
@@ -158,9 +158,7 @@ By default, validation runs on every change. That's great for short forms, but i
158
158
  ```typescript
159
159
  // Validate only when a field loses focus
160
160
  const form = useForm(validator, {
161
- initialValues: {
162
- /* ... */
163
- },
161
+ initialValues: {/* ... */},
164
162
  validationMode: 'blur',
165
163
  });
166
164
  ```
@@ -176,9 +174,7 @@ const form = useForm(validator, {
176
174
  ```typescript
177
175
  // Don't bother the user until they submit
178
176
  const form = useForm(validator, {
179
- initialValues: {
180
- /* ... */
181
- },
177
+ initialValues: {/* ... */},
182
178
  validationMode: 'submit',
183
179
  });
184
180
  ```
package/docs/RECIPES.md CHANGED
@@ -44,7 +44,6 @@ Patterns and techniques. Each recipe is self-contained.
44
44
  **Solution:** Use `onSubmit` to call the API, and `setServerErrors` to display backend validation errors. Server errors auto-clear when the user edits the affected field.
45
45
 
46
46
  ```tsx
47
- import { useForm } from '@railway-ts/use-form';
48
47
  import {
49
48
  object,
50
49
  string,
@@ -57,6 +56,7 @@ import {
57
56
  ROOT_ERROR_KEY,
58
57
  type InferSchemaType,
59
58
  } from '@railway-ts/pipelines/schema';
59
+ import { useForm } from '@railway-ts/use-form';
60
60
 
61
61
  const userSchema = object({
62
62
  username: required(chain(string(), nonEmpty(), minLength(3))),
@@ -187,7 +187,7 @@ Errors also use dot notation: `form.getFieldError('address.city')`, `form.getFie
187
187
 
188
188
  **Problem:** A field is a fixed-length tuple — three numbers for a position
189
189
  vector, two for lat/long, four for a CMYK color — and each element needs its
190
- own input with its own error message. This is *not* the dynamic-array case
190
+ own input with its own error message. This is _not_ the dynamic-array case
191
191
  (no push/remove/reorder); the shape is part of the schema.
192
192
 
193
193
  **Solution:** Use `tupleOf(elementValidator, length)` from
@@ -196,7 +196,6 @@ emits per-index sub-paths in dot form (`r1.0`, `r1.1`, `r1.2`), which you
196
196
  bind directly with `getFieldProps`. No `arrayHelpers` involved.
197
197
 
198
198
  ```tsx
199
- import { useForm, type UseFormReturn, type ExtractFieldPaths } from '@railway-ts/use-form';
200
199
  import {
201
200
  object,
202
201
  required,
@@ -206,6 +205,7 @@ import {
206
205
  positive,
207
206
  type InferSchemaType,
208
207
  } from '@railway-ts/pipelines/schema';
208
+ import { useForm, type UseFormReturn, type ExtractFieldPaths } from '@railway-ts/use-form';
209
209
 
210
210
  const vec3 = tupleOf(chain(parseNumber(), positive('Must be positive')), 3);
211
211
 
@@ -227,18 +227,8 @@ function LambertForm() {
227
227
 
228
228
  return (
229
229
  <form onSubmit={(e) => void form.handleSubmit(e)} noValidate>
230
- <VecFieldset
231
- label="r₁"
232
- unit="km"
233
- form={form}
234
- names={['r1.0', 'r1.1', 'r1.2']}
235
- />
236
- <VecFieldset
237
- label="r₂"
238
- unit="km"
239
- form={form}
240
- names={['r2.0', 'r2.1', 'r2.2']}
241
- />
230
+ <VecFieldset label="r₁" unit="km" form={form} names={['r1.0', 'r1.1', 'r1.2']} />
231
+ <VecFieldset label="r₂" unit="km" form={form} names={['r2.0', 'r2.1', 'r2.2']} />
242
232
 
243
233
  <button type="submit">Solve</button>
244
234
  </form>
@@ -258,12 +248,7 @@ type VecFieldsetProps<TValues extends Record<string, unknown>> = {
258
248
  names: readonly ExtractFieldPaths<TValues>[];
259
249
  };
260
250
 
261
- function VecFieldset<TValues extends Record<string, unknown>>({
262
- label,
263
- unit,
264
- form,
265
- names,
266
- }: VecFieldsetProps<TValues>) {
251
+ function VecFieldset<TValues extends Record<string, unknown>>({ label, unit, form, names }: VecFieldsetProps<TValues>) {
267
252
  const errors = names.map((n) => (form.touched[n] ? form.errors[n] : undefined));
268
253
  const firstError = errors.find((e): e is string => Boolean(e));
269
254
 
@@ -275,13 +260,7 @@ function VecFieldset<TValues extends Record<string, unknown>>({
275
260
  </legend>
276
261
  <div style={{ display: 'flex', gap: '0.5rem' }}>
277
262
  {names.map((name, i) => (
278
- <input
279
- key={name}
280
- type="number"
281
- step="any"
282
- aria-invalid={Boolean(errors[i])}
283
- {...form.getFieldProps(name)}
284
- />
263
+ <input key={name} type="number" step="any" aria-invalid={Boolean(errors[i])} {...form.getFieldProps(name)} />
285
264
  ))}
286
265
  </div>
287
266
  {firstError && <span role="alert">{firstError}</span>}
@@ -570,8 +549,8 @@ function SearchBox() {
570
549
  **Solution:** Use a single `useForm` with all fields. Validate on each "Next" click with `validateForm`, advance only if valid.
571
550
 
572
551
  ```tsx
573
- import { useState } from 'react';
574
552
  import { isOk } from '@railway-ts/pipelines/result';
553
+ import { useState } from 'react';
575
554
 
576
555
  function MultiStepForm() {
577
556
  const [step, setStep] = useState(1);
@@ -1010,9 +989,7 @@ sliders, radios, file inputs) and array helper operations (`push`, `remove`,
1010
989
 
1011
990
  ```tsx
1012
991
  const form = useForm(schema, {
1013
- initialValues: {
1014
- /* ... */
1015
- },
992
+ initialValues: {/* ... */},
1016
993
  validationMode: 'submit',
1017
994
  });
1018
995
 
@@ -1058,8 +1035,8 @@ For the full technical details, see the [API Reference: Error Priority](./API.md
1058
1035
  ### Zod
1059
1036
 
1060
1037
  ```tsx
1061
- import { z } from 'zod';
1062
1038
  import { useForm } from '@railway-ts/use-form';
1039
+ import { z } from 'zod';
1063
1040
 
1064
1041
  const userSchema = z.object({
1065
1042
  username: z.string().min(3, 'Username must be at least 3 characters'),
@@ -1097,8 +1074,8 @@ function ZodForm() {
1097
1074
  ### Valibot
1098
1075
 
1099
1076
  ```tsx
1100
- import * as v from 'valibot';
1101
1077
  import { useForm } from '@railway-ts/use-form';
1078
+ import * as v from 'valibot';
1102
1079
 
1103
1080
  const userSchema = v.object({
1104
1081
  username: v.pipe(v.string(), v.minLength(3, 'Username must be at least 3 characters')),
@@ -1251,9 +1228,7 @@ You can also combine `onSubmit` (for the main action) with the returned `Result`
1251
1228
 
1252
1229
  ```typescript
1253
1230
  const form = useForm(schema, {
1254
- initialValues: {
1255
- /* ... */
1256
- },
1231
+ initialValues: {/* ... */},
1257
1232
  onSubmit: async (values) => {
1258
1233
  await api.createUser(values);
1259
1234
  },
@@ -1276,8 +1251,8 @@ match(result, {
1276
1251
  **Solution:** Extract a reusable `Field` component that takes the form instance, field name, and label.
1277
1252
 
1278
1253
  ```tsx
1279
- import { useForm, type UseFormReturn, type ExtractFieldPaths } from '@railway-ts/use-form';
1280
1254
  import { object, required, chain, string, email, minLength, type InferSchemaType } from '@railway-ts/pipelines/schema';
1255
+ import { useForm, type UseFormReturn, type ExtractFieldPaths } from '@railway-ts/use-form';
1281
1256
 
1282
1257
  const loginSchema = object({
1283
1258
  email: required(chain(string(), email())),
@@ -1334,9 +1309,9 @@ For more control, accept `children` or render props instead of hard-coding `<inp
1334
1309
  Wrap field components in `React.memo` so they only re-render when their specific field changes:
1335
1310
 
1336
1311
  ```tsx
1337
- import { memo, useMemo } from 'react';
1338
- import { useForm, type UseFormReturn, type ExtractFieldPaths } from '@railway-ts/use-form';
1339
1312
  import { object, required, string, type InferSchemaType } from '@railway-ts/pipelines/schema';
1313
+ import { useForm, type UseFormReturn, type ExtractFieldPaths } from '@railway-ts/use-form';
1314
+ import { memo, useMemo } from 'react';
1340
1315
 
1341
1316
  const largeFormSchema = object({
1342
1317
  field1: required(string()),
@@ -1388,9 +1363,7 @@ For forms with many fields, `validationMode: 'blur'` avoids re-validating on eve
1388
1363
 
1389
1364
  ```typescript
1390
1365
  const form = useForm(schema, {
1391
- initialValues: {
1392
- /* ... */
1393
- },
1366
+ initialValues: {/* ... */},
1394
1367
  validationMode: 'blur',
1395
1368
  });
1396
1369
  ```
@@ -1424,8 +1397,8 @@ UI libraries like Material-UI and Chakra UI use different prop names than native
1424
1397
 
1425
1398
  ```tsx
1426
1399
  import { TextField, Button } from '@mui/material';
1427
- import { useForm } from '@railway-ts/use-form';
1428
1400
  import { object, required, chain, string, email, minLength, type InferSchemaType } from '@railway-ts/pipelines/schema';
1401
+ import { useForm } from '@railway-ts/use-form';
1429
1402
 
1430
1403
  const loginSchema = object({
1431
1404
  email: required(chain(string(), email())),
@@ -1478,8 +1451,8 @@ function MuiForm() {
1478
1451
 
1479
1452
  ```tsx
1480
1453
  import { Field, Input, Button } from '@chakra-ui/react';
1481
- import { useForm } from '@railway-ts/use-form';
1482
1454
  import { object, required, chain, string, email, minLength, type InferSchemaType } from '@railway-ts/pipelines/schema';
1455
+ import { useForm } from '@railway-ts/use-form';
1483
1456
 
1484
1457
  const loginSchema = object({
1485
1458
  email: required(chain(string(), email())),
@@ -1519,11 +1492,12 @@ function ChakraForm() {
1519
1492
  Shadcn components use native HTML under the hood, so `getFieldProps` works directly:
1520
1493
 
1521
1494
  ```tsx
1495
+ import { object, required, chain, string, email, minLength, type InferSchemaType } from '@railway-ts/pipelines/schema';
1496
+ import { useForm } from '@railway-ts/use-form';
1497
+
1498
+ import { Button } from '@/components/ui/button';
1522
1499
  import { Input } from '@/components/ui/input';
1523
1500
  import { Label } from '@/components/ui/label';
1524
- import { Button } from '@/components/ui/button';
1525
- import { useForm } from '@railway-ts/use-form';
1526
- import { object, required, chain, string, email, minLength, type InferSchemaType } from '@railway-ts/pipelines/schema';
1527
1501
 
1528
1502
  const loginSchema = object({
1529
1503
  email: required(chain(string(), email())),
@@ -1676,9 +1650,7 @@ function PersistentForm() {
1676
1650
  ```tsx
1677
1651
  function FormWithWarning() {
1678
1652
  const form = useForm(schema, {
1679
- initialValues: {
1680
- /* ... */
1681
- },
1653
+ initialValues: {/* ... */},
1682
1654
  });
1683
1655
 
1684
1656
  useEffect(() => {
@@ -1711,7 +1683,6 @@ For React Router or Next.js navigation, you'll also need to hook into the router
1711
1683
  This recipe combines everything: schema validation, per-field async validators, server errors, cross-field validation (password confirmation), and Result pattern-matching on submit.
1712
1684
 
1713
1685
  ```tsx
1714
- import { useForm } from '@railway-ts/use-form';
1715
1686
  import { ok, err, match, fromPromise, type Result } from '@railway-ts/pipelines/result';
1716
1687
  import {
1717
1688
  object,
@@ -1725,6 +1696,7 @@ import {
1725
1696
  ROOT_ERROR_KEY,
1726
1697
  type InferSchemaType,
1727
1698
  } from '@railway-ts/pipelines/schema';
1699
+ import { useForm } from '@railway-ts/use-form';
1728
1700
 
1729
1701
  // --- Schema ---
1730
1702
 
@@ -1837,9 +1809,6 @@ This form demonstrates:
1837
1809
  The same registration form using React Query for server state and React Router for navigation -- no Result types, just idiomatic React patterns.
1838
1810
 
1839
1811
  ```tsx
1840
- import { useNavigate } from 'react-router-dom';
1841
- import { useMutation, useQueryClient } from '@tanstack/react-query';
1842
- import { useForm } from '@railway-ts/use-form';
1843
1812
  import {
1844
1813
  object,
1845
1814
  string,
@@ -1852,6 +1821,9 @@ import {
1852
1821
  ROOT_ERROR_KEY,
1853
1822
  type InferSchemaType,
1854
1823
  } from '@railway-ts/pipelines/schema';
1824
+ import { useForm } from '@railway-ts/use-form';
1825
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
1826
+ import { useNavigate } from 'react-router-dom';
1855
1827
 
1856
1828
  // --- Schema ---
1857
1829
 
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@railway-ts/use-form",
3
- "version": "0.1.32",
3
+ "version": "0.1.34",
4
4
  "description": "React form hook that works with @railway-ts/pipelines to manage form state, validation, and submission.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",
7
7
  "module": "./dist/index.mjs",
8
- "types": "./dist/index.d.ts",
8
+ "types": "./dist/index.d.mts",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./dist/index.d.ts",
11
+ "types": "./dist/index.d.mts",
12
12
  "import": "./dist/index.mjs",
13
13
  "default": "./dist/index.mjs"
14
14
  }
@@ -24,26 +24,11 @@
24
24
  },
25
25
  "scripts": {
26
26
  "example": "bun --hot examples/server.ts",
27
- "build": "bunx tsup",
28
- "build:watch": "bunx tsup --watch",
29
- "dev": "bunx tsup --watch",
27
+ "build": "tsdown",
28
+ "dev": "tsdown --watch",
29
+ "typecheck": "tsc --noEmit",
30
30
  "test": "bun test",
31
- "test:watch": "bun test --watch",
32
- "test:coverage": "bun test --coverage",
33
- "test:coverage:lcov": "mkdir -p coverage && bun test --coverage --coverage-reporter=lcov",
34
- "test:bail": "bun test --bail",
35
- "test:fast": "bun test --bail --timeout=1000",
36
- "test:pattern": "bun test --test-name-pattern",
37
- "test:only": "bun test --only",
38
- "test:reporter": "bun test --reporter=junit --reporter-outfile=junit.xml",
39
- "lint": "bunx eslint .",
40
- "lint:fix": "bunx eslint . --fix",
41
- "format": "bunx prettier --write .",
42
- "format:check": "bunx prettier --check .",
43
- "typecheck": "bunx tsc --noEmit",
44
- "size": "bunx size-limit",
45
- "prepublishOnly": "bun run typecheck && bun run lint && bun run test && bun run build && bun run size",
46
- "check": "bun run typecheck && bun run lint && bun run test"
31
+ "test:coverage": "mkdir -p coverage && bun test --coverage --coverage-reporter=lcov"
47
32
  },
48
33
  "keywords": [
49
34
  "react",
@@ -54,51 +39,36 @@
54
39
  "typescript",
55
40
  "type-safe"
56
41
  ],
57
- "repository": "github:sakobu/railway-ts-use-form",
58
- "homepage": "https://github.com/sakobu/railway-ts-use-form#readme",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/sakobu/railway-ts.git",
45
+ "directory": "packages/use-form"
46
+ },
47
+ "homepage": "https://github.com/sakobu/railway-ts/tree/main/packages/use-form#readme",
59
48
  "bugs": {
60
- "url": "https://github.com/sakobu/railway-ts-use-form/issues"
49
+ "url": "https://github.com/sakobu/railway-ts/issues"
61
50
  },
62
51
  "author": "Sarkis Melkonian",
63
52
  "license": "MIT",
64
53
  "publishConfig": {
65
54
  "access": "public"
66
55
  },
67
- "size-limit": [
68
- {
69
- "path": "dist/index.mjs",
70
- "limit": "10 kB"
71
- }
72
- ],
73
56
  "peerDependencies": {
74
- "@railway-ts/pipelines": "^0.1.27",
57
+ "@railway-ts/pipelines": "^0.1.27 || ^0.2.0",
75
58
  "react": "^18.0.0 || ^19.0.0",
76
59
  "typescript": ">=5.0"
77
60
  },
78
61
  "devDependencies": {
79
- "@eslint/js": "^10.0.1",
80
62
  "@happy-dom/global-registrator": "^20.9.0",
81
- "@railway-ts/pipelines": "^0.1.29",
63
+ "@railway-ts/pipelines": "0.2.0",
82
64
  "@testing-library/dom": "^10.4.1",
83
65
  "@testing-library/jest-dom": "^6.9.1",
84
66
  "@testing-library/react": "^16.3.2",
85
67
  "@testing-library/user-event": "^14.6.1",
86
- "@types/bun": "^1.3.12",
87
68
  "@types/react": "^19.2.14",
88
69
  "@types/react-dom": "^19.2.3",
89
- "@typescript-eslint/eslint-plugin": "^8.58.2",
90
- "@typescript-eslint/parser": "^8.58.2",
91
- "eslint": "^10.2.1",
92
- "eslint-config-prettier": "^10.1.8",
93
- "@eslint-react/eslint-plugin": "^4.2.3",
94
- "eslint-plugin-react-hooks": "^7.1.1",
95
- "prettier": "^3.8.3",
96
70
  "react": "^19.2.5",
97
71
  "react-dom": "^19.2.5",
98
- "@size-limit/preset-small-lib": "^12.1.0",
99
- "size-limit": "^12.1.0",
100
- "tsup": "^8.5.1",
101
- "typescript": "^6.0.0",
102
72
  "valibot": "^1.3.1",
103
73
  "zod": "^4.3.6"
104
74
  }