Skip to content

Commit 05b5ab1

Browse files
authored
Merge pull request #17 from fabrix-app/v1.5
[fix] #11
2 parents 08b7aea + c174fdb commit 05b5ab1

File tree

9 files changed

+76
-34
lines changed

9 files changed

+76
-34
lines changed

lib/Fabrix.ts

+47-12
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ export class FabrixApp extends EventEmitter {
4141
private _spools: {[key: string]: Spool | ServerSpool | ExtensionSpool | DatastoreSpool | SystemSpool | ToolSpool | MiscSpool }
4242
private _resources: string[] = [ ]
4343

44-
public controllers: {[key: string]: any } // FabrixController }
45-
public services: {[key: string]: any } // FabrixService }
46-
public policies: {[key: string]: any } // FabrixPolicy }
47-
public models: {[key: string]: any } // FabrixModel }
44+
public controllers: {[key: string]: FabrixGeneric } // FabrixController }
45+
public services: {[key: string]: FabrixGeneric } // FabrixService }
46+
public policies: {[key: string]: FabrixGeneric } // FabrixPolicy }
47+
public models: {[key: string]: FabrixGeneric } // FabrixModel }
4848
public resolvers: {[key: string]: any } // FabrixResolver }
4949

5050
/**
@@ -79,14 +79,49 @@ export class FabrixApp extends EventEmitter {
7979

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

82-
this._logger = new LoggerProxy(this)
83-
this._env = processEnv
84-
this._pkg = app.pkg
85-
this._versions = process.versions
86-
this._config = new Configuration(app.config, processEnv)
87-
this._spools = {}
88-
this._api = app.api
89-
this._fabrix = pkg
82+
Object.defineProperties(this, {
83+
_logger: {
84+
value: new LoggerProxy(this),
85+
enumerable: false
86+
},
87+
_env: {
88+
value: processEnv,
89+
enumerable: false
90+
},
91+
_pkg: {
92+
value: app.pkg,
93+
enumerable: false
94+
},
95+
_versions: {
96+
value: process.versions,
97+
enumerable: false
98+
},
99+
_config: {
100+
value: new Configuration(app.config, processEnv),
101+
enumerable: false
102+
},
103+
_spools: {
104+
value: {},
105+
enumerable: false
106+
},
107+
_api: {
108+
value: app.api,
109+
enumerable: false
110+
},
111+
_fabrix: {
112+
value: pkg,
113+
enumerable: false
114+
}
115+
})
116+
117+
// this._logger = new LoggerProxy(this)
118+
// this._env = processEnv
119+
// this._pkg = app.pkg
120+
// this._versions = process.versions
121+
// this._config = new Configuration(app.config, processEnv)
122+
// this._spools = {}
123+
// this._api = app.api
124+
// this._fabrix = pkg
90125

91126
// Set the max listeners from the config
92127
this.setMaxListeners(this.config.get('main.maxListeners'))

lib/LoggerProxy.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { FabrixApp } from './'
2+
import { FabrixGeneric } from './common/Generic'
23

34
// declare global {
45
// interface Console {
@@ -37,7 +38,7 @@ import { FabrixApp } from './'
3738
// (message?: any, ...optionalParams: any[]): void
3839
// }
3940

40-
export class LoggerProxy {
41+
export class LoggerProxy extends FabrixGeneric {
4142
public app: FabrixApp
4243
public warn
4344
public debug
@@ -48,13 +49,7 @@ export class LoggerProxy {
4849
* Instantiate Proxy; bind log events to default console.log
4950
*/
5051
constructor (app: FabrixApp) {
51-
Object.defineProperties(this, {
52-
app: {
53-
value: app,
54-
writable: false,
55-
enumerable: false
56-
}
57-
})
52+
super(app)
5853

5954
this.app.on('fabrix:log', (level: string, msg: any[] = [ ]) => (
6055
console[level] || console.log)(level, ...msg)

lib/Templates.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,22 @@ export const Templates = {
4242
silly: {
4343
ready (app: FabrixApp) {
4444
const resources = (app.resources || []).map(resource => {
45-
let prefix = resource.charAt(0).toUpperCase() + resource.slice(1)
45+
let prefix = resource.charAt(0).toUpperCase() + resource.slice(1) + (` (${ Object.keys(app.api[resource]).length })`)
4646
while (prefix.length < 17) { prefix = prefix + ' '}
4747
return `${ prefix } : ${Object.keys(app.api[resource] || {})}`
4848
}).join('\n ')
4949

50+
let apiResourcesLabel = `API Resources (${ (app.resources || []).length })`
51+
while (apiResourcesLabel.length < 18) { apiResourcesLabel = apiResourcesLabel + ' '}
52+
53+
let spoolsLabel = `Spools (${ Object.keys(app.spools || {}).length})`
54+
while (spoolsLabel.length < 18) { spoolsLabel = spoolsLabel + ' '}
55+
5056
return (
5157
` API
52-
API Resources : ${resources ? app.resources : 'NONE INSTALLED'}
58+
${ apiResourcesLabel }: ${resources ? app.resources : 'NONE INSTALLED'}
5359
${ resources }
54-
Spools : ${Object.keys(app.spools || {})}`
60+
${ spoolsLabel }: ${Object.keys(app.spools || {})}`
5561
)
5662
},
5763

lib/common/Generic.ts

+7
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@ export class FabrixGeneric {
1414
}
1515
})
1616
}
17+
18+
/**
19+
* Return the id of this controller
20+
*/
21+
get id (): string {
22+
return this.constructor.name.toLowerCase()
23+
}
1724
}

lib/common/Model.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ export class FabrixModel extends FabrixGeneric {
2929
private _schema: any
3030
private _resolver: any
3131

32-
public store
33-
public migrate
32+
public store: any
33+
public migrate: any
3434

3535
/**
3636
* Model configuration
3737
*/
38-
public static config (app: FabrixApp, datastore?) {
38+
public static config (app: FabrixApp, datastore?): {[key: string]: any} {
3939
return {
4040
tableName: null,
4141
store: null,
@@ -72,12 +72,12 @@ export class FabrixModel extends FabrixGeneric {
7272
* Construct the model and bind the Resolver
7373
*/
7474
constructor (app: FabrixApp, datastore?) {
75-
super(app)
76-
7775
if (!(app instanceof EventEmitter)) {
7876
throw new Error('The "app" argument must be of type EventEmitter')
7977
}
8078

79+
super(app)
80+
8181
this._datastore = datastore
8282

8383
this.resolver = new (<typeof FabrixModel>this.constructor).resolver(this, datastore)

lib/common/spools/datastore.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ export class DatastoreSpool extends Spool {
3131
async initialize (): Promise<any> {
3232
Object.entries(this.app.models).forEach(([ modelName, model ]) => {
3333
const modelConfig = (<typeof FabrixModel>model.constructor).config(this.app, this._datastore)
34-
model.store = modelConfig.store || this.app.config.get('models.defaultStore')
35-
model.migrate = modelConfig.migrate || this.app.config.get('models.migrate') || 'safe'
36-
console.log('INIT STORE', model.store)
34+
Object.assign(model, { store: modelConfig['store'] || this.app.config.get('models.defaultStore')})
35+
Object.assign(model, { migrate: modelConfig['migrate'] || this.app.config.get('models.migrate') || 'safe'})
3736
})
3837
return Promise.resolve()
3938
}

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fabrix/fabrix",
3-
"version": "1.1.5",
3+
"version": "1.5.0",
44
"description": "Strongly Typed Modern Web Application Framework for Node.js",
55
"keywords": [
66
"framework",

test/integration/fabrixapp.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ describe('Fabrix', () => {
556556
})
557557

558558
// https://github.com/fabrix-app/fabrix/issues/11
559-
it.skip('should log itself without failing', (done) => {
559+
it('should log itself without failing', (done) => {
560560
app.log.info(app)
561561
console.log(app)
562562
done()

0 commit comments

Comments
 (0)