microcms-typescript

1.0.14 • Public • Published

microcms-typescript

description

Convert MicroCMS schema to TypeScript type definitions.

usage

microcms-typescript src-dir [dist-file]

Use the file name as the type name.
If there are multiple schema files with the same type name, the one with the latest date will be used for conversion.

For output types

api-contents-20210905132840.json -> cms-types.ts

{
  "apiFields": [
    {
      "idValue": "g8ZUm5uLha",
      "fieldId": "title",
      "name": "title",
      "kind": "text",
      "required": true,
      "isUnique": false
    },
    { "fieldId": "visible", "name": "visible", "kind": "boolean", "required": true },
    { "fieldId": "keyword", "name": "keyword", "kind": "textArea" },
    { "fieldId": "parent", "name": "parent", "kind": "relation" },
    { "fieldId": "body", "name": "body", "kind": "textArea" }
  ],
  "customFields": []
}
import type { EndPoints } from './cms-types';

let a:EndPoints["gets"]["contents"];
/*
{
    limit:number
    offset:number
    totalCount:number
    contents:{
        id: string;
        title: string;
        visible: boolean;
        keyword?: string;
        parent?: string;
        body?: string;
        createdAt: string;
        updatedAt: string;
        publishedAt: string;
        revisedAt: string;
    }[]
}
*/

let b:EndPoints["get"]["contents"];
/*
{
    id: string;
    title: string;
    visible: boolean;
    keyword?: string;
    parent?: string;
    body?: string;
    createdAt: string;
    updatedAt: string;
    publishedAt: string;
    revisedAt: string;
}
*/

let c:EndPoints["post"]["contents"];
let d:EndPoints["put"]["contents"];
/*
{
    title: string;
    visible: boolean;
    keyword?: string;
    parent?: string;
    body?: string;
    createdAt?: string;
    updatedAt?: string;
    publishedAt?: string;
    revisedAt?: string;
}
*/

let e:EndPoints["patch"]["contents"];
/*
{
    title?: string;
    visible?: boolean;
    keyword?: string;
    parent?: string;
    body?: string;
    createdAt?: string;
    updatedAt?: string;
    publishedAt?: string;
    revisedAt?: string;
}
*/

Readme

Keywords

Package Sidebar

Install

npm i microcms-typescript

Weekly Downloads

352

Version

1.0.14

License

MIT

Unpacked Size

8.65 kB

Total Files

4

Last publish

Collaborators

  • sora_kumo