@nocobase/plugin-workflow 0.11.1-alpha.4 → 0.12.0-alpha.1

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 (537) hide show
  1. package/client.d.ts +2 -3
  2. package/client.js +1 -1
  3. package/dist/client/index.js +7802 -0
  4. package/{lib → dist}/client/nodes/aggregate.d.ts +1 -5
  5. package/{lib → dist}/client/nodes/create.d.ts +1 -2
  6. package/{lib → dist}/client/nodes/destroy.d.ts +1 -1
  7. package/{lib → dist}/client/nodes/query.d.ts +1 -2
  8. package/{lib → dist}/client/nodes/request.d.ts +1 -2
  9. package/{lib → dist}/client/nodes/update.d.ts +1 -1
  10. package/{lib → dist}/client/schemas/collection.d.ts +1 -2
  11. package/{lib → dist}/client/triggers/collection.d.ts +6 -7
  12. package/{lib → dist}/index.d.ts +1 -0
  13. package/dist/index.js +18 -0
  14. package/dist/locale/en-US.js +133 -0
  15. package/{lib → dist}/locale/es-ES.js +51 -54
  16. package/dist/locale/fr-FR.js +133 -0
  17. package/dist/locale/ja-JP.js +91 -0
  18. package/dist/locale/pt-BR.js +133 -0
  19. package/dist/locale/ru-RU.js +91 -0
  20. package/dist/locale/tr-TR.js +91 -0
  21. package/dist/locale/zh-CN.js +216 -0
  22. package/dist/node_modules/cron-parser/.eslintrc.json +15 -0
  23. package/dist/node_modules/cron-parser/.travis.yml +7 -0
  24. package/dist/node_modules/cron-parser/LICENSE +21 -0
  25. package/dist/node_modules/cron-parser/component.json +11 -0
  26. package/dist/node_modules/cron-parser/index.d.ts +1 -0
  27. package/dist/node_modules/cron-parser/lib/date.js +252 -0
  28. package/dist/node_modules/cron-parser/lib/expression.js +983 -0
  29. package/dist/node_modules/cron-parser/lib/field_compactor.js +70 -0
  30. package/dist/node_modules/cron-parser/lib/field_stringify.js +38 -0
  31. package/dist/node_modules/cron-parser/lib/parser.js +1 -0
  32. package/dist/node_modules/cron-parser/node_modules/luxon/build/amd/luxon.js +8489 -0
  33. package/dist/node_modules/cron-parser/node_modules/luxon/build/cjs-browser/luxon.js +8487 -0
  34. package/dist/node_modules/cron-parser/node_modules/luxon/build/global/luxon.js +8490 -0
  35. package/dist/node_modules/cron-parser/node_modules/luxon/build/global/luxon.min.js +1 -0
  36. package/dist/node_modules/cron-parser/node_modules/luxon/build/node/luxon.js +7522 -0
  37. package/dist/node_modules/cron-parser/node_modules/luxon/package.json +96 -0
  38. package/dist/node_modules/cron-parser/node_modules/luxon/src/datetime.js +2169 -0
  39. package/dist/node_modules/cron-parser/node_modules/luxon/src/duration.js +880 -0
  40. package/dist/node_modules/cron-parser/node_modules/luxon/src/errors.js +61 -0
  41. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/conversions.js +157 -0
  42. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/diff.js +80 -0
  43. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/digits.js +76 -0
  44. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/english.js +233 -0
  45. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/formats.js +191 -0
  46. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/formatter.js +386 -0
  47. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/invalid.js +14 -0
  48. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/locale.js +482 -0
  49. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/regexParser.js +335 -0
  50. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/tokenParser.js +424 -0
  51. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/util.js +292 -0
  52. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/zoneUtil.js +36 -0
  53. package/dist/node_modules/cron-parser/node_modules/luxon/src/info.js +193 -0
  54. package/dist/node_modules/cron-parser/node_modules/luxon/src/interval.js +602 -0
  55. package/dist/node_modules/cron-parser/node_modules/luxon/src/luxon.js +26 -0
  56. package/dist/node_modules/cron-parser/node_modules/luxon/src/luxonFilled.js +13 -0
  57. package/dist/node_modules/cron-parser/node_modules/luxon/src/settings.js +137 -0
  58. package/dist/node_modules/cron-parser/node_modules/luxon/src/zone.js +88 -0
  59. package/dist/node_modules/cron-parser/node_modules/luxon/src/zones/IANAZone.js +191 -0
  60. package/dist/node_modules/cron-parser/node_modules/luxon/src/zones/fixedOffsetZone.js +94 -0
  61. package/dist/node_modules/cron-parser/node_modules/luxon/src/zones/invalidZone.js +53 -0
  62. package/dist/node_modules/cron-parser/node_modules/luxon/src/zones/localZone.js +63 -0
  63. package/dist/node_modules/cron-parser/package.json +1 -0
  64. package/dist/node_modules/cron-parser/test/31_of_month.js +17 -0
  65. package/dist/node_modules/cron-parser/test/bug.js +29 -0
  66. package/dist/node_modules/cron-parser/test/crondate.js +16 -0
  67. package/dist/node_modules/cron-parser/test/crontab.example +7 -0
  68. package/dist/node_modules/cron-parser/test/empty_around_comma.js +22 -0
  69. package/dist/node_modules/cron-parser/test/expression.js +1489 -0
  70. package/dist/node_modules/cron-parser/test/field_compactor.js +250 -0
  71. package/dist/node_modules/cron-parser/test/field_stringify.js +84 -0
  72. package/dist/node_modules/cron-parser/test/fields.js +32 -0
  73. package/dist/node_modules/cron-parser/test/increment_on_first_iteration.js +22 -0
  74. package/dist/node_modules/cron-parser/test/index-ts3.test-d.ts +133 -0
  75. package/dist/node_modules/cron-parser/test/index.test-d.ts +138 -0
  76. package/dist/node_modules/cron-parser/test/leap_year.js +17 -0
  77. package/dist/node_modules/cron-parser/test/parser.js +46 -0
  78. package/dist/node_modules/cron-parser/test/parser_crondate_formats.js +145 -0
  79. package/dist/node_modules/cron-parser/test/parser_day_of_month.js +169 -0
  80. package/dist/node_modules/cron-parser/test/prev_date.js +32 -0
  81. package/dist/node_modules/cron-parser/test/stringify.js +402 -0
  82. package/dist/node_modules/cron-parser/test/timezone.js +422 -0
  83. package/dist/node_modules/cron-parser/types/common.d.ts +131 -0
  84. package/dist/node_modules/cron-parser/types/index.d.ts +45 -0
  85. package/dist/node_modules/cron-parser/types/ts3/index.d.ts +28 -0
  86. package/dist/node_modules/lru-cache/index-cjs.d.ts +7 -0
  87. package/dist/node_modules/lru-cache/index-cjs.js +1 -0
  88. package/dist/node_modules/lru-cache/index.d.ts +807 -0
  89. package/dist/node_modules/lru-cache/index.js +1334 -0
  90. package/dist/node_modules/lru-cache/index.min.js +2 -0
  91. package/dist/node_modules/lru-cache/package.json +1 -0
  92. package/dist/server/Plugin.js +297 -0
  93. package/{src/server/Processor.ts → dist/server/Processor.js} +80 -147
  94. package/dist/server/actions/index.js +49 -0
  95. package/{src/server/actions/nodes.ts → dist/server/actions/nodes.js} +55 -81
  96. package/{src/server/actions/workflows.ts → dist/server/actions/workflows.js} +60 -72
  97. package/dist/server/collections/executions.js +37 -0
  98. package/dist/server/collections/flow_nodes.js +56 -0
  99. package/dist/server/collections/jobs.js +33 -0
  100. package/dist/server/collections/workflows.js +90 -0
  101. package/{lib → dist}/server/constants.js +5 -8
  102. package/dist/server/fields/expression-field.js +11 -0
  103. package/dist/server/fields/index.js +11 -0
  104. package/dist/server/functions/index.js +13 -0
  105. package/dist/server/index.js +41 -0
  106. package/dist/server/instructions/aggregate.js +37 -0
  107. package/dist/server/instructions/calculation.js +34 -0
  108. package/dist/server/instructions/condition.js +123 -0
  109. package/{src/server/instructions/create.ts → dist/server/instructions/create.js} +17 -17
  110. package/dist/server/instructions/delay.js +87 -0
  111. package/dist/server/instructions/destroy.js +24 -0
  112. package/dist/server/instructions/index.js +40 -0
  113. package/{src/server/instructions/loop.ts → dist/server/instructions/loop.js} +21 -43
  114. package/{src/server/instructions/manual/actions.ts → dist/server/instructions/manual/actions.js} +18 -44
  115. package/dist/server/instructions/manual/collecions/jobs.js +21 -0
  116. package/dist/server/instructions/manual/collecions/users.js +19 -0
  117. package/dist/server/instructions/manual/collecions/users_jobs.js +52 -0
  118. package/{src/server/instructions/manual/forms/create.ts → dist/server/instructions/manual/forms/create.js} +8 -8
  119. package/dist/server/instructions/manual/forms/index.js +16 -0
  120. package/{src/server/instructions/manual/forms/update.ts → dist/server/instructions/manual/forms/update.js} +8 -8
  121. package/dist/server/instructions/manual/index.js +160 -0
  122. package/dist/server/instructions/parallel.js +105 -0
  123. package/dist/server/instructions/query.js +36 -0
  124. package/dist/server/instructions/request.js +69 -0
  125. package/dist/server/instructions/sql.js +26 -0
  126. package/dist/server/instructions/update.js +24 -0
  127. package/{src/server/migrations/20221129153547-calculation-variables.ts → dist/server/migrations/20221129153547-calculation-variables.js} +20 -19
  128. package/dist/server/migrations/20230221032941-change-request-body-type.js +71 -0
  129. package/dist/server/migrations/20230221071831-calculation-expression.js +94 -0
  130. package/dist/server/migrations/20230221121203-condition-calculation.js +41 -0
  131. package/dist/server/migrations/20230221162902-jsonb-to-json.js +52 -0
  132. package/dist/server/migrations/20230411034722-manual-multi-form.js +252 -0
  133. package/dist/server/migrations/20230612021134-manual-collection-block.js +126 -0
  134. package/dist/server/migrations/20230710115902-manual-action-values.js +74 -0
  135. package/{src/server/triggers/collection.ts → dist/server/triggers/collection.js} +34 -64
  136. package/dist/server/triggers/index.js +27 -0
  137. package/{src/server/triggers/schedule.ts → dist/server/triggers/schedule.js} +108 -220
  138. package/dist/server/types/Execution.js +8 -0
  139. package/dist/server/types/FlowNode.js +8 -0
  140. package/dist/server/types/Job.js +8 -0
  141. package/dist/server/types/Workflow.js +8 -0
  142. package/dist/server/types/index.js +2 -0
  143. package/{lib → dist}/server/utils.js +6 -8
  144. package/package.json +26 -37
  145. package/server.d.ts +2 -3
  146. package/server.js +1 -1
  147. package/lib/client/AddButton.js +0 -161
  148. package/lib/client/Branch.js +0 -50
  149. package/lib/client/CanvasContent.js +0 -51
  150. package/lib/client/ExecutionCanvas.js +0 -218
  151. package/lib/client/ExecutionLink.js +0 -48
  152. package/lib/client/ExecutionPage.js +0 -68
  153. package/lib/client/ExecutionResourceProvider.js +0 -48
  154. package/lib/client/FlowContext.js +0 -21
  155. package/lib/client/WorkflowCanvas.js +0 -300
  156. package/lib/client/WorkflowLink.js +0 -48
  157. package/lib/client/WorkflowPage.js +0 -70
  158. package/lib/client/WorkflowProvider.js +0 -100
  159. package/lib/client/components/CollectionBlockInitializer.js +0 -103
  160. package/lib/client/components/CollectionFieldset.js +0 -198
  161. package/lib/client/components/Duration.js +0 -72
  162. package/lib/client/components/DynamicExpression.js +0 -117
  163. package/lib/client/components/FieldsSelect.js +0 -72
  164. package/lib/client/components/FilterDynamicComponent.js +0 -34
  165. package/lib/client/components/NodeDescription.js +0 -73
  166. package/lib/client/components/NullRender.js +0 -9
  167. package/lib/client/components/OpenDrawer.js +0 -68
  168. package/lib/client/components/RadioWithTooltip.js +0 -65
  169. package/lib/client/components/ValueBlock.js +0 -103
  170. package/lib/client/components/renderEngineReference.js +0 -49
  171. package/lib/client/constants.js +0 -126
  172. package/lib/client/index.js +0 -121
  173. package/lib/client/interfaces/expression.js +0 -38
  174. package/lib/client/locale/index.js +0 -42
  175. package/lib/client/nodes/aggregate.js +0 -353
  176. package/lib/client/nodes/calculation.js +0 -292
  177. package/lib/client/nodes/condition.js +0 -531
  178. package/lib/client/nodes/create.js +0 -110
  179. package/lib/client/nodes/delay.js +0 -47
  180. package/lib/client/nodes/destroy.js +0 -49
  181. package/lib/client/nodes/index.js +0 -550
  182. package/lib/client/nodes/loop.js +0 -171
  183. package/lib/client/nodes/manual/AssigneesSelect.js +0 -56
  184. package/lib/client/nodes/manual/DetailsBlockProvider.js +0 -106
  185. package/lib/client/nodes/manual/FormBlockInitializer.js +0 -107
  186. package/lib/client/nodes/manual/FormBlockProvider.js +0 -113
  187. package/lib/client/nodes/manual/ModeConfig.js +0 -126
  188. package/lib/client/nodes/manual/SchemaConfig.js +0 -468
  189. package/lib/client/nodes/manual/WorkflowTodo.js +0 -642
  190. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +0 -60
  191. package/lib/client/nodes/manual/forms/create.js +0 -111
  192. package/lib/client/nodes/manual/forms/custom.js +0 -428
  193. package/lib/client/nodes/manual/forms/update.js +0 -168
  194. package/lib/client/nodes/manual/index.js +0 -168
  195. package/lib/client/nodes/manual/utils.js +0 -31
  196. package/lib/client/nodes/parallel.js +0 -162
  197. package/lib/client/nodes/query.js +0 -112
  198. package/lib/client/nodes/request.js +0 -225
  199. package/lib/client/nodes/sql.js +0 -61
  200. package/lib/client/nodes/update.js +0 -127
  201. package/lib/client/schemas/collection.js +0 -93
  202. package/lib/client/schemas/executions.js +0 -190
  203. package/lib/client/schemas/workflows.js +0 -397
  204. package/lib/client/style.js +0 -350
  205. package/lib/client/triggers/collection.js +0 -188
  206. package/lib/client/triggers/index.js +0 -356
  207. package/lib/client/triggers/schedule/EndsByField.js +0 -71
  208. package/lib/client/triggers/schedule/OnField.js +0 -117
  209. package/lib/client/triggers/schedule/RepeatField.js +0 -155
  210. package/lib/client/triggers/schedule/ScheduleConfig.js +0 -251
  211. package/lib/client/triggers/schedule/constants.js +0 -11
  212. package/lib/client/triggers/schedule/index.js +0 -101
  213. package/lib/client/triggers/schedule/locale/Cron.zh-CN.js +0 -48
  214. package/lib/client/utils.js +0 -59
  215. package/lib/client/variable.js +0 -319
  216. package/lib/index.js +0 -13
  217. package/lib/locale/en-US.js +0 -136
  218. package/lib/locale/fr-FR.js +0 -136
  219. package/lib/locale/ja-JP.js +0 -94
  220. package/lib/locale/pt-BR.js +0 -136
  221. package/lib/locale/ru-RU.js +0 -94
  222. package/lib/locale/tr-TR.js +0 -94
  223. package/lib/locale/zh-CN.js +0 -219
  224. package/lib/server/Plugin.js +0 -382
  225. package/lib/server/Processor.js +0 -394
  226. package/lib/server/actions/index.js +0 -30
  227. package/lib/server/actions/nodes.js +0 -269
  228. package/lib/server/actions/workflows.js +0 -273
  229. package/lib/server/collections/executions.js +0 -33
  230. package/lib/server/collections/flow_nodes.js +0 -53
  231. package/lib/server/collections/jobs.js +0 -30
  232. package/lib/server/collections/workflows.js +0 -76
  233. package/lib/server/fields/expression-field.js +0 -19
  234. package/lib/server/fields/index.js +0 -12
  235. package/lib/server/functions/index.js +0 -26
  236. package/lib/server/index.js +0 -55
  237. package/lib/server/instructions/aggregate.js +0 -57
  238. package/lib/server/instructions/calculation.js +0 -59
  239. package/lib/server/instructions/condition.js +0 -150
  240. package/lib/server/instructions/create.js +0 -60
  241. package/lib/server/instructions/delay.js +0 -118
  242. package/lib/server/instructions/destroy.js +0 -37
  243. package/lib/server/instructions/index.js +0 -44
  244. package/lib/server/instructions/loop.js +0 -107
  245. package/lib/server/instructions/manual/actions.js +0 -99
  246. package/lib/server/instructions/manual/collecions/jobs.js +0 -21
  247. package/lib/server/instructions/manual/collecions/users.js +0 -19
  248. package/lib/server/instructions/manual/collecions/users_jobs.js +0 -46
  249. package/lib/server/instructions/manual/forms/create.js +0 -52
  250. package/lib/server/instructions/manual/forms/index.js +0 -15
  251. package/lib/server/instructions/manual/forms/update.js +0 -53
  252. package/lib/server/instructions/manual/index.js +0 -174
  253. package/lib/server/instructions/parallel.js +0 -128
  254. package/lib/server/instructions/query.js +0 -53
  255. package/lib/server/instructions/request.js +0 -99
  256. package/lib/server/instructions/sql.js +0 -34
  257. package/lib/server/instructions/update.js +0 -38
  258. package/lib/server/migrations/20221129153547-calculation-variables.js +0 -92
  259. package/lib/server/migrations/20230221032941-change-request-body-type.js +0 -90
  260. package/lib/server/migrations/20230221071831-calculation-expression.js +0 -111
  261. package/lib/server/migrations/20230221121203-condition-calculation.js +0 -103
  262. package/lib/server/migrations/20230221162902-jsonb-to-json.js +0 -64
  263. package/lib/server/migrations/20230411034722-manual-multi-form.js +0 -297
  264. package/lib/server/migrations/20230612021134-manual-collection-block.js +0 -155
  265. package/lib/server/migrations/20230710115902-manual-action-values.js +0 -97
  266. package/lib/server/triggers/collection.js +0 -175
  267. package/lib/server/triggers/index.js +0 -46
  268. package/lib/server/triggers/schedule.js +0 -582
  269. package/lib/server/types/Execution.js +0 -15
  270. package/lib/server/types/FlowNode.js +0 -15
  271. package/lib/server/types/Job.js +0 -15
  272. package/lib/server/types/Workflow.js +0 -15
  273. package/lib/server/types/index.js +0 -5
  274. package/src/client/AddButton.tsx +0 -111
  275. package/src/client/Branch.tsx +0 -37
  276. package/src/client/CanvasContent.tsx +0 -25
  277. package/src/client/ExecutionCanvas.tsx +0 -166
  278. package/src/client/ExecutionLink.tsx +0 -16
  279. package/src/client/ExecutionPage.tsx +0 -45
  280. package/src/client/ExecutionResourceProvider.tsx +0 -21
  281. package/src/client/FlowContext.ts +0 -7
  282. package/src/client/WorkflowCanvas.tsx +0 -221
  283. package/src/client/WorkflowLink.tsx +0 -16
  284. package/src/client/WorkflowPage.tsx +0 -52
  285. package/src/client/WorkflowProvider.tsx +0 -84
  286. package/src/client/components/CollectionBlockInitializer.tsx +0 -71
  287. package/src/client/components/CollectionFieldset.tsx +0 -152
  288. package/src/client/components/Duration.tsx +0 -45
  289. package/src/client/components/DynamicExpression.tsx +0 -57
  290. package/src/client/components/FieldsSelect.tsx +0 -32
  291. package/src/client/components/FilterDynamicComponent.tsx +0 -15
  292. package/src/client/components/NodeDescription.tsx +0 -51
  293. package/src/client/components/NullRender.tsx +0 -3
  294. package/src/client/components/OpenDrawer.tsx +0 -24
  295. package/src/client/components/RadioWithTooltip.tsx +0 -38
  296. package/src/client/components/ValueBlock.tsx +0 -67
  297. package/src/client/components/renderEngineReference.tsx +0 -30
  298. package/src/client/constants.tsx +0 -91
  299. package/src/client/index.tsx +0 -51
  300. package/src/client/interfaces/expression.tsx +0 -25
  301. package/src/client/locale/index.ts +0 -18
  302. package/src/client/nodes/aggregate.tsx +0 -327
  303. package/src/client/nodes/calculation.tsx +0 -216
  304. package/src/client/nodes/condition.tsx +0 -463
  305. package/src/client/nodes/create.tsx +0 -85
  306. package/src/client/nodes/delay.tsx +0 -37
  307. package/src/client/nodes/destroy.tsx +0 -34
  308. package/src/client/nodes/index.tsx +0 -500
  309. package/src/client/nodes/loop.tsx +0 -144
  310. package/src/client/nodes/manual/AssigneesSelect.tsx +0 -33
  311. package/src/client/nodes/manual/DetailsBlockProvider.tsx +0 -80
  312. package/src/client/nodes/manual/FormBlockInitializer.tsx +0 -69
  313. package/src/client/nodes/manual/FormBlockProvider.tsx +0 -75
  314. package/src/client/nodes/manual/ModeConfig.tsx +0 -84
  315. package/src/client/nodes/manual/SchemaConfig.tsx +0 -509
  316. package/src/client/nodes/manual/WorkflowTodo.tsx +0 -607
  317. package/src/client/nodes/manual/WorkflowTodoBlockInitializer.tsx +0 -28
  318. package/src/client/nodes/manual/forms/create.tsx +0 -92
  319. package/src/client/nodes/manual/forms/custom.tsx +0 -392
  320. package/src/client/nodes/manual/forms/update.tsx +0 -134
  321. package/src/client/nodes/manual/index.tsx +0 -162
  322. package/src/client/nodes/manual/utils.ts +0 -28
  323. package/src/client/nodes/parallel.tsx +0 -138
  324. package/src/client/nodes/query.tsx +0 -88
  325. package/src/client/nodes/request.tsx +0 -185
  326. package/src/client/nodes/sql.tsx +0 -37
  327. package/src/client/nodes/update.tsx +0 -100
  328. package/src/client/schemas/collection.ts +0 -75
  329. package/src/client/schemas/executions.tsx +0 -169
  330. package/src/client/schemas/workflows.ts +0 -364
  331. package/src/client/style.tsx +0 -350
  332. package/src/client/triggers/collection.tsx +0 -190
  333. package/src/client/triggers/index.tsx +0 -311
  334. package/src/client/triggers/schedule/EndsByField.tsx +0 -40
  335. package/src/client/triggers/schedule/OnField.tsx +0 -64
  336. package/src/client/triggers/schedule/RepeatField.tsx +0 -116
  337. package/src/client/triggers/schedule/ScheduleConfig.tsx +0 -227
  338. package/src/client/triggers/schedule/constants.ts +0 -4
  339. package/src/client/triggers/schedule/index.tsx +0 -78
  340. package/src/client/triggers/schedule/locale/Cron.zh-CN.ts +0 -79
  341. package/src/client/utils.ts +0 -36
  342. package/src/client/variable.tsx +0 -318
  343. package/src/index.ts +0 -1
  344. package/src/locale/en-US.ts +0 -136
  345. package/src/locale/es-ES.ts +0 -129
  346. package/src/locale/fr-FR.ts +0 -137
  347. package/src/locale/ja-JP.ts +0 -90
  348. package/src/locale/pt-BR.ts +0 -136
  349. package/src/locale/ru-RU.ts +0 -90
  350. package/src/locale/tr-TR.ts +0 -90
  351. package/src/locale/zh-CN.ts +0 -248
  352. package/src/server/Plugin.ts +0 -355
  353. package/src/server/__tests__/Plugin.test.ts +0 -398
  354. package/src/server/__tests__/Processor.test.ts +0 -474
  355. package/src/server/__tests__/actions/workflows.test.ts +0 -419
  356. package/src/server/__tests__/collections/categories.ts +0 -27
  357. package/src/server/__tests__/collections/comments.ts +0 -24
  358. package/src/server/__tests__/collections/posts.ts +0 -42
  359. package/src/server/__tests__/collections/replies.ts +0 -9
  360. package/src/server/__tests__/collections/tags.ts +0 -15
  361. package/src/server/__tests__/index.ts +0 -89
  362. package/src/server/__tests__/instructions/aggregate.test.ts +0 -294
  363. package/src/server/__tests__/instructions/calculation.test.ts +0 -265
  364. package/src/server/__tests__/instructions/condition.test.ts +0 -335
  365. package/src/server/__tests__/instructions/create.test.ts +0 -129
  366. package/src/server/__tests__/instructions/delay.test.ts +0 -182
  367. package/src/server/__tests__/instructions/destroy.test.ts +0 -58
  368. package/src/server/__tests__/instructions/loop.test.ts +0 -331
  369. package/src/server/__tests__/instructions/manual.test.ts +0 -1173
  370. package/src/server/__tests__/instructions/parallel.test.ts +0 -445
  371. package/src/server/__tests__/instructions/query.test.ts +0 -359
  372. package/src/server/__tests__/instructions/request.test.ts +0 -247
  373. package/src/server/__tests__/instructions/sql.test.ts +0 -162
  374. package/src/server/__tests__/instructions/update.test.ts +0 -189
  375. package/src/server/__tests__/triggers/collection.test.ts +0 -333
  376. package/src/server/__tests__/triggers/schedule.test.ts +0 -369
  377. package/src/server/actions/index.ts +0 -25
  378. package/src/server/collections/executions.ts +0 -35
  379. package/src/server/collections/flow_nodes.ts +0 -54
  380. package/src/server/collections/jobs.ts +0 -31
  381. package/src/server/collections/workflows.ts +0 -88
  382. package/src/server/constants.ts +0 -26
  383. package/src/server/fields/expression-field.ts +0 -11
  384. package/src/server/fields/index.ts +0 -7
  385. package/src/server/functions/index.ts +0 -16
  386. package/src/server/index.ts +0 -6
  387. package/src/server/instructions/aggregate.ts +0 -42
  388. package/src/server/instructions/calculation.ts +0 -41
  389. package/src/server/instructions/condition.ts +0 -172
  390. package/src/server/instructions/delay.ts +0 -105
  391. package/src/server/instructions/destroy.ts +0 -23
  392. package/src/server/instructions/index.ts +0 -64
  393. package/src/server/instructions/manual/collecions/jobs.ts +0 -17
  394. package/src/server/instructions/manual/collecions/users.ts +0 -15
  395. package/src/server/instructions/manual/collecions/users_jobs.ts +0 -50
  396. package/src/server/instructions/manual/forms/index.ts +0 -12
  397. package/src/server/instructions/manual/index.ts +0 -184
  398. package/src/server/instructions/parallel.ts +0 -121
  399. package/src/server/instructions/query.ts +0 -42
  400. package/src/server/instructions/request.ts +0 -88
  401. package/src/server/instructions/sql.ts +0 -25
  402. package/src/server/instructions/update.ts +0 -24
  403. package/src/server/migrations/20230221032941-change-request-body-type.ts +0 -76
  404. package/src/server/migrations/20230221071831-calculation-expression.ts +0 -102
  405. package/src/server/migrations/20230221121203-condition-calculation.ts +0 -82
  406. package/src/server/migrations/20230221162902-jsonb-to-json.ts +0 -51
  407. package/src/server/migrations/20230411034722-manual-multi-form.ts +0 -282
  408. package/src/server/migrations/20230612021134-manual-collection-block.ts +0 -138
  409. package/src/server/migrations/20230710115902-manual-action-values.ts +0 -78
  410. package/src/server/triggers/index.ts +0 -22
  411. package/src/server/types/Execution.ts +0 -26
  412. package/src/server/types/FlowNode.ts +0 -21
  413. package/src/server/types/Job.ts +0 -18
  414. package/src/server/types/Workflow.ts +0 -36
  415. package/src/server/types/index.ts +0 -4
  416. package/src/server/utils.ts +0 -17
  417. /package/{lib → dist}/client/AddButton.d.ts +0 -0
  418. /package/{lib → dist}/client/Branch.d.ts +0 -0
  419. /package/{lib → dist}/client/CanvasContent.d.ts +0 -0
  420. /package/{lib → dist}/client/ExecutionCanvas.d.ts +0 -0
  421. /package/{lib → dist}/client/ExecutionLink.d.ts +0 -0
  422. /package/{lib → dist}/client/ExecutionPage.d.ts +0 -0
  423. /package/{lib → dist}/client/ExecutionResourceProvider.d.ts +0 -0
  424. /package/{lib → dist}/client/FlowContext.d.ts +0 -0
  425. /package/{lib → dist}/client/WorkflowCanvas.d.ts +0 -0
  426. /package/{lib → dist}/client/WorkflowLink.d.ts +0 -0
  427. /package/{lib → dist}/client/WorkflowPage.d.ts +0 -0
  428. /package/{lib → dist}/client/WorkflowProvider.d.ts +0 -0
  429. /package/{lib → dist}/client/components/CollectionBlockInitializer.d.ts +0 -0
  430. /package/{lib → dist}/client/components/CollectionFieldset.d.ts +0 -0
  431. /package/{lib → dist}/client/components/Duration.d.ts +0 -0
  432. /package/{lib → dist}/client/components/DynamicExpression.d.ts +0 -0
  433. /package/{lib → dist}/client/components/FieldsSelect.d.ts +0 -0
  434. /package/{lib → dist}/client/components/FilterDynamicComponent.d.ts +0 -0
  435. /package/{lib → dist}/client/components/NodeDescription.d.ts +0 -0
  436. /package/{lib → dist}/client/components/NullRender.d.ts +0 -0
  437. /package/{lib → dist}/client/components/OpenDrawer.d.ts +0 -0
  438. /package/{lib → dist}/client/components/RadioWithTooltip.d.ts +0 -0
  439. /package/{lib → dist}/client/components/ValueBlock.d.ts +0 -0
  440. /package/{lib → dist}/client/components/renderEngineReference.d.ts +0 -0
  441. /package/{lib → dist}/client/constants.d.ts +0 -0
  442. /package/{lib → dist}/client/index.d.ts +0 -0
  443. /package/{lib → dist}/client/interfaces/expression.d.ts +0 -0
  444. /package/{lib → dist}/client/locale/index.d.ts +0 -0
  445. /package/{lib → dist}/client/nodes/calculation.d.ts +0 -0
  446. /package/{lib → dist}/client/nodes/condition.d.ts +0 -0
  447. /package/{lib → dist}/client/nodes/delay.d.ts +0 -0
  448. /package/{lib → dist}/client/nodes/index.d.ts +0 -0
  449. /package/{lib → dist}/client/nodes/loop.d.ts +0 -0
  450. /package/{lib → dist}/client/nodes/manual/AssigneesSelect.d.ts +0 -0
  451. /package/{lib → dist}/client/nodes/manual/DetailsBlockProvider.d.ts +0 -0
  452. /package/{lib → dist}/client/nodes/manual/FormBlockInitializer.d.ts +0 -0
  453. /package/{lib → dist}/client/nodes/manual/FormBlockProvider.d.ts +0 -0
  454. /package/{lib → dist}/client/nodes/manual/ModeConfig.d.ts +0 -0
  455. /package/{lib → dist}/client/nodes/manual/SchemaConfig.d.ts +0 -0
  456. /package/{lib → dist}/client/nodes/manual/WorkflowTodo.d.ts +0 -0
  457. /package/{lib → dist}/client/nodes/manual/WorkflowTodoBlockInitializer.d.ts +0 -0
  458. /package/{lib → dist}/client/nodes/manual/forms/create.d.ts +0 -0
  459. /package/{lib → dist}/client/nodes/manual/forms/custom.d.ts +0 -0
  460. /package/{lib → dist}/client/nodes/manual/forms/update.d.ts +0 -0
  461. /package/{lib → dist}/client/nodes/manual/index.d.ts +0 -0
  462. /package/{lib → dist}/client/nodes/manual/utils.d.ts +0 -0
  463. /package/{lib → dist}/client/nodes/parallel.d.ts +0 -0
  464. /package/{lib → dist}/client/nodes/sql.d.ts +0 -0
  465. /package/{lib → dist}/client/schemas/executions.d.ts +0 -0
  466. /package/{lib → dist}/client/schemas/workflows.d.ts +0 -0
  467. /package/{lib → dist}/client/style.d.ts +0 -0
  468. /package/{lib → dist}/client/triggers/index.d.ts +0 -0
  469. /package/{lib → dist}/client/triggers/schedule/EndsByField.d.ts +0 -0
  470. /package/{lib → dist}/client/triggers/schedule/OnField.d.ts +0 -0
  471. /package/{lib → dist}/client/triggers/schedule/RepeatField.d.ts +0 -0
  472. /package/{lib → dist}/client/triggers/schedule/ScheduleConfig.d.ts +0 -0
  473. /package/{lib → dist}/client/triggers/schedule/constants.d.ts +0 -0
  474. /package/{lib → dist}/client/triggers/schedule/index.d.ts +0 -0
  475. /package/{lib → dist}/client/triggers/schedule/locale/Cron.zh-CN.d.ts +0 -0
  476. /package/{lib → dist}/client/utils.d.ts +0 -0
  477. /package/{lib → dist}/client/variable.d.ts +0 -0
  478. /package/{lib → dist}/locale/en-US.d.ts +0 -0
  479. /package/{lib → dist}/locale/es-ES.d.ts +0 -0
  480. /package/{lib → dist}/locale/fr-FR.d.ts +0 -0
  481. /package/{lib → dist}/locale/ja-JP.d.ts +0 -0
  482. /package/{lib → dist}/locale/pt-BR.d.ts +0 -0
  483. /package/{lib → dist}/locale/ru-RU.d.ts +0 -0
  484. /package/{lib → dist}/locale/tr-TR.d.ts +0 -0
  485. /package/{lib → dist}/locale/zh-CN.d.ts +0 -0
  486. /package/{lib → dist}/server/Plugin.d.ts +0 -0
  487. /package/{lib → dist}/server/Processor.d.ts +0 -0
  488. /package/{lib → dist}/server/actions/index.d.ts +0 -0
  489. /package/{lib → dist}/server/actions/nodes.d.ts +0 -0
  490. /package/{lib → dist}/server/actions/workflows.d.ts +0 -0
  491. /package/{lib → dist}/server/collections/executions.d.ts +0 -0
  492. /package/{lib → dist}/server/collections/flow_nodes.d.ts +0 -0
  493. /package/{lib → dist}/server/collections/jobs.d.ts +0 -0
  494. /package/{lib → dist}/server/collections/workflows.d.ts +0 -0
  495. /package/{lib → dist}/server/constants.d.ts +0 -0
  496. /package/{lib → dist}/server/fields/expression-field.d.ts +0 -0
  497. /package/{lib → dist}/server/fields/index.d.ts +0 -0
  498. /package/{lib → dist}/server/functions/index.d.ts +0 -0
  499. /package/{lib → dist}/server/index.d.ts +0 -0
  500. /package/{lib → dist}/server/instructions/aggregate.d.ts +0 -0
  501. /package/{lib → dist}/server/instructions/calculation.d.ts +0 -0
  502. /package/{lib → dist}/server/instructions/condition.d.ts +0 -0
  503. /package/{lib → dist}/server/instructions/create.d.ts +0 -0
  504. /package/{lib → dist}/server/instructions/delay.d.ts +0 -0
  505. /package/{lib → dist}/server/instructions/destroy.d.ts +0 -0
  506. /package/{lib → dist}/server/instructions/index.d.ts +0 -0
  507. /package/{lib → dist}/server/instructions/loop.d.ts +0 -0
  508. /package/{lib → dist}/server/instructions/manual/actions.d.ts +0 -0
  509. /package/{lib → dist}/server/instructions/manual/collecions/jobs.d.ts +0 -0
  510. /package/{lib → dist}/server/instructions/manual/collecions/users.d.ts +0 -0
  511. /package/{lib → dist}/server/instructions/manual/collecions/users_jobs.d.ts +0 -0
  512. /package/{lib → dist}/server/instructions/manual/forms/create.d.ts +0 -0
  513. /package/{lib → dist}/server/instructions/manual/forms/index.d.ts +0 -0
  514. /package/{lib → dist}/server/instructions/manual/forms/update.d.ts +0 -0
  515. /package/{lib → dist}/server/instructions/manual/index.d.ts +0 -0
  516. /package/{lib → dist}/server/instructions/parallel.d.ts +0 -0
  517. /package/{lib → dist}/server/instructions/query.d.ts +0 -0
  518. /package/{lib → dist}/server/instructions/request.d.ts +0 -0
  519. /package/{lib → dist}/server/instructions/sql.d.ts +0 -0
  520. /package/{lib → dist}/server/instructions/update.d.ts +0 -0
  521. /package/{lib → dist}/server/migrations/20221129153547-calculation-variables.d.ts +0 -0
  522. /package/{lib → dist}/server/migrations/20230221032941-change-request-body-type.d.ts +0 -0
  523. /package/{lib → dist}/server/migrations/20230221071831-calculation-expression.d.ts +0 -0
  524. /package/{lib → dist}/server/migrations/20230221121203-condition-calculation.d.ts +0 -0
  525. /package/{lib → dist}/server/migrations/20230221162902-jsonb-to-json.d.ts +0 -0
  526. /package/{lib → dist}/server/migrations/20230411034722-manual-multi-form.d.ts +0 -0
  527. /package/{lib → dist}/server/migrations/20230612021134-manual-collection-block.d.ts +0 -0
  528. /package/{lib → dist}/server/migrations/20230710115902-manual-action-values.d.ts +0 -0
  529. /package/{lib → dist}/server/triggers/collection.d.ts +0 -0
  530. /package/{lib → dist}/server/triggers/index.d.ts +0 -0
  531. /package/{lib → dist}/server/triggers/schedule.d.ts +0 -0
  532. /package/{lib → dist}/server/types/Execution.d.ts +0 -0
  533. /package/{lib → dist}/server/types/FlowNode.d.ts +0 -0
  534. /package/{lib → dist}/server/types/Job.d.ts +0 -0
  535. /package/{lib → dist}/server/types/Workflow.d.ts +0 -0
  536. /package/{lib → dist}/server/types/index.d.ts +0 -0
  537. /package/{lib → dist}/server/utils.d.ts +0 -0
