@pisell/core 0.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.
- package/README.md +1 -0
- package/es/app/app.d.ts +101 -0
- package/es/app/app.js +177 -0
- package/es/app/const.d.ts +4 -0
- package/es/app/const.js +6 -0
- package/es/app/index.d.ts +14 -0
- package/es/app/index.js +52 -0
- package/es/applicationManager/application.d.ts +197 -0
- package/es/applicationManager/application.js +469 -0
- package/es/applicationManager/index.d.ts +19 -0
- package/es/applicationManager/index.js +206 -0
- package/es/aws/index.d.ts +16 -0
- package/es/aws/index.js +76 -0
- package/es/cmd/const.d.ts +11 -0
- package/es/cmd/const.js +13 -0
- package/es/cmd/index.d.ts +13 -0
- package/es/cmd/index.js +91 -0
- package/es/cmd/type.d.ts +5 -0
- package/es/cmd/type.js +1 -0
- package/es/communicationManager/index.d.ts +59 -0
- package/es/communicationManager/index.js +174 -0
- package/es/config.d.ts +3 -0
- package/es/config.js +14 -0
- package/es/cookie/index.d.ts +13 -0
- package/es/cookie/index.js +47 -0
- package/es/css/global.less +73 -0
- package/es/css/index.less +31 -0
- package/es/css/variables.css +84 -0
- package/es/data/index.d.ts +8 -0
- package/es/data/index.js +16 -0
- package/es/history/config.d.ts +24 -0
- package/es/history/config.js +43 -0
- package/es/history/index.d.ts +26 -0
- package/es/history/index.js +80 -0
- package/es/history/type.d.ts +2 -0
- package/es/history/type.js +1 -0
- package/es/hooks/index.d.ts +12 -0
- package/es/hooks/index.js +13 -0
- package/es/hooks/useDelayedValue/index.d.ts +2 -0
- package/es/hooks/useDelayedValue/index.js +26 -0
- package/es/hooks/useDispatch/index.d.ts +2 -0
- package/es/hooks/useDispatch/index.js +2 -0
- package/es/hooks/useLowCode/index.d.ts +13 -0
- package/es/hooks/useLowCode/index.js +74 -0
- package/es/hooks/useStore/index.d.ts +6 -0
- package/es/hooks/useStore/index.js +11 -0
- package/es/index.d.ts +8 -0
- package/es/index.js +10 -0
- package/es/indexDB/index.d.ts +296 -0
- package/es/indexDB/index.js +1619 -0
- package/es/locales/en.d.ts +3 -0
- package/es/locales/en.js +5 -0
- package/es/locales/index.d.ts +39 -0
- package/es/locales/index.js +199 -0
- package/es/locales/original.d.ts +3 -0
- package/es/locales/original.js +7 -0
- package/es/locales/type.d.ts +19 -0
- package/es/locales/type.js +1 -0
- package/es/locales/zh-CN.d.ts +3 -0
- package/es/locales/zh-CN.js +5 -0
- package/es/locales/zh-HK.d.ts +3 -0
- package/es/locales/zh-HK.js +5 -0
- package/es/logger/feishu.d.ts +11 -0
- package/es/logger/feishu.js +50 -0
- package/es/logger/index.d.ts +135 -0
- package/es/logger/index.js +870 -0
- package/es/menuManager/hooks.d.ts +17 -0
- package/es/menuManager/hooks.js +136 -0
- package/es/menuManager/index.d.ts +28 -0
- package/es/menuManager/index.js +165 -0
- package/es/models/global.d.ts +32 -0
- package/es/models/global.js +66 -0
- package/es/models/index.d.ts +45 -0
- package/es/models/index.js +65 -0
- package/es/models/type.d.ts +2 -0
- package/es/models/type.js +1 -0
- package/es/plugin/index.d.ts +0 -0
- package/es/plugin/index.js +0 -0
- package/es/pubsub/example.d.ts +5 -0
- package/es/pubsub/example.js +92 -0
- package/es/pubsub/index.d.ts +73 -0
- package/es/pubsub/index.js +166 -0
- package/es/render/index.d.ts +0 -0
- package/es/render/index.js +0 -0
- package/es/request/cache.d.ts +46 -0
- package/es/request/cache.js +372 -0
- package/es/request/cancelToken.d.ts +38 -0
- package/es/request/cancelToken.js +59 -0
- package/es/request/config.d.ts +3 -0
- package/es/request/config.js +63 -0
- package/es/request/constants.d.ts +2 -0
- package/es/request/constants.js +6 -0
- package/es/request/index.d.ts +24 -0
- package/es/request/index.js +267 -0
- package/es/request/pisell2Request.d.ts +6 -0
- package/es/request/pisell2Request.js +62 -0
- package/es/request/type.d.ts +57 -0
- package/es/request/type.js +10 -0
- package/es/request/utils.d.ts +46 -0
- package/es/request/utils.js +147 -0
- package/es/routes/config.d.ts +7 -0
- package/es/routes/config.js +17 -0
- package/es/routes/index.d.ts +28 -0
- package/es/routes/index.js +151 -0
- package/es/socket/components/SocketMonitorPage.d.ts +6 -0
- package/es/socket/components/SocketMonitorPage.js +485 -0
- package/es/socket/components/index.d.ts +2 -0
- package/es/socket/components/index.js +2 -0
- package/es/socket/constants.d.ts +33 -0
- package/es/socket/constants.js +39 -0
- package/es/socket/events.d.ts +31 -0
- package/es/socket/events.js +19 -0
- package/es/socket/heartbeat.d.ts +66 -0
- package/es/socket/heartbeat.js +184 -0
- package/es/socket/index.d.ts +61 -0
- package/es/socket/index.js +246 -0
- package/es/socket/monitor.d.ts +169 -0
- package/es/socket/monitor.js +448 -0
- package/es/socket/reconnect.d.ts +61 -0
- package/es/socket/reconnect.js +199 -0
- package/es/socket/socket.d.ts +130 -0
- package/es/socket/socket.js +613 -0
- package/es/socket/types.d.ts +85 -0
- package/es/socket/types.js +35 -0
- package/es/storage/index.d.ts +17 -0
- package/es/storage/index.js +46 -0
- package/es/tasks/index.d.ts +127 -0
- package/es/tasks/index.js +1119 -0
- package/es/tasks/scheduledTasksExample.d.ts +61 -0
- package/es/tasks/scheduledTasksExample.js +351 -0
- package/es/tasks/type.d.ts +100 -0
- package/es/tasks/type.js +1 -0
- package/es/tasks/useTasks.d.ts +5 -0
- package/es/tasks/useTasks.js +25 -0
- package/es/type.d.ts +2 -0
- package/es/type.js +1 -0
- package/es/utils/adaptiveThrottle/index.d.ts +36 -0
- package/es/utils/adaptiveThrottle/index.js +136 -0
- package/es/variables/VariablesProvider.d.ts +7 -0
- package/es/variables/VariablesProvider.js +12 -0
- package/es/variables/config.d.ts +3 -0
- package/es/variables/config.js +16 -0
- package/es/variables/index.d.ts +6 -0
- package/es/variables/index.js +5 -0
- package/es/variables/type.d.ts +2 -0
- package/es/variables/type.js +1 -0
- package/es/website/index.d.ts +6 -0
- package/es/website/index.js +65 -0
- package/lib/app/app.d.ts +101 -0
- package/lib/app/app.js +171 -0
- package/lib/app/const.d.ts +4 -0
- package/lib/app/const.js +33 -0
- package/lib/app/index.d.ts +14 -0
- package/lib/app/index.js +76 -0
- package/lib/applicationManager/application.d.ts +197 -0
- package/lib/applicationManager/application.js +280 -0
- package/lib/applicationManager/index.d.ts +19 -0
- package/lib/applicationManager/index.js +88 -0
- package/lib/aws/index.d.ts +16 -0
- package/lib/aws/index.js +67 -0
- package/lib/cmd/const.d.ts +11 -0
- package/lib/cmd/const.js +39 -0
- package/lib/cmd/index.d.ts +13 -0
- package/lib/cmd/index.js +96 -0
- package/lib/cmd/type.d.ts +5 -0
- package/lib/cmd/type.js +17 -0
- package/lib/communicationManager/index.d.ts +59 -0
- package/lib/communicationManager/index.js +102 -0
- package/lib/config.d.ts +3 -0
- package/lib/config.js +36 -0
- package/lib/cookie/index.d.ts +13 -0
- package/lib/cookie/index.js +62 -0
- package/lib/css/global.less +73 -0
- package/lib/css/index.less +31 -0
- package/lib/css/variables.css +84 -0
- package/lib/data/index.d.ts +8 -0
- package/lib/data/index.js +38 -0
- package/lib/history/config.d.ts +24 -0
- package/lib/history/config.js +41 -0
- package/lib/history/index.d.ts +26 -0
- package/lib/history/index.js +99 -0
- package/lib/history/type.d.ts +2 -0
- package/lib/history/type.js +17 -0
- package/lib/hooks/index.d.ts +12 -0
- package/lib/hooks/index.js +44 -0
- package/lib/hooks/useDelayedValue/index.d.ts +2 -0
- package/lib/hooks/useDelayedValue/index.js +36 -0
- package/lib/hooks/useDispatch/index.d.ts +2 -0
- package/lib/hooks/useDispatch/index.js +26 -0
- package/lib/hooks/useLowCode/index.d.ts +13 -0
- package/lib/hooks/useLowCode/index.js +75 -0
- package/lib/hooks/useStore/index.d.ts +6 -0
- package/lib/hooks/useStore/index.js +33 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +58 -0
- package/lib/indexDB/index.d.ts +296 -0
- package/lib/indexDB/index.js +767 -0
- package/lib/locales/en.d.ts +3 -0
- package/lib/locales/en.js +29 -0
- package/lib/locales/index.d.ts +39 -0
- package/lib/locales/index.js +159 -0
- package/lib/locales/original.d.ts +3 -0
- package/lib/locales/original.js +31 -0
- package/lib/locales/type.d.ts +19 -0
- package/lib/locales/type.js +17 -0
- package/lib/locales/zh-CN.d.ts +3 -0
- package/lib/locales/zh-CN.js +29 -0
- package/lib/locales/zh-HK.d.ts +3 -0
- package/lib/locales/zh-HK.js +29 -0
- package/lib/logger/feishu.d.ts +11 -0
- package/lib/logger/feishu.js +52 -0
- package/lib/logger/index.d.ts +135 -0
- package/lib/logger/index.js +476 -0
- package/lib/menuManager/hooks.d.ts +17 -0
- package/lib/menuManager/hooks.js +135 -0
- package/lib/menuManager/index.d.ts +28 -0
- package/lib/menuManager/index.js +125 -0
- package/lib/models/global.d.ts +32 -0
- package/lib/models/global.js +62 -0
- package/lib/models/index.d.ts +45 -0
- package/lib/models/index.js +69 -0
- package/lib/models/type.d.ts +2 -0
- package/lib/models/type.js +17 -0
- package/lib/plugin/index.d.ts +0 -0
- package/lib/plugin/index.js +0 -0
- package/lib/pubsub/example.d.ts +5 -0
- package/lib/pubsub/example.js +61 -0
- package/lib/pubsub/index.d.ts +73 -0
- package/lib/pubsub/index.js +141 -0
- package/lib/render/index.d.ts +0 -0
- package/lib/render/index.js +0 -0
- package/lib/request/cache.d.ts +46 -0
- package/lib/request/cache.js +195 -0
- package/lib/request/cancelToken.d.ts +38 -0
- package/lib/request/cancelToken.js +59 -0
- package/lib/request/config.d.ts +3 -0
- package/lib/request/config.js +69 -0
- package/lib/request/constants.d.ts +2 -0
- package/lib/request/constants.js +34 -0
- package/lib/request/index.d.ts +24 -0
- package/lib/request/index.js +210 -0
- package/lib/request/pisell2Request.d.ts +6 -0
- package/lib/request/pisell2Request.js +75 -0
- package/lib/request/type.d.ts +57 -0
- package/lib/request/type.js +36 -0
- package/lib/request/utils.d.ts +46 -0
- package/lib/request/utils.js +113 -0
- package/lib/routes/config.d.ts +7 -0
- package/lib/routes/config.js +50 -0
- package/lib/routes/index.d.ts +28 -0
- package/lib/routes/index.js +121 -0
- package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
- package/lib/socket/components/SocketMonitorPage.js +340 -0
- package/lib/socket/components/index.d.ts +2 -0
- package/lib/socket/components/index.js +39 -0
- package/lib/socket/constants.d.ts +33 -0
- package/lib/socket/constants.js +62 -0
- package/lib/socket/events.d.ts +31 -0
- package/lib/socket/events.js +44 -0
- package/lib/socket/heartbeat.d.ts +66 -0
- package/lib/socket/heartbeat.js +157 -0
- package/lib/socket/index.d.ts +61 -0
- package/lib/socket/index.js +198 -0
- package/lib/socket/monitor.d.ts +169 -0
- package/lib/socket/monitor.js +350 -0
- package/lib/socket/reconnect.d.ts +61 -0
- package/lib/socket/reconnect.js +157 -0
- package/lib/socket/socket.d.ts +130 -0
- package/lib/socket/socket.js +426 -0
- package/lib/socket/types.d.ts +85 -0
- package/lib/socket/types.js +36 -0
- package/lib/storage/index.d.ts +17 -0
- package/lib/storage/index.js +64 -0
- package/lib/tasks/index.d.ts +127 -0
- package/lib/tasks/index.js +710 -0
- package/lib/tasks/scheduledTasksExample.d.ts +61 -0
- package/lib/tasks/scheduledTasksExample.js +267 -0
- package/lib/tasks/type.d.ts +100 -0
- package/lib/tasks/type.js +17 -0
- package/lib/tasks/useTasks.d.ts +5 -0
- package/lib/tasks/useTasks.js +37 -0
- package/lib/type.d.ts +2 -0
- package/lib/type.js +17 -0
- package/lib/utils/adaptiveThrottle/index.d.ts +36 -0
- package/lib/utils/adaptiveThrottle/index.js +121 -0
- package/lib/variables/VariablesProvider.d.ts +7 -0
- package/lib/variables/VariablesProvider.js +51 -0
- package/lib/variables/config.d.ts +3 -0
- package/lib/variables/config.js +38 -0
- package/lib/variables/index.d.ts +6 -0
- package/lib/variables/index.js +29 -0
- package/lib/variables/type.d.ts +2 -0
- package/lib/variables/type.js +17 -0
- package/lib/website/index.d.ts +6 -0
- package/lib/website/index.js +75 -0
- package/package.json +49 -0
package/es/locales/en.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Locale, LibraryItem, LoadLibraryByUrlParams } from "./type";
|
|
2
|
+
import App from "../app";
|
|
3
|
+
export interface LocalesOptions {
|
|
4
|
+
locale?: Locale;
|
|
5
|
+
library?: {
|
|
6
|
+
[key in Locale]: LibraryItem;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export declare class Locales {
|
|
10
|
+
private app;
|
|
11
|
+
locale: string;
|
|
12
|
+
library: {
|
|
13
|
+
[key in Locale]: LibraryItem;
|
|
14
|
+
};
|
|
15
|
+
constructor(app: App, options?: LocalesOptions);
|
|
16
|
+
getLocale: () => string;
|
|
17
|
+
getCurrentTexts: (locale?: Locale) => {
|
|
18
|
+
[key: string]: string;
|
|
19
|
+
};
|
|
20
|
+
setLocale: (locale: Locale, reload?: boolean) => void;
|
|
21
|
+
getText: (id: string, locale?: Locale) => string;
|
|
22
|
+
isCN: () => boolean;
|
|
23
|
+
loadLibraryByUrl: (urls: LoadLibraryByUrlParams) => Promise<{
|
|
24
|
+
[x: string]: LibraryItem;
|
|
25
|
+
}>;
|
|
26
|
+
loadLibraryByItems(libraryList: LibraryItem[]): void;
|
|
27
|
+
loadLibrary: (urls: LoadLibraryByUrlParams) => Promise<{
|
|
28
|
+
[x: string]: LibraryItem;
|
|
29
|
+
}>;
|
|
30
|
+
translation: (text: string | {
|
|
31
|
+
[key: string]: string;
|
|
32
|
+
}, locale?: Locale) => string | number;
|
|
33
|
+
getLibraryByData: (data: LibraryItem[]) => LibraryItem;
|
|
34
|
+
createTextsByLibrary: (id: string, library?: {
|
|
35
|
+
[x: string]: LibraryItem;
|
|
36
|
+
} | undefined) => {
|
|
37
|
+
[x: string]: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
2
|
+
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; } } }; }
|
|
3
|
+
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); }
|
|
4
|
+
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; }
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
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
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
+
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); } }
|
|
12
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
|
+
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; }
|
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
15
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
16
|
+
import _ from "lodash";
|
|
17
|
+
//@ts-ignore
|
|
18
|
+
import { isString, isNumber } from "@pisell/utils";
|
|
19
|
+
import en from "./en";
|
|
20
|
+
import zhCN from "./zh-CN";
|
|
21
|
+
import zhHK from "./zh-HK";
|
|
22
|
+
import original from "./original";
|
|
23
|
+
export var Locales = /*#__PURE__*/function () {
|
|
24
|
+
function Locales(app, options) {
|
|
25
|
+
var _this = this;
|
|
26
|
+
_classCallCheck(this, Locales);
|
|
27
|
+
_defineProperty(this, "app", void 0);
|
|
28
|
+
// 当前语言 本地语言 > 英文语言包
|
|
29
|
+
_defineProperty(this, "locale", en.locale);
|
|
30
|
+
// 语言包
|
|
31
|
+
_defineProperty(this, "library", [original, en, zhCN, zhHK].reduce(function (pre, cur) {
|
|
32
|
+
pre[cur.locale] = cur;
|
|
33
|
+
return pre;
|
|
34
|
+
}, {}));
|
|
35
|
+
_defineProperty(this, "getLocale", function () {
|
|
36
|
+
return _this.locale;
|
|
37
|
+
});
|
|
38
|
+
_defineProperty(this, "getCurrentTexts", function (locale) {
|
|
39
|
+
return _this.library[locale || _this.locale].translations;
|
|
40
|
+
});
|
|
41
|
+
_defineProperty(this, "setLocale", function (locale) {
|
|
42
|
+
var reload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
43
|
+
_this.locale = locale;
|
|
44
|
+
if (reload) {
|
|
45
|
+
window.location.reload();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
_defineProperty(this, "getText", function (id, locale) {
|
|
50
|
+
var _this$getCurrentTexts;
|
|
51
|
+
return ((_this$getCurrentTexts = _this.getCurrentTexts(locale)) === null || _this$getCurrentTexts === void 0 ? void 0 : _this$getCurrentTexts[id]) || id;
|
|
52
|
+
});
|
|
53
|
+
_defineProperty(this, "isCN", function () {
|
|
54
|
+
var locale = _this.getLocale();
|
|
55
|
+
return locale === "zh-CN" || locale === "zh-HK";
|
|
56
|
+
});
|
|
57
|
+
_defineProperty(this, "loadLibraryByUrl", /*#__PURE__*/function () {
|
|
58
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(urls) {
|
|
59
|
+
var fetchList, res, library, _iterator, _step, item, _item;
|
|
60
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
61
|
+
while (1) switch (_context.prev = _context.next) {
|
|
62
|
+
case 0:
|
|
63
|
+
_context.prev = 0;
|
|
64
|
+
fetchList = urls.map(function (item) {
|
|
65
|
+
// 字符串类型使用默认的fetch
|
|
66
|
+
if (typeof item === "string") {
|
|
67
|
+
return fetch(item);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 函数类型,执行函数
|
|
71
|
+
if (typeof item === "function") {
|
|
72
|
+
return item();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// LibraryItem 类型,直接包装成 Promise
|
|
76
|
+
if (_typeof(item) === "object" && item !== null && "locale" in item) {
|
|
77
|
+
return Promise.resolve(item);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 其他使用传入的Promise
|
|
81
|
+
return item;
|
|
82
|
+
}); // 并发请求, 提升加载速度
|
|
83
|
+
_context.next = 4;
|
|
84
|
+
return Promise.all(fetchList);
|
|
85
|
+
case 4:
|
|
86
|
+
res = _context.sent;
|
|
87
|
+
library = _objectSpread({}, _this.library);
|
|
88
|
+
_iterator = _createForOfIteratorHelper(res);
|
|
89
|
+
_context.prev = 7;
|
|
90
|
+
_iterator.s();
|
|
91
|
+
case 9:
|
|
92
|
+
if ((_step = _iterator.n()).done) {
|
|
93
|
+
_context.next = 22;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
item = _step.value;
|
|
97
|
+
if (!(item instanceof Response)) {
|
|
98
|
+
_context.next = 17;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
_context.next = 14;
|
|
102
|
+
return item.json();
|
|
103
|
+
case 14:
|
|
104
|
+
_context.t0 = _context.sent;
|
|
105
|
+
_context.next = 18;
|
|
106
|
+
break;
|
|
107
|
+
case 17:
|
|
108
|
+
_context.t0 = item;
|
|
109
|
+
case 18:
|
|
110
|
+
_item = _context.t0;
|
|
111
|
+
// 进行合并
|
|
112
|
+
library = _objectSpread(_objectSpread({}, library), {}, _defineProperty({}, _item.locale, _.mergeWith(library[_item.locale] || {}, _item)));
|
|
113
|
+
case 20:
|
|
114
|
+
_context.next = 9;
|
|
115
|
+
break;
|
|
116
|
+
case 22:
|
|
117
|
+
_context.next = 27;
|
|
118
|
+
break;
|
|
119
|
+
case 24:
|
|
120
|
+
_context.prev = 24;
|
|
121
|
+
_context.t1 = _context["catch"](7);
|
|
122
|
+
_iterator.e(_context.t1);
|
|
123
|
+
case 27:
|
|
124
|
+
_context.prev = 27;
|
|
125
|
+
_iterator.f();
|
|
126
|
+
return _context.finish(27);
|
|
127
|
+
case 30:
|
|
128
|
+
// 设置
|
|
129
|
+
_this.library = library;
|
|
130
|
+
return _context.abrupt("return", library);
|
|
131
|
+
case 34:
|
|
132
|
+
_context.prev = 34;
|
|
133
|
+
_context.t2 = _context["catch"](0);
|
|
134
|
+
console.log(_context.t2);
|
|
135
|
+
throw _context.t2;
|
|
136
|
+
case 38:
|
|
137
|
+
case "end":
|
|
138
|
+
return _context.stop();
|
|
139
|
+
}
|
|
140
|
+
}, _callee, null, [[0, 34], [7, 24, 27, 30]]);
|
|
141
|
+
}));
|
|
142
|
+
return function (_x) {
|
|
143
|
+
return _ref.apply(this, arguments);
|
|
144
|
+
};
|
|
145
|
+
}());
|
|
146
|
+
_defineProperty(this, "loadLibrary", function (urls) {
|
|
147
|
+
return _this.loadLibraryByUrl(urls);
|
|
148
|
+
});
|
|
149
|
+
_defineProperty(this, "translation", function (text, locale) {
|
|
150
|
+
if (!text) {
|
|
151
|
+
return "";
|
|
152
|
+
}
|
|
153
|
+
if (isString(text) || isNumber(text)) {
|
|
154
|
+
return text;
|
|
155
|
+
}
|
|
156
|
+
var primary = locale || _this.getLocale();
|
|
157
|
+
if (typeof text === 'string') {
|
|
158
|
+
return text;
|
|
159
|
+
}
|
|
160
|
+
return text[primary] || text["original"] || text["en"] || text["zh-CN"] || text["zh-HK"];
|
|
161
|
+
});
|
|
162
|
+
_defineProperty(this, "getLibraryByData", function (data) {
|
|
163
|
+
return data.reduce(function (pre, next) {
|
|
164
|
+
return _objectSpread(_objectSpread({}, pre), {}, _defineProperty({}, next.locale, next));
|
|
165
|
+
}, {});
|
|
166
|
+
});
|
|
167
|
+
_defineProperty(this, "createTextsByLibrary", function (id, library) {
|
|
168
|
+
var _library = library || _this.library;
|
|
169
|
+
return Object.keys(_library).reduce(function (pre, next) {
|
|
170
|
+
var _library$next$transla;
|
|
171
|
+
var _pre = _objectSpread({}, pre);
|
|
172
|
+
var cur = (_library$next$transla = _library[next].translations) === null || _library$next$transla === void 0 ? void 0 : _library$next$transla[id];
|
|
173
|
+
if (cur) {
|
|
174
|
+
_pre[_library[next].locale] = cur;
|
|
175
|
+
}
|
|
176
|
+
return _pre;
|
|
177
|
+
}, {});
|
|
178
|
+
});
|
|
179
|
+
this.app = app;
|
|
180
|
+
this.locale = (options === null || options === void 0 ? void 0 : options.locale) || this.app.storage.getStorage('locale') || en.locale;
|
|
181
|
+
this.library = (options === null || options === void 0 ? void 0 : options.library) || [original, en, zhCN, zhHK].reduce(function (pre, cur) {
|
|
182
|
+
pre[cur.locale] = cur;
|
|
183
|
+
return pre;
|
|
184
|
+
}, {});
|
|
185
|
+
}
|
|
186
|
+
_createClass(Locales, [{
|
|
187
|
+
key: "loadLibraryByItems",
|
|
188
|
+
value: function loadLibraryByItems(libraryList) {
|
|
189
|
+
var library = _objectSpread({}, this.library);
|
|
190
|
+
libraryList.forEach(function (item) {
|
|
191
|
+
library = _objectSpread(_objectSpread({}, library), {}, _defineProperty({}, item.locale, _.mergeWith(library[item.locale] || {}, item)));
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// 设置
|
|
195
|
+
this.library = library;
|
|
196
|
+
}
|
|
197
|
+
}]);
|
|
198
|
+
return Locales;
|
|
199
|
+
}();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare type Locale = 'original' | 'en' | 'zh-CN' | 'zh-HK' | string;
|
|
2
|
+
export declare type MultiLanguage = {
|
|
3
|
+
[key in Locale]: string;
|
|
4
|
+
};
|
|
5
|
+
export interface LibraryItem {
|
|
6
|
+
locale: Locale;
|
|
7
|
+
name: string;
|
|
8
|
+
translations: {
|
|
9
|
+
[key: string]: string;
|
|
10
|
+
};
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}
|
|
13
|
+
export interface LocaleConfig {
|
|
14
|
+
locale: Locale;
|
|
15
|
+
library: {
|
|
16
|
+
[key in Locale]: LibraryItem;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export declare type LoadLibraryByUrlParams = (string | Promise<LibraryItem> | (() => Promise<LibraryItem>) | LibraryItem)[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface contentItem {
|
|
2
|
+
key: string;
|
|
3
|
+
value: string;
|
|
4
|
+
}
|
|
5
|
+
interface sendWebhookProps {
|
|
6
|
+
title: string;
|
|
7
|
+
content: contentItem[];
|
|
8
|
+
webhook: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const sendWarningLog: ({ title, content, webhook }: sendWebhookProps) => Promise<any>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
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
|
+
var createFeishuMessageContent = function createFeishuMessageContent(contentArr) {
|
|
6
|
+
return JSON.stringify(contentArr.map(function (item) {
|
|
7
|
+
return [{
|
|
8
|
+
tag: "text",
|
|
9
|
+
text: "".concat(item.key, ": ")
|
|
10
|
+
}, {
|
|
11
|
+
tag: "text",
|
|
12
|
+
text: "".concat(item.value)
|
|
13
|
+
}];
|
|
14
|
+
}));
|
|
15
|
+
};
|
|
16
|
+
export var sendWarningLog = /*#__PURE__*/function () {
|
|
17
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
18
|
+
var title, content, webhook, contentStr, response;
|
|
19
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
20
|
+
while (1) switch (_context.prev = _context.next) {
|
|
21
|
+
case 0:
|
|
22
|
+
title = _ref.title, content = _ref.content, webhook = _ref.webhook;
|
|
23
|
+
contentStr = createFeishuMessageContent(content);
|
|
24
|
+
_context.next = 4;
|
|
25
|
+
return fetch(webhook, {
|
|
26
|
+
headers: {
|
|
27
|
+
"Content-Type": "application/json"
|
|
28
|
+
},
|
|
29
|
+
method: "POST",
|
|
30
|
+
body: JSON.stringify({
|
|
31
|
+
msg_type: "post",
|
|
32
|
+
content: "{\"post\":{\"zh_cn\":{\"title\":\"".concat(title, "\",\"content\":").concat(contentStr, "}}}")
|
|
33
|
+
})
|
|
34
|
+
});
|
|
35
|
+
case 4:
|
|
36
|
+
response = _context.sent;
|
|
37
|
+
_context.next = 7;
|
|
38
|
+
return response.json();
|
|
39
|
+
case 7:
|
|
40
|
+
return _context.abrupt("return", _context.sent);
|
|
41
|
+
case 8:
|
|
42
|
+
case "end":
|
|
43
|
+
return _context.stop();
|
|
44
|
+
}
|
|
45
|
+
}, _callee);
|
|
46
|
+
}));
|
|
47
|
+
return function sendWarningLog(_x) {
|
|
48
|
+
return _ref2.apply(this, arguments);
|
|
49
|
+
};
|
|
50
|
+
}();
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import App from "../app";
|
|
2
|
+
export declare type LogConsoleType = "info" | "warning" | "error" | "debug";
|
|
3
|
+
/**
|
|
4
|
+
* 日志项接口
|
|
5
|
+
*/
|
|
6
|
+
interface LogItem {
|
|
7
|
+
logId?: string | number;
|
|
8
|
+
type: LogConsoleType;
|
|
9
|
+
title: string;
|
|
10
|
+
date?: string;
|
|
11
|
+
metadata?: any;
|
|
12
|
+
feishu?: any;
|
|
13
|
+
}
|
|
14
|
+
interface LogFile {
|
|
15
|
+
fileName: string;
|
|
16
|
+
date: string;
|
|
17
|
+
fileContent: LogFileContent;
|
|
18
|
+
}
|
|
19
|
+
interface LogFileContent {
|
|
20
|
+
metadata: any;
|
|
21
|
+
logs: LogItem[];
|
|
22
|
+
}
|
|
23
|
+
export interface LoggerOptions {
|
|
24
|
+
prefix?: string;
|
|
25
|
+
checkInterval?: number;
|
|
26
|
+
feishuConfig?: any;
|
|
27
|
+
retentionDays?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 日志管理器类
|
|
31
|
+
*/
|
|
32
|
+
declare class LoggerManager {
|
|
33
|
+
private logBuffer;
|
|
34
|
+
private timer;
|
|
35
|
+
private checkInterval;
|
|
36
|
+
private prefix;
|
|
37
|
+
private metadata;
|
|
38
|
+
private db;
|
|
39
|
+
private app;
|
|
40
|
+
private feishuConfig;
|
|
41
|
+
private retentionDays;
|
|
42
|
+
private metadataFunction;
|
|
43
|
+
private status;
|
|
44
|
+
/**
|
|
45
|
+
* 构造函数
|
|
46
|
+
* @param prefix 日志前缀
|
|
47
|
+
* @param checkInterval 检查间隔时间,默认5分钟
|
|
48
|
+
*/
|
|
49
|
+
constructor(app: App, options?: LoggerOptions);
|
|
50
|
+
init(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* 初始化 IndexDB
|
|
53
|
+
*/
|
|
54
|
+
private initDB;
|
|
55
|
+
/**
|
|
56
|
+
* 设置元数据
|
|
57
|
+
* @param metadata 元数据
|
|
58
|
+
*/
|
|
59
|
+
setMetadata(metadata: any): void;
|
|
60
|
+
setMetadataFunction(metadataFunction: () => any): void;
|
|
61
|
+
/**
|
|
62
|
+
* 初始化定时器
|
|
63
|
+
*/
|
|
64
|
+
initTimer(): void;
|
|
65
|
+
private setStatus;
|
|
66
|
+
stop(): void;
|
|
67
|
+
/**
|
|
68
|
+
* 添加日志
|
|
69
|
+
* @param log 日志项
|
|
70
|
+
*/
|
|
71
|
+
addLog(log: LogItem): void;
|
|
72
|
+
/**
|
|
73
|
+
* 发送飞书通知
|
|
74
|
+
* @param log 日志项
|
|
75
|
+
*/
|
|
76
|
+
private sendFeishuNotification;
|
|
77
|
+
/**
|
|
78
|
+
* 创建日志文件名
|
|
79
|
+
* @returns 日志文件名
|
|
80
|
+
*/
|
|
81
|
+
private createFileName;
|
|
82
|
+
/**
|
|
83
|
+
* 创建AWS日志文件名
|
|
84
|
+
* @param isManual 紧急上传
|
|
85
|
+
* @returns 日志文件名
|
|
86
|
+
*/
|
|
87
|
+
createAWSFileName(urgent?: boolean): Promise<any>;
|
|
88
|
+
/**
|
|
89
|
+
* 创建日志文件
|
|
90
|
+
* @param _fileName 文件名
|
|
91
|
+
* @returns 日志文件对象
|
|
92
|
+
*/
|
|
93
|
+
private createFile;
|
|
94
|
+
/**
|
|
95
|
+
* 存储日志到持久化存储
|
|
96
|
+
*/
|
|
97
|
+
storeLog(urgent?: boolean): Promise<void>;
|
|
98
|
+
uploadIndexDBLog(): Promise<void>;
|
|
99
|
+
private storeLogToIndexDB;
|
|
100
|
+
/**
|
|
101
|
+
* 清理旧日志,只保留最近指定天数的日志
|
|
102
|
+
*/
|
|
103
|
+
private cleanupOldLogs;
|
|
104
|
+
/**
|
|
105
|
+
* 获取日志文件列表
|
|
106
|
+
* @returns 日志文件列表
|
|
107
|
+
*/
|
|
108
|
+
getLogFiles(): Promise<LogFile[]>;
|
|
109
|
+
/**
|
|
110
|
+
* 获取指定日志文件的内容
|
|
111
|
+
* @param fileName 日志文件名
|
|
112
|
+
* @returns 日志文件内容
|
|
113
|
+
*/
|
|
114
|
+
getLogFile(fileName: string): Promise<LogFile | null>;
|
|
115
|
+
/**
|
|
116
|
+
* 清空指定日志文件
|
|
117
|
+
* @param fileName 日志文件名,不指定则清空所有日志
|
|
118
|
+
* @returns 是否成功
|
|
119
|
+
*/
|
|
120
|
+
clearLogs(fileName?: string): Promise<boolean>;
|
|
121
|
+
/**
|
|
122
|
+
* 设置日志保留天数
|
|
123
|
+
* @param days 保留天数
|
|
124
|
+
*/
|
|
125
|
+
setRetentionDays(days: number): void;
|
|
126
|
+
/**
|
|
127
|
+
* 手动触发清理旧日志
|
|
128
|
+
*/
|
|
129
|
+
manualCleanup(): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* 销毁实例
|
|
132
|
+
*/
|
|
133
|
+
destroy(): void;
|
|
134
|
+
}
|
|
135
|
+
export default LoggerManager;
|