Skip to content

Commit 6b8a784

Browse files
committed
Preparing for 2.0.0-rc.1.
Added getEndpoint(), which was removed from JSData.
1 parent db1574a commit 6b8a784

7 files changed

+126
-36
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
##### 2.0.0-rc.1 - xx June 2015
2+
3+
Added `getEndpoint()`, which was removed from JSData
4+
15
##### 2.0.0-beta.1 - 17 April 2015
26

37
Prepare for 2.0

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
"karma.start.js"
3030
],
3131
"dependencies": {
32-
"js-data": "2.0.0-beta.1"
32+
"js-data": "2.0.0-rc.1"
3333
}
3434
}

dist/js-data-http.js

+58-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* js-data-http
3-
* @version 2.0.0-beta.3 - Homepage <http://www.js-data.io/docs/dshttpadapter>
3+
* @version 2.0.0-rc.1 - Homepage <http://www.js-data.io/docs/dshttpadapter>
44
* @author Jason Dobry <[email protected]>
55
* @copyright (c) 2014-2015 Jason Dobry
66
* @license MIT <https://github.com/js-data/js-data-http/blob/master/LICENSE>
@@ -63,27 +63,18 @@ return /******/ (function(modules) { // webpackBootstrap
6363
/* 0 */
6464
/***/ function(module, exports, __webpack_require__) {
6565

66-
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; };
67-
6866
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } };
6967

7068
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
7169

72-
Object.defineProperty(exports, '__esModule', {
73-
value: true
74-
});
75-
76-
var _JSData = __webpack_require__(1);
77-
78-
var _JSData2 = _interopRequireWildcard(_JSData);
79-
70+
var JSData = __webpack_require__(1);
8071
var axios = null;
8172

8273
try {
8374
axios = __webpack_require__(2);
8475
} catch (e) {}
8576

