Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaid/jaid-core
Combines jaid-logger, essential-config, got, koa and sequelize.
https://github.com/jaid/jaid-core
core framework jaid-core jaid-logger javascript javascript-framework javascript-frameworks js-framework koa lib library orm personal sequelize util utility winston
Last synced: 22 days ago
JSON representation
Combines jaid-logger, essential-config, got, koa and sequelize.
- Host: GitHub
- URL: https://github.com/jaid/jaid-core
- Owner: Jaid
- License: mit
- Created: 2019-07-30T23:27:58.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-05-06T10:21:19.000Z (over 1 year ago)
- Last Synced: 2024-12-20T09:36:18.962Z (27 days ago)
- Topics: core, framework, jaid-core, jaid-logger, javascript, javascript-framework, javascript-frameworks, js-framework, koa, lib, library, orm, personal, sequelize, util, utility, winston
- Language: JavaScript
- Homepage: https://github.com/Jaid/jaid-core
- Size: 9.1 MB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license.txt
Awesome Lists containing this project
README
# jaid-core
**Combines jaid-logger, essential-config, got, koa and sequelize.**
## Installation
```bash
npm install --save jaid-core@^8.2.0
``````bash
yarn add jaid-core@^8.2.0
```
(if [configured properly](https://help.github.com/en/github/managing-packages-with-github-packages/configuring-npm-for-use-with-github-packages))```bash
npm install --save @jaid/jaid-core@^8.2.0
```## Usage
### 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`
`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:
```js
import {JaidCorePlugin} from "jaid-core"export default class Plugin extends JaidCorePlugin {
constructor(options = {}) {
super()
this.options = {
...options
}
}ready() {
this.log("Hello!")
}}
```Sequelize model example:
```js
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):
```js
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} 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:
```bash
git clone [email protected]:jaid/jaid-core.git
cd jaid-core
npm install
```
Testing:
```bash
npm run test:dev
```
Testing in production environment:
```bash
npm run test
```## License
[MIT License](https://raw.githubusercontent.com/jaid/jaid-core/master/license.txt)
Copyright © 2020, Jaid \ (https://github.com/jaid)