@pisell/core 1.0.0 → 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 (267) hide show
  1. package/es/app/app.d.ts +83 -0
  2. package/es/app/app.js +151 -0
  3. package/es/app/const.d.ts +4 -0
  4. package/es/app/const.js +6 -0
  5. package/es/app/index.d.ts +14 -0
  6. package/es/app/index.js +52 -0
  7. package/es/applicationManager/application.d.ts +50 -0
  8. package/es/applicationManager/application.js +223 -0
  9. package/es/applicationManager/index.d.ts +13 -0
  10. package/es/applicationManager/index.js +190 -0
  11. package/es/config.d.ts +3 -3
  12. package/es/config.js +5 -5
  13. package/es/cookie/index.d.ts +13 -0
  14. package/es/cookie/index.js +47 -0
  15. package/es/css/global.less +73 -0
  16. package/es/css/index.less +31 -0
  17. package/es/css/variables.css +84 -0
  18. package/es/data/index.d.ts +8 -0
  19. package/es/data/index.js +16 -0
  20. package/es/{locales → history}/config.d.ts +5 -5
  21. package/es/history/config.js +43 -0
  22. package/es/history/index.d.ts +20 -0
  23. package/es/history/index.js +41 -0
  24. package/es/history/type.d.ts +2 -0
  25. package/es/hooks/index.d.ts +12 -0
  26. package/es/hooks/index.js +13 -0
  27. package/es/hooks/useDelayedValue/index.d.ts +2 -0
  28. package/es/hooks/useDelayedValue/index.js +26 -0
  29. package/es/hooks/useDispatch/index.d.ts +2 -0
  30. package/es/hooks/useDispatch/index.js +2 -0
  31. package/es/hooks/useLowCode/index.d.ts +13 -0
  32. package/es/hooks/useLowCode/index.js +74 -0
  33. package/es/hooks/useStore/index.d.ts +6 -0
  34. package/es/hooks/useStore/index.js +11 -0
  35. package/es/index.d.ts +1 -2
  36. package/es/index.js +9 -2
  37. package/es/indexDB/index.d.ts +178 -0
  38. package/es/indexDB/index.js +542 -0
  39. package/es/locales/en.d.ts +2 -1
  40. package/es/locales/en.js +5 -1
  41. package/es/locales/index.d.ts +37 -53
  42. package/es/locales/index.js +213 -70
  43. package/es/locales/original.d.ts +3 -0
  44. package/es/locales/original.js +7 -0
  45. package/es/locales/type.d.ts +15 -5
  46. package/es/locales/zh-CN.d.ts +2 -1
  47. package/es/locales/zh-CN.js +5 -1
  48. package/es/locales/zh-HK.d.ts +2 -1
  49. package/es/locales/zh-HK.js +5 -1
  50. package/es/logger/feishu.d.ts +11 -0
  51. package/es/logger/feishu.js +50 -0
  52. package/es/logger/index.d.ts +122 -0
  53. package/es/logger/index.js +539 -0
  54. package/es/menuManager/hooks.d.ts +17 -0
  55. package/es/menuManager/hooks.js +136 -0
  56. package/es/menuManager/index.d.ts +28 -0
  57. package/es/menuManager/index.js +142 -0
  58. package/es/models/global.d.ts +32 -0
  59. package/es/models/global.js +66 -0
  60. package/es/models/index.d.ts +45 -0
  61. package/es/models/index.js +65 -0
  62. package/es/models/type.d.ts +2 -0
  63. package/es/models/type.js +1 -0
  64. package/es/plugin/index.d.ts +0 -0
  65. package/es/plugin/index.js +0 -0
  66. package/es/pubsub/example.d.ts +5 -0
  67. package/es/pubsub/example.js +92 -0
  68. package/es/pubsub/index.d.ts +63 -0
  69. package/es/pubsub/index.js +144 -0
  70. package/es/request/cache.d.ts +46 -0
  71. package/es/request/cache.js +311 -0
  72. package/es/request/cancelToken.d.ts +38 -0
  73. package/es/request/cancelToken.js +59 -0
  74. package/es/request/config.d.ts +3 -0
  75. package/es/request/config.js +58 -0
  76. package/es/request/constants.d.ts +2 -0
  77. package/es/request/constants.js +6 -0
  78. package/es/request/index.d.ts +24 -0
  79. package/es/request/index.js +176 -0
  80. package/es/request/pisell2Request.d.ts +6 -0
  81. package/es/request/pisell2Request.js +62 -0
  82. package/es/request/type.d.ts +41 -0
  83. package/es/request/type.js +1 -0
  84. package/es/request/utils.d.ts +46 -0
  85. package/es/request/utils.js +147 -0
  86. package/es/routes/config.d.ts +7 -0
  87. package/es/routes/config.js +17 -0
  88. package/es/routes/index.d.ts +28 -0
  89. package/es/routes/index.js +148 -0
  90. package/es/socket/components/SocketMonitorPage.d.ts +6 -0
  91. package/es/socket/components/SocketMonitorPage.js +485 -0
  92. package/es/socket/components/index.d.ts +2 -0
  93. package/es/socket/components/index.js +2 -0
  94. package/es/socket/constants.d.ts +33 -0
  95. package/es/socket/constants.js +39 -0
  96. package/es/socket/events.d.ts +31 -0
  97. package/es/socket/events.js +19 -0
  98. package/es/socket/heartbeat.d.ts +66 -0
  99. package/es/socket/heartbeat.js +184 -0
  100. package/es/socket/index.d.ts +61 -0
  101. package/es/socket/index.js +246 -0
  102. package/es/socket/monitor.d.ts +169 -0
  103. package/es/socket/monitor.js +447 -0
  104. package/es/socket/reconnect.d.ts +61 -0
  105. package/es/socket/reconnect.js +199 -0
  106. package/es/socket/socket.d.ts +129 -0
  107. package/es/socket/socket.js +595 -0
  108. package/es/socket/types.d.ts +85 -0
  109. package/es/socket/types.js +35 -0
  110. package/es/storage/index.d.ts +17 -0
  111. package/es/storage/index.js +56 -0
  112. package/es/tasks/index.d.ts +77 -0
  113. package/es/tasks/index.js +743 -0
  114. package/es/tasks/type.d.ts +62 -0
  115. package/es/tasks/type.js +1 -0
  116. package/es/tasks/useTasks.d.ts +5 -0
  117. package/es/tasks/useTasks.js +25 -0
  118. package/es/type.d.ts +1 -1
  119. package/es/variables/VariablesProvider.d.ts +7 -0
  120. package/es/variables/VariablesProvider.js +12 -0
  121. package/es/variables/config.d.ts +3 -0
  122. package/es/variables/config.js +16 -0
  123. package/es/variables/index.d.ts +6 -0
  124. package/es/variables/index.js +5 -0
  125. package/es/variables/type.d.ts +2 -0
  126. package/es/variables/type.js +1 -0
  127. package/es/website/index.d.ts +6 -0
  128. package/es/website/index.js +65 -0
  129. package/lib/app/app.d.ts +83 -0
  130. package/lib/app/app.js +125 -0
  131. package/lib/app/const.d.ts +4 -0
  132. package/lib/app/const.js +33 -0
  133. package/lib/app/index.d.ts +14 -0
  134. package/lib/app/index.js +76 -0
  135. package/lib/applicationManager/application.d.ts +50 -0
  136. package/lib/applicationManager/application.js +110 -0
  137. package/lib/applicationManager/index.d.ts +13 -0
  138. package/lib/applicationManager/index.js +76 -0
  139. package/lib/config.d.ts +3 -3
  140. package/lib/cookie/index.d.ts +13 -0
  141. package/lib/cookie/index.js +64 -0
  142. package/lib/css/global.less +73 -0
  143. package/lib/css/index.less +31 -0
  144. package/lib/css/variables.css +84 -0
  145. package/lib/data/index.d.ts +8 -0
  146. package/lib/data/index.js +35 -0
  147. package/lib/{locales → history}/config.d.ts +5 -5
  148. package/lib/history/config.js +41 -0
  149. package/lib/history/index.d.ts +20 -0
  150. package/lib/history/index.js +58 -0
  151. package/lib/history/type.d.ts +2 -0
  152. package/lib/history/type.js +17 -0
  153. package/lib/hooks/index.d.ts +12 -0
  154. package/lib/{date → hooks}/index.js +14 -20
  155. package/lib/hooks/useDelayedValue/index.d.ts +2 -0
  156. package/lib/hooks/useDelayedValue/index.js +36 -0
  157. package/lib/hooks/useDispatch/index.d.ts +2 -0
  158. package/lib/hooks/useDispatch/index.js +26 -0
  159. package/lib/hooks/useLowCode/index.d.ts +13 -0
  160. package/lib/hooks/useLowCode/index.js +75 -0
  161. package/lib/hooks/useStore/index.d.ts +6 -0
  162. package/lib/hooks/useStore/index.js +33 -0
  163. package/lib/index.d.ts +1 -2
  164. package/lib/index.js +3 -22
  165. package/lib/indexDB/index.d.ts +178 -0
  166. package/lib/indexDB/index.js +277 -0
  167. package/lib/locales/en.d.ts +2 -1
  168. package/lib/locales/en.js +5 -1
  169. package/lib/locales/index.d.ts +37 -53
  170. package/lib/locales/index.js +130 -41
  171. package/lib/locales/original.d.ts +3 -0
  172. package/lib/locales/original.js +31 -0
  173. package/lib/locales/type.d.ts +15 -5
  174. package/lib/locales/zh-CN.d.ts +2 -1
  175. package/lib/locales/zh-CN.js +5 -1
  176. package/lib/locales/zh-HK.d.ts +2 -1
  177. package/lib/locales/zh-HK.js +5 -1
  178. package/lib/logger/feishu.d.ts +11 -0
  179. package/lib/logger/feishu.js +52 -0
  180. package/lib/logger/index.d.ts +122 -0
  181. package/lib/logger/index.js +288 -0
  182. package/lib/menuManager/hooks.d.ts +17 -0
  183. package/lib/menuManager/hooks.js +135 -0
  184. package/lib/menuManager/index.d.ts +28 -0
  185. package/lib/menuManager/index.js +110 -0
  186. package/lib/models/global.d.ts +32 -0
  187. package/lib/models/global.js +62 -0
  188. package/lib/models/index.d.ts +45 -0
  189. package/lib/models/index.js +69 -0
  190. package/lib/models/type.d.ts +2 -0
  191. package/lib/models/type.js +17 -0
  192. package/lib/plugin/index.d.ts +0 -0
  193. package/lib/plugin/index.js +0 -0
  194. package/lib/pubsub/example.d.ts +5 -0
  195. package/lib/pubsub/example.js +61 -0
  196. package/lib/pubsub/index.d.ts +63 -0
  197. package/lib/pubsub/index.js +129 -0
  198. package/lib/request/cache.d.ts +46 -0
  199. package/lib/request/cache.js +159 -0
  200. package/lib/request/cancelToken.d.ts +38 -0
  201. package/lib/request/cancelToken.js +59 -0
  202. package/lib/request/config.d.ts +3 -0
  203. package/lib/request/config.js +64 -0
  204. package/lib/request/constants.d.ts +2 -0
  205. package/lib/request/constants.js +34 -0
  206. package/lib/request/index.d.ts +24 -0
  207. package/lib/request/index.js +147 -0
  208. package/lib/request/pisell2Request.d.ts +6 -0
  209. package/lib/request/pisell2Request.js +75 -0
  210. package/lib/request/type.d.ts +41 -0
  211. package/lib/request/type.js +17 -0
  212. package/lib/request/utils.d.ts +46 -0
  213. package/lib/request/utils.js +113 -0
  214. package/lib/routes/config.d.ts +7 -0
  215. package/lib/routes/config.js +50 -0
  216. package/lib/routes/index.d.ts +28 -0
  217. package/lib/routes/index.js +118 -0
  218. package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
  219. package/lib/socket/components/SocketMonitorPage.js +346 -0
  220. package/lib/socket/components/index.d.ts +2 -0
  221. package/lib/socket/components/index.js +39 -0
  222. package/lib/socket/constants.d.ts +33 -0
  223. package/lib/socket/constants.js +62 -0
  224. package/lib/socket/events.d.ts +31 -0
  225. package/lib/socket/events.js +44 -0
  226. package/lib/socket/heartbeat.d.ts +66 -0
  227. package/lib/socket/heartbeat.js +152 -0
  228. package/lib/socket/index.d.ts +61 -0
  229. package/lib/socket/index.js +200 -0
  230. package/lib/socket/monitor.d.ts +169 -0
  231. package/lib/socket/monitor.js +346 -0
  232. package/lib/socket/reconnect.d.ts +61 -0
  233. package/lib/socket/reconnect.js +153 -0
  234. package/lib/socket/socket.d.ts +129 -0
  235. package/lib/socket/socket.js +410 -0
  236. package/lib/socket/types.d.ts +85 -0
  237. package/lib/socket/types.js +36 -0
  238. package/lib/storage/index.d.ts +17 -0
  239. package/lib/storage/index.js +63 -0
  240. package/lib/tasks/index.d.ts +77 -0
  241. package/lib/tasks/index.js +438 -0
  242. package/lib/tasks/type.d.ts +62 -0
  243. package/lib/{date → tasks}/type.js +1 -1
  244. package/lib/tasks/useTasks.d.ts +5 -0
  245. package/lib/tasks/useTasks.js +37 -0
  246. package/lib/type.d.ts +1 -1
  247. package/lib/variables/VariablesProvider.d.ts +7 -0
  248. package/lib/{locales/config.js → variables/VariablesProvider.js} +17 -29
  249. package/lib/variables/config.d.ts +3 -0
  250. package/lib/{date → variables}/config.js +2 -7
  251. package/lib/variables/index.d.ts +6 -0
  252. package/lib/variables/index.js +29 -0
  253. package/lib/variables/type.d.ts +2 -0
  254. package/lib/variables/type.js +17 -0
  255. package/lib/website/index.d.ts +6 -0
  256. package/lib/website/index.js +75 -0
  257. package/package.json +22 -5
  258. package/es/date/config.d.ts +0 -3
  259. package/es/date/config.js +0 -21
  260. package/es/date/index.d.ts +0 -7
  261. package/es/date/index.js +0 -22
  262. package/es/date/type.d.ts +0 -7
  263. package/es/locales/config.js +0 -57
  264. package/lib/date/config.d.ts +0 -3
  265. package/lib/date/index.d.ts +0 -7
  266. package/lib/date/type.d.ts +0 -7
  267. /package/es/{date → history}/type.js +0 -0
