docs: update README and loader documentation

This commit is contained in:
2026-06-13 10:24:42 +08:00
parent ea98399c24
commit a3e0e953ff
2 changed files with 27 additions and 6 deletions
+26 -5
View File
@@ -128,16 +128,40 @@ Parses a value string according to the given schema.
Creates a validation function for the given schema.
### `schemaToTypeString(schema: Schema): string`
Converts a schema AST back to a human-readable type string.
### `ParseError`
Error class thrown for invalid schema syntax.
### Types
The following TypeScript types are exported:
- `Schema` — union of all schema AST node types
- `ParsedSchema` — the return type of `defineSchema()`
- `PrimitiveSchema`, `TupleSchema`, `ArraySchema` — AST node types
- `ReferenceSchema`, `ReverseReferenceSchema` — reference AST node types
- `StringLiteralSchema`, `UnionSchema` — literal and union AST node types
## Schema Syntax
| Type | Schema | Example Value |
|------|--------|---------------|
| String | `string` or `identifier` | `hello` |
| Number | `number` | `42` |
| Int | `int` | `42` |
| Float | `float` | `3.14` |
| Number | `number` | `42` or `3.14` |
| Boolean | `boolean` | `true` or `false` |
| Tuple | `[Type1; Type2; ...]` | `[hello; 42; true]` or `hello; 42; true` |
| Array | `Type[]` or `[Type][]` | `[1; 2; 3]` or `1; 2; 3` |
| Array of Tuples | `[Type1; Type2][]` | `[[a; 1]; [b; 2]]` or `[a; 1]; [b; 2]` |
| Union | `Type1 \| Type2` | `hello` or `42` (matches first valid member) |
| String Literal | `'on' \| 'off'` or `"red"` | `on` or `off` |
| Reference | `@tablename` or `@tablename[]` | (resolved at CSV load time) |
| Reverse Reference | `~tablename(fk)` | (resolved at CSV load time) |
## Notes
@@ -145,10 +169,7 @@ Creates a validation function for the given schema.
- Outermost brackets `[]` are optional for tuple and array values
- Special characters can be escaped with backslash: `\;`, `\[`, `\]`, `\\`
- Empty arrays/tuples are not allowed
## CSV Loader
For loading CSV files with schema validation in rspack, see [csv-loader.md](./csv-loader.md).
- For CSV loading with reference resolution, see [csv-loader.md](./csv-loader.md)
```javascript
// rspack.config.js
+1 -1
View File
@@ -1,6 +1,6 @@
# typed-csv/csv-loader
A rspack/rollup loader for CSV files that uses typed-csv for type validation.
A bundler loader (rspack/webpack/rollup/esbuild) for CSV files that uses typed-csv for type validation and cross-table reference resolution.
## Installation