npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

coleslaw

v0.0.2

Published

Coleslaw is a Domain Specific Language (DSL) and related tools, for designing and creating Models.

Downloads

3

Readme

Coleslaw

Coleslaw is a Domain Specific Language (DSL) and related tools, for designing and creating Models.

Installing

$ npm install coleslaw --save

Usage

This library has 2 main apis:

  • Model compilation
  • Model building

The compilation step converts your model code into into model definition objects. Next you pass these model definitions into builders.

This library also contains the main Model builder.

Author a model

// example.cls
model Example {
    field auto id eid: string
    field name: string

    validate eid: uuid
    validate name: alphanum, required

    authorize allow ? update

    child tests: Test // 1:Many relationship with the Test model
}

module.exports = Example

The coleslaw language inherits from ecmascript 5. Which means that it is ecmascript with the addition of the model statement.

Compile your model

During your build process, or at runtime, you can compile a model into javascript which can then be required or eval'd.

var fs = require('fs')
var path = require('path')
var coleslaw = require('coleslaw')

coleslaw.compile(fs.readFileSync(path.join(__dirname, 'example.cls'), 'utf8'), (err, code) => {
    if (err) throw err
    eval(code)
})

The resulting code is a plain javascript object representing the model described. This model can be used by various coleslaw builders.

Build your model definitions into Models

The default model builder can be used to generate Model instances from model defintions. Model instances have standard CRUD (create, retrieve, update, delete) functionality.

model Example {
    field value: string
}

var ExampleModel = coleslaw.build(Example, options) // Example is the model definition
var instance = new ExampleModel({ value: 'test' })  // from an existing object
instance.set('value', 'success')                    // update a field value
instance.save()                                     // Calls dataAccess.update()

In this case we are using the coleslaw.build example to create a Model type from the Example model definition. Next we can create an instance of ExampleModel and do basic CRUD operations. The model keeps track of the state of the object.

Model features

  • fields
  • relationships
  • validation rules
  • authorization rules
  • access rules

Model Builders