@nifrajs/web 2.1.0 → 2.3.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 (194) hide show
  1. package/README.md +3 -3
  2. package/dist/build-vite.d.ts +68 -0
  3. package/dist/build-vite.d.ts.map +1 -0
  4. package/dist/build-vite.js +433 -0
  5. package/dist/build-vite.js.map +1 -0
  6. package/dist/build.d.ts +174 -65
  7. package/dist/build.d.ts.map +1 -1
  8. package/dist/build.js +376 -135
  9. package/dist/build.js.map +1 -1
  10. package/dist/bun-dev-entry.d.ts +83 -0
  11. package/dist/bun-dev-entry.d.ts.map +1 -0
  12. package/dist/bun-dev-entry.js +136 -0
  13. package/dist/bun-dev-entry.js.map +1 -0
  14. package/dist/chunk-names.js +1 -1
  15. package/dist/client.d.ts +3 -9
  16. package/dist/client.d.ts.map +1 -1
  17. package/dist/client.js +209 -27
  18. package/dist/client.js.map +1 -1
  19. package/dist/conformance.d.ts +2 -2
  20. package/dist/conformance.js +3 -3
  21. package/dist/deferred.d.ts +11 -11
  22. package/dist/deferred.d.ts.map +1 -1
  23. package/dist/deferred.js +16 -16
  24. package/dist/dev-error.d.ts +2 -2
  25. package/dist/dev-error.js +3 -3
  26. package/dist/dev-port.d.ts +36 -0
  27. package/dist/dev-port.d.ts.map +1 -0
  28. package/dist/dev-port.js +48 -0
  29. package/dist/dev-port.js.map +1 -0
  30. package/dist/dev.d.ts +62 -5
  31. package/dist/dev.d.ts.map +1 -1
  32. package/dist/dev.js +419 -60
  33. package/dist/dev.js.map +1 -1
  34. package/dist/draft.d.ts +44 -7
  35. package/dist/draft.d.ts.map +1 -1
  36. package/dist/draft.js +92 -9
  37. package/dist/draft.js.map +1 -1
  38. package/dist/fn-state.d.ts +56 -0
  39. package/dist/fn-state.d.ts.map +1 -0
  40. package/dist/fn-state.js +77 -0
  41. package/dist/fn-state.js.map +1 -0
  42. package/dist/fn.d.ts +111 -0
  43. package/dist/fn.d.ts.map +1 -0
  44. package/dist/fn.js +125 -0
  45. package/dist/fn.js.map +1 -0
  46. package/dist/fonts-google.d.ts +9 -9
  47. package/dist/fonts-google.js +10 -10
  48. package/dist/fonts.d.ts +7 -7
  49. package/dist/fonts.js +1 -1
  50. package/dist/forms.d.ts +8 -8
  51. package/dist/fs.d.ts +15 -2
  52. package/dist/fs.d.ts.map +1 -1
  53. package/dist/fs.js +8 -2
  54. package/dist/fs.js.map +1 -1
  55. package/dist/index.d.ts +266 -74
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +869 -179
  58. package/dist/index.js.map +1 -1
  59. package/dist/internal/head-attributes.d.ts +15 -0
  60. package/dist/internal/head-attributes.d.ts.map +1 -0
  61. package/dist/internal/head-attributes.js +99 -0
  62. package/dist/internal/head-attributes.js.map +1 -0
  63. package/dist/internal/script-types.d.ts +14 -0
  64. package/dist/internal/script-types.d.ts.map +1 -0
  65. package/dist/internal/script-types.js +17 -0
  66. package/dist/internal/script-types.js.map +1 -0
  67. package/dist/internal/server-boundary.d.ts +60 -0
  68. package/dist/internal/server-boundary.d.ts.map +1 -0
  69. package/dist/internal/server-boundary.js +174 -0
  70. package/dist/internal/server-boundary.js.map +1 -0
  71. package/dist/internal/timing-safe-equal.d.ts +16 -0
  72. package/dist/internal/timing-safe-equal.d.ts.map +1 -0
  73. package/dist/internal/timing-safe-equal.js +26 -0
  74. package/dist/internal/timing-safe-equal.js.map +1 -0
  75. package/dist/internal/vite-import.d.ts +63 -0
  76. package/dist/internal/vite-import.d.ts.map +1 -0
  77. package/dist/internal/vite-import.js +94 -0
  78. package/dist/internal/vite-import.js.map +1 -0
  79. package/dist/islands.d.ts +5 -5
  80. package/dist/islands.js +5 -5
  81. package/dist/isr.d.ts +15 -15
  82. package/dist/isr.d.ts.map +1 -1
  83. package/dist/isr.js +8 -21
  84. package/dist/isr.js.map +1 -1
  85. package/dist/llms-txt.d.ts.map +1 -1
  86. package/dist/llms-txt.js +12 -6
  87. package/dist/llms-txt.js.map +1 -1
  88. package/dist/manifest.d.ts +121 -40
  89. package/dist/manifest.d.ts.map +1 -1
  90. package/dist/manifest.js +136 -26
  91. package/dist/manifest.js.map +1 -1
  92. package/dist/module-graph.d.ts +91 -0
  93. package/dist/module-graph.d.ts.map +1 -0
  94. package/dist/module-graph.js +92 -0
  95. package/dist/module-graph.js.map +1 -0
  96. package/dist/navigation.d.ts +120 -5
  97. package/dist/navigation.d.ts.map +1 -1
  98. package/dist/navigation.js +37 -5
  99. package/dist/navigation.js.map +1 -1
  100. package/dist/plugins/css-modules.d.ts +3 -3
  101. package/dist/plugins/css-modules.d.ts.map +1 -1
  102. package/dist/plugins/css-modules.js +0 -0
  103. package/dist/plugins/css-modules.js.map +1 -1
  104. package/dist/plugins/kit.d.ts +8 -8
  105. package/dist/plugins/kit.js +9 -9
  106. package/dist/plugins/scss.js +3 -3
  107. package/dist/plugins/vite-leak-guard.d.ts +45 -0
  108. package/dist/plugins/vite-leak-guard.d.ts.map +1 -0
  109. package/dist/plugins/vite-leak-guard.js +67 -0
  110. package/dist/plugins/vite-leak-guard.js.map +1 -0
  111. package/dist/plugins/vite-server-fn.d.ts +23 -0
  112. package/dist/plugins/vite-server-fn.d.ts.map +1 -0
  113. package/dist/plugins/vite-server-fn.js +51 -0
  114. package/dist/plugins/vite-server-fn.js.map +1 -0
  115. package/dist/plugins/vite-server-only.d.ts +49 -0
  116. package/dist/plugins/vite-server-only.d.ts.map +1 -0
  117. package/dist/plugins/vite-server-only.js +57 -0
  118. package/dist/plugins/vite-server-only.js.map +1 -0
  119. package/dist/prerender.d.ts +5 -5
  120. package/dist/prerender.js +7 -7
  121. package/dist/public-dir.d.ts +36 -0
  122. package/dist/public-dir.d.ts.map +1 -0
  123. package/dist/public-dir.js +89 -0
  124. package/dist/public-dir.js.map +1 -0
  125. package/dist/query.d.ts +10 -10
  126. package/dist/query.js +15 -15
  127. package/dist/route-manifest.d.ts +91 -0
  128. package/dist/route-manifest.d.ts.map +1 -0
  129. package/dist/route-manifest.js +128 -0
  130. package/dist/route-manifest.js.map +1 -0
  131. package/dist/router.d.ts +94 -22
  132. package/dist/router.d.ts.map +1 -1
  133. package/dist/router.js +170 -58
  134. package/dist/router.js.map +1 -1
  135. package/dist/search.d.ts +94 -0
  136. package/dist/search.d.ts.map +1 -0
  137. package/dist/search.js +232 -0
  138. package/dist/search.js.map +1 -0
  139. package/dist/server-only.d.ts +6 -6
  140. package/dist/server-only.js +7 -7
  141. package/dist/service-worker.d.ts +56 -0
  142. package/dist/service-worker.d.ts.map +1 -0
  143. package/dist/service-worker.js +127 -0
  144. package/dist/service-worker.js.map +1 -0
  145. package/dist/vite.d.ts +25 -17
  146. package/dist/vite.d.ts.map +1 -1
  147. package/dist/vite.js +75 -33
  148. package/dist/vite.js.map +1 -1
  149. package/package.json +48 -4
  150. package/server-manifest.d.ts +31 -0
  151. package/src/build-vite.ts +553 -0
  152. package/src/build.ts +563 -172
  153. package/src/bun-dev-entry.ts +184 -0
  154. package/src/chunk-names.ts +1 -1
  155. package/src/client.ts +221 -30
  156. package/src/conformance.ts +3 -3
  157. package/src/deferred.ts +17 -17
  158. package/src/dev-error.ts +3 -3
  159. package/src/dev-port.ts +63 -0
  160. package/src/dev.ts +468 -66
  161. package/src/draft.ts +124 -12
  162. package/src/fn-state.ts +107 -0
  163. package/src/fn.ts +199 -0
  164. package/src/fonts-google.ts +13 -13
  165. package/src/fonts.ts +7 -7
  166. package/src/forms.ts +8 -8
  167. package/src/fs.ts +24 -6
  168. package/src/index.ts +1174 -225
  169. package/src/internal/head-attributes.ts +109 -0
  170. package/src/internal/script-types.ts +18 -0
  171. package/src/internal/server-boundary.ts +187 -0
  172. package/src/internal/timing-safe-equal.ts +24 -0
  173. package/src/internal/vite-import.ts +92 -0
  174. package/src/islands.ts +7 -7
  175. package/src/isr.ts +18 -30
  176. package/src/llms-txt.ts +13 -5
  177. package/src/manifest.ts +264 -48
  178. package/src/module-graph.ts +146 -0
  179. package/src/navigation.ts +151 -5
  180. package/src/plugins/css-modules.ts +0 -0
  181. package/src/plugins/kit.ts +11 -11
  182. package/src/plugins/scss.ts +3 -3
  183. package/src/plugins/vite-leak-guard.ts +110 -0
  184. package/src/plugins/vite-server-fn.ts +67 -0
  185. package/src/plugins/vite-server-only.ts +75 -0
  186. package/src/prerender.ts +10 -10
  187. package/src/public-dir.ts +108 -0
  188. package/src/query.ts +22 -22
  189. package/src/route-manifest.ts +240 -0
  190. package/src/router.ts +288 -74
  191. package/src/search.ts +297 -0
  192. package/src/server-only.ts +7 -7
  193. package/src/service-worker.ts +165 -0
  194. package/src/vite.ts +103 -49
