Skip to content

BinPar/directus-typescript-gen

 
 

Repository files navigation

directus-typescript-gen

Dynamically extract typings from a live Directus server and generate TypeScript definition files to be used by the Directus TypeScript SDK!

This enables type-checking, autocompletion, and other TypeScript goodness.

Usage

Use the generator on a running Directus server to generate the TypeScript definitions:

npx directus-typescript-gen --host http://localhost:8055 --email admin@example.com --password <...> --typeName MyCollections --outFile my-collections.d.ts

The generated file will look like:

export interface Article {
  article_id: string;
  title: string;
  body: string;
  publish_date?: string;
}

export interface ArticleAuthor {
  article_id: string;
  author_email: string;
}

export interface Author {
  email: string;
  first_name: string;
  last_name: string;
}

export type MyCollections = {
  article: Article;
  article_author: ArticleAuthor;
  author: Author;
};

Then instantiate the Directus SDK client:

import { Directus } from "@directus/sdk";
import { MyCollections } from "./my-collections.d.ts";

const directus = new Directus<MyCollections>();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 85.1%
  • TypeScript 14.9%