Commit 66d1a76e authored by rockyl's avatar rockyl

sourcemap

parent dcfdbde2
# Created by .ignore support plugin (hsz.mobi)
/src/
/fetch-api.iml
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchApi = exports.setup = void 0;
require("./object-assign-polyfill");
var querystringify_1 = require("querystringify");
var builtin_successfully_judges_1 = require("./builtin-successfully-judges");
const querystringify_1 = require("querystringify");
const 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 = '';
class ApiError extends Error {
constructor(name, code, message) {
super();
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;
this.message = message;
}
return _this;
}
return ApiError;
}(Error));
var _options = {
}
let _options = {
apiHost: '',
fetch: fetch,
successfullyJudge: builtin_successfully_judges_1.codeOnlyMode,
messageField: 'msg',
};
......@@ -34,27 +40,21 @@ function setup(options) {
Object.assign(_options, options);
}
exports.setup = setup;
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 +
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);
options = {
method: method,
headers: __assign({}, headers),
credentials: credentials,
const options = {
method,
headers: Object.assign({}, headers),
credentials,
};
if (params) {
if (method.toLowerCase() === 'post') {
switch (contentType) {
case 'form-data':
formData = new FormData();
for (key in params) {
value = params[key];
let formData = new FormData();
for (let key in params) {
let value = params[key];
if (value instanceof File) {
formData.append(key, value, value.name);
}
......@@ -79,31 +79,22 @@ function fetchApi(uri, _a) {
url += (url.endsWith('?') ? '' : '&') + querystringify_1.stringify(params);
}
}
_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();
try {
let fetchMethod = _options.fetch;
const response = await fetchMethod(url, options);
const respText = await response.text();
if (response.status === 310) {
location.href = respText;
}
jsonObj = JSON.parse(respText);
let jsonObj = JSON.parse(respText);
if (_options.successfullyJudge(jsonObj)) {
return [2, jsonObj.data];
return jsonObj.data;
}
return Promise.reject(new ApiError('call api failed', jsonObj.code, errMessage || jsonObj[_options.messageField]));
}
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];
catch (e) {
return Promise.reject(e);
}
});
});
}
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,oCAAiC;AACjC,iDAAyC;AACzC,6EAA0D;AAE1D,gEAA8C;AAK9C;IAAuB,4BAAK;IAI3B,kBAAY,IAA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E,UAAU,IAAI,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAC3F,CAAC;KACF;IAAC,OAAO,CAAC,EAAE;QACX,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;KACzB;AACF,CAAC;AAxED,4BAwEC"}
\ No newline at end of file
......@@ -5,11 +5,11 @@ if (typeof Object.assign != 'function') {
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
let to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) {
for (var nextKey in nextSource) {
for (let nextKey in nextSource) {
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
......
{
"name": "fetch-api",
"version": "1.0.2",
"version": "1.0.5",
"main": "out/index.js",
"types": "out/index.d.ts",
"license": "MIT",
......
......@@ -85,7 +85,6 @@ interface FetchApiOptions {
let _options: SetupOptions = {
apiHost: '',
fetch: fetch,
successfullyJudge: codeOnlyMode,
messageField: 'msg',
};
......
{
"compilerOptions": {
"target": "ES5",
"target": "ES2017",
"noImplicitAny": false,
"removeComments": true,
"noEmitOnError": true,
"noEmitHelpers": true,
"module": "commonjs",
"noEmitHelpers": false,
"module": "CommonJS",
"experimentalDecorators": true,
"sourceMap": true,
"outDir": "out/",
......
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