@agentshouse/mdruntime 0.1.0-c11a2e8d6df41 → 0.1.0-c11fdcbfb7fe2
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/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +30 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +4 -13
- package/dist/adapter.d.ts +69 -10
- package/dist/adapter.d.ts.map +1 -1
- package/dist/{binary.d.ts → attachment.d.ts} +3 -3
- package/dist/attachment.d.ts.map +1 -0
- package/dist/{binary.js → attachment.js} +1 -1
- package/dist/authored.d.ts.map +1 -1
- package/dist/authored.js +0 -2
- package/dist/client.d.ts +8 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -2
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +6 -6
- package/dist/conversation-live.d.ts +1 -0
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +2 -1
- package/dist/conversation-row.d.ts +12 -0
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +10 -0
- package/dist/conversation.d.ts +4 -3
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +39 -34
- package/dist/declaration.js +2 -2
- package/dist/download.d.ts +2 -2
- package/dist/download.d.ts.map +1 -1
- package/dist/entry.d.ts +9 -0
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +38 -6
- package/dist/figures.d.ts +1 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +2 -2
- package/dist/house-query.d.ts.map +1 -1
- package/dist/house-query.js +24 -4
- package/dist/identity.d.ts +1 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +1 -1
- package/dist/index.d.ts +11 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +2 -0
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +16 -3
- package/dist/memory.js +4 -4
- package/dist/messages.d.ts +5 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +14 -3
- package/dist/model.d.ts +6 -5
- package/dist/model.d.ts.map +1 -1
- package/dist/opened.d.ts +5 -5
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +2 -2
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +2 -0
- package/dist/outcome.d.ts +16 -16
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +4 -4
- package/dist/overlay.d.ts +17 -6
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +108 -37
- package/dist/paths.d.ts +1 -1
- package/dist/paths.js +1 -1
- package/dist/queries.js +2 -2
- package/dist/query.d.ts +1 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +20 -4
- package/dist/react.d.ts +6 -0
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +4 -1
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +2 -1
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +13 -3
- package/dist/replica.d.ts +3 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +2 -2
- package/dist/room-draft.d.ts +1 -1
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +4 -4
- package/dist/room-drafts.js +2 -2
- package/dist/room-list.d.ts.map +1 -1
- package/dist/room-list.js +2 -0
- package/dist/rows.d.ts +0 -1
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +1 -1
- package/dist/run-tables.d.ts +25 -0
- package/dist/run-tables.d.ts.map +1 -0
- package/dist/run-tables.js +98 -0
- package/dist/runs.d.ts +27 -0
- package/dist/runs.d.ts.map +1 -0
- package/dist/runs.js +92 -0
- package/dist/saves.d.ts +3 -3
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +37 -37
- package/dist/selector.d.ts +3 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +22 -0
- package/dist/socket.d.ts +3 -1
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +7 -0
- package/dist/source.d.ts +17 -0
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +33 -7
- package/dist/store/records.d.ts +8 -3
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +2 -2
- package/dist/store.d.ts +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/stored.d.ts +2 -2
- package/dist/stored.d.ts.map +1 -1
- package/dist/surface.d.ts +7 -1
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +3 -0
- package/dist/tables.d.ts +13 -1
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +15 -1
- package/dist/tallies.js +2 -2
- package/dist/wire.d.ts +1 -0
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +1 -0
- package/package.json +3 -3
- package/dist/binary.d.ts.map +0 -1
- package/dist/reference-forms.d.ts +0 -4
- package/dist/reference-forms.d.ts.map +0 -1
- package/dist/reference-forms.js +0 -74
package/dist/room-draft.js
CHANGED
|
@@ -3,7 +3,7 @@ import { definitionsAt, governing } from './collection.js';
|
|
|
3
3
|
import { runtimeError } from './failure.js';
|
|
4
4
|
import { sha256 } from './digest.js';
|
|
5
5
|
import { declaredType } from './outcome.js';
|
|
6
|
-
import {
|
|
6
|
+
import { attachmentLocalId } from './identity.js';
|
|
7
7
|
import { normalize } from './paths.js';
|
|
8
8
|
export function returnedBy() {
|
|
9
9
|
return { kind: 'withdrawn', code: 'withdrawn', fields: {}, retryable: false };
|
|
@@ -292,7 +292,7 @@ export function underneath(parts, path, visible) {
|
|
|
292
292
|
if (parts.removal !== undefined && markdown !== parts.removal.base)
|
|
293
293
|
report.removal = markdown;
|
|
294
294
|
if (parts.file !== undefined) {
|
|
295
|
-
const file =
|
|
295
|
+
const file = attachmentBase(visible, path);
|
|
296
296
|
if (file !== parts.file.base || markdown !== null)
|
|
297
297
|
report.file = file;
|
|
298
298
|
}
|
|
@@ -300,7 +300,7 @@ export function underneath(parts, path, visible) {
|
|
|
300
300
|
}
|
|
301
301
|
export async function heldFile(blob, base) {
|
|
302
302
|
return {
|
|
303
|
-
localId:
|
|
303
|
+
localId: attachmentLocalId(),
|
|
304
304
|
...(blob instanceof File ? { name: blob.name } : {}),
|
|
305
305
|
byteLength: blob.size,
|
|
306
306
|
mediaType: declaredType(blob),
|
|
@@ -308,7 +308,7 @@ export async function heldFile(blob, base) {
|
|
|
308
308
|
base,
|
|
309
309
|
};
|
|
310
310
|
}
|
|
311
|
-
export function
|
|
311
|
+
export function attachmentBase(visible, path) {
|
|
312
312
|
const binary = visible?.binaries[path];
|
|
313
313
|
if (binary === undefined)
|
|
314
314
|
return null;
|
package/dist/room-drafts.js
CHANGED
|
@@ -5,7 +5,7 @@ import { runtimeError, uncaught } from './failure.js';
|
|
|
5
5
|
import { roomDraftRevision } from './identity.js';
|
|
6
6
|
import { normalize } from './paths.js';
|
|
7
7
|
import { slicing } from './replica.js';
|
|
8
|
-
import {
|
|
8
|
+
import { attachmentBase, gatheredParts, held, heldFile, heldMarks, readParts, staleWrite, underneath, } from './room-draft.js';
|
|
9
9
|
import { stepped } from './turn.js';
|
|
10
10
|
const ROOM_DRAFTS = 'room-drafts';
|
|
11
11
|
const presentationTopic = (app) => `presentation\u0000${app}`;
|
|
@@ -106,7 +106,7 @@ async function writtenRoomDraft({ store }, room, path, revision, input, next) {
|
|
|
106
106
|
const file = parts.file === undefined
|
|
107
107
|
? undefined
|
|
108
108
|
: await heldFile(parts.file.blob, parts.file.base === undefined
|
|
109
|
-
?
|
|
109
|
+
? attachmentBase(await visibleOf(store, room, [path]), path)
|
|
110
110
|
: parts.file.base);
|
|
111
111
|
const kept = held(current?.parts, parts, file);
|
|
112
112
|
const record = {
|
package/dist/room-list.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"room-list.d.ts","sourceRoot":"","sources":["../src/room-list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"room-list.d.ts","sourceRoot":"","sources":["../src/room-list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG1C,eAAO,MAAM,eAAe,cAAc,CAAC;AAE3C,KAAK,cAAc,GAAG,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC;AA2B/D,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvF;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,cAAc,GAAG,SAAS,GACjC,OAAO,CAAC,IAAI,CAAC,CAGf;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,IAAI,CAU5E"}
|
package/dist/room-list.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { uncaught } from './failure.js';
|
|
2
|
+
import { runsListed } from './runs.js';
|
|
2
3
|
export const ROOM_LIST_TOPIC = 'room-list';
|
|
3
4
|
async function kept(runtime, next) {
|
|
4
5
|
const local = await runtime.store.open();
|
|
@@ -8,6 +9,7 @@ async function kept(runtime, next) {
|
|
|
8
9
|
return;
|
|
9
10
|
await local.fact('roomList', listed);
|
|
10
11
|
runtime.store.tell(ROOM_LIST_TOPIC, listed);
|
|
12
|
+
await runsListed(runtime, local, listed);
|
|
11
13
|
}
|
|
12
14
|
function changed(held, change) {
|
|
13
15
|
const named = new Map(change.rooms.map((room) => [room.room_ref, room]));
|
package/dist/rows.d.ts
CHANGED
|
@@ -37,7 +37,6 @@ export declare function documentKey(room: string, path: string): string;
|
|
|
37
37
|
export declare function roomOfKey(key: string): string;
|
|
38
38
|
export declare function roomsOfReach(reach: PlanReach): ReadonlySet<string>;
|
|
39
39
|
export declare function pathOfKey(key: string): string;
|
|
40
|
-
export declare function markdownPath(path: string): boolean;
|
|
41
40
|
export declare function folderOf(path: string): string;
|
|
42
41
|
export declare function writtenFacts(path: string, content: string, composition: Composition): SavedFacts | null;
|
|
43
42
|
export declare function described(path: string, content: string | null, facts: SavedFacts | null): Described;
|
package/dist/rows.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,UAAU,EACf,KAAK,SAAS,EACf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAA4B,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,KAAK,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAEjC,KAAK,QAAQ,GAAG;IACd,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IAC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OAAO,CAAC,CAAC,EACzC,UAAU,EAAE,UAAU,GAAG,SAAS,GACjC,MAAM,EAAE,CAMV;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAiBnF"}
|
package/dist/rows.js
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RunEvent, RunMarks } from './adapter.js';
|
|
2
|
+
import type { Connection } from './tables.js';
|
|
3
|
+
export declare const RUN_TABLES: readonly string[];
|
|
4
|
+
export type RunsAsked = {
|
|
5
|
+
readonly room: string;
|
|
6
|
+
} | {
|
|
7
|
+
readonly sent: true;
|
|
8
|
+
};
|
|
9
|
+
export type RunSight = {
|
|
10
|
+
readonly held: readonly string[];
|
|
11
|
+
readonly searched: readonly string[];
|
|
12
|
+
readonly starter: string | null;
|
|
13
|
+
};
|
|
14
|
+
export type HeldRun = {
|
|
15
|
+
readonly room: string;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly document: string;
|
|
18
|
+
readonly current: boolean;
|
|
19
|
+
};
|
|
20
|
+
export declare function runMarks(connection: Connection): RunMarks;
|
|
21
|
+
export declare function keptRuns(connection: Connection, event: RunEvent): RunMarks | null;
|
|
22
|
+
export declare function heldRuns(connection: Connection, asked: RunsAsked, sight: RunSight): HeldRun[] | null;
|
|
23
|
+
export declare function runsLeft(connection: Connection, sight: RunSight): RunMarks;
|
|
24
|
+
export declare function forgottenRuns(connection: Connection): void;
|
|
25
|
+
//# sourceMappingURL=run-tables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-tables.d.ts","sourceRoot":"","sources":["../src/run-tables.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,QAAQ,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,eAAO,MAAM,UAAU,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, starter TEXT, current INTEGER NOT NULL, sent INTEGER NOT NULL, stale INTEGER NOT NULL, document TEXT NOT NULL) WITHOUT ROWID',
|
|
5
|
+
'CREATE INDEX runs_room ON runs (room, name)',
|
|
6
|
+
'CREATE INDEX runs_starter ON runs (starter, name)',
|
|
7
|
+
'CREATE TABLE run_marks (listing TEXT PRIMARY KEY, mark TEXT, relisting TEXT) WITHOUT ROWID',
|
|
8
|
+
];
|
|
9
|
+
const SENT_LISTING = '';
|
|
10
|
+
const IN_LIST = 'SELECT value FROM json_each(?)';
|
|
11
|
+
function kept(connection, run, sent, listed) {
|
|
12
|
+
connection.run(`INSERT INTO runs (name, room, starter, current, sent, stale, document) VALUES (?, ?, ?, ?, ?, 0, ?)
|
|
13
|
+
ON CONFLICT (name) DO UPDATE SET room = excluded.room, starter = excluded.starter,
|
|
14
|
+
current = excluded.current, stale = 0, document = excluded.document${listed ? ', sent = excluded.sent' : ''}`, [run.name, run.room, run.starter, run.current ? 1 : 0, sent ? 1 : 0, run.document]);
|
|
15
|
+
}
|
|
16
|
+
function ofListing(listing) {
|
|
17
|
+
return listing === null ? 'sent = 1' : 'room = ?';
|
|
18
|
+
}
|
|
19
|
+
function listingBound(listing) {
|
|
20
|
+
return listing === null ? [] : [listing];
|
|
21
|
+
}
|
|
22
|
+
export function runMarks(connection) {
|
|
23
|
+
const rooms = {};
|
|
24
|
+
let sent = null;
|
|
25
|
+
for (const row of connection.rows('SELECT listing, mark FROM run_marks WHERE mark IS NOT NULL ORDER BY listing')) {
|
|
26
|
+
const listing = text(row.listing);
|
|
27
|
+
if (listing === SENT_LISTING)
|
|
28
|
+
sent = text(row.mark);
|
|
29
|
+
else
|
|
30
|
+
rooms[listing] = text(row.mark);
|
|
31
|
+
}
|
|
32
|
+
return { rooms, sent };
|
|
33
|
+
}
|
|
34
|
+
export function keptRuns(connection, event) {
|
|
35
|
+
if (event.kind === 'run') {
|
|
36
|
+
kept(connection, event.run, event.listing === null, false);
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (event.kind === 'removed') {
|
|
40
|
+
connection.run('DELETE FROM runs WHERE name = ?', [event.name]);
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const { listing, runs, whole, more, mark } = event;
|
|
44
|
+
const key = listing ?? SENT_LISTING;
|
|
45
|
+
const [held] = connection.rows('SELECT mark, relisting FROM run_marks WHERE listing = ?', [key]);
|
|
46
|
+
if (whole && (held === undefined || held.relisting !== mark)) {
|
|
47
|
+
connection.run(`UPDATE runs SET stale = 1 WHERE ${ofListing(listing)}`, listingBound(listing));
|
|
48
|
+
connection.run('INSERT INTO run_marks (listing, mark, relisting) VALUES (?, NULL, ?) ON CONFLICT (listing) DO UPDATE SET relisting = excluded.relisting', [key, mark]);
|
|
49
|
+
}
|
|
50
|
+
for (const run of runs)
|
|
51
|
+
kept(connection, run, listing === null, true);
|
|
52
|
+
if (more)
|
|
53
|
+
return null;
|
|
54
|
+
if (whole) {
|
|
55
|
+
connection.run(`DELETE FROM runs WHERE ${ofListing(listing)} AND stale = 1`, listingBound(listing));
|
|
56
|
+
}
|
|
57
|
+
connection.run('INSERT INTO run_marks (listing, mark, relisting) VALUES (?, ?, NULL) ON CONFLICT (listing) DO UPDATE SET mark = excluded.mark, relisting = NULL', [key, mark]);
|
|
58
|
+
return runMarks(connection);
|
|
59
|
+
}
|
|
60
|
+
function listingOf(asked, sight) {
|
|
61
|
+
if ('sent' in asked || sight.searched.includes(asked.room))
|
|
62
|
+
return SENT_LISTING;
|
|
63
|
+
return sight.held.includes(asked.room) ? asked.room : null;
|
|
64
|
+
}
|
|
65
|
+
export function heldRuns(connection, asked, sight) {
|
|
66
|
+
const listing = listingOf(asked, sight);
|
|
67
|
+
if (listing !== null &&
|
|
68
|
+
connection.rows('SELECT 1 FROM run_marks WHERE listing = ? AND mark IS NOT NULL', [listing])
|
|
69
|
+
.length === 0)
|
|
70
|
+
return null;
|
|
71
|
+
const [scope, bound] = 'sent' in asked ? ['starter = ?', sight.starter] : ['room = ?', asked.room];
|
|
72
|
+
return connection
|
|
73
|
+
.rows(`SELECT room, name, current, document FROM runs
|
|
74
|
+
WHERE ${scope} AND (room IN (${IN_LIST}) OR (starter = ? AND room IN (${IN_LIST})))
|
|
75
|
+
ORDER BY name`, [bound, JSON.stringify(sight.held), sight.starter, JSON.stringify(sight.searched)])
|
|
76
|
+
.map((row) => ({
|
|
77
|
+
room: text(row.room),
|
|
78
|
+
name: text(row.name),
|
|
79
|
+
document: text(row.document),
|
|
80
|
+
current: count(row.current) === 1,
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
export function runsLeft(connection, sight) {
|
|
84
|
+
const held = JSON.stringify(sight.held);
|
|
85
|
+
const searched = JSON.stringify(sight.searched);
|
|
86
|
+
connection.run(`DELETE FROM runs WHERE room NOT IN (${IN_LIST})
|
|
87
|
+
AND NOT (coalesce(starter = ?, 0) AND room IN (${IN_LIST}))`, [held, sight.starter, searched]);
|
|
88
|
+
connection.run(`UPDATE runs SET sent = 1 WHERE room IN (${IN_LIST})`, [searched]);
|
|
89
|
+
connection.run(`DELETE FROM run_marks WHERE listing <> ? AND listing NOT IN (${IN_LIST})`, [
|
|
90
|
+
SENT_LISTING,
|
|
91
|
+
held,
|
|
92
|
+
]);
|
|
93
|
+
return runMarks(connection);
|
|
94
|
+
}
|
|
95
|
+
export function forgottenRuns(connection) {
|
|
96
|
+
for (const table of tablesOf(RUN_TABLES))
|
|
97
|
+
connection.run(`DELETE FROM ${table}`);
|
|
98
|
+
}
|
package/dist/runs.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RoomList, RunEvent } from './adapter.js';
|
|
2
|
+
import type { PendingResult } from './query.js';
|
|
3
|
+
import type { RunsAsked } from './run-tables.js';
|
|
4
|
+
import type { Runtime } from './runtime.js';
|
|
5
|
+
import type { RuntimeStore } from './store.js';
|
|
6
|
+
export declare const RUNS_TOPIC = "runs";
|
|
7
|
+
export type RunEntry = {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly document: string;
|
|
10
|
+
};
|
|
11
|
+
export type Runs = {
|
|
12
|
+
readonly current: readonly RunEntry[];
|
|
13
|
+
readonly history: readonly RunEntry[];
|
|
14
|
+
};
|
|
15
|
+
export type HeldRunEntry = RunEntry & {
|
|
16
|
+
readonly room: string;
|
|
17
|
+
};
|
|
18
|
+
export type HeldRuns = {
|
|
19
|
+
readonly current: readonly HeldRunEntry[];
|
|
20
|
+
readonly history: readonly HeldRunEntry[];
|
|
21
|
+
};
|
|
22
|
+
export declare function runsAsked(input: unknown): RunsAsked;
|
|
23
|
+
export declare function watchRuns(runtime: Runtime, input: unknown, deliver: (runs: HeldRuns | PendingResult) => void): () => void;
|
|
24
|
+
export declare function runsOpened(runtime: Runtime): Promise<void>;
|
|
25
|
+
export declare function runHeard(runtime: Runtime, event: RunEvent): void;
|
|
26
|
+
export declare function runsListed(runtime: Runtime, local: RuntimeStore, roomList: RoomList): Promise<void>;
|
|
27
|
+
//# sourceMappingURL=runs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runs.d.ts","sourceRoot":"","sources":["../src/runs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,QAAQ,EAAE,QAAQ,EAAY,MAAM,cAAc,CAAC;AAGzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAW,SAAS,EAAY,MAAM,iBAAiB,CAAC;AACpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,eAAO,MAAM,UAAU,SAAS,CAAC;AAEjC,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5E,MAAM,MAAM,IAAI,GAAG;IACjB,QAAQ,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhE,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,CAAC;IAC1C,QAAQ,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,CAAC;CAC3C,CAAC;AAaF,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAGnD;AA6CD,wBAAgB,SAAS,CACvB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,CAAC,IAAI,EAAE,QAAQ,GAAG,aAAa,KAAK,IAAI,GAChD,MAAM,IAAI,CAcZ;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAGhE;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI,CAMhE;AAED,wBAAsB,UAAU,CAC9B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,IAAI,CAAC,CAMf"}
|
package/dist/runs.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { refusedForSpace } from './durability.js';
|
|
2
|
+
import { uncaught } from './failure.js';
|
|
3
|
+
export const RUNS_TOPIC = 'runs';
|
|
4
|
+
function sightOf(roomList, member) {
|
|
5
|
+
const rooms = roomList?.rooms ?? [];
|
|
6
|
+
return {
|
|
7
|
+
held: rooms.filter((room) => room.level !== 'search').map((room) => room.room_ref),
|
|
8
|
+
searched: rooms.filter((room) => room.level === 'search').map((room) => room.room_ref),
|
|
9
|
+
starter: member?.id ?? null,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function runsAsked(input) {
|
|
13
|
+
const asked = input;
|
|
14
|
+
return asked?.sent === true ? { sent: true } : { room: String(asked?.room) };
|
|
15
|
+
}
|
|
16
|
+
function entryOf({ room, name, document }) {
|
|
17
|
+
return { room, name, document };
|
|
18
|
+
}
|
|
19
|
+
function touches(asked, touched) {
|
|
20
|
+
return touched === null || 'sent' in asked || touched.includes(asked.room);
|
|
21
|
+
}
|
|
22
|
+
function touchedBy(event) {
|
|
23
|
+
if (event.kind === 'run')
|
|
24
|
+
return [event.run.room];
|
|
25
|
+
if (event.kind === 'removed')
|
|
26
|
+
return [event.room];
|
|
27
|
+
if (event.listing !== null)
|
|
28
|
+
return [event.listing];
|
|
29
|
+
return event.whole ? null : event.runs.map((run) => run.room);
|
|
30
|
+
}
|
|
31
|
+
function written(runtime, marks, touched) {
|
|
32
|
+
const { store, socket } = runtime;
|
|
33
|
+
if (marks !== null)
|
|
34
|
+
socket.runs()?.hold(marks);
|
|
35
|
+
store.tell(RUNS_TOPIC, touched);
|
|
36
|
+
}
|
|
37
|
+
function unwritten(error) {
|
|
38
|
+
if (!refusedForSpace(error))
|
|
39
|
+
uncaught(error);
|
|
40
|
+
}
|
|
41
|
+
function unheard(asked) {
|
|
42
|
+
return { pending: 'sent' in asked ? [] : [{ room: asked.room, awaits: 'acquisition' }] };
|
|
43
|
+
}
|
|
44
|
+
async function heldRuns(runtime, asked) {
|
|
45
|
+
const { store } = runtime;
|
|
46
|
+
const { roomList, member } = await (await store.open()).facts(['roomList', 'member']);
|
|
47
|
+
const held = roomList === null
|
|
48
|
+
? null
|
|
49
|
+
: await store.ask({ kind: 'run.held', asked, sight: sightOf(roomList, member) });
|
|
50
|
+
if (held === null)
|
|
51
|
+
return unheard(asked);
|
|
52
|
+
return {
|
|
53
|
+
current: held.filter((run) => run.current).map(entryOf),
|
|
54
|
+
history: held.map(entryOf),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export function watchRuns(runtime, input, deliver) {
|
|
58
|
+
const { store } = runtime;
|
|
59
|
+
const asked = runsAsked(input);
|
|
60
|
+
const answer = () => store.publication(async () => {
|
|
61
|
+
if (!watcher.held())
|
|
62
|
+
return;
|
|
63
|
+
const runs = await heldRuns(runtime, asked);
|
|
64
|
+
if (watcher.held())
|
|
65
|
+
deliver(runs);
|
|
66
|
+
});
|
|
67
|
+
const watcher = store.watch(RUNS_TOPIC, (touched) => {
|
|
68
|
+
if (touches(asked, touched))
|
|
69
|
+
void answer();
|
|
70
|
+
});
|
|
71
|
+
void answer();
|
|
72
|
+
return watcher.stop;
|
|
73
|
+
}
|
|
74
|
+
export async function runsOpened(runtime) {
|
|
75
|
+
const { store, socket } = runtime;
|
|
76
|
+
socket.runs()?.hold(await store.ask({ kind: 'run.marks' }));
|
|
77
|
+
}
|
|
78
|
+
export function runHeard(runtime, event) {
|
|
79
|
+
const { store, socket } = runtime;
|
|
80
|
+
if (socket.closed())
|
|
81
|
+
return;
|
|
82
|
+
void store
|
|
83
|
+
.exclusive(() => store.ask({ kind: 'run.keep', event }))
|
|
84
|
+
.then((marks) => written(runtime, marks, touchedBy(event)), unwritten);
|
|
85
|
+
}
|
|
86
|
+
export async function runsListed(runtime, local, roomList) {
|
|
87
|
+
const { store } = runtime;
|
|
88
|
+
const { member } = await local.facts(['member']);
|
|
89
|
+
await store
|
|
90
|
+
.exclusive(() => store.ask({ kind: 'run.left', sight: sightOf(roomList, member) }))
|
|
91
|
+
.then((marks) => written(runtime, marks, null), unwritten);
|
|
92
|
+
}
|
package/dist/saves.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ChangeBatch, type WrittenBy } from './change.js';
|
|
2
2
|
import type { ConversationFiles } from './conversation.js';
|
|
3
|
-
import { type AttachAnswer, type
|
|
3
|
+
import { type AttachAnswer, type AttachmentLinkAnswer, type HeldAttachmentAnswer, type HeldShownAnswer } from './outcome.js';
|
|
4
4
|
import { type RoomDraftParts } from './room-draft.js';
|
|
5
5
|
import type { Runtime } from './runtime.js';
|
|
6
6
|
import { type SaveRefusal } from './save.js';
|
|
@@ -20,8 +20,8 @@ export type SavedParts = {
|
|
|
20
20
|
readonly parts: RoomDraftParts;
|
|
21
21
|
};
|
|
22
22
|
export type AttachmentSurface = {
|
|
23
|
-
read(room: string, path: string, revision?: string): Promise<
|
|
24
|
-
link(room: string, path: string, revision?: string): Promise<
|
|
23
|
+
read(room: string, path: string, revision?: string): Promise<HeldAttachmentAnswer>;
|
|
24
|
+
link(room: string, path: string, revision?: string): Promise<AttachmentLinkAnswer>;
|
|
25
25
|
show(room: string, path: string, revision?: string): Promise<HeldShownAnswer>;
|
|
26
26
|
attach(room: string, file: File): Promise<AttachAnswer>;
|
|
27
27
|
part(file: string, part: number): Promise<Uint8Array | null>;
|
package/dist/saves.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"saves.d.ts","sourceRoot":"","sources":["../src/saves.ts"],"names":[],"mappings":"AAUA,OAAO,EAA2B,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAKxF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAI3D,OAAO,EASL,KAAK,YAAY,EACjB,KAAK,
|
|
1
|
+
{"version":3,"file":"saves.d.ts","sourceRoot":"","sources":["../src/saves.ts"],"names":[],"mappings":"AAUA,OAAO,EAA2B,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAKxF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAI3D,OAAO,EASL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EAGzB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACrB,MAAM,cAAc,CAAC;AAatB,OAAO,EAQL,KAAK,cAAc,EAGpB,MAAM,iBAAiB,CAAC;AAGzB,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AAYF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,SAAS,EAAE,SAAS,GAAG,SAAS,GAC/B,OAAO,CAAC,UAAU,CAAC,CAsCrB;AAuBD,wBAAgB,SAAS,CACvB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,SAAS,EAAE,SAAS,GAAG,SAAS,GAC/B,OAAO,CAAC,UAAU,CAAC,CAyBrB;AAuOD,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAK9F;AA+RD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,CAKrE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,CAQrE"}
|
package/dist/saves.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isImageType, parse } from '@agentshouse/mdmodel';
|
|
2
|
-
import {
|
|
2
|
+
import { attachmentRecord } from './attachment.js';
|
|
3
3
|
import { changeSet } from './change-set.js';
|
|
4
4
|
import { queuedFile } from './change.js';
|
|
5
5
|
import { available, definitionsAt, typeAt } from './collection.js';
|
|
@@ -8,13 +8,13 @@ import { attachedFile } from './file.js';
|
|
|
8
8
|
import { roomDraftRevision } from './identity.js';
|
|
9
9
|
import { compositionFor } from './listing.js';
|
|
10
10
|
import { scoped } from './models.js';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { absentAttachment, attachAnswer, attachmentAnswer, attachmentLinkAnswer, failure, linkedAnswer, OFFLINE, UNCERTAIN, } from './outcome.js';
|
|
12
|
+
import { sameAttachment } from './overlay.js';
|
|
13
13
|
import { ancestors } from './paths.js';
|
|
14
14
|
import { connectionNow } from './preparation.js';
|
|
15
15
|
import { append, sliceAt, withdrawable } from './queue.js';
|
|
16
16
|
import { entryAt, replaying, slicing, } from './replica.js';
|
|
17
|
-
import {
|
|
17
|
+
import { attachmentBase, changesOf, held, heldFile, joinedOver, moveTarget, readSavedParts, } from './room-draft.js';
|
|
18
18
|
import { refuse } from './refusal.js';
|
|
19
19
|
import { visibleOf } from './room-drafts.js';
|
|
20
20
|
import { destination, planSave, } from './save.js';
|
|
@@ -77,7 +77,7 @@ export function saveParts(runtime, locator, named, writtenBy) {
|
|
|
77
77
|
for (const { path, parts } of read) {
|
|
78
78
|
const file = parts.file === undefined
|
|
79
79
|
? undefined
|
|
80
|
-
: await heldFile(parts.file.blob, parts.file.base === undefined ?
|
|
80
|
+
: await heldFile(parts.file.blob, parts.file.base === undefined ? attachmentBase(visible, path) : parts.file.base);
|
|
81
81
|
if (parts.file !== undefined && file !== undefined) {
|
|
82
82
|
files.push({ key: file.localId, blob: parts.file.blob });
|
|
83
83
|
}
|
|
@@ -159,7 +159,7 @@ async function loaded(runtime, locator, replica, saved, consumed, files, written
|
|
|
159
159
|
}
|
|
160
160
|
function textDiffers(left, right) {
|
|
161
161
|
return ((left?.content ?? undefined) !== (right?.content ?? undefined) ||
|
|
162
|
-
!
|
|
162
|
+
!sameAttachment(left?.binary ?? undefined, right?.binary ?? undefined));
|
|
163
163
|
}
|
|
164
164
|
function textOf(entry) {
|
|
165
165
|
if (entry === null)
|
|
@@ -251,7 +251,7 @@ export function batchFile(store, batch) {
|
|
|
251
251
|
return (await store.open()).file(localId, change?.kind === 'binary' ? change.mediaType : '');
|
|
252
252
|
};
|
|
253
253
|
}
|
|
254
|
-
async function
|
|
254
|
+
async function transferAttachment(runtime, request, transfer, answer) {
|
|
255
255
|
const { store, socket, presence } = runtime;
|
|
256
256
|
const { session } = socket;
|
|
257
257
|
if (socket.closed() || session.now().refusal !== null)
|
|
@@ -287,19 +287,19 @@ async function transferBinary(runtime, request, transfer, answer) {
|
|
|
287
287
|
return UNCERTAIN;
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
|
-
function
|
|
290
|
+
function fetchAttachment(runtime, request, name) {
|
|
291
291
|
const { store, socket } = runtime;
|
|
292
|
-
return
|
|
292
|
+
return transferAttachment(runtime, request, (authorization) => store.opened.fetch(name, () => socket.binary(authorization, request)), attachmentAnswer);
|
|
293
293
|
}
|
|
294
|
-
async function
|
|
294
|
+
async function readAttachment(runtime, request, name) {
|
|
295
295
|
if (runtime.socket.closed())
|
|
296
296
|
return UNCERTAIN;
|
|
297
297
|
const held = await runtime.store.opened.find(name);
|
|
298
298
|
if (held !== null)
|
|
299
299
|
return held;
|
|
300
|
-
return
|
|
300
|
+
return fetchAttachment(runtime, request, name);
|
|
301
301
|
}
|
|
302
|
-
async function
|
|
302
|
+
async function attachmentPath(store, locator, path, revision) {
|
|
303
303
|
if (revision !== undefined)
|
|
304
304
|
return { kind: 'path', locator, path, revision };
|
|
305
305
|
const replica = await store.replica(locator);
|
|
@@ -312,7 +312,7 @@ async function binaryPath(store, locator, path, revision) {
|
|
|
312
312
|
return null;
|
|
313
313
|
if (held.binary.state === 'pending')
|
|
314
314
|
return { kind: 'pending', localId: held.binary.localId };
|
|
315
|
-
const record =
|
|
315
|
+
const record = attachmentRecord(path, held.binary, held.revision ?? undefined);
|
|
316
316
|
if (record.state !== 'accepted')
|
|
317
317
|
return null;
|
|
318
318
|
const queued = replica.queue.flatMap((batch) => batch.changes);
|
|
@@ -340,17 +340,17 @@ async function binaryPath(store, locator, path, revision) {
|
|
|
340
340
|
revision: record.revision,
|
|
341
341
|
};
|
|
342
342
|
}
|
|
343
|
-
async function
|
|
343
|
+
async function askedAttachment({ store, socket }, locator, path, revision) {
|
|
344
344
|
await socket.ready;
|
|
345
345
|
const drafted = (await store.draft(locator, path))?.parts.file;
|
|
346
346
|
return drafted !== undefined && drafted.localId === revision
|
|
347
347
|
? { kind: 'pending', localId: revision }
|
|
348
|
-
:
|
|
348
|
+
: attachmentPath(store, locator, path, revision);
|
|
349
349
|
}
|
|
350
|
-
async function
|
|
350
|
+
async function pendingAttachment(store, locator, path, localId) {
|
|
351
351
|
const facts = await queuedFacts(store, locator, path, localId);
|
|
352
352
|
return facts === null
|
|
353
|
-
?
|
|
353
|
+
? absentAttachment(path)
|
|
354
354
|
: {
|
|
355
355
|
kind: 'binary',
|
|
356
356
|
file: localId,
|
|
@@ -358,13 +358,13 @@ async function pendingBinary(store, locator, path, localId) {
|
|
|
358
358
|
mediaType: facts.mediaType,
|
|
359
359
|
};
|
|
360
360
|
}
|
|
361
|
-
async function
|
|
362
|
-
const asked = await
|
|
361
|
+
async function readAttachmentPath(runtime, locator, path, revision) {
|
|
362
|
+
const asked = await askedAttachment(runtime, locator, path, revision);
|
|
363
363
|
if (asked === null)
|
|
364
|
-
return
|
|
364
|
+
return absentAttachment(path);
|
|
365
365
|
if (asked.kind === 'pending')
|
|
366
|
-
return
|
|
367
|
-
return
|
|
366
|
+
return pendingAttachment(runtime.store, locator, path, asked.localId);
|
|
367
|
+
return readAttachment(runtime, asked, { locator, path: asked.path, revision: asked.revision });
|
|
368
368
|
}
|
|
369
369
|
async function heldMediaType(store, locator, path) {
|
|
370
370
|
const replica = await store.record(locator);
|
|
@@ -372,20 +372,20 @@ async function heldMediaType(store, locator, path) {
|
|
|
372
372
|
return held === undefined ? store.attached.of(locator, path)?.mediaType : held.binary?.mediaType;
|
|
373
373
|
}
|
|
374
374
|
function linkOf(runtime, asked, held) {
|
|
375
|
-
return
|
|
375
|
+
return transferAttachment(runtime, asked, (authorization) => runtime.socket.link(authorization, asked), (result) => attachmentLinkAnswer(result, held));
|
|
376
376
|
}
|
|
377
|
-
async function
|
|
377
|
+
async function linkAttachmentPath(runtime, locator, path, revision) {
|
|
378
378
|
const { store, socket } = runtime;
|
|
379
379
|
await socket.ready;
|
|
380
|
-
const asked = await
|
|
380
|
+
const asked = await attachmentPath(store, locator, path, revision);
|
|
381
381
|
if (asked === null || asked.kind === 'pending')
|
|
382
|
-
return
|
|
382
|
+
return absentAttachment(path);
|
|
383
383
|
return linkOf(runtime, asked, revision === undefined ? await heldMediaType(store, locator, path) : undefined);
|
|
384
384
|
}
|
|
385
385
|
function shownImage(runtime, asked, name) {
|
|
386
386
|
const { store, socket } = runtime;
|
|
387
387
|
return new Promise((answer) => {
|
|
388
|
-
void
|
|
388
|
+
void transferAttachment(runtime, asked, (authorization) => store.opened.fetch(name, async () => {
|
|
389
389
|
const read = await socket.binary(authorization, asked);
|
|
390
390
|
const copies = read.kind === 'binary' ? (read.copies ?? []) : [];
|
|
391
391
|
if (read.kind === 'binary' && read.url !== undefined && copies.length > 0) {
|
|
@@ -398,16 +398,16 @@ function shownImage(runtime, asked, name) {
|
|
|
398
398
|
});
|
|
399
399
|
}
|
|
400
400
|
return read;
|
|
401
|
-
}),
|
|
401
|
+
}), attachmentAnswer).then(answer);
|
|
402
402
|
});
|
|
403
403
|
}
|
|
404
|
-
async function
|
|
404
|
+
async function showAttachmentPath(runtime, locator, path, revision) {
|
|
405
405
|
const { store } = runtime;
|
|
406
|
-
const asked = await
|
|
406
|
+
const asked = await askedAttachment(runtime, locator, path, revision);
|
|
407
407
|
if (asked === null)
|
|
408
|
-
return
|
|
408
|
+
return absentAttachment(path);
|
|
409
409
|
if (asked.kind === 'pending')
|
|
410
|
-
return
|
|
410
|
+
return pendingAttachment(store, locator, path, asked.localId);
|
|
411
411
|
if (runtime.socket.closed())
|
|
412
412
|
return UNCERTAIN;
|
|
413
413
|
const name = { locator, path: asked.path, revision: asked.revision };
|
|
@@ -430,7 +430,7 @@ async function attachFile(runtime, locator, file, answer) {
|
|
|
430
430
|
socket.session.now().refusal !== null)
|
|
431
431
|
return OFFLINE;
|
|
432
432
|
const request = await attachedFile(locator, file);
|
|
433
|
-
return
|
|
433
|
+
return transferAttachment(runtime, { locator }, async (held) => {
|
|
434
434
|
const result = await socket.attach(held, request);
|
|
435
435
|
if (result.kind === 'attached' && locator !== null) {
|
|
436
436
|
store.attached.hold(locator, result.path, {
|
|
@@ -444,7 +444,7 @@ async function attachFile(runtime, locator, file, answer) {
|
|
|
444
444
|
async function keyedAttachment(runtime, link) {
|
|
445
445
|
await runtime.socket.ready;
|
|
446
446
|
const asked = { kind: 'key', link };
|
|
447
|
-
return
|
|
447
|
+
return transferAttachment(runtime, { locator: null }, (authorization) => runtime.socket.link(authorization, asked), (result) => attachmentLinkAnswer(result));
|
|
448
448
|
}
|
|
449
449
|
export function conversationFiles(runtime) {
|
|
450
450
|
return {
|
|
@@ -455,9 +455,9 @@ export function conversationFiles(runtime) {
|
|
|
455
455
|
export function attachmentSurface(runtime) {
|
|
456
456
|
return {
|
|
457
457
|
part: runtime.store.part,
|
|
458
|
-
read: (room, path, revision) =>
|
|
459
|
-
link: (room, path, revision) =>
|
|
460
|
-
show: (room, path, revision) =>
|
|
458
|
+
read: (room, path, revision) => readAttachmentPath(runtime, room, path, revision),
|
|
459
|
+
link: (room, path, revision) => linkAttachmentPath(runtime, room, path, revision),
|
|
460
|
+
show: (room, path, revision) => showAttachmentPath(runtime, room, path, revision),
|
|
461
461
|
attach: (room, file) => attachFile(runtime, room, file, attachAnswer),
|
|
462
462
|
};
|
|
463
463
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selector.d.ts","sourceRoot":"","sources":["../src/selector.ts"],"names":[],"mappings":"AAaA,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,OAAO,GACtC,OAAO,CAET;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,OAAO,EAAE,CAOnF"}
|
package/dist/selector.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function rewrittenAt(value, members, rewrite) {
|
|
2
|
+
if (Array.isArray(value))
|
|
3
|
+
return value.map((one) => rewrittenAt(one, members, rewrite));
|
|
4
|
+
const [member, ...rest] = members;
|
|
5
|
+
if (member === undefined)
|
|
6
|
+
return rewrite(value);
|
|
7
|
+
if (value === null || typeof value !== 'object' || !Object.hasOwn(value, member))
|
|
8
|
+
return value;
|
|
9
|
+
const held = value;
|
|
10
|
+
return { ...held, [member]: rewrittenAt(held[member], rest, rewrite) };
|
|
11
|
+
}
|
|
12
|
+
export function selectorRewritten(value, selector, rewrite) {
|
|
13
|
+
return rewrittenAt(value, selector.split('.'), rewrite);
|
|
14
|
+
}
|
|
15
|
+
export function selectorValues(value, selector) {
|
|
16
|
+
const selected = [];
|
|
17
|
+
selectorRewritten(value, selector, (one) => {
|
|
18
|
+
selected.push(one);
|
|
19
|
+
return one;
|
|
20
|
+
});
|
|
21
|
+
return selected;
|
|
22
|
+
}
|