@wzyjs/utils 0.2.13 → 0.2.20
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/cjs/browser/element.d.ts +0 -1
- package/dist/cjs/browser/index.js +3 -1
- package/dist/cjs/browser/initHttpClient.js +62 -0
- package/dist/cjs/browser/other.d.ts +0 -1
- package/dist/cjs/browser/style.d.ts +0 -1
- package/dist/cjs/browser.d.ts +0 -1
- package/dist/cjs/common/array.d.ts +2 -0
- package/dist/cjs/common/array.js +68 -0
- package/dist/cjs/common/classs.d.ts +0 -1
- package/dist/cjs/common/dayjs.js +1 -0
- package/dist/cjs/common/index.d.ts +1 -1
- package/dist/cjs/common/index.js +3 -1
- package/dist/cjs/common/number.d.ts +1 -1
- package/dist/cjs/common/number.js +14 -0
- package/dist/cjs/common/object.d.ts +0 -1
- package/dist/cjs/common/other.d.ts +0 -1
- package/dist/cjs/common/string.d.ts +2 -1
- package/dist/cjs/common/string.js +33 -0
- package/dist/cjs/node/file/index.js +58 -0
- package/dist/cjs/node/index.d.ts +1 -1
- package/dist/cjs/node/index.js +3 -1
- package/dist/cjs/node/jsonFile/config.json +8 -0
- package/dist/cjs/node/jsonFile/index.d.ts +3 -3
- package/dist/cjs/node/jsonFile/index.js +37 -13
- package/dist/cjs/node/mail/index.d.ts +0 -1
- package/dist/cjs/node.d.ts +0 -1
- package/dist/esm/browser/element.d.ts +0 -1
- package/dist/esm/browser/index.js +2 -1
- package/dist/esm/{node/database/Collection.js → browser/initHttpClient.js} +51 -340
- package/dist/esm/browser/other.d.ts +0 -1
- package/dist/esm/browser/style.d.ts +0 -1
- package/dist/esm/browser.d.ts +0 -1
- package/dist/esm/common/array.d.ts +2 -0
- package/dist/esm/common/array.js +65 -0
- package/dist/esm/common/classs.d.ts +0 -1
- package/dist/esm/common/dayjs.js +1 -0
- package/dist/esm/common/index.d.ts +1 -1
- package/dist/esm/common/index.js +1 -0
- package/dist/esm/common/number.d.ts +1 -1
- package/dist/esm/common/number.js +21 -0
- package/dist/esm/common/object.d.ts +0 -1
- package/dist/esm/common/other.d.ts +0 -1
- package/dist/esm/common/string.d.ts +2 -1
- package/dist/esm/common/string.js +40 -0
- package/dist/esm/node/file/index.js +52 -0
- package/dist/esm/node/index.d.ts +1 -1
- package/dist/esm/node/index.js +1 -1
- package/dist/esm/node/jsonFile/index.d.ts +3 -3
- package/dist/esm/node/jsonFile/index.js +79 -21
- package/dist/esm/node/mail/index.d.ts +0 -1
- package/dist/esm/node.d.ts +0 -1
- package/package.json +8 -8
- package/dist/cjs/browser/element.d.ts.map +0 -1
- package/dist/cjs/browser/index.d.ts +0 -19
- package/dist/cjs/browser/index.d.ts.map +0 -1
- package/dist/cjs/browser/other.d.ts.map +0 -1
- package/dist/cjs/browser/style.d.ts.map +0 -1
- package/dist/cjs/browser.d.ts.map +0 -1
- package/dist/cjs/common/classs.d.ts.map +0 -1
- package/dist/cjs/common/dayjs.d.ts +0 -8
- package/dist/cjs/common/dayjs.d.ts.map +0 -1
- package/dist/cjs/common/index.d.ts.map +0 -1
- package/dist/cjs/common/number.d.ts.map +0 -1
- package/dist/cjs/common/object.d.ts.map +0 -1
- package/dist/cjs/common/other.d.ts.map +0 -1
- package/dist/cjs/common/string.d.ts.map +0 -1
- package/dist/cjs/node/database/Collection.d.ts +0 -23
- package/dist/cjs/node/database/Collection.d.ts.map +0 -1
- package/dist/cjs/node/database/Collection.js +0 -219
- package/dist/cjs/node/database/Database.d.ts +0 -11
- package/dist/cjs/node/database/Database.d.ts.map +0 -1
- package/dist/cjs/node/database/Database.js +0 -47
- package/dist/cjs/node/database/index.d.ts +0 -3
- package/dist/cjs/node/database/index.d.ts.map +0 -1
- package/dist/cjs/node/database/index.js +0 -38
- package/dist/cjs/node/database/types.d.ts +0 -152
- package/dist/cjs/node/database/types.d.ts.map +0 -1
- package/dist/cjs/node/database/types.js +0 -51
- package/dist/cjs/node/database/utils.d.ts +0 -4
- package/dist/cjs/node/database/utils.d.ts.map +0 -1
- package/dist/cjs/node/database/utils.js +0 -53
- package/dist/cjs/node/index.d.ts.map +0 -1
- package/dist/cjs/node/jsonFile/index.d.ts.map +0 -1
- package/dist/cjs/node/mail/index.d.ts.map +0 -1
- package/dist/cjs/node.d.ts.map +0 -1
- package/dist/esm/browser/element.d.ts.map +0 -1
- package/dist/esm/browser/index.d.ts +0 -19
- package/dist/esm/browser/index.d.ts.map +0 -1
- package/dist/esm/browser/other.d.ts.map +0 -1
- package/dist/esm/browser/style.d.ts.map +0 -1
- package/dist/esm/browser.d.ts.map +0 -1
- package/dist/esm/common/classs.d.ts.map +0 -1
- package/dist/esm/common/dayjs.d.ts +0 -8
- package/dist/esm/common/dayjs.d.ts.map +0 -1
- package/dist/esm/common/index.d.ts.map +0 -1
- package/dist/esm/common/number.d.ts.map +0 -1
- package/dist/esm/common/object.d.ts.map +0 -1
- package/dist/esm/common/other.d.ts.map +0 -1
- package/dist/esm/common/string.d.ts.map +0 -1
- package/dist/esm/node/database/Collection.d.ts +0 -23
- package/dist/esm/node/database/Collection.d.ts.map +0 -1
- package/dist/esm/node/database/Database.d.ts +0 -11
- package/dist/esm/node/database/Database.d.ts.map +0 -1
- package/dist/esm/node/database/Database.js +0 -36
- package/dist/esm/node/database/index.d.ts +0 -3
- package/dist/esm/node/database/index.d.ts.map +0 -1
- package/dist/esm/node/database/index.js +0 -2
- package/dist/esm/node/database/types.d.ts +0 -152
- package/dist/esm/node/database/types.d.ts.map +0 -1
- package/dist/esm/node/database/types.js +0 -55
- package/dist/esm/node/database/utils.d.ts +0 -4
- package/dist/esm/node/database/utils.d.ts.map +0 -1
- package/dist/esm/node/database/utils.js +0 -29
- package/dist/esm/node/index.d.ts.map +0 -1
- package/dist/esm/node/jsonFile/index.d.ts.map +0 -1
- package/dist/esm/node/mail/index.d.ts.map +0 -1
- package/dist/esm/node.d.ts.map +0 -1
|
@@ -1,356 +1,67 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
3
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
2
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
4
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
5
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
12
6
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
13
|
-
import { cloneDeep, merge, isObject } from 'lodash';
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// 如果是根据 条件 查询
|
|
39
|
-
} else {
|
|
40
|
-
var page = conditions.page,
|
|
41
|
-
order = conditions.order,
|
|
42
|
-
where = conditions.where,
|
|
43
|
-
options = conditions.options;
|
|
44
|
-
if (options) {
|
|
45
|
-
record = record.options(options);
|
|
46
|
-
}
|
|
47
|
-
if (where) {
|
|
48
|
-
record = record.where(where);
|
|
49
|
-
}
|
|
50
|
-
if (order) {
|
|
51
|
-
record = record.orderBy(order.field, order.type || 'desc');
|
|
52
|
-
}
|
|
53
|
-
if (page !== null && page !== void 0 && page.current && page !== null && page !== void 0 && page.size) {
|
|
54
|
-
record = record.skip((page.current - 1) * page.size);
|
|
55
|
-
}
|
|
56
|
-
if (page !== null && page !== void 0 && page.size) {
|
|
57
|
-
record = record.limit(page.size);
|
|
7
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
8
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
9
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
10
|
+
import axios from 'axios';
|
|
11
|
+
import { pick } from 'lodash';
|
|
12
|
+
var ErrorMiddleware = function ErrorMiddleware(onError) {
|
|
13
|
+
return /*#__PURE__*/function () {
|
|
14
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_, next) {
|
|
15
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
16
|
+
while (1) switch (_context.prev = _context.next) {
|
|
17
|
+
case 0:
|
|
18
|
+
_context.prev = 0;
|
|
19
|
+
_context.next = 3;
|
|
20
|
+
return next();
|
|
21
|
+
case 3:
|
|
22
|
+
_context.next = 8;
|
|
23
|
+
break;
|
|
24
|
+
case 5:
|
|
25
|
+
_context.prev = 5;
|
|
26
|
+
_context.t0 = _context["catch"](0);
|
|
27
|
+
onError(_context.t0);
|
|
28
|
+
case 8:
|
|
29
|
+
case "end":
|
|
30
|
+
return _context.stop();
|
|
58
31
|
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
key: "request",
|
|
73
|
-
value: function request(params) {
|
|
74
|
-
switch (params.method) {
|
|
75
|
-
case Method.Add:
|
|
76
|
-
return this.joinConditions().add(params.data);
|
|
77
|
-
case Method.Find:
|
|
78
|
-
case Method.FindList:
|
|
79
|
-
return this.joinConditions(params.conditions).get();
|
|
80
|
-
case Method.Delete:
|
|
81
|
-
return this.joinConditions(params.conditions).remove();
|
|
82
|
-
case Method.Update:
|
|
83
|
-
if (params.isSet && '_id' in params.conditions) {
|
|
84
|
-
return this.joinConditions(params.conditions).set(params.data);
|
|
85
|
-
}
|
|
86
|
-
return this.joinConditions(params.conditions).update(params.data);
|
|
87
|
-
case Method.Count:
|
|
88
|
-
return this.joinConditions(params.conditions).count();
|
|
89
|
-
default:
|
|
90
|
-
throw new Error('method is not exist');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// 处理出参
|
|
95
|
-
}, {
|
|
96
|
-
key: "handleRes",
|
|
97
|
-
value: function () {
|
|
98
|
-
var _handleRes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params, res) {
|
|
99
|
-
var data, addRes, _params$conditions, updateRes, _params$conditions2, getRes, getListRes, countRes;
|
|
100
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
101
|
-
while (1) switch (_context.prev = _context.next) {
|
|
102
|
-
case 0:
|
|
103
|
-
if (res) {
|
|
104
|
-
delete res.requestId;
|
|
105
|
-
}
|
|
106
|
-
data = res;
|
|
107
|
-
_context.t0 = params.method;
|
|
108
|
-
_context.next = _context.t0 === Method.Add ? 5 : _context.t0 === Method.Update ? 11 : _context.t0 === Method.Find ? 17 : _context.t0 === Method.FindList ? 20 : 26;
|
|
109
|
-
break;
|
|
110
|
-
case 5:
|
|
111
|
-
addRes = res;
|
|
112
|
-
if (!(addRes.id && params.isReturn)) {
|
|
113
|
-
_context.next = 10;
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
_context.next = 9;
|
|
117
|
-
return this.find({
|
|
118
|
-
_id: addRes.id,
|
|
119
|
-
field: (_params$conditions = params.conditions) === null || _params$conditions === void 0 ? void 0 : _params$conditions.field
|
|
120
|
-
});
|
|
121
|
-
case 9:
|
|
122
|
-
data = _context.sent;
|
|
123
|
-
case 10:
|
|
124
|
-
return _context.abrupt("break", 26);
|
|
125
|
-
case 11:
|
|
126
|
-
updateRes = res;
|
|
127
|
-
if (!(updateRes.updated && params.isReturn && '_id' in params.conditions)) {
|
|
128
|
-
_context.next = 16;
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
_context.next = 15;
|
|
132
|
-
return this.find({
|
|
133
|
-
_id: params.conditions._id,
|
|
134
|
-
field: (_params$conditions2 = params.conditions) === null || _params$conditions2 === void 0 ? void 0 : _params$conditions2.field
|
|
135
|
-
});
|
|
136
|
-
case 15:
|
|
137
|
-
data = _context.sent;
|
|
138
|
-
case 16:
|
|
139
|
-
return _context.abrupt("break", 26);
|
|
140
|
-
case 17:
|
|
141
|
-
getRes = res;
|
|
142
|
-
data = (getRes === null || getRes === void 0 ? void 0 : getRes.data[0]) || null;
|
|
143
|
-
return _context.abrupt("break", 26);
|
|
144
|
-
case 20:
|
|
145
|
-
getListRes = res;
|
|
146
|
-
_context.next = 23;
|
|
147
|
-
return this.request({
|
|
148
|
-
method: Method.Count,
|
|
149
|
-
conditions: params.conditions
|
|
150
|
-
});
|
|
151
|
-
case 23:
|
|
152
|
-
countRes = _context.sent;
|
|
153
|
-
data = {
|
|
154
|
-
list: getListRes.data,
|
|
155
|
-
total: countRes.total
|
|
156
|
-
};
|
|
157
|
-
return _context.abrupt("break", 26);
|
|
158
|
-
case 26:
|
|
159
|
-
return _context.abrupt("return", data);
|
|
160
|
-
case 27:
|
|
161
|
-
case "end":
|
|
162
|
-
return _context.stop();
|
|
163
|
-
}
|
|
164
|
-
}, _callee, this);
|
|
165
|
-
}));
|
|
166
|
-
function handleRes(_x, _x2) {
|
|
167
|
-
return _handleRes.apply(this, arguments);
|
|
168
|
-
}
|
|
169
|
-
return handleRes;
|
|
170
|
-
}() // 处理数据
|
|
171
|
-
}, {
|
|
172
|
-
key: "handleData",
|
|
173
|
-
value: function () {
|
|
174
|
-
var _handleData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
|
|
32
|
+
}, _callee, null, [[0, 5]]);
|
|
33
|
+
}));
|
|
34
|
+
return function (_x, _x2) {
|
|
35
|
+
return _ref.apply(this, arguments);
|
|
36
|
+
};
|
|
37
|
+
}();
|
|
38
|
+
};
|
|
39
|
+
export var initHttpClient = function initHttpClient(setupHttpClient, option) {
|
|
40
|
+
setupHttpClient({
|
|
41
|
+
middleware: [ErrorMiddleware(option.onError)],
|
|
42
|
+
fetcher: function () {
|
|
43
|
+
var _fetcher = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(req, options) {
|
|
44
|
+
var response;
|
|
175
45
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
176
46
|
while (1) switch (_context2.prev = _context2.next) {
|
|
177
47
|
case 0:
|
|
178
|
-
_context2.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
return _context2.abrupt("
|
|
185
|
-
case
|
|
186
|
-
if ('_id' in params.data) {
|
|
187
|
-
delete params.data._id;
|
|
188
|
-
}
|
|
189
|
-
return _context2.abrupt("break", 8);
|
|
190
|
-
case 8:
|
|
191
|
-
return _context2.abrupt("return", params);
|
|
192
|
-
case 9:
|
|
48
|
+
_context2.next = 2;
|
|
49
|
+
return axios(_objectSpread(_objectSpread(_objectSpread({}, pick(req, ['method', 'url', 'data', 'query', 'headers'])), pick(options, ['baseURL', 'withCredentials'])), {}, {
|
|
50
|
+
timeout: options.timeout
|
|
51
|
+
}));
|
|
52
|
+
case 2:
|
|
53
|
+
response = _context2.sent;
|
|
54
|
+
return _context2.abrupt("return", response.data);
|
|
55
|
+
case 4:
|
|
193
56
|
case "end":
|
|
194
57
|
return _context2.stop();
|
|
195
58
|
}
|
|
196
59
|
}, _callee2);
|
|
197
60
|
}));
|
|
198
|
-
function
|
|
199
|
-
return
|
|
200
|
-
}
|
|
201
|
-
return handleData;
|
|
202
|
-
}() // 处理条件
|
|
203
|
-
}, {
|
|
204
|
-
key: "handleConditions",
|
|
205
|
-
value: function handleConditions(params) {
|
|
206
|
-
if (params.method !== Method.Add) {
|
|
207
|
-
params.conditions = merge(cloneDeep(defaultConditions), params.conditions);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// 处理 where 条件
|
|
211
|
-
if (params.conditions && 'where' in params.conditions) {
|
|
212
|
-
var _ = this.db.command;
|
|
213
|
-
for (var key in params.conditions.where) {
|
|
214
|
-
var whereValue = params.conditions.where[key];
|
|
215
|
-
if (isObject(whereValue)) {
|
|
216
|
-
var _ref = whereValue,
|
|
217
|
-
type = _ref.type,
|
|
218
|
-
value = _ref.value;
|
|
219
|
-
switch (type) {
|
|
220
|
-
case Command.In:
|
|
221
|
-
params.conditions.where[key] = _.in(value);
|
|
222
|
-
break;
|
|
223
|
-
case Command.Nin:
|
|
224
|
-
params.conditions.where[key] = _.nin(value);
|
|
225
|
-
break;
|
|
226
|
-
case Command.Gt:
|
|
227
|
-
params.conditions.where[key] = _.gt(value);
|
|
228
|
-
break;
|
|
229
|
-
case Command.Gte:
|
|
230
|
-
params.conditions.where[key] = _.gte(value);
|
|
231
|
-
break;
|
|
232
|
-
case Command.Lt:
|
|
233
|
-
params.conditions.where[key] = _.lt(value);
|
|
234
|
-
break;
|
|
235
|
-
case Command.Lte:
|
|
236
|
-
params.conditions.where[key] = _.lte(value);
|
|
237
|
-
break;
|
|
238
|
-
case Command.Eq:
|
|
239
|
-
params.conditions.where[key] = _.eq(value);
|
|
240
|
-
break;
|
|
241
|
-
case Command.Neq:
|
|
242
|
-
params.conditions.where[key] = _.neq(value);
|
|
243
|
-
break;
|
|
244
|
-
case Command.Gtlt:
|
|
245
|
-
params.conditions.where[key] = _.and(_.gt(value[0]), _.lt(value[1]));
|
|
246
|
-
break;
|
|
247
|
-
default:
|
|
248
|
-
var check = type;
|
|
249
|
-
console.error(666, '处理 where 条件 出现未定义的情况', check);
|
|
250
|
-
break;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return params;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// 执行
|
|
259
|
-
}, {
|
|
260
|
-
key: "exec",
|
|
261
|
-
value: function () {
|
|
262
|
-
var _exec = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
|
|
263
|
-
var res;
|
|
264
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
265
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
266
|
-
case 0:
|
|
267
|
-
_context3.next = 2;
|
|
268
|
-
return this.handleData(params);
|
|
269
|
-
case 2:
|
|
270
|
-
params = _context3.sent;
|
|
271
|
-
_context3.next = 5;
|
|
272
|
-
return this.handleConditions(params);
|
|
273
|
-
case 5:
|
|
274
|
-
params = _context3.sent;
|
|
275
|
-
_context3.next = 8;
|
|
276
|
-
return this.request(params);
|
|
277
|
-
case 8:
|
|
278
|
-
res = _context3.sent;
|
|
279
|
-
return _context3.abrupt("return", this.handleRes(params, res));
|
|
280
|
-
case 10:
|
|
281
|
-
case "end":
|
|
282
|
-
return _context3.stop();
|
|
283
|
-
}
|
|
284
|
-
}, _callee3, this);
|
|
285
|
-
}));
|
|
286
|
-
function exec(_x4) {
|
|
287
|
-
return _exec.apply(this, arguments);
|
|
61
|
+
function fetcher(_x3, _x4) {
|
|
62
|
+
return _fetcher.apply(this, arguments);
|
|
288
63
|
}
|
|
289
|
-
return
|
|
290
|
-
}()
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
value: function add(data, isReturn, conditions) {
|
|
294
|
-
return this.exec({
|
|
295
|
-
method: Method.Add,
|
|
296
|
-
conditions: conditions,
|
|
297
|
-
data: data,
|
|
298
|
-
isReturn: isReturn
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// 删
|
|
303
|
-
}, {
|
|
304
|
-
key: "delete",
|
|
305
|
-
value: function _delete(conditions) {
|
|
306
|
-
return this.exec({
|
|
307
|
-
method: Method.Delete,
|
|
308
|
-
conditions: conditions
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// 改
|
|
313
|
-
}, {
|
|
314
|
-
key: "update",
|
|
315
|
-
value: function update(conditions, data, isReturn, isSet) {
|
|
316
|
-
return this.exec({
|
|
317
|
-
method: Method.Update,
|
|
318
|
-
conditions: conditions,
|
|
319
|
-
data: data,
|
|
320
|
-
isReturn: isReturn,
|
|
321
|
-
isSet: isSet
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// 查
|
|
326
|
-
}, {
|
|
327
|
-
key: "find",
|
|
328
|
-
value: function find(conditions) {
|
|
329
|
-
return this.exec({
|
|
330
|
-
method: Method.Find,
|
|
331
|
-
conditions: conditions
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// 查列表
|
|
336
|
-
}, {
|
|
337
|
-
key: "findList",
|
|
338
|
-
value: function findList(conditions) {
|
|
339
|
-
return this.exec({
|
|
340
|
-
method: Method.FindList,
|
|
341
|
-
conditions: conditions
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// 查
|
|
346
|
-
}, {
|
|
347
|
-
key: "count",
|
|
348
|
-
value: function count(conditions) {
|
|
349
|
-
return this.exec({
|
|
350
|
-
method: Method.Count,
|
|
351
|
-
conditions: conditions
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
}]);
|
|
355
|
-
return Collection;
|
|
356
|
-
}();
|
|
64
|
+
return fetcher;
|
|
65
|
+
}()
|
|
66
|
+
});
|
|
67
|
+
};
|
|
@@ -8,4 +8,3 @@ export declare const hexToRgba: (hexColor: string, a?: number) => {
|
|
|
8
8
|
};
|
|
9
9
|
export declare const flashBackground: (el: string | Element, color: string, a?: number) => void;
|
|
10
10
|
export declare const flashBorder: (el: string | Element, color: string, a?: number) => void;
|
|
11
|
-
//# sourceMappingURL=style.d.ts.map
|
package/dist/esm/browser.d.ts
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
8
|
+
import { levenshteinDistance } from "./string";
|
|
9
|
+
|
|
10
|
+
// 数组随机变换位置
|
|
11
|
+
export var shuffleArray = function shuffleArray(array) {
|
|
12
|
+
var shuffledArray = _toConsumableArray(array); // 创建数组的副本以避免修改原数组
|
|
13
|
+
for (var i = shuffledArray.length - 1; i > 0; i--) {
|
|
14
|
+
var j = Math.floor(Math.random() * (i + 1));
|
|
15
|
+
var _ref = [shuffledArray[j], shuffledArray[i]];
|
|
16
|
+
shuffledArray[i] = _ref[0];
|
|
17
|
+
shuffledArray[j] = _ref[1];
|
|
18
|
+
}
|
|
19
|
+
return shuffledArray;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// 去重函数,接受一个字符串数组,返回一个相似程度高的去重后的数组
|
|
23
|
+
export var removeSimilarDuplicates = function removeSimilarDuplicates(arr, threshold, isLog) {
|
|
24
|
+
var uniqueArray = [];
|
|
25
|
+
var similarPairs = []; // 用于存储相似的字符串对
|
|
26
|
+
var _iterator = _createForOfIteratorHelper(arr),
|
|
27
|
+
_step;
|
|
28
|
+
try {
|
|
29
|
+
var _loop = function _loop() {
|
|
30
|
+
var str = _step.value;
|
|
31
|
+
var isSimilar = uniqueArray.some(function (uniqueStr) {
|
|
32
|
+
var distance = levenshteinDistance(str, uniqueStr);
|
|
33
|
+
if (distance <= threshold) {
|
|
34
|
+
similarPairs.push([str, uniqueStr]); // 记录相似字符串对
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
});
|
|
39
|
+
if (!isSimilar) {
|
|
40
|
+
uniqueArray.push(str);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
44
|
+
_loop();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 打印相似的字符串
|
|
48
|
+
} catch (err) {
|
|
49
|
+
_iterator.e(err);
|
|
50
|
+
} finally {
|
|
51
|
+
_iterator.f();
|
|
52
|
+
}
|
|
53
|
+
if (isLog) {
|
|
54
|
+
if (similarPairs.length > 0) {
|
|
55
|
+
similarPairs.forEach(function (pair) {
|
|
56
|
+
console.log(pair[0]);
|
|
57
|
+
console.log(pair[1]);
|
|
58
|
+
console.log();
|
|
59
|
+
});
|
|
60
|
+
} else {
|
|
61
|
+
console.log('没有找到类似的字符串');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return uniqueArray;
|
|
65
|
+
};
|
package/dist/esm/common/dayjs.js
CHANGED
package/dist/esm/common/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const getRandomNum: (min: number, max: number) => number;
|
|
2
2
|
export declare const limitDecimals: (v: string, num: number | undefined, isForce: boolean) => string;
|
|
3
3
|
export declare const getFileSize: (size: number) => string;
|
|
4
|
-
|
|
4
|
+
export declare const isValidNumber: (value: any) => boolean;
|
|
@@ -28,4 +28,25 @@ export var getFileSize = function getFileSize(size) {
|
|
|
28
28
|
}
|
|
29
29
|
// @ts-ignore
|
|
30
30
|
return "".concat((s.toFixed(1) / 1).toString()).concat(d);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// 校验是否为有效的数值
|
|
34
|
+
export var isValidNumber = function isValidNumber(value) {
|
|
35
|
+
// 检查是否为数字类型
|
|
36
|
+
if (typeof value !== 'number') {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 检查是否为 NaN
|
|
41
|
+
if (isNaN(value)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 检查是否为 Infinity 或 -Infinity
|
|
46
|
+
if (value === Infinity || value === -Infinity) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 如果以上检查都通过,则是有效的数值
|
|
51
|
+
return true;
|
|
31
52
|
};
|
|
@@ -17,4 +17,5 @@ export declare const getSliceStr: (str: string, before: string, after: string) =
|
|
|
17
17
|
export declare const getProxyUrl: (url: string) => string;
|
|
18
18
|
export declare const getLength: (value: string) => number;
|
|
19
19
|
export declare const getCookie: (name: string) => string | null;
|
|
20
|
-
|
|
20
|
+
export declare const generateAlphabetArray: (n: number) => string[];
|
|
21
|
+
export declare const levenshteinDistance: (a: string, b: string) => number;
|