Skip to content

Commit 8edfddb

Browse files
authored
Merge pull request #10 from fabrix-app/v1.1
V1.1
2 parents 41256f5 + e44259e commit 8edfddb

File tree

8 files changed

+81
-6
lines changed

8 files changed

+81
-6
lines changed

lib/Core.ts

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
NamespaceConflictError,
1212
PackageNotDefinedError,
1313
TimeoutError,
14+
SanityError,
1415
SpoolError,
1516
ValidationError
1617
} from './errors'
@@ -39,6 +40,7 @@ export const Errors = {
3940
NamespaceConflictError,
4041
PackageNotDefinedError,
4142
TimeoutError,
43+
SanityError,
4244
SpoolError,
4345
ValidationError
4446
}

lib/common/Model.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { FabrixGeneric } from './Generic'
1111
export class FabrixModel extends FabrixGeneric {
1212
private _app: FabrixApp
1313
private _datastore: any
14+
private _instance: any
1415
private _config: {[key: string]: any}
1516
private _schema: any
1617
private _resolver: any
@@ -76,16 +77,26 @@ export class FabrixModel extends FabrixGeneric {
7677
}
7778

7879
get datastore() {
79-
// if (!this._datastore) {
80-
// this.app.log.warn(`${this.name} did not receive an instance of the datastore`)
81-
// }
80+
if (!this._datastore) {
81+
// This will throw an error if the logger is not set yet
82+
// this.app.log.warn(`${this.name} did not receive an instance of the datastore`)
83+
}
8284
return this._datastore
8385
}
8486

8587
set datastore(datastore) {
8688
this._datastore = datastore
8789
}
8890

91+
get instance() {
92+
if (!this._resolver) {
93+
return
94+
// This will throw an error if the logger is not set yet
95+
// this.app.log.warn(`${this.name} did not receive an instance from the datastore`)
96+
}
97+
return this._resolver.instance
98+
}
99+
89100
/**
90101
* Return the config of this model
91102
*/

lib/common/Resolver.ts

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export class FabrixResolver {
1717
this.app.emit(`resolver:${this.model.name}:constructed`, this)
1818
}
1919

20+
get instance(): any {
21+
return
22+
}
23+
2024
/**
2125
* Return the parent model
2226
*/

lib/errors/SanityError.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Generic Sanity error; commonly used to wrap joi errors, but can be
3+
* used for any Sanity-related exception.
4+
*/
5+
export class SanityError extends Error {
6+
constructor (msg: string, details?: any[]) {
7+
super(msg + '\n' + SanityError.humanizeMessage(details))
8+
}
9+
10+
get name () {
11+
return 'SanityError'
12+
}
13+
14+
/**
15+
* Humanize a list of error details
16+
*
17+
* @param details a "joi-style details" list
18+
* @param details.message
19+
* @param details.path
20+
* @param details.type
21+
* @param details.context
22+
* @return String
23+
*/
24+
static humanizeMessage (details?: any[]) {
25+
const preamble = 'The following configuration values are invalid: '
26+
const paths = (details || [ ]).map(d => d.path.join('.'))
27+
28+
return preamble + paths.join(', ')
29+
}
30+
}

lib/errors/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export { GraphCompletenessError } from './GraphCompletenessError'
55
export { IllegalAccessError } from './IllegalAccessError'
66
export { NamespaceConflictError } from './NamespaceConflictError'
77
export { PackageNotDefinedError } from './PackageNotDefinedError'
8-
export { TimeoutError } from './TimeoutError'
8+
export { SanityError } from './SanityError'
99
export { SpoolError } from './SpoolError'
10+
export { TimeoutError } from './TimeoutError'
1011
export { ValidationError } from './ValidationError'

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.2",
3+
"version": "1.1.3",
44
"description": "Strongly Typed Modern Web Application Framework for Node.js",
55
"keywords": [
66
"framework",

test/lib/errors/errors.test.js

+27
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('lib.Errors', () => {
1515
assert(global.NamespaceConflictError)
1616
assert(global.ValidationError)
1717
assert(global.SpoolError)
18+
assert(global.SanityError)
1819
})
1920

2021
describe('ConfigNotDefinedError', () => {
@@ -92,6 +93,32 @@ describe('lib.Errors', () => {
9293

9394
})
9495
})
96+
describe('SanityError', () => {
97+
it('#name', () => {
98+
const err = new SanityError()
99+
// err.constructor.humanizeMessage([])
100+
assert.equal(err.name, 'SanityError')
101+
})
102+
describe('#message', () => {
103+
it('should specify missing/undefined spools', () => {
104+
const testConfig = {
105+
main: {
106+
spools: [
107+
undefined
108+
]
109+
}
110+
}
111+
112+
try {
113+
new lib.Configuration(testConfig)
114+
}
115+
catch (e) {
116+
assert(/The following configuration values are invalid/.test(e.message))
117+
assert(/main.spools\.0/.test(e.message))
118+
}
119+
})
120+
})
121+
})
95122
describe('SpoolError', () => {
96123
it('#name', () => {
97124
const err = new SpoolError()

0 commit comments

Comments
 (0)