{"id":13609674,"url":"https://github.com/bwireman/genus","last_synced_at":"2025-07-30T12:32:21.235Z","repository":{"id":39582903,"uuid":"492529790","full_name":"bwireman/genus","owner":"bwireman","description":"Type Script and Elixir structs, a monster mash","archived":false,"fork":false,"pushed_at":"2023-03-04T18:45:12.000Z","size":98,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-07T15:46:09.149Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bwireman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-05-15T15:41:20.000Z","updated_at":"2024-08-29T11:07:12.000Z","dependencies_parsed_at":"2024-01-14T06:56:18.942Z","dependency_job_id":null,"html_url":"https://github.com/bwireman/genus","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwireman%2Fgenus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwireman%2Fgenus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwireman%2Fgenus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwireman%2Fgenus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bwireman","download_url":"https://codeload.github.com/bwireman/genus/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228133893,"owners_count":17874561,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T19:01:37.014Z","updated_at":"2024-12-04T15:19:21.536Z","avatar_url":"https://github.com/bwireman.png","language":"Elixir","funding_links":[],"categories":["Elixir"],"sub_categories":[],"readme":"# Genus\n\nMacro for generating Typescript types and Elixir structs\n\n## Installation\n\n```elixir\ndef deps do\n  [\n    {:genus, git: \"git@github.com:bwireman/genus.git\"}\n  ]\nend\n```\n\n## Usage\n\n```elixir\ndefmodule User do\n  # load the `tschema` macro\n  use Genus\n  tschema name: \"User\" do\n    field(:id, :string, required: true)\n    field(:email, :string)\n    field(:active, :bool, default: false)\n    field(:role, :union, \"Role\", true, [:enduser, :admin, :superuser], default: :enduser)\n  end\nend\n```\n\n### Macro Options\n\n- name: Name of the generated TypeScript interface, defaults to the last piece of the module name\n- imports: keyword of other imports and import overrides to add to the generated file\n\n### Elixir output\n\n```elixir\ndefmodule User do\n  @enforce_keys [:id]\n  defstruct [id: nil, email: nil, active: false, role: :enduser]\nend\n```\n\n### Typescript output\n\n```typescript\n// Do Not Modify! This file was generated by Genus from an Elixir struct @ Elixir.User\n// https://github.com/bwireman/genus\n\nexport type Role = \"enduser\" | \"admin\" | \"superuser\"\n\nexport interface User {\n  id: string\n  email?: string\n  active: boolean\n  role: Role\n}\n\nexport const apply_user = (v: any): User =\u003e v\n\nexport const build_user = ({ id, email, active, role }: {\n  id: string\n  email?: string\n  active?: boolean\n  role?: Role\n}): User =\u003e {\n  return {\n    id: id,\n    email: email || undefined,\n    active: active || false,\n    role: role || \"enduser\",\n  }\n}\n\nexport const new_user = (id: string) =\u003e build_user({ id })\n```\n\n### Config\n\n```elixir\nimport Config\n\nconfig :genus,\n  # path directory to save the write TypeScript code to\n  # defaults to \"./ts\"\n  directory: \"types\",\n  # indent spacer for generated TypeScript\n  # defaults to \"  \"\n  indent: \"\\t\"\n```\n\n## Types\n\n| Format                                       | Elixir type | TS type     |\n| -------------------------------------------- | ----------- | ----------- |\n| (name, :string)                              | String.t()  | string      |\n| (name, :integer)                             | integer()   | number      |\n| (name, :float)                               | float()     | number      |\n| (name, :bool)                                | bool()      | boolean     |\n| (name)                                       | any()       | any         |\n| (name, :external, type_name)                 | any()       | type_name   |\n| (name, :list, type_name)                     | list()      | type_name[] |\n| (name, :union, type_name, is_string, values) | any()       | type_name   |\n\n#### Type Options\n\n- type_name `String.t()`: represents the TS type to use\n- is_string `bool()`: Should the union be represented as strings in TS\n- values `list()`: Values that compose the union\n\n## Field Options\n\n#### `default: value` | `required: true|false`\n\nFields default to being optional and with a `nil` default in Elixir and nullable with a default of `undefined` in TypeScript. If you specify a value that will be the default value in both Elixir and Typescript. You can also specify `required:` and mark the field as required in both the Elixir struct and the generator function\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwireman%2Fgenus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbwireman%2Fgenus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwireman%2Fgenus/lists"}