@pluve/logger-sdk 0.0.1 → 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.
Files changed (41) hide show
  1. package/README.md +195 -76
  2. package/dist/cjs/index.d.ts +5 -0
  3. package/dist/cjs/index.js +14 -2
  4. package/dist/cjs/loggerSDK.d.ts +27 -20
  5. package/dist/cjs/loggerSDK.js +86 -354
  6. package/dist/cjs/transportAdapter.d.ts +51 -5
  7. package/dist/cjs/transportAdapter.js +133 -60
  8. package/dist/cjs/types.d.ts +37 -26
  9. package/dist/cjs/utils.d.ts +27 -2
  10. package/dist/cjs/utils.js +151 -12
  11. package/dist/esm/index.d.ts +5 -0
  12. package/dist/esm/index.js +4 -2
  13. package/dist/esm/loggerSDK.d.ts +27 -20
  14. package/dist/esm/loggerSDK.js +141 -674
  15. package/dist/esm/transportAdapter.d.ts +51 -5
  16. package/dist/esm/transportAdapter.js +260 -111
  17. package/dist/esm/types.d.ts +37 -26
  18. package/dist/esm/utils.d.ts +27 -2
  19. package/dist/esm/utils.js +190 -14
  20. package/dist/umd/logger-sdk.min.js +1 -1
  21. package/lib/dbQueue.js +133 -0
  22. package/lib/index.d.ts +1 -0
  23. package/lib/index.js +9 -0
  24. package/lib/loggerSDK.d.ts +29 -0
  25. package/lib/loggerSDK.js +571 -0
  26. package/lib/storeAdapter.js +99 -0
  27. package/lib/transportAdapter.d.ts +66 -0
  28. package/lib/transportAdapter.js +406 -0
  29. package/lib/types.d.ts +35 -0
  30. package/lib/types.js +1 -0
  31. package/lib/utils.d.ts +5 -0
  32. package/lib/utils.js +50 -0
  33. package/package.json +8 -2
  34. package/dist/cjs/dbQueue.js +0 -88
  35. package/dist/cjs/storeAdapter.js +0 -64
  36. package/dist/esm/dbQueue.d.ts +0 -10
  37. package/dist/esm/dbQueue.js +0 -194
  38. package/dist/esm/storeAdapter.d.ts +0 -7
  39. package/dist/esm/storeAdapter.js +0 -139
  40. /package/{dist/cjs → lib}/dbQueue.d.ts +0 -0
  41. /package/{dist/cjs → lib}/storeAdapter.d.ts +0 -0
