{"id":23915793,"url":"https://github.com/bryantgillespie/directus-sdk-typegen","last_synced_at":"2025-08-01T08:12:12.007Z","repository":{"id":257774197,"uuid":"859362152","full_name":"bryantgillespie/directus-sdk-typegen","owner":"bryantgillespie","description":"CLI and library to generate TypeScript types from Directus collections for use with Directus SDK.","archived":false,"fork":false,"pushed_at":"2025-04-18T09:39:42.000Z","size":63,"stargazers_count":23,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-04T03:40:46.296Z","etag":null,"topics":["directus","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/bryantgillespie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-09-18T14:33:13.000Z","updated_at":"2025-06-01T19:42:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"bf61c83d-0d92-491f-bc0e-bb9b066a74cd","html_url":"https://github.com/bryantgillespie/directus-sdk-typegen","commit_stats":null,"previous_names":["bryantgillespie/directus-sdk-typegen"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bryantgillespie%2Fdirectus-sdk-typegen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bryantgillespie%2Fdirectus-sdk-typegen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bryantgillespie%2Fdirectus-sdk-typegen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bryantgillespie%2Fdirectus-sdk-typegen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bryantgillespie","download_url":"https://codeload.github.com/bryantgillespie/directus-sdk-typegen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bryantgillespie%2Fdirectus-sdk-typegen/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":257944602,"owners_count":22626239,"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":["directus","typescript"],"created_at":"2025-01-05T11:48:17.457Z","updated_at":"2025-06-10T11:36:28.959Z","avatar_url":"https://github.com/bryantgillespie.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Directus SDK Types Generator\n\nOpinionated CLI tool and library to generate TypeScript types from Directus collections to use with the Directus SDK.\n\nGenerates the individual interfaces for the Directus collections and a `Schema` type that collects all the interfaces together for use with the Directus SDK.\n\n## Example\n\nGenerate the types from the CLI.\n\n```bash\nnpx directus-sdk-typegen -u http://localhost:8055 -t your-token-here -o ./my-schema.ts\n```\n\n```typescript\n// my-schema.ts\nexport interface Event {\n\t/** @required */\n\tid: string;\n\tstatus?: 'draft' | 'active' | 'past';\n\tsort?: number | null;\n\tuser_created?: DirectusUser | string | null;\n\tdate_created?: string | null;\n\tuser_updated?: DirectusUser | string | null;\n\tdate_updated?: string | null;\n\t/** @description Name of the event. @required */\n\ttitle: string;\n\t/** @required */\n\tslug: string;\n\t/** @description When does this event start? @required */\n\tstart_at: string;\n\t/** @description When does this event end? */\n\tend_at?: string | null;\n\t/** @description Short description of the event. Used in SEO meta description. */\n\tdescription?: string | null;\n\tfeatured_image?: DirectusFile | string | null;\n\ttimezone?: string | null;\n\tlocation?: 'whereby' | 'youtube' | 'other' | null;\n\tlocation_url?: string | null;\n\tlocation_youtube?: string | null;\n\trecording_url?: string | null;\n\tcontent?: string | null;\n\tlocation_whereby?: any | null;\n\tcustom_registration_questions?: EventCustomRegistrationQuestion[] | string[];\n\temails?: EventEmail[] | string[];\n\tfeedback?: EventFeedback[] | string[];\n\tregistrants?: EventRegistration[] | string[];\n\thosts?: EventHost[] | string[];\n}\n\nexport interface Schema {\n\tevents: Event[]\n}\n```\n\nThen use the generated types with the Directus SDK.\n\n```typescript\nimport type { Schema } from './my-schema';\n\nimport {\n\tcreateDirectus,\n    rest\n} from '@directus/sdk';\n\nconst directus = createDirectus\u003cSchema\u003e('http://localhost:8055').with(rest())\n```\n\n## Installation\n\nYou can run the CLI tool using `npx` or install it globally.\n\n```bash\nnpx directus-sdk-typegen -u http://localhost:8055 -t your-token-here -o ./my-schema.ts\n```\n\nor\n\n```bash\nnpm install -g directus-sdk-typegen\n```\n\n```bash\ndirectus-sdk-typegen -u http://localhost:8055 -t your-token-here -o ./my-schema.ts\n```\n\n## Usage\n\nYou can use the Directus Type Generator as a CLI tool or as a library in your Node.js application.\n\n### CLI Usage\n\nTo generate TypeScript types from Directus collections, use the following command:\n\n```bash\nnpx directus-sdk-typegen --url \u003cDIRECTUS_API_URL\u003e --token \u003cDIRECTUS_API_TOKEN\u003e --output \u003cOUTPUT_FILE_PATH\u003e\n```\n\n#### Options\n- `-o, --output \u003cpath\u003e`: Specify the output file path including filename (default: `./directus-schema.ts`).\n- `-u, --url \u003curl\u003e`: Directus API URL (default: `http://localhost:8055`).\n- `-t, --token \u003ctoken\u003e`: Directus API token. Needs Adminstrator permissions (default: `your-token-here`).\n\n### Library Usage\n\nYou can also use the generator programmatically in your Node.js application:\n\n```typescript\n// Output to a file\nimport { generateDirectusTypes } from 'directus-sdk-typegen';\n\nasync function generateTypes() {\n    try {\n        await generateDirectusTypes({\n            outputPath: './my-schema.ts',\n            directusUrl: 'http://localhost:8055',\n            directusToken: 'your-token-here',\n        });\n    } catch (error) {\n        console.error('Failed to generate types:', error);\n    }\n}\n\ngenerateTypes();\n```\n\n```typescript\n// Return types as a variable\nimport { generateDirectusTypes } from 'directus-sdk-typegen';\n\nasync function generateTypes() {\n    try {\n        const types = await generateDirectusTypes({\n            directusUrl: 'http://localhost:8055',\n            directusToken: 'your-token-here',\n        });\n        // Do something else with the types\n        console.log(types);\n    } catch (error) {\n        console.error('Failed to generate types:', error);\n    }\n}\n```\n\n\n## Contributing\n\nHappy to accept contributions that improve the types generated! But please open an issue first to discuss changes.\n\n## License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbryantgillespie%2Fdirectus-sdk-typegen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbryantgillespie%2Fdirectus-sdk-typegen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbryantgillespie%2Fdirectus-sdk-typegen/lists"}