1.0.14 • Published 1 year ago

microcms-typescript v1.0.14

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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;
}
*/
1.0.14

1 year ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.9

3 years ago

1.0.10

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago