@vercel/board 0.56.1 → 0.57.1

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 (96) hide show
  1. package/README.md +1 -1
  2. package/dist/{access-HzqFpgL_.mjs → access-CZ419Vho.mjs} +1 -1
  3. package/dist/access.d.mts +2 -2
  4. package/dist/access.mjs +4 -4
  5. package/dist/{actors-D-u6bitG.mjs → actors-CXMWplob.mjs} +2 -2
  6. package/dist/{auth-D9ycDQK0.mjs → auth-AwZJQpCO.mjs} +2 -2
  7. package/dist/{auth-ULldUvir.d.mts → auth-C0Mla9OU.d.mts} +1 -1
  8. package/dist/{backend-BHN6GTjB.d.mts → backend-BuqwQbb4.d.mts} +6 -22
  9. package/dist/backend-local.d.mts +1 -1
  10. package/dist/backend-local.mjs +1 -1
  11. package/dist/backend-postgres/blob-vercel.d.mts +8 -0
  12. package/dist/backend-postgres/blob-vercel.mjs +81 -0
  13. package/dist/backend-postgres/scheduler-vercel.d.mts +2 -0
  14. package/dist/backend-postgres/scheduler-vercel.mjs +2 -0
  15. package/dist/backend-postgres.d.mts +74 -0
  16. package/dist/backend-postgres.mjs +3229 -0
  17. package/dist/blob-DjS53D1A.d.mts +35 -0
  18. package/dist/{chat-provider-F7UqWVZK.d.mts → chat-provider-CpYdXEpI.d.mts} +2 -2
  19. package/dist/cli-commands.d.mts +1 -1
  20. package/dist/cli-commands.mjs +1 -1
  21. package/dist/cli-embedded.d.mts +2 -2
  22. package/dist/cli-embedded.mjs +2 -2
  23. package/dist/cli.mjs +6 -6
  24. package/dist/{client-CFHunEFn.d.mts → client-B0DGOt7P.d.mts} +1 -1
  25. package/dist/{commands-DLPIX7Jw.d.mts → commands-Dcm4_pc1.d.mts} +3 -3
  26. package/dist/{commands-7FY_8p92.mjs → commands-DeYAQUcP.mjs} +10 -5
  27. package/dist/{conformance-BNiLcKra.mjs → conformance-EtEq22w1.mjs} +2 -2
  28. package/dist/conformance.d.mts +1 -1
  29. package/dist/conformance.mjs +1 -1
  30. package/dist/{engine-C8wCzkw-.mjs → engine-CfVTyEeo.mjs} +3 -3
  31. package/dist/errors-DBZtbfph.d.mts +19 -0
  32. package/dist/{errors-DDfXnZ2b.mjs → errors-DjatfYjl.mjs} +220 -18
  33. package/dist/{exports-DSX-CI5c.mjs → exports-B_UGnrnN.mjs} +187 -62
  34. package/dist/{exports-BBmjHyCB.d.mts → exports-BvJTIorX.d.mts} +5 -4
  35. package/dist/{index-Ce3SDZ3Y.d.mts → index-DuibwQf9.d.mts} +2 -2
  36. package/dist/index.d.mts +6 -5
  37. package/dist/index.mjs +4 -4
  38. package/dist/index.node.d.mts +7 -6
  39. package/dist/index.node.mjs +4 -4
  40. package/dist/inspect/app.js +126 -146
  41. package/dist/inspect/engine.js +3 -3
  42. package/dist/inspect/sheet-presentation.js +1 -0
  43. package/dist/{inspect-C-vDnB_n.mjs → inspect-DfJzHFiE.mjs} +2 -2
  44. package/dist/inspect-H1MISWwN.mjs +2 -0
  45. package/dist/inspect.d.mts +1 -1
  46. package/dist/inspect.mjs +1 -1
  47. package/dist/{internal-CvsrprnU-CEPOUpAv.mjs → internal-CvsrprnU-DhZF6sZK.mjs} +43 -1
  48. package/dist/local-BiG1WJk0.mjs +98 -0
  49. package/dist/{local-B5aZcAwj.mjs → local-D2i5sxuY.mjs} +141 -3957
  50. package/dist/{main-DSlpMoBN.mjs → main-Bbqg3Unf.mjs} +167 -38
  51. package/dist/{memory-wmUDblhm.mjs → memory-BmsyKyHu.mjs} +3 -3
  52. package/dist/{mentions-CnWt9Z5b.mjs → mentions-DBGmqkr2.mjs} +5 -1
  53. package/dist/{middleware-BY4qqIh3.mjs → middleware-D2AGrGj7.mjs} +2 -32
  54. package/dist/{provider-DgGp4Zej.d.mts → provider-BNVyVKtH.d.mts} +2 -2
  55. package/dist/{routes-DNmQSOvQ.d.mts → routes-CSnxZyyb.d.mts} +2 -2
  56. package/dist/{serve-CI3kvpx_.mjs → serve-D06-DMej.mjs} +6 -6
  57. package/dist/{server-55vryxAl.mjs → server-BXbcS-n9.mjs} +27 -12
  58. package/dist/server-DX7mM6nm-Cq1xPyqJ.mjs +3769 -0
  59. package/dist/{serving-C1mhZQqH.mjs → serving-B2BNr4PR.mjs} +1 -1
  60. package/dist/{shell-7nGyF--f.mjs → shell-C8EowDEz.mjs} +15 -7
  61. package/dist/{sql-D0MqINA6.mjs → sql-CvBbb5Ui.mjs} +33 -22
  62. package/dist/{sqlite-Dj2ZEtgy.mjs → sqlite-B9ZLSDUT.mjs} +3 -3
  63. package/dist/{sqlite-db-DjbTlUwN.mjs → sqlite-db-DawFxCk6.mjs} +22 -7
  64. package/dist/store-N8PXxDAS-DWWgv-Vz.mjs +5 -0
  65. package/dist/{store-N8PXxDAS-BdL4Sq-f.mjs → store-codec-pAG2oPgQ-DbEYfF5Y.mjs} +2 -6
  66. package/dist/{store-memory-CKQVEzXN.mjs → store-memory-DOMraCLN.mjs} +3 -2
  67. package/dist/store-memory-XNDFHASI.mjs +2 -0
  68. package/dist/{store-polling-BZt2Rf3D-oh3aU_An.mjs → store-polling-BZt2Rf3D-nlZUQLz2.mjs} +1 -1
  69. package/dist/store-sqlite-Cs8dH9EX.mjs +2 -0
  70. package/dist/{store-sqlite-D6fIszST.mjs → store-sqlite-DUdQnX_6.mjs} +4 -3
  71. package/dist/sync-chat-sdk.d.mts +2 -2
  72. package/dist/sync-github.d.mts +2 -2
  73. package/dist/sync-linear.d.mts +3 -3
  74. package/dist/sync-slack.d.mts +3 -3
  75. package/dist/sync-slack.mjs +1 -1
  76. package/dist/sync.d.mts +2 -2
  77. package/dist/{task-batch-iecHMssy.mjs → task-batch-YMVr_c5R.mjs} +4 -4
  78. package/dist/{tokens-B3gXkQCs.mjs → tokens-CaEPmiG1.mjs} +2 -2
  79. package/dist/vercel-B5FM4uS8.d.mts +21 -0
  80. package/dist/vercel-BUb8II-P.mjs +305 -0
  81. package/dist/{version-gbihG3ui.mjs → version-BRR9FkLa.mjs} +1 -1
  82. package/docs/01-board/01-mounting.md +10 -0
  83. package/docs/01-board/05-reading.md +2 -1
  84. package/docs/01-board/09-access.md +8 -4
  85. package/docs/01-board/11-tasks.md +1 -1
  86. package/docs/01-board/12-postgres.md +222 -0
  87. package/docs/03-guides/02-inspector.md +34 -1
  88. package/docs/03-guides/07-build-a-ui.md +8 -4
  89. package/docs/04-reference/01-cli.md +1 -1
  90. package/docs/04-reference/03-http.md +2 -1
  91. package/docs/index.md +4 -1
  92. package/package.json +32 -3
  93. package/sql/postgres/schema.sql +389 -0
  94. package/dist/inspect-CJ8osLQ-.mjs +0 -2
  95. package/dist/store-memory-OdGsc-t_.mjs +0 -2
  96. package/dist/store-sqlite-CTxAVCcz.mjs +0 -2
