nitro 3.0.1-alpha.2 → 3.0.260415-beta

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 (297) hide show
  1. package/LICENSE +6 -0
  2. package/README.md +2 -2
  3. package/dist/THIRD-PARTY-LICENSES.md +1646 -0
  4. package/dist/_build/common.mjs +7261 -3812
  5. package/dist/_build/rolldown.mjs +32 -42
  6. package/dist/_build/rollup.mjs +28 -48
  7. package/dist/_build/vite.build.mjs +10 -10
  8. package/dist/_chunks/nitro.mjs +102 -327
  9. package/dist/_chunks/nitro2.mjs +8 -9
  10. package/dist/_chunks/nitro3.mjs +136 -0
  11. package/dist/_chunks/nitro4.mjs +127 -0
  12. package/dist/_chunks/utils.mjs +40 -29
  13. package/dist/_common.mjs +13 -25
  14. package/dist/_dev.d.mts +0 -3
  15. package/dist/{_chunks/dev.mjs → _dev.mjs} +132 -330
  16. package/dist/_libs/_.mjs +2 -0
  17. package/dist/_libs/_2.mjs +2 -0
  18. package/dist/_libs/_3.mjs +2 -0
  19. package/dist/_libs/_4.mjs +2 -0
  20. package/dist/_libs/_5.mjs +2 -0
  21. package/dist/_libs/_6.mjs +2 -0
  22. package/dist/_libs/_7.mjs +2 -0
  23. package/dist/_libs/c12+rc9.mjs +814 -0
  24. package/dist/_libs/{c12+giget+readdirp+chokidar.d.mts → c12+readdirp+chokidar.d.mts} +49 -40
  25. package/dist/_libs/citty.mjs +142 -41
  26. package/dist/_libs/commondir+is-reference.mjs +60 -56
  27. package/dist/_libs/compatx.d.mts +0 -2
  28. package/dist/_libs/compatx.mjs +1 -4
  29. package/dist/_libs/esbuild.d.mts +0 -1
  30. package/dist/_libs/escape-string-regexp.mjs +1 -4
  31. package/dist/_libs/{pluginutils+plugin-commonjs.d.mts → estree+pluginutils.d.mts} +0 -5
  32. package/dist/_libs/estree-walker.mjs +4 -92
  33. package/dist/_libs/exsolve.d.mts +1 -0
  34. package/dist/_libs/hasown+resolve+deepmerge.mjs +160 -246
  35. package/dist/_libs/httpxy.d.mts +20 -13
  36. package/dist/_libs/httpxy.mjs +519 -95
  37. package/dist/_libs/js-tokens.d.mts +1 -0
  38. package/dist/_libs/klona.mjs +1 -4
  39. package/dist/_libs/magic-string.d.mts +0 -2
  40. package/dist/_libs/mlly.d.mts +0 -2
  41. package/dist/_libs/nypm+tinyexec.mjs +822 -0
  42. package/dist/_libs/perfect-debounce.mjs +68 -0
  43. package/dist/_libs/pkg-types.d.mts +0 -3
  44. package/dist/_libs/plugin-alias.mjs +1 -5
  45. package/dist/_libs/plugin-inject.mjs +1 -7
  46. package/dist/_libs/plugin-json.mjs +1 -5
  47. package/dist/_libs/pluginutils.mjs +3 -35
  48. package/dist/_libs/readdirp+chokidar.mjs +187 -365
  49. package/dist/_libs/remapping.mjs +1 -5
  50. package/dist/_libs/resolve-uri+gen-mapping.mjs +15 -53
  51. package/dist/_libs/rou3.d.mts +1 -4
  52. package/dist/_libs/rou3.mjs +223 -78
  53. package/dist/_libs/std-env.d.mts +8 -2
  54. package/dist/_libs/strip-literal.d.mts +1 -0
  55. package/dist/_libs/tsconfck.mjs +21 -334
  56. package/dist/_libs/ultrahtml.mjs +3 -16
  57. package/dist/_libs/unimport+unplugin.mjs +244 -388
  58. package/dist/_libs/unplugin+unimport.d.mts +5 -15
  59. package/dist/_libs/unwasm.d.mts +0 -3
  60. package/dist/_presets.mjs +576 -488
  61. package/dist/builder.d.mts +5 -25
  62. package/dist/builder.mjs +3 -8
  63. package/dist/cli/_chunks/build.mjs +22 -25
  64. package/dist/cli/_chunks/common.mjs +1 -4
  65. package/dist/cli/_chunks/deploy.mjs +37 -0
  66. package/dist/cli/_chunks/dev.mjs +6 -11
  67. package/dist/cli/_chunks/docs.mjs +28 -0
  68. package/dist/cli/_chunks/list.mjs +4 -8
  69. package/dist/cli/_chunks/prepare.mjs +2 -6
  70. package/dist/cli/_chunks/preview.mjs +48 -0
  71. package/dist/cli/_chunks/run.mjs +7 -11
  72. package/dist/cli/_chunks/task.mjs +1 -5
  73. package/dist/cli/index.mjs +5 -6
  74. package/dist/docs/0.docs/0.index/index.md +56 -0
  75. package/dist/docs/0.docs/1.quick-start.md +110 -0
  76. package/dist/docs/0.docs/10.lifecycle.md +204 -0
  77. package/dist/docs/0.docs/11.openapi.md +291 -0
  78. package/dist/docs/0.docs/12.plugins.md +164 -0
  79. package/dist/docs/0.docs/13.tasks.md +277 -0
  80. package/dist/docs/0.docs/14.websocket.md +386 -0
  81. package/dist/docs/0.docs/15.migration.md +213 -0
  82. package/dist/docs/0.docs/16.nightly.md +31 -0
  83. package/dist/docs/0.docs/2.renderer.md +322 -0
  84. package/dist/docs/0.docs/3.routing.md +711 -0
  85. package/dist/docs/0.docs/4.server-entry.md +239 -0
  86. package/dist/docs/0.docs/5.cache.md +408 -0
  87. package/dist/docs/0.docs/6.storage.md +261 -0
  88. package/dist/docs/0.docs/7.assets.md +166 -0
  89. package/dist/docs/0.docs/8.configuration.md +256 -0
  90. package/dist/docs/0.docs/9.database.md +185 -0
  91. package/dist/docs/1.deploy/0.index/index.md +64 -0
  92. package/dist/docs/1.deploy/1.runtimes/0.node.md +63 -0
  93. package/dist/docs/1.deploy/1.runtimes/1.bun.md +15 -0
  94. package/dist/docs/1.deploy/1.runtimes/2.deno.md +19 -0
  95. package/dist/docs/1.deploy/2.providers/0.alwaysdata.md +50 -0
  96. package/dist/docs/1.deploy/2.providers/1.aws.md +47 -0
  97. package/dist/docs/1.deploy/2.providers/10.flightcontrol.md +67 -0
  98. package/dist/docs/1.deploy/2.providers/11.genezio.md +67 -0
  99. package/dist/docs/1.deploy/2.providers/12.github-pages.md +68 -0
  100. package/dist/docs/1.deploy/2.providers/13.gitlab-pages.md +37 -0
  101. package/dist/docs/1.deploy/2.providers/14.heroku.md +84 -0
  102. package/dist/docs/1.deploy/2.providers/15.iis.md +38 -0
  103. package/dist/docs/1.deploy/2.providers/16.koyeb.md +109 -0
  104. package/dist/docs/1.deploy/2.providers/17.netlify.md +47 -0
  105. package/dist/docs/1.deploy/2.providers/18.platform-sh.md +37 -0
  106. package/dist/docs/1.deploy/2.providers/19.render.md +37 -0
  107. package/dist/docs/1.deploy/2.providers/2.aws-amplify.md +81 -0
  108. package/dist/docs/1.deploy/2.providers/20.stormkit.md +24 -0
  109. package/dist/docs/1.deploy/2.providers/21.vercel.md +270 -0
  110. package/dist/docs/1.deploy/2.providers/22.zeabur.md +19 -0
  111. package/dist/docs/1.deploy/2.providers/23.zephyr.md +99 -0
  112. package/dist/docs/1.deploy/2.providers/24.zerops.md +102 -0
  113. package/dist/docs/1.deploy/2.providers/3.azure.md +72 -0
  114. package/dist/docs/1.deploy/2.providers/4.cleavr.md +33 -0
  115. package/dist/docs/1.deploy/2.providers/5.cloudflare.md +369 -0
  116. package/dist/docs/1.deploy/2.providers/6.deno-deploy.md +66 -0
  117. package/dist/docs/1.deploy/2.providers/7.digitalocean.md +46 -0
  118. package/dist/docs/1.deploy/2.providers/8.edgeone.md +20 -0
  119. package/dist/docs/1.deploy/2.providers/9.firebase.md +32 -0
  120. package/dist/docs/2.config/0.index/index.md +1221 -0
  121. package/dist/docs/3.examples/0.index/index.md +3 -0
  122. package/dist/docs/3.examples/1.api-routes.md +145 -0
  123. package/dist/docs/3.examples/10.hono.md +74 -0
  124. package/dist/docs/3.examples/11.import-alias.md +97 -0
  125. package/dist/docs/3.examples/12.middleware.md +91 -0
  126. package/dist/docs/3.examples/13.mono-jsx.md +68 -0
  127. package/dist/docs/3.examples/14.nano-jsx.md +70 -0
  128. package/dist/docs/3.examples/15.plugins.md +91 -0
  129. package/dist/docs/3.examples/16.renderer.md +113 -0
  130. package/dist/docs/3.examples/17.runtime-config.md +97 -0
  131. package/dist/docs/3.examples/18.server-fetch.md +87 -0
  132. package/dist/docs/3.examples/19.shiki.md +198 -0
  133. package/dist/docs/3.examples/2.auto-imports.md +92 -0
  134. package/dist/docs/3.examples/20.virtual-routes.md +74 -0
  135. package/dist/docs/3.examples/21.vite-nitro-plugin.md +79 -0
  136. package/dist/docs/3.examples/22.vite-rsc.md +1041 -0
  137. package/dist/docs/3.examples/23.vite-ssr-html.md +217 -0
  138. package/dist/docs/3.examples/24.vite-ssr-preact.md +247 -0
  139. package/dist/docs/3.examples/25.vite-ssr-react.md +226 -0
  140. package/dist/docs/3.examples/26.vite-ssr-solid.md +256 -0
  141. package/dist/docs/3.examples/27.vite-ssr-tsr-react.md +442 -0
  142. package/dist/docs/3.examples/28.vite-ssr-tss-react.md +444 -0
  143. package/dist/docs/3.examples/29.vite-ssr-vue-router.md +617 -0
  144. package/dist/docs/3.examples/3.cached-handler.md +81 -0
  145. package/dist/docs/3.examples/30.vite-trpc.md +335 -0
  146. package/dist/docs/3.examples/31.websocket.md +282 -0
  147. package/dist/docs/3.examples/4.custom-error-handler.md +98 -0
  148. package/dist/docs/3.examples/5.database.md +157 -0
  149. package/dist/docs/3.examples/6.elysia.md +70 -0
  150. package/dist/docs/3.examples/7.express.md +78 -0
  151. package/dist/docs/3.examples/8.fastify.md +79 -0
  152. package/dist/docs/3.examples/9.hello-world.md +68 -0
  153. package/dist/docs/README.md +86 -0
  154. package/dist/docs/index.md +121 -0
  155. package/dist/node_modules/@poppinss/dumper/build/formatters/html/main.js +8 -0
  156. package/dist/node_modules/@poppinss/dumper/package.json +1 -1
  157. package/dist/node_modules/@speed-highlight/core/dist/index.js +4 -4
  158. package/dist/node_modules/@speed-highlight/core/dist/terminal.js +2 -2
  159. package/dist/node_modules/@speed-highlight/core/package.json +1 -1
  160. package/dist/node_modules/cookie-es/dist/index.mjs +299 -250
  161. package/dist/node_modules/cookie-es/package.json +26 -23
  162. package/dist/node_modules/croner/dist/croner.js +1 -1
  163. package/dist/node_modules/croner/package.json +11 -1
  164. package/dist/node_modules/defu/dist/defu.mjs +2 -2
  165. package/dist/node_modules/defu/package.json +33 -28
  166. package/dist/node_modules/rendu/dist/_chunks/libs/cookie-es.mjs +151 -0
  167. package/dist/node_modules/rendu/dist/index.mjs +5 -112
  168. package/dist/node_modules/rendu/package.json +25 -24
  169. package/dist/node_modules/youch/build/helpers-B9BQYaS6.js +23 -0
  170. package/dist/node_modules/youch/build/index.js +204 -351
  171. package/dist/node_modules/youch/build/public/error_info/script.js +1 -1
  172. package/dist/node_modules/youch/build/public_dir-C5bujZKB.js +25 -0
  173. package/dist/node_modules/youch/build/src/templates/error_cause/main.js +44 -0
  174. package/dist/node_modules/youch/build/src/templates/error_info/main.js +72 -0
  175. package/dist/node_modules/youch/build/src/templates/error_metadata/main.js +65 -0
  176. package/dist/node_modules/youch/build/src/templates/error_stack/main.js +152 -0
  177. package/dist/node_modules/youch/build/src/templates/error_stack_source/main.js +46 -0
  178. package/dist/node_modules/youch/build/src/templates/header/main.js +24 -0
  179. package/dist/node_modules/youch/build/src/templates/layout/main.js +27 -0
  180. package/dist/node_modules/youch/package.json +35 -32
  181. package/dist/presets/_nitro/runtime/nitro-dev.mjs +12 -57
  182. package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +1 -0
  183. package/dist/presets/_nitro/runtime/service-worker.mjs +1 -2
  184. package/dist/presets/aws-lambda/runtime/_utils.mjs +6 -6
  185. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +3 -1
  186. package/dist/presets/azure/runtime/_utils.mjs +5 -5
  187. package/dist/presets/azure/runtime/azure-swa.mjs +5 -5
  188. package/dist/presets/bun/runtime/bun.mjs +9 -6
  189. package/dist/presets/cloudflare/runtime/_module-handler.mjs +1 -1
  190. package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +4 -4
  191. package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +3 -3
  192. package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +2 -2
  193. package/dist/presets/cloudflare/runtime/plugin.dev.mjs +10 -21
  194. package/dist/presets/deno/runtime/deno-deploy.mjs +4 -4
  195. package/dist/presets/deno/runtime/deno-server.mjs +9 -6
  196. package/dist/presets/edgeone/runtime/edgeone.mjs +10 -0
  197. package/dist/presets/netlify/runtime/netlify-edge.mjs +2 -3
  198. package/dist/presets/netlify/runtime/netlify.mjs +1 -1
  199. package/dist/presets/node/runtime/node-cluster.mjs +5 -4
  200. package/dist/presets/node/runtime/node-middleware.mjs +1 -1
  201. package/dist/presets/node/runtime/node-server.mjs +8 -5
  202. package/dist/presets/stormkit/runtime/stormkit.mjs +1 -2
  203. package/dist/presets/vercel/runtime/cron-handler.mjs +25 -0
  204. package/dist/presets/vercel/runtime/queue-handler.mjs +21 -0
  205. package/dist/presets/vercel/runtime/vercel.node.mjs +3 -3
  206. package/dist/presets/vercel/runtime/vercel.web.mjs +3 -5
  207. package/dist/presets/winterjs/runtime/winterjs.mjs +10 -10
  208. package/dist/presets/zephyr/runtime/server.mjs +3 -0
  209. package/dist/runtime/internal/app.mjs +12 -11
  210. package/dist/runtime/internal/cache.d.mts +0 -4
  211. package/dist/runtime/internal/cache.mjs +32 -256
  212. package/dist/runtime/internal/context.d.mts +3 -1
  213. package/dist/runtime/internal/context.mjs +1 -9
  214. package/dist/runtime/internal/error/dev.d.mts +5 -4
  215. package/dist/runtime/internal/error/dev.mjs +47 -49
  216. package/dist/runtime/internal/error/hooks.d.mts +1 -1
  217. package/dist/runtime/internal/error/prod.d.mts +2 -5
  218. package/dist/runtime/internal/error/prod.mjs +19 -33
  219. package/dist/runtime/internal/error/utils.d.mts +4 -4
  220. package/dist/runtime/internal/meta.d.mts +1 -1
  221. package/dist/runtime/internal/plugin.d.mts +2 -2
  222. package/dist/runtime/internal/route-rules.d.mts +11 -4
  223. package/dist/runtime/internal/route-rules.mjs +15 -5
  224. package/dist/runtime/internal/routes/dev-tasks.d.mts +3 -2
  225. package/dist/runtime/internal/routes/dev-tasks.mjs +15 -10
  226. package/dist/runtime/internal/routes/openapi.mjs +2 -2
  227. package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
  228. package/dist/runtime/internal/routes/renderer-template.dev.d.mts +2 -1
  229. package/dist/runtime/internal/routes/scalar.mjs +3 -3
  230. package/dist/runtime/internal/routes/swagger.mjs +7 -4
  231. package/dist/runtime/internal/runtime-config.d.mts +1 -1
  232. package/dist/runtime/internal/runtime-config.mjs +2 -2
  233. package/dist/runtime/internal/static.mjs +5 -4
  234. package/dist/runtime/internal/task.d.mts +3 -1
  235. package/dist/runtime/internal/task.mjs +7 -7
  236. package/dist/runtime/internal/vite/dev-entry.mjs +6 -3
  237. package/dist/runtime/internal/vite/dev-worker.mjs +264 -0
  238. package/dist/runtime/meta.d.mts +1 -0
  239. package/dist/runtime/meta.mjs +2 -0
  240. package/dist/runtime/nitro.d.mts +2 -0
  241. package/dist/runtime/nitro.mjs +4 -2
  242. package/dist/runtime/virtual/error-handler.mjs +1 -1
  243. package/dist/runtime/virtual/renderer-template.mjs +1 -1
  244. package/dist/runtime/virtual/server-assets.d.mts +2 -1
  245. package/dist/runtime/virtual/tracing.d.mts +5 -0
  246. package/dist/runtime/virtual/tracing.mjs +1 -0
  247. package/dist/runtime/vite.d.mts +1 -1
  248. package/dist/types/index.d.mts +215 -195
  249. package/dist/types/index.mjs +1 -11
  250. package/dist/vite.d.mts +3 -8
  251. package/dist/vite.mjs +285 -253
  252. package/lib/tsconfig.json +3 -5
  253. package/package.json +97 -80
  254. package/dist/_libs/confbox.mjs +0 -2509
  255. package/dist/_libs/nypm+giget+tinyexec.mjs +0 -3603
  256. package/dist/_libs/rc9+c12+dotenv.mjs +0 -972
  257. package/dist/node_modules/hookable/dist/index.mjs +0 -266
  258. package/dist/node_modules/hookable/package.json +0 -52
  259. package/dist/node_modules/youch/build/chunk-4L7RY2JA.js +0 -42
  260. package/dist/node_modules/youch/build/chunk-7QV3D5YX.js +0 -83
  261. package/dist/node_modules/youch/build/chunk-AUGPHE32.js +0 -39
  262. package/dist/node_modules/youch/build/chunk-CM7DWJNZ.js +0 -44
  263. package/dist/node_modules/youch/build/chunk-EJH674NB.js +0 -223
  264. package/dist/node_modules/youch/build/chunk-OIJ3WD7L.js +0 -81
  265. package/dist/node_modules/youch/build/chunk-P36L72PL.js +0 -87
  266. package/dist/node_modules/youch/build/chunk-PE3GG3TN.js +0 -65
  267. package/dist/node_modules/youch/build/chunk-X53OIOJH.js +0 -70
  268. package/dist/presets/_nitro/runtime/nitro-dev.d.mts +0 -2
  269. package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +0 -3
  270. package/dist/presets/_nitro/runtime/service-worker.d.mts +0 -2
  271. package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +0 -2
  272. package/dist/presets/aws-lambda/runtime/_utils.d.mts +0 -8
  273. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +0 -2
  274. package/dist/presets/aws-lambda/runtime/aws-lambda.d.mts +0 -3
  275. package/dist/presets/azure/runtime/_utils.d.mts +0 -2
  276. package/dist/presets/azure/runtime/azure-swa.d.mts +0 -5
  277. package/dist/presets/bun/runtime/bun.d.mts +0 -3
  278. package/dist/presets/cloudflare/runtime/_module-handler.d.mts +0 -16
  279. package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +0 -11
  280. package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +0 -3
  281. package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +0 -20
  282. package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +0 -3
  283. package/dist/presets/deno/runtime/deno-deploy.d.mts +0 -5
  284. package/dist/presets/deno/runtime/deno-server.d.mts +0 -3
  285. package/dist/presets/netlify/runtime/netlify-edge.d.mts +0 -3
  286. package/dist/presets/netlify/runtime/netlify.d.mts +0 -4
  287. package/dist/presets/node/runtime/node-cluster.d.mts +0 -3
  288. package/dist/presets/node/runtime/node-middleware.d.mts +0 -3
  289. package/dist/presets/node/runtime/node-server.d.mts +0 -3
  290. package/dist/presets/standard/runtime/server.d.mts +0 -3
  291. package/dist/presets/stormkit/runtime/stormkit.d.mts +0 -21
  292. package/dist/presets/vercel/runtime/isr.d.mts +0 -2
  293. package/dist/presets/vercel/runtime/vercel.node.d.mts +0 -3
  294. package/dist/presets/vercel/runtime/vercel.web.d.mts +0 -8
  295. package/dist/presets/winterjs/runtime/winterjs.d.mts +0 -2
  296. package/dist/presets/zeabur/runtime/zeabur.d.mts +0 -3
  297. package/dist/runtime/internal/vite/node-runner.mjs +0 -359
