diff --git a/lib/actions/app.coffee b/lib/actions/app.coffee index cc959195..ee04c3ed 100644 --- a/lib/actions/app.coffee +++ b/lib/actions/app.coffee @@ -7,7 +7,6 @@ log = require('../log/log') resin = require('../resin') widgets = require('../widgets/widgets') patterns = require('../patterns/patterns') -applicationModel = require('../models/application') authHooks = require('../hooks/auth') config = require('../config') @@ -29,14 +28,14 @@ exports.create = authHooks.failIfNotLoggedIn (name, program) -> # Maybe we should break or handle better? slugifiedType = device.getDeviceSlug(type) - applicationModel.create(name, slugifiedType).then -> + resin.models.application.create(name, slugifiedType).then -> return callback() .catch(callback) ], errors.handle exports.list = authHooks.failIfNotLoggedIn -> - applicationModel.getAll().then (applications) -> + resin.models.application.getAll().then (applications) -> log.out table.horizontal applications, (application) -> application.device_type = device.getDisplayName(application.device_type) @@ -50,7 +49,7 @@ exports.list = authHooks.failIfNotLoggedIn -> .catch(errors.handle) exports.info = authHooks.failIfNotLoggedIn (id) -> - applicationModel.get(id).then (application) -> + resin.models.application.get(id).then (application) -> log.out table.vertical application, (application) -> application.device_type = device.getDisplayName(application.device_type) @@ -67,7 +66,7 @@ exports.restart = authHooks.failIfNotLoggedIn (id) -> exports.remove = authHooks.failIfNotLoggedIn (id, program) -> patterns.remove 'application', program.parent.yes, (callback) -> - applicationModel.remove(id).then -> + resin.models.application.remove(id).then -> return callback() .catch(callback) , errors.handle diff --git a/lib/actions/device.coffee b/lib/actions/device.coffee index 5987cab8..1374667b 100644 --- a/lib/actions/device.coffee +++ b/lib/actions/device.coffee @@ -1,4 +1,3 @@ -deviceModel = require('../models/device') getDeviceDisplayName = require('../device/device').getDisplayName log = require('../log/log') table = require('../table/table') @@ -10,7 +9,7 @@ authHooks = require('../hooks/auth') config = require('../config') exports.list = authHooks.failIfNotLoggedIn (applicationId) -> - deviceModel.getAll(applicationId).then (devices) -> + resin.models.device.getAll(applicationId).then (devices) -> log.out table.horizontal devices, (device) -> device.application = device.application[0].app_name @@ -26,7 +25,7 @@ exports.list = authHooks.failIfNotLoggedIn (applicationId) -> exports.remove = authHooks.failIfNotLoggedIn (id, program) -> patterns.remove 'device', program.parent.yes, (callback) -> - deviceModel.remove(id).then -> + resin.models.device.remove(id).then -> return callback() .catch(callback) , errors.handle diff --git a/lib/actions/environment-variables.coffee b/lib/actions/environment-variables.coffee index ff703e84..d384633c 100644 --- a/lib/actions/environment-variables.coffee +++ b/lib/actions/environment-variables.coffee @@ -3,7 +3,7 @@ table = require('../table/table') errors = require('../errors/errors') patterns = require('../patterns/patterns') log = require('../log/log') -environemtVariablesModel = require('../models/environment-variables') +resin = require('../resin') authHooks = require('../hooks/auth') SYSTEM_VAR_REGEX = /^RESIN_/ @@ -17,7 +17,7 @@ exports.list = authHooks.failIfNotLoggedIn (program) -> if not applicationId? errors.handle(new Error('You have to specify an application')) - environemtVariablesModel.getAll(applicationId).then (environmentVariables) -> + resin.models.environmentVariables.getAll(applicationId).then (environmentVariables) -> if not program.parent.verbose? environmentVariables = _.reject(environmentVariables, isSystemVariable) @@ -27,7 +27,7 @@ exports.list = authHooks.failIfNotLoggedIn (program) -> exports.remove = authHooks.failIfNotLoggedIn (id, program) -> patterns.remove 'environment variable', program.parent.yes, (callback) -> - environemtVariablesModel.remove(id).then -> + resin.models.environmentVariables.remove(id).then -> return callback() .catch(callback) , errors.handle diff --git a/lib/actions/keys.coffee b/lib/actions/keys.coffee index d4b26f41..eb2627c9 100644 --- a/lib/actions/keys.coffee +++ b/lib/actions/keys.coffee @@ -6,7 +6,6 @@ patterns = require('../patterns/patterns') table = require('../table/table') helpers = require('../helpers/helpers') errors = require('../errors/errors') -keyModel = require('../models/key') config = require('../config') exports.list = authHooks.failIfNotLoggedIn -> diff --git a/lib/models/key.coffee b/lib/models/key.coffee deleted file mode 100644 index 356e36a9..00000000 --- a/lib/models/key.coffee +++ /dev/null @@ -1,5 +0,0 @@ -canvas = require('./_canvas') - -exports.getAll = -> - return canvas.get - resource: 'user__has__public_key' diff --git a/lib/resin/index.coffee b/lib/resin/index.coffee index c91d4ab2..634ea284 100644 --- a/lib/resin/index.coffee +++ b/lib/resin/index.coffee @@ -1,2 +1,3 @@ module.exports = server: require('./server/server') + models: require('./models') diff --git a/lib/models/_canvas.coffee b/lib/resin/models/_canvas.coffee similarity index 77% rename from lib/models/_canvas.coffee rename to lib/resin/models/_canvas.coffee index 24734814..bf2ec1f6 100644 --- a/lib/models/_canvas.coffee +++ b/lib/resin/models/_canvas.coffee @@ -1,9 +1,9 @@ _ = require('lodash') Canvas = require('resin-platform-api') Promise = require('bluebird') -config = require('../config') -resin = require('../resin') -promisifiedServerRequest = Promise.promisify(resin.server.request) +config = require('../../config') +server = require('../server/server') +promisifiedServerRequest = Promise.promisify(server.request, server) class CanvasRequestService extends Canvas(_, Promise) _request: (params) -> diff --git a/lib/models/_canvas.spec.coffee b/lib/resin/models/_canvas.spec.coffee similarity index 89% rename from lib/models/_canvas.spec.coffee rename to lib/resin/models/_canvas.spec.coffee index 4c78409d..52d525db 100644 --- a/lib/models/_canvas.spec.coffee +++ b/lib/resin/models/_canvas.spec.coffee @@ -6,9 +6,9 @@ chaiAsPromised = require('chai-as-promised') expect = chai.expect chai.use(chaiAsPromised) -mock = require('../../tests/utils/mock') +mock = require('../../../tests/utils/mock') canvas = require('./_canvas') -config = require('../config') +config = require('../../config') URI = application: url.resolve(config.apiPrefix, 'application') diff --git a/lib/models/application.coffee b/lib/resin/models/application.coffee similarity index 95% rename from lib/models/application.coffee rename to lib/resin/models/application.coffee index 48e9ded0..178ce9d6 100644 --- a/lib/models/application.coffee +++ b/lib/resin/models/application.coffee @@ -1,7 +1,7 @@ _ = require('lodash') Promise = require('bluebird') canvas = require('./_canvas') -errors = require('../errors/errors') +errors = require('../../errors/errors') exports.getAll = -> return canvas.get diff --git a/lib/models/device.coffee b/lib/resin/models/device.coffee similarity index 91% rename from lib/models/device.coffee rename to lib/resin/models/device.coffee index 79a3eb91..6ccb29d9 100644 --- a/lib/models/device.coffee +++ b/lib/resin/models/device.coffee @@ -1,7 +1,7 @@ canvas = require('./_canvas') _ = require('lodash') Promise = require('bluebird') -errors = require('../errors/errors') +errors = require('../../errors/errors') exports.getAll = (applicationId) -> return canvas.get diff --git a/lib/models/environment-variables.coffee b/lib/resin/models/environment-variables.coffee similarity index 92% rename from lib/models/environment-variables.coffee rename to lib/resin/models/environment-variables.coffee index 06282a79..be0f66a7 100644 --- a/lib/models/environment-variables.coffee +++ b/lib/resin/models/environment-variables.coffee @@ -1,6 +1,6 @@ Promise = require('bluebird') canvas = require('./_canvas') -errors = require('../errors/errors') +errors = require('../../errors/errors') exports.getAll = (applicationId) -> return canvas.get diff --git a/lib/resin/models/index.coffee b/lib/resin/models/index.coffee new file mode 100644 index 00000000..38fad673 --- /dev/null +++ b/lib/resin/models/index.coffee @@ -0,0 +1,4 @@ +module.exports = + application: require('./application') + device: require('./device') + environmentVariables: require('./environment-variables')