@lunora/server 1.0.0-alpha.2 → 1.0.0-alpha.20

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 (41) hide show
  1. package/LICENSE.md +6 -0
  2. package/README.md +51 -1
  3. package/__assets__/package-og.svg +1 -1
  4. package/dist/data-model.d.mts +158 -32
  5. package/dist/data-model.d.ts +158 -32
  6. package/dist/index.d.mts +459 -117
  7. package/dist/index.d.ts +459 -117
  8. package/dist/index.mjs +20 -15
  9. package/dist/packem_shared/{LunoraEnvError-DjFkpkSP.mjs → LunoraEnvError-BGmd1Qs0.mjs} +4 -4
  10. package/dist/packem_shared/LunoraError-WbxmrpxR.mjs +9 -0
  11. package/dist/packem_shared/{PRESENCE_DEFAULT_TTL_MS-BZYd5-uo.mjs → PRESENCE_DEFAULT_TTL_MS-BtPCiNLW.mjs} +4 -4
  12. package/dist/packem_shared/bindOrm-Bfgl7f-Q.mjs +146 -0
  13. package/dist/packem_shared/buildRlsReadRegistry-D54vUQe4.mjs +107 -0
  14. package/dist/packem_shared/{composePluginMiddleware-Ck5_TUO8.mjs → composePluginMiddleware-CcTj1_v2.mjs} +9 -6
  15. package/dist/packem_shared/{createPolicyDsl-De67zPDS.mjs → createPolicyDsl-By3QB4he.mjs} +4 -1
  16. package/dist/packem_shared/createSecrets-DwaR2rNG.mjs +58 -0
  17. package/dist/packem_shared/{defineAggregateIndex-DxSso0rH.mjs → defineAggregateIndex-znq4ygKQ.mjs} +69 -10
  18. package/dist/packem_shared/defineIdentity-DiX4zM9x.mjs +35 -0
  19. package/dist/packem_shared/{defineMigration-CAJLr6fx.mjs → defineMigration-Hx01yIht.mjs} +3 -1
  20. package/dist/packem_shared/defineMutator-EIXAWhs9.mjs +11 -0
  21. package/dist/packem_shared/defineShape-C5scNOrf.mjs +18 -0
  22. package/dist/packem_shared/{defineStorageRule-qu0mpilX.mjs → defineStorageRule-B5nL4Z1P.mjs} +4 -1
  23. package/dist/packem_shared/functions-Di9FUNkf.mjs +5 -0
  24. package/dist/packem_shared/{httpAction-B7FYUEgr.mjs → httpAction-DCXoYPIk.mjs} +42 -27
  25. package/dist/packem_shared/{initLunora-CATvPsVt.mjs → initLunora-sQUqaejx.mjs} +18 -4
  26. package/dist/packem_shared/{mask-Jc84C_hK.mjs → mask-BT1YgRbF.mjs} +89 -9
  27. package/dist/packem_shared/policy-tag-DvpVH2tv.mjs +13 -0
  28. package/dist/packem_shared/{protectPublic-BjFkQ_Or.mjs → protectPublic-BlcGpiRc.mjs} +1 -1
  29. package/dist/packem_shared/{rls-BDKRbMCA.mjs → rls-B_ZWgslr.mjs} +51 -7
  30. package/dist/packem_shared/{run-middleware-CYQOuoV6.mjs → run-middleware-I6EiQfxL.mjs} +3 -1
  31. package/dist/packem_shared/{storageRules-4a30FSpI.mjs → storageRules-6QxzDOcx.mjs} +1 -1
  32. package/dist/packem_shared/{types.d-DmvyEMD6.d.mts → types.d-BB3pjV0m.d.mts} +10 -4
  33. package/dist/packem_shared/{types.d-BDY0FYHK.d.ts → types.d-Cxl6ndhm.d.ts} +10 -4
  34. package/dist/rls/testing.d.mts +1 -1
  35. package/dist/rls/testing.d.ts +1 -1
  36. package/dist/rls/testing.mjs +1 -1
  37. package/dist/types.d.mts +206 -5
  38. package/dist/types.d.ts +206 -5
  39. package/package.json +6 -5
  40. package/dist/packem_shared/LunoraError-DhggBJZF.mjs +0 -51
  41. package/dist/packem_shared/bindOrm-DCuyr46L.mjs +0 -71
package/LICENSE.md CHANGED
@@ -103,3 +103,9 @@ Unless required by applicable law or agreed to in writing, software distributed
103
103
  under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
