{"id":15678231,"url":"https://github.com/chappio/directus-extension-models","last_synced_at":"2025-05-07T02:28:23.714Z","repository":{"id":171517999,"uuid":"647917464","full_name":"ChappIO/directus-extension-models","owner":"ChappIO","description":"Generate TypeScript types from your directus schema for custom extension development","archived":false,"fork":false,"pushed_at":"2024-11-25T12:57:06.000Z","size":275,"stargazers_count":28,"open_issues_count":7,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-07T02:28:18.934Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/ChappIO.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-31T20:04:28.000Z","updated_at":"2025-04-04T10:45:40.000Z","dependencies_parsed_at":"2024-10-23T13:32:09.646Z","dependency_job_id":null,"html_url":"https://github.com/ChappIO/directus-extension-models","commit_stats":null,"previous_names":["chappio/directus-extension-models"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChappIO%2Fdirectus-extension-models","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChappIO%2Fdirectus-extension-models/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChappIO%2Fdirectus-extension-models/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChappIO%2Fdirectus-extension-models/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChappIO","download_url":"https://codeload.github.com/ChappIO/directus-extension-models/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252801214,"owners_count":21806275,"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-10-03T16:19:15.628Z","updated_at":"2025-05-07T02:28:23.692Z","avatar_url":"https://github.com/ChappIO.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Directus extension: Generate TypeScript Types Models\n[![directus-extension-models](https://npmbadge.com/npm/directus-extension-models?mode=yarn)](https://www.npmjs.com/package/directus-extension-models)\n\nThis extension lets you generate typescript types from your Schema, allowing you to more easily develop your custom extensions with type checking.\n\n## Usage\n\nTo install the extension, simply install the package into your project:\n\n```bash\nnpm install directus-extension-models\n```\n\nor\n\n```bash\nyarn add directus-extension-models\n```\n\nThen, run the `models snapshot` command to export your model to disk: `directus models snapshot \u003ctargetFile\u003e`.\n\nExample:\n\n```bash\ndirectus models snapshot ./path/to/target/model.d.ts\n```\n\n\u003e :thumbsup: **Global Types**: You can specify the --global option while taking a snapshot to generate a global\n\u003e type definition file giving you types without having to import them.\n\n### Usage in @directus/sdk\n\nYou can now create your directus sdk using these generated models:\n\n```typescript\nimport {createDirectus, readItem, readSingleton, rest} from \"@directus/sdk\";\nimport {Collections} from \"./models\";\n\nconst directus = createDirectus\u003cCollections\u003e(\n    'https://my.directus.example.com'\n)\n    .with(rest());\n\n(async () =\u003e {\n    const settings = await directus.request(\n        readSingleton('directus_settings')\n    );\n    console.log(`Welcome to ${settings.project_name}`);\n\n    const user = await directus.request(\n        readItem('directus_users', 'user-id-in-here')\n    );\n\n    console.log(`Hi ${user.first_name}!`);\n})();\n```\n\n### Usage in Directus extensions\n\n```typescript\nimport {defineEndpoint} from '@directus/extensions-sdk';\nimport type {CollectionName, ItemIn} from \"../models\";\nimport type {ItemsService} from \"@directus/api/dist/services\";\n\nexport default defineEndpoint((router, {services}) =\u003e {\n    /**\n     * You probably want to move this utility to a place more suitable\n     * for your extension\n     */\n    function items\u003cC extends CollectionName\u003e(collectionName: C): ItemsService\u003cItemIn\u003cC\u003e\u003e {\n        return new services.ItemsService(collectionName);\n    }\n\n    router.get('/', async (_req, res) =\u003e {\n        const settings = await items('directus_settings')\n            .readSingleton({});\n\n        res.json({\n            name: settings.project_name\n        });\n    });\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchappio%2Fdirectus-extension-models","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchappio%2Fdirectus-extension-models","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchappio%2Fdirectus-extension-models/lists"}