{"id":16440832,"url":"https://github.com/idevelopthings/surrealdb-type-generator","last_synced_at":"2025-06-10T17:35:31.142Z","repository":{"id":60392621,"uuid":"542838764","full_name":"iDevelopThings/surrealdb-type-generator","owner":"iDevelopThings","description":"Typescript type definition generator for surrealdb databases.","archived":false,"fork":false,"pushed_at":"2022-09-29T01:14:18.000Z","size":38,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-26T01:11:50.725Z","etag":null,"topics":["surrealdb"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/surrealdb.types","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iDevelopThings.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-28T23:54:03.000Z","updated_at":"2023-10-01T05:07:13.000Z","dependencies_parsed_at":"2023-01-19T00:31:10.036Z","dependency_job_id":null,"html_url":"https://github.com/iDevelopThings/surrealdb-type-generator","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/iDevelopThings%2Fsurrealdb-type-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iDevelopThings%2Fsurrealdb-type-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iDevelopThings%2Fsurrealdb-type-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iDevelopThings%2Fsurrealdb-type-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iDevelopThings","download_url":"https://codeload.github.com/iDevelopThings/surrealdb-type-generator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iDevelopThings%2Fsurrealdb-type-generator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259118359,"owners_count":22807956,"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":["surrealdb"],"created_at":"2024-10-11T09:13:09.332Z","updated_at":"2025-06-10T17:35:31.119Z","avatar_url":"https://github.com/iDevelopThings.png","language":"TypeScript","readme":"\u003cbr\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://surrealdb.com#gh-dark-mode-only\" target=\"_blank\"\u003e\n        \u003cimg width=\"300\" src=\"https://raw.githubusercontent.com/surrealdb/surrealdb/bcac94f9d6ee154fd6ec2b5c0c910525b0c23b7a/img/white/logo.svg\" alt=\"SurrealDB Logo\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://surrealdb.com#gh-light-mode-only\" target=\"_blank\"\u003e\n        \u003cimg width=\"300\" src=\"https://raw.githubusercontent.com/surrealdb/surrealdb/bcac94f9d6ee154fd6ec2b5c0c910525b0c23b7a/img/black/logo.svg\" alt=\"SurrealDB Logo\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\n\u003ch2\u003eTypeScript Definition Generator\u003c/h2\u003e\n\n\u003cp\u003e\nThis package will allow you to generate type information from your well defined surrealdb tables :)\n\u003c/p\u003e\n\n\u003cp\u003e\nFirst of all, install the package: \n\u003c/p\u003e\n\n```bash\nnpm install surrealdb.types\nyarn add surrealdb.types\n\n# or install it globally\n\nnpm install -g surrealdb.types\nyarn global add surrealdb.types\n```\n\n## Generating types:\n\n#### Local package usage:\n\n```bash\n# This will generate the types into your current directory\n./bin/surrealdb-types --namespace test --database application --user root --pass secret --host http://0.0.0.0:8000\n# This will generate the types into your current directory as `db-types.d.ts`\n./bin/surrealdb-types --output ./db-types.d.ts --namespace test --database application --user root --pass secret --host http://0.0.0.0:8000\n```\n\n#### Global package usage:\n\n```bash\n# This will generate the types into your current directory\nsurrealdb-types --namespace test --database application --user root --pass secret --host http://0.0.0.0:8000\n# This will generate the types into your current directory as `db-types.d.ts`\nsurrealdb-types --output ./db-types.d.ts --namespace test --database application --user root --pass secret --host http://0.0.0.0:8000\n```\n\n## Programmatic usage:\n\n```typescript \nimport {Generator, Structure, ProcessedStructure} from \"surrealdb.types/gen\"\nimport * as ts from \"typescript\";\n\nconst generator = new Generator({\n    output : './myname.d.ts'\n    db : {\n        namespace: 'test',\n        database: 'application',\n        user: 'root',\n        pass: 'secret',\n        host: 'http://0.0.0.0:4269',\n    },\n    tableNameFormatterFn: (name:string) =\u003e name.toUpperCase(),\n    \n    // Exclude admin tables?(example)\n    allowGeneration: (tableName: string, structure: Structure[]) =\u003e tableName.includes('admin') === false,\n    \n    // Rename fields or modify their typescript types\n    beforeTableGenerationFn?: (tableName: string, structure: ProcessedStructure[]) =\u003e {\n        return structure.map(field =\u003e {\n            field.name = 'randomly_renamed_field' + field.name\n            return field;\n        })\n    },\n    \n    // You can modify the generated AST for everything here \n    // before it's output to the compiler\n    beforeCompilationFn?: (input: ts.NodeArray\u003cany\u003e) =\u003e {\n        // You can use https://ts-ast-viewer.com \n        // To enter some ts and get an AST version for ease of use.\n        return input;\n    }\n\n});\n\n// Finally we can run the generator\ngenerator.process()\n\t.then(() =\u003e console.log('Finished.'))\n\t.catch(err =\u003e console.error(err));\n\n```\n\n### Configuration:\n```typescript\nexport type GeneratorConfig = {\n    // Modify how table names are converted to model names\n    // This is the name of the actual type\n    tableNameFormatterFn?: (name: string) =\u003e string,\n    \n    // Add a hook to prevent a specific table from being generated\n    // Returning false means it wont be generated\n    allowGeneration?: (tableName: string, structure: Structure[]) =\u003e boolean,\n    // Add a hook function to run some arbitrary code before the table AST is generated\n    // This would allow you to adjust how types are formatted in the structure for example\n    beforeTableGenerationFn?: (tableName: string, structure: ProcessedStructure[]) =\u003e ProcessedStructure[],\n    \n    // Add a function to modify/add/remove ts nodes, before they're sent to the compiler\n    beforeCompilationFn?: (input: ts.NodeArray\u003cany\u003e) =\u003e ts.NodeArray\u003cany\u003e,\n    \n    db?: SurrealDbConfig,\n    \n    // The path to output the generated typescript file\n    output: string;\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidevelopthings%2Fsurrealdb-type-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidevelopthings%2Fsurrealdb-type-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidevelopthings%2Fsurrealdb-type-generator/lists"}