restql 1.1.6 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +20 -34
- package/dist/cjs/index.js +72 -429
- package/dist/esm/index.js +189 -0
- package/dist/umd/index.js +11890 -20478
- package/dist/umd/index.min.js +7 -1
- package/package.json +48 -60
- package/dist/es/index.js +0 -544
package/package.json
CHANGED
|
@@ -1,86 +1,74 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "restql",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "RESTful API Resolver for Nested-Linked Resources | 🕸 🕷",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "./dist/cjs/index.js",
|
|
6
|
-
"module": "./dist/
|
|
7
|
+
"module": "./dist/esm/index.js",
|
|
8
|
+
"unpkg": "./dist/umd/index.js",
|
|
7
9
|
"files": [
|
|
8
10
|
"dist/"
|
|
9
11
|
],
|
|
10
12
|
"scripts": {
|
|
11
|
-
"prepare": "npm run
|
|
12
|
-
"
|
|
13
|
-
"lint": "
|
|
14
|
-
"lint:
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"test": "npm run test
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"build": "
|
|
22
|
-
"build:
|
|
23
|
-
"build:es": "cross-env BABEL_ENV=production NODE_ENV=development RESTQL_FMT=es rollup --config",
|
|
24
|
-
"build:umd": "cross-env BABEL_ENV=production NODE_ENV=development RESTQL_FMT=umd rollup --config",
|
|
25
|
-
"build:umd:min": "cross-env BABEL_ENV=production NODE_ENV=production RESTQL_FMT=umd rollup --config"
|
|
13
|
+
"prepare": "npm run clear && npm run lint && npm run test && npm run build",
|
|
14
|
+
"clear": "rm -fr ./coverage/ ./dist/ ./stats.html",
|
|
15
|
+
"lint": "eslint ./src/",
|
|
16
|
+
"lint:fix": "npm run lint -- --fix",
|
|
17
|
+
"test": "jest --config ./.jest.config.json",
|
|
18
|
+
"test:coverage": "npm run test -- --coverage",
|
|
19
|
+
"test:watch": "npm run test -- --watch",
|
|
20
|
+
"build": "npm run build:cjs && npm run build:esm && npm run build:umd && npm run build:umd:min",
|
|
21
|
+
"build:cjs": "BABEL_ENV=production MODULE_FMT=cjs rollup --config",
|
|
22
|
+
"build:esm": "BABEL_ENV=production MODULE_FMT=esm rollup --config",
|
|
23
|
+
"build:umd": "BABEL_ENV=production MODULE_FMT=umd rollup --config",
|
|
24
|
+
"build:umd:min": "BABEL_ENV=production MODULE_FMT=umd MINIFY=true rollup --config"
|
|
26
25
|
},
|
|
27
26
|
"repository": {
|
|
28
27
|
"type": "git",
|
|
29
28
|
"url": "git+https://github.com/relztic/restql.git"
|
|
30
29
|
},
|
|
31
30
|
"keywords": [
|
|
32
|
-
"
|
|
31
|
+
"package",
|
|
32
|
+
"javascript",
|
|
33
33
|
"rest",
|
|
34
34
|
"api",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"node",
|
|
38
|
-
"npm",
|
|
39
|
-
"yarn"
|
|
35
|
+
"recursive",
|
|
36
|
+
"resolver"
|
|
40
37
|
],
|
|
41
|
-
"author": "Ariel
|
|
38
|
+
"author": "Ariel Díaz <relztic@gmail.com> (https://www.linkedin.com/in/relztic/)",
|
|
42
39
|
"license": "MIT",
|
|
43
40
|
"bugs": {
|
|
44
41
|
"url": "https://github.com/relztic/restql/issues/"
|
|
45
42
|
},
|
|
46
43
|
"homepage": "https://github.com/relztic/restql/#readme",
|
|
47
44
|
"dependencies": {
|
|
48
|
-
"axios": "^
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"url-regex": "^4.1.1"
|
|
45
|
+
"axios": "^1.13.6",
|
|
46
|
+
"lodash": "^4.17.23",
|
|
47
|
+
"md5": "^2.3.0",
|
|
48
|
+
"validator": "^13.15.26"
|
|
53
49
|
},
|
|
54
50
|
"devDependencies": {
|
|
55
|
-
"babel
|
|
56
|
-
"babel-
|
|
57
|
-
"babel
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"eslint": "^
|
|
65
|
-
"eslint-config-airbnb": "^
|
|
66
|
-
"eslint-
|
|
67
|
-
"eslint-plugin-
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"
|
|
77
|
-
"rollup-plugin-babel": "^3.0.3",
|
|
78
|
-
"rollup-plugin-commonjs": "^8.2.6",
|
|
79
|
-
"rollup-plugin-json": "^2.3.0",
|
|
80
|
-
"rollup-plugin-node-builtins": "^2.1.2",
|
|
81
|
-
"rollup-plugin-node-globals": "^1.1.0",
|
|
82
|
-
"rollup-plugin-node-resolve": "^3.0.0",
|
|
83
|
-
"rollup-plugin-uglify": "^2.0.1",
|
|
84
|
-
"rollup-plugin-visualizer": "^0.3.1"
|
|
51
|
+
"@babel/core": "^7.26.0",
|
|
52
|
+
"@babel/preset-env": "^7.26.0",
|
|
53
|
+
"@rollup/plugin-babel": "^6.1.0",
|
|
54
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
55
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
56
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
57
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
58
|
+
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
|
|
59
|
+
"eslint": "^10.0.2",
|
|
60
|
+
"eslint-config-prettier": "^10.1.8",
|
|
61
|
+
"eslint-flat-config-airbnb": "^2.0.5",
|
|
62
|
+
"eslint-plugin-jest": "^29.15.0",
|
|
63
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
64
|
+
"globals": "^17.3.0",
|
|
65
|
+
"jest": "^30.2.0",
|
|
66
|
+
"prettier": "^3.8.1",
|
|
67
|
+
"rollup": "^4.59.0",
|
|
68
|
+
"rollup-plugin-polyfill-node": "^0.13.0",
|
|
69
|
+
"rollup-plugin-visualizer": "^7.0.0"
|
|
70
|
+
},
|
|
71
|
+
"overrides": {
|
|
72
|
+
"serialize-javascript": "^7.0.3"
|
|
85
73
|
}
|
|
86
|
-
}
|
|
74
|
+
}
|
package/dist/es/index.js
DELETED
|
@@ -1,544 +0,0 @@
|
|
|
1
|
-
import _regeneratorRuntime from 'babel-runtime/regenerator';
|
|
2
|
-
import cloneDeep from 'lodash/cloneDeep';
|
|
3
|
-
import merge from 'lodash/merge';
|
|
4
|
-
import axios from 'axios';
|
|
5
|
-
import md5 from 'md5';
|
|
6
|
-
import UrlRegex from 'url-regex';
|
|
7
|
-
|
|
8
|
-
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
|
9
|
-
return typeof obj;
|
|
10
|
-
} : function (obj) {
|
|
11
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var asyncToGenerator = function (fn) {
|
|
23
|
-
return function () {
|
|
24
|
-
var gen = fn.apply(this, arguments);
|
|
25
|
-
return new Promise(function (resolve, reject) {
|
|
26
|
-
function step(key, arg) {
|
|
27
|
-
try {
|
|
28
|
-
var info = gen[key](arg);
|
|
29
|
-
var value = info.value;
|
|
30
|
-
} catch (error) {
|
|
31
|
-
reject(error);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (info.done) {
|
|
36
|
-
resolve(value);
|
|
37
|
-
} else {
|
|
38
|
-
return Promise.resolve(value).then(function (value) {
|
|
39
|
-
step("next", value);
|
|
40
|
-
}, function (err) {
|
|
41
|
-
step("throw", err);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return step("next");
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
var defineProperty = function (obj, key, value) {
|
|
60
|
-
if (key in obj) {
|
|
61
|
-
Object.defineProperty(obj, key, {
|
|
62
|
-
value: value,
|
|
63
|
-
enumerable: true,
|
|
64
|
-
configurable: true,
|
|
65
|
-
writable: true
|
|
66
|
-
});
|
|
67
|
-
} else {
|
|
68
|
-
obj[key] = value;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return obj;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
var _extends = Object.assign || function (target) {
|
|
75
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
76
|
-
var source = arguments[i];
|
|
77
|
-
|
|
78
|
-
for (var key in source) {
|
|
79
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
80
|
-
target[key] = source[key];
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return target;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
var slicedToArray = function () {
|
|
109
|
-
function sliceIterator(arr, i) {
|
|
110
|
-
var _arr = [];
|
|
111
|
-
var _n = true;
|
|
112
|
-
var _d = false;
|
|
113
|
-
var _e = undefined;
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
|
117
|
-
_arr.push(_s.value);
|
|
118
|
-
|
|
119
|
-
if (i && _arr.length === i) break;
|
|
120
|
-
}
|
|
121
|
-
} catch (err) {
|
|
122
|
-
_d = true;
|
|
123
|
-
_e = err;
|
|
124
|
-
} finally {
|
|
125
|
-
try {
|
|
126
|
-
if (!_n && _i["return"]) _i["return"]();
|
|
127
|
-
} finally {
|
|
128
|
-
if (_d) throw _e;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return _arr;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return function (arr, i) {
|
|
136
|
-
if (Array.isArray(arr)) {
|
|
137
|
-
return arr;
|
|
138
|
-
} else if (Symbol.iterator in Object(arr)) {
|
|
139
|
-
return sliceIterator(arr, i);
|
|
140
|
-
} else {
|
|
141
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
}();
|
|
145
|
-
|
|
146
|
-
// External Packages
|
|
147
|
-
/**
|
|
148
|
-
* @constant {Object} responses The responses to cache.
|
|
149
|
-
*/
|
|
150
|
-
var responses = {};
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Fetches a resource based on its options, if not cached.
|
|
154
|
-
*
|
|
155
|
-
* @param {string} resource The resource to fetch.
|
|
156
|
-
* @param {Object} options The options to bypass.
|
|
157
|
-
* @returns {Promise<Object>} A promise which resolves into an object.
|
|
158
|
-
*/
|
|
159
|
-
var fetchResource = (function () {
|
|
160
|
-
var _ref = asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(resource, options) {
|
|
161
|
-
var key;
|
|
162
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
163
|
-
while (1) {
|
|
164
|
-
switch (_context.prev = _context.next) {
|
|
165
|
-
case 0:
|
|
166
|
-
key = md5(resource + '-' + JSON.stringify(options));
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
if (!(key in responses)) {
|
|
170
|
-
responses[key] = axios(resource, options).then(function (response) {
|
|
171
|
-
responses[key] = response;
|
|
172
|
-
|
|
173
|
-
return response;
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return _context.abrupt('return', responses[key]);
|
|
178
|
-
|
|
179
|
-
case 3:
|
|
180
|
-
case 'end':
|
|
181
|
-
return _context.stop();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}, _callee, this);
|
|
185
|
-
}));
|
|
186
|
-
|
|
187
|
-
function fetchResource(_x, _x2) {
|
|
188
|
-
return _ref.apply(this, arguments);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return fetchResource;
|
|
192
|
-
})();
|
|
193
|
-
|
|
194
|
-
// External Packages
|
|
195
|
-
/**
|
|
196
|
-
* @constant {Object} urlRegex The URL regex to test.
|
|
197
|
-
*/
|
|
198
|
-
var urlRegex = UrlRegex({ exact: true });
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Determines whether or not a resource is valid.
|
|
202
|
-
*
|
|
203
|
-
* @param {string} resource The resource to test.
|
|
204
|
-
* @returns {boolean} Whether or not a resource is valid.
|
|
205
|
-
*/
|
|
206
|
-
function isResource(resource) {
|
|
207
|
-
return urlRegex.test(resource);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* @constant {string} PROP_DELIMITER The delimiter of a property.
|
|
212
|
-
*/
|
|
213
|
-
var PROP_DELIMITER = '.';
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* @constant {RegExp} REGEX_PROP_IS_ARR_IS_OPT Determines whether or not a property is an array and/or is optional.
|
|
217
|
-
*/
|
|
218
|
-
var REGEX_PROP_IS_ARR_IS_OPT = /^([^[\]?]+)(\[])?(\?)?$/;
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* @constant {Object} constants The constants of the library.
|
|
222
|
-
*/
|
|
223
|
-
var constants = Object.freeze({
|
|
224
|
-
PROP_DELIMITER: PROP_DELIMITER,
|
|
225
|
-
REGEX_PROP_IS_ARR_IS_OPT: REGEX_PROP_IS_ARR_IS_OPT
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
// Internal Packages
|
|
229
|
-
/**
|
|
230
|
-
* Gets the parsed properties from an object.
|
|
231
|
-
*
|
|
232
|
-
* @param {Object} obj The object to use.
|
|
233
|
-
* @param {string} props The properties to apply.
|
|
234
|
-
* @returns {Array} An array.
|
|
235
|
-
* @throws {RuntimeError} If a property could not be got.
|
|
236
|
-
*/
|
|
237
|
-
function objectGet(obj, props) {
|
|
238
|
-
var nextPropsArr = props.split(constants.PROP_DELIMITER);
|
|
239
|
-
|
|
240
|
-
var _ref = constants.REGEX_PROP_IS_ARR_IS_OPT.exec(nextPropsArr.shift()) || [],
|
|
241
|
-
_ref2 = slicedToArray(_ref, 4),
|
|
242
|
-
prop = _ref2[1],
|
|
243
|
-
isArr = _ref2[2],
|
|
244
|
-
isOpt = _ref2[3];
|
|
245
|
-
|
|
246
|
-
var nextProps = nextPropsArr.join(constants.PROP_DELIMITER);
|
|
247
|
-
|
|
248
|
-
if (!prop) {
|
|
249
|
-
return obj;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (!(prop in obj)) {
|
|
253
|
-
if (isOpt) {
|
|
254
|
-
return isArr ? [] : null;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
throw new Error('RuntimeError: could not get property `' + prop + '`');
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
var nextObjs = obj[prop];
|
|
261
|
-
|
|
262
|
-
return isArr ? nextObjs.map(function (nextObj) {
|
|
263
|
-
return objectGet(nextObj, nextProps);
|
|
264
|
-
}) : objectGet(nextObjs, nextProps);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// Internal Packages
|
|
268
|
-
/**
|
|
269
|
-
* Sets the parsed properties to an object.
|
|
270
|
-
*
|
|
271
|
-
* @param {Array} data The data to use.
|
|
272
|
-
* @param {string} props The properties to apply.
|
|
273
|
-
* @returns {Object} An object.
|
|
274
|
-
*/
|
|
275
|
-
function objectSet(data, props) {
|
|
276
|
-
var nextPropsArr = props.split(constants.PROP_DELIMITER);
|
|
277
|
-
|
|
278
|
-
var _ref = constants.REGEX_PROP_IS_ARR_IS_OPT.exec(nextPropsArr.shift()) || [],
|
|
279
|
-
_ref2 = slicedToArray(_ref, 3),
|
|
280
|
-
prop = _ref2[1],
|
|
281
|
-
isArr = _ref2[2];
|
|
282
|
-
|
|
283
|
-
var nextProps = nextPropsArr.join(constants.PROP_DELIMITER);
|
|
284
|
-
|
|
285
|
-
if (!prop) {
|
|
286
|
-
return data;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
return defineProperty({}, prop, isArr ? data.map(function (nextData) {
|
|
290
|
-
return objectSet(nextData, nextProps);
|
|
291
|
-
}) : objectSet(data, nextProps));
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// External Packages
|
|
295
|
-
// Internal Packages
|
|
296
|
-
/**
|
|
297
|
-
* Resolves the nested-linked resources of a RESTful API.
|
|
298
|
-
*
|
|
299
|
-
* @param {string} resource The resource to fetch.
|
|
300
|
-
* @param {Object} resolver The resolver to apply.
|
|
301
|
-
* @param {Object} options The options to bypass.
|
|
302
|
-
* @returns {Promise<Object>} A promise which resolves into an object.
|
|
303
|
-
* @throws {InvalidArgumentError} If a resource is invalid.
|
|
304
|
-
* @throws {RuntimeError} If a resource could not be fetched.
|
|
305
|
-
*/
|
|
306
|
-
var resolve = (function () {
|
|
307
|
-
var _ref = asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resource, resolver, options) {
|
|
308
|
-
var _this = this;
|
|
309
|
-
|
|
310
|
-
var response, obj, resourcesObj, resourcesArr, responses;
|
|
311
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
312
|
-
while (1) {
|
|
313
|
-
switch (_context3.prev = _context3.next) {
|
|
314
|
-
case 0:
|
|
315
|
-
if (resource) {
|
|
316
|
-
_context3.next = 2;
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
return _context3.abrupt('return', null);
|
|
321
|
-
|
|
322
|
-
case 2:
|
|
323
|
-
if (isResource(resource)) {
|
|
324
|
-
_context3.next = 4;
|
|
325
|
-
break;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
throw new Error('InvalidArgumentError: invalid resource `' + resource + '`');
|
|
329
|
-
|
|
330
|
-
case 4:
|
|
331
|
-
_context3.t0 = cloneDeep;
|
|
332
|
-
_context3.next = 7;
|
|
333
|
-
return fetchResource(resource, options);
|
|
334
|
-
|
|
335
|
-
case 7:
|
|
336
|
-
_context3.t1 = _context3.sent;
|
|
337
|
-
response = (0, _context3.t0)(_context3.t1);
|
|
338
|
-
|
|
339
|
-
if (response.config.validateStatus(response.status)) {
|
|
340
|
-
_context3.next = 11;
|
|
341
|
-
break;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
throw new Error('RuntimeError: could not fetch resource `' + resource + '`');
|
|
345
|
-
|
|
346
|
-
case 11:
|
|
347
|
-
obj = response.data;
|
|
348
|
-
|
|
349
|
-
if (resolver) {
|
|
350
|
-
_context3.next = 14;
|
|
351
|
-
break;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
return _context3.abrupt('return', obj);
|
|
355
|
-
|
|
356
|
-
case 14:
|
|
357
|
-
resourcesObj = Object.keys(resolver).map(function (props) {
|
|
358
|
-
return defineProperty({}, props, objectGet(obj, props));
|
|
359
|
-
});
|
|
360
|
-
resourcesArr = Object.entries(resourcesObj.reduce(function (result, val) {
|
|
361
|
-
return _extends({}, result, val);
|
|
362
|
-
}, {}));
|
|
363
|
-
_context3.next = 18;
|
|
364
|
-
return Promise.all(resourcesArr.map(function () {
|
|
365
|
-
var _ref4 = asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
|
|
366
|
-
var _ref5 = slicedToArray(_ref3, 2),
|
|
367
|
-
props = _ref5[0],
|
|
368
|
-
resources = _ref5[1];
|
|
369
|
-
|
|
370
|
-
var nextResolver, data;
|
|
371
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
372
|
-
while (1) {
|
|
373
|
-
switch (_context2.prev = _context2.next) {
|
|
374
|
-
case 0:
|
|
375
|
-
nextResolver = resolver[props];
|
|
376
|
-
|
|
377
|
-
if (!Array.isArray(resources)) {
|
|
378
|
-
_context2.next = 7;
|
|
379
|
-
break;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
_context2.next = 4;
|
|
383
|
-
return Promise.all(resources.map(function () {
|
|
384
|
-
var _ref6 = asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(nextResource) {
|
|
385
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
386
|
-
while (1) {
|
|
387
|
-
switch (_context.prev = _context.next) {
|
|
388
|
-
case 0:
|
|
389
|
-
return _context.abrupt('return', resolve(nextResource, nextResolver, options));
|
|
390
|
-
|
|
391
|
-
case 1:
|
|
392
|
-
case 'end':
|
|
393
|
-
return _context.stop();
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
}, _callee, _this);
|
|
397
|
-
}));
|
|
398
|
-
|
|
399
|
-
return function (_x5) {
|
|
400
|
-
return _ref6.apply(this, arguments);
|
|
401
|
-
};
|
|
402
|
-
}()));
|
|
403
|
-
|
|
404
|
-
case 4:
|
|
405
|
-
_context2.t0 = _context2.sent;
|
|
406
|
-
_context2.next = 10;
|
|
407
|
-
break;
|
|
408
|
-
|
|
409
|
-
case 7:
|
|
410
|
-
_context2.next = 9;
|
|
411
|
-
return resolve(resources, nextResolver, options);
|
|
412
|
-
|
|
413
|
-
case 9:
|
|
414
|
-
_context2.t0 = _context2.sent;
|
|
415
|
-
|
|
416
|
-
case 10:
|
|
417
|
-
data = _context2.t0;
|
|
418
|
-
return _context2.abrupt('return', [props, data]);
|
|
419
|
-
|
|
420
|
-
case 12:
|
|
421
|
-
case 'end':
|
|
422
|
-
return _context2.stop();
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}, _callee2, _this);
|
|
426
|
-
}));
|
|
427
|
-
|
|
428
|
-
return function (_x4) {
|
|
429
|
-
return _ref4.apply(this, arguments);
|
|
430
|
-
};
|
|
431
|
-
}()));
|
|
432
|
-
|
|
433
|
-
case 18:
|
|
434
|
-
responses = _context3.sent;
|
|
435
|
-
return _context3.abrupt('return', responses.reduce(function (result, _ref7) {
|
|
436
|
-
var _ref8 = slicedToArray(_ref7, 2),
|
|
437
|
-
props = _ref8[0],
|
|
438
|
-
data = _ref8[1];
|
|
439
|
-
|
|
440
|
-
return merge(result, objectSet(data, props));
|
|
441
|
-
}, obj));
|
|
442
|
-
|
|
443
|
-
case 20:
|
|
444
|
-
case 'end':
|
|
445
|
-
return _context3.stop();
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
}, _callee3, this);
|
|
449
|
-
}));
|
|
450
|
-
|
|
451
|
-
function resolve(_x, _x2, _x3) {
|
|
452
|
-
return _ref.apply(this, arguments);
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
return resolve;
|
|
456
|
-
})();
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Determines whether or not an object is valid.
|
|
460
|
-
*
|
|
461
|
-
* @param {Object} obj The object to test.
|
|
462
|
-
* @returns {boolean} Whether or not an object is valid.
|
|
463
|
-
*/
|
|
464
|
-
function isObject(obj) {
|
|
465
|
-
return obj !== null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && !Array.isArray(obj);
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
// Internal Packages
|
|
469
|
-
/**
|
|
470
|
-
* Determines whether or not a resolver is valid.
|
|
471
|
-
*
|
|
472
|
-
* @param {Object} resolver The resolver to test.
|
|
473
|
-
* @returns {boolean} Whether or not a resolver is valid.
|
|
474
|
-
*/
|
|
475
|
-
function isResolver(resolver) {
|
|
476
|
-
if (!resolver) {
|
|
477
|
-
return true;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
var keys = Object.keys(resolver);
|
|
481
|
-
|
|
482
|
-
if (!keys.length) {
|
|
483
|
-
return false;
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
return keys.map(function (key) {
|
|
487
|
-
return !key.startsWith(constants.PROP_DELIMITER) && !key.endsWith(constants.PROP_DELIMITER) && isResolver(resolver[key]);
|
|
488
|
-
}).reduce(function (result, val) {
|
|
489
|
-
return result && val;
|
|
490
|
-
}, true);
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
// Internal Packages
|
|
494
|
-
/**
|
|
495
|
-
* Resolves the nested-linked resources of a RESTful API.
|
|
496
|
-
*
|
|
497
|
-
* @param {string} resource The resource to fetch.
|
|
498
|
-
* @param {Object} resolver The resolver to apply.
|
|
499
|
-
* @param {Object} [options] The options to bypass.
|
|
500
|
-
* @returns {Promise<Object>} A promise which resolves into an object.
|
|
501
|
-
* @throws {InvalidArgumentError} If a resolver is invalid.
|
|
502
|
-
* @throws {InvalidArgumentError} If an options are invalid.
|
|
503
|
-
*/
|
|
504
|
-
var restql = (function () {
|
|
505
|
-
var _ref = asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(resource, resolver) {
|
|
506
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
507
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
508
|
-
while (1) {
|
|
509
|
-
switch (_context.prev = _context.next) {
|
|
510
|
-
case 0:
|
|
511
|
-
if (!(!isObject(resolver) || !isResolver(resolver))) {
|
|
512
|
-
_context.next = 2;
|
|
513
|
-
break;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
throw new Error('InvalidArgumentError: invalid resolver `' + JSON.stringify(resolver) + '`');
|
|
517
|
-
|
|
518
|
-
case 2:
|
|
519
|
-
if (isObject(options)) {
|
|
520
|
-
_context.next = 4;
|
|
521
|
-
break;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
throw new Error('InvalidArgumentError: invalid options `' + JSON.stringify(options) + '`');
|
|
525
|
-
|
|
526
|
-
case 4:
|
|
527
|
-
return _context.abrupt('return', resolve(resource, resolver, options));
|
|
528
|
-
|
|
529
|
-
case 5:
|
|
530
|
-
case 'end':
|
|
531
|
-
return _context.stop();
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
}, _callee, this);
|
|
535
|
-
}));
|
|
536
|
-
|
|
537
|
-
function restql(_x2, _x3) {
|
|
538
|
-
return _ref.apply(this, arguments);
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
return restql;
|
|
542
|
-
})();
|
|
543
|
-
|
|
544
|
-
export default restql;
|