litzjs 0.0.0 → 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.
package/README.md CHANGED
@@ -23,7 +23,7 @@ multipart-safe internal actions, and a release gate via `bun run check`.
23
23
  Inside a React + Vite app:
24
24
 
25
25
  ```bash
26
- bun add litz react react-dom
26
+ bun add litzjs react react-dom
27
27
  ```
28
28
 
29
29
  ## Quick Start
@@ -39,7 +39,7 @@ Add the Litz Vite plugin. By default, Litz discovers:
39
39
 
40
40
  ```ts
41
41
  import { defineConfig } from "vite";
42
- import { litz } from "litz/vite";
42
+ import { litz } from "litzjs/vite";
43
43
 
44
44
  export default defineConfig({
45
45
  plugins: [litz()],
@@ -66,7 +66,7 @@ Mount the Litz app from your browser entry.
66
66
  `src/main.tsx`
67
67
 
68
68
  ```tsx
69
- import { mountApp } from "litz/client";
69
+ import { mountApp } from "litzjs/client";
70
70
 
71
71
  const root = document.getElementById("app");
72
72
 
@@ -81,7 +81,7 @@ You can optionally provide a wrapper component around the app root:
81
81
 
82
82
  ```tsx
83
83
  import { StrictMode } from "react";
84
- import { mountApp } from "litz/client";
84
+ import { mountApp } from "litzjs/client";
85
85
 
86
86
  mountApp(root, StrictMode);
87
87
  ```
@@ -89,7 +89,7 @@ mountApp(root, StrictMode);
89
89
  For providers or wrappers with props, pass a component:
90
90
 
91
91
  ```tsx
92
- import { mountApp } from "litz/client";
92
+ import { mountApp } from "litzjs/client";
93
93
 
94
94
  function AppProviders({ children }: React.PropsWithChildren) {
95
95
  return <ThemeProvider theme={theme}>{children}</ThemeProvider>;
@@ -115,7 +115,7 @@ Create your first route.
115
115
  `src/routes/index.tsx`
116
116
 
117
117
  ```tsx
118
- import { defineRoute } from "litz";
118
+ import { defineRoute } from "litzjs";
119
119
 
