@sqlite-sync/cloudflare 0.4.0 → 0.4.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 (2) hide show
  1. package/README.md +58 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # @sqlite-sync/cloudflare
2
+
3
+ Cloudflare backend utilities for [sqlite-sync](https://github.com/krolebord-dev/sqlite-sync) — a local-first SQLite sync engine for web apps, with reactive queries, offline persistence, and CRDT-based replication.
4
+
5
+ This package provides a Durable Object adapter and execution helpers for running the sync backend on Cloudflare, so clients built with [`@sqlite-sync/core`](https://www.npmjs.com/package/@sqlite-sync/core) can sync CRDT event batches with a remote server.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @sqlite-sync/cloudflare
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```ts
16
+ // event-log-server.ts
17
+ import { durableObjectAdapter, type RemoteHandler } from "@sqlite-sync/cloudflare";
18
+ import { type Connection, routePartykitRequest, Server } from "partyserver";
19
+ import { syncDbSchema } from "../src/db-schema";
20
+
21
+ export class EventLogServer extends Server<Env> {
22
+ private remoteHandler!: RemoteHandler;
23
+
24
+ onStart() {
25
+ const { remoteHandler } = durableObjectAdapter.createCrdtStorage({
26
+ storage: this.ctx.storage,
27
+ nodeId: this.ctx.id.toString(),
28
+ syncDbSchema,
29
+ crdtEventsTable: "crdt_events",
30
+ batchSize: 100,
31
+ broadcastPayload: (payload) => this.broadcast(payload),
32
+ });
33
+ this.remoteHandler = remoteHandler;
34
+ }
35
+
36
+ onMessage(connection: Connection, message: string) {
37
+ const result = this.remoteHandler.handleMessage(message);
38
+ if (result.success) {
39
+ connection.send(result.payload);
40
+ }
41
+ }
42
+ }
43
+
44
+ export default {
45
+ fetch: (request: Request, env: Env) =>
46
+ routePartykitRequest(request, env).then(
47
+ (res) => res || new Response("Not Found", { status: 404 }),
48
+ ),
49
+ } satisfies ExportedHandler<Env>;
50
+ ```
51
+
52
+ ## Documentation
53
+
54
+ See the [full documentation](https://github.com/krolebord-dev/sqlite-sync/blob/main/docs.md) and the [project README](https://github.com/krolebord-dev/sqlite-sync) for how sync works and client setup.
55
+
56
+ ## License
57
+
58
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sqlite-sync/cloudflare",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Cloudflare utilities for @sqlite-sync/core",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -30,7 +30,7 @@
30
30
  "dist"
31
31
  ],
32
32
  "dependencies": {
33
- "@sqlite-sync/core": "0.4.0"
33
+ "@sqlite-sync/core": "0.4.2"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@cloudflare/workers-types": "^4.0.0",