@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
@@ -0,0 +1,113 @@
1
+ import { findMiddlewareFile } from "./router.js";
2
+ import { scanAppRoutes } from "./route-scan.js";
3
+ import { resolveBoundary } from "./segment.js";
4
+ import { freezeConfig } from "./config-freeze.js";
5
+ import { existsSync } from "node:fs";
6
+ import { basename, join } from "node:path";
7
+ import { pathToFileURL } from "node:url";
8
+ import { routeFromModule } from "@junejs/core/route";
9
+ //#region src/manifest.ts
10
+ async function importLayout(file) {
11
+ const mod = await import(pathToFileURL(file).href);
12
+ return typeof mod.default === "function" ? {
13
+ component: mod.default,
14
+ boundary: mod.segmentBoundary === true
15
+ } : null;
16
+ }
17
+ async function buildManifest(appRoot) {
18
+ const appDir = join(appRoot, "app");
19
+ const frozen = await freezeConfig(appRoot);
20
+ const scanned = await scanAppRoutes(appRoot);
21
+ const layoutCache = /* @__PURE__ */ new Map();
22
+ const loadCached = async (f) => {
23
+ if (!layoutCache.has(f)) layoutCache.set(f, await importLayout(f));
24
+ return layoutCache.get(f) ?? null;
25
+ };
26
+ const componentsFor = async (files) => {
27
+ const items = [];
28
+ for (const f of files) {
29
+ const c = await loadCached(f);
30
+ items.push({
31
+ file: f,
32
+ entry: c?.component ?? null,
33
+ boundary: !!c?.boundary
34
+ });
35
+ }
36
+ return resolveBoundary(items);
37
+ };
38
+ const loadingCache = /* @__PURE__ */ new Map();
39
+ const loadingFor = async (file) => {
40
+ if (!file) return void 0;
41
+ if (!loadingCache.has(file)) {
42
+ const loaded = await importLayout(file);
43
+ loadingCache.set(file, loaded ? loaded.component : null);
44
+ }
45
+ return loadingCache.get(file) ?? void 0;
46
+ };
47
+ const routes = {};
48
+ const dynamicRoutes = [];
49
+ const resourceRoutes = [];
50
+ const generatedRoutes = scanned.filter((r) => r.generated).map((r) => r.path);
51
+ const layoutChains = {};
52
+ const layoutBoundaries = {};
53
+ const loadings = {};
54
+ for (const r of scanned) {
55
+ const mod = await import(pathToFileURL(r.file).href);
56
+ if (r.resource) {
57
+ const handler = mod.default;
58
+ if (typeof handler === "function") resourceRoutes.push({
59
+ pattern: r.path,
60
+ handler
61
+ });
62
+ continue;
63
+ }
64
+ const def = routeFromModule(mod);
65
+ if (!def) continue;
66
+ const { chain, boundaryIndex, key } = await componentsFor(r.layouts);
67
+ const loading = await loadingFor(r.loading);
68
+ if (r.dynamic) {
69
+ dynamicRoutes.push({
70
+ pattern: r.path,
71
+ def
72
+ });
73
+ layoutChains[r.path] = chain;
74
+ } else {
75
+ routes[r.path] = def;
76
+ layoutChains[r.path] = chain;
77
+ }
78
+ if (boundaryIndex !== null && key !== null) layoutBoundaries[r.path] = {
79
+ index: boundaryIndex,
80
+ key
81
+ };
82
+ if (loading) loadings[r.path] = loading;
83
+ }
84
+ let extra;
85
+ const extraFile = findMiddlewareFile(appDir);
86
+ if (extraFile) {
87
+ const mod = await import(pathToFileURL(extraFile).href);
88
+ if (typeof mod.default === "function") extra = mod.default;
89
+ }
90
+ let agentName;
91
+ const agentDir = join(appDir, frozen.agent.runtime.dir);
92
+ if (frozen.agent.runtime.enabled && existsSync(agentDir)) {
93
+ const cfgFile = join(agentDir, "agent.ts");
94
+ agentName = (existsSync(cfgFile) ? (await import(pathToFileURL(cfgFile).href)).default : void 0)?.name ?? basename(agentDir);
95
+ }
96
+ return {
97
+ routes,
98
+ dynamicRoutes,
99
+ resourceRoutes,
100
+ ...generatedRoutes.length ? { generatedRoutes } : {},
101
+ layoutChains,
102
+ layoutBoundaries,
103
+ loadings,
104
+ document: frozen.document,
105
+ agent: frozen.agent,
106
+ agentName,
107
+ i18n: frozen.i18n,
108
+ earlyHints: frozen.earlyHints,
109
+ extra
110
+ };
111
+ }
112
+ //#endregion
113
+ export { buildManifest, importLayout };
@@ -1,11 +1,12 @@
1
1
  import { RenderTarget } from "@junejs/core/route";