104
  CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
105
  specific language governing permissions and limitations under the License.
106
+
107
+ <!-- DEPENDENCIES -->
108
+ <!-- /DEPENDENCIES -->
109
+
110
+ <!-- TYPE_DEPENDENCIES -->
111
+ <!-- /TYPE_DEPENDENCIES -->
package/README.md CHANGED
@@ -91,10 +91,60 @@ export const send = mutation
91
91
 
92
92
  The builder chain is `<builder>.input(validators).<kind>(handler)`, plus `.use(middleware)` and `.output(validator)`. `internalQuery` / `internalMutation` / `internalAction` are the same builders but kept off the public `api`. Run `lunora codegen` (or the Vite plugin) to (re)generate `_generated/` after a schema change.
93
93
 
94
- > **Determinism:** `query` and `mutation` handlers must be deterministic — they may be re-run on OCC retry or subscription re-evaluation. Compute time, randomness, and network results in an `action` (e.g. `Date.now()`, `crypto.randomUUID()`, `fetch`) and pass them into the mutation as arguments.
94
+ > **Determinism:** `query` and `mutation` handlers must be deterministic — they may be re-run on OCC retry or subscription re-evaluation. Read the current time from **`ctx.now`** (epoch ms, captured once per execution — also on `ActionCtx`) instead of `Date.now()`; compute randomness and network results in an `action` (`crypto.randomUUID()`, `fetch`) and pass them into the mutation as arguments. The `nondeterministic_query_mutation` advisor flags `Date.now()`/`Math.random()`/`fetch` in query/mutation handlers.
95
+
96
+ ### Local-first sync engine
97
+
98
+ `defineShape` declares a **partial replication shape** (a named table view with a server-resolved `where` predicate, AND-composed with RLS) and `defineMutator` declares a **custom mutator** (an authoritative `server` impl plus an optional optimistic `client` twin). Both are discovered by codegen and drive the [local-first sync engine](https://lunora.sh/docs/concepts/local-first) — clients subscribe to shapes over the poke diff protocol and push optimistic writes rebased over the server's authoritative result. The client-side runtime lives in [`@lunora/db`](https://www.npmjs.com/package/@lunora/db).
95
99
 
96
100
  > This README covers the basics. For the full API, options, and guides, see the **[documentation](https://lunora.sh/docs/packages/server)**.
97
101
 
102
+ ### Caching with Workers Cache
103
+
104
+ Lunora supports Cloudflare Workers Cache for HTTP actions (`httpRoute`). RPC queries and mutations are `POST /_lunora/rpc` and are not cacheable at the edge by design.
105
+
106
+ **Enable Workers Cache** in `wrangler.jsonc`:
107
+
108
+ ```jsonc
109
+ {
110
+ "cache": { "enabled": true },
111
+ }
112
+ ```
113
+
114
+ The dev server and CLI automatically bump `compatibility_date` to the minimum required when cache is enabled — you do not need to set it manually.
115
+
116
+ **Set cache headers declaratively** on an `httpRoute`:
117
+
118
+ ```ts
119
+ import { httpRoute } from "./_generated/server";
120
+
121
+ export const getProduct = httpRoute
122
+ .get("/api/products/:id")
123
+ .params({ id: v.string() })
124
+ .cacheControl("public, max-age=300, stale-while-revalidate=3600")
125
+ .cacheTag("products")
126
+ .handler(async ({ ctx, params }) => {
127
+ return { id: params.id, name: "Widget" };
128
+ });
129
+ ```
130
+
131
+ **Purge cache by tag** from an action handler:
132
+
133
+ ```ts
134
+ import { action } from "./_generated/server";
135
+
136
+ export const refreshProducts = action.action(async ({ ctx }) => {
137
+ if (!ctx.cache) {
138
+ throw new Error("Workers Cache is not enabled in wrangler.jsonc");
139
+ }
140
+
141
+ await ctx.cache.purge({ tags: ["products"] });
142
+ return { ok: true };
143
+ });
144
+ ```
145
+
146
+ The `ctx.cache.purge` API accepts `{ tags?: string[]; purgeEverything?: boolean }`. Only action handlers expose `ctx.cache`; queries and mutations run inside the Durable Object and do not have access to the Worker-level cache binding.
147
+
98
148
  ## Related
99
149
 
100
150
  - [`@lunora/values`](https://www.npmjs.com/package/@lunora/values) — the `v.*` validators re-exported here.