docs: update README and loader documentation
This commit is contained in:
@@ -128,16 +128,40 @@ Parses a value string according to the given schema.
|
|||||||
|
|
||||||
Creates a validation function for 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
|
## Schema Syntax
|
||||||
|
|
||||||
| Type | Schema | Example Value |
|
| Type | Schema | Example Value |
|
||||||
|------|--------|---------------|
|
|------|--------|---------------|
|
||||||
| String | `string` or `identifier` | `hello` |
|
| 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` |
|
| Boolean | `boolean` | `true` or `false` |
|
||||||
| Tuple | `[Type1; Type2; ...]` | `[hello; 42; true]` or `hello; 42; true` |
|
| Tuple | `[Type1; Type2; ...]` | `[hello; 42; true]` or `hello; 42; true` |
|
||||||
| Array | `Type[]` or `[Type][]` | `[1; 2; 3]` or `1; 2; 3` |
|
| 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]` |
|
| 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
|
## Notes
|
||||||
|
|
||||||
@@ -145,10 +169,7 @@ Creates a validation function for the given schema.
|
|||||||
- Outermost brackets `[]` are optional for tuple and array values
|
- Outermost brackets `[]` are optional for tuple and array values
|
||||||
- Special characters can be escaped with backslash: `\;`, `\[`, `\]`, `\\`
|
- Special characters can be escaped with backslash: `\;`, `\[`, `\]`, `\\`
|
||||||
- Empty arrays/tuples are not allowed
|
- Empty arrays/tuples are not allowed
|
||||||
|
- For CSV loading with reference resolution, see [csv-loader.md](./csv-loader.md)
|
||||||
## CSV Loader
|
|
||||||
|
|
||||||
For loading CSV files with schema validation in rspack, see [csv-loader.md](./csv-loader.md).
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// rspack.config.js
|
// rspack.config.js
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
# typed-csv/csv-loader
|
# 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
|
## Installation
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user