Skip to content

Commit

Permalink
Merge pull request #3 from listepo/listepo/patch
Browse files Browse the repository at this point in the history
Update dependencies and add travis
  • Loading branch information
IanVS committed Feb 18, 2016
2 parents 5902c29 + d394562 commit 8175203
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 29 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: node_js
node_js:
- "5"
- "4"
- "0.12"
before_script:
- "cd ./tests/dummy npm i"
script:
- "npm test"
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<p align="center"><img src="/../images/sails.png?raw=true" height="80"/><img src="/../images/jsonapi.png?raw=true" height="80"/></p>

# sails-hook-jsonapi
[![Build Status](https://travis-ci.org/IanVS/sails-hook-jsonapi.svg?branch=master)](https://travis-ci.org/listepo/sails-hook-jsonapi)
[![Dependency Status](https://david-dm.org/IanVS/sails-hook-jsonapi.svg)](https://david-dm.org/IanVS/sails-hook-jsonapi)
[![devDependency Status](https://david-dm.org/IanVS/sails-hook-jsonapi/dev-status.svg)](https://david-dm.org/IanVS/sails-hook-jsonapi#info=devDependencies)



This is a [Sails JS](http://sailsjs.org) hook for creating an API which conforms to JSON API specifications per jsonapi.org.

*Note*: This project is still in development, and is not yet fully functional.
*Note*: This project is still in development, and is not yet fully functional.

### Installation

Expand Down
7 changes: 3 additions & 4 deletions lib/hook.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use strict';

module.exports = function jsonApiHook(sails) {

let moduleUtils = require('./utils/module-utils');
let _ = require('lodash');
var moduleUtils = require('./utils/module-utils');
var _ = require('lodash');

return {

Expand All @@ -16,7 +15,7 @@ module.exports = function jsonApiHook(sails) {
},

loadModules: function (cb) {
let hook = this;
var hook = this;
moduleUtils.loadResponses(sails, function loadedJsonapiResponseModules(err, responseDefs) {
if (err) return cb(err);
// Register responses as middleware
Expand Down
1 change: 0 additions & 1 deletion lib/responses/ok.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

/**
* 200 (OK) Response
*
Expand Down
10 changes: 5 additions & 5 deletions lib/utils/model-utils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

let pluralize = require('pluralize');
var pluralize = require('pluralize');

// Only attributes which are not primary key ('id') or have an alias (relationship)
exports.getOwnAttributes = function (Model) {
let ownAttrs = [];
var ownAttrs = [];
Object.keys(Model.definition).forEach(function (key) {
if (!Model.definition[key].primaryKey && !Model.definition[key].alias) {
ownAttrs.push(key);
Expand All @@ -24,7 +24,7 @@ exports.getRef = function (Model, cb) {

// Only strips primary key ('id')
exports.getAttributes = function (Model) {
let attrs = [];
var attrs = [];
Object.keys(Model._attributes).forEach(function (key) {
if (!Model._attributes[key].primaryKey) {
attrs.push(key);
Expand All @@ -40,9 +40,9 @@ exports.getModelName = function (req) {

// Returns singular-ized model names of related models
exports.getRelatedModelNames = function (req) {
let rels = [];
var rels = [];
req.options.associations.forEach(function (assoc) {
let model = pluralize(assoc.alias, 1);
var model = pluralize(assoc.alias, 1);
rels.push(model);
});
return rels;
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/module-utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

let buildDictionary = require('sails-build-dictionary');
let path = require('path');
let _ = require('lodash');
var buildDictionary = require('sails-build-dictionary');
var path = require('path');
var _ = require('lodash');

function bindToSails(sails, cb) {
return function (err, modules) {
Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"scripts": {
"test": "tape tests/responses/*.js | tap-spec",
"lint": "eslint lib/ tests/responses/",
"pretest": "npm run lint"
"pretest": "npm run lint",
"postinstall": "cd ./tests/dummy && npm i"
},
"keywords": [
"sails",
Expand All @@ -28,17 +29,19 @@
"url": "https://github.com/IanVS/sails-hook-jsonapi"
},
"dependencies": {
"jsonapi-serializer": "SeyZ/jsonapi-serializer#2.0.0-beta.1",
"jsonapi-serializer": "^2.0.4",
"lodash": "^4.5.0",
"pluralize": "^1.1.2",
"sails-build-dictionary": "^0.10.1"
},
"devDependencies": {
"barrels": "^1.5.0",
"eslint": "^1.0.0",
"eslint": "^1.10.3",
"eslint-config-ianvs": "^0.0.6",
"eslint-config-standard": "^4.0.0",
"eslint-config-standard": "^4.4.0",
"eslint-plugin-promise": "^1.0.8",
"eslint-plugin-standard": "^1.1.0",
"sails": "^0.11.0",
"sails": "^0.12.1",
"sails-memory": "^0.10.5",
"tap-spec": "^4.0.2",
"tape": "^4.0.1",
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"grunt-sync": "~0.0.4",
"include-all": "~0.1.3",
"rc": "~0.5.0",
"sails": "~0.11.0",
"sails": "~0.12.1",
"sails-disk": "~0.10.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/load-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

let path = require('path');
var path = require('path');

module.exports = {
appPath: path.join(process.cwd(), 'tests/dummy'),
Expand Down
16 changes: 8 additions & 8 deletions tests/responses/ok-test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* global User, Author, Book */
'use strict';

let Barrels = require('barrels');
let path = require('path');
let Sails = require('sails').Sails;
let test = require('tape-catch');
let loadConfig = require('../helpers/load-config');
let fixtures,
var Barrels = require('barrels');
var path = require('path');
var Sails = require('sails').Sails;
var test = require('tape-catch');
var loadConfig = require('../helpers/load-config');
var fixtures,
barrels,
sails;

test('Sails does not crash', function (t) {
Expand All @@ -16,7 +17,7 @@ test('Sails does not crash', function (t) {
t.fail(err);
}
sails = _sails;
let barrels = new Barrels(path.join(process.cwd(), '/tests/fixtures'));
barrels = new Barrels(path.join(process.cwd(), '/tests/fixtures'));
fixtures = barrels.data;
barrels.populate(function (err) {
if (err) {
Expand Down Expand Up @@ -101,7 +102,6 @@ test('Returns correct attributes', function (t) {
}
t.end();
});

});

test('Returns correct nested resources', function (t) {
Expand Down

0 comments on commit 8175203

Please sign in to comment.