@pisell/pisellos 0.0.567 → 0.0.568

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 (228) hide show
  1. package/dist/core/index.js +6 -9
  2. package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -2
  3. package/dist/model/strategy/adapter/walletPass/example.js +3 -26
  4. package/dist/model/strategy/adapter/walletPass/utils.js +0 -3
  5. package/dist/model/strategy/strategy-example.js +5 -19
  6. package/dist/modules/Cart/index.js +0 -3
  7. package/dist/modules/Cart/utils/cartProduct.js +0 -1
  8. package/dist/modules/Date/index.js +1 -5
  9. package/dist/modules/Discount/index.js +1 -4
  10. package/dist/modules/OpenData/index.js +0 -2
  11. package/dist/modules/Order/index.d.ts +1 -1
  12. package/dist/modules/Order/index.js +14 -41
  13. package/dist/modules/Payment/index.js +142 -270
  14. package/dist/modules/Payment/walletpass.js +4 -5
  15. package/dist/modules/Rules/index.js +0 -7
  16. package/dist/modules/Schedule/utils.js +0 -1
  17. package/dist/modules/Step/index.js +0 -1
  18. package/dist/plugins/request.js +1 -4
  19. package/dist/plugins/window.js +2 -6
  20. package/dist/server/index.js +88 -121
  21. package/dist/server/modules/menu/index.js +32 -41
  22. package/dist/server/modules/products/index.js +29 -49
  23. package/dist/server/modules/quotation/index.js +29 -38
  24. package/dist/server/modules/resource/index.js +3 -4
  25. package/dist/server/modules/schedule/index.js +32 -40
  26. package/dist/server/utils/product.js +0 -1
  27. package/dist/solution/BookingByStep/index.d.ts +1 -1
  28. package/dist/solution/BookingByStep/index.js +7 -59
  29. package/dist/solution/BookingByStep/utils/capacity.js +1 -11
  30. package/dist/solution/BookingByStep/utils/resources.js +1 -3
  31. package/dist/solution/BookingByStep/utils/timeslots.js +2 -43
  32. package/dist/solution/BookingTicket/index.d.ts +1 -1
  33. package/dist/solution/BookingTicket/index.js +5 -7
  34. package/dist/solution/BookingTicket/utils/scan/handleScan.js +25 -31
  35. package/dist/solution/BookingTicket/utils/scan/index.js +6 -10
  36. package/dist/solution/BuyTickets/index.js +9 -12
  37. package/dist/solution/Checkout/index.js +177 -246
  38. package/dist/solution/Checkout/utils/index.js +4 -16
  39. package/dist/solution/RegisterAndLogin/index.js +30 -76
  40. package/dist/solution/ScanOrder/index.js +50 -60
  41. package/dist/solution/ShopDiscount/index.js +2 -7
  42. package/dist/solution/VenueBooking/index.d.ts +5 -0
  43. package/dist/solution/VenueBooking/index.js +364 -327
  44. package/dist/utils/task.js +15 -18
  45. package/dist/utils/watch.js +0 -1
  46. package/lib/apis/picoding.js +2 -0
  47. package/lib/core/index.js +130 -131
  48. package/lib/effects/index.js +46 -57
  49. package/lib/index.js +92 -53
  50. package/lib/model/index.js +14 -21
  51. package/lib/model/strategy/adapter/dataVariant/adapter.js +38 -50
  52. package/lib/model/strategy/adapter/dataVariant/evaluator.js +162 -236
  53. package/lib/model/strategy/adapter/dataVariant/examples.js +229 -237
  54. package/lib/model/strategy/adapter/dataVariant/index.js +39 -34
  55. package/lib/model/strategy/adapter/dataVariant/type.js +57 -28
  56. package/lib/model/strategy/adapter/index.js +100 -64
  57. package/lib/model/strategy/adapter/itemRule/adapter.js +156 -144
  58. package/lib/model/strategy/adapter/itemRule/evaluator.js +36 -48
  59. package/lib/model/strategy/adapter/itemRule/examples.js +295 -225
  60. package/lib/model/strategy/adapter/itemRule/index.js +83 -57
  61. package/lib/model/strategy/adapter/itemRule/type.js +97 -36
  62. package/lib/model/strategy/adapter/promotion/adapter.js +84 -63
  63. package/lib/model/strategy/adapter/promotion/evaluator.js +381 -231
  64. package/lib/model/strategy/adapter/promotion/examples.js +139 -159
  65. package/lib/model/strategy/adapter/promotion/index.js +1 -49
  66. package/lib/model/strategy/adapter/promotion/type.js +199 -35
  67. package/lib/model/strategy/adapter/type.js +4 -16
  68. package/lib/model/strategy/adapter/walletPass/evaluator.js +180 -152
  69. package/lib/model/strategy/adapter/walletPass/example.js +217 -190
  70. package/lib/model/strategy/adapter/walletPass/index.js +75 -51
  71. package/lib/model/strategy/adapter/walletPass/locales.js +36 -58
  72. package/lib/model/strategy/adapter/walletPass/type.js +4 -16
  73. package/lib/model/strategy/adapter/walletPass/utils.js +652 -402
  74. package/lib/model/strategy/engine.js +270 -168
  75. package/lib/model/strategy/index.js +49 -34
  76. package/lib/model/strategy/strategy-example.js +243 -239
  77. package/lib/model/strategy/type.js +100 -40
  78. package/lib/modules/Account/index.js +39 -53
  79. package/lib/modules/Account/types.js +20 -33
  80. package/lib/modules/AccountList/index.js +116 -154
  81. package/lib/modules/AccountList/types.js +30 -31
  82. package/lib/modules/AccountList/utils.js +18 -30
  83. package/lib/modules/BaseModule.js +22 -45
  84. package/lib/modules/Cart/index.js +170 -124
  85. package/lib/modules/Cart/types.js +46 -51
  86. package/lib/modules/Cart/utils/cartAccount.js +40 -39
  87. package/lib/modules/Cart/utils/cartDate.js +56 -61
  88. package/lib/modules/Cart/utils/cartDiscount.js +28 -33
  89. package/lib/modules/Cart/utils/cartNote.js +27 -32
  90. package/lib/modules/Cart/utils/cartProduct.js +306 -241
  91. package/lib/modules/Cart/utils/cartRelationForms.js +29 -35
  92. package/lib/modules/Cart/utils/cartResource.js +72 -78
  93. package/lib/modules/Cart/utils/changePrice.js +26 -62
  94. package/lib/modules/Cart/utils/index.js +106 -48
  95. package/lib/modules/Customer/constants.js +13 -34
  96. package/lib/modules/Customer/index.js +216 -153
  97. package/lib/modules/Customer/types.js +38 -35
  98. package/lib/modules/Date/index.js +116 -115
  99. package/lib/modules/Date/types.js +16 -28
  100. package/lib/modules/Date/utils.js +174 -123
  101. package/lib/modules/Discount/index.js +117 -113
  102. package/lib/modules/Discount/types.js +9 -31
  103. package/lib/modules/Guests/index.js +30 -56
  104. package/lib/modules/Guests/types.js +23 -33
  105. package/lib/modules/Holder/index.js +209 -189
  106. package/lib/modules/Holder/types.js +4 -16
  107. package/lib/modules/Holder/utils.js +20 -49
  108. package/lib/modules/OpenData/index.js +63 -74
  109. package/lib/modules/OpenData/types.js +4 -16
  110. package/lib/modules/OpenData/utils.js +44 -78
  111. package/lib/modules/Order/index.d.ts +1 -1
  112. package/lib/modules/Order/index.js +332 -320
  113. package/lib/modules/Order/types.js +24 -33
  114. package/lib/modules/Order/utils.js +350 -284
  115. package/lib/modules/Payment/cash.js +20 -33
  116. package/lib/modules/Payment/cashRecommendationAlgorithm.js +145 -76
  117. package/lib/modules/Payment/eftpos.js +16 -30
  118. package/lib/modules/Payment/index.js +566 -432
  119. package/lib/modules/Payment/mx51.js +1 -0
  120. package/lib/modules/Payment/types.js +216 -107
  121. package/lib/modules/Payment/utils.js +50 -47
  122. package/lib/modules/Payment/walletpass.js +221 -203
  123. package/lib/modules/Product/index.js +51 -46
  124. package/lib/modules/Product/types.js +4 -16
  125. package/lib/modules/Product/utils.js +32 -33
  126. package/lib/modules/ProductList/index.js +111 -110
  127. package/lib/modules/ProductList/types.js +9 -31
  128. package/lib/modules/Quotation/index.js +60 -82
  129. package/lib/modules/Quotation/types.js +4 -16
  130. package/lib/modules/Resource/index.js +27 -59
  131. package/lib/modules/Resource/types.js +22 -32
  132. package/lib/modules/Resource/utils.js +30 -38
  133. package/lib/modules/Rules/index.js +1172 -872
  134. package/lib/modules/Rules/types.js +17 -40
  135. package/lib/modules/SalesSummary/index.js +59 -68
  136. package/lib/modules/SalesSummary/types.js +4 -16
  137. package/lib/modules/SalesSummary/utils.js +176 -193
  138. package/lib/modules/ScanOrderLogger/index.js +59 -79
  139. package/lib/modules/ScanOrderLogger/providers/feishu.js +54 -78
  140. package/lib/modules/ScanOrderLogger/providers/grafana.js +13 -36
  141. package/lib/modules/ScanOrderLogger/types.js +4 -16
  142. package/lib/modules/Schedule/getDateIsInSchedule.js +334 -167
  143. package/lib/modules/Schedule/index.js +97 -107
  144. package/lib/modules/Schedule/type.js +4 -16
  145. package/lib/modules/Schedule/types.js +4 -16
  146. package/lib/modules/Schedule/utils.js +433 -291
  147. package/lib/modules/Step/index.js +40 -52
  148. package/lib/modules/Step/tyeps.js +4 -16
  149. package/lib/modules/Summary/index.js +66 -70
  150. package/lib/modules/Summary/types.js +4 -16
  151. package/lib/modules/Summary/utils.js +782 -429
  152. package/lib/modules/index.js +212 -57
  153. package/lib/plugins/app.js +4 -16
  154. package/lib/plugins/index.js +36 -25
  155. package/lib/plugins/request.js +137 -126
  156. package/lib/plugins/shopStore.js +4 -16
  157. package/lib/plugins/user.js +4 -16
  158. package/lib/plugins/window.js +171 -179
  159. package/lib/server/index.js +882 -623
  160. package/lib/server/modules/index.js +85 -59
  161. package/lib/server/modules/menu/index.js +146 -122
  162. package/lib/server/modules/menu/types.js +18 -31
  163. package/lib/server/modules/order/index.js +195 -231
  164. package/lib/server/modules/order/types.js +107 -32
  165. package/lib/server/modules/order/utils/filterBookings.js +174 -140
  166. package/lib/server/modules/order/utils/filterOrders.js +89 -60
  167. package/lib/server/modules/products/index.js +430 -335
  168. package/lib/server/modules/products/types.js +41 -34
  169. package/lib/server/modules/quotation/index.js +76 -77
  170. package/lib/server/modules/quotation/types.js +21 -31
  171. package/lib/server/modules/resource/index.js +216 -187
  172. package/lib/server/modules/resource/types.js +42 -33
  173. package/lib/server/modules/schedule/index.js +134 -119
  174. package/lib/server/modules/schedule/types.js +14 -21
  175. package/lib/server/modules/schedule/utils.js +334 -163
  176. package/lib/server/types.js +4 -16
  177. package/lib/server/utils/index.js +25 -23
  178. package/lib/server/utils/product.js +196 -139
  179. package/lib/server/utils/schedule.js +34 -41
  180. package/lib/server/utils/time.js +40 -49
  181. package/lib/solution/BookingByStep/index.d.ts +1 -1
  182. package/lib/solution/BookingByStep/index.js +1530 -1343
  183. package/lib/solution/BookingByStep/types.js +40 -99
  184. package/lib/solution/BookingByStep/utils/capacity.js +192 -160
  185. package/lib/solution/BookingByStep/utils/products.js +42 -52
  186. package/lib/solution/BookingByStep/utils/resources.js +527 -330
  187. package/lib/solution/BookingByStep/utils/stock.js +65 -44
  188. package/lib/solution/BookingByStep/utils/timeslots.js +129 -131
  189. package/lib/solution/BookingTicket/index.d.ts +1 -1
  190. package/lib/solution/BookingTicket/index.js +147 -122
  191. package/lib/solution/BookingTicket/types.js +38 -64
  192. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +64 -80
  193. package/lib/solution/BookingTicket/utils/scan/handleScan.js +82 -80
  194. package/lib/solution/BookingTicket/utils/scan/index.js +90 -94
  195. package/lib/solution/BookingTicket/utils/scan/scanCache.js +90 -43
  196. package/lib/solution/BuyTickets/index.js +67 -70
  197. package/lib/solution/BuyTickets/types.js +22 -38
  198. package/lib/solution/Checkout/index.js +1451 -1158
  199. package/lib/solution/Checkout/types.js +91 -61
  200. package/lib/solution/Checkout/utils/index.js +227 -158
  201. package/lib/solution/PlaceOrder/index.js +55 -0
  202. package/lib/solution/RegisterAndLogin/config.js +493 -460
  203. package/lib/solution/RegisterAndLogin/index.js +633 -630
  204. package/lib/solution/RegisterAndLogin/types.js +189 -76
  205. package/lib/solution/RegisterAndLogin/utils.js +183 -125
  206. package/lib/solution/Sales/index.js +218 -200
  207. package/lib/solution/Sales/types.js +27 -33
  208. package/lib/solution/ScanOrder/index.js +803 -840
  209. package/lib/solution/ScanOrder/types.js +34 -34
  210. package/lib/solution/ScanOrder/utils.js +372 -331
  211. package/lib/solution/ShopDiscount/index.js +230 -236
  212. package/lib/solution/ShopDiscount/types.js +15 -37
  213. package/lib/solution/ShopDiscount/utils.js +309 -172
  214. package/lib/solution/VenueBooking/index.d.ts +5 -0
  215. package/lib/solution/VenueBooking/index.js +886 -929
  216. package/lib/solution/VenueBooking/types.js +20 -40
  217. package/lib/solution/VenueBooking/utils/dateSummary.js +22 -54
  218. package/lib/solution/VenueBooking/utils/resource.js +31 -54
  219. package/lib/solution/VenueBooking/utils/slotMerge.js +88 -106
  220. package/lib/solution/VenueBooking/utils/smartPricing.js +112 -100
  221. package/lib/solution/VenueBooking/utils/timeSlot.js +133 -132
  222. package/lib/solution/VenueBooking/utils.js +130 -67
  223. package/lib/solution/index.js +102 -37
  224. package/lib/store/createStore.js +32 -29
  225. package/lib/types/index.js +4 -16
  226. package/lib/utils/task.js +36 -36
  227. package/lib/utils/watch.js +81 -47
  228. package/package.json +2 -1
