@junejs/server 0.1.2 → 0.2.0

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 (130) hide show
  1. package/assets/icon-latin.LICENSE.txt +92 -0
  2. package/assets/icon-latin.ttf +0 -0
  3. package/dist/adapter-DcZ-W1-7.d.ts +62 -0
  4. package/dist/adapter.d.ts +2 -56
  5. package/dist/adapter.js +62 -5
  6. package/dist/agent-compile.d.ts +38 -0
  7. package/dist/agent-compile.js +145 -0
  8. package/dist/agent-discover.d.ts +4 -4
  9. package/dist/agent-discover.js +30 -44
  10. package/dist/agent-durable.d.ts +94 -19
  11. package/dist/agent-durable.js +647 -32
  12. package/dist/agent-native.d.ts +44 -13
  13. package/dist/agent-native.js +264 -27
  14. package/dist/app.d.ts +5 -5
  15. package/dist/app.js +42 -10
  16. package/dist/blob.d.ts +4 -5
  17. package/dist/build.d.ts +8 -29
  18. package/dist/build.js +138 -289
  19. package/dist/client-bundle.d.ts +8 -9
  20. package/dist/client-bundle.js +1 -1
  21. package/dist/config-freeze-CyXvNqi2.d.ts +17 -0
  22. package/dist/config-freeze.d.ts +2 -0
  23. package/dist/config-freeze.js +54 -0
  24. package/dist/config-loader.d.ts +3 -4
  25. package/dist/connection-auth.d.ts +38 -0
  26. package/dist/connection-auth.js +31 -0
  27. package/dist/content-freeze-CyiW2fRK.d.ts +4 -0
  28. package/dist/content-freeze.d.ts +2 -0
  29. package/dist/content-freeze.js +83 -0
  30. package/dist/content.d.ts +22 -9
  31. package/dist/content.js +43 -3
  32. package/dist/core-version.d.ts +4 -0
  33. package/dist/core-version.js +12 -0
  34. package/dist/css-modules-ambient.d.ts +2 -1
  35. package/dist/css-modules.d.ts +10 -11
  36. package/dist/css.d.ts +9 -10
  37. package/dist/d1-migrate.d.ts +6 -7
  38. package/dist/d1-migrate.js +3 -2
  39. package/dist/db.d.ts +2 -2
  40. package/dist/deploy.d.ts +3 -4
  41. package/dist/deploy.js +3 -2
  42. package/dist/dev-reload.d.ts +3 -4
  43. package/dist/dev.d.ts +8 -5
  44. package/dist/dev.js +40 -9
  45. package/dist/favicon.d.ts +37 -0
  46. package/dist/favicon.js +248 -0
  47. package/dist/host.d.ts +6 -5
  48. package/dist/host.js +2 -1
  49. package/dist/icon-letter.d.ts +3 -0
  50. package/dist/icon-letter.js +8 -0
  51. package/dist/index.d.ts +11 -5
  52. package/dist/index.js +9 -3
  53. package/dist/instrumentation.d.ts +2 -3
  54. package/dist/instrumentation.js +2 -1
  55. package/dist/island-registry.d.ts +6 -7
  56. package/dist/isolate-local.d.ts +5 -0
  57. package/dist/isolate-local.js +12 -0
  58. package/dist/kv.d.ts +3 -4
  59. package/dist/llms-links.d.ts +9 -0
  60. package/dist/llms-links.js +65 -0
  61. package/dist/manifest-CwTT1zVs.d.ts +11 -0
  62. package/dist/manifest.d.ts +2 -0
  63. package/dist/manifest.js +113 -0
  64. package/dist/negotiate.d.ts +4 -3
  65. package/dist/negotiate.js +24 -14
  66. package/dist/{pipeline-CCp9idQ4.d.ts → pipeline-BHUjBO0G.d.ts} +13 -1
  67. package/dist/pipeline.d.ts +2 -2
  68. package/dist/pipeline.js +286 -35
  69. package/dist/resources.d.ts +5 -6
  70. package/dist/route-rank.d.ts +10 -0
  71. package/dist/route-rank.js +38 -0
  72. package/dist/route-scan-BMbBzPIB.d.ts +20 -0
  73. package/dist/route-scan.d.ts +2 -0
  74. package/dist/route-scan.js +100 -0
  75. package/dist/router.d.ts +12 -13
  76. package/dist/router.js +58 -44
  77. package/dist/rsc-build.d.ts +6 -7
  78. package/dist/rsc-bundle.d.ts +6 -7
  79. package/dist/rsc-manifest.d.ts +5 -6
  80. package/dist/rsc-runtime/flight-render-routes.d.ts +3 -4
  81. package/dist/rsc-runtime/flight-render.d.ts +2 -3
  82. package/dist/rsc-runtime/flight-to-html.d.ts +2 -3
  83. package/dist/rsc-runtime/flight-to-html.js +3 -2
  84. package/dist/rsc-runtime/rsc-worker.js +11 -8
  85. package/dist/rsc-runtime/rsdw-shims.d.ts +2 -1
  86. package/dist/segment.d.ts +4 -5
  87. package/dist/sqlite-driver.d.ts +11 -11
  88. package/dist/sqlite-driver.js +17 -4
  89. package/dist/static-files.d.ts +4 -5
  90. package/dist/tsconfig-jsx.d.ts +4 -4
  91. package/dist/tsconfig-jsx.js +1 -1
  92. package/dist/turn-events.d.ts +4 -0
  93. package/dist/turn-events.js +46 -0
  94. package/dist/web-manifest.d.ts +5 -0
  95. package/dist/web-manifest.js +42 -0
  96. package/dist/worker-2qbQjj2c.d.ts +64 -0
  97. package/dist/worker.d.ts +2 -56
  98. package/dist/worker.js +121 -103
  99. package/package.json +22 -9
  100. package/src/adapter.ts +84 -3
  101. package/src/agent-compile.ts +271 -0
  102. package/src/agent-discover.ts +77 -63
  103. package/src/agent-durable.ts +998 -30
  104. package/src/agent-native.ts +370 -35
  105. package/src/app.ts +75 -6
  106. package/src/build.ts +237 -444
  107. package/src/config-freeze.ts +109 -0
  108. package/src/connection-auth.ts +101 -0
  109. package/src/content-freeze.ts +151 -0
  110. package/src/content.ts +55 -4
  111. package/src/core-version.ts +34 -0
  112. package/src/dev.ts +41 -8
  113. package/src/favicon.ts +325 -0
  114. package/src/host.ts +4 -3
  115. package/src/icon-letter.ts +14 -0
  116. package/src/index.ts +22 -0
  117. package/src/isolate-local.ts +33 -0
  118. package/src/llms-links.ts +96 -0
  119. package/src/manifest.ts +130 -0
  120. package/src/negotiate.ts +39 -15
  121. package/src/pipeline.ts +494 -44
  122. package/src/route-rank.ts +60 -0
  123. package/src/route-scan.ts +161 -0
  124. package/src/router.ts +75 -58
  125. package/src/rsc-runtime/rsc-worker.tsx +5 -4
  126. package/src/sqlite-driver.ts +36 -6
  127. package/src/tsconfig-jsx.ts +2 -2
  128. package/src/turn-events.ts +43 -0
  129. package/src/web-manifest.ts +38 -0
  130. package/src/worker.ts +197 -117
