@weft-js/start 0.0.0-stage → 0.1.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 (75) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +41 -2
  3. package/package.json +107 -4
  4. package/src/app.mjs +82 -0
  5. package/src/auth/better-auth.ts +58 -0
  6. package/src/auth/drizzle.ts +17 -0
  7. package/src/auth.ts +47 -0
  8. package/src/boot.ts +44 -0
  9. package/src/builtin.tsx +19 -0
  10. package/src/bus/postgres.ts +91 -0
  11. package/src/bus.ts +48 -0
  12. package/src/capture.d.mts +1 -0
  13. package/src/capture.mjs +15 -0
  14. package/src/changes-sql.d.mts +14 -0
  15. package/src/changes-sql.mjs +99 -0
  16. package/src/changes.ts +253 -0
  17. package/src/channel-fake.ts +55 -0
  18. package/src/channel.ts +616 -0
  19. package/src/client.tsx +20 -0
  20. package/src/contract.mjs +308 -0
  21. package/src/data.ts +929 -0
  22. package/src/db/bun-sqlite.d.ts +10 -0
  23. package/src/db/changes-mysql.ts +86 -0
  24. package/src/db/changes-postgres.ts +159 -0
  25. package/src/db/changes-sqlite.ts +116 -0
  26. package/src/db/core.ts +63 -0
  27. package/src/db/index.ts +27 -0
  28. package/src/db/mysql.ts +67 -0
  29. package/src/db/postgres.ts +65 -0
  30. package/src/db/sqlite.ts +139 -0
  31. package/src/derive.d.mts +16 -0
  32. package/src/derive.mjs +140 -0
  33. package/src/dev-runtime.mjs +42 -0
  34. package/src/exec.ts +519 -0
  35. package/src/extension.ts +38 -0
  36. package/src/first-paint.ts +57 -0
  37. package/src/form.tsx +134 -0
  38. package/src/gate.css +6 -0
  39. package/src/hub.ts +822 -0
  40. package/src/index.ts +106 -0
  41. package/src/inline.mjs +2 -0
  42. package/src/inspect.mjs +280 -0
  43. package/src/link.ts +456 -0
  44. package/src/list-drizzle.ts +50 -0
  45. package/src/list.ts +224 -0
  46. package/src/listen.ts +28 -0
  47. package/src/live-fake.ts +42 -0
  48. package/src/live-target.mjs +144 -0
  49. package/src/live.ts +499 -0
  50. package/src/media.ts +43 -0
  51. package/src/migrations.mjs +19 -0
  52. package/src/mux-session.ts +6 -0
  53. package/src/mux.ts +135 -0
  54. package/src/og/DefaultCard.tsx +60 -0
  55. package/src/og/fonts.mjs +64 -0
  56. package/src/og/images.mjs +54 -0
  57. package/src/og/index.mjs +146 -0
  58. package/src/og/native.mjs +29 -0
  59. package/src/range.mjs +19 -0
  60. package/src/router.ts +149 -0
  61. package/src/routes.mjs +142 -0
  62. package/src/run.tsx +198 -0
  63. package/src/rust.ts +333 -0
  64. package/src/server.tsx +1014 -0
  65. package/src/shape.d.mts +3 -0
  66. package/src/shape.mjs +73 -0
  67. package/src/share-server.ts +208 -0
  68. package/src/share.ts +503 -0
  69. package/src/sheets.mjs +75 -0
  70. package/src/sidecar.mjs +503 -0
  71. package/src/socket.ts +389 -0
  72. package/src/stream.ts +13 -0
  73. package/src/verify.ts +251 -0
  74. package/src/view.tsx +47 -0
  75. package/src/vite.mjs +899 -0
package/src/view.tsx ADDED
@@ -0,0 +1,47 @@
1
+ // The route views (research 25 §3): `<App>` renders level 0, and each level renders its route's component with the
2
+ // next level as `children`. The same file compiles for the server and the client, so both build the same tree and
3
+ // hydration keys line up. A level's hole reads only its route id: params and data reach the component as live
4
+ // props, so a navigation that keeps the route re-runs only the bindings that read what changed.
5
+
6
+ import { untrack } from '@weft-js/core'
7
+ import { active, level, type RouteState } from './router'
8
+
9
+ // The route state travels as a prop, not a context: a level's view runs later, in the hole that shows it, under that
10
+ // hole's owner. `active.route` is the state of the render in progress (a server pass is synchronous; the client has one).
11
+ export function App(props: { route: RouteState }) {
12
+ const route = (active.route = untrack(() => props.route))
13
+ return <Level route={route} depth={0} />
14
+ }
15
+
16
+ export function Level(props: { route: RouteState; depth: number }) {
17
+ const route = untrack(() => props.route)
18
+ const lv = level(route, untrack(() => props.depth))
19
+ const next = untrack(() => props.depth) + 1
20
+ const view = () => {
21
+ const id = lv.id.value
22
+ if (id === undefined) return null
23
+ const html = route.mount ? lv.html.value : undefined
24
+ if (html !== undefined) return route.mount!(html, untrack(() => props.depth), () => <Level route={route} depth={next} />)
25
+ const Route = route.comps[id] as ((props: { params: Record<string, string>; data: unknown; children: unknown }) => unknown) | undefined
26
+ if (!Route) return null
27
+ const body = () => <Route params={lv.params.value} data={lv.data.value}><Level route={route} depth={next} /></Route>
28
+ return route.around ? route.around(untrack(() => props.depth), id, body) : body()
29
+ }
30
+ return <>{view()}</>
31
+ }
32
+
33
+ /**
34
+ * `<a>` with `aria-current="page"` while its path is the current one. Any same-origin `<a href>` navigates on the
35
+ * client (start() listens for clicks); Link only adds the current-page state. In a static level the server writes it
36
+ * and start() updates it after a navigation, so a Link needs no code there.
37
+ *
38
+ * @weft static
39
+ */
40
+ export function Link({ href, children, ...rest }: Record<string, unknown> & { href: string; class?: string; rel?: string; children?: unknown }) {
41
+ const route = active.route
42
+ return (
43
+ <a {...rest} href={href} aria-current={route && route.path.value.replace(/[?#].*/, '') === href ? 'page' : undefined}>
44
+ {children}
45
+ </a>
46
+ )
47
+ }