@pepys/ingest 0.1.0 → 0.2.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pepys/ingest",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "pepys ingest: the receive routes, the fact log and the blob store",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@impz/client": "6.12.0",
|
|
25
|
-
"@pepys/kit": "0.
|
|
26
|
-
"@pepys/schema": "0.
|
|
25
|
+
"@pepys/kit": "0.2.0",
|
|
26
|
+
"@pepys/schema": "0.2.0",
|
|
27
27
|
"@s2-dev/streamstore": "0.30.0",
|
|
28
28
|
"@zgeoff/std": "0.4.3",
|
|
29
29
|
"tiny-invariant": "1.3.3",
|
|
@@ -32,9 +32,9 @@ interface PullRunnerDependencies {
|
|
|
32
32
|
resyncMarks: ResyncMarks;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
35
|
+
// For a resync pull, removes each mark it was given that no tie set again since. A pull's fact is
|
|
36
|
+
// noted in no mark: a resynced fact ties with the body it replaces, and would mark its entity again
|
|
37
|
+
// on every run.
|
|
38
38
|
export function makePullRunner(dependencies: PullRunnerDependencies): PullRunner {
|
|
39
39
|
return async (sourceName, pathName, cursor) => {
|
|
40
40
|
const source = dependencies.deployment.sources.find(
|
|
@@ -85,7 +85,7 @@ export function makePullRunner(dependencies: PullRunnerDependencies): PullRunner
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
for (const mark of marks) {
|
|
88
|
-
dependencies.resyncMarks.remove(source.name, mark
|
|
88
|
+
dependencies.resyncMarks.remove(source.name, mark);
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
return {
|
|
@@ -8,7 +8,9 @@ import type { LastBody, StoredFactTime } from './collect-tied-entities.ts';
|
|
|
8
8
|
// it. In memory only, so a restart loses them.
|
|
9
9
|
export interface ResyncMarks {
|
|
10
10
|
list: (source: string) => readonly ResyncMark[];
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
// A mark set again while the pull ran is a new object, so it stays for the next pull.
|
|
13
|
+
remove: (source: string, mark: ResyncMark) => void;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
// What the receive route of one source tells the marks.
|
|
@@ -20,8 +22,7 @@ export interface SourceMarks {
|
|
|
20
22
|
interface SourceState {
|
|
21
23
|
lastBodies: Map<EntityID, LastBody>;
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
marks: Map<EntityID, string | undefined>;
|
|
25
|
+
marks: Map<EntityID, ResyncMark>;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export interface ResyncMarkStore {
|
|
@@ -53,10 +54,13 @@ export function createResyncMarks(options: ResyncMarksOptions): ResyncMarkStore
|
|
|
53
54
|
|
|
54
55
|
return {
|
|
55
56
|
marks: {
|
|
56
|
-
list: (source) =>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
list: (source) => [...(sources.get(source)?.marks.values() ?? [])],
|
|
58
|
+
remove: (source, mark) => {
|
|
59
|
+
const marks = sources.get(source)?.marks;
|
|
60
|
+
|
|
61
|
+
if (marks?.get(mark.entity) === mark) {
|
|
62
|
+
marks.delete(mark.entity);
|
|
63
|
+
}
|
|
60
64
|
},
|
|
61
65
|
},
|
|
62
66
|
createSourceMarks: (source) => {
|
|
@@ -82,15 +86,19 @@ export function createResyncMarks(options: ResyncMarksOptions): ResyncMarkStore
|
|
|
82
86
|
};
|
|
83
87
|
}
|
|
84
88
|
|
|
85
|
-
// The locator
|
|
89
|
+
// The locator and digest come from the last body stored for the entity, which the caller has noted
|
|
90
|
+
// first.
|
|
91
|
+
// Each call makes a new mark object, which `remove` tells apart from the one a pull was given.
|
|
86
92
|
function addMarks(
|
|
87
93
|
state: SourceState,
|
|
88
94
|
entities: readonly EntityID[],
|
|
89
95
|
options: ResyncMarksOptions,
|
|
90
96
|
): void {
|
|
91
97
|
for (const entity of entities) {
|
|
98
|
+
const last = state.lastBodies.get(entity);
|
|
99
|
+
|
|
92
100
|
state.marks.delete(entity);
|
|
93
|
-
state.marks.set(entity,
|
|
101
|
+
state.marks.set(entity, { entity, locator: last?.locator, lastBodyDigest: last?.digest });
|
|
94
102
|
}
|
|
95
103
|
|
|
96
104
|
trimToCapacity(state.marks, options.capacity);
|
|
@@ -98,7 +106,7 @@ function addMarks(
|
|
|
98
106
|
|
|
99
107
|
// drops the oldest entries first: a Map and a Set keep insertion order
|
|
100
108
|
function trimToCapacity(
|
|
101
|
-
entries: Map<EntityID, LastBody> | Map<EntityID,
|
|
109
|
+
entries: Map<EntityID, LastBody> | Map<EntityID, ResyncMark>,
|
|
102
110
|
capacity: number,
|
|
103
111
|
): void {
|
|
104
112
|
for (const key of entries.keys()) {
|