@@ -1,262 +1,311 @@
1
+ const COOKIE_MAX_AGE_LIMIT = 3456e4;
2
+ function endIndex(str, min, len) {
3
+ const index = str.indexOf(";", min);
4
+ return index === -1 ? len : index;
5
+ }
6
+ function eqIndex(str, min, max) {
7
+ const index = str.indexOf("=", min);
8
+ return index < max ? index : -1;
9
+ }
10
+ function valueSlice(str, min, max) {
11
+ if (min === max) return "";
12
+ let start = min;
13
+ let end = max;
14
+ do {
15
+ const code = str.charCodeAt(start);
16
+ if (code !== 32 && code !== 9) break;
17
+ } while (++start < end);
18
+ while (end > start) {
19
+ const code = str.charCodeAt(end - 1);
20
+ if (code !== 32 && code !== 9) break;
21
+ end--;
22
+ }
23
+ return str.slice(start, end);
24
+ }
25
+ const NullObject = /* @__PURE__ */ (() => {
26
+ const C = function() {};
27
+ C.prototype = Object.create(null);
28
+ return C;
29
+ })();
1
30
  function parse(str, options) {
2
- if (typeof str !== "string") {
3
- throw new TypeError("argument str must be a string");
4
- }
5
- const obj = {};
6
- const opt = options || {};
7
- const dec = opt.decode || decode;
8
- let index = 0;
9
- while (index < str.length) {
10
- const eqIdx = str.indexOf("=", index);
11
- if (eqIdx === -1) {
12
- break;
13
- }
14
- let endIdx = str.indexOf(";", index);
15
- if (endIdx === -1) {
16
- endIdx = str.length;
17
- } else if (endIdx < eqIdx) {
18
- index = str.lastIndexOf(";", eqIdx - 1) + 1;
19
- continue;
20
- }
21
- const key = str.slice(index, eqIdx).trim();
22
- if (opt?.filter && !opt?.filter(key)) {
23
- index = endIdx + 1;
24
- continue;
25
- }
26
- if (void 0 === obj[key]) {
27
- let val = str.slice(eqIdx + 1, endIdx).trim();
28
- if (val.codePointAt(0) === 34) {
29
- val = val.slice(1, -1);
30
- }
31
- obj[key] = tryDecode(val, dec);
32
- }
33
- index = endIdx + 1;
34
- }
35
- return obj;
31
+ const obj = new NullObject();
32
+ const len = str.length;
33
+ if (len < 2) return obj;
34
+ const dec = options?.decode || decode;
35
+ const allowMultiple = options?.allowMultiple || false;
36
+ let index = 0;
37
+ do {
38
+ const eqIdx = eqIndex(str, index, len);
39
+ if (eqIdx === -1) break;
40
+ const endIdx = endIndex(str, index, len);
41
+ if (eqIdx > endIdx) {
42
+ index = str.lastIndexOf(";", eqIdx - 1) + 1;
43
+ continue;
44
+ }
45
+ const key = valueSlice(str, index, eqIdx);
46
+ if (options?.filter && !options.filter(key)) {
47
+ index = endIdx + 1;
48
+ continue;
49
+ }
50
+ const val = dec(valueSlice(str, eqIdx + 1, endIdx));
51
+ if (allowMultiple) {
52
+ const existing = obj[key];
53
+ if (existing === void 0) obj[key] = val;
54
+ else if (Array.isArray(existing)) existing.push(val);
55
+ else obj[key] = [existing, val];
56
+ } else if (obj[key] === void 0) obj[key] = val;
57
+ index = endIdx + 1;
58
+ } while (index < len);
59
+ return obj;
36
60
  }
