Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
linter and default configs
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicBoettger committed Mar 27, 2017
1 parent 6c76522 commit c4499ab
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 260 deletions.
1 change: 0 additions & 1 deletion generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ module.exports = Generator.extend({
writing: function () {
this.destinationRoot(this.props.name);
if (this.props.category === 'core') {
this.props.name = '@molecuel/core';
this.fs.copy(
this.templatePath('_config/_development.json'),
this.destinationPath('config/development.json')
Expand Down
239 changes: 12 additions & 227 deletions generators/app/templates/_core/_Readme.md
Original file line number Diff line number Diff line change
@@ -1,227 +1,12 @@
[![Build Status](https://travis-ci.org/molecuel/core.svg?branch=master)](https://travis-ci.org/molecuel/core)
[![Coverage Status](https://coveralls.io/repos/github/molecuel/core/badge.svg?branch=master)](https://coveralls.io/github/molecuel/core?branch=master)

# Core module for molecuel Framework

@molecuel/core is the core module for the molecuel application framework. It's initialization is based on the @molecuel/di Typescript dependency injection module.

The version 2.x branch supports Subjects and streams based on rxjs.
Streams can be used as DataStreams. For example for save handlers and much more. The streams in this case works like a queue of handlers for a dataset.
Subjects can be used as EventEmitters (but should not be used too much).

The core module is initialized as real Singleton based on the dependency injection module.


## Registering data functions<a name="regdatafunc"></a>

Data functions are very important for a typical molecuel application. They are async and can be registered to be executed by various modules. For example a http or socket module can use a registered data function to return data from a datbase.
The routes can be registered in the configuration.
If the http module (for example) has a configured route which points to a @dataRead function it creates a app.get route from it and the return value of the registered function will be returned via http.

Data Decorator provided by the core module:
@dataRead - Tags a data function for reading data
@dataCreate - Tags a data function for creating data
@dataUpdate - Tags a data function for updating data
@dataReplace - Tags a data function for replacing data. This is for example used by HTTP Put request which know the exact URI.
@dataDelete - Tags a data function for deleting data
@mapDataParams - Maps request parameters to the data function and specifies limits and type for parameters to enhance security.

Example for a tagged class:

```js
import {di, injectable} from '@molecuel/di';
import {MlclCore, dataRead, dataCreate, dataUpdate, dataDelete, mapDataParams} from '../dist';

@injectable
class MyDataFunctionClass {
@dataCreate()
public myDataCreaCheck() {
return true;
}
@dataUpdate()
public myDataUpdateCheck() {
return true;
}
@dataDelete()
public async myDataDeleteCheck() {
return true;
}
@mapDataParams([
new MlclDataParam('id', 'id', 'integer', 999),
new MlclDataParam('test', 'name', 'string', 10)
])
@dataRead()
public async myDataReadCheck(id: number, name: string) {
return {
data: (id + ' = "' + name+'"')
};
}
}
di.bootstrap(MlclCore);
```

### Init system

The init system is based on the stream feature of molecuel core described below but can be combined with a method decorator on a injectable class to set different init methods.

For example database initialization can have a higher priority ( lower init value ) or port listen directives can have higher priorities.

The code example show how it works internally ( this can be used by every molecuel module and this is just example code). For example a http module can have two or more init functions. The first to initialize the routes and the second one to add the port listener after some other init priorities have been initialized.

```js
import {di, injectable} from '@molecuel/di';
import {Observable} from '@reactivex/rxjs';
import {MlclCore, init} from '../dist';
di.bootstrap(MlclCore);
let core = di.getInstance('MlclCore');
let obs1Success;
let obs2Success;
// this is normally part of a module and can be added via imports
@injectable
class MyInitTestClass {
// sets the init priority to 20
@init(20)
public myinit(x) {
return Observable.create(y => {
setTimeout(function() {
if(obs2Success) {
obs1Success = true;
console.log('huhu');
y.next(x);
} else {
y.error(new Error('Wrong priority'));
}
y.complete();
}, 100);
});
}
}
// this is normally part of a module and can be added via imports
@injectable
class MyInitTestClass2 {
// sets the init priority to 10
@init(50)
public myini2t(x) {
return Observable.create(y => {
setTimeout(function() {
if(!obs1Success) {
obs2Success = true;
console.log('here');
y.next(x);
} else {
y.error(new Error('Wrong priority'));
}
y.complete();
}, 100);
});
}
}
let mlclInit = async () => core.init();
mlclInit();
// alternative init with promise
// this is the important part to run the complete init stream of the molecuel framework
/*core.init().then(function() {
console.log('cherr');
});*/
```


### Subject example

```js
import {di} from 'mlcl_di';
import {Subject, Observable} from '@reactivex/rxjs';
import {MlclCore, MlclMessage} from '../dist';
di.bootstrap(MlclCore);
let core = di.getInstance('MlclCore')
let initSubject = core.createSubject('init');
initSubject.subscribe(function(msg: MlclMessage) {
console.log(msg);
});
let msg = new MlclMessage();
msg.topic= 'test';
msg.message = 'hello world';
initSubject.next(msg);
```

### Stream example
```js
import {di} from 'mlcl_di';
import {Subject, Observable} from '@reactivex/rxjs';
import {MlclCore, MlclStream} from '../dist';
di.bootstrap(MlclCore);
let core = di.getInstance('MlclCore')
let testStream = core.createStream('teststream');
let obs1 = x=> Observable.create(y => {
setTimeout(function() {
if(obs2Success) {
obs1Success = true;
y.next(x);
} else {
y.error(new Error('Wrong priority'));
}
y.complete();
}, 100);
});

let obs2 = x => Observable.create(y => {
setTimeout(function() {
if(!obs1Success) {
obs2Success = true;
x.firstname = 'Dominic2';
y.next(x);
} else {
y.error(new Error('Wrong priority'));
}
y.complete();
}, 500);
});
testStream.addObserverFactory(obs1, 50);
testStream.addObserverFactory(obs2, 10);

let myobs = Observable.from([{firstname: 'Dominic'}]);
myobs = testStream.renderStream(myobs);
myobs.subscribe(function(res) {
console.log('got result');
}, function(err) {
should.not.exist(err);
}, function() {
console.log('execution of all observables completed');
});
```

## Config handling

The default config will be searched in the current working directory of the process in the config subfolder. If no NODE_ENV variable is set the development.json will be used.
It's possible to override the configpath via environment variables.

configpath is the path and will be combined with the NODE_ENV.
configfilepath is the full path to a json configuration.

```js
import {di} from 'mlcl_di';
import {MlclConfig} from '../dist';

let config = di.getInstance('MlclConfig');
// returns the whole configuration
config.getConfig();
// returns a dot notated path
config.getConfig('database.url');
```

## Parameter handling

To handle parsing of an object with parameters for use in any registered function (cf. [Registering data functions](#regdatafunc)), use the core's renderDataParams method which returns an array of values to supply said function with, according to previously defined mapping.

```js
import {di} from 'mlcl_di';

let core = di.getInstance('MlclCore');
let functionParams = core.renderDataParams({id: '500', test: 'Hello!'}, 'MyDataFunctionClass', 'myDataReadCheck');
let functionResult = await (di.getInstance('MyDataFunctionClass').myDataReadCheck(...functionParams));

```

## API Documentation

The current API Documentation can be found on <https://molecuel.github.io/core/>
# @molecuel/<%= name %> [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage percentage][coveralls-image]][coveralls-url]

<%= name %>

[npm-image]: https://badge.fury.io/js/%40molecuel%2F<%= name %>.svg
[npm-url]: https://npmjs.org/package/@molecuel/<%= name %>
[travis-image]: https://travis-ci.org/molecuel/<%= name %>.svg?branch=master
[travis-url]: https://travis-ci.org/molecuel/<%= name %>
[daviddm-image]: https://david-dm.org/molecuel/<%= name %>.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/molecuel/<%= name %>
[coveralls-image]: https://coveralls.io/repos/molecuel/<%= name %>/badge.svg
[coveralls-url]: https://coveralls.io/r/molecuel/<%= name %>
50 changes: 23 additions & 27 deletions generators/app/templates/_core/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,51 @@
"description": "Core module for molecuel Application framework",
"main": "dist/index.js",
"scripts": {
"test": "mocha",
"start": "node dist/index.js",
"tslint": "./node_modules/.bin/tslint --project tsconfig.json",
"tslint_test": "./node_modules/.bin/tslint --project tsconfig.test.json",
"ts": "./node_modules/.bin/tsc -p .",
"ts_test": "./node_modules/.bin/tsc -p tsconfig.test.json",
"build": "npm run tslint && npm run ts",
"build_test": "npm run tslint_test && npm run ts_test",
"build_all": "npm run build && npm run build_test",
"mocha": "./node_modules/.bin/mocha",
"test": "npm run ts_test && npm run mocha",
"cover": "istanbul cover ./node_modules/mocha/bin/_mocha && npm run remap && npm run remaphtml && npm run remaplcov",
"remap": "./node_modules/.bin/remap-istanbul -i coverage/coverage.json -o coverage/coverage-remap.json",
"remaphtml": "./node_modules/.bin/remap-istanbul -i coverage/coverage.json -o coverage/html -t html",
"remaplcov": "./node_modules/.bin/remap-istanbul -i coverage/coverage.json -o coverage/lcov-remap.info -t lcovonly",
"coveralls": "npm run cover && cat ./coverage/lcov-remap.info | coveralls"
"coveralls": "npm run cover && cat ./coverage/lcov-remap.info | coveralls",
"createdoc": "./node_modules/.bin/typedoc --gaID <%= gaid %> --out ./docs --target es6 --mode file --ignoreCompilerErrors",
"publishdocs": "./node_modules/.bin/gh-pages -d docs",
"docs": "npm run createdoc && npm run publishdocs",
"2npm": "./node_modules/.bin/publish && npm run docs"
},
"keywords": [],
"devDependencies": {
"@types/gulp": "^3.8.32",
"@types/gulp-plumber": "^0.0.29",
"@types/gulp-tslint": "^3.6.30",
"@types/gulp-typescript": "^0.0.32",
"@types/lodash": "^4.14.42",
"@types/merge2": "^0.3.29",
"@types/mocha": "^2.2.33",
"@types/mocha": "^2.2.36",
"@types/should": "^8.1.30",
"@types/when": "^2.4.28",
"assert": ">=0.0.1",
"coveralls": "^2.11.15",
"del": "^2.2.0",
"gulp": "^3.9.1",
"gulp-gh-pages": "^0.5.4",
"gulp-plumber": "^1.1.0",
"gulp-sourcemaps": "^2.2.2",
"gulp-tsconfig-files": "^0.2.5",
"gulp-tslint": "^4.3.2",
"gulp-typedoc": "^2.0.1",
"gulp-typescript": "^3.1.3",
"gulp-util": "^3.0.7",
"gulpclass": "0.0.8",
"gh-pages": "^0.12.0",
"istanbul": "^0.4.5",
"merge2": "^1.0.1",
"mocha": "*",
"mocha-lcov-reporter": "^1.2.0",
"should": ">= 0.0.1",
"tslint": "^3.5.0",
"tslint-stylish": "^2.1.0-beta",
"publish": "^0.6.0",
"remap-istanbul": "^0.9.3",
"should": ">=11.2.0",
"tslint": "^4.4.2",
"typedoc": "^0.5.1",
"typescript": "^2.1.0"
"typescript": "^2.2.1"
},
"dependencies": {
"@molecuel/core": "^2.0.6",
"@molecuel/di": "^0.2.0",
"@reactivex/rxjs": "^5.0.0-rc.5",
"@reactivex/rxjs": "^5.2.0",
"config": "^1.24.0",
"reflect-metadata": "^0.1.3",
"remap-istanbul": "^0.8.4"
"reflect-metadata": "^0.1.3"
},
"devconfig": {
"paths": {
Expand Down
8 changes: 4 additions & 4 deletions generators/app/templates/_src/_index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
import 'reflect-metadata';
import {Observable, Subject} from '@reactivex/rxjs';
import {di, singleton, injectable} from '@molecuel/di';
"use strict";
import "reflect-metadata";
import {Observable, Subject} from "@reactivex/rxjs";
import {di, singleton, injectable} from "@molecuel/di";
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@molecuel/generator-generator",
"version": "0.0.2",
"version": "0.0.3",
"description": "Molecuel generator for core version 2.x",
"homepage": "https://github.com/molecuel/",
"author": {
Expand Down

0 comments on commit c4499ab

Please sign in to comment.