@lunora/react 0.0.0 → 1.0.0-alpha.2

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 (31) hide show
  1. package/LICENSE.md +105 -0
  2. package/README.md +150 -9
  3. package/__assets__/package-og.svg +14 -0
  4. package/dist/index.d.mts +499 -0
  5. package/dist/index.d.ts +499 -0
  6. package/dist/index.mjs +17 -0
  7. package/dist/packem_shared/Authenticated-DtKgZT2Z.mjs +33 -0
  8. package/dist/packem_shared/CheckoutButton-CVSry8U1.mjs +185 -0
  9. package/dist/packem_shared/LunoraProvider-D38Xp16l.mjs +80 -0
  10. package/dist/packem_shared/cache-CItk3fgN.mjs +75 -0
  11. package/dist/packem_shared/hydratePreloaded-BlFL9FGq.mjs +46 -0
  12. package/dist/packem_shared/lunoraQueryOptions-CsuWzjg1.mjs +16 -0
  13. package/dist/packem_shared/query-key-C5rufkEE.mjs +21 -0
  14. package/dist/packem_shared/query-options.d-D4okOpO8.d.mts +38 -0
  15. package/dist/packem_shared/query-options.d-D4okOpO8.d.ts +38 -0
  16. package/dist/packem_shared/use-paginated-core-CoOfcc-p.mjs +161 -0
  17. package/dist/packem_shared/useAuth-CNUKtOOp.mjs +129 -0
  18. package/dist/packem_shared/useAuthState-BiGhtSCs.mjs +36 -0
  19. package/dist/packem_shared/useConnectionStatus-DRSY9ldm.mjs +30 -0
  20. package/dist/packem_shared/useInfiniteQuery-MH0x4l8h.mjs +97 -0
  21. package/dist/packem_shared/useMutation-CrvMXRsk.mjs +67 -0
  22. package/dist/packem_shared/usePaginatedQuery-D3PTDRGS.mjs +46 -0
  23. package/dist/packem_shared/usePresence-D7jLuxj0.mjs +108 -0
  24. package/dist/packem_shared/useQuery-C5S0W-7K.mjs +41 -0
  25. package/dist/packem_shared/useRateLimit-DTEffQEi.mjs +64 -0
  26. package/dist/packem_shared/useStream-BRY9nemd.mjs +125 -0
  27. package/dist/packem_shared/useSubscription-CHMCjyQg.mjs +139 -0
  28. package/dist/server.d.mts +51 -0
  29. package/dist/server.d.ts +51 -0
  30. package/dist/server.mjs +31 -0
  31. package/package.json +60 -17
package/LICENSE.md ADDED
@@ -0,0 +1,105 @@
1
+ # Functional Source License, Version 1.1, Apache 2.0 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-Apache-2.0
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 anolilab and contributors
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or service
34
+ that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software that
39
+ exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee using
52
+ the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to the
59
+ infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN
79
+ IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following will
93
+ apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/README.md CHANGED
@@ -1,18 +1,159 @@
1
- # @lunora/react
1
+ <!-- START_PACKAGE_OG_IMAGE_PLACEHOLDER -->
2
2
 
