simpleworkjs
v0.2.5
Published
The SimpleWorkJS framework — one install for the model-first ORM, identity/RBAC, Express/Socket.IO backend, browser assets, and CLI.
Maintainers
Readme
simpleworkjs
The SimpleWorkJS framework behind a single
install. Instead of wiring up the individual packages, depend on simpleworkjs
and get the model-first ORM, identity/RBAC, the Express/Socket.IO backend, the
browser assets, and the simpleworks CLI — all pinned to a known-good set.
npm install simpleworkjsOne version to track.
[email protected]bundles compatible versions of@simpleworkjs/orm,@simpleworkjs/orm-identity,@simpleworkjs/backend,@simpleworkjs/frontend, and@simpleworkjs/conf. You can still install those packages directly if you want finer control — this is a convenience facade, not a replacement.
Usage
// app.js
const {backend, conf} = require('simpleworkjs');
const models = require('./models');
backend({conf, models}).start();// models/Task.js
const {Model} = require('simpleworkjs');
class Task extends Model {
static fields = {
id: {type: 'uuid', primaryKey: true},
title: {type: 'string', isRequired: true},
done: {type: 'boolean', default: false},
createdBy: {type: 'hasOne', model: 'User'},
};
static permissions = {
read: ['user'],
create: ['admin'],
update: ['admin', 'owner'],
delete: ['admin'],
};
}
module.exports = Task;What's exported
require('simpleworkjs') gives you one object:
| Export | From | What it is |
|--------|------|------------|
| backend | @simpleworkjs/backend | The server factory — backend({conf, models}).start(). |
| Model, ORM, fields, adapters, init | @simpleworkjs/orm-identity | The model-first ORM API. |
| identity | @simpleworkjs/orm-identity | Built-in User/Group/Role/Permission/AuthToken models. |
| auth | @simpleworkjs/orm-identity | Login, token, and permission-middleware helpers. |
| frontend | @simpleworkjs/frontend | Browser asset path helpers (.assets). |
| conf | @simpleworkjs/conf | The loaded config (see note below). |
The Model you get is the same class the backend uses internally, so
instanceof and model registration behave correctly.
conf is loaded lazily
@simpleworkjs/conf reads your app's conf/ directory (from the working
directory) the moment it's required, and exits if a required config file is
missing. To keep require('simpleworkjs') free of side effects, conf is a
lazy getter — it loads on first access (simpleworkjs.conf), exactly as
require('@simpleworkjs/conf') would.
CLI
The simpleworks CLI is available without a separate install:
npx simpleworks generate my-app
npx simpleworks orm:migrate
npx simpleworks start
npx simpleworks helpIt delegates to @simpleworkjs/backend's command runner — see the
backend CLI docs.
A note on the uuid override
Sequelize bundles an older uuid. Because npm overrides only apply at the
root of an install, add this to your app's package.json (not just rely on
the framework's) so the transitive copy is forced up:
{
"overrides": {
"uuid": "^11.1.1"
}
}npx simpleworks generate scaffolds this for you.
Related packages
@simpleworkjs/orm— base ORM.@simpleworkjs/orm-identity— identity/RBAC.@simpleworkjs/backend— server framework + CLI.@simpleworkjs/frontend— browser assets.@simpleworkjs/conf— configuration loader.demo-todo— runnable golden-path starter.
License
MIT
