Skip to content

Commit

Permalink
Merge pull request #31 from fabrix-app/v1.6
Browse files Browse the repository at this point in the history
V1.6
  • Loading branch information
scott-wyatt authored Nov 25, 2018
2 parents 21f0b80 + 0092e67 commit 7ef7094
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 77 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Fabrix is a strongly typed modern web application framework for Node.js. It buil
## Getting Started

#### Install
Install the Fabrix CLI. This will help you generate a Fabrix app and more quickly.
Install the Fabrix CLI. This will help you generate a Fabrix app and more.

```sh
$ npm install @fabrix/fab-cli -g
Expand Down
8 changes: 4 additions & 4 deletions archetype/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "tsc -p ./src/tsconfig.release.json",
"lint": "tslint -p ./src",
"watch": "tsc -w -p ./src/tsconfig.release.json",
"test": "npm run clean && npm run copy && npm run lint && npm run build && nyc mocha",
"test": "npm run compile && nyc mocha",
"prepublishOnly": "npm run compile",
"compile": "npm run clean && npm run build && npm run copy",
"copy": "copyfiles -u 1 src/config/**/*.json dist",
Expand All @@ -16,11 +16,11 @@
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"dependencies": {
"@fabrix/fabrix": "^1.5",
"@fabrix/spool-router": "^1.5"
"@fabrix/fabrix": "^1.5.9",
"@fabrix/spool-router": "^1.5.1"
},
"devDependencies": {
"@fabrix/spool-repl": "^1.5",
"@fabrix/spool-repl": "^1.5.0",
"@fabrix/lint": "^1.0.0-alpha.3",
"@types/node": "~10.3.4",
"copyfiles": "^2.0.0",
Expand Down
20 changes: 10 additions & 10 deletions archetype/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as Controllers from './controllers'
import * as Models from './models'
import * as Policies from './policies'
import * as Services from './services'
import * as Resolvers from './resolvers'
import * as controllers from './controllers'
import * as models from './models'
import * as policies from './policies'
import * as services from './services'
import * as resolvers from './resolvers'

export {
Controllers,
Models,
Policies,
Services,
Resolvers
controllers,
models,
policies,
services,
resolvers
}
6 changes: 4 additions & 2 deletions archetype/src/config/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import { RouterSpool } from '@fabrix/spool-router'
export const main = {

/**
* Order does *not* matter. Each module is loaded according to its own
* requirements.
* Order matters. Each module is loaded according to its own
* requirements, however, when there are spools
* with conflicting configuration, the last spool loaded
* takes priority.
*/
spools: [
RouterSpool
Expand Down
2 changes: 1 addition & 1 deletion archetype/test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const FabrixApp = require('@fabrix/fabrix').FabrixApp

before(() => {
global.app = new FabrixApp(require('../'))
global.app = new FabrixApp(require('../dist'))
return global.app.start()
})

Expand Down
2 changes: 2 additions & 0 deletions lib/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class Configuration extends Map<any, any> {
&& typeof v !== 'function'
) {
// If value is an array, flatten by index and don't try to flatten further
// Configs with Array will throw a warning in v2.0 and an error in v3.0
if (Array.isArray(v)) {
v.forEach((val, i) => {
toReturn[`${k}.${i}`] = val
Expand Down Expand Up @@ -75,6 +76,7 @@ export class Configuration extends Map<any, any> {
*/
static initialResources (tree, resources = []) {
if (tree.hasOwnProperty('main') && tree.main.hasOwnProperty('resources')) {
// Configs with Array will throw a warning in v2.0 and an error in v3.0
if (!isArray(tree.main['resources'])) {
throw new ConfigValueError('if set, main.resources must be an array')
}
Expand Down
6 changes: 5 additions & 1 deletion lib/Core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const Errors = {
}

export const Core = {
// An Exception convenience
// An Exception convenience: added v1.5
BreakException: {},
// Methods reserved so that they are not autobound
reservedMethods: [
Expand All @@ -59,10 +59,12 @@ export const Core = {
'methods',
'config',
'schema',
// Should additional resource types be added to reserved or should this be removed completely?
'services',
'models'
],

// Deprecated v1.6
globals: Object.freeze(Object.assign({
Service: FabrixService,
Controller: FabrixController,
Expand All @@ -71,13 +73,15 @@ export const Core = {
Resolver: FabrixResolver
}, Errors)),

// Deprecated v1.6
globalPropertyOptions: Object.freeze({
writable: false,
enumerable: false,
configurable: false
}),

/**
* Deprecated v1.6
* Prepare the global namespace with required Fabrix types. Ignore identical
* values already present; fail on non-matching values.
*
Expand Down
3 changes: 2 additions & 1 deletion lib/Fabrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { MiscSpool } from './common/spools/misc'
import { enumerable } from './common/decorators/enumerable'

// inject Error and Resource types into the global namespace
Core.assignGlobals()
// Deprecate Globals v1.6
// Core.assignGlobals()

/**
* The Fabrix Application. Merges the configuration and API resources
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fabrix/fabrix",
"version": "1.5.9",
"version": "1.6.0",
"description": "Strongly Typed Modern Web Application Framework for Node.js",
"keywords": [
"framework",
Expand Down
3 changes: 2 additions & 1 deletion test/lib/Controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ describe('lib/Controller', () => {
describe('sanity', () => {
it('should exist', () => {
assert(Controller)
assert(global.Controller)
// Deprecated v1.6
// assert(global.Controller)
})
it('can instantiate without error', () => {
const app = new Fabrix(testApp)
Expand Down
55 changes: 28 additions & 27 deletions test/lib/Core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,34 @@ describe('lib.Core', () => {
})
})

describe('#assignGlobals', () => {
it('should assign values to the global namespace', () => {
lib.Core.assignGlobals()

assert(global.Service)
assert(global.Controller)
assert(global.Model)
assert(global.Policy)
assert(Service)
})
it('global variables should be immutable and error if mutation is attempted', () => {
delete global.Service
assert(global.Service)
assert(Service)
})
it('should ignore conflicts for identical values', () => {
const s1 = Service
lib.Core.assignGlobals()
lib.Core.assignGlobals()
lib.Core.assignGlobals()
lib.Core.assignGlobals()

assert(global.Service)
assert(Service)
assert.equal(s1, Service)
})
})
// Deprecated v1.6
// describe('#assignGlobals', () => {
// it('should assign values to the global namespace', () => {
// lib.Core.assignGlobals()
//
// assert(global.Service)
// assert(global.Controller)
// assert(global.Model)
// assert(global.Policy)
// assert(Service)
// })
// it('global variables should be immutable and error if mutation is attempted', () => {
// delete global.Service
// assert(global.Service)
// assert(Service)
// })
// it('should ignore conflicts for identical values', () => {
// const s1 = Service
// lib.Core.assignGlobals()
// lib.Core.assignGlobals()
// lib.Core.assignGlobals()
// lib.Core.assignGlobals()
//
// assert(global.Service)
// assert(Service)
// assert.equal(s1, Service)
// })
// })
describe('#handlePromiseRejection', () => {
it('should throw an error and log it', () => {
assert.throws(() => lib.Core.handlePromiseRejection(new Error('Promise Rejection Test')), Error)
Expand Down
3 changes: 2 additions & 1 deletion test/lib/Model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ describe('lib/Model', () => {
describe('sanity', () => {
it('should exist', () => {
assert(Model)
assert(global.Model)
// Deprecated v1.6
// assert(global.Model)
})
it('can instantiate without error', () => {
const app = new Fabrix(testApp)
Expand Down
3 changes: 2 additions & 1 deletion test/lib/Policy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ describe('lib/Policy', () => {
describe('sanity', () => {
it('should exist', () => {
assert(Policy)
assert(global.Policy)
// Deprecated v1.6
// assert(global.Policy)
})
it('can instantiate without error', () => {
const app = new Fabrix(testApp)
Expand Down
3 changes: 2 additions & 1 deletion test/lib/Resolver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ describe('lib/Resolver', () => {
describe('sanity', () => {
it('should exist', () => {
assert(Resolver)
assert(global.Resolver)
// Deprecated v1.6
// assert(global.Resolver)
})
it('can instantiate without error', () => {
const app = new Fabrix(testApp)
Expand Down
3 changes: 2 additions & 1 deletion test/lib/Service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ describe('lib/Service', () => {
describe('sanity', () => {
it('should exist', () => {
assert(Service)
assert(global.Service)
// Deprecated v1.6
// assert(global.Service)
})
it('can instantiate without error', () => {
const app = new Fabrix(testApp)
Expand Down
49 changes: 26 additions & 23 deletions test/lib/errors/errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,75 @@ const assert = require('assert')
const Spool = require('../../../dist/common/Spool').Spool
const lib = require('../../../dist/index')

const Errors = require('../../../dist/errors')

describe('lib.Errors', () => {
it('all Error types should be global', () => {
assert(global.ConfigNotDefinedError)
assert(global.ApiNotDefinedError)
assert(global.ConfigValueError)
assert(global.PackageNotDefinedError)
assert(global.IllegalAccessError)
assert(global.TimeoutError)
assert(global.GraphCompletenessError)
assert(global.NamespaceConflictError)
assert(global.ValidationError)
assert(global.SpoolError)
assert(global.SanityError)
// Deprecated v1.6
// assert(global.ConfigNotDefinedError)
// assert(global.ApiNotDefinedError)
// assert(global.ConfigValueError)
// assert(global.PackageNotDefinedError)
// assert(global.IllegalAccessError)
// assert(global.TimeoutError)
// assert(global.GraphCompletenessError)
// assert(global.NamespaceConflictError)
// assert(global.ValidationError)
// assert(global.SpoolError)
// assert(global.SanityError)
})

describe('ConfigNotDefinedError', () => {
it('#name', () => {
const err = new ConfigNotDefinedError()
const err = new Errors.ConfigNotDefinedError()
assert.equal(err.name, 'ConfigNotDefinedError')
})
})
describe('ApiNotDefinedError', () => {
it('#name', () => {
const err = new ApiNotDefinedError()
const err = new Errors.ApiNotDefinedError()
assert.equal(err.name, 'ApiNotDefinedError')
})
})
describe('ConfigValueError', () => {
it('#name', () => {
const err = new ConfigValueError()
const err = new Errors.ConfigValueError()
assert.equal(err.name, 'ConfigValueError')
})
})
describe('PackageNotDefinedError', () => {
it('#name', () => {
const err = new PackageNotDefinedError()
const err = new Errors.PackageNotDefinedError()
assert.equal(err.name, 'PackageNotDefinedError')
})
})
describe('IllegalAccessError', () => {
it('#name', () => {
const err = new IllegalAccessError()
const err = new Errors.IllegalAccessError()
assert.equal(err.name, 'IllegalAccessError')
})
})
describe('TimeoutError', () => {
it('#name', () => {
const err = new TimeoutError()
const err = new Errors.TimeoutError()
assert.equal(err.name, 'TimeoutError')
})
})
describe('GraphCompletenessError', () => {
it('#name', () => {
const err = new GraphCompletenessError()
const err = new Errors.GraphCompletenessError()
assert.equal(err.name, 'GraphCompletenessError')
})
})
describe('NamespaceConflictError', () => {
it('#name', () => {
const err = new NamespaceConflictError()
const err = new Errors.NamespaceConflictError()
assert.equal(err.name, 'NamespaceConflictError')
})
})
describe('ValidationError', () => {
it('#name', () => {
const err = new ValidationError()
const err = new Errors.ValidationError()
// err.constructor.humanizeMessage([])
assert.equal(err.name, 'ValidationError')
})
Expand All @@ -95,7 +98,7 @@ describe('lib.Errors', () => {
})
describe('SanityError', () => {
it('#name', () => {
const err = new SanityError()
const err = new Errors.SanityError()
// err.constructor.humanizeMessage([])
assert.equal(err.name, 'SanityError')
})
Expand All @@ -121,13 +124,13 @@ describe('lib.Errors', () => {
})
describe('SpoolError', () => {
it('#name', () => {
const err = new SpoolError()
const err = new Errors.SpoolError()
assert.equal(err.name, 'SpoolError')
})
describe('#message', () => {
it('should specify the failed spool and stage', () => {
const Failspool = class Failspool extends Spool { }
const err = new SpoolError(Failspool, new Error(), 'constructor')
const err = new Errors.SpoolError(Failspool, new Error(), 'constructor')

assert(/spool failed/.test(err.message))
assert(/"constructor"/.test(err.message))
Expand Down

0 comments on commit 7ef7094

Please sign in to comment.