edge-book 0.12.1 → 0.12.2

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.
Files changed (2) hide show
  1. package/dist/edge-book.js +35 -21
  2. package/package.json +1 -1
package/dist/edge-book.js CHANGED
@@ -477,7 +477,10 @@ async function createEndorsement(store, input) {
477
477
  }
478
478
  async function signals(store) {
479
479
  const raw = await readJson(store.file(SIGNALS_FILE), {});
480
- for (const id of Object.keys(raw)) raw[id].lifecycle = signalLifecycle(store, raw[id]);
480
+ for (const id of Object.keys(raw)) {
481
+ const sig = raw[id];
482
+ sig.lifecycle = signalLifecycle(store, sig);
483
+ }
481
484
  return raw;
482
485
  }
483
486
  async function createSignal(store, input) {
@@ -505,8 +508,9 @@ async function expireSignals(store) {
505
508
  const all = await readJson(store.file(SIGNALS_FILE), {});
506
509
  let changed = false;
507
510
  for (const id of Object.keys(all)) {
508
- if (all[id].lifecycle !== "expired" && Date.parse(all[id].expires_at) <= Date.now()) {
509
- all[id].lifecycle = "expired";
511
+ const sig = all[id];
512
+ if (sig.lifecycle !== "expired" && Date.parse(sig.expires_at) <= Date.now()) {
513
+ sig.lifecycle = "expired";
510
514
  changed = true;
511
515
  }
512
516
  }
@@ -521,7 +525,8 @@ async function saveEphemeral(store, posts2) {
521
525
  async function ephemeralPosts(store) {
522
526
  const raw = await readJson(store.file(EPHEMERAL_FILE), {});
523
527
  for (const id of Object.keys(raw)) {
524
- raw[id].lifecycle = computeLifecycle(raw[id].expires_at, EPHEMERAL_TTL_POLICY[raw[id].post_type].hard, raw[id].lifecycle);
528
+ const post = raw[id];
529
+ post.lifecycle = computeLifecycle(post.expires_at, EPHEMERAL_TTL_POLICY[post.post_type].hard, post.lifecycle);
525
530
  }
526
531
  return raw;
527
532
  }
@@ -553,9 +558,10 @@ async function expireEphemeral(store) {
553
558
  const all = await readJson(store.file(EPHEMERAL_FILE), {});
554
559
  let changed = false;
555
560
  for (const id of Object.keys(all)) {
556
- const next = computeLifecycle(all[id].expires_at, EPHEMERAL_TTL_POLICY[all[id].post_type].hard, all[id].lifecycle);
557
- if (next !== all[id].lifecycle) {
558
- all[id].lifecycle = next;
561
+ const post = all[id];
562
+ const next = computeLifecycle(post.expires_at, EPHEMERAL_TTL_POLICY[post.post_type].hard, post.lifecycle);
563
+ if (next !== post.lifecycle) {
564
+ post.lifecycle = next;
559
565
  changed = true;
560
566
  }
561
567
  }
@@ -609,8 +615,9 @@ async function deleteQuery(store, queryId) {
609
615
  const ans = await store.answers();
610
616
  let changed = false;
611
617
  for (const id of Object.keys(ans)) {
612
- if (ans[id].parent.uri === parentUri && ans[id].lifecycle !== "tombstoned") {
613
- ans[id].lifecycle = "tombstoned";
618
+ const answer = ans[id];
619
+ if (answer.parent.uri === parentUri && answer.lifecycle !== "tombstoned") {
620
+ answer.lifecycle = "tombstoned";
614
621
  changed = true;
615
622
  }
616
623
  }
@@ -2088,8 +2095,9 @@ var EdgeBookStore = class {
2088
2095
  const cutoff = Date.now() - windowMs;
2089
2096
  const all = await readJson(this.file(INBOUND_RATE_FILE), {});
2090
2097
  for (const k of Object.keys(all)) {
2091
- all[k] = all[k].filter((t) => t > cutoff);
2092
- if (!all[k].length) delete all[k];
2098
+ const kept = all[k].filter((t) => t > cutoff);
2099
+ all[k] = kept;
2100
+ if (!kept.length) delete all[k];
2093
2101
  }
2094
2102
  const peerCount = (all[peerAgentId] ?? []).length;
2095
2103
  const globalCount = Object.values(all).reduce((n, arr) => n + arr.length, 0);
@@ -2360,29 +2368,35 @@ var EdgeBookStore = class {
2360
2368
  const identity = await this.identity();
2361
2369
  const caps = await this.capabilities();
2362
2370
  for (const id of Object.keys(caps)) {
2363
- if (caps[id].status === "active") {
2364
- caps[id].status = "deprecated";
2365
- caps[id].updated_at = now();
2366
- const { signature: _sig, ...rest } = caps[id];
2367
- caps[id].signature = signPayload(rest, identity.private_key_pem);
2371
+ const cap = caps[id];
2372
+ if (cap.status === "active") {
2373
+ cap.status = "deprecated";
2374
+ cap.updated_at = now();
2375
+ const { signature: _sig, ...rest } = cap;
2376
+ cap.signature = signPayload(rest, identity.private_key_pem);
2368
2377
  }
2369
2378
  }
2370
2379
  await this.saveCapabilities(caps);
2371
2380
  const sigs = await readJson(this.file(SIGNALS_FILE), {});
2372
2381
  for (const id of Object.keys(sigs)) {
2373
- if (sigs[id].lifecycle !== "expired") sigs[id].lifecycle = "expired";
2382
+ const sig = sigs[id];
2383
+ if (sig.lifecycle !== "expired") sig.lifecycle = "expired";
2374
2384
  }
2375
2385
  await this.saveSignals(sigs);
2376
2386
  const eph = await readJson(this.file(EPHEMERAL_FILE), {});
2377
2387
  for (const id of Object.keys(eph)) {
2378
- const lc = eph[id].lifecycle;
2388
+ const post = eph[id];
2389
+ const lc = post.lifecycle;
2379
2390
  if (lc === "expired" || lc === "cancelled" || lc === "tombstoned") continue;
2380
- const t = eph[id].post_type;
2381
- eph[id].lifecycle = t === "query" || t === "delegation_request" ? "cancelled" : "expired";
2391
+ const t = post.post_type;
2392
+ post.lifecycle = t === "query" || t === "delegation_request" ? "cancelled" : "expired";
2382
2393
  }
2383
2394
  await this.saveEphemeral(eph);
2384
2395
  const ans = await readJson(this.file(ANSWERS_FILE), {});
2385
- for (const id of Object.keys(ans)) if (ans[id].lifecycle !== "tombstoned") ans[id].lifecycle = "tombstoned";
2396
+ for (const id of Object.keys(ans)) {
2397
+ const answer = ans[id];
2398
+ if (answer.lifecycle !== "tombstoned") answer.lifecycle = "tombstoned";
2399
+ }
2386
2400
  await this.saveAnswers(ans);
2387
2401
  await this.audit("agent.deregister", (await this.identity()).agent_id, {});
2388
2402
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-book",
3
- "version": "0.12.1",
3
+ "version": "0.12.2",
4
4
  "description": "Run your own Edge Book agent and connect it to the hosted reader.",
5
5
  "license": "MIT",
6
6
  "type": "module",