@pisell/pisellos 2.2.93 → 2.2.95

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 (53) hide show
  1. package/dist/modules/Order/index.d.ts +1 -1
  2. package/dist/plugins/app-types/app/app.d.ts +1 -0
  3. package/dist/server/index.d.ts +55 -0
  4. package/dist/server/index.js +826 -207
  5. package/dist/server/modules/index.d.ts +6 -0
  6. package/dist/server/modules/index.js +7 -0
  7. package/dist/server/modules/order/index.d.ts +87 -0
  8. package/dist/server/modules/order/index.js +916 -0
  9. package/dist/server/modules/order/types.d.ts +530 -0
  10. package/dist/server/modules/order/types.js +141 -0
  11. package/dist/server/modules/order/utils/filterBookings.d.ts +6 -0
  12. package/dist/server/modules/order/utils/filterBookings.js +350 -0
  13. package/dist/server/modules/order/utils/filterOrders.d.ts +15 -0
  14. package/dist/server/modules/order/utils/filterOrders.js +226 -0
  15. package/dist/server/modules/resource/index.d.ts +88 -0
  16. package/dist/server/modules/resource/index.js +1202 -0
  17. package/dist/server/modules/resource/types.d.ts +121 -0
  18. package/dist/server/modules/resource/types.js +47 -0
  19. package/dist/solution/BookingByStep/index.d.ts +1 -1
  20. package/dist/solution/BookingTicket/index.d.ts +1 -1
  21. package/dist/solution/Sales/index.d.ts +96 -0
  22. package/dist/solution/Sales/index.js +562 -0
  23. package/dist/solution/Sales/types.d.ts +66 -0
  24. package/dist/solution/Sales/types.js +26 -0
  25. package/dist/solution/index.d.ts +1 -0
  26. package/dist/solution/index.js +2 -1
  27. package/lib/modules/Order/index.d.ts +1 -1
  28. package/lib/plugins/app-types/app/app.d.ts +1 -0
  29. package/lib/server/index.d.ts +55 -0
  30. package/lib/server/index.js +343 -1
  31. package/lib/server/modules/index.d.ts +6 -0
  32. package/lib/server/modules/index.js +16 -2
  33. package/lib/server/modules/order/index.d.ts +87 -0
  34. package/lib/server/modules/order/index.js +543 -0
  35. package/lib/server/modules/order/types.d.ts +530 -0
  36. package/lib/server/modules/order/types.js +34 -0
  37. package/lib/server/modules/order/utils/filterBookings.d.ts +6 -0
  38. package/lib/server/modules/order/utils/filterBookings.js +320 -0
  39. package/lib/server/modules/order/utils/filterOrders.d.ts +15 -0
  40. package/lib/server/modules/order/utils/filterOrders.js +197 -0
  41. package/lib/server/modules/resource/index.d.ts +88 -0
  42. package/lib/server/modules/resource/index.js +571 -0
  43. package/lib/server/modules/resource/types.d.ts +121 -0
  44. package/lib/server/modules/resource/types.js +35 -0
  45. package/lib/solution/BookingByStep/index.d.ts +1 -1
  46. package/lib/solution/BookingTicket/index.d.ts +1 -1
  47. package/lib/solution/Sales/index.d.ts +96 -0
  48. package/lib/solution/Sales/index.js +413 -0
  49. package/lib/solution/Sales/types.d.ts +66 -0
  50. package/lib/solution/Sales/types.js +35 -0
  51. package/lib/solution/index.d.ts +1 -0
  52. package/lib/solution/index.js +3 -1
  53. package/package.json +1 -1
