@4fu/arbor-journal-sqlite 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +187 -2
- package/blob-store.d.ts +45 -0
- package/blob-store.js +104 -0
- package/index.d.ts +12 -0
- package/index.js +9 -0
- package/package.json +52 -4
- package/schema.d.ts +33 -0
- package/schema.js +145 -0
- package/search.d.ts +49 -0
- package/search.js +89 -0
- package/segmenter.d.ts +30 -0
- package/segmenter.js +107 -0
- package/sqlite-journal.d.ts +75 -0
- package/sqlite-journal.js +660 -0
- package/stored.d.ts +14 -0
- package/stored.js +57 -0
package/stored.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading refs back out of storage.
|
|
3
|
+
*
|
|
4
|
+
* The journal stores refs as text. A ref that does not match the vocabulary in
|
|
5
|
+
* docs/journal.md#refs means the database was written by something else, so
|
|
6
|
+
* reading it fails in the core's error shape instead of handing a caller a
|
|
7
|
+
* string that is not a ref.
|
|
8
|
+
*/
|
|
9
|
+
import { arborError } from "@4fu/arbor-errors";
|
|
10
|
+
const PATTERNS = [
|
|
11
|
+
/^r\d+$/, // an event
|
|
12
|
+
/^c\d+$/, // a window
|
|
13
|
+
/^n\d+(@\d+)?$/, // a note, or one of its revisions
|
|
14
|
+
/^t\d+$/, // a task
|
|
15
|
+
/^m\d+$/, // a message between windows
|
|
16
|
+
/^ws\d+$/, // a workspace
|
|
17
|
+
/^e\d+$/, // an environment revision
|
|
18
|
+
/^(sk|mcp|svc):[^\s@]+@\d+$/, // a skill, an MCP server or a service
|
|
19
|
+
/^b\d+$/, // media stored beside the journal
|
|
20
|
+
/^[^\s:]+:[^\s]+$/, // an outside message, by its native id
|
|
21
|
+
];
|
|
22
|
+
function malformed(kind, value) {
|
|
23
|
+
throw arborError({
|
|
24
|
+
code: "internal",
|
|
25
|
+
rule: "journal.storage.ref",
|
|
26
|
+
message: `journal: stored ${kind} ${value} is not a ref`,
|
|
27
|
+
nextAction: "the journal database was written by another build; rebuild it",
|
|
28
|
+
details: { kind, value },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** Any ref. */
|
|
32
|
+
export function storedRef(value) {
|
|
33
|
+
for (const pattern of PATTERNS) {
|
|
34
|
+
if (pattern.test(value))
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
return malformed("ref", value);
|
|
38
|
+
}
|
|
39
|
+
export function storedWindowRef(value) {
|
|
40
|
+
if (value === null)
|
|
41
|
+
return null;
|
|
42
|
+
if (!/^c\d+$/.test(value))
|
|
43
|
+
return malformed("window ref", value);
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
export function storedBlobRef(value) {
|
|
47
|
+
if (!/^b\d+$/.test(value))
|
|
48
|
+
return malformed("blob ref", value);
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
export function storedExternalRef(value) {
|
|
52
|
+
if (value === null)
|
|
53
|
+
return null;
|
|
54
|
+
if (!/^[^\s:]+:[^\s]+$/.test(value))
|
|
55
|
+
return malformed("external ref", value);
|
|
56
|
+
return value;
|
|
57
|
+
}
|