|
1 | 1 | /*!
|
2 | 2 | * 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> |
4 | 4 | * @author Jason Dobry <[email protected]>
|
5 | 5 | * @copyright (c) 2014-2015 Jason Dobry
|
6 | 6 | * @license MIT <https://github.com/js-data/js-data-http/blob/master/LICENSE>
|
@@ -63,27 +63,18 @@ return /******/ (function(modules) { // webpackBootstrap
|
63 | 63 | /* 0 */
|
64 | 64 | /***/ function(module, exports, __webpack_require__) {
|
65 | 65 |
|
66 |
| - var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; |
67 |
| - |
68 | 66 | var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } };
|
69 | 67 |
|
70 | 68 | 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; }; })();
|
71 | 69 |
|
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); |
80 | 71 | var axios = null;
|
81 | 72 |
|
82 | 73 | try {
|
83 | 74 | axios = __webpack_require__(2);
|
84 | 75 | } catch (e) {}
|
85 | 76 |
|
86 |
| - var DSUtils = _JSData2['default'].DSUtils; |
| 77 | + var DSUtils = JSData.DSUtils; |
87 | 78 | var deepMixIn = DSUtils.deepMixIn;
|
88 | 79 | var removeCircular = DSUtils.removeCircular;
|
89 | 80 | var copy = DSUtils.copy;
|
@@ -150,11 +141,64 @@ return /******/ (function(modules) { // webpackBootstrap
|
150 | 141 | }
|
151 | 142 |
|
152 | 143 | _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 | + }, { |
153 | 197 | key: 'getPath',
|
154 | 198 | value: function getPath(method, resourceConfig, id, options) {
|
155 | 199 | var _this = this;
|
156 | 200 | 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)]; |
158 | 202 | if (method === 'find' || method === 'update' || method === 'destroy') {
|
159 | 203 | args.push(id);
|
160 | 204 | }
|
@@ -345,8 +389,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
345 | 389 | return DSHttpAdapter;
|
346 | 390 | })();
|
347 | 391 |
|
348 |
| - exports['default'] = DSHttpAdapter; |
349 |
| - module.exports = exports['default']; |
| 392 | + module.exports = DSHttpAdapter; |
350 | 393 |
|
351 | 394 | /***/ },
|
352 | 395 | /* 1 */
|
|
0 commit comments