Skip to content

Commit

Permalink
Update interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
neolao committed May 27, 2017
1 parent 5cdcc6d commit 8cc3f38
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 84 deletions.
98 changes: 96 additions & 2 deletions interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,110 @@ export interface ContainerInterface
/**
* Get a service definition
*
* @param {String} id Service id
* @return {Definition} Service definition
* @param {String} id Service id
* @return {DefinitionInterface} Service definition
*/
getDefinition(id:string):DefinitionInterface;

/**
* Set a service definition
*
* @param {String} id Service id
* @param {DefinitionInterface} definition Service definition
*/
setDefinition(id:string, definition:DefinitionInterface):void;

/**
* Get service definitions
*
* @return {Map} Definitions
*/
getDefinitions():Map<string, DefinitionInterface>;

/**
* Get service reference
*
* @param {String} id Service id
* @return {ReferenceInterface} Service reference
*/
getReference(id:string):ReferenceInterface;

/**
* Register an instantiated service
*
* @param {String} id Service id
* @param {*} service Service instance
* @return {DefinitionInterface} Serice definition
*/
register(id:string, service:any):DefinitionInterface;

/**
* Add a compiler pass
*
* @param {CompilerPassInterface} compiler Compiler pass
*/
addCompilerPass(compiler:CompilerPassInterface):void;

/**
* Find services ids tagged the specified name
*
* @param {String} tagName Tag name
* @return {Array} Service ids
*/
findTaggedServiceIds(tagName:string):Array<string>;

/**
* Get service instance
*
* @param {String} id Service id
* @return {*} Service instance
*/
get(id:string):*;

/**
* Get service class path
*
* @param {String} id Service id
* @return {String} Service class path
*/
getServiceClassPath(id:string):Generator<*,string,*>;

/**
* Get definition class path
*
* @param {Definition} definition Service definition
* @return {String} Service class path
*/
getDefinitionClassPath(definition:DefinitionInterface):Generator<*,string,*>;

/**
* Build definition instance
*
* @param {Definition} definition Service definition
* @return {*} Service instance
*/
buildInstance(definition:DefinitionInterface):Generator<*,*,*>;

/**
* Resolve a parameter
*
* @param {*} parameter The parameter
* @return {*} The resolved parameter
*/
resolveParameter(parameter:any):Generator<*,*,*>;
}

/**
* Container compiler pass interface
*/
export interface CompilerPassInterface
{
/**
* Process
*
* @param {ContainerInterface} container Container
*/
process(container:ContainerInterface):Generator<*,*,*>;
}


