@yaks/browse 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +324 -2
- package/_dist/app.d.ts +8 -0
- package/_dist/app.d.ts.map +1 -0
- package/_dist/cli.d.ts +16 -0
- package/_dist/cli.d.ts.map +1 -0
- package/_dist/hosting.d.ts +24 -0
- package/_dist/hosting.d.ts.map +1 -0
- package/_dist/mod.d.ts +7 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/types.d.ts +5 -0
- package/_dist/types.d.ts.map +1 -0
- package/_dist/url.d.ts +2 -0
- package/_dist/url.d.ts.map +1 -0
- package/app.js +10 -0
- package/app.js.map +1 -0
- package/app.ts +10 -0
- package/browser-links.js +22 -0
- package/browser-links.js.map +1 -0
- package/browser-links.ts +28 -0
- package/cli.js +172 -0
- package/cli.js.map +1 -0
- package/cli.ts +168 -0
- package/client.js +748 -0
- package/client.js.map +1 -0
- package/client.ts +734 -0
- package/clipboard.js +18 -0
- package/clipboard.js.map +1 -0
- package/clipboard.ts +17 -0
- package/commands.js +1157 -0
- package/commands.js.map +1 -0
- package/commands.ts +1108 -0
- package/components/Ansi.tsx +160 -0
- package/components/App.tsx +446 -0
- package/components/Canvas.tsx +625 -0
- package/components/Card.tsx +276 -0
- package/components/Chat.tsx +205 -0
- package/components/Configuration.tsx +218 -0
- package/components/Decision.tsx +49 -0
- package/components/Dot.tsx +52 -0
- package/components/Entity.tsx +609 -0
- package/components/Fault.tsx +43 -0
- package/components/Filter.tsx +103 -0
- package/components/Keybindings.tsx +100 -0
- package/components/Keys.tsx +67 -0
- package/components/Markdown.tsx +90 -0
- package/components/Navigation.tsx +161 -0
- package/components/New.tsx +490 -0
- package/components/Peek.tsx +168 -0
- package/components/Prio.tsx +20 -0
- package/components/Run.tsx +263 -0
- package/components/Search.tsx +280 -0
- package/components/Stamp.tsx +44 -0
- package/components/Status.tsx +514 -0
- package/components/Sync.tsx +173 -0
- package/components/Tile.tsx +50 -0
- package/components/answered.js +23 -0
- package/components/answered.js.map +1 -0
- package/components/answered.ts +25 -0
- package/components/comp.js +11 -0
- package/components/comp.js.map +1 -0
- package/components/comp.ts +10 -0
- package/components/drag.js +173 -0
- package/components/drag.js.map +1 -0
- package/components/drag.ts +198 -0
- package/components/fields.tsx +90 -0
- package/components/fixtures/README.md +10 -0
- package/components/fixtures/archetypes.json +3646 -0
- package/components/hits.js +63 -0
- package/components/hits.js.map +1 -0
- package/components/hits.ts +84 -0
- package/components/icons.tsx +177 -0
- package/components/inspect.tsx +331 -0
- package/components/mount.ts +79 -0
- package/components/nav.tsx +479 -0
- package/components/offers.js +26 -0
- package/components/offers.js.map +1 -0
- package/components/offers.ts +54 -0
- package/components/page.js +21 -0
- package/components/page.js.map +1 -0
- package/components/page.ts +18 -0
- package/components/read.js +5 -0
- package/components/read.js.map +1 -0
- package/components/read.ts +7 -0
- package/components/registry.js +285 -0
- package/components/registry.js.map +1 -0
- package/components/registry.ts +317 -0
- package/components/session_status.tsx +115 -0
- package/components/subscriptions.js +149 -0
- package/components/subscriptions.js.map +1 -0
- package/components/subscriptions.ts +161 -0
- package/components/title.tsx +21 -0
- package/components/useQuery.js +166 -0
- package/components/useQuery.js.map +1 -0
- package/components/useQuery.ts +211 -0
- package/components/views/Board.tsx +450 -0
- package/components/views/BoardTile.tsx +65 -0
- package/components/views/Dashboard.tsx +148 -0
- package/components/views/Debug.tsx +445 -0
- package/components/views/Dependency.tsx +51 -0
- package/components/views/Entry.tsx +500 -0
- package/components/views/Gist.tsx +28 -0
- package/components/views/Inline.tsx +54 -0
- package/components/views/Json.tsx +19 -0
- package/components/views/Layout.tsx +211 -0
- package/components/views/List.tsx +238 -0
- package/components/views/Md.tsx +43 -0
- package/components/views/Media.tsx +48 -0
- package/components/views/Memory.tsx +32 -0
- package/components/views/Relate.tsx +205 -0
- package/components/views/Search.tsx +42 -0
- package/components/views/Session.tsx +850 -0
- package/components/views/SessionManage.tsx +127 -0
- package/components/views/Show.tsx +758 -0
- package/components/views/Shown.tsx +72 -0
- package/components/views/Split.tsx +58 -0
- package/components/views/TaskTile.tsx +37 -0
- package/components/views/Title.tsx +105 -0
- package/components/views/Wake.tsx +77 -0
- package/components/views/Web.tsx +49 -0
- package/components/wells.js +30 -0
- package/components/wells.js.map +1 -0
- package/components/wells.ts +33 -0
- package/configuration.js +38 -0
- package/configuration.js.map +1 -0
- package/configuration.ts +41 -0
- package/decision_sync.js +88 -0
- package/decision_sync.js.map +1 -0
- package/decision_sync.ts +93 -0
- package/deno.json +1 -0
- package/domain-host.tsx +108 -0
- package/edge.js +193 -0
- package/edge.js.map +1 -0
- package/edge.ts +196 -0
- package/entry_log.js +241 -0
- package/entry_log.js.map +1 -0
- package/entry_log.ts +214 -0
- package/failure.js +22 -0
- package/failure.js.map +1 -0
- package/failure.ts +34 -0
- package/front.json +61 -0
- package/highlight.js +143 -0
- package/highlight.js.map +1 -0
- package/highlight.ts +149 -0
- package/history.js +68 -0
- package/history.js.map +1 -0
- package/history.ts +72 -0
- package/host_commands.js +107 -0
- package/host_commands.js.map +1 -0
- package/host_commands.ts +38 -0
- package/hosting.js +53 -0
- package/hosting.js.map +1 -0
- package/hosting.ts +72 -0
- package/idb.js +14 -0
- package/idb.js.map +1 -0
- package/idb.ts +15 -0
- package/index.js +232 -0
- package/index.js.map +1 -0
- package/index.ts +252 -0
- package/keybindings.js +136 -0
- package/keybindings.js.map +1 -0
- package/keybindings.ts +37 -0
- package/kit.js +103 -0
- package/kit.js.map +1 -0
- package/kit.ts +119 -0
- package/layout.js +254 -0
- package/layout.js.map +1 -0
- package/layout.ts +210 -0
- package/legacy_outbox.js +53 -0
- package/legacy_outbox.js.map +1 -0
- package/legacy_outbox.ts +63 -0
- package/live.js +2883 -0
- package/live.js.map +1 -0
- package/live.ts +3334 -0
- package/live_archetypes.js +92 -0
- package/live_archetypes.js.map +1 -0
- package/live_archetypes.ts +113 -0
- package/live_client.js +145 -0
- package/live_client.js.map +1 -0
- package/live_client.ts +120 -0
- package/main.tsx +5 -0
- package/mod.js +7 -0
- package/mod.js.map +1 -0
- package/mod.ts +7 -0
- package/mount.tsx +50 -0
- package/navigation.js +120 -0
- package/navigation.js.map +1 -0
- package/navigation.ts +152 -0
- package/near.js +83 -0
- package/near.js.map +1 -0
- package/near.ts +83 -0
- package/new.js +295 -0
- package/new.js.map +1 -0
- package/new.ts +361 -0
- package/outbox.js +112 -0
- package/outbox.js.map +1 -0
- package/outbox.ts +129 -0
- package/owner.js +39 -0
- package/owner.js.map +1 -0
- package/owner.ts +37 -0
- package/package.json +81 -4
- package/paste.js +157 -0
- package/paste.js.map +1 -0
- package/paste.ts +122 -0
- package/props.js +303 -0
- package/props.js.map +1 -0
- package/props.ts +358 -0
- package/providers.js +136 -0
- package/providers.js.map +1 -0
- package/providers.ts +194 -0
- package/query.js +987 -0
- package/query.js.map +1 -0
- package/query.ts +1113 -0
- package/remote.js +37 -0
- package/remote.js.map +1 -0
- package/remote.ts +46 -0
- package/resolver.js +149 -0
- package/resolver.js.map +1 -0
- package/resolver.ts +213 -0
- package/rfc2047.js +37 -0
- package/rfc2047.js.map +1 -0
- package/rfc2047.ts +40 -0
- package/row_holds.js +107 -0
- package/row_holds.js.map +1 -0
- package/row_holds.ts +93 -0
- package/served.ts +42 -0
- package/session_worktree.js +7 -0
- package/session_worktree.js.map +1 -0
- package/session_worktree.ts +16 -0
- package/sessions.js +57 -0
- package/sessions.js.map +1 -0
- package/sessions.ts +53 -0
- package/sha.js +161 -0
- package/sha.js.map +1 -0
- package/sha.ts +164 -0
- package/styles.css +2823 -0
- package/subs.js +36 -0
- package/subs.js.map +1 -0
- package/subs.ts +40 -0
- package/terminal-route.js +13 -0
- package/terminal-route.js.map +1 -0
- package/terminal-route.ts +17 -0
- package/terminal.js +251 -0
- package/terminal.js.map +1 -0
- package/terminal.ts +186 -0
- package/time.js +142 -0
- package/time.js.map +1 -0
- package/time.ts +133 -0
- package/title.js +25 -0
- package/title.js.map +1 -0
- package/title.ts +50 -0
- package/tui/doc.ts +6 -0
- package/tui/testing.ts +19 -0
- package/twin.js +11 -0
- package/twin.js.map +1 -0
- package/twin.ts +13 -0
- package/types.js +456 -0
- package/types.js.map +1 -0
- package/types.ts +1370 -0
- package/url.js +77 -0
- package/url.js.map +1 -0
- package/url.ts +85 -0
- package/verb.js +82 -0
- package/verb.js.map +1 -0
- package/verb.ts +137 -0
- package/warmth.js +41 -0
- package/warmth.js.map +1 -0
- package/warmth.ts +54 -0
- package/wire.js +86 -0
- package/wire.js.map +1 -0
- package/wire.ts +63 -0
package/layout.ts
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// Tiling layout gestures (D-14718), pure: each op reads the panes the
|
|
2
|
+
// caller already has and returns ONE flat Change[] — apply() runs it
|
|
3
|
+
// atomically, so a multi-pane edit never tears. No door talks to a cache
|
|
4
|
+
// or a socket here; the web view and the future TUI share this seam.
|
|
5
|
+
// Within a batch, reparents come BEFORE deletes: the reaper's doom-walk
|
|
6
|
+
// reads current rows, so a child moved first escapes its old parent's
|
|
7
|
+
// cascade.
|
|
8
|
+
import { type Change, type Pane, uuid } from './types.js'
|
|
9
|
+
|
|
10
|
+
export type Dir = 'h' | 'v'
|
|
11
|
+
|
|
12
|
+
let by = (panes: Pane[], eid: string) => panes.find((p) => p.eid == eid)
|
|
13
|
+
|
|
14
|
+
// Siblings in paint order. The eid tiebreak keeps two panes minted with
|
|
15
|
+
// one order value stable across renders.
|
|
16
|
+
/// kids([{eid: 'b', parent: 'r', order: 1},
|
|
17
|
+
/// {eid: 'a', parent: 'r', order: 0}], 'r').map(p => p.eid)
|
|
18
|
+
/// -> ['a', 'b']
|
|
19
|
+
export let kids = (panes: Pane[], parent: string) =>
|
|
20
|
+
panes.filter((p) => p.parent == parent)
|
|
21
|
+
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0) || (a.eid < b.eid ? -1 : 1))
|
|
22
|
+
|
|
23
|
+
let mint = (eid: string, comp: Record<string, unknown>): Change => ({
|
|
24
|
+
eid,
|
|
25
|
+
name: 'pane',
|
|
26
|
+
comp,
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
// Split a pane. Along the surrounding dir it is ONE change — a new empty
|
|
30
|
+
// sibling at the pane's own weight, ordered between it and the next
|
|
31
|
+
// (weights renormalize at render, so nothing else moves). Across, the
|
|
32
|
+
// pane BECOMES the container: its content (or its old-dir children,
|
|
33
|
+
// hoisted under a new intermediate) moves down, an empty pane joins as
|
|
34
|
+
// the second child. The new pane is empty on purpose — it renders the
|
|
35
|
+
// palette.
|
|
36
|
+
export let split = (panes: Pane[], eid: string, dir: Dir): Change[] => {
|
|
37
|
+
let p = by(panes, eid)
|
|
38
|
+
if (!p) return []
|
|
39
|
+
let parent = p.parent ? by(panes, p.parent) : undefined
|
|
40
|
+
if (parent?.dir == dir) {
|
|
41
|
+
let sibs = kids(panes, parent.eid)
|
|
42
|
+
let next = sibs[sibs.findIndex((s) => s.eid == eid) + 1]
|
|
43
|
+
let order = next
|
|
44
|
+
? ((p.order ?? 0) + (next.order ?? 0)) / 2
|
|
45
|
+
: (p.order ?? 0) + 1
|
|
46
|
+
return [mint(uuid(), {
|
|
47
|
+
layout: p.layout,
|
|
48
|
+
parent: parent.eid,
|
|
49
|
+
size: p.size ?? 1,
|
|
50
|
+
order,
|
|
51
|
+
})]
|
|
52
|
+
}
|
|
53
|
+
if (p.dir == dir) {
|
|
54
|
+
// A container split along its own axis: one more child at the end.
|
|
55
|
+
let last = kids(panes, eid).at(-1)
|
|
56
|
+
return [mint(uuid(), {
|
|
57
|
+
layout: p.layout,
|
|
58
|
+
parent: eid,
|
|
59
|
+
size: last?.size ?? 1,
|
|
60
|
+
order: (last?.order ?? 0) + 1,
|
|
61
|
+
})]
|
|
62
|
+
}
|
|
63
|
+
let held = p.dir ? kids(panes, eid) : []
|
|
64
|
+
let a = uuid()
|
|
65
|
+
return [
|
|
66
|
+
{ eid, name: 'pane', comp: { dir, content: null, view: null } },
|
|
67
|
+
...held.map((k) => mint(k.eid, { parent: a })),
|
|
68
|
+
mint(a, {
|
|
69
|
+
layout: p.layout,
|
|
70
|
+
parent: eid,
|
|
71
|
+
size: 1,
|
|
72
|
+
order: 0,
|
|
73
|
+
...(p.dir
|
|
74
|
+
? { dir: p.dir }
|
|
75
|
+
: { content: p.content ?? null, view: p.view ?? null }),
|
|
76
|
+
}),
|
|
77
|
+
mint(uuid(), {
|
|
78
|
+
layout: p.layout,
|
|
79
|
+
parent: eid,
|
|
80
|
+
size: 1,
|
|
81
|
+
order: 1,
|
|
82
|
+
}),
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Close a pane: delete its entity — descendants cascade server-side, and
|
|
87
|
+
// the siblings' weights renormalize at render with no splice. When the
|
|
88
|
+
// parent goes unary the survivor hoists into it (content up, or dir +
|
|
89
|
+
// children up) and is deleted, so no container ever holds one child. The
|
|
90
|
+
// root never deletes — a layout always has a pane — it clears to empty.
|
|
91
|
+
export let close = (panes: Pane[], eid: string): Change[] => {
|
|
92
|
+
let p = by(panes, eid)
|
|
93
|
+
if (!p) return []
|
|
94
|
+
if (!p.parent) {
|
|
95
|
+
return [
|
|
96
|
+
...kids(panes, eid).map((k) =>
|
|
97
|
+
({ eid: k.eid, name: 'entity', comp: null }) as Change
|
|
98
|
+
),
|
|
99
|
+
{ eid, name: 'pane', comp: { dir: null, content: null, view: null } },
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
let del: Change = { eid, name: 'entity', comp: null }
|
|
103
|
+
let sibs = kids(panes, p.parent).filter((s) => s.eid != eid)
|
|
104
|
+
if (sibs.length != 1) return [del]
|
|
105
|
+
let s = sibs[0]
|
|
106
|
+
let parent = p.parent
|
|
107
|
+
return [
|
|
108
|
+
del,
|
|
109
|
+
...(s.dir
|
|
110
|
+
? [
|
|
111
|
+
...kids(panes, s.eid).map((k) => mint(k.eid, { parent: parent })),
|
|
112
|
+
mint(parent, { dir: s.dir }),
|
|
113
|
+
]
|
|
114
|
+
: [
|
|
115
|
+
mint(parent, {
|
|
116
|
+
dir: null,
|
|
117
|
+
content: s.content ?? null,
|
|
118
|
+
view: s.view ?? null,
|
|
119
|
+
}),
|
|
120
|
+
]),
|
|
121
|
+
{ eid: s.eid, name: 'entity', comp: null },
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// The smallest weight a drag can leave — a pane never resizes to nothing
|
|
126
|
+
// (close is the gesture for that).
|
|
127
|
+
let MIN = 0.05
|
|
128
|
+
|
|
129
|
+
// Transfer weight between two adjacent siblings: a grows by delta, b
|
|
130
|
+
// shrinks. Delta is in WEIGHT units — the caller converts pixels against
|
|
131
|
+
// the siblings' total. One batch on settle, never per pixel.
|
|
132
|
+
/// resize([{eid: 'a', parent: 'r', size: 1},
|
|
133
|
+
/// {eid: 'b', parent: 'r', size: 1}], 'a', 'b', 0.5)
|
|
134
|
+
/// -> [{eid: 'a', name: 'pane', comp: {size: 1.5}},
|
|
135
|
+
/// {eid: 'b', name: 'pane', comp: {size: 0.5}}]
|
|
136
|
+
export let resize = (
|
|
137
|
+
panes: Pane[],
|
|
138
|
+
a: string,
|
|
139
|
+
b: string,
|
|
140
|
+
delta: number,
|
|
141
|
+
): Change[] => {
|
|
142
|
+
let pa = by(panes, a)
|
|
143
|
+
let pb = by(panes, b)
|
|
144
|
+
if (!pa || !pb || pa.parent != pb.parent) return []
|
|
145
|
+
let wa = pa.size ?? 1
|
|
146
|
+
let wb = pb.size ?? 1
|
|
147
|
+
let d = Math.max(Math.min(delta, wb - MIN), MIN - wa)
|
|
148
|
+
if (!d) return []
|
|
149
|
+
// Rounded so a drag stores tidy weights, and a clamped edge lands ON
|
|
150
|
+
// the floor instead of a float hair above it.
|
|
151
|
+
let r4 = (n: number) => Math.round(n * 1e4) / 1e4
|
|
152
|
+
return [
|
|
153
|
+
mint(a, { size: r4(wa + d) }),
|
|
154
|
+
mint(b, { size: r4(wb - d) }),
|
|
155
|
+
]
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Fill a leaf: what it shows and how. null clears back to empty.
|
|
159
|
+
export let setContent = (
|
|
160
|
+
panes: Pane[],
|
|
161
|
+
eid: string,
|
|
162
|
+
target: string | null,
|
|
163
|
+
view?: string | null,
|
|
164
|
+
): Change[] =>
|
|
165
|
+
by(panes, eid) ? [mint(eid, { content: target, view: view ?? null })] : []
|
|
166
|
+
|
|
167
|
+
// Exchange two leaves' content — the panes keep their place and size.
|
|
168
|
+
export let swap = (panes: Pane[], a: string, b: string): Change[] => {
|
|
169
|
+
let pa = by(panes, a)
|
|
170
|
+
let pb = by(panes, b)
|
|
171
|
+
if (!pa || !pb) return []
|
|
172
|
+
return [
|
|
173
|
+
mint(a, { content: pb.content ?? null, view: pb.view ?? null }),
|
|
174
|
+
mint(b, { content: pa.content ?? null, view: pa.view ?? null }),
|
|
175
|
+
]
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// A fresh layout in one batch: doc + layout + root. One leaf (or none)
|
|
179
|
+
// IS the root; more make the root an h-container with equal children.
|
|
180
|
+
export let mintLayout = (
|
|
181
|
+
title: string,
|
|
182
|
+
leaves: { content?: string | null; view?: string | null }[] = [],
|
|
183
|
+
): { eid: string; changes: Change[] } => {
|
|
184
|
+
let eid = uuid()
|
|
185
|
+
let root = uuid()
|
|
186
|
+
let changes: Change[] = [
|
|
187
|
+
{ eid, name: 'doc', comp: { title, body: '' } },
|
|
188
|
+
{ eid, name: 'layout', comp: { root: root } },
|
|
189
|
+
...(leaves.length < 2
|
|
190
|
+
? [mint(root, { layout: eid, ...(leaves[0] ?? {}) })]
|
|
191
|
+
: [
|
|
192
|
+
mint(root, { layout: eid, dir: 'h' }),
|
|
193
|
+
...leaves.map((leaf, i) =>
|
|
194
|
+
mint(uuid(), {
|
|
195
|
+
layout: eid,
|
|
196
|
+
parent: root,
|
|
197
|
+
size: 1,
|
|
198
|
+
order: i,
|
|
199
|
+
...leaf,
|
|
200
|
+
})
|
|
201
|
+
),
|
|
202
|
+
]),
|
|
203
|
+
]
|
|
204
|
+
return { eid, changes }
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Deliberately absent: fork (the shared-layout copy is data the model
|
|
208
|
+
// already supports — the gesture lands with the palette phase, D-14718
|
|
209
|
+
// rollout 3) and any tree normalizer — every op above leaves the tree
|
|
210
|
+
// well-formed, so no renderer defends against a malformed one.
|
package/legacy_outbox.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export let legacyOutbox = (name)=>{
|
|
2
|
+
let opening;
|
|
3
|
+
let db = ()=>opening ??= new Promise((resolve, reject)=>{
|
|
4
|
+
let request = indexedDB.open(name);
|
|
5
|
+
let absent = false;
|
|
6
|
+
request.onupgradeneeded = ()=>{
|
|
7
|
+
absent = true;
|
|
8
|
+
request.transaction.abort();
|
|
9
|
+
};
|
|
10
|
+
request.onsuccess = ()=>resolve(request.result);
|
|
11
|
+
request.onerror = ()=>absent ? resolve(undefined) : reject(request.error);
|
|
12
|
+
request.onblocked = ()=>reject(new Error('Legacy outbox is blocked'));
|
|
13
|
+
});
|
|
14
|
+
let transaction = async (mode, run)=>{
|
|
15
|
+
let database = await db();
|
|
16
|
+
if (!database || !database.objectStoreNames.contains('outbox')) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
return await new Promise((resolve, reject)=>{
|
|
20
|
+
let tx = database.transaction('outbox', mode);
|
|
21
|
+
let request = run(tx.objectStore('outbox'));
|
|
22
|
+
tx.oncomplete = ()=>resolve(request.result);
|
|
23
|
+
tx.onabort = tx.onerror = ()=>reject(tx.error ?? request.error);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
load: async ()=>{
|
|
28
|
+
// One readonly transaction keeps keys and values paired under other tabs.
|
|
29
|
+
let rows = [];
|
|
30
|
+
await transaction('readonly', (s)=>{
|
|
31
|
+
let request = s.openCursor();
|
|
32
|
+
request.onsuccess = ()=>{
|
|
33
|
+
let cursor = request.result;
|
|
34
|
+
if (!cursor) return;
|
|
35
|
+
rows.push([
|
|
36
|
+
String(cursor.key),
|
|
37
|
+
cursor.value
|
|
38
|
+
]);
|
|
39
|
+
cursor.continue();
|
|
40
|
+
};
|
|
41
|
+
return request;
|
|
42
|
+
});
|
|
43
|
+
return rows;
|
|
44
|
+
},
|
|
45
|
+
remove: async (key)=>{
|
|
46
|
+
await transaction('readwrite', (s)=>s.delete(key));
|
|
47
|
+
},
|
|
48
|
+
close: ()=>{
|
|
49
|
+
void opening?.then((db)=>db?.close(), ()=>{});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=legacy_outbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy_outbox.js","sources":["./legacy_outbox.ts"],"names":[],"mappings":"AASA,OAAO,IAAI,eAAe,CAAC;EACzB,IAAI;EACJ,IAAI,KAAK,IACP,YAAY,IAAI,QAAQ,CAAC,SAAS;MAChC,IAAI,UAAU,UAAU,IAAI,CAAC;MAC7B,IAAI,SAAS;MACb,QAAQ,eAAe,GAAG;QACxB,SAAS;QACT,QAAQ,WAAW,CAAE,KAAK;MAC5B;MACA,QAAQ,SAAS,GAAG,IAAM,QAAQ,QAAQ,MAAM;MAChD,QAAQ,OAAO,GAAG,IAChB,SAAS,QAAQ,aAAa,OAAO,QAAQ,KAAK;MACpD,QAAQ,SAAS,GAAG,IAAM,OAAO,IAAI,MAAM;IAC7C;EACF,IAAI,cAAc,OAChB,MACA;IAEA,IAAI,WAAW,MAAM;IACrB,IAAI,CAAC,YAAY,CAAC,SAAS,gBAAgB,CAAC,QAAQ,CAAC,WAAW;MAC9D,OAAO;IACT;IACA,OAAO,MAAM,IAAI,QAAW,CAAC,SAAS;MACpC,IAAI,KAAK,SAAS,WAAW,CAAC,UAAU;MACxC,IAAI,UAAU,IAAI,GAAG,WAAW,CAAC;MACjC,GAAG,UAAU,GAAG,IAAM,QAAQ,QAAQ,MAAM;MAC5C,GAAG,OAAO,GAAG,GAAG,OAAO,GAAG,IAAM,OAAO,GAAG,KAAK,IAAI,QAAQ,KAAK;IAClE;EACF;EACA,OAAO;IACL,MAAM;MACJ,0EAA0E;MAC1E,IAAI,OAAkD,EAAE;MACxD,MAAM,YAAY,YAAY,CAAC;QAC7B,IAAI,UAAU,EAAE,UAAU;QAC1B,QAAQ,SAAS,GAAG;UAClB,IAAI,SAAS,QAAQ,MAAM;UAC3B,IAAI,CAAC,QAAQ;UACb,KAAK,IAAI,CAAC;YAAC,OAAO,OAAO,GAAG;YAAG,OAAO,KAAK;WAAC;UAC5C,OAAO,QAAQ;QACjB;QACA,OAAO;MACT;MACA,OAAO;IACT;IACA,QAAQ,OAAO;MACb,MAAM,YAAY,aAAa,CAAC,IAAM,EAAE,MAAM,CAAC;IACjD;IACA,OAAO;MACL,KAAK,SAAS,KAAK,CAAC,KAAO,IAAI,SAAS,KAAO;IACjD;EACF;AACF,EAAC"}
|
package/legacy_outbox.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Change } from './types.ts'
|
|
2
|
+
|
|
3
|
+
// Read the old shape only to move it. Never send from it, create it, or treat
|
|
4
|
+
// a failed read/delete as success. The destination commits before removal.
|
|
5
|
+
export type LegacyOutbox = {
|
|
6
|
+
load: () => Promise<[string, { changes: Change[]; at: number }][]>
|
|
7
|
+
remove: (key: string) => Promise<void>
|
|
8
|
+
close?: () => void
|
|
9
|
+
}
|
|
10
|
+
export let legacyOutbox = (name: string): LegacyOutbox => {
|
|
11
|
+
let opening: Promise<IDBDatabase | undefined> | undefined
|
|
12
|
+
let db = () =>
|
|
13
|
+
opening ??= new Promise((resolve, reject) => {
|
|
14
|
+
let request = indexedDB.open(name)
|
|
15
|
+
let absent = false
|
|
16
|
+
request.onupgradeneeded = () => {
|
|
17
|
+
absent = true
|
|
18
|
+
request.transaction!.abort()
|
|
19
|
+
}
|
|
20
|
+
request.onsuccess = () => resolve(request.result)
|
|
21
|
+
request.onerror = () =>
|
|
22
|
+
absent ? resolve(undefined) : reject(request.error)
|
|
23
|
+
request.onblocked = () => reject(new Error('Legacy outbox is blocked'))
|
|
24
|
+
})
|
|
25
|
+
let transaction = async <T>(
|
|
26
|
+
mode: IDBTransactionMode,
|
|
27
|
+
run: (s: IDBObjectStore) => IDBRequest<T>,
|
|
28
|
+
) => {
|
|
29
|
+
let database = await db()
|
|
30
|
+
if (!database || !database.objectStoreNames.contains('outbox')) {
|
|
31
|
+
return undefined
|
|
32
|
+
}
|
|
33
|
+
return await new Promise<T>((resolve, reject) => {
|
|
34
|
+
let tx = database.transaction('outbox', mode)
|
|
35
|
+
let request = run(tx.objectStore('outbox'))
|
|
36
|
+
tx.oncomplete = () => resolve(request.result)
|
|
37
|
+
tx.onabort = tx.onerror = () => reject(tx.error ?? request.error)
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
load: async () => {
|
|
42
|
+
// One readonly transaction keeps keys and values paired under other tabs.
|
|
43
|
+
let rows: Awaited<ReturnType<LegacyOutbox['load']>> = []
|
|
44
|
+
await transaction('readonly', (s) => {
|
|
45
|
+
let request = s.openCursor()
|
|
46
|
+
request.onsuccess = () => {
|
|
47
|
+
let cursor = request.result
|
|
48
|
+
if (!cursor) return
|
|
49
|
+
rows.push([String(cursor.key), cursor.value])
|
|
50
|
+
cursor.continue()
|
|
51
|
+
}
|
|
52
|
+
return request
|
|
53
|
+
})
|
|
54
|
+
return rows
|
|
55
|
+
},
|
|
56
|
+
remove: async (key) => {
|
|
57
|
+
await transaction('readwrite', (s) => s.delete(key))
|
|
58
|
+
},
|
|
59
|
+
close: () => {
|
|
60
|
+
void opening?.then((db) => db?.close(), () => {})
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
}
|