@soffits/dsh-card-board 0.17.4 → 0.18.0
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/CHANGELOG.md +6 -0
- package/README.md +4 -2
- package/client.js +21 -14
- package/index.js +4 -3
- package/package.json +1 -1
- package/src/presses.js +4 -1
- package/src/routes.js +14 -5
- package/src/schema.js +15 -4
- package/src/store.js +7 -7
- package/src/watch.js +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.18.0
|
|
4
|
+
|
|
5
|
+
A press names its row by the row's `key` (`source.row` in the event is now that key), so it lands on the row the person tapped even when the card was rewritten in between. Before, it named the row by its place: after a handled row dropped out, or a quick second tick, a press could answer or tick the row below it, since rows often share button ids. A row without a key still goes by its place; an index that points at a keyed row is refused. Rows ticked this visit are kept apart by key too, so ticking a second one no longer hides the first.
|
|
6
|
+
|
|
7
|
+
Open live streams now end when the plugin is unloaded or reloaded, so pages reconnect instead of waiting on a stream that will never send again (the cleanup was registered on an event Cordis doesn't send, so file watches leaked too). A card that can be found but not read shows as a broken card instead of failing the whole board, an unreadable action log no longer blocks every board, and a failing change listener is logged instead of escaping.
|
|
8
|
+
|
|
3
9
|
## 0.17.4
|
|
4
10
|
|
|
5
11
|
The opened view wraps a long unbroken word (an id, a key, a path) in its heading and text instead of growing wider than a phone screen and scrolling sideways, and an opened row's tick box flows in one row with its other buttons.
|
package/README.md
CHANGED
|
@@ -329,16 +329,18 @@ The plugin doesn't act on a press itself. It checks that the person may see the
|
|
|
329
329
|
"person": "alex",
|
|
330
330
|
"user": "<verified user id>",
|
|
331
331
|
"at": "2026-03-02T09:41:12.000Z",
|
|
332
|
-
"source": { "plugin": "dsh-card-board", "board": "home", "card": "chores", "row":
|
|
332
|
+
"source": { "plugin": "dsh-card-board", "board": "home", "card": "chores", "row": "chore-2" }
|
|
333
333
|
}
|
|
334
334
|
```
|
|
335
335
|
|
|
336
|
+
`source.row` names the row by its `key`, so a press lands on the row the person saw even when the card was rewritten in between; a row without a key goes by its place in `rows`, which a rewrite can shift, so give every row with buttons a key.
|
|
337
|
+
|
|
336
338
|
It's appended to the action log, emitted in-process as the Cordis event `card-board/action`, and published on channel `ui.action.<kind>` through [dsh-cron-jobs](https://github.com/soffits/dsh-cron-jobs) when that's installed, so a job subscribed to `ui.action.done` can mark the thing done wherever it lives. `person` is `owner` on a single-person DSH.
|
|
337
339
|
|
|
338
340
|
Taking a press back is another press, appended to the same log, so every record says who, when, what and whether it was undone. Its `action` is `undo` (channel `ui.action.undo`), `undoes` names the press, `of` is the kind it takes back, `inverse` the declared name, and `payload` is the action's own payload without the time the person picked, plus the inverse's. The press keeps the inverse as the card offered it, so an undo works after the card was rewritten, and a press taken back shows as `undone`. A handler that receives a press and its undo in one batch should treat the pair as nothing happening.
|
|
339
341
|
|
|
340
342
|
```json
|
|
341
|
-
{ "press": "5d0f…", "action": "undo", "of": "done", "id": "library-books:done", "undoes": "fcb114dd-3890-42e6-af4b-b23173edf8e0", "inverse": "reopen", "payload": {}, "person": "alex", "at": "2026-03-02T09:41:15.000Z", "source": { "plugin": "dsh-card-board", "board": "home", "card": "chores", "row":
|
|
343
|
+
{ "press": "5d0f…", "action": "undo", "of": "done", "id": "library-books:done", "undoes": "fcb114dd-3890-42e6-af4b-b23173edf8e0", "inverse": "reopen", "payload": {}, "person": "alex", "at": "2026-03-02T09:41:15.000Z", "source": { "plugin": "dsh-card-board", "board": "home", "card": "chores", "row": "chore-2" } }
|
|
342
344
|
```
|
|
343
345
|
|
|
344
346
|
The press log is never a second source of the item's state: a press only marks the gap until the owner of the item writes the card again, and after that a row's box follows the card's `checked`.
|
package/client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @soffits/dsh-card-board 0.
|
|
1
|
+
/* @soffits/dsh-card-board 0.18.0: built by scripts/build.mjs from src/client/. Do not edit. */
|
|
2
2
|
window.__ModuleLoader__.load({
|
|
3
3
|
id: "@soffits/dsh-card-board",
|
|
4
4
|
factory: (require) => {
|
|
@@ -982,12 +982,14 @@ function dropAfter(rect, x, y, single) {
|
|
|
982
982
|
|
|
983
983
|
// src/client/ticks.js
|
|
984
984
|
var doneOf = (row) => row?.actions?.find((action) => action.kind === "done" && action.label === void 0);
|
|
985
|
+
var rowRef = (row, index) => row?.key ?? index;
|
|
986
|
+
var keptId = (row) => row.key ?? doneOf(row)?.id;
|
|
985
987
|
function keepOf(row, index) {
|
|
986
988
|
const done = doneOf(row);
|
|
987
|
-
return done === void 0 ? void 0 : { id:
|
|
989
|
+
return done === void 0 ? void 0 : { id: keptId(row), index, row: { ...row, checked: true, actions: [done] } };
|
|
988
990
|
}
|
|
989
991
|
function keepTicked(rows, kept = []) {
|
|
990
|
-
const present = new Set(rows.map(
|
|
992
|
+
const present = new Set(rows.map(keptId));
|
|
991
993
|
const missing = kept.filter((entry) => !present.has(entry.id)).sort((a, b) => a.index - b.index);
|
|
992
994
|
if (missing.length === 0) return rows;
|
|
993
995
|
const merged = [...rows];
|
|
@@ -1118,13 +1120,14 @@ function Row({ lead, title, sub, meta, value, spark, row, index, washCount, fres
|
|
|
1118
1120
|
buttons?.length > 0 && (0, import_react6.createElement)(
|
|
1119
1121
|
"span",
|
|
1120
1122
|
{ className: "cb-rowActions" },
|
|
1121
|
-
buttons.some((action) => action.kind === "step") && rowActions(index, buttons, "steps"),
|
|
1122
|
-
rowActions(index, buttons, "buttons")
|
|
1123
|
+
buttons.some((action) => action.kind === "step") && rowActions(rowRef(row, index), buttons, "steps"),
|
|
1124
|
+
rowActions(rowRef(row, index), buttons, "buttons")
|
|
1123
1125
|
)
|
|
1124
1126
|
);
|
|
1125
1127
|
}
|
|
1126
1128
|
function DoneBox({ row, index, done, rowControls, t, labelled = false }) {
|
|
1127
|
-
const
|
|
1129
|
+
const ref = rowRef(row, index);
|
|
1130
|
+
const { checked, undo } = doneState(row, rowControls.latest(ref, done.id));
|
|
1128
1131
|
const label = t(checked ? undo ? "markNotDone" : "checked" : "markDone");
|
|
1129
1132
|
return (0, import_react6.createElement)(
|
|
1130
1133
|
"span",
|
|
@@ -1135,7 +1138,7 @@ function DoneBox({ row, index, done, rowControls, t, labelled = false }) {
|
|
|
1135
1138
|
title: label,
|
|
1136
1139
|
label: (0, import_react6.createElement)("span", { className: labelled ? void 0 : "cb-visuallyHidden" }, label),
|
|
1137
1140
|
onChange: (value) => {
|
|
1138
|
-
if (value) rowControls.press(
|
|
1141
|
+
if (value) rowControls.press(ref, done);
|
|
1139
1142
|
else if (undo) rowControls.undo(undo);
|
|
1140
1143
|
}
|
|
1141
1144
|
})
|
|
@@ -1150,7 +1153,7 @@ function ListCard({ data, live, locale, t, rowActions, ask, all = false, onOpenR
|
|
|
1150
1153
|
const hidden = listed.length - rows.length;
|
|
1151
1154
|
const ticked = (row) => {
|
|
1152
1155
|
const done = doneOf(row);
|
|
1153
|
-
return done !== void 0 && rowControls !== void 0 ? doneState(row, rowControls.latest(data.rows.indexOf(row), done.id)).checked : row.checked === true;
|
|
1156
|
+
return done !== void 0 && rowControls !== void 0 ? doneState(row, rowControls.latest(rowRef(row, data.rows.indexOf(row)), done.id)).checked : row.checked === true;
|
|
1154
1157
|
};
|
|
1155
1158
|
const progress = data.progress;
|
|
1156
1159
|
return (0, import_react6.createElement)(
|
|
@@ -1224,12 +1227,12 @@ function OpenedRow({ row, kind, index, live, locale, t, rowActions, ask, rowCont
|
|
|
1224
1227
|
(buttons.length > 0 || done && rowControls) && (0, import_react6.createElement)(
|
|
1225
1228
|
"footer",
|
|
1226
1229
|
{ className: "cb-openActions" },
|
|
1227
|
-
buttons.some((action) => action.kind === "step") && rowActions(index, buttons, "steps", false),
|
|
1230
|
+
buttons.some((action) => action.kind === "step") && rowActions(rowRef(row, index), buttons, "steps", false),
|
|
1228
1231
|
(0, import_react6.createElement)(
|
|
1229
1232
|
"div",
|
|
1230
1233
|
{ className: "cb-openButtons" },
|
|
1231
1234
|
done && rowControls && (0, import_react6.createElement)(DoneBox, { row, index, done, rowControls, t, labelled: true }),
|
|
1232
|
-
buttons.some((action) => action.kind !== "step") && rowActions(index, buttons, "buttons", false)
|
|
1235
|
+
buttons.some((action) => action.kind !== "step") && rowActions(rowRef(row, index), buttons, "buttons", false)
|
|
1233
1236
|
)
|
|
1234
1237
|
)
|
|
1235
1238
|
);
|
|
@@ -1561,10 +1564,14 @@ function Card({ entry, live, boardId, assistant, tracks, active, locale, t, pres
|
|
|
1561
1564
|
lines: row === void 0 ? summaryLines(card, locale, t).slice(0, 15) : [line],
|
|
1562
1565
|
context: { board: boardId, card: entry.id, ...row === void 0 ? {} : { row }, type: card.type, updatedAt: card.updatedAt }
|
|
1563
1566
|
});
|
|
1564
|
-
const
|
|
1567
|
+
const indexOf = (row) => typeof row === "string" ? card.data.rows.findIndex((other) => other.key === row) : row;
|
|
1568
|
+
const rowLine = (row) => card.type === "status" ? statusRowLine(card.data.rows[indexOf(row)], locale) : listRowLine(card.data.rows[indexOf(row)]);
|
|
1565
1569
|
const askName = assistant ? t("action.chatNamed", { name: assistant }) : void 0;
|
|
1566
1570
|
const named = (list) => assistant ? list?.map((action) => action.kind === "chat" && action.label === void 0 ? { ...action, label: askName } : action) : list;
|
|
1567
|
-
const onPress = (target) => (action, extra) =>
|
|
1571
|
+
const onPress = (target) => (action, extra) => {
|
|
1572
|
+
const index = target.row === void 0 ? -1 : indexOf(target.row);
|
|
1573
|
+
return press(action, extra, { card: entry.id, ...target }, index >= 0 ? { row: card.data.rows[index], index } : void 0);
|
|
1574
|
+
};
|
|
1568
1575
|
const rowActions = actions && ((row, list, part2, compact = true) => (0, import_react10.createElement)(actions.ActionBar, {
|
|
1569
1576
|
actions: named(list),
|
|
1570
1577
|
part: part2,
|
|
@@ -2048,11 +2055,11 @@ function BoardsPage() {
|
|
|
2048
2055
|
showToast({ text: "toast.undoFailed" });
|
|
2049
2056
|
}
|
|
2050
2057
|
}, [post, showToast]);
|
|
2051
|
-
const press = (0, import_react15.useCallback)(async (action, extra, target,
|
|
2058
|
+
const press = (0, import_react15.useCallback)(async (action, extra, target, at2) => {
|
|
2052
2059
|
const answer = await post({ ...target, id: action.id, ...extra });
|
|
2053
2060
|
if (answer?.undoable) {
|
|
2054
2061
|
showToast({ text: TOAST_KEYS[action.kind] ?? "toast.event", undo: () => undo(answer.press, target.card) });
|
|
2055
|
-
const keep = action.kind === "done" &&
|
|
2062
|
+
const keep = action.kind === "done" && at2 !== void 0 ? keepOf(at2.row, at2.index) : void 0;
|
|
2056
2063
|
if (keep) setKept((prev) => ({ ...prev, [target.card]: withKept(prev[target.card], keep) }));
|
|
2057
2064
|
}
|
|
2058
2065
|
return answer;
|
package/index.js
CHANGED
|
@@ -68,9 +68,9 @@ export function apply(ctx, config) {
|
|
|
68
68
|
timeoutSeconds: config.actionTimeoutSeconds ?? 300,
|
|
69
69
|
warn: message => logger.warn(message),
|
|
70
70
|
})
|
|
71
|
-
const watches = createWatches()
|
|
72
|
-
ctx.
|
|
73
|
-
const routes = createRoutes({
|
|
71
|
+
const watches = createWatches({ warn: message => logger.warn(message) })
|
|
72
|
+
ctx.effect(() => () => watches.close())
|
|
73
|
+
const { routes, close } = createRoutes({
|
|
74
74
|
dataDir,
|
|
75
75
|
people,
|
|
76
76
|
identity: () => ctx.get('requestIdentity'),
|
|
@@ -82,6 +82,7 @@ export function apply(ctx, config) {
|
|
|
82
82
|
messages: createMessages(fileURLToPath(new URL('./locale', import.meta.url))),
|
|
83
83
|
version,
|
|
84
84
|
})
|
|
85
|
+
ctx.effect(() => close)
|
|
85
86
|
for (const route of routes) ctx.connection.fetch.register(route)
|
|
86
87
|
logger.info(`serving boards from ${dataDir} (${people.enabled ? 'per person' : 'single owner'})`)
|
|
87
88
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soffits/dsh-card-board",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "A data-driven card board for DeepSeek Harness: scripts write small JSON cards, the Web UI shows each person the boards they may see.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/src/presses.js
CHANGED
|
@@ -64,7 +64,10 @@ async function readTail(path) {
|
|
|
64
64
|
*/
|
|
65
65
|
export function createPresses({ logPath, publisher, notify = () => {}, timeoutSeconds, warn = () => {}, now = Date.now }) {
|
|
66
66
|
let recent
|
|
67
|
-
const loaded = readTail(logPath).then(events => { recent = events }
|
|
67
|
+
const loaded = readTail(logPath).then(events => { recent = events }, error => {
|
|
68
|
+
warn(`action log ${logPath} unreadable, starting without recent presses: ${error.message}`)
|
|
69
|
+
recent = []
|
|
70
|
+
})
|
|
68
71
|
|
|
69
72
|
async function list() {
|
|
70
73
|
await loaded
|
package/src/routes.js
CHANGED
|
@@ -20,7 +20,7 @@ import { join } from 'node:path'
|
|
|
20
20
|
import { mayAct, maySee, maySeeCard, viewerOf, withoutActions } from './access.js'
|
|
21
21
|
import { parseArrangement } from './arrange.js'
|
|
22
22
|
import { LANGUAGE_ID } from './messages.js'
|
|
23
|
-
import { ID_PATTERN, PRESS_KINDS, findAction } from './schema.js'
|
|
23
|
+
import { ID_PATTERN, KEY_PATTERN, PRESS_KINDS, findAction } from './schema.js'
|
|
24
24
|
import { cardVersions, freshness, parseSeen } from './seen.js'
|
|
25
25
|
import { boardTag, cardPath, cardTag, listBoards, readBoard, readCard, readCards, resolveDataDir } from './store.js'
|
|
26
26
|
|
|
@@ -63,6 +63,9 @@ const NO_PROVIDER = 'This board needs a sign-in plugin that provides requestIden
|
|
|
63
63
|
* @param {number} [options.heartbeatMs]
|
|
64
64
|
*/
|
|
65
65
|
export function createRoutes({ dataDir, people, identity, pollSeconds, presses, seen, arrange, watches, messages, version = '', heartbeatMs = HEARTBEAT_MS }) {
|
|
66
|
+
/** Ends each open events stream. DSH only drops a route on unload, so a stream it already answered would live on. */
|
|
67
|
+
const streams = new Set()
|
|
68
|
+
|
|
66
69
|
/** The viewer and their board, or the Response that refuses them. */
|
|
67
70
|
async function access(board) {
|
|
68
71
|
const viewer = await viewerOf(people, identity())
|
|
@@ -154,14 +157,20 @@ export function createRoutes({ dataDir, people, identity, pollSeconds, presses,
|
|
|
154
157
|
let unwatch = () => {}
|
|
155
158
|
let unarrange = () => {}
|
|
156
159
|
const heartbeat = setInterval(() => send(': ping\n\n'), heartbeatMs)
|
|
160
|
+
const end = () => {
|
|
161
|
+
finish()
|
|
162
|
+
try { controller.close() } catch { /* already closed */ }
|
|
163
|
+
}
|
|
157
164
|
finish = () => {
|
|
158
165
|
if (!open) return
|
|
159
166
|
open = false
|
|
160
167
|
clearInterval(heartbeat)
|
|
161
168
|
unwatch()
|
|
162
169
|
unarrange()
|
|
170
|
+
streams.delete(end)
|
|
163
171
|
request.signal?.removeEventListener?.('abort', finish)
|
|
164
172
|
}
|
|
173
|
+
streams.add(end)
|
|
165
174
|
request.signal?.addEventListener?.('abort', finish)
|
|
166
175
|
send(': connected\n\n')
|
|
167
176
|
// The viewer's own arrangement changing elsewhere (another device) reaches this page too.
|
|
@@ -172,8 +181,7 @@ export function createRoutes({ dataDir, people, identity, pollSeconds, presses,
|
|
|
172
181
|
const again = await access(id)
|
|
173
182
|
if (again.refused) {
|
|
174
183
|
data({ type: 'gone' })
|
|
175
|
-
|
|
176
|
-
try { controller.close() } catch { /* already closed */ }
|
|
184
|
+
end()
|
|
177
185
|
return
|
|
178
186
|
}
|
|
179
187
|
}
|
|
@@ -250,7 +258,7 @@ export function createRoutes({ dataDir, people, identity, pollSeconds, presses,
|
|
|
250
258
|
if (undo !== undefined) return undoPress({ board, card, undo })
|
|
251
259
|
if (typeof board !== 'string' || !ID_PATTERN.test(board) || typeof card !== 'string' || !ID_PATTERN.test(card) || typeof id !== 'string')
|
|
252
260
|
return json(400, { error: 'Say which board, card and action.' })
|
|
253
|
-
if (row !== undefined && !(Number.isInteger(row) && row >= 0)) return json(400, { error: 'row must be a row index.' })
|
|
261
|
+
if (row !== undefined && !(Number.isInteger(row) && row >= 0) && !(typeof row === 'string' && KEY_PATTERN.test(row))) return json(400, { error: 'row must be a row key, or the index of a row without one.' })
|
|
254
262
|
if (until !== undefined && (typeof until !== 'string' || !DATE_TIME.test(until) || Number.isNaN(Date.parse(until))))
|
|
255
263
|
return json(400, { error: 'until must be an ISO date-time with a zone.' })
|
|
256
264
|
const viewer = await viewerOf(people, identity())
|
|
@@ -288,7 +296,7 @@ export function createRoutes({ dataDir, people, identity, pollSeconds, presses,
|
|
|
288
296
|
return json(200, { press: result.event.press, state: 'pending', at: result.event.at, undoes: result.event.undoes })
|
|
289
297
|
}
|
|
290
298
|
|
|
291
|
-
|
|
299
|
+
const routes = [
|
|
292
300
|
{ path: BOARDS_PATH, methods: ['GET'], requestBody: 'buffered', fetch: boards },
|
|
293
301
|
{ path: BOARD_PATH, methods: ['GET'], requestBody: 'buffered', fetch: board },
|
|
294
302
|
{ path: CARD_PATH, methods: ['GET'], requestBody: 'buffered', fetch: card },
|
|
@@ -298,4 +306,5 @@ export function createRoutes({ dataDir, people, identity, pollSeconds, presses,
|
|
|
298
306
|
{ path: LOCALE_PATH, methods: ['GET'], requestBody: 'buffered', fetch: locale },
|
|
299
307
|
{ path: ACTION_PATH, methods: ['POST'], requestBody: 'buffered', fetch: action },
|
|
300
308
|
]
|
|
309
|
+
return { routes, close: () => { for (const end of [...streams]) end() } }
|
|
301
310
|
}
|
package/src/schema.js
CHANGED
|
@@ -603,14 +603,25 @@ export function checkCard(card) {
|
|
|
603
603
|
return c.problems
|
|
604
604
|
}
|
|
605
605
|
|
|
606
|
+
/**
|
|
607
|
+
* The row a press names: by its `key`, so a press still finds it after the card
|
|
608
|
+
* was rewritten; only a row without a key goes by its place.
|
|
609
|
+
*/
|
|
610
|
+
export function findRow(card, row) {
|
|
611
|
+
const rows = card?.data?.rows
|
|
612
|
+
if (!Array.isArray(rows)) return undefined
|
|
613
|
+
if (typeof row === 'string') return rows.find(candidate => candidate?.key === row)
|
|
614
|
+
return rows[row]?.key === undefined ? rows[row] : undefined
|
|
615
|
+
}
|
|
616
|
+
|
|
606
617
|
/**
|
|
607
618
|
* The action a press names, looked up in the card as written: on the card
|
|
608
|
-
* itself, or on
|
|
609
|
-
* those its detail shows when opened. Undefined when there is no
|
|
610
|
-
* so a browser can only press what the data offers.
|
|
619
|
+
* itself, or on a row of a list or status card (`findRow`), among its own
|
|
620
|
+
* buttons and those its detail shows when opened. Undefined when there is no
|
|
621
|
+
* such action, so a browser can only press what the data offers.
|
|
611
622
|
*/
|
|
612
623
|
export function findAction(card, actionId, row) {
|
|
613
|
-
const holder = row === undefined ? card : card
|
|
624
|
+
const holder = row === undefined ? card : findRow(card, row)
|
|
614
625
|
const list = [holder?.actions, holder?.detail?.actions].flatMap(value => (Array.isArray(value) ? value : []))
|
|
615
626
|
return list.find(action => action?.id === actionId)
|
|
616
627
|
}
|
package/src/store.js
CHANGED
|
@@ -19,17 +19,17 @@ const MAX_BOARD_BYTES = 64 * 1024
|
|
|
19
19
|
|
|
20
20
|
/** A file's content if it is a regular file inside `root` and not too big; else a reason. */
|
|
21
21
|
async function readInside(root, path, maxBytes) {
|
|
22
|
-
let real
|
|
23
22
|
try {
|
|
24
|
-
real = await realpath(path)
|
|
23
|
+
const real = await realpath(path)
|
|
24
|
+
if (!real.startsWith(root + sep)) return { problem: 'points outside the data folder' }
|
|
25
|
+
const info = await stat(real)
|
|
26
|
+
if (!info.isFile()) return { problem: 'is not a file' }
|
|
27
|
+
if (info.size > maxBytes) return { problem: `is larger than ${Math.round(maxBytes / 1024)} KB` }
|
|
28
|
+
return { text: await readFile(real, 'utf8') }
|
|
25
29
|
} catch (error) {
|
|
30
|
+
// Gone between two of the reads (a producer replacing it) counts as missing, like gone before them.
|
|
26
31
|
return { missing: error.code === 'ENOENT', problem: error.code === 'ENOENT' ? 'file not found' : `cannot read: ${error.code ?? error.message}` }
|
|
27
32
|
}
|
|
28
|
-
if (!real.startsWith(root + sep)) return { problem: 'points outside the data folder' }
|
|
29
|
-
const info = await stat(real)
|
|
30
|
-
if (!info.isFile()) return { problem: 'is not a file' }
|
|
31
|
-
if (info.size > maxBytes) return { problem: `is larger than ${Math.round(maxBytes / 1024)} KB` }
|
|
32
|
-
return { text: await readFile(real, 'utf8') }
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
async function readJson(root, path, maxBytes, check) {
|
package/src/watch.js
CHANGED
|
@@ -40,8 +40,9 @@ export function changes(before, after) {
|
|
|
40
40
|
* @param {object} [options]
|
|
41
41
|
* @param {number} [options.pollMs] - the stat poll's interval (default 10 s)
|
|
42
42
|
* @param {number} [options.settleMs] - how long a burst of file events is gathered before one scan (default 120 ms)
|
|
43
|
+
* @param {(message: string) => void} [options.warn] - told when a change listener fails
|
|
43
44
|
*/
|
|
44
|
-
export function createWatches({ pollMs = 10_000, settleMs = 120 } = {}) {
|
|
45
|
+
export function createWatches({ pollMs = 10_000, settleMs = 120, warn = () => {} } = {}) {
|
|
45
46
|
const boards = new Map()
|
|
46
47
|
|
|
47
48
|
function open(dir) {
|
|
@@ -55,7 +56,9 @@ export function createWatches({ pollMs = 10_000, settleMs = 120 } = {}) {
|
|
|
55
56
|
const files = await snapshot(dir)
|
|
56
57
|
const events = entry.files === null ? [] : changes(entry.files, files)
|
|
57
58
|
entry.files = files
|
|
58
|
-
for (const event of events)
|
|
59
|
+
for (const event of events)
|
|
60
|
+
for (const listener of entry.listeners)
|
|
61
|
+
Promise.resolve().then(() => listener(event)).catch(error => warn(`a change listener failed: ${error.message}`))
|
|
59
62
|
} while (entry.again)
|
|
60
63
|
})().finally(() => { entry.scanning = null })
|
|
61
64
|
return entry.scanning
|