86-
var DSUtils = _JSData2['default'].DSUtils;
77+
var DSUtils = JSData.DSUtils;
8778
var deepMixIn = DSUtils.deepMixIn;
8879
var removeCircular = DSUtils.removeCircular;
8980
var copy = DSUtils.copy;
@@ -150,11 +141,64 @@ return /******/ (function(modules) { // webpackBootstrap
150141
}
151142

152143
_createClass(DSHttpAdapter, [{
144+
key: 'getEndpoint',
145+
value: function getEndpoint(resourceConfig, id, options) {
146+
var _this = this;
147+
148+
options = options || {};
149+
options.params = options.params || {};
150+
151+
var item = undefined;
152+
var parentKey = resourceConfig.parentKey;
153+
var endpoint = options.hasOwnProperty('endpoint') ? options.endpoint : resourceConfig.endpoint;
154+
var parentField = resourceConfig.parentField;
155+
var parentDef = resourceConfig.getResource(resourceConfig.parent);
156+
var parentId = options.params[parentKey];
157+
158+
if (parentId === false || !parentKey || !parentDef) {
159+
if (parentId === false) {
160+
delete options.params[parentKey];
161+
}
162+
return endpoint;
163+
} else {
164+
delete options.params[parentKey];
165+
166+
if (DSUtils._sn(id)) {
167+
item = resourceConfig.get(id);
168+
} else if (DSUtils._o(id)) {
169+
item = id;
170+
}
171+
172+
if (item) {
173+
parentId = parentId || item[parentKey] || (item[parentField] ? item[parentField][parentDef.idAttribute] : null);
174+
}
175+
176+
if (parentId) {
177+
var _ret = (function () {
178+
delete options.endpoint;
179+
var _options = {};
180+
DSUtils.forOwn(options, function (value, key) {
181+
_options[key] = value;
182+
});
183+
return {
184+
v: DSUtils.makePath(_this.getEndpoint(parentDef, parentId, DSUtils._(parentDef, _options)), parentId, endpoint)
185+
};
186+
})();
187+
188+
if (typeof _ret === 'object') {
189+
return _ret.v;
190+
}
191+
} else {
192+
return endpoint;
193+
}
194+
}
195+
}
196+
}, {
153197
key: 'getPath',
154198
value: function getPath(method, resourceConfig, id, options) {
155199
var _this = this;
156200
options = options || {};
157-
var args = [options.basePath || _this.defaults.basePath || resourceConfig.basePath, resourceConfig.getEndpoint(isString(id) || isNumber(id) || method === 'create' ? id : null, options)];
201+
var args = [options.basePath || _this.defaults.basePath || resourceConfig.basePath, this.getEndpoint(resourceConfig, isString(id) || isNumber(id) || method === 'create' ? id : null, options)];
158202
if (method === 'find' || method === 'update' || method === 'destroy') {
159203
args.push(id);
160204
}
@@ -345,8 +389,7 @@ return /******/ (function(modules) { // webpackBootstrap
345389
return DSHttpAdapter;
346390
})();
347391

348-
exports['default'] = DSHttpAdapter;
349-
module.exports = exports['default'];
392+
module.exports = DSHttpAdapter;
350393

351394
/***/ },
352395
/* 1 */

dist/js-data-http.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js-data-http.min.map

+1-1
Large diffs are not rendered by default.

package.json

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "js-data-http",
33
"description": "http adapter for js-data.",
4-
"version": "2.0.0-beta.3",
4+
"version": "2.0.0-rc.1",
55
"homepage": "http://www.js-data.io/docs/dshttpadapter",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/js-data/js-data-http.git"
99
},
1010
"author": {
1111
"name": "Jason Dobry",
12+
"url": "http://www.pseudobry.com",
1213
"email": "[email protected]"
1314
},
1415
"licenses": [
@@ -26,30 +27,30 @@
2627
"http"
2728
],
2829
"devDependencies": {
29-
"babel-core": "5.1.10",
30-
"babel-loader": "5.0.0",
31-
"es6-promise": "2.1.0",
30+
"babel-core": "5.6.15",
31+
"babel-loader": "5.2.2",
32+
"es6-promise": "2.3.0",
3233
"grunt": "0.4.5",
3334
"grunt-contrib-clean": "0.6.0",
3435
"grunt-contrib-uglify": "0.9.1",
3536
"grunt-contrib-watch": "0.6.1",
36-
"grunt-karma": "0.10.1",
37+
"grunt-karma": "0.11.1",
3738
"grunt-karma-coveralls": "2.5.3",
3839
"grunt-webpack": "1.0.8",
3940
"jit-grunt": "0.9.1",
4041
"jshint-loader": "0.8.3",
41-
"karma": "0.12.31",
42+
"karma": "0.12.37",
4243
"karma-chai": "0.1.0",
43-
"karma-chrome-launcher": "0.1.8",
44-
"karma-coverage": "0.3.1",
45-
"karma-firefox-launcher": "0.1.4",
46-
"karma-mocha": "0.1.10",
47-
"karma-phantomjs-launcher": "0.1.4",
44+
"karma-chrome-launcher": "0.2.0",
45+
"karma-coverage": "0.4.2",
46+
"karma-firefox-launcher": "0.1.6",
47+
"karma-mocha": "0.2.0",
48+
"karma-phantomjs-launcher": "0.2.0",
4849
"karma-script-launcher": "0.1.0",
4950
"karma-sinon": "1.0.4",
5051
"karma-spec-reporter": "0.0.19",
51-
"time-grunt": "1.1.1",
52-
"webpack-dev-server": "1.8.0"
52+
"time-grunt": "1.2.1",
53+
"webpack-dev-server": "1.9.0"
5354
},
5455
"scripts": {
5556
"test": "grunt test"
@@ -59,6 +60,6 @@
5960
"mout": "0.11.0"
6061
},
6162
"peerDependencies": {
62-
"js-data": ">=2.0.0-beta.3"
63+
"js-data": "2.0.0-rc.1"
6364
}
6465
}

src/index.js

+45-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import JSData from 'js-data';
1+
let JSData = require('js-data');
22
let axios = null;
33

44
try {
@@ -52,12 +52,54 @@ class DSHttpAdapter {
5252
this.http = options.http || axios;
5353
}
5454

55+
getEndpoint(resourceConfig, id, options) {
56+
options = options || {};
57+
options.params = options.params || {};
58+
59+
let item;
60+
let parentKey = resourceConfig.parentKey;
61+
let endpoint = options.hasOwnProperty('endpoint') ? options.endpoint : resourceConfig.endpoint;
62+
let parentField = resourceConfig.parentField;
63+
let parentDef = resourceConfig.getResource(resourceConfig.parent);
64+
let parentId = options.params[parentKey];
65+
66+
if (parentId === false || !parentKey || !parentDef) {
67+
if (parentId === false) {
68+
delete options.params[parentKey];
69+
}
70+
return endpoint;
71+
} else {
72+
delete options.params[parentKey];
73+
74+
if (DSUtils._sn(id)) {
75+
item = resourceConfig.get(id);
76+
} else if (DSUtils._o(id)) {
77+
item = id;
78+
}
79+
80+
if (item) {
81+
parentId = parentId || item[parentKey] || (item[parentField] ? item[parentField][parentDef.idAttribute] : null);
82+
}
83+
84+
if (parentId) {
85+
delete options.endpoint;
86+
let _options = {};
87+
DSUtils.forOwn(options, (value, key) => {
88+
_options[key] = value;
89+
});
90+
return DSUtils.makePath(this.getEndpoint(parentDef, parentId, DSUtils._(parentDef, _options)), parentId, endpoint);
91+
} else {
92+
return endpoint;
93+
}
94+
}
95+
}
96+
5597
getPath(method, resourceConfig, id, options) {
5698
let _this = this;
5799
options = options || {};
58100
let args = [
59101
options.basePath || _this.defaults.basePath || resourceConfig.basePath,
60-
resourceConfig.getEndpoint((isString(id) || isNumber(id) || method === 'create') ? id : null, options)
102+
this.getEndpoint(resourceConfig, (isString(id) || isNumber(id) || method === 'create') ? id : null, options)
61103
];
62104
if (method === 'find' || method === 'update' || method === 'destroy') {
63105
args.push(id);
@@ -246,5 +288,5 @@ class DSHttpAdapter {
246288
}
247289
}
248290

249-
export default DSHttpAdapter;
291+
module.exports = DSHttpAdapter;
250292

0 commit comments

Comments
 (0)