generateDataTypes()

Description

Generate Typescript Interfaces for your database and save them in a specified path in your local directory.

Use Cases

You can use this feature to make your development easier by generating database tables interfaces for your Typescript projects. Most likely, you won't need to use this during the runtime, but as a one-time script in your package.json. To implement it:

  1. Create a file deskree-interfaces.ts that will instantiate Deskree Client together with a Deskree Admin Token:

    import createClient from '@deskree/deskree-js'
    import axios from 'axios'
    
    const options = {
      projectId: "YOUR_PROJECT_ID",
      axios: axios,
      adminToken: "YOUR_DESKREE_ADMIN_TOKEN"
    }
    
    const client = createClient(options);
    client.config().generateDataTypes({path: "./src/interfaces", name: "deskree.types.ts"})

    DANGER: Always keep your Deskree Admin token secure as it is a very powerful token that may allow unwanted access to your data if compromised. If you believe that is the case, you can always refresh your to

  2. In your package.json "scripts" object, create a script that will execute the deskree-interfaces.ts file. The script depends on your typescript configuration and file location. Example:

    "scripts": {
        "deskree-interfaces": "tsc && node lib/src/deskree-interfaces.js"
    }

    Or you can use packages like TS Node to run typescript files directly. For more information, visit.

    "scripts": {
        "deskree-interfaces": "npx ts-node /src/deskree-interfaces.ts"
    }
  3. Run the newly created script in your console: npm run deskree-interfaces

  4. The interfaces file should appear in the specified directory for you to use throughout your project.

Request

Parameters

FieldRequiredData TypeDescription

options

Object

Options Object describing filtering, sorting, and other options

Options Object Parameters

FieldRequiredData TypeDescription

database

default

Currently accepts only "default" value, but with multiple databases per project feature coming soon, it will be accepting the name of the database to extract the configs from. Default: "default"

path

string

Relative path where typescript interfaces should be saved. Should always end with / Example: ./src/interfaces/

Default: will save the file in the same directory where the method is executed.

fileName

`string`

File name of the interfaces. Default: deskree-types.interface.ts

Example

await client.config().generateDataTypes({
    database: "default",
    path: "../interfaces"
})

Response

Creates Typescript Interface file in the specified path.

Example

export type UsersDataType = {
	roles: string[]
	uid: string
	email: string
	createdAt?: string
	updatedAt?: string
}

export type BooksDataType = {
	uid: string
	name: string
	arrayOfBooleans?: boolean[]
	updatedAt?: string
	author?: string
	arrayOfInt?: number[]
	arrayOfStrings?: string[]
	arrayOfFloats?: number[]
	createdAt?: string
	image?: string
}

Last updated

Copyright © 2023 Deskree Technologies Inc.