2
2
  import { FRAGMENT_ACCEPT, SEGMENT_HEADER, TITLE_HEADER, encodeTitle } from "@junejs/core/nav-protocol";
3
3
  //#region src/negotiate.d.ts
4
- type Negotiated = {
4
+ export declare function acceptTarget(accept: string): RenderTarget | null;
5
+ export type Negotiated = {
5
6
  target: RenderTarget;
6
7
  pathname: string;
7
8
  speculative: boolean;
8
9
  };
9
- declare function negotiate(url: URL, request: Request, basePath?: string): Negotiated;
10
+ export declare function negotiate(url: URL, request: Request, basePath?: string): Negotiated;
10
11
  //#endregion
11
- export { FRAGMENT_ACCEPT, Negotiated, SEGMENT_HEADER, TITLE_HEADER, encodeTitle, negotiate };
12
+ export { FRAGMENT_ACCEPT, SEGMENT_HEADER, TITLE_HEADER, encodeTitle };
package/dist/negotiate.js CHANGED
@@ -1,14 +1,30 @@
1
- import { FRAGMENT_ACCEPT, SEGMENT_HEADER, TITLE_HEADER, encodeTitle } from "@junejs/core/nav-protocol";
1
+ import { FRAGMENT_ACCEPT, FRAGMENT_ACCEPT as FRAGMENT_ACCEPT$1, SEGMENT_HEADER, TITLE_HEADER, encodeTitle } from "@junejs/core/nav-protocol";
2
2
  //#region src/negotiate.ts
3
3
  const EXT_TARGET = {
4
4
  ".json": "json",
5
5
  ".md": "md"
6
6
  };
7
- const ACCEPT_TARGET = [
8
- [/text\/vnd\.june\.fragment\+html/, "fragment"],
9
- [/text\/markdown/, "md"],
10
- [/application\/json/, "json"]
11
- ];
7
+ const QVALUE = /^(?:0(?:\.\d{0,3})?|1(?:\.0{0,3})?)$/;
8
+ function acceptRanges(accept) {
9
+ const ranges = /* @__PURE__ */ new Map();
10
+ for (const part of accept.split(",")) {
11
+ const [type, ...params] = part.split(";").map((s) => s.trim().toLowerCase());
12
+ if (!type) continue;
13
+ const raw = params.find((p) => p.startsWith("q="))?.slice(2).trim();
14
+ ranges.set(type, raw !== void 0 && QVALUE.test(raw) ? Number(raw) : 1);
15
+ }
16
+ return ranges;
17
+ }
18
+ function acceptTarget(accept) {
19
+ const ranges = acceptRanges(accept);
20
+ if ((ranges.get(FRAGMENT_ACCEPT$1) ?? 0) > 0) return "fragment";
21
+ const html = ranges.get("text/html") ?? ranges.get("text/*") ?? ranges.get("*/*") ?? 0;
22
+ const md = ranges.get("text/markdown") ?? 0;
23
+ const json = ranges.get("application/json") ?? 0;
24
+ const best = Math.max(md, json);
25
+ if (best <= 0 || best < html) return null;
26
+ return md >= json ? "md" : "json";
27
+ }
12
28
  function negotiate(url, request, basePath) {
13
29
  const original = basePath ?? url.pathname;
14
30
  let pathname = original;
@@ -20,13 +36,7 @@ function negotiate(url, request, basePath) {
20
36
  }
21
37
  if (pathname === "/index") pathname = "/";
22
38
  else if (target && pathname === "/") pathname = original;
23
- if (!target) {
24
- const accept = request.headers.get("accept") ?? "";
25
- for (const [re, t] of ACCEPT_TARGET) if (re.test(accept)) {
26
- target = t;
27
- break;
28
- }
29
- }
39
+ if (!target) target = acceptTarget(request.headers.get("accept") ?? "");
30
40
  const purpose = request.headers.get("sec-purpose") ?? "";
31
41
  const speculative = /prefetch|prerender/.test(purpose);
32
42
  return {
@@ -36,4 +46,4 @@ function negotiate(url, request, basePath) {
36
46
  };
37
47
  }
38
48
  //#endregion
39
- export { FRAGMENT_ACCEPT, SEGMENT_HEADER, TITLE_HEADER, encodeTitle, negotiate };
49
+ export { FRAGMENT_ACCEPT, SEGMENT_HEADER, TITLE_HEADER, acceptTarget, encodeTitle, negotiate };
@@ -4,6 +4,7 @@ import React from "react";
4
4
  import { DocumentConfig } from "@junejs/core/document";
5
5
  import { I18nConfig } from "@junejs/core/i18n";
6
6
  import { Resources } from "@junejs/core/resources";
7
+ import { Principal, Session } from "@junejs/core/context";
7
8
  //#region src/pipeline.d.ts
8
9
  type LayoutComponent = React.ComponentType<{
9
10
  children: React.ReactNode;
@@ -30,8 +31,16 @@ type PipelineConfig = {
30
31
  i18n?: I18nConfig;
31
32
  routeList: () => Promise<string[]> | string[];
32
33
  resolve: RouteResolver;
34
+ staticBuild?: boolean;
33
35
  resources?: () => Promise<Resources> | Resources;
34
36
  services?: () => Promise<unknown> | unknown;
37
+ identity?: (request: Request) => Promise<{
38
+ user?: Principal;
39
+ session?: Session;
40
+ }> | {
41
+ user?: Principal;
42
+ session?: Session;
43
+ };
35
44
  earlyHints?: string[];
36
45
  htmlCacheControl?: string;
37
46
  notFoundComponent?: React.ComponentType<{
@@ -45,6 +54,9 @@ type ExtraHandler = MiddlewareHandler;
45
54
  type Pipeline = {
46
55
  fetch(request: Request): Promise<Response>;
47
56
  };
57
+ declare function markdownPath(pathname: string, isHome: boolean): string;
58
+ declare function htmlPath(pathname: string, isHome: boolean): string;
59
+ declare function isDecodablePath(pathname: string): boolean;
48
60
  declare function createPipeline(cfg: PipelineConfig): Pipeline;
49
61
  //#endregion
50
- export { Pipeline as a, ResolvedResource as c, createPipeline as d, MiddlewareHandler as i, ResourceHandler as l, LayoutComponent as n, PipelineConfig as o, LoadingComponent as r, Resolved as s, ExtraHandler as t, RouteResolver as u };
62
+ export { Pipeline as a, ResolvedResource as c, createPipeline as d, htmlPath as f, MiddlewareHandler as i, ResourceHandler as l, markdownPath as m, LayoutComponent as n, PipelineConfig as o, isDecodablePath as p, LoadingComponent as r, Resolved as s, ExtraHandler as t, RouteResolver as u };
@@ -1,2 +1,2 @@
1
- import { a as Pipeline, c as ResolvedResource, d as createPipeline, i as MiddlewareHandler, l as ResourceHandler, n as LayoutComponent, o as PipelineConfig, r as LoadingComponent, s as Resolved, t as ExtraHandler, u as RouteResolver } from "./pipeline-CCp9idQ4.js";
2
- export { ExtraHandler, LayoutComponent, LoadingComponent, MiddlewareHandler, Pipeline, PipelineConfig, Resolved, ResolvedResource, ResourceHandler, RouteResolver, createPipeline };
1
+ import { a as Pipeline, c as ResolvedResource, d as createPipeline, f as htmlPath, i as MiddlewareHandler, l as ResourceHandler, m as markdownPath, n as LayoutComponent, o as PipelineConfig, p as isDecodablePath, r as LoadingComponent, s as Resolved, t as ExtraHandler, u as RouteResolver } from "./pipeline-BHUjBO0G.js";
2
+ export { ExtraHandler, LayoutComponent, LoadingComponent, MiddlewareHandler, Pipeline, PipelineConfig, Resolved, ResolvedResource, ResourceHandler, RouteResolver, createPipeline, htmlPath, isDecodablePath, markdownPath };