Adding autobind decorator to server

This commit is contained in:
John Lyon-Smith
2018-03-26 11:37:18 -07:00
parent 80c37f8642
commit 49ca7f3bf1
18 changed files with 51 additions and 55 deletions

View File

@@ -7,6 +7,7 @@
}]
],
"plugins": [
"transform-decorators-legacy",
"transform-class-properties",
"transform-object-rest-spread"
]

View File

@@ -566,6 +566,12 @@
"integrity": "sha1-1+sjt5oxf4VDlixQW4J8fWysJ94=",
"dev": true
},
"babel-plugin-syntax-decorators": {
"version": "6.13.0",
"resolved": "https://registry.npmjs.org/babel-plugin-syntax-decorators/-/babel-plugin-syntax-decorators-6.13.0.tgz",
"integrity": "sha1-MSVjtNvePMgGzuPkFszurd0RrAs=",
"dev": true
},
"babel-plugin-syntax-exponentiation-operator": {
"version": "6.13.0",
"resolved": "https://registry.npmjs.org/babel-plugin-syntax-exponentiation-operator/-/babel-plugin-syntax-exponentiation-operator-6.13.0.tgz",
@@ -607,6 +613,17 @@
"babel-template": "6.26.0"
}
},
"babel-plugin-transform-decorators-legacy": {
"version": "1.3.4",
"resolved": "https://registry.npmjs.org/babel-plugin-transform-decorators-legacy/-/babel-plugin-transform-decorators-legacy-1.3.4.tgz",
"integrity": "sha1-dBtY9sW86eYCfgiC2cmU8E82aSU=",
"dev": true,
"requires": {
"babel-plugin-syntax-decorators": "6.13.0",
"babel-runtime": "6.26.0",
"babel-template": "6.26.0"
}
},
"babel-plugin-transform-es2015-arrow-functions": {
"version": "6.22.0",
"resolved": "https://registry.npmjs.org/babel-plugin-transform-es2015-arrow-functions/-/babel-plugin-transform-es2015-arrow-functions-6.22.0.tgz",

View File

@@ -54,17 +54,18 @@
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-env": "^1.5.2",
"jest": "^21.1.0",
"monzilla": "^1.1.0"
},
"private": true,
"keywords": {
"0": "rest",
"1": "api",
"2": "deighton"
},
"keywords": [
"rest",
"api",
"deighton"
],
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/KingstonSoftware/deighton-ar.git"

View File