120
120
  export const route = defineRoute("/", {
121
121
  component: HomePage,
@@ -138,7 +138,7 @@ Routes are explicit. The path you pass to `defineRoute(...)` is the source of tr
138
138
  Add a loader when you need server data:
139
139
 
140
140
  ```tsx
141
- import { data, defineRoute, server } from "litz";
141
+ import { data, defineRoute, server } from "litzjs";
142
142
 
143
143
  export const route = defineRoute("/me", {
144
144
  component: ProfilePage,
@@ -175,7 +175,7 @@ Layouts are explicit too. A route opts into a layout by importing it and passing
175
175
 
176
176
  ```tsx
177
177
  import type { ReactNode } from "react";
178
- import { defineLayout, defineRoute } from "litz";
178
+ import { defineLayout, defineRoute } from "litzjs";
179
179
 
180
180
  export const dashboardLayout = defineLayout("/dashboard", {
181
181
  component: DashboardShell,
@@ -220,7 +220,7 @@ When you want the server to return UI instead of JSON, return `view(...)`.
220
220
 
221
221
  ```tsx
222
222
  import * as React from "react";
223
- import { defineRoute, server, view } from "litz";
223
+ import { defineRoute, server, view } from "litzjs";
224
224
 
225
225
  export const route = defineRoute("/reports", {
226
226
  component: ReportsPage,
@@ -306,7 +306,7 @@ Actions handle writes. They can return `data(...)`, `invalid(...)`, `redirect(..
306
306
 
307
307
  ```tsx
308
308
  import { useFormStatus } from "react-dom";
309
- import { data, defineRoute, invalid, server } from "litz";
309
+ import { data, defineRoute, invalid, server } from "litzjs";
310
310
 
311
311
  export const route = defineRoute("/projects/new", {
312
312
  component: NewProjectPage,
@@ -359,7 +359,7 @@ If you need imperative writes instead of a form, use `route.useSubmit()`.
359
359
  Litz ships a small client navigation layer.
360
360
 
361
361
  ```tsx
362
- import { Link, useNavigate } from "litz/client";
362
+ import { Link, useNavigate } from "litzjs/client";
363
363
 
364
364
  function Nav() {
365
365
  const navigate = useNavigate();
@@ -384,7 +384,7 @@ Plain `<a href>` elements stay native and perform normal browser navigations.
384
384
  You can also inspect the active route chain:
385
385
 
386
386
  ```tsx
387
- import { useMatches } from "litz";
387
+ import { useMatches } from "litzjs";
388
388
 
389
389
  function Breadcrumbs() {
390
390
  const matches = useMatches();
@@ -402,7 +402,7 @@ function Breadcrumbs() {
402
402
  If you want the current concrete browser location instead of the route pattern chain:
403
403
 
404
404
  ```tsx
405
- import { useLocation, usePathname } from "litz";
405
+ import { useLocation, usePathname } from "litzjs";
406
406
 
407
407
  function RouteMeta() {
408
408
  const pathname = usePathname();
@@ -482,7 +482,7 @@ resource hooks work like route hooks, but against that resource instance.
482
482
  A resource always declares a `component`. That component reads resource state through hooks.
483
483
 
484
484
  ```tsx
485
- import { data, defineResource, server } from "litz";
485
+ import { data, defineResource, server } from "litzjs";
486
486
 
487
487
  export const resource = defineResource("/resource/user/:id", {
488
488
  component: UserCard,
@@ -546,7 +546,7 @@ Resources can also return `view(...)` from the server and consume it with `resou
546
546
 
547
547
  ```tsx
548
548
  import * as React from "react";
549
- import { defineResource, server, view } from "litz";
549
+ import { defineResource, server, view } from "litzjs";
550
550
 
551
551
  export const resource = defineResource("/resource/account/:id", {
552
552
  component: AccountMenu,
@@ -572,7 +572,7 @@ Resources can define actions with the same self-contained form story as routes:
572
572
 
573
573
  ```tsx
574
574
  import * as React from "react";
575
- import { defineResource, server, view } from "litz";
575
+ import { defineResource, server, view } from "litzjs";
576
576
  import { useFormStatus } from "react-dom";
577
577
 
578
578
  export const resource = defineResource("/resource/feed/:id", {
@@ -702,7 +702,7 @@ so they stay in sync instead of duplicating work.
702
702
  API routes expose raw HTTP handlers and come with a thin client helper.
703
703
 
704
704
  ```ts
705
- import { defineApiRoute } from "litz";
705
+ import { defineApiRoute } from "litzjs";
706
706
 
707
707
  export const api = defineApiRoute("/api/health", {
708
708
  middleware: [],
@@ -740,7 +740,7 @@ Supported method keys:
740
740
  Litz ships a default WinterCG-style server runtime:
741
741
 
742
742
  ```ts
743
- import { createServer } from "litz/server";
743
+ import { createServer } from "litzjs/server";
744
744
 
745
745
  export default createServer({
746
746
  createContext(request) {
@@ -757,7 +757,7 @@ export default createServer({
757
757
  In simple apps, `createServer()` with no arguments is enough:
758
758
 
759
759
  ```ts
760
- import { createServer } from "litz/server";
760
+ import { createServer } from "litzjs/server";
761
761
 
762
762
  export default createServer();
763
763
  ```
@@ -768,25 +768,27 @@ The Vite plugin injects the discovered server manifest automatically into that e
768
768
 
769
769
  When you run `vite build`, Litz always writes the browser assets to `dist/client`.
770
770
 
771
- Server output depends on whether you provide a custom server entry:
771
+ Server output is always `dist/server/index.js`. The Vite plugin injects the discovered server
772
+ manifest into `createServer(...)` automatically.
772
773
 
773
- - No custom server entry:
774
- Litz emits a self-contained `dist/server/index.js`.
775
- That file inlines the built document HTML and all client asset contents, so the server handler can
776
- serve `/` and `/assets/*` by itself. This is the default one-file server deployment mode.
777
- - Custom server entry present:
778
- Litz emits `dist/server/index.js` from your server entry and injects the discovered server
779
- manifest into `createServer(...)`.
780
- Litz does not inject static asset or document serving in this mode. Your host server or platform
781
- is responsible for serving `dist/client` however you want, for example through `express.static`,
782
- a CDN, or a platform asset binding.
774
+ By default, your host server or platform is responsible for serving `dist/client` (for example
775
+ through `express.static`, a CDN, or a platform asset binding).
776
+
777
+ If you want a self-contained single-file deployment, enable `embedAssets`:
778
+
779
+ ```ts
780
+ litz({ embedAssets: true });
781
+ ```
782
+
783
+ This inlines the built document HTML and all client asset contents into the server bundle, so the
784
+ server handler can serve `/` and `/assets/*` by itself without a separate static file server.
783
785
 
784
786
  You can let Litz discover `src/server.ts` or `src/server/index.ts`, or configure a different path
785
787
  explicitly in `vite.config.ts`:
786
788
 
787
789
  ```ts
788
790
  import { defineConfig } from "vite";
789
- import { litz } from "litz/vite";
791
+ import { litz } from "litzjs/vite";
790
792
 
791
793
  export default defineConfig({
792
794
  plugins: [
@@ -807,7 +809,7 @@ Litz's server boundaries are explicit, but they are still normal server request
807
809
  - Route loaders and actions are server handlers.
808
810
  - Resource loaders and actions are server handlers.
809
811
  - API routes are raw HTTP handlers.
810
- - The `/_litz/*` transport used by the client runtime is an implementation detail, not a private trust boundary.
812
+ - The `/_litzjs/*` transport used by the client runtime is an implementation detail, not a private trust boundary.
811
813
 
812
814
  That means Litz apps should treat route loaders, actions, resources, and API routes like any other
813
815
  server endpoint:
@@ -815,7 +817,7 @@ server endpoint:
815
817
  - authenticate and authorize inside middleware or handlers
816
818
  - validate params, search params, headers, and form/body input
817
819
  - apply CSRF protections when using cookie-backed auth for writes
818
- - do not assume a request came from Litz just because it arrived through `/_litz/*`
820
+ - do not assume a request came from Litz just because it arrived through `/_litzjs/*`
819
821
 
820
822
  Litz may serve `index.html` itself, but it also supports deployments where the document is served
821
823
  statically or by a custom server. Security decisions must not depend on the document coming from
@@ -833,7 +835,7 @@ Server handlers can return these helpers:
833
835
  - `withHeaders(result, headers)`
834
836
 
835
837
  ```tsx
836
- import { data, defineRoute, error, redirect, server, withHeaders } from "litz";
838
+ import { data, defineRoute, error, redirect, server, withHeaders } from "litzjs";
837
839
 
838
840
  export const route = defineRoute("/projects/:id", {
839
841
  component: ProjectPage,
@@ -875,7 +877,7 @@ Behavior summary:
875
877
  Routes, resources, and API routes can declare a `middleware` array. Middleware runs in order and can continue with `next()`, short-circuit with a result, or explicitly replace `context` with `next({ context })`.
876
878
 
877
879
  ```tsx
878
- import { data, defineApiRoute, defineRoute, error, server } from "litz";
880
+ import { data, defineApiRoute, defineRoute, error, server } from "litzjs";
879
881
 
880
882
  export const route = defineRoute("/dashboard", {
881
883
  component: DashboardPage,