Commit Graph

73 Commits

Author SHA1 Message Date
hypercross 89be2783d1 fix(csv-loader): use commas in generated type declarations
Update `type-gen.ts` to replace semicolons with commas in the
generated TypeScript type definitions to ensure valid syntax.
2026-04-22 19:23:49 +08:00
hypercross eef3dbfac8 feat(csv-loader): resolve @table references in type declarations
Update type generation to transform @table references into capitalized
type names when using custom schema strings. This ensures that
generated TypeScript types correctly reference other CSV modules.
2026-04-22 18:15:55 +08:00
hypercross e0317946d5 feat(csv-loader): expand custom type references in schemas
Allow custom type names to be expanded before parsing the schema
string. This enables using declared types within complex structures
like tuples or arrays. The original schema string is preserved for
type generation to ensure the output uses the named type rather than
the expanded inline definition.
2026-04-22 17:58:36 +08:00
hypercross 46504a53dd feat(csv-loader): preserve original schema strings in type generation
Store the original schema string during CSV parsing to prevent
unnecessary expansion of type name references in the generated
TypeScript definitions. This ensures that declared types reference
each other by name rather than inlining their full definitions.
2026-04-22 17:08:06 +08:00
hypercross ea362d4229 test(csv-loader): add tests for custom type expansion in tuples and
arrays
2026-04-22 16:43:42 +08:00
hypercross f101c12097 feat(csv-loader): export generated type definitions 2026-04-22 16:39:41 +08:00
hypercross f03226221d test: add support for array suffixes in type expansion
Update `expandSchemaInString` to handle the `[]` suffix, allowing
type aliases to represent arrays (e.g., `IntentEffects[]`). Added a
fixture and test case to verify parsing of tuple arrays and type
aliases.
2026-04-22 16:37:54 +08:00
hypercross 1061e12c81 feat: enrich ParseError with schema and value context
Include the schema string and the input value in `ParseError` to
provide more helpful debugging information when parsing fails.
2026-04-22 16:14:23 +08:00
hypercross b5be558b57 fix(parser): fix empty array and nested bracket parsing
Improve the `ValueParser` to correctly disambiguate between empty
arrays `[]` and the start of nested structures. This ensures that
the parser can distinguish between an array containing a single
element that starts with a bracket and an actual empty array.

Update tests to reflect that parsed tuples are returned as arrays
rather than objects.
2026-04-22 00:28:10 +08:00
hypercross 585f33b856 test: add encounter fixture and complex schema test case 2026-04-22 00:24:25 +08:00
hypercross 721544e7b2 refactor: update CSV comment syntax for declarations
Update the syntax for type declarations and reverse reference
declarations in CSV files to be more explicit.

- Change type declarations from `# TypeName := schema` to
  `# type TypeName = schema`
- Change reverse reference declarations from `# fieldName :=
  ~table(key)`
  to `# inject fieldName = ~table(key)`
2026-04-21 14:36:02 +08:00
hypercross e5332f506d test: update csvToModule to mutate rows instead of returning new objects 2026-04-21 14:24:24 +08:00
hypercross 55a33b98e5 refactor: modularize validator and type declaration logic 2026-04-21 13:55:47 +08:00
hypercross 53ccac39e6 feat(csv-loader): add support for custom type declarations
Introduce the ability to define reusable types within CSV files using
comment lines with the format `# TypeName := schema`.

- Support parsing type declarations from comments or schema cells
- Enable recursive expansion of type names within schemas
- Integrate declared types into generated TypeScript definitions
- Allow columns to reference declared types by name
2026-04-21 13:47:16 +08:00
hypercross 89ac1619e7 refactor(csv-loader): simplify module generation logic
Update the code generation in `csvToModule` to use a more concise
mapping pattern for row resolvers, removing the unnecessary object
spread and nested braces.
2026-04-20 15:49:41 +08:00
hypercross 3e768f5c83 test: refactor csv-loader tests into separate files
Split the monolithic `src/csv-loader/loader.test.ts` into multiple
specialized test files to improve maintainability and readability:

