3.4.2 • Published 4 years ago

melodi-data v3.4.2

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

melodi-data Build Status

Data models, common logic, boilerplate, etc. stored here

Get Started

Environment variables

The following environment variables must be set wherever this package is used, and they will be in the dependent project via an import:

const config = require('melodi-data').config;

let port = config.PORT; // the value of "PORT" in the dependent project's .env file
Environment variableDescriptionExample value
BEDCONTROL_MONGO_URLThe URL to the MongoDB instance you'd like to use, appended with the Bed Control database name.mongodb://localhost:27017/bedcontrol
AGENDA_MONGO_URLThe URL to the MongoDB instance you'd like to use, appended with the Agenda database name.mongodb://localhost:27017/melodi-data
IQD_MONGO_URLThe URL to the MongoDB instance you'd like to use, appended with the IQ Dashboard database name.mongodb://localhost:27017/iqd
USERS_MONGO_URLThe URL to the MongoDB instance you'd like to use, appended with the Users database name.mongodb://localhost:27017/users
DOMAINThe domain of the server. Used to construct URLs.localhost
PORTThe port at which to run this service.3456
JWT_SECRETThe JWT secret through which passwords are verified.shh
JWT_EXPIRES_INThe duration of time the JWT should be valid after creation. Values must conform to the specifcation described here: https://github.com/auth0/node-jsonwebtoken#jwtsignpayload-secretorprivatekey-options-callback1 week
RABBITMQ_HOSTThe hostname of the RabbitMQ instancelocalhost
RABBITMQ_PORTThe port of the RabbitMQ instance5672
BYPASS_AUTHBypasses all authentication/authorization checks. Good for testing GraphQL queries.false
PUBLISH_SERVER_ERRORSPublishes errors messages from the server to the client through GraphQL.false
AD_LDAP_URLActive Directory server URLldap://example.org/ldap
AD_BASE_DNActive Directory domaindc=org
AD_USERNAMEActive Directory usernameroot
AD_PASSWORDActive Directory passwordpass

Contributing

This package contains most of the data models required for the Melodi ecosystem, as well as a few other minor utilities. It's a centralized location for boilerplate stuff every individual application might need.

Directory Structure

  • src/ – contains all source files

    • models/ – contains data models that are used across applications

      Each model should have its own directory with at least some of the following files:

      • model.js – Defines the Mongoose schema/model and exports the Mongoose model.
      • schema.js – Defines and exports the GraphQL type for the model. The GraphQL schema is dynamically created from the Mongoose model using mongoose-graphql in most cases.
      • resolvers.js – Defines and exports the necessary GraphQL resolvers for the model.
      • index.js – Export the model, schema, and resolvers in one object, so imports can look like:

        const Bed = require('./models/bed/'); // from /src/index.js
        // Bed is { model, resolvers, schema }
    • config.js – Defines and exports common environment configuration variables. (AD creds, MongoDB URLs, etc.)

    • index.js – Exports all models and utilities that should be available to dependent projects.
  • test/ – contains tests for each models and utility

  • server.js – Starts a GraphQL server with all the GraphQL types in this module for development purposes. DO NOT USE THIS IN PRODUCTION

Testing

Use the following scripts in package.json to run the tests.

Running tests

  • yarn run jest runs all Jest tests.
  • yarn run jest:watch runs all Jest tests, watching for test file changes.

Coverage

  • yarn run jest:coverage runs all Jest tests and generates a test coverage report. An HTML coverage report will be generated here: /coverage/lcov_report/index.html

Documentation

  • yarn generate-docs will create a static HTML website based on the JSDoc content within source files. The output directory is docs/.
  • yarn generate-docs:watch will watch for changes in src/ and regenerate the site when changes are made.

After you've generated the HTML content ind docs/, you can view it locally by opening docs/melodi-data/<version>/index.html in a web browser.

Releasing

Zeit's release tool is included as a dev dependency in this repo. It will automatically create a tagged commit with the versions bumped appropriately.

Release Types

  • Major (breaking) - any breaking changes.
    • Removing stuff from the GraphQL schema
    • Changing export names/locations
  • Minor (feature) - non-destructive feature additions.
    • Adding fields to a GraphQL schema
    • Adding new module
  • Patch (fix) - fixes to current functionality.
    • Bug fixes
    • Security-related dependency upgrades

When you want to create a release, do the following:

  • Be sure you're on the master branch
  • Run npm run release (you can specify the release type if you wish)
  • That's it

Examples

# Create release, automatically detecting type from commits
npm run release

# Create major release 1.0.0 -> 2.0.0
npm run release major

# Create minor release 1.0.0 -> 1.1.0
npm run release minor

# Create patch release 1.0.0 -> 1.0.1
npm run release path

It can automatically detect the release type

Basically, include the type of changes made in the commit message in parentheses:

git commit -m "Removed some fields from the GraphQL schema (major)"

To exclude a commit from the change list for a release use (ignore).

Read more here: https://github.com/zeit/release#pre-defining-types