package/src/forms.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * `@nifrajs/web/forms` — a typed form ↔ backend-schema binding. The three artifacts that must agree —
3
- * a form's `<input name>`, the action's `formData.get`, and the typed-client payload — all key off the
2
+ * `@nifrajs/web/forms` - a typed form ↔ backend-schema binding. The three artifacts that must agree -
3
+ * a form's `<input name>`, the action's `formData.get`, and the typed-client payload - all key off the
4
4
  * ONE route body schema, derived purely from `typeof backend`. A typo'd field name, or a field the
5
5
  * schema doesn't have, becomes a COMPILE error instead of a silent runtime empty.
6
6
  *
@@ -8,14 +8,14 @@
8
8
  * import { formFor } from "@nifrajs/web/forms"
9
9
  *
10
10
  * const f = formFor<typeof backend, "/todos">() // method defaults to "post"
11
- * // In the component (any framework — spread the props onto an input):
11
+ * // In the component (any framework - spread the props onto an input):
12
12
  * <input {...f.field("text")} /> // "text" ∈ the body's keys, else a compile error
13
13
  * // In the action:
14
14
  * const text = f.read(await request.formData(), "text") // an orphan key won't compile
15
15
  * await api.todos.post({ text }) // payload already typed by nifra
16
16
  *
