@pisell/core 1.0.1 → 1.0.2

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.
Files changed (124) hide show
  1. package/es/app/app.d.ts +15 -54
  2. package/es/app/app.js +33 -48
  3. package/es/app/const.js +3 -3
  4. package/es/app/index.d.ts +1 -1
  5. package/es/app/index.js +9 -11
  6. package/es/applicationManager/application.d.ts +2 -2
  7. package/es/applicationManager/application.js +9 -12
  8. package/es/applicationManager/index.js +4 -4
  9. package/es/config.js +5 -5
  10. package/es/data/index.d.ts +8 -29
  11. package/es/data/index.js +16 -8
  12. package/es/history/config.js +5 -5
  13. package/es/history/index.d.ts +1 -1
  14. package/es/history/index.js +4 -4
  15. package/es/hooks/useDelayedValue/index.js +1 -1
  16. package/es/hooks/useLowCode/index.js +5 -5
  17. package/es/hooks/useStore/index.d.ts +2 -2
  18. package/es/index.d.ts +0 -7
  19. package/es/index.js +8 -7
  20. package/es/indexDB/index.d.ts +3 -1
  21. package/es/indexDB/index.js +28 -22
  22. package/es/locales/index.d.ts +30 -89
  23. package/es/locales/index.js +202 -243
  24. package/es/locales/type.d.ts +3 -3
  25. package/es/logger/feishu.js +2 -2
  26. package/es/logger/index.d.ts +1 -1
  27. package/es/logger/index.js +31 -23
  28. package/es/menuManager/hooks.d.ts +10 -1
  29. package/es/menuManager/hooks.js +4 -6
  30. package/es/menuManager/index.d.ts +1 -1
  31. package/es/menuManager/index.js +3 -3
  32. package/es/models/global.js +8 -7
  33. package/es/models/index.d.ts +6 -6
  34. package/es/models/index.js +1 -2
  35. package/es/pubsub/index.d.ts +1 -1
  36. package/es/pubsub/index.js +3 -3
  37. package/es/request/cache.d.ts +1 -1
  38. package/es/request/cache.js +7 -6
  39. package/es/request/config.js +7 -7
  40. package/es/request/index.js +12 -11
  41. package/es/request/pisell2Request.d.ts +1 -1
  42. package/es/request/pisell2Request.js +5 -5
  43. package/es/request/type.d.ts +1 -0
  44. package/es/request/utils.js +5 -3
  45. package/es/routes/index.d.ts +2 -2
  46. package/es/routes/index.js +11 -17
  47. package/es/socket/components/SocketMonitorPage.js +255 -462
  48. package/es/socket/events.js +3 -3
  49. package/es/socket/heartbeat.js +6 -7
  50. package/es/socket/index.js +7 -7
  51. package/es/socket/monitor.d.ts +1 -1
  52. package/es/socket/monitor.js +24 -15
  53. package/es/socket/reconnect.js +9 -9
  54. package/es/socket/socket.js +11 -13
  55. package/es/socket/types.d.ts +2 -1
  56. package/es/socket/types.js +23 -7
  57. package/es/storage/index.d.ts +17 -42
  58. package/es/storage/index.js +55 -61
  59. package/es/tasks/index.d.ts +1 -1
  60. package/es/tasks/index.js +46 -22
  61. package/es/tasks/type.d.ts +4 -4
  62. package/es/tasks/useTasks.d.ts +2 -1
  63. package/es/tasks/useTasks.js +1 -1
  64. package/es/variables/VariablesProvider.js +3 -5
  65. package/es/variables/config.js +5 -5
  66. package/es/variables/index.d.ts +3 -3
  67. package/lib/app/app.d.ts +15 -54
  68. package/lib/app/app.js +7 -10
  69. package/lib/app/index.d.ts +1 -1
  70. package/lib/applicationManager/application.d.ts +2 -2
  71. package/lib/data/index.d.ts +8 -29
  72. package/lib/data/index.js +8 -22
  73. package/lib/history/index.d.ts +1 -1
  74. package/lib/hooks/useStore/index.d.ts +2 -2
  75. package/lib/index.d.ts +0 -7
  76. package/lib/index.js +0 -37
  77. package/lib/indexDB/index.d.ts +3 -1
  78. package/lib/indexDB/index.js +8 -18
  79. package/lib/locales/index.d.ts +30 -89
  80. package/lib/locales/index.js +111 -124
  81. package/lib/locales/type.d.ts +3 -3
  82. package/lib/logger/index.d.ts +1 -1
  83. package/lib/menuManager/hooks.d.ts +10 -1
  84. package/lib/menuManager/index.d.ts +1 -1
  85. package/lib/models/index.d.ts +6 -6
  86. package/lib/models/index.js +1 -2
  87. package/lib/pubsub/index.d.ts +1 -1
  88. package/lib/request/cache.d.ts +1 -1
  89. package/lib/request/config.js +2 -12
  90. package/lib/request/index.js +5 -1
  91. package/lib/request/pisell2Request.d.ts +1 -1
  92. package/lib/request/type.d.ts +1 -0
  93. package/lib/request/utils.js +2 -0
  94. package/lib/routes/index.d.ts +2 -2
  95. package/lib/socket/monitor.d.ts +1 -1
  96. package/lib/socket/types.d.ts +2 -1
  97. package/lib/storage/index.d.ts +17 -42
  98. package/lib/storage/index.js +35 -38
  99. package/lib/tasks/index.d.ts +1 -1
  100. package/lib/tasks/type.d.ts +4 -4
  101. package/lib/tasks/useTasks.d.ts +2 -1
  102. package/lib/variables/VariablesProvider.js +1 -1
  103. package/lib/variables/index.d.ts +3 -3
  104. package/package.json +11 -4
  105. package/es/locales/config.d.ts +0 -24
  106. package/es/locales/config.js +0 -59
  107. package/es/models/tasks.d.ts +0 -31
  108. package/es/models/tasks.js +0 -331
  109. package/es/models/tasksUtils.d.ts +0 -65
  110. package/es/models/tasksUtils.js +0 -179
  111. package/es/storage/config.d.ts +0 -3
  112. package/es/storage/config.js +0 -16
  113. package/es/storage/type.d.ts +0 -5
  114. package/es/storage/type.js +0 -1
  115. package/lib/locales/config.d.ts +0 -24
  116. package/lib/locales/config.js +0 -66
  117. package/lib/models/tasks.d.ts +0 -31
  118. package/lib/models/tasks.js +0 -199
  119. package/lib/models/tasksUtils.d.ts +0 -65
  120. package/lib/models/tasksUtils.js +0 -160
  121. package/lib/storage/config.d.ts +0 -3
  122. package/lib/storage/config.js +0 -38
  123. package/lib/storage/type.d.ts +0 -5
  124. package/lib/storage/type.js +0 -17
