jaid-core
v8.1.0
Published
Combines jaid-logger, essential-config, got, koa and sequelize.
Maintainers
Readme
jaid-core
Combines jaid-logger, essential-config, got, koa and sequelize.
Installation
npm install --save jaid-core@^8.1.0yarn add jaid-core@^8.1.0
(if configured properly)
npm install --save @jaid/jaid-core@^8.1.0Usage
Plugins
These optional plugin properties may be called by jaid-core:
Name|Parameters|Return value
---|---|---
constructor|JaidCore core
setCoreReference|JaidCore core
getConfigSetup||Object additionalConfigSetup
preInit||boolean shouldRemovePlugin
handleConfig|Object config|boolean shouldRemovePlugin
handleKoa|Koa koa
handleGot|Got got
collectModels||Object<string, {default: Model, schema: Object}>
init||boolean shouldRemovePlugin
postInit||boolean shouldRemovePlugin
ready|
handleLog|string level, string[] fragments|
JaidCorePlugin
Plugins can inherit from any superclass. When they inherit from JaidCorePlugin, some fields for the instance are automatically set:
.core.logger(has.info,.warn,.error,.debug).config(Object of the loaded config)
Plugin example:
import {JaidCorePlugin} from "jaid-core"
export default class Plugin extends JaidCorePlugin {
constructor(options = {}) {
super()
this.options = {
...options
}
}
ready() {
this.log("Hello!")
}
}Sequelize model example:
import Sequelize from "sequelize"
class PluginModel extends Sequelize.Model {
/**
* @return {string}
*/
getTitle() {
return this.title
}
}
/**
* @type {import("sequelize").ModelAttributes}
*/
export const schema = {
title: {
type: Sequelize.STRING,
allowNull: false
}
}
export default PluginModelAdvanced Sequelize model (dynamically generated):
import Sequelize from "sequelize"
/**
* @param {typeof import("sequelize").Model} Model
* @param {import("jaid-core").ModelDefinitionContext} context
* @return {{default, schema}}
*/
export default (Model, {models}) => {
class AdvancedModel extends Model {
/**
* @param {Object<string, import("sequelize").Model>} models
*/
static associate() {
AdvancedModel.belongsTo(models.AnotherModel, {
foreignKey: {
allowNull: false,
},
})
}
/**
* @return {string}
*/
getTitle() {
return this.title
}
}
/**
* @type {import("sequelize").ModelAttributes}
*/
const schema = {
title: {
type: Sequelize.STRING,
allowNull: false
}
}
return {
default: AdvancedModel,
schema,
}
}Development
Setting up:
git clone [email protected]:jaid/jaid-core.git
cd jaid-core
npm installTesting:
npm run test:devTesting in production environment:
npm run testLicense
MIT License
Copyright © 2020, Jaid <[email protected]> (https://github.com/jaid)