17
17
  * Framework-agnostic + dependency-free: no codegen, no schema is bundled into the client, and the
18
- * runtime is a trivial pass-through — all the work is in the types. It checks the field KEY, never the
18
+ * runtime is a trivial pass-through - all the work is in the types. It checks the field KEY, never the
19
19
  * MEANING (a `field("email")` collecting a phone is still valid here); that stays an app/AI concern.
20
20
  */
21
21
  import type { RouteInfo, Server } from "@nifrajs/core/server"
@@ -28,7 +28,7 @@ type FormEntries = ReturnType<FormData["getAll"]>
28
28
  /** The route registry baked into a server's type (`typeof app`). */
29
29
  type RegistryOf<App> = App extends Server<infer R, infer _Ctx> ? R : never
30
30
 
31
- /** Every route path the app declares — constrains `Path`, so a wrong path is itself a type error. */
31
+ /** Every route path the app declares - constrains `Path`, so a wrong path is itself a type error. */
32
32
  export type RoutePaths<App> = keyof RegistryOf<App> & string
33
33
 
34
34
  /** The body object type of `App`'s `Method Path` route (`never` when the route declares no body). */
@@ -42,7 +42,7 @@ export type RouteBody<
42
42
  : never
43
43
  : never
44
44
 
45
- /** The valid field names for that route's body — the schema's keys as a string union. */
45
+ /** The valid field names for that route's body - the schema's keys as a string union. */
46
46
  export type FieldKey<App, Path extends string, Method extends string> = [
47
47
  RouteBody<App, Path, Method>,
48
48
  ] extends [never]