@@ -1,179 +0,0 @@
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 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; }
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; }
4
- 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; }
5
- 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); } }
6
- 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); }); }; }
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
- 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
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
12
- 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 storage from "../storage";
14
- import dayjs from 'dayjs';
15
- import { getUniqueId } from '@pisell/utils';
16
- var getStorage = storage.getStorage,
17
- setStorage = storage.setStorage;
18
-
19
- // 任务
20
-
21
- export var TasksManager = /*#__PURE__*/function () {
22
- function TasksManager() {
23
- var _this = this;
24
- _classCallCheck(this, TasksManager);
25
- _defineProperty(this, "tasks", void 0);
26
- _defineProperty(this, "saveTaskQueueToLocalStorage", function (state) {
27
- setStorage('tasks', JSON.stringify(state));
28
- });
29
- _defineProperty(this, "loadTaskQueueFromLocalStorage", function () {
30
- var tasks = getStorage('tasks');
31
- return tasks ? JSON.parse(tasks) : null;
32
- });
33
- _defineProperty(this, "runTask", /*#__PURE__*/function () {
34
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(task) {
35
- var beforeAction, afterAction, action, res;
36
- return _regeneratorRuntime().wrap(function _callee$(_context) {
37
- while (1) switch (_context.prev = _context.next) {
38
- case 0:
39
- // 执行任务前的钩子
40
- beforeAction = _this.getTask(task.beforeAction); // 执行任务后的钩子
41
- afterAction = _this.getTask(task.afterAction); // 当前任务
42
- action = _this.getTask(task.action);
43
- res = {
44
- status: "success"
45
- };
46
- _context.prev = 4;
47
- if (!beforeAction) {
48
- _context.next = 8;
49
- break;
50
- }
51
- _context.next = 8;
52
- return beforeAction(task.beforePayload);
53
- case 8:
54
- if (!action) {
55
- _context.next = 12;
56
- break;
57
- }
58
- _context.next = 11;
59
- return action(task.payload);
60
- case 11:
61
- res = _context.sent;
62
- case 12:
63
- if (!afterAction) {
64
- _context.next = 15;
65
- break;
66
- }
67
- _context.next = 15;
68
- return afterAction(task.afterPayload);
69
- case 15:
70
- _context.next = 20;
71
- break;
72
- case 17:
73
- _context.prev = 17;
74
- _context.t0 = _context["catch"](4);
75
- res = {
76
- status: "failure"
77
- };
78
- case 20:
79
- return _context.abrupt("return", res);
80
- case 21:
81
- case "end":
82
- return _context.stop();
83
- }
84
- }, _callee, null, [[4, 17]]);
85
- }));
86
- return function (_x) {
87
- return _ref.apply(this, arguments);
88
- };
89
- }());
90
- _defineProperty(this, "createTaskData", function (payload) {
91
- return _objectSpread({
92
- id: getUniqueId('task_'),
93
- create_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
94
- type: 'local',
95
- retries: 0,
96
- maxRetries: 3,
97
- status: 'pending',
98
- // 执行函数
99
- action: '',
100
- // 执行参数
101
- payload: {},
102
- // 执行前的钩子
103
- beforeAction: '',
104
- // 执行前的参数
105
- beforePayload: {},
106
- // 执行后的钩子
107
- afterAction: '',
108
- // 执行后的参数
109
- afterPayload: {}
110
- }, payload);
111
- });
112
- _defineProperty(this, "createTask", function (payload) {
113
- dispatch({
114
- type: "tasks/addTasks",
115
- payload: {
116
- queueId: "order_1",
117
- module: "orders",
118
- tasks: [{
119
- action: "createOrder",
120
- payload: {
121
- order: 1
122
- }
123
- }, {
124
- action: "syncCloudOrder",
125
- payload: {
126
- order: 1
127
- }
128
- }, {
129
- action: "goPayment",
130
- payload: {
131
- order: 1
132
- }
133
- }]
134
- }
135
- });
136
- });
137
- this.tasks = new Map();
138
- }
139
-
140
- // 单例模式
141
- _createClass(TasksManager, [{
142
- key: "useTask",
143
- value:
144
- // 注册任务
145
- function useTask(name, plugin) {
146
- this.tasks.set(name, plugin);
147
- }
148
- // 注册任务列表
149
- }, {
150
- key: "useTasks",
151
- value: function useTasks(tasks) {
152
- var _this2 = this;
153
- tasks.forEach(function (_ref2) {
154
- var name = _ref2.name,
155
- plugin = _ref2.plugin;
156
- _this2.tasks.set(name, plugin);
157
- });
158
- }
159
-
160
- // 获取任务
161
- }, {
162
- key: "getTask",
163
- value: function getTask(name) {
164
- return this.tasks.get(name);
165
- }
166
-
167
- // 将任务队列状态同步到 localStorage
168
- }], [{
169
- key: "getInstance",
170
- value: function getInstance() {
171
- if (!TasksManager.instance) {
172
- TasksManager.instance = new TasksManager();
173
- }
174
- return TasksManager.instance;
175
- }
176
- }]);
177
- return TasksManager;
178
- }();
179
- _defineProperty(TasksManager, "instance", void 0);
@@ -1,3 +0,0 @@
1
- import { StorageConfig } from './type';
2
- export declare const setConfig: (newConfig: Partial<StorageConfig>) => void;
3
- export declare const getConfig: () => StorageConfig;
@@ -1,16 +0,0 @@
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 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; }
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; }
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; }
5
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
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); }
7
- var defaultConfig = {
8
- STORAGE_KEY: 'CapacitorStorage.native_'
9
- };
10
- var config = _objectSpread({}, defaultConfig);
11
- export var setConfig = function setConfig(newConfig) {
12
- config = _objectSpread(_objectSpread({}, config), newConfig);
13
- };
14
- export var getConfig = function getConfig() {
15
- return config;
16
- };
@@ -1,5 +0,0 @@
1
- export interface StorageConfig {
2
- STORAGE_KEY: string;
3
- setStorageAfter?: (key: string, value: string) => void;
4
- removeStorageAfter?: (key: string) => string;
5
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,24 +0,0 @@
1
- import { LocaleConfig } from './type';
2
- /**
3
- * @title: 默认配置
4
- * @description:
5
- * @return {*}
6
- * @Author: zhiwei.Wang
7
- */
8
- export declare const defaultConfig: LocaleConfig;
9
- /**
10
- * @title: 设置配置
11
- * @description:
12
- * @param {Partial} newConfig
13
- * @return {*}
14
- * @Author: zhiwei.Wang
15
- */
16
- export declare const setConfig: (newConfig: Partial<LocaleConfig>) => LocaleConfig;
17
- /**
18
- * @title: 获取配置
19
- * @description:
20
- * @param {*} LocaleConfig
21
- * @return {*}
22
- * @Author: zhiwei.Wang
23
- */
24
- export declare const getConfig: () => LocaleConfig;
@@ -1,66 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
29
- // src/locales/config.ts
30
- var config_exports = {};
31
- __export(config_exports, {
32
- defaultConfig: () => defaultConfig,
33
- getConfig: () => getConfig,
34
- setConfig: () => setConfig
35
- });
36
- module.exports = __toCommonJS(config_exports);
37
- var import_en = __toESM(require("./en"));
38
- var import_zh_CN = __toESM(require("./zh-CN"));
39
- var import_zh_HK = __toESM(require("./zh-HK"));
40
- var import_original = __toESM(require("./original"));
41
- var import_storage = __toESM(require("../storage"));
42
- var storageLocale = import_storage.default.getStorage("locale");
43
- var defaultConfig = {
44
- // 当前语言 本地语言 > 英文语言包
45
- locale: storageLocale || import_en.default.locale,
46
- // 语言包
47
- library: [import_original.default, import_en.default, import_zh_CN.default, import_zh_HK.default].reduce((pre, cur) => {
48
- pre[cur.locale] = cur;
49
- return pre;
50
- }, {})
51
- };
52
- var config = {
53
- ...defaultConfig
54
- };
55
- var setConfig = (newConfig) => {
56
- config = { ...config, ...newConfig };
57
- import_storage.default.setStorage("locale", config.locale);
58
- return config;
59
- };
60
- var getConfig = () => config;
61
- // Annotate the CommonJS export names for ESM import in node:
62
- 0 && (module.exports = {
63
- defaultConfig,
64
- getConfig,
65
- setConfig
66
- });
@@ -1,31 +0,0 @@
1
- import { Effect, Subscription } from 'dva';
2
- import { Reducer } from 'redux';
3
- import { Task } from './tasksUtils';
4
- export interface TasksModal {
5
- namespace: 'tasks';
6
- state: {
7
- global: {
8
- [key: string]: {
9
- status: "uncompleted" | "completed";
10
- tasks: Task[];
11
- };
12
- };
13
- };
14
- effects: {
15
- init: Effect;
16
- executeQueue: Effect;
17
- retryTask: Effect;
18
- addTasks: Effect;
19
- };
20
- reducers: {
21
- setState: Reducer<any>;
22
- updateTask: Reducer<any>;
23
- updateQueueStatus: Reducer<any>;
24
- setTasks: Reducer<any>;
25
- };
26
- subscriptions: {
27
- _init: Subscription;
28
- };
29
- }
30
- declare const TaskQueueModel: TasksModal;
31
- export default TaskQueueModel;
@@ -1,199 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/models/tasks.ts
20
- var tasks_exports = {};
21
- __export(tasks_exports, {
22
- default: () => tasks_default
23
- });
24
- module.exports = __toCommonJS(tasks_exports);
25
- var import_tasksUtils = require("./tasksUtils");
26
- var tasksManager = import_tasksUtils.TasksManager.getInstance();
27
- var TaskQueueModel = {
28
- namespace: "tasks",
29
- state: {
30
- global: {
31
- init: {
32
- status: "uncompleted",
33
- tasks: []
34
- }
35
- }
36
- },
37
- effects: {
38
- /**
39
- * @title: 初始化
40
- * @description:
41
- * @return {*}
42
- * @Author: zhiwei.Wang
43
- * @Date: 2024-09-26 13:52
44
- */
45
- *init({ params }, { put, call }) {
46
- const tasks = tasksManager.loadTaskQueueFromLocalStorage();
47
- if (tasks) {
48
- yield put({
49
- type: "setState",
50
- payload: tasks
51
- });
52
- }
53
- },
54
- /**
55
- * @title: 执行任务队列
56
- * @description:
57
- * @return {*}
58
- * @Author: zhiwei.Wang
59
- * @Date: 2024-09-26 13:52
60
- */
61
- *executeQueue({ payload }, { call, put, select }) {
62
- const { queueId, module: module2 } = payload;
63
- const taskQueue = yield select((state) => {
64
- var _a, _b, _c;
65
- return (_c = (_b = (_a = state["tasks"]) == null ? void 0 : _a[module2]) == null ? void 0 : _b[queueId]) == null ? void 0 : _c.tasks;
66
- });
67
- if (taskQueue && taskQueue.length) {
68
- const tasksToExecute = taskQueue.filter(
69
- (task) => task.status === "pending" || task.status === "failure"
70
- );
71
- for (let task of tasksToExecute) {
72
- try {
73
- if (task.retries < task.maxRetries) {
74
- task.status = "in-progress";
75
- yield put({
76
- type: "updateTask",
77
- payload: { module: module2, queueId, taskId: task.id, other: { status: "in-progress" } }
78
- });
79
- const { status } = yield call(tasksManager.runTask, task);
80
- task.status = status;
81
- let _other = {
82
- status
83
- };
84
- if (status === "failure") {
85
- _other.retries = task.retries + 1;
86
- }
87
- yield put({
88
- type: "updateTask",
89
- payload: { module: module2, queueId, taskId: task.id, other: _other }
90
- });
91
- }
92
- } catch (error) {
93
- console.error("任务异常", error);
94
- }
95
- }
96
- yield put({
97
- type: "updateQueueStatus",
98
- payload: { queueId, module: module2, status: tasksToExecute.some((task) => task.status === "failure") ? "uncompleted" : "completed" }
99
- });
100
- console.log("任务队列执行完成", taskQueue);
101
- }
102
- },
103
- /**
104
- * @title: 重试任务
105
- * @description:
106
- * @return {*}
107
- * @Author: zhiwei.Wang
108
- * @Date: 2024-09-26 13:53
109
- */
110
- *retryTask({ payload }, { put }) {
111
- const { queueId, module: module2 } = payload;
112
- yield put({ type: "executeQueue", payload: { queueId, module: module2 } });
113
- },
114
- // 添加任务
115
- *addTasks({ payload }, { put, select }) {
116
- const { queueId, module: module2, tasks } = payload;
117
- const taskQueue = yield select((state) => {
118
- var _a, _b, _c;
119
- return (_c = (_b = (_a = state["tasks"]) == null ? void 0 : _a[module2]) == null ? void 0 : _b[queueId]) == null ? void 0 : _c.tasks;
120
- });
121
- let _tasks = [...taskQueue || []];
122
- let newTasks = tasks.map((d) => {
123
- return tasksManager.createTask({ ...d, queueId, module: module2 });
124
- });
125
- _tasks = _tasks.concat(newTasks);
126
- yield put({
127
- type: "setTasks",
128
- payload: { queueId, module: module2, tasks: _tasks }
129
- });
130
- }
131
- },
132
- reducers: {
133
- setState(state, { payload }) {
134
- return { ...state, ...payload };
135
- },
136
- // 更新任务状态
137
- updateTask(state, { payload }) {
138
- var _a, _b;
139
- const { queueId, taskId, other, module: module2 } = payload;
140
- const taskQueue = ((_b = (_a = state[module2]) == null ? void 0 : _a[queueId]) == null ? void 0 : _b.tasks) || [];
141
- const updatedTasks = taskQueue.map((task) => {
142
- if (task.id === taskId) {
143
- return { ...task, ...other };
144
- }
145
- return task;
146
- });
147
- const newState = {
148
- ...state,
149
- [module2]: {
150
- ...state[module2],
151
- [queueId]: {
152
- ...state[module2][queueId],
153
- status: updatedTasks.some((task) => task.status === "failure") ? "uncompleted" : "completed",
154
- tasks: updatedTasks
155
- }
156
- }
157
- };
158
- tasksManager.saveTaskQueueToLocalStorage(newState);
159
- return newState;
160
- },
161
- updateQueueStatus(state, { payload }) {
162
- const { queueId, status, module: module2 } = payload;
163
- const newState = {
164
- ...state,
165
- [module2]: {
166
- ...state[module2],
167
- [queueId]: {
168
- ...state[module2][queueId],
169
- status
170
- }
171
- }
172
- };
173
- tasksManager.saveTaskQueueToLocalStorage(newState);
174
- return newState;
175
- },
176
- // 设置任务
177
- setTasks(state, { payload }) {
178
- const { queueId, module: module2, tasks } = payload;
179
- const newState = {
180
- ...state,
181
- [module2]: {
182
- ...state[module2],
183
- [queueId]: {
184
- ...state[module2][queueId],
185
- tasks
186
- }
187
- }
188
- };
189
- tasksManager.saveTaskQueueToLocalStorage(newState);
190
- return newState;
191
- }
192
- },
193
- subscriptions: {
194
- _init({ dispatch }) {
195
- dispatch({ type: "init" });
196
- }
197
- }
198
- };
199
- var tasks_default = TaskQueueModel;
@@ -1,65 +0,0 @@
1
- export interface Task {
2
- id: string;
3
- type: 'local' | 'cloud';
4
- retries: number;
5
- maxRetries: number;
6
- status: 'pending' | 'in-progress' | 'success' | 'failure';
7
- action: string;
8
- payload: any;
9
- beforeAction?: string;
10
- beforePayload?: any;
11
- afterAction?: string;
12
- afterPayload?: any;
13
- [key: string]: any;
14
- }
15
- export interface TaskConfig {
16
- tasks: Task[];
17
- }
18
- export declare class TasksManager {
19
- private static instance;
20
- private tasks;
21
- private constructor();
22
- static getInstance(): TasksManager;
23
- useTask(name: string, plugin: any): void;
24
- useTasks(tasks: {
25
- name: string;
26
- plugin: any;
27
- }[]): void;
28
- getTask(name: string): any;
29
- saveTaskQueueToLocalStorage: (state: any) => void;
30
- loadTaskQueueFromLocalStorage: () => any;
31
- /**
32
- * @title: 执行任务
33
- * @description:
34
- * @param {Task} task
35
- * @return {*}
36
- * @Author: zhiwei.Wang
37
- * @Date: 2024-09-26 13:53
38
- */
39
- runTask: (task: Task) => Promise<{
40
- status: string;
41
- }>;
42
- /**
43
- * @title: 创建任务数据
44
- * @description:
45
- * @param {Partial} payload
46
- * @return {*}
47
- * @Author: zhiwei.Wang
48
- * @Date: 2024-09-26 13:54
49
- */
50
- createTaskData: (payload: Partial<Task>) => {
51
- id: string;
52
- type: string;
53
- retries: number;
54
- maxRetries: number;
55
- status: string;
56
- action: string;
57
- payload: any;
58
- beforeAction: string;
59
- beforePayload: any;
60
- afterAction: string;
61
- afterPayload: any;
62
- create_at: string;
63
- };
64
- createTask: (payload: Partial<Task>) => void;
65
- }