Git Product home page Git Product logo

nfroidure / knifecycle Goto Github PK

View Code? Open in Web Editor NEW
31.0 3.0 2.0 3.1 MB

Manage your NodeJS processes's lifecycle automatically with an unobtrusive dependency injection implementation.

Home Page: https://insertafter.com/en/blog/unobstrusive_dependency_injection_with_knifecycle.html

License: MIT License

TypeScript 100.00%
javascript dependency-injection-container inversion-of-control nodejs function-decorator handler-functions hacktoberfest

knifecycle's Issues

Remove methods and export decorators

The $.constant,$.service,$.initializer methods can be replaced by coupling $.register and initializer, service, constant decorators that would make it more composable and flexible.

Use `$inject` as a prop on providers

Feature description

Instead of using $.depends which is a function, it is maybe better to use $inject since it is more known and may be more understood.

It will introduce breaking changes.

Use cases

I often end up creating files that exports a function like this which introduce a lot of boilerplate only to allow customizing services/deps name:

module.exports = initDBService;

function initDBService($, name='db', dependencies=['ENV']) {
  return $.service(name, $depends(dbService));
}

function dbService({ ENV }) {
/// actual service code
}

Which is later used like this:

import initDBService from 'db';
import $ from 'knifecycle/instance';

initDBService($);

It would be more concise to do this:

module.exports = dbService;

dbService.$inject = ['ENV'];

function dbService({ ENV }) {
/// actual service code
}

And use it that way:

import dbService from 'db';
import $ from 'knifecycle/instance';

$.service('db', dbService);

// Optionnally change deps
const customDBService = dbService.bind();
customDBService.$inject = ['CONFIG:ENV'];
$.service('customDB', customDBService);

The only con is that some people could forget the bind and this would create some weird behaviors.

  • I will do it

Better service mapping symbol?

Currently the mapping symbol is :. It unfortunately do not tells the direction in which the map takes places leading to constant lookup of the doc.

Maybe that > would be a better fit ?

This would be a breaking change so will wait the 2.0.0 version to do so.

An in-range update of browserify is breaking the build 🚨

The devDependency browserify was updated from 16.2.3 to 16.3.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

browserify is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 8 commits.

  • 9824fae 16.3.0
  • 9e3397b Add http2 to builtins (#1913)
  • d2ade25 Add http2 to builtins
  • 876182d Tweak license text so Github detects it correctly
  • 16f82a7 Update license (#1906)
  • 7ad39ce Merge pull request #1139 from insidewarehouse/resolve-exposed-folders
  • f13b713 when a module is exposed, it should still resolve the way it would normally do, i.e. with/without extension and directories should fall back to index, and index from a directory should be accepted with/without extension too
  • 8f80729 Update license

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Optional dependencies

Feature request

Feature description

Allow to flag dependencies as optionnal: ?myOptionnalService

Use cases

Optionnal debugging service, optionnal ENV/CONSTANTS.

[x] I will do it

rootContext?

Follow up to https://twitter.com/nfroidure/status/865478307826946048

This project creates a tight link with the library instead of using the module system and functions while making testing harder. Why not just pass an rootContext down through the functions?

App.js

/**
 * @flow
 */
const AppLogger = require('./AppLogger')
import type { appLogger } from './AppLogger'
const Server = require('./Server')

type rootContext = {
  env: {
    LOGFILE: string,
    PORT: string,
  },
  now: () => number,
  logger: appLogger,
}

const main = async () => {
  if (
    typeof process.env.LOGFILE !== 'string' ||
    typeof process.env.PORT !== 'string'
  ) {
    return
  }
  const rootContext: rootContext = {
    env: process.env,
    now: () => Date.now(),
    logger: AppLogger.make(process.env.LOGFILE),
  }
  const server = await Server.make(rootContext)
}

main()

AppLogger.js

/**
 * @flow
 */
const Logger = require('logger')

export type appLogger = {
  +log: (info: 'info', string: string, ...args: Array<number | string>) => void,
}

exports.make = (outPath: string) => Logger.createLogger(outPath)

GetTimeRoute.js

/**
 * @flow
 */
import type { appLogger } from './AppLogger'

type rootContext = {
  +now: () => number,
  +logger: appLogger,
}

exports.make = (rootContext: rootContext) => (
  req: express$Request,
  res: express$Response,
  next: express$NextFunction
) => {
  const currentTime = rootContext.now()
  rootContext.logger.log('info', 'Sending the current time:', currentTime)
  res.status(200).end(String(currentTime))
}

Server.js

/**
 * @flow
 */
const express = require('express')
const GetTimeRoute = require('./GetTimeRoute')
import type { appLogger } from './AppLogger'

type rootContext = {
  +env: {
    +PORT: string,
  },
  +now: () => number,
  +logger: appLogger,
}

exports.make = async (rootContext: rootContext) => {
  const app = express()
  app.get('/time', GetTimeRoute.make(rootContext))
  const server = await new Promise(resolve =>
    app.listen(rootContext.env.PORT, resolve)
  )
  rootContext.logger.log(
    'info',
    'server listening on port ' + rootContext.env.PORT + '!'
  )
  return server
}

Document `$*` internal services types

The $inject, $shutdown, $dispose, $autoload and $instance internal services should be documented and their interface should be specified in the types definitions.

Better naming

Some bad naming choices were made, the 2.0.0 breaking changes is a good occasion to bring better names:

  • $shutdown would be better named $dispose
  • $shutdownAll would be better named $destroy
  • $fatalError should be renamed $fatalErrorPromise

An in-range update of babel7 is breaking the build 🚨

There have been updates to the babel7 monorepo:

    • The devDependency @babel/cli was updated from 7.1.0 to 7.1.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.

babel7 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

`$injector` should accept flags

Would be nice to allow to specify that the injector is used in singleton context to avoid loading non-singletons into singletons.

An in-range update of jsdoc-to-markdown is breaking the build 🚨

Version 3.0.1 of jsdoc-to-markdown was just published.

Branch Build failing 🚨
Dependency jsdoc-to-markdown
Current Version 3.0.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

jsdoc-to-markdown is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • dependency-ci Dependencies checked Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 5 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Rethink handler auto detection

Currently the handler util uses autoInject and autoName under the hood but it may be a mistake. Indeed, if we use Babel to replace auto-detections by their raw usage for perf reasons, we could use autoHandler and replace those calls with handler ones.

Such Babel transformation would change this:

import { autoHandler } from 'knifecycle';

export default autoHandler(async getUser({ db }, { userId})) {});

into

import { handler } from 'knifecycle';

export default handler('getUser', ['user'], async getUser({ db }, { userId})) {})

