0.0.3 • Published 8 months ago
@reyalp/preshape v0.0.3
Preshape
Typescript & PostgreSQL code generator
It generates typedefs/enums/serdes/pg-migrations from DSL, see sample/*.txt, sample/*.yml.
run them with:
pnpm run test:do:draft -- -f <input-file>
output files are in test/src/*.ts, test/data/*/*.sql.
Types
| DSL notation | means | map to typescript | map to pgsql |
|---|---|---|---|
bool | boolean | boolean | int2 |
i32 | signed 32-bits integer | number | int4 |
u8 | unsigned 8-bits integer | number | uint2 |
i4 | unsigned 4-bits integer | number | int2 |
i64 | unsigned 64-bits integer | bigint | int8 |
i53 | unsigned 53-bits integersafe integer | number | int8 |
str | str(at most 232-1 octets) | number | int2 |
str/16 | str(at most 16 octets) | string | text |
str/i8 | str(at most 28-1 octets) | string | text |
str/u8 | str(at most 28-1 octets)i/u are the same | string | text |
bytea | bolb(at most <= 232-1 bytes) | Buffer | bytea |
?i32 | i32 or nothing | number | undefined | int4NULLABLE |
[i32] | i32 array(at most 232-1 elements) | number[] | jsonbTODO: maybe array? |
[i32; 4] | i32 array(at most 4 elements) | number[] | jsonb |
[i32; i8] | i32 array(at most 28-1 elements) | number[] | jsonb |
[?i32] | optional i32 array | (number | undefined)[] | jsonb |
[str/4; 4] | string array(at most 4 elements)(each contains at most 4 octets) | string[] | jsonb |
(i4; i8; str) | tuple | [number, number, string] | jsonb |
(label: i4; i8; str) | tuple, labelled | [labal: number, number, string] | jsonb |
[(i8, i8)] | array of tuple | [number, number][] | jsonb |
[(i8, [i8])] | array of tuple.. mixed | [number, number[]][] | jsonb |
| { id i32 name str} | a struct/object | { id: number; name: string } | jsonb |
| { ... t case { 'u1' { arg1 str } 'u2' { arg2 i32 } }} | tagged union | { ... } & ({ t: 'u1'; arg1: string } | { t: 'u2'; arg2: number}) | jsonb |
TODO Cont'd