3
- > ⚠️ **Placeholder release.** This package name is reserved for the [Lunora](https://lunora.sh) framework. The real `1.0.0-alpha` release is coming soon.
3
+ <a href="https://www.anolilab.com/open-source" align="center">
4
4
 
5
- React hooks for Lunora: useQuery, useMutation, useSubscription, and useAuth
5
+ <img src="__assets__/package-og.svg" alt="react" />
6
6
 
7
- Lunora is a type-safe, real-time backend framework for Cloudflare Workers + Durable Objects with a Vite-first developer experience.
7
+ </a>
8
8
 
9
- - Website: https://lunora.sh
10
- - Repository: https://github.com/anolilab/lunora
9
+ <h3 align="center">React hooks for Lunora: useQuery, useMutation, useSubscription, and useAuth</h3>
11
10
 
12
- ## Status
11
+ <!-- END_PACKAGE_OG_IMAGE_PLACEHOLDER -->
13
12
 
14
- This is a `0.0.0` placeholder to reserve the npm name. Do not depend on it yet — APIs and exports are not published in this version. Watch the repository for the alpha release.
13
+ <br />
14
+
15
+ <div align="center">
16
+
17
+ [![typescript-image][typescript-badge]][typescript-url]
18
+ [![FSL-1.1-Apache-2.0 licence][license-badge]][license]
19
+ [![npm version][npm-version-badge]][npm-version]
20
+ [![npm downloads][npm-downloads-badge]][npm-downloads]
21
+ [![PRs Welcome][prs-welcome-badge]][prs-welcome]
22
+
23
+ </div>
24
+
25
+ ---
26
+
27
+ <div align="center">
28
+ <p>
29
+ <sup>
30
+ Daniel Bannert's open source work is supported by the community on <a href="https://github.com/sponsors/prisis">GitHub Sponsors</a>
31
+ </sup>
32
+ </p>
33
+ </div>
34
+
35
+ ---
36
+
37
+ React hooks for Lunora — `useQuery`, `useMutation`, `useSubscription`, `useAuth`, and more — that wrap a `@lunora/client` instance behind a `LunoraProvider`. The hooks are client-only; server-side data loading lives in the socket-free `@lunora/react/server` entry.
38
+
39
+ Part of the [Lunora](https://github.com/anolilab/lunora) framework — a type-safe, real-time backend on Cloudflare Workers + Durable Objects with a Vite-first DX.
40
+
41
+ ## Install
42
+
43
+ ```sh
44
+ npm install @lunora/react
45
+ ```
46
+
47
+ ```sh
48
+ yarn add @lunora/react
49
+ ```
50
+
51
+ ```sh
52
+ pnpm add @lunora/react
53
+ ```
54
+
55
+ ## Usage
56
+
57
+ ```tsx
58
+ import { LunoraClient } from "@lunora/client";
59
+ import { LunoraProvider, useMutation, useQuery } from "@lunora/react";
60
+ import { api } from "./lunora/_generated/api";
61
+
62
+ const client = new LunoraClient({ url: "https://app.acme.test" });
63
+
64
+ export function App() {
65
+ return (
66
+ <LunoraProvider client={client}>
67
+ <MessageList room="general" />
68
+ </LunoraProvider>
69
+ );
70
+ }
71
+
72
+ function MessageList({ room }: { room: string }) {
73
+ const messages = useQuery(api.messages.list, { room });
74
+ const { mutate, pending } = useMutation(api.messages.send);
75
+
76
+ if (messages === undefined) return <p>Loading…</p>;
77
+
78
+ return (
79
+ <>
80
+ <ul>
81
+ {messages.map((m) => (
82
+ <li key={m.id}>{m.body}</li>
83
+ ))}
84
+ </ul>
85
+ <button disabled={pending} onClick={() => mutate({ room, body: "hi" })}>
86
+ Send
87
+ </button>
88
+ </>
89
+ );
90
+ }
91
+ ```
92
+
93
+ `useQuery` returns `undefined` until the first response lands; pass `"skip"` as the args to short-circuit (no network call, no subscription). `useMutation(fn)` returns `{ mutate, pending, data, error, reset, withOptimisticUpdate }` — `mutate` is awaitable and rejects on failure.
94
+
95
+ ## Hooks
96
+
97
+ | Hook | Returns | Notes |
98
+ | ---------------------------------------------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------ |
99
+ | `useQuery(fn, args, options?)` | `T \| undefined` | Live query; shares one WS subscription across consumers of the same key. |
100
+ | `useMutation(fn)` | `{ mutate, pending, data, error, reset, withOptimisticUpdate }` | Per-call `optimistic` / `optimisticUpdate` options pass through to the client. |
101
+ | `useSubscription(fn, args, options?)` | `{ data, error }` | No initial fetch — only server-pushed values. |
102
+ | `usePaginatedQuery(fn, args, { initialNumItems })` | `{ results, status, isLoading, loadMore }` | Cursor-paginated feed that stays consistent under live edits. |
103
+ | `useInfiniteQuery(fn, args, { initialNumItems })` | `{ pages, status, hasNextPage, fetchNextPage, … }` | Page-array variant of the same paginator. |
104
+ | `usePreloadedQuery(preloaded)` | `T` | Reads a server `Preloaded` token, then goes live. |
105
+ | `usePresence({ heartbeat, listPresent, roomId, … })` | present members | Drives the `definePresence` heartbeat + list functions. |
106
+ | `useStream(fn, args, options?)` | `{ chunks, status, error, cancel }` | Consumes a streamed action response chunk by chunk. |
107
+ | `useRateLimit(config, options?)` | `{ ok, disabled, retryAfter, check, consume, reset }` | Client-side mirror of a `@lunora/ratelimit` budget for instant UX. |
108
+ | `useConnectionStatus()` | `ConnectionStatus` | `idle` / `connecting` / `connected` / `offline`. |
109
+ | `useAuth()` | `{ user, token, setToken }` | Call `setToken(jwt)` after sign-in; RPC then carries the token. |
110
+ | `useAuthState()` | `{ isAuthenticated, isLoading }` | Hydration-safe three-state gate. |
111
+
112
+ `Authenticated`, `Unauthenticated`, and `AuthLoading` are gate components built on `useAuthState`. `CheckoutButton`, `CustomerPortalButton`, and `useCheckout` wrap `@lunora/payment` flows.
113
+
114
+ ## Server Components
115
+
116
+ The package root is a client boundary. For React Server Components / the Next.js App Router, load data from the socket-free `@lunora/react/server` entry: `prefetchQuery` seeds the TanStack cache for `HydrationBoundary`, `preloadQuery` returns a serializable token for `usePreloadedQuery`, and `fetchQuery` / `fetchMutation` / `fetchAction` run one-shot RPC calls. Build a fresh `createServerClient({ url, token? })` per request so a user's token never leaks across requests.
117
+
118
+ > This README covers the basics. For the full API, options, and guides, see the **[documentation](https://lunora.sh/docs/api/react)**.
119
+
120
+ ## Related
121
+
122
+ - [`@lunora/client`](https://www.npmjs.com/package/@lunora/client) — the browser SDK these hooks wrap. Its `@lunora/client/query` subpath is the shared live-query state machine, and `@lunora/client/ssr` provides the server-side preloading used by `@lunora/react/server`.
123
+
124
+ ## Supported Node.js Versions
125
+
126
+ Libraries in this ecosystem make the best effort to track [Node.js' release schedule](https://github.com/nodejs/release#release-schedule).
127
+ Here's [a post on why we think this is important](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a).
128
+
129
+ ## Contributing
130
+
131
+ If you would like to help take a look at the [list of issues](https://github.com/anolilab/lunora/issues) and check our [Contributing](https://github.com/anolilab/lunora/blob/alpha/.github/CONTRIBUTING.md) guidelines.
132
+
133
+ > **Note:** please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
134
+
135
+ ## Credits
136
+
137
+ - [Daniel Bannert](https://github.com/prisis)
138
+ - [All Contributors](https://github.com/anolilab/lunora/graphs/contributors)
139
+
140
+ ## Made with ❤️ at Anolilab
141
+
142
+ This is an open source project and will always remain free to use. If you think it's cool, please star it 🌟. [Anolilab](https://www.anolilab.com/open-source) is a Development and AI Studio. Contact us at [hello@anolilab.com](mailto:hello@anolilab.com) if you need any help with these technologies or just want to say hi!
15
143
 
16
144
  ## License
17
145
 
18
- FSL-1.1-Apache-2.0
146
+ The Lunora react package is open-sourced software licensed under the [FSL-1.1-Apache-2.0][license].
147
+
148
+ <!-- badges -->
149
+
150
+ [license-badge]: https://img.shields.io/badge/license-FSL--1.1--Apache--2.0-blue.svg?style=for-the-badge
151
+ [license]: https://github.com/anolilab/lunora/blob/alpha/LICENSE.md
152
+ [npm-version-badge]: https://img.shields.io/npm/v/@lunora/react?style=for-the-badge
153
+ [npm-version]: https://www.npmjs.com/package/@lunora/react
154
+ [npm-downloads-badge]: https://img.shields.io/npm/dm/@lunora/react?style=for-the-badge
155
+ [npm-downloads]: https://www.npmjs.com/package/@lunora/react
156
+ [prs-welcome-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=for-the-badge
157
+ [prs-welcome]: https://github.com/anolilab/lunora/blob/alpha/.github/CONTRIBUTING.md
158
+ [typescript-badge]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
159
+ [typescript-url]: https://www.typescriptlang.org/