@@ -0,0 +1,438 @@
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/tasks/index.ts
30
+ var tasks_exports = {};
31
+ __export(tasks_exports, {
32
+ TasksManager: () => TasksManager
33
+ });
34
+ module.exports = __toCommonJS(tasks_exports);
35
+ var import_dayjs = __toESM(require("dayjs"));
36
+ var import_utils = require("@pisell/utils");
37
+ var import_useTasks = __toESM(require("./useTasks"));
38
+ var TasksManager = class {
39
+ constructor(app) {
40
+ this.useTasks = import_useTasks.default;
41
+ this.watchTaskCallback = () => {
42
+ };
43
+ // 将任务队列状态同步到 local
44
+ this.saveTaskQueueToLocal = async (state) => {
45
+ var _a;
46
+ console.log("saveTaskQueueToLocal", state);
47
+ let tasksData = await this.db.get("tasks", "tasks");
48
+ const newData = { id: "tasks", ...state };
49
+ if (!tasksData) {
50
+ await this.db.add("tasks", newData);
51
+ } else {
52
+ await this.db.update("tasks", newData);
53
+ }
54
+ (_a = this.watchTaskCallback) == null ? void 0 : _a.call(this, this.tasks);
55
+ };
56
+ // 从 local 加载任务队列状态
57
+ this.loadTaskQueueFromLocal = async () => {
58
+ var _a, _b;
59
+ try {
60
+ const tasks = await this.db.get("tasks", "tasks");
61
+ for (let module2 in tasks) {
62
+ for (let queueId in tasks[module2]) {
63
+ for (let task of ((_b = (_a = tasks == null ? void 0 : tasks[module2]) == null ? void 0 : _a[queueId]) == null ? void 0 : _b.tasks) || []) {
64
+ if (task.destroy) {
65
+ delete tasks[module2][queueId].tasks;
66
+ }
67
+ }
68
+ }
69
+ }
70
+ return tasks;
71
+ } catch (err) {
72
+ console.log("loadTaskQueueFromLocal", err);
73
+ return null;
74
+ }
75
+ };
76
+ /**
77
+ * @title: 执行任务
78
+ * @description:
79
+ * @param {Task} task
80
+ * @return {*}
81
+ * @Author: zhiwei.Wang
82
+ * @Date: 2024-09-26 13:53
83
+ */
84
+ this.runTask = async (task) => {
85
+ const beforeAction = this.getTaskFunction(task.beforeAction || "");
86
+ const afterAction = this.getTaskFunction(task.afterAction || "");
87
+ const action = this.getTaskFunction(task.action || "");
88
+ let beforeActionRes;
89
+ let afterActionRes;
90
+ let actionRes = { status: "success" };
91
+ try {
92
+ if (beforeAction) {
93
+ beforeActionRes = await beforeAction({ task });
94
+ }
95
+ if (action) {
96
+ actionRes = await action({ task, beforeActionRes });
97
+ }
98
+ if (afterAction) {
99
+ afterActionRes = await afterAction({ task, actionRes, afterActionRes });
100
+ }
101
+ } catch (error) {
102
+ this.app.logger.addLog({
103
+ type: "error",
104
+ title: `任务执行失败-${task.id}`,
105
+ metadata: { error, taskPayload: task == null ? void 0 : task.payload }
106
+ });
107
+ console.log("任务执行失败", error);
108
+ actionRes = { status: "failure" };
109
+ }
110
+ console.log("Tasks--->", `任务执行成功: ${task.id}`);
111
+ return actionRes;
112
+ };
113
+ /**
114
+ * @title: 启动轮询
115
+ * @description: 根据轮询间隔定期执行任务
116
+ * @param {Task} task
117
+ * @return {*}
118
+ */
119
+ this.startPolling = (task) => {
120
+ if (!task.polling || !task.polling.interval) {
121
+ console.log("不是轮询任务");
122
+ return;
123
+ }
124
+ const timerId = setTimeout(async () => {
125
+ var _a;
126
+ try {
127
+ await this.runTask(task);
128
+ console.log("轮询任务", task);
129
+ let _task = { ...task };
130
+ _task.pollingResult = {
131
+ count: (((_a = _task.pollingResult) == null ? void 0 : _a.count) || 0) + 1,
132
+ timerId
133
+ };
134
+ const newTask = this.updateTask({
135
+ module: task.module,
136
+ queueId: task.queueId,
137
+ taskId: task.id,
138
+ other: _task
139
+ });
140
+ if (!newTask) {
141
+ return;
142
+ }
143
+ this.startPolling(newTask);
144
+ } catch (error) {
145
+ clearTimeout(timerId);
146
+ console.error("轮询任务异常", error);
147
+ }
148
+ }, task.polling.interval);
149
+ };
150
+ /**
151
+ * @title: 创建任务数据
152
+ * @description:
153
+ * @param {Partial} payload
154
+ * @return {*}
155
+ * @Author: zhiwei.Wang
156
+ * @Date: 2024-09-26 13:54
157
+ */
158
+ this.createTaskData = (payload) => {
159
+ return {
160
+ id: (0, import_utils.getUniqueId)("task_"),
161
+ create_at: (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss"),
162
+ type: "local",
163
+ retries: 0,
164
+ maxRetries: 3,
165
+ status: "pending",
166
+ // 执行函数
167
+ action: "",
168
+ // 执行参数
169
+ payload: {},
170
+ // 执行前的钩子
171
+ beforeAction: "",
172
+ // 执行前的参数
173
+ beforePayload: {},
174
+ // 执行后的钩子
175
+ afterAction: "",
176
+ // 执行后的参数
177
+ afterPayload: {},
178
+ destroy: true,
179
+ ...payload
180
+ };
181
+ };
182
+ this.getTaskQueue = (payload) => {
183
+ const { queueId, module: module2 } = payload;
184
+ return this.tasks[module2][queueId].tasks;
185
+ };
186
+ this.timeout = (ms) => {
187
+ return new Promise((resolve) => {
188
+ setTimeout(() => {
189
+ resolve(true);
190
+ }, ms || 5e3);
191
+ });
192
+ };
193
+ if (!app) {
194
+ throw new Error("app is required");
195
+ }
196
+ this.app = app;
197
+ this.taskFunctions = /* @__PURE__ */ new Map();
198
+ this.tasks = {};
199
+ this.db = app.dbManager;
200
+ }
201
+ // 单例模式
202
+ static getInstance(app) {
203
+ if (!TasksManager.instance && app) {
204
+ TasksManager.instance = new TasksManager(app);
205
+ }
206
+ return TasksManager.instance;
207
+ }
208
+ // 注册任务函数
209
+ addTaskFunction(name, fun) {
210
+ this.taskFunctions.set(name, fun);
211
+ console.log("Tasks--->", `注册任务函数成功: ${name}`);
212
+ }
213
+ // 注册任务函数列表
214
+ addTaskFunctions(tasks) {
215
+ tasks.forEach(({ name, fun }) => {
216
+ this.taskFunctions.set(name, fun);
217
+ });
218
+ }
219
+ getTasks() {
220
+ return this.tasks;
221
+ }
222
+ // 获取任务函数
223
+ getTaskFunction(name) {
224
+ if (!name) {
225
+ return null;
226
+ }
227
+ return this.taskFunctions.get(name);
228
+ }
229
+ // 初始化任务
230
+ async init() {
231
+ const tasks = await this.loadTaskQueueFromLocal();
232
+ if (tasks) {
233
+ console.log("initTasks", tasks);
234
+ }
235
+ }
236
+ /**
237
+ * @title: 执行任务队列
238
+ * @description:
239
+ * @return {*}
240
+ * @Author: zhiwei.Wang
241
+ * @Date: 2024-09-26 13:52
242
+ */
243
+ async run(payload) {
244
+ var _a, _b;
245
+ const { queueId, module: module2, callback } = payload;
246
+ let taskQueueStatus = "";
247
+ while (taskQueueStatus !== "completed") {
248
+ const taskQueue = this.getTaskQueue(payload);
249
+ const errorTaskIds = [];
250
+ if (taskQueue && taskQueue.length) {
251
+ const tasksToExecute = taskQueue.filter(
252
+ (task) => (task == null ? void 0 : task.status) === "pending" || (task == null ? void 0 : task.status) === "failure"
253
+ );
254
+ console.log("Tasks--->", "需要执行的任务", tasksToExecute);
255
+ for (let task of tasksToExecute) {
256
+ try {
257
+ if (task.retries !== void 0 && task.maxRetries !== void 0 && task.retries < task.maxRetries) {
258
+ task.status = "in-progress";
259
+ this.updateTask({ module: module2, queueId, taskId: task.id, other: { status: task.status } });
260
+ if (task.polling) {
261
+ this.startPolling(task);
262
+ } else {
263
+ const { status } = await this.runTask(task);
264
+ task.status = status;
265
+ }
266
+ if (task.status === "success") {
267
+ if ((_a = task.pollingResult) == null ? void 0 : _a.timerId) {
268
+ }
269
+ this.deleteTask({ module: module2, queueId, taskId: task.id });
270
+ } else {
271
+ let _other = {
272
+ status: task.status
273
+ };
274
+ if (task.status === "failure") {
275
+ _other.retries = task.retries + 1;
276
+ }
277
+ errorTaskIds.push(task.id);
278
+ this.updateTask({ module: module2, queueId, taskId: task.id, other: _other });
279
+ }
280
+ } else {
281
+ console.log("Tasks--->", "任务没有重试次数,需要删除", task);
282
+ this.deleteTask({ module: module2, queueId, taskId: task.id });
283
+ }
284
+ } catch (error) {
285
+ console.error("任务异常", error);
286
+ }
287
+ }
288
+ taskQueueStatus = ((_b = this.getTaskQueue(payload)) == null ? void 0 : _b.some((task) => task.status === "failure")) ? "uncompleted" : "completed";
289
+ this.updateQueueStatus({
290
+ queueId,
291
+ module: module2,
292
+ status: taskQueueStatus
293
+ });
294
+ console.log("Tasks--->", "任务队列执行完成", taskQueue);
295
+ } else {
296
+ taskQueueStatus = "completed";
297
+ }
298
+ if (taskQueueStatus === "uncompleted") {
299
+ this.app.logger.addLog({
300
+ type: "info",
301
+ title: `任务队列执行存在失败-${queueId}`,
302
+ metadata: { taskQueue, errorTaskIds }
303
+ });
304
+ await this.timeout();
305
+ } else if (taskQueueStatus === "completed") {
306
+ console.log("Tasks--->", "任务队列全部执行完成");
307
+ callback == null ? void 0 : callback();
308
+ }
309
+ }
310
+ }
311
+ deleteTask(payload) {
312
+ var _a, _b, _c, _d;
313
+ const { queueId, module: module2, taskId } = payload;
314
+ this.tasks[module2][queueId].tasks = (_d = (_c = (_b = (_a = this.tasks) == null ? void 0 : _a[module2]) == null ? void 0 : _b[queueId]) == null ? void 0 : _c.tasks) == null ? void 0 : _d.filter((task) => {
315
+ var _a2;
316
+ if ((_a2 = task.pollingResult) == null ? void 0 : _a2.timerId) {
317
+ clearTimeout(task.pollingResult.timerId);
318
+ }
319
+ return task.id !== taskId;
320
+ });
321
+ this.saveTaskQueueToLocal(this.tasks);
322
+ console.log("Tasks--->", "删除指定任务", queueId, module2, taskId);
323
+ }
324
+ /**
325
+ * @title: 重试任务
326
+ * @description:
327
+ * @return {*}
328
+ * @Author: zhiwei.Wang
329
+ * @Date: 2024-09-26 13:53
330
+ */
331
+ retryTask(payload) {
332
+ const { queueId, module: module2 } = payload;
333
+ this.run({ queueId, module: module2 });
334
+ }
335
+ // 添加任务
336
+ addTask(payload) {
337
+ var _a, _b, _c;
338
+ const { queueId, module: module2, tasks } = payload;
339
+ const taskQueue = (_b = (_a = this.tasks[module2]) == null ? void 0 : _a[queueId]) == null ? void 0 : _b.tasks;
340
+ let _tasks = [...taskQueue || []];
341
+ let newTasks = (_c = tasks == null ? void 0 : tasks.map) == null ? void 0 : _c.call(tasks, (d) => {
342
+ return this.createTaskData({ ...d, queueId, module: module2 });
343
+ });
344
+ _tasks = _tasks.concat(newTasks);
345
+ this.setTasks({ queueId, module: module2, tasks: _tasks });
346
+ console.log("Tasks--->", `任务添加成功`, newTasks);
347
+ }
348
+ // 更新任务状态
349
+ updateTask(payload) {
350
+ var _a, _b, _c;
351
+ const { queueId, taskId, other, module: module2 } = payload;
352
+ let newTask = null;
353
+ const taskQueue = ((_b = (_a = this.tasks[module2]) == null ? void 0 : _a[queueId]) == null ? void 0 : _b.tasks) || [];
354
+ const updatedTasks = taskQueue.map((task) => {
355
+ if (task.id === taskId) {
356
+ newTask = { ...task, ...other };
357
+ return newTask;
358
+ }
359
+ return task;
360
+ });
361
+ const newState = {
362
+ ...this.tasks,
363
+ [module2]: {
364
+ ...this.tasks[module2],
365
+ [queueId]: {
366
+ ...(_c = this.tasks[module2]) == null ? void 0 : _c[queueId],
367
+ status: updatedTasks.some((task) => task.status === "failure") ? "uncompleted" : "completed",
368
+ tasks: updatedTasks
369
+ }
370
+ }
371
+ };
372
+ this.saveTaskQueueToLocal(newState);
373
+ this.tasks = newState;
374
+ return newTask;
375
+ }
376
+ updateQueueStatus(payload) {
377
+ const { queueId, status, module: module2 } = payload;
378
+ const newState = {
379
+ ...this.tasks,
380
+ [module2]: {
381
+ ...this.tasks[module2],
382
+ [queueId]: {
383
+ ...this.tasks[module2][queueId],
384
+ status
385
+ }
386
+ }
387
+ };
388
+ this.saveTaskQueueToLocal(newState);
389
+ this.tasks = newState;
390
+ }
391
+ // 设置任务
392
+ setTasks(payload) {
393
+ const { queueId, module: module2, tasks } = payload;
394
+ const moduleData = this.tasks[module2] || {};
395
+ const queueIdData = moduleData[queueId] || {};
396
+ const newState = {
397
+ ...this.tasks,
398
+ [module2]: {
399
+ ...moduleData,
400
+ [queueId]: {
401
+ ...queueIdData,
402
+ tasks
403
+ }
404
+ }
405
+ };
406
+ this.saveTaskQueueToLocal(newState);
407
+ this.tasks = newState;
408
+ }
409
+ clearAllTaskTimer(tasks) {
410
+ var _a;
411
+ for (let task of tasks || []) {
412
+ if ((_a = task.pollingResult) == null ? void 0 : _a.timerId) {
413
+ clearTimeout(task.pollingResult.timerId);
414
+ }
415
+ }
416
+ }
417
+ // 清空任务
418
+ clearTasks(payload) {
419
+ const { queueId, module: module2 } = payload;
420
+ this.clearAllTaskTimer(this.tasks[module2][queueId].tasks);
421
+ this.tasks[module2][queueId].tasks = [];
422
+ this.saveTaskQueueToLocal(this.tasks);
423
+ console.log("Tasks--->", "清空指定任务", queueId, module2);
424
+ }
425
+ // 清空全部任务
426
+ clearAllTasks() {
427
+ this.tasks = {};
428
+ this.saveTaskQueueToLocal(this.tasks);
429
+ console.log("Tasks--->", "清空全部任务");
430
+ }
431
+ watchTask(callback) {
432
+ this.watchTaskCallback = callback;
433
+ }
434
+ };
435
+ // Annotate the CommonJS export names for ESM import in node:
436
+ 0 && (module.exports = {
437
+ TasksManager
438
+ });
@@ -0,0 +1,62 @@
1
+ export type TaskRunStatus = "pending" | "in-progress" | "success" | "failure";
2
+ export interface Task {
3
+ id?: string;
4
+ type?: "local" | "cloud";
5
+ retries?: number;
6
+ maxRetries?: number;
7
+ status?: TaskRunStatus;
8
+ action: string;
9
+ payload: any;
10
+ beforeAction?: string;
11
+ beforePayload?: any;
12
+ afterAction?: string;
13
+ afterPayload?: any;
14
+ polling?: {
15
+ interval?: number;
16
+ };
17
+ pollingResult?: {
18
+ count: number;
19
+ timerId?: any;
20
+ };
21
+ manual?: boolean;
22
+ destroy?: boolean;
23
+ [key: string]: any;
24
+ }
25
+ export interface TaskConfig {
26
+ tasks: Task[];
27
+ }
28
+ type TaskModuleName = string;
29
+ type TaskQueueName = string;
30
+ type TaskStatus = "uncompleted" | "completed";
31
+ export interface TaskQueue {
32
+ status: TaskStatus;
33
+ tasks: Task[];
34
+ }
35
+ export interface RunTaskParams {
36
+ module: TaskModuleName;
37
+ queueId: TaskQueueName;
38
+ callback?: () => void;
39
+ }
40
+ export interface DeleteTaskParams {
41
+ module: TaskModuleName;
42
+ queueId: TaskQueueName;
43
+ taskId: string;
44
+ }
45
+ export interface AddTaskParams {
46
+ module: TaskModuleName;
47
+ queueId: TaskQueueName;
48
+ tasks: Task[];
49
+ }
50
+ export interface TaskRunResult {
51
+ status: TaskRunStatus;
52
+ [key: string]: any;
53
+ }
54
+ export interface TasksModule {
55
+ [key: TaskModuleName]: {
56
+ [key: TaskQueueName]: {
57
+ status: TaskStatus;
58
+ tasks: Task[];
59
+ };
60
+ };
61
+ }
62
+ export {};
@@ -12,6 +12,6 @@ var __copyProps = (to, from, except, desc) => {
12
12
  };
13
13
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
14
 
15
- // src/date/type.ts
15
+ // src/tasks/type.ts
16
16
  var type_exports = {};
17
17
  module.exports = __toCommonJS(type_exports);
@@ -0,0 +1,5 @@
1
+ import { TasksModule } from './type';
2
+ declare const useTasks: () => {
3
+ tasks: TasksModule;
4
+ };
5
+ export default useTasks;
@@ -0,0 +1,37 @@
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/tasks/useTasks.tsx
20
+ var useTasks_exports = {};
21
+ __export(useTasks_exports, {
22
+ default: () => useTasks_default
23
+ });
24
+ module.exports = __toCommonJS(useTasks_exports);
25
+ var import_app = require("../app");
26
+ var import_react = require("react");
27
+ var useTasks = () => {
28
+ const { app } = (0, import_app.useApp)();
29
+ const [tasks, setTasks] = (0, import_react.useState)({});
30
+ (0, import_react.useEffect)(() => {
31
+ app.tasksManager.watchTask((taskModule) => {
32
+ setTasks(taskModule);
33
+ });
34
+ }, []);
35
+ return { tasks };
36
+ };
37
+ var useTasks_default = useTasks;
package/lib/type.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export interface UtilsConfig {
1
+ export interface CoreConfig {
2
2
  }
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ export declare const useVariablesContext: () => any;
3
+ interface VariablesProviderProps {
4
+ children: React.ReactNode;
5
+ }
6
+ export declare const VariablesProvider: React.FC<VariablesProviderProps>;
7
+ export {};
@@ -26,38 +26,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  ));
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
 
