diff --git a/README.md b/README.md index de7d6bc..bc896b6 100755 --- a/README.md +++ b/README.md @@ -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 diff --git a/archetype/package.json b/archetype/package.json index 083b9d0..b2772b9 100755 --- a/archetype/package.json +++ b/archetype/package.json @@ -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", @@ -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", diff --git a/archetype/src/api/index.ts b/archetype/src/api/index.ts index b0f7274..a04abf9 100755 --- a/archetype/src/api/index.ts +++ b/archetype/src/api/index.ts @@ -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 } diff --git a/archetype/src/config/main.ts b/archetype/src/config/main.ts index cfa29ff..9ad0026 100755 --- a/archetype/src/config/main.ts +++ b/archetype/src/config/main.ts @@ -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 diff --git a/archetype/test/index.js b/archetype/test/index.js index b73b551..6042219 100755 --- a/archetype/test/index.js +++ b/archetype/test/index.js @@ -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() }) diff --git a/lib/Configuration.ts b/lib/Configuration.ts index 47218a6..39314f1 100755 --- a/lib/Configuration.ts +++ b/lib/Configuration.ts @@ -39,6 +39,7 @@ export class Configuration extends Map { && 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 @@ -75,6 +76,7 @@ export class Configuration extends Map { */ 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') } diff --git a/lib/Core.ts b/lib/Core.ts index a8a8027..5ca6591 100755 --- a/lib/Core.ts +++ b/lib/Core.ts @@ -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: [ @@ -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, @@ -71,6 +73,7 @@ export const Core = { Resolver: FabrixResolver }, Errors)), + // Deprecated v1.6 globalPropertyOptions: Object.freeze({ writable: false, enumerable: false, @@ -78,6 +81,7 @@ export const Core = { }), /** + * Deprecated v1.6 * Prepare the global namespace with required Fabrix types. Ignore identical * values already present; fail on non-matching values. * diff --git a/lib/Fabrix.ts b/lib/Fabrix.ts index 7e3ef00..48c5b18 100644 --- a/lib/Fabrix.ts +++ b/lib/Fabrix.ts @@ -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 diff --git a/package-lock.json b/package-lock.json index 8165275..55e1480 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@fabrix/fabrix", - "version": "1.5.9", + "version": "1.6.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e2f3a2e..b9901b0 100755 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/lib/Controller.test.js b/test/lib/Controller.test.js index 9e4666b..73cb9c1 100755 --- a/test/lib/Controller.test.js +++ b/test/lib/Controller.test.js @@ -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) diff --git a/test/lib/Core.test.js b/test/lib/Core.test.js index bf8bd8f..7c457c6 100755 --- a/test/lib/Core.test.js +++ b/test/lib/Core.test.js @@ -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) diff --git a/test/lib/Model.test.js b/test/lib/Model.test.js index 9f2c66b..4f61408 100755 --- a/test/lib/Model.test.js +++ b/test/lib/Model.test.js @@ -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) diff --git a/test/lib/Policy.test.js b/test/lib/Policy.test.js index e08be05..bc1a367 100755 --- a/test/lib/Policy.test.js +++ b/test/lib/Policy.test.js @@ -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) diff --git a/test/lib/Resolver.test.js b/test/lib/Resolver.test.js index a57361e..905124f 100755 --- a/test/lib/Resolver.test.js +++ b/test/lib/Resolver.test.js @@ -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) diff --git a/test/lib/Service.test.js b/test/lib/Service.test.js index 29ce934..97b3cc0 100755 --- a/test/lib/Service.test.js +++ b/test/lib/Service.test.js @@ -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) diff --git a/test/lib/errors/errors.test.js b/test/lib/errors/errors.test.js index 8445131..a0ff376 100755 --- a/test/lib/errors/errors.test.js +++ b/test/lib/errors/errors.test.js @@ -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') }) @@ -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') }) @@ -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))