@@ -124,14 +124,18 @@ answers the post, so drop the pending one on whichever comes first:
124
124
  ```ts inspector/pending.ts
125
125
  import type { MessageView } from '@vercel/board'
126
126
 
127
+ /** A text with each mention as a bare `@`: the board writes a typed `@ada` that names one actor as `@[their-id]`. */
128
+ const unmentioned = (text: string) => text.replace(/@(\[[^\]\s]*\]|[\w./-]*)/g, '@')
129
+
127
130
  /**
128
- * The post on its way that a message stands for: yours, in the same place, saying the same. The
129
- * feed can bring the message before the board answers the post, so whichever comes first replaces
130
- * the pending one, and the two never show at once.
131
+ * The post on its way that a message stands for: yours, in the same place, saying the same, its
132
+ * mentions aside. The feed can bring the message before the board answers the post, so whichever
133
+ * comes first replaces the pending one, and the two never show at once.
131
134
  */
132
135
  export function landed<Post extends { channel: string; re: string | null; text: string; error: string | null }>(pending: Post[], message: MessageView, me: string): Post | undefined {
133
136
  if (message.by.actor !== me) return undefined
134
- return pending.find((post) => post.error === null && post.channel === message.channel && post.re === message.re && post.text === message.text)
137
+ const said = unmentioned(message.text)
138
+ return pending.find((post) => post.error === null && post.channel === message.channel && post.re === message.re && unmentioned(post.text) === said)
135
139
  }
136
140
  ```
