ant-design-x-vue-next
Version:
Ant Design X for Vue — community continuation aligned with @ant-design/x
97 lines (96 loc) • 3.06 kB
JavaScript
import l, { getXRequestGlobalOptions as y } from "./x-request.mjs";
class g {
constructor(t, e) {
if (!t || typeof t != "string") throw new Error("The baseURL is not valid!");
this.baseURL = t, this.options = e || {};
}
}
class c extends g {
constructor(t, e) {
super(t, e), this._asyncHandler = Promise.resolve(), this.lastHeaders = new Headers(), this._manual = (e == null ? void 0 : e.manual) ?? !1;
const r = y(), u = {
baseURL: t,
model: e == null ? void 0 : e.model,
dangerouslyApiKey: e == null ? void 0 : e.dangerouslyApiKey,
headers: {
...r.headers || {},
...(e == null ? void 0 : e.headers) || {}
},
fetch: (e == null ? void 0 : e.fetch) ?? r.fetch,
middlewares: {
...r.middlewares || {},
...(e == null ? void 0 : e.middlewares) || {},
onResponse: async (a) => {
var d, h;
this.lastHeaders = a.headers;
const s = ((d = e == null ? void 0 : e.middlewares) == null ? void 0 : d.onResponse) || ((h = r.middlewares) == null ? void 0 : h.onResponse);
return s ? s(a) : a;
}
},
timeout: (e == null ? void 0 : e.timeout) ?? r.timeout,
streamTimeout: (e == null ? void 0 : e.streamTimeout) ?? r.streamTimeout,
retryInterval: (e == null ? void 0 : e.retryInterval) ?? r.retryInterval,
retryTimes: (e == null ? void 0 : e.retryTimes) ?? r.retryTimes,
streamSeparator: (e == null ? void 0 : e.streamSeparator) ?? r.streamSeparator,
partSeparator: (e == null ? void 0 : e.partSeparator) ?? r.partSeparator,
kvSeparator: (e == null ? void 0 : e.kvSeparator) ?? r.kvSeparator
};
this.legacy = l(u).value;
}
get asyncHandler() {
return this._asyncHandler;
}
get isTimeout() {
return this.legacy.isTimeout;
}
get isStreamTimeout() {
return this.legacy.isStreamTimeout;
}
get isRequesting() {
return this.legacy.isRequesting;
}
get manual() {
return this._manual;
}
run(t) {
if (!this.manual)
return console.warn("[XRequest] The request is not manual, so it cannot be run!"), !1;
const e = this.options.callbacks, r = {
...this.options.params || {},
...t || {}
};
return this._asyncHandler = this.legacy.create(
r,
{
onUpdate: (u) => {
var a;
(a = e == null ? void 0 : e.onUpdate) == null || a.call(e, u, this.lastHeaders);
},
onSuccess: (u) => {
var a;
(a = e == null ? void 0 : e.onSuccess) == null || a.call(e, u, this.lastHeaders);
},
onError: (u) => {
var a;
return (a = e == null ? void 0 : e.onError) == null ? void 0 : a.call(e, u, void 0, this.lastHeaders);
}
},
this.options.transformStream
), !0;
}
abort() {
this.legacy.abort();
}
}
function f(m, t) {
return new c(m, {
manual: !0,
...t
});
}
export {
g as AbstractXRequestClass,
c as ManualXRequestClass,
f as createManualXRequest,
f as default
};