@lmzhen/dsh-evolution-state-domain 0.3.67 → 0.3.69

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/lib/index.js +11 -12
  2. package/package.json +3 -3
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { DomainError, defineDomain, domainTable } from "@deepseek-ai/dsh-storage-domain";
3
- import { CURATOR_STATE_KEY, CURATOR_STATE_TABLE, PENDING_RESOLVED_CAP, PENDING_TABLE, PROVIDER_DOMAIN, REVIEW_STATE_SESSION_CAP, REVIEW_STATE_TABLE, assertCloneable, canClaimPending, canResolvePending, cloneRecord, recordIssue, releasedStatus } from "@lmzhen/dsh-evolution-state-storage";
3
+ import { CURATOR_STATE_KEY, CURATOR_STATE_TABLE, PENDING_RESOLVED_CAP, PENDING_TABLE, PROVIDER_DOMAIN, REVIEW_STATE_SESSION_CAP, REVIEW_STATE_TABLE, assertCloneable, canClaimPending, canResolvePending, cloneRecord, recordIssue, releasedStatus, selectPendingOverflow, selectSessionOverflow } from "@lmzhen/dsh-evolution-state-storage";
4
4
  //#region lib/types/index.js
5
5
  /**
6
6
  * storage-domain provider for evolution state.
@@ -135,8 +135,12 @@ function apply(ctx) {
135
135
  const entries = [...table.entries()].map(([key, row]) => ({
136
136
  key,
137
137
  updatedAt: row.updatedAt ?? 0
138
- })).filter((entry) => entry.key !== sessionId).sort((a, b) => a.updatedAt - b.updatedAt);
139
- for (const entry of entries.slice(0, Math.max(0, entries.length - REVIEW_STATE_SESSION_CAP + 1))) {
138
+ })).filter((entry) => entry.key !== sessionId);
139
+ const victims = new Set(selectSessionOverflow(entries, {
140
+ keyOf: (entry) => entry.key,
141
+ stampOf: (entry) => entry.updatedAt
142
+ }, REVIEW_STATE_SESSION_CAP));
143
+ for (const entry of entries.filter((candidate) => victims.has(candidate.key))) {
140
144
  const current = table.get(entry.key);
141
145
  if (current === void 0 || (current.updatedAt ?? 0) !== entry.updatedAt) continue;
142
146
  await table.delete(entry.key).catch((error) => {
@@ -158,7 +162,7 @@ function apply(ctx) {
158
162
  async transactCuratorState(task) {
159
163
  const table = (await ensure()).table(CURATOR_STATE_TABLE);
160
164
  const guarded = (current) => {
161
- const next = task(current);
165
+ const next = task(current === null ? null : cloneRecord(current));
162
166
  if (next === null) return null;
163
167
  const issue = recordIssue(CURATOR_STATE_TABLE, next) ?? assertCloneable(next);
164
168
  if (issue !== null) throw new Error(`evolution-state-domain: refusing to persist an invalid curator-state record: ${issue}`);
@@ -248,16 +252,11 @@ function apply(ctx) {
248
252
  return resolved.record;
249
253
  });
250
254
  if (resolved.record !== null) {
251
- const resolvedEntries = [...table.entries()].map(([key, record]) => ({
255
+ const evictedRecords = new Set(selectPendingOverflow([...table.entries()].map(([, record]) => record), PENDING_RESOLVED_CAP));
256
+ const evicted = [...table.entries()].filter(([, record]) => evictedRecords.has(record)).map(([key, record]) => ({
252
257
  key,
253
258
  record
254
- })).filter((entry) => (entry.record.status === "approved" || entry.record.status === "rejected") && entry.record.kind !== "capability");
255
- const resolvedAtMs = (record) => {
256
- const parsed = Date.parse(record.resolvedAt ?? "");
257
- return Number.isNaN(parsed) ? Number.MAX_SAFE_INTEGER : parsed;
258
- };
259
- resolvedEntries.sort((a, b) => resolvedAtMs(a.record) - resolvedAtMs(b.record));
260
- const evicted = resolvedEntries.slice(0, Math.max(0, resolvedEntries.length - PENDING_RESOLVED_CAP));
259
+ }));
261
260
  for (const entry of evicted) {
262
261
  const current = table.get(entry.key);
263
262
  if (!(current !== void 0 && (current.status === "approved" || current.status === "rejected") && current.resolvedAt === entry.record.resolvedAt)) continue;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lmzhen/dsh-evolution-state-domain",
3
3
  "description": "storage-domain provider for evolution state (community build)",
4
- "version": "0.3.67",
4
+ "version": "0.3.69",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -36,13 +36,13 @@
36
36
  "@deepseek-ai/dsh-invariants": "^0.1.1-rc.2",
37
37
  "@deepseek-ai/cordis": "^4.0.1",
38
38
  "@deepseek-ai/dsh-storage-domain": "^0.1.1-rc.2",
39
- "@lmzhen/dsh-evolution-state-storage": "^0.3.67"
39
+ "@lmzhen/dsh-evolution-state-storage": "^0.3.69"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@deepseek-ai/dsh-invariants": "^0.1.1-rc.2",
43
43
  "@deepseek-ai/dsh-storage-domain": "^0.1.1-rc.2",
44
44
  "@deepseek-ai/dsh-storage": "^0.1.1-rc.2",
45
45
  "@deepseek-ai/dsh-storage-json": "^0.1.1-rc.2",
46
- "@lmzhen/dsh-evolution-state-storage": "^0.3.67"
46
+ "@lmzhen/dsh-evolution-state-storage": "^0.3.69"
47
47
  }
48
48
  }