piclaw 0.0.19 → 0.0.21

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 (270) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/public/assets/defult-D5RLDUrI.js +1 -0
  3. package/.output/public/assets/{dist-CMBqBOCp.js → dist-BH_oa-kv.js} +1 -1
  4. package/.output/public/assets/index-7JvURuHy.js +204 -0
  5. package/.output/public/assets/index-K43slwjJ.css +1 -0
  6. package/.output/public/index.html +11 -2
  7. package/.output/server/_...path_.get.mjs +16 -0
  8. package/.output/server/_chunks/app.mjs +261 -181
  9. package/.output/server/_chunks/browser.mjs +4 -1
  10. package/.output/server/_chunks/config.mjs +4 -0
  11. package/.output/server/_chunks/db.mjs +32 -28
  12. package/.output/server/_chunks/device-bus.mjs +123 -0
  13. package/.output/server/_chunks/dummy.mjs +1 -1
  14. package/.output/server/_chunks/logger.mjs +23 -0
  15. package/.output/server/_chunks/login.mjs +1 -1
  16. package/.output/server/_chunks/notes.mjs +1 -3
  17. package/.output/server/_chunks/renderer-template.mjs +1 -1
  18. package/.output/server/_chunks/sandbox.mjs +217 -0
  19. package/.output/server/_chunks/server.mjs +2302 -122
  20. package/.output/server/_chunks/terminal.mjs +63 -8
  21. package/.output/server/_chunks/uploads.mjs +60 -0
  22. package/.output/server/_chunks/virtual.mjs +192 -54
  23. package/.output/server/_id_.delete.mjs +5 -2
  24. package/.output/server/_id_.patch.mjs +2 -0
  25. package/.output/server/_id_2.delete.mjs +8 -0
  26. package/.output/server/_jid_.delete.mjs +5 -2
  27. package/.output/server/_jid_.patch.mjs +37 -4
  28. package/.output/server/_jid_2.delete.mjs +5 -2
  29. package/.output/server/_libs/@acemir/cssom+[...].mjs +2269 -1137
  30. package/.output/server/_libs/@google/genai.mjs +337 -273
  31. package/.output/server/_libs/@mariozechner/pi-agent-core+[...].mjs +381 -2073
  32. package/.output/server/_libs/@mariozechner/pi-coding-agent+[...].mjs +231 -131
  33. package/.output/server/_libs/_.mjs +3 -2
  34. package/.output/server/_libs/_10.mjs +2 -4
  35. package/.output/server/_libs/_11.mjs +2 -4
  36. package/.output/server/_libs/_12.mjs +2 -3
  37. package/.output/server/_libs/_13.mjs +2 -3
  38. package/.output/server/_libs/_14.mjs +2 -4
  39. package/.output/server/_libs/_15.mjs +2 -4
  40. package/.output/server/_libs/_16.mjs +2 -3
  41. package/.output/server/_libs/_17.mjs +2 -4
  42. package/.output/server/_libs/_18.mjs +2 -2
  43. package/.output/server/_libs/_19.mjs +2 -2
  44. package/.output/server/_libs/_2.mjs +3 -3
  45. package/.output/server/_libs/_20.mjs +2 -2
  46. package/.output/server/_libs/_21.mjs +2 -2
  47. package/.output/server/_libs/_22.mjs +2 -2
  48. package/.output/server/_libs/_23.mjs +2 -2
  49. package/.output/server/_libs/_24.mjs +2 -2
  50. package/.output/server/_libs/_25.mjs +2 -2
  51. package/.output/server/_libs/_26.mjs +2 -2
  52. package/.output/server/_libs/_27.mjs +2 -2
  53. package/.output/server/_libs/_28.mjs +2 -2
  54. package/.output/server/_libs/_29.mjs +2 -2
  55. package/.output/server/_libs/_3.mjs +3 -3
  56. package/.output/server/_libs/_30.mjs +2 -2
  57. package/.output/server/_libs/_31.mjs +2 -2
  58. package/.output/server/_libs/_32.mjs +2 -2
  59. package/.output/server/_libs/_33.mjs +2 -2
  60. package/.output/server/_libs/_34.mjs +2 -2
  61. package/.output/server/_libs/_35.mjs +2 -2
  62. package/.output/server/_libs/_36.mjs +2 -2
  63. package/.output/server/_libs/_37.mjs +2 -2
  64. package/.output/server/_libs/_38.mjs +2 -2
  65. package/.output/server/_libs/_39.mjs +2 -2
  66. package/.output/server/_libs/_4.mjs +4 -3
  67. package/.output/server/_libs/_40.mjs +2 -2
  68. package/.output/server/_libs/_41.mjs +2 -2
  69. package/.output/server/_libs/_42.mjs +2 -2
  70. package/.output/server/_libs/_43.mjs +2 -2
  71. package/.output/server/_libs/_44.mjs +2 -2
  72. package/.output/server/_libs/_45.mjs +2 -2
  73. package/.output/server/_libs/_46.mjs +2 -2
  74. package/.output/server/_libs/_47.mjs +2 -2
  75. package/.output/server/_libs/_48.mjs +2 -2
  76. package/.output/server/_libs/_49.mjs +2 -2
  77. package/.output/server/_libs/_5.mjs +2 -3
  78. package/.output/server/_libs/_50.mjs +2 -2
  79. package/.output/server/_libs/_51.mjs +2 -2
  80. package/.output/server/_libs/_52.mjs +2 -2
  81. package/.output/server/_libs/_53.mjs +2 -2
  82. package/.output/server/_libs/_54.mjs +2 -2
  83. package/.output/server/_libs/_55.mjs +2 -2
  84. package/.output/server/_libs/_56.mjs +2 -2
  85. package/.output/server/_libs/_57.mjs +2 -2
  86. package/.output/server/_libs/_58.mjs +2 -2
  87. package/.output/server/_libs/_59.mjs +2 -2
  88. package/.output/server/_libs/_6.mjs +2 -3
  89. package/.output/server/_libs/_60.mjs +2 -2
  90. package/.output/server/_libs/_61.mjs +2 -2
  91. package/.output/server/_libs/_62.mjs +2 -2
  92. package/.output/server/_libs/_63.mjs +2 -2
  93. package/.output/server/_libs/_64.mjs +2 -2
  94. package/.output/server/_libs/_65.mjs +2 -2
  95. package/.output/server/_libs/_66.mjs +2 -2
  96. package/.output/server/_libs/_67.mjs +2 -2
  97. package/.output/server/_libs/_68.mjs +2 -2
  98. package/.output/server/_libs/_69.mjs +2 -2
  99. package/.output/server/_libs/_7.mjs +2 -5
  100. package/.output/server/_libs/_70.mjs +2 -2
  101. package/.output/server/_libs/_71.mjs +2 -2
  102. package/.output/server/_libs/_72.mjs +2 -2
  103. package/.output/server/_libs/_73.mjs +2 -2
  104. package/.output/server/_libs/_74.mjs +2 -2
  105. package/.output/server/_libs/_75.mjs +2 -2
  106. package/.output/server/_libs/_76.mjs +2 -2
  107. package/.output/server/_libs/_77.mjs +2 -2
  108. package/.output/server/_libs/_78.mjs +2 -2
  109. package/.output/server/_libs/_79.mjs +2 -2
  110. package/.output/server/_libs/_8.mjs +2 -3
  111. package/.output/server/_libs/_80.mjs +2 -2
  112. package/.output/server/_libs/_81.mjs +2 -2
  113. package/.output/server/_libs/_82.mjs +2 -2
  114. package/.output/server/_libs/_83.mjs +2 -2
  115. package/.output/server/_libs/_84.mjs +2 -2
  116. package/.output/server/_libs/_85.mjs +2 -2
  117. package/.output/server/_libs/_86.mjs +2 -2
  118. package/.output/server/_libs/_87.mjs +2 -2
  119. package/.output/server/_libs/_88.mjs +2 -2
  120. package/.output/server/_libs/_89.mjs +2 -2
  121. package/.output/server/_libs/_9.mjs +2 -4
  122. package/.output/server/_libs/_90.mjs +5 -2
  123. package/.output/server/_libs/_91.mjs +3 -2
  124. package/.output/server/_libs/_92.mjs +2 -2
  125. package/.output/server/_libs/_93.mjs +2 -2
  126. package/.output/server/_libs/_94.mjs +2 -2
  127. package/.output/server/_libs/agent-base.mjs +1 -1
  128. package/.output/server/_libs/cheerio+[...].mjs +1 -1
  129. package/.output/server/_libs/data-uri-to-buffer.mjs +2 -67
  130. package/.output/server/_libs/data-urls+[...].mjs +1 -1
  131. package/.output/server/_libs/diff.mjs +1 -1
  132. package/.output/server/_libs/exodus__bytes.mjs +99 -81
  133. package/.output/server/_libs/fetch-blob+node-domexception.mjs +1 -1
  134. package/.output/server/_libs/h3+rou3+srvx.mjs +34 -4
  135. package/.output/server/_libs/html-encoding-sniffer.mjs +1 -1
  136. package/.output/server/_libs/https-proxy-agent.mjs +2 -2
  137. package/.output/server/_libs/jsdom.mjs +1 -1
  138. package/.output/server/_libs/just-bash+[...].mjs +4676 -3916
  139. package/.output/server/_libs/mariozechner__jiti.mjs +1 -1
  140. package/.output/server/_libs/mariozechner__pi-ai.mjs +1472 -0
  141. package/.output/server/_libs/md4x.mjs +1 -1
  142. package/.output/server/_libs/mime.mjs +838 -1
  143. package/.output/server/_libs/node-fetch.mjs +4 -4
  144. package/.output/server/_libs/node-liblzma.mjs +1 -1
  145. package/.output/server/_libs/silvia-odwyer__photon-node.mjs +1 -1
  146. package/.output/server/_routes/api/auth/approve.mjs +2 -0
  147. package/.output/server/_routes/api/auth/revoke.mjs +2 -0
  148. package/.output/server/_routes/api/auth/status.mjs +25 -6
  149. package/.output/server/_routes/api/browser2.mjs +1 -1
  150. package/.output/server/_routes/api/config2.mjs +2 -0
  151. package/.output/server/_routes/api/device_events.mjs +36 -0
  152. package/.output/server/_routes/api/files/groups.mjs +1 -2
  153. package/.output/server/_routes/api/files/raw.mjs +1 -1
  154. package/.output/server/_routes/api/groups.mjs +5 -3
  155. package/.output/server/_routes/api/groups2.mjs +18 -6
  156. package/.output/server/_routes/api/health.mjs +1 -2
  157. package/.output/server/_routes/api/messages.mjs +7 -1
  158. package/.output/server/_routes/api/notes/delete.mjs +4 -1
  159. package/.output/server/_routes/api/notes/write.mjs +2 -0
  160. package/.output/server/_routes/api/ntfy/setup.mjs +8 -0
  161. package/.output/server/_routes/api/pi/apikey.mjs +3 -2
  162. package/.output/server/_routes/api/pi/apikey_providers.mjs +1 -2
  163. package/.output/server/_routes/api/pi/commands.mjs +13 -3
  164. package/.output/server/_routes/api/pi/login/events.mjs +0 -1
  165. package/.output/server/_routes/api/pi/login/respond.mjs +2 -1
  166. package/.output/server/_routes/api/pi/login.mjs +1 -2
  167. package/.output/server/_routes/api/pi/logout.mjs +2 -1
  168. package/.output/server/_routes/api/pi/models.mjs +1 -2
  169. package/.output/server/_routes/api/pi/models_config2.mjs +2 -0
  170. package/.output/server/_routes/api/pi/settings2.mjs +2 -0
  171. package/.output/server/_routes/api/pi/status.mjs +1 -2
  172. package/.output/server/_routes/api/proxy.mjs +19 -1
  173. package/.output/server/_routes/api/sandbox.mjs +26 -0
  174. package/.output/server/_routes/api/sandbox2.mjs +17 -0
  175. package/.output/server/_routes/api/send.mjs +26 -18
  176. package/.output/server/_routes/api/status.mjs +1 -3
  177. package/.output/server/_routes/api/stop.mjs +11 -0
  178. package/.output/server/_routes/api/store/plugins.mjs +75 -0
  179. package/.output/server/_routes/api/store/skills.mjs +11 -0
  180. package/.output/server/_routes/api/tasks2.mjs +3 -2
  181. package/.output/server/_routes/api/telegram/setup.mjs +5 -2
  182. package/.output/server/_routes/api/telegram/status.mjs +1 -2
  183. package/.output/server/_routes/api/terminal2.mjs +2 -1
  184. package/.output/server/_routes/api/tunnel/setup.mjs +4 -2
  185. package/.output/server/_runtime.mjs +1 -2
  186. package/.output/server/_utils.mjs +10 -2
  187. package/.output/server/index.mjs +1 -1
  188. package/.output/server/node_modules/amdefine/amdefine.js +301 -0
  189. package/.output/server/node_modules/amdefine/package.json +16 -0
  190. package/.output/server/node_modules/compressjs/lib/BWT.js +420 -0
  191. package/.output/server/node_modules/compressjs/lib/BWTC.js +234 -0
  192. package/.output/server/node_modules/compressjs/lib/BitStream.js +108 -0
  193. package/.output/server/node_modules/compressjs/lib/Bzip2.js +936 -0
  194. package/.output/server/node_modules/compressjs/lib/CRC32.js +105 -0
  195. package/.output/server/node_modules/compressjs/lib/Context1Model.js +56 -0
  196. package/.output/server/node_modules/compressjs/lib/DefSumModel.js +152 -0
  197. package/.output/server/node_modules/compressjs/lib/DeflateDistanceModel.js +55 -0
  198. package/.output/server/node_modules/compressjs/lib/Dmc.js +197 -0
  199. package/.output/server/node_modules/compressjs/lib/DummyRangeCoder.js +81 -0
  200. package/.output/server/node_modules/compressjs/lib/FenwickModel.js +194 -0
  201. package/.output/server/node_modules/compressjs/lib/Huffman.js +514 -0
  202. package/.output/server/node_modules/compressjs/lib/HuffmanAllocator.js +227 -0
  203. package/.output/server/node_modules/compressjs/lib/LogDistanceModel.js +46 -0
  204. package/.output/server/node_modules/compressjs/lib/Lzjb.js +300 -0
  205. package/.output/server/node_modules/compressjs/lib/LzjbR.js +241 -0
  206. package/.output/server/node_modules/compressjs/lib/Lzp3.js +273 -0
  207. package/.output/server/node_modules/compressjs/lib/MTFModel.js +208 -0
  208. package/.output/server/node_modules/compressjs/lib/NoModel.js +46 -0
  209. package/.output/server/node_modules/compressjs/lib/PPM.js +343 -0
  210. package/.output/server/node_modules/compressjs/lib/RangeCoder.js +238 -0
  211. package/.output/server/node_modules/compressjs/lib/Simple.js +111 -0
  212. package/.output/server/node_modules/compressjs/lib/Stream.js +53 -0
  213. package/.output/server/node_modules/compressjs/lib/Util.js +324 -0
  214. package/.output/server/node_modules/compressjs/lib/freeze.js +14 -0
  215. package/.output/server/node_modules/compressjs/main.js +29 -0
  216. package/.output/server/node_modules/compressjs/package.json +35 -0
  217. package/.output/server/package.json +2 -1
  218. package/README.md +10 -1
  219. package/lib/index.d.mts +1 -0
  220. package/lib/index.mjs +1 -0
  221. package/lib/piclaw.mjs +100 -0
  222. package/lib/utils.mjs +96 -0
  223. package/package.json +16 -11
  224. package/.output/public/assets/defult-CMO6TZ5a.js +0 -1
  225. package/.output/public/assets/index-jdnbJw-M.js +0 -204
  226. package/.output/public/assets/index-ooXrRwgl.css +0 -1
  227. package/.output/server/_chunks/commands.mjs +0 -282
  228. package/.output/server/_chunks/pi.mjs +0 -202
  229. package/.output/server/_chunks/session.mjs +0 -1114
  230. package/.output/server/_libs/@aws-crypto/crc32+[...].mjs +0 -299
  231. package/.output/server/_libs/@aws-sdk/client-bedrock-runtime+[...].mjs +0 -17828
  232. package/.output/server/_libs/@aws-sdk/credential-provider-http+[...].mjs +0 -122
  233. package/.output/server/_libs/@aws-sdk/credential-provider-ini+[...].mjs +0 -417
  234. package/.output/server/_libs/@aws-sdk/credential-provider-process+[...].mjs +0 -54
  235. package/.output/server/_libs/@aws-sdk/credential-provider-sso+[...].mjs +0 -1151
  236. package/.output/server/_libs/@aws-sdk/credential-provider-web-identity+[...].mjs +0 -50
  237. package/.output/server/_libs/@smithy/credential-provider-imds+[...].mjs +0 -369
  238. package/.output/server/_libs/@tootallnate/quickjs-emscripten+[...].mjs +0 -3011
  239. package/.output/server/_libs/_100.mjs +0 -2
  240. package/.output/server/_libs/_101.mjs +0 -2
  241. package/.output/server/_libs/_102.mjs +0 -5
  242. package/.output/server/_libs/_103.mjs +0 -3
  243. package/.output/server/_libs/_104.mjs +0 -2
  244. package/.output/server/_libs/_105.mjs +0 -3
  245. package/.output/server/_libs/_106.mjs +0 -2
  246. package/.output/server/_libs/_107.mjs +0 -2
  247. package/.output/server/_libs/_95.mjs +0 -2
  248. package/.output/server/_libs/_96.mjs +0 -2
  249. package/.output/server/_libs/_97.mjs +0 -2
  250. package/.output/server/_libs/_98.mjs +0 -2
  251. package/.output/server/_libs/_99.mjs +0 -2
  252. package/.output/server/_libs/amdefine.mjs +0 -188
  253. package/.output/server/_libs/ast-types.mjs +0 -2270
  254. package/.output/server/_libs/aws-sdk__nested-clients.mjs +0 -3141
  255. package/.output/server/_libs/basic-ftp.mjs +0 -1906
  256. package/.output/server/_libs/compressjs.mjs +0 -50
  257. package/.output/server/_libs/degenerator+[...].mjs +0 -9964
  258. package/.output/server/_libs/get-uri.mjs +0 -413
  259. package/.output/server/_libs/http-proxy-agent.mjs +0 -123
  260. package/.output/server/_libs/ip-address.mjs +0 -1423
  261. package/.output/server/_libs/lru-cache.mjs +0 -732
  262. package/.output/server/_libs/netmask.mjs +0 -139
  263. package/.output/server/_libs/pac-proxy-agent+[...].mjs +0 -3104
  264. package/.output/server/_libs/proxy-agent+proxy-from-env.mjs +0 -204
  265. package/.output/server/_libs/smithy__core.mjs +0 -192
  266. package/.output/server/node_modules/tslib/modules/index.js +0 -70
  267. package/.output/server/node_modules/tslib/modules/package.json +0 -3
  268. package/.output/server/node_modules/tslib/package.json +0 -47
  269. package/.output/server/node_modules/tslib/tslib.js +0 -484
  270. package/bin/piclaw.mjs +0 -195
