@vercel/board 0.31.0 → 0.33.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.
Files changed (166) hide show
  1. package/README.md +25 -20
  2. package/dist/{access-CY5xVMIK.mjs → access-N3XmkKXg.mjs} +3 -3
  3. package/dist/access.d.mts +4 -5
  4. package/dist/access.mjs +5 -5
  5. package/dist/{actors-Bm-ojWWT.mjs → actors-ihyN47OV.mjs} +3 -3
  6. package/dist/{auth-DLYSt_-A.d.mts → auth-D6z3rMNj.d.mts} +11 -93
  7. package/dist/{auth-CyO2aw5n.mjs → auth-r-_PeZyw.mjs} +39 -151
  8. package/dist/{backend-Bob-5CM7.d.mts → backend-CWpyR1A7.d.mts} +81 -51
  9. package/dist/backend-local.d.mts +28 -0
  10. package/dist/backend-local.mjs +2 -0
  11. package/dist/{chat-provider-DkFp2hrh.mjs → chat-provider-9hCT654s.mjs} +2 -2
  12. package/dist/{chat-provider-BChYrrA7.d.mts → chat-provider-DJpFUaFv.d.mts} +2 -3
  13. package/dist/cli-commands.d.mts +1 -1
  14. package/dist/cli-commands.mjs +1 -1
  15. package/dist/cli-embedded.d.mts +2 -2
  16. package/dist/cli-embedded.mjs +2 -2
  17. package/dist/cli.mjs +6 -6
  18. package/dist/{commands-DK4W3HCJ.d.mts → commands-BOBQHVqM.d.mts} +14 -0
  19. package/dist/{commands-L1JSGz2Z.mjs → commands-CHoMl06v.mjs} +39 -12
  20. package/dist/{conformance-DK43HiHf.mjs → conformance-qKmGLTAT.mjs} +40 -5
  21. package/dist/conformance.d.mts +1 -1
  22. package/dist/conformance.mjs +1 -1
  23. package/dist/{engine-DurYIRt8.mjs → engine-JxgZiikU.mjs} +6 -8
  24. package/dist/{errors-CJXhhzvT.mjs → errors-Pk0XV1hK.mjs} +56 -2
  25. package/dist/{events-lujPA3gQ.mjs → events-IQg0k281.mjs} +2 -2
  26. package/dist/exports-BuKjVq2t.d.mts +4 -0
  27. package/dist/exports-gHDHlg0i.mjs +3207 -0
  28. package/dist/{external-D3p5T57R.mjs → external-CYe424fO.mjs} +1 -1
  29. package/dist/{folds-DLUzfibJ.d.mts → folds-DjFTiqIM.d.mts} +38 -44
  30. package/dist/index-CXvvYNYj.d.mts +11 -0
  31. package/dist/index.d.mts +9 -8
  32. package/dist/index.mjs +21 -8
  33. package/dist/index.node.d.mts +5 -6
  34. package/dist/index.node.mjs +3 -3
  35. package/dist/inspect/app.js +95 -95
  36. package/dist/{internal-CvsrprnU-zZMpDiRY.mjs → internal-CvsrprnU-CEPOUpAv.mjs} +63 -43
  37. package/dist/local-BbLjA5vI.mjs +8818 -0
  38. package/dist/{main-Dz-8komG.mjs → main-CQpCZJFw.mjs} +140 -36
  39. package/dist/{backend-a2/store-memory.mjs → memory-7RRnLa4X.mjs} +3 -3
  40. package/dist/middleware-BU7rVi9F.mjs +103 -0
  41. package/dist/{client-COfYrgfV.d.mts → provider-BlzUvcM9.d.mts} +665 -5
  42. package/dist/{schemas-DBmUO6pr.mjs → schemas-BG205xds.mjs} +2 -5
  43. package/dist/{serve-CTmow-YH.mjs → serve-D8_W4UN6.mjs} +33 -24
  44. package/dist/{node-BgeGcwX0.mjs → server-BiIUXWbU.mjs} +419 -6
  45. package/dist/{serving-DBFRo6U_.mjs → serving-D7rcUtSC.mjs} +1 -1
  46. package/dist/{sql-CT5xVuGr.mjs → sql-BQzKUqQt.mjs} +349 -114
  47. package/dist/sqlite-DCtZFEVm.mjs +30 -0
  48. package/dist/{sqlite-db-0WeSOEZN.mjs → sqlite-db-qLTs52Ny.mjs} +2 -3
  49. package/dist/{store-codec-pAG2oPgQ-SqDXlPBR.mjs → store-N8PXxDAS-BdL4Sq-f.mjs} +6 -2
  50. package/dist/{store-memory-B0PkVSuQ.mjs → store-memory-CKQVEzXN.mjs} +2 -4
  51. package/dist/store-memory-OdGsc-t_.mjs +2 -0
  52. package/dist/{store-polling-BZt2Rf3D-Div-bJ_D.mjs → store-polling-BZt2Rf3D-oh3aU_An.mjs} +1 -1
  53. package/dist/store-sqlite-CTxAVCcz.mjs +2 -0
  54. package/dist/{store-sqlite-D85t3tE7.mjs → store-sqlite-D6fIszST.mjs} +3 -4
  55. package/dist/sync-chat-sdk.d.mts +2 -2
  56. package/dist/sync-chat-sdk.mjs +2 -2
  57. package/dist/sync-github.d.mts +2 -2
  58. package/dist/sync-github.mjs +2 -2
  59. package/dist/sync-linear.d.mts +2 -3
  60. package/dist/sync-linear.mjs +2 -2
  61. package/dist/sync-slack.d.mts +3 -3
  62. package/dist/sync-slack.mjs +4 -4
  63. package/dist/sync.d.mts +2 -2
  64. package/dist/sync.mjs +2 -2
  65. package/dist/{watchers-hash-BjwlnGD9.mjs → targets-CknPGGVi.mjs} +40 -10
  66. package/dist/{tokens-Dnyd_y1n.mjs → tokens-DPKjl3jf.mjs} +15 -43
  67. package/docs/01-board/01-mounting.md +243 -288
  68. package/docs/01-board/03-identity.md +41 -50
  69. package/docs/01-board/04-messages.md +19 -16
  70. package/docs/01-board/05-reading.md +3 -3
  71. package/docs/01-board/06-watchers.md +58 -105
  72. package/docs/01-board/07-schedules.md +21 -41
  73. package/docs/01-board/08-middleware.md +11 -17
  74. package/docs/01-board/09-access.md +76 -313
  75. package/docs/01-board/10-local.md +81 -0
  76. package/docs/01-quickstart.md +49 -126
  77. package/docs/02-sync/01-overview.md +25 -80
  78. package/docs/02-sync/02-functions.md +10 -16
  79. package/docs/02-sync/03-slack.md +13 -26
  80. package/docs/02-sync/04-github.md +8 -20
  81. package/docs/02-sync/07-linear.md +6 -10
  82. package/docs/03-guides/02-inspector.md +3 -3
  83. package/docs/03-guides/03-ci.md +88 -128
  84. package/docs/03-guides/04-triage.md +7 -15
  85. package/docs/03-guides/05-agent-factory.md +30 -36
  86. package/docs/04-reference/01-cli.md +118 -32
  87. package/docs/04-reference/02-board.md +60 -74
  88. package/docs/04-reference/03-http.md +119 -57
  89. package/docs/04-reference/05-conformance.md +31 -45
  90. package/docs/index.md +41 -65
  91. package/package.json +12 -83
  92. package/dist/a2-DngWY2Eb.mjs +0 -4238
  93. package/dist/access-DPcrKIH_.d.mts +0 -37
  94. package/dist/backend-a2/blob-vercel.d.mts +0 -8
  95. package/dist/backend-a2/blob-vercel.mjs +0 -81
  96. package/dist/backend-a2/contract.d.mts +0 -828
  97. package/dist/backend-a2/contract.mjs +0 -5
  98. package/dist/backend-a2/scheduler-local.d.mts +0 -11
  99. package/dist/backend-a2/scheduler-local.mjs +0 -2
  100. package/dist/backend-a2/scheduler-qstash.d.mts +0 -79
  101. package/dist/backend-a2/scheduler-qstash.mjs +0 -522
  102. package/dist/backend-a2/scheduler-vercel.d.mts +0 -38
  103. package/dist/backend-a2/scheduler-vercel.mjs +0 -204
  104. package/dist/backend-a2/store-memory.d.mts +0 -11
  105. package/dist/backend-a2/store-postgres.d.mts +0 -38
  106. package/dist/backend-a2/store-postgres.mjs +0 -2977
  107. package/dist/backend-a2/store-redis-http.d.mts +0 -17
  108. package/dist/backend-a2/store-redis-http.mjs +0 -520
  109. package/dist/backend-a2/store-redis.d.mts +0 -31
  110. package/dist/backend-a2/store-redis.mjs +0 -88
  111. package/dist/backend-a2/store-sqlite.d.mts +0 -12
  112. package/dist/backend-a2/store-sqlite.mjs +0 -31
  113. package/dist/backend-a2.d.mts +0 -2633
  114. package/dist/backend-a2.mjs +0 -3
  115. package/dist/backend-http-BRrRbjRx.d.mts +0 -672
  116. package/dist/backend-http-CvUKOn-m.mjs +0 -585
  117. package/dist/backend-http-D8mUzuKQ.mjs +0 -18
  118. package/dist/backend-http.d.mts +0 -10
  119. package/dist/backend-http.mjs +0 -2
  120. package/dist/backend-http.node.d.mts +0 -10
  121. package/dist/backend-http.node.mjs +0 -2
  122. package/dist/backend-vercel-Ba8JDtqW.mjs +0 -86
  123. package/dist/backend-vercel-BaSEUdwg.d.mts +0 -674
  124. package/dist/backend-vercel-CmY9yZ9m.mjs +0 -1656
  125. package/dist/backend-vercel.d.mts +0 -9
  126. package/dist/backend-vercel.mjs +0 -11
  127. package/dist/backend-vercel.node.d.mts +0 -17
  128. package/dist/backend-vercel.node.mjs +0 -2
  129. package/dist/blob-Bx8QPWEd.d.mts +0 -40
  130. package/dist/blob-WbB2DJKn.mjs +0 -201
  131. package/dist/errors-2vGs49Db.d.mts +0 -16
  132. package/dist/exports-CWIdN0Ub.mjs +0 -1389
  133. package/dist/exports-FBOQWT7O.d.mts +0 -5
  134. package/dist/files-SniSmeEr.mjs +0 -47
  135. package/dist/folds-Cu9Q9zyQ.mjs +0 -207
  136. package/dist/index-Ho-ayyQL.d.mts +0 -11
  137. package/dist/index.default-BUcwDaAe.mjs +0 -12
  138. package/dist/local-C76Fy5ad.mjs +0 -44
  139. package/dist/middleware-BavYSDUa.mjs +0 -62
  140. package/dist/platform-B4TnJtWu-Do3agKr5.mjs +0 -32
  141. package/dist/project-CQ4VUibA.mjs +0 -124
  142. package/dist/provider-gynDUoyW.d.mts +0 -665
  143. package/dist/redis-tables-DHf85ixI.mjs +0 -3895
  144. package/dist/reducer-Bswr11ar-P324o9vn.mjs +0 -74
  145. package/dist/reducer-CYPHsSmd-BXjGiptm.d.mts +0 -170
  146. package/dist/reducers-DcENwtwZ.mjs +0 -538
  147. package/dist/retryable-lazy-DZWmHpii-DpTc5PIP.mjs +0 -19
  148. package/dist/scheduler-task-X1SToDjP-D2Il2rln.mjs +0 -69
  149. package/dist/server-B9gu0qi1-DI1WvcVK.d.mts +0 -391
  150. package/dist/server-DG8D6VV0.mjs +0 -17
  151. package/dist/server-DX7mM6nm-D7N_7bug.mjs +0 -3611
  152. package/dist/session-clear-XJYpmUpg-2q8l_FJR.mjs +0 -63
  153. package/dist/store-DEzcHZOA-B-5vhxef.d.mts +0 -540
  154. package/dist/store-N8PXxDAS-DWWgv-Vz.mjs +0 -5
  155. package/dist/store-memory-4IBl0Ztu.mjs +0 -2
  156. package/dist/store-presence-polling-JuAy2Ck2-Dh-g_KYM.mjs +0 -109
  157. package/dist/store-sqlite-iBTYYKBj.mjs +0 -2
  158. package/dist/stream-buffer-DrTyiIuo-Be10yOBR.mjs +0 -53
  159. package/dist/targets-Cgjs29T0.mjs +0 -33
  160. package/dist/types-CmrFjpml.d.mts +0 -102
  161. package/dist/wait-until-Dw4XrIDQ.mjs +0 -42
  162. package/docs/01-board/02-database.md +0 -258
  163. package/docs/04-reference/04-log.md +0 -247
  164. package/sql/postgres/board.sql +0 -145
  165. package/sql/postgres/notifications.sql +0 -24
  166. package/sql/postgres/schema.sql +0 -451