@@ -1,67 +1,74 @@
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/server/modules/resource/index.ts
20
- var resource_exports = {};
21
- __export(resource_exports, {
22
- ResourceHooks: () => import_types2.ResourceHooks,
23
- ResourceModule: () => ResourceModule,
24
- resourceModule: () => resourceModule
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "ResourceHooks", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _types.ResourceHooks;
10
+ }
25
11
  });
26
- module.exports = __toCommonJS(resource_exports);
27
- var import_lodash_es = require("lodash-es");
28
- var import_BaseModule = require("../../../modules/BaseModule");
29
- var import_types = require("./types");
30
- var import_types2 = require("./types");
31
- var RESOURCE_STORE_NAME = "resources";
32
- var DEFAULT_PAGE_SIZE = 999;
33
- var RESOURCE_SYNC_DEBOUNCE_MS = 1e4;
34
- var ResourceModule = class extends import_BaseModule.BaseModule {
12
+ exports.resourceModule = exports.ResourceModule = void 0;
13
+ var _lodashEs = require("lodash-es");
14
+ var _BaseModule = require("../../../modules/BaseModule");
15
+ var _types = require("./types");
16
+ /**
17
+ * SQLite 存储名称
18
+ */
19
+ const RESOURCE_STORE_NAME = 'resources';
20
+ // const BOOKING_STORE_NAME = 'resource_bookings'
21
+
22
+ /**
23
+ * 默认分页大小
24
+ */
25
+ const DEFAULT_PAGE_SIZE = 999;
26
+
27
+ /**
28
+ * 同步防抖超时(毫秒)
29
+ */
30
+ const RESOURCE_SYNC_DEBOUNCE_MS = 10_000;
31
+
32
+ /**
33
+ * Resource 模块
34
+ */
35
+ class ResourceModule extends _BaseModule.BaseModule {
36
+ defaultName = 'resource';
37
+ defaultVersion = '1.0.0';
38
+ store;
39
+ dbManager;
40
+ logger; // LoggerManager 实例
41
+ resourceDataSource;
42
+
43
+ /** 倒排索引: resourceId -> ResourceBooking[] */
44
+ resourceIdIndex = new Map();
45
+
46
+ /** 待处理的同步消息队列 */
47
+ pendingSyncMessages = [];
48
+ syncTimer;
35
49
  constructor(name, version) {
36
50
  super(name, version);
37
- this.defaultName = "resource";
38
- this.defaultVersion = "1.0.0";
39
- /** 倒排索引: resourceId -> ResourceBooking[] */
40
- this.resourceIdIndex = /* @__PURE__ */ new Map();
41
- /** 待处理的同步消息队列 */
42
- this.pendingSyncMessages = [];
43
51
  }
52
+
44
53
  // ─────────────────────────────────────────────────────────────────
45
54
  // 初始化 & 生命周期
46
55
  // ─────────────────────────────────────────────────────────────────
56
+
47
57
  async initialize(core, options) {
48
- var _a, _b;
49
58
  this.core = core;
50
- this.store = options == null ? void 0 : options.store;
51
- if (Array.isArray((_a = options == null ? void 0 : options.initialState) == null ? void 0 : _a.list)) {
52
- this.store.list = ((_b = options == null ? void 0 : options.initialState) == null ? void 0 : _b.list).map(
53
- (item) => this.normalizeResource(item)
54
- );
59
+ this.store = options?.store;
60
+ if (Array.isArray(options?.initialState?.list)) {
61
+ this.store.list = (options?.initialState?.list).map(item => this.normalizeResource(item));
55
62
  this.syncResourcesMap();
56
- this.core.effects.emit(import_types.ResourceHooks.onResourcesChanged, this.store.list);
63
+ this.core.effects.emit(_types.ResourceHooks.onResourcesChanged, this.store.list);
57
64
  } else {
58
65
  this.store.list = [];
59
- this.store.map = /* @__PURE__ */ new Map();
66
+ this.store.map = new Map();
60
67
  }
61
68
  if (!Array.isArray(this.store.bookings)) {
62
69
  this.store.bookings = [];
63
70
  }
64
- const appPlugin = core.getPlugin("app");
71
+ const appPlugin = core.getPlugin('app');
65
72
  if (appPlugin) {
66
73
  const app = appPlugin.getApp();
67
74
  this.dbManager = app.sqlite || app.dbManager;
@@ -73,7 +80,7 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
73
80
  logInfo(title, metadata) {
74
81
  if (this.logger) {
75
82
  this.logger.addLog({
76
- type: "info",
83
+ type: 'info',
77
84
  title: `[ResourceModule] ${title}`,
78
85
  metadata: metadata || {}
79
86
  });
@@ -82,7 +89,7 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
82
89
  logError(title, error, metadata) {
83
90
  if (this.logger) {
84
91
  this.logger.addLog({
85
- type: "error",
92
+ type: 'error',
86
93
  title: `[ResourceModule] ${title}`,
87
94
  metadata: metadata || {}
88
95
  });
@@ -91,156 +98,179 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
91
98
  async preload() {
92
99
  const cachedResources = await this.loadResourcesFromSQLite();
93
100
  if (cachedResources.length > 0) {
94
- this.store.list = (0, import_lodash_es.cloneDeep)(cachedResources).map((item) => this.normalizeResource(item));
101
+ this.store.list = (0, _lodashEs.cloneDeep)(cachedResources).map(item => this.normalizeResource(item));
95
102
  this.syncResourcesMap();
96
- await this.safeEmit(import_types.ResourceHooks.onResourcesChanged, this.store.list);
103
+ await this.safeEmit(_types.ResourceHooks.onResourcesChanged, this.store.list);
97
104
  } else {
98
105
  const resources = await this.loadResourcesByServer();
99
106
  if (resources.length > 0) {
100
- this.store.list = (0, import_lodash_es.cloneDeep)(resources).map((item) => this.normalizeResource(item));
107
+ this.store.list = (0, _lodashEs.cloneDeep)(resources).map(item => this.normalizeResource(item));
101
108
  this.syncResourcesMap();
102
- await this.safeEmit(import_types.ResourceHooks.onResourcesChanged, this.store.list);
109
+ await this.safeEmit(_types.ResourceHooks.onResourcesChanged, this.store.list);
103
110
  }
104
111
  }
112
+
113
+ // const cachedBookings = await this.loadBookingsFromSQLite()
114
+ // if (cachedBookings.length > 0) {
115
+ // this.store.bookings = cloneDeep(cachedBookings)
116
+ // this.syncBookingsIndex()
117
+ // }
105
118
  }
106
119
  getRoutes() {
107
120
  return [];
108
121
  }
109
122
  destroy() {
110
- var _a;
111
123
  if (this.syncTimer) {
112
124
  clearTimeout(this.syncTimer);
113
- this.syncTimer = void 0;
125
+ this.syncTimer = undefined;
114
126
  }
115
127
  this.pendingSyncMessages = [];
116
- if ((_a = this.resourceDataSource) == null ? void 0 : _a.destroy)
117
- this.resourceDataSource.destroy();
128
+ if (this.resourceDataSource?.destroy) this.resourceDataSource.destroy();
118
129
  super.destroy();
119
130
  }
131
+
120
132
  // ─────────────────────────────────────────────────────────────────
121
133
  // Resource CRUD
122
134
  // ─────────────────────────────────────────────────────────────────
135
+
123
136
  /**
124
137
  * 获取所有资源(支持 includeBookings 附加预订信息)
125
138
  */
126
139
  getResources(queryOptions) {
127
- this.logInfo("getResources", {
140
+ this.logInfo('getResources', {
128
141
  queryOptions
129
142
  });
130
- if (!(queryOptions == null ? void 0 : queryOptions.includeBookings)) {
143
+ if (!queryOptions?.includeBookings) {
131
144
  return this.store.list;
132
145
  }
133
- return this.store.list.map((resource) => this.attachBookingsToResource(resource));
146
+ return this.store.list.map(resource => this.attachBookingsToResource(resource));
134
147
  }
148
+
135
149
  /**
136
150
  * 根据 ID 获取单个资源
137
151
  */
138
152
  getResourceById(id, queryOptions) {
139
153
  const resource = this.store.map.get(id);
140
- if (!resource)
141
- return void 0;
142
- if (queryOptions == null ? void 0 : queryOptions.includeBookings) {
154
+ if (!resource) return undefined;
155
+ if (queryOptions?.includeBookings) {
143
156
  return this.attachBookingsToResource(resource);
144
157
  }
145
158
  return resource;
146
159
  }
160
+
147
161
  /**
148
162
  * 创建资源
149
163
  */
150
164
  createResource(data) {
151
- const id = (data == null ? void 0 : data.id) ?? (data == null ? void 0 : data.form_record_id) ?? Date.now();
152
- const resource = this.normalizeResource({ ...data, id });
165
+ const id = data?.id ?? data?.form_record_id ?? Date.now();
166
+ const resource = this.normalizeResource({
167
+ ...data,
168
+ id
169
+ });
153
170
  this.store.list.push(resource);
154
171
  this.store.map.set(resource.id, resource);
155
- this.saveResourcesToSQLite(this.store.list).catch(() => {
156
- });
157
- this.safeEmit(import_types.ResourceHooks.onResourcesChanged, this.store.list);
172
+ this.saveResourcesToSQLite(this.store.list).catch(() => {});
173
+ this.safeEmit(_types.ResourceHooks.onResourcesChanged, this.store.list);
158
174
  return resource;
159
175
  }
176
+
160
177
  /**
161
178
  * 更新资源
162
179
  */
163
180
  updateResource(id, data) {
164
- const index = this.store.list.findIndex((r) => this.getIdKey(r.id) === this.getIdKey(id));
165
- if (index === -1)
166
- return void 0;
167
- const updated = this.normalizeResource({ ...this.store.list[index], ...data, id });
181
+ const index = this.store.list.findIndex(r => this.getIdKey(r.id) === this.getIdKey(id));
182
+ if (index === -1) return undefined;
183
+ const updated = this.normalizeResource({
184
+ ...this.store.list[index],
185
+ ...data,
186
+ id
187
+ });
168
188
  this.store.list[index] = updated;
169
189
  this.store.map.set(updated.id, updated);
170
- this.saveResourcesToSQLite(this.store.list).catch(() => {
171
- });
172
- this.safeEmit(import_types.ResourceHooks.onResourcesChanged, this.store.list);
190
+ this.saveResourcesToSQLite(this.store.list).catch(() => {});
191
+ this.safeEmit(_types.ResourceHooks.onResourcesChanged, this.store.list);
173
192
  return updated;
174
193
  }
194
+
175
195
  /**
176
196
  * 删除资源
177
197
  */
178
198
  deleteResource(id) {
179
199
  const key = this.getIdKey(id);
180
- const index = this.store.list.findIndex((r) => this.getIdKey(r.id) === key);
181
- if (index === -1)
182
- return false;
200
+ const index = this.store.list.findIndex(r => this.getIdKey(r.id) === key);
201
+ if (index === -1) return false;
183
202
  this.store.list.splice(index, 1);
184
203
  this.store.map.delete(id);
185
- this.saveResourcesToSQLite(this.store.list).catch(() => {
186
- });
187
- this.safeEmit(import_types.ResourceHooks.onResourcesChanged, this.store.list);
204
+ this.saveResourcesToSQLite(this.store.list).catch(() => {});
205
+ this.safeEmit(_types.ResourceHooks.onResourcesChanged, this.store.list);
188
206
  return true;
189
207
  }
208
+
190
209
  // ─────────────────────────────────────────────────────────────────
191
210
  // Booking CRUD
192
211
  // ─────────────────────────────────────────────────────────────────
212
+
193
213
  /**
194
214
  * 根据资源 ID 获取预订列表
195
215
  */
196
216
  getBookingsByResourceId(resourceId) {
197
217
  return this.resourceIdIndex.get(resourceId) || [];
198
218
  }
219
+
199
220
  /**
200
221
  * 创建预订
201
222
  */
202
223
  createBooking(booking) {
203
- const id = (booking == null ? void 0 : booking.id) ?? Date.now();
224
+ const id = booking?.id ?? Date.now();
204
225
  const normalized = {
205
226
  id,
206
227
  ...booking
207
228
  };
208
229
  this.store.bookings.push(normalized);
209
230
  const rid = normalized.resource_id ?? normalized.resourceId;
210
- if (rid !== void 0) {
231
+ if (rid !== undefined) {
211
232
  const existing = this.resourceIdIndex.get(rid) || [];
212
233
  existing.push(normalized);
213
234
  this.resourceIdIndex.set(rid, existing);
214
235
  }
215
- this.safeEmit(import_types.ResourceHooks.onBookingsChanged, this.store.bookings);
236
+
237
+ // this.saveBookingsToSQLite(this.store.bookings).catch(() => {})
238
+ this.safeEmit(_types.ResourceHooks.onBookingsChanged, this.store.bookings);
216
239
  return normalized;
217
240
  }
241
+
218
242
  /**
219
243
  * 更新预订
220
244
  */
221
245
  updateBooking(id, data) {
222
- const index = this.store.bookings.findIndex((b) => this.getIdKey(b.id) === this.getIdKey(id));
223
- if (index === -1)
224
- return void 0;
246
+ const index = this.store.bookings.findIndex(b => this.getIdKey(b.id) === this.getIdKey(id));
247
+ if (index === -1) return undefined;
225
248
  const old = this.store.bookings[index];
226
- const updated = { ...old, ...data, id: old.id };
249
+ const updated = {
250
+ ...old,
251
+ ...data,
252
+ id: old.id
253
+ };
227
254
  this.store.bookings[index] = updated;
228
255
  this.rebuildBookingsIndex();
229
- this.safeEmit(import_types.ResourceHooks.onBookingsChanged, this.store.bookings);
256
+ // this.saveBookingsToSQLite(this.store.bookings).catch(() => {})
257
+ this.safeEmit(_types.ResourceHooks.onBookingsChanged, this.store.bookings);
230
258
  return updated;
231
259
  }
260
+
232
261
  /**
233
262
  * 删除预订
234
263
  */
235
264
  deleteBooking(id) {
236
- const index = this.store.bookings.findIndex((b) => this.getIdKey(b.id) === this.getIdKey(id));
237
- if (index === -1)
238
- return false;
265
+ const index = this.store.bookings.findIndex(b => this.getIdKey(b.id) === this.getIdKey(id));
266
+ if (index === -1) return false;
239
267
  this.store.bookings.splice(index, 1);
240
268
  this.rebuildBookingsIndex();
241
- this.safeEmit(import_types.ResourceHooks.onBookingsChanged, this.store.bookings);
269
+ // this.saveBookingsToSQLite(this.store.bookings).catch(() => {})
270
+ this.safeEmit(_types.ResourceHooks.onBookingsChanged, this.store.bookings);
242
271
  return true;
243
272
  }
273
+
244
274
  /**
245
275
  * 清空缓存
246
276
  */
@@ -252,15 +282,19 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
252
282
  if (this.dbManager) {
253
283
  try {
254
284
  await this.dbManager.clear(RESOURCE_STORE_NAME);
285
+ // await this.dbManager.clear(BOOKING_STORE_NAME)
255
286
  } catch {
287
+ // 清理失败不影响调用方
256
288
  }
257
289
  }
258
- await this.safeEmit(import_types.ResourceHooks.onResourcesChanged, this.store.list);
259
- await this.safeEmit(import_types.ResourceHooks.onBookingsChanged, this.store.bookings);
290
+ await this.safeEmit(_types.ResourceHooks.onResourcesChanged, this.store.list);
291
+ await this.safeEmit(_types.ResourceHooks.onBookingsChanged, this.store.bookings);
260
292
  }
293
+
261
294
  // ─────────────────────────────────────────────────────────────────
262
295
  // 内部工具方法
263
296
  // ─────────────────────────────────────────────────────────────────
297
+
264
298
  attachBookingsToResource(resource) {
265
299
  return {
266
300
  ...resource,
@@ -270,21 +304,20 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
270
304
  normalizeResource(resource) {
271
305
  const normalized = {
272
306
  ...resource,
273
- id: (resource == null ? void 0 : resource.id) ?? (resource == null ? void 0 : resource.form_record_id) ?? ""
307
+ id: resource?.id ?? resource?.form_record_id ?? ''
274
308
  };
275
- if (normalized.form_record_id === void 0 && normalized.id !== "") {
309
+ if (normalized.form_record_id === undefined && normalized.id !== '') {
276
310
  normalized.form_record_id = normalized.id;
277
311
  }
278
- if (normalized.resource_form_id === void 0 || normalized.resource_form_id === null) {
279
- normalized.resource_form_id = "";
312
+ if (normalized.resource_form_id === undefined || normalized.resource_form_id === null) {
313
+ normalized.resource_form_id = '';
280
314
  }
281
- if (normalized.schedule === void 0 || normalized.schedule === null) {
282
- normalized.schedule = "";
315
+ if (normalized.schedule === undefined || normalized.schedule === null) {
316
+ normalized.schedule = '';
283
317
  }
284
318
  if (Array.isArray(normalized.times)) {
285
- normalized.times = normalized.times.map((timeSlot) => {
286
- if (!timeSlot || typeof timeSlot !== "object")
287
- return timeSlot;
319
+ normalized.times = normalized.times.map(timeSlot => {
320
+ if (!timeSlot || typeof timeSlot !== 'object') return timeSlot;
288
321
  const startAt = timeSlot.start_at ?? timeSlot.start;
289
322
  const endAt = timeSlot.end_at ?? timeSlot.end;
290
323
  return {
@@ -297,7 +330,7 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
297
330
  });
298
331
  }
299
332
  if (Array.isArray(normalized.children)) {
300
- normalized.children = normalized.children.map((child) => this.normalizeResource(child));
333
+ normalized.children = normalized.children.map(child => this.normalizeResource(child));
301
334
  }
302
335
  return normalized;
303
336
  }
@@ -305,11 +338,12 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
305
338
  try {
306
339
  await this.core.effects.emit(event, payload);
307
340
  } catch (error) {
341
+ // 不让外部监听器异常影响资源模块预加载或清理流程
308
342
  console.error(`[ResourceModule] 事件派发失败: ${event}`, error);
309
343
  }
310
344
  }
311
345
  syncResourcesMap() {
312
- this.store.map = /* @__PURE__ */ new Map();
346
+ this.store.map = new Map();
313
347
  for (const resource of this.store.list) {
314
348
  this.store.map.set(resource.id, resource);
315
349
  }
@@ -318,8 +352,7 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
318
352
  this.resourceIdIndex.clear();
319
353
  for (const booking of this.store.bookings) {
320
354
  const rid = booking.resource_id ?? booking.resourceId;
321
- if (rid === void 0)
322
- continue;
355
+ if (rid === undefined) continue;
323
356
  const existing = this.resourceIdIndex.get(rid) || [];
324
357
  existing.push(booking);
325
358
  this.resourceIdIndex.set(rid, existing);
@@ -331,32 +364,34 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
331
364
  getIdKey(id) {
332
365
  return String(id);
333
366
  }
367
+
334
368
  // ─────────────────────────────────────────────────────────────────
335
369
  // 数据加载
336
370
  // ─────────────────────────────────────────────────────────────────
371
+
337
372
  async loadResourcesByServer() {
338
- if (!this.resourceDataSource)
339
- return [];
373
+ if (!this.resourceDataSource) return [];
340
374
  try {
341
375
  const response = await this.resourceDataSource.getResourcePage({
342
376
  num: DEFAULT_PAGE_SIZE,
343
377
  skip: 1
344
378
  });
345
- const resourceList = Array.isArray(response == null ? void 0 : response.list) ? response.list : [];
346
- const normalizedList = resourceList.map((item) => this.normalizeResource(item));
379
+ const resourceList = Array.isArray(response?.list) ? response.list : [];
380
+ const normalizedList = resourceList.map(item => this.normalizeResource(item));
347
381
  await this.saveResourcesToSQLite(normalizedList);
348
- await this.safeEmit(import_types.ResourceHooks.onResourcesLoaded, normalizedList);
382
+ await this.safeEmit(_types.ResourceHooks.onResourcesLoaded, normalizedList);
349
383
  return normalizedList;
350
384
  } catch {
351
385
  return [];
352
386
  }
353
387
  }
388
+
354
389
  // ─────────────────────────────────────────────────────────────────
355
390
  // SQLite 持久化
356
391
  // ─────────────────────────────────────────────────────────────────
392
+
357
393
  async loadResourcesFromSQLite() {
358
- if (!this.dbManager)
359
- return [];
394
+ if (!this.dbManager) return [];
360
395
  try {
361
396
  const resources = await this.dbManager.getAll(RESOURCE_STORE_NAME);
362
397
  return resources || [];
@@ -365,25 +400,24 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
365
400
  }
366
401
  }
367
402
  async saveResourcesToSQLite(resourceList) {
368
- if (!this.dbManager)
369
- return;
403
+ if (!this.dbManager) return;
370
404
  try {
371
405
  await this.dbManager.clear(RESOURCE_STORE_NAME);
372
- if (resourceList.length === 0)
373
- return;
406
+ if (resourceList.length === 0) return;
374
407
  if (this.dbManager.bulkAdd) {
375
408
  await this.dbManager.bulkAdd(RESOURCE_STORE_NAME, resourceList);
376
409
  return;
377
410
  }
378
- await Promise.all(resourceList.map((r) => this.dbManager.add(RESOURCE_STORE_NAME, r)));
411
+ await Promise.all(resourceList.map(r => this.dbManager.add(RESOURCE_STORE_NAME, r)));
379
412
  } catch (error) {
380
- console.error("saveResourcesToSQLite error", error);
381
- this.logError("保存资源到 SQLite 失败", {
413
+ console.error('saveResourcesToSQLite error', error);
414
+ this.logError('保存资源到 SQLite 失败', {
382
415
  error: error instanceof Error ? error.message : String(error),
383
416
  resourceList: resourceList.length
384
417
  });
385
418
  }
386
419
  }
420
+
387
421
  // private async loadBookingsFromSQLite(): Promise<ResourceBooking[]> {
388
422
  // if (!this.dbManager) return []
389
423
  // try {
@@ -393,6 +427,7 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
393
427
  // return []
394
428
  // }
395
429
  // }
430
+
396
431
  // private async saveBookingsToSQLite(bookings: ResourceBooking[]): Promise<void> {
397
432
  // if (!this.dbManager) return
398
433
  // try {
@@ -407,96 +442,92 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
407
442
  // // 忽略 SQLite 异常
408
443
  // }
409
444
  // }
445
+
410
446
  // ─────────────────────────────────────────────────────────────────
411
447
  // pubsub 同步
412
448
  // ─────────────────────────────────────────────────────────────────
449
+
413
450
  initResourceDataSource() {
414
- var _a, _b;
415
- const ResourceDataSourceClass = (_b = (_a = this.core.serverOptions) == null ? void 0 : _a.All_DATA_SOURCES) == null ? void 0 : _b.ResourceDataSource;
416
- if (!ResourceDataSourceClass)
417
- return;
451
+ const ResourceDataSourceClass = this.core.serverOptions?.All_DATA_SOURCES?.ResourceDataSource;
452
+ if (!ResourceDataSourceClass) return;
418
453
  this.resourceDataSource = new ResourceDataSourceClass();
419
454
  }
420
455
  async setupResourceSync() {
421
- var _a, _b, _c;
422
- if (!this.resourceDataSource)
423
- return;
456
+ if (!this.resourceDataSource) return;
424
457
  const result = await this.resourceDataSource.run({
425
458
  pubsub: {
426
- callback: (res) => {
427
- const data = (res == null ? void 0 : res.data) || res;
428
- if (!data)
429
- return;
430
- const channelKey = data.module || "resource";
431
- this.pendingSyncMessages.push({ ...data, _channelKey: channelKey });
432
- if (this.syncTimer)
433
- clearTimeout(this.syncTimer);
459
+ callback: res => {
460
+ const data = res?.data || res;
461
+ if (!data) return;
462
+ const channelKey = data.module || 'resource';
463
+ this.pendingSyncMessages.push({
464
+ ...data,
465
+ _channelKey: channelKey
466
+ });
467
+ if (this.syncTimer) clearTimeout(this.syncTimer);
434
468
  this.syncTimer = setTimeout(() => {
435
469
  this.processSyncMessages();
436
470
  }, RESOURCE_SYNC_DEBOUNCE_MS);
437
471
  }
438
472
  }
439
473
  }).catch(() => {
474
+ // 忽略同步初始化异常
440
475
  });
441
- console.log("result", result);
442
- if ((_b = (_a = result == null ? void 0 : result.data) == null ? void 0 : _a.list) == null ? void 0 : _b.length) {
443
- await this.mergeResourcesToStore((_c = result == null ? void 0 : result.data) == null ? void 0 : _c.list);
476
+ if (result?.data?.list?.length) {
477
+ await this.mergeResourcesToStore(result?.data?.list);
444
478
  }
445
479
  }
446
480
  async processSyncMessages() {
447
- var _a, _b, _c;
448
481
  const messages = [...this.pendingSyncMessages];
449
482
  this.pendingSyncMessages = [];
450
- if (messages.length === 0)
451
- return;
483
+ if (messages.length === 0) return;
452
484
  const deleteIds = [];
453
- const bodyUpdates = /* @__PURE__ */ new Map();
485
+ const bodyUpdates = new Map();
454
486
  const sseRefreshIds = [];
455
487
  for (const msg of messages) {
456
- if (msg.operation === "delete" || msg.action === "delete") {
457
- if ((_a = msg.ids) == null ? void 0 : _a.length)
458
- deleteIds.push(...msg.ids);
459
- else if (msg.id !== void 0)
460
- deleteIds.push(msg.id);
488
+ if (msg.operation === 'delete' || msg.action === 'delete') {
489
+ if (msg.ids?.length) deleteIds.push(...msg.ids);else if (msg.id !== undefined) deleteIds.push(msg.id);
461
490
  continue;
462
491
  }
463
492
  if (msg.body) {
464
493
  const bodyId = msg.body.id ?? msg.id;
465
- if (bodyId === void 0)
466
- continue;
467
- bodyUpdates.set(this.getIdKey(bodyId), { ...msg.body, id: bodyId });
494
+ if (bodyId === undefined) continue;
495
+ bodyUpdates.set(this.getIdKey(bodyId), {
496
+ ...msg.body,
497
+ id: bodyId
498
+ });
468
499
  continue;
469
500
  }
470
- if ((_b = msg.ids) == null ? void 0 : _b.length) {
501
+ if (msg.ids?.length) {
471
502
  sseRefreshIds.push(...msg.ids);
472
- } else if (msg.id !== void 0) {
503
+ } else if (msg.id !== undefined) {
473
504
  sseRefreshIds.push(msg.id);
474
- } else if ((_c = msg.relation_resource_ids) == null ? void 0 : _c.length) {
505
+ } else if (msg.relation_resource_ids?.length) {
475
506
  sseRefreshIds.push(...msg.relation_resource_ids);
476
507
  }
477
508
  }
478
509
  const uniqueDeleteIds = this.uniqueResourceIds(deleteIds);
479
510
  const uniqueSSEIds = this.uniqueResourceIds(sseRefreshIds);
480
511
  const bodyList = [...bodyUpdates.values()];
481
- if (uniqueDeleteIds.length > 0)
482
- await this.removeResourcesByIds(uniqueDeleteIds);
483
- if (bodyList.length > 0)
484
- await this.mergeResourcesToStore(bodyList);
512
+ if (uniqueDeleteIds.length > 0) await this.removeResourcesByIds(uniqueDeleteIds);
513
+ if (bodyList.length > 0) await this.mergeResourcesToStore(bodyList);
485
514
  if (uniqueSSEIds.length > 0) {
486
515
  const freshResources = await this.fetchResourcesBySSE(uniqueSSEIds);
487
- if (freshResources.length > 0)
488
- await this.mergeResourcesToStore(freshResources);
516
+ if (freshResources.length > 0) await this.mergeResourcesToStore(freshResources);
489
517
  }
490
- if (uniqueDeleteIds.length === 0 && bodyList.length === 0 && uniqueSSEIds.length === 0)
491
- return;
492
- await this.core.effects.emit(import_types.ResourceHooks.onResourcesSyncCompleted, null);
518
+ if (uniqueDeleteIds.length === 0 && bodyList.length === 0 && uniqueSSEIds.length === 0) return;
519
+ await this.core.effects.emit(_types.ResourceHooks.onResourcesSyncCompleted, null);
493
520
  }
494
521
  async fetchResourcesBySSE(ids) {
495
- if (!this.resourceDataSource)
496
- return [];
522
+ if (!this.resourceDataSource) return [];
497
523
  try {
498
524
  const list = await this.resourceDataSource.run({
499
- sse: { query: { type: "resource", ids } }
525
+ sse: {
526
+ query: {
527
+ type: 'resource',
528
+ ids
529
+ }
530
+ }
500
531
  });
501
532
  return list || [];
502
533
  } catch {
@@ -504,8 +535,8 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
504
535
  }
505
536
  }
506
537
  async removeResourcesByIds(ids) {
507
- const keySet = new Set(ids.map((id) => this.getIdKey(id)));
508
- this.store.list = this.store.list.filter((r) => !keySet.has(this.getIdKey(r.id)));
538
+ const keySet = new Set(ids.map(id => this.getIdKey(id)));
539
+ this.store.list = this.store.list.filter(r => !keySet.has(this.getIdKey(r.id)));
509
540
  this.syncResourcesMap();
510
541
  if (this.dbManager) {
511
542
  try {
@@ -513,21 +544,20 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
513
544
  await this.dbManager.delete(RESOURCE_STORE_NAME, id);
514
545
  }
515
546
  } catch {
547
+ // 忽略 SQLite 异常
516
548
  }
517
549
  }
518
- await this.safeEmit(import_types.ResourceHooks.onResourcesChanged, this.store.list);
550
+ await this.safeEmit(_types.ResourceHooks.onResourcesChanged, this.store.list);
519
551
  }
520
552
  async mergeResourcesToStore(freshResources) {
521
- const freshMap = /* @__PURE__ */ new Map();
553
+ const freshMap = new Map();
522
554
  for (const r of freshResources) {
523
- if ((r == null ? void 0 : r.id) === void 0)
524
- continue;
555
+ if (r?.id === undefined) continue;
525
556
  freshMap.set(this.getIdKey(r.id), this.normalizeResource(r));
526
557
  }
527
- const updatedList = this.store.list.map((r) => {
558
+ const updatedList = this.store.list.map(r => {
528
559
  const key = this.getIdKey(r.id);
529
- if (!freshMap.has(key))
530
- return r;
560
+ if (!freshMap.has(key)) return r;
531
561
  const fresh = freshMap.get(key);
532
562
  freshMap.delete(key);
533
563
  return fresh;
@@ -538,20 +568,19 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
538
568
  this.store.list = updatedList;
539
569
  this.syncResourcesMap();
540
570
  await this.saveResourcesToSQLite(this.store.list);
541
- await this.safeEmit(import_types.ResourceHooks.onResourcesChanged, this.store.list);
571
+ await this.safeEmit(_types.ResourceHooks.onResourcesChanged, this.store.list);
542
572
  }
543
573
  uniqueResourceIds(ids) {
544
- const idMap = /* @__PURE__ */ new Map();
574
+ const idMap = new Map();
545
575
  for (const id of ids) {
546
576
  idMap.set(this.getIdKey(id), id);
547
577
  }
548
578
  return [...idMap.values()];
549
579
  }
550
- };
551
- var resourceModule = new ResourceModule();
552
- // Annotate the CommonJS export names for ESM import in node:
553
- 0 && (module.exports = {
554
- ResourceHooks,
555
- ResourceModule,
556
- resourceModule
557
- });
580
+ }
581
+
582
+ // ─────────────────────────────────────────────────────────────────
583
+ // 导出
584
+ // ─────────────────────────────────────────────────────────────────
585
+ exports.ResourceModule = ResourceModule;
586
+ const resourceModule = exports.resourceModule = new ResourceModule();