Commit dcfdbde2 authored by rockyl's avatar rockyl

init

parent dc286cbd
export declare function codeOnlyMode(response: any): boolean;
export declare function successMode(response: any): any;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.successMode = exports.codeOnlyMode = void 0;
function codeOnlyMode(response) {
return !response.hasOwnProperty('code') || response.code == 0;
}
exports.codeOnlyMode = codeOnlyMode;
function successMode(response) {
return response.success;
}
exports.successMode = successMode;
//# sourceMappingURL=builtin-successfully-judges.js.map
\ No newline at end of file
{"version":3,"file":"builtin-successfully-judges.js","sourceRoot":"","sources":["../src/builtin-successfully-judges.ts"],"names":[],"mappings":";;;AASA,SAAgB,YAAY,CAAC,QAAQ;IACpC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC;AAC/D,CAAC;AAFD,oCAEC;AAKD,SAAgB,WAAW,CAAC,QAAQ;IACnC,OAAO,QAAQ,CAAC,OAAO,CAAC;AACzB,CAAC;AAFD,kCAEC"}
\ No newline at end of file
interface FetchApiOptions {
import './object-assign-polyfill';
export * from './builtin-successfully-judges';
interface SetupOptions {
apiHost?: string;
fetch?: Function;
successfullyJudge?: (resp: any) => boolean;
messageField?: string;
}
interface FetchApiOptions {
host?: string;
......@@ -11,6 +15,5 @@ interface FetchApiOptions {
contentType?: string;
errMessage?: string;
}
export declare function setup(options: FetchApiOptions): void;
export declare function setup(options: SetupOptions): void;
export declare function fetchApi(uri: string, { host, params, headers, method, credentials, contentType, errMessage, }?: FetchApiOptions): Promise<any>;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const querystringify_1 = require("querystringify");
class ApiError extends Error {
constructor(name, code, message, details) {
super();
this.code = 0;
this.details = '';
exports.fetchApi = exports.setup = void 0;
require("./object-assign-polyfill");
var querystringify_1 = require("querystringify");
var builtin_successfully_judges_1 = require("./builtin-successfully-judges");
__exportStar(require("./builtin-successfully-judges"), exports);
var ApiError = (function (_super) {
__extends(ApiError, _super);
function ApiError(name, code, message) {
var _this = _super.call(this) || this;
_this.code = 0;
_this.details = '';
if (name) {
this.name = name;
_this.name = name;
}
if (code) {
this.code = code;
_this.code = code;
}
if (message) {
this.message = message;
}
if (details) {
this.details = details;
}
}
}
let _options = {};
_this.message = message;
}
return _this;
}
return ApiError;
}(Error));
var _options = {
apiHost: '',
fetch: fetch,
successfullyJudge: builtin_successfully_judges_1.codeOnlyMode,
messageField: 'msg',
};
function setup(options) {
_options = options;
Object.assign(_options, options);
}
exports.setup = setup;
async function fetchApi(uri, { host = '', params, headers = {}, method = 'get', credentials = 'include', contentType = 'json', errMessage, } = {}) {
let url = host +
(uri.startsWith('http') || uri.startsWith('//') ? uri : (_options.apiHost || '') + uri);
const options = {
method,
headers: Object.assign({}, headers),
credentials,
function fetchApi(uri, _a) {
var _b = _a === void 0 ? {} : _a, _c = _b.host, host = _c === void 0 ? '' : _c, params = _b.params, _d = _b.headers, headers = _d === void 0 ? {} : _d, _e = _b.method, method = _e === void 0 ? 'get' : _e, _f = _b.credentials, credentials = _f === void 0 ? 'include' : _f, _g = _b.contentType, contentType = _g === void 0 ? 'json' : _g, errMessage = _b.errMessage;
return __awaiter(this, void 0, void 0, function () {
var url, options, formData, key, value, fetchMethod, response, respText, jsonObj, e_1;
return __generator(this, function (_h) {
switch (_h.label) {
case 0:
url = host +
(uri.startsWith('http') || uri.startsWith('//') ? uri : _options.apiHost + uri);
options = {
method: method,
headers: __assign({}, headers),
credentials: credentials,
};
if (params) {
if (method.toLowerCase() === 'post') {
switch (contentType) {
case 'form-data':
let formData = new FormData();
for (let key in params) {
let value = params[key];
formData = new FormData();
for (key in params) {
value = params[key];
if (value instanceof File) {
formData.append(key, value, value.name);
}
......@@ -64,22 +79,31 @@ async function fetchApi(uri, { host = '', params, headers = {}, method = 'get',
url += (url.endsWith('?') ? '' : '&') + querystringify_1.stringify(params);
}
}
try {
let fetchMethod = _options.fetch || fetch;
const response = await fetchMethod(url, options);
const respText = await response.text();
_h.label = 1;
case 1:
_h.trys.push([1, 4, , 5]);
fetchMethod = _options.fetch;
return [4, fetchMethod(url, options)];
case 2:
response = _h.sent();
return [4, response.text()];
case 3:
respText = _h.sent();
if (response.status === 310) {
location.href = respText;
}
let jsonObj = JSON.parse(respText);
if (jsonObj.code === 0) {
return jsonObj.data;
}
return Promise.reject(new ApiError('call api failed', jsonObj.code, errMessage, jsonObj.msg));
jsonObj = JSON.parse(respText);
if (_options.successfullyJudge(jsonObj)) {
return [2, jsonObj.data];
}
catch (e) {
return Promise.reject(e);
return [2, Promise.reject(new ApiError('call api failed', jsonObj.code, errMessage || jsonObj[_options.messageField]))];
case 4:
e_1 = _h.sent();
return [2, Promise.reject(e_1)];
case 5: return [2];
}
});
});
}
exports.fetchApi = fetchApi;
//# sourceMappingURL=index.js.map
\ No newline at end of file
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAMA,mDAAyC;AAKzC,MAAM,QAAS,SAAQ,KAAK;IAI3B,YAAY,IAAY,EAAE,IAAa,EAAE,OAAgB,EAAE,OAAgB;QAC1E,KAAK,EAAE,CAAC;QAJT,SAAI,GAAW,CAAC,CAAC;QACjB,YAAO,GAAW,EAAE,CAAC;QAKpB,IAAI,IAAI,EAAE;YACT,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;SACjB;QACD,IAAI,IAAI,EAAE;YACT,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;SACjB;QACD,IAAI,OAAO,EAAE;YACZ,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;SACvB;QACD,IAAI,OAAO,EAAE;YACZ,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;SACvB;IACF,CAAC;CACD;AAmDD,IAAI,QAAQ,GAAoB,EAAE,CAAC;AAMnC,SAAgB,KAAK,CAAC,OAAwB;IAC7C,QAAQ,GAAG,OAAO,CAAC;AACpB,CAAC;AAFD,sBAEC;AAOM,KAAK,UAAU,QAAQ,CAC7B,GA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AAG,CAAC,GAAG,0BAAS,CAAC,MAAM,CAAC,CAAC;yBAC1D;qBACD;;;;oBAGI,WAAW,GAAG,QAAQ,CAAC,KAAK,CAAC;oBAChB,WAAM,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,EAAA;;oBAA1C,QAAQ,GAAG,SAA+B;oBAC/B,WAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;oBAAhC,QAAQ,GAAG,SAAqB;oBAEtC,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;wBAE5B,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC;qBACzB;oBAEG,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;oBACnC,IAAI,QAAQ,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE;wBACxC,WAAO,OAAO,CAAC,IAAI,EAAC;qBACpB;oBAED,WAAO,OAAO,CAAC,MAAM,CACpB,IAAI,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC,IAAI,EAAE,UAAU,IAAI,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAC3F,EAAC;;;oBAEF,WAAO,OAAO,CAAC,MAAM,CAAC,GAAC,CAAC,EAAC;;;;;CAE1B;AAxED,4BAwEC"}
\ No newline at end of file
if (typeof Object.assign != 'function') {
Object.defineProperty(Object, "assign", {
value: function assign(target, varArgs) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) {
for (var nextKey in nextSource) {
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
},
writable: true,
configurable: true
});
}
//# sourceMappingURL=object-assign-polyfill.js.map
\ No newline at end of file
{"version":3,"file":"object-assign-polyfill.js","sourceRoot":"","sources":["../src/object-assign-polyfill.ts"],"names":[],"mappings":"AAAA,IAAI,OAAO,MAAM,CAAC,MAAM,IAAI,UAAU,EAAE;IAEvC,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE;QACvC,KAAK,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO;YACrC,YAAY,CAAC;YACb,IAAI,MAAM,IAAI,IAAI,EAAE;gBACnB,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAC;aAClE;YAED,IAAI,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;YAExB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;gBACtD,IAAI,UAAU,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;gBAElC,IAAI,UAAU,IAAI,IAAI,EAAE;oBACvB,KAAK,IAAI,OAAO,IAAI,UAAU,EAAE;wBAE/B,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE;4BAC9D,EAAE,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;yBAClC;qBACD;iBACD;aACD;YACD,OAAO,EAAE,CAAC;QACX,CAAC;QACD,QAAQ,EAAE,IAAI;QACd,YAAY,EAAE,IAAI;KAClB,CAAC,CAAC;CACH"}
\ No newline at end of file
{
"name": "fetch-api",
"version": "1.0.1",
"version": "1.0.2",
"main": "out/index.js",
"types": "out/index.d.ts",
"license": "MIT",
"dependencies": {
"@types/querystringify": "^2.0.0",
"querystringify": "^2.1.1"
},
"scripts": {
"dev": "tsc -w",
"build": "tsc"
}
}
/**
* Created by rockyl on 2020/11/26.
*
* 接口成功判断
*/
/**
* 仅code判断模式
*/
export function codeOnlyMode(response) {
return !response.hasOwnProperty('code') || response.code == 0;
}
/**
* success判断模式
*/
export function successMode(response) {
return response.success;
}
......@@ -4,7 +4,11 @@
* 封装fetch请求
*/
import './object-assign-polyfill'
import {stringify} from 'querystringify';
import {codeOnlyMode} from './builtin-successfully-judges'
export * from './builtin-successfully-judges';
/**
* api错误
......@@ -13,7 +17,7 @@ class ApiError extends Error {
code: number = 0;
details: string = '';
constructor(name: string, code?: number, message?: string, details?: string) {
constructor(name: string, code?: number, message?: string) {
super();
if (name) {
......@@ -25,18 +29,17 @@ class ApiError extends Error {
if (message) {
this.message = message;
}
if (details) {
this.details = details;
}
}
}
/**
* 总配置
*/
interface FetchApiOptions {
interface SetupOptions {
apiHost?: string;
fetch?: Function;
successfullyJudge?: (resp) => boolean;
messageField?: string;
}
/**
......@@ -80,14 +83,19 @@ interface FetchApiOptions {
errMessage?: string;
}
let _options: FetchApiOptions = {};
let _options: SetupOptions = {
apiHost: '',
fetch: fetch,
successfullyJudge: codeOnlyMode,
messageField: 'msg',
};
/**
* 配置
* @param options
*/
export function setup(options: FetchApiOptions) {
_options = options;
export function setup(options: SetupOptions) {
Object.assign(_options, options);
}
/**
......@@ -109,7 +117,7 @@ export async function fetchApi(
) {
let url =
host +
(uri.startsWith('http') || uri.startsWith('//') ? uri : (_options.apiHost || '') + uri);
(uri.startsWith('http') || uri.startsWith('//') ? uri : _options.apiHost + uri);
const options: any = {
method,
......@@ -147,7 +155,7 @@ export async function fetchApi(
}
try {
let fetchMethod = _options.fetch || fetch;
let fetchMethod = _options.fetch;
const response = await fetchMethod(url, options);
const respText = await response.text();
......@@ -157,13 +165,12 @@ export async function fetchApi(
}
let jsonObj = JSON.parse(respText);
if (jsonObj.code === 0) {
if (_options.successfullyJudge(jsonObj)) {
return jsonObj.data;
// return Promise.resolve(jsonObj.data) ;
}
return Promise.reject(
new ApiError('call api failed', jsonObj.code, errMessage, jsonObj.msg),
new ApiError('call api failed', jsonObj.code, errMessage || jsonObj[_options.messageField]),
);
} catch (e) {
return Promise.reject(e);
......
if (typeof Object.assign != 'function') {
// Must be writable: true, enumerable: false, configurable: true
Object.defineProperty(Object, "assign", {
value: function assign(target, varArgs) { // .length of function is 2
'use strict';
if (target == null) { // TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}
let to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) { // Skip over if undefined or null
for (let nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
},
writable: true,
configurable: true
});
}
{
"compileOnSave": true,
"compilerOptions": {
"target": "es2017",
"target": "ES5",
"noImplicitAny": false,
"removeComments": true,
"noEmitOnError": true,
......@@ -9,7 +8,6 @@
"module": "commonjs",
"experimentalDecorators": true,
"sourceMap": true,
"watch": true,
"outDir": "out/",
"declaration": true,
"lib": [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment