@agentshouse/mdruntime 0.1.0-c6bf34fa9e444 → 0.1.0-c6d3d5d8beeb0
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 +21 -19
- package/dist/acceptance.d.ts +0 -3
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +105 -166
- package/dist/act-lanes.d.ts +30 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +225 -0
- package/dist/actions.d.ts +8 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +180 -85
- package/dist/adapter.d.ts +222 -73
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +0 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +2 -7
- package/dist/{binary.d.ts → attachment.d.ts} +8 -4
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +15 -0
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +345 -0
- package/dist/bootstrap.d.ts +1 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +6 -18
- package/dist/chain.d.ts +1 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +5 -2
- 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 +6 -2
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +7 -2
- package/dist/chat-types.d.ts +0 -2
- package/dist/chat-types.d.ts.map +1 -1
- package/dist/chat-types.js +2 -4
- package/dist/client.d.ts +30 -23
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +55 -68
- package/dist/collection.d.ts +27 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +34 -10
- package/dist/column.d.ts +5 -0
- package/dist/column.d.ts.map +1 -0
- package/dist/column.js +9 -0
- package/dist/compile.d.ts +4 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +101 -63
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +45 -28
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +150 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +260 -0
- package/dist/conversation-row.d.ts +23 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +39 -4
- package/dist/conversation.d.ts +67 -49
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +993 -1032
- 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 +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +47 -47
- package/dist/download.d.ts +6 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +42 -0
- package/dist/durability.d.ts +5 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +26 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +126 -36
- package/dist/expectation.d.ts +26 -13
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +72 -19
- package/dist/failure.d.ts +3 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +8 -0
- package/dist/figures.d.ts +2 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +8 -6
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -2
- package/dist/host.d.ts +24 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +108 -32
- package/dist/house-query.d.ts +24 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +102 -0
- 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 +30 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -8
- package/dist/install.d.ts +10 -6
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +93 -116
- package/dist/lifecycle.d.ts +2 -2
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +81 -56
- package/dist/linked-file.d.ts +7 -0
- package/dist/linked-file.d.ts.map +1 -0
- package/dist/linked-file.js +16 -0
- package/dist/listing.d.ts +29 -22
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +71 -78
- package/dist/live.d.ts +19 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +97 -39
- package/dist/loaded.d.ts +7 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +46 -0
- package/dist/locks.d.ts +2 -4
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +12 -39
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +11 -23
- package/dist/media.d.ts +20 -4
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +184 -37
- package/dist/memory.d.ts +10 -4
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +103 -40
- package/dist/messages.d.ts +21 -6
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +54 -42
- package/dist/modal.d.ts +2 -0
- package/dist/modal.d.ts.map +1 -0
- package/dist/modal.js +11 -0
- package/dist/model.d.ts +10 -8
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -5
- package/dist/models.d.ts +4 -8
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +97 -137
- package/dist/name.d.ts +0 -1
- package/dist/name.d.ts.map +1 -1
- package/dist/name.js +3 -7
- package/dist/observation.d.ts +29 -12
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +217 -85
- package/dist/online.d.ts +7 -0
- package/dist/online.d.ts.map +1 -0
- package/dist/online.js +29 -0
- package/dist/opened.d.ts +6 -6
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +7 -7
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +26 -11
- package/dist/outcome.d.ts +33 -13
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +36 -6
- package/dist/overlay.d.ts +23 -8
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +132 -48
- 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 +6 -58
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +28 -110
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +22 -0
- package/dist/preparation.d.ts +33 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +210 -92
- package/dist/presence.d.ts +58 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +231 -0
- package/dist/queries.d.ts +2 -2
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +138 -80
- package/dist/query.d.ts +2 -3
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +3 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +6 -7
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +482 -0
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +200 -40
- package/dist/react.d.ts +21 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +33 -1
- package/dist/readiness.d.ts +23 -5
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +18 -10
- package/dist/reads.d.ts +5 -2
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +64 -11
- package/dist/recovery.d.ts +4 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +31 -8
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +6 -6
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +5 -6
- package/dist/replica.d.ts +6 -16
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +20 -21
- 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 +32 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +282 -72
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +29 -23
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +47 -0
- package/dist/rows.d.ts +11 -3
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +28 -15
- 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/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runs.d.ts +27 -0
- package/dist/runs.d.ts.map +1 -0
- package/dist/runs.js +92 -0
- package/dist/runtime.d.ts +16 -21
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +43 -86
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +337 -232
- package/dist/saves.d.ts +9 -45
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +208 -748
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +4 -5
- package/dist/selector.d.ts +3 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +22 -0
- package/dist/shared.d.ts +1 -6
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -95
- package/dist/shown.d.ts +10 -6
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +108 -75
- package/dist/socket/lanes.d.ts +12 -4
- package/dist/socket/lanes.d.ts.map +1 -1
- package/dist/socket/lanes.js +34 -8
- package/dist/socket/session.d.ts +4 -2
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket/session.js +3 -0
- package/dist/socket.d.ts +7 -7
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +13 -16
- package/dist/source.d.ts +42 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +81 -13
- package/dist/store/installs.d.ts +2 -2
- package/dist/store/installs.d.ts.map +1 -1
- package/dist/store/installs.js +10 -4
- package/dist/store/readiness.d.ts +5 -4
- package/dist/store/readiness.d.ts.map +1 -1
- package/dist/store/readiness.js +28 -12
- package/dist/store/records.d.ts +33 -11
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +94 -28
- package/dist/store/rooms-shown.d.ts +8 -0
- package/dist/store/rooms-shown.d.ts.map +1 -0
- package/dist/store/rooms-shown.js +13 -0
- 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 +26 -16
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +50 -18
- package/dist/stored.d.ts +42 -17
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +236 -66
- package/dist/surface.d.ts +21 -9
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +74 -38
- package/dist/sync.d.ts +4 -3
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +136 -110
- package/dist/tables.d.ts +43 -58
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +114 -334
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +8 -9
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +51 -11
- package/dist/wire.d.ts +72 -12
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +31 -14
- package/package.json +4 -3
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
- package/dist/job.d.ts +0 -33
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -54
- package/dist/log.d.ts +0 -6
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/socket/rooms.d.ts +0 -43
- 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/readiness.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
const
|
|
1
|
+
export const INBOXES_READ = 'inbox';
|
|
2
|
+
export const INBOXES_LISTED = { op: 'list' };
|
|
3
|
+
export const COMPLETE_ROOMS = new Set(['complete', 'unadmitted']);
|
|
4
|
+
export function inboxRooms({ answer }) {
|
|
5
|
+
if (answer === null)
|
|
6
|
+
return null;
|
|
7
|
+
const { inboxes } = answer;
|
|
8
|
+
return [...new Set(inboxes.flatMap(({ room }) => (room === undefined ? [] : [room])))].sort();
|
|
9
|
+
}
|
|
10
|
+
function held({ listed, conversations, unsettled }) {
|
|
11
|
+
return (listed && (conversations === 'complete' || conversations === 'undeclared') && unsettled === 0);
|
|
12
|
+
}
|
|
2
13
|
export function readinessOf(facts) {
|
|
3
|
-
const { established, coverage:
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const stored = facts.code === 'stored';
|
|
10
|
-
const ready = stored && complete;
|
|
11
|
-
const usable = stored && (ready || established);
|
|
14
|
+
const { established, first, coverage: whole, ...reported } = facts;
|
|
15
|
+
const complete = held(whole);
|
|
16
|
+
const coverage = { listed: whole.listed, conversations: whole.conversations, complete };
|
|
17
|
+
const ready = facts.code === 'stored' && complete;
|
|
18
|
+
const boot = facts.code === 'boot' || facts.code === 'stored';
|
|
19
|
+
const usable = ready || (boot && (held(first) || established));
|
|
12
20
|
const status = ready
|
|
13
21
|
? 'ready'
|
|
14
22
|
: facts.space !== null
|
package/dist/reads.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type CallResult } from './outcome.js';
|
|
2
2
|
import type { Recovery } from './recovery.js';
|
|
3
|
+
import type { Attempt, Retries } from './retried.js';
|
|
3
4
|
import type { Connection, RuntimeDatabase } from './tables.js';
|
|
4
5
|
export declare const READ_TABLES: readonly string[];
|
|
5
6
|
export type ReadAt = {
|
|
@@ -14,7 +15,7 @@ export type ObservedRead = {
|
|
|
14
15
|
};
|
|
15
16
|
export type ReadAnswers = {
|
|
16
17
|
watch(name: string, input: unknown, deliver: (read: ObservedRead) => void): () => void;
|
|
17
|
-
again(): void;
|
|
18
|
+
again(led?: Promise<unknown>): void;
|
|
18
19
|
reopened(): void;
|
|
19
20
|
};
|
|
20
21
|
export type ReadAnswersOptions = {
|
|
@@ -23,8 +24,10 @@ export type ReadAnswersOptions = {
|
|
|
23
24
|
readonly unkept: readonly string[];
|
|
24
25
|
readonly leading: readonly string[];
|
|
25
26
|
readonly recovery: Recovery;
|
|
26
|
-
|
|
27
|
+
readonly retries: Retries;
|
|
28
|
+
call(name: string, input: unknown, attempt: Attempt): Promise<CallResult>;
|
|
27
29
|
online(): boolean;
|
|
30
|
+
streaming(): boolean;
|
|
28
31
|
closed(): boolean;
|
|
29
32
|
full(): boolean;
|
|
30
33
|
filled(): void;
|
package/dist/reads.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reads.d.ts","sourceRoot":"","sources":["../src/reads.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reads.d.ts","sourceRoot":"","sources":["../src/reads.ts"],"names":[],"mappings":"AAEA,OAAO,EAA6B,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE/D,eAAO,MAAM,WAAW,EAAE,SAAS,MAAM,EAExC,CAAC;AAEF,MAAM,MAAM,MAAM,GA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,wBAAgB,UAAU,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMhG;AAED,wBAAgB,QAAQ,CACtB,UAAU,EAAE,UAAU,EACtB,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,MAAM,EAC9B,MAAM,EAAE,MAAM,GACb,IAAI,CAMN;AAED,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAGvF;AAMD,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAwKpE"}
|
package/dist/reads.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { refusedForSpace } from './durability.js';
|
|
2
|
+
import { uncaught } from './failure.js';
|
|
2
3
|
import { answeredResult, UNCERTAIN } from './outcome.js';
|
|
3
4
|
export const READ_TABLES = [
|
|
4
5
|
'CREATE TABLE read_answers (name TEXT NOT NULL, input TEXT NOT NULL, build TEXT NOT NULL, answer TEXT NOT NULL, PRIMARY KEY (name, input)) WITHOUT ROWID',
|
|
@@ -24,19 +25,32 @@ export function readAnswers(options) {
|
|
|
24
25
|
const leading = new Set(options.leading);
|
|
25
26
|
const reads = new Map();
|
|
26
27
|
function leads(read) {
|
|
27
|
-
|
|
28
|
+
const op = read.asked?.op;
|
|
29
|
+
return (leading.has(read.at.name) || (typeof op === 'string' && leading.has(`${read.at.name}.${op}`)));
|
|
30
|
+
}
|
|
31
|
+
function kept(name, input) {
|
|
32
|
+
if (unkept.has(name))
|
|
33
|
+
return false;
|
|
34
|
+
const { op, ...named } = (input ?? {});
|
|
35
|
+
if (typeof op !== 'string')
|
|
36
|
+
return true;
|
|
37
|
+
const opName = `${name}.${op}`;
|
|
38
|
+
return (!unkept.has(opName) &&
|
|
39
|
+
!Object.keys(named).some((field) => named[field] !== undefined && unkept.has(`${opName} ${field}`)));
|
|
28
40
|
}
|
|
29
41
|
function show(read, shown) {
|
|
30
42
|
read.shown = shown;
|
|
31
43
|
for (const deliver of read.observers)
|
|
32
44
|
deliver(shown);
|
|
33
45
|
}
|
|
34
|
-
async function
|
|
46
|
+
async function keep(read, answer) {
|
|
35
47
|
if (!read.shown.kept || options.full())
|
|
36
48
|
return;
|
|
37
49
|
await database.ask({ kind: 'read.keep', ...read.at, answer }).catch((error) => {
|
|
38
50
|
if (refusedForSpace(error))
|
|
39
51
|
options.filled();
|
|
52
|
+
else
|
|
53
|
+
uncaught(error);
|
|
40
54
|
});
|
|
41
55
|
}
|
|
42
56
|
async function asked(read, led) {
|
|
@@ -44,7 +58,11 @@ export function readAnswers(options) {
|
|
|
44
58
|
read.owed = true;
|
|
45
59
|
return;
|
|
46
60
|
}
|
|
47
|
-
const
|
|
61
|
+
const attempt = { step: 'reading', instance: read.key };
|
|
62
|
+
const result = await options.call(read.at.name, read.asked, attempt).catch((error) => {
|
|
63
|
+
options.retries.failed(attempt.step, attempt.instance, error);
|
|
64
|
+
return UNCERTAIN;
|
|
65
|
+
});
|
|
48
66
|
if (options.closed())
|
|
49
67
|
return;
|
|
50
68
|
read.owed = !answered(result);
|
|
@@ -57,23 +75,52 @@ export function readAnswers(options) {
|
|
|
57
75
|
if (text === read.text && read.shown.failure === null)
|
|
58
76
|
return;
|
|
59
77
|
read.text = text;
|
|
60
|
-
await
|
|
78
|
+
await keep(read, text);
|
|
61
79
|
await led;
|
|
62
80
|
if (!options.closed())
|
|
63
81
|
show(read, { ...read.shown, answer, failure: null });
|
|
64
82
|
}
|
|
83
|
+
function lost(read) {
|
|
84
|
+
return read.owed && read.shown.failure?.kind === 'transport-uncertainty' && options.streaming();
|
|
85
|
+
}
|
|
86
|
+
function retrying(read) {
|
|
87
|
+
return `${read.key} again`;
|
|
88
|
+
}
|
|
89
|
+
function askedLater(read) {
|
|
90
|
+
void recovery.attempt(retrying(read), async () => {
|
|
91
|
+
if (options.closed() || read.observers.size === 0 || !lost(read))
|
|
92
|
+
return 'done';
|
|
93
|
+
await attempted(read);
|
|
94
|
+
return lost(read) ? 'again' : 'done';
|
|
95
|
+
}, { again: true });
|
|
96
|
+
}
|
|
65
97
|
function forgotten(read) {
|
|
66
98
|
read.text = null;
|
|
67
99
|
read.shown = { ...read.shown, answer: null, failure: null };
|
|
68
100
|
}
|
|
69
|
-
function
|
|
70
|
-
|
|
101
|
+
function attempted(read, led) {
|
|
102
|
+
read.asking = true;
|
|
103
|
+
return recovery
|
|
104
|
+
.attempt(read.key, async () => {
|
|
71
105
|
await asked(read, led);
|
|
72
106
|
return 'done';
|
|
107
|
+
})
|
|
108
|
+
.finally(() => {
|
|
109
|
+
const unanswered = read.joined && read.owed;
|
|
110
|
+
read.asking = false;
|
|
111
|
+
read.joined = false;
|
|
112
|
+
if (unanswered)
|
|
113
|
+
void ask(read);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function ask(read, led) {
|
|
117
|
+
return attempted(read, led).finally(() => {
|
|
118
|
+
if (lost(read))
|
|
119
|
+
askedLater(read);
|
|
73
120
|
});
|
|
74
121
|
}
|
|
75
122
|
function opened(name, input, key) {
|
|
76
|
-
const held =
|
|
123
|
+
const held = kept(name, input);
|
|
77
124
|
const read = {
|
|
78
125
|
key,
|
|
79
126
|
at: { name, input: JSON.stringify(input ?? null), build },
|
|
@@ -83,6 +130,8 @@ export function readAnswers(options) {
|
|
|
83
130
|
text: null,
|
|
84
131
|
shown: { answer: null, failure: null, kept: held },
|
|
85
132
|
owed: false,
|
|
133
|
+
asking: false,
|
|
134
|
+
joined: false,
|
|
86
135
|
};
|
|
87
136
|
if (held) {
|
|
88
137
|
read.stored = database.ask({ kind: 'read.stored', ...read.at }).then((text) => {
|
|
@@ -90,7 +139,7 @@ export function readAnswers(options) {
|
|
|
90
139
|
return;
|
|
91
140
|
read.text = text;
|
|
92
141
|
read.shown = { ...read.shown, answer: JSON.parse(text) };
|
|
93
|
-
},
|
|
142
|
+
}, uncaught);
|
|
94
143
|
}
|
|
95
144
|
reads.set(key, read);
|
|
96
145
|
return read;
|
|
@@ -106,7 +155,10 @@ export function readAnswers(options) {
|
|
|
106
155
|
if (!read.shown.kept)
|
|
107
156
|
forgotten(read);
|
|
108
157
|
deliver(read.shown);
|
|
109
|
-
|
|
158
|
+
if (read.asking)
|
|
159
|
+
read.joined = true;
|
|
160
|
+
else
|
|
161
|
+
void ask(read);
|
|
110
162
|
});
|
|
111
163
|
return () => {
|
|
112
164
|
read.observers.delete(deliver);
|
|
@@ -114,15 +166,16 @@ export function readAnswers(options) {
|
|
|
114
166
|
reads.delete(key);
|
|
115
167
|
};
|
|
116
168
|
},
|
|
117
|
-
again() {
|
|
169
|
+
again(first = Promise.resolve()) {
|
|
118
170
|
const all = [...reads.values()];
|
|
119
|
-
const led = Promise.all(all.filter(leads).map((read) => ask(read)));
|
|
171
|
+
const led = Promise.all([first, ...all.filter(leads).map((read) => ask(read, first))]);
|
|
120
172
|
for (const read of all)
|
|
121
173
|
if (!leads(read))
|
|
122
174
|
void ask(read, led);
|
|
123
175
|
},
|
|
124
176
|
reopened() {
|
|
125
177
|
for (const read of reads.values()) {
|
|
178
|
+
recovery.cancel(retrying(read));
|
|
126
179
|
if (read.text === null) {
|
|
127
180
|
if (read.owed)
|
|
128
181
|
void ask(read);
|
package/dist/recovery.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export type Attempt = (signal: AbortSignal) => Promise<Attempted>;
|
|
|
5
5
|
export type AttemptOptions = {
|
|
6
6
|
readonly at?: number;
|
|
7
7
|
readonly again?: boolean;
|
|
8
|
+
readonly attempts?: number;
|
|
8
9
|
};
|
|
9
10
|
export type RecoveryOptions = {
|
|
10
11
|
readonly firstMs?: number;
|
|
@@ -16,11 +17,13 @@ export type Recovery = {
|
|
|
16
17
|
attempt(intent: string, run: Attempt, options?: AttemptOptions): Promise<boolean>;
|
|
17
18
|
pending(intent: string): boolean;
|
|
18
19
|
resume(): void;
|
|
20
|
+
again(): void;
|
|
21
|
+
waits(wake: () => void): () => void;
|
|
19
22
|
cancel(intent: string): void;
|
|
20
23
|
scope(inFlight?: number): Recovery;
|
|
21
24
|
retire(): Promise<void>;
|
|
22
25
|
};
|
|
23
26
|
export declare function retryDelay(tries: number, firstMs?: number, maxMs?: number): number;
|
|
24
|
-
export declare function untilAnswered<T>(ask: () => Promise<T>, signal: AbortSignal, answered?: (answer: T) => boolean): Promise<T>;
|
|
27
|
+
export declare function untilAnswered<T>(ask: () => Promise<T>, signal: AbortSignal, answered?: (answer: T) => boolean, owner?: Recovery): Promise<T>;
|
|
25
28
|
export declare function createRecovery(options?: RecoveryOptions): Recovery;
|
|
26
29
|
//# sourceMappingURL=recovery.d.ts.map
|
package/dist/recovery.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../src/recovery.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnE,MAAM,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;AAElE,MAAM,MAAM,cAAc,GAAG;
|
|
1
|
+
{"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../src/recovery.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnE,MAAM,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;AAElE,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAA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@@ -7,7 +7,7 @@ export function retryDelay(tries, firstMs = FIRST_MS, maxMs = MAX_MS) {
|
|
|
7
7
|
const longest = Math.min(maxMs, firstMs * 2 ** tries);
|
|
8
8
|
return longest / 2 + (Math.random() * longest) / 2;
|
|
9
9
|
}
|
|
10
|
-
export async function untilAnswered(ask, signal, answered = () => true) {
|
|
10
|
+
export async function untilAnswered(ask, signal, answered = () => true, owner) {
|
|
11
11
|
for (let tries = 0;; tries += 1) {
|
|
12
12
|
try {
|
|
13
13
|
const answer = await ask();
|
|
@@ -19,16 +19,16 @@ export async function untilAnswered(ask, signal, answered = () => true) {
|
|
|
19
19
|
throw error;
|
|
20
20
|
}
|
|
21
21
|
await new Promise((resume) => {
|
|
22
|
-
const
|
|
22
|
+
const done = () => {
|
|
23
23
|
clearTimeout(again);
|
|
24
|
+
signal.removeEventListener('abort', done);
|
|
25
|
+
unheld();
|
|
24
26
|
resume();
|
|
25
27
|
};
|
|
26
28
|
// A read that failed is asked again on the doubling backoff, so its asker is answered once the failure clears.
|
|
27
|
-
const again = setTimeout(()
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}, retryDelay(tries));
|
|
31
|
-
signal.addEventListener('abort', stop, { once: true });
|
|
29
|
+
const again = setTimeout(done, retryDelay(tries));
|
|
30
|
+
signal.addEventListener('abort', done, { once: true });
|
|
31
|
+
const unheld = owner?.waits(done) ?? (() => { });
|
|
32
32
|
});
|
|
33
33
|
signal.throwIfAborted();
|
|
34
34
|
}
|
|
@@ -38,6 +38,7 @@ function owner(backoff, inFlight, release = () => { }) {
|
|
|
38
38
|
const children = new Set();
|
|
39
39
|
const running = new Set();
|
|
40
40
|
const queued = [];
|
|
41
|
+
const waiting = new Set();
|
|
41
42
|
let free = inFlight;
|
|
42
43
|
let retired = false;
|
|
43
44
|
function finish(key, intent, done) {
|
|
@@ -105,7 +106,7 @@ function owner(backoff, inFlight, release = () => { }) {
|
|
|
105
106
|
return;
|
|
106
107
|
}
|
|
107
108
|
intent.tries += 1;
|
|
108
|
-
if (intent.tries >=
|
|
109
|
+
if (intent.tries >= intent.attempts) {
|
|
109
110
|
if (again === null) {
|
|
110
111
|
finish(key, intent, false);
|
|
111
112
|
return;
|
|
@@ -157,6 +158,7 @@ function owner(backoff, inFlight, release = () => { }) {
|
|
|
157
158
|
const intent = {
|
|
158
159
|
run,
|
|
159
160
|
tries: 0,
|
|
161
|
+
attempts: options.attempts ?? backoff.attempts,
|
|
160
162
|
timer: null,
|
|
161
163
|
due: null,
|
|
162
164
|
guided: false,
|
|
@@ -195,6 +197,27 @@ function owner(backoff, inFlight, release = () => { }) {
|
|
|
195
197
|
launch(key, intent);
|
|
196
198
|
}
|
|
197
199
|
},
|
|
200
|
+
again() {
|
|
201
|
+
if (retired)
|
|
202
|
+
return;
|
|
203
|
+
for (const [key, intent] of [...intents]) {
|
|
204
|
+
if (intent.timer === null || intent.guided)
|
|
205
|
+
continue;
|
|
206
|
+
clearTimeout(intent.timer);
|
|
207
|
+
intent.timer = null;
|
|
208
|
+
launch(key, intent);
|
|
209
|
+
}
|
|
210
|
+
for (const wake of [...waiting])
|
|
211
|
+
wake();
|
|
212
|
+
for (const child of [...children])
|
|
213
|
+
child.again();
|
|
214
|
+
},
|
|
215
|
+
waits(wake) {
|
|
216
|
+
waiting.add(wake);
|
|
217
|
+
return () => {
|
|
218
|
+
waiting.delete(wake);
|
|
219
|
+
};
|
|
220
|
+
},
|
|
198
221
|
cancel(key) {
|
|
199
222
|
const intent = intents.get(key);
|
|
200
223
|
if (intent === undefined)
|
package/dist/refresh.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type Refreshing = {
|
|
|
20
20
|
later(paths: readonly string[], roomVersion: string): Promise<ReadonlySet<string>>;
|
|
21
21
|
stage(page: RefreshedPage): Promise<boolean>;
|
|
22
22
|
};
|
|
23
|
-
type PageContent = Pick<RefreshPage, 'documents' | 'facts' | 'revisions' | 'fileIds' | 'created' | 'changes' | '
|
|
23
|
+
type PageContent = Pick<RefreshPage, 'documents' | 'facts' | 'revisions' | 'fileIds' | 'created' | 'changes' | 'attachments'>;
|
|
24
24
|
export declare function pageEntries(page: PageContent, removals: readonly string[], roomVersion: string, prior: (paths: readonly string[]) => Promise<ReadonlyMap<string, HeldEntry>>): Promise<StoredEntry[]>;
|
|
25
25
|
export declare function advancement(refresh: Refresher, authorization: Authorization, held: ReplicaRecord, remodel: Remodel, continuing: () => boolean, staging: Refreshing): Promise<Advancement>;
|
|
26
26
|
export {};
|
package/dist/refresh.js
CHANGED
|
@@ -12,7 +12,7 @@ function* listing(page, removals) {
|
|
|
12
12
|
const written = new Set();
|
|
13
13
|
for (const [kept, named] of [
|
|
14
14
|
[documents, page.documents],
|
|
15
|
-
[binaries, page.
|
|
15
|
+
[binaries, page.attachments],
|
|
16
16
|
]) {
|
|
17
17
|
for (const path of Object.keys(named)) {
|
|
18
18
|
yield ROW_WEIGHT;
|
|
@@ -60,7 +60,7 @@ function* entering(page, roomVersion, listed, prior) {
|
|
|
60
60
|
path,
|
|
61
61
|
content: null,
|
|
62
62
|
facts: null,
|
|
63
|
-
binary: { state: 'accepted', ...page.
|
|
63
|
+
binary: { state: 'accepted', ...page.attachments[path] },
|
|
64
64
|
revision: page.revisions[path] ?? prior.get(path)?.revision ?? null,
|
|
65
65
|
fileId: page.fileIds?.[path] ?? null,
|
|
66
66
|
created: page.created?.[path] ?? null,
|
|
@@ -104,14 +104,14 @@ function unwritten(page, kept) {
|
|
|
104
104
|
...(page.fileIds === undefined ? {} : { fileIds: without(page.fileIds, kept) }),
|
|
105
105
|
...(page.created === undefined ? {} : { created: without(page.created, kept) }),
|
|
106
106
|
changes: without(page.changes, kept),
|
|
107
|
-
|
|
107
|
+
attachments: without(page.attachments, kept),
|
|
108
108
|
removals: page.removals.filter((path) => !kept.has(path)),
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
async function pageOf(answered, roomVersion, staging) {
|
|
112
112
|
const page = unwritten(answered, await staging.later([
|
|
113
113
|
...Object.keys(answered.documents),
|
|
114
|
-
...Object.keys(answered.
|
|
114
|
+
...Object.keys(answered.attachments),
|
|
115
115
|
...answered.removals,
|
|
116
116
|
], roomVersion));
|
|
117
117
|
return {
|
|
@@ -129,7 +129,7 @@ export async function advancement(refresh, authorization, held, remodel, continu
|
|
|
129
129
|
return unconfirmed;
|
|
130
130
|
const first = await refresh(authorization, {
|
|
131
131
|
locator,
|
|
132
|
-
selection: held.replica.selection,
|
|
132
|
+
selection: held.declaration.replica.selection,
|
|
133
133
|
fromRoomVersion,
|
|
134
134
|
});
|
|
135
135
|
if (first.kind !== 'net-advancement')
|
|
@@ -154,7 +154,7 @@ export async function advancement(refresh, authorization, held, remodel, continu
|
|
|
154
154
|
return unconfirmed;
|
|
155
155
|
const page = await refresh(authorization, {
|
|
156
156
|
locator,
|
|
157
|
-
selection: held.replica.selection,
|
|
157
|
+
selection: held.declaration.replica.selection,
|
|
158
158
|
fromRoomVersion,
|
|
159
159
|
pageToken,
|
|
160
160
|
});
|
package/dist/refusal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAQpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,wBAAsB,MAAM,CAC1B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,aAAa,EACrB,QAAQ,GAAE,eAAe,GAAG,IAAW,iBAiDxC"}
|
package/dist/refusal.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { changeSet, mergeChangeSets } from './change-set.js';
|
|
2
2
|
import { composedOf } from './collection.js';
|
|
3
|
+
import { uncaught } from './failure.js';
|
|
3
4
|
import { listedLocators } from './listing.js';
|
|
4
5
|
import { prepare } from './preparation.js';
|
|
5
6
|
import { storedRecord } from './replica.js';
|
|
6
7
|
import { emitRefusal } from './shown.js';
|
|
7
8
|
export async function refuse(runtime, reason, provider = null) {
|
|
8
|
-
const { store, socket,
|
|
9
|
+
const { store, socket, presence } = runtime;
|
|
9
10
|
socket.session.set({ paused: true });
|
|
10
11
|
socket.abortReads();
|
|
11
12
|
try {
|
|
@@ -28,13 +29,13 @@ export async function refuse(runtime, reason, provider = null) {
|
|
|
28
29
|
}),
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
|
-
catch {
|
|
32
|
-
|
|
32
|
+
catch (error) {
|
|
33
|
+
uncaught(error);
|
|
33
34
|
}
|
|
34
35
|
const listedNow = listedLocators(runtime, held);
|
|
35
36
|
for (const locator of listedNow) {
|
|
36
37
|
if (!held.has(locator))
|
|
37
|
-
|
|
38
|
+
presence.modelled(locator, revoked);
|
|
38
39
|
}
|
|
39
40
|
store.changed(mergeChangeSets(listedNow.map((locator) => changeSet(locator, { documents: null, room: true }))));
|
|
40
41
|
prepare(runtime);
|
|
@@ -45,12 +46,10 @@ export async function refuse(runtime, reason, provider = null) {
|
|
|
45
46
|
socket.session.set({
|
|
46
47
|
refusal: {
|
|
47
48
|
code: reason,
|
|
48
|
-
retryable: false,
|
|
49
49
|
reauthorizationOffered: reason === 'revoked-authorization',
|
|
50
50
|
refusal: provider,
|
|
51
51
|
},
|
|
52
52
|
});
|
|
53
|
-
journal.record(`connection refused ${reason}`);
|
|
54
53
|
emitRefusal(runtime);
|
|
55
54
|
}
|
|
56
55
|
}
|
package/dist/replica.d.ts
CHANGED
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
import { type TypedPath } from '@agentshouse/mdmodel';
|
|
2
|
-
import type {
|
|
2
|
+
import type { SavedFacts, MutationResult, TypedSelection } from './adapter.js';
|
|
3
3
|
import { type ChangeBatch, type Precondition } from './change.js';
|
|
4
4
|
import { type Collection, type Composition } from './collection.js';
|
|
5
5
|
import { type ModelState } from './model.js';
|
|
6
6
|
import { type Layer } from './overlay.js';
|
|
7
|
+
import type { StoredReplica } from './store.js';
|
|
7
8
|
import type { HeldEntry, OverlayEntry, StoredEntry } from './tables.js';
|
|
8
|
-
export type ReplicaRecord = {
|
|
9
|
-
readonly locator: string;
|
|
10
|
-
readonly name: string;
|
|
11
|
-
readonly handle: string;
|
|
12
|
-
readonly operations: OperationScopes;
|
|
13
|
-
readonly replica: ReplicaAdmission;
|
|
9
|
+
export type ReplicaRecord = Omit<StoredReplica, 'model'> & {
|
|
14
10
|
readonly model: ModelState;
|
|
15
|
-
readonly typedSelection: TypedSelection | null;
|
|
16
|
-
readonly providerOwnedPaths: readonly string[];
|
|
17
|
-
readonly roomVersion: string;
|
|
18
|
-
readonly transfer: string;
|
|
19
|
-
readonly inventory: BootstrapInventory;
|
|
20
|
-
readonly key: number;
|
|
21
11
|
};
|
|
22
12
|
export type HeldReplica = {
|
|
23
13
|
readonly record: ReplicaRecord;
|
|
@@ -32,7 +22,7 @@ export type Slice = Layer & {
|
|
|
32
22
|
readonly facts: Readonly<Record<string, SavedFacts>>;
|
|
33
23
|
readonly held: ReadonlySet<string>;
|
|
34
24
|
};
|
|
35
|
-
export declare function compositionOf(
|
|
25
|
+
export declare function compositionOf(model: ModelState, typedSelection: TypedSelection | null, builtIn: ModelState, typedPaths: readonly TypedPath[]): Composition;
|
|
36
26
|
export declare function storedRecord(record: ReplicaRecord): string;
|
|
37
27
|
export declare function slicing(entries: readonly HeldEntry[], paths: Iterable<string>): Generator<number, Slice, void>;
|
|
38
28
|
export type LayerEntry = Omit<StoredEntry, 'facts'>;
|
|
@@ -48,8 +38,8 @@ export type Replayed = {
|
|
|
48
38
|
};
|
|
49
39
|
export declare function replaying(confirmed: Slice, queue: readonly ChangeBatch[], locator: string, composition: Composition): Generator<number, Replayed, void>;
|
|
50
40
|
export declare function overlayOf(visible: VisibleLayer, touched: Iterable<string>): Generator<number, OverlayEntry[], void>;
|
|
51
|
-
export declare function holds(layer: Layer, preconditions: readonly Precondition[]): boolean;
|
|
52
|
-
export declare function landed(batch: ChangeBatch, confirmed: Layer, current?: Readonly<Record<string, string>>): boolean;
|
|
41
|
+
export declare function holds(layer: Layer, preconditions: readonly Precondition[], composition: Composition): boolean;
|
|
42
|
+
export declare function landed(batch: ChangeBatch, confirmed: Layer, composition: Composition, current?: Readonly<Record<string, string>>): boolean;
|
|
53
43
|
export type Standing = {
|
|
54
44
|
readonly withdrawn: readonly ChangeBatch[];
|
|
55
45
|
readonly kept: readonly ChangeBatch[];
|
package/dist/replica.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replica.d.ts","sourceRoot":"","sources":["../src/replica.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"replica.d.ts","sourceRoot":"","sources":["../src/replica.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,KAAK,EAAE,UAAU,EAAc,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC3F,OAAO,EAKL,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAA+B,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACjG,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAwD,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AAIhG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM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el';
|
|
2
|
-
import { immutable, landing } from './change.js';
|
|
3
|
-
import { collectionOf } from './collection.js';
|
|
2
|
+
import { immutable, isPart, landing, } from './change.js';
|
|
3
|
+
import { collectionOf, definitionsAt } from './collection.js';
|
|
4
4
|
import { storedModel } from './model.js';
|
|
5
|
-
import {
|
|
5
|
+
import { acceptedAttachments, overlaying } from './overlay.js';
|
|
6
6
|
import { writtenFacts } from './rows.js';
|
|
7
7
|
import { effectiveIn, rewriting } from './save.js';
|
|
8
|
+
import { guarding } from './shared.js';
|
|
8
9
|
import { ROW_WEIGHT } from './turn.js';
|
|
9
|
-
export function compositionOf(
|
|
10
|
+
export function compositionOf(model, typedSelection, builtIn, typedPaths) {
|
|
10
11
|
return {
|
|
11
|
-
model
|
|
12
|
-
selection:
|
|
13
|
-
? null
|
|
14
|
-
: { roots: record.typedSelection.roots, model: builtIn },
|
|
12
|
+
model,
|
|
13
|
+
selection: typedSelection === null ? null : { roots: typedSelection.roots, model: builtIn },
|
|
15
14
|
typedPaths,
|
|
16
15
|
};
|
|
17
16
|
}
|
|
@@ -37,7 +36,7 @@ function strict(values, held) {
|
|
|
37
36
|
throw new UnreadPath(property);
|
|
38
37
|
}
|
|
39
38
|
};
|
|
40
|
-
return
|
|
39
|
+
return guarding(values, {
|
|
41
40
|
get(target, property, receiver) {
|
|
42
41
|
guard(property);
|
|
43
42
|
return Reflect.get(target, property, receiver);
|
|
@@ -170,7 +169,7 @@ export function* replaying(confirmed, queue, locator, composition) {
|
|
|
170
169
|
for (const change of effective.changes)
|
|
171
170
|
for (const path of changePaths(change))
|
|
172
171
|
touched.add(path);
|
|
173
|
-
layer = yield* overlaying(layer, [effective]);
|
|
172
|
+
layer = yield* overlaying(layer, [effective], composition);
|
|
174
173
|
yield ROW_WEIGHT;
|
|
175
174
|
}
|
|
176
175
|
return {
|
|
@@ -209,12 +208,12 @@ export function* overlayOf(visible, touched) {
|
|
|
209
208
|
function present(layer, path) {
|
|
210
209
|
return layer.documents[path] !== undefined || layer.binaries[path] !== undefined;
|
|
211
210
|
}
|
|
212
|
-
export function holds(layer, preconditions) {
|
|
211
|
+
export function holds(layer, preconditions, composition) {
|
|
213
212
|
const parsed = new Map();
|
|
214
213
|
const documentAt = (path) => {
|
|
215
214
|
if (!parsed.has(path)) {
|
|
216
215
|
const text = layer.documents[path];
|
|
217
|
-
const opened = text === undefined ? null : parse(text, path);
|
|
216
|
+
const opened = text === undefined ? null : parse(text, path, definitionsAt(composition, path));
|
|
218
217
|
parsed.set(path, opened?.ok === true ? opened.document : null);
|
|
219
218
|
}
|
|
220
219
|
return parsed.get(path) ?? null;
|
|
@@ -248,7 +247,7 @@ export function holds(layer, preconditions) {
|
|
|
248
247
|
}
|
|
249
248
|
function effects(change) {
|
|
250
249
|
const path = change.path;
|
|
251
|
-
if (change
|
|
250
|
+
if (isPart(change)) {
|
|
252
251
|
return [change];
|
|
253
252
|
}
|
|
254
253
|
if (change.kind === 'create' && !('content' in change)) {
|
|
@@ -274,11 +273,11 @@ function effects(change) {
|
|
|
274
273
|
{ kind: 'present', path: change.to },
|
|
275
274
|
];
|
|
276
275
|
}
|
|
277
|
-
if (change.kind === '
|
|
276
|
+
if (change.kind === 'arrival')
|
|
278
277
|
return [{ kind: 'present', path }];
|
|
279
278
|
return [{ kind: 'absent', path }];
|
|
280
279
|
}
|
|
281
|
-
export function landed(batch, confirmed, current = {}) {
|
|
280
|
+
export function landed(batch, confirmed, composition, current = {}) {
|
|
282
281
|
const documents = new Proxy(confirmed.documents, {
|
|
283
282
|
get(target, property, receiver) {
|
|
284
283
|
if (typeof property === 'string' && Object.hasOwn(current, property))
|
|
@@ -298,9 +297,9 @@ export function landed(batch, confirmed, current = {}) {
|
|
|
298
297
|
}
|
|
299
298
|
return effects(change).every((effect) => {
|
|
300
299
|
if (effect.kind === 'absent')
|
|
301
|
-
return holds(layer, [effect]);
|
|
300
|
+
return holds(layer, [effect], composition);
|
|
302
301
|
const at = landing(batch.changes, index, effect.path);
|
|
303
|
-
return at === null || holds(layer, [{ ...effect, path: at }]);
|
|
302
|
+
return at === null || holds(layer, [{ ...effect, path: at }], composition);
|
|
304
303
|
});
|
|
305
304
|
});
|
|
306
305
|
}
|
|
@@ -325,7 +324,7 @@ export function* standing(confirmed, queue, withdrawable, local, locator, compos
|
|
|
325
324
|
const withdrawn = [];
|
|
326
325
|
const kept = [];
|
|
327
326
|
for (const batch of queue) {
|
|
328
|
-
if (withdrawable(batch) && !holds(layer, batch.preconditions)) {
|
|
327
|
+
if (withdrawable(batch) && !holds(layer, batch.preconditions, composition)) {
|
|
329
328
|
withdrawn.push(batch);
|
|
330
329
|
continue;
|
|
331
330
|
}
|
|
@@ -336,7 +335,7 @@ export function* standing(confirmed, queue, withdrawable, local, locator, compos
|
|
|
336
335
|
})
|
|
337
336
|
: batch;
|
|
338
337
|
let unapplied = false;
|
|
339
|
-
const next = yield* overlaying(layer, [effective], () => {
|
|
338
|
+
const next = yield* overlaying(layer, [effective], composition, () => {
|
|
340
339
|
unapplied = true;
|
|
341
340
|
});
|
|
342
341
|
if (local && unapplied) {
|
|
@@ -354,7 +353,7 @@ export function returnedPaths(submitted, accepted) {
|
|
|
354
353
|
...Object.keys(accepted.revisions),
|
|
355
354
|
...Object.keys(accepted.fileIds ?? {}),
|
|
356
355
|
...Object.keys(accepted.changes),
|
|
357
|
-
...Object.keys(accepted.
|
|
356
|
+
...Object.keys(accepted.attachments ?? {}),
|
|
358
357
|
...accepted.removals,
|
|
359
358
|
]);
|
|
360
359
|
for (const change of submitted.changes) {
|
|
@@ -421,7 +420,7 @@ export function* returning(confirmed, submitted, accepted, writtenAt, compositio
|
|
|
421
420
|
binaries.set(change.to, moved);
|
|
422
421
|
binaries.set(change.path, undefined);
|
|
423
422
|
}
|
|
424
|
-
for (const [path, binary] of
|
|
423
|
+
for (const [path, binary] of acceptedAttachments(accepted.attachments ?? {}))
|
|
425
424
|
binaries.set(path, binary);
|
|
426
425
|
for (const path of accepted.removals) {
|
|
427
426
|
binaries.set(path, undefined);
|