@sourcepress/cache 0.1.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/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-test.log +14 -0
- package/LICENSE +21 -0
- package/dist/__tests__/memory.test.d.ts +2 -0
- package/dist/__tests__/memory.test.d.ts.map +1 -0
- package/dist/__tests__/memory.test.js +72 -0
- package/dist/__tests__/memory.test.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/interface.d.ts +53 -0
- package/dist/interface.d.ts.map +1 -0
- package/dist/interface.js +2 -0
- package/dist/interface.js.map +1 -0
- package/dist/memory.d.ts +24 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +63 -0
- package/dist/memory.js.map +1 -0
- package/package.json +27 -0
- package/src/__tests__/memory.test.ts +82 -0
- package/src/index.ts +9 -0
- package/src/interface.ts +59 -0
- package/src/memory.ts +75 -0
- package/tsconfig.json +5 -0
- package/vitest.config.ts +2 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
> @sourcepress/cache@0.1.0 test /Users/fabianvontiedemann/Developer/org/sourcepress/packages/cache
|
|
3
|
+
> vitest run
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
RUN v3.2.4 /Users/fabianvontiedemann/Developer/org/sourcepress/packages/cache
|
|
7
|
+
|
|
8
|
+
✓ src/__tests__/memory.test.ts (7 tests) 2ms
|
|
9
|
+
|
|
10
|
+
Test Files 1 passed (1)
|
|
11
|
+
Tests 7 passed (7)
|
|
12
|
+
Start at 00:19:47
|
|
13
|
+
Duration 1.51s (transform 28ms, setup 0ms, collect 84ms, tests 2ms, environment 0ms, prepare 206ms)
|
|
14
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SourcePress Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/memory.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
import { MemoryCache } from "../memory.js";
|
|
3
|
+
describe("MemoryCache", () => {
|
|
4
|
+
let cache;
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
cache = new MemoryCache();
|
|
7
|
+
});
|
|
8
|
+
describe("content files", () => {
|
|
9
|
+
const content = {
|
|
10
|
+
path: "content/posts/hello.mdx",
|
|
11
|
+
sha: "abc123",
|
|
12
|
+
frontmatter: { title: "Hello" },
|
|
13
|
+
body: "World",
|
|
14
|
+
last_synced_at: "2026-04-04",
|
|
15
|
+
};
|
|
16
|
+
it("stores and retrieves content", async () => {
|
|
17
|
+
await cache.setContentFile(content.path, content);
|
|
18
|
+
const result = await cache.getContentFile(content.path);
|
|
19
|
+
expect(result).toEqual(content);
|
|
20
|
+
});
|
|
21
|
+
it("returns null for missing content", async () => {
|
|
22
|
+
const result = await cache.getContentFile("nope");
|
|
23
|
+
expect(result).toBeNull();
|
|
24
|
+
});
|
|
25
|
+
it("lists content with prefix filter", async () => {
|
|
26
|
+
await cache.setContentFile("content/posts/a.mdx", {
|
|
27
|
+
...content,
|
|
28
|
+
path: "content/posts/a.mdx",
|
|
29
|
+
});
|
|
30
|
+
await cache.setContentFile("content/cases/b.mdx", {
|
|
31
|
+
...content,
|
|
32
|
+
path: "content/cases/b.mdx",
|
|
33
|
+
});
|
|
34
|
+
const posts = await cache.listContentFiles("content/posts/");
|
|
35
|
+
expect(posts).toHaveLength(1);
|
|
36
|
+
expect(posts[0].path).toBe("content/posts/a.mdx");
|
|
37
|
+
});
|
|
38
|
+
it("deletes content", async () => {
|
|
39
|
+
await cache.setContentFile(content.path, content);
|
|
40
|
+
await cache.deleteContentFile(content.path);
|
|
41
|
+
const result = await cache.getContentFile(content.path);
|
|
42
|
+
expect(result).toBeNull();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe("sync state", () => {
|
|
46
|
+
it("stores and retrieves sync state", async () => {
|
|
47
|
+
await cache.setSyncState({ last_commit_sha: "abc", last_synced_at: "2026-04-04" });
|
|
48
|
+
const state = await cache.getSyncState();
|
|
49
|
+
expect(state?.last_commit_sha).toBe("abc");
|
|
50
|
+
});
|
|
51
|
+
it("returns null when no sync state", async () => {
|
|
52
|
+
const state = await cache.getSyncState();
|
|
53
|
+
expect(state).toBeNull();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
describe("clear", () => {
|
|
57
|
+
it("removes all data", async () => {
|
|
58
|
+
await cache.setContentFile("a", {
|
|
59
|
+
path: "a",
|
|
60
|
+
sha: "1",
|
|
61
|
+
frontmatter: {},
|
|
62
|
+
body: "",
|
|
63
|
+
last_synced_at: "",
|
|
64
|
+
});
|
|
65
|
+
await cache.setSyncState({ last_commit_sha: "x", last_synced_at: "" });
|
|
66
|
+
await cache.clear();
|
|
67
|
+
expect(await cache.getContentFile("a")).toBeNull();
|
|
68
|
+
expect(await cache.getSyncState()).toBeNull();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
//# sourceMappingURL=memory.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.test.js","sourceRoot":"","sources":["../../src/__tests__/memory.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC5B,IAAI,KAAkB,CAAC;IAEvB,UAAU,CAAC,GAAG,EAAE;QACf,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC9B,MAAM,OAAO,GAAkB;YAC9B,IAAI,EAAE,yBAAyB;YAC/B,GAAG,EAAE,QAAQ;YACb,WAAW,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE;YAC/B,IAAI,EAAE,OAAO;YACb,cAAc,EAAE,YAAY;SAC5B,CAAC;QAEF,EAAE,CAAC,8BAA8B,EAAE,KAAK,IAAI,EAAE;YAC7C,MAAM,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAClD,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,cAAc,CAAC,O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AC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,aAAa,EACb,aAAa,EACb,eAAe,EACf,UAAU,EACV,SAAS,EACT,gBAAgB,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export interface CacheProvider {
|
|
2
|
+
getContentFile(path: string): Promise<CachedContent | null>;
|
|
3
|
+
setContentFile(path: string, data: CachedContent): Promise<void>;
|
|
4
|
+
listContentFiles(prefix?: string): Promise<CachedContent[]>;
|
|
5
|
+
deleteContentFile(path: string): Promise<void>;
|
|
6
|
+
getKnowledgeFile(path: string): Promise<CachedKnowledge | null>;
|
|
7
|
+
setKnowledgeFile(path: string, data: CachedKnowledge): Promise<void>;
|
|
8
|
+
listKnowledgeFiles(prefix?: string): Promise<CachedKnowledge[]>;
|
|
9
|
+
deleteKnowledgeFile(path: string): Promise<void>;
|
|
10
|
+
getGraphEdges(): Promise<CachedEdge[]>;
|
|
11
|
+
setGraphEdges(edges: CachedEdge[]): Promise<void>;
|
|
12
|
+
getSyncState(): Promise<SyncState | null>;
|
|
13
|
+
setSyncState(state: SyncState): Promise<void>;
|
|
14
|
+
getEvalResults(): Promise<CachedEvalResult[]>;
|
|
15
|
+
addEvalResult(result: CachedEvalResult): Promise<void>;
|
|
16
|
+
clear(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export interface CachedContent {
|
|
19
|
+
path: string;
|
|
20
|
+
sha: string;
|
|
21
|
+
frontmatter: Record<string, unknown>;
|
|
22
|
+
body: string;
|
|
23
|
+
last_synced_at: string;
|
|
24
|
+
}
|
|
25
|
+
export interface CachedKnowledge {
|
|
26
|
+
path: string;
|
|
27
|
+
sha: string;
|
|
28
|
+
entities: Array<{
|
|
29
|
+
type: string;
|
|
30
|
+
name: string;
|
|
31
|
+
}>;
|
|
32
|
+
quality: string;
|
|
33
|
+
quality_score: number;
|
|
34
|
+
last_synced_at: string;
|
|
35
|
+
}
|
|
36
|
+
export interface CachedEdge {
|
|
37
|
+
source: string;
|
|
38
|
+
target: string;
|
|
39
|
+
relation_type: string;
|
|
40
|
+
}
|
|
41
|
+
export interface SyncState {
|
|
42
|
+
last_commit_sha: string;
|
|
43
|
+
last_synced_at: string;
|
|
44
|
+
}
|
|
45
|
+
export interface CachedEvalResult {
|
|
46
|
+
content_type: string;
|
|
47
|
+
prompt_version: string;
|
|
48
|
+
score: number;
|
|
49
|
+
status: "keep" | "discard";
|
|
50
|
+
date: string;
|
|
51
|
+
reasoning?: string;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC7B,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC;IAC5D,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAC5D,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/C,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,e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AC;CACvB;AAED,MAAM,WAAW,UAAU;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,SAAS;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":""}
|
package/dist/memory.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CacheProvider, CachedContent, CachedEdge, CachedEvalResult, CachedKnowledge, SyncState } from "./interface.js";
|
|
2
|
+
export declare class MemoryCache implements CacheProvider {
|
|
3
|
+
private content;
|
|
4
|
+
private knowledge;
|
|
5
|
+
private edges;
|
|
6
|
+
private syncState;
|
|
7
|
+
private evalResults;
|
|
8
|
+
getContentFile(path: string): Promise<CachedContent | null>;
|
|
9
|
+
setContentFile(path: string, data: CachedContent): Promise<void>;
|
|
10
|
+
listContentFiles(prefix?: string): Promise<CachedContent[]>;
|
|
11
|
+
deleteContentFile(path: string): Promise<void>;
|
|
12
|
+
getKnowledgeFile(path: string): Promise<CachedKnowledge | null>;
|
|
13
|
+
setKnowledgeFile(path: string, data: CachedKnowledge): Promise<void>;
|
|
14
|
+
listKnowledgeFiles(prefix?: string): Promise<CachedKnowledge[]>;
|
|
15
|
+
deleteKnowledgeFile(path: string): Promise<void>;
|
|
16
|
+
getGraphEdges(): Promise<CachedEdge[]>;
|
|
17
|
+
setGraphEdges(edges: CachedEdge[]): Promise<void>;
|
|
18
|
+
getSyncState(): Promise<SyncState | null>;
|
|
19
|
+
setSyncState(state: SyncState): Promise<void>;
|
|
20
|
+
getEvalResults(): Promise<CachedEvalResult[]>;
|
|
21
|
+
addEvalResult(result: CachedEvalResult): Promise<void>;
|
|
22
|
+
clear(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,aAAa,EACb,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,MAAM,gBAAgB,CAAC;AAExB,qBAAa,WAAY,YAAW,aAAa;IAChD,OAAO,CAAC,OAAO,CAAoC;IACnD,OAAO,CAAC,SAAS,CAAsC;IACvD,OAAO,CAAC,KAAK,CAAoB;IACjC,OAAO,CAAC,SAAS,CAA0B;IAC3C,OAAO,CAAC,WAAW,CAA0B;IAEvC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAG3D,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAGhE,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAK3D,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAG/D,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAGpE,kBAAkB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAK/D,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhD,aAAa,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAGtC,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjD,YAAY,IAAI,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAGzC,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7C,cAAc,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAG7C,aAAa,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAO5B"}
|
package/dist/memory.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export class MemoryCache {
|
|
2
|
+
content = new Map();
|
|
3
|
+
knowledge = new Map();
|
|
4
|
+
edges = [];
|
|
5
|
+
syncState = null;
|
|
6
|
+
evalResults = [];
|
|
7
|
+
async getContentFile(path) {
|
|
8
|
+
return this.content.get(path) ?? null;
|
|
9
|
+
}
|
|
10
|
+
async setContentFile(path, data) {
|
|
11
|
+
this.content.set(path, data);
|
|
12
|
+
}
|
|
13
|
+
async listContentFiles(prefix) {
|
|
14
|
+
const all = Array.from(this.content.values());
|
|
15
|
+
if (!prefix)
|
|
16
|
+
return all;
|
|
17
|
+
return all.filter((c) => c.path.startsWith(prefix));
|
|
18
|
+
}
|
|
19
|
+
async deleteContentFile(path) {
|
|
20
|
+
this.content.delete(path);
|
|
21
|
+
}
|
|
22
|
+
async getKnowledgeFile(path) {
|
|
23
|
+
return this.knowledge.get(path) ?? null;
|
|
24
|
+
}
|
|
25
|
+
async setKnowledgeFile(path, data) {
|
|
26
|
+
this.knowledge.set(path, data);
|
|
27
|
+
}
|
|
28
|
+
async listKnowledgeFiles(prefix) {
|
|
29
|
+
const all = Array.from(this.knowledge.values());
|
|
30
|
+
if (!prefix)
|
|
31
|
+
return all;
|
|
32
|
+
return all.filter((k) => k.path.startsWith(prefix));
|
|
33
|
+
}
|
|
34
|
+
async deleteKnowledgeFile(path) {
|
|
35
|
+
this.knowledge.delete(path);
|
|
36
|
+
}
|
|
37
|
+
async getGraphEdges() {
|
|
38
|
+
return [...this.edges];
|
|
39
|
+
}
|
|
40
|
+
async setGraphEdges(edges) {
|
|
41
|
+
this.edges = [...edges];
|
|
42
|
+
}
|
|
43
|
+
async getSyncState() {
|
|
44
|
+
return this.syncState;
|
|
45
|
+
}
|
|
46
|
+
async setSyncState(state) {
|
|
47
|
+
this.syncState = { ...state };
|
|
48
|
+
}
|
|
49
|
+
async getEvalResults() {
|
|
50
|
+
return [...this.evalResults];
|
|
51
|
+
}
|
|
52
|
+
async addEvalResult(result) {
|
|
53
|
+
this.evalResults.push({ ...result });
|
|
54
|
+
}
|
|
55
|
+
async clear() {
|
|
56
|
+
this.content.clear();
|
|
57
|
+
this.knowledge.clear();
|
|
58
|
+
this.edges = [];
|
|
59
|
+
this.syncState = null;
|
|
60
|
+
this.evalResults = [];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AASA,MAAM,OAAO,WAAW;IACf,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;IAC3C,SAAS,GAAG,IAAI,GAAG,EAA2B,CAAC;IAC/C,KAAK,GAAiB,EAAE,CAAC;IACzB,SAAS,GAAqB,IAAI,CAAC;IACnC,WAAW,GAAuB,EAAE,CAAC;IAE7C,KAAK,CAAC,cAAc,CAAC,IAAY;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;IACvC,CAAC;IACD,KAAK,CAAC,cAAc,CAAC,IAAY,EAA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AAC,aAAa;QAClB,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IACD,KAAK,CAAC,aAAa,CAAC,KAAmB;QACtC,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,YAAY;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IACD,KAAK,CAAC,YAAY,CAAC,KAAgB;QAClC,IAAI,CAAC,SAAS,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,cAAc;QACnB,OAAO,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IAC9B,CAAC;IACD,KAAK,CAAC,aAAa,CAAC,MAAwB;QAC3C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,KAAK;QACV,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;IACvB,CAAC;CACD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sourcepress/cache",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@sourcepress/core": "0.1.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5.7.0",
|
|
19
|
+
"vitest": "^3.0.0"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"typecheck": "tsc --noEmit",
|
|
25
|
+
"clean": "rm -rf dist"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
import type { CachedContent } from "../interface.js";
|
|
3
|
+
import { MemoryCache } from "../memory.js";
|
|
4
|
+
|
|
5
|
+
describe("MemoryCache", () => {
|
|
6
|
+
let cache: MemoryCache;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
cache = new MemoryCache();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe("content files", () => {
|
|
13
|
+
const content: CachedContent = {
|
|
14
|
+
path: "content/posts/hello.mdx",
|
|
15
|
+
sha: "abc123",
|
|
16
|
+
frontmatter: { title: "Hello" },
|
|
17
|
+
body: "World",
|
|
18
|
+
last_synced_at: "2026-04-04",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
it("stores and retrieves content", async () => {
|
|
22
|
+
await cache.setContentFile(content.path, content);
|
|
23
|
+
const result = await cache.getContentFile(content.path);
|
|
24
|
+
expect(result).toEqual(content);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("returns null for missing content", async () => {
|
|
28
|
+
const result = await cache.getContentFile("nope");
|
|
29
|
+
expect(result).toBeNull();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("lists content with prefix filter", async () => {
|
|
33
|
+
await cache.setContentFile("content/posts/a.mdx", {
|
|
34
|
+
...content,
|
|
35
|
+
path: "content/posts/a.mdx",
|
|
36
|
+
});
|
|
37
|
+
await cache.setContentFile("content/cases/b.mdx", {
|
|
38
|
+
...content,
|
|
39
|
+
path: "content/cases/b.mdx",
|
|
40
|
+
});
|
|
41
|
+
const posts = await cache.listContentFiles("content/posts/");
|
|
42
|
+
expect(posts).toHaveLength(1);
|
|
43
|
+
expect(posts[0].path).toBe("content/posts/a.mdx");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("deletes content", async () => {
|
|
47
|
+
await cache.setContentFile(content.path, content);
|
|
48
|
+
await cache.deleteContentFile(content.path);
|
|
49
|
+
const result = await cache.getContentFile(content.path);
|
|
50
|
+
expect(result).toBeNull();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("sync state", () => {
|
|
55
|
+
it("stores and retrieves sync state", async () => {
|
|
56
|
+
await cache.setSyncState({ last_commit_sha: "abc", last_synced_at: "2026-04-04" });
|
|
57
|
+
const state = await cache.getSyncState();
|
|
58
|
+
expect(state?.last_commit_sha).toBe("abc");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("returns null when no sync state", async () => {
|
|
62
|
+
const state = await cache.getSyncState();
|
|
63
|
+
expect(state).toBeNull();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe("clear", () => {
|
|
68
|
+
it("removes all data", async () => {
|
|
69
|
+
await cache.setContentFile("a", {
|
|
70
|
+
path: "a",
|
|
71
|
+
sha: "1",
|
|
72
|
+
frontmatter: {},
|
|
73
|
+
body: "",
|
|
74
|
+
last_synced_at: "",
|
|
75
|
+
});
|
|
76
|
+
await cache.setSyncState({ last_commit_sha: "x", last_synced_at: "" });
|
|
77
|
+
await cache.clear();
|
|
78
|
+
expect(await cache.getContentFile("a")).toBeNull();
|
|
79
|
+
expect(await cache.getSyncState()).toBeNull();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
package/src/index.ts
ADDED
package/src/interface.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export interface CacheProvider {
|
|
2
|
+
getContentFile(path: string): Promise<CachedContent | null>;
|
|
3
|
+
setContentFile(path: string, data: CachedContent): Promise<void>;
|
|
4
|
+
listContentFiles(prefix?: string): Promise<CachedContent[]>;
|
|
5
|
+
deleteContentFile(path: string): Promise<void>;
|
|
6
|
+
|
|
7
|
+
getKnowledgeFile(path: string): Promise<CachedKnowledge | null>;
|
|
8
|
+
setKnowledgeFile(path: string, data: CachedKnowledge): Promise<void>;
|
|
9
|
+
listKnowledgeFiles(prefix?: string): Promise<CachedKnowledge[]>;
|
|
10
|
+
deleteKnowledgeFile(path: string): Promise<void>;
|
|
11
|
+
|
|
12
|
+
getGraphEdges(): Promise<CachedEdge[]>;
|
|
13
|
+
setGraphEdges(edges: CachedEdge[]): Promise<void>;
|
|
14
|
+
|
|
15
|
+
getSyncState(): Promise<SyncState | null>;
|
|
16
|
+
setSyncState(state: SyncState): Promise<void>;
|
|
17
|
+
|
|
18
|
+
getEvalResults(): Promise<CachedEvalResult[]>;
|
|
19
|
+
addEvalResult(result: CachedEvalResult): Promise<void>;
|
|
20
|
+
|
|
21
|
+
clear(): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface CachedContent {
|
|
25
|
+
path: string;
|
|
26
|
+
sha: string;
|
|
27
|
+
frontmatter: Record<string, unknown>;
|
|
28
|
+
body: string;
|
|
29
|
+
last_synced_at: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface CachedKnowledge {
|
|
33
|
+
path: string;
|
|
34
|
+
sha: string;
|
|
35
|
+
entities: Array<{ type: string; name: string }>;
|
|
36
|
+
quality: string;
|
|
37
|
+
quality_score: number;
|
|
38
|
+
last_synced_at: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface CachedEdge {
|
|
42
|
+
source: string;
|
|
43
|
+
target: string;
|
|
44
|
+
relation_type: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface SyncState {
|
|
48
|
+
last_commit_sha: string;
|
|
49
|
+
last_synced_at: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface CachedEvalResult {
|
|
53
|
+
content_type: string;
|
|
54
|
+
prompt_version: string;
|
|
55
|
+
score: number;
|
|
56
|
+
status: "keep" | "discard";
|
|
57
|
+
date: string;
|
|
58
|
+
reasoning?: string;
|
|
59
|
+
}
|
package/src/memory.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CacheProvider,
|
|
3
|
+
CachedContent,
|
|
4
|
+
CachedEdge,
|
|
5
|
+
CachedEvalResult,
|
|
6
|
+
CachedKnowledge,
|
|
7
|
+
SyncState,
|
|
8
|
+
} from "./interface.js";
|
|
9
|
+
|
|
10
|
+
export class MemoryCache implements CacheProvider {
|
|
11
|
+
private content = new Map<string, CachedContent>();
|
|
12
|
+
private knowledge = new Map<string, CachedKnowledge>();
|
|
13
|
+
private edges: CachedEdge[] = [];
|
|
14
|
+
private syncState: SyncState | null = null;
|
|
15
|
+
private evalResults: CachedEvalResult[] = [];
|
|
16
|
+
|
|
17
|
+
async getContentFile(path: string): Promise<CachedContent | null> {
|
|
18
|
+
return this.content.get(path) ?? null;
|
|
19
|
+
}
|
|
20
|
+
async setContentFile(path: string, data: CachedContent): Promise<void> {
|
|
21
|
+
this.content.set(path, data);
|
|
22
|
+
}
|
|
23
|
+
async listContentFiles(prefix?: string): Promise<CachedContent[]> {
|
|
24
|
+
const all = Array.from(this.content.values());
|
|
25
|
+
if (!prefix) return all;
|
|
26
|
+
return all.filter((c) => c.path.startsWith(prefix));
|
|
27
|
+
}
|
|
28
|
+
async deleteContentFile(path: string): Promise<void> {
|
|
29
|
+
this.content.delete(path);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async getKnowledgeFile(path: string): Promise<CachedKnowledge | null> {
|
|
33
|
+
return this.knowledge.get(path) ?? null;
|
|
34
|
+
}
|
|
35
|
+
async setKnowledgeFile(path: string, data: CachedKnowledge): Promise<void> {
|
|
36
|
+
this.knowledge.set(path, data);
|
|
37
|
+
}
|
|
38
|
+
async listKnowledgeFiles(prefix?: string): Promise<CachedKnowledge[]> {
|
|
39
|
+
const all = Array.from(this.knowledge.values());
|
|
40
|
+
if (!prefix) return all;
|
|
41
|
+
return all.filter((k) => k.path.startsWith(prefix));
|
|
42
|
+
}
|
|
43
|
+
async deleteKnowledgeFile(path: string): Promise<void> {
|
|
44
|
+
this.knowledge.delete(path);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async getGraphEdges(): Promise<CachedEdge[]> {
|
|
48
|
+
return [...this.edges];
|
|
49
|
+
}
|
|
50
|
+
async setGraphEdges(edges: CachedEdge[]): Promise<void> {
|
|
51
|
+
this.edges = [...edges];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async getSyncState(): Promise<SyncState | null> {
|
|
55
|
+
return this.syncState;
|
|
56
|
+
}
|
|
57
|
+
async setSyncState(state: SyncState): Promise<void> {
|
|
58
|
+
this.syncState = { ...state };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async getEvalResults(): Promise<CachedEvalResult[]> {
|
|
62
|
+
return [...this.evalResults];
|
|
63
|
+
}
|
|
64
|
+
async addEvalResult(result: CachedEvalResult): Promise<void> {
|
|
65
|
+
this.evalResults.push({ ...result });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async clear(): Promise<void> {
|
|
69
|
+
this.content.clear();
|
|
70
|
+
this.knowledge.clear();
|
|
71
|
+
this.edges = [];
|
|
72
|
+
this.syncState = null;
|
|
73
|
+
this.evalResults = [];
|
|
74
|
+
}
|
|
75
|
+
}
|
package/tsconfig.json
ADDED
package/vitest.config.ts
ADDED