29
- // src/locales/config.ts
30
- var config_exports = {};
31
- __export(config_exports, {
32
- defaultConfig: () => defaultConfig,
33
- getConfig: () => getConfig,
34
- setConfig: () => setConfig
29
+ // src/variables/VariablesProvider.tsx
30
+ var VariablesProvider_exports = {};
31
+ __export(VariablesProvider_exports, {
32
+ VariablesProvider: () => VariablesProvider,
33
+ useVariablesContext: () => useVariablesContext
35
34
  });
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 defaultConfig = {
41
- // 当前语言
42
- locale: "en",
43
- // 语言包
44
- texts: {
45
- "en": import_en.default,
46
- "zh-CN": import_zh_CN.default,
47
- "zh-HK": import_zh_HK.default
48
- }
49
- };
50
- var config = {
51
- ...defaultConfig
35
+ module.exports = __toCommonJS(VariablesProvider_exports);
36
+ var import_react = __toESM(require("react"));
37
+ var VariablesContext = (0, import_react.createContext)({});
38
+ VariablesContext.displayName = "VariablesContext";
39
+ var useVariablesContext = () => {
40
+ return import_react.default.useContext(VariablesContext);
52
41
  };
53
- var setConfig = (newConfig) => {
54
- config = { ...config, ...newConfig };
55
- return config;
42
+ var VariablesProvider = ({
43
+ children
44
+ }) => {
45
+ return /* @__PURE__ */ import_react.default.createElement(VariablesContext.Provider, { value: {} }, children);
56
46
  };
57
- var getConfig = () => config;
58
47
  // Annotate the CommonJS export names for ESM import in node:
59
48
  0 && (module.exports = {
60
- defaultConfig,
61
- getConfig,
62
- setConfig
49
+ VariablesProvider,
50
+ useVariablesContext
63
51
  });
@@ -0,0 +1,3 @@
1
+ import { VariablesConfig } from './type';
2
+ export declare const setConfig: (newConfig: Partial<VariablesConfig>) => void;
3
+ export declare const getConfig: () => VariablesConfig;
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // src/date/config.ts
19
+ // src/variables/config.ts
20
20
  var config_exports = {};
21
21
  __export(config_exports, {
22
22
  getConfig: () => getConfig,
@@ -24,12 +24,7 @@ __export(config_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(config_exports);
26
26
  var defaultConfig = {
27
- locale: "en",
28
- defaultFormats: {
29
- "en": "HH:mm DD/MM/YYYY",
30
- "zh-CN": "YYYY-MM-DD HH:mm",
31
- "zh-HK": "YYYY-MM-DD HH:mm"
32
- }
27
+ globalVariableMap: {}
33
28
  };
34
29
  var config = { ...defaultConfig };
35
30
  var setConfig = (newConfig) => {
@@ -0,0 +1,6 @@
1
+ export type VariableMap = Record<string, string>;
2
+ declare const _default: {
3
+ setConfig: (newConfig: Partial<import("@").VariablesConfig>) => void;
4
+ getConfig: () => import("@").VariablesConfig;
5
+ };
6
+ export default _default;
@@ -0,0 +1,29 @@
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/variables/index.ts
20
+ var variables_exports = {};
21
+ __export(variables_exports, {
22
+ default: () => variables_default
23
+ });
24
+ module.exports = __toCommonJS(variables_exports);
25
+ var import_config = require("./config");
26
+ var variables_default = {
27
+ setConfig: import_config.setConfig,
28
+ getConfig: import_config.getConfig
29
+ };
@@ -0,0 +1,2 @@
1
+ export interface VariablesConfig {
2
+ }