8.1.0 • Published 4 years ago

jaid-core v8.1.0

Weekly downloads
87
License
-
Repository
github
Last release
4 years ago

jaid-core



Combines jaid-logger, essential-config, got, koa and sequelize.

Installation

npm install --save jaid-core@^8.1.0

yarn add jaid-core@^8.1.0


(if configured properly)

npm install --save @jaid/jaid-core@^8.1.0

Usage

Plugins

These optional plugin properties may be called by jaid-core:

NameParametersReturn value
constructorJaidCore core
setCoreReferenceJaidCore core
getConfigSetupObject additionalConfigSetup
preInitboolean shouldRemovePlugin
handleConfigObject configboolean shouldRemovePlugin
handleKoaKoa koa
handleGotGot got
collectModelsObject<string, {default: Model, schema: Object}>
initboolean shouldRemovePlugin
postInitboolean shouldRemovePlugin
ready
handleLogstring 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 PluginModel

Advanced 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 git@github.com:jaid/jaid-core.git
cd jaid-core
npm install

Testing:

npm run test:dev

Testing in production environment:

npm run test

License

MIT License
Copyright © 2020, Jaid \jaid.jsx@gmail.com (https://github.com/jaid)

8.1.0

4 years ago

8.0.3

4 years ago

8.0.2

4 years ago

8.0.1

4 years ago

8.0.0

4 years ago

7.5.0

4 years ago

7.4.0

4 years ago

7.3.4

4 years ago

7.3.3

4 years ago

7.3.2

4 years ago

7.3.1

4 years ago

7.3.0

4 years ago

7.2.1

4 years ago

7.2.0

4 years ago

7.1.2

4 years ago

7.1.1

4 years ago

7.1.0

4 years ago

7.0.0

4 years ago

6.0.1

4 years ago

6.0.0

4 years ago

5.9.4

4 years ago

5.9.3

4 years ago

5.9.2

4 years ago

5.9.1

4 years ago

5.9.0

4 years ago

5.8.0

4 years ago

5.7.1

4 years ago

5.6.0

4 years ago

5.5.0

5 years ago

5.4.0

5 years ago

5.3.1

5 years ago

5.3.0

5 years ago

5.2.0

5 years ago

5.1.0

5 years ago

5.0.0

5 years ago

4.7.0

5 years ago

4.6.0

5 years ago

4.5.3

5 years ago

4.5.2

5 years ago

4.5.1

5 years ago

4.5.0

5 years ago

4.4.0

5 years ago

4.3.3

5 years ago

4.3.2

5 years ago

4.3.1

5 years ago

4.3.0

5 years ago

4.2.0

5 years ago

4.1.0

5 years ago

4.0.0

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago