Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

trails

Package Overview
Dependencies
Maintainers
2
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trails - npm Package Compare versions

Comparing version 3.0.0-pre.1 to 3.0.0-pre.2

archetype/config/web.js

2

archetype/config/log.js

@@ -9,3 +9,3 @@ /**

module.exports = {
level: 'info'
}

@@ -8,3 +8,2 @@ {

"dependencies": {
"trailpack-repl": "^2",
"trailpack-router": "^2",

@@ -14,6 +13,7 @@ "trails": "^2"

"devDependencies": {
"eslint": "^3.15.0",
"eslint-config-trails": "^2",
"mocha": "^3.2.0",
"supertest": "^1.2"
"eslint": "^3",
"eslint-config-trails": "^3",
"mocha": "^3",
"supertest": "^3",
"trailpack-repl": "^2"
},

@@ -24,3 +24,3 @@ "scripts": {

"engines": {
"node": ">= 4.0.0"
"node": ">= 7.6.0"
},

@@ -27,0 +27,0 @@ "eslintConfig": {

@@ -8,2 +8,2 @@ /**

server.start().catch(err => server.stop(err))
module.exports = server.start()

@@ -1,2 +0,1 @@

/*eslint no-console: 0 */
/*eslint no-process-env: 0 */

@@ -50,2 +49,7 @@

Object.defineProperties(this, {
logger: {
value: new lib.LoggerProxy(this),
enumerable: false,
writable: false
},
env: {

@@ -81,56 +85,2 @@ enumerable: false,

value: { }
},
loadedPacks: {
enumerable: false,
writable: true,
value: [ ]
},
bound: {
enumerable: false,
writable: true,
value: false
},
started: {
enumerable: false,
writable: true,
value: false
},
stopped: {
enumerable: false,
writable: true,
value: false
},
timers: {
enumerable: false,
writable: true,
value: { }
},
models: {
enumerable: true,
writable: false,
value: { }
},
services: {
enumerable: true,
writable: false,
value: { }
},
controllers: {
enumerable: true,
writable: false,
value: { }
},
policies: {
enumerable: true,
writable: false,
value: { }
},
resolvers: {
enumerable: true,
writable: false,
value: { }
},
translate: {
enumerable: false,
writable: true
}

@@ -151,10 +101,9 @@ })

})
this.loadedPacks = Object.keys(this.packs).map(name => this.packs[name])
// bind resource methods
Object.assign(this.controllers, lib.Core.bindMethods(this, 'controllers'))
Object.assign(this.policies, lib.Core.bindMethods(this, 'policies'))
this.controllers = lib.Core.bindMethods(this, 'controllers')
this.policies = lib.Core.bindMethods(this, 'policies')
lib.Core.bindListeners(this)
lib.Core.bindTrailpackPhaseListeners(this, this.loadedPacks)
lib.Core.bindApplicationListeners(this)
lib.Core.bindTrailpackPhaseListeners(this, Object.values(this.packs))
}

@@ -168,8 +117,4 @@

async start () {
this.emit('trails:start')
await this.after('trails:ready')
this.started = true
return this

@@ -182,20 +127,13 @@ }