- `parseCsv-basic.test.ts`: Primitive types, arrays, and tuples
- `parseCsv-caching.test.ts`: Table caching logic
- `parseCsv-circular.test.ts`: Circular reference detection
- `parseCsv-combinators.test.ts`: References in unions and tuples
- `parseCsv-noResolveRefs.
2026-04-20 11:37:56 +08:00
hypercross d0ed1dc92d refactor: use parseValue for reference ID extraction
Replace the custom `ReferenceValueParser` class with the core
`parseValue` function in `reference-resolver.ts`. This simplifies
the logic for parsing reference IDs and ensures consistency with the
rest of the schema parsing engine.
2026-04-20 11:15:51 +08:00
hypercross f66f60aa0e test: add comprehensive tests for csvToModule
- Add unit tests for accessor-based output, circular references,
  and reverse reference resolution in `csvToModule`.
- Extract fixture loading logic into `test-utils.ts`.
- Refactor `loader.test.ts` to use the new test utilities.
2026-04-20 01:29:59 +08:00
hypercross f94e9b68e4 refactor(csv-loader): decouple reference resolution and module
generation

Extract reference resolution logic, type generation, and module
generation into dedicated modules to improve maintainability and
clean up the core loader.
2026-04-20 00:48:01 +08:00
hypercross eeaac92e39 test: add integration test for CSV reference resolution
Add integration tests for `parseCsv` using fixture CSV files
to verify that table references are correctly resolved across
multiple files.
2026-04-20 00:21:41 +08:00
hypercross c3572a5b56 fix(csv-loader): handle object foreign keys in reverse lookups
Update `csvToModule` to check if a foreign key value is an object
containing the default primary key before converting it to a string.
This ensures correct key mapping when references are resolved as
objects rather than primitive IDs.
2026-04-19 23:58:09 +08:00
hyper 5f941aba10 feat(csv-loader): support references in addition to strings for foreignKey reverse ref 2026-04-19 18:58:52 +08:00
hypercross 9a2db5edb6 feat(csv-loader): strip comments before parsing CSV
Pre-filter comment lines from the content before passing it to
`csv-parse`. This prevents quote parsing errors when comment lines
contain double quotes and simplifies the record filtering logic.
2026-04-19 14:40:41 +08:00
hypercross 5a1627c6f1 test: improve reverse reference resolution handling 2026-04-19 14:19:45 +08:00
hypercross be8eb277d4 test(csv-loader): add test for multiple comment lines at the beginning
with reverse references
2026-04-19 14:15:44 +08:00
hypercross 9dd4f60c2d feat(csv-loader): allow configurable comment character
Allow `parseCsv` to accept a custom comment character for parsing
reverse reference declarations, instead of being hardcoded to `#`.
2026-04-19 14:06:11 +08:00
hypercross e76ae79b2d Add reverse reference schema (~tablename(foreignKey))
Support reverse references via ~tablename(foreignKey) syntax,
complementing forward @tablename references. Includes parser,
validator, and CSV loader integration with the new
ReverseReferenceSchema type.
2026-04-18 22:47:58 +08:00
hypercross 0954dcf594 fix: avoid exporting loader in index 2026-04-17 17:27:19 +08:00
hypercross 740bb503b1 fix: fix type generator for tuples 2026-04-17 15:11:46 +08:00
hypercross c8f0d6b0de refactor: avoid readonly in nested types 2026-04-17 14:53:49 +08:00
hypercross 075045223f feat: add @type? optional notation 2026-04-17 11:41:06 +08:00
hypercross 1f3a812728 fix: all tables generate accessors 2026-04-15 14:52:41 +08:00
hypercross 852a108c53 fix: update type generation 2026-04-15 14:46:03 +08:00
hypercross 6eba70bb3b refactor: accessor based imports 2026-04-15 14:36:52 +08:00
hypercross 392d5f1431 fix: fix minor gotchas 2026-04-15 14:12:16 +08:00
hypercross ae2445b79c feat: add AGENTS.md 2026-04-15 14:01:50 +08:00
hypercross 8343df2316 fix: bug fixes and new tests 2026-04-15 13:58:14 +08:00
hypercross d5fdb69ad7 fix: fix nested references? 2026-04-15 13:24:51 +08:00
hypercross 97c8b1966c refactor: support string literals without quotes 2026-04-13 10:45:54 +08:00
hypercross 51a11a26bf chore: add tests 2026-04-13 10:18:12 +08:00
hypercross 14948fb5f6 feat: union and string literals 2026-04-13 10:05:49 +08:00
hypercross d78ef75272 fix: typing and remove singularization 2026-04-11 23:05:22 +08:00
hypercross daac7badbb feat: parse references 2026-04-11 22:56:01 +08:00
hypercross 3051df3e8b fix: skip empty lines 2026-04-07 12:11:01 +08:00
hypercross ad38976e86 refactor: reorg/remove webpack dependency 2026-04-07 11:25:02 +08:00
hypercross 77ee96d70c feat: esbuild csv-loader support 2026-04-07 11:20:12 +08:00
hypercross 4eb6a17e9f refactor: table name deduction & readonly type 2026-04-05 12:43:23 +08:00
hypercross f656a62606 fix: add int/float to type gen 2026-04-04 17:08:29 +08:00
hypercross 4146fda348 feat: add int/float to types 2026-04-04 17:05:25 +08:00
hypercross 8bf28c8aed fix: types for rollup 2026-04-04 16:55:17 +08:00