2 changes: 1 addition & 1 deletion lib/Bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ var Bundle = class Bundle {
*loadConfigurationFile(filePath) {
var configuration = (0, _configYaml2.default)(filePath, { encoding: "utf8" });

if (_typeof(configuration.services) !== 'object') {
if (_typeof(configuration.services) !== "object") {
return;
}
for (var serviceId in configuration.services) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/DebugCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var DebugCommand = class DebugCommand {
var id = _ref2[0];
var definition = _ref2[1];

console.info(_safe2.default.green("ID : ") + _safe2.default.bgBlack.cyan("" + definition.getId()));
console.info(_safe2.default.green("ID : ") + _safe2.default.bgBlack.cyan("" + id));
console.info(_safe2.default.green("Class: ") + definition.getClassPath());
console.info("");
}
Expand Down
8 changes: 2 additions & 6 deletions lib/ServiceContainer/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ var _harmonyReflect2 = _interopRequireDefault(_harmonyReflect);

var _isGenerator = require("is-generator");

var _bindGenerator = require("bind-generator");

var _bindGenerator2 = _interopRequireDefault(_bindGenerator);

var _Definition = require("./Definition");

var _Definition2 = _interopRequireDefault(_Definition);
Expand Down Expand Up @@ -84,8 +80,8 @@ var Container = class Container {
}

addCompilerPass(compiler) {
_assert2.default.strictEqual(_typeof(compiler.process), 'function');
_assert2.default.strictEqual(compiler.process.constructor.name, 'GeneratorFunction');
_assert2.default.strictEqual(_typeof(compiler.process), "function");
_assert2.default.strictEqual(compiler.process.constructor.name, "GeneratorFunction");

this.compilers.add(compiler);
}
Expand Down
1 change: 1 addition & 0 deletions lib/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ services:
class: "Command/DebugCommand"
tags:
- { name: "solfege.console.command" }

152 changes: 97 additions & 55 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,61 +1,103 @@
{
"name": "solfegejs-dependency-injection",
"description": "Dependency injection for SolfegeJS",
"version": "1.0.9",
"author": "neolao <contact@neolao.com>",
"repository": "https://github.com/neolao/solfege-bundle-dependency-injection.git",
"license": "MIT",
"files": [
"lib",
"interface.js"
"name": "solfegejs-dependency-injection",
"description": "Dependency injection for SolfegeJS",
"version": "1.0.10",
"author": "neolao <contact@neolao.com>",
"repository": "https://github.com/neolao/solfege-bundle-dependency-injection.git",
"license": "MIT",
"files": [
"lib",
"interface.js"
],
"main": "lib/Bundle.js",
"engines": {
"node": ">= 5"
},
"peerDependencies": {
"solfegejs": "2.x"
},
"dependencies": {
"bind-generator": "^1.0.0",
"co-fs": "^1.2",
"colors": "^1.1",
"config-yaml": "^1.0",
"harmony-reflect": "^1.4",
"is-generator": "^1.0.3"
},
"devDependencies": {
"babel-cli": "^6.7",
"babel-eslint": "^7.2",
"babel-preset-solfege": "^1.0",
"chai": "^3.5",
"co-mocha": "^1.2.0",
"coveralls": "^2.13.1",
"eslint": "^3.19",
"eslint-plugin-flowtype": "^2.33.0",
"eslint-plugin-import": "^2.3",
"eslint-plugin-node": "^4.2",
"flow-bin": "^0.46.0",
"gnomon": "^1.5.0",
"istanbul": "0.4.*",
"jsdoc": "^3.4",
"mocha": "^3.0",
"nyc": "^10.3.2",
"watch": "^1.0.2"
},
"scripts": {
"prepare": "npm run build && npm test",
"test": "mocha --harmony --compilers js:babel-core/register --require co-mocha --recursive --reporter spec --bail",
"coverage": "nyc npm test",
"coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
"flow-stop": "flow stop",
"flow-start": "flow start",
"flow-restart": "flow stop; flow start",
"prebuild": "npm run lint; flow",
"build": "babel --out-dir lib src --copy-files",
"watch": "watch 'echo \"----------\"; npm run build --silent | gnomon --medium=1.0 --high=4.0 --real-time=false' ./src",
"lint": "eslint --ext .js src",
"example-build": "flow; babel --out-dir example/lib example/src --copy-files",
"example-console": "node --harmony example/lib/console.js"
},
"babel": {
"presets": [
"solfege"
],
"main": "lib/Bundle.js",
"engines": {
"node": ">= 5"
"comments": false
},
"eslintConfig": {
"extends": ["eslint:recommended", "plugin:flowtype/recommended"],
"parser": "babel-eslint",
"env": {
"es6": true,
"node": true
},
"peerDependencies": {
"solfegejs": "2.x"
},
"dependencies": {
"bind-generator": "^1.0.0",
"co-fs": "^1.2",
"colors": "^1.1",
"config-yaml": "^1.0",
"harmony-reflect": "^1.4",
"is-generator": "^1.0.3"
},
"devDependencies": {
"babel-cli": "^6.7",
"babel-preset-solfege": "^1.0",
"chai": "^3.5",
"co-mocha": "^1.2.0",
"coveralls": "^2.13.1",
"flow-bin": "^0.46.0",
"gnomon": "^1.5.0",
"istanbul": "0.4.*",
"jsdoc": "^3.4",
"mocha": "^3.0",
"nyc": "^10.3.2",
"watch": "^1.0.2"
},
"scripts": {
"prepare": "npm run build && npm test",
"test": "mocha --harmony --compilers js:babel-core/register --require co-mocha --recursive --reporter spec --bail",
"coverage": "nyc npm test",
"coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
"flow-stop": "flow stop",
"flow-start": "flow start",
"flow-restart": "flow stop; flow start",
"prebuild": "flow",
"build": "babel --out-dir lib src --copy-files",
"watch": "watch 'echo \"----------\"; npm run build --silent | gnomon --medium=1.0 --high=4.0 --real-time=false' ./src",
"example-build": "flow; babel --out-dir example/lib example/src --copy-files",
"example-console": "node --harmony example/lib/console.js"
"plugins": [
"import",
"node",
"flowtype"
],
"parserOptions": {
"ecmaVersion": 7
},
"babel": {
"presets": [
"solfege"
],
"comments": false
"rules": {
"indent": [
"error",
4,
{
"SwitchCase": 1
}
],
"quotes": [
"error",
"double",
{
"avoidEscape": true,
"allowTemplateLiterals": true
}
],
"require-yield": "off",
"no-console": "off",
"flowtype/space-after-type-colon": [2, "never"]
}
}
}
4 changes: 2 additions & 2 deletions src/Bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class Bundle
*
* @param {Application} application Solfege application
*/
*initialize(application:any):*
*initialize(application:any):Generator<void,void,void>
{
this.application = application;

Expand Down Expand Up @@ -127,7 +127,7 @@ export default class Bundle
let configuration = configYaml(filePath, {encoding: "utf8"});

// Parse the services
if (typeof configuration.services !== 'object') {
if (typeof configuration.services !== "object") {
return;
}
for (let serviceId in configuration.services) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/DebugCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default class DebugCommand
console.info(colors.yellow("========"));
console.info("");
for (let [id, definition] of definitions) {
console.info(colors.green("ID : ") + colors.bgBlack.cyan(`${definition.getId()}`));
console.info(colors.green("ID : ") + colors.bgBlack.cyan(`${id}`));
console.info(colors.green("Class: ") + definition.getClassPath());
console.info("");
}
Expand Down
Loading

0 comments on commit 8cc3f38

Please sign in to comment.