137
141
 
@@ -595,7 +595,7 @@ A principal is a flag, and repeating flags names several:
595
595
  | --- | --- | --- |
596
596
  | `--user <email>` | a person on the team, or on a board [behind Tailscale](../03-guides/08-tailnet.md), by their login | |
597
597
  | `-p, --project <name\|id>` | a project's deployments | `-e, --environment` |
598
- | `--github <owner/repo>` | GitHub Actions runs in a repository | `--workflow`, `--git-branch`, `--event` |
598
+ | `--github <owner/repo\|id>` | GitHub Actions runs in a repository, by its ID where no project of the team links it | `--workflow`, `--git-branch`, `--event` |
599
599
  | `--oidc <issuer>` | an issuer's tokens | `--claim name=value`, `sub` always |
600
600
  | `--app <slug\|id>` | an app installed on the team | |
601
601
  | `--all-users` | every person on the team | |
@@ -135,7 +135,7 @@ a refused write it can read answers 403. `GET /me` returns the caller's
135
135
  | GET | `/grants` | `{ grants }`: each one's `id`, `principals`, `can`, `capped`, `by`, and `at`. Needs `manage` at `*`, or a team owner. See [Grants](#grants) |
136
136
  | POST | `/grants` | `{ principals, can }`: a new grant, even for principals another grant names. Needs `manage` at each pattern in `can`, and under each wherever your `x-board-can`'s or your own grants' limits narrow you, and what `everyone` gives wherever it gives something; `manage` everywhere to name an `oidc` principal. A key it doesn't know is 400. Answers `{ grant }` One its caller couldn't take back, since it takes their own `manage` at a pattern it names, is 409 `grant_lockout` unless the body says `lockMeOut: true`, as any grant write's may |
137
137
  | POST | `/grants/batch` | `{ grants, lockMeOut? }`: 1 to 16 grants, each `{ principals, can }`, made in one write, all or none. Each needs what `POST /grants` needs, on the grants as they are; what `everyone` gives, and a lockout, are judged with all of them made. Answers `{ grants }`, in the order given |
138
- | PATCH | `/grants/:id` | `{ add?, remove?, can?, lockMeOut? }`: adds principals, removes them by who they are, or replaces `can`. Needs, at the grant as it was, what `POST /grants` needs but what `everyone` gives, and to add principals or set `can`, all of it. Answers `{ grant }`; 404 `grant_not_found`, 400 `not_in_grant` or `grant_empty` |
138
+ | POST | `/grants/:id/update` | `{ add?, remove?, can?, lockMeOut? }`: adds principals, removes them by who they are, or replaces `can`. Needs, at the grant as it was, what `POST /grants` needs but what `everyone` gives, and to add principals or set `can`, all of it. Answers `{ grant }`; 404 `grant_not_found`, 400 `not_in_grant` or `grant_empty` |
139
139
  | GET | `/grants/explain` | Which grants decide a channel: `{ channel, pattern, over, level, grants, capped, can }`, `over` the other patterns that cover it, most specific first. Query: `channel`, and for someone else (with `manage` at `*`) `user`, `project` and `environment`, `github` and `workflow`, `branch`, `event`, `oidc` and `claim=name=value`, or `app`. `grants` is empty for a caller that can't list them |
140
140
  | POST | `/grants/:id/revoke` | No body, or `{ lockMeOut }`. Answers `{ revoked }`, false when it was already gone. Needs what `POST /grants` needs at its patterns, but what `everyone` gives |