@@ -1,109 +0,0 @@
1
- import { r as POLL_TIMINGS } from "./internal-CvsrprnU-zZMpDiRY.mjs";
2
- import { n as defaultSleep } from "./store-polling-BZt2Rf3D-Div-bJ_D.mjs";
3
- //#region ../../node_modules/.pnpm/experimental-a2@0.24.0_@upstash+qstash@2.12.0_@vercel+queue@0.7.0_ai@7.0.130_zod@4.6.5__b1e2c243a963f2620a5d202817417c26/node_modules/experimental-a2/dist/store-presence-polling-JuAy2Ck2.js
4
- const key = ({ participant, field }) => JSON.stringify([participant, field]);
5
- function pollPresence({ read, deliver, sleep = defaultSleep }) {
6
- let stopped = false;
7
- let pending;
8
- let interval = Math.min(POLL_TIMINGS.activeFloorMs, POLL_TIMINGS.idleCeilingMs);
9
- let version = 0;
10
- const seen = /* @__PURE__ */ new Map();
11
- const activate = () => {
12
- version += 1;
13
- interval = Math.min(POLL_TIMINGS.activeFloorMs, POLL_TIMINGS.idleCeilingMs);
14
- pending?.cancel();
15
- };
16
- const ready = read().then((rows) => {
17
- if (stopped) return;
18
- for (const row of rows) seen.set(key(row), row);
19
- }).catch(() => void 0);
20
- /** Delivers how `rows` differ from what was seen; true when they do. */
21
- const reconcile = (rows) => {
22
- const live = /* @__PURE__ */ new Set();
23
- let changed = false;
24
- for (const row of rows) {
25
- const id = key(row);
26
- live.add(id);
27
- const prior = seen.get(id);
28
- seen.set(id, row);
29
- if (prior?.seen === row.seen && prior.at.getTime() === row.at.getTime() && JSON.stringify(prior.value) === JSON.stringify(row.value)) continue;
30
- changed = true;
31
- deliver({
32
- participant: row.participant,
33
- values: { [row.field]: row.value },
34
- seen: row.seen,
35
- at: row.at
36
- });
37
- }
38
- for (const [id, row] of seen) {
39
- if (live.has(id)) continue;
40
- seen.delete(id);
41
- changed = true;
42
- deliver({
43
- participant: row.participant,
44
- values: { [row.field]: null },
45
- seen: row.seen,
46
- at: row.at
47
- });
48
- }
49
- return changed;
50
- };
51
- const run = async () => {
52
- await ready;
53
- for (;;) {
54
- if (stopped) return;
55
- const before = version;
56
- pending = sleep(interval);
57
- await pending.promise;
58
- if (stopped) return;
59
- try {
60
- const reading = version;
61
- const rows = await read();
62
- if (stopped) return;
63
- if (version !== reading) continue;
64
- if (reconcile(rows)) activate();
65
- else if (version === before) interval = Math.min(interval * 2, POLL_TIMINGS.idleCeilingMs);
66
- } catch {
67
- interval = POLL_TIMINGS.idleCeilingMs;
68
- }
69
- }
70
- };
71
- run();
72
- return {
73
- ready,
74
- async snapshot(readSnapshot) {
75
- const reading = version;
76
- const rows = await readSnapshot();
77
- if (!stopped && version === reading && reconcile(rows)) activate();
78
- return rows;
79
- },
80
- wake: activate,
81
- update(patch) {
82
- for (const [field, value] of Object.entries(patch.values)) {
83
- const id = key({
84
- participant: patch.participant,
85
- field
86
- });
87
- if (value === null) {
88
- seen.delete(id);
89
- continue;
90
- }
91
- seen.set(id, {
92
- participant: patch.participant,
93
- field,
94
- value,
95
- seen: patch.seen,
96
- at: patch.at
97
- });
98
- }
99
- activate();
100
- },
101
- stop() {
102
- stopped = true;
103
- pending?.cancel();
104
- seen.clear();
105
- }
106
- };
107
- }
108
- //#endregion
109
- export { pollPresence as t };
@@ -1,2 +0,0 @@
1
- import { t as sqlite } from "./store-sqlite-D85t3tE7.mjs";
2
- export { sqlite };
@@ -1,53 +0,0 @@
1
- import { i as PRESENCE_TIMINGS } from "./internal-CvsrprnU-zZMpDiRY.mjs";
2
- //#region ../../node_modules/.pnpm/experimental-a2@0.24.0_@upstash+qstash@2.12.0_@vercel+queue@0.7.0_ai@7.0.130_zod@4.6.5__b1e2c243a963f2620a5d202817417c26/node_modules/experimental-a2/dist/stream-buffer-DrTyiIuo.js
3
- const key = ({ participant, field }) => JSON.stringify([participant, field]);
4
- function presenceTombstones() {
5
- const stamps = /* @__PURE__ */ new Map();
6
- const prune = () => {
7
- const cutoff = Date.now() - PRESENCE_TIMINGS.tombstoneMs;
8
- for (const [id, stamp] of stamps) {
9
- if (stamp.keptAtMs > cutoff) return;
10
- stamps.delete(id);
11
- }
12
- };
13
- return {
14
- outranks(write) {
15
- if (stamps.size === 0) return false;
16
- prune();
17
- const stamp = stamps.get(key(write));
18
- return stamp !== void 0 && stamp.atMs > write.at.getTime();
19
- },
20
- keep(deletion) {
21
- prune();
22
- const id = key(deletion);
23
- stamps.delete(id);
24
- stamps.set(id, {
25
- atMs: deletion.at.getTime(),
26
- keptAtMs: Date.now()
27
- });
28
- },
29
- drop(field) {
30
- if (stamps.size > 0) stamps.delete(key(field));
31
- }
32
- };
33
- }
34
- const isSerializedEvent = (event) => "payloadJson" in event;
35
- const parseSerializedEvent = (event) => ({
36
- id: event.id,
37
- type: event.type,
38
- payload: JSON.parse(event.payloadJson),
39
- index: event.index,
40
- sessionId: event.sessionId,
41
- createdAt: new Date(event.createdAtMs)
42
- });
43
- /**
44
- * The next event a stream iterator already holds, removed without
45
- * awaiting its `next()`, which then continues after it; `undefined` when
46
- * it holds none. Call only while no `next()` is pending. The SSE encoder
47
- * writes these with the event `next()` just returned, so a buffered
48
- * backlog leaves in few writes.
49
- */
50
- const bufferedEvents = /* @__PURE__ */ new WeakMap();
51
- const takeBuffered = (iterator) => bufferedEvents.get(iterator)?.();
52
- //#endregion
53
- export { takeBuffered as a, presenceTombstones as i, isSerializedEvent as n, parseSerializedEvent as r, bufferedEvents as t };
@@ -1,33 +0,0 @@
1
- import { l as isThreadTarget } from "./external-D3p5T57R.mjs";
2
- import { n as replaceMentions, t as extractMentions } from "./mentions-CB6ShY4R.mjs";
3
- //#region src/server/targets.ts
4
- /** A target as a post or a receipt names it, resolved: a plain one's kind goes by its shape. */
5
- const syncTarget = (target) => typeof target === "string" ? {
6
- target,
7
- kind: isThreadTarget(target) ? "thread" : "channel"
8
- } : target;
9
- /** Whether `text` mentions anyone by email, `@[ada@vercel.com]`, which sync looks up. */
10
- const mentionsEmails = (text) => extractMentions(text).some((token) => token.kind === "actor" && token.actor.includes("@"));
11
- /**
12
- * `@[ada@vercel.com]`: each email `find` knows (a synced platform's user) becomes that user's
13
- * exact mention, `@[slack:user:U0456]`, so it reads natively there; the rest stay plain text.
14
- */
15
- async function withEmailMentions(text, find) {
16
- const emails = extractMentions(text).flatMap((token) => token.kind === "actor" && token.actor.includes("@") ? [token.actor] : []);
17
- if (emails.length === 0) return {
18
- text,
19
- found: []
20
- };
21
- const byEmail = /* @__PURE__ */ new Map();
22
- for (const email of emails) byEmail.set(email, await find?.(email).catch(() => null) ?? null);
23
- return {
24
- text: replaceMentions(text, (token) => {
25
- if (token.kind !== "actor" || !byEmail.has(token.actor)) return null;
26
- const actor = byEmail.get(token.actor);
27
- return actor ? `@[${actor.id}]` : token.actor;
28
- }),
29
- found: [...byEmail.values()].filter((actor) => actor !== null)
30
- };
31
- }
32
- //#endregion
33
- export { syncTarget as n, withEmailMentions as r, mentionsEmails as t };
@@ -1,102 +0,0 @@
1
- import { a as ExternalCopy, c as SyncedThread, g as BoardEvent, o as Message } from "./folds-DLUzfibJ.mjs";
2
- import { t as A2Store } from "./store-DEzcHZOA-B-5vhxef.mjs";
3
- //#region src/store/types.d.ts
4
- /**
5
- * What a query matches, resolved by the board: handles are already actor and
6
- * principal sets, so a backend never needs the actors.
7
- */
8
- type MessageFilter = {
9
- /** One channel, or with `subtree` it and every channel under it. */
10
- channel?: {
11
- path: string;
12
- subtree: boolean;
13
- };
14
- /** In one of these channels: those a reader may read. None matches nothing. */
15
- channels?: readonly string[];
16
- /** A thread: its root and its replies. */
17
- re?: number;
18
- /** Written by one of these actors, or by an agent of one of these people. */
19
- by?: {
20
- actors: readonly string[];
21
- principals: readonly string[];
22
- };
23
- /** Mentions one of these actors. */
24
- mentions?: readonly string[];
25
- /** The sync key it came from, or `board`. */
26
- from?: string;
27
- /** Lowercased: a substring of the lowercased text. */
28
- text?: string;
29
- /** Each on the message or its thread's root; `values: null` is any value. */
30
- labels?: readonly {
31
- key: string;
32
- values: readonly string[] | null;
33
- }[];
34
- };
35
- /** By message ID: `after` takes the first `limit` after it; otherwise the last `limit`. */
36
- type Page = {
37
- before?: number;
38
- after?: number;
39
- limit: number;
40
- };
41
- /** A thread as `/threads` lists it: its root, how many replies aren't deleted, and the latest. */
42
- type ThreadSummary = {
43
- root: Message;
44
- replies: number;
45
- last: Message | null;
46
- };
47
- /**
48
- * The board's messages, kept from its log. Each read says which log index it
49
- * reflects (`position`), so a reader knows what it has seen.
50
- */
51
- interface MessageTables {
52
- /** The last log index applied. */
53
- position(): Promise<number>;
54
- /** Applies one board event, exactly once: an event at or below the position changes nothing. */
55
- apply(event: BoardEvent): Promise<void>;
56
- /**
57
- * Applies `event` only if it's the very next one, and says whether it did: a
58
- * writer catching the tables up on its own write, without waiting on the consumer.
59
- */
60
- applyNext(event: BoardEvent): Promise<boolean>;
61
- message(id: number): Promise<Message | null>;
62
- /** The message a post with this event ID created. A root's thread key is one. */
63
- byEventId(eventId: string): Promise<Message | null>;
64
- /** Each of `ids` as it was right after event `index`; one not posted by then is absent. */
65
- messagesAt(ids: readonly number[], index: number): Promise<Map<number, Message>>;
66
- /** A thread's root and every reply, deleted ones included, by ID. */
67
- thread(root: number): Promise<Message[]>;
68
- messages(filter: MessageFilter, page: Page): Promise<{
69
- messages: Message[];
70
- position: number;
71
- }>;
72
- /** Threads with a message that matches, by their latest reply. */
73
- threads(filter: MessageFilter, page: Page): Promise<{
74
- threads: ThreadSummary[];
75
- position: number;
76
- }>;
77
- /** A thread's sync: its targets, and the platform thread it lives in on each. */
78
- syncOf(thread: string): Promise<SyncedThread | null>;
79
- /** The board thread a platform thread belongs to. */
80
- threadOf(externalThread: string): Promise<string | null>;
81
- /** Each message's copies, by target: where it went, or came from, on each platform. */
82
- copiesOf(ids: readonly number[]): Promise<Map<number, Record<string, ExternalCopy>>>;
83
- /** The board message a platform message is a copy of, or came in as. */
84
- messageOf(externalThread: string, platformMessage: string): Promise<number | null>;
85
- /** Every platform thread a board thread lives in. */
86
- externalThreads(): Promise<string[]>;
87
- /** The messages that carry an attachment, by ID. A deleted message carries none. */
88
- withAttachment(attachment: string): Promise<Message[]>;
89
- close(): Promise<void>;
90
- }
91
- /**
92
- * Where a board keeps everything: its A2 log, and the tables it reads from. Create one with
93
- * `postgres()`, `redis()`, `redisHttp()`, `sqlite()`, or `memory()` from `@vercel/board/backend-a2/store-*`.
94
- */
95
- type BoardStore = {
96
- /** The board's A2 store. */
97
- readonly log: A2Store;
98
- readonly tables: MessageTables;
99
- close(): Promise<void>;
100
- };
101
- //#endregion
102
- export { BoardStore as t };
@@ -1,42 +0,0 @@
1
- //#region src/client/ids.ts
2
- const hex = (bytes) => Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
3
- /** SHA-256 of `text`, in hex. */
4
- async function sha256(text) {
5
- return hex(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text))));
6
- }
7
- /**
8
- * A UUIDv8 from `parts`, exactly as A2's `idempotentId` makes one: the IDs a board derives for the
9
- * writes its own code makes, which no request may post with.
10
- */
11
- async function derivedId(...parts) {
12
- const bytes = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify(parts)))).slice(0, 16);
13
- bytes[6] = bytes[6] & 15 | 128;
14
- bytes[8] = bytes[8] & 63 | 128;
15
- const text = hex(bytes);
16
- return `${text.slice(0, 8)}-${text.slice(8, 12)}-${text.slice(12, 16)}-${text.slice(16, 20)}-${text.slice(20, 32)}`;
17
- }
18
- /** A derived ID's shape. */
19
- const DERIVED_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-8[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
20
- /**
21
- * A post's ID, from one derived for it, under `principal`: a board takes a `key:<principal>:` ID
22
- * only from that principal, so no one else can post with it first.
23
- */
24
- const keyId = async (principal, derived) => `key:${principal}:${(await sha256(`board-key\u001f${derived}`)).slice(0, 32)}`;
25
- /**
26
- * Whether `id` is exactly the shape `keyId` makes for `principal`. A prefix check isn't enough:
27
- * a principal's ID can be the start of another's (`oidc:gitlab.com:acme` and `oidc:gitlab.com:acme:ci`).
28
- */
29
- const isKeyIdOf = (id, principal) => id.startsWith(`key:${principal}:`) && /^[0-9a-f]{32}$/.test(id.slice(`key:${principal}:`.length));
30
- //#endregion
31
- //#region src/server/wait-until.ts
32
- /**
33
- * Keeps `task` running after the response, where the platform offers it: Vercel's request context, as A2
34
- * reads it too. Elsewhere it runs on in the process.
35
- */
36
- function waitUntil(task) {
37
- try {
38
- Reflect.get(globalThis, Symbol.for("@vercel/request-context"))?.get?.()?.waitUntil?.(task);
39
- } catch {}
40
- }
41
- //#endregion
42
- export { keyId as a, isKeyIdOf as i, DERIVED_ID as n, sha256 as o, derivedId as r, waitUntil as t };
@@ -1,258 +0,0 @@
1
- ---
2
- title: Database
3
- description: "Where a board on `a2()` keeps everything: Postgres or Redis in production, SQLite by default, memory in tests."
4
- ---
5
-
6
- ## Pick a store
7
-
8
- ```package-install
9
- npm i @vercel/board pg
10
- ```
11
-
12
- ```ts app/api/board/[[...path]]/route.ts
13
- import { board } from '@vercel/board'
14
- import { a2 } from '@vercel/board/backend-a2'
15
- import { postgres } from '@vercel/board/backend-a2/store-postgres'
16
-
17
- const team = board({
18
- backend: a2({
19
- store: postgres({ connectionString: process.env.DATABASE_URL! }),
20
- }),
21
- })
22
- export const GET = team.fetch, POST = team.fetch
23
- ```
24
-
25
- | Store | From | For |
26
- | --- | --- | --- |
27
- | `postgres({ connectionString })` | `@vercel/board/backend-a2/store-postgres` | production; needs `pg` |
28
- | `redis({ url })` | `@vercel/board/backend-a2/store-redis` | production, on Redis over TCP; needs `ioredis` |
29
- | `redisHttp({ url, token })` | `@vercel/board/backend-a2/store-redis-http` | production, on Upstash's REST API; needs nothing |
30
- | `sqlite({ path })` | `@vercel/board/backend-a2/store-sqlite` | development, one long-running server, and `vb serve`; `path` defaults to `.a2/dev.db` |
31
- | `memory({ clock })` | `@vercel/board/backend-a2/store-memory` | tests |
32
-
33
- Leave `store` out and it's `sqlite()`: a file at `.a2/dev.db`, under the
34
- working directory, in every environment. That suits development and one
35
- long-running server. On Vercel the filesystem isn't writable outside `/tmp`, so
36
- the board answers each request with a 500, `no_store`, until you pass a store.
37
- A SQLite file in `/tmp` would be a separate, throwaway board on each instance,
38
- so don't. See [Mounting](./01-mounting.md#options).
39
-
40
- ## What a store keeps
41
-
42
- One database holds two things:
43
-
44
- - **The log.** Every board fact is an event in one A2 session, `board`, in
45
- A2's tables (`a2_*`). It's the truth: nothing else is written directly.
46
- - **The tables.** board keeps its own tables (`board_*`) from the log, one
47
- event at a time, in order, and reads from them.
48
-
49
- | Table | Holds |
50
- | --- | --- |
51
- | `board_messages` | each message as it is now, with the columns filters use; a root's row also holds its reply count and its latest reply |
52
- | `board_versions` | each message after every event that changed it, so `vb tail` and watchers can show a change before and after |
53
- | `board_terms` | labels and mentions, so `--label` and `--mentions` are an index lookup |
54
- | `board_sync_threads`, `board_copies` | where each thread and message lives on each platform: a thread's targets and the platform thread on each, a message's copy on each |
55
- | `board_external_threads`, `board_external_messages` | the other way: which board thread and message a platform's thread and message are |
56
- | `board_positions` | the last log index the tables applied |
57
-
58
- On Redis the tables are hashes and sorted sets under
59
- `<keyPrefix>:{<keyPrefix>:board}`, with a sorted set for each channel, thread,
60
- author, mention, and label, so the same filters are a lookup there too.
61
-
62
- A post, a reply, a thread, and a channel's list of threads cost the same on a
63
- board of a hundred messages or a hundred thousand. Other lists stop as soon as
64
- they fill a page, so a filter that matches often is as fast. One that matches
65
- rarely, and `/threads` filtered by more than a channel, read further into the
66
- board to answer.
67
-
68
- ## Postgres
69
-
70
- Neither A2 nor board creates tables in Postgres. Apply one file, once per
71
- database, before the first deploy:
72
-
73
- ```bash
74
- psql "$DATABASE_URL" -f node_modules/@vercel/board/sql/postgres/schema.sql
75
- ```
76
-
77
- `schema.sql` holds A2's tables, then board's. Every statement creates only
78
- what's missing and leaves existing data alone, so it's safe to apply again. A
79
- board whose tables are missing answers with an error that names the file.
80
-
81
- On Vercel, apply it on every build, before the app builds. Neon from the
82
- Vercel Marketplace sets `DATABASE_URL`, and can give each preview deployment a
83
- branch of its own.
84
-
85
- ```js scripts/migrate.mjs
86
- import { readFileSync } from 'node:fs'
87
- import pg from 'pg'
88
-
89
- // The direct connection, when the database has one: migrations shouldn't go through a pooler.
90
- const client = new pg.Client({ connectionString: process.env.DATABASE_URL_UNPOOLED || process.env.DATABASE_URL })
91
- await client.connect()
92
- await client.query(readFileSync('node_modules/@vercel/board/sql/postgres/schema.sql', 'utf8'))
93
- await client.end()
94
- ```
95
-
96
- ```json package.json
97
- {
98
- "scripts": {
99
- "build": "node scripts/migrate.mjs && next build"
100
- }
101
- }
102
- ```
103
-
104
- With a migration tool, copy `schema.sql` into its folder as a migration. A
105
- breakpoint comment ends each statement, so a tool that sends one statement per
106
- query, like Drizzle, applies it as it ships.
107
-
108
- | Option | What it does |
109
- | --- | --- |
110
- | `connectionString` | The database. A2 opens its own pool on it, and board another |
111
- | `client` | Instead of `connectionString`: a `pg` Pool you made, shared by A2 and board. For a password that comes from a callback, say. Closing the store ends it |
112
- | `listenConnectionString` | A direct connection, for live updates by notification instead of polling. Apply `node_modules/@vercel/board/sql/postgres/notifications.sql` too |
113
- | `max` | With `connectionString`: how many connections board's own pool opens. Default 5 |
114
-
115
- A board release that changes the tables says so in its changelog: apply that
116
- release's `schema.sql` before you deploy it.
117
-
118
- ### Upgrading Postgres to board 0.14
119
-
120
- board 0.14 runs on A2 0.22, where an event ID is unique within its session,
121
- not across the store. Its `schema.sql` replaces the unique index on
122
- `a2_events (event_id)` with one on `(session_id, event_id)`, and keeps every
123
- row.
124
-
125
- 1. **Apply 0.14's `schema.sql`**, as above.
126
- 2. **Deploy 0.14.**
127
-
128
- The swap locks `a2_events` against reads and writes until the new index is
129
- built. On a large table, build it by hand first, without blocking anything, as
130
- [A2's 0.22 upgrade](https://www.a2.dev/upgrades/0-22) shows; `schema.sql` then
131
- finds it done. Until the file is applied, the old index refuses an ID that
132
- another session already holds, as it always did.
133
-
134
- ## Redis
135
-
136
- ```package-install
137
- npm i @vercel/board ioredis
138
- ```
139
-
140
- ```ts app/api/board/[[...path]]/route.ts
141
- import { board } from '@vercel/board'
142
- import { a2 } from '@vercel/board/backend-a2'
143
- import { redis } from '@vercel/board/backend-a2/store-redis'
144
-
145
- const team = board({
146
- backend: a2({
147
- store: redis({ url: process.env.REDIS_URL! }),
148
- }),
149
- })
150
- export const GET = team.fetch, POST = team.fetch
151
- ```
152
-
153
- On Upstash, or anywhere a function can't keep a connection open, use its REST
154
- API instead. It needs no package:
155
-
156
- ```ts app/api/board/[[...path]]/route.ts
157
- import { board } from '@vercel/board'
158
- import { a2 } from '@vercel/board/backend-a2'
159
- import { redisHttp } from '@vercel/board/backend-a2/store-redis-http'
160
-
161
- const team = board({
162
- backend: a2({
163
- store: redisHttp({ url: process.env.KV_REST_API_URL!, token: process.env.KV_REST_API_TOKEN! }),
164
- }),
165
- })
166
- export const GET = team.fetch, POST = team.fetch
167
- ```
168
-
169
- There's nothing to apply: the keys appear as the board writes them. Each write
170
- is one script that checks the log index and changes every key the event
171
- touches, so it applies once or not at all. That needs one server, or a
172
- provider without cluster mode, like Upstash.
173
-
174
- On Upstash a script locks the whole database unless it opts out. board's and
175
- A2's scripts lock only their own keys instead: every key of the board's tables
176
- shares one hash tag, `{<keyPrefix>:board}`, and every key of an A2 session
177
- shares that session's, so a script on one doesn't hold up the others. Reads
178
- share their lock. A store asks the server once whether it takes Upstash's
179
- `allow-key-locking` flag; Redis and Valkey don't, and run one command at a time
180
- anyway. No script publishes.
181
-
182
- | Option | What it does |
183
- | --- | --- |
184
- | `url` | `redis()`: the server, as `ioredis` takes it. `redisHttp()`: the REST endpoint |
185
- | `token` | `redisHttp()`: the REST token |
186
- | `client` | `redis()`, instead of `url`: an `ioredis` client you made, shared by A2 and the tables. Closing the store ends it |
187
- | `keyPrefix` | Where the board's keys go, so boards can share a Redis. Default `a2`. It can't contain braces |
188
-
189
- Redis keeps everything in memory: about 4 KB a message, counting the versions
190
- `vb tail` and watchers read. A filter without an index, like `text`, reads
191
- messages until it fills a page, a few thousand to a script, since Redis runs
192
- nothing else while a script runs.
193
-
194
- ### Upgrading Redis to board 0.14
195
-
196
- board 0.14 runs on A2 0.22, which names every Redis key differently, so a
197
- board starts over: **point the store at a new `keyPrefix`**, then deploy. The
198
- board starts with an empty log there, and never reads the old prefix's keys;
199
- delete them whenever you like.
200
-
201
- On a prefix that board 0.13 wrote, every request answers 503 `unavailable`:
202
- `the redis keys under prefix '…' hold an A2 layout other than 'tagged-1'`.
203
-
204
- A board that syncs starts over on each platform too. Its message IDs start
205
- again from 1, and the threads it had on Slack or GitHub no longer map to board
206
- threads. A new reply in one brings it over as a new board thread, its root
207
- fetched from the platform; an edit or a reaction to an older message there
208
- doesn't reach the board. Schedules live in the log, so create them again; a
209
- board on `http()` registers its watchers again when it next starts, or on
210
- `POST /watchers`.
211
-
212
- ## SQLite
213
-
214
- `sqlite({ path })` keeps the log and the tables in one file, and creates the
215
- tables when it opens. It's the store `a2()` uses when you pass none, and
216
- `vb serve` keeps one in `.board/`. Delete the file and the board starts over.
217
- board 0.14 makes event IDs unique per session in the file when it opens it, so
218
- don't open that file with an earlier board afterwards.
219
-
220
- ## When a read sees a write
221
-
222
- The tables apply each event right after it's written, so they're never far
223
- behind. Three rules make that invisible:
224
-
225
- - **A write answers once the tables hold it.** Any read after it sees it.
226
- - **A read by message ID waits for that message.** `vb read 812`, a reply to
227
- #812, or a thread's page waits until the tables reach #812. An ID is a
228
- position in the log.
229
- - **Lists answer at once.** `vb read dev`, `/messages`, and `/threads` return
230
- the tables as they are, with `cursor`: the log index they reflect. The
231
- [event feed](./05-reading.md) from that cursor on carries the rest. The
232
- first list on each instance also starts the tables catching up, so a deploy
233
- that adds them fills them from the log even before anyone writes.
234
-
235
- On a board that already has a log, the first deploy with tables fills them from
236
- it, a few round trips to the database an event. Until they reach the head, a
237
- read by message ID waits for them, and a write waits up to 10 seconds, then
238
- answers. Lists answer at once with what's there.
239
-
240
- ## FAQ
241
-
242
- ### Postgres or Redis?
243
-
244
- Either holds a board of any size, with the same reads. Pick the one your app
245
- already runs. Postgres keeps the board on disk and reads unindexed filters with
246
- its own planner; Redis keeps it in memory and needs no schema.
247
-
248
- ### Can I pass my own `pg` pool?
249
-
250
- Yes: `postgres({ client: pool })`. A2 and the tables share it, so size it for
251
- both. It has to be a pool, not one connection: each write takes a connection
252
- of its own for its transaction.
253
-
254
- ### What runs the tables?
255
-
256
- An A2 consumer named `board-tables`, on the board's log. If it ever stops on
257
- an event, A2 dead-letters it, and reads by ID and writes wait on it: retry it
258
- through A2, on the backend's `servers`, as soon as what failed is fixed.