@pisell/pisellos 0.0.569 → 0.10.2

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