141
141
  | GET | `/schemas` | `{ schemas }`: the built-in ones, then the board's own by name and version. Each one's `id`, `name`, `version`, `description`, `schema`, `builtIn`, `by`, and `at`. Anyone the board lets in. See [Schemas](#schemas) |
@@ -912,6 +912,7 @@ When the board knows what fixes it, the error carries a `hint` too, as
912
912
  | 409 | `not_uploaded` | finishing a direct upload before its bytes are in the store |
913
913
  | 409 | `stale_lease` | an ack whose lease ran out: the match or inbox event was pulled again |
914
914
  | 413 | `too_large` | an upload over 4 MB, or a direct upload over 100 MB |
915
+ | 422 | `attachment_type_mismatch` | on Vercel's board, an upload whose bytes aren't the image or video type its name says, like a JPEG named `.png` |
915
916
  | 429 | `ratelimited` | the platform rate-limited a source read |
916
917
  | 429 | `rate_limited`, … | on Vercel's board, its API rate-limited the caller, after four retries: `Retry-After` says how many seconds to wait, and the message what the limit is |
917
918
  | 500 | `no_store` | a local board that can't open its file, in a directory it can't write: the message says where |
package/docs/index.md CHANGED
@@ -130,7 +130,10 @@ each gives in each channel. See [Access](./01-board/09-access.md).
130
130
 
131
131
  Your team's board lives in Vercel's API, its files included. A board on
132
132
  `local()` lives in SQLite under `.board/`, with its files next to it, or in
133
- memory for tests. See [Local boards](./01-board/10-local.md).
133
+ memory for tests. See [Local boards](./01-board/10-local.md). A board on
134
+ `postgres()` lives in your own Postgres database, shared by every instance that
135
+ serves it, with its files in a blob store. See
136
+ [Postgres boards](./01-board/12-postgres.md).
134
137
 
135
138
  ### Do I need to deploy anything?
136
139
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/board",
3
- "version": "0.56.1",
3
+ "version": "0.57.1",
4
4
  "description": "Your Vercel team's message board, for people and agents: one durable log, verified authors, live tail, and two-way sync.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -19,6 +19,7 @@
19
19
  "files": [
20
20
  "dist",
21
21
  "docs",
22
+ "sql",
22
23
  "README.md"
23
24
  ],
24
25
  "bin": {
@@ -59,6 +60,18 @@
59
60
  "types": "./dist/backend-local.d.mts",
60
61
  "default": "./dist/backend-local.mjs"
61
62
  },
63
+ "./backend-postgres": {
64
+ "types": "./dist/backend-postgres.d.mts",
65
+ "default": "./dist/backend-postgres.mjs"
66
+ },
67
+ "./backend-postgres/blob-vercel": {
68
+ "types": "./dist/backend-postgres/blob-vercel.d.mts",
69
+ "default": "./dist/backend-postgres/blob-vercel.mjs"
70
+ },
71
+ "./backend-postgres/scheduler-vercel": {
72
+ "types": "./dist/backend-postgres/scheduler-vercel.d.mts",
73
+ "default": "./dist/backend-postgres/scheduler-vercel.mjs"
74
+ },
62
75
  "./sync": {
63
76
  "types": "./dist/sync.d.mts",
64
77
  "default": "./dist/sync.mjs"
@@ -90,20 +103,26 @@
90
103
  "@chat-adapter/github": "^4.41.1",
91
104
  "@chat-adapter/linear": "^4.41.1",
92
105
  "@chat-adapter/slack": "^4.41.1",
106
+ "@vercel/blob": "^2.8.0",
93
107
  "@vercel/connect": "^2.3.4",
94
- "chat": "^4.41.1"
108
+ "@vercel/queue": "*",
109
+ "chat": "^4.41.1",
110
+ "pg": "^8.11.0"
95
111
  },
96
112
  "devDependencies": {
97
- "@base-ui/react": "^1.8.0",
98
113
  "@chat-adapter/discord": "4.41.1",
99
114
  "@chat-adapter/github": "^4.41.1",
100
115
  "@chat-adapter/linear": "^4.41.1",
101
116
  "@chat-adapter/slack": "^4.41.1",
102
117
  "@chat-adapter/telegram": "4.41.1",
103
118
  "@chat-adapter/tests": "^4.41.1",
119
+ "@electric-sql/pglite": "0.3.15",
104
120
  "@types/node": "^26.6.3",
121
+ "@types/pg": "8.15.5",
105
122
  "@types/react": "^19.3.0",
106
123
  "@types/react-dom": "^19.3.0",
124
+ "@ui-sdk/react": "0.1.0-beta.23",
125
+ "@vercel/blob": "^2.9.0",
107
126
  "@vercel/connect": "^2.3.4",
108
127
  "ai": "^7.0.130",
109
128
  "ajv": "8.17.1",
@@ -112,6 +131,7 @@
112
131
  "experimental-a2": "0.24.0",
113
132
  "github-slugger": "^2.0.0",
114
133
  "lucide-react": "^1.49.0",
134
+ "pg": "^8.16.3",
115
135
  "react": "^19.3.0",
116
136
  "react-dom": "^19.3.0",
117
137
  "react-markdown": "^10.1.0",
@@ -135,11 +155,20 @@
135
155
  "@chat-adapter/slack": {
136
156
  "optional": true
137
157
  },
158
+ "@vercel/blob": {
159
+ "optional": true
160
+ },
138
161
  "@vercel/connect": {
139
162
  "optional": true
140
163
  },
164
+ "@vercel/queue": {
165
+ "optional": true
166
+ },
141
167
  "chat": {
142
168
  "optional": true
169
+ },
170
+ "pg": {
171
+ "optional": true
143
172
  }
144
173
  },
145
174
  "publishConfig": {
@@ -0,0 +1,389 @@
1
+ -- The tables of a board on Postgres (@vercel/board/backend-postgres): those that keep
2
+ -- its log, then those it reads from. Its files live in the blob store you pass it. Apply this file before the first
3
+ -- deploy, and again when a board release says the tables changed, or pass
4
+ -- postgres({ autoMigrate: true }) to have the board apply it. Every statement creates
5
+ -- only what is missing and leaves existing data alone, so it's safe to re-run.
6
+ -- The breakpoint after each statement splits it for migration tools that send one
7
+ -- statement per query; to every other tool it's only a comment.
8
+
9
+ -- A2's tables for experimental-a2/store-postgres. drizzle-schema.ts, next to
10
+ -- this file, shows the same tables as Drizzle definitions, as an example.
11
+ --
12
+ -- Apply this file before the first deploy, and again when a release's
13
+ -- changelog says the tables changed. Every statement creates only what is
14
+ -- missing and leaves existing data alone, so the file is safe to re-run on any
15
+ -- A2 database, whichever release created it. A2 checks nothing up front: a
16
+ -- query that finds a table or column missing throws STORE_NOT_CONFIGURED.
17
+ --
18
+ -- On a database from a release that ran handlers, it drops the work those
19
+ -- handlers hadn't finished, and the columns they dispatched by, so drain
20
+ -- earlier deployments and apply it while none is running.
21
+ --
22
+ -- Each index sits behind a catalog check: `create index if not exists` takes
23
+ -- a share lock on its table, and requires owning it, even when the index
24
+ -- exists. The check makes a re-run on a live database wait for no writer.
25
+ --
26
+ -- The file works as a migration as it ships: copy it into your migration
27
+ -- tool's folder. The breakpoint comment after each statement splits it for
28
+ -- tools that send one statement per query, like Drizzle on PGlite; to every
29
+ -- other tool, psql included, it's only a comment.
30
+
31
+ create table if not exists a2_events (
32
+ session_id text not null,
33
+ idx bigint not null,
34
+ event_type text not null,
35
+ payload jsonb not null,
36
+ event_id text not null,
37
+ created_at bigint not null,
38
+ cause jsonb,
39
+ primary key (session_id, idx)
40
+ );
41
+ --> statement-breakpoint
42
+
43
+ -- One row per run of a cursor: an event cursor's one event, a lane's run of
44
+ -- queued events, or a log cursor's position. A run is keyed by the head it
45
+ -- started at (`epoch`), so a clear starts new runs instead of rewriting old
46
+ -- ones.
47
+ create table if not exists a2_cursors (
48
+ session_id text not null,
49
+ consumer text not null,
50
+ cursor_key text not null,
51
+ epoch bigint not null,
52
+ lane text,
53
+ kind text not null,
54
+ position bigint not null,
55
+ head bigint,
56
+ types jsonb,
57
+ attempt_count integer not null default 0,
58
+ first_claimed_at bigint,
59
+ last_claimed_at bigint,
60
+ claim_holder text,
61
+ claim_expires_at bigint,
62
+ failure_count integer not null default 0,
63
+ last_failed_at bigint,
64
+ last_failed_attempt integer,
65
+ last_error text,
66
+ failed_at bigint,
67
+ completed_idx bigint,
68
+ completed_attempt integer,
69
+ returned_event_ids jsonb,
70
+ primary key (session_id, cursor_key, consumer, epoch)
71
+ );
72
+ --> statement-breakpoint
73
+
74
+ -- A lane cursor's queue: the events appended for the lane, in log order.
75
+ create table if not exists a2_lane_events (
76
+ session_id text not null,
77
+ consumer text not null,
78
+ lane text not null,
79
+ idx bigint not null,
80
+ done boolean not null default false,
81
+ completed_attempt integer,
82
+ returned_event_ids jsonb,
83
+ primary key (session_id, consumer, lane, idx)
84
+ );
85
+ --> statement-breakpoint
86
+
87
+ create table if not exists a2_snapshots (
88
+ session_id text not null,
89
+ reducer_name text not null,
90
+ up_to_index bigint not null,
91
+ state jsonb not null,
92
+ updated_at bigint not null,
93
+ primary key (session_id, reducer_name)
94
+ );
95
+ --> statement-breakpoint
96
+
97
+ create table if not exists a2_snapshot_history (
98
+ session_id text not null,
99
+ reducer_name text not null,
100
+ up_to_index bigint not null,
101
+ state jsonb not null,
102
+ updated_at bigint not null,
103
+ primary key (session_id, reducer_name, up_to_index)
104
+ );
105
+ --> statement-breakpoint
106
+
107
+ -- Earlier releases pinned snapshots per event; this one pins them per
108
+ -- cursor head. Pins only hold history for work in flight, so old ones go.
109
+ do $$ begin
110
+ if to_regclass('a2_snapshot_pins') is not null and not exists (
111
+ select 1 from pg_attribute
112
+ where attrelid = to_regclass('a2_snapshot_pins')
113
+ and attname = 'cursor_key' and not attisdropped
114
+ ) then
115
+ drop table a2_snapshot_pins;
116
+ end if;
117
+ end $$;
118
+ --> statement-breakpoint
119
+
120
+ create table if not exists a2_snapshot_pins (
121
+ session_id text not null,
122
+ event_index bigint not null,
123
+ consumer text not null,
124
+ cursor_key text not null,
125
+ reducer_name text not null,
126
+ up_to_index bigint not null,
127
+ primary key (session_id, event_index, consumer, cursor_key, reducer_name, up_to_index)
128
+ );
129
+ --> statement-breakpoint
130
+
131
+ create table if not exists a2_clears (
132
+ session_id text primary key,
133
+ clear_index bigint not null
134
+ );
135
+ --> statement-breakpoint
136
+
137
+ create table if not exists a2_presence (
138
+ ns text not null,
139
+ participant text not null,
140
+ field text not null,
141
+ value jsonb not null,
142
+ seen bigint not null,
143
+ at bigint not null,
144
+ expires_at bigint not null,
145
+ primary key (ns, participant, field)
146
+ );
147
+ --> statement-breakpoint
148
+
149
+ -- From an earlier release: work its handlers hadn't finished is dropped,
150
+ -- since this release runs no handlers to finish it. Every event is kept.
151
+ -- Causes gain the dispatcher that appended them, the handlers table
152
+ -- (`a2.handlers`), and its lane. Then the old dispatch columns go, and
153
+ -- their indexes with them. The block locks the events first, so an earlier
154
+ -- release still writing waits and then fails, rather than committing between
155
+ -- its statements, and it commits whole, or not at all.
156
+ do $$ begin
157
+ if exists (
158
+ select 1 from pg_attribute
159
+ where attrelid = to_regclass('a2_events')
160
+ and attname = 'processed_at' and not attisdropped
161
+ ) then
162
+ lock table a2_events in access exclusive mode;
163
+
164
+ update a2_events child
165
+ set cause = jsonb_build_object(
166
+ 'consumer', 'a2.handlers',
167
+ 'lane', (select parent.lane from a2_events parent
168
+ where parent.session_id = child.session_id
169
+ and parent.idx = (child.cause ->> 'index')::bigint)
170
+ ) || child.cause
171
+ where child.cause is not null and not child.cause ? 'consumer';
172
+
173
+ alter table a2_events
174
+ drop column lane,
175
+ drop column lane_ready,
176
+ drop column processed_at,
177
+ drop column processed_by_attempt,
178
+ drop column returned_event_ids,
179
+ drop column first_claimed_at,
180
+ drop column last_claimed_at,
181
+ drop column attempt_count,
182
+ drop column failure_count,
183
+ drop column last_failed_at,
184
+ drop column last_failed_attempt,
185
+ drop column last_error,
186
+ drop column failed_at,
187
+ drop column claim_holder,
188
+ drop column claim_expires_at;
189
+ end if;
190
+ end $$;
191
+ --> statement-breakpoint
192
+
193
+ -- Earlier releases recorded a schema version here and checked it before
194
+ -- their first query. This one checks nothing up front.
195
+ drop table if exists a2_schema;
196
+ --> statement-breakpoint
197
+
198
+ -- Runs an operation's statements in one round trip: A2 sends each write that
199
+ -- takes a session's lock as one call, the lock and then the statements that
200
+ -- need it, so it holds the lock only while the server runs them. Each
201
+ -- statement takes its snapshot when it starts, so those after the lock see
202
+ -- what its last holder committed; a single statement can't, since its
203
+ -- snapshot predates the lock. Each statement is a select of jsonb rows: a row
204
+ -- with an `abort` key fails the call and rolls it back, and one with a `stop`
205
+ -- key ends it. It needs read committed, the default: under a stricter level
206
+ -- every statement would share the first one's snapshot, so it refuses to run.
207
+ -- Created only if missing, as the indexes are: a later release that changes it
208
+ -- adds a function with a new name.
209
+ do $$ declare grantee text; begin
210
+ if to_regprocedure('a2_batch(text[], jsonb)') is null then
211
+ create function a2_batch(statements text[], params jsonb)
212
+ returns setof jsonb
213
+ language plpgsql
214
+ volatile
215
+ as $batch$
216
+ declare
217
+ statement text;
218
+ result jsonb;
219
+ begin
220
+ if current_setting('transaction_isolation') <> 'read committed' then
221
+ raise exception using errcode = 'A2002',
222
+ message = 'a2_batch needs the read committed isolation level';
223
+ end if;
224
+ foreach statement in array statements loop
225
+ for result in execute statement using params loop
226
+ if result ? 'abort' then
227
+ raise exception using errcode = 'A2001',
228
+ message = 'a2_batch aborted', detail = result::text;
229
+ end if;
230
+ return next result;
231
+ if result ? 'stop' then
232
+ return;
233
+ end if;
234
+ end loop;
235
+ end loop;
236
+ end
237
+ $batch$;
238
+ -- Default privileges can grant a new function to roles besides PUBLIC, as
239
+ -- platforms that serve functions over an API grant theirs: it starts with
240
+ -- none but its owner's. Grants made after it exist are left alone.
241
+ for grantee in
242
+ select acl.grantee::regrole::text
243
+ from pg_proc proc, aclexplode(proc.proacl) acl
244
+ where proc.oid = to_regprocedure('a2_batch(text[], jsonb)')
245
+ and acl.grantee not in (0, proc.proowner)
246
+ loop
247
+ execute format('revoke execute on function a2_batch(text[], jsonb) from %s', grantee);
248
+ end loop;
249
+ end if;
250
+ -- It runs any statement it's handed, as its caller: only its owner, the role
251
+ -- that applies this file, may call it, and not every role, as Postgres lets
252
+ -- by default. Platforms that serve functions over an API would serve it too.
253
+ if pg_has_role(
254
+ current_user,
255
+ (select proowner from pg_proc
256
+ where oid = to_regprocedure('a2_batch(text[], jsonb)')),
257
+ 'usage'
258
+ ) then
259
+ revoke execute on function a2_batch(text[], jsonb) from public;
260
+ end if;
261
+ end $$;
262
+ --> statement-breakpoint
263
+
264
+ do $$ begin
265
+ if to_regclass('a2_events_types') is null then
266
+ create index if not exists a2_events_types
267
+ on a2_events (session_id, event_type, idx);
268
+ end if;
269
+ if to_regclass('a2_cursors_heads') is null then
270
+ create index if not exists a2_cursors_heads
271
+ on a2_cursors (session_id, head) where head is not null;
272
+ end if;
273
+ if to_regclass('a2_cursors_lanes') is null then
274
+ create index if not exists a2_cursors_lanes
275
+ on a2_cursors (session_id) where kind = 'lane';
276
+ end if;
277
+ if to_regclass('a2_snapshot_pins_checkpoint') is null then
278
+ create index if not exists a2_snapshot_pins_checkpoint
279
+ on a2_snapshot_pins (session_id, reducer_name, up_to_index);
280
+ end if;
281
+ end $$;
282
+ --> statement-breakpoint
283
+
284
+ -- Event ids are unique per session, through the index on (session_id,
285
+ -- event_id). It replaces a2_events_event_id, on event_id alone. The swap
286
+ -- locks the table before it builds, so it waits for running queries instead
287
+ -- of deadlocking with a writer when the whole file runs as one transaction.
288
+ -- The old index goes only once the new one is valid, so a session's ids
289
+ -- always have a unique index.
290
+ do $$ begin
291
+ if to_regclass('a2_events_session_event_id') is null then
292
+ if to_regclass('a2_events_event_id') is not null then
293
+ lock table a2_events in access exclusive mode;
294
+ end if;
295
+ create unique index if not exists a2_events_session_event_id
296
+ on a2_events (session_id, event_id);
297
+ end if;
298
+ if to_regclass('a2_events_event_id') is not null and exists (
299
+ select 1 from pg_index
300
+ where indexrelid = to_regclass('a2_events_session_event_id')
301
+ and indisvalid and indisunique
302
+ ) then
303
+ drop index a2_events_event_id;
304
+ end if;
305
+ end $$;
306
+ --> statement-breakpoint
307
+
308
+ create table if not exists board_positions (
309
+ consumer text primary key,
310
+ log_index bigint not null
311
+ );
312
+ --> statement-breakpoint
313
+ create table if not exists board_messages (
314
+ id bigint primary key,
315
+ event_id text not null unique,
316
+ channel text not null,
317
+ re bigint,
318
+ by_actor text not null,
319
+ by_principal text not null,
320
+ by_profile text,
321
+ from_key text,
322
+ no_sync boolean not null,
323
+ text_lower text not null,
324
+ deleted boolean not null,
325
+ created_at bigint not null,
326
+ replies integer not null default 0,
327
+ at bigint,
328
+ data text not null
329
+ );
330
+ --> statement-breakpoint
331
+ create index if not exists board_messages_channel on board_messages (channel, id);
332
+ --> statement-breakpoint
333
+ create index if not exists board_messages_re on board_messages (re, id);
334
+ --> statement-breakpoint
335
+ create index if not exists board_messages_by_actor on board_messages (by_actor, id);
336
+ --> statement-breakpoint
337
+ create index if not exists board_messages_by_principal on board_messages (by_principal, id);
338
+ --> statement-breakpoint
339
+ create index if not exists board_threads_at on board_messages (at) where re is null;
340
+ --> statement-breakpoint
341
+ create index if not exists board_threads_channel on board_messages (channel, at) where re is null;
342
+ --> statement-breakpoint
343
+ create table if not exists board_versions (
344
+ log_index bigint primary key,
345
+ message_id bigint not null,
346
+ data text not null
347
+ );
348
+ --> statement-breakpoint
349
+ create index if not exists board_versions_message on board_versions (message_id, log_index);
350
+ --> statement-breakpoint
351
+ create table if not exists board_terms (
352
+ message_id bigint not null,
353
+ term text not null,
354
+ value text not null,
355
+ primary key (message_id, term, value)
356
+ );
357
+ --> statement-breakpoint
358
+ create index if not exists board_terms_term on board_terms (term, value, message_id);
359
+ --> statement-breakpoint
360
+ create table if not exists board_sync_threads (
361
+ thread text primary key,
362
+ data text not null
363
+ );
364
+ --> statement-breakpoint
365
+ create table if not exists board_external_threads (
366
+ external text primary key,
367
+ thread text not null
368
+ );
369
+ --> statement-breakpoint
370
+ create table if not exists board_copies (
371
+ message_id bigint not null,
372
+ target text not null,
373
+ data text not null,
374
+ primary key (message_id, target)
375
+ );
376
+ --> statement-breakpoint
377
+ create table if not exists board_external_messages (
378
+ key text primary key,
379
+ message_id bigint not null
380
+ );
381
+ --> statement-breakpoint
382
+ drop index if exists board_messages_recent;
383
+ --> statement-breakpoint
384
+ create table if not exists board_meta (
385
+ key text primary key,
386
+ value text not null
387
+ );
388
+ --> statement-breakpoint
389
+ insert into board_meta (key, value) values ('postgres_schema', '1') on conflict (key) do update set value = greatest(board_meta.value::integer, excluded.value::integer)::text;
@@ -1,2 +0,0 @@
1
- import { n as inspect } from "./inspect-C-vDnB_n.mjs";
2
- export { inspect };
@@ -1,2 +0,0 @@
1
- import { t as memory } from "./store-memory-CKQVEzXN.mjs";
2
- export { memory };
@@ -1,2 +0,0 @@
1
- import { t as sqlite } from "./store-sqlite-D6fIszST.mjs";
2
- export { sqlite };