@cueloop/daemon 0.1.0-alpha.50 → 0.1.0-alpha.51
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/package.json +2 -2
- package/src/retention.test.ts +15 -0
- package/src/retention.ts +23 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cueloop/daemon",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.51",
|
|
4
4
|
"description": "The cueloop session daemon and its client: socket protocol, atomic store, resumable waits",
|
|
5
5
|
"homepage": "https://github.com/mmurakaru/cueloop#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@cueloop/schema": "0.1.0-alpha.
|
|
36
|
+
"@cueloop/schema": "0.1.0-alpha.51",
|
|
37
37
|
"valibot": "^1.4.2"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
package/src/retention.test.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
DEFAULT_CLEANUP_PERIOD_DAYS,
|
|
12
12
|
LATEST_REPORT_FILENAME,
|
|
13
13
|
isExpired,
|
|
14
|
+
parseRefineState,
|
|
14
15
|
pruneExpiredReports,
|
|
15
16
|
pruneExpiredSessions,
|
|
16
17
|
resolveCleanupPeriodDays,
|
|
@@ -78,6 +79,20 @@ describe("resolveCleanupPeriodDays", () => {
|
|
|
78
79
|
});
|
|
79
80
|
});
|
|
80
81
|
|
|
82
|
+
describe("parseRefineState", () => {
|
|
83
|
+
test("reads the analyzed fingerprint map", () => {
|
|
84
|
+
// Assert
|
|
85
|
+
expect([...parseRefineState({ analyzed: { ses_a: "1:2:x" } })]).toEqual([["ses_a", "1:2:x"]]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("returns an empty map for the legacy or malformed shape", () => {
|
|
89
|
+
// Assert
|
|
90
|
+
expect(parseRefineState({ seenSessionIds: ["ses_a"] }).size).toBe(0);
|
|
91
|
+
expect(parseRefineState({ analyzed: { ses_a: 5 } }).size).toBe(0);
|
|
92
|
+
expect(parseRefineState(null).size).toBe(0);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
81
96
|
describe("isExpired", () => {
|
|
82
97
|
test("is true past the window and false inside it", () => {
|
|
83
98
|
// Assert
|
package/src/retention.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readdirSync, readFileSync, rmSync, statSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
+
import * as v from "valibot";
|
|
4
5
|
import type { SessionStore } from "./store";
|
|
5
6
|
|
|
6
7
|
export const DEFAULT_CLEANUP_PERIOD_DAYS = 30;
|
|
@@ -9,6 +10,22 @@ export const TIMESTAMPED_REPORT_PREFIX = "refine-";
|
|
|
9
10
|
|
|
10
11
|
const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000;
|
|
11
12
|
|
|
13
|
+
const CleanupConfigSchema = v.object({
|
|
14
|
+
cleanup: v.optional(v.object({ period_days: v.optional(v.number()) })),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const RefineStateSchema = v.object({
|
|
18
|
+
analyzed: v.optional(v.record(v.string(), v.string()), {}),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export type RefineState = v.InferOutput<typeof RefineStateSchema>;
|
|
22
|
+
|
|
23
|
+
export function parseRefineState(raw: unknown): Map<string, string> {
|
|
24
|
+
const parsed = v.safeParse(RefineStateSchema, raw);
|
|
25
|
+
if (!parsed.success) return new Map();
|
|
26
|
+
return new Map(Object.entries(parsed.output.analyzed));
|
|
27
|
+
}
|
|
28
|
+
|
|
12
29
|
function userConfigPath(env: NodeJS.ProcessEnv): string {
|
|
13
30
|
const explicit = env.CUELOOP_CONFIG;
|
|
14
31
|
if (explicit && explicit.trim()) return explicit;
|
|
@@ -18,15 +35,16 @@ function userConfigPath(env: NodeJS.ProcessEnv): string {
|
|
|
18
35
|
}
|
|
19
36
|
|
|
20
37
|
function readConfiguredPeriodDays(path: string): number | undefined {
|
|
21
|
-
let raw:
|
|
38
|
+
let raw: unknown;
|
|
22
39
|
try {
|
|
23
|
-
raw = Bun.TOML.parse(readFileSync(path, "utf8"))
|
|
40
|
+
raw = Bun.TOML.parse(readFileSync(path, "utf8"));
|
|
24
41
|
} catch {
|
|
25
42
|
return undefined;
|
|
26
43
|
}
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
44
|
+
const parsed = v.safeParse(CleanupConfigSchema, raw);
|
|
45
|
+
if (!parsed.success) return undefined;
|
|
46
|
+
const value = parsed.output.cleanup?.period_days;
|
|
47
|
+
return value !== undefined && Number.isFinite(value) && value >= 0 ? value : undefined;
|
|
30
48
|
}
|
|
31
49
|
|
|
32
50
|
export function resolveCleanupPeriodDays(env: NodeJS.ProcessEnv = process.env): number {
|