@@ -53,13 +53,13 @@ export type FieldKey<App, Path extends string, Method extends string> = [
53
53
  export type FieldProps = Record<string, unknown>
54
54
 
55
55
  export interface FormHandle<App, Path extends string, Method extends string> {
56
- /** Input props for a schema field. `name` is constrained to the body's keys — a typo, or a field the
56
+ /** Input props for a schema field. `name` is constrained to the body's keys - a typo, or a field the
57
57
  * schema doesn't have, is a COMPILE error. Spread onto an element: `<input {...f.field("text")} />`. */
58
58
  field<K extends FieldKey<App, Path, Method>>(
59
59
  name: K,
60
60
  props?: FieldProps,
61
61
  ): FieldProps & { name: K }
62
- /** `formData.get`, key-constrained to the body's fields — reading an orphan key won't compile. */
62
+ /** `formData.get`, key-constrained to the body's fields - reading an orphan key won't compile. */
63
63
  read<K extends FieldKey<App, Path, Method>>(form: FormData, name: K): FormEntry
64
64
  /** `formData.getAll`, key-checked the same way. */
65
65
  readAll<K extends FieldKey<App, Path, Method>>(form: FormData, name: K): FormEntries
package/src/fs.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @nifrajs/web/fs — filesystem route discovery. Separated from the main entry so `app.fetch`
2
+ * @nifrajs/web/fs - filesystem route discovery. Separated from the main entry so `app.fetch`
3
3
  * (and the rest of @nifrajs/web) stays fs-free + edge-portable: this runs at build/startup
4
4
  * only. It scans a routes dir and feeds the pure `buildManifest`.
5
5
  */
@@ -8,9 +8,22 @@ import { buildManifest, type Manifest, type RouteModule } from "./manifest.ts"
8
8
 
9
9
  /** Options for {@link discoverRoutes}. */
10
10
  export interface DiscoverRoutesOptions {
11
- /** Appended (as `?<importQuery>`) to each route's dynamic import — the dev server sets a
12
- * changing value to bust Bun's module cache so SSR picks up edited route files. */
11
+ /** Appended (as `?<importQuery>`) to each route's dynamic import - the dev server sets a
12
+ * changing value to bust Bun's module cache so SSR picks up edited route files. Ignored when
13
+ * {@link load} is supplied, which does its own cache handling. */
13
14
  readonly importQuery?: string
15
+ /**
16
+ * Load a route module by its absolute path, instead of a bare dynamic `import()`.
17
+ *
18
+ * This is what lets a pipeline own SSR resolution. A bare `import()` always resolves through the
19
+ * RUNTIME - Bun - so the Vite dev server ended up serving the client while Bun resolved the server,
20
+ * two resolvers disagreeing about one specifier in a single process. That is the dual-React bug and
21
+ * the reason `resolve.dedupe` never reached SSR: the alias governs Vite, and SSR never asked Vite.
22
+ *
23
+ * Pass `vite.ssrLoadModule` here and the Vite pipeline resolves both halves. Omit it and Bun does,
24
+ * which is correct for the Bun pipeline. Either way one toolchain owns the phase.
25
+ */
26
+ readonly load?: (absolutePath: string) => Promise<unknown>
14
27
  }
15
28
 
16
29
  /** Scan a `routes/` directory (recursively) and build the route manifest. */
@@ -19,8 +32,13 @@ export function discoverRoutes(dir: string, options: DiscoverRoutesOptions = {})
19
32
  .map((file) => file.replaceAll("\\", "/")) // normalize Windows separators
20
33
  .filter((file) => /\.(tsx|jsx|svelte|vue|mdx)$/.test(file))
21
34
  const query = options.importQuery ? `?${options.importQuery}` : ""
22
- return buildManifest(
23
- files,
24
- (file) => () => import(`${dir}/${file}${query}`) as Promise<RouteModule>,
35
+ const load = options.load
36
+ return buildManifest(files, (file) =>
37
+ load === undefined
38
+ ? () => import(`${dir}/${file}${query}`) as Promise<RouteModule>
39
+ : // No `importQuery` here: an injected loader owns its own invalidation (Vite's module graph
40
+ // re-evaluates on change), and appending a cache-buster would defeat it by minting a new
41
+ // module id per request.
42
+ () => load(`${dir}/${file}`) as Promise<RouteModule>,
25
43
  )
26
44
  }