Registry / database / cockpit-orm

cockpit-orm

JSON →
library0.4.0jsnpmunverified

An object-relational mapping library for Cockpit Headless CMS (v0.4.0, stable). Provides Entry and Collection classes to manage Cockpit content without manually fetching the Cockpit API. Depends on cockpit-sdk ^0.8.3. Differentiates by offering a schema-driven, class-based ORM pattern similar to ActiveRecord, with features like slug-based syncing, save/update via POST, and custom collection methods. Useful for Node.js and browser environments.

npm install cockpit-orm
INSTALL
IMPORT
SIG · COCKPIT-ORM
C
cockpit-orm
databasejavascriptv0.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Entry
import { Entry } from 'cockpit-orm'
import Entry from 'cockpit-orm'
Named export, not default
Collection
import { Collection } from 'cockpit-orm'
const Collection = require('cockpit-orm').Collection
ESM only; named export
default import
import { Entry, Collection } from 'cockpit-orm'
import cockpitOrm from 'cockpit-orm'
Default export is undefined; use named exports only

Shows how to extend Entry and Collection, sync an entry by slug, and get a field value.

import { Entry, Collection } from 'cockpit-orm'; import cockpit from 'cockpit-sdk'; const cockpitInstance = cockpit({ baseURL: 'https://your-cockpit.com/api', token: process.env.COCKPIT_TOKEN ?? '' }); class Post extends Entry { static cockpit = cockpitInstance; static slugField = 'title_slug'; static schema = { name: 'Posts', fields: [ { name: 'title', type: 'text' }, { name: 'body', type: 'text' }, { name: 'published', type: 'boolean' } ] }; } class PostCollection extends Collection { static collectionName = 'Posts'; static cockpit = cockpitInstance; } const post = new Post(); post.setSlug('my-first-post'); post.sync().then(() => { console.log(post.get('title')); });
Debug
Known issues
breakingJoi validation error when schema does not match cockpit collection exactly
fix
Ensure the static schema matches the Cockpit collection schema verbatim, including field names and types.
affects: >=0.0.0
gotchaEntry.get() returns undefined for fields not synced or set
fix
Always sync() before reading fields, or check has() before get().
affects: >=0.0.0
gotchaEntry.save() does not update existing entries; it always creates a new entry (POST)
fix
Use sync() to fetch existing data, modify, then save() to create a new version. There is no PUT/PATCH support.
affects: >=0.0.0
deprecatedNo deprecations noted in v0.4.0
fix
N/A
affects: 0.4.0
Errors
Common errors & fixes
TypeError: cockpit_orm__WEBPACK_IMPORTED_MODULE_0__ is undefined
Using default import when named exports are required
fix
Replace 'import cockpitOrm from "cockpit-orm"' with 'import { Entry, Collection } from "cockpit-orm"'
Error: "name" is required
Missing static schema.name or schema not provided
fix
Add static schema = { name: 'YourCollectionName', fields: [...] } to the Entry subclass
Cannot read property 'get' of undefined
Trying to call get() on a non-synced Entry or without setting a slug/id
fix
Ensure sync() is called and awaited before get(), or use set() to set fields locally first
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies
cockpit-sdkrequiredPeer dependency required for API calls
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
cockpit-orm — npm install cockpit-orm · libregistry