Skip to content

Commit 08b7aea

Browse files
committed
[fix] enumerable app, and generics
1 parent ce5b7be commit 08b7aea

10 files changed

+68
-58
lines changed

lib/Fabrix.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { DatastoreSpool } from './common/spools/datastore'
1818
import { SystemSpool } from './common/spools/system'
1919
import { ToolSpool } from './common/spools/tool'
2020
import { MiscSpool } from './common/spools/misc'
21+
import { enumerable } from './common/decorators/enumerable'
2122

2223
// inject Error and Resource types into the global namespace
2324
Core.assignGlobals()
@@ -30,7 +31,6 @@ export interface FabrixApp {
3031
[key: string]: any
3132
}
3233
export class FabrixApp extends EventEmitter {
33-
3434
private _logger: LoggerProxy
3535
private _env: IEnv
3636
private _pkg: any // IPkg
@@ -137,43 +137,51 @@ export class FabrixApp extends EventEmitter {
137137
this.emit('fabrix:constructed')
138138
}
139139

140+
// @enumerable(false)
140141
get logger () {
141142
return this._logger
142143
}
143144

145+
// @enumerable(false)
144146
get env () {
145147
return this._env
146148
}
147149

150+
// @enumerable(false)
148151
get pkg () {
149152
return this._pkg
150153
}
151154

155+
// @enumerable(false)
152156
get versions () {
153157
return this._versions
154158
}
155159

160+
// @enumerable(false)
156161
get config () {
157162
return this._config
158163
}
159164

160165
/**
161166
* Gets the package.json of the Fabrix module
162167
*/
168+
// @enumerable(false)
163169
get fabrix () {
164170
return this._fabrix
165171
}
166172

167173
/**
168174
* Gets the Spools that have been installed
169175
*/
176+
// @enumerable(false)
170177
get spools () {
171178
return this._spools
172179
}
173180

174181
/**
175182
* Gets the api
176183
*/
184+
// @enumerable(false)
177185
get api () {
178186
return this._api
179187
}
@@ -182,6 +190,7 @@ export class FabrixApp extends EventEmitter {
182190
* Return the Fabrix logger
183191
* fires fabrix:log:* log events
184192
*/
193+
// @enumerable(false)
185194
get log () {
186195
return this.logger
187196
}
@@ -199,6 +208,7 @@ export class FabrixApp extends EventEmitter {
199208
/**
200209
* Gets the Api resources that have been set
201210
*/
211+
// @enumerable(false)
202212
get resources() {
203213
return this._resources
204214
}

lib/LoggerProxy.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,23 @@ import { FabrixApp } from './'
3838
// }
3939

4040
export class LoggerProxy {
41-
app: FabrixApp
42-
warn
43-
debug
44-
info
45-
error
46-
silly
41+
public app: FabrixApp
42+
public warn
43+
public debug
44+
public info
45+
public error
46+
public silly
4747
/**
4848
* Instantiate Proxy; bind log events to default console.log
4949
*/
5050
constructor (app: FabrixApp) {
51-
this.app = app
51+
Object.defineProperties(this, {
52+
app: {
53+
value: app,
54+
writable: false,
55+
enumerable: false
56+
}
57+
})
5258

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

lib/common/Controller.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
import { FabrixApp } from '../index'
44
import { EventEmitter } from 'events'
5+
import { FabrixGeneric } from './Generic'
56

67
/**
78
* Fabrix Controller Class.
89
*/
9-
export class FabrixController {
10-
private _app: FabrixApp
10+
export class FabrixController extends FabrixGeneric {
11+
public app: FabrixApp
1112

1213
constructor (app: FabrixApp) {
1314
if (!(app instanceof EventEmitter)) {
1415
throw new Error('The "app" argument must be of type EventEmitter')
1516
}
16-
this._app = app
17+
super(app)
1718
this.app.emit(`controller:${this.id}:constructed`, this)
1819
}
1920

@@ -26,12 +27,6 @@ export class FabrixController {
2627
}
2728
}
2829

29-
// @enumerable(false)
30-
// @writable(false)
31-
get app(): FabrixApp {
32-
return this._app
33-
}
34-
3530
/**
3631
* Return the id of this controller
3732
*/

lib/common/Generic.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ import { FabrixApp } from '../index'
33
* Fabrix Generic Class.
44
*/
55
export class FabrixGeneric {
6+
public app: FabrixApp
67
public methods: string[] = []
7-
constructor (app: FabrixApp) {}
8+
constructor (app: FabrixApp) {
9+
Object.defineProperties(this, {
10+
app: {
11+
value: app,
12+
writable: false,
13+
enumerable: false
14+
}
15+
})
16+
}
817
}

lib/common/Model.ts

+15-7
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@ import { FabrixResolver } from './'
44
import { IllegalAccessError } from '../errors'
55
import { FabrixGeneric } from './Generic'
66

7+
// export interface FabrixModel {
8+
// new(): FabrixModel
9+
// config(app: FabrixApp, datastore?): {
10+
// [key: string]: any,
11+
// tableName?: string,
12+
// store?: any,
13+
// migrate?: string
14+
// }
15+
// schema(app: FabrixApp, datastore?): {
16+
// [key: string]: any
17+
// }
18+
// resolver(): any
19+
// }
720

821
/**
922
* Fabrix Model Class.
1023
*/
1124
export class FabrixModel extends FabrixGeneric {
12-
private _app: FabrixApp
25+
public app: FabrixApp
1326
private _datastore: any
1427
private _instance: any
1528
private _config: {[key: string]: any}
@@ -22,7 +35,7 @@ export class FabrixModel extends FabrixGeneric {
2235
/**
2336
* Model configuration
2437
*/
25-
public static config (app: FabrixApp, datastore?): {[key: string]: any} {
38+
public static config (app: FabrixApp, datastore?) {
2639
return {
2740
tableName: null,
2841
store: null,
@@ -64,18 +77,13 @@ export class FabrixModel extends FabrixGeneric {
6477
if (!(app instanceof EventEmitter)) {
6578
throw new Error('The "app" argument must be of type EventEmitter')
6679
}
67-
this._app = app
6880

6981
this._datastore = datastore
7082

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

75-
get app(): FabrixApp {
76-
return this._app
77-
}
78-
7987
get datastore() {
8088
if (!this._datastore) {
8189
// This will throw an error if the logger is not set yet

lib/common/Policy.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { FabrixGeneric } from './Generic'
99
* Fabrix Policy Class.
1010
*/
1111
export class FabrixPolicy extends FabrixGeneric {
12-
private _app: FabrixApp
12+
public app: FabrixApp
1313

1414

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

@@ -37,12 +36,6 @@ export class FabrixPolicy extends FabrixGeneric {
3736
}
3837
}
3938

40-
// @enumerable(false)
41-
// @writable(false)
42-
get app(): FabrixApp {
43-
return this._app
44-
}
45-
4639
/**
4740
* Return the id of this policy
4841
*/

lib/common/Service.ts

-8
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ import { FabrixGeneric } from './Generic'
99
* Fabrix Service Class.
1010
*/
1111
export class FabrixService extends FabrixGeneric {
12-
private _app: FabrixApp
1312

1413
constructor (app: FabrixApp) {
1514
super(app)
1615

1716
if (!(app instanceof EventEmitter)) {
1817
throw new Error('The "app" argument must be of type EventEmitter')
1918
}
20-
this._app = app
2119
this.app.emit(`service:${this.id}:constructed`, this)
2220
}
2321

@@ -30,12 +28,6 @@ export class FabrixService extends FabrixGeneric {
3028
}
3129
}
3230

33-
// @enumerable(false)
34-
// @writable(false)
35-
get app(): FabrixApp {
36-
return this._app
37-
}
38-
3931
/**
4032
* Return the id of this controller
4133
*/

lib/common/Spool.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { EventEmitter } from 'events'
44
import { defaultsDeep, omit } from 'lodash'
55
import { IApi, IPkg, ISpoolConfig, ILifecycle } from './index'
66
import { FabrixApp } from '../index'
7+
import { FabrixGeneric } from './Generic'
78

89
/**
910
* @class Spool
@@ -12,9 +13,9 @@ import { FabrixApp } from '../index'
1213
export interface Spool {
1314
[key: string]: any
1415
}
15-
export class Spool {
16+
export class Spool extends FabrixGeneric {
17+
public app: FabrixApp
1618
private _stage = 'pre'
17-
private _app: FabrixApp
1819
private _config: ISpoolConfig
1920
private _pkg: any // IPkg
2021
private _api: IApi
@@ -93,14 +94,14 @@ export class Spool {
9394
api = { }
9495
}: { pkg?: any, config?: ISpoolConfig, api?: IApi }
9596
) {
97+
super(app)
9698
if (!(app instanceof EventEmitter)) {
9799
throw new Error('The "app" argument must be of type EventEmitter')
98100
}
99101
if (!pkg) {
100102
throw new Error('Spool is missing package definition ("spool.pkg")')
101103
}
102104

103-
this._app = app
104105
this._pkg = Object.freeze(pkg)
105106
this._api = api
106107

@@ -124,10 +125,6 @@ export class Spool {
124125
return this._stage
125126
}
126127

127-
get app (): FabrixApp {
128-
return this._app
129-
}
130-
131128
get api () {
132129
return this._api
133130
}

package-lock.json

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

0 commit comments

Comments
 (0)