37
61
  function decode(str) {
38
- return str.includes("%") ? decodeURIComponent(str) : str;
62
+ if (!str.includes("%")) return str;
63
+ try {
64
+ return decodeURIComponent(str);
65
+ } catch {
66
+ return str;
67
+ }
39
68
  }
40
- function tryDecode(str, decode2) {
41
- try {
42
- return decode2(str);
43
- } catch {
44
- return str;
45
- }
69
+ const cookieNameRegExp = /^[\u0021-\u003A\u003C\u003E-\u007E]+$/;
70
+ const cookieValueRegExp = /^[\u0021-\u003A\u003C-\u007E]*$/;
71
+ const domainValueRegExp = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i;
72
+ const pathValueRegExp = /^[\u0020-\u003A\u003C-\u007E]*$/;
73
+ const __toString = Object.prototype.toString;
74
+ function stringifyCookie(cookie, options) {
75
+ const enc = options?.encode || encodeURIComponent;
76
+ const keys = Object.keys(cookie);
77
+ let str = "";
78
+ for (const [i, name] of keys.entries()) {
79
+ const val = cookie[name];
80
+ if (val === void 0) continue;
81
+ if (!cookieNameRegExp.test(name)) throw new TypeError(`cookie name is invalid: ${name}`);
82
+ const value = enc(val);
83
+ if (!cookieValueRegExp.test(value)) throw new TypeError(`cookie val is invalid: ${val}`);
84
+ if (i > 0) str += "; ";
85
+ str += name + "=" + value;
86
+ }
87
+ return str;
46
88
  }
47
-
48
- const fieldContentRegExp = /^[\u0009\u0020-\u007E\u0080-\u00FF]+$/;
49
- function serialize(name, value, options) {
50
- const opt = options || {};
51
- const enc = opt.encode || encodeURIComponent;
52
- if (typeof enc !== "function") {
53
- throw new TypeError("option encode is invalid");
54
- }
55
- if (!fieldContentRegExp.test(name)) {
56
- throw new TypeError("argument name is invalid");
57
- }
58
- const encodedValue = enc(value);
59
- if (encodedValue && !fieldContentRegExp.test(encodedValue)) {
60
- throw new TypeError("argument val is invalid");
61
- }
62
- let str = name + "=" + encodedValue;
63
- if (void 0 !== opt.maxAge && opt.maxAge !== null) {
64
- const maxAge = opt.maxAge - 0;
65
- if (Number.isNaN(maxAge) || !Number.isFinite(maxAge)) {
66
- throw new TypeError("option maxAge is invalid");
67
- }
68
- str += "; Max-Age=" + Math.floor(maxAge);
69
- }
70
- if (opt.domain) {
71
- if (!fieldContentRegExp.test(opt.domain)) {
72
- throw new TypeError("option domain is invalid");
73
- }
74
- str += "; Domain=" + opt.domain;
75
- }
76
- if (opt.path) {
77
- if (!fieldContentRegExp.test(opt.path)) {
78
- throw new TypeError("option path is invalid");
79
- }
80
- str += "; Path=" + opt.path;
81
- }
82
- if (opt.expires) {
83
- if (!isDate(opt.expires) || Number.isNaN(opt.expires.valueOf())) {
84
- throw new TypeError("option expires is invalid");
85
- }
86
- str += "; Expires=" + opt.expires.toUTCString();
87
- }
88
- if (opt.httpOnly) {
89
- str += "; HttpOnly";
90
- }
91
- if (opt.secure) {
92
- str += "; Secure";
93
- }
94
- if (opt.priority) {
95
- const priority = typeof opt.priority === "string" ? opt.priority.toLowerCase() : opt.priority;
96
- switch (priority) {
97
- case "low": {
98
- str += "; Priority=Low";
99
- break;
100
- }
101
- case "medium": {
102
- str += "; Priority=Medium";
103
- break;
104
- }
105
- case "high": {
106
- str += "; Priority=High";
107
- break;
108
- }
109
- default: {
110
- throw new TypeError("option priority is invalid");
111
- }
112
- }
113
- }
114
- if (opt.sameSite) {
115
- const sameSite = typeof opt.sameSite === "string" ? opt.sameSite.toLowerCase() : opt.sameSite;
116
- switch (sameSite) {
117
- case true: {
118
- str += "; SameSite=Strict";
119
- break;
120
- }
121
- case "lax": {
122
- str += "; SameSite=Lax";
123
- break;
124
- }
125
- case "strict": {
126
- str += "; SameSite=Strict";
127
- break;
128
- }
129
- case "none": {
130
- str += "; SameSite=None";
131
- break;
132
- }
133
- default: {
134
- throw new TypeError("option sameSite is invalid");
135
- }
136
- }
137
- }
138
- if (opt.partitioned) {
139
- str += "; Partitioned";
140
- }
141
- return str;
89
+ function serialize(_a0, _a1, _a2) {
90
+ const isObj = typeof _a0 === "object" && _a0 !== null;
91
+ const options = isObj ? _a1 : _a2;
92
+ const stringify = options?.stringify || JSON.stringify;
93
+ const cookie = isObj ? _a0 : {
94
+ ..._a2,
95
+ name: _a0,
96
+ value: _a1 == void 0 ? "" : typeof _a1 === "string" ? _a1 : stringify(_a1)
97
+ };
98
+ const enc = options?.encode || encodeURIComponent;
99
+ if (!cookieNameRegExp.test(cookie.name)) throw new TypeError(`argument name is invalid: ${cookie.name}`);
100
+ const value = cookie.value ? enc(cookie.value) : "";
101
+ if (!cookieValueRegExp.test(value)) throw new TypeError(`argument val is invalid: ${cookie.value}`);
102
+ if (!cookie.secure) {
103
+ if (cookie.partitioned) throw new TypeError(`Partitioned cookies must have the Secure attribute`);
104
+ if (cookie.sameSite && String(cookie.sameSite).toLowerCase() === "none") throw new TypeError(`SameSite=None cookies must have the Secure attribute`);
105
+ if (cookie.name.length > 9 && cookie.name.charCodeAt(0) === 95 && cookie.name.charCodeAt(1) === 95) {
106
+ const nameLower = cookie.name.toLowerCase();
107
+ if (nameLower.startsWith("__secure-") || nameLower.startsWith("__host-")) throw new TypeError(`${cookie.name} cookies must have the Secure attribute`);
108
+ }
109
+ }
110
+ if (cookie.name.length > 7 && cookie.name.charCodeAt(0) === 95 && cookie.name.charCodeAt(1) === 95 && cookie.name.toLowerCase().startsWith("__host-")) {
111
+ if (cookie.path !== "/") throw new TypeError(`__Host- cookies must have Path=/`);
112
+ if (cookie.domain) throw new TypeError(`__Host- cookies must not have a Domain attribute`);
113
+ }
114
+ let str = cookie.name + "=" + value;
115
+ if (cookie.maxAge !== void 0) {
116
+ if (!Number.isInteger(cookie.maxAge)) throw new TypeError(`option maxAge is invalid: ${cookie.maxAge}`);
117
+ str += "; Max-Age=" + Math.max(0, Math.min(cookie.maxAge, COOKIE_MAX_AGE_LIMIT));
118
+ }
119
+ if (cookie.domain) {
120
+ if (!domainValueRegExp.test(cookie.domain)) throw new TypeError(`option domain is invalid: ${cookie.domain}`);
121
+ str += "; Domain=" + cookie.domain;
122
+ }
123
+ if (cookie.path) {
124
+ if (!pathValueRegExp.test(cookie.path)) throw new TypeError(`option path is invalid: ${cookie.path}`);
125
+ str += "; Path=" + cookie.path;
126
+ }
127
+ if (cookie.expires) {
128
+ if (!isDate(cookie.expires) || !Number.isFinite(cookie.expires.valueOf())) throw new TypeError(`option expires is invalid: ${cookie.expires}`);
129
+ str += "; Expires=" + cookie.expires.toUTCString();
130
+ }
131
+ if (cookie.httpOnly) str += "; HttpOnly";
132
+ if (cookie.secure) str += "; Secure";
133
+ if (cookie.partitioned) str += "; Partitioned";
134
+ if (cookie.priority) switch (typeof cookie.priority === "string" ? cookie.priority.toLowerCase() : void 0) {
135
+ case "low":
136
+ str += "; Priority=Low";
137
+ break;
138
+ case "medium":
139
+ str += "; Priority=Medium";
140
+ break;
141
+ case "high":
142
+ str += "; Priority=High";
143
+ break;
144
+ default: throw new TypeError(`option priority is invalid: ${cookie.priority}`);
145
+ }
146
+ if (cookie.sameSite) switch (typeof cookie.sameSite === "string" ? cookie.sameSite.toLowerCase() : cookie.sameSite) {
147
+ case true:
148
+ case "strict":
149
+ str += "; SameSite=Strict";
150
+ break;
151
+ case "lax":
152
+ str += "; SameSite=Lax";
153
+ break;
154
+ case "none":
155
+ str += "; SameSite=None";
156
+ break;
157
+ default: throw new TypeError(`option sameSite is invalid: ${cookie.sameSite}`);
158
+ }
159
+ return str;
142
160
  }
143
161
  function isDate(val) {
144
- return Object.prototype.toString.call(val) === "[object Date]" || val instanceof Date;
162
+ return __toString.call(val) === "[object Date]";
163
+ }
164
+ const maxAgeRegExp = /^-?\d+$/;
165
+ const _nullProto = /* @__PURE__ */ Object.getPrototypeOf({});
166
+ function parseSetCookie(str, options) {
167
+ const len = str.length;
168
+ let _endIdx = len;
169
+ let eqIdx = -1;
170
+ for (let i = 0; i < len; i++) {
171
+ const c = str.charCodeAt(i);
172
+ if (c === 59) {
173
+ _endIdx = i;
174
+ break;
175
+ }
176
+ if (c === 61 && eqIdx === -1) eqIdx = i;
177
+ }
178
+ if (eqIdx >= _endIdx) eqIdx = -1;
179
+ const name = eqIdx === -1 ? "" : _trim(str, 0, eqIdx);
180
+ if (name && name in _nullProto) return void 0;
181
+ let value = eqIdx === -1 ? _trim(str, 0, _endIdx) : _trim(str, eqIdx + 1, _endIdx);
182
+ if (!name && !value) return void 0;
183
+ if (name.length + value.length > 4096) return void 0;
184
+ if (options?.decode !== false) value = _decode(value, options?.decode);
185
+ const setCookie = {
186
+ name,
187
+ value
188
+ };
189
+ let index = _endIdx + 1;
190
+ while (index < len) {
191
+ let endIdx = len;
192
+ let attrEqIdx = -1;
193
+ for (let i = index; i < len; i++) {
194
+ const c = str.charCodeAt(i);
195
+ if (c === 59) {
196
+ endIdx = i;
197
+ break;
198
+ }
199
+ if (c === 61 && attrEqIdx === -1) attrEqIdx = i;
200
+ }
201
+ if (attrEqIdx >= endIdx) attrEqIdx = -1;
202
+ const attr = attrEqIdx === -1 ? _trim(str, index, endIdx) : _trim(str, index, attrEqIdx);
203
+ const val = attrEqIdx === -1 ? void 0 : _trim(str, attrEqIdx + 1, endIdx);
204
+ if (val === void 0 || val.length <= 1024) switch (attr.toLowerCase()) {
205
+ case "httponly":
206
+ setCookie.httpOnly = true;
207
+ break;
208
+ case "secure":
209
+ setCookie.secure = true;
210
+ break;
211
+ case "partitioned":
212
+ setCookie.partitioned = true;
213
+ break;
214
+ case "domain":
215
+ if (val) setCookie.domain = (val.charCodeAt(0) === 46 ? val.slice(1) : val).toLowerCase();
216
+ break;
217
+ case "path":
218
+ setCookie.path = val;
219
+ break;
220
+ case "max-age":
221
+ if (val && maxAgeRegExp.test(val)) setCookie.maxAge = Math.min(Number(val), COOKIE_MAX_AGE_LIMIT);
222
+ break;
223
+ case "expires": {
224
+ if (!val) break;
225
+ const date = new Date(val);
226
+ if (Number.isFinite(date.valueOf())) {
227
+ const maxDate = new Date(Date.now() + COOKIE_MAX_AGE_LIMIT * 1e3);
228
+ setCookie.expires = date > maxDate ? maxDate : date;
229
+ }
230
+ break;
231
+ }
232
+ case "priority": {
233
+ if (!val) break;
234
+ const priority = val.toLowerCase();
235
+ if (priority === "low" || priority === "medium" || priority === "high") setCookie.priority = priority;
236
+ break;
237
+ }
238
+ case "samesite": {
239
+ if (!val) break;
240
+ const sameSite = val.toLowerCase();
241
+ if (sameSite === "lax" || sameSite === "strict" || sameSite === "none") setCookie.sameSite = sameSite;
242
+ else setCookie.sameSite = "lax";
243
+ break;
244
+ }
245
+ default: {
246
+ const attrLower = attr.toLowerCase();
247
+ if (attrLower && !(attrLower in _nullProto)) setCookie[attrLower] = val;
248
+ }
249
+ }
250
+ index = endIdx + 1;
251
+ }
252
+ return setCookie;
145
253
  }
146
-
147
- function parseSetCookie(setCookieValue, options) {
148
- const parts = (setCookieValue || "").split(";").filter((str) => typeof str === "string" && !!str.trim());
149
- const nameValuePairStr = parts.shift() || "";
150
- const parsed = _parseNameValuePair(nameValuePairStr);
151
- const name = parsed.name;
152
- let value = parsed.value;
153
- try {
154
- value = options?.decode === false ? value : (options?.decode || decodeURIComponent)(value);
155
- } catch {
156
- }
157
- const cookie = {
158
- name,
159
- value
160
- };
161
- for (const part of parts) {
162
- const sides = part.split("=");
163
- const partKey = (sides.shift() || "").trimStart().toLowerCase();
164
- const partValue = sides.join("=");
165
- switch (partKey) {
166
- case "expires": {
167
- cookie.expires = new Date(partValue);
168
- break;
169
- }
170
- case "max-age": {
171
- cookie.maxAge = Number.parseInt(partValue, 10);
172
- break;
173
- }
174
- case "secure": {
175
- cookie.secure = true;
176
- break;
177
- }
178
- case "httponly": {
179
- cookie.httpOnly = true;
180
- break;
181
- }
182
- case "samesite": {
183
- cookie.sameSite = partValue;
184
- break;
185
- }
186
- default: {
187
- cookie[partKey] = partValue;
188
- }
189
- }
190
- }
191
- return cookie;
254
+ function _trim(str, start, end) {
255
+ if (start === end) return "";
256
+ let s = start;
257
+ let e = end;
258
+ while (s < e && (str.charCodeAt(s) === 32 || str.charCodeAt(s) === 9)) s++;
259
+ while (e > s && (str.charCodeAt(e - 1) === 32 || str.charCodeAt(e - 1) === 9)) e--;
260
+ return str.slice(s, e);
192
261
  }
193
- function _parseNameValuePair(nameValuePairStr) {
194
- let name = "";
195
- let value = "";
196
- const nameValueArr = nameValuePairStr.split("=");
197
- if (nameValueArr.length > 1) {
198
- name = nameValueArr.shift();
199
- value = nameValueArr.join("=");
200
- } else {
201
- value = nameValuePairStr;
202
- }
203
- return { name, value };
262
+ function _decode(value, decode) {
263
+ if (!decode && !value.includes("%")) return value;
264
+ try {
265
+ return (decode || decodeURIComponent)(value);
266
+ } catch {
267
+ return value;
268
+ }
204
269
  }
205
-
206
270
  function splitSetCookieString(cookiesString) {
207
- if (Array.isArray(cookiesString)) {
208
- return cookiesString.flatMap((c) => splitSetCookieString(c));
209
- }
210
- if (typeof cookiesString !== "string") {
211
- return [];
212
- }
213
- const cookiesStrings = [];
214
- let pos = 0;
215
- let start;
216
- let ch;
217
- let lastComma;
218
- let nextStart;
219
- let cookiesSeparatorFound;
220
- const skipWhitespace = () => {
221
- while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
222
- pos += 1;
223
- }
224
- return pos < cookiesString.length;
225
- };
226
- const notSpecialChar = () => {
227
- ch = cookiesString.charAt(pos);
228
- return ch !== "=" && ch !== ";" && ch !== ",";
229
- };
230
- while (pos < cookiesString.length) {
231
- start = pos;
232
- cookiesSeparatorFound = false;
233
- while (skipWhitespace()) {
234
- ch = cookiesString.charAt(pos);
235
- if (ch === ",") {
236
- lastComma = pos;
237
- pos += 1;
238
- skipWhitespace();
239
- nextStart = pos;
240
- while (pos < cookiesString.length && notSpecialChar()) {
241
- pos += 1;
242
- }
243
- if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
244
- cookiesSeparatorFound = true;
245
- pos = nextStart;
246
- cookiesStrings.push(cookiesString.slice(start, lastComma));
247
- start = pos;
248
- } else {
249
- pos = lastComma + 1;
250
- }
251
- } else {
252
- pos += 1;
253
- }
254
- }
255
- if (!cookiesSeparatorFound || pos >= cookiesString.length) {
256
- cookiesStrings.push(cookiesString.slice(start));
257
- }
258
- }
259
- return cookiesStrings;
271
+ if (Array.isArray(cookiesString)) return cookiesString.flatMap((c) => splitSetCookieString(c));
272
+ if (typeof cookiesString !== "string") return [];
273
+ const cookiesStrings = [];
274
+ let pos = 0;
275
+ let start;
276
+ let ch;
277
+ let lastComma;
278
+ let nextStart;
279
+ let cookiesSeparatorFound;
280
+ const skipWhitespace = () => {
281
+ while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) pos += 1;
282
+ return pos < cookiesString.length;
283
+ };
284
+ const notSpecialChar = () => {
285
+ ch = cookiesString.charAt(pos);
286
+ return ch !== "=" && ch !== ";" && ch !== ",";
287
+ };
288
+ while (pos < cookiesString.length) {
289
+ start = pos;
290
+ cookiesSeparatorFound = false;
291
+ while (skipWhitespace()) {
292
+ ch = cookiesString.charAt(pos);
293
+ if (ch === ",") {
294
+ lastComma = pos;
295
+ pos += 1;
296
+ skipWhitespace();
297
+ nextStart = pos;
298
+ while (pos < cookiesString.length && notSpecialChar()) pos += 1;
299
+ if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
300
+ cookiesSeparatorFound = true;
301
+ pos = nextStart;
302
+ cookiesStrings.push(cookiesString.slice(start, lastComma));
303
+ start = pos;
304
+ } else pos = lastComma + 1;
305
+ } else pos += 1;
306
+ }
307
+ if (!cookiesSeparatorFound || pos >= cookiesString.length) cookiesStrings.push(cookiesString.slice(start));
308
+ }
309
+ return cookiesStrings;
260
310
  }
