@drzl/validation-core 3.18.0 → 3.22.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 CHANGED
@@ -53,20 +53,45 @@ Shared interfaces and helpers used by validation generators.
53
53
  - CHECK constraints (shared by every generator that reads them)
54
54
  - `parseCheck(expression, name)` -> the parts of a `CHECK` that can be stated with certainty:
55
55
  column comparisons, `BETWEEN`, `IN (...)`, top-level `AND`, `length()`/`char_length()`,
56
- `cardinality()`/`array_length(col, 1)`, and comparisons between two columns. A disjunction, a
57
- negation, `octet_length`, an unrecognised function call and a regex match are all refused
58
- whole rather than half-applied.
59
- - `COLUMN_FORMATS` -> patterns for the column formats that are expressible. Only `numeric` is:
60
- Postgres accepts `today`, `January 8, 1999` and `allballs`, so a date or time pattern would
61
- reject rows the database takes.
56
+ `octet_length()`, `cardinality()`/`array_length(col, 1)`, and comparisons between two columns.
57
+ A negation, an unrecognised function call and a regex match are all refused whole rather than
58
+ half-applied, and a disjunction is read only where the whole of it pins one column to a set.
59
+ - `lengthMeasure(column, check)` -> how to answer a count on a given column, as one of
60
+ `'codePoints'`, `'utf8Bytes'` or `'byteLength'`, or nothing where no expression answers it.
61
+ The unit is on the check and the answer needs the column too: measured on PostgreSQL 17.5,
62
+ `length()` is the character count on a `text` and the byte count on a `bytea`, and
63
+ `char_length(bytea)` is not a function that exists. `measureExpression(measure, variable)`
64
+ renders it and `lengthCheckLabel(check)` renders the message the ledger keys on.
65
+ - `COLUMN_FORMATS` -> patterns for the column formats that are expressible, which is a short
66
+ list: Postgres accepts `today`, `January 8, 1999` and `allballs`, so a date or time pattern
67
+ would reject rows the database takes. `numeric` is Postgres's numeric input grammar, and
68
+ `pgBigint`/`mysqlBigint` are the two answers a `bigint({ mode: 'string' })` column has, since
69
+ Postgres parses that text as an integer literal (`0x1f` and `1_000` included) and MySQL parses
70
+ it as a decimal number it then rounds (`12.5` becomes 13). Each was measured against its own
71
+ server; neither states the magnitude, and the entry says why.
62
72
  - `CODEPOINT_LENGTH` -> `[...v].length`, since `varchar(n)` counts characters and JavaScript's
63
73
  `.length` counts UTF-16 units. All four generators use it.
64
74
  - `isIntegerColumn(c)`
75
+ - Constraints as data (shared by the generators that emit a ledger)
76
+ - `tableConstraints(table)` -> every CHECK, unique constraint, primary key and foreign key on a
77
+ table, each with a stable `id`, the columns it names, the rule as a sentence, whether a
78
+ generated schema enforces it, and, where it does, the exact message it attaches. A folded
79
+ numeric CHECK carries its `bounds` and a folded `IN` list its `values`, because those are what
80
+ is left to match on once the library writes the failure message itself.
81
+ - `classifyTableChecks(table)` -> the one reading of `parseCheck` plus the column-shape guards,
82
+ shared with `meta`, so "the database also checks this and no schema does" is one answer rather
83
+ than two.
84
+ - `renderConstraintsModule(tables, opts)` -> the source of `constraints.ts`: the data above plus,
85
+ unless `errorMap` is false, `constraintForIssue(table, issue)`. Plain objects with no import of
86
+ any kind, and the matcher reads zod's path items and valibot's alike.
87
+ - `resolveConstraints(option)` expands the `true` shorthand; `CONSTRAINTS_MODULE` is the file
88
+ name every generator writes it to.
65
89
  - Uniqueness
66
90
  - `renderDuplicateFinder(table, fnName, rowType)` -> the source of a function returning the rows
67
- in a batch that collide with an earlier row on a unique constraint. Plain TypeScript with no
68
- reference to any validation library, so all four generators emit the same one. Null and absent
69
- columns skip a constraint, matching SQL.
91
+ in a batch that collide with an earlier row on the primary key or a unique constraint. Plain
92
+ TypeScript with no reference to any validation library, so every validator generator emits the
93
+ same one. Null and absent columns skip a constraint, matching SQL, so rows that leave a
94
+ generated key to the database report nothing on it.
70
95
  - Naming (shared by every generator that emits a schema name)
71
96
  - `resolveAffix({ affix, schemaSuffix })` -> `ResolvedAffix`
72
97
  - `schemaName(mode, tsName, resolved)`, `typeName(mode, tsName, resolved)`