package/src/negotiate.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  // header — a link is unambiguous; Accept is a hint. The clean pathname (with
7
7
  // the projection extension stripped) is what the router matches.
8
8
 
9
+ import { FRAGMENT_ACCEPT } from "@junejs/core/nav-protocol";
9
10
  import type { RenderTarget } from "@junejs/core/route";
10
11
 
11
12
  // The fragment media type + title header are the client-router wire protocol —
@@ -18,12 +19,43 @@ const EXT_TARGET: Record<string, RenderTarget> = {
18
19
  ".md": "md",
19
20
  };
20
21
 
21
- const ACCEPT_TARGET: Array<[test: RegExp, target: RenderTarget]> = [
22
- // fragment first: its media type is exact + can't collide with browser Accepts.
23
- [/text\/vnd\.june\.fragment\+html/, "fragment"],
24
- [/text\/markdown/, "md"],
25
- [/application\/json/, "json"],
26
- ];
22
+ // RFC 9110 §12.4.2 qvalue: 0–1 with at most three decimals ("0", "0.5", "1.000").
23
+ const QVALUE = /^(?:0(?:\.\d{0,3})?|1(?:\.0{0,3})?)$/;
24
+
25
+ // Parse an Accept header into media-range → q (RFC 9110 §12.5.1). A q outside the
26
+ // qvalue grammar ("2", "-0.5", "0.1234") is malformed and reads as the default 1:
27
+ // the client still listed the type, so it stays acceptable at the default weight
28
+ // rather than being dropped or excluded. Parameters other than q are ignored.
29
+ function acceptRanges(accept: string): Map<string, number> {
30
+ const ranges = new Map<string, number>();
31
+ for (const part of accept.split(",")) {
32
+ const [type, ...params] = part.split(";").map((s) => s.trim().toLowerCase());
33
+ if (!type) continue;
34
+ const raw = params.find((p) => p.startsWith("q="))?.slice(2).trim();
35
+ ranges.set(type, raw !== undefined && QVALUE.test(raw) ? Number(raw) : 1);
36
+ }
37
+ return ranges;
38
+ }
39
+
40
+ // The projection an Accept header asks for — null when it asks for none of the
41
+ // agent projections (→ the HTML view). ONE decision shared by the pipeline and
42
+ // the deployed worker's asset layer (withAssets), so the two can't disagree.
43
+ // - The client router's fragment media type (exact range, q > 0) wins outright.
44
+ // - Markdown / JSON are chosen when listed with q > 0 and at least as preferred
45
+ // as HTML; HTML's quality is text/html's, else the text/* or */* wildcard's.
46
+ // So `text/markdown, text/html;q=0.9` → md, `text/html, text/markdown;q=0.5`
47
+ // → HTML, and a plain browser Accept (no markdown/json) → HTML.
48
+ // - Ties go to the agent projection (md before json), as they always have.
49
+ export function acceptTarget(accept: string): RenderTarget | null {
50
+ const ranges = acceptRanges(accept);
51
+ if ((ranges.get(FRAGMENT_ACCEPT) ?? 0) > 0) return "fragment";
52
+ const html = ranges.get("text/html") ?? ranges.get("text/*") ?? ranges.get("*/*") ?? 0;
53
+ const md = ranges.get("text/markdown") ?? 0;
54
+ const json = ranges.get("application/json") ?? 0;
55
+ const best = Math.max(md, json);
56
+ if (best <= 0 || best < html) return null;
57
+ return md >= json ? "md" : "json";
58
+ }
27
59
 
28
60
  export type Negotiated = {
29
61
  target: RenderTarget;
@@ -61,15 +93,7 @@ export function negotiate(url: URL, request: Request, basePath?: string): Negoti
61
93
  pathname = original;
62
94
  }
63
95
 
64
- if (!target) {
65
- const accept = request.headers.get("accept") ?? "";
66
- for (const [re, t] of ACCEPT_TARGET) {
67
- if (re.test(accept)) {
68
- target = t;
69
- break;
70
- }
71
- }
72
- }
96
+ if (!target) target = acceptTarget(request.headers.get("accept") ?? "");
73
97
 
74
98
  // A speculative request (Sec-Purpose: prefetch / prerender) may never be seen
75
99
  // — load()s read it to skip side effects (analytics, rate limits, counters).