261
-
262
- export { parse, parseSetCookie, serialize, splitSetCookieString };
311
+ export { parse, parse as parseCookie, parseSetCookie, serialize, serialize as serializeCookie, splitSetCookieString, stringifyCookie };
@@ -1,37 +1,40 @@
1
1
  {
2
2
  "name": "cookie-es",
3
- "version": "2.0.0",
4
- "repository": "unjs/cookie-es",
3
+ "version": "3.1.1",
5
4
  "license": "MIT",
6
- "sideEffects": false,
7
- "type": "module",
8
- "exports": {
9
- "types": "./dist/index.d.mts",
10
- "default": "./dist/index.mjs"
11
- },
12
- "types": "./dist/index.d.mts",
5
+ "repository": "unjs/cookie-es",
13
6
  "files": [
14
7
  "dist"
15
8
  ],
9
+ "type": "module",
10
+ "sideEffects": false,
11
+ "types": "./dist/index.d.mts",
12
+ "exports": {
13
+ ".": "./dist/index.mjs"
14
+ },
16
15
  "scripts": {
17
- "build": "unbuild",
16
+ "build": "obuild",
18
17
  "dev": "vitest --coverage",
19
- "lint": "eslint --cache . && prettier -c src test",
20
- "lint:fix": "automd && eslint --cache . --fix && prettier -c src test -w",
18
+ "lint": "oxlint . && oxfmt --check src test",
19
+ "fmt": "automd && oxlint . --fix && oxfmt src test",
21
20
  "release": "pnpm test && pnpm build && changelogen --release --push && npm publish",
22
21
  "test": "pnpm lint && vitest run --coverage"
23
22
  },
24
23
  "devDependencies": {
25
- "@types/node": "^22.13.5",
26
- "@vitest/coverage-v8": "^3.0.7",
27
- "automd": "^0.4.0",
28
- "changelogen": "^0.6.0",
29
- "eslint": "^9.21.0",
30
- "eslint-config-unjs": "^0.4.2",
31
- "prettier": "^3.5.2",
32
- "typescript": "^5.7.3",
33
- "unbuild": "^3.5.0",
34
- "vitest": "^3.0.7"
24
+ "@types/node": "^25.5.0",
25
+ "@vitest/coverage-v8": "^4.1.1",
26
+ "automd": "^0.4.3",
27
+ "changelogen": "^0.6.2",
28
+ "cookie": "^1.1.1",
29
+ "eslint-config-unjs": "^0.6.2",
30
+ "magic-string": "^0.30.21",
31
+ "mitata": "^1.0.34",
32
+ "obuild": "^0.4.32",
33
+ "oxfmt": "^0.41.0",
34
+ "oxlint": "^1.56.0",
35
+ "rolldown": "1.0.0-rc.11",
36
+ "typescript": "^6.0.2",
37
+ "vitest": "^4.1.1"
35
38
  },
36
- "packageManager": "pnpm@10.5.2"
39
+ "packageManager": "pnpm@10.32.1"
37
40
  }