@opendatalabs/personal-server-ts-server 1.33.0 → 1.33.1

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.
@@ -113359,7 +113359,7 @@ var LedgerFold = class {
113359
113359
  through = null;
113360
113360
  retry;
113361
113361
  skipped;
113362
- partial = false;
113362
+ truncated = false;
113363
113363
  // A Map keeps arbitrary keys (including "__proto__") out of the prototype
113364
113364
  // chain; Object.fromEntries defines each one as an own property again.
113365
113365
  records = /* @__PURE__ */ new Map();
@@ -113376,7 +113376,7 @@ var LedgerFold = class {
113376
113376
  attemptedAt: ledger.retry.attemptedAt
113377
113377
  } : void 0;
113378
113378
  this.skipped = ledger.skipped;
113379
- this.partial = ledger.partial === true;
113379
+ this.truncated = ledger.truncated === true;
113380
113380
  for (const [key, pair] of Object.entries(ledger.records)) {
113381
113381
  this.records.set(key, [pair[0], pair[1]]);
113382
113382
  }
@@ -113403,7 +113403,7 @@ var LedgerFold = class {
113403
113403
  return;
113404
113404
  if (this.baseline === null) {
113405
113405
  this.baseline = version4.collectedAt;
113406
- } else if (isEarlier(version4.collectedAt, this.baseline) && !this.partial) {
113406
+ } else if (isEarlier(version4.collectedAt, this.baseline) && !this.truncated) {
113407
113407
  this.baseline = version4.collectedAt;
113408
113408
  }
113409
113409
  if (isNewer(version4.collectedAt, this.current)) {
@@ -113453,8 +113453,8 @@ var LedgerFold = class {
113453
113453
  /**
113454
113454
  * Make room for `need` records by dropping some that are absent: not in the
113455
113455
  * newest tracked version, not in the version being folded, and not
113456
- * pre-tracking (first seen at or before the baseline). Pre-tracking records
113457
- * are never dropped. Dated records that are absent CAN be dropped (and are
113456
+ * baseline records (first seen at or before the baseline). Baseline records
113457
+ * are never dropped. Other absent records CAN be dropped (and are
113458
113458
  * dated as new if they return): that needs a scope near the cap, and
113459
113459
  * whoever can write the scope can provoke it. Among the evictable ones the
113460
113460
  * most recently first seen go first. Returns how many were dropped.
@@ -113502,17 +113502,17 @@ var LedgerFold = class {
113502
113502
  }
113503
113503
  /**
113504
113504
  * Prune and return the ledger, or null when nothing was ever folded.
113505
- * `partial` marks a ledger rebuilt from only the newest retained versions;
113505
+ * `truncated` marks a ledger rebuilt from only the newest retained versions;
113506
113506
  * `through` overrides the completeness marker (see `ScopeFirstSeenLedger`).
113507
113507
  */
113508
113508
  async finish(options = {}) {
113509
113509
  if (this.scope === null || this.latest === null)
113510
113510
  return null;
113511
113511
  await this.prune();
113512
- const partial2 = this.partial || options.partial === true;
113512
+ const truncated = this.truncated || options.truncated === true;
113513
113513
  const retry = options.retry === void 0 ? this.retry : options.retry;
113514
113514
  return {
113515
- version: 3,
113515
+ version: 4,
113516
113516
  scope: this.scope,
113517
113517
  baseline: this.baseline,
113518
113518
  current: this.current,
@@ -113520,7 +113520,7 @@ var LedgerFold = class {
113520
113520
  through: options.through ?? this.through ?? this.latest.collectedAt,
113521
113521
  ...retry ? { retry } : {},
113522
113522
  ...this.skipped ? { skipped: this.skipped } : {},
113523
- ...partial2 ? { partial: true } : {},
113523
+ ...truncated ? { truncated: true } : {},
113524
113524
  records: Object.fromEntries(this.records)
113525
113525
  };
113526
113526
  }
@@ -113535,7 +113535,7 @@ function listAddedTimestamps(ledger) {
113535
113535
  for (const [first, last2] of Object.values(ledger.records)) {
113536
113536
  if (Date.parse(last2) !== currentMs)
113537
113537
  continue;
113538
- if (Date.parse(first) <= baselineMs)
113538
+ if (ledger.partial === true && Date.parse(first) <= baselineMs)
113539
113539
  continue;
113540
113540
  added.push(first);
113541
113541
  }
@@ -113554,9 +113554,9 @@ function nullableParseable(value) {
113554
113554
  var SKIP_REASONS = /* @__PURE__ */ new Set(["too_large", "unreadable"]);
113555
113555
  function readScopeFirstSeenLedger(value) {
113556
113556
  try {
113557
- if (!isRecord3(value) || value.version !== 3)
113557
+ if (!isRecord3(value) || value.version !== 4)
113558
113558
  return null;
113559
- const { scope, baseline, current, latest, through, records, skipped, partial: partial2 } = value;
113559
+ const { scope, baseline, current, latest, through, records, skipped, truncated } = value;
113560
113560
  if (typeof scope !== "string" || scope.length === 0)
113561
113561
  return null;
113562
113562
  if (!nullableParseable(baseline) || !nullableParseable(current)) {
@@ -113586,7 +113586,7 @@ function readScopeFirstSeenLedger(value) {
113586
113586
  }
113587
113587
  if (skipped !== void 0 && !SKIP_REASONS.has(skipped))
113588
113588
  return null;
113589
- if (partial2 !== void 0 && partial2 !== true)
113589
+ if (truncated !== void 0 && truncated !== true)
113590
113590
  return null;
113591
113591
  if (!isRecord3(records))
113592
113592
  return null;
@@ -113602,7 +113602,7 @@ function readScopeFirstSeenLedger(value) {
113602
113602
  copied.set(key, [pair[0], pair[1]]);
113603
113603
  }
113604
113604
  return {
113605
- version: 3,
113605
+ version: 4,
113606
113606
  scope,
113607
113607
  baseline,
113608
113608
  current,
@@ -113610,7 +113610,7 @@ function readScopeFirstSeenLedger(value) {
113610
113610
  through,
113611
113611
  ...retryValue ? { retry: retryValue } : {},
113612
113612
  ...skipped ? { skipped } : {},
113613
- ...partial2 ? { partial: true } : {},
113613
+ ...truncated ? { truncated: true } : {},
113614
113614
  records: Object.fromEntries(copied)
113615
113615
  };
113616
113616
  } catch {
@@ -113639,6 +113639,7 @@ async function withScopeLock(scope, fn3) {
113639
113639
  }
113640
113640
 
113641
113641
  // ../core/dist/additions/ledger-store.js
113642
+ var OLDEST_PAGE = 20;
113642
113643
  var REBUILD_VERSION_LIMIT = 200;
113643
113644
  var REBUILD_BYTE_BUDGET = 256 * 1024 * 1024;
113644
113645
  function isRecord4(value) {
@@ -113694,6 +113695,11 @@ async function dropIfScopeEmpty(storage, scope) {
113694
113695
  function latestStillStored(storage, ledger) {
113695
113696
  return storage.findEntry({ scope: ledger.scope, at: ledger.latest.collectedAt })?.collectedAt === ledger.latest.collectedAt;
113696
113697
  }
113698
+ function baselineStillStored(storage, ledger) {
113699
+ if (ledger.baseline === null)
113700
+ return true;
113701
+ return storage.findEntry({ scope: ledger.scope, at: ledger.baseline })?.collectedAt === ledger.baseline;
113702
+ }
113697
113703
  function isMarker(ledger) {
113698
113704
  return ledger.skipped === "too_large" || ledger.skipped === "unreadable";
113699
113705
  }
@@ -113716,6 +113722,32 @@ async function foldEntries(storage, scope, entries, fold) {
113716
113722
  }
113717
113723
  return { folded, failed };
113718
113724
  }
113725
+ function oldestStartsAtFirst(oldestInstant) {
113726
+ const lowest = oldestInstant.reduce((a10, b10) => b10.version < a10.version ? b10 : a10);
113727
+ return lowest.version <= 1 || (lowest.afterTombstoneVersion ?? null) !== null;
113728
+ }
113729
+ function baselineIsKnown(storage, ledger) {
113730
+ if (ledger.baseline === null || ledger.skipped !== void 0)
113731
+ return true;
113732
+ if (ledger.truncated === true)
113733
+ return false;
113734
+ const count = storage.countVersions(ledger.scope);
113735
+ const tail = storage.listVersions(ledger.scope, {
113736
+ limit: OLDEST_PAGE,
113737
+ offset: Math.max(0, count - OLDEST_PAGE)
113738
+ }).filter((entry) => !Number.isNaN(Date.parse(entry.collectedAt)));
113739
+ if (tail.length === 0)
113740
+ return false;
113741
+ const oldestMs = Math.min(...tail.map((e10) => Date.parse(e10.collectedAt)));
113742
+ if (Date.parse(ledger.baseline) !== oldestMs)
113743
+ return false;
113744
+ return oldestStartsAtFirst(tail.filter((entry) => Date.parse(entry.collectedAt) === oldestMs));
113745
+ }
113746
+ function withDerivedPartial(storage, ledger) {
113747
+ if (baselineIsKnown(storage, ledger))
113748
+ return ledger;
113749
+ return { ...ledger, partial: true };
113750
+ }
113719
113751
  function retryOf(failed, now) {
113720
113752
  if (failed.length === 0)
113721
113753
  return null;
@@ -113732,7 +113764,7 @@ async function rebuild(storage, scope, retained, budget, now) {
113732
113764
  const { folded, failed } = await foldEntries(storage, scope, selected, fold);
113733
113765
  if (folded === 0) {
113734
113766
  return {
113735
- version: 3,
113767
+ version: 4,
113736
113768
  scope,
113737
113769
  baseline: null,
113738
113770
  current: null,
@@ -113744,7 +113776,10 @@ async function rebuild(storage, scope, retained, budget, now) {
113744
113776
  }
113745
113777
  const total = storage.countVersions(scope);
113746
113778
  return fold.finish({
113747
- partial: folded < total,
113779
+ // Truncated only when the window or the byte budget left versions out. A
113780
+ // version that could not be read is not a truncation: it is retried (see
113781
+ // `retry`), and the ledger converges once it is read or deleted.
113782
+ truncated: selected.length < retained.length || retained.length < total,
113748
113783
  through: retained[0].collectedAt,
113749
113784
  retry: retryOf(failed, now)
113750
113785
  });
@@ -113778,7 +113813,7 @@ async function catchUp(storage, ledger, retained, budget, now) {
113778
113813
  })[0];
113779
113814
  const windowCut = beyond !== void 0 && Date.parse(beyond.collectedAt) > Date.parse(ledger.through);
113780
113815
  return await fold.finish({
113781
- partial: windowCut || selected.length < newer.length,
113816
+ truncated: windowCut || selected.length < newer.length,
113782
113817
  through: selected.length > 0 ? retained[0].collectedAt : ledger.through,
113783
113818
  retry
113784
113819
  }) ?? ledger;
@@ -113827,7 +113862,7 @@ async function ensureScopeLedger(storage, scope, options = {}) {
113827
113862
  return null;
113828
113863
  }
113829
113864
  let existing = await readStoredLedger(storage, scope);
113830
- if (existing && (!latestStillStored(storage, existing) || isMarker(existing) && newerThan(retained, existing).length > 0)) {
113865
+ if (existing && (!latestStillStored(storage, existing) || !baselineStillStored(storage, existing) || isMarker(existing) && newerThan(retained, existing).length > 0)) {
113831
113866
  existing = null;
113832
113867
  }
113833
113868
  const ledger = existing ? await catchUp(storage, existing, retained, budget, now) : await rebuild(storage, scope, retained, budget, now);
@@ -113839,7 +113874,7 @@ async function ensureScopeLedger(storage, scope, options = {}) {
113839
113874
  } catch {
113840
113875
  }
113841
113876
  }
113842
- return ledger;
113877
+ return ledger ? withDerivedPartial(storage, ledger) : ledger;
113843
113878
  } catch {
113844
113879
  return null;
113845
113880
  }
@@ -113902,6 +113937,7 @@ async function summarizeAdditions(input) {
113902
113937
  let total = 0;
113903
113938
  let trackedSince = null;
113904
113939
  let trackedSinceAt = Infinity;
113940
+ let anyPartial = false;
113905
113941
  for await (const ledger of input.ledgers) {
113906
113942
  for (const firstSeen of listAddedTimestamps(ledger)) {
113907
113943
  const date5 = localDate(formatter, new Date(Date.parse(firstSeen)));
@@ -113918,14 +113954,24 @@ async function summarizeAdditions(input) {
113918
113954
  trackedSince = scopeTrackedSince;
113919
113955
  }
113920
113956
  }
113957
+ const partial2 = scopeTrackedSince !== null && ledger.partial === true;
113958
+ anyPartial ||= partial2;
113921
113959
  scopes.push({
113922
113960
  scope: ledger.scope,
113923
113961
  total: ledger.latest.total,
113924
- trackedSince: scopeTrackedSince
113962
+ trackedSince: scopeTrackedSince,
113963
+ partial: partial2
113925
113964
  });
113926
113965
  }
113927
113966
  scopes.sort((a10, b10) => a10.scope.localeCompare(b10.scope));
113928
- return { timezone, total, days: dayRows, trackedSince, scopes };
113967
+ return {
113968
+ timezone,
113969
+ total,
113970
+ days: dayRows,
113971
+ trackedSince,
113972
+ partial: anyPartial,
113973
+ scopes
113974
+ };
113929
113975
  }
113930
113976
 
113931
113977
  // ../core/dist/contracts/data.js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opendatalabs/personal-server-ts-server",
3
- "version": "1.33.0",
3
+ "version": "1.33.1",
4
4
  "description": "Hono HTTP server for the Vana Personal Server — routes, middleware, composition root",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -51,8 +51,8 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@hono/node-server": "^1.19.17",
54
- "@opendatalabs/personal-server-ts-core": "1.33.0",
55
- "@opendatalabs/personal-server-ts-lite": "1.33.0",
54
+ "@opendatalabs/personal-server-ts-core": "1.33.1",
55
+ "@opendatalabs/personal-server-ts-lite": "1.33.1",
56
56
  "@opendatalabs/vana-sdk": "3.23.0-pr.211.36da1d8",
57
57
  "better-sqlite3": "^12.11.1",
58
58
  "hono": "^4.13.12",