@agentshouse/mdruntime 0.1.0-c7bd7ca3faee4 → 0.1.0-c7df8f7608e12
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 +27 -12
- package/dist/acceptance.d.ts +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +328 -0
- 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 +26 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +338 -0
- package/dist/adapter.d.ts +349 -95
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +6 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +35 -41
- package/dist/attachment.d.ts +21 -2
- package/dist/attachment.d.ts.map +1 -1
- package/dist/attachment.js +14 -7
- 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 +37 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +324 -52
- package/dist/cell.d.ts +6 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +9 -0
- package/dist/chain.d.ts +12 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +67 -0
- package/dist/change-set.d.ts +13 -14
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +17 -56
- package/dist/change.d.ts +50 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +39 -0
- package/dist/chat-types.d.ts +3 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +11 -0
- package/dist/client.d.ts +68 -27
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +129 -38
- package/dist/collection.d.ts +36 -14
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +74 -54
- 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 +19 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +755 -0
- package/dist/connection.d.ts +8 -105
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +115 -2121
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- 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 +52 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +76 -0
- package/dist/conversation.d.ts +104 -48
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +1139 -545
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/discovery.d.ts +12 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +175 -0
- 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 +24 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +12 -0
- package/dist/entry.d.ts +44 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +238 -0
- package/dist/expectation.d.ts +34 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +123 -0
- package/dist/failure.d.ts +16 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +27 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +199 -0
- package/dist/file.d.ts +2 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +8 -122
- package/dist/holdings.d.ts +29 -0
- package/dist/holdings.d.ts.map +1 -0
- package/dist/holdings.js +95 -0
- package/dist/host.d.ts +33 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +221 -35
- 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 +3 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +13 -1
- package/dist/index.d.ts +51 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -0
- package/dist/install.d.ts +60 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +537 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +292 -0
- package/dist/listing.d.ts +60 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +168 -0
- package/dist/live.d.ts +39 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +223 -0
- 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 +7 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +34 -0
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +49 -0
- package/dist/media.d.ts +24 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +365 -0
- package/dist/memory.d.ts +28 -8
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +358 -104
- package/dist/messages.d.ts +67 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +180 -0
- 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 +19 -16
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +12 -14
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +153 -0
- package/dist/name.d.ts +3 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +118 -0
- package/dist/observation.d.ts +44 -9
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +271 -33
- package/dist/online.d.ts +7 -0
- package/dist/online.d.ts.map +1 -0
- package/dist/online.js +29 -0
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +71 -0
- package/dist/outcome.d.ts +95 -5
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +114 -1
- package/dist/overlay.d.ts +32 -6
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +240 -189
- 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 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +36 -0
- package/dist/paths.d.ts +2 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +26 -0
- package/dist/preparation.d.ts +46 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +344 -0
- 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 +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +330 -0
- package/dist/query.d.ts +51 -181
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -461
- package/dist/questions.d.ts +30 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +117 -0
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +480 -0
- package/dist/reach.d.ts +30 -5
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +475 -91
- package/dist/react.d.ts +37 -9
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +41 -18
- package/dist/read.d.ts +7 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +17 -0
- package/dist/readiness.d.ts +68 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +35 -0
- package/dist/reads.d.ts +39 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +189 -0
- package/dist/recovery.d.ts +29 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +255 -0
- package/dist/refresh.d.ts +20 -7
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +155 -59
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +55 -0
- package/dist/replica.d.ts +48 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +362 -166
- 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 +85 -14
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +502 -96
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +222 -0
- 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 +40 -35
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +77 -123
- 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 +35 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +48 -22
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +994 -215
- package/dist/saves.d.ts +34 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +463 -0
- package/dist/search.d.ts +15 -54
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -121
- package/dist/seed.d.ts +25 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +145 -0
- 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 +10 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +339 -0
- package/dist/shown.d.ts +35 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +326 -0
- package/dist/socket/admission.d.ts +7 -0
- package/dist/socket/admission.d.ts.map +1 -0
- package/dist/socket/admission.js +39 -0
- package/dist/socket/answers.d.ts +6 -0
- package/dist/socket/answers.d.ts.map +1 -0
- package/dist/socket/answers.js +20 -0
- package/dist/socket/lanes.d.ts +28 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +103 -0
- package/dist/socket/reads.d.ts +10 -0
- package/dist/socket/reads.d.ts.map +1 -0
- package/dist/socket/reads.js +31 -0
- package/dist/socket/session.d.ts +41 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +26 -0
- package/dist/socket.d.ts +70 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +172 -0
- package/dist/source.d.ts +76 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +119 -0
- package/dist/status.d.ts +7 -4
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -15
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +40 -0
- package/dist/store/readiness.d.ts +11 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +68 -0
- package/dist/store/records.d.ts +234 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +474 -0
- package/dist/store/room-held.d.ts +8 -0
- package/dist/store/room-held.d.ts.map +1 -0
- package/dist/store/room-held.js +17 -0
- 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 +11 -0
- package/dist/store/space.d.ts.map +1 -0
- package/dist/store/space.js +41 -0
- package/dist/store/watchers.d.ts +17 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +56 -0
- package/dist/store/writes.d.ts +24 -0
- package/dist/store/writes.d.ts.map +1 -0
- package/dist/store/writes.js +125 -0
- package/dist/store.d.ts +115 -95
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +173 -395
- package/dist/stored.d.ts +181 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +807 -0
- package/dist/surface.d.ts +100 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +258 -0
- package/dist/sync.d.ts +21 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +557 -0
- package/dist/tables.d.ts +400 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +520 -0
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +128 -0
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/turn.d.ts +9 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +75 -0
- package/dist/validation.d.ts +31 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +144 -0
- package/dist/windows.d.ts +11 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +16 -0
- package/dist/wire.d.ts +248 -37
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +93 -33
- package/package.json +28 -16
- package/AGENTS.md +0 -253
- package/dist/log.d.ts +0 -5
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/read-side.d.ts +0 -18
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -433
package/dist/shared.js
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { finished, ROW_WEIGHT } from './turn.js';
|
|
2
|
+
const BITS = 5;
|
|
3
|
+
const MASK = (1 << BITS) - 1;
|
|
4
|
+
const roots = new WeakMap();
|
|
5
|
+
function hashOf(key) {
|
|
6
|
+
let hash = 0x811c9dc5;
|
|
7
|
+
for (let index = 0; index < key.length; index += 1) {
|
|
8
|
+
hash ^= key.charCodeAt(index);
|
|
9
|
+
hash = Math.imul(hash, 0x01000193);
|
|
10
|
+
}
|
|
11
|
+
return hash >>> 0;
|
|
12
|
+
}
|
|
13
|
+
function isLeaf(node) {
|
|
14
|
+
return 'key' in node;
|
|
15
|
+
}
|
|
16
|
+
function isCollision(node) {
|
|
17
|
+
return 'leaves' in node;
|
|
18
|
+
}
|
|
19
|
+
function fragment(hash, shift) {
|
|
20
|
+
return (hash >>> shift) & MASK;
|
|
21
|
+
}
|
|
22
|
+
function count(bits) {
|
|
23
|
+
let left = bits - ((bits >>> 1) & 0x55555555);
|
|
24
|
+
left = (left & 0x33333333) + ((left >>> 2) & 0x33333333);
|
|
25
|
+
return (((left + (left >>> 4)) & 0x0f0f0f0f) * 0x01010101) >>> 24;
|
|
26
|
+
}
|
|
27
|
+
function slot(bitmap, bit) {
|
|
28
|
+
return count(bitmap & (bit - 1));
|
|
29
|
+
}
|
|
30
|
+
function lookup(root, key) {
|
|
31
|
+
const hash = hashOf(key);
|
|
32
|
+
let node = root.node;
|
|
33
|
+
let shift = 0;
|
|
34
|
+
while (node !== undefined) {
|
|
35
|
+
if (isLeaf(node))
|
|
36
|
+
return node.key === key ? node : undefined;
|
|
37
|
+
if (isCollision(node))
|
|
38
|
+
return node.leaves.find((leaf) => leaf.key === key);
|
|
39
|
+
const bit = 1 << fragment(hash, shift);
|
|
40
|
+
if ((node.bitmap & bit) === 0)
|
|
41
|
+
return undefined;
|
|
42
|
+
node = node.children[slot(node.bitmap, bit)];
|
|
43
|
+
shift += BITS;
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
function branchOf(node, shift) {
|
|
48
|
+
return { bitmap: 1 << fragment(node.hash, shift), children: [node] };
|
|
49
|
+
}
|
|
50
|
+
function joined(left, right, shift) {
|
|
51
|
+
if (left.hash === right.hash) {
|
|
52
|
+
const leaves = isCollision(left) ? left.leaves : [left];
|
|
53
|
+
return { hash: right.hash, leaves: [...leaves, right] };
|
|
54
|
+
}
|
|
55
|
+
return put(branchOf(left, shift), right, shift);
|
|
56
|
+
}
|
|
57
|
+
function put(node, leaf, shift) {
|
|
58
|
+
if (node === undefined)
|
|
59
|
+
return leaf;
|
|
60
|
+
if (isLeaf(node)) {
|
|
61
|
+
if (node.key !== leaf.key)
|
|
62
|
+
return joined(node, leaf, shift);
|
|
63
|
+
return node.value === leaf.value ? node : leaf;
|
|
64
|
+
}
|
|
65
|
+
if (isCollision(node)) {
|
|
66
|
+
if (node.hash !== leaf.hash)
|
|
67
|
+
return joined(node, leaf, shift);
|
|
68
|
+
const at = node.leaves.findIndex((held) => held.key === leaf.key);
|
|
69
|
+
if (at === -1)
|
|
70
|
+
return { hash: node.hash, leaves: [...node.leaves, leaf] };
|
|
71
|
+
if (node.leaves[at].value === leaf.value)
|
|
72
|
+
return node;
|
|
73
|
+
return {
|
|
74
|
+
hash: node.hash,
|
|
75
|
+
leaves: node.leaves.map((held, index) => (index === at ? leaf : held)),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const bit = 1 << fragment(leaf.hash, shift);
|
|
79
|
+
const at = slot(node.bitmap, bit);
|
|
80
|
+
if ((node.bitmap & bit) === 0) {
|
|
81
|
+
return {
|
|
82
|
+
bitmap: node.bitmap | bit,
|
|
83
|
+
children: [...node.children.slice(0, at), leaf, ...node.children.slice(at)],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const child = node.children[at];
|
|
87
|
+
const next = put(child, leaf, shift + BITS);
|
|
88
|
+
if (next === child)
|
|
89
|
+
return node;
|
|
90
|
+
return {
|
|
91
|
+
bitmap: node.bitmap,
|
|
92
|
+
children: node.children.map((held, index) => (index === at ? next : held)),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function lone(node) {
|
|
96
|
+
if (node.children.length !== 1)
|
|
97
|
+
return null;
|
|
98
|
+
const [only] = node.children;
|
|
99
|
+
return isLeaf(only) || isCollision(only) ? only : null;
|
|
100
|
+
}
|
|
101
|
+
function taken(node, hash, key, shift) {
|
|
102
|
+
if (isLeaf(node))
|
|
103
|
+
return undefined;
|
|
104
|
+
if (isCollision(node)) {
|
|
105
|
+
const leaves = node.leaves.filter((leaf) => leaf.key !== key);
|
|
106
|
+
return leaves.length === 1 ? leaves[0] : { hash: node.hash, leaves };
|
|
107
|
+
}
|
|
108
|
+
const bit = 1 << fragment(hash, shift);
|
|
109
|
+
const at = slot(node.bitmap, bit);
|
|
110
|
+
const child = node.children[at];
|
|
111
|
+
const next = taken(child, hash, key, shift + BITS);
|
|
112
|
+
if (next === undefined) {
|
|
113
|
+
if (node.children.length === 1)
|
|
114
|
+
return undefined;
|
|
115
|
+
const rest = {
|
|
116
|
+
bitmap: node.bitmap & ~bit,
|
|
117
|
+
children: node.children.filter((_, index) => index !== at),
|
|
118
|
+
};
|
|
119
|
+
return lone(rest) ?? rest;
|
|
120
|
+
}
|
|
121
|
+
const replaced = {
|
|
122
|
+
bitmap: node.bitmap,
|
|
123
|
+
children: node.children.map((held, index) => (index === at ? next : held)),
|
|
124
|
+
};
|
|
125
|
+
return lone(replaced) ?? replaced;
|
|
126
|
+
}
|
|
127
|
+
function* leavesOf(node) {
|
|
128
|
+
if (node === undefined)
|
|
129
|
+
return;
|
|
130
|
+
if (isLeaf(node)) {
|
|
131
|
+
yield node;
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (isCollision(node)) {
|
|
135
|
+
yield* node.leaves;
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
for (const child of node.children)
|
|
139
|
+
yield* leavesOf(child);
|
|
140
|
+
}
|
|
141
|
+
function facade(root) {
|
|
142
|
+
let keys;
|
|
143
|
+
const target = {};
|
|
144
|
+
const map = new Proxy(target, {
|
|
145
|
+
get(held, property, receiver) {
|
|
146
|
+
if (typeof property === 'string') {
|
|
147
|
+
const leaf = lookup(root, property);
|
|
148
|
+
if (leaf !== undefined)
|
|
149
|
+
return leaf.value;
|
|
150
|
+
}
|
|
151
|
+
return Reflect.get(held, property, receiver);
|
|
152
|
+
},
|
|
153
|
+
has(held, property) {
|
|
154
|
+
return ((typeof property === 'string' && lookup(root, property) !== undefined) ||
|
|
155
|
+
Reflect.has(held, property));
|
|
156
|
+
},
|
|
157
|
+
ownKeys() {
|
|
158
|
+
keys ??= [...leavesOf(root.node)].map((leaf) => leaf.key);
|
|
159
|
+
return keys;
|
|
160
|
+
},
|
|
161
|
+
getOwnPropertyDescriptor(_held, property) {
|
|
162
|
+
if (typeof property !== 'string')
|
|
163
|
+
return undefined;
|
|
164
|
+
const leaf = lookup(root, property);
|
|
165
|
+
if (leaf === undefined)
|
|
166
|
+
return undefined;
|
|
167
|
+
return { value: leaf.value, writable: false, enumerable: true, configurable: true };
|
|
168
|
+
},
|
|
169
|
+
set: () => false,
|
|
170
|
+
defineProperty: () => false,
|
|
171
|
+
deleteProperty: () => false,
|
|
172
|
+
});
|
|
173
|
+
roots.set(map, root);
|
|
174
|
+
return map;
|
|
175
|
+
}
|
|
176
|
+
const guarded = new WeakMap();
|
|
177
|
+
export function guarding(values, handler) {
|
|
178
|
+
const map = new Proxy(values, handler);
|
|
179
|
+
guarded.set(map, values);
|
|
180
|
+
return map;
|
|
181
|
+
}
|
|
182
|
+
export function* entriesIn(map) {
|
|
183
|
+
const root = roots.get(map);
|
|
184
|
+
if (root === undefined) {
|
|
185
|
+
const values = guarded.get(map) ?? map;
|
|
186
|
+
for (const key of Object.keys(values))
|
|
187
|
+
yield [key, values[key]];
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
for (const leaf of leavesOf(root.node))
|
|
191
|
+
yield [leaf.key, leaf.value];
|
|
192
|
+
}
|
|
193
|
+
function* rooted(map) {
|
|
194
|
+
const held = roots.get(map);
|
|
195
|
+
if (held !== undefined)
|
|
196
|
+
return held;
|
|
197
|
+
let node;
|
|
198
|
+
for (const [key, value] of entriesIn(map)) {
|
|
199
|
+
node = put(node, { key, hash: hashOf(key), value }, 0);
|
|
200
|
+
yield ROW_WEIGHT;
|
|
201
|
+
}
|
|
202
|
+
return { node };
|
|
203
|
+
}
|
|
204
|
+
const RUN = 1 << 10;
|
|
205
|
+
function* merged(left, right) {
|
|
206
|
+
const into = [];
|
|
207
|
+
let at = 0;
|
|
208
|
+
let from = 0;
|
|
209
|
+
while (at < left.length || from < right.length) {
|
|
210
|
+
into.push(from === right.length || (at < left.length && left[at] < right[from])
|
|
211
|
+
? left[at++]
|
|
212
|
+
: right[from++]);
|
|
213
|
+
yield ROW_WEIGHT;
|
|
214
|
+
}
|
|
215
|
+
return into;
|
|
216
|
+
}
|
|
217
|
+
function* pathsOf(map) {
|
|
218
|
+
for (const [key] of entriesIn(map))
|
|
219
|
+
yield key;
|
|
220
|
+
}
|
|
221
|
+
export function* sortedKeys(map) {
|
|
222
|
+
return yield* sorting(pathsOf(map));
|
|
223
|
+
}
|
|
224
|
+
export function* sorting(keys) {
|
|
225
|
+
let runs = [];
|
|
226
|
+
let run = [];
|
|
227
|
+
for (const key of keys) {
|
|
228
|
+
run.push(key);
|
|
229
|
+
yield ROW_WEIGHT;
|
|
230
|
+
if (run.length === RUN) {
|
|
231
|
+
runs.push(run.sort());
|
|
232
|
+
run = [];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (run.length > 0)
|
|
236
|
+
runs.push(run.sort());
|
|
237
|
+
while (runs.length > 1) {
|
|
238
|
+
const next = [];
|
|
239
|
+
for (let at = 0; at < runs.length; at += 2) {
|
|
240
|
+
next.push(at + 1 === runs.length ? runs[at] : yield* merged(runs[at], runs[at + 1]));
|
|
241
|
+
}
|
|
242
|
+
runs = next;
|
|
243
|
+
}
|
|
244
|
+
return runs[0] ?? [];
|
|
245
|
+
}
|
|
246
|
+
export function* patching(base, set, removed = []) {
|
|
247
|
+
const root = yield* rooted(base);
|
|
248
|
+
let node = root.node;
|
|
249
|
+
for (const key of removed) {
|
|
250
|
+
if (node === undefined)
|
|
251
|
+
break;
|
|
252
|
+
const before = lookup({ node }, key);
|
|
253
|
+
if (before === undefined)
|
|
254
|
+
continue;
|
|
255
|
+
node = taken(node, before.hash, key, 0);
|
|
256
|
+
yield ROW_WEIGHT;
|
|
257
|
+
}
|
|
258
|
+
for (const [key, value] of set) {
|
|
259
|
+
node = put(node, { key, hash: hashOf(key), value }, 0);
|
|
260
|
+
yield ROW_WEIGHT;
|
|
261
|
+
}
|
|
262
|
+
if (node === root.node && roots.has(base))
|
|
263
|
+
return base;
|
|
264
|
+
return facade({ node });
|
|
265
|
+
}
|
|
266
|
+
const drafts = new WeakMap();
|
|
267
|
+
const GONE = Symbol('gone');
|
|
268
|
+
export function drafted(base) {
|
|
269
|
+
const written = new Map();
|
|
270
|
+
const read = (key) => {
|
|
271
|
+
const held = written.get(key);
|
|
272
|
+
if (held === GONE)
|
|
273
|
+
return undefined;
|
|
274
|
+
return held ?? (Object.hasOwn(base, key) ? base[key] : undefined);
|
|
275
|
+
};
|
|
276
|
+
const draft = new Proxy({}, {
|
|
277
|
+
get(held, property, receiver) {
|
|
278
|
+
if (typeof property === 'string') {
|
|
279
|
+
const value = read(property);
|
|
280
|
+
if (value !== undefined)
|
|
281
|
+
return value;
|
|
282
|
+
}
|
|
283
|
+
return Reflect.get(held, property, receiver);
|
|
284
|
+
},
|
|
285
|
+
has(held, property) {
|
|
286
|
+
return ((typeof property === 'string' && read(property) !== undefined) ||
|
|
287
|
+
Reflect.has(held, property));
|
|
288
|
+
},
|
|
289
|
+
ownKeys() {
|
|
290
|
+
const keys = new Set(Object.keys(base));
|
|
291
|
+
for (const [key, value] of written) {
|
|
292
|
+
if (value === GONE)
|
|
293
|
+
keys.delete(key);
|
|
294
|
+
else
|
|
295
|
+
keys.add(key);
|
|
296
|
+
}
|
|
297
|
+
return [...keys];
|
|
298
|
+
},
|
|
299
|
+
getOwnPropertyDescriptor(_held, property) {
|
|
300
|
+
if (typeof property !== 'string')
|
|
301
|
+
return undefined;
|
|
302
|
+
const value = read(property);
|
|
303
|
+
if (value === undefined)
|
|
304
|
+
return undefined;
|
|
305
|
+
return { value, writable: true, enumerable: true, configurable: true };
|
|
306
|
+
},
|
|
307
|
+
set(_held, property, value) {
|
|
308
|
+
if (typeof property !== 'string')
|
|
309
|
+
return false;
|
|
310
|
+
written.set(property, value);
|
|
311
|
+
return true;
|
|
312
|
+
},
|
|
313
|
+
deleteProperty(_held, property) {
|
|
314
|
+
if (typeof property !== 'string')
|
|
315
|
+
return false;
|
|
316
|
+
written.set(property, GONE);
|
|
317
|
+
return true;
|
|
318
|
+
},
|
|
319
|
+
defineProperty: () => false,
|
|
320
|
+
});
|
|
321
|
+
drafts.set(draft, { base, written });
|
|
322
|
+
return draft;
|
|
323
|
+
}
|
|
324
|
+
export function settled(draft) {
|
|
325
|
+
return finished(settling(draft));
|
|
326
|
+
}
|
|
327
|
+
export function* settling(draft) {
|
|
328
|
+
const held = drafts.get(draft);
|
|
329
|
+
const set = [];
|
|
330
|
+
const removed = [];
|
|
331
|
+
for (const [key, value] of held.written) {
|
|
332
|
+
if (value === GONE)
|
|
333
|
+
removed.push(key);
|
|
334
|
+
else
|
|
335
|
+
set.push([key, value]);
|
|
336
|
+
yield ROW_WEIGHT;
|
|
337
|
+
}
|
|
338
|
+
return yield* patching(held.base, set, removed);
|
|
339
|
+
}
|
package/dist/shown.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Member } from './adapter.js';
|
|
2
|
+
import { type ChangeSet } from './change-set.js';
|
|
3
|
+
import type { QueueEntry } from './outcome.js';
|
|
4
|
+
import type { Runtime } from './runtime.js';
|
|
5
|
+
import type { Live, Moving } from './socket.js';
|
|
6
|
+
import { type CycleProgress } from './status.js';
|
|
7
|
+
export declare const ROOMS_TOPIC = "rooms";
|
|
8
|
+
export declare const STATUS_TOPIC = "sync-status";
|
|
9
|
+
export declare const REFUSAL_TOPIC = "connection-refusal";
|
|
10
|
+
export declare const STORAGE_LOSS_TOPIC = "storage-loss";
|
|
11
|
+
export declare const SERVICE_MODE_TOPIC = "service-mode";
|
|
12
|
+
export declare const MEMBER_TOPIC = "member";
|
|
13
|
+
export declare const TIME_ZONE_TOPIC = "time-zone";
|
|
14
|
+
export declare const AUTHORITY_TOPIC = "authority-changes";
|
|
15
|
+
export declare const LOCKS_TOPIC = "locks";
|
|
16
|
+
export declare const queueTopic: (locator: string) => string;
|
|
17
|
+
export declare function recoverReads({ liveQueries, figures }: Runtime, locators?: readonly string[]): void;
|
|
18
|
+
export declare function emitRooms(runtime: Runtime, changed?: readonly string[]): Promise<void>;
|
|
19
|
+
export declare function emitKnownRooms(runtime: Runtime): void;
|
|
20
|
+
export declare function emitRefusal(runtime: Runtime): void;
|
|
21
|
+
export declare function storageLossNow({ store }: Runtime): string | null;
|
|
22
|
+
export declare function emitStorageLoss(runtime: Runtime): void;
|
|
23
|
+
export declare function emitMember({ store }: Runtime, member: Member | null): void;
|
|
24
|
+
export declare function emitTimeZone({ store }: Runtime, zone: string | null): void;
|
|
25
|
+
export declare function show(runtime: Runtime): Promise<void>;
|
|
26
|
+
export declare function moveTo(runtime: Runtime, next: Moving): Promise<void>;
|
|
27
|
+
export declare function statusShown(runtime: Runtime): Promise<void>;
|
|
28
|
+
export declare function transferring({ socket }: Runtime): Moving;
|
|
29
|
+
export declare function pendingShown(runtime: Runtime): Promise<void>;
|
|
30
|
+
export declare function entriesOf(runtime: Runtime, locator: string): Promise<readonly QueueEntry[]>;
|
|
31
|
+
export declare function publishChangeSet(runtime: Runtime, set: ChangeSet): Promise<void>;
|
|
32
|
+
export declare function submissionDue(runtime: Runtime, locators?: readonly string[]): Promise<void>;
|
|
33
|
+
export declare function roomUnreadable(runtime: Runtime, locator: string): void;
|
|
34
|
+
export declare function rest(runtime: Runtime, progress: CycleProgress | null, live?: Live): Promise<void>;
|
|
35
|
+
//# sourceMappingURL=shown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shown.d.ts","sourceRoot":"","sources":["../src/shown.ts"],"names":[],"mappings":"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"}
|