@@ -1,64 +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/storeAdapter.ts
20
- var storeAdapter_exports = {};
21
- __export(storeAdapter_exports, {
22
- browserStorage: () => browserStorage,
23
- wechatStorage: () => wechatStorage
24
- });
25
- module.exports = __toCommonJS(storeAdapter_exports);
26
- function browserStorage(key) {
27
- return {
28
- async get() {
29
- return Promise.resolve(localStorage.getItem(key));
30
- },
31
- async set(val) {
32
- localStorage.setItem(key, val);
33
- return Promise.resolve();
34
- },
35
- async remove() {
36
- localStorage.removeItem(key);
37
- return Promise.resolve();
38
- }
39
- };
40
- }
41
- function wechatStorage(key) {
42
- return {
43
- async get() {
44
- return new Promise((res) => {
45
- wx.getStorage({ key, success: (r) => res(r.data), fail: () => res(null) });
46
- });
47
- },
48
- async set(val) {
49
- return new Promise((res) => {
50
- wx.setStorage({ key, data: val, success: () => res(void 0), fail: () => res(void 0) });
51
- });
52
- },
53
- async remove() {
54
- return new Promise((res) => {
55
- wx.removeStorage({ key, success: () => res(void 0), fail: () => res(void 0) });
56
- });
57
- }
58
- };
59
- }
60
- // Annotate the CommonJS export names for ESM import in node:
61
- 0 && (module.exports = {
62
- browserStorage,
63
- wechatStorage
64
- });
@@ -1,10 +0,0 @@
1
- export default class IDBQueue {
2
- private dbName;
3
- private storeName;
4
- private db;
5
- constructor(dbName?: string, storeName?: string);
6
- open(): Promise<void>;
7
- add(item: any): Promise<void>;
8
- getAll(): Promise<any[]>;
9
- clear(): Promise<unknown>;
10
- }
@@ -1,194 +0,0 @@
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
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
- 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); } }
7
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
- 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; }
9
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
10
- 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); }
11
- /*
12
- * @Author : 黄震 huangzhen@yfpharmacy.com
13
- * @Date : 2025-11-21 14:32:51
14
- * @LastEditors : 黄震 huangzhen@yfpharmacy.com
15
- * @LastEditTime : 2025-11-21 14:38:50
16
- * @Description : 描述
17
- * Copyright (c) 2025 by 益丰大药房连锁股份有限公司, All Rights Reserved.
18
- */
19
-
20
- import { isBrowser, isIndexedDBAvailable } from "./utils";
21
-
22
- // IndexedDB 轻量队列:作为 localStorage 的冗余通道
23
- var IDBQueue = /*#__PURE__*/function () {
24
- function IDBQueue() {
25
- var dbName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'logger_sdk_db';
26
- var storeName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'queue';
27
- _classCallCheck(this, IDBQueue);
28
- _defineProperty(this, "dbName", void 0);
29
- _defineProperty(this, "storeName", void 0);
30
- _defineProperty(this, "db", null);
31
- this.dbName = dbName;
32
- this.storeName = storeName;
33
- }
34
-
35
- // 打开数据库并初始化对象仓库
36
- _createClass(IDBQueue, [{
37
- key: "open",
38
- value: function () {
39
- var _open = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
40
- var _this = this;
41
- return _regeneratorRuntime().wrap(function _callee$(_context) {
42
- while (1) switch (_context.prev = _context.next) {
43
- case 0:
44
- if (!(!isBrowser() || !isIndexedDBAvailable())) {
45
- _context.next = 2;
46
- break;
47
- }
48
- return _context.abrupt("return");
49
- case 2:
50
- if (!this.db) {
51
- _context.next = 4;
52
- break;
53
- }
54
- return _context.abrupt("return");
55
- case 4:
56
- return _context.abrupt("return", new Promise(function (resolve, reject) {
57
- var req = indexedDB.open(_this.dbName, 1);
58
- req.onupgradeneeded = function () {
59
- var db = req.result;
60
- if (!db.objectStoreNames.contains(_this.storeName)) db.createObjectStore(_this.storeName, {
61
- autoIncrement: true
62
- });
63
- };
64
- req.onsuccess = function () {
65
- _this.db = req.result;
66
- resolve();
67
- };
68
- req.onerror = function () {
69
- return reject(req.error);
70
- };
71
- }));
72
- case 5:
73
- case "end":
74
- return _context.stop();
75
- }
76
- }, _callee, this);
77
- }));
78
- function open() {
79
- return _open.apply(this, arguments);
80
- }
81
- return open;
82
- }() // 入队:追加一条记录
83
- }, {
84
- key: "add",
85
- value: function () {
86
- var _add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(item) {
87
- var _this2 = this;
88
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
89
- while (1) switch (_context2.prev = _context2.next) {
90
- case 0:
91
- if (this.db) {
92
- _context2.next = 2;
93
- break;
94
- }
95
- return _context2.abrupt("return");
96
- case 2:
97
- return _context2.abrupt("return", new Promise(function (res, rej) {
98
- var tx = _this2.db.transaction(_this2.storeName, 'readwrite');
99
- var st = tx.objectStore(_this2.storeName);
100
- var r = st.add(item);
101
- r.onsuccess = function () {
102
- return res();
103
- };
104
- r.onerror = function () {
105
- return rej(r.error);
106
- };
107
- }));
108
- case 3:
109
- case "end":
110
- return _context2.stop();
111
- }
112
- }, _callee2, this);
113
- }));
114
- function add(_x) {
115
- return _add.apply(this, arguments);
116
- }
117
- return add;
118
- }() // 读取全部记录(调试/回溯用)
119
- }, {
120
- key: "getAll",
121
- value: function () {
122
- var _getAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
123
- var _this3 = this;
124
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
125
- while (1) switch (_context3.prev = _context3.next) {
126
- case 0:
127
- if (this.db) {
128
- _context3.next = 2;
129
- break;
130
- }
131
- return _context3.abrupt("return", []);
132
- case 2:
133
- return _context3.abrupt("return", new Promise(function (res, rej) {
134
- var tx = _this3.db.transaction(_this3.storeName, 'readonly');
135
- var st = tx.objectStore(_this3.storeName);
136
- var req = st.getAll();
137
- req.onsuccess = function () {
138
- return res(req.result || []);
139
- };
140
- req.onerror = function () {
141
- return rej(req.error);
142
- };
143
- }));
144
- case 3:
145
- case "end":
146
- return _context3.stop();
147
- }
148
- }, _callee3, this);
149
- }));
150
- function getAll() {
151
- return _getAll.apply(this, arguments);
152
- }
153
- return getAll;
154
- }() // 清空队列:发送成功后用于兜底清理
155
- }, {
156
- key: "clear",
157
- value: function () {
158
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
159
- var _this4 = this;
160
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
161
- while (1) switch (_context4.prev = _context4.next) {
162
- case 0:
163
- if (this.db) {
164
- _context4.next = 2;
165
- break;
166
- }
167
- return _context4.abrupt("return");
168
- case 2:
169
- return _context4.abrupt("return", new Promise(function (res, rej) {
170
- var tx = _this4.db.transaction(_this4.storeName, 'readwrite');
171
- var st = tx.objectStore(_this4.storeName);
172
- var req = st.clear();
173
- req.onsuccess = function () {
174
- return res(undefined);
175
- };
176
- req.onerror = function () {
177
- return rej(req.error);
178
- };
179
- }));
180
- case 3:
181
- case "end":
182
- return _context4.stop();
183
- }
184
- }, _callee4, this);
185
- }));
186
- function clear() {
187
- return _clear.apply(this, arguments);
188
- }
189
- return clear;
190
- }()
191
- }]);
192
- return IDBQueue;
193
- }();
194
- export { IDBQueue as default };
@@ -1,7 +0,0 @@
1
- export interface StorageAdapter {
2
- get(): Promise<string | null>;
3
- set(val: string): Promise<void>;
4
- remove(): Promise<void>;
5
- }
6
- export declare function browserStorage(key: string): StorageAdapter;
7
- export declare function wechatStorage(key: string): StorageAdapter;
@@ -1,139 +0,0 @@
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
- /*
6
- * @Author : 黄震 huangzhen@yfpharmacy.com
7
- * @Date : 2025-11-21 14:33:56
8
- * @LastEditors : 黄震 huangzhen@yfpharmacy.com
9
- * @LastEditTime : 2025-11-21 14:34:17
10
- * @Description : 存储适配器接口
11
- * Copyright (c) 2025 by 益丰大药房连锁股份有限公司, All Rights Reserved.
12
- */
13
- // 存储适配器接口:统一不同运行环境下的持久化能力
14
-
15
- // 浏览器环境:使用 localStorage 简单持久化
16
- export function browserStorage(key) {
17
- return {
18
- get: function get() {
19
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
20
- return _regeneratorRuntime().wrap(function _callee$(_context) {
21
- while (1) switch (_context.prev = _context.next) {
22
- case 0:
23
- return _context.abrupt("return", Promise.resolve(localStorage.getItem(key)));
24
- case 1:
25
- case "end":
26
- return _context.stop();
27
- }
28
- }, _callee);
29
- }))();
30
- },
31
- set: function set(val) {
32
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
33
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
34
- while (1) switch (_context2.prev = _context2.next) {
35
- case 0:
36
- localStorage.setItem(key, val);
37
- return _context2.abrupt("return", Promise.resolve());
38
- case 2:
39
- case "end":
40
- return _context2.stop();
41
- }
42
- }, _callee2);
43
- }))();
44
- },
45
- remove: function remove() {
46
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
47
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
48
- while (1) switch (_context3.prev = _context3.next) {
49
- case 0:
50
- localStorage.removeItem(key);
51
- return _context3.abrupt("return", Promise.resolve());
52
- case 2:
53
- case "end":
54
- return _context3.stop();
55
- }
56
- }, _callee3);
57
- }))();
58
- }
59
- };
60
- }
61
-
62
- // 微信小程序环境:封装 wx.*Storage API
63
- export function wechatStorage(key) {
64
- return {
65
- get: function get() {
66
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
67
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
68
- while (1) switch (_context4.prev = _context4.next) {
69
- case 0:
70
- return _context4.abrupt("return", new Promise(function (res) {
71
- // @ts-ignore
72
- wx.getStorage({
73
- key: key,
74
- success: function success(r) {
75
- return res(r.data);
76
- },
77
- fail: function fail() {
78
- return res(null);
79
- }
80
- });
81
- }));
82
- case 1:
83
- case "end":
84
- return _context4.stop();
85
- }
86
- }, _callee4);
87
- }))();
88
- },
89
- set: function set(val) {
90
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
91
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
92
- while (1) switch (_context5.prev = _context5.next) {
93
- case 0:
94
- return _context5.abrupt("return", new Promise(function (res) {
95
- // @ts-ignore
96
- wx.setStorage({
97
- key: key,
98
- data: val,
99
- success: function success() {
100
- return res(undefined);
101
- },
102
- fail: function fail() {
103
- return res(undefined);
104
- }
105
- });
106
- }));
107
- case 1:
108
- case "end":
109
- return _context5.stop();
110
- }
111
- }, _callee5);
112
- }))();
113
- },
114
- remove: function remove() {
115
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
116
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
117
- while (1) switch (_context6.prev = _context6.next) {
118
- case 0:
119
- return _context6.abrupt("return", new Promise(function (res) {
120
- // @ts-ignore
121
- wx.removeStorage({
122
- key: key,
123
- success: function success() {
124
- return res(undefined);
125
- },
126
- fail: function fail() {
127
- return res(undefined);
128
- }
129
- });
130
- }));
131
- case 1:
132
- case "end":
133
- return _context6.stop();
134
- }
135
- }, _callee6);
136
- }))();
137
- }
138
- };
139
- }
File without changes
File without changes