1.0.11 • Published 5 months ago

cockpit-generate v1.0.11

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

What is cockpit-generate?

cockpit-generate is a tool for generation of a typesafe javascript client to use with Cockpit CMS.

Getting started

The fastest way to get started with cockpit-generate is by following the Quickstart.

Add cockpit-generate to yout project.

npm install cockpit-generate

Add yout API-URL and password to your .env file.

COCKPIT_API_KEY=USR-ddad43036e48261a66asdkljksadl7971626494a2
COCKPIT_API_URL=https://cms.cockpit.com

Now add a config file in the root of your project and add the routes to yout api endpoint

//cockpit.config.cjs
module.exports =  [
  {
    type: "collection",
    name: "tours",
  },
  {
    type: "collection",
    name: "stations",
  },
];

Generate your client file

npx cockpit-generate

How does it work?

During the genertation process the script will fetch data from the provides routes. This data will be converted to type definitions and generate the functions for getting data.

How to use it?

To use it import the generated client file to yout project make some calls to yout api.

import client from "./.cockpit/client";

const allItems = await client.tours.getAll():
const allItemsFiltered = await client.tours.getAll({
  where: {
    keyToLookFor: "valueToLookFor",
  }
}):
const singleItem = await client.tours.get('itemID')

All the response data will have types and autocomplete.

1.0.11

5 months ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago