@socketsecurity/lib 6.0.9 → 6.0.10

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 (335) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +8 -9
  3. package/dist/abort/signal.d.ts +1 -1
  4. package/dist/abort/signal.js +1 -1
  5. package/dist/ai/agent-context.d.mts +1 -1
  6. package/dist/ai/agent-context.js +3 -2
  7. package/dist/ai/backends.d.mts +3 -3
  8. package/dist/ai/backends.js +2 -2
  9. package/dist/ai/billing-context.d.mts +74 -0
  10. package/dist/ai/billing-context.js +129 -0
  11. package/dist/ai/credentials.d.mts +39 -5
  12. package/dist/ai/credentials.js +61 -6
  13. package/dist/ai/discover.d.mts +4 -0
  14. package/dist/ai/discover.js +4 -0
  15. package/dist/ai/exec.d.mts +1 -1
  16. package/dist/ai/exec.js +1 -1
  17. package/dist/ai/http.d.mts +8 -8
  18. package/dist/ai/http.js +6 -6
  19. package/dist/ai/profiles.d.mts +9 -10
  20. package/dist/ai/profiles.js +0 -5
  21. package/dist/ai/role.d.mts +58 -0
  22. package/dist/ai/role.js +96 -0
  23. package/dist/ai/route-heuristic.d.mts +177 -0
  24. package/dist/ai/route-heuristic.js +194 -0
  25. package/dist/ai/route.d.mts +10 -9
  26. package/dist/ai/route.js +14 -13
  27. package/dist/ai/spawn.d.mts +2 -1
  28. package/dist/ai/spawn.js +25 -2
  29. package/dist/ai/subagent-status.d.mts +2 -0
  30. package/dist/ai/subagent-status.js +2 -0
  31. package/dist/ai/tier.d.mts +1 -1
  32. package/dist/ai/types.d.mts +9 -2
  33. package/dist/ai/worktree.d.mts +1 -1
  34. package/dist/ai/worktree.js +3 -2
  35. package/dist/argv/parse.d.ts +2 -0
  36. package/dist/argv/parse.js +2 -0
  37. package/dist/bin/_internal.d.ts +1 -1
  38. package/dist/bin/_internal.js +1 -1
  39. package/dist/bin/prim.cjs +446 -300
  40. package/dist/bin/shadow.js +2 -1
  41. package/dist/bin/which.d.ts +28 -3
  42. package/dist/bin/which.js +45 -3
  43. package/dist/cacache/_internal.d.ts +10 -2
  44. package/dist/cacache/_internal.js +6 -10
  45. package/dist/cache/ttl/_internal.d.ts +33 -0
  46. package/dist/cache/ttl/_internal.js +68 -0
  47. package/dist/cache/ttl/browser.d.ts +56 -0
  48. package/dist/cache/ttl/browser.js +257 -0
  49. package/dist/cache/ttl/store.js +10 -33
  50. package/dist/cache/ttl/types.d.ts +46 -3
  51. package/dist/checks/primordials-defaults.d.ts +5 -5
  52. package/dist/checks/primordials-defaults.js +5 -5
  53. package/dist/checks/primordials.d.ts +1 -1
  54. package/dist/checks/primordials.js +25 -17
  55. package/dist/cli/check-primordials.d.ts +6 -1
  56. package/dist/cli/check-primordials.js +14 -5
  57. package/dist/cli/check.js +1 -1
  58. package/dist/cli/socket-lib.d.ts +1 -1
  59. package/dist/cli/socket-lib.js +3 -3
  60. package/dist/colors/socket-palette.d.ts +1 -1
  61. package/dist/compression/brotli.d.ts +6 -2
  62. package/dist/compression/brotli.js +4 -0
  63. package/dist/compression/gzip.d.ts +6 -2
  64. package/dist/compression/gzip.js +6 -1
  65. package/dist/config/layers.d.ts +4 -4
  66. package/dist/config/layers.js +4 -4
  67. package/dist/constants/agents.d.ts +3 -0
  68. package/dist/constants/agents.js +3 -0
  69. package/dist/constants/node.d.ts +14 -0
  70. package/dist/constants/node.js +14 -0
  71. package/dist/constants/package-default-node-range.js +1 -5
  72. package/dist/constants/packages.d.ts +5 -0
  73. package/dist/constants/packages.js +5 -0
  74. package/dist/constants/platform.d.ts +1 -1
  75. package/dist/constants/platform.js +1 -1
  76. package/dist/constants/socket.js +1 -1
  77. package/dist/constants/typescript.d.ts +5 -0
  78. package/dist/constants/typescript.js +5 -0
  79. package/dist/debug/_internal.d.ts +22 -7
  80. package/dist/debug/_internal.js +33 -15
  81. package/dist/debug/namespace.js +11 -8
  82. package/dist/debug/output.d.ts +12 -1
  83. package/dist/debug/output.js +33 -16
  84. package/dist/dlx/binary-resolution.js +7 -4
  85. package/dist/eco/npm/npm/parse-lockfile.js +2 -1
  86. package/dist/eco/npm/vlt/exec.d.ts +1 -1
  87. package/dist/eco/npm/vlt/exec.js +1 -1
  88. package/dist/env/agents.d.ts +6 -0
  89. package/dist/env/agents.js +29 -0
  90. package/dist/env/flags.d.ts +12 -0
  91. package/dist/env/flags.js +23 -0
  92. package/dist/env/github-status.js +2 -2
  93. package/dist/env/providers.d.ts +6 -0
  94. package/dist/env/providers.js +23 -0
  95. package/dist/env/proxy.js +1 -1
  96. package/dist/env/rewire.d.ts +32 -0
  97. package/dist/env/rewire.js +55 -23
  98. package/dist/env/runtimes.d.ts +9 -0
  99. package/dist/env/runtimes.js +53 -0
  100. package/dist/env/socket-cli.d.ts +5 -2
  101. package/dist/env/socket-cli.js +6 -3
  102. package/dist/errors/predicates.d.ts +3 -2
  103. package/dist/errors/predicates.js +5 -3
  104. package/dist/errors/stack.js +2 -1
  105. package/dist/events/exit/_internal.d.ts +1 -23
  106. package/dist/external/@npmcli/package-json.js +179 -88
  107. package/dist/external/@npmcli/promise-spawn.js +2 -2
  108. package/dist/external/@sinclair/typebox/value.js +5 -4
  109. package/dist/external/@socketregistry/yocto-spinner.js +3 -3
  110. package/dist/external/adm-zip.d.ts +82 -0
  111. package/dist/external/adm-zip.js +2 -2
  112. package/dist/external/cacache.d.ts +87 -0
  113. package/dist/external/debug.d.ts +22 -0
  114. package/dist/external/debug.js +11 -4
  115. package/dist/external/del.d.ts +1 -0
  116. package/dist/external/external-pack.d.ts +12 -0
  117. package/dist/external/external-pack.js +41 -34
  118. package/dist/external/fast-glob.d.ts +8 -0
  119. package/dist/external/fast-sort.d.ts +1 -0
  120. package/dist/external/get-east-asian-width.d.ts +5 -0
  121. package/dist/external/get-east-asian-width.js +8 -1
  122. package/dist/external/has-flag.d.ts +1 -0
  123. package/dist/external/inquirer-pack.d.ts +18 -0
  124. package/dist/external/libnpmexec.d.ts +35 -0
  125. package/dist/external/libnpmpack.d.ts +1 -0
  126. package/dist/external/make-fetch-happen.d.ts +13 -0
  127. package/dist/external/normalize-package-data.d.ts +4 -0
  128. package/dist/external/npm-core.d.ts +14 -0
  129. package/dist/external/npm-pack.d.ts +24 -0
  130. package/dist/external/npm-pack.js +1551 -1867
  131. package/dist/external/npm-package-arg.d.ts +4 -0
  132. package/dist/external/p-map.js +8 -1
  133. package/dist/external/pacote.d.ts +15 -0
  134. package/dist/external/pico-pack.d.ts +16 -0
  135. package/dist/external/pico-pack.js +38 -23
  136. package/dist/external/picomatch.d.ts +96 -0
  137. package/dist/external/pony-cause.d.ts +14 -0
  138. package/dist/external/semver.d.ts +60 -0
  139. package/dist/external/semver.js +1459 -4
  140. package/dist/external/shell-quote.d.ts +51 -0
  141. package/dist/external/shell-quote.js +55 -15
  142. package/dist/external/signal-exit.d.ts +1 -0
  143. package/dist/external/spdx-correct.d.ts +4 -0
  144. package/dist/external/spdx-expression-parse.d.ts +4 -0
  145. package/dist/external/spdx-pack.d.ts +10 -0
  146. package/dist/external/std-env.d.ts +284 -0
  147. package/dist/external/std-env.js +323 -0
  148. package/dist/external/streaming-iterables.d.ts +11 -0
  149. package/dist/external/supports-color.d.ts +1 -0
  150. package/dist/external/tar-fs.d.ts +31 -0
  151. package/dist/external/validate-npm-package-name.d.ts +4 -0
  152. package/dist/external/which.d.ts +25 -0
  153. package/dist/external/which.js +2 -2
  154. package/dist/external/yargs-parser.d.ts +2 -0
  155. package/dist/external/yargs-parser.js +11 -3
  156. package/dist/external/yoctocolors-cjs.d.ts +51 -0
  157. package/dist/external-tools/bazel/asset-names.d.ts +1 -1
  158. package/dist/external-tools/bazel/from-download.d.ts +1 -1
  159. package/dist/external-tools/bazel/resolve.d.ts +3 -0
  160. package/dist/external-tools/bazel/resolve.js +3 -0
  161. package/dist/external-tools/cdxgen/asset-names.d.ts +5 -5
  162. package/dist/external-tools/cdxgen/asset-names.js +3 -3
  163. package/dist/external-tools/cdxgen/from-download.d.ts +2 -2
  164. package/dist/external-tools/cdxgen/from-download.js +1 -1
  165. package/dist/external-tools/cdxgen/resolve.d.ts +4 -1
  166. package/dist/external-tools/cdxgen/resolve.js +4 -1
  167. package/dist/external-tools/cdxgen/types.d.ts +1 -1
  168. package/dist/external-tools/from-download.d.ts +2 -2
  169. package/dist/external-tools/from-download.js +1 -1
  170. package/dist/external-tools/janus/asset-names.d.ts +4 -1
  171. package/dist/external-tools/janus/asset-names.js +3 -0
  172. package/dist/external-tools/janus/from-download.d.ts +3 -3
  173. package/dist/external-tools/janus/from-download.js +2 -2
  174. package/dist/external-tools/janus/resolve.d.ts +3 -0
  175. package/dist/external-tools/janus/resolve.js +3 -0
  176. package/dist/external-tools/jre/asset-names.d.ts +3 -1
  177. package/dist/external-tools/jre/asset-names.js +2 -0
  178. package/dist/external-tools/jre/from-download.d.ts +1 -1
  179. package/dist/external-tools/manifest.d.ts +5 -3
  180. package/dist/external-tools/manifest.js +4 -2
  181. package/dist/external-tools/opengrep/asset-names.d.ts +1 -1
  182. package/dist/external-tools/opengrep/resolve.d.ts +3 -0
  183. package/dist/external-tools/opengrep/resolve.js +3 -0
  184. package/dist/external-tools/python/asset-names.d.ts +3 -1
  185. package/dist/external-tools/python/asset-names.js +7 -3
  186. package/dist/external-tools/python/pin.js +3 -1
  187. package/dist/external-tools/python/resolve.d.ts +3 -0
  188. package/dist/external-tools/python/resolve.js +3 -0
  189. package/dist/external-tools/sbt/resolve.d.ts +3 -0
  190. package/dist/external-tools/sbt/resolve.js +3 -0
  191. package/dist/external-tools/skillspector/from-uv.d.ts +1 -1
  192. package/dist/external-tools/synp/resolve.d.ts +3 -0
  193. package/dist/external-tools/synp/resolve.js +3 -0
  194. package/dist/external-tools/trivy/asset-names.d.ts +1 -1
  195. package/dist/external-tools/trivy/resolve.d.ts +3 -0
  196. package/dist/external-tools/trivy/resolve.js +3 -0
  197. package/dist/external-tools/trufflehog/asset-names.d.ts +4 -1
  198. package/dist/external-tools/trufflehog/asset-names.js +3 -0
  199. package/dist/external-tools/trufflehog/from-download.d.ts +1 -1
  200. package/dist/external-tools/trufflehog/resolve.d.ts +3 -0
  201. package/dist/external-tools/trufflehog/resolve.js +3 -0
  202. package/dist/external-tools/uv/asset-names.d.ts +1 -1
  203. package/dist/external-tools/uv/resolve.d.ts +3 -0
  204. package/dist/external-tools/uv/resolve.js +3 -0
  205. package/dist/fleet/repo-config.d.ts +8 -6
  206. package/dist/fleet/repo-config.js +8 -6
  207. package/dist/fs/_internal.d.ts +1 -1
  208. package/dist/fs/_internal.js +1 -1
  209. package/dist/fs/access.d.ts +2 -0
  210. package/dist/fs/access.js +2 -0
  211. package/dist/fs/allowed-dirs-cache.js +5 -3
  212. package/dist/fs/find.js +1 -2
  213. package/dist/fs/inspect.d.ts +2 -2
  214. package/dist/fs/read-file.js +3 -4
  215. package/dist/fs/safe.js +1 -1
  216. package/dist/git/_internal.js +5 -1
  217. package/dist/github/commit.d.ts +92 -0
  218. package/dist/github/commit.js +113 -0
  219. package/dist/github/ghsa.js +1 -1
  220. package/dist/github/refs-graphql.js +1 -1
  221. package/dist/github/request.js +1 -1
  222. package/dist/github/token.d.ts +5 -2
  223. package/dist/github/token.js +6 -4
  224. package/dist/github/workflow-runs.d.ts +107 -0
  225. package/dist/github/workflow-runs.js +98 -0
  226. package/dist/http-request/_internal.d.ts +1 -1
  227. package/dist/http-request/browser.d.ts +6 -0
  228. package/dist/http-request/browser.js +3 -2
  229. package/dist/http-request/download.js +2 -0
  230. package/dist/http-request/headers.d.ts +1 -1
  231. package/dist/http-request/headers.js +1 -1
  232. package/dist/http-request/request-attempt.js +6 -3
  233. package/dist/http-request/request-types.d.ts +10 -1
  234. package/dist/http-request/request.js +2 -2
  235. package/dist/http-request/user-agent.d.ts +23 -2
  236. package/dist/http-request/user-agent.js +48 -6
  237. package/dist/integrity.d.ts +3 -1
  238. package/dist/integrity.js +3 -1
  239. package/dist/json/format.js +4 -1
  240. package/dist/logger/_internal.d.ts +13 -15
  241. package/dist/logger/_internal.js +21 -21
  242. package/dist/logger/colors.d.ts +9 -3
  243. package/dist/logger/colors.js +6 -13
  244. package/dist/logger/console-methods.js +2 -2
  245. package/dist/logger/console.d.ts +1 -0
  246. package/dist/logger/console.js +9 -9
  247. package/dist/logger/node.js +2 -1
  248. package/dist/native-messaging/install.js +1 -1
  249. package/dist/native-messaging/rate-limit.d.ts +4 -1
  250. package/dist/native-messaging/rate-limit.js +4 -1
  251. package/dist/node/events.d.ts +3 -0
  252. package/dist/node/events.js +3 -0
  253. package/dist/node/fs.d.ts +1 -1
  254. package/dist/node/timers-promises.d.ts +3 -0
  255. package/dist/node/timers-promises.js +3 -0
  256. package/dist/node/url.d.ts +3 -0
  257. package/dist/node/url.js +3 -0
  258. package/dist/npm/meta-cache.d.ts +183 -0
  259. package/dist/npm/meta-cache.js +318 -0
  260. package/dist/npm/meta-slice.d.ts +27 -0
  261. package/dist/npm/meta-slice.js +68 -0
  262. package/dist/npm/meta-types.d.ts +282 -0
  263. package/dist/npm/meta-types.js +2 -0
  264. package/dist/npm/meta.d.ts +125 -0
  265. package/dist/npm/meta.js +347 -0
  266. package/dist/npm/registry.d.ts +212 -0
  267. package/dist/npm/registry.js +284 -0
  268. package/dist/objects/getters.d.ts +1 -1
  269. package/dist/objects/getters.js +1 -1
  270. package/dist/packages/manifest.js +6 -7
  271. package/dist/packages/metadata-extensions.js +2 -4
  272. package/dist/packages/provenance.d.ts +8 -0
  273. package/dist/packages/provenance.js +8 -0
  274. package/dist/packages/tarball.js +1 -2
  275. package/dist/packages/validation.d.ts +0 -10
  276. package/dist/packages/validation.js +0 -14
  277. package/dist/paths/exts.d.ts +30 -0
  278. package/dist/paths/exts.js +30 -0
  279. package/dist/paths/filenames.d.ts +6 -0
  280. package/dist/paths/filenames.js +6 -0
  281. package/dist/paths/globs.d.ts +6 -0
  282. package/dist/paths/globs.js +6 -0
  283. package/dist/paths/resolve.js +19 -14
  284. package/dist/paths/socket.d.ts +8 -8
  285. package/dist/paths/socket.js +8 -8
  286. package/dist/perf/report.js +4 -2
  287. package/dist/pkg-ext/data.js +0 -2
  288. package/dist/primordials/globals.d.ts +1 -1
  289. package/dist/primordials/globals.js +1 -1
  290. package/dist/primordials/headers.d.ts +13 -1
  291. package/dist/primordials/headers.js +13 -1
  292. package/dist/primordials/process.d.ts +1 -1
  293. package/dist/primordials/process.js +1 -1
  294. package/dist/primordials/url.d.ts +18 -0
  295. package/dist/primordials/url.js +18 -0
  296. package/dist/process/spawn/child.js +3 -5
  297. package/dist/promises/_internal.d.ts +1 -1
  298. package/dist/promises/_internal.js +1 -2
  299. package/dist/promises/options.js +3 -3
  300. package/dist/releases/socket-btm-binary-naming.js +12 -1
  301. package/dist/secrets/_internal.d.ts +1 -1
  302. package/dist/secrets/_internal.js +1 -1
  303. package/dist/secrets/find.d.ts +2 -2
  304. package/dist/secrets/find.js +2 -2
  305. package/dist/secrets/keychain.d.ts +10 -1
  306. package/dist/secrets/keychain.js +10 -1
  307. package/dist/secrets/socket-api-token.d.ts +1 -1
  308. package/dist/secrets/socket-api-token.js +1 -1
  309. package/dist/secrets/types.d.ts +1 -1
  310. package/dist/smol/http.d.ts +2 -0
  311. package/dist/smol/http.js +2 -0
  312. package/dist/smol/https.d.ts +2 -0
  313. package/dist/smol/https.js +2 -0
  314. package/dist/sorts/_internal.d.ts +2 -3
  315. package/dist/sorts/_internal.js +1 -3
  316. package/dist/spinner/format.js +2 -4
  317. package/dist/stdio/footer.js +8 -7
  318. package/dist/stdio/prompts.d.ts +8 -15
  319. package/dist/stdio/prompts.js +18 -29
  320. package/dist/strings/predicates.d.ts +2 -2
  321. package/dist/strings/search.js +1 -1
  322. package/dist/strings/types.d.ts +4 -0
  323. package/dist/strings/width.d.ts +1 -0
  324. package/dist/strings/width.js +17 -8
  325. package/dist/themes/context.d.ts +13 -0
  326. package/dist/themes/context.js +23 -8
  327. package/dist/versions/_internal.d.ts +43 -13
  328. package/dist/versions/_internal.js +27 -15
  329. package/dist/versions/compare.d.ts +16 -10
  330. package/dist/versions/compare.js +36 -16
  331. package/dist/versions/parse.js +1 -1
  332. package/dist/versions/range.js +3 -2
  333. package/dist/words/pluralize.js +4 -1
  334. package/llms.txt +63 -750
  335. package/package.json +200 -35
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  /* Socket Lib - Built with rolldown */
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+ let _socketsecurity_lib_paths_normalize = require("@socketsecurity/lib/paths/normalize");
4
5
 
5
6
  //#region src/bin/shadow.ts
6
7
  /**
@@ -20,7 +21,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
20
21
  */
21
22
  function isShadowBinPath(dirPath) {
22
23
  if (!dirPath) return false;
23
- return dirPath.replace(/\\/g, "/").includes("node_modules/.bin");
24
+ return (0, _socketsecurity_lib_paths_normalize.normalizePath)(dirPath).includes("node_modules/.bin");
24
25
  }
25
26
 
26
27
  //#endregion
@@ -8,9 +8,11 @@
8
8
  * through `resolveRealBinSync` so the caller gets the underlying script path
9
9
  * (e.g., `npm-cli.js`) rather than the wrapper. Default `nothrow: true` so a
10
10
  * missing binary returns `undefined` instead of bubbling a `which` package
11
- * error. Caching matches `_internal.binPathCache` and `binPathAllCache`. Both
12
- * caches validate hits with `existsSync` so a tool reinstall mid-session
13
- * doesn't return a stale path.
11
+ * error. `whichLocalBin` resolves a tool from the project-local
12
+ * `node_modules/.bin` (the inverse of `findRealBin`, which skips it). Caching
13
+ * matches `_internal.binPathCache` and `binPathAllCache`. Both caches
14
+ * validate hits with `existsSync` so a tool reinstall mid-session doesn't
15
+ * return a stale path.
14
16
  */
15
17
  import type { WhichOptions } from './types';
16
18
  /**
@@ -47,6 +49,29 @@ import type { WhichOptions } from './types';
47
49
  * path, the original path, or null if not found.
48
50
  */
49
51
  export declare function which(binName: string, options?: WhichOptions): Promise<string | string[] | null>;
52
+ /**
53
+ * Resolve a tool installed in the project-local `node_modules/.bin` to its
54
+ * ABSOLUTE path. This is the inverse of findRealBin: that helper SKIPS
55
+ * node_modules/.bin (shadow bins) to find the real package manager behind a
56
+ * tool's shim, whereas whichLocalBin WANTS the local bin — it is for spawning a
57
+ * dev dependency's own CLI (oxlint, vitest, tsc) directly instead of through
58
+ * `pnpm exec`. Returns the platform-correct absolute path (the .cmd / .exe shim
59
+ * on Windows, the symlink on POSIX), falling back to a plain PATH lookup, or
60
+ * undefined when the tool resolves nowhere. `options.cwd` overrides the project
61
+ * root whose node_modules/.bin is searched (default process.cwd()); an explicit
62
+ * `options.path` replaces that local bin dir entirely.
63
+ *
64
+ * In npm's terminology this is "local" (vs "global" with `-g`): a locally
65
+ * installed package's executables are linked into node_modules/.bin. See
66
+ * https://docs.npmjs.com/cli/v11/configuring-npm/folders#executables.
67
+ *
68
+ * @example
69
+ * ;```typescript
70
+ * whichLocalBin('oxlint') // '/repo/node_modules/.bin/oxlint'
71
+ * whichLocalBin('missing') // undefined
72
+ * ```
73
+ */
74
+ export declare function whichLocalBin(binName: string, options?: WhichOptions): string | undefined;
50
75
  /**
51
76
  * Find a binary in the system PATH and resolve to the real underlying script
52
77
  * asynchronously. Resolves wrapper scripts (.cmd, .ps1, shell scripts) to the
package/dist/bin/which.js CHANGED
@@ -5,8 +5,11 @@ const require_runtime = require('../_virtual/_rolldown/runtime.js');
5
5
  const require_paths_predicates = require('../paths/predicates.js');
6
6
  const require_primordials_array = require('../primordials/array.js');
7
7
  const require_node_fs = require('../node/fs.js');
8
+ const require_node_path = require('../node/path.js');
8
9
  const require_bin__internal = require('./_internal.js');
9
10
  const require_bin_resolve = require('./resolve.js');
11
+ let node_process = require("node:process");
12
+ node_process = require_runtime.__toESM(node_process);
10
13
  let src_external_which = require("../external/which");
11
14
  src_external_which = require_runtime.__toESM(src_external_which);
12
15
 
@@ -21,9 +24,11 @@ src_external_which = require_runtime.__toESM(src_external_which);
21
24
  * through `resolveRealBinSync` so the caller gets the underlying script path
22
25
  * (e.g., `npm-cli.js`) rather than the wrapper. Default `nothrow: true` so a
23
26
  * missing binary returns `undefined` instead of bubbling a `which` package
24
- * error. Caching matches `_internal.binPathCache` and `binPathAllCache`. Both
25
- * caches validate hits with `existsSync` so a tool reinstall mid-session
26
- * doesn't return a stale path.
27
+ * error. `whichLocalBin` resolves a tool from the project-local
28
+ * `node_modules/.bin` (the inverse of `findRealBin`, which skips it). Caching
29
+ * matches `_internal.binPathCache` and `binPathAllCache`. Both caches
30
+ * validate hits with `existsSync` so a tool reinstall mid-session doesn't
31
+ * return a stale path.
27
32
  */
28
33
  /**
29
34
  * Find an executable in the system PATH asynchronously.
@@ -67,6 +72,42 @@ async function which(binName, options) {
67
72
  }
68
73
  }
69
74
  /**
75
+ * Resolve a tool installed in the project-local `node_modules/.bin` to its
76
+ * ABSOLUTE path. This is the inverse of findRealBin: that helper SKIPS
77
+ * node_modules/.bin (shadow bins) to find the real package manager behind a
78
+ * tool's shim, whereas whichLocalBin WANTS the local bin — it is for spawning a
79
+ * dev dependency's own CLI (oxlint, vitest, tsc) directly instead of through
80
+ * `pnpm exec`. Returns the platform-correct absolute path (the .cmd / .exe shim
81
+ * on Windows, the symlink on POSIX), falling back to a plain PATH lookup, or
82
+ * undefined when the tool resolves nowhere. `options.cwd` overrides the project
83
+ * root whose node_modules/.bin is searched (default process.cwd()); an explicit
84
+ * `options.path` replaces that local bin dir entirely.
85
+ *
86
+ * In npm's terminology this is "local" (vs "global" with `-g`): a locally
87
+ * installed package's executables are linked into node_modules/.bin. See
88
+ * https://docs.npmjs.com/cli/v11/configuring-npm/folders#executables.
89
+ *
90
+ * @example
91
+ * ;```typescript
92
+ * whichLocalBin('oxlint') // '/repo/node_modules/.bin/oxlint'
93
+ * whichLocalBin('missing') // undefined
94
+ * ```
95
+ */
96
+ function whichLocalBin(binName, options) {
97
+ const opts = {
98
+ __proto__: null,
99
+ ...options
100
+ };
101
+ const path = require_node_path.getNodePath();
102
+ const local = whichSync(binName, {
103
+ nothrow: true,
104
+ path: opts.path ?? path.join(opts.cwd ?? node_process.default.cwd(), "node_modules", ".bin")
105
+ });
106
+ if (typeof local === "string") return local;
107
+ const found = whichSync(binName, { nothrow: true });
108
+ return typeof found === "string" ? found : void 0;
109
+ }
110
+ /**
70
111
  * Find a binary in the system PATH and resolve to the real underlying script
71
112
  * asynchronously. Resolves wrapper scripts (.cmd, .ps1, shell scripts) to the
72
113
  * actual .js files they execute.
@@ -215,6 +256,7 @@ function whichSync(binName, options) {
215
256
 
216
257
  //#endregion
217
258
  exports.which = which;
259
+ exports.whichLocalBin = whichLocalBin;
218
260
  exports.whichReal = whichReal;
219
261
  exports.whichRealSync = whichRealSync;
220
262
  exports.whichSync = whichSync;
@@ -2,9 +2,17 @@
2
2
  * @file Accessor for the vendored `cacache` module. Centralised so other
3
3
  * `cacache/*` leaves stay decoupled from the import path — if the vendoring
4
4
  * moves, only this leaf updates.
5
+ * Snapshot safety: the vendored `cacache` resolves through the npm-pack
6
+ * bundle, whose module-eval constructs a live native `[Foreign]` handle.
7
+ * Importing it at module load pins that handle into the heap and aborts
8
+ * `node --build-snapshot`, so the require is deferred to first use and
9
+ * memoized.
5
10
  */
11
+ import type cacache from '../external/cacache';
6
12
  /**
7
- * Get the cacache module for cache operations.
13
+ * Get the cacache module for cache operations. Required lazily on first call so
14
+ * importing a `cacache/*` leaf does not pull in the native-handle-bearing
15
+ * npm-pack bundle.
8
16
  *
9
17
  * @example
10
18
  * ;```typescript
@@ -12,4 +20,4 @@
12
20
  * const entries = await cacache.ls(cacheDir)
13
21
  * ```
14
22
  */
15
- export declare function getCacache(): import("../external/cacache").CacacheInstance;
23
+ export declare function getCacache(): typeof cacache;
@@ -1,18 +1,13 @@
1
1
  "use strict";
2
2
  /* Socket Lib - Built with rolldown */
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
- const require_runtime = require('../_virtual/_rolldown/runtime.js');
5
- let src_external_cacache = require("../external/cacache");
6
- src_external_cacache = require_runtime.__toESM(src_external_cacache);
7
4
 
8
5
  //#region src/cacache/_internal.ts
6
+ let cached;
9
7
  /**
10
- * @file Accessor for the vendored `cacache` module. Centralised so other
11
- * `cacache/*` leaves stay decoupled from the import path — if the vendoring
12
- * moves, only this leaf updates.
13
- */
14
- /**
15
- * Get the cacache module for cache operations.
8
+ * Get the cacache module for cache operations. Required lazily on first call so
9
+ * importing a `cacache/*` leaf does not pull in the native-handle-bearing
10
+ * npm-pack bundle.
16
11
  *
17
12
  * @example
18
13
  * ;```typescript
@@ -21,7 +16,8 @@ src_external_cacache = require_runtime.__toESM(src_external_cacache);
21
16
  * ```
22
17
  */
23
18
  function getCacache() {
24
- return src_external_cacache.default;
19
+ if (cached === void 0) cached = require("../external/cacache");
20
+ return cached;
25
21
  }
26
22
 
27
23
  //#endregion
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @file Private internals shared by the `cache/ttl/*` stores — the TTL /
3
+ * prefix / memo-cap defaults, the clock-skew-aware expiry predicate, the
4
+ * wildcard key matcher, and the LRU insertion-order setter. One owner so the
5
+ * node store (`./store`, cacache-backed) and the browser store
6
+ * (`./browser`, adapter-backed) cannot drift on expiry or matching
7
+ * semantics. Pure helpers over primordials only — no `node:*`, no
8
+ * `process`, so both stores stay importable from browser bundles.
9
+ */
10
+ import type { TtlCacheEntry } from './types';
11
+ export declare const DEFAULT_MEMO_MAX_SIZE = 1000;
12
+ export declare const DEFAULT_PREFIX = "ttl-cache";
13
+ export declare const DEFAULT_TTL_MS: number;
14
+ /**
15
+ * Create a matcher for a key pattern (with wildcard support) against FULL
16
+ * (prefixed) cache keys. Without a wildcard the pattern is a plain prefix
17
+ * match; with wildcards the pattern is anchored both ends so `foo*bar`
18
+ * matches exactly `foo<anything>bar`.
19
+ */
20
+ export declare function createKeyMatcher(prefix: string, pattern: string): (fullKey: string) => boolean;
21
+ /**
22
+ * Check if an entry is expired for the given ttl. Also detects clock skew by
23
+ * treating a suspiciously far-future `expiresAt` (more than 10 seconds past
24
+ * the expected `now + ttl` horizon) as expired.
25
+ */
26
+ export declare function isExpiredEntry(entry: TtlCacheEntry<unknown>, ttl: number): boolean;
27
+ /**
28
+ * Set an entry in a memo Map capped at `maxSize`, using the Map's
29
+ * insertion-order semantics as the LRU list: an existing key is deleted first
30
+ * so the re-insert moves it to the tail, and when the cap is hit the oldest
31
+ * entry (first key in iteration order) is evicted.
32
+ */
33
+ export declare function lruSet(map: Map<string, TtlCacheEntry<unknown>>, maxSize: number, key: string, entry: TtlCacheEntry<unknown>): void;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ /* Socket Lib - Built with rolldown */
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+ const require_primordials_string = require('../../primordials/string.js');
5
+ const require_primordials_regexp = require('../../primordials/regexp.js');
6
+ const require_primordials_date = require('../../primordials/date.js');
7
+
8
+ //#region src/cache/ttl/_internal.ts
9
+ /**
10
+ * @file Private internals shared by the `cache/ttl/*` stores — the TTL /
11
+ * prefix / memo-cap defaults, the clock-skew-aware expiry predicate, the
12
+ * wildcard key matcher, and the LRU insertion-order setter. One owner so the
13
+ * node store (`./store`, cacache-backed) and the browser store
14
+ * (`./browser`, adapter-backed) cannot drift on expiry or matching
15
+ * semantics. Pure helpers over primordials only — no `node:*`, no
16
+ * `process`, so both stores stay importable from browser bundles.
17
+ */
18
+ const DEFAULT_MEMO_MAX_SIZE = 1e3;
19
+ const DEFAULT_PREFIX = "ttl-cache";
20
+ const DEFAULT_TTL_MS = 300 * 1e3;
21
+ const MAX_FUTURE_SKEW_MS = 1e4;
22
+ /**
23
+ * Create a matcher for a key pattern (with wildcard support) against FULL
24
+ * (prefixed) cache keys. Without a wildcard the pattern is a plain prefix
25
+ * match; with wildcards the pattern is anchored both ends so `foo*bar`
26
+ * matches exactly `foo<anything>bar`.
27
+ */
28
+ function createKeyMatcher(prefix, pattern) {
29
+ const fullPattern = `${prefix}:${pattern}`;
30
+ if (!pattern.includes("*")) return (fullKey) => require_primordials_string.StringPrototypeStartsWith(fullKey, fullPattern);
31
+ const regex = new require_primordials_regexp.RegExpCtor(`^${require_primordials_string.StringPrototypeReplaceAll(require_primordials_string.StringPrototypeReplaceAll(fullPattern, /[.+?^${}()|[\]\\]/g, "\\$&"), "*", ".*")}$`);
32
+ return (fullKey) => require_primordials_regexp.RegExpPrototypeTest(regex, fullKey);
33
+ }
34
+ /**
35
+ * Check if an entry is expired for the given ttl. Also detects clock skew by
36
+ * treating a suspiciously far-future `expiresAt` (more than 10 seconds past
37
+ * the expected `now + ttl` horizon) as expired.
38
+ */
39
+ function isExpiredEntry(entry, ttl) {
40
+ const now = require_primordials_date.DateNow();
41
+ if (entry.expiresAt > now + ttl + MAX_FUTURE_SKEW_MS) return true;
42
+ return now > entry.expiresAt;
43
+ }
44
+ /**
45
+ * Set an entry in a memo Map capped at `maxSize`, using the Map's
46
+ * insertion-order semantics as the LRU list: an existing key is deleted first
47
+ * so the re-insert moves it to the tail, and when the cap is hit the oldest
48
+ * entry (first key in iteration order) is evicted.
49
+ */
50
+ function lruSet(map, maxSize, key, entry) {
51
+ if (map.has(key)) map.delete(key);
52
+ else if (map.size >= maxSize) {
53
+ const oldest = map.keys().next().value;
54
+ /* c8 ignore start - defensive unreachable branch */
55
+ if (oldest === void 0) return;
56
+ /* c8 ignore stop */
57
+ map.delete(oldest);
58
+ }
59
+ map.set(key, entry);
60
+ }
61
+
62
+ //#endregion
63
+ exports.DEFAULT_MEMO_MAX_SIZE = DEFAULT_MEMO_MAX_SIZE;
64
+ exports.DEFAULT_PREFIX = DEFAULT_PREFIX;
65
+ exports.DEFAULT_TTL_MS = DEFAULT_TTL_MS;
66
+ exports.createKeyMatcher = createKeyMatcher;
67
+ exports.isExpiredEntry = isExpiredEntry;
68
+ exports.lruSet = lruSet;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @file `createBrowserTtlCache` — browser-safe sibling of `createTtlCache`
3
+ * (`./store`). Same two-tier design and `TtlCache` contract, but the
4
+ * persistent tier is an injected `TtlCacheStorage` adapter (wrap
5
+ * `chrome.storage.local`, `sessionStorage` / `localStorage`, IndexedDB, …)
6
+ * instead of cacache, so the module's import graph stays primordials-only —
7
+ * safe for Chrome MV3 service workers, content scripts, popups, and web
8
+ * workers. Shared semantics live in `./_internal` (one owner, so the node
9
+ * and browser stores cannot drift): TTL default, clock-skew detection, LRU
10
+ * memo eviction via Map insertion order, prefix namespacing, wildcard
11
+ * matching. `getOrFetch` deduplicates concurrent fetches for the same key
12
+ * (thundering-herd protection), and single-key methods throw on `*`.
13
+ * Differences from `./store` (cacache-specific pieces that don't map):
14
+ *
15
+ * - No cacache `ls.stream` — `getAll` / `deleteAll` / `clear` enumerate the
16
+ * persistent tier only when the adapter provides the optional `keys()`
17
+ * (e.g. `chrome.storage.local.get(null)`, `sessionStorage.key(i)`). Without
18
+ * it they still cover the memo tier, and delete those memo keys from
19
+ * storage too; storage-only entries from previous sessions are then
20
+ * unreachable by wildcard but still expire per-entry on read.
21
+ * - No storage supplied ⇒ memo-only cache (all operations stay correct).
22
+ * - A corrupt or shape-invalid storage entry is treated as a miss and deleted
23
+ * best-effort; storage failures never throw — the memo tier is the source
24
+ * of truth, mirroring store.ts's cacache error handling.
25
+ */
26
+ import type { BrowserTtlCacheOptions, TtlCache } from './types';
27
+ /**
28
+ * Create a browser-safe TTL cache instance. Same contract as
29
+ * `createTtlCache`, with the persistent tier backed by the injected
30
+ * `storage` adapter (or absent, for a memo-only cache).
31
+ *
32
+ * @example
33
+ * ;```typescript
34
+ * const cache = createBrowserTtlCache({
35
+ * prefix: 'my-extension',
36
+ * storage: {
37
+ * async getItem(key) {
38
+ * return (await chrome.storage.local.get(key))[key]
39
+ * },
40
+ * async keys() {
41
+ * return Object.keys(await chrome.storage.local.get(null))
42
+ * },
43
+ * async removeItem(key) {
44
+ * await chrome.storage.local.remove(key)
45
+ * },
46
+ * async setItem(key, value) {
47
+ * await chrome.storage.local.set({ [key]: value })
48
+ * },
49
+ * },
50
+ * ttl: 60_000,
51
+ * })
52
+ * await cache.set('key', { value: 42 })
53
+ * const data = await cache.get('key') // { value: 42 }
54
+ * ```
55
+ */
56
+ export declare function createBrowserTtlCache(options?: BrowserTtlCacheOptions | undefined): TtlCache;
@@ -0,0 +1,257 @@
1
+ "use strict";
2
+ /* Socket Lib - Built with rolldown */
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+ const require_primordials_error = require('../../primordials/error.js');
5
+ const require_primordials_string = require('../../primordials/string.js');
6
+ const require_primordials_math = require('../../primordials/math.js');
7
+ const require_primordials_map_set = require('../../primordials/map-set.js');
8
+ const require_primordials_date = require('../../primordials/date.js');
9
+ const require_primordials_json = require('../../primordials/json.js');
10
+ const require_cache_ttl__internal = require('./_internal.js');
11
+
12
+ //#region src/cache/ttl/browser.ts
13
+ /**
14
+ * @file `createBrowserTtlCache` — browser-safe sibling of `createTtlCache`
15
+ * (`./store`). Same two-tier design and `TtlCache` contract, but the
16
+ * persistent tier is an injected `TtlCacheStorage` adapter (wrap
17
+ * `chrome.storage.local`, `sessionStorage` / `localStorage`, IndexedDB, …)
18
+ * instead of cacache, so the module's import graph stays primordials-only —
19
+ * safe for Chrome MV3 service workers, content scripts, popups, and web
20
+ * workers. Shared semantics live in `./_internal` (one owner, so the node
21
+ * and browser stores cannot drift): TTL default, clock-skew detection, LRU
22
+ * memo eviction via Map insertion order, prefix namespacing, wildcard
23
+ * matching. `getOrFetch` deduplicates concurrent fetches for the same key
24
+ * (thundering-herd protection), and single-key methods throw on `*`.
25
+ * Differences from `./store` (cacache-specific pieces that don't map):
26
+ *
27
+ * - No cacache `ls.stream` — `getAll` / `deleteAll` / `clear` enumerate the
28
+ * persistent tier only when the adapter provides the optional `keys()`
29
+ * (e.g. `chrome.storage.local.get(null)`, `sessionStorage.key(i)`). Without
30
+ * it they still cover the memo tier, and delete those memo keys from
31
+ * storage too; storage-only entries from previous sessions are then
32
+ * unreachable by wildcard but still expire per-entry on read.
33
+ * - No storage supplied ⇒ memo-only cache (all operations stay correct).
34
+ * - A corrupt or shape-invalid storage entry is treated as a miss and deleted
35
+ * best-effort; storage failures never throw — the memo tier is the source
36
+ * of truth, mirroring store.ts's cacache error handling.
37
+ */
38
+ /**
39
+ * Create a browser-safe TTL cache instance. Same contract as
40
+ * `createTtlCache`, with the persistent tier backed by the injected
41
+ * `storage` adapter (or absent, for a memo-only cache).
42
+ *
43
+ * @example
44
+ * ;```typescript
45
+ * const cache = createBrowserTtlCache({
46
+ * prefix: 'my-extension',
47
+ * storage: {
48
+ * async getItem(key) {
49
+ * return (await chrome.storage.local.get(key))[key]
50
+ * },
51
+ * async keys() {
52
+ * return Object.keys(await chrome.storage.local.get(null))
53
+ * },
54
+ * async removeItem(key) {
55
+ * await chrome.storage.local.remove(key)
56
+ * },
57
+ * async setItem(key, value) {
58
+ * await chrome.storage.local.set({ [key]: value })
59
+ * },
60
+ * },
61
+ * ttl: 60_000,
62
+ * })
63
+ * await cache.set('key', { value: 42 })
64
+ * const data = await cache.get('key') // { value: 42 }
65
+ * ```
66
+ */
67
+ function createBrowserTtlCache(options) {
68
+ const opts = {
69
+ __proto__: null,
70
+ memoize: true,
71
+ memoMaxSize: require_cache_ttl__internal.DEFAULT_MEMO_MAX_SIZE,
72
+ prefix: require_cache_ttl__internal.DEFAULT_PREFIX,
73
+ storage: void 0,
74
+ ttl: require_cache_ttl__internal.DEFAULT_TTL_MS,
75
+ ...options
76
+ };
77
+ if (opts.prefix?.includes("*")) throw new require_primordials_error.TypeErrorCtor("Cache prefix cannot contain wildcards (*). Use clear({ prefix: \"pattern*\" }) for wildcard matching.");
78
+ const { storage } = opts;
79
+ const memoCache = new require_primordials_map_set.MapCtor();
80
+ const memoMaxSize = require_primordials_math.MathMax(1, opts.memoMaxSize ?? 1e3);
81
+ const prefix = opts.prefix ?? "ttl-cache";
82
+ const ttl = opts.ttl ?? 3e5;
83
+ const fullPrefix = `${prefix}:`;
84
+ /**
85
+ * Build full cache key with prefix.
86
+ */
87
+ function buildKey(key) {
88
+ return `${fullPrefix}${key}`;
89
+ }
90
+ /**
91
+ * Best-effort deletion from the storage adapter — failures are swallowed.
92
+ */
93
+ async function removeQuietly(fullKey) {
94
+ if (!storage) return;
95
+ try {
96
+ await storage.removeItem(fullKey);
97
+ } catch {}
98
+ }
99
+ /**
100
+ * List the storage adapter's keys via its optional `keys()`. Returns an
101
+ * empty list when the adapter has no enumeration or when it fails.
102
+ */
103
+ async function listStorageKeys() {
104
+ if (!storage?.keys) return [];
105
+ try {
106
+ return await storage.keys();
107
+ } catch {
108
+ return [];
109
+ }
110
+ }
111
+ /**
112
+ * Read + parse + validate one entry from the storage adapter. Returns the
113
+ * live entry, or undefined on miss / corrupt / shape-invalid / expired —
114
+ * deleting dead entries best-effort.
115
+ */
116
+ async function readStorageEntry(fullKey) {
117
+ if (!storage) return;
118
+ let raw;
119
+ try {
120
+ raw = await storage.getItem(fullKey);
121
+ } catch {
122
+ return;
123
+ }
124
+ if (typeof raw !== "string") return;
125
+ let parsed;
126
+ try {
127
+ parsed = require_primordials_json.JSONParse(raw);
128
+ } catch {
129
+ await removeQuietly(fullKey);
130
+ return;
131
+ }
132
+ if (parsed === null || typeof parsed !== "object" || typeof parsed.expiresAt !== "number") {
133
+ await removeQuietly(fullKey);
134
+ return;
135
+ }
136
+ const entry = parsed;
137
+ if (require_cache_ttl__internal.isExpiredEntry(entry, ttl)) {
138
+ await removeQuietly(fullKey);
139
+ return;
140
+ }
141
+ return entry;
142
+ }
143
+ async function get(key) {
144
+ if (require_primordials_string.StringPrototypeIncludes(key, "*")) throw new require_primordials_error.TypeErrorCtor("Cache key cannot contain wildcards (*). Use getAll(pattern) to retrieve multiple entries.");
145
+ const fullKey = buildKey(key);
146
+ if (opts.memoize) {
147
+ const memoEntry = memoCache.get(fullKey);
148
+ if (memoEntry && !require_cache_ttl__internal.isExpiredEntry(memoEntry, ttl)) {
149
+ require_cache_ttl__internal.lruSet(memoCache, memoMaxSize, fullKey, memoEntry);
150
+ return memoEntry.data;
151
+ }
152
+ if (memoEntry) memoCache.delete(fullKey);
153
+ }
154
+ const entry = await readStorageEntry(fullKey);
155
+ if (entry) {
156
+ if (opts.memoize) require_cache_ttl__internal.lruSet(memoCache, memoMaxSize, fullKey, entry);
157
+ return entry.data;
158
+ }
159
+ }
160
+ async function getAll(pattern) {
161
+ const results = new require_primordials_map_set.MapCtor();
162
+ const matches = require_cache_ttl__internal.createKeyMatcher(prefix, pattern);
163
+ if (opts.memoize) for (const { 0: fullKey, 1: entry } of memoCache.entries()) {
164
+ if (!matches(fullKey)) continue;
165
+ if (require_cache_ttl__internal.isExpiredEntry(entry, ttl)) {
166
+ memoCache.delete(fullKey);
167
+ continue;
168
+ }
169
+ results.set(require_primordials_string.StringPrototypeSlice(fullKey, fullPrefix.length), entry.data);
170
+ }
171
+ for (const fullKey of await listStorageKeys()) {
172
+ if (!require_primordials_string.StringPrototypeStartsWith(fullKey, fullPrefix) || !matches(fullKey)) continue;
173
+ const originalKey = require_primordials_string.StringPrototypeSlice(fullKey, fullPrefix.length);
174
+ if (results.has(originalKey)) continue;
175
+ const entry = await readStorageEntry(fullKey);
176
+ if (!entry) continue;
177
+ results.set(originalKey, entry.data);
178
+ if (opts.memoize) require_cache_ttl__internal.lruSet(memoCache, memoMaxSize, fullKey, entry);
179
+ }
180
+ return results;
181
+ }
182
+ async function set(key, data) {
183
+ if (require_primordials_string.StringPrototypeIncludes(key, "*")) throw new require_primordials_error.TypeErrorCtor("Cache key cannot contain wildcards (*). Wildcards are only supported in clear({ prefix: \"pattern*\" }).");
184
+ const fullKey = buildKey(key);
185
+ const entry = {
186
+ data,
187
+ expiresAt: require_primordials_date.DateNow() + ttl
188
+ };
189
+ if (opts.memoize) require_cache_ttl__internal.lruSet(memoCache, memoMaxSize, fullKey, entry);
190
+ if (storage) try {
191
+ await storage.setItem(fullKey, require_primordials_json.JSONStringify(entry));
192
+ } catch {}
193
+ }
194
+ const inflightRequests = new require_primordials_map_set.MapCtor();
195
+ async function getOrFetch(key, fetcher) {
196
+ const fullKey = buildKey(key);
197
+ const preexisting = inflightRequests.get(fullKey);
198
+ if (preexisting) return await preexisting;
199
+ const cached = await get(key);
200
+ if (cached !== void 0) return cached;
201
+ const rechecked = inflightRequests.get(fullKey);
202
+ if (rechecked) return await rechecked;
203
+ const promise = (async () => {
204
+ try {
205
+ const data = await fetcher();
206
+ await set(key, data);
207
+ return data;
208
+ } finally {
209
+ inflightRequests.delete(fullKey);
210
+ }
211
+ })();
212
+ inflightRequests.set(fullKey, promise);
213
+ return await promise;
214
+ }
215
+ async function deleteEntry(key) {
216
+ if (require_primordials_string.StringPrototypeIncludes(key, "*")) throw new require_primordials_error.TypeErrorCtor("Cache key cannot contain wildcards (*). Use deleteAll(pattern) to remove multiple entries.");
217
+ const fullKey = buildKey(key);
218
+ memoCache.delete(fullKey);
219
+ await removeQuietly(fullKey);
220
+ }
221
+ async function deleteAll(pattern) {
222
+ const matches = pattern ? require_cache_ttl__internal.createKeyMatcher(prefix, pattern) : void 0;
223
+ const removedKeys = new require_primordials_map_set.SetCtor();
224
+ for (const fullKey of memoCache.keys()) if (!matches || matches(fullKey)) removedKeys.add(fullKey);
225
+ for (const fullKey of await listStorageKeys()) {
226
+ if (!require_primordials_string.StringPrototypeStartsWith(fullKey, fullPrefix)) continue;
227
+ if (!matches || matches(fullKey)) removedKeys.add(fullKey);
228
+ }
229
+ for (const fullKey of removedKeys) {
230
+ memoCache.delete(fullKey);
231
+ await removeQuietly(fullKey);
232
+ }
233
+ return removedKeys.size;
234
+ }
235
+ async function clear(clearOptions) {
236
+ if ({
237
+ __proto__: null,
238
+ ...clearOptions
239
+ }.memoOnly) {
240
+ memoCache.clear();
241
+ return;
242
+ }
243
+ await deleteAll();
244
+ }
245
+ return {
246
+ clear,
247
+ delete: deleteEntry,
248
+ deleteAll,
249
+ get,
250
+ getAll,
251
+ getOrFetch,
252
+ set
253
+ };
254
+ }
255
+
256
+ //#endregion
257
+ exports.createBrowserTtlCache = createBrowserTtlCache;