@@ -1,732 +0,0 @@
1
- import { t as __commonJSMin } from "../_runtime.mjs";
2
- var require_lru_cache = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3
- var perf = typeof performance === "object" && performance && typeof performance.now === "function" ? performance : Date;
4
- var AC = typeof AbortController === "function" ? AbortController : class AbortController {
5
- constructor() {
6
- this.signal = new AS();
7
- }
8
- abort(reason = /* @__PURE__ */ new Error("This operation was aborted")) {
9
- this.signal.reason = this.signal.reason || reason;
10
- this.signal.aborted = true;
11
- this.signal.dispatchEvent({
12
- type: "abort",
13
- target: this.signal
14
- });
15
- }
16
- };
17
- var hasAbortSignal = typeof AbortSignal === "function";
18
- var hasACAbortSignal = typeof AC.AbortSignal === "function";
19
- var AS = hasAbortSignal ? AbortSignal : hasACAbortSignal ? AC.AbortController : class AbortSignal {
20
- constructor() {
21
- this.reason = void 0;
22
- this.aborted = false;
23
- this._listeners = [];
24
- }
25
- dispatchEvent(e) {
26
- if (e.type === "abort") {
27
- this.aborted = true;
28
- this.onabort(e);
29
- this._listeners.forEach((f) => f(e), this);
30
- }
31
- }
32
- onabort() {}
33
- addEventListener(ev, fn) {
34
- if (ev === "abort") this._listeners.push(fn);
35
- }
36
- removeEventListener(ev, fn) {
37
- if (ev === "abort") this._listeners = this._listeners.filter((f) => f !== fn);
38
- }
39
- };
40
- var warned = /* @__PURE__ */ new Set();
41
- var deprecatedOption = (opt, instead) => {
42
- const code = `LRU_CACHE_OPTION_${opt}`;
43
- if (shouldWarn(code)) warn(code, `${opt} option`, `options.${instead}`, LRUCache);
44
- };
45
- var deprecatedMethod = (method, instead) => {
46
- const code = `LRU_CACHE_METHOD_${method}`;
47
- if (shouldWarn(code)) {
48
- const { prototype } = LRUCache;
49
- const { get } = Object.getOwnPropertyDescriptor(prototype, method);
50
- warn(code, `${method} method`, `cache.${instead}()`, get);
51
- }
52
- };
53
- var deprecatedProperty = (field, instead) => {
54
- const code = `LRU_CACHE_PROPERTY_${field}`;
55
- if (shouldWarn(code)) {
56
- const { prototype } = LRUCache;
57
- const { get } = Object.getOwnPropertyDescriptor(prototype, field);
58
- warn(code, `${field} property`, `cache.${instead}`, get);
59
- }
60
- };
61
- var emitWarning = (...a) => {
62
- typeof process === "object" && process && typeof process.emitWarning === "function" ? process.emitWarning(...a) : console.error(...a);
63
- };
64
- var shouldWarn = (code) => !warned.has(code);
65
- var warn = (code, what, instead, fn) => {
66
- warned.add(code);
67
- emitWarning(`The ${what} is deprecated. Please use ${instead} instead.`, "DeprecationWarning", code, fn);
68
- };
69
- var isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
70
- /* istanbul ignore next - This is a little bit ridiculous, tbh.
71
- * The maximum array length is 2^32-1 or thereabouts on most JS impls.
72
- * And well before that point, you're caching the entire world, I mean,
73
- * that's ~32GB of just integers for the next/prev links, plus whatever
74
- * else to hold that many keys and values. Just filling the memory with
75
- * zeroes at init time is brutal when you get that big.
76
- * But why not be complete?
77
- * Maybe in the future, these limits will have expanded. */
78
- var getUintArray = (max) => !isPosInt(max) ? null : max <= Math.pow(2, 8) ? Uint8Array : max <= Math.pow(2, 16) ? Uint16Array : max <= Math.pow(2, 32) ? Uint32Array : max <= Number.MAX_SAFE_INTEGER ? ZeroArray : null;
79
- var ZeroArray = class extends Array {
80
- constructor(size) {
81
- super(size);
82
- this.fill(0);
83
- }
84
- };
85
- var Stack = class {
86
- constructor(max) {
87
- if (max === 0) return [];
88
- this.heap = new (getUintArray(max))(max);
89
- this.length = 0;
90
- }
91
- push(n) {
92
- this.heap[this.length++] = n;
93
- }
94
- pop() {
95
- return this.heap[--this.length];
96
- }
97
- };
98
- var LRUCache = class LRUCache {
99
- constructor(options = {}) {
100
- const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, fetchContext, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort } = options;
101
- const { length, maxAge, stale } = options instanceof LRUCache ? {} : options;
102
- if (max !== 0 && !isPosInt(max)) throw new TypeError("max option must be a nonnegative integer");
103
- const UintArray = max ? getUintArray(max) : Array;
104
- if (!UintArray) throw new Error("invalid max value: " + max);
105
- this.max = max;
106
- this.maxSize = maxSize;
107
- this.maxEntrySize = maxEntrySize || this.maxSize;
108
- this.sizeCalculation = sizeCalculation || length;
109
- if (this.sizeCalculation) {
110
- if (!this.maxSize && !this.maxEntrySize) throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
111
- if (typeof this.sizeCalculation !== "function") throw new TypeError("sizeCalculation set to non-function");
112
- }
113
- this.fetchMethod = fetchMethod || null;
114
- if (this.fetchMethod && typeof this.fetchMethod !== "function") throw new TypeError("fetchMethod must be a function if specified");
115
- this.fetchContext = fetchContext;
116
- if (!this.fetchMethod && fetchContext !== void 0) throw new TypeError("cannot set fetchContext without fetchMethod");
117
- this.keyMap = /* @__PURE__ */ new Map();
118
- this.keyList = new Array(max).fill(null);
119
- this.valList = new Array(max).fill(null);
120
- this.next = new UintArray(max);
121
- this.prev = new UintArray(max);
122
- this.head = 0;
123
- this.tail = 0;
124
- this.free = new Stack(max);
125
- this.initialFill = 1;
126
- this.size = 0;
127
- if (typeof dispose === "function") this.dispose = dispose;
128
- if (typeof disposeAfter === "function") {
129
- this.disposeAfter = disposeAfter;
130
- this.disposed = [];
131
- } else {
132
- this.disposeAfter = null;
133
- this.disposed = null;
134
- }
135
- this.noDisposeOnSet = !!noDisposeOnSet;
136
- this.noUpdateTTL = !!noUpdateTTL;
137
- this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
138
- this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
139
- this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
140
- this.ignoreFetchAbort = !!ignoreFetchAbort;
141
- if (this.maxEntrySize !== 0) {
142
- if (this.maxSize !== 0) {
143
- if (!isPosInt(this.maxSize)) throw new TypeError("maxSize must be a positive integer if specified");
144
- }
145
- if (!isPosInt(this.maxEntrySize)) throw new TypeError("maxEntrySize must be a positive integer if specified");
146
- this.initializeSizeTracking();
147
- }
148
- this.allowStale = !!allowStale || !!stale;
149
- this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
150
- this.updateAgeOnGet = !!updateAgeOnGet;
151
- this.updateAgeOnHas = !!updateAgeOnHas;
152
- this.ttlResolution = isPosInt(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1;
153
- this.ttlAutopurge = !!ttlAutopurge;
154
- this.ttl = ttl || maxAge || 0;
155
- if (this.ttl) {
156
- if (!isPosInt(this.ttl)) throw new TypeError("ttl must be a positive integer if specified");
157
- this.initializeTTLTracking();
158
- }
159
- if (this.max === 0 && this.ttl === 0 && this.maxSize === 0) throw new TypeError("At least one of max, maxSize, or ttl is required");
160
- if (!this.ttlAutopurge && !this.max && !this.maxSize) {
161
- const code = "LRU_CACHE_UNBOUNDED";
162
- if (shouldWarn(code)) {
163
- warned.add(code);
164
- emitWarning("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", code, LRUCache);
165
- }
166
- }
167
- if (stale) deprecatedOption("stale", "allowStale");
168
- if (maxAge) deprecatedOption("maxAge", "ttl");
169
- if (length) deprecatedOption("length", "sizeCalculation");
170
- }
171
- getRemainingTTL(key) {
172
- return this.has(key, { updateAgeOnHas: false }) ? Infinity : 0;
173
- }
174
- initializeTTLTracking() {
175
- this.ttls = new ZeroArray(this.max);
176
- this.starts = new ZeroArray(this.max);
177
- this.setItemTTL = (index, ttl, start = perf.now()) => {
178
- this.starts[index] = ttl !== 0 ? start : 0;
179
- this.ttls[index] = ttl;
180
- if (ttl !== 0 && this.ttlAutopurge) {
181
- const t = setTimeout(() => {
182
- if (this.isStale(index)) this.delete(this.keyList[index]);
183
- }, ttl + 1);
184
- /* istanbul ignore else - unref() not supported on all platforms */
185
- if (t.unref) t.unref();
186
- }
187
- };
188
- this.updateItemAge = (index) => {
189
- this.starts[index] = this.ttls[index] !== 0 ? perf.now() : 0;
190
- };
191
- this.statusTTL = (status, index) => {
192
- if (status) {
193
- status.ttl = this.ttls[index];
194
- status.start = this.starts[index];
195
- status.now = cachedNow || getNow();
196
- status.remainingTTL = status.now + status.ttl - status.start;
197
- }
198
- };
199
- let cachedNow = 0;
200
- const getNow = () => {
201
- const n = perf.now();
202
- if (this.ttlResolution > 0) {
203
- cachedNow = n;
204
- const t = setTimeout(() => cachedNow = 0, this.ttlResolution);
205
- /* istanbul ignore else - not available on all platforms */
206
- if (t.unref) t.unref();
207
- }
208
- return n;
209
- };
210
- this.getRemainingTTL = (key) => {
211
- const index = this.keyMap.get(key);
212
- if (index === void 0) return 0;
213
- return this.ttls[index] === 0 || this.starts[index] === 0 ? Infinity : this.starts[index] + this.ttls[index] - (cachedNow || getNow());
214
- };
215
- this.isStale = (index) => {
216
- return this.ttls[index] !== 0 && this.starts[index] !== 0 && (cachedNow || getNow()) - this.starts[index] > this.ttls[index];
217
- };
218
- }
219
- updateItemAge(_index) {}
220
- statusTTL(_status, _index) {}
221
- setItemTTL(_index, _ttl, _start) {}
222
- isStale(_index) {
223
- return false;
224
- }
225
- initializeSizeTracking() {
226
- this.calculatedSize = 0;
227
- this.sizes = new ZeroArray(this.max);
228
- this.removeItemSize = (index) => {
229
- this.calculatedSize -= this.sizes[index];
230
- this.sizes[index] = 0;
231
- };
232
- this.requireSize = (k, v, size, sizeCalculation) => {
233
- if (this.isBackgroundFetch(v)) return 0;
234
- if (!isPosInt(size)) if (sizeCalculation) {
235
- if (typeof sizeCalculation !== "function") throw new TypeError("sizeCalculation must be a function");
236
- size = sizeCalculation(v, k);
237
- if (!isPosInt(size)) throw new TypeError("sizeCalculation return invalid (expect positive integer)");
238
- } else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
239
- return size;
240
- };
241
- this.addItemSize = (index, size, status) => {
242
- this.sizes[index] = size;
243
- if (this.maxSize) {
244
- const maxSize = this.maxSize - this.sizes[index];
245
- while (this.calculatedSize > maxSize) this.evict(true);
246
- }
247
- this.calculatedSize += this.sizes[index];
248
- if (status) {
249
- status.entrySize = size;
250
- status.totalCalculatedSize = this.calculatedSize;
251
- }
252
- };
253
- }
254
- removeItemSize(_index) {}
255
- addItemSize(_index, _size) {}
256
- requireSize(_k, _v, size, sizeCalculation) {
257
- if (size || sizeCalculation) throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
258
- }
259
- *indexes({ allowStale = this.allowStale } = {}) {
260
- if (this.size) for (let i = this.tail;;) {
261
- if (!this.isValidIndex(i)) break;
262
- if (allowStale || !this.isStale(i)) yield i;
263
- if (i === this.head) break;
264
- else i = this.prev[i];
265
- }
266
- }
267
- *rindexes({ allowStale = this.allowStale } = {}) {
268
- if (this.size) for (let i = this.head;;) {
269
- if (!this.isValidIndex(i)) break;
270
- if (allowStale || !this.isStale(i)) yield i;
271
- if (i === this.tail) break;
272
- else i = this.next[i];
273
- }
274
- }
275
- isValidIndex(index) {
276
- return index !== void 0 && this.keyMap.get(this.keyList[index]) === index;
277
- }
278
- *entries() {
279
- for (const i of this.indexes()) if (this.valList[i] !== void 0 && this.keyList[i] !== void 0 && !this.isBackgroundFetch(this.valList[i])) yield [this.keyList[i], this.valList[i]];
280
- }
281
- *rentries() {
282
- for (const i of this.rindexes()) if (this.valList[i] !== void 0 && this.keyList[i] !== void 0 && !this.isBackgroundFetch(this.valList[i])) yield [this.keyList[i], this.valList[i]];
283
- }
284
- *keys() {
285
- for (const i of this.indexes()) if (this.keyList[i] !== void 0 && !this.isBackgroundFetch(this.valList[i])) yield this.keyList[i];
286
- }
287
- *rkeys() {
288
- for (const i of this.rindexes()) if (this.keyList[i] !== void 0 && !this.isBackgroundFetch(this.valList[i])) yield this.keyList[i];
289
- }
290
- *values() {
291
- for (const i of this.indexes()) if (this.valList[i] !== void 0 && !this.isBackgroundFetch(this.valList[i])) yield this.valList[i];
292
- }
293
- *rvalues() {
294
- for (const i of this.rindexes()) if (this.valList[i] !== void 0 && !this.isBackgroundFetch(this.valList[i])) yield this.valList[i];
295
- }
296
- [Symbol.iterator]() {
297
- return this.entries();
298
- }
299
- find(fn, getOptions) {
300
- for (const i of this.indexes()) {
301
- const v = this.valList[i];
302
- const value = this.isBackgroundFetch(v) ? v.__staleWhileFetching : v;
303
- if (value === void 0) continue;
304
- if (fn(value, this.keyList[i], this)) return this.get(this.keyList[i], getOptions);
305
- }
306
- }
307
- forEach(fn, thisp = this) {
308
- for (const i of this.indexes()) {
309
- const v = this.valList[i];
310
- const value = this.isBackgroundFetch(v) ? v.__staleWhileFetching : v;
311
- if (value === void 0) continue;
312
- fn.call(thisp, value, this.keyList[i], this);
313
- }
314
- }
315
- rforEach(fn, thisp = this) {
316
- for (const i of this.rindexes()) {
317
- const v = this.valList[i];
318
- const value = this.isBackgroundFetch(v) ? v.__staleWhileFetching : v;
319
- if (value === void 0) continue;
320
- fn.call(thisp, value, this.keyList[i], this);
321
- }
322
- }
323
- get prune() {
324
- deprecatedMethod("prune", "purgeStale");
325
- return this.purgeStale;
326
- }
327
- purgeStale() {
328
- let deleted = false;
329
- for (const i of this.rindexes({ allowStale: true })) if (this.isStale(i)) {
330
- this.delete(this.keyList[i]);
331
- deleted = true;
332
- }
333
- return deleted;
334
- }
335
- dump() {
336
- const arr = [];
337
- for (const i of this.indexes({ allowStale: true })) {
338
- const key = this.keyList[i];
339
- const v = this.valList[i];
340
- const value = this.isBackgroundFetch(v) ? v.__staleWhileFetching : v;
341
- if (value === void 0) continue;
342
- const entry = { value };
343
- if (this.ttls) {
344
- entry.ttl = this.ttls[i];
345
- const age = perf.now() - this.starts[i];
346
- entry.start = Math.floor(Date.now() - age);
347
- }
348
- if (this.sizes) entry.size = this.sizes[i];
349
- arr.unshift([key, entry]);
350
- }
351
- return arr;
352
- }
353
- load(arr) {
354
- this.clear();
355
- for (const [key, entry] of arr) {
356
- if (entry.start) {
357
- const age = Date.now() - entry.start;
358
- entry.start = perf.now() - age;
359
- }
360
- this.set(key, entry.value, entry);
361
- }
362
- }
363
- dispose(_v, _k, _reason) {}
364
- set(k, v, { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, size = 0, sizeCalculation = this.sizeCalculation, noUpdateTTL = this.noUpdateTTL, status } = {}) {
365
- size = this.requireSize(k, v, size, sizeCalculation);
366
- if (this.maxEntrySize && size > this.maxEntrySize) {
367
- if (status) {
368
- status.set = "miss";
369
- status.maxEntrySizeExceeded = true;
370
- }
371
- this.delete(k);
372
- return this;
373
- }
374
- let index = this.size === 0 ? void 0 : this.keyMap.get(k);
375
- if (index === void 0) {
376
- index = this.newIndex();
377
- this.keyList[index] = k;
378
- this.valList[index] = v;
379
- this.keyMap.set(k, index);
380
- this.next[this.tail] = index;
381
- this.prev[index] = this.tail;
382
- this.tail = index;
383
- this.size++;
384
- this.addItemSize(index, size, status);
385
- if (status) status.set = "add";
386
- noUpdateTTL = false;
387
- } else {
388
- this.moveToTail(index);
389
- const oldVal = this.valList[index];
390
- if (v !== oldVal) {
391
- if (this.isBackgroundFetch(oldVal)) oldVal.__abortController.abort(/* @__PURE__ */ new Error("replaced"));
392
- else if (!noDisposeOnSet) {
393
- this.dispose(oldVal, k, "set");
394
- if (this.disposeAfter) this.disposed.push([
395
- oldVal,
396
- k,
397
- "set"
398
- ]);
399
- }
400
- this.removeItemSize(index);
401
- this.valList[index] = v;
402
- this.addItemSize(index, size, status);
403
- if (status) {
404
- status.set = "replace";
405
- const oldValue = oldVal && this.isBackgroundFetch(oldVal) ? oldVal.__staleWhileFetching : oldVal;
406
- if (oldValue !== void 0) status.oldValue = oldValue;
407
- }
408
- } else if (status) status.set = "update";
409
- }
410
- if (ttl !== 0 && this.ttl === 0 && !this.ttls) this.initializeTTLTracking();
411
- if (!noUpdateTTL) this.setItemTTL(index, ttl, start);
412
- this.statusTTL(status, index);
413
- if (this.disposeAfter) while (this.disposed.length) this.disposeAfter(...this.disposed.shift());
414
- return this;
415
- }
416
- newIndex() {
417
- if (this.size === 0) return this.tail;
418
- if (this.size === this.max && this.max !== 0) return this.evict(false);
419
- if (this.free.length !== 0) return this.free.pop();
420
- return this.initialFill++;
421
- }
422
- pop() {
423
- if (this.size) {
424
- const val = this.valList[this.head];
425
- this.evict(true);
426
- return val;
427
- }
428
- }
429
- evict(free) {
430
- const head = this.head;
431
- const k = this.keyList[head];
432
- const v = this.valList[head];
433
- if (this.isBackgroundFetch(v)) v.__abortController.abort(/* @__PURE__ */ new Error("evicted"));
434
- else {
435
- this.dispose(v, k, "evict");
436
- if (this.disposeAfter) this.disposed.push([
437
- v,
438
- k,
439
- "evict"
440
- ]);
441
- }
442
- this.removeItemSize(head);
443
- if (free) {
444
- this.keyList[head] = null;
445
- this.valList[head] = null;
446
- this.free.push(head);
447
- }
448
- this.head = this.next[head];
449
- this.keyMap.delete(k);
450
- this.size--;
451
- return head;
452
- }
453
- has(k, { updateAgeOnHas = this.updateAgeOnHas, status } = {}) {
454
- const index = this.keyMap.get(k);
455
- if (index !== void 0) {
456
- if (!this.isStale(index)) {
457
- if (updateAgeOnHas) this.updateItemAge(index);
458
- if (status) status.has = "hit";
459
- this.statusTTL(status, index);
460
- return true;
461
- } else if (status) {
462
- status.has = "stale";
463
- this.statusTTL(status, index);
464
- }
465
- } else if (status) status.has = "miss";
466
- return false;
467
- }
468
- peek(k, { allowStale = this.allowStale } = {}) {
469
- const index = this.keyMap.get(k);
470
- if (index !== void 0 && (allowStale || !this.isStale(index))) {
471
- const v = this.valList[index];
472
- return this.isBackgroundFetch(v) ? v.__staleWhileFetching : v;
473
- }
474
- }
475
- backgroundFetch(k, index, options, context) {
476
- const v = index === void 0 ? void 0 : this.valList[index];
477
- if (this.isBackgroundFetch(v)) return v;
478
- const ac = new AC();
479
- if (options.signal) options.signal.addEventListener("abort", () => ac.abort(options.signal.reason));
480
- const fetchOpts = {
481
- signal: ac.signal,
482
- options,
483
- context
484
- };
485
- const cb = (v, updateCache = false) => {
486
- const { aborted } = ac.signal;
487
- const ignoreAbort = options.ignoreFetchAbort && v !== void 0;
488
- if (options.status) if (aborted && !updateCache) {
489
- options.status.fetchAborted = true;
490
- options.status.fetchError = ac.signal.reason;
491
- if (ignoreAbort) options.status.fetchAbortIgnored = true;
492
- } else options.status.fetchResolved = true;
493
- if (aborted && !ignoreAbort && !updateCache) return fetchFail(ac.signal.reason);
494
- if (this.valList[index] === p) if (v === void 0) if (p.__staleWhileFetching) this.valList[index] = p.__staleWhileFetching;
495
- else this.delete(k);
496
- else {
497
- if (options.status) options.status.fetchUpdated = true;
498
- this.set(k, v, fetchOpts.options);
499
- }
500
- return v;
501
- };
502
- const eb = (er) => {
503
- if (options.status) {
504
- options.status.fetchRejected = true;
505
- options.status.fetchError = er;
506
- }
507
- return fetchFail(er);
508
- };
509
- const fetchFail = (er) => {
510
- const { aborted } = ac.signal;
511
- const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;
512
- const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
513
- const noDelete = allowStale || options.noDeleteOnFetchRejection;
514
- if (this.valList[index] === p) {
515
- if (!noDelete || p.__staleWhileFetching === void 0) this.delete(k);
516
- else if (!allowStaleAborted) this.valList[index] = p.__staleWhileFetching;
517
- }
518
- if (allowStale) {
519
- if (options.status && p.__staleWhileFetching !== void 0) options.status.returnedStale = true;
520
- return p.__staleWhileFetching;
521
- } else if (p.__returned === p) throw er;
522
- };
523
- const pcall = (res, rej) => {
524
- this.fetchMethod(k, v, fetchOpts).then((v) => res(v), rej);
525
- ac.signal.addEventListener("abort", () => {
526
- if (!options.ignoreFetchAbort || options.allowStaleOnFetchAbort) {
527
- res();
528
- if (options.allowStaleOnFetchAbort) res = (v) => cb(v, true);
529
- }
530
- });
531
- };
532
- if (options.status) options.status.fetchDispatched = true;
533
- const p = new Promise(pcall).then(cb, eb);
534
- p.__abortController = ac;
535
- p.__staleWhileFetching = v;
536
- p.__returned = null;
537
- if (index === void 0) {
538
- this.set(k, p, {
539
- ...fetchOpts.options,
540
- status: void 0
541
- });
542
- index = this.keyMap.get(k);
543
- } else this.valList[index] = p;
544
- return p;
545
- }
546
- isBackgroundFetch(p) {
547
- return p && typeof p === "object" && typeof p.then === "function" && Object.prototype.hasOwnProperty.call(p, "__staleWhileFetching") && Object.prototype.hasOwnProperty.call(p, "__returned") && (p.__returned === p || p.__returned === null);
548
- }
549
- async fetch(k, { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, ttl = this.ttl, noDisposeOnSet = this.noDisposeOnSet, size = 0, sizeCalculation = this.sizeCalculation, noUpdateTTL = this.noUpdateTTL, noDeleteOnFetchRejection = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection = this.allowStaleOnFetchRejection, ignoreFetchAbort = this.ignoreFetchAbort, allowStaleOnFetchAbort = this.allowStaleOnFetchAbort, fetchContext = this.fetchContext, forceRefresh = false, status, signal } = {}) {
550
- if (!this.fetchMethod) {
551
- if (status) status.fetch = "get";
552
- return this.get(k, {
553
- allowStale,
554
- updateAgeOnGet,
555
- noDeleteOnStaleGet,
556
- status
557
- });
558
- }
559
- const options = {
560
- allowStale,
561
- updateAgeOnGet,
562
- noDeleteOnStaleGet,
563
- ttl,
564
- noDisposeOnSet,
565
- size,
566
- sizeCalculation,
567
- noUpdateTTL,
568
- noDeleteOnFetchRejection,
569
- allowStaleOnFetchRejection,
570
- allowStaleOnFetchAbort,
571
- ignoreFetchAbort,
572
- status,
573
- signal
574
- };
575
- let index = this.keyMap.get(k);
576
- if (index === void 0) {
577
- if (status) status.fetch = "miss";
578
- const p = this.backgroundFetch(k, index, options, fetchContext);
579
- return p.__returned = p;
580
- } else {
581
- const v = this.valList[index];
582
- if (this.isBackgroundFetch(v)) {
583
- const stale = allowStale && v.__staleWhileFetching !== void 0;
584
- if (status) {
585
- status.fetch = "inflight";
586
- if (stale) status.returnedStale = true;
587
- }
588
- return stale ? v.__staleWhileFetching : v.__returned = v;
589
- }
590
- const isStale = this.isStale(index);
591
- if (!forceRefresh && !isStale) {
592
- if (status) status.fetch = "hit";
593
- this.moveToTail(index);
594
- if (updateAgeOnGet) this.updateItemAge(index);
595
- this.statusTTL(status, index);
596
- return v;
597
- }
598
- const p = this.backgroundFetch(k, index, options, fetchContext);
599
- const hasStale = p.__staleWhileFetching !== void 0;
600
- const staleVal = hasStale && allowStale;
601
- if (status) {
602
- status.fetch = hasStale && isStale ? "stale" : "refresh";
603
- if (staleVal && isStale) status.returnedStale = true;
604
- }
605
- return staleVal ? p.__staleWhileFetching : p.__returned = p;
606
- }
607
- }
608
- get(k, { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status } = {}) {
609
- const index = this.keyMap.get(k);
610
- if (index !== void 0) {
611
- const value = this.valList[index];
612
- const fetching = this.isBackgroundFetch(value);
613
- this.statusTTL(status, index);
614
- if (this.isStale(index)) {
615
- if (status) status.get = "stale";
616
- if (!fetching) {
617
- if (!noDeleteOnStaleGet) this.delete(k);
618
- if (status) status.returnedStale = allowStale;
619
- return allowStale ? value : void 0;
620
- } else {
621
- if (status) status.returnedStale = allowStale && value.__staleWhileFetching !== void 0;
622
- return allowStale ? value.__staleWhileFetching : void 0;
623
- }
624
- } else {
625
- if (status) status.get = "hit";
626
- if (fetching) return value.__staleWhileFetching;
627
- this.moveToTail(index);
628
- if (updateAgeOnGet) this.updateItemAge(index);
629
- return value;
630
- }
631
- } else if (status) status.get = "miss";
632
- }
633
- connect(p, n) {
634
- this.prev[n] = p;
635
- this.next[p] = n;
636
- }
637
- moveToTail(index) {
638
- if (index !== this.tail) {
639
- if (index === this.head) this.head = this.next[index];
640
- else this.connect(this.prev[index], this.next[index]);
641
- this.connect(this.tail, index);
642
- this.tail = index;
643
- }
644
- }
645
- get del() {
646
- deprecatedMethod("del", "delete");
647
- return this.delete;
648
- }
649
- delete(k) {
650
- let deleted = false;
651
- if (this.size !== 0) {
652
- const index = this.keyMap.get(k);
653
- if (index !== void 0) {
654
- deleted = true;
655
- if (this.size === 1) this.clear();
656
- else {
657
- this.removeItemSize(index);
658
- const v = this.valList[index];
659
- if (this.isBackgroundFetch(v)) v.__abortController.abort(/* @__PURE__ */ new Error("deleted"));
660
- else {
661
- this.dispose(v, k, "delete");
662
- if (this.disposeAfter) this.disposed.push([
663
- v,
664
- k,
665
- "delete"
666
- ]);
667
- }
668
- this.keyMap.delete(k);
669
- this.keyList[index] = null;
670
- this.valList[index] = null;
671
- if (index === this.tail) this.tail = this.prev[index];
672
- else if (index === this.head) this.head = this.next[index];
673
- else {
674
- this.next[this.prev[index]] = this.next[index];
675
- this.prev[this.next[index]] = this.prev[index];
676
- }
677
- this.size--;
678
- this.free.push(index);
679
- }
680
- }
681
- }
682
- if (this.disposed) while (this.disposed.length) this.disposeAfter(...this.disposed.shift());
683
- return deleted;
684
- }
685
- clear() {
686
- for (const index of this.rindexes({ allowStale: true })) {
687
- const v = this.valList[index];
688
- if (this.isBackgroundFetch(v)) v.__abortController.abort(/* @__PURE__ */ new Error("deleted"));
689
- else {
690
- const k = this.keyList[index];
691
- this.dispose(v, k, "delete");
692
- if (this.disposeAfter) this.disposed.push([
693
- v,
694
- k,
695
- "delete"
696
- ]);
697
- }
698
- }
699
- this.keyMap.clear();
700
- this.valList.fill(null);
701
- this.keyList.fill(null);
702
- if (this.ttls) {
703
- this.ttls.fill(0);
704
- this.starts.fill(0);
705
- }
706
- if (this.sizes) this.sizes.fill(0);
707
- this.head = 0;
708
- this.tail = 0;
709
- this.initialFill = 1;
710
- this.free.length = 0;
711
- this.calculatedSize = 0;
712
- this.size = 0;
713
- if (this.disposed) while (this.disposed.length) this.disposeAfter(...this.disposed.shift());
714
- }
715
- get reset() {
716
- deprecatedMethod("reset", "clear");
717
- return this.clear;
718
- }
719
- get length() {
720
- deprecatedProperty("length", "size");
721
- return this.size;
722
- }
723
- static get AbortController() {
724
- return AC;
725
- }
726
- static get AbortSignal() {
727
- return AS;
728
- }
729
- };
730
- module.exports = LRUCache;
731
- }));
732
- export { require_lru_cache as t };