unforgit 0.11.8 → 0.11.10

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.
@@ -2046,6 +2046,43 @@ var RemoteClient = class {
2046
2046
  }
2047
2047
  return res.json();
2048
2048
  }
2049
+ async syncPull(orgId, repoId, since) {
2050
+ const params = new URLSearchParams({ orgId, repoId });
2051
+ if (since) params.set("since", since.toISOString());
2052
+ const res = await this.fetchWithRetry(
2053
+ `${this.baseUrl}/v1/sync/pull?${params.toString()}`,
2054
+ { method: "GET", headers: this.getHeaders() },
2055
+ "syncPull"
2056
+ );
2057
+ if (!res.ok) {
2058
+ this.handleError(res, "syncPull", await res.text());
2059
+ }
2060
+ const memories = await res.json();
2061
+ return memories.map((memory) => ({
2062
+ ...memory,
2063
+ createdAt: new Date(memory.createdAt),
2064
+ updatedAt: new Date(memory.updatedAt),
2065
+ deletedAt: memory.deletedAt ? new Date(memory.deletedAt) : void 0
2066
+ }));
2067
+ }
2068
+ async syncTombstones(orgId, repoId, since) {
2069
+ const params = new URLSearchParams({ orgId, repoId });
2070
+ if (since) params.set("since", since.toISOString());
2071
+ const res = await this.fetchWithRetry(
2072
+ `${this.baseUrl}/v1/sync/tombstones?${params.toString()}`,
2073
+ { method: "GET", headers: this.getHeaders() },
2074
+ "syncTombstones"
2075
+ );
2076
+ if (!res.ok) {
2077
+ this.handleError(res, "syncTombstones", await res.text());
2078
+ }
2079
+ const tombstones = await res.json();
2080
+ return tombstones.map((tombstone) => ({
2081
+ ...tombstone,
2082
+ deletedAt: new Date(tombstone.deletedAt),
2083
+ syncedAt: tombstone.syncedAt ? new Date(tombstone.syncedAt) : void 0
2084
+ }));
2085
+ }
2049
2086
  async deprecate(id, reason) {
2050
2087
  const res = await this.fetchWithRetry(
2051
2088
  `${this.baseUrl}/v1/memory/${pathSegment(id)}/deprecate`,
@@ -3392,9 +3429,8 @@ var LocalStore = class {
3392
3429
  ).all(orgId, repoId, since.toISOString());
3393
3430
  return rows.map(rowToMemory);
3394
3431
  }
3395
- upsertFromRemote(memory) {
3432
+ upsertFromRemote(memory, conflictResolution = "last_write_wins") {
3396
3433
  const existing = this.getById(memory.id);
3397
- const now = (/* @__PURE__ */ new Date()).toISOString();
3398
3434
  const normalizedOrgId = memory.orgId.toLowerCase();
3399
3435
  const normalizedRepoId = memory.repoId.toLowerCase();
3400
3436
  if (!existing) {
@@ -3425,7 +3461,7 @@ var LocalStore = class {
3425
3461
  memory.deletedAt?.toISOString() ?? null,
3426
3462
  memory.deletedBy ?? null,
3427
3463
  memory.createdAt.toISOString(),
3428
- now
3464
+ memory.updatedAt.toISOString()
3429
3465
  );
3430
3466
  return { action: "created", conflict: false };
3431
3467
  }
@@ -3437,6 +3473,10 @@ var LocalStore = class {
3437
3473
  }
3438
3474
  }
3439
3475
  const hasConflict = localVersion !== remoteVersion && existing.updatedAt > memory.updatedAt;
3476
+ const preserveLocal = hasConflict && (conflictResolution === "manual" || conflictResolution === "local_wins" || conflictResolution === "last_write_wins" && existing.updatedAt >= memory.updatedAt);
3477
+ if (preserveLocal) {
3478
+ return { action: "skipped", conflict: true };
3479
+ }
3440
3480
  this.db.prepare(
3441
3481
  `UPDATE memories SET
3442
3482
  memory_type = ?, visibility = ?, status = ?, text = ?, summary = ?, tags = ?,
@@ -3459,10 +3499,10 @@ var LocalStore = class {
3459
3499
  memory.consolidationVersion ?? null,
3460
3500
  memory.authorId ?? null,
3461
3501
  memory.authorName ?? null,
3462
- Math.max(remoteVersion, localVersion) + 1,
3502
+ remoteVersion,
3463
3503
  memory.deletedAt?.toISOString() ?? null,
3464
3504
  memory.deletedBy ?? null,
3465
- now,
3505
+ memory.updatedAt.toISOString(),
3466
3506
  memory.id
3467
3507
  );
3468
3508
  return { action: "updated", conflict: hasConflict };
@@ -3567,13 +3607,16 @@ var LocalStore = class {
3567
3607
  });
3568
3608
  return transaction.immediate();
3569
3609
  }
3570
- markAsPulled(memoryId, localVersion) {
3610
+ markAsPulled(memoryId, remoteVersion) {
3571
3611
  const now = (/* @__PURE__ */ new Date()).toISOString();
3572
3612
  this.db.prepare(`
3573
- UPDATE sync_state
3574
- SET sync_status = 'synced', local_version = ?, last_pulled_at = ?
3613
+ UPDATE sync_state
3614
+ SET sync_status = 'synced',
3615
+ local_version = ?,
3616
+ remote_version = ?,
3617
+ last_pulled_at = ?
3575
3618
  WHERE memory_id = ?
3576
- `).run(localVersion, now, memoryId);
3619
+ `).run(remoteVersion, remoteVersion, now, memoryId);
3577
3620
  }
3578
3621
  markAsConflict(memoryId, remoteVersion) {
3579
3622
  this.db.prepare(`
@@ -4424,4 +4467,4 @@ export {
4424
4467
  RemoteClient,
4425
4468
  LocalStore
4426
4469
  };
4427
- //# sourceMappingURL=chunk-23T3TBYJ.js.map
4470
+ //# sourceMappingURL=chunk-J74YKGDT.js.map