@@ -0,0 +1,1202 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5
+ 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; } } }; }
6
+ 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); }
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
+ 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); }
9
+ 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; }
10
+ 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; }
11
+ 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; }
12
+ 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); } }
13
+ 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); }); }; }
14
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
+ 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); } }
16
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
18
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
19
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
20
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
21
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
22
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
23
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
24
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
25
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
26
+ 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; }
27
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
28
+ 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); }
29
+ import { cloneDeep } from 'lodash-es';
30
+ import { BaseModule } from "../../../modules/BaseModule";
31
+ import { ResourceHooks } from "./types";
32
+
33
+ /**
34
+ * SQLite 存储名称
35
+ */
36
+ var RESOURCE_STORE_NAME = 'resources';
37
+ var BOOKING_STORE_NAME = 'resource_bookings';
38
+
39
+ /**
40
+ * 默认分页大小
41
+ */
42
+ var DEFAULT_PAGE_SIZE = 999;
43
+
44
+ /**
45
+ * 同步防抖超时(毫秒)
46
+ */
47
+ var RESOURCE_SYNC_DEBOUNCE_MS = 10000;
48
+
49
+ /**
50
+ * Resource 模块
51
+ */
52
+ export var ResourceModule = /*#__PURE__*/function (_BaseModule) {
53
+ _inherits(ResourceModule, _BaseModule);
54
+ var _super = _createSuper(ResourceModule);
55
+ function ResourceModule(name, version) {
56
+ var _this;
57
+ _classCallCheck(this, ResourceModule);
58
+ _this = _super.call(this, name, version);
59
+ _defineProperty(_assertThisInitialized(_this), "defaultName", 'resource');
60
+ _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
61
+ _defineProperty(_assertThisInitialized(_this), "store", void 0);
62
+ _defineProperty(_assertThisInitialized(_this), "dbManager", void 0);
63
+ _defineProperty(_assertThisInitialized(_this), "logger", void 0);
64
+ // LoggerManager 实例
65
+ _defineProperty(_assertThisInitialized(_this), "resourceDataSource", void 0);
66
+ /** 倒排索引: resourceId -> ResourceBooking[] */
67
+ _defineProperty(_assertThisInitialized(_this), "resourceIdIndex", new Map());
68
+ /** 待处理的同步消息队列 */
69
+ _defineProperty(_assertThisInitialized(_this), "pendingSyncMessages", []);
70
+ _defineProperty(_assertThisInitialized(_this), "syncTimer", void 0);
71
+ return _this;
72
+ }
73
+
74
+ // ─────────────────────────────────────────────────────────────────
75
+ // 初始化 & 生命周期
76
+ // ─────────────────────────────────────────────────────────────────
77
+ _createClass(ResourceModule, [{
78
+ key: "initialize",
79
+ value: function () {
80
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
81
+ var _options$initialState,
82
+ _this2 = this;
83
+ var _options$initialState2, appPlugin, app;
84
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
85
+ while (1) switch (_context.prev = _context.next) {
86
+ case 0:
87
+ this.core = core;
88
+ this.store = options === null || options === void 0 ? void 0 : options.store;
89
+ if (Array.isArray(options === null || options === void 0 || (_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.list)) {
90
+ this.store.list = (options === null || options === void 0 || (_options$initialState2 = options.initialState) === null || _options$initialState2 === void 0 ? void 0 : _options$initialState2.list).map(function (item) {
91
+ return _this2.normalizeResource(item);
92
+ });
93
+ this.syncResourcesMap();
94
+ this.core.effects.emit(ResourceHooks.onResourcesChanged, this.store.list);
95
+ } else {
96
+ this.store.list = [];
97
+ this.store.map = new Map();
98
+ }
99
+ if (!Array.isArray(this.store.bookings)) {
100
+ this.store.bookings = [];
101
+ }
102
+ appPlugin = core.getPlugin('app');
103
+ if (appPlugin) {
104
+ app = appPlugin.getApp();
105
+ this.dbManager = app.sqlite || app.dbManager;
106
+ this.logger = app.logger;
107
+ }
108
+ this.initResourceDataSource();
109
+ this.setupResourceSync();
110
+ case 8:
111
+ case "end":
112
+ return _context.stop();
113
+ }
114
+ }, _callee, this);
115
+ }));
116
+ function initialize(_x, _x2) {
117
+ return _initialize.apply(this, arguments);
118
+ }
119
+ return initialize;
120
+ }()
121
+ }, {
122
+ key: "logInfo",
123
+ value: function logInfo(title, metadata) {
124
+ if (this.logger) {
125
+ this.logger.addLog({
126
+ type: 'info',
127
+ title: "[ResourceModule] ".concat(title),
128
+ metadata: metadata || {}
129
+ });
130
+ }
131
+ }
132
+ }, {
133
+ key: "logError",
134
+ value: function logError(title, error, metadata) {
135
+ if (this.logger) {
136
+ this.logger.addLog({
137
+ type: 'error',
138
+ title: "[ResourceModule] ".concat(title),
139
+ metadata: metadata || {}
140
+ });
141
+ }
142
+ }
143
+ }, {
144
+ key: "preload",
145
+ value: function () {
146
+ var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
147
+ var _this3 = this;
148
+ var cachedResources, resources, cachedBookings;
149
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
150
+ while (1) switch (_context2.prev = _context2.next) {
151
+ case 0:
152
+ _context2.next = 2;
153
+ return this.loadResourcesFromSQLite();
154
+ case 2:
155
+ cachedResources = _context2.sent;
156
+ if (!(cachedResources.length > 0)) {
157
+ _context2.next = 10;
158
+ break;
159
+ }
160
+ this.store.list = cloneDeep(cachedResources).map(function (item) {
161
+ return _this3.normalizeResource(item);
162
+ });
163
+ this.syncResourcesMap();
164
+ _context2.next = 8;
165
+ return this.safeEmit(ResourceHooks.onResourcesChanged, this.store.list);
166
+ case 8:
167
+ _context2.next = 18;
168
+ break;
169
+ case 10:
170
+ _context2.next = 12;
171
+ return this.loadResourcesByServer();
172
+ case 12:
173
+ resources = _context2.sent;
174
+ if (!(resources.length > 0)) {
175
+ _context2.next = 18;
176
+ break;
177
+ }
178
+ this.store.list = cloneDeep(resources).map(function (item) {
179
+ return _this3.normalizeResource(item);
180
+ });
181
+ this.syncResourcesMap();
182
+ _context2.next = 18;
183
+ return this.safeEmit(ResourceHooks.onResourcesChanged, this.store.list);
184
+ case 18:
185
+ _context2.next = 20;
186
+ return this.loadBookingsFromSQLite();
187
+ case 20:
188
+ cachedBookings = _context2.sent;
189
+ if (cachedBookings.length > 0) {
190
+ this.store.bookings = cloneDeep(cachedBookings);
191
+ this.syncBookingsIndex();
192
+ }
193
+ case 22:
194
+ case "end":
195
+ return _context2.stop();
196
+ }
197
+ }, _callee2, this);
198
+ }));
199
+ function preload() {
200
+ return _preload.apply(this, arguments);
201
+ }
202
+ return preload;
203
+ }()
204
+ }, {
205
+ key: "getRoutes",
206
+ value: function getRoutes() {
207
+ return [];
208
+ }
209
+ }, {
210
+ key: "destroy",
211
+ value: function destroy() {
212
+ var _this$resourceDataSou;
213
+ if (this.syncTimer) {
214
+ clearTimeout(this.syncTimer);
215
+ this.syncTimer = undefined;
216
+ }
217
+ this.pendingSyncMessages = [];
218
+ if ((_this$resourceDataSou = this.resourceDataSource) !== null && _this$resourceDataSou !== void 0 && _this$resourceDataSou.destroy) this.resourceDataSource.destroy();
219
+ _get(_getPrototypeOf(ResourceModule.prototype), "destroy", this).call(this);
220
+ }
221
+
222
+ // ─────────────────────────────────────────────────────────────────
223
+ // Resource CRUD
224
+ // ─────────────────────────────────────────────────────────────────
225
+
226
+ /**
227
+ * 获取所有资源(支持 includeBookings 附加预订信息)
228
+ */
229
+ }, {
230
+ key: "getResources",
231
+ value: function getResources(queryOptions) {
232
+ var _this4 = this;
233
+ this.logInfo('getResources', {
234
+ queryOptions: queryOptions
235
+ });
236
+ if (!(queryOptions !== null && queryOptions !== void 0 && queryOptions.includeBookings)) {
237
+ return this.store.list;
238
+ }
239
+ return this.store.list.map(function (resource) {
240
+ return _this4.attachBookingsToResource(resource);
241
+ });
242
+ }
243
+
244
+ /**
245
+ * 根据 ID 获取单个资源
246
+ */
247
+ }, {
248
+ key: "getResourceById",
249
+ value: function getResourceById(id, queryOptions) {
250
+ var resource = this.store.map.get(id);
251
+ if (!resource) return undefined;
252
+ if (queryOptions !== null && queryOptions !== void 0 && queryOptions.includeBookings) {
253
+ return this.attachBookingsToResource(resource);
254
+ }
255
+ return resource;
256
+ }
257
+
258
+ /**
259
+ * 创建资源
260
+ */
261
+ }, {
262
+ key: "createResource",
263
+ value: function createResource(data) {
264
+ var _ref, _data$id;
265
+ var id = (_ref = (_data$id = data === null || data === void 0 ? void 0 : data.id) !== null && _data$id !== void 0 ? _data$id : data === null || data === void 0 ? void 0 : data.form_record_id) !== null && _ref !== void 0 ? _ref : Date.now();
266
+ var resource = this.normalizeResource(_objectSpread(_objectSpread({}, data), {}, {
267
+ id: id
268
+ }));
269
+ this.store.list.push(resource);
270
+ this.store.map.set(resource.id, resource);
271
+ this.saveResourcesToSQLite(this.store.list).catch(function () {});
272
+ this.safeEmit(ResourceHooks.onResourcesChanged, this.store.list);
273
+ return resource;
274
+ }
275
+
276
+ /**
277
+ * 更新资源
278
+ */
279
+ }, {
280
+ key: "updateResource",
281
+ value: function updateResource(id, data) {
282
+ var _this5 = this;
283
+ var index = this.store.list.findIndex(function (r) {
284
+ return _this5.getIdKey(r.id) === _this5.getIdKey(id);
285
+ });
286
+ if (index === -1) return undefined;
287
+ var updated = this.normalizeResource(_objectSpread(_objectSpread(_objectSpread({}, this.store.list[index]), data), {}, {
288
+ id: id
289
+ }));
290
+ this.store.list[index] = updated;
291
+ this.store.map.set(updated.id, updated);
292
+ this.saveResourcesToSQLite(this.store.list).catch(function () {});
293
+ this.safeEmit(ResourceHooks.onResourcesChanged, this.store.list);
294
+ return updated;
295
+ }
296
+
297
+ /**
298
+ * 删除资源
299
+ */
300
+ }, {
301
+ key: "deleteResource",
302
+ value: function deleteResource(id) {
303
+ var _this6 = this;
304
+ var key = this.getIdKey(id);
305
+ var index = this.store.list.findIndex(function (r) {
306
+ return _this6.getIdKey(r.id) === key;
307
+ });
308
+ if (index === -1) return false;
309
+ this.store.list.splice(index, 1);
310
+ this.store.map.delete(id);
311
+ this.saveResourcesToSQLite(this.store.list).catch(function () {});
312
+ this.safeEmit(ResourceHooks.onResourcesChanged, this.store.list);
313
+ return true;
314
+ }
315
+
316
+ // ─────────────────────────────────────────────────────────────────
317
+ // Booking CRUD
318
+ // ─────────────────────────────────────────────────────────────────
319
+
320
+ /**
321
+ * 根据资源 ID 获取预订列表
322
+ */
323
+ }, {
324
+ key: "getBookingsByResourceId",
325
+ value: function getBookingsByResourceId(resourceId) {
326
+ return this.resourceIdIndex.get(resourceId) || [];
327
+ }
328
+
329
+ /**
330
+ * 创建预订
331
+ */
332
+ }, {
333
+ key: "createBooking",
334
+ value: function createBooking(booking) {
335
+ var _booking$id, _normalized$resource_;
336
+ var id = (_booking$id = booking === null || booking === void 0 ? void 0 : booking.id) !== null && _booking$id !== void 0 ? _booking$id : Date.now();
337
+ var normalized = _objectSpread({
338
+ id: id
339
+ }, booking);
340
+ this.store.bookings.push(normalized);
341
+ var rid = (_normalized$resource_ = normalized.resource_id) !== null && _normalized$resource_ !== void 0 ? _normalized$resource_ : normalized.resourceId;
342
+ if (rid !== undefined) {
343
+ var existing = this.resourceIdIndex.get(rid) || [];
344
+ existing.push(normalized);
345
+ this.resourceIdIndex.set(rid, existing);
346
+ }
347
+ this.saveBookingsToSQLite(this.store.bookings).catch(function () {});
348
+ this.safeEmit(ResourceHooks.onBookingsChanged, this.store.bookings);
349
+ return normalized;
350
+ }
351
+
352
+ /**
353
+ * 更新预订
354
+ */
355
+ }, {
356
+ key: "updateBooking",
357
+ value: function updateBooking(id, data) {
358
+ var _this7 = this;
359
+ var index = this.store.bookings.findIndex(function (b) {
360
+ return _this7.getIdKey(b.id) === _this7.getIdKey(id);
361
+ });
362
+ if (index === -1) return undefined;
363
+ var old = this.store.bookings[index];
364
+ var updated = _objectSpread(_objectSpread(_objectSpread({}, old), data), {}, {
365
+ id: old.id
366
+ });
367
+ this.store.bookings[index] = updated;
368
+ this.rebuildBookingsIndex();
369
+ this.saveBookingsToSQLite(this.store.bookings).catch(function () {});
370
+ this.safeEmit(ResourceHooks.onBookingsChanged, this.store.bookings);
371
+ return updated;
372
+ }
373
+
374
+ /**
375
+ * 删除预订
376
+ */
377
+ }, {
378
+ key: "deleteBooking",
379
+ value: function deleteBooking(id) {
380
+ var _this8 = this;
381
+ var index = this.store.bookings.findIndex(function (b) {
382
+ return _this8.getIdKey(b.id) === _this8.getIdKey(id);
383
+ });
384
+ if (index === -1) return false;
385
+ this.store.bookings.splice(index, 1);
386
+ this.rebuildBookingsIndex();
387
+ this.saveBookingsToSQLite(this.store.bookings).catch(function () {});
388
+ this.safeEmit(ResourceHooks.onBookingsChanged, this.store.bookings);
389
+ return true;
390
+ }
391
+
392
+ /**
393
+ * 清空缓存
394
+ */
395
+ }, {
396
+ key: "clear",
397
+ value: (function () {
398
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
399
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
400
+ while (1) switch (_context3.prev = _context3.next) {
401
+ case 0:
402
+ this.store.list = [];
403
+ this.store.map.clear();
404
+ this.store.bookings = [];
405
+ this.resourceIdIndex.clear();
406
+ if (!this.dbManager) {
407
+ _context3.next = 12;
408
+ break;
409
+ }
410
+ _context3.prev = 5;
411
+ _context3.next = 8;
412
+ return this.dbManager.clear(RESOURCE_STORE_NAME);
413
+ case 8:
414
+ _context3.next = 12;
415
+ break;
416
+ case 10:
417
+ _context3.prev = 10;
418
+ _context3.t0 = _context3["catch"](5);
419
+ case 12:
420
+ _context3.next = 14;
421
+ return this.safeEmit(ResourceHooks.onResourcesChanged, this.store.list);
422
+ case 14:
423
+ _context3.next = 16;
424
+ return this.safeEmit(ResourceHooks.onBookingsChanged, this.store.bookings);
425
+ case 16:
426
+ case "end":
427
+ return _context3.stop();
428
+ }
429
+ }, _callee3, this, [[5, 10]]);
430
+ }));
431
+ function clear() {
432
+ return _clear.apply(this, arguments);
433
+ }
434
+ return clear;
435
+ }() // ─────────────────────────────────────────────────────────────────
436
+ // 内部工具方法
437
+ // ─────────────────────────────────────────────────────────────────
438
+ )
439
+ }, {
440
+ key: "attachBookingsToResource",
441
+ value: function attachBookingsToResource(resource) {
442
+ return _objectSpread(_objectSpread({}, resource), {}, {
443
+ bookings: this.getBookingsByResourceId(resource.id)
444
+ });
445
+ }
446
+ }, {
447
+ key: "normalizeResource",
448
+ value: function normalizeResource(resource) {
449
+ var _ref2,
450
+ _resource$id,
451
+ _this9 = this;
452
+ var normalized = _objectSpread(_objectSpread({}, resource), {}, {
453
+ id: (_ref2 = (_resource$id = resource === null || resource === void 0 ? void 0 : resource.id) !== null && _resource$id !== void 0 ? _resource$id : resource === null || resource === void 0 ? void 0 : resource.form_record_id) !== null && _ref2 !== void 0 ? _ref2 : ''
454
+ });
455
+ if (normalized.form_record_id === undefined && normalized.id !== '') {
456
+ normalized.form_record_id = normalized.id;
457
+ }
458
+ if (normalized.resource_form_id === undefined || normalized.resource_form_id === null) {
459
+ normalized.resource_form_id = '';
460
+ }
461
+ if (normalized.schedule === undefined || normalized.schedule === null) {
462
+ normalized.schedule = '';
463
+ }
464
+ if (Array.isArray(normalized.times)) {
465
+ normalized.times = normalized.times.map(function (timeSlot) {
466
+ var _timeSlot$start_at, _timeSlot$end_at, _timeSlot$start, _timeSlot$end;
467
+ if (!timeSlot || _typeof(timeSlot) !== 'object') return timeSlot;
468
+ var startAt = (_timeSlot$start_at = timeSlot.start_at) !== null && _timeSlot$start_at !== void 0 ? _timeSlot$start_at : timeSlot.start;
469
+ var endAt = (_timeSlot$end_at = timeSlot.end_at) !== null && _timeSlot$end_at !== void 0 ? _timeSlot$end_at : timeSlot.end;
470
+ return _objectSpread(_objectSpread({}, timeSlot), {}, {
471
+ start_at: startAt,
472
+ end_at: endAt,
473
+ start: (_timeSlot$start = timeSlot.start) !== null && _timeSlot$start !== void 0 ? _timeSlot$start : startAt,
474
+ end: (_timeSlot$end = timeSlot.end) !== null && _timeSlot$end !== void 0 ? _timeSlot$end : endAt
475
+ });
476
+ });
477
+ }
478
+ if (Array.isArray(normalized.children)) {
479
+ normalized.children = normalized.children.map(function (child) {
480
+ return _this9.normalizeResource(child);
481
+ });
482
+ }
483
+ return normalized;
484
+ }
485
+ }, {
486
+ key: "safeEmit",
487
+ value: function () {
488
+ var _safeEmit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(event, payload) {
489
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
490
+ while (1) switch (_context4.prev = _context4.next) {
491
+ case 0:
492
+ _context4.prev = 0;
493
+ _context4.next = 3;
494
+ return this.core.effects.emit(event, payload);
495
+ case 3:
496
+ _context4.next = 8;
497
+ break;
498
+ case 5:
499
+ _context4.prev = 5;
500
+ _context4.t0 = _context4["catch"](0);
501
+ // 不让外部监听器异常影响资源模块预加载或清理流程
502
+ console.error("[ResourceModule] \u4E8B\u4EF6\u6D3E\u53D1\u5931\u8D25: ".concat(event), _context4.t0);
503
+ case 8:
504
+ case "end":
505
+ return _context4.stop();
506
+ }
507
+ }, _callee4, this, [[0, 5]]);
508
+ }));
509
+ function safeEmit(_x3, _x4) {
510
+ return _safeEmit.apply(this, arguments);
511
+ }
512
+ return safeEmit;
513
+ }()
514
+ }, {
515
+ key: "syncResourcesMap",
516
+ value: function syncResourcesMap() {
517
+ this.store.map = new Map();
518
+ var _iterator = _createForOfIteratorHelper(this.store.list),
519
+ _step;
520
+ try {
521
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
522
+ var resource = _step.value;
523
+ this.store.map.set(resource.id, resource);
524
+ }
525
+ } catch (err) {
526
+ _iterator.e(err);
527
+ } finally {
528
+ _iterator.f();
529
+ }
530
+ }
531
+ }, {
532
+ key: "syncBookingsIndex",
533
+ value: function syncBookingsIndex() {
534
+ this.resourceIdIndex.clear();
535
+ var _iterator2 = _createForOfIteratorHelper(this.store.bookings),
536
+ _step2;
537
+ try {
538
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
539
+ var _booking$resource_id;
540
+ var booking = _step2.value;
541
+ var rid = (_booking$resource_id = booking.resource_id) !== null && _booking$resource_id !== void 0 ? _booking$resource_id : booking.resourceId;
542
+ if (rid === undefined) continue;
543
+ var existing = this.resourceIdIndex.get(rid) || [];
544
+ existing.push(booking);
545
+ this.resourceIdIndex.set(rid, existing);
546
+ }
547
+ } catch (err) {
548
+ _iterator2.e(err);
549
+ } finally {
550
+ _iterator2.f();
551
+ }
552
+ }
553
+ }, {
554
+ key: "rebuildBookingsIndex",
555
+ value: function rebuildBookingsIndex() {
556
+ this.syncBookingsIndex();
557
+ }
558
+ }, {
559
+ key: "getIdKey",
560
+ value: function getIdKey(id) {
561
+ return String(id);
562
+ }
563
+
564
+ // ─────────────────────────────────────────────────────────────────
565
+ // 数据加载
566
+ // ─────────────────────────────────────────────────────────────────
567
+ }, {
568
+ key: "loadResourcesByServer",
569
+ value: function () {
570
+ var _loadResourcesByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
571
+ var _this10 = this;
572
+ var response, resourceList, normalizedList;
573
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
574
+ while (1) switch (_context5.prev = _context5.next) {
575
+ case 0:
576
+ if (this.resourceDataSource) {
577
+ _context5.next = 2;
578
+ break;
579
+ }
580
+ return _context5.abrupt("return", []);
581
+ case 2:
582
+ _context5.prev = 2;
583
+ _context5.next = 5;
584
+ return this.resourceDataSource.getResourcePage({
585
+ num: DEFAULT_PAGE_SIZE,
586
+ skip: 1
587
+ });
588
+ case 5:
589
+ response = _context5.sent;
590
+ resourceList = Array.isArray(response === null || response === void 0 ? void 0 : response.list) ? response.list : [];
591
+ normalizedList = resourceList.map(function (item) {
592
+ return _this10.normalizeResource(item);
593
+ });
594
+ _context5.next = 10;
595
+ return this.saveResourcesToSQLite(normalizedList);
596
+ case 10:
597
+ _context5.next = 12;
598
+ return this.safeEmit(ResourceHooks.onResourcesLoaded, normalizedList);
599
+ case 12:
600
+ return _context5.abrupt("return", normalizedList);
601
+ case 15:
602
+ _context5.prev = 15;
603
+ _context5.t0 = _context5["catch"](2);
604
+ return _context5.abrupt("return", []);
605
+ case 18:
606
+ case "end":
607
+ return _context5.stop();
608
+ }
609
+ }, _callee5, this, [[2, 15]]);
610
+ }));
611
+ function loadResourcesByServer() {
612
+ return _loadResourcesByServer.apply(this, arguments);
613
+ }
614
+ return loadResourcesByServer;
615
+ }() // ─────────────────────────────────────────────────────────────────
616
+ // SQLite 持久化
617
+ // ─────────────────────────────────────────────────────────────────
618
+ }, {
619
+ key: "loadResourcesFromSQLite",
620
+ value: function () {
621
+ var _loadResourcesFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
622
+ var resources;
623
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
624
+ while (1) switch (_context6.prev = _context6.next) {
625
+ case 0:
626
+ if (this.dbManager) {
627
+ _context6.next = 2;
628
+ break;
629
+ }
630
+ return _context6.abrupt("return", []);
631
+ case 2:
632
+ _context6.prev = 2;
633
+ _context6.next = 5;
634
+ return this.dbManager.getAll(RESOURCE_STORE_NAME);
635
+ case 5:
636
+ resources = _context6.sent;
637
+ return _context6.abrupt("return", resources || []);
638
+ case 9:
639
+ _context6.prev = 9;
640
+ _context6.t0 = _context6["catch"](2);
641
+ return _context6.abrupt("return", []);
642
+ case 12:
643
+ case "end":
644
+ return _context6.stop();
645
+ }
646
+ }, _callee6, this, [[2, 9]]);
647
+ }));
648
+ function loadResourcesFromSQLite() {
649
+ return _loadResourcesFromSQLite.apply(this, arguments);
650
+ }
651
+ return loadResourcesFromSQLite;
652
+ }()
653
+ }, {
654
+ key: "saveResourcesToSQLite",
655
+ value: function () {
656
+ var _saveResourcesToSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(resourceList) {
657
+ var _this11 = this;
658
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
659
+ while (1) switch (_context7.prev = _context7.next) {
660
+ case 0:
661
+ if (this.dbManager) {
662
+ _context7.next = 2;
663
+ break;
664
+ }
665
+ return _context7.abrupt("return");
666
+ case 2:
667
+ _context7.prev = 2;
668
+ _context7.next = 5;
669
+ return this.dbManager.clear(RESOURCE_STORE_NAME);
670
+ case 5:
671
+ if (!(resourceList.length === 0)) {
672
+ _context7.next = 7;
673
+ break;
674
+ }
675
+ return _context7.abrupt("return");
676
+ case 7:
677
+ if (!this.dbManager.bulkAdd) {
678
+ _context7.next = 11;
679
+ break;
680
+ }
681
+ _context7.next = 10;
682
+ return this.dbManager.bulkAdd(RESOURCE_STORE_NAME, resourceList);
683
+ case 10:
684
+ return _context7.abrupt("return");
685
+ case 11:
686
+ _context7.next = 13;
687
+ return Promise.all(resourceList.map(function (r) {
688
+ return _this11.dbManager.add(RESOURCE_STORE_NAME, r);
689
+ }));
690
+ case 13:
691
+ _context7.next = 19;
692
+ break;
693
+ case 15:
694
+ _context7.prev = 15;
695
+ _context7.t0 = _context7["catch"](2);
696
+ console.error('saveResourcesToSQLite error', _context7.t0);
697
+ this.logError('保存资源到 SQLite 失败', {
698
+ error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0),
699
+ resourceList: resourceList.length
700
+ });
701
+ case 19:
702
+ case "end":
703
+ return _context7.stop();
704
+ }
705
+ }, _callee7, this, [[2, 15]]);
706
+ }));
707
+ function saveResourcesToSQLite(_x5) {
708
+ return _saveResourcesToSQLite.apply(this, arguments);
709
+ }
710
+ return saveResourcesToSQLite;
711
+ }()
712
+ }, {
713
+ key: "loadBookingsFromSQLite",
714
+ value: function () {
715
+ var _loadBookingsFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
716
+ var bookings;
717
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
718
+ while (1) switch (_context8.prev = _context8.next) {
719
+ case 0:
720
+ if (this.dbManager) {
721
+ _context8.next = 2;
722
+ break;
723
+ }
724
+ return _context8.abrupt("return", []);
725
+ case 2:
726
+ _context8.prev = 2;
727
+ _context8.next = 5;
728
+ return this.dbManager.getAll(BOOKING_STORE_NAME);
729
+ case 5:
730
+ bookings = _context8.sent;
731
+ return _context8.abrupt("return", bookings || []);
732
+ case 9:
733
+ _context8.prev = 9;
734
+ _context8.t0 = _context8["catch"](2);
735
+ return _context8.abrupt("return", []);
736
+ case 12:
737
+ case "end":
738
+ return _context8.stop();
739
+ }
740
+ }, _callee8, this, [[2, 9]]);
741
+ }));
742
+ function loadBookingsFromSQLite() {
743
+ return _loadBookingsFromSQLite.apply(this, arguments);
744
+ }
745
+ return loadBookingsFromSQLite;
746
+ }()
747
+ }, {
748
+ key: "saveBookingsToSQLite",
749
+ value: function () {
750
+ var _saveBookingsToSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(bookings) {
751
+ var _this12 = this;
752
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
753
+ while (1) switch (_context9.prev = _context9.next) {
754
+ case 0:
755
+ if (this.dbManager) {
756
+ _context9.next = 2;
757
+ break;
758
+ }
759
+ return _context9.abrupt("return");
760
+ case 2:
761
+ _context9.prev = 2;
762
+ _context9.next = 5;
763
+ return this.dbManager.clear(BOOKING_STORE_NAME);
764
+ case 5:
765
+ if (!(bookings.length === 0)) {
766
+ _context9.next = 7;
767
+ break;
768
+ }
769
+ return _context9.abrupt("return");
770
+ case 7:
771
+ if (!this.dbManager.bulkAdd) {
772
+ _context9.next = 11;
773
+ break;
774
+ }
775
+ _context9.next = 10;
776
+ return this.dbManager.bulkAdd(BOOKING_STORE_NAME, bookings);
777
+ case 10:
778
+ return _context9.abrupt("return");
779
+ case 11:
780
+ _context9.next = 13;
781
+ return Promise.all(bookings.map(function (b) {
782
+ return _this12.dbManager.add(BOOKING_STORE_NAME, b);
783
+ }));
784
+ case 13:
785
+ _context9.next = 17;
786
+ break;
787
+ case 15:
788
+ _context9.prev = 15;
789
+ _context9.t0 = _context9["catch"](2);
790
+ case 17:
791
+ case "end":
792
+ return _context9.stop();
793
+ }
794
+ }, _callee9, this, [[2, 15]]);
795
+ }));
796
+ function saveBookingsToSQLite(_x6) {
797
+ return _saveBookingsToSQLite.apply(this, arguments);
798
+ }
799
+ return saveBookingsToSQLite;
800
+ }() // ─────────────────────────────────────────────────────────────────
801
+ // pubsub 同步
802
+ // ─────────────────────────────────────────────────────────────────
803
+ }, {
804
+ key: "initResourceDataSource",
805
+ value: function initResourceDataSource() {
806
+ var _serverOptions;
807
+ var ResourceDataSourceClass = (_serverOptions = this.core.serverOptions) === null || _serverOptions === void 0 || (_serverOptions = _serverOptions.All_DATA_SOURCES) === null || _serverOptions === void 0 ? void 0 : _serverOptions.ResourceDataSource;
808
+ if (!ResourceDataSourceClass) return;
809
+ this.resourceDataSource = new ResourceDataSourceClass();
810
+ }
811
+ }, {
812
+ key: "setupResourceSync",
813
+ value: function () {
814
+ var _setupResourceSync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
815
+ var _this13 = this,
816
+ _result$data;
817
+ var result, _result$data2;
818
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
819
+ while (1) switch (_context10.prev = _context10.next) {
820
+ case 0:
821
+ if (this.resourceDataSource) {
822
+ _context10.next = 2;
823
+ break;
824
+ }
825
+ return _context10.abrupt("return");
826
+ case 2:
827
+ _context10.next = 4;
828
+ return this.resourceDataSource.run({
829
+ pubsub: {
830
+ callback: function callback(res) {
831
+ var data = (res === null || res === void 0 ? void 0 : res.data) || res;
832
+ if (!data) return;
833
+ var channelKey = data.module || 'resource';
834
+ _this13.pendingSyncMessages.push(_objectSpread(_objectSpread({}, data), {}, {
835
+ _channelKey: channelKey
836
+ }));
837
+ if (_this13.syncTimer) clearTimeout(_this13.syncTimer);
838
+ _this13.syncTimer = setTimeout(function () {
839
+ _this13.processSyncMessages();
840
+ }, RESOURCE_SYNC_DEBOUNCE_MS);
841
+ }
842
+ }
843
+ }).catch(function () {
844
+ // 忽略同步初始化异常
845
+ });
846
+ case 4:
847
+ result = _context10.sent;
848
+ console.log('result', result);
849
+ if (!(result !== null && result !== void 0 && (_result$data = result.data) !== null && _result$data !== void 0 && (_result$data = _result$data.list) !== null && _result$data !== void 0 && _result$data.length)) {
850
+ _context10.next = 9;
851
+ break;
852
+ }
853
+ _context10.next = 9;
854
+ return this.mergeResourcesToStore(result === null || result === void 0 || (_result$data2 = result.data) === null || _result$data2 === void 0 ? void 0 : _result$data2.list);
855
+ case 9:
856
+ case "end":
857
+ return _context10.stop();
858
+ }
859
+ }, _callee10, this);
860
+ }));
861
+ function setupResourceSync() {
862
+ return _setupResourceSync.apply(this, arguments);
863
+ }
864
+ return setupResourceSync;
865
+ }()
866
+ }, {
867
+ key: "processSyncMessages",
868
+ value: function () {
869
+ var _processSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
870
+ var messages, deleteIds, bodyUpdates, sseRefreshIds, _iterator3, _step3, _msg$ids2, _msg$relation_resourc, msg, _msg$ids, _msg$body$id, bodyId, uniqueDeleteIds, uniqueSSEIds, bodyList, freshResources;
871
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
872
+ while (1) switch (_context11.prev = _context11.next) {
873
+ case 0:
874
+ messages = _toConsumableArray(this.pendingSyncMessages);
875
+ this.pendingSyncMessages = [];
876
+ if (!(messages.length === 0)) {
877
+ _context11.next = 4;
878
+ break;
879
+ }
880
+ return _context11.abrupt("return");
881
+ case 4:
882
+ deleteIds = [];
883
+ bodyUpdates = new Map();
884
+ sseRefreshIds = [];
885
+ _iterator3 = _createForOfIteratorHelper(messages);
886
+ _context11.prev = 8;
887
+ _iterator3.s();
888
+ case 10:
889
+ if ((_step3 = _iterator3.n()).done) {
890
+ _context11.next = 24;
891
+ break;
892
+ }
893
+ msg = _step3.value;
894
+ if (!(msg.operation === 'delete' || msg.action === 'delete')) {
895
+ _context11.next = 15;
896
+ break;
897
+ }
898
+ if ((_msg$ids = msg.ids) !== null && _msg$ids !== void 0 && _msg$ids.length) deleteIds.push.apply(deleteIds, _toConsumableArray(msg.ids));else if (msg.id !== undefined) deleteIds.push(msg.id);
899
+ return _context11.abrupt("continue", 22);
900
+ case 15:
901
+ if (!msg.body) {
902
+ _context11.next = 21;
903
+ break;
904
+ }
905
+ bodyId = (_msg$body$id = msg.body.id) !== null && _msg$body$id !== void 0 ? _msg$body$id : msg.id;
906
+ if (!(bodyId === undefined)) {
907
+ _context11.next = 19;
908
+ break;
909
+ }
910
+ return _context11.abrupt("continue", 22);
911
+ case 19:
912
+ bodyUpdates.set(this.getIdKey(bodyId), _objectSpread(_objectSpread({}, msg.body), {}, {
913
+ id: bodyId
914
+ }));
915
+ return _context11.abrupt("continue", 22);
916
+ case 21:
917
+ if ((_msg$ids2 = msg.ids) !== null && _msg$ids2 !== void 0 && _msg$ids2.length) {
918
+ sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.ids));
919
+ } else if (msg.id !== undefined) {
920
+ sseRefreshIds.push(msg.id);
921
+ } else if ((_msg$relation_resourc = msg.relation_resource_ids) !== null && _msg$relation_resourc !== void 0 && _msg$relation_resourc.length) {
922
+ sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.relation_resource_ids));
923
+ }
924
+ case 22:
925
+ _context11.next = 10;
926
+ break;
927
+ case 24:
928
+ _context11.next = 29;
929
+ break;
930
+ case 26:
931
+ _context11.prev = 26;
932
+ _context11.t0 = _context11["catch"](8);
933
+ _iterator3.e(_context11.t0);
934
+ case 29:
935
+ _context11.prev = 29;
936
+ _iterator3.f();
937
+ return _context11.finish(29);
938
+ case 32:
939
+ uniqueDeleteIds = this.uniqueResourceIds(deleteIds);
940
+ uniqueSSEIds = this.uniqueResourceIds(sseRefreshIds);
941
+ bodyList = _toConsumableArray(bodyUpdates.values());
942
+ if (!(uniqueDeleteIds.length > 0)) {
943
+ _context11.next = 38;
944
+ break;
945
+ }
946
+ _context11.next = 38;
947
+ return this.removeResourcesByIds(uniqueDeleteIds);
948
+ case 38:
949
+ if (!(bodyList.length > 0)) {
950
+ _context11.next = 41;
951
+ break;
952
+ }
953
+ _context11.next = 41;
954
+ return this.mergeResourcesToStore(bodyList);
955
+ case 41:
956
+ if (!(uniqueSSEIds.length > 0)) {
957
+ _context11.next = 48;
958
+ break;
959
+ }
960
+ _context11.next = 44;
961
+ return this.fetchResourcesBySSE(uniqueSSEIds);
962
+ case 44:
963
+ freshResources = _context11.sent;
964
+ if (!(freshResources.length > 0)) {
965
+ _context11.next = 48;
966
+ break;
967
+ }
968
+ _context11.next = 48;
969
+ return this.mergeResourcesToStore(freshResources);
970
+ case 48:
971
+ if (!(uniqueDeleteIds.length === 0 && bodyList.length === 0 && uniqueSSEIds.length === 0)) {
972
+ _context11.next = 50;
973
+ break;
974
+ }
975
+ return _context11.abrupt("return");
976
+ case 50:
977
+ _context11.next = 52;
978
+ return this.core.effects.emit(ResourceHooks.onResourcesSyncCompleted, null);
979
+ case 52:
980
+ case "end":
981
+ return _context11.stop();
982
+ }
983
+ }, _callee11, this, [[8, 26, 29, 32]]);
984
+ }));
985
+ function processSyncMessages() {
986
+ return _processSyncMessages.apply(this, arguments);
987
+ }
988
+ return processSyncMessages;
989
+ }()
990
+ }, {
991
+ key: "fetchResourcesBySSE",
992
+ value: function () {
993
+ var _fetchResourcesBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(ids) {
994
+ var list;
995
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
996
+ while (1) switch (_context12.prev = _context12.next) {
997
+ case 0:
998
+ if (this.resourceDataSource) {
999
+ _context12.next = 2;
1000
+ break;
1001
+ }
1002
+ return _context12.abrupt("return", []);
1003
+ case 2:
1004
+ _context12.prev = 2;
1005
+ _context12.next = 5;
1006
+ return this.resourceDataSource.run({
1007
+ sse: {
1008
+ query: {
1009
+ type: 'resource',
1010
+ ids: ids
1011
+ }
1012
+ }
1013
+ });
1014
+ case 5:
1015
+ list = _context12.sent;
1016
+ return _context12.abrupt("return", list || []);
1017
+ case 9:
1018
+ _context12.prev = 9;
1019
+ _context12.t0 = _context12["catch"](2);
1020
+ return _context12.abrupt("return", []);
1021
+ case 12:
1022
+ case "end":
1023
+ return _context12.stop();
1024
+ }
1025
+ }, _callee12, this, [[2, 9]]);
1026
+ }));
1027
+ function fetchResourcesBySSE(_x7) {
1028
+ return _fetchResourcesBySSE.apply(this, arguments);
1029
+ }
1030
+ return fetchResourcesBySSE;
1031
+ }()
1032
+ }, {
1033
+ key: "removeResourcesByIds",
1034
+ value: function () {
1035
+ var _removeResourcesByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(ids) {
1036
+ var _this14 = this;
1037
+ var keySet, _iterator4, _step4, id;
1038
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1039
+ while (1) switch (_context13.prev = _context13.next) {
1040
+ case 0:
1041
+ keySet = new Set(ids.map(function (id) {
1042
+ return _this14.getIdKey(id);
1043
+ }));
1044
+ this.store.list = this.store.list.filter(function (r) {
1045
+ return !keySet.has(_this14.getIdKey(r.id));
1046
+ });
1047
+ this.syncResourcesMap();
1048
+ if (!this.dbManager) {
1049
+ _context13.next = 26;
1050
+ break;
1051
+ }
1052
+ _context13.prev = 4;
1053
+ _iterator4 = _createForOfIteratorHelper(ids);
1054
+ _context13.prev = 6;
1055
+ _iterator4.s();
1056
+ case 8:
1057
+ if ((_step4 = _iterator4.n()).done) {
1058
+ _context13.next = 14;
1059
+ break;
1060
+ }
1061
+ id = _step4.value;
1062
+ _context13.next = 12;
1063
+ return this.dbManager.delete(RESOURCE_STORE_NAME, id);
1064
+ case 12:
1065
+ _context13.next = 8;
1066
+ break;
1067
+ case 14:
1068
+ _context13.next = 19;
1069
+ break;
1070
+ case 16:
1071
+ _context13.prev = 16;
1072
+ _context13.t0 = _context13["catch"](6);
1073
+ _iterator4.e(_context13.t0);
1074
+ case 19:
1075
+ _context13.prev = 19;
1076
+ _iterator4.f();
1077
+ return _context13.finish(19);
1078
+ case 22:
1079
+ _context13.next = 26;
1080
+ break;
1081
+ case 24:
1082
+ _context13.prev = 24;
1083
+ _context13.t1 = _context13["catch"](4);
1084
+ case 26:
1085
+ _context13.next = 28;
1086
+ return this.safeEmit(ResourceHooks.onResourcesChanged, this.store.list);
1087
+ case 28:
1088
+ case "end":
1089
+ return _context13.stop();
1090
+ }
1091
+ }, _callee13, this, [[4, 24], [6, 16, 19, 22]]);
1092
+ }));
1093
+ function removeResourcesByIds(_x8) {
1094
+ return _removeResourcesByIds.apply(this, arguments);
1095
+ }
1096
+ return removeResourcesByIds;
1097
+ }()
1098
+ }, {
1099
+ key: "mergeResourcesToStore",
1100
+ value: function () {
1101
+ var _mergeResourcesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(freshResources) {
1102
+ var _this15 = this;
1103
+ var freshMap, _iterator5, _step5, r, updatedList, _iterator6, _step6, _r;
1104
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1105
+ while (1) switch (_context14.prev = _context14.next) {
1106
+ case 0:
1107
+ freshMap = new Map();
1108
+ _iterator5 = _createForOfIteratorHelper(freshResources);
1109
+ _context14.prev = 2;
1110
+ _iterator5.s();
1111
+ case 4:
1112
+ if ((_step5 = _iterator5.n()).done) {
1113
+ _context14.next = 11;
1114
+ break;
1115
+ }
1116
+ r = _step5.value;
1117
+ if (!((r === null || r === void 0 ? void 0 : r.id) === undefined)) {
1118
+ _context14.next = 8;
1119
+ break;
1120
+ }
1121
+ return _context14.abrupt("continue", 9);
1122
+ case 8:
1123
+ freshMap.set(this.getIdKey(r.id), this.normalizeResource(r));
1124
+ case 9:
1125
+ _context14.next = 4;
1126
+ break;
1127
+ case 11:
1128
+ _context14.next = 16;
1129
+ break;
1130
+ case 13:
1131
+ _context14.prev = 13;
1132
+ _context14.t0 = _context14["catch"](2);
1133
+ _iterator5.e(_context14.t0);
1134
+ case 16:
1135
+ _context14.prev = 16;
1136
+ _iterator5.f();
1137
+ return _context14.finish(16);
1138
+ case 19:
1139
+ updatedList = this.store.list.map(function (r) {
1140
+ var key = _this15.getIdKey(r.id);
1141
+ if (!freshMap.has(key)) return r;
1142
+ var fresh = freshMap.get(key);
1143
+ freshMap.delete(key);
1144
+ return fresh;
1145
+ });
1146
+ _iterator6 = _createForOfIteratorHelper(freshMap.values());
1147
+ try {
1148
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1149
+ _r = _step6.value;
1150
+ updatedList.push(_r);
1151
+ }
1152
+ } catch (err) {
1153
+ _iterator6.e(err);
1154
+ } finally {
1155
+ _iterator6.f();
1156
+ }
1157
+ this.store.list = updatedList;
1158
+ this.syncResourcesMap();
1159
+ _context14.next = 26;
1160
+ return this.saveResourcesToSQLite(this.store.list);
1161
+ case 26:
1162
+ _context14.next = 28;
1163
+ return this.safeEmit(ResourceHooks.onResourcesChanged, this.store.list);
1164
+ case 28:
1165
+ case "end":
1166
+ return _context14.stop();
1167
+ }
1168
+ }, _callee14, this, [[2, 13, 16, 19]]);
1169
+ }));
1170
+ function mergeResourcesToStore(_x9) {
1171
+ return _mergeResourcesToStore.apply(this, arguments);
1172
+ }
1173
+ return mergeResourcesToStore;
1174
+ }()
1175
+ }, {
1176
+ key: "uniqueResourceIds",
1177
+ value: function uniqueResourceIds(ids) {
1178
+ var idMap = new Map();
1179
+ var _iterator7 = _createForOfIteratorHelper(ids),
1180
+ _step7;
1181
+ try {
1182
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1183
+ var id = _step7.value;
1184
+ idMap.set(this.getIdKey(id), id);
1185
+ }
1186
+ } catch (err) {
1187
+ _iterator7.e(err);
1188
+ } finally {
1189
+ _iterator7.f();
1190
+ }
1191
+ return _toConsumableArray(idMap.values());
1192
+ }
1193
+ }]);
1194
+ return ResourceModule;
1195
+ }(BaseModule);
1196
+
1197
+ // ─────────────────────────────────────────────────────────────────
1198
+ // 导出
1199
+ // ─────────────────────────────────────────────────────────────────
1200
+
1201
+ export var resourceModule = new ResourceModule();
1202
+ export { ResourceHooks } from "./types";