@@ -0,0 +1,1334 @@
1
+ "use strict";
2
+ /**
3
+ * @module LRUCache
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LRUCache = void 0;
7
+ const perf = typeof performance === 'object' &&
8
+ performance &&
9
+ typeof performance.now === 'function'
10
+ ? performance
11
+ : Date;
12
+ const warned = new Set();
13
+ const emitWarning = (msg, type, code, fn) => {
14
+ typeof process === 'object' &&
15
+ process &&
16
+ typeof process.emitWarning === 'function'
17
+ ? process.emitWarning(msg, type, code, fn)
18
+ : console.error(`[${code}] ${type}: ${msg}`);
19
+ };
20
+ const shouldWarn = (code) => !warned.has(code);
21
+ const TYPE = Symbol('type');
22
+ const isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
23
+ /* c8 ignore start */
24
+ // This is a little bit ridiculous, tbh.
25
+ // The maximum array length is 2^32-1 or thereabouts on most JS impls.
26
+ // And well before that point, you're caching the entire world, I mean,
27
+ // that's ~32GB of just integers for the next/prev links, plus whatever
28
+ // else to hold that many keys and values. Just filling the memory with
29
+ // zeroes at init time is brutal when you get that big.
30
+ // But why not be complete?
31
+ // Maybe in the future, these limits will have expanded.
32
+ const getUintArray = (max) => !isPosInt(max)
33
+ ? null
34
+ : max <= Math.pow(2, 8)
35
+ ? Uint8Array
36
+ : max <= Math.pow(2, 16)
37
+ ? Uint16Array
38
+ : max <= Math.pow(2, 32)
39
+ ? Uint32Array
40
+ : max <= Number.MAX_SAFE_INTEGER
41
+ ? ZeroArray
42
+ : null;
43
+ /* c8 ignore stop */
44
+ class ZeroArray extends Array {
45
+ constructor(size) {
46
+ super(size);
47
+ this.fill(0);
48
+ }
49
+ }
50
+ class Stack {
51
+ heap;
52
+ length;
53
+ // private constructor
54
+ static #constructing = false;
55
+ static create(max) {
56
+ const HeapCls = getUintArray(max);
57
+ if (!HeapCls)
58
+ return [];
59
+ Stack.#constructing = true;
60
+ const s = new Stack(max, HeapCls);
61
+ Stack.#constructing = false;
62
+ return s;
63
+ }
64
+ constructor(max, HeapCls) {
65
+ /* c8 ignore start */
66
+ if (!Stack.#constructing) {
67
+ throw new TypeError('instantiate Stack using Stack.create(n)');
68
+ }
69
+ /* c8 ignore stop */
70
+ this.heap = new HeapCls(max);
71
+ this.length = 0;
72
+ }
73
+ push(n) {
74
+ this.heap[this.length++] = n;
75
+ }
76
+ pop() {
77
+ return this.heap[--this.length];
78
+ }
79
+ }
80
+ /**
81
+ * Default export, the thing you're using this module to get.
82
+ *
83
+ * All properties from the options object (with the exception of
84
+ * {@link OptionsBase.max} and {@link OptionsBase.maxSize}) are added as
85
+ * normal public members. (`max` and `maxBase` are read-only getters.)
86
+ * Changing any of these will alter the defaults for subsequent method calls,
87
+ * but is otherwise safe.
88
+ */
89
+ class LRUCache {
90
+ // properties coming in from the options of these, only max and maxSize
91
+ // really *need* to be protected. The rest can be modified, as they just
92
+ // set defaults for various methods.
93
+ #max;
94
+ #maxSize;
95
+ #dispose;
96
+ #disposeAfter;
97
+ #fetchMethod;
98
+ /**
99
+ * {@link LRUCache.OptionsBase.ttl}
100
+ */
101
+ ttl;
102
+ /**
103
+ * {@link LRUCache.OptionsBase.ttlResolution}
104
+ */
105
+ ttlResolution;
106
+ /**
107
+ * {@link LRUCache.OptionsBase.ttlAutopurge}
108
+ */
109
+ ttlAutopurge;
110
+ /**
111
+ * {@link LRUCache.OptionsBase.updateAgeOnGet}
112
+ */
113
+ updateAgeOnGet;
114
+ /**
115
+ * {@link LRUCache.OptionsBase.updateAgeOnHas}
116
+ */
117
+ updateAgeOnHas;
118
+ /**
119
+ * {@link LRUCache.OptionsBase.allowStale}
120
+ */
121
+ allowStale;
122
+ /**
123
+ * {@link LRUCache.OptionsBase.noDisposeOnSet}
124
+ */
125
+ noDisposeOnSet;
126
+ /**
127
+ * {@link LRUCache.OptionsBase.noUpdateTTL}
128
+ */
129
+ noUpdateTTL;
130
+ /**
131
+ * {@link LRUCache.OptionsBase.maxEntrySize}
132
+ */
133
+ maxEntrySize;
134
+ /**
135
+ * {@link LRUCache.OptionsBase.sizeCalculation}
136
+ */
137
+ sizeCalculation;
138
+ /**
139
+ * {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}
140
+ */
141
+ noDeleteOnFetchRejection;
142
+ /**
143
+ * {@link LRUCache.OptionsBase.noDeleteOnStaleGet}
144
+ */
145
+ noDeleteOnStaleGet;
146
+ /**
147
+ * {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}
148
+ */
149
+ allowStaleOnFetchAbort;
150
+ /**
151
+ * {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}
152
+ */
153
+ allowStaleOnFetchRejection;
154
+ /**
155
+ * {@link LRUCache.OptionsBase.ignoreFetchAbort}
156
+ */
157
+ ignoreFetchAbort;
158
+ // computed properties
159
+ #size;
160
+ #calculatedSize;
161
+ #keyMap;
162
+ #keyList;
163
+ #valList;
164
+ #next;
165
+ #prev;
166
+ #head;
167
+ #tail;
168
+ #free;
169
+ #disposed;
170
+ #sizes;
171
+ #starts;
172
+ #ttls;
173
+ #hasDispose;
174
+ #hasFetchMethod;
175
+ #hasDisposeAfter;
176
+ /**
177
+ * Do not call this method unless you need to inspect the
178
+ * inner workings of the cache. If anything returned by this
179
+ * object is modified in any way, strange breakage may occur.
180
+ *
181
+ * These fields are private for a reason!
182
+ *
183
+ * @internal
184
+ */
185
+ static unsafeExposeInternals(c) {
186
+ return {
187
+ // properties
188
+ starts: c.#starts,
189
+ ttls: c.#ttls,
190
+ sizes: c.#sizes,
191
+ keyMap: c.#keyMap,
192
+ keyList: c.#keyList,
193
+ valList: c.#valList,
194
+ next: c.#next,
195
+ prev: c.#prev,
196
+ get head() {
197
+ return c.#head;
198
+ },
199
+ get tail() {
200
+ return c.#tail;
201
+ },
202
+ free: c.#free,
203
+ // methods
204
+ isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
205
+ backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
206
+ moveToTail: (index) => c.#moveToTail(index),
207
+ indexes: (options) => c.#indexes(options),
208
+ rindexes: (options) => c.#rindexes(options),
209
+ isStale: (index) => c.#isStale(index),
210
+ };
211
+ }
212
+ // Protected read-only members
213
+ /**
214
+ * {@link LRUCache.OptionsBase.max} (read-only)
215
+ */
216
+ get max() {
217
+ return this.#max;
218
+ }
219
+ /**
220
+ * {@link LRUCache.OptionsBase.maxSize} (read-only)
221
+ */
222
+ get maxSize() {
223
+ return this.#maxSize;
224
+ }
225
+ /**
226
+ * The total computed size of items in the cache (read-only)
227
+ */
228
+ get calculatedSize() {
229
+ return this.#calculatedSize;
230
+ }
231
+ /**
232
+ * The number of items stored in the cache (read-only)
233
+ */
234
+ get size() {
235
+ return this.#size;
236
+ }
237
+ /**
238
+ * {@link LRUCache.OptionsBase.fetchMethod} (read-only)
239
+ */
240
+ get fetchMethod() {
241
+ return this.#fetchMethod;
242
+ }
243
+ /**
244
+ * {@link LRUCache.OptionsBase.dispose} (read-only)
245
+ */
246
+ get dispose() {
247
+ return this.#dispose;
248
+ }
249
+ /**
250
+ * {@link LRUCache.OptionsBase.disposeAfter} (read-only)
251
+ */
252
+ get disposeAfter() {
253
+ return this.#disposeAfter;
254
+ }
255
+ constructor(options) {
256
+ const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort, } = options;
257
+ if (max !== 0 && !isPosInt(max)) {
258
+ throw new TypeError('max option must be a nonnegative integer');
259
+ }
260
+ const UintArray = max ? getUintArray(max) : Array;
261
+ if (!UintArray) {
262
+ throw new Error('invalid max value: ' + max);
263
+ }
264
+ this.#max = max;
265
+ this.#maxSize = maxSize;
266
+ this.maxEntrySize = maxEntrySize || this.#maxSize;
267
+ this.sizeCalculation = sizeCalculation;
268
+ if (this.sizeCalculation) {
269
+ if (!this.#maxSize && !this.maxEntrySize) {
270
+ throw new TypeError('cannot set sizeCalculation without setting maxSize or maxEntrySize');
271
+ }
272
+ if (typeof this.sizeCalculation !== 'function') {
273
+ throw new TypeError('sizeCalculation set to non-function');
274
+ }
275
+ }
276
+ if (fetchMethod !== undefined &&
277
+ typeof fetchMethod !== 'function') {
278
+ throw new TypeError('fetchMethod must be a function if specified');
279
+ }
280
+ this.#fetchMethod = fetchMethod;
281
+ this.#hasFetchMethod = !!fetchMethod;
282
+ this.#keyMap = new Map();
283
+ this.#keyList = new Array(max).fill(undefined);
284
+ this.#valList = new Array(max).fill(undefined);
285
+ this.#next = new UintArray(max);
286
+ this.#prev = new UintArray(max);
287
+ this.#head = 0;
288
+ this.#tail = 0;
289
+ this.#free = Stack.create(max);
290
+ this.#size = 0;
291
+ this.#calculatedSize = 0;
292
+ if (typeof dispose === 'function') {
293
+ this.#dispose = dispose;
294
+ }
295
+ if (typeof disposeAfter === 'function') {
296
+ this.#disposeAfter = disposeAfter;
297
+ this.#disposed = [];
298
+ }
299
+ else {
300
+ this.#disposeAfter = undefined;
301
+ this.#disposed = undefined;
302
+ }
303
+ this.#hasDispose = !!this.#dispose;
304
+ this.#hasDisposeAfter = !!this.#disposeAfter;
305
+ this.noDisposeOnSet = !!noDisposeOnSet;
306
+ this.noUpdateTTL = !!noUpdateTTL;
307
+ this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
308
+ this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
309
+ this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
310
+ this.ignoreFetchAbort = !!ignoreFetchAbort;
311
+ // NB: maxEntrySize is set to maxSize if it's set
312
+ if (this.maxEntrySize !== 0) {
313
+ if (this.#maxSize !== 0) {
314
+ if (!isPosInt(this.#maxSize)) {
315
+ throw new TypeError('maxSize must be a positive integer if specified');
316
+ }
317
+ }
318
+ if (!isPosInt(this.maxEntrySize)) {
319
+ throw new TypeError('maxEntrySize must be a positive integer if specified');
320
+ }
321
+ this.#initializeSizeTracking();
322
+ }
323
+ this.allowStale = !!allowStale;
324
+ this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
325
+ this.updateAgeOnGet = !!updateAgeOnGet;
326
+ this.updateAgeOnHas = !!updateAgeOnHas;
327
+ this.ttlResolution =
328
+ isPosInt(ttlResolution) || ttlResolution === 0
329
+ ? ttlResolution
330
+ : 1;
331
+ this.ttlAutopurge = !!ttlAutopurge;
332
+ this.ttl = ttl || 0;
333
+ if (this.ttl) {
334
+ if (!isPosInt(this.ttl)) {
335
+ throw new TypeError('ttl must be a positive integer if specified');
336
+ }
337
+ this.#initializeTTLTracking();
338
+ }
339
+ // do not allow completely unbounded caches
340
+ if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
341
+ throw new TypeError('At least one of max, maxSize, or ttl is required');
342
+ }
343
+ if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
344
+ const code = 'LRU_CACHE_UNBOUNDED';
345
+ if (shouldWarn(code)) {
346
+ warned.add(code);
347
+ const msg = 'TTL caching without ttlAutopurge, max, or maxSize can ' +
348
+ 'result in unbounded memory consumption.';
349
+ emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache);
350
+ }
351
+ }
352
+ }
353
+ /**
354
+ * Return the remaining TTL time for a given entry key
355
+ */
356
+ getRemainingTTL(key) {
357
+ return this.#keyMap.has(key) ? Infinity : 0;
358
+ }
359
+ #initializeTTLTracking() {
360
+ const ttls = new ZeroArray(this.#max);
361
+ const starts = new ZeroArray(this.#max);
362
+ this.#ttls = ttls;
363
+ this.#starts = starts;
364
+ this.#setItemTTL = (index, ttl, start = perf.now()) => {
365
+ starts[index] = ttl !== 0 ? start : 0;
366
+ ttls[index] = ttl;
367
+ if (ttl !== 0 && this.ttlAutopurge) {
368
+ const t = setTimeout(() => {
369
+ if (this.#isStale(index)) {
370
+ this.delete(this.#keyList[index]);
371
+ }
372
+ }, ttl + 1);
373
+ // unref() not supported on all platforms
374
+ /* c8 ignore start */
375
+ if (t.unref) {
376
+ t.unref();
377
+ }
378
+ /* c8 ignore stop */
379
+ }
380
+ };
381
+ this.#updateItemAge = index => {
382
+ starts[index] = ttls[index] !== 0 ? perf.now() : 0;
383
+ };
384
+ this.#statusTTL = (status, index) => {
385
+ if (ttls[index]) {
386
+ const ttl = ttls[index];
387
+ const start = starts[index];
388
+ status.ttl = ttl;
389
+ status.start = start;
390
+ status.now = cachedNow || getNow();
391
+ status.remainingTTL = status.now + ttl - start;
392
+ }
393
+ };
394
+ // debounce calls to perf.now() to 1s so we're not hitting
395
+ // that costly call repeatedly.
396
+ let cachedNow = 0;
397
+ const getNow = () => {
398
+ const n = perf.now();
399
+ if (this.ttlResolution > 0) {
400
+ cachedNow = n;
401
+ const t = setTimeout(() => (cachedNow = 0), this.ttlResolution);
402
+ // not available on all platforms
403
+ /* c8 ignore start */
404
+ if (t.unref) {
405
+ t.unref();
406
+ }
407
+ /* c8 ignore stop */
408
+ }
409
+ return n;
410
+ };
411
+ this.getRemainingTTL = key => {
412
+ const index = this.#keyMap.get(key);
413
+ if (index === undefined) {
414
+ return 0;
415
+ }
416
+ return ttls[index] === 0 || starts[index] === 0
417
+ ? Infinity
418
+ : starts[index] + ttls[index] - (cachedNow || getNow());
419
+ };
420
+ this.#isStale = index => {
421
+ return (ttls[index] !== 0 &&
422
+ starts[index] !== 0 &&
423
+ (cachedNow || getNow()) - starts[index] > ttls[index]);
424
+ };
425
+ }
426
+ // conditionally set private methods related to TTL
427
+ #updateItemAge = () => { };
428
+ #statusTTL = () => { };
429
+ #setItemTTL = () => { };
430
+ /* c8 ignore stop */
431
+ #isStale = () => false;
432
+ #initializeSizeTracking() {
433
+ const sizes = new ZeroArray(this.#max);
434
+ this.#calculatedSize = 0;
435
+ this.#sizes = sizes;
436
+ this.#removeItemSize = index => {
437
+ this.#calculatedSize -= sizes[index];
438
+ sizes[index] = 0;
439
+ };
440
+ this.#requireSize = (k, v, size, sizeCalculation) => {
441
+ // provisionally accept background fetches.
442
+ // actual value size will be checked when they return.
443
+ if (this.#isBackgroundFetch(v)) {
444
+ return 0;
445
+ }
446
+ if (!isPosInt(size)) {
447
+ if (sizeCalculation) {
448
+ if (typeof sizeCalculation !== 'function') {
449
+ throw new TypeError('sizeCalculation must be a function');
450
+ }
451
+ size = sizeCalculation(v, k);
452
+ if (!isPosInt(size)) {
453
+ throw new TypeError('sizeCalculation return invalid (expect positive integer)');
454
+ }
455
+ }
456
+ else {
457
+ throw new TypeError('invalid size value (must be positive integer). ' +
458
+ 'When maxSize or maxEntrySize is used, sizeCalculation ' +
459
+ 'or size must be set.');
460
+ }
461
+ }
462
+ return size;
463
+ };
464
+ this.#addItemSize = (index, size, status) => {
465
+ sizes[index] = size;
466
+ if (this.#maxSize) {
467
+ const maxSize = this.#maxSize - sizes[index];
468
+ while (this.#calculatedSize > maxSize) {
469
+ this.#evict(true);
470
+ }
471
+ }
472
+ this.#calculatedSize += sizes[index];
473
+ if (status) {
474
+ status.entrySize = size;
475
+ status.totalCalculatedSize = this.#calculatedSize;
476
+ }
477
+ };
478
+ }
479
+ #removeItemSize = _i => { };
480
+ #addItemSize = (_i, _s, _st) => { };
481
+ #requireSize = (_k, _v, size, sizeCalculation) => {
482
+ if (size || sizeCalculation) {
483
+ throw new TypeError('cannot set size without setting maxSize or maxEntrySize on cache');
484
+ }
485
+ return 0;
486
+ };
487
+ *#indexes({ allowStale = this.allowStale } = {}) {
488
+ if (this.#size) {
489
+ for (let i = this.#tail; true;) {
490
+ if (!this.#isValidIndex(i)) {
491
+ break;
492
+ }
493
+ if (allowStale || !this.#isStale(i)) {
494
+ yield i;
495
+ }
496
+ if (i === this.#head) {
497
+ break;
498
+ }
499
+ else {
500
+ i = this.#prev[i];
501
+ }
502
+ }
503
+ }
504
+ }
505
+ *#rindexes({ allowStale = this.allowStale } = {}) {
506
+ if (this.#size) {
507
+ for (let i = this.#head; true;) {
508
+ if (!this.#isValidIndex(i)) {
509
+ break;
510
+ }
511
+ if (allowStale || !this.#isStale(i)) {
512
+ yield i;
513
+ }
514
+ if (i === this.#tail) {
515
+ break;
516
+ }
517
+ else {
518
+ i = this.#next[i];
519
+ }
520
+ }
521
+ }
522
+ }
523
+ #isValidIndex(index) {
524
+ return (index !== undefined &&
525
+ this.#keyMap.get(this.#keyList[index]) === index);
526
+ }
527
+ /**
528
+ * Return a generator yielding `[key, value]` pairs,
529
+ * in order from most recently used to least recently used.
530
+ */
531
+ *entries() {
532
+ for (const i of this.#indexes()) {
533
+ if (this.#valList[i] !== undefined &&
534
+ this.#keyList[i] !== undefined &&
535
+ !this.#isBackgroundFetch(this.#valList[i])) {
536
+ yield [this.#keyList[i], this.#valList[i]];
537
+ }
538
+ }
539
+ }
540
+ /**
541
+ * Inverse order version of {@link LRUCache.entries}
542
+ *
543
+ * Return a generator yielding `[key, value]` pairs,
544
+ * in order from least recently used to most recently used.
545
+ */
546
+ *rentries() {
547
+ for (const i of this.#rindexes()) {
548
+ if (this.#valList[i] !== undefined &&
549
+ this.#keyList[i] !== undefined &&
550
+ !this.#isBackgroundFetch(this.#valList[i])) {
551
+ yield [this.#keyList[i], this.#valList[i]];
552
+ }
553
+ }
554
+ }
555
+ /**
556
+ * Return a generator yielding the keys in the cache,
557
+ * in order from most recently used to least recently used.
558
+ */
559
+ *keys() {
560
+ for (const i of this.#indexes()) {
561
+ const k = this.#keyList[i];
562
+ if (k !== undefined &&
563
+ !this.#isBackgroundFetch(this.#valList[i])) {
564
+ yield k;
565
+ }
566
+ }
567
+ }
568
+ /**
569
+ * Inverse order version of {@link LRUCache.keys}
570
+ *
571
+ * Return a generator yielding the keys in the cache,
572
+ * in order from least recently used to most recently used.
573
+ */
574
+ *rkeys() {
575
+ for (const i of this.#rindexes()) {
576
+ const k = this.#keyList[i];
577
+ if (k !== undefined &&
578
+ !this.#isBackgroundFetch(this.#valList[i])) {
579
+ yield k;
580
+ }
581
+ }
582
+ }
583
+ /**
584
+ * Return a generator yielding the values in the cache,
585
+ * in order from most recently used to least recently used.
586
+ */
587
+ *values() {
588
+ for (const i of this.#indexes()) {
589
+ const v = this.#valList[i];
590
+ if (v !== undefined &&
591
+ !this.#isBackgroundFetch(this.#valList[i])) {
592
+ yield this.#valList[i];
593
+ }
594
+ }
595
+ }
596
+ /**
597
+ * Inverse order version of {@link LRUCache.values}
598
+ *
599
+ * Return a generator yielding the values in the cache,
600
+ * in order from least recently used to most recently used.
601
+ */
602
+ *rvalues() {
603
+ for (const i of this.#rindexes()) {
604
+ const v = this.#valList[i];
605
+ if (v !== undefined &&
606
+ !this.#isBackgroundFetch(this.#valList[i])) {
607
+ yield this.#valList[i];
608
+ }
609
+ }
610
+ }
611
+ /**
612
+ * Iterating over the cache itself yields the same results as
613
+ * {@link LRUCache.entries}
614
+ */
615
+ [Symbol.iterator]() {
616
+ return this.entries();
617
+ }
618
+ /**
619
+ * Find a value for which the supplied fn method returns a truthy value,
620
+ * similar to Array.find(). fn is called as fn(value, key, cache).
621
+ */
622
+ find(fn, getOptions = {}) {
623
+ for (const i of this.#indexes()) {
624
+ const v = this.#valList[i];
625
+ const value = this.#isBackgroundFetch(v)
626
+ ? v.__staleWhileFetching
627
+ : v;
628
+ if (value === undefined)
629
+ continue;
630
+ if (fn(value, this.#keyList[i], this)) {
631
+ return this.get(this.#keyList[i], getOptions);
632
+ }
633
+ }
634
+ }
635
+ /**
636
+ * Call the supplied function on each item in the cache, in order from
637
+ * most recently used to least recently used. fn is called as
638
+ * fn(value, key, cache). Does not update age or recenty of use.
639
+ * Does not iterate over stale values.
640
+ */
641
+ forEach(fn, thisp = this) {
642
+ for (const i of this.#indexes()) {
643
+ const v = this.#valList[i];
644
+ const value = this.#isBackgroundFetch(v)
645
+ ? v.__staleWhileFetching
646
+ : v;
647
+ if (value === undefined)
648
+ continue;
649
+ fn.call(thisp, value, this.#keyList[i], this);
650
+ }
651
+ }
652
+ /**
653
+ * The same as {@link LRUCache.forEach} but items are iterated over in
654
+ * reverse order. (ie, less recently used items are iterated over first.)
655
+ */
656
+ rforEach(fn, thisp = this) {
657
+ for (const i of this.#rindexes()) {
658
+ const v = this.#valList[i];
659
+ const value = this.#isBackgroundFetch(v)
660
+ ? v.__staleWhileFetching
661
+ : v;
662
+ if (value === undefined)
663
+ continue;
664
+ fn.call(thisp, value, this.#keyList[i], this);
665
+ }
666
+ }
667
+ /**
668
+ * Delete any stale entries. Returns true if anything was removed,
669
+ * false otherwise.
670
+ */
671
+ purgeStale() {
672
+ let deleted = false;
673
+ for (const i of this.#rindexes({ allowStale: true })) {
674
+ if (this.#isStale(i)) {
675
+ this.delete(this.#keyList[i]);
676
+ deleted = true;
677
+ }
678
+ }
679
+ return deleted;
680
+ }
681
+ /**
682
+ * Return an array of [key, {@link LRUCache.Entry}] tuples which can be
683
+ * passed to cache.load()
684
+ */
685
+ dump() {
686
+ const arr = [];
687
+ for (const i of this.#indexes({ allowStale: true })) {
688
+ const key = this.#keyList[i];
689
+ const v = this.#valList[i];
690
+ const value = this.#isBackgroundFetch(v)
691
+ ? v.__staleWhileFetching
692
+ : v;
693
+ if (value === undefined || key === undefined)
694
+ continue;
695
+ const entry = { value };
696
+ if (this.#ttls && this.#starts) {
697
+ entry.ttl = this.#ttls[i];
698
+ // always dump the start relative to a portable timestamp
699
+ // it's ok for this to be a bit slow, it's a rare operation.
700
+ const age = perf.now() - this.#starts[i];
701
+ entry.start = Math.floor(Date.now() - age);
702
+ }
703
+ if (this.#sizes) {
704
+ entry.size = this.#sizes[i];
705
+ }
706
+ arr.unshift([key, entry]);
707
+ }
708
+ return arr;
709
+ }
710
+ /**
711
+ * Reset the cache and load in the items in entries in the order listed.
712
+ * Note that the shape of the resulting cache may be different if the
713
+ * same options are not used in both caches.
714
+ */
715
+ load(arr) {
716
+ this.clear();
717
+ for (const [key, entry] of arr) {
718
+ if (entry.start) {
719
+ // entry.start is a portable timestamp, but we may be using
720
+ // node's performance.now(), so calculate the offset, so that
721
+ // we get the intended remaining TTL, no matter how long it's
722
+ // been on ice.
723
+ //
724
+ // it's ok for this to be a bit slow, it's a rare operation.
725
+ const age = Date.now() - entry.start;
726
+ entry.start = perf.now() - age;
727
+ }
728
+ this.set(key, entry.value, entry);
729
+ }
730
+ }
731
+ /**
732
+ * Add a value to the cache.
733
+ */
734
+ set(k, v, setOptions = {}) {
735
+ const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status, } = setOptions;
736
+ let { noUpdateTTL = this.noUpdateTTL } = setOptions;
737
+ const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation);
738
+ // if the item doesn't fit, don't do anything
739
+ // NB: maxEntrySize set to maxSize by default
740
+ if (this.maxEntrySize && size > this.maxEntrySize) {
741
+ if (status) {
742
+ status.set = 'miss';
743
+ status.maxEntrySizeExceeded = true;
744
+ }
745
+ // have to delete, in case something is there already.
746
+ this.delete(k);
747
+ return this;
748
+ }
749
+ let index = this.#size === 0 ? undefined : this.#keyMap.get(k);
750
+ if (index === undefined) {
751
+ // addition
752
+ index = (this.#size === 0
753
+ ? this.#tail
754
+ : this.#free.length !== 0
755
+ ? this.#free.pop()
756
+ : this.#size === this.#max
757
+ ? this.#evict(false)
758
+ : this.#size);
759
+ this.#keyList[index] = k;
760
+ this.#valList[index] = v;
761
+ this.#keyMap.set(k, index);
762
+ this.#next[this.#tail] = index;
763
+ this.#prev[index] = this.#tail;
764
+ this.#tail = index;
765
+ this.#size++;
766
+ this.#addItemSize(index, size, status);
767
+ if (status)
768
+ status.set = 'add';
769
+ noUpdateTTL = false;
770
+ }
771
+ else {
772
+ // update
773
+ this.#moveToTail(index);
774
+ const oldVal = this.#valList[index];
775
+ if (v !== oldVal) {
776
+ if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
777
+ oldVal.__abortController.abort(new Error('replaced'));
778
+ }
779
+ else if (!noDisposeOnSet) {
780
+ if (this.#hasDispose) {
781
+ this.#dispose?.(oldVal, k, 'set');
782
+ }
783
+ if (this.#hasDisposeAfter) {
784
+ this.#disposed?.push([oldVal, k, 'set']);
785
+ }
786
+ }
787
+ this.#removeItemSize(index);
788
+ this.#addItemSize(index, size, status);
789
+ this.#valList[index] = v;
790
+ if (status) {
791
+ status.set = 'replace';
792
+ const oldValue = oldVal && this.#isBackgroundFetch(oldVal)
793
+ ? oldVal.__staleWhileFetching
794
+ : oldVal;
795
+ if (oldValue !== undefined)
796
+ status.oldValue = oldValue;
797
+ }
798
+ }
799
+ else if (status) {
800
+ status.set = 'update';
801
+ }
802
+ }
803
+ if (ttl !== 0 && !this.#ttls) {
804
+ this.#initializeTTLTracking();
805
+ }
806
+ if (this.#ttls) {
807
+ if (!noUpdateTTL) {
808
+ this.#setItemTTL(index, ttl, start);
809
+ }
810
+ if (status)
811
+ this.#statusTTL(status, index);
812
+ }
813
+ if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
814
+ const dt = this.#disposed;
815
+ let task;
816
+ while ((task = dt?.shift())) {
817
+ this.#disposeAfter?.(...task);
818
+ }
819
+ }
820
+ return this;
821
+ }
822
+ /**
823
+ * Evict the least recently used item, returning its value or
824
+ * `undefined` if cache is empty.
825
+ */
826
+ pop() {
827
+ try {
828
+ while (this.#size) {
829
+ const val = this.#valList[this.#head];
830
+ this.#evict(true);
831
+ if (this.#isBackgroundFetch(val)) {
832
+ if (val.__staleWhileFetching) {
833
+ return val.__staleWhileFetching;
834
+ }
835
+ }
836
+ else if (val !== undefined) {
837
+ return val;
838
+ }
839
+ }
840
+ }
841
+ finally {
842
+ if (this.#hasDisposeAfter && this.#disposed) {
843
+ const dt = this.#disposed;
844
+ let task;
845
+ while ((task = dt?.shift())) {
846
+ this.#disposeAfter?.(...task);
847
+ }
848
+ }
849
+ }
850
+ }
851
+ #evict(free) {
852
+ const head = this.#head;
853
+ const k = this.#keyList[head];
854
+ const v = this.#valList[head];
855
+ if (this.#hasFetchMethod && this.#isBackgroundFetch(v)) {
856
+ v.__abortController.abort(new Error('evicted'));
857
+ }
858
+ else if (this.#hasDispose || this.#hasDisposeAfter) {
859
+ if (this.#hasDispose) {
860
+ this.#dispose?.(v, k, 'evict');
861
+ }
862
+ if (this.#hasDisposeAfter) {
863
+ this.#disposed?.push([v, k, 'evict']);
864
+ }
865
+ }
866
+ this.#removeItemSize(head);
867
+ // if we aren't about to use the index, then null these out
868
+ if (free) {
869
+ this.#keyList[head] = undefined;
870
+ this.#valList[head] = undefined;
871
+ this.#free.push(head);
872
+ }
873
+ if (this.#size === 1) {
874
+ this.#head = this.#tail = 0;
875
+ this.#free.length = 0;
876
+ }
877
+ else {
878
+ this.#head = this.#next[head];
879
+ }
880
+ this.#keyMap.delete(k);
881
+ this.#size--;
882
+ return head;
883
+ }
884
+ /**
885
+ * Check if a key is in the cache, without updating the recency of use.
886
+ * Will return false if the item is stale, even though it is technically
887
+ * in the cache.
888
+ *
889
+ * Will not update item age unless
890
+ * {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
891
+ */
892
+ has(k, hasOptions = {}) {
893
+ const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
894
+ const index = this.#keyMap.get(k);
895
+ if (index !== undefined) {
896
+ const v = this.#valList[index];
897
+ if (this.#isBackgroundFetch(v) &&
898
+ v.__staleWhileFetching === undefined) {
899
+ return false;
900
+ }
901
+ if (!this.#isStale(index)) {
902
+ if (updateAgeOnHas) {
903
+ this.#updateItemAge(index);
904
+ }
905
+ if (status) {
906
+ status.has = 'hit';
907
+ this.#statusTTL(status, index);
908
+ }
909
+ return true;
910
+ }
911
+ else if (status) {
912
+ status.has = 'stale';
913
+ this.#statusTTL(status, index);
914
+ }
915
+ }
916
+ else if (status) {
917
+ status.has = 'miss';
918
+ }
919
+ return false;
920
+ }
921
+ /**
922
+ * Like {@link LRUCache#get} but doesn't update recency or delete stale
923
+ * items.
924
+ *
925
+ * Returns `undefined` if the item is stale, unless
926
+ * {@link LRUCache.OptionsBase.allowStale} is set.
927
+ */
928
+ peek(k, peekOptions = {}) {
929
+ const { allowStale = this.allowStale } = peekOptions;
930
+ const index = this.#keyMap.get(k);
931
+ if (index !== undefined &&
932
+ (allowStale || !this.#isStale(index))) {
933
+ const v = this.#valList[index];
934
+ // either stale and allowed, or forcing a refresh of non-stale value
935
+ return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
936
+ }
937
+ }
938
+ #backgroundFetch(k, index, options, context) {
939
+ const v = index === undefined ? undefined : this.#valList[index];
940
+ if (this.#isBackgroundFetch(v)) {
941
+ return v;
942
+ }
943
+ const ac = new AbortController();
944
+ const { signal } = options;
945
+ // when/if our AC signals, then stop listening to theirs.
946
+ signal?.addEventListener('abort', () => ac.abort(signal.reason), {
947
+ signal: ac.signal,
948
+ });
949
+ const fetchOpts = {
950
+ signal: ac.signal,
951
+ options,
952
+ context,
953
+ };
954
+ const cb = (v, updateCache = false) => {
955
+ const { aborted } = ac.signal;
956
+ const ignoreAbort = options.ignoreFetchAbort && v !== undefined;
957
+ if (options.status) {
958
+ if (aborted && !updateCache) {
959
+ options.status.fetchAborted = true;
960
+ options.status.fetchError = ac.signal.reason;
961
+ if (ignoreAbort)
962
+ options.status.fetchAbortIgnored = true;
963
+ }
964
+ else {
965
+ options.status.fetchResolved = true;
966
+ }
967
+ }
968
+ if (aborted && !ignoreAbort && !updateCache) {
969
+ return fetchFail(ac.signal.reason);
970
+ }
971
+ // either we didn't abort, and are still here, or we did, and ignored
972
+ const bf = p;
973
+ if (this.#valList[index] === p) {
974
+ if (v === undefined) {
975
+ if (bf.__staleWhileFetching) {
976
+ this.#valList[index] = bf.__staleWhileFetching;
977
+ }
978
+ else {
979
+ this.delete(k);
980
+ }
981
+ }
982
+ else {
983
+ if (options.status)
984
+ options.status.fetchUpdated = true;
985
+ this.set(k, v, fetchOpts.options);
986
+ }
987
+ }
988
+ return v;
989
+ };
990
+ const eb = (er) => {
991
+ if (options.status) {
992
+ options.status.fetchRejected = true;
993
+ options.status.fetchError = er;
994
+ }
995
+ return fetchFail(er);
996
+ };
997
+ const fetchFail = (er) => {
998
+ const { aborted } = ac.signal;
999
+ const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;
1000
+ const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
1001
+ const noDelete = allowStale || options.noDeleteOnFetchRejection;
1002
+ const bf = p;
1003
+ if (this.#valList[index] === p) {
1004
+ // if we allow stale on fetch rejections, then we need to ensure that
1005
+ // the stale value is not removed from the cache when the fetch fails.
1006
+ const del = !noDelete || bf.__staleWhileFetching === undefined;
1007
+ if (del) {
1008
+ this.delete(k);
1009
+ }
1010
+ else if (!allowStaleAborted) {
1011
+ // still replace the *promise* with the stale value,
1012
+ // since we are done with the promise at this point.
1013
+ // leave it untouched if we're still waiting for an
1014
+ // aborted background fetch that hasn't yet returned.
1015
+ this.#valList[index] = bf.__staleWhileFetching;
1016
+ }
1017
+ }
1018
+ if (allowStale) {
1019
+ if (options.status && bf.__staleWhileFetching !== undefined) {
1020
+ options.status.returnedStale = true;
1021
+ }
1022
+ return bf.__staleWhileFetching;
1023
+ }
1024
+ else if (bf.__returned === bf) {
1025
+ throw er;
1026
+ }
1027
+ };
1028
+ const pcall = (res, rej) => {
1029
+ const fmp = this.#fetchMethod?.(k, v, fetchOpts);
1030
+ if (fmp && fmp instanceof Promise) {
1031
+ fmp.then(v => res(v), rej);
1032
+ }
1033
+ // ignored, we go until we finish, regardless.
1034
+ // defer check until we are actually aborting,
1035
+ // so fetchMethod can override.
1036
+ ac.signal.addEventListener('abort', () => {
1037
+ if (!options.ignoreFetchAbort ||
1038
+ options.allowStaleOnFetchAbort) {
1039
+ res();
1040
+ // when it eventually resolves, update the cache.
1041
+ if (options.allowStaleOnFetchAbort) {
1042
+ res = v => cb(v, true);
1043
+ }
1044
+ }
1045
+ });
1046
+ };
1047
+ if (options.status)
1048
+ options.status.fetchDispatched = true;
1049
+ const p = new Promise(pcall).then(cb, eb);
1050
+ const bf = Object.assign(p, {
1051
+ __abortController: ac,
1052
+ __staleWhileFetching: v,
1053
+ __returned: undefined,
1054
+ });
1055
+ if (index === undefined) {
1056
+ // internal, don't expose status.
1057
+ this.set(k, bf, { ...fetchOpts.options, status: undefined });
1058
+ index = this.#keyMap.get(k);
1059
+ }
1060
+ else {
1061
+ this.#valList[index] = bf;
1062
+ }
1063
+ return bf;
1064
+ }
1065
+ #isBackgroundFetch(p) {
1066
+ if (!this.#hasFetchMethod)
1067
+ return false;
1068
+ const b = p;
1069
+ return (!!b &&
1070
+ b instanceof Promise &&
1071
+ b.hasOwnProperty('__staleWhileFetching') &&
1072
+ b.__abortController instanceof AbortController);
1073
+ }
1074
+ async fetch(k, fetchOptions = {}) {
1075
+ const {
1076
+ // get options
1077
+ allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet,
1078
+ // set options
1079
+ ttl = this.ttl, noDisposeOnSet = this.noDisposeOnSet, size = 0, sizeCalculation = this.sizeCalculation, noUpdateTTL = this.noUpdateTTL,
1080
+ // fetch exclusive options
1081
+ noDeleteOnFetchRejection = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection = this.allowStaleOnFetchRejection, ignoreFetchAbort = this.ignoreFetchAbort, allowStaleOnFetchAbort = this.allowStaleOnFetchAbort, context, forceRefresh = false, status, signal, } = fetchOptions;
1082
+ if (!this.#hasFetchMethod) {
1083
+ if (status)
1084
+ status.fetch = 'get';
1085
+ return this.get(k, {
1086
+ allowStale,
1087
+ updateAgeOnGet,
1088
+ noDeleteOnStaleGet,
1089
+ status,
1090
+ });
1091
+ }
1092
+ const options = {
1093
+ allowStale,
1094
+ updateAgeOnGet,
1095
+ noDeleteOnStaleGet,
1096
+ ttl,
1097
+ noDisposeOnSet,
1098
+ size,
1099
+ sizeCalculation,
1100
+ noUpdateTTL,
1101
+ noDeleteOnFetchRejection,
1102
+ allowStaleOnFetchRejection,
1103
+ allowStaleOnFetchAbort,
1104
+ ignoreFetchAbort,
1105
+ status,
1106
+ signal,
1107
+ };
1108
+ let index = this.#keyMap.get(k);
1109
+ if (index === undefined) {
1110
+ if (status)
1111
+ status.fetch = 'miss';
1112
+ const p = this.#backgroundFetch(k, index, options, context);
1113
+ return (p.__returned = p);
1114
+ }
1115
+ else {
1116
+ // in cache, maybe already fetching
1117
+ const v = this.#valList[index];
1118
+ if (this.#isBackgroundFetch(v)) {
1119
+ const stale = allowStale && v.__staleWhileFetching !== undefined;
1120
+ if (status) {
1121
+ status.fetch = 'inflight';
1122
+ if (stale)
1123
+ status.returnedStale = true;
1124
+ }
1125
+ return stale ? v.__staleWhileFetching : (v.__returned = v);
1126
+ }
1127
+ // if we force a refresh, that means do NOT serve the cached value,
1128
+ // unless we are already in the process of refreshing the cache.
1129
+ const isStale = this.#isStale(index);
1130
+ if (!forceRefresh && !isStale) {
1131
+ if (status)
1132
+ status.fetch = 'hit';
1133
+ this.#moveToTail(index);
1134
+ if (updateAgeOnGet) {
1135
+ this.#updateItemAge(index);
1136
+ }
1137
+ if (status)
1138
+ this.#statusTTL(status, index);
1139
+ return v;
1140
+ }
1141
+ // ok, it is stale or a forced refresh, and not already fetching.
1142
+ // refresh the cache.
1143
+ const p = this.#backgroundFetch(k, index, options, context);
1144
+ const hasStale = p.__staleWhileFetching !== undefined;
1145
+ const staleVal = hasStale && allowStale;
1146
+ if (status) {
1147
+ status.fetch = isStale ? 'stale' : 'refresh';
1148
+ if (staleVal && isStale)
1149
+ status.returnedStale = true;
1150
+ }
1151
+ return staleVal ? p.__staleWhileFetching : (p.__returned = p);
1152
+ }
1153
+ }
1154
+ /**
1155
+ * Return a value from the cache. Will update the recency of the cache
1156
+ * entry found.
1157
+ *
1158
+ * If the key is not found, get() will return `undefined`.
1159
+ */
1160
+ get(k, getOptions = {}) {
1161
+ const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status, } = getOptions;
1162
+ const index = this.#keyMap.get(k);
1163
+ if (index !== undefined) {
1164
+ const value = this.#valList[index];
1165
+ const fetching = this.#isBackgroundFetch(value);
1166
+ if (status)
1167
+ this.#statusTTL(status, index);
1168
+ if (this.#isStale(index)) {
1169
+ if (status)
1170
+ status.get = 'stale';
1171
+ // delete only if not an in-flight background fetch
1172
+ if (!fetching) {
1173
+ if (!noDeleteOnStaleGet) {
1174
+ this.delete(k);
1175
+ }
1176
+ if (status && allowStale)
1177
+ status.returnedStale = true;
1178
+ return allowStale ? value : undefined;
1179
+ }
1180
+ else {
1181
+ if (status &&
1182
+ allowStale &&
1183
+ value.__staleWhileFetching !== undefined) {
1184
+ status.returnedStale = true;
1185
+ }
1186
+ return allowStale ? value.__staleWhileFetching : undefined;
1187
+ }
1188
+ }
1189
+ else {
1190
+ if (status)
1191
+ status.get = 'hit';
1192
+ // if we're currently fetching it, we don't actually have it yet
1193
+ // it's not stale, which means this isn't a staleWhileRefetching.
1194
+ // If it's not stale, and fetching, AND has a __staleWhileFetching
1195
+ // value, then that means the user fetched with {forceRefresh:true},
1196
+ // so it's safe to return that value.
1197
+ if (fetching) {
1198
+ return value.__staleWhileFetching;
1199
+ }
1200
+ this.#moveToTail(index);
1201
+ if (updateAgeOnGet) {
1202
+ this.#updateItemAge(index);
1203
+ }
1204
+ return value;
1205
+ }
1206
+ }
1207
+ else if (status) {
1208
+ status.get = 'miss';
1209
+ }
1210
+ }
1211
+ #connect(p, n) {
1212
+ this.#prev[n] = p;
1213
+ this.#next[p] = n;
1214
+ }
1215
+ #moveToTail(index) {
1216
+ // if tail already, nothing to do
1217
+ // if head, move head to next[index]
1218
+ // else
1219
+ // move next[prev[index]] to next[index] (head has no prev)
1220
+ // move prev[next[index]] to prev[index]
1221
+ // prev[index] = tail
1222
+ // next[tail] = index
1223
+ // tail = index
1224
+ if (index !== this.#tail) {
1225
+ if (index === this.#head) {
1226
+ this.#head = this.#next[index];
1227
+ }
1228
+ else {
1229
+ this.#connect(this.#prev[index], this.#next[index]);
1230
+ }
1231
+ this.#connect(this.#tail, index);
1232
+ this.#tail = index;
1233
+ }
1234
+ }
1235
+ /**
1236
+ * Deletes a key out of the cache.
1237
+ * Returns true if the key was deleted, false otherwise.
1238
+ */
1239
+ delete(k) {
1240
+ let deleted = false;
1241
+ if (this.#size !== 0) {
1242
+ const index = this.#keyMap.get(k);
1243
+ if (index !== undefined) {
1244
+ deleted = true;
1245
+ if (this.#size === 1) {
1246
+ this.clear();
1247
+ }
1248
+ else {
1249
+ this.#removeItemSize(index);
1250
+ const v = this.#valList[index];
1251
+ if (this.#isBackgroundFetch(v)) {
1252
+ v.__abortController.abort(new Error('deleted'));
1253
+ }
1254
+ else if (this.#hasDispose || this.#hasDisposeAfter) {
1255
+ if (this.#hasDispose) {
1256
+ this.#dispose?.(v, k, 'delete');
1257
+ }
1258
+ if (this.#hasDisposeAfter) {
1259
+ this.#disposed?.push([v, k, 'delete']);
1260
+ }
1261
+ }
1262
+ this.#keyMap.delete(k);
1263
+ this.#keyList[index] = undefined;
1264
+ this.#valList[index] = undefined;
1265
+ if (index === this.#tail) {
1266
+ this.#tail = this.#prev[index];
1267
+ }
1268
+ else if (index === this.#head) {
1269
+ this.#head = this.#next[index];
1270
+ }
1271
+ else {
1272
+ this.#next[this.#prev[index]] = this.#next[index];
1273
+ this.#prev[this.#next[index]] = this.#prev[index];
1274
+ }
1275
+ this.#size--;
1276
+ this.#free.push(index);
1277
+ }
1278
+ }
1279
+ }
1280
+ if (this.#hasDisposeAfter && this.#disposed?.length) {
1281
+ const dt = this.#disposed;
1282
+ let task;
1283
+ while ((task = dt?.shift())) {
1284
+ this.#disposeAfter?.(...task);
1285
+ }
1286
+ }
1287
+ return deleted;
1288
+ }
1289
+ /**
1290
+ * Clear the cache entirely, throwing away all values.
1291
+ */
1292
+ clear() {
1293
+ for (const index of this.#rindexes({ allowStale: true })) {
1294
+ const v = this.#valList[index];
1295
+ if (this.#isBackgroundFetch(v)) {
1296
+ v.__abortController.abort(new Error('deleted'));
1297
+ }
1298
+ else {
1299
+ const k = this.#keyList[index];
1300
+ if (this.#hasDispose) {
1301
+ this.#dispose?.(v, k, 'delete');
1302
+ }
1303
+ if (this.#hasDisposeAfter) {
1304
+ this.#disposed?.push([v, k, 'delete']);
1305
+ }
1306
+ }
1307
+ }
1308
+ this.#keyMap.clear();
1309
+ this.#valList.fill(undefined);
1310
+ this.#keyList.fill(undefined);
1311
+ if (this.#ttls && this.#starts) {
1312
+ this.#ttls.fill(0);
1313
+ this.#starts.fill(0);
1314
+ }
1315
+ if (this.#sizes) {
1316
+ this.#sizes.fill(0);
1317
+ }
1318
+ this.#head = 0;
1319
+ this.#tail = 0;
1320
+ this.#free.length = 0;
1321
+ this.#calculatedSize = 0;
1322
+ this.#size = 0;
1323
+ if (this.#hasDisposeAfter && this.#disposed) {
1324
+ const dt = this.#disposed;
1325
+ let task;
1326
+ while ((task = dt?.shift())) {
1327
+ this.#disposeAfter?.(...task);
1328
+ }
1329
+ }
1330
+ }
1331
+ }
1332
+ exports.LRUCache = LRUCache;
1333
+ exports.default = LRUCache;
1334
+ //# sourceMappingURL=index.js.map