@noah-libjs/request 0.0.7 → 0.0.8
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/dist/Request.d.ts +1 -0
- package/dist/helper.d.ts +9 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +87 -3
- package/package.json +3 -3
package/dist/Request.d.ts
CHANGED
package/dist/helper.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ICommonOption } from "@noah-libjs/utils";
|
|
2
|
+
import { FormInstance } from "antd";
|
|
3
|
+
export type T_FETCH_OPTIONS = ((f?: FormInstance) => (Promise<ICommonOption[]> | ICommonOption[])) | {
|
|
4
|
+
url: string;
|
|
5
|
+
labelKey?: string;
|
|
6
|
+
valueKey?: string;
|
|
7
|
+
method?: 'get' | 'post';
|
|
8
|
+
};
|
|
9
|
+
export declare function safe_fetch_options(cb: T_FETCH_OPTIONS, f?: FormInstance): Promise<ICommonOption[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
|
-
import { Request } from './Request';
|
|
2
|
+
import { Request, request } from './Request';
|
|
3
3
|
export * from './types';
|
|
4
|
+
export * from './helper';
|
|
4
5
|
export { codeMessage } from './constant';
|
|
5
6
|
declare function createInstance(defaultConfig?: {}): AxiosInstance;
|
|
6
|
-
declare const request: Request;
|
|
7
7
|
export { Request, createInstance, request };
|
package/dist/index.js
CHANGED
|
@@ -3,11 +3,12 @@ import _createClass from "@babel/runtime/helpers/createClass";
|
|
|
3
3
|
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
4
4
|
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
5
5
|
import _inherits from "@babel/runtime/helpers/inherits";
|
|
6
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
7
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
7
8
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
8
9
|
import axios, { Axios } from 'axios';
|
|
9
10
|
import utils from 'axios/lib/utils';
|
|
10
|
-
import { MyLog, EventEmitter } from '@noah-libjs/utils';
|
|
11
|
+
import { MyLog, EventEmitter, isFunction, safe_async_call, expect_array, cache_fetch, get } from '@noah-libjs/utils';
|
|
11
12
|
import bind from 'axios/lib/helpers/bind';
|
|
12
13
|
var codeMessage = {
|
|
13
14
|
200: '服务器成功返回请求的数据。',
|
|
@@ -262,6 +263,7 @@ Object.defineProperty(Request, "logger", {
|
|
|
262
263
|
writable: true,
|
|
263
264
|
value: new MyLog('Request')
|
|
264
265
|
});
|
|
266
|
+
var request = new Request();
|
|
265
267
|
function doUnboxing(res) {
|
|
266
268
|
var isBoxing = typeof (res === null || res === void 0 ? void 0 : res.code) === 'number' && !!res.data;
|
|
267
269
|
if (isBoxing) {
|
|
@@ -269,6 +271,89 @@ function doUnboxing(res) {
|
|
|
269
271
|
}
|
|
270
272
|
return res;
|
|
271
273
|
}
|
|
274
|
+
|
|
275
|
+
/******************************************************************************
|
|
276
|
+
Copyright (c) Microsoft Corporation.
|
|
277
|
+
|
|
278
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
279
|
+
purpose with or without fee is hereby granted.
|
|
280
|
+
|
|
281
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
282
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
283
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
284
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
285
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
286
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
287
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
288
|
+
***************************************************************************** */
|
|
289
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
290
|
+
function adopt(value) {
|
|
291
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
292
|
+
resolve(value);
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
296
|
+
function fulfilled(value) {
|
|
297
|
+
try {
|
|
298
|
+
step(generator.next(value));
|
|
299
|
+
} catch (e) {
|
|
300
|
+
reject(e);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function rejected(value) {
|
|
304
|
+
try {
|
|
305
|
+
step(generator["throw"](value));
|
|
306
|
+
} catch (e) {
|
|
307
|
+
reject(e);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function step(result) {
|
|
311
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
312
|
+
}
|
|
313
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
317
|
+
var e = new Error(message);
|
|
318
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
319
|
+
};
|
|
320
|
+
function safe_fetch_options(cb, f) {
|
|
321
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
322
|
+
var arr, _cb$method, method, _cb$valueKey, valueKey, _cb$labelKey, labelKey, url;
|
|
323
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
324
|
+
while (1) switch (_context.prev = _context.next) {
|
|
325
|
+
case 0:
|
|
326
|
+
if (!isFunction(cb)) {
|
|
327
|
+
_context.next = 7;
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
_context.next = 3;
|
|
331
|
+
return safe_async_call(cb, f);
|
|
332
|
+
case 3:
|
|
333
|
+
arr = _context.sent;
|
|
334
|
+
return _context.abrupt("return", expect_array(arr));
|
|
335
|
+
case 7:
|
|
336
|
+
_cb$method = cb.method, method = _cb$method === void 0 ? 'get' : _cb$method, _cb$valueKey = cb.valueKey, valueKey = _cb$valueKey === void 0 ? 'value' : _cb$valueKey, _cb$labelKey = cb.labelKey, labelKey = _cb$labelKey === void 0 ? 'label' : _cb$labelKey, url = cb.url;
|
|
337
|
+
return _context.abrupt("return", cache_fetch(url, function () {
|
|
338
|
+
return request.ins({
|
|
339
|
+
method: method,
|
|
340
|
+
url: url
|
|
341
|
+
});
|
|
342
|
+
}).then(function (res) {
|
|
343
|
+
return expect_array(res.data).map(function (_) {
|
|
344
|
+
return {
|
|
345
|
+
label: get(_, labelKey),
|
|
346
|
+
value: get(_, valueKey)
|
|
347
|
+
};
|
|
348
|
+
});
|
|
349
|
+
}));
|
|
350
|
+
case 9:
|
|
351
|
+
case "end":
|
|
352
|
+
return _context.stop();
|
|
353
|
+
}
|
|
354
|
+
}, _callee);
|
|
355
|
+
}));
|
|
356
|
+
}
|
|
272
357
|
function createInstance() {
|
|
273
358
|
var defaultConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
274
359
|
var instance = bind(Axios.prototype.request, request.ins);
|
|
@@ -276,5 +361,4 @@ function createInstance() {
|
|
|
276
361
|
utils.extend(instance, request.ins);
|
|
277
362
|
return instance;
|
|
278
363
|
}
|
|
279
|
-
|
|
280
|
-
export { Request, codeMessage, createInstance, request };
|
|
364
|
+
export { Request, codeMessage, createInstance, request, safe_fetch_options };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noah-libjs/request",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@noah-libjs/utils": "0.0.
|
|
24
|
+
"@noah-libjs/utils": "0.0.8",
|
|
25
25
|
"axios": "^0.26.1",
|
|
26
26
|
"store": "2.x"
|
|
27
27
|
},
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"keywords": [],
|
|
33
33
|
"author": "",
|
|
34
34
|
"license": "MIT",
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "a50958bb900a9e145a8a722b69c639cac93d2094"
|
|
36
36
|
}
|