feat: accept io-ts codecs as table field types - #8
Merged
Conversation
Widen FieldType to also accept any io-ts Mixed codec at the root of a field, alongside the existing string-token vocabulary. Codecs don't nest inside string-tree records; use io-ts combinators for nesting inside a codec. io-ts is declared as an optional peer dependency.
Contributor
Author
|
@greptile review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FieldTypeinsrc/schema.tsto accept any io-ts-shaped codec at the root of a field, alongside the existing string-token vocabulary. Codecs do not nest inside string-tree records — use io-ts combinators (t.type,t.array, …) for nesting within a codec._A/_O/_I/name/is/encode/decode) so the emitted.d.tsis self-contained; consumers don't needio-tsresolvable to useFieldType.StringFieldTypealongsideFieldTypefor consumers that want to spell the string-only arm.docs/3.results/4.table_changes.mdwith the codec arm and a short example.src/tests/datasets/codec_fields.tsas a compile-time check that codec-flavored schemas type-check.The interface remains a thin pass-through — no runtime validation is added here; codecs flow through
Schemas.registerto adapters.Test plan
pnpm installsucceedspnpm run buildsucceeds anddist/schema.d.tshas noimport("io-ts")referencepnpm run lintis cleansrc/tests/datasets/users.ts,products.ts) still type-check unchanged (non-breaking)src/tests/datasets/codec_fields.tstype-checks withoutas anyor suppressionsGreptile Summary
This PR widens
FieldTypeinsrc/schema.tsto accept io-ts codecs alongside the existing string-token vocabulary, using a self-contained local structural interface (IoTsCodec) soio-tsdoes not appear as an import in the emitted.d.ts.StringFieldTypeis now exported for consumers who need to reference the string-only arm explicitly.src/schema.ts: Renames the originalFieldTypetoStringFieldType(now exported), introduces a localIoTsCodecstructural interface, and re-exportsFieldType = StringFieldType | IoTsCodec— no io-ts import, keeping the emitted declaration self-contained.src/tests/datasets/codec_fields.ts: New compile-time test confirming that io-ts codecs type-check correctly as field values inside aSchemaDefinition.package.json/pnpm-lock.yaml: Addsfp-tsandio-tsas devDependencies so the new test dataset compiles in CI.Confidence Score: 5/5
Safe to merge — the change is additive and non-breaking; existing string-token schemas are unaffected.
The structural
IoTsCodecinterface correctly avoids any io-ts import in the emitted declaration, the string-token path is unchanged, and the new compile-time test dataset validates the codec arm. The two findings are minor documentation and export surface observations that don't affect runtime correctness.The documentation in
docs/3.results/4.table_changes.mdreferencesimport("io-ts").Mixedrather than the actual local structural type, which is worth correcting before the docs are published.Important Files Changed
IoTsCodecinterface andStringFieldTypealias; widensFieldTypeto accept codecs without importing from io-ts.IoTsCodecis not exported (minor).import("io-ts").Mixedwhich doesn't match the actual local structural interface in the emitted.d.ts.SchemaDefinition; looks correct.fp-tsandio-tsas devDependencies so the compile-time test dataset builds correctly.Class Diagram
%%{init: {'theme': 'neutral'}}%% classDiagram class StringFieldType { <<type>> string Array~StringFieldType~ Record~string, StringFieldType~ } class IoTsCodec { <<interface>> +readonly _A: unknown +readonly _O: unknown +readonly _I: unknown +readonly name: string +is(u: unknown) boolean +encode(a: never) unknown +decode(i: unknown) unknown } class FieldType { <<type>> StringFieldType | IoTsCodec } class TableDefinition { <<interface>> +fields: Record~string, FieldType~ +indexes: Record~string, IndexDefinition~ } class SchemaDefinition { <<interface>> +[tableName: string]: TableDefinition } FieldType ..> StringFieldType : union arm FieldType ..> IoTsCodec : union arm TableDefinition --> FieldType : fields values SchemaDefinition --> TableDefinition : table valuesPrompt To Fix All With AI
Reviews (2): Last reviewed commit: "address greptile review feedback (greplo..." | Re-trigger Greptile