leading to better performances since handler would not attempt any auto-detection then.

An in-range update of metapak is breaking the build 🚨

The devDependency metapak was updated from 3.1.1 to 3.1.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

metapak is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 2 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Add a special property for extra infos

Feature description

Currently adding extra infos can be done by adding properties to functions
but it won't be replicated by the various helpers Knifecyle provides.

For that matter, creating an _extra special props could lead to more flexibility.

Use cases

For example, in my Swagger HTTP Router
project, I could add extra informations like OAuth roles, CORS etc... to handlers so that
the router initialisation could reuse it to add some additionnel logic on their basis.

  • I will/have implement the feature

An in-range update of sinon is breaking the build 🚨

The devDependency sinon was updated from 7.3.0 to 7.3.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

sinon is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 6 commits.

  • 3812a7d Update docs/changelog.md and set new release id in docs/_config.yml
  • 93bef55 Add release documentation for v7.3.1
  • e02c192 7.3.1
  • 8ee1d35 Update CHANGELOG.md and AUTHORS for new release
  • bc53d82 Fix security issues
  • 1a09166 Update @sinonjs/samsam to v3.3.1

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of eslint-plugin-prettier is breaking the build 🚨

The devDependency eslint-plugin-prettier was updated from 3.0.1 to 3.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-plugin-prettier is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 38 commits.

  • bb521d0 Build: update package.json and changelog for v3.1.0
  • 21fa69a New: Allow options to be passed to prettier.getFileInfo (#187)
  • bb597e1 build(deps-dev): bump eslint-plugin-eslint-plugin from 2.0.1 to 2.1.0
  • 0bb7c1d build(deps-dev): bump eslint-config-prettier from 4.1.0 to 4.2.0
  • 2f77df4 build(deps-dev): bump vue-eslint-parser from 6.0.3 to 6.0.4
  • 222b87a build(deps-dev): bump mocha from 6.1.3 to 6.1.4
  • 58d8ff8 build(deps-dev): bump prettier from 1.16.4 to 1.17.0
  • e94e56c build(deps-dev): bump mocha from 6.1.2 to 6.1.3
  • c02244b build(deps-dev): bump mocha from 6.1.1 to 6.1.2
  • a9a2e4e build(deps-dev): bump mocha from 6.0.2 to 6.1.1
  • 073c14c build(deps-dev): bump eslint from 5.15.3 to 5.16.0
  • bda931f build(deps-dev): bump eslint from 5.15.2 to 5.15.3
  • 19f53d6 build(deps-dev): bump eslint from 5.15.1 to 5.15.2
  • 34b39de build(deps-dev): bump eslint from 5.15.0 to 5.15.1
  • 13bcc66 build(deps-dev): bump eslint from 5.14.1 to 5.15.0

There are 38 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Create an autoloader?

In order to dynamically load dependencies code, allow to provide an $autoload service to automatically load initializers code could be nice and fit well to embrace SystemJS modules.

An in-range update of metapak-nfroidure is breaking the build 🚨

The devDependency metapak-nfroidure was updated from 7.1.2 to 7.2.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

metapak-nfroidure is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 3 commits.

  • f58a03d 7.2.0
  • c0a2e8e feat(Jest config): Allow to add project roots
  • 82b25b0 chore(Dependencies): Update dependencies

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Do not catch common errors for optional module

This commit do not solves every possible error:
8cfcabd

TypeError for example but maybe more errors ain't throwed back and lead to unexpected behaviors.

Maybe check for a single error code instead of white listing a set of common errors... Options to specify the error codes that should be ignored may be the best solution.

An in-range update of babel7 is breaking the build 🚨

There have been updates to the babel7 monorepo:

    • The devDependency @babel/cli was updated from 7.1.2 to 7.1.5.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.

babel7 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Add an $injector service

$.run(['$inject']).then(({ $inject }) => {
  $inject(['aService']).then(({ aService }) => {
    // Yay!  
  });
});

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml
  • The new Node.js version is in-range for the engines in 1 of your package.json files, so that was left alone

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of karma-browserify is breaking the build 🚨

The devDependency karma-browserify was updated from 6.0.0 to 6.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

karma-browserify is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 4 commits.

  • ee355f5 6.1.0
  • a3ebf22 chore(project): bump dependencies
  • 58f9788 chore(project): replace phantomjs with chrome for testing
  • b2709c3 chore(travis): drop sudo requirement

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of cz-conventional-changelog is breaking the build 🚨

Version 2.1.0 of cz-conventional-changelog was just published.

Branch Build failing 🚨
Dependency cz-conventional-changelog
Current Version 2.0.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

cz-conventional-changelog is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • dependency-ci Dependencies checked Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v2.1.0

<a name"2.1.0">

2.1.0 (2017-10-27)

Features

  • prompt: add confirmation fields + edit for clarity (#58) (d40ac2c5)
Commits

The new version differs by 3 commits.

  • d40ac2c feat(prompt): add confirmation fields + edit for clarity (#58)
  • f7a770e Merge pull request #57 from Epitrochoid/remove-unused-dep
  • 2d1095b Removed unused pad-right dependency

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Create an `handler` decorator

Often having that kind of boilerplate code:

module.exports = initializer({
  name: getMovingDevicesMails.name,
  type: 'service',
  inject: [
    'getMovingDevices',
    'elasticSearch', '?log',
  ],
}, (...args) => Promise.resolve(
  getMovingDevicesMails.bind(null, ...args)
));

That could be simplified like so:

module.exports = handler(getMovingDevicesMails, [
  'getMovingDevices',
  'elasticSearch', '?log',
]);

An in-range update of babel7 is breaking the build 🚨

There have been updates to the babel7 monorepo:

    • The devDependency @babel/cli was updated from 7.1.1 to 7.1.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.

babel7 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Add chaining?

I am not a big fan of chaining features but since Knifecycle is an OOP thing it may make sense to make it methods chainable.

Better debug

Just spend time on debugging the following case:

$.constant('x',  $.depends(['y'], () -> { }));

A simple check for function given to constant with dependencies and a nice error would have saved me some time.

Also, find some time to check bad definitions like this one:

$.service('x',  $.depends(['x'], () -> { }));

Better signature for provider/service

Check for the use case of needing a servicePromise property on service initializers, looks like it doesn't make sense.

Also check for the necessity of having two imbrications of promises for the providers.

Allow to create singleton services

A singleton service instance is available across multiple running silos. It is maintained in a WeakMap in order to avoid spawning multiple instances of a service while ensuring unused services can still be garbage collected.

import { depends, service } from './knifecycle';
import LoggerService from 'logger';

service('logger', depends('stdout', LoggerService), { singleton: true });

Consider checking singleton dependencies are also singletons, not sure it is that important, but with no use case for singleton depending on non-singleton, it may help prevent programming errors.

Export constants that may be useful as `Knifecycle` static properties

Feature description

To be DRY, some knifecycle friendly libs will benefit from those exports while expressing the dependency to Knifecycle in a declarative way.

Use cases

$inject and other $ prefixed props, the optional/mapping symbols, the dependency declaration parser and available errors.

An in-range update of sinon is breaking the build 🚨

The devDependency sinon was updated from 7.2.5 to 7.2.6.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

sinon is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 6 commits.

  • 0468cd4 Update docs/changelog.md and set new release id in docs/_config.yml
  • 7f2c8c2 Add release documentation for v7.2.6
  • 36b99b3 7.2.6
  • 1fc586e Update CHANGELOG.md and AUTHORS for new release
  • c8758fd Upgrade @sinonjs/formatio
  • e24daed Set fake.lastArg to last argument regardless of type

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.