*/
async stop (err) {
this.stopped = true
if (err) {
this.log.error('\n', err.stack || '')
}
if (!this.started) {
this.log.error('The application did not boot successfully.')
this.log.error('Try increasing the loglevel to "debug" to learn more')
}
async stop () {
this.emit('trails:stop')
lib.Core.unbindListeners(this)
await Promise.all(this.loadedPacks.map(pack => {
await Promise.all(Object.values(this.packs).map(pack => {
this.log.debug('Unloading trailpack', pack.name, '...')
return pack.unload()
}))
this.log.debug('All trailpacks unloaded. Done.')
.then(() => {
this.log.debug('All trailpacks unloaded. Done.')
this.removeAllListeners()
})

@@ -206,11 +144,2 @@ return this

/**
* @override
* Log app events for debugging
*/
emit (event) {
this.log.debug('trails event:', event)
return super.emit.apply(this, arguments)
}
/**
* Resolve Promise once ANY of the events in the list have emitted.

@@ -263,19 +192,8 @@ *

/**
* Create any configured paths which may not already exist.
* Return the Trails logger
* @fires trails:log:* log events
*/
async createPaths () {
if (this.config.get('main.createPaths') === false) {
this.log.warn('createPaths is disabled. Configured paths will not be created')
return
}
return lib.Core.createDefaultPaths(this)
}
/**
* Expose the logger on the app object. The logger can be configured by
* setting the "config.log.logger" config property.
*/
get log () {
return this.config.get('log.logger')
return this.logger
}
}

@@ -1,2 +0,1 @@

/*eslint no-console: 0 */
const merge = require('lodash.merge')

@@ -6,14 +5,9 @@ const path = require('path')

const ConfigurationProxyHandler = {
get (target, key, receiver) {
if (Reflect.has(target, key)) return target[key]
return target.get(key)
},
set (target, key, value, receiver) {
if (target.hasOwnProperty(key)) {
target[key] = value
return true
get (target, key) {
if (target.has && target.has(key)) {
const value = target.immutable ? Object.freeze(target.get(key)) : target.get(key)
return new Proxy(value, ConfigurationProxyHandler)
}
else {
throw new IllegalAccessError('Cannot set properties directly on config. Use .set(key, value)')
return target.immutable ? Object.freeze(target[key]) : target[key]
}

@@ -44,3 +38,3 @@ }

if (this.immutable) {
throw new TypeError('Configuration is frozen')
throw new IllegalAccessError('Cannot set properties directly on config. Use .set(key, value) (immutable)')
}

@@ -69,3 +63,3 @@

Object.entries(tree).forEach(([ k, v ]) => {
if (typeof v === 'object') {
if (typeof v === 'object' && v !== null) {
const flatObject = Configuration.flattenTree(v)

@@ -122,10 +116,2 @@ Object.keys(flatObject).forEach(flatKey => {

validateConfig () {
if (!this.has('main')) {
throw new ConfigNotDefinedError()
}
if (!this.has('log.logger')) {
throw new LoggerNotDefinedError()
}
/*

@@ -132,0 +118,0 @@ TODO re-enable

@@ -28,2 +28,9 @@ /**

/**
* Return a reference to the Trails configuration map.
*/
get config () {
return this.app.config
}
get services () {

@@ -30,0 +37,0 @@ return this.app.services

@@ -19,3 +19,4 @@ /*eslint no-console: 0 */

'config',
'schema'
'schema',
'services'
],

@@ -59,6 +60,2 @@

return mapValues(app.api[resource], (Resource, resourceName) => {
if (typeof Resource === 'function') {
throw new Error(`${resourceName} should be a class. It is a regular object`)
}
const obj = new Resource(app)

@@ -125,16 +122,2 @@

/**
* Bind listeners various application events
*/
bindListeners (app) {
if (app.bound) {
app.log.warn('Someone attempted to bindListeners() twice! Stacktrace below.')
app.log.warn(console.trace()) // eslint-disable-line no-console
return
}
Core.bindApplicationListeners(app)
app.bound = true
},
/**
* Bind listeners to trails application events

@@ -150,3 +133,2 @@ */

app.config.freeze()
app.emit('trails:config:frozen')
})

@@ -163,2 +145,3 @@ app.once('trailpack:all:initialized', () => {

app.log.info(lib.Templates.hr)
app.log.info(lib.Templates.docs)
})

@@ -169,3 +152,2 @@ app.once('trails:stop', () => {

})
app.once('trails:error:fatal', err => app.stop(err))
},

@@ -184,9 +166,7 @@

app.after(configuredEvents)
.then(() => app.createPaths())
.then(() => this.createDefaultPaths(app))
.then(() => app.emit('trailpack:all:configured'))
.catch(err => app.stop(err))
app.after(validatedEvents)
.then(() => app.emit('trailpack:all:validated'))
.catch(err => app.stop(err))

@@ -198,3 +178,2 @@ app.after(initializedEvents)

})
.catch(err => app.stop(err))
},

@@ -213,3 +192,2 @@

.then(() => app.emit(`trailpack:${pack.name}:initialized`))
.catch(err => app.stop(err))

@@ -220,3 +198,2 @@ app.after(lifecycle.configure.listen.concat('trailpack:all:validated'))

.then(() => app.emit(`trailpack:${pack.name}:configured`))
.catch(err => app.stop(err))

@@ -227,12 +204,3 @@ app.after('trails:start')

.then(() => app.emit(`trailpack:${pack.name}:validated`))
.catch(err => app.stop(err))
},
/**
* Unbind all listeners that were bound during application startup
*/
unbindListeners (app) {
app.removeAllListeners()
app.bound = false
}
}

@@ -6,3 +6,2 @@ exports.ApiNotDefinedError = require('./ApiNotDefinedError')

exports.IllegalAccessError = require('./IllegalAccessError')
exports.LoggerNotDefinedError = require('./LoggerNotDefinedError')
exports.NamespaceConflictError = require('./NamespaceConflictError')

@@ -9,0 +8,0 @@ exports.PackageNotDefinedError = require('./PackageNotDefinedError')

exports.Errors = require('./errors')
exports.Schemas = require('./schemas')
exports.Configuration = require('./Configuration')
exports.Core = require('./Core')
exports.LoggerProxy = require('./LoggerProxy')
exports.Pathfinder = require('./Pathfinder')
exports.Core = require('./Core')
exports.Configuration = require('./Configuration')
exports.Templates = require('./Templates')

@@ -34,2 +34,9 @@ /**

/**
* Return a reference to the Trails configuration map.
*/
get config () {
return this.app.config
}
get services () {

@@ -36,0 +43,0 @@ return this.app.services

@@ -28,2 +28,9 @@ /**

/**
* Return a reference to the Trails configuration map.
*/
get config () {
return this.app.config
}
get services () {

@@ -30,0 +37,0 @@ return this.app.services

@@ -5,2 +5,3 @@ /*eslint max-len: 0 */

hr: '---------------------------------------------------------------',
docs: 'Trails Documentation: http://trailsjs.io/doc',

@@ -16,3 +17,3 @@ info: {

`---------------------------------------------------------------
${new Date()}
Now: ${new Date()}
Basic Info

@@ -47,3 +48,3 @@ Application : ${app.pkg.name}

Policies : ${Object.keys(app.api.policies)}
Trailpacks : ${app.loadedPacks}`
Trailpacks : ${Object.keys(app.packs)}`
)

@@ -53,26 +54,12 @@ },

initialized: `
..@@@@.. .@. @@
.@@@@@@@@@@@@@@@@. @@@ @@
.@@@@' '@@@@. @@@ @@
@@@@ @@@@ @@@ .. @@
.@@; '@@. @@@ .@@@@. @@
@@@ .@@@. .@@@@. @@@ @@@@@@@@@ @@@@@@@@@ @@@@@@@@@ @@@@@@@@ @@' '@@ @@
@@' .@@@@@@@. .@@@@@@@@ '@@ @@@@@@@@@ @@@@@@@@@ @@@@@@@@@ @@@@@@@@ @@. .@@ @@
@@' @@@@@@@@@@@ :@@@@@@@@@@ '@@ @@@ '@@@@' @@
@@@ :@@@@@@@@@@@. @@@@@@@@@@@@ @@@ @@@ '' @@
@@ @@@@@'@@@@@@@ :@@@@'@@@@@@@ @@ @@@ @@ .@@@@@@@@@@@.
.@@ @@@@@ @@@@@@@ :@@@@ @@@@@@@ @@: @@@ @@ .@@@@@@@ .@@@@@@@ @@ @@ .@@@@@@@@@@@@@@'
@@@ @@@' @@@@@@. @@@@ @@@@@@@ @@+ @@@ @@ .@@@@: .@@@@' @@ @@ @@@'
@@@ @@ @@@@@ '@' @@@@@' @@: @@@ @@@@@' @@@' @@ @@ .@@
'@@ @@ @@ @@ @@@ @@@@ @@@ @@ @@ @@@
@@. @@ @@ .@@ @@@ @@@ @@@ @@ @@ .@@.
@@. '@@@. @@ .@@ @@@ @@@ @@' .. @@ .@@@@......
'@@ '@@@@@@@@@@.@@ .@@' @@@ @@' @@. .@@ @@ .@@@@@@@@@@@.
'@@. @@@@ .@@' @@@ @@' @@@ +@@ @@ @@ '@@@.
@@@. '@@ @@@ @@@ @@' '@@. .@@@ @@ @@ @@@
'@@@. @@ .@@@' @@@ @@' '@@. .@@@@ @@ @@ @@@
.@@@@. @@@@@@' @@@ @@' '@@@. .@@@ @@ @@ @@ @@@
.@@@@@@@..... @@@. @@@ @@' '@@@@@.....@@@@@' @@ @@ @@ .@@@@@@@@@@@@@@@
'@@@@@@@@ @@@ @@. '@@@@@@@@@' @@ @@ @@ '@@@@@@@@@@@@'
▓▓▓▓▓▓▓▓▓▀▓ ▓▓▓▓▓▓▓▓▓▌
▓▓▓▓▓▓▓▓ ▓ ▀▓▓▓▓▓▓▓▌
▓▓▓▓▓▓▀ ▓ ▀▓▓▓▓▓▌ ▄▄▄▄▄▄▄▄ ▄▄▄▄▄ ▄ ▄ ▄ ▄▄▄▄▄
▓▓▓▀ ▓ ▀█▓▓▌ ▐▓ ▓ ▀▓ ▓▀▓ ▐▓ ▓▌ ▓▌ █▌
▀ ▓ ▐▓ ▓ ▓ ▓▌ ▐▓ ▐▓ ▓▌ ▀█▓▄▄▄
▓ ▐▓ ▓▀▀▓▓ ▓▓▄▄▄▓▓ ▐▓ ▓▌ ▀▓
▄▓▓ ▐▓ ▓ ▀▓ ▓▓ ▓▌ ▐▓ ▓▌▄▄▄▄ ▀▓▄▄▄▓▀
▄▓▀ ▀▓
▄▓▀ ▄▓▄ ▀█▄
▀▀ ▀▀▀▀▀▀ ▀▀▀
`

@@ -79,0 +66,0 @@ }

{
"name": "trails",
"version": "3.0.0-pre.1",
"version": "3.0.0-pre.2",
"description": "Modern Web Application Framework for Node.js",

@@ -80,2 +80,3 @@ "keywords": [

"pre-commit": "^1.1.3",
"proxyquire": "^1.7.11",
"smokesignals": "next",

@@ -82,0 +83,0 @@ "trailpack": "next",

@@ -1,3 +0,1 @@

'use strict'
const Trailpack = require('trailpack')

@@ -4,0 +2,0 @@

@@ -1,7 +0,4 @@

'use strict'
const fs = require('fs')
const path = require('path')
const assert = require('assert')
const smokesignals = require('smokesignals')
const TrailsApp = require('../..')

@@ -103,16 +100,2 @@ const Trailpack = require('trailpack')

})
describe('@LoggerNotDefinedError', () => {
it('should throw LoggerNotDefinedError if logger is missing', () => {
const def = {
pkg: { },
api: { },
config: {
main: {
paths: { root: __dirname }
}
}
}
assert.throws(() => new TrailsApp(def), lib.Errors.LoggerNotDefinedError)
})
})
describe('@ApiNotDefinedError', () => {

@@ -125,5 +108,2 @@ it('should throw ApiNotDefinedError if no api definition is provided', () => {

paths: { root: __dirname }
},
log: {
logger: new smokesignals.Logger('silent')
}

@@ -141,5 +121,2 @@ }

paths: { root: __dirname }
},
log: {
logger: new smokesignals.Logger('silent')
}

@@ -165,5 +142,2 @@ }

]
},
log: {
logger: new smokesignals.Logger('silent')
}

@@ -181,6 +155,3 @@ }

config: {
main: { },
log: {
logger: new smokesignals.Logger('silent')
}
main: { }
},

@@ -193,3 +164,4 @@ pkg: { }

assert.equal(app.env.FOO, 'bar')
assert.throws(() => app.env.FOO = 1, TypeError)
app.env.FOO = 1
assert.equal(app.env.FOO, 'bar')
})

@@ -205,3 +177,2 @@

},
log: { logger: new smokesignals.Logger('debug') },
foo: 'bar'

@@ -228,3 +199,2 @@ }

},
log: { logger: new smokesignals.Logger('silent') },
foo: 'bar'

@@ -235,3 +205,4 @@ }

assert.equal(app.config.get('foo'), 'bar')
assert.throws(() => app.config = { }, Error)
app.config = { }
assert.equal(app.config.get('foo'), 'bar')
})

@@ -238,0 +209,0 @@ })

@@ -1,3 +0,1 @@

'use strict'
const assert = require('assert')

@@ -249,2 +247,11 @@ const lib = require('../../lib')

})
it.skip('should throw an error when attempting to set a value after frozen', () => {
const config = new lib.Configuration(_.cloneDeep(testConfig), { NODE_ENV: 'test' })
config.freeze()
//assert.throws(() => config.customObject = 'test', IllegalAccessError)
//assert.throws(() => config.customObject.newValue = 'test', IllegalAccessError)
assert.throws(() => config.customObject.string = 'b', IllegalAccessError)
assert.throws(() => config.set('customObject.string', 'b'), IllegalAccessError)
})
})

@@ -251,0 +258,0 @@ describe('#flattenTree', () => {

@@ -1,5 +0,5 @@

'use strict'
const assert = require('assert')
const Controller = require('../../lib/Controller')
const Trails = require('../../')
const testApp = require('../integration/testapp')

@@ -23,3 +23,17 @@ describe('lib/Controller', () => {

})
describe('#log', () => {
it('is a convenience method that simply invokes app.log', done => {
const app = new Trails(testApp)
const TestController = class TestController extends Controller { }
app.once('trails:log', (level, [ msg ]) => {
assert.equal(level, 'info')
assert.equal(msg, 'hello from controller')
done()
})
new TestController(app).log('info', 'hello from controller')
})
})
})

@@ -1,3 +0,1 @@

'use strict'
const assert = require('assert')

@@ -57,3 +55,3 @@ const _ = require('lodash')

it('global variables should be immutable and error if mutation is attempted', () => {
assert.throws(() => delete global.Service, Error)
delete global.Service
assert(global.Service)

@@ -60,0 +58,0 @@ assert(Service)

@@ -1,5 +0,2 @@

'use strict'
const assert = require('assert')
const smokesignals = require('smokesignals')
const Trailpack = require('trailpack')

@@ -11,3 +8,2 @@ const lib = require('../../lib')

assert(global.ConfigNotDefinedError)
assert(global.LoggerNotDefinedError)
assert(global.ApiNotDefinedError)

@@ -30,8 +26,2 @@ assert(global.ConfigValueError)

})
describe('LoggerNotDefinedError', () => {
it('#name', () => {
const err = new LoggerNotDefinedError()
assert.equal(err.name, 'LoggerNotDefinedError')
})
})
describe('ApiNotDefinedError', () => {

@@ -91,5 +81,2 @@ it('#name', () => {

]
},
log: {
logger: new smokesignals.Logger('silent')
}

@@ -96,0 +83,0 @@ }

@@ -1,3 +0,1 @@

'use strict'
const assert = require('assert')

@@ -4,0 +2,0 @@ const Model = require('../../lib/Model')

@@ -1,3 +0,1 @@

'use strict'
const EventEmitter = require('events').EventEmitter

@@ -4,0 +2,0 @@ const assert = require('assert')

@@ -1,5 +0,5 @@

'use strict'
const assert = require('assert')
const Policy = require('../../lib/Policy')
const Trails = require('../../')
const testApp = require('../integration/testapp')

@@ -23,2 +23,16 @@ describe('lib/Policy', () => {

})
describe('#log', () => {
it('is a convenience method that simply invokes app.log', done => {
const app = new Trails(testApp)
const TestPolicy = class TestPolicy extends Policy { }
app.once('trails:log', (level, [ msg ]) => {
assert.equal(level, 'info')
assert.equal(msg, 'hello from policy')
done()
})
new TestPolicy(app).log('info', 'hello from policy')
})
})
})

@@ -1,3 +0,1 @@

'use strict'
const assert = require('assert')

@@ -4,0 +2,0 @@ const Model = require('../../lib/Model')

@@ -1,5 +0,5 @@

'use strict'
const assert = require('assert')
const Service = require('../../lib/Service')
const Trails = require('../../')
const testApp = require('../integration/testapp')

@@ -23,2 +23,16 @@ describe('lib/Service', () => {

})
describe('#log', () => {
it('is a convenience method that simply invokes app.log', done => {
const app = new Trails(testApp)
const TestService = class TestService extends Service { }
app.once('trails:log', (level, [ msg ]) => {
assert.equal(level, 'info')
assert.equal(msg, 'hello from service')
done()
})
new TestService(app).log('info', 'hello from service')
})
})
})

@@ -1,2 +0,1 @@

const smokesignals = require('smokesignals')
const TrailsApp = require('trails')

@@ -8,5 +7,5 @@ const app = new TrailsApp({

/**
* Write custom logic here to test out your Trails Controller on RunKit
* @return Promise or value
*/
* Write custom logic here to test out your Trails Controller on RunKit
* @return Promise or value
*/
runkitEndpoint (request) {

@@ -29,5 +28,2 @@ return {

]
},
log: {
logger: new smokesignals.Logger('debug')
}

@@ -34,0 +30,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc