@tinycloud/replica 0.3.0-beta.6 → 0.3.0-beta.7

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/dist/sqlite.cjs CHANGED
@@ -1366,12 +1366,15 @@ var SqliteReplicaStore = class _SqliteReplicaStore {
1366
1366
  }
1367
1367
  #storeGrantPolicy(g, policy, existing) {
1368
1368
  const installedAt = existing?.installedAt ?? policy.at;
1369
+ const keepExisting = existing !== null && existing.consentDeadline < policy.consentDeadline;
1370
+ const consentDeadline = keepExisting ? existing.consentDeadline : policy.consentDeadline;
1371
+ const consentAnchor = keepExisting ? existing.consentAnchor : policy.consentAnchor;
1369
1372
  const effectiveExpiresAt = Math.min(
1370
1373
  g.expiresAt === null ? Infinity : g.expiresAt * 1e3,
1371
1374
  installedAt + policy.ttlMs,
1372
- policy.consentDeadline
1375
+ consentDeadline
1373
1376
  );
1374
- if (!Number.isSafeInteger(installedAt) || installedAt < 0 || !Number.isSafeInteger(effectiveExpiresAt) || effectiveExpiresAt < 0 || !Number.isSafeInteger(policy.consentDeadline) || policy.consentDeadline < 0 || !Number.isSafeInteger(policy.consentAnchor.at) || policy.consentAnchor.at < 0 || !Number.isSafeInteger(policy.ttlMs) || policy.ttlMs <= 0) {
1377
+ if (!Number.isSafeInteger(installedAt) || installedAt < 0 || !Number.isSafeInteger(effectiveExpiresAt) || effectiveExpiresAt < 0 || !Number.isSafeInteger(consentDeadline) || consentDeadline < 0 || !Number.isSafeInteger(consentAnchor.at) || consentAnchor.at < 0 || !Number.isSafeInteger(policy.ttlMs) || policy.ttlMs <= 0) {
1375
1378
  throw new ReplicaError(ReplicaErrorCode.GRANT_EXPIRED, "The replica grant has no finite effective expiry.");
1376
1379
  }
1377
1380
  this.#db.run(
@@ -1383,11 +1386,11 @@ var SqliteReplicaStore = class _SqliteReplicaStore {
1383
1386
  g.cid,
1384
1387
  installedAt,
1385
1388
  effectiveExpiresAt,
1386
- policy.consentDeadline,
1387
- policy.consentAnchor.at,
1388
- policy.consentAnchor.source
1389
+ consentDeadline,
1390
+ consentAnchor.at,
1391
+ consentAnchor.source
1389
1392
  );
1390
- return { installedAt, effectiveExpiresAt, consentDeadline: policy.consentDeadline, consentAnchor: policy.consentAnchor };
1393
+ return { installedAt, effectiveExpiresAt, consentDeadline, consentAnchor };
1391
1394
  }
1392
1395
  async installGatedGrant(g, policy) {
1393
1396
  return this.#guardedWrite("Installing the gated grant", () => {