@tinycloud/replica 0.3.0-beta.5 → 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.js CHANGED
@@ -1335,12 +1335,15 @@ var SqliteReplicaStore = class _SqliteReplicaStore {
1335
1335
  }
1336
1336
  #storeGrantPolicy(g, policy, existing) {
1337
1337
  const installedAt = existing?.installedAt ?? policy.at;
1338
+ const keepExisting = existing !== null && existing.consentDeadline < policy.consentDeadline;
1339
+ const consentDeadline = keepExisting ? existing.consentDeadline : policy.consentDeadline;
1340
+ const consentAnchor = keepExisting ? existing.consentAnchor : policy.consentAnchor;
1338
1341
  const effectiveExpiresAt = Math.min(
1339
1342
  g.expiresAt === null ? Infinity : g.expiresAt * 1e3,
1340
1343
  installedAt + policy.ttlMs,
1341
- policy.consentDeadline
1344
+ consentDeadline
1342
1345
  );
1343
- 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) {
1346
+ 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) {
1344
1347
  throw new ReplicaError(ReplicaErrorCode.GRANT_EXPIRED, "The replica grant has no finite effective expiry.");
1345
1348
  }
1346
1349
  this.#db.run(
@@ -1352,11 +1355,11 @@ var SqliteReplicaStore = class _SqliteReplicaStore {
1352
1355
  g.cid,
1353
1356
  installedAt,
1354
1357
  effectiveExpiresAt,
1355
- policy.consentDeadline,
1356
- policy.consentAnchor.at,
1357
- policy.consentAnchor.source
1358
+ consentDeadline,
1359
+ consentAnchor.at,
1360
+ consentAnchor.source
1358
1361
  );
1359
- return { installedAt, effectiveExpiresAt, consentDeadline: policy.consentDeadline, consentAnchor: policy.consentAnchor };
1362
+ return { installedAt, effectiveExpiresAt, consentDeadline, consentAnchor };
1360
1363
  }
1361
1364
  async installGatedGrant(g, policy) {
1362
1365
  return this.#guardedWrite("Installing the gated grant", () => {