Skip to content

Latest commit

 

History

History
67 lines (53 loc) · 3.23 KB

README.md

File metadata and controls

67 lines (53 loc) · 3.23 KB

@hatchifyjs/core

@hatchifyjs/core provides core libraries and types for defining Schemas. Schemas are used by other packages like @hatchifyjs/koa and @hatchifyjs/react to provide low-code-like functionality.

The following defines a SalesPerson schema that has multiple attributes (aka fields) and relationships with other schemas:

import { PartialSchema,
  boolean, datetime, dateonly, integer, string, enumerate
  belongsTo, hasMany, hasOne } from "@hatchifyjs/core"
  
export const SalesPerson = {
  name: "SalesPerson",
  pluralName: "SalesPeople",
  id: uuid({required: true, autoIncrement: true}),
  attributes: {
    name:         string({ required: true }),
    description:  text(),
    hireDate:     datetime(),
    birthday:     dateonly(),
    commission:   number({min: 0}),
    importance:   integer({min: 0, max: 100, step: 10}),
    isSenior:     boolean({ default: false }),
    status:       enumerate({ values: ["active", "inactive"] }),
    salesGroupId: uuid(),
  },
  relationships: {
    salesGroup: belongsTo(),
    accounts:   hasMany(),
    todos:      hasMany().through()
    user:       hasOne()
  },
} satisfies PartialSchema

To learn how to define a schema, we suggest reading:

  • PartialSchema - To understand how to define a schema and how it effects the database, API, and UI.
  • Attributes - How to specify attributes on a schema.
  • Relationships - How to specify relationships on a schema.

Exports

@hatchifyjs/core exports the following types and methods to help you build a schema:

Types:

Attributes:

Relationships: