@agentshouse/mdruntime 0.1.0-cd507e16e5fc0 → 0.1.0-cd71aba4d0215
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/README.md +8 -8
- package/dist/acceptance.d.ts +0 -3
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +74 -145
- package/dist/act-lanes.d.ts +33 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +177 -0
- package/dist/actions.d.ts +7 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +40 -30
- package/dist/adapter.d.ts +27 -45
- package/dist/adapter.d.ts.map +1 -1
- package/dist/bootstrap.d.ts +1 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +6 -19
- package/dist/change-set.d.ts +4 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +4 -2
- package/dist/client.d.ts +7 -12
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +29 -14
- package/dist/collection.d.ts +22 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +12 -2
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +15 -21
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +26 -16
- package/dist/conversation-live.d.ts +8 -6
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +7 -6
- package/dist/conversation.d.ts +23 -10
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +127 -102
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +18 -40
- package/dist/durability.d.ts +3 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/expectation.d.ts +4 -2
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +33 -11
- package/dist/failure.d.ts +3 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +6 -0
- package/dist/host.d.ts +17 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +39 -9
- package/dist/index.d.ts +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/install.d.ts +1 -3
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +48 -65
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +38 -27
- package/dist/listing.d.ts +6 -11
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +25 -62
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +3 -3
- package/dist/locks.d.ts +2 -4
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +10 -38
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +10 -21
- package/dist/media.d.ts +1 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +4 -4
- package/dist/memory.d.ts +4 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +38 -21
- package/dist/messages.d.ts +0 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +13 -31
- package/dist/model.d.ts +0 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -5
- package/dist/models.d.ts +4 -8
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +97 -136
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +12 -17
- package/dist/opened.d.ts +1 -1
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +5 -5
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +6 -4
- package/dist/outcome.d.ts +3 -0
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +15 -0
- package/dist/overlay.d.ts +2 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +32 -21
- package/dist/page-metadata.d.ts +8 -0
- package/dist/page-metadata.d.ts.map +1 -0
- package/dist/page-metadata.js +19 -0
- package/dist/parts.d.ts +3 -51
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +14 -111
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +22 -15
- package/dist/presence.d.ts +52 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +220 -0
- package/dist/queries.d.ts +1 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +5 -7
- package/dist/query.d.ts +0 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.js +1 -1
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +455 -0
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +27 -8
- package/dist/react.d.ts +11 -0
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +15 -1
- package/dist/reads.d.ts +3 -1
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +9 -2
- package/dist/recovery.d.ts +3 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +29 -7
- package/dist/refresh.js +2 -2
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +5 -4
- package/dist/replica.d.ts +5 -11
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +13 -15
- package/dist/retried.d.ts +30 -0
- package/dist/retried.d.ts.map +1 -0
- package/dist/retried.js +72 -0
- package/dist/room-draft.d.ts +4 -6
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +36 -52
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +17 -16
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +3 -4
- package/dist/runtime.d.ts +9 -16
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +41 -90
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +233 -116
- package/dist/saves.d.ts +2 -40
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +107 -702
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +2 -3
- package/dist/shared.d.ts +0 -5
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +4 -90
- package/dist/shown.d.ts +4 -3
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +26 -31
- package/dist/socket/lanes.d.ts +2 -1
- package/dist/socket/lanes.d.ts.map +1 -1
- package/dist/socket/lanes.js +5 -2
- package/dist/socket/session.d.ts +0 -1
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket.d.ts +2 -4
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +4 -8
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +5 -4
- package/dist/store/records.d.ts +3 -3
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +4 -5
- package/dist/store/space.d.ts +1 -1
- package/dist/store/space.d.ts.map +1 -1
- package/dist/store/space.js +0 -2
- package/dist/store/watchers.js +1 -2
- package/dist/store.d.ts +10 -5
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +38 -13
- package/dist/stored.d.ts +1 -1
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +6 -6
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +8 -8
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +86 -78
- package/dist/tables.d.ts +0 -5
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +8 -11
- package/dist/tallies.js +5 -5
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +2 -2
- package/dist/wire.d.ts +40 -4
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +12 -3
- package/package.json +3 -2
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/job.d.ts +0 -33
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -54
- package/dist/socket/rooms.d.ts +0 -44
- package/dist/socket/rooms.d.ts.map +0 -1
- package/dist/socket/rooms.js +0 -90
- package/dist/store/fences.d.ts +0 -16
- package/dist/store/fences.d.ts.map +0 -1
- package/dist/store/fences.js +0 -26
package/dist/models.js
CHANGED
|
@@ -1,195 +1,156 @@
|
|
|
1
|
+
import { equalValue } from '@agentshouse/mdmodel';
|
|
1
2
|
import { changeSet } from './change-set.js';
|
|
2
3
|
import { composedOf } from './collection.js';
|
|
3
|
-
import {
|
|
4
|
+
import { declared, sameDeclaration } from './declaration.js';
|
|
5
|
+
import { uncaught } from './failure.js';
|
|
6
|
+
import { declarationOf, listedLocators } from './listing.js';
|
|
4
7
|
import { loseRooms } from './lost.js';
|
|
5
8
|
import { NO_MODEL } from './model.js';
|
|
9
|
+
import { settle } from './queue.js';
|
|
6
10
|
import { storedRecord } from './replica.js';
|
|
7
|
-
import { overlayDiff, preparedAfter, replayed, sliceAt } from './saves.js';
|
|
8
11
|
import { emitRooms } from './shown.js';
|
|
9
|
-
|
|
10
|
-
return
|
|
11
|
-
(JSON.stringify(held.operations) === JSON.stringify(room.operations) &&
|
|
12
|
-
JSON.stringify(held.replica) === JSON.stringify(room.replica) &&
|
|
13
|
-
JSON.stringify(held.providerOwnedPaths) === JSON.stringify(room.providerOwnedPaths) &&
|
|
14
|
-
JSON.stringify(held.authoredPaths) === JSON.stringify(room.authoredPaths) &&
|
|
15
|
-
JSON.stringify(held.typedSelection) === JSON.stringify(room.typedSelection ?? null)));
|
|
12
|
+
function declaredAsHeld(held, declaration) {
|
|
13
|
+
return held === undefined || sameDeclaration(held.declaration, declaration);
|
|
16
14
|
}
|
|
17
15
|
export function revoked(model) {
|
|
18
16
|
return model?.status === 'unavailable' && model.reason === 'revoked';
|
|
19
17
|
}
|
|
20
|
-
function unheldModelOf({
|
|
21
|
-
return
|
|
18
|
+
function unheldModelOf({ presence }, locator) {
|
|
19
|
+
return presence.unheldModel(locator) ?? NO_MODEL;
|
|
22
20
|
}
|
|
23
|
-
|
|
21
|
+
async function modelNow(runtime, locator) {
|
|
22
|
+
return (await runtime.store.record(locator))?.model ?? unheldModelOf(runtime, locator);
|
|
23
|
+
}
|
|
24
|
+
function restands(held, model, declaration) {
|
|
25
|
+
return (JSON.stringify(held.model) !== JSON.stringify(model) ||
|
|
26
|
+
!equalValue(held.declaration.typedSelection, declaration.typedSelection));
|
|
27
|
+
}
|
|
28
|
+
function recordAlone(store, record) {
|
|
29
|
+
return {
|
|
30
|
+
locator: record.locator,
|
|
31
|
+
key: record.key,
|
|
32
|
+
record: storedRecord(record),
|
|
33
|
+
composed: composedOf(store.composed(record)),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function unheld(runtime, locator, model) {
|
|
37
|
+
runtime.presence.modelled(locator, model);
|
|
38
|
+
emitRooms(runtime);
|
|
39
|
+
}
|
|
40
|
+
function recorded(runtime, locator, declaration, model) {
|
|
24
41
|
const { store, socket } = runtime;
|
|
25
|
-
|
|
26
|
-
if (held === undefined || (held.name === room.name && held.handle === room.handle))
|
|
27
|
-
return;
|
|
28
|
-
await store.exclusive(async () => {
|
|
42
|
+
return store.exclusive(async () => {
|
|
29
43
|
if (!socket.continuing())
|
|
30
44
|
return;
|
|
31
|
-
const current = await store.record(
|
|
32
|
-
if (current === undefined)
|
|
45
|
+
const current = await store.record(locator);
|
|
46
|
+
if (current === undefined) {
|
|
47
|
+
unheld(runtime, locator, model);
|
|
33
48
|
return;
|
|
34
|
-
|
|
35
|
-
await
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
composed: composedOf(store.composed(record)),
|
|
42
|
-
},
|
|
43
|
-
],
|
|
44
|
-
});
|
|
45
|
-
emitRooms(runtime);
|
|
49
|
+
}
|
|
50
|
+
const answer = await (await store.open()).commit({ rooms: [recordAlone(store, { ...current, declaration, model })] });
|
|
51
|
+
void store.changed(changeSet(locator, {
|
|
52
|
+
documents: answer.changed[locator] ?? [],
|
|
53
|
+
room: true,
|
|
54
|
+
unindexed: answer.indexed[locator] === false,
|
|
55
|
+
}));
|
|
46
56
|
});
|
|
47
57
|
}
|
|
48
|
-
async function
|
|
49
|
-
return (await runtime.store.record(locator))?.model ?? unheldModelOf(runtime, locator);
|
|
50
|
-
}
|
|
51
|
-
export async function retainModel(runtime, local, room, given) {
|
|
58
|
+
export async function retainModel(runtime, locator, declaration, given, refused) {
|
|
52
59
|
const { store, socket } = runtime;
|
|
53
|
-
const held = await store.record(
|
|
54
|
-
const previous = held?.model ?? unheldModelOf(runtime,
|
|
60
|
+
const held = await store.record(locator);
|
|
61
|
+
const previous = held?.model ?? unheldModelOf(runtime, locator);
|
|
55
62
|
const next = given ?? previous;
|
|
56
|
-
if (JSON.stringify(previous) === JSON.stringify(next) && declaredAsHeld(held,
|
|
63
|
+
if (JSON.stringify(previous) === JSON.stringify(next) && declaredAsHeld(held, declaration))
|
|
64
|
+
return;
|
|
65
|
+
if (held !== undefined && !restands(held, next, declaration)) {
|
|
66
|
+
await recorded(runtime, locator, declaration, next);
|
|
57
67
|
return;
|
|
58
|
-
|
|
68
|
+
}
|
|
69
|
+
await settle(runtime, [locator], async (works) => {
|
|
59
70
|
if (!socket.continuing())
|
|
60
|
-
return;
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const record = {
|
|
66
|
-
...current.record,
|
|
67
|
-
name: room.name,
|
|
68
|
-
handle: room.handle,
|
|
69
|
-
operations: room.operations,
|
|
70
|
-
replica: room.replica,
|
|
71
|
-
providerOwnedPaths: room.providerOwnedPaths,
|
|
72
|
-
authoredPaths: room.authoredPaths,
|
|
73
|
-
typedSelection: room.typedSelection ?? null,
|
|
74
|
-
model: next,
|
|
75
|
-
};
|
|
76
|
-
const confirmedLayer = await sliceAt(store, record, 'confirmed', current.queue, current.overlaid);
|
|
77
|
-
const replayedLayer = await replayed(store, record, confirmedLayer, current.queue);
|
|
78
|
-
const diff = await overlayDiff(record, current, replayedLayer.visible, replayedLayer.touched);
|
|
79
|
-
const answer = await local.commit({
|
|
80
|
-
rooms: [
|
|
81
|
-
{
|
|
82
|
-
locator: room.locator,
|
|
83
|
-
key: record.key,
|
|
84
|
-
record: storedRecord(record),
|
|
85
|
-
roots: record.typedSelection?.roots ?? [],
|
|
86
|
-
composed: composedOf(store.composed(record)),
|
|
87
|
-
overlay: diff.overlay,
|
|
88
|
-
},
|
|
89
|
-
],
|
|
90
|
-
});
|
|
91
|
-
preparedAfter(runtime, room.locator, answer);
|
|
92
|
-
changed = changeSet(room.locator, {
|
|
93
|
-
documents: answer.changed[room.locator] ?? [],
|
|
94
|
-
room: true,
|
|
95
|
-
});
|
|
71
|
+
return [];
|
|
72
|
+
const current = works.get(locator)?.replica;
|
|
73
|
+
if (current === undefined) {
|
|
74
|
+
unheld(runtime, locator, next);
|
|
75
|
+
return [];
|
|
96
76
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
77
|
+
return [
|
|
78
|
+
{
|
|
79
|
+
locator,
|
|
80
|
+
record: { ...current.record, declaration, model: next },
|
|
81
|
+
...(refused === undefined ? {} : { refused }),
|
|
82
|
+
},
|
|
83
|
+
];
|
|
104
84
|
});
|
|
105
85
|
}
|
|
106
|
-
export async function scoped(runtime, result,
|
|
107
|
-
const { socket, journal } = runtime;
|
|
86
|
+
export async function scoped(runtime, result, locator, declaration) {
|
|
87
|
+
const { socket, presence, journal } = runtime;
|
|
108
88
|
if (result.scope === 'content' && !result.retryable) {
|
|
109
|
-
journal.record(`scoped refusal ${
|
|
110
|
-
await loseRooms(runtime, [
|
|
89
|
+
journal.record(`scoped refusal ${locator} ${result.scope} ${result.code}`);
|
|
90
|
+
await loseRooms(runtime, [locator]);
|
|
111
91
|
return;
|
|
112
92
|
}
|
|
113
|
-
|
|
114
|
-
refusal: { code: result.code, fields: result.fields, retryable: result.retryable },
|
|
115
|
-
});
|
|
116
|
-
let scopedAway = room;
|
|
93
|
+
presence.refused(locator, result);
|
|
117
94
|
if (result.scope === 'model')
|
|
118
|
-
await retainModel(runtime,
|
|
119
|
-
status: 'unavailable',
|
|
120
|
-
reason: 'not-readable',
|
|
121
|
-
});
|
|
122
|
-
else if (result.scope !== 'operation') {
|
|
123
|
-
socket.rooms.stand(room.locator, { unreadable: true });
|
|
124
|
-
scopedAway = { ...room, replica: { ...room.replica, admission: 'unavailable' } };
|
|
125
|
-
await retainModel(runtime, local, scopedAway, null);
|
|
126
|
-
}
|
|
95
|
+
await retainModel(runtime, locator, declaration, { status: 'unavailable', reason: 'not-readable' }, true);
|
|
127
96
|
if (!socket.continuing())
|
|
128
97
|
return;
|
|
129
|
-
list(runtime, scopedAway, admitted(runtime, scopedAway));
|
|
130
98
|
emitRooms(runtime);
|
|
131
|
-
journal.record(`scoped refusal ${
|
|
99
|
+
journal.record(`scoped refusal ${locator} ${result.scope} ${result.code}`);
|
|
132
100
|
}
|
|
133
101
|
export async function settleModels(runtime, held, status, local) {
|
|
134
|
-
const { store, socket, journal } = runtime;
|
|
102
|
+
const { store, socket, presence, journal } = runtime;
|
|
135
103
|
const owed = (model) => model.status !== 'unavailable' && model.status !== status;
|
|
136
104
|
const declaredAnew = await store.exclusive(async () => {
|
|
137
105
|
if (!socket.continuing())
|
|
138
106
|
return [];
|
|
139
|
-
const stored = await store.rooms(held.
|
|
140
|
-
const unchanged = held.filter((
|
|
141
|
-
const record = stored.get(
|
|
142
|
-
return (owed(record?.model ?? unheldModelOf(runtime,
|
|
107
|
+
const stored = await store.rooms([...held.keys()]);
|
|
108
|
+
const unchanged = [...held].filter(([locator, declaration]) => {
|
|
109
|
+
const record = stored.get(locator)?.record;
|
|
110
|
+
return (owed(record?.model ?? unheldModelOf(runtime, locator)) &&
|
|
111
|
+
declaredAsHeld(record, declaration));
|
|
143
112
|
});
|
|
144
|
-
const records = unchanged.flatMap((
|
|
145
|
-
const record = stored.get(
|
|
113
|
+
const records = unchanged.flatMap(([locator]) => {
|
|
114
|
+
const record = stored.get(locator)?.record;
|
|
146
115
|
return record === undefined
|
|
147
116
|
? []
|
|
148
117
|
: [{ ...record, model: { ...record.model, status } }];
|
|
149
118
|
});
|
|
150
119
|
if (records.length > 0) {
|
|
151
120
|
try {
|
|
152
|
-
await local.commit({
|
|
153
|
-
rooms: records.map((record) => ({
|
|
154
|
-
locator: record.locator,
|
|
155
|
-
key: record.key,
|
|
156
|
-
record: storedRecord(record),
|
|
157
|
-
composed: composedOf(store.composed(record)),
|
|
158
|
-
})),
|
|
159
|
-
});
|
|
121
|
+
await local.commit({ rooms: records.map((record) => recordAlone(store, record)) });
|
|
160
122
|
}
|
|
161
|
-
catch {
|
|
123
|
+
catch (error) {
|
|
162
124
|
journal.record(`model ${status} persistence failed`);
|
|
125
|
+
uncaught(error);
|
|
163
126
|
}
|
|
164
127
|
}
|
|
165
|
-
for (const
|
|
166
|
-
const
|
|
167
|
-
if (!stored.has(
|
|
168
|
-
|
|
169
|
-
unheldModel: { ...unheldModel, status },
|
|
170
|
-
});
|
|
128
|
+
for (const [locator] of unchanged) {
|
|
129
|
+
const unheldModel = presence.unheldModel(locator);
|
|
130
|
+
if (!stored.has(locator) && unheldModel !== null) {
|
|
131
|
+
presence.modelled(locator, { ...unheldModel, status });
|
|
171
132
|
}
|
|
172
|
-
list(runtime, room, admitted(runtime, room));
|
|
173
133
|
}
|
|
174
134
|
if (unchanged.length > 0)
|
|
175
135
|
emitRooms(runtime);
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
});
|
|
136
|
+
const kept = new Set(unchanged.map(([locator]) => locator));
|
|
137
|
+
return [...held].filter(([locator]) => !kept.has(locator) &&
|
|
138
|
+
owed(stored.get(locator)?.record.model ?? unheldModelOf(runtime, locator)));
|
|
180
139
|
});
|
|
181
|
-
for (const
|
|
182
|
-
const model = await modelNow(runtime,
|
|
140
|
+
for (const [locator, declaration] of declaredAnew) {
|
|
141
|
+
const model = await modelNow(runtime, locator);
|
|
183
142
|
if (owed(model))
|
|
184
|
-
await retainModel(runtime,
|
|
143
|
+
await retainModel(runtime, locator, declaration, { ...model, status });
|
|
185
144
|
}
|
|
186
145
|
}
|
|
187
146
|
export async function cachedModels(runtime, local) {
|
|
188
|
-
const { store,
|
|
147
|
+
const { store, presence } = runtime;
|
|
189
148
|
const held = await store.rooms();
|
|
190
|
-
await settleModels(runtime, listedLocators(runtime, held).flatMap((locator) => {
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
149
|
+
await settleModels(runtime, new Map(listedLocators(runtime, held).flatMap((locator) => {
|
|
150
|
+
const discovered = presence.room(locator);
|
|
151
|
+
const declaration = discovered === undefined
|
|
152
|
+
? declarationOf(runtime, locator, held.get(locator))?.room
|
|
153
|
+
: declared(discovered);
|
|
154
|
+
return declaration === undefined ? [] : [[locator, declaration]];
|
|
155
|
+
})), 'cached', local);
|
|
195
156
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../src/observation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAExF,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B,OAAO,IAAI,CAAC,CAAC;IACb,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACpD,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAErC,MAAM,MAAM,WAAW,GAAG;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAE3E,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC;IACpE,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC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MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,MAAM,CAY3E;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,YAAY,GAAG,IAAI,CA+BjF"}
|
package/dist/observation.js
CHANGED
|
@@ -90,24 +90,19 @@ export function opened(watch, keyed) {
|
|
|
90
90
|
return new Promise((resolve, reject) => {
|
|
91
91
|
let handle;
|
|
92
92
|
let stop = () => { };
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
stop();
|
|
105
|
-
reject(error);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
catch (error) {
|
|
93
|
+
stop = watch((message) => {
|
|
94
|
+
if (handle !== undefined) {
|
|
95
|
+
handle.receive(message);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
handle = observed(message, () => stop(), keyed);
|
|
99
|
+
resolve(handle.observation);
|
|
100
|
+
}, (error) => {
|
|
101
|
+
if (handle !== undefined)
|
|
102
|
+
return;
|
|
103
|
+
stop();
|
|
109
104
|
reject(error);
|
|
110
|
-
}
|
|
105
|
+
});
|
|
111
106
|
});
|
|
112
107
|
}
|
|
113
108
|
export function observing(watch) {
|
package/dist/opened.d.ts
CHANGED
|
@@ -18,5 +18,5 @@ export type OpenedFiles = {
|
|
|
18
18
|
find(name: OpenedName): Promise<KeptBinary | null>;
|
|
19
19
|
fetch(name: OpenedName, read: () => Promise<BinaryResult>): Promise<KeptResult>;
|
|
20
20
|
};
|
|
21
|
-
export declare function openedFiles(database: RuntimeDatabase,
|
|
21
|
+
export declare function openedFiles(database: RuntimeDatabase, lost: (locator: string) => boolean): OpenedFiles;
|
|
22
22
|
//# sourceMappingURL=opened.d.ts.map
|
package/dist/opened.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opened.d.ts","sourceRoot":"","sources":["../src/opened.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGjD,OAAO,EAAoC,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAErF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAC;AAEhF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IACnD,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACjF,CAAC;AAsBF,wBAAgB,WAAW,CACzB,QAAQ,EAAE,eAAe,EACzB,
|
|
1
|
+
{"version":3,"file":"opened.d.ts","sourceRoot":"","sources":["../src/opened.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGjD,OAAO,EAAoC,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAErF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAC;AAEhF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IACnD,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACjF,CAAC;AAsBF,wBAAgB,WAAW,CACzB,QAAQ,EAAE,eAAe,EACzB,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,GACjC,WAAW,CAsFb"}
|
package/dist/opened.js
CHANGED
|
@@ -20,7 +20,7 @@ function taken(chunks, size) {
|
|
|
20
20
|
}
|
|
21
21
|
return part;
|
|
22
22
|
}
|
|
23
|
-
export function openedFiles(database,
|
|
23
|
+
export function openedFiles(database, lost) {
|
|
24
24
|
const fetching = new Map();
|
|
25
25
|
async function find(name) {
|
|
26
26
|
const held = await database.ask({ kind: 'opened.find', ...name });
|
|
@@ -36,14 +36,14 @@ export function openedFiles(database, fenced) {
|
|
|
36
36
|
let part = 0;
|
|
37
37
|
const write = async (bytes) => {
|
|
38
38
|
if (!(await database.ask({ kind: 'opened.part', key, part, bytes }))) {
|
|
39
|
-
throw new Error(
|
|
39
|
+
throw new Error();
|
|
40
40
|
}
|
|
41
41
|
part += 1;
|
|
42
42
|
};
|
|
43
43
|
try {
|
|
44
|
-
if (
|
|
44
|
+
if (lost(name.locator) ||
|
|
45
45
|
!(await database.ask({ kind: 'opened.begin', key, ...name, mediaType }))) {
|
|
46
|
-
throw new Error(
|
|
46
|
+
throw new Error();
|
|
47
47
|
}
|
|
48
48
|
for (;;) {
|
|
49
49
|
const read = await reader.read();
|
|
@@ -61,7 +61,7 @@ export function openedFiles(database, fenced) {
|
|
|
61
61
|
await write(taken(chunks, held));
|
|
62
62
|
const received = hashed.hex();
|
|
63
63
|
if (sha256 !== undefined && sha256 !== received) {
|
|
64
|
-
throw new Error(
|
|
64
|
+
throw new Error();
|
|
65
65
|
}
|
|
66
66
|
const whole = await database.ask({
|
|
67
67
|
kind: 'opened.keep',
|
package/dist/opening.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opening.d.ts","sourceRoot":"","sources":["../src/opening.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"opening.d.ts","sourceRoot":"","sources":["../src/opening.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,wBAAsB,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CA2CxF"}
|
package/dist/opening.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { conversationsOpened } from './conversation.js';
|
|
2
2
|
import { detectStorageLoss, nextGeneration, refusedForSpace } from './durability.js';
|
|
3
|
+
import { uncaught } from './failure.js';
|
|
3
4
|
import { sweep } from './install.js';
|
|
4
5
|
import { eraseFenced } from './lost.js';
|
|
5
6
|
import { prepare } from './preparation.js';
|
|
7
|
+
import { unpair } from './queue.js';
|
|
6
8
|
import { emitRooms, emitStorageLoss, statusShown } from './shown.js';
|
|
7
9
|
export async function open(runtime, opened) {
|
|
8
10
|
const { store, socket, journal, shell, conversations, build, usableWhenHeld } = runtime;
|
|
@@ -40,18 +42,18 @@ export async function open(runtime, opened) {
|
|
|
40
42
|
await conversationsOpened(conversations, opened);
|
|
41
43
|
if (interrupted.length > 0) {
|
|
42
44
|
queueMicrotask(() => {
|
|
43
|
-
void eraseFenced(runtime, interrupted).catch(() => {
|
|
45
|
+
void eraseFenced(runtime, interrupted).catch((error) => {
|
|
44
46
|
journal.record('erasure failed');
|
|
47
|
+
uncaught(error);
|
|
45
48
|
});
|
|
46
49
|
});
|
|
47
50
|
}
|
|
48
51
|
statusShown(runtime);
|
|
49
52
|
prepare(runtime);
|
|
50
53
|
emitRooms(runtime);
|
|
51
|
-
void
|
|
52
|
-
.exclusive(() => runtime.unpair(opened))
|
|
53
|
-
.catch(() => {
|
|
54
|
+
void unpair(runtime).catch((error) => {
|
|
54
55
|
journal.record('unpair failed');
|
|
56
|
+
uncaught(error);
|
|
55
57
|
});
|
|
56
58
|
return opened;
|
|
57
59
|
}
|
package/dist/outcome.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ActionResult, AdapterFailure, AttachResult, BinaryLinkResult, HistoryResult, HistoryRevision, ProviderRefusal, RoomVersionAt, ScopedRefusal } from './adapter.js';
|
|
2
2
|
import type { ChangeBatch } from './change.js';
|
|
3
|
+
import type { Attempt, Retries } from './retried.js';
|
|
3
4
|
import type { KeptBinary, KeptResult } from './opened.js';
|
|
4
5
|
type Refused<Kind extends string> = ProviderRefusal & {
|
|
5
6
|
kind: Kind;
|
|
@@ -84,5 +85,7 @@ export type QueueEntry = {
|
|
|
84
85
|
} & (Submission | {
|
|
85
86
|
readonly state: 'local';
|
|
86
87
|
});
|
|
88
|
+
export declare const UNANSWERED: ActionResult;
|
|
89
|
+
export declare function handedOutcome(retries: Retries, attempt: Attempt | undefined, result: ActionResult): CallResult;
|
|
87
90
|
export {};
|
|
88
91
|
//# sourceMappingURL=outcome.d.ts.map
|
package/dist/outcome.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outcome.d.ts","sourceRoot":"","sources":["../src/outcome.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,eAAe,EACf,aAAa,EACb,aAAa,EACd,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"outcome.d.ts","sourceRoot":"","sources":["../src/outcome.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,eAAe,EACf,aAAa,EACb,aAAa,EACd,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE1D,KAAK,OAAO,CAAC,IAAI,SAAS,MAAM,IAAI,eAAe,GAAG;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC;AAErE,MAAM,MAAM,OAAO,GACf,OAAO,CAAC,uBAAuB,CAAC,GAChC,OAAO,CAAC,uBAAuB,CAAC,GAChC,CAAC,OAAO,CAAC,mBAAmB,CAAC,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,GACpD,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,GAC9C,aAAa,CAAC;AAElB,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,QAA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CAAA;CAAE,CAExF;AAED,MAAM,MAAM,OAAO,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAEnD,eAAO,MAAM,OAAO,EAAE,OAA6B,CAAC;AAEpD,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEtD;AAED,eAAO,MAAM,SAAS,EAAE,OAKvB,CAAC;AAEF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAEnD;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAiBvD;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,UAAU,CAE7D;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAIlE;AAED,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,WAAW,CAAA;CAAE,GAC3C;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAExD,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAA;CAAE,GAAG,CACvD,UAAU,GACV;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAC9B,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,YAAgD,CAAC;AAE1E,wBAAgB,aAAa,CAC3B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,GAAG,SAAS,EAC5B,MAAM,EAAE,YAAY,GACnB,UAAU,CAUZ"}
|
package/dist/outcome.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { refusalError } from './failure.js';
|
|
1
2
|
export const UNREADABLE = {
|
|
2
3
|
kind: 'unreadable',
|
|
3
4
|
code: 'room-not-readable',
|
|
@@ -82,3 +83,17 @@ export function historyAnswer(result) {
|
|
|
82
83
|
? result
|
|
83
84
|
: failure(result);
|
|
84
85
|
}
|
|
86
|
+
export const UNANSWERED = { kind: 'transport-uncertainty' };
|
|
87
|
+
export function handedOutcome(retries, attempt, result) {
|
|
88
|
+
if (attempt !== undefined) {
|
|
89
|
+
const { step, instance } = attempt;
|
|
90
|
+
if (result.kind === 'action')
|
|
91
|
+
retries.succeeded(step, instance);
|
|
92
|
+
else if (result.kind === 'transport-uncertainty')
|
|
93
|
+
retries.uncertain(step, instance, result);
|
|
94
|
+
else if (result.kind === 'rejected' && result.retryable) {
|
|
95
|
+
retries.failed(step, instance, refusalError(result));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return calledResult(result);
|
|
99
|
+
}
|
package/dist/overlay.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BinaryFile, HeadChange } from './adapter.js';
|
|
2
|
+
import { type Composition } from './collection.js';
|
|
2
3
|
import type { ChangeBatch } from './change.js';
|
|
3
4
|
export type Heads = {
|
|
4
5
|
revisions: Readonly<Record<string, string>>;
|
|
@@ -22,5 +23,5 @@ export type Layer = Heads & {
|
|
|
22
23
|
export declare function acceptedBinaries(files: Readonly<Record<string, BinaryFile>>): Generator<readonly [string, HeldBinary]>;
|
|
23
24
|
export declare function sameBinary(left: HeldBinary | undefined, right: HeldBinary | undefined): boolean;
|
|
24
25
|
export declare function sameChange(left: HeadChange | undefined, right: HeadChange | undefined): boolean;
|
|
25
|
-
export declare function overlaying(base: Layer, queue: readonly ChangeBatch[], unapplied?: () => void): Generator<number, Layer, void>;
|
|
26
|
+
export declare function overlaying(base: Layer, queue: readonly ChangeBatch[], composition: Composition, unapplied?: () => void): Generator<number, Layer, void>;
|
|
26
27
|
//# sourceMappingURL=overlay.d.ts.map
|
package/dist/overlay.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../src/overlay.ts"],"names":[],"mappings":"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AAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,GAC1C,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAE1C;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,EAAE,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAW/F;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,EAAE,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAQ/F;AA+ND,wBAAiB,UAAU,CACzB,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,WAAW,EAAE,WAAW,EACxB,SAAS,CAAC,EAAE,MAAM,IAAI,GACrB,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAsChC"}
|
package/dist/overlay.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { apply, frontmatterValue, parse, serialize, } from '@agentshouse/mdmodel';
|
|
1
|
+
import { apply, create, frontmatterValue, parse, serialize, TYPE_FIELD, } from '@agentshouse/mdmodel';
|
|
2
|
+
import { definitionsAt } from './collection.js';
|
|
2
3
|
import { drafted, entriesIn, settling } from './shared.js';
|
|
3
4
|
import { ROW_WEIGHT } from './turn.js';
|
|
4
5
|
export function* acceptedBinaries(files) {
|
|
@@ -24,7 +25,6 @@ export function sameChange(left, right) {
|
|
|
24
25
|
left.author?.id === right.author?.id &&
|
|
25
26
|
left.author?.name === right.author?.name);
|
|
26
27
|
}
|
|
27
|
-
const EMPTY_FRONTMATTER = '---\n---\n';
|
|
28
28
|
function isPart(change) {
|
|
29
29
|
return change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble';
|
|
30
30
|
}
|
|
@@ -53,16 +53,23 @@ function* priorsOf(preconditions) {
|
|
|
53
53
|
preamble: (path) => preambles.get(path) ?? '',
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
-
function compose(fields, sections) {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
function compose(path, fields, sections, composition) {
|
|
57
|
+
const declared = fields[TYPE_FIELD];
|
|
58
|
+
const type = typeof declared === 'string' && declared !== '' ? declared : undefined;
|
|
59
|
+
const definition = definitionsAt(composition, path)(type);
|
|
60
|
+
const created = create(type, definition);
|
|
61
|
+
const next = apply(created, [
|
|
62
|
+
...Object.entries(fields).flatMap(([name, value]) => (name !== TYPE_FIELD || type === undefined) && frontmatterValue(value)
|
|
63
|
+
? [{ kind: 'field', name, value, prior: undefined }]
|
|
64
|
+
: []),
|
|
65
|
+
...Object.entries(sections).map(([name, value]) => ({
|
|
66
|
+
kind: 'section',
|
|
67
|
+
name,
|
|
68
|
+
value,
|
|
69
|
+
prior: undefined,
|
|
70
|
+
})),
|
|
71
|
+
], definition);
|
|
72
|
+
return serialize(next.outcome === 'applied' ? next.document : created);
|
|
66
73
|
}
|
|
67
74
|
function edited(change, priors) {
|
|
68
75
|
if (change.kind === 'field')
|
|
@@ -81,17 +88,19 @@ function edited(change, priors) {
|
|
|
81
88
|
prior: priors.section(change.path, change.name),
|
|
82
89
|
};
|
|
83
90
|
}
|
|
84
|
-
function edit(staged, changes, priors) {
|
|
91
|
+
function edit(staged, changes, priors, composition) {
|
|
85
92
|
const path = changes[0].path;
|
|
86
93
|
delete staged.revisions[path];
|
|
87
94
|
const text = staged.documents[path];
|
|
88
95
|
if (text === undefined)
|
|
89
96
|
return changes.length;
|
|
90
|
-
const
|
|
97
|
+
const definitions = definitionsAt(composition, path);
|
|
98
|
+
const parsed = parse(text, path, definitions);
|
|
91
99
|
if (!parsed.ok)
|
|
92
100
|
return changes.length;
|
|
101
|
+
const definition = definitions(parsed.document.type);
|
|
93
102
|
const wanted = changes.map((change) => edited(change, priors));
|
|
94
|
-
const first = apply(parsed.document, wanted);
|
|
103
|
+
const first = apply(parsed.document, wanted, definition);
|
|
95
104
|
if (first.outcome === 'refuse')
|
|
96
105
|
return changes.length;
|
|
97
106
|
if (first.outcome === 'applied') {
|
|
@@ -100,7 +109,7 @@ function edit(staged, changes, priors) {
|
|
|
100
109
|
}
|
|
101
110
|
const stale = new Set(first.stale);
|
|
102
111
|
const kept = wanted.filter((_, at) => !stale.has(at));
|
|
103
|
-
const rest = apply(parsed.document, kept);
|
|
112
|
+
const rest = apply(parsed.document, kept, definition);
|
|
104
113
|
if (rest.outcome !== 'applied')
|
|
105
114
|
return changes.length;
|
|
106
115
|
staged.documents[path] = serialize(rest.document);
|
|
@@ -151,10 +160,12 @@ function erase(staged, path) {
|
|
|
151
160
|
delete staged.changes[path];
|
|
152
161
|
delete staged.binaries[path];
|
|
153
162
|
}
|
|
154
|
-
function stage(staged, change) {
|
|
163
|
+
function stage(staged, change, composition) {
|
|
155
164
|
if (change.kind === 'create') {
|
|
156
165
|
staged.documents[change.path] =
|
|
157
|
-
'content' in change
|
|
166
|
+
'content' in change
|
|
167
|
+
? change.content
|
|
168
|
+
: compose(change.path, change.fields, change.sections, composition);
|
|
158
169
|
delete staged.fileIds[change.path];
|
|
159
170
|
delete staged.created[change.path];
|
|
160
171
|
delete staged.changes[change.path];
|
|
@@ -206,7 +217,7 @@ function arrive(heads, change) {
|
|
|
206
217
|
if (change.change !== undefined)
|
|
207
218
|
heads.changes[change.path] = change.change;
|
|
208
219
|
}
|
|
209
|
-
export function* overlaying(base, queue, unapplied) {
|
|
220
|
+
export function* overlaying(base, queue, composition, unapplied) {
|
|
210
221
|
const staged = {
|
|
211
222
|
documents: drafted(base.documents),
|
|
212
223
|
binaries: drafted(base.binaries),
|
|
@@ -220,7 +231,7 @@ export function* overlaying(base, queue, unapplied) {
|
|
|
220
231
|
for (let index = 0; index < batch.changes.length; index += 1) {
|
|
221
232
|
const change = batch.changes[index];
|
|
222
233
|
if (!isPart(change)) {
|
|
223
|
-
if (!stage(staged, change))
|
|
234
|
+
if (!stage(staged, change, composition))
|
|
224
235
|
unapplied?.();
|
|
225
236
|
yield ROW_WEIGHT;
|
|
226
237
|
continue;
|
|
@@ -234,7 +245,7 @@ export function* overlaying(base, queue, unapplied) {
|
|
|
234
245
|
index += 1;
|
|
235
246
|
}
|
|
236
247
|
const text = staged.documents[change.path] ?? '';
|
|
237
|
-
for (let left = edit(staged, run, priors); left > 0; left -= 1)
|
|
248
|
+
for (let left = edit(staged, run, priors, composition); left > 0; left -= 1)
|
|
238
249
|
unapplied?.();
|
|
239
250
|
yield ROW_WEIGHT + text.length;
|
|
240
251
|
}
|