@@ -1,11 +1,11 @@
import childProcess from 'child_process'
import path from 'path'
import timers from 'timers'
import autoBind from 'auto-bind2'
import autobind from 'autobind-decorator'
@autobind
export class ServerTool {
constructor(toolName, log) {
autoBind(this)
this.toolName = toolName
this.log = log
this.actors = [

View File

@@ -1,13 +0,0 @@
{
"presets": [
[ "env", {
"targets": {
"node": 8
}
}]
],
"plugins": [
"transform-class-properties",
"transform-object-rest-spread"
]
}

View File

@@ -1,7 +0,0 @@
.DS_STORE
*.log
node_modules
dist
coverage
**/local*.json*
.idea/

View File

@@ -1,10 +1,10 @@
import amqp from 'amqplib'
import uuidv4 from 'uuid/v4'
import autoBind from 'auto-bind2'
import autobind from 'autobind-decorator'
@autobind
export class MQ {
constructor(container) {
autoBind(this)
this.container = container
this.log = container.log
this.replyQueueName = `reply-${uuidv4()}`

View File

@@ -1,13 +1,13 @@
import IOServer from 'socket.io'
import autoBind from 'auto-bind2'
import autobind from 'autobind-decorator'
@autobind
export class WS {
constructor(container) {
this.log = container.log
this.io = new IOServer(container.server, { path: '/socketio' })
this.socketMap = {}
this.db = container.db
autoBind(this)
}
listen() {

View File

@@ -5,7 +5,7 @@ import createError from 'http-errors'
import path from 'path'
import util from 'util'
import config from 'config'
import autoBind from 'auto-bind2'
import autobind from 'autobind-decorator'
function pipeToGridFS(readable, gfsWriteable) {
const promise = new Promise((resolve, reject) => {
@@ -23,6 +23,7 @@ function pipeToGridFS(readable, gfsWriteable) {
return promise
}
@autobind
export class AssetRoutes {
static rangeRegex = /^byte (\d+)/
@@ -32,7 +33,6 @@ export class AssetRoutes {
this.db = container.db
this.rs = container.rs
this.uploadTimeout = config.get('api.uploadTimout')
autoBind(this)
app.route('/assets/:_id')
.get(passport.authenticate('bearer', { session: false }), this.getAsset)
.delete(passport.authenticate('bearer', { session: false }), this.deleteAsset)

View File

@@ -6,9 +6,10 @@ import crypto from 'crypto'
import urlSafeBase64 from 'urlsafe-base64'
import util from 'util'
import * as loginToken from './loginToken'
import autoBind from 'auto-bind2'
import autobind from 'autobind-decorator'
import url from 'url'
@autobind
export class AuthRoutes {
constructor(container) {
const app = container.app
@@ -20,7 +21,6 @@ export class AuthRoutes {
this.sendEmailDelayInSeconds = config.get('email.sendEmailDelayInSeconds')
this.supportEmail = config.get('email.supportEmail')
this.sendEmail = config.get('email.sendEmail')
autoBind(this)
app.route('/auth/login')
// Used to login. Email must be confirmed.
.post(this.login)
@@ -194,7 +194,7 @@ export class AuthRoutes {
if (this.sendEmail) {
await this.mq.request('dar-email', 'sendEmail', msgs)
}
res.json({})
} catch(err) {
if (err instanceof createError.HttpError) {

View File

@@ -1,8 +1,9 @@
import passport from 'passport'
import createError from 'http-errors'
import { makeFingerprint } from '../makeFingerprint'
import autoBind from 'auto-bind2'
import autobind from 'autobind-decorator'
@autobind
export class ProjectRoutes {
constructor(container) {
const app = container.app
@@ -11,7 +12,6 @@ export class ProjectRoutes {
this.db = container.db
this.mq = container.mq
this.ws = container.ws
autoBind(this)
app.route('/projects')
.get(passport.authenticate('bearer', { session: false }), this.listProjects)

View File

@@ -4,9 +4,10 @@ import crypto from 'crypto'
import urlSafeBase64 from 'urlsafe-base64'
import url from 'url'
import util from 'util'
import autoBind from 'auto-bind2'
import autobind from 'autobind-decorator'
import config from 'config'
@autobind
export class UserRoutes {
constructor(container) {
const app = container.app
@@ -17,7 +18,6 @@ export class UserRoutes {
this.ws = container.ws
this.maxEmailTokenAgeInHours = config.get('email.maxEmailTokenAgeInHours')
this.sendEmail = config.get('email.sendEmail')
autoBind(this)
app.route('/users')
.get(passport.authenticate('bearer', { session: false }), this.listUsers)
// Add a new user, send email confirmation email

View File

@@ -7,12 +7,11 @@ import readlineSync from 'readline-sync'
import crypto from 'crypto'
import urlSafeBase64 from 'urlsafe-base64'
import util from 'util'
import autobind from 'autobind-decorator'
import autoBind from 'auto-bind2'
@autobind
class AddUserTool {
constructor(toolName, log) {
autoBind(this)
this.toolName = toolName
this.log = log
}

View File

@@ -4,11 +4,11 @@ import JSON5 from 'json5'
import fs from 'fs'
import uuidv4 from 'uuid/v4'
import chalk from 'chalk'
import autoBind from 'auto-bind2'
import autobind from 'autobind-decorator'
@autobind
class SendMessageTool {
constructor(toolName, log) {
autoBind(this)
this.toolName = toolName
this.log = log
}

View File

@@ -2,18 +2,17 @@ import mongoose from 'mongoose'
import mongodb from 'mongodb'
import Grid from 'gridfs-stream'
import merge from 'mongoose-merge-plugin'
import autoBind from 'auto-bind2'
import autobind from 'autobind-decorator'
import * as Schemas from './schemas'
import util from 'util'
Grid.mongo = mongoose.mongo
@autobind
export class DB {
constructor() {
mongoose.Promise = Promise
mongoose.plugin(merge)
autoBind(this)
}
connect(mongoUri, isProduction) {

View File

@@ -8,8 +8,9 @@ import appRoot from 'app-root-path'
import JSON5 from 'json5'
import aws from 'aws-sdk'
import config from 'config'
import autoBind from 'auto-bind2'
import autobind from 'autobind-decorator'
@autobind
export class EmailHandlers {
constructor(container) {
this.log = container.log
@@ -35,8 +36,6 @@ export class EmailHandlers {
html: def.html ? handlebars.compile(fs.readFileSync(def.html).toString()) : null
}
}
autoBind(this)
}
sendEmail(options) {

View File

@@ -2,7 +2,7 @@ import Canvas from 'canvas'
import fs from 'fs'
import util from 'util'
import createError from 'http-errors'
import autoBind from 'auto-bind2'
import autobind from 'autobind-decorator'
import stream from 'stream'
function streamToBuffer(readable) {
@@ -132,11 +132,11 @@ function normalizeOrientation(image, orientation) {
return loadImage(canvas.toBuffer())
}
@autobind
export class ImageHandlers {
constructor(container) {
this.db = container.db
this.log = container.log
autoBind(this)
}
scaleImage(options) {

View File

@@ -1,14 +1,14 @@
import amqp from 'amqplib'
import autoBind from 'auto-bind2'
import autobind from 'autobind-decorator'
import createError from 'http-errors'
@autobind
export class MS {
constructor(exchangeName, options, log) {
this.exchangeName = exchangeName
this.options = options || {}
this.isProduction = (process.env.NODE_ENV === 'production')
this.log = log
autoBind(this)
}
async connect(amqpUri) {