Skip to content

[chore] Merge upstream #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Many Fabrix installations will include some of the following Spools:

## Documentation

See [**fabrix.app/doc**](http://fabrix.app/doc) for complete documentation.
See [**fabrix.app/docs**](http://fabrix.app/docs) for complete documentation.

## More Resources

Expand Down
71 changes: 58 additions & 13 deletions lib/Fabrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { DatastoreSpool } from './common/spools/datastore'
import { SystemSpool } from './common/spools/system'
import { ToolSpool } from './common/spools/tool'
import { MiscSpool } from './common/spools/misc'
import { enumerable } from './common/decorators/enumerable'

// inject Error and Resource types into the global namespace
Core.assignGlobals()
Expand All @@ -30,7 +31,6 @@ export interface FabrixApp {
[key: string]: any
}
export class FabrixApp extends EventEmitter {

private _logger: LoggerProxy
private _env: IEnv
private _pkg: any // IPkg
Expand All @@ -41,10 +41,10 @@ export class FabrixApp extends EventEmitter {
private _spools: {[key: string]: Spool | ServerSpool | ExtensionSpool | DatastoreSpool | SystemSpool | ToolSpool | MiscSpool }
private _resources: string[] = [ ]

public controllers: {[key: string]: any } // FabrixController }
public services: {[key: string]: any } // FabrixService }
public policies: {[key: string]: any } // FabrixPolicy }
public models: {[key: string]: any } // FabrixModel }
public controllers: {[key: string]: FabrixGeneric } // FabrixController }
public services: {[key: string]: FabrixGeneric } // FabrixService }
public policies: {[key: string]: FabrixGeneric } // FabrixPolicy }
public models: {[key: string]: FabrixGeneric } // FabrixModel }
public resolvers: {[key: string]: any } // FabrixResolver }

/**
Expand Down Expand Up @@ -79,14 +79,49 @@ export class FabrixApp extends EventEmitter {

const processEnv = Object.freeze(Object.assign({}, JSON.parse(JSON.stringify(process.env))))

this._logger = new LoggerProxy(this)
this._env = processEnv
this._pkg = app.pkg
this._versions = process.versions
this._config = new Configuration(app.config, processEnv)
this._spools = {}
this._api = app.api
this._fabrix = pkg
Object.defineProperties(this, {
_logger: {
value: new LoggerProxy(this),
enumerable: false
},
_env: {
value: processEnv,
enumerable: false
},
_pkg: {
value: app.pkg,
enumerable: false
},
_versions: {
value: process.versions,
enumerable: false
},
_config: {
value: new Configuration(app.config, processEnv),
enumerable: false
},
_spools: {
value: {},
enumerable: false
},
_api: {
value: app.api,
enumerable: false
},
_fabrix: {
value: pkg,
enumerable: false
}
})

// this._logger = new LoggerProxy(this)
// this._env = processEnv
// this._pkg = app.pkg
// this._versions = process.versions
// this._config = new Configuration(app.config, processEnv)
// this._spools = {}
// this._api = app.api
// this._fabrix = pkg

// Set the max listeners from the config
this.setMaxListeners(this.config.get('main.maxListeners'))
Expand Down Expand Up @@ -137,43 +172,51 @@ export class FabrixApp extends EventEmitter {
this.emit('fabrix:constructed')
}

// @enumerable(false)
get logger () {
return this._logger
}

// @enumerable(false)
get env () {
return this._env
}

// @enumerable(false)
get pkg () {
return this._pkg
}

// @enumerable(false)
get versions () {
return this._versions
}

// @enumerable(false)
get config () {
return this._config
}

/**
* Gets the package.json of the Fabrix module
*/
// @enumerable(false)
get fabrix () {
return this._fabrix
}

/**
* Gets the Spools that have been installed
*/
// @enumerable(false)
get spools () {
return this._spools
}

/**
* Gets the api
*/
// @enumerable(false)
get api () {
return this._api
}
Expand All @@ -182,6 +225,7 @@ export class FabrixApp extends EventEmitter {
* Return the Fabrix logger
* fires fabrix:log:* log events
*/
// @enumerable(false)
get log () {
return this.logger
}
Expand All @@ -199,6 +243,7 @@ export class FabrixApp extends EventEmitter {
/**
* Gets the Api resources that have been set
*/
// @enumerable(false)
get resources() {
return this._resources
}
Expand Down
17 changes: 9 additions & 8 deletions lib/LoggerProxy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FabrixApp } from './'
import { FabrixGeneric } from './common/Generic'

// declare global {
// interface Console {
Expand Down Expand Up @@ -37,18 +38,18 @@ import { FabrixApp } from './'
// (message?: any, ...optionalParams: any[]): void
// }

export class LoggerProxy {
app: FabrixApp
warn
debug
info
error
silly
export class LoggerProxy extends FabrixGeneric {
public app: FabrixApp
public warn
public debug
public info
public error
public silly
/**
* Instantiate Proxy; bind log events to default console.log
*/
constructor (app: FabrixApp) {
this.app = app
super(app)

this.app.on('fabrix:log', (level: string, msg: any[] = [ ]) => (
console[level] || console.log)(level, ...msg)
Expand Down
14 changes: 10 additions & 4 deletions lib/Templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FabrixApp } from './index'

export const Templates = {
hr: '---------------------------------------------------------------',
docs: 'Fabrix Documentation: http://fabrix.app/doc',
docs: 'Fabrix Documentation: https://fabrix.app/docs',

info: {
start: 'Spooling up...',
Expand Down Expand Up @@ -42,16 +42,22 @@ export const Templates = {
silly: {
ready (app: FabrixApp) {
const resources = (app.resources || []).map(resource => {
let prefix = resource.charAt(0).toUpperCase() + resource.slice(1)
let prefix = resource.charAt(0).toUpperCase() + resource.slice(1) + (` (${ Object.keys(app.api[resource]).length })`)
while (prefix.length < 17) { prefix = prefix + ' '}
return `${ prefix } : ${Object.keys(app.api[resource] || {})}`
}).join('\n ')

let apiResourcesLabel = `API Resources (${ (app.resources || []).length })`
while (apiResourcesLabel.length < 18) { apiResourcesLabel = apiResourcesLabel + ' '}

let spoolsLabel = `Spools (${ Object.keys(app.spools || {}).length})`
while (spoolsLabel.length < 18) { spoolsLabel = spoolsLabel + ' '}

return (
` API
API Resources : ${resources ? app.resources : 'NONE INSTALLED'}
${ apiResourcesLabel }: ${resources ? app.resources : 'NONE INSTALLED'}
${ resources }
Spools : ${Object.keys(app.spools || {})}`
${ spoolsLabel }: ${Object.keys(app.spools || {})}`
)
},

Expand Down
13 changes: 4 additions & 9 deletions lib/common/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

import { FabrixApp } from '../index'
import { EventEmitter } from 'events'
import { FabrixGeneric } from './Generic'

/**
* Fabrix Controller Class.
*/
export class FabrixController {
private _app: FabrixApp
export class FabrixController extends FabrixGeneric {
public app: FabrixApp

constructor (app: FabrixApp) {
if (!(app instanceof EventEmitter)) {
throw new Error('The "app" argument must be of type EventEmitter')
}
this._app = app
super(app)
this.app.emit(`controller:${this.id}:constructed`, this)
}

Expand All @@ -26,12 +27,6 @@ export class FabrixController {
}
}

// @enumerable(false)
// @writable(false)
get app(): FabrixApp {
return this._app
}

/**
* Return the id of this controller
*/
Expand Down
18 changes: 17 additions & 1 deletion lib/common/Generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ import { FabrixApp } from '../index'
* Fabrix Generic Class.
*/
export class FabrixGeneric {
public app: FabrixApp
public methods: string[] = []
constructor (app: FabrixApp) {}
constructor (app: FabrixApp) {
Object.defineProperties(this, {
app: {
value: app,
writable: false,
enumerable: false
}
})
}

/**
* Return the id of this controller
*/
get id (): string {
return this.constructor.name.toLowerCase()
}
}
28 changes: 18 additions & 10 deletions lib/common/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,33 @@ import { FabrixResolver } from './'
import { IllegalAccessError } from '../errors'
import { FabrixGeneric } from './Generic'

// export interface FabrixModel {
// new(): FabrixModel
// config(app: FabrixApp, datastore?): {
// [key: string]: any,
// tableName?: string,
// store?: any,
// migrate?: string
// }
// schema(app: FabrixApp, datastore?): {
// [key: string]: any
// }
// resolver(): any
// }

/**
* Fabrix Model Class.
*/
export class FabrixModel extends FabrixGeneric {
private _app: FabrixApp
public app: FabrixApp
private _datastore: any
private _instance: any
private _config: {[key: string]: any}
private _schema: any
private _resolver: any

public store
public migrate
public store: any
public migrate: any

/**
* Model configuration
Expand Down Expand Up @@ -59,23 +72,18 @@ export class FabrixModel extends FabrixGeneric {
* Construct the model and bind the Resolver
*/
constructor (app: FabrixApp, datastore?) {
super(app)

if (!(app instanceof EventEmitter)) {
throw new Error('The "app" argument must be of type EventEmitter')
}
this._app = app

super(app)

this._datastore = datastore

this.resolver = new (<typeof FabrixModel>this.constructor).resolver(this, datastore)
this.app.emit(`model:${this.name}:constructed`, this)
}

get app(): FabrixApp {
return this._app
}

get datastore() {
if (!this._datastore) {
// This will throw an error if the logger is not set yet
Expand Down
9 changes: 1 addition & 8 deletions lib/common/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { FabrixGeneric } from './Generic'
* Fabrix Policy Class.
*/
export class FabrixPolicy extends FabrixGeneric {
private _app: FabrixApp
public app: FabrixApp


/**
Expand All @@ -24,7 +24,6 @@ export class FabrixPolicy extends FabrixGeneric {
if (!(app instanceof EventEmitter)) {
throw new Error('The "app" argument must be of type EventEmitter')
}
this._app = app
this.app.emit(`policy:${this.id}:constructed`, this)
}

Expand All @@ -37,12 +36,6 @@ export class FabrixPolicy extends FabrixGeneric {
}
}

// @enumerable(false)
// @writable(false)
get app(): FabrixApp {
return this._app
}

/**
* Return the id of this policy
*/
Expand Down
Loading