@rulvar/store-sqlite 1.126.0 → 1.128.0

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/index.d.ts CHANGED
@@ -157,7 +157,9 @@ declare class SqliteQuotaLimiter implements QuotaLimiter {
157
157
  private readonly now;
158
158
  constructor(options: SqliteQuotaLimiterOptions);
159
159
  reserve(request: QuotaReservationRequest): Promise<QuotaDecision>;
160
- reconcile(reservationId: string, usage: Usage): Promise<void>;
160
+ reconcile(reservationId: string, usage: Usage, actual?: {
161
+ requests?: number;
162
+ }): Promise<void>;
161
163
  /** Current-window counters per rule, for telemetry and referees. */
162
164
  snapshot(): Array<{
163
165
  rule: QuotaRule;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DatabaseSync } from "node:sqlite";
2
- import { ConfigError, JournalOrderViolation, LeaseHeldError, QUOTA_WINDOW_MS, mergeQuotaDenial, metaMatchesFilter, quotaActualTokens, quotaEstimateTokens, quotaRuleAdmission, quotaRuleKey, quotaRuleMatches, snapshotQuotaRules } from "@rulvar/core";
2
+ import { ConfigError, JournalOrderViolation, LeaseHeldError, QUOTA_WINDOW_MS, mergeQuotaDenial, metaMatchesFilter, quotaActualRequestsDelta, quotaActualTokens, quotaEstimateTokens, quotaRuleAdmission, quotaRuleKey, quotaRuleMatches, snapshotQuotaRules } from "@rulvar/core";
3
3
  import { randomUUID } from "node:crypto";
4
4
  //#region src/store.ts
5
5
  /**
@@ -509,7 +509,7 @@ var SqliteQuotaLimiter = class {
509
509
  throw thrown;
510
510
  }
511
511
  }
512
- reconcile(reservationId, usage) {
512
+ reconcile(reservationId, usage, actual) {
513
513
  const at = this.now();
514
514
  const windowStart = at - at % QUOTA_WINDOW_MS;
515
515
  this.db.exec("BEGIN IMMEDIATE");
@@ -522,8 +522,9 @@ var SqliteQuotaLimiter = class {
522
522
  this.db.prepare("DELETE FROM quota_reservations WHERE id = ?").run(reservationId);
523
523
  if (row.window_start === windowStart) {
524
524
  const delta = quotaActualTokens(usage) - row.estimate_tokens;
525
- const adjust = this.db.prepare("UPDATE quota_buckets SET tokens = MAX(0, tokens + ?) WHERE rule_key = ? AND window_start = ?");
526
- for (const key of JSON.parse(row.rule_keys)) adjust.run(delta, key, windowStart);
525
+ const requestsDelta = quotaActualRequestsDelta(actual);
526
+ const adjust = this.db.prepare("UPDATE quota_buckets SET tokens = MAX(0, tokens + ?), requests = requests + ? WHERE rule_key = ? AND window_start = ?");
527
+ for (const key of JSON.parse(row.rule_keys)) adjust.run(delta, requestsDelta, key, windowStart);
527
528
  }
528
529
  this.db.exec("COMMIT");
529
530
  return Promise.resolve();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulvar/store-sqlite",
3
- "version": "1.126.0",
3
+ "version": "1.128.0",
4
4
  "description": "Rulvar SQLite store implementing JournalStore and LeasableStore with a fencing epoch.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -22,13 +22,13 @@
22
22
  "access": "public"
23
23
  },
24
24
  "dependencies": {
25
- "@rulvar/core": "1.126.0"
25
+ "@rulvar/core": "1.128.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^22.20.1",
29
29
  "tsdown": "^0.22.14",
30
30
  "typescript": "~6.0.3",
31
- "@rulvar/store-conformance": "1.126.0"
31
+ "@rulvar/store-conformance": "1.128.0"
32
32
  },
33
33
  "repository": {
34
34
  "type": "git",