@jcbuisson/express-x-drizzle 3.1.11 → 3.1.12
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 +1 -1
- package/package.json +1 -1
- package/src/drizzle-plugins.mjs +2 -3
package/CLAUDE.md
CHANGED
|
@@ -24,6 +24,6 @@ The library exports one function: `drizzleOfflinePlugin(app, db, metadata, model
|
|
|
24
24
|
|
|
25
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
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 } }`)
|
|
27
|
+
2. **`sync` service** — Implements an offline-first reconciliation algorithm. The client sends its local metadata dictionary (`{ uid → { created_at, updated_at, deleted_at } }`). The server computes set intersections between client UIDs and database UIDs, then determines add/update/delete operations for both sides. An overlap-aware lock serializes sync calls whose `where` scopes can touch the same records. 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
28
|
|
|
29
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
package/src/drizzle-plugins.mjs
CHANGED
|
@@ -193,8 +193,7 @@ export function drizzleOfflinePlugin(app, db, metadata, models) {
|
|
|
193
193
|
// add a synchronization service
|
|
194
194
|
app.createService('sync', {
|
|
195
195
|
|
|
196
|
-
|
|
197
|
-
go: async (modelName, where, cutoffDate, clientMetadataDict) => {
|
|
196
|
+
go: async (modelName, where, clientMetadataDict) => {
|
|
198
197
|
|
|
199
198
|
// overlap-aware lock so independent scopes can still run in parallel, but overlapping where predicates do not
|
|
200
199
|
if (!syncLocks.has(modelName)) syncLocks.set(modelName, new OverlapLock())
|
|
@@ -202,7 +201,7 @@ export function drizzleOfflinePlugin(app, db, metadata, models) {
|
|
|
202
201
|
const releaseSyncLock = await syncLock.acquire(where)
|
|
203
202
|
|
|
204
203
|
try {
|
|
205
|
-
console.log('>>>>> SYNC', modelName, where
|
|
204
|
+
console.log('>>>>> SYNC', modelName, where)
|
|
206
205
|
const databaseService = app.service(modelName)
|
|
207
206
|
|
|
208
207
|
// STEP1: get existing database `where` values and build a dictionary
|