
Product
Introducing Module Reachability: Focus on the Vulnerabilities That Matter
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
Generates typescript interfaces or zod typespecs from atlas DDL specification.
atlas2ts: Generate typescript interfaces and zod typespecs from atlas HCL files
Parameters:
-h, --help Print help message
-i, --input Path of one or more input files to process
-o, --output Path of output file for generated types (defaults to db-types.ts)
-g, --generator Generator to be used, can be ts (default) or zod
-t, --template name of liquid template file (resolved relative to template root) to feed the generated content into
--template-root Root relative to which templates will be resolved
--naming-strategy Strategy used to derive field & type names from column names and tables. Can be unmodified or camel-case (default)
--type-names Name & type mapping (Can be repeated) eg. -n users.name:Person.handle
--field-names Field name mapping
--field-types Field type mapping
--verbose Enable verbose output (Useful for bug reports)
atlas2ts -i fixtures/dvdrental.hcl -o fixtures/dvdrental.ts
atlas2ts -i fixtures/dvdrental.hcl -o fixtures/dvdrental.zod.ts -g zod
By default atlas2ts will camel-case the names of types and fields as per common convention in js ecosystem. You can also pass --naming-strategy=unmodified
to prevent this conversion. The type names will always have first character capitalized.
In addition, atlas2ts enables you to selectively override the names of types or fields in generated code.
atlas2ts -i fixtures/dvdrental.hcl -o fixtures/dvdrental.ts --type-names user:Person
In above example the interface generated for user
table will be Person
(rather than User
).
Similarly, we can configure the name of fields for specific columns:
atlas2ts -i fixtures/dvdrental.hcl -o fixtures/dvdrental.ts --field-names user.name:handle
Here the field for name
column of user table will be named as handle
(rather than name
).
Please note that atlas2ts does not know how you will use these mapped fields in your code. It is your responsibility to ensure that at runtime the generated SQL uses the correct table/column names.
Atlas2TS usually makes a sane guess around what db types should be mapped to what TS types.
However, it may need help when custom types or json fields are used.
For these scenarios, you can specify the types to be used in generated through type-mapping or field-types argument.
--type-mapping
allows you to specify what type should be used for a specific db level type.
atlas2ts -i fixtures/dvdrental.hcl -o fixtures/dvdrental.ts --type-mapping decimal:string
--field-types
allows you to specify what type should be used for a specific field:
atlas2ts -i fixtures/dvdrental.hcl -o fixtures/dvdrental.ts --field-types User.email:string
Note that the key here is typename.fieldname combination which can be different from tablename.columnname:
atlas2ts -i fixtures/dvdrental.hcl -o fixtures/dvdrental.ts --field-names user.name:handle --field-types User.handle:string
The typename in the key is optional, so we can use just the fieldname to override the type of a field in all tables:
atlas2ts -i fixtures/dvdrental.hcl -o fixtures/dvdrental.ts --field-types createdAt:Date
If these types need to be imported from elsewhere you can also define a liquid template containing relevant imports into which the output will be injected.
atlas2ts -i fixtures/dvdrental.hcl -o fixtures/dvdrental.ts --field-names user.name:handle --field-types User.handle:Str --template-root fixtures/templates --template base.ts.liquid
--template-root
should point to a directory where template(s) will be found, and template is the specific template to be used. If this template uses Partials or layouts those files will also be found from the template-root.
This template must contain a {{output}}
block where the output will be injected.
For multiple mappings, --type-names
, --field-names
or --field-types
parameter can be passed multiple times.
MIT
FAQs
Autogenerate typescript interfaces & Zod typespecs from Atlas DDL spec
The npm package atlas2ts receives a total of 2 weekly downloads. As such, atlas2ts popularity was classified as not popular.
We found that atlas2ts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
Company News
Socket is bringing best-in-class reachability analysis into the platform — cutting false positives, accelerating triage, and cementing our place as the leader in software supply chain security.
Product
Socket is introducing a new way to organize repositories and apply repository-specific security policies.