@jcbuisson/express-x-drizzle 1.0.7 → 1.0.8

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/CLAUDE.md ADDED
@@ -0,0 +1,29 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Package
6
+
7
+ `@jcbuisson/express-x-drizzle` is an ESM-only NPM package (no build step). The single source file is `src/drizzle-plugins.mjs`; the package root re-exports it as `drizzle-plugins.mjs` via the `"main"` field in `package.json`.
8
+
9
+ No test runner or linter is configured. There are no build, test, or lint commands.
10
+
11
+ To publish: `npm publish` (package is public, not private).
12
+
13
+ ## Architecture
14
+
15
+ The library exports one function: `drizzleOfflinePlugin(app, db, metadata, models)`.
16
+
17
+ **Parameters:**
18
+ - `app` — an `express-x` application instance (from `@jcbuisson/express-x`)
19
+ - `db` — a Drizzle ORM database instance
20
+ - `metadata` — a Drizzle table schema used to store per-record timestamps (`uid`, `created_at`, `updated_at`, `deleted_at`)
21
+ - `models` — array of Drizzle table schemas to expose as services
22
+
23
+ **What it does:**
24
+
25
+ 1. **Per-model services** — For each table in `models`, registers an `express-x` service named after the table. Each service exposes: `findUnique`, `findMany`, `createWithMeta`, `updateWithMeta`, `deleteWithMeta`. All mutation methods write to both the model table and the `metadata` table inside a transaction, keeping timestamps in sync.
26
+
27
+ 2. **`sync` service** — Implements an offline-first reconciliation algorithm. The client sends its local metadata dictionary (`{ uid → { created_at, updated_at, deleted_at } }`) plus a `cutoffDate`. The server computes set intersections between client UIDs and database UIDs, then determines add/update/delete operations for both sides. A `Mutex` (from `express-x`) serializes concurrent sync calls globally. The return value tells the client which records to add, update, or delete locally, and which UIDs the client should push to the database with full data.
28
+
29
+ **Key invariant:** The sync algorithm compares `updated_at` (falling back to `created_at`) timestamps to decide which side wins a conflict — the most recently updated side wins. Records marked `deleted_at` on the client trigger a soft-delete propagation to the database.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcbuisson/express-x-drizzle",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Drizzle ORM plugins for express-x framework",
5
5
  "main": "src/drizzle-plugins.mjs",
6
6
  "type": "module",
@@ -24,10 +24,9 @@
24
24
  "license": "MIT",
25
25
  "bugs": "",
26
26
  "keywords": [],
27
- "scripts": {
28
- },
27
+ "scripts": {},
29
28
  "dependencies": {
30
- "@jcbuisson/express-x": "^3.0.4",
29
+ "@jcbuisson/express-x": "^3.0.5",
31
30
  "@jcbuisson/express-x-client": "^3.0.5",
32
31
  "@vueuse/core": "^14.3.0",
33
32
  "dexie": "^4.4.2",
@@ -149,6 +149,7 @@ export function drizzleOfflinePlugin(app, db, metadata, models) {
149
149
  }
150
150
  } catch(err) {
151
151
  console.log('*** err sync', err)
152
+ throw err
152
153
  } finally {
153
154
  syncMutexes.get(mutexKey).release()
154
155
  }
@@ -1,14 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(npm test *)",
5
- "Bash(node -e \"require\\('tsx'\\)\")",
6
- "Bash(npm install *)",
7
- "Bash(node --test test/sync.test.mjs)",
8
- "Bash(tee /tmp/test-output.txt)",
9
- "Bash(tee /tmp/test-output2.txt)",
10
- "Bash(node --help)",
11
- "Bash(node --import tsx/esm --import /tmp/preload.mjs --test --test-force-exit test/round-trip.test.mjs)"
12
- ]
13
- }
14
- }