tetherdb 0.1.0 → 0.1.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.1.1] - 2026-08-23
6
+
7
+ - Add `tetherPlugin` (`tetherdb/vite`) for zero-config Vite dev and preview servers.
8
+ - Add `TetherServer.prototype.createMiddleware()` for Connect and Express integration.
9
+ - Improve `TetherServer.prototype.attach()` to coexist with other WebSocket handlers.
10
+ - Simplify Todo example to use Vite plugin.
11
+
12
+ ## [0.1.0] - 2026-08-20
13
+
14
+ - Initial release.
15
+ - Offline-first IndexedDB client with real-time two-way WebSocket sync (`tetherdb/client`).
16
+ - Server with SQLite, filesystem, and in-memory storage backends (`tetherdb/server`).
17
+ - CLI tool for server management and maintenance (`tetherdb/cli`).
package/README.md CHANGED
@@ -16,7 +16,8 @@
16
16
  [Framework Integration](#framework-integration) •
17
17
  [CLI & Server](#cli--server-administration) •
18
18
  [Production Deployment](#production-deployment) •
19
- [Example App](#example-application)
19
+ [Example App](#example-application)
20
+ [Changelog](CHANGELOG.md)
20
21
 
21
22
  ## Features
22
23
 
@@ -80,7 +81,7 @@ interface Todo {
80
81
  }
81
82
 
82
83
  // 1. Initialize client with server endpoint
83
- const client = new TetherClient('my-todo-app', {
84
+ const client = new TetherClient('todo-app', {
84
85
  url: 'http://localhost:8080',
85
86
  });
86
87
 
@@ -132,6 +133,52 @@ client.onSyncStatusChange.register((status) => {
132
133
 
133
134
  ## Framework Integration
134
135
 
136
+ ### Vite Plugin (Zero-Config Development)
137
+
138
+ Embed TetherDB sync and authentication directly inside your Vite dev and preview servers with `tetherdb/vite`:
139
+
140
+ ```typescript
141
+ // vite.config.ts
142
+ import { defineConfig } from 'vite';
143
+ import { SqliteStorage } from 'tetherdb/server';
144
+ import { tetherPlugin } from 'tetherdb/vite';
145
+
146
+ export default defineConfig({
147
+ plugins: [
148
+ tetherPlugin({
149
+ // Optional persistent storage (defaults to in-memory)
150
+ storage: new SqliteStorage({ baseDir: './data' }),
151
+ // Pre-declare applications and tables
152
+ apps: [{ appId: 'todo-app', tables: ['todos'] }],
153
+ // Pre-provision default demo accounts
154
+ users: [{ username: 'demo', password: 'password123' }],
155
+ }),
156
+ ],
157
+ });
158
+ ```
159
+
160
+ Now running `vite` serves frontend assets (HMR), REST authentication endpoints (`/auth/login`, `/auth/register`), and real-time WebSocket sync (`/sync`) all on the same dev port with zero CORS configuration!
161
+
162
+ ### Connect & Express Middleware
163
+
164
+ Mount TetherDB endpoints into an existing Express or Node.js HTTP application:
165
+
166
+ ```typescript
167
+ import express from 'express';
168
+ import { TetherServer } from 'tetherdb/server';
169
+
170
+ const app = express();
171
+ const tetherServer = new TetherServer();
172
+
173
+ // Mount authentication and health REST middleware
174
+ app.use(tetherServer.createMiddleware());
175
+
176
+ const server = app.listen(8080);
177
+
178
+ // Attach WebSocket sync handler
179
+ tetherServer.attach(server);
180
+ ```
181
+
135
182
  ### React Hook Example
136
183
 
137
184
  Bind any TetherDB table to component state with automatic real-time updates:
@@ -172,14 +219,14 @@ npx tetherdb --file=./data --port=8080
172
219
 
173
220
  # Manage apps, tables, and users
174
221
  npx tetherdb apps list --sqlite=./data
175
- npx tetherdb apps add my-todo-app --sqlite=./data
176
- npx tetherdb tables add my-todo-app todos --sqlite=./data
222
+ npx tetherdb apps add todo-app --sqlite=./data
223
+ npx tetherdb tables add todo-app todos --sqlite=./data
177
224
  npx tetherdb users add alice secret --sqlite=./data
178
225
 
179
226
  # Run database maintenance & compaction
180
227
  npx tetherdb maintenance checkpoint --sqlite=./data
181
228
  npx tetherdb maintenance vacuum --sqlite=./data
182
- npx tetherdb maintenance prune my-todo-app 1000 --sqlite=./data
229
+ npx tetherdb maintenance prune todo-app 1000 --sqlite=./data
183
230
  ```
184
231
 
185
232
  ## HTTP & WebSocket Endpoints
@@ -1647,8 +1647,6 @@ var TetherServer = class {
1647
1647
  this._webSocketServer?.handleUpgrade(req, socket, head, (ws) => {
1648
1648
  this._webSocketServer?.emit("connection", ws, req);
1649
1649
  });
1650
- } else {
1651
- socket.destroy();
1652
1650
  }
1653
1651
  });
1654
1652
  }
@@ -1736,6 +1734,23 @@ var TetherServer = class {
1736
1734
  }
1737
1735
  });
1738
1736
  }
1737
+ /**
1738
+ * Creates a Connect- and Express-compatible HTTP middleware handler.
1739
+ *
1740
+ * @returns Middleware function `(req, res, next) => void`.
1741
+ */
1742
+ createMiddleware() {
1743
+ return (req, res, next) => {
1744
+ this.handleHttpRequest(req, res).then(
1745
+ (handled) => {
1746
+ if (!handled) next();
1747
+ },
1748
+ (err) => {
1749
+ next(err);
1750
+ }
1751
+ );
1752
+ };
1753
+ }
1739
1754
  /**
1740
1755
  * Handles incoming HTTP requests for authentication and discovery endpoints.
1741
1756
  *