@jarenjs/forms 0.49.2 → 0.56.0
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/README.md +32 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -21,13 +21,13 @@ import {
|
|
|
21
21
|
|
|
22
22
|
const schema = {
|
|
23
23
|
type: 'object',
|
|
24
|
-
title: 'Sign up',
|
|
25
24
|
properties: {
|
|
26
25
|
username: { type: 'string', minLength: 3, pattern: '^[a-z0-9_]+$' },
|
|
27
26
|
email: { type: 'string', format: 'email' },
|
|
28
27
|
age: { type: 'integer', minimum: 13 },
|
|
29
28
|
},
|
|
30
29
|
required: ['username', 'email'],
|
|
30
|
+
title: 'Sign up',
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
// 1. Build the field tree once
|
|
@@ -90,6 +90,27 @@ stylesheet is the second kind of host, and the website's data studio the first.
|
|
|
90
90
|
|
|
91
91
|
Which date formats get a **native** control is decided by the offset, not by convenience. HTML's `datetime-local` and `time` inputs cannot produce one, and RFC 3339 requires one — binding them to `date-time`/`time` would make the control emit values its own schema rejects, so those stay text inputs. The `iso-date-time`/`iso-time` formats leave the offset optional and are exactly what those inputs spell, so they map losslessly. `formatMinimum`/`formatMaximum` reach the field as constraints and become the control's `min`/`max`, so the picker itself refuses an out-of-range date; HTML has no exclusive date bounds, so `formatExclusive*` stays a submit-time check.
|
|
92
92
|
|
|
93
|
+
### The same model, by code
|
|
94
|
+
|
|
95
|
+
The schema above is what `@jarenjs/linq/forms` emits, byte for byte:
|
|
96
|
+
|
|
97
|
+
```javascript
|
|
98
|
+
import * as f from '@jarenjs/linq/forms';
|
|
99
|
+
|
|
100
|
+
export const signup = f.object({
|
|
101
|
+
username: f.string().min(3).pattern('^[a-z0-9_]+$'),
|
|
102
|
+
email: f.string().format('email'),
|
|
103
|
+
age: f.integer().min(13).optional(),
|
|
104
|
+
}).open().title('Sign up');
|
|
105
|
+
|
|
106
|
+
const model = buildFormModel(signup.schema);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Every rule of the next section is a `.form({ … })` on the member it
|
|
110
|
+
belongs to; the pen's document is
|
|
111
|
+
[FORMS-PEN.md](../linq/docs/FORMS-PEN.md), and nothing in this package
|
|
112
|
+
depends on it — the schema is the contract.
|
|
113
|
+
|
|
93
114
|
## Layer 1 — preemptive per-field validation
|
|
94
115
|
|
|
95
116
|
`validateField(field, value)` returns `[{ keyword, message }]` using `@jarenjs/core` directly:
|
|
@@ -119,6 +140,16 @@ One namespaced annotation keyword — safe under every metaschema, invisible to
|
|
|
119
140
|
} }
|
|
120
141
|
```
|
|
121
142
|
|
|
143
|
+
These annotations can be **written by code**: `@jarenjs/linq/forms` is
|
|
144
|
+
the schema pen plus `form({ visible, enabled, assert, computed,
|
|
145
|
+
message })` on every builder, with the rules captured as callbacks over
|
|
146
|
+
the same context (`c.root`, `c.value`, `c.pointer`) rather than typed
|
|
147
|
+
as path strings, and `assertOnSubmit()` answering the layer-3 twin
|
|
148
|
+
below in one call. The document above is what it emits, byte for byte
|
|
149
|
+
— see [the by-code twin](#the-same-model-by-code) and
|
|
150
|
+
[FORMS-PEN.md](../linq/docs/FORMS-PEN.md). This package depends on
|
|
151
|
+
none of it; the annotation is the contract.
|
|
152
|
+
|
|
122
153
|
Recognized members — unknown members are ignored for forward compatibility:
|
|
123
154
|
|
|
124
155
|
| Member | Kind | Meaning |
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jarenjs/forms",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.56.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"types": "./dist/types/index.d.ts",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"prepack": "npm run build:types"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@jarenjs/core": "^0.
|
|
51
|
-
"@jarenjs/formats": "^0.
|
|
52
|
-
"@jarenjs/json": "^0.
|
|
53
|
-
"@jarenjs/validate": "^0.
|
|
50
|
+
"@jarenjs/core": "^0.56.0",
|
|
51
|
+
"@jarenjs/formats": "^0.56.0",
|
|
52
|
+
"@jarenjs/json": "^0.56.0",
|
|
53
|
+
"@jarenjs/validate": "^0.56.0"
|
|
54
54
|
}
|
|
55
55
|
}
|