PackagesCoreOverview

@quatrain/core

📦 API Reference: Detailed TypeScript documentation, classes, interfaces, and methods are available in the TypeDoc API Reference for @quatrain/core ↗.

The foundation of the Quatrain framework. This package provides the base components for building business objects and defining data models. It works entirely in-memory and has no persistence dependencies.

Features

  • Base Objects: BaseObject, AbstractObject, DataObject for in-memory object management
  • Built-in Models: User and Entity models with full property definitions
  • Property System: Strongly-typed properties with built-in validation
  • Object URI: A unified resource identification system that works with or without a database
  • Status Management: Built-in lifecycle statuses (created, pending, active, deleted)

Installation

npm install @quatrain/core
# or
yarn add @quatrain/core

Quick Start

Defining a Model

import { BaseObject, StringProperty, NumberProperty } from '@quatrain/core'
 
export class Product extends BaseObject {
   static COLLECTION = 'products'
   static PROPS_DEFINITION = [
      { name: 'name', type: StringProperty.TYPE, mandatory: true },
      { name: 'sku', type: StringProperty.TYPE, mandatory: true },
      { name: 'price', type: NumberProperty.TYPE, defaultValue: 0 },
   ]
}

Creating and Using Objects

const product = await Product.factory()
product._.name = 'My Awesome Product'
product._.sku = 'PROD-001'
product._.price = 29.99
 
console.log(product.isValid()) // true
console.log(product.toJSON()) // { name: 'My Awesome Product', sku: 'PROD-001', price: 29.99 }

Property Types

PropertyDescriptionExample
StringPropertyText valuesNames, descriptions, SKUs
NumberPropertyNumeric valuesPrices, quantities, ages
BooleanPropertyTrue/false valuesFlags, toggles
DateTimePropertyTimestampsCreated dates, due dates
EnumPropertyPredefined optionsStatus, category
ArrayPropertyLists of valuesTags, related items
ObjectPropertyReferences to other objectsAuthor, parent
FilePropertyFile referencesDocuments, images
HashPropertyEncrypted valuesPasswords
MapPropertyKey-value pairsMetadata, settings

Object Lifecycle

Objects follow a standard lifecycle with built-in status management:

created → pending → active → deleted

Access status via object.status and update using object.set('status', statuses.ACTIVE).

Architecture

This package is designed to be the base layer with no external dependencies except logging. For persistence, combine with backend adapters:

  • @quatrain/backend-postgres - PostgreSQL/Supabase
  • @quatrain/backend-firestore - Firebase Firestore
  • @quatrain/backend-sqlite - SQLite

Documentation

For concrete examples and usage guides, please refer to the How-To Guide.

License

AGPL-3.0-only