-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (client): extensible value type for use with custom parsers (#1791)
This PR modifies the types of our client to enable users to extend the `Value` type. This is needed when using custom parsers. For example, the parser below used to throw a type error because `Date` is not a `Value` (where `Value` is the type of base SQL values): ```ts const parser: Parser = { timestampz: (date: string) => { return new Date(date) }, } ``` With this PR, we can now write this parser as: ```ts const parser: Parser<Date> = { timestampz: (date: string) => { return new Date(date) }, } ``` And an example usage of this parser with the `ShapeStream`: ```ts type CustomRow = { foo: number bar: boolean baz: string ts: Date } const shapeStream = new ShapeStream<CustomRow>({ url: `...`, parser: { timestampz: (date: string) => { return new Date(date) }, }, }) ``` Note that this would throw an error as `Date` is not a type that occurs in the row: ```ts type CustomRow = { foo: number bar: boolean baz: string } const shapeStream = new ShapeStream<CustomRow>({ url: `...`, parser: { // type error here timestampz: (date: string) => { return new Date(date) }, }, }) ```
- Loading branch information
Showing
12 changed files
with
117 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@electric-sql/client": patch | ||
--- | ||
|
||
Make parser generic such that it can be parameterized with additional types supported by custom parsers. |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.