New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

cockpit-orm

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cockpit-orm

ORM for Cockpit Headless CMS

latest
Source
npmnpm
Version
0.4.0
Version published
Maintainers
1
Created
Source

Cockpit ORM

Create a representations of you collections and entries to manage data without manually fetching the Cockpit API.

npm install cockpit-orm
# or
yarn add cockpit-orm

Entry

The Entry class is for mapping one single entry of a collection.

  • Create a new Entry class by extending Entry.
  • Use the schema given by Cockpit so your local entry knows the collection name and fields.
  • Use a authenticated Cockpt SDK instance that will be called internally.
  • Set an optional slugField to use a handy slug that will identify this Entry instead of _id. When the slugField is undefined the _id field will be used.
import { Entry } from "cockpit-orm";
import schema from "../schemas/Portfolioitems.json";
import cockpit from "../"; // Initiated CockpitSDK instance.

class Post extends Entry {
  static cockpit = cockpit;
  static slugField = "title_slug";
  static schema = {
    // Cockpit collection schema.
    name: "post",
    fields: [{ name: "title", options: { slug: true } }, { name: "body" }]
  };
}

Sync new Post by slug.

async () => {
  const post = new Post();

  post.setSlug("hello-work");

  await post.sync(); // Fetches cockpit and fill all other fields.

  post.get("title");
  post.get("body");
};

Add new entry.

const post = new Post({ title: "Hello" });

post.get("title"); // Hello
post.has("body"); // false

post.save(); // POST to cockpit

Update entry.

async () => {
  const post = new Post();

  post.setSlug("hello-work");

  await post.sync(); // Fetches cockpit and fill all other fields.

  post.set("title", "New title");
  post.set("body", "New body");

  await post.save(); // POST to cockpit
};

Collection

The Collection class is for fetching the whole collection entries.

import { Collection } from "cockpit-orm";
import Entry from "./Entry";
import cockpit from "../"; // Initiated CockpitSDK instance.

export default class PostCollection extends Collection {
  static collectionName = "Posts";
  static slugField = "title_slug";
  static cockpit = cockpit;
}

Get entries

const posts = new PostCollection();

const entries = posts.getEntries();

Custom methods

export default class PostCollection extends Collection {
  //...

  getPublished(fields) {
    return this.getObject(fields, { filter: { published: true } });
  }
}

const entries = new PostCollection().getPublished();

Keywords

cockpit

FAQs

Package last updated on 24 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts