@agentshouse/mdruntime 0.1.0-c5d81e5d5cb58 → 0.1.0-c5fe3b2cddda7
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/dist/adapter.d.ts +15 -28
- package/dist/adapter.d.ts.map +1 -1
- package/dist/bootstrap.d.ts +7 -14
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +82 -107
- package/dist/collection.d.ts +0 -3
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +1 -17
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +16 -8
- package/dist/connection.d.ts +0 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +455 -688
- package/dist/conversation.d.ts +2 -3
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +56 -10
- package/dist/durability.d.ts +0 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +1 -0
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +1 -1
- package/dist/fulltext.d.ts.map +1 -1
- package/dist/fulltext.js +7 -5
- package/dist/host.d.ts +0 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +6 -4
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/media.d.ts +1 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +19 -9
- package/dist/memory.d.ts +2 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +50 -20
- package/dist/model.d.ts +0 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -9
- package/dist/outcome.d.ts +0 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/reach.js +1 -1
- package/dist/readiness.d.ts +3 -15
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +4 -10
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +26 -0
- package/dist/refresh.d.ts +5 -4
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +4 -4
- package/dist/replica.d.ts +1 -2
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +0 -4
- package/dist/room-draft.d.ts +17 -2
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +40 -6
- package/dist/shared.d.ts +0 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +0 -10
- package/dist/status.d.ts +0 -4
- package/dist/status.d.ts.map +1 -1
- package/dist/store.d.ts +6 -29
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +7 -63
- package/dist/stored.d.ts +1 -25
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +51 -115
- package/dist/tables.d.ts +3 -40
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +3 -52
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/validation.d.ts +3 -4
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +35 -96
- package/package.json +2 -2
- package/dist/reads.d.ts +0 -11
- package/dist/reads.d.ts.map +0 -1
- package/dist/reads.js +0 -100
package/dist/validation.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { assess,
|
|
2
|
-
import {
|
|
3
|
-
import { sameTyping } from './model.js';
|
|
1
|
+
import { assess, parse, parseFrontmatter, verdicts, } from '@agentshouse/mdmodel';
|
|
2
|
+
import { selected } from './collection.js';
|
|
4
3
|
import { paced, ROW_WEIGHT, yielded } from './turn.js';
|
|
5
4
|
const NO_TYPES = { types: {} };
|
|
6
5
|
function modelOf(model) {
|
|
@@ -60,103 +59,43 @@ function declared(content) {
|
|
|
60
59
|
const read = parseFrontmatter(content);
|
|
61
60
|
return read.ok ? (read.frontmatter.type ?? 'any') : undefined;
|
|
62
61
|
}
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
function shifted({ was, now }) {
|
|
63
|
+
return ((now === undefined) !== (was === undefined) ||
|
|
64
|
+
(now === null) !== (was === null) ||
|
|
65
|
+
declared(now) !== declared(was));
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
(left.selection === null || right.selection === null
|
|
70
|
-
? left.selection === right.selection
|
|
71
|
-
: sameTyping(left.selection.model, right.selection.model)) &&
|
|
72
|
-
JSON.stringify(left.selection?.roots ?? null) === JSON.stringify(right.selection?.roots ?? null));
|
|
73
|
-
}
|
|
74
|
-
function checked(path, content, composition) {
|
|
75
|
-
const model = governing(composition, path);
|
|
76
|
-
return checkDocument(path, content, modelOf(model), { anyRoom: true });
|
|
77
|
-
}
|
|
78
|
-
async function reachingAll(checks, composition, next) {
|
|
79
|
-
const targets = [
|
|
80
|
-
...new Set(checks.flatMap(({ check }) => check.ok ? check.references.flatMap(({ target }) => (target === null ? [] : [target])) : [])),
|
|
81
|
-
];
|
|
82
|
-
const known = await next(targets);
|
|
67
|
+
const PAGE_TEXT = 1 << 20;
|
|
68
|
+
export async function validatedNeighbourhood(changes, composition, source) {
|
|
83
69
|
const pace = paced();
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
await pace((check.references.length + 1) * ROW_WEIGHT);
|
|
70
|
+
const changedAt = new Set();
|
|
71
|
+
const moved = [];
|
|
72
|
+
for (const change of changes) {
|
|
73
|
+
changedAt.add(change.path);
|
|
74
|
+
if (shifted(change))
|
|
75
|
+
moved.push(change.path);
|
|
76
|
+
await pace((change.now?.length ?? 0) + (change.was?.length ?? 0) + ROW_WEIGHT);
|
|
92
77
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const change =
|
|
104
|
-
|
|
78
|
+
const referring = moved.length === 0
|
|
79
|
+
? []
|
|
80
|
+
: (await source.referrers(moved)).filter((path) => !changedAt.has(path));
|
|
81
|
+
const texts = await source.texts(referring);
|
|
82
|
+
const total = changes.length + referring.length;
|
|
83
|
+
let at = 0;
|
|
84
|
+
const walk = async () => {
|
|
85
|
+
const entries = [];
|
|
86
|
+
let text = 0;
|
|
87
|
+
while (at < total && text < PAGE_TEXT) {
|
|
88
|
+
const change = changes[at];
|
|
89
|
+
const path = change?.path ?? referring[at - changes.length];
|
|
90
|
+
const content = change === undefined ? texts.get(path) : change.now;
|
|
91
|
+
at += 1;
|
|
92
|
+
text += ROW_WEIGHT;
|
|
93
|
+
if (content === undefined || content === null)
|
|
105
94
|
continue;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
else
|
|
109
|
-
known.set(path, { type: declared(change.now), binary: change.now === null });
|
|
95
|
+
entries.push({ path, content });
|
|
96
|
+
text += content.length;
|
|
110
97
|
}
|
|
111
|
-
return
|
|
98
|
+
return { entries, next: at < total ? String(at) : null };
|
|
112
99
|
};
|
|
113
|
-
|
|
114
|
-
const checks = [];
|
|
115
|
-
const pace = paced();
|
|
116
|
-
for (const { path, was, now } of changes) {
|
|
117
|
-
await pace((now?.length ?? 0) + (was?.length ?? 0) + ROW_WEIGHT);
|
|
118
|
-
const modeled = governing(composition, path).status !== 'unavailable';
|
|
119
|
-
if ((now === undefined) !== (was === undefined) ||
|
|
120
|
-
declared(now) !== declared(was) ||
|
|
121
|
-
(now === null) !== (was === null)) {
|
|
122
|
-
shifted.push(path);
|
|
123
|
-
}
|
|
124
|
-
if (!modeled && typedIn(was) && !typedIn(now))
|
|
125
|
-
return false;
|
|
126
|
-
if (now === undefined)
|
|
127
|
-
continue;
|
|
128
|
-
if (now === null)
|
|
129
|
-
return false;
|
|
130
|
-
if (!modeled) {
|
|
131
|
-
if (declared(now) === undefined)
|
|
132
|
-
return false;
|
|
133
|
-
if (typedIn(now))
|
|
134
|
-
continue;
|
|
135
|
-
const check = checked(path, now, composition);
|
|
136
|
-
if (!check.ok)
|
|
137
|
-
return false;
|
|
138
|
-
checks.push({ path, check });
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
checks.push({ path, check: checked(path, now, composition) });
|
|
142
|
-
}
|
|
143
|
-
if (!(await reachingAll(checks, composition, next)))
|
|
144
|
-
return false;
|
|
145
|
-
if (shifted.length === 0)
|
|
146
|
-
return true;
|
|
147
|
-
if (source.referrers === null)
|
|
148
|
-
return false;
|
|
149
|
-
const files = (await source.referrers(shifted)).filter((file) => !changedAt.has(file));
|
|
150
|
-
if (files.length === 0)
|
|
151
|
-
return true;
|
|
152
|
-
const texts = await source.texts(files);
|
|
153
|
-
const rechecked = [];
|
|
154
|
-
for (const file of files) {
|
|
155
|
-
const content = texts.get(file);
|
|
156
|
-
if (content === undefined || content === null)
|
|
157
|
-
return false;
|
|
158
|
-
await pace(content.length + ROW_WEIGHT);
|
|
159
|
-
rechecked.push({ path: file, check: checked(file, content, composition) });
|
|
160
|
-
}
|
|
161
|
-
return reachingAll(rechecked, composition, next);
|
|
100
|
+
return validatedCollection(walk, source.lookup, composition);
|
|
162
101
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdruntime",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-c5fe3b2cddda7",
|
|
4
4
|
"description": "The headless core of MD App",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"LICENSE"
|
|
55
55
|
],
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@agentshouse/mdmodel": "0.1.0-
|
|
57
|
+
"@agentshouse/mdmodel": "0.1.0-c96c61ea31316"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"react": ">=18"
|
package/dist/reads.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Adapter } from './adapter.js';
|
|
2
|
-
import type { Reads } from './bootstrap.js';
|
|
3
|
-
export type DoorReads = Reads & {
|
|
4
|
-
carried(locator: string): number;
|
|
5
|
-
finished(locator: string, turn: number): void;
|
|
6
|
-
opened(): void;
|
|
7
|
-
applied(): void;
|
|
8
|
-
lost(): void;
|
|
9
|
-
};
|
|
10
|
-
export declare function doorReads(adapter: Adapter, declaration: (locator: string) => unknown, generation: () => number): DoorReads;
|
|
11
|
-
//# sourceMappingURL=reads.d.ts.map
|
package/dist/reads.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reads.d.ts","sourceRoot":"","sources":["../src/reads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAOR,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG;IAC9B,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9C,MAAM,IAAI,IAAI,CAAC;IACf,OAAO,IAAI,IAAI,CAAC;IAChB,IAAI,IAAI,IAAI,CAAC;CACd,CAAC;AAkCF,wBAAgB,SAAS,CACvB,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,EACzC,UAAU,EAAE,MAAM,MAAM,GACvB,SAAS,CA4FX"}
|
package/dist/reads.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
function declaredAs(declaration) {
|
|
2
|
-
if (declaration === null || typeof declaration !== 'object')
|
|
3
|
-
return declaration;
|
|
4
|
-
const { roomVersion: _version, ...declared } = declaration;
|
|
5
|
-
return declared;
|
|
6
|
-
}
|
|
7
|
-
function sameHeld(one, other) {
|
|
8
|
-
return one === other;
|
|
9
|
-
}
|
|
10
|
-
function failed(answer) {
|
|
11
|
-
return answer?.kind === 'transport-uncertainty';
|
|
12
|
-
}
|
|
13
|
-
function continues(answer) {
|
|
14
|
-
const page = answer;
|
|
15
|
-
return page?.kind === 'net-advancement' && page.pageToken !== undefined;
|
|
16
|
-
}
|
|
17
|
-
export function doorReads(adapter, declaration, generation) {
|
|
18
|
-
const reading = new Map();
|
|
19
|
-
const taken = new Map();
|
|
20
|
-
let carrying = false;
|
|
21
|
-
function joined(read, authorization, request, ask) {
|
|
22
|
-
const key = `${read} ${request.locator} ${request.pageToken ?? ''}`;
|
|
23
|
-
const { held, received, ...named } = request;
|
|
24
|
-
const asked = JSON.stringify([declaredAs(declaration(request.locator)), named]);
|
|
25
|
-
const asking = generation();
|
|
26
|
-
const current = reading.get(key);
|
|
27
|
-
if (current !== undefined &&
|
|
28
|
-
current.authorization === authorization &&
|
|
29
|
-
current.asked === asked &&
|
|
30
|
-
sameHeld(current.held, held) &&
|
|
31
|
-
current.received === received &&
|
|
32
|
-
(!current.settled || current.holder < asking)) {
|
|
33
|
-
if (current.settled && !current.continued)
|
|
34
|
-
reading.delete(key);
|
|
35
|
-
else
|
|
36
|
-
current.holder = Math.max(current.holder, asking);
|
|
37
|
-
if (current.from === asking)
|
|
38
|
-
return current.answer;
|
|
39
|
-
const again = () => joined(read, authorization, request, ask);
|
|
40
|
-
return current.answer.then((answer) => {
|
|
41
|
-
if (failed(answer))
|
|
42
|
-
return again();
|
|
43
|
-
taken.set(request.locator, (taken.get(request.locator) ?? 0) + 1);
|
|
44
|
-
return answer;
|
|
45
|
-
}, again);
|
|
46
|
-
}
|
|
47
|
-
const answer = ask();
|
|
48
|
-
const sent = {
|
|
49
|
-
locator: request.locator,
|
|
50
|
-
authorization,
|
|
51
|
-
asked,
|
|
52
|
-
held,
|
|
53
|
-
received,
|
|
54
|
-
answer,
|
|
55
|
-
from: asking,
|
|
56
|
-
holder: asking,
|
|
57
|
-
settled: false,
|
|
58
|
-
continued: false,
|
|
59
|
-
};
|
|
60
|
-
reading.set(key, sent);
|
|
61
|
-
const settled = (result, kept) => {
|
|
62
|
-
sent.settled = true;
|
|
63
|
-
sent.continued = kept && read === 'refresh' && continues(result);
|
|
64
|
-
if (reading.get(key) !== sent)
|
|
65
|
-
return;
|
|
66
|
-
const live = sent.holder === generation();
|
|
67
|
-
if (!kept || (live ? !sent.continued : !carrying))
|
|
68
|
-
reading.delete(key);
|
|
69
|
-
};
|
|
70
|
-
answer.then((result) => settled(result, !failed(result)), () => settled(null, false));
|
|
71
|
-
return answer;
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
bootstrap: (authorization, request) => joined('bootstrap', authorization, request, () => adapter.bootstrap(authorization, request)),
|
|
75
|
-
refresh: (authorization, request) => joined('refresh', authorization, request, () => adapter.refresh(authorization, request)),
|
|
76
|
-
reached: (locator, roomVersion, target) => adapter.reached(locator, roomVersion, target),
|
|
77
|
-
carried: (locator) => taken.get(locator) ?? 0,
|
|
78
|
-
finished(locator, turn) {
|
|
79
|
-
for (const [key, held] of reading) {
|
|
80
|
-
if (held.locator !== locator || !held.settled || held.holder !== turn)
|
|
81
|
-
continue;
|
|
82
|
-
if (turn === generation() || !carrying)
|
|
83
|
-
reading.delete(key);
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
opened() {
|
|
87
|
-
carrying = true;
|
|
88
|
-
},
|
|
89
|
-
applied() {
|
|
90
|
-
carrying = false;
|
|
91
|
-
for (const [key, held] of reading) {
|
|
92
|
-
if (held.settled && held.holder !== generation())
|
|
93
|
-
reading.delete(key);
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
lost() {
|
|
97
|
-
reading.clear();
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
}
|