@jam-overture/loom 0.2.0 → 0.3.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 (194) hide show
  1. package/dist/audience/compose.d.ts +112 -0
  2. package/dist/audience/compose.js +134 -0
  3. package/dist/audience/memory.d.ts +14 -0
  4. package/dist/audience/memory.js +71 -0
  5. package/dist/audience/overlay-store.d.ts +343 -0
  6. package/dist/audience/overlay-store.js +217 -0
  7. package/dist/audience/rule.d.ts +121 -0
  8. package/dist/audience/rule.js +78 -0
  9. package/dist/cli/index.d.ts +3 -4
  10. package/dist/cli/index.js +3 -4
  11. package/dist/data/adapter.d.ts +9 -1
  12. package/dist/data/adapter.js +2 -0
  13. package/dist/data/resolve.d.ts +1 -1
  14. package/dist/interpretation/anthropic.d.ts +1 -1
  15. package/dist/interpretation/anthropic.js +2 -22
  16. package/dist/interpretation/client.d.ts +1 -1
  17. package/dist/interpretation/materialize.js +67 -22
  18. package/dist/interpretation/openai-compatible.d.ts +36 -0
  19. package/dist/interpretation/openai-compatible.js +79 -0
  20. package/dist/interpretation/status.d.ts +19 -0
  21. package/dist/interpretation/status.js +26 -0
  22. package/dist/live/index.d.ts +73 -0
  23. package/dist/live/index.js +73 -0
  24. package/dist/live/pages.d.ts +187 -0
  25. package/dist/live/pages.js +161 -0
  26. package/dist/live/pull.d.ts +147 -0
  27. package/dist/live/pull.js +398 -0
  28. package/dist/live/pulling.d.ts +79 -0
  29. package/dist/live/pulling.js +117 -0
  30. package/dist/live/window.d.ts +129 -0
  31. package/dist/live/window.js +132 -0
  32. package/dist/render/addressed.d.ts +35 -0
  33. package/dist/render/addressed.js +79 -0
  34. package/dist/render/document-theme.d.ts +70 -0
  35. package/dist/render/document-theme.js +139 -0
  36. package/dist/render/editable.d.ts +15 -1
  37. package/dist/render/editable.js +13 -1
  38. package/dist/render/expected.d.ts +98 -0
  39. package/dist/render/expected.js +88 -0
  40. package/dist/render/index.d.ts +2 -0
  41. package/dist/render/index.js +2 -0
  42. package/dist/render/render.d.ts +11 -0
  43. package/dist/render/render.js +192 -46
  44. package/dist/render/request.d.ts +8 -1
  45. package/dist/render/request.js +1 -0
  46. package/dist/runtime/auto-apply-ceiling.d.ts +54 -0
  47. package/dist/runtime/auto-apply-ceiling.js +66 -0
  48. package/dist/runtime/gate.js +69 -10
  49. package/dist/runtime/index.d.ts +1 -0
  50. package/dist/runtime/index.js +1 -0
  51. package/dist/runtime/nesting.d.ts +13 -1
  52. package/dist/runtime/nesting.js +41 -24
  53. package/dist/runtime/policy-change.js +8 -2
  54. package/dist/runtime/policy-log.d.ts +5 -5
  55. package/dist/runtime/policy.d.ts +8 -6
  56. package/dist/runtime/policy.js +5 -2
  57. package/dist/runtime/repointing.js +0 -0
  58. package/dist/sdk/definition.d.ts +65 -6
  59. package/dist/sdk/definition.js +44 -0
  60. package/dist/sdk/registry.d.ts +17 -1
  61. package/dist/sdk/registry.js +39 -0
  62. package/dist/signals/acted.contract.d.ts +21 -0
  63. package/dist/signals/acted.contract.js +236 -0
  64. package/dist/signals/acted.d.ts +359 -0
  65. package/dist/signals/acted.js +135 -0
  66. package/dist/signals/agenda.d.ts +585 -0
  67. package/dist/signals/agenda.js +295 -0
  68. package/dist/signals/arrivals.contract.d.ts +21 -0
  69. package/dist/signals/arrivals.contract.js +180 -0
  70. package/dist/signals/arrivals.d.ts +375 -0
  71. package/dist/signals/arrivals.js +254 -0
  72. package/dist/signals/broadcast.d.ts +25 -15
  73. package/dist/signals/broadcast.js +209 -36
  74. package/dist/signals/collect.d.ts +137 -43
  75. package/dist/signals/collect.js +103 -36
  76. package/dist/signals/conversion.d.ts +348 -0
  77. package/dist/signals/conversion.js +235 -0
  78. package/dist/signals/correlated.contract.d.ts +24 -0
  79. package/dist/signals/correlated.contract.js +94 -0
  80. package/dist/signals/counters.d.ts +51 -0
  81. package/dist/signals/counters.js +58 -0
  82. package/dist/signals/deployment-change.d.ts +28 -4
  83. package/dist/signals/deployment-change.js +57 -16
  84. package/dist/signals/deployment.d.ts +18 -5
  85. package/dist/signals/deployment.js +37 -11
  86. package/dist/signals/door.d.ts +34 -12
  87. package/dist/signals/door.js +37 -13
  88. package/dist/signals/expire.d.ts +192 -0
  89. package/dist/signals/expire.js +213 -0
  90. package/dist/signals/frontier.d.ts +268 -0
  91. package/dist/signals/frontier.js +145 -0
  92. package/dist/signals/funnel-hours.contract.d.ts +21 -0
  93. package/dist/signals/funnel-hours.contract.js +221 -0
  94. package/dist/signals/funnel-hours.d.ts +293 -0
  95. package/dist/signals/funnel-hours.js +99 -0
  96. package/dist/signals/funnel.d.ts +60 -0
  97. package/dist/signals/funnel.js +35 -20
  98. package/dist/signals/health.d.ts +201 -4
  99. package/dist/signals/health.js +214 -2
  100. package/dist/signals/index.d.ts +19 -0
  101. package/dist/signals/index.js +19 -0
  102. package/dist/signals/inside.d.ts +190 -0
  103. package/dist/signals/inside.js +263 -0
  104. package/dist/signals/join.d.ts +56 -0
  105. package/dist/signals/join.js +60 -0
  106. package/dist/signals/journal.d.ts +112 -9
  107. package/dist/signals/kept.contract.d.ts +22 -0
  108. package/dist/signals/kept.contract.js +111 -0
  109. package/dist/signals/library-agenda-change.d.ts +324 -0
  110. package/dist/signals/library-agenda-change.js +199 -0
  111. package/dist/signals/library-agenda.d.ts +258 -0
  112. package/dist/signals/library-agenda.js +167 -0
  113. package/dist/signals/library-reach-change.d.ts +10 -0
  114. package/dist/signals/library-reach-change.js +11 -3
  115. package/dist/signals/library-senders-change.d.ts +457 -0
  116. package/dist/signals/library-senders-change.js +367 -0
  117. package/dist/signals/library-senders-reach-change.d.ts +486 -0
  118. package/dist/signals/library-senders-reach-change.js +538 -0
  119. package/dist/signals/library-senders-reach.d.ts +340 -0
  120. package/dist/signals/library-senders-reach.js +252 -0
  121. package/dist/signals/library-senders.d.ts +271 -0
  122. package/dist/signals/library-senders.js +180 -0
  123. package/dist/signals/library-word-reach-change.js +2 -6
  124. package/dist/signals/memory.js +142 -1
  125. package/dist/signals/migrate.d.ts +6 -5
  126. package/dist/signals/migrate.js +150 -6
  127. package/dist/signals/notice.d.ts +88 -33
  128. package/dist/signals/notice.js +38 -16
  129. package/dist/signals/part-pace.d.ts +378 -0
  130. package/dist/signals/part-pace.js +333 -0
  131. package/dist/signals/parts.d.ts +25 -15
  132. package/dist/signals/parts.js +32 -73
  133. package/dist/signals/postgres.js +400 -26
  134. package/dist/signals/region.d.ts +1 -1
  135. package/dist/signals/retention.d.ts +43 -21
  136. package/dist/signals/retention.js +25 -8
  137. package/dist/signals/rhythm.d.ts +302 -0
  138. package/dist/signals/rhythm.js +262 -0
  139. package/dist/signals/rollup.d.ts +127 -1
  140. package/dist/signals/rollup.js +211 -24
  141. package/dist/signals/schema.d.ts +640 -3
  142. package/dist/signals/schema.js +239 -3
  143. package/dist/signals/silences.d.ts +310 -11
  144. package/dist/signals/silences.js +243 -0
  145. package/dist/signals/subtrees.d.ts +123 -0
  146. package/dist/signals/subtrees.js +102 -0
  147. package/dist/signals/tally.d.ts +125 -4
  148. package/dist/signals/unread.d.ts +292 -0
  149. package/dist/signals/unread.js +137 -0
  150. package/dist/signals/window-agenda.d.ts +276 -0
  151. package/dist/signals/window-agenda.js +83 -0
  152. package/dist/signals/window-funnels.d.ts +88 -0
  153. package/dist/signals/window-funnels.js +47 -0
  154. package/dist/store/cache.d.ts +101 -0
  155. package/dist/store/cache.js +149 -0
  156. package/dist/store/history.d.ts +82 -0
  157. package/dist/store/history.js +36 -0
  158. package/dist/store/index.d.ts +11 -0
  159. package/dist/store/index.js +11 -0
  160. package/dist/store/migrate.d.ts +26 -0
  161. package/dist/store/migrate.js +64 -0
  162. package/dist/store/postgres-audience.d.ts +14 -0
  163. package/dist/store/postgres-audience.js +272 -0
  164. package/dist/store/postgres.d.ts +1 -0
  165. package/dist/store/postgres.js +1 -0
  166. package/dist/store/schema.d.ts +312 -0
  167. package/dist/store/schema.js +77 -0
  168. package/dist/store/source.d.ts +57 -1
  169. package/dist/store/source.js +65 -1
  170. package/dist/submit/resolve.d.ts +1 -1
  171. package/dist/telemetry/index.d.ts +1 -0
  172. package/dist/telemetry/index.js +1 -0
  173. package/dist/telemetry/journal.d.ts +32 -0
  174. package/dist/telemetry/memory.js +10 -1
  175. package/dist/telemetry/postgres.js +18 -2
  176. package/dist/telemetry/window.d.ts +135 -0
  177. package/dist/telemetry/window.js +101 -0
  178. package/dist/testing/audience-overlay-contract.d.ts +31 -0
  179. package/dist/testing/audience-overlay-contract.js +354 -0
  180. package/dist/testing/contracts.d.ts +1 -0
  181. package/dist/testing/contracts.js +1 -0
  182. package/dist/testing/journal-contract.js +158 -5
  183. package/dist/theme/contrast.d.ts +19 -14
  184. package/dist/theme/contrast.js +181 -17
  185. package/dist/tree/apply.js +13 -0
  186. package/dist/tree/mutation.d.ts +18 -0
  187. package/dist/tree/mutation.js +24 -12
  188. package/dist/tree/navigation.d.ts +5 -0
  189. package/dist/tree/navigation.js +32 -10
  190. package/dist/tree/outline.d.ts +7 -0
  191. package/dist/tree/outline.js +9 -5
  192. package/package.json +39 -96
  193. package/dist/runtime/inverse-interpreter.d.ts +0 -90
  194. package/dist/runtime/inverse-interpreter.js +0 -56
@@ -0,0 +1,272 @@
1
+ import { and, desc, eq } from "drizzle-orm";
2
+ import { DEFAULT_APPLICATION_ID } from "../application/application.js";
3
+ import { audienceFormListingsOf, audienceOverlayOf, audienceRulesOutcomeOf, clampAudienceRuleHistoryLimit, parseAudienceRuleRevision, parseStoredAudienceForm, servedFormsOf, withdrawnFormOf, } from "../audience/overlay-store.js";
4
+ import { err, ok } from "../result.js";
5
+ import { isUniqueViolation, unavailable } from "./driver.js";
6
+ import { loomAudienceForms, loomAudienceRules } from "./schema.js";
7
+ /**
8
+ * The audience dimension, backed by Postgres (0022). It is the table that
9
+ * `AudienceOverlaySource` was declared as a seam in place of, and it is the
10
+ * store dimension a page served per audience has been waiting on (0263, 0359).
11
+ *
12
+ * **There is no transaction here, and that is the point of the composite primary
13
+ * key.** `recordRules` reads the head, computes the next revision and inserts
14
+ * it; two editors racing at the same head both compute `N + 1` and the database
15
+ * refuses the second. `loom_revisions` and `loom_policy_revisions` get their
16
+ * ordering guarantee the same way, and a `SELECT … FOR UPDATE` could not serve
17
+ * here anyway: the first revision of a page's rules has no row to lock.
18
+ *
19
+ * A refused insert is reported as `out-of-date` against the head as it is *now*,
20
+ * which is the truth the caller needs rather than the one it raced against.
21
+ */
22
+ /**
23
+ * Rows come back as `unknown` and are parsed, never cast — storage is a boundary
24
+ * like any other, and it is the one where the data outlives the code that wrote
25
+ * it. A rule is edited rarely and read on every request for as long as the page
26
+ * is published, so of everything in this schema it is among the likeliest to be
27
+ * read back by code that did not write it.
28
+ */
29
+ const toRevision = (row, treeId) => parseAudienceRuleRevision({
30
+ treeId: row.treeId,
31
+ revision: row.revision,
32
+ rules: row.rules,
33
+ actor: row.actor,
34
+ recordedAt: row.recordedAt,
35
+ }, treeId);
36
+ /**
37
+ * **Two columns become one field or none**, which is where the backend's
38
+ * spelling of *not withdrawn* stops: `NULL` is mapped to an absent key here, so
39
+ * what the parser and every caller downstream see is the single shape
40
+ * `StoredAudienceForm` declares. A half-set pair — `withdrawn_at` with no
41
+ * `withdrawn_by` — is no write this module makes, and reaches the parser as a
42
+ * withdrawal missing its actor, which `unreadable` is for.
43
+ */
44
+ const toForm = (row, treeId) => parseStoredAudienceForm({
45
+ treeId: row.treeId,
46
+ audienceId: row.audienceId,
47
+ delta: row.delta,
48
+ actor: row.actor,
49
+ authoredAt: row.authoredAt,
50
+ ...(row.withdrawnBy === null && row.withdrawnAt === null
51
+ ? {}
52
+ : { withdrawn: { actor: row.withdrawnBy, at: row.withdrawnAt } }),
53
+ }, treeId);
54
+ /**
55
+ * Every query is filtered by the application this handle speaks for (0260), and
56
+ * every write sets it.
57
+ *
58
+ * Without it a page's rules would be read across applications, and two
59
+ * deployments that happened to name their trees alike would serve each other's
60
+ * forms — which is the one thing a dimension that decides *who sees what* cannot
61
+ * get wrong.
62
+ */
63
+ export const postgresAudienceOverlayStore = (db, scope = {}) => {
64
+ const application = scope.application ?? DEFAULT_APPLICATION_ID;
65
+ const head = async (treeId) => {
66
+ try {
67
+ const rows = await db
68
+ .select()
69
+ .from(loomAudienceRules)
70
+ .where(mineRules(application, eq(loomAudienceRules.treeId, treeId)))
71
+ .orderBy(desc(loomAudienceRules.revision))
72
+ .limit(1);
73
+ const row = rows[0];
74
+ return row === undefined ? ok(undefined) : toRevision(row, treeId);
75
+ }
76
+ catch (cause) {
77
+ return err(unavailable(cause, `could not read ${treeId}'s audience rules`));
78
+ }
79
+ };
80
+ const storedForms = async (treeId) => {
81
+ try {
82
+ const rows = await db
83
+ .select()
84
+ .from(loomAudienceForms)
85
+ .where(mineForms(application, eq(loomAudienceForms.treeId, treeId)))
86
+ .orderBy(loomAudienceForms.audienceId);
87
+ const forms = [];
88
+ for (const row of rows) {
89
+ const form = toForm(row, treeId);
90
+ if (!form.ok)
91
+ return form;
92
+ forms.push(form.value);
93
+ }
94
+ return ok(forms);
95
+ }
96
+ catch (cause) {
97
+ return err(unavailable(cause, `could not read ${treeId}'s audience forms`));
98
+ }
99
+ };
100
+ return {
101
+ overlay: async (treeId) => {
102
+ const rules = await head(treeId);
103
+ if (!rules.ok)
104
+ return rules;
105
+ const forms = await storedForms(treeId);
106
+ if (!forms.ok)
107
+ return forms;
108
+ return ok(audienceOverlayOf(rules.value, servedFormsOf(forms.value)));
109
+ },
110
+ rules: async (treeId) => head(treeId),
111
+ history: async (treeId, request) => {
112
+ try {
113
+ const rows = await db
114
+ .select()
115
+ .from(loomAudienceRules)
116
+ .where(mineRules(application, eq(loomAudienceRules.treeId, treeId)))
117
+ .orderBy(desc(loomAudienceRules.revision))
118
+ .limit(clampAudienceRuleHistoryLimit(request?.limit));
119
+ const revisions = [];
120
+ for (const row of rows) {
121
+ const revision = toRevision(row, treeId);
122
+ if (!revision.ok)
123
+ return revision;
124
+ revisions.push(revision.value);
125
+ }
126
+ return ok(revisions);
127
+ }
128
+ catch (cause) {
129
+ return err(unavailable(cause, `could not read ${treeId}'s audience rule history`));
130
+ }
131
+ },
132
+ forms: async (treeId) => {
133
+ const forms = await storedForms(treeId);
134
+ return forms.ok ? ok(audienceFormListingsOf(forms.value)) : forms;
135
+ },
136
+ recordRules: async (treeId, request) => {
137
+ /**
138
+ * Outside the `try`, because `head` is total: the only statement here that
139
+ * can collide is the insert, and a narrow `try` is what lets the `catch`
140
+ * say *a unique violation on this insert means somebody else recorded*
141
+ * rather than guessing which of two statements threw.
142
+ */
143
+ const current = await head(treeId);
144
+ if (!current.ok)
145
+ return current;
146
+ const outcome = audienceRulesOutcomeOf(treeId, request, current.value);
147
+ if (!outcome.ok || outcome.value.outcome === "unchanged")
148
+ return outcome;
149
+ const revision = outcome.value.revision;
150
+ try {
151
+ await db.insert(loomAudienceRules).values({
152
+ applicationId: application,
153
+ treeId: revision.treeId,
154
+ revision: revision.revision,
155
+ rules: revision.rules,
156
+ actor: revision.actor,
157
+ recordedAt: revision.recordedAt,
158
+ });
159
+ }
160
+ catch (cause) {
161
+ if (!isUniqueViolation(cause)) {
162
+ return err(unavailable(cause, `could not record ${treeId}'s audience rules`));
163
+ }
164
+ /**
165
+ * Somebody else took this revision between the read and the insert. The
166
+ * head is re-read rather than guessed at, so the number reported is the
167
+ * one the caller now has to edit from.
168
+ */
169
+ const raced = await head(treeId);
170
+ return err({
171
+ code: "out-of-date",
172
+ treeId,
173
+ expected: request.expectedRevision ?? current.value?.revision ?? 0,
174
+ current: raced.ok ? (raced.value?.revision ?? 0) : revision.revision,
175
+ });
176
+ }
177
+ return outcome;
178
+ },
179
+ setForm: async (treeId, request) => {
180
+ if (request.delta.treeId !== treeId) {
181
+ return err({
182
+ code: "tree-mismatch",
183
+ treeId,
184
+ delta: request.delta.treeId,
185
+ });
186
+ }
187
+ const stored = { treeId, ...request, withdrawn: undefined };
188
+ try {
189
+ await db
190
+ .insert(loomAudienceForms)
191
+ .values({
192
+ applicationId: application,
193
+ treeId,
194
+ audienceId: request.audienceId,
195
+ delta: request.delta,
196
+ baseRevision: request.delta.baseRevision,
197
+ actor: request.actor,
198
+ authoredAt: request.authoredAt,
199
+ withdrawnBy: null,
200
+ withdrawnAt: null,
201
+ })
202
+ /**
203
+ * The rebase, as one statement. A form replaced by reading it, deciding
204
+ * it has moved and writing it back is a form two editors can lose half
205
+ * of; the key is already the identity, so the database can be asked to
206
+ * do it in one.
207
+ */
208
+ .onConflictDoUpdate({
209
+ target: [
210
+ loomAudienceForms.applicationId,
211
+ loomAudienceForms.treeId,
212
+ loomAudienceForms.audienceId,
213
+ ],
214
+ set: {
215
+ delta: request.delta,
216
+ baseRevision: request.delta.baseRevision,
217
+ actor: request.actor,
218
+ authoredAt: request.authoredAt,
219
+ /**
220
+ * Writing a form puts it back into service (0403). Left out of
221
+ * the `set`, a form withdrawn and then written again would keep
222
+ * its withdrawal and go on not being served — the work rebuilt
223
+ * and the segment still getting the base, with nothing naming
224
+ * the reason.
225
+ */
226
+ withdrawnBy: null,
227
+ withdrawnAt: null,
228
+ },
229
+ });
230
+ }
231
+ catch (cause) {
232
+ return err(unavailable(cause, `could not store ${request.audienceId}'s form of ${treeId}`));
233
+ }
234
+ return ok(stored);
235
+ },
236
+ /**
237
+ * **Read, then a conditional update, and no transaction**, which is the
238
+ * shape the rest of this module earns the right to: the row is read to
239
+ * answer with it and to tell *withdrew one* from *there was none*, and the
240
+ * `UPDATE`'s own `WHERE` is what makes the write safe rather than the read
241
+ * being fresh. A `setForm` racing it either lands first — and is withdrawn,
242
+ * which is what the caller asked — or lands after and puts the form back,
243
+ * which is the later of two acts winning.
244
+ */
245
+ withdrawForm: async (treeId, request) => {
246
+ const forms = await storedForms(treeId);
247
+ if (!forms.ok)
248
+ return forms;
249
+ const held = forms.value.find((form) => form.audienceId === request.audienceId);
250
+ if (held === undefined)
251
+ return ok(undefined);
252
+ try {
253
+ await db
254
+ .update(loomAudienceForms)
255
+ .set({ withdrawnBy: request.actor, withdrawnAt: request.withdrawnAt })
256
+ .where(mineForms(application, eq(loomAudienceForms.treeId, treeId), eq(loomAudienceForms.audienceId, request.audienceId)));
257
+ }
258
+ catch (cause) {
259
+ return err(unavailable(cause, `could not withdraw ${request.audienceId}'s form of ${treeId}`));
260
+ }
261
+ return ok(withdrawnFormOf(held, request));
262
+ },
263
+ };
264
+ };
265
+ /**
266
+ * Every read starts at one of these, so a query cannot forget the application by
267
+ * omission — the device `postgresTreeStore` and `postgresPolicyLog` both use,
268
+ * written per table because the two tables are two sets of columns.
269
+ */
270
+ const mineRules = (application, ...rest) => and(eq(loomAudienceRules.applicationId, application), ...rest);
271
+ const mineForms = (application, ...rest) => and(eq(loomAudienceForms.applicationId, application), ...rest);
272
+ //# sourceMappingURL=postgres-audience.js.map
@@ -3,6 +3,7 @@ import type { LoomDatabase } from "./database.js";
3
3
  import { type TreeStore } from "./store.js";
4
4
  export * from "./database.js";
5
5
  export * from "./migrate.js";
6
+ export * from "./postgres-audience.js";
6
7
  export * from "./postgres-holds.js";
7
8
  export * from "./postgres-policy-log.js";
8
9
  export * from "./postgres-applications.js";
@@ -13,6 +13,7 @@ import { loomRevisions, loomTrees } from "./schema.js";
13
13
  import { anchorBound, anchorResumes, clampListingLimit, clampRevisionLimit, } from "./store.js";
14
14
  export * from "./database.js";
15
15
  export * from "./migrate.js";
16
+ export * from "./postgres-audience.js";
16
17
  export * from "./postgres-holds.js";
17
18
  export * from "./postgres-policy-log.js";
18
19
  export * from "./postgres-applications.js";
@@ -816,4 +816,316 @@ export declare const loomProjects: import("drizzle-orm/pg-core").PgTableWithColu
816
816
  };
817
817
  dialect: "pg";
818
818
  }>;
819
+ /**
820
+ * A page's audience rules, as an append-only log of the whole ordered list.
821
+ *
822
+ * The composite primary key is load-bearing exactly as `loom_revisions`' and
823
+ * `loom_policy_revisions`' are: it makes the *database* enforce the sequence, so
824
+ * two people editing one page's rules cannot both commit even if both read the
825
+ * head before either wrote. `overlay-store.ts` says the same from the other
826
+ * side.
827
+ *
828
+ * `rules` is the whole ordered list as JSON rather than a row per rule, and that
829
+ * is the decision this table exists to carry. 0359 clause 3 makes the order the
830
+ * precedence — the last matching rule wins a contested node — and an order
831
+ * expressed as a `position` column is an order a reorder half-applies: several
832
+ * row updates, with a reader arriving between two of them served a precedence
833
+ * nobody authored. One value, written once, is the only shape that cannot do
834
+ * that. It is also the reason `loom_trees.document` is one column.
835
+ *
836
+ * `recorded_at` is text rather than a timestamp to match
837
+ * `loom_revisions.applied_at` and `loom_policy_revisions.recorded_at` — an
838
+ * ISO-8601 UTC instant orders lexicographically exactly as it orders in time, and
839
+ * what the runtime holds above this boundary is a string.
840
+ */
841
+ export declare const loomAudienceRules: import("drizzle-orm/pg-core").PgTableWithColumns<{
842
+ name: "loom_audience_rules";
843
+ schema: undefined;
844
+ columns: {
845
+ applicationId: import("drizzle-orm/pg-core").PgColumn<{
846
+ name: "application_id";
847
+ tableName: "loom_audience_rules";
848
+ dataType: "string";
849
+ columnType: "PgText";
850
+ data: string;
851
+ driverParam: string;
852
+ notNull: true;
853
+ hasDefault: true;
854
+ isPrimaryKey: false;
855
+ isAutoincrement: false;
856
+ hasRuntimeDefault: false;
857
+ enumValues: [string, ...string[]];
858
+ baseColumn: never;
859
+ identity: undefined;
860
+ generated: undefined;
861
+ }, {}, {}>;
862
+ treeId: import("drizzle-orm/pg-core").PgColumn<{
863
+ name: "tree_id";
864
+ tableName: "loom_audience_rules";
865
+ dataType: "string";
866
+ columnType: "PgText";
867
+ data: string;
868
+ driverParam: string;
869
+ notNull: true;
870
+ hasDefault: false;
871
+ isPrimaryKey: false;
872
+ isAutoincrement: false;
873
+ hasRuntimeDefault: false;
874
+ enumValues: [string, ...string[]];
875
+ baseColumn: never;
876
+ identity: undefined;
877
+ generated: undefined;
878
+ }, {}, {}>;
879
+ revision: import("drizzle-orm/pg-core").PgColumn<{
880
+ name: "revision";
881
+ tableName: "loom_audience_rules";
882
+ dataType: "number";
883
+ columnType: "PgInteger";
884
+ data: number;
885
+ driverParam: string | number;
886
+ notNull: true;
887
+ hasDefault: false;
888
+ isPrimaryKey: false;
889
+ isAutoincrement: false;
890
+ hasRuntimeDefault: false;
891
+ enumValues: undefined;
892
+ baseColumn: never;
893
+ identity: undefined;
894
+ generated: undefined;
895
+ }, {}, {}>;
896
+ rules: import("drizzle-orm/pg-core").PgColumn<{
897
+ name: "rules";
898
+ tableName: "loom_audience_rules";
899
+ dataType: "json";
900
+ columnType: "PgJsonb";
901
+ data: unknown;
902
+ driverParam: unknown;
903
+ notNull: true;
904
+ hasDefault: false;
905
+ isPrimaryKey: false;
906
+ isAutoincrement: false;
907
+ hasRuntimeDefault: false;
908
+ enumValues: undefined;
909
+ baseColumn: never;
910
+ identity: undefined;
911
+ generated: undefined;
912
+ }, {}, {}>;
913
+ actor: import("drizzle-orm/pg-core").PgColumn<{
914
+ name: "actor";
915
+ tableName: "loom_audience_rules";
916
+ dataType: "string";
917
+ columnType: "PgText";
918
+ data: string;
919
+ driverParam: string;
920
+ notNull: true;
921
+ hasDefault: false;
922
+ isPrimaryKey: false;
923
+ isAutoincrement: false;
924
+ hasRuntimeDefault: false;
925
+ enumValues: [string, ...string[]];
926
+ baseColumn: never;
927
+ identity: undefined;
928
+ generated: undefined;
929
+ }, {}, {}>;
930
+ recordedAt: import("drizzle-orm/pg-core").PgColumn<{
931
+ name: "recorded_at";
932
+ tableName: "loom_audience_rules";
933
+ dataType: "string";
934
+ columnType: "PgText";
935
+ data: string;
936
+ driverParam: string;
937
+ notNull: true;
938
+ hasDefault: false;
939
+ isPrimaryKey: false;
940
+ isAutoincrement: false;
941
+ hasRuntimeDefault: false;
942
+ enumValues: [string, ...string[]];
943
+ baseColumn: never;
944
+ identity: undefined;
945
+ generated: undefined;
946
+ }, {}, {}>;
947
+ };
948
+ dialect: "pg";
949
+ }>;
950
+ /**
951
+ * The delta each audience earns, one row per audience per page.
952
+ *
953
+ * Rows rather than a second log, and the asymmetry with the table above is
954
+ * deliberate: a rule decides *who sees which form* and is therefore a decision
955
+ * to be attributed, where a form is a document being worked on and rebased onto
956
+ * a base that has moved. A log of every edit of a form would be a record of
957
+ * drafting rather than of deciding, and the record of how a form came to say
958
+ * what it says is the proposal that produced it.
959
+ *
960
+ * One row per audience rather than one row per page holding every form: two
961
+ * audiences' forms are then independent writes, which is what a deployment with
962
+ * four audiences and two editors needs.
963
+ *
964
+ * `base_revision` is the one denormalised value here, and it is a column for the
965
+ * query it exists for — the same argument `loom_policy_revisions.fingerprint` is
966
+ * a column on. A screen listing a page's audiences asks *which of these forms is
967
+ * behind the page*, and answering it from `delta` means loading every delta to
968
+ * read one integer off each. The write takes it from the delta beside it and
969
+ * never from a caller, so the two cannot disagree.
970
+ */
971
+ export declare const loomAudienceForms: import("drizzle-orm/pg-core").PgTableWithColumns<{
972
+ name: "loom_audience_forms";
973
+ schema: undefined;
974
+ columns: {
975
+ applicationId: import("drizzle-orm/pg-core").PgColumn<{
976
+ name: "application_id";
977
+ tableName: "loom_audience_forms";
978
+ dataType: "string";
979
+ columnType: "PgText";
980
+ data: string;
981
+ driverParam: string;
982
+ notNull: true;
983
+ hasDefault: true;
984
+ isPrimaryKey: false;
985
+ isAutoincrement: false;
986
+ hasRuntimeDefault: false;
987
+ enumValues: [string, ...string[]];
988
+ baseColumn: never;
989
+ identity: undefined;
990
+ generated: undefined;
991
+ }, {}, {}>;
992
+ treeId: import("drizzle-orm/pg-core").PgColumn<{
993
+ name: "tree_id";
994
+ tableName: "loom_audience_forms";
995
+ dataType: "string";
996
+ columnType: "PgText";
997
+ data: string;
998
+ driverParam: string;
999
+ notNull: true;
1000
+ hasDefault: false;
1001
+ isPrimaryKey: false;
1002
+ isAutoincrement: false;
1003
+ hasRuntimeDefault: false;
1004
+ enumValues: [string, ...string[]];
1005
+ baseColumn: never;
1006
+ identity: undefined;
1007
+ generated: undefined;
1008
+ }, {}, {}>;
1009
+ audienceId: import("drizzle-orm/pg-core").PgColumn<{
1010
+ name: "audience_id";
1011
+ tableName: "loom_audience_forms";
1012
+ dataType: "string";
1013
+ columnType: "PgText";
1014
+ data: string;
1015
+ driverParam: string;
1016
+ notNull: true;
1017
+ hasDefault: false;
1018
+ isPrimaryKey: false;
1019
+ isAutoincrement: false;
1020
+ hasRuntimeDefault: false;
1021
+ enumValues: [string, ...string[]];
1022
+ baseColumn: never;
1023
+ identity: undefined;
1024
+ generated: undefined;
1025
+ }, {}, {}>;
1026
+ delta: import("drizzle-orm/pg-core").PgColumn<{
1027
+ name: "delta";
1028
+ tableName: "loom_audience_forms";
1029
+ dataType: "json";
1030
+ columnType: "PgJsonb";
1031
+ data: unknown;
1032
+ driverParam: unknown;
1033
+ notNull: true;
1034
+ hasDefault: false;
1035
+ isPrimaryKey: false;
1036
+ isAutoincrement: false;
1037
+ hasRuntimeDefault: false;
1038
+ enumValues: undefined;
1039
+ baseColumn: never;
1040
+ identity: undefined;
1041
+ generated: undefined;
1042
+ }, {}, {}>;
1043
+ baseRevision: import("drizzle-orm/pg-core").PgColumn<{
1044
+ name: "base_revision";
1045
+ tableName: "loom_audience_forms";
1046
+ dataType: "number";
1047
+ columnType: "PgInteger";
1048
+ data: number;
1049
+ driverParam: string | number;
1050
+ notNull: true;
1051
+ hasDefault: false;
1052
+ isPrimaryKey: false;
1053
+ isAutoincrement: false;
1054
+ hasRuntimeDefault: false;
1055
+ enumValues: undefined;
1056
+ baseColumn: never;
1057
+ identity: undefined;
1058
+ generated: undefined;
1059
+ }, {}, {}>;
1060
+ actor: import("drizzle-orm/pg-core").PgColumn<{
1061
+ name: "actor";
1062
+ tableName: "loom_audience_forms";
1063
+ dataType: "string";
1064
+ columnType: "PgText";
1065
+ data: string;
1066
+ driverParam: string;
1067
+ notNull: true;
1068
+ hasDefault: false;
1069
+ isPrimaryKey: false;
1070
+ isAutoincrement: false;
1071
+ hasRuntimeDefault: false;
1072
+ enumValues: [string, ...string[]];
1073
+ baseColumn: never;
1074
+ identity: undefined;
1075
+ generated: undefined;
1076
+ }, {}, {}>;
1077
+ authoredAt: import("drizzle-orm/pg-core").PgColumn<{
1078
+ name: "authored_at";
1079
+ tableName: "loom_audience_forms";
1080
+ dataType: "string";
1081
+ columnType: "PgText";
1082
+ data: string;
1083
+ driverParam: string;
1084
+ notNull: true;
1085
+ hasDefault: false;
1086
+ isPrimaryKey: false;
1087
+ isAutoincrement: false;
1088
+ hasRuntimeDefault: false;
1089
+ enumValues: [string, ...string[]];
1090
+ baseColumn: never;
1091
+ identity: undefined;
1092
+ generated: undefined;
1093
+ }, {}, {}>;
1094
+ withdrawnBy: import("drizzle-orm/pg-core").PgColumn<{
1095
+ name: "withdrawn_by";
1096
+ tableName: "loom_audience_forms";
1097
+ dataType: "string";
1098
+ columnType: "PgText";
1099
+ data: string;
1100
+ driverParam: string;
1101
+ notNull: false;
1102
+ hasDefault: false;
1103
+ isPrimaryKey: false;
1104
+ isAutoincrement: false;
1105
+ hasRuntimeDefault: false;
1106
+ enumValues: [string, ...string[]];
1107
+ baseColumn: never;
1108
+ identity: undefined;
1109
+ generated: undefined;
1110
+ }, {}, {}>;
1111
+ withdrawnAt: import("drizzle-orm/pg-core").PgColumn<{
1112
+ name: "withdrawn_at";
1113
+ tableName: "loom_audience_forms";
1114
+ dataType: "string";
1115
+ columnType: "PgText";
1116
+ data: string;
1117
+ driverParam: string;
1118
+ notNull: false;
1119
+ hasDefault: false;
1120
+ isPrimaryKey: false;
1121
+ isAutoincrement: false;
1122
+ hasRuntimeDefault: false;
1123
+ enumValues: [string, ...string[]];
1124
+ baseColumn: never;
1125
+ identity: undefined;
1126
+ generated: undefined;
1127
+ }, {}, {}>;
1128
+ };
1129
+ dialect: "pg";
1130
+ }>;
819
1131
  //# sourceMappingURL=schema.d.ts.map
@@ -211,4 +211,81 @@ export const loomProjects = pgTable("loom_projects", {
211
211
  */
212
212
  closedAt: text("closed_at"),
213
213
  });
214
+ /**
215
+ * A page's audience rules, as an append-only log of the whole ordered list.
216
+ *
217
+ * The composite primary key is load-bearing exactly as `loom_revisions`' and
218
+ * `loom_policy_revisions`' are: it makes the *database* enforce the sequence, so
219
+ * two people editing one page's rules cannot both commit even if both read the
220
+ * head before either wrote. `overlay-store.ts` says the same from the other
221
+ * side.
222
+ *
223
+ * `rules` is the whole ordered list as JSON rather than a row per rule, and that
224
+ * is the decision this table exists to carry. 0359 clause 3 makes the order the
225
+ * precedence — the last matching rule wins a contested node — and an order
226
+ * expressed as a `position` column is an order a reorder half-applies: several
227
+ * row updates, with a reader arriving between two of them served a precedence
228
+ * nobody authored. One value, written once, is the only shape that cannot do
229
+ * that. It is also the reason `loom_trees.document` is one column.
230
+ *
231
+ * `recorded_at` is text rather than a timestamp to match
232
+ * `loom_revisions.applied_at` and `loom_policy_revisions.recorded_at` — an
233
+ * ISO-8601 UTC instant orders lexicographically exactly as it orders in time, and
234
+ * what the runtime holds above this boundary is a string.
235
+ */
236
+ export const loomAudienceRules = pgTable("loom_audience_rules", {
237
+ /** See `loomTrees.applicationId`. */
238
+ applicationId: text("application_id").notNull().default("app_default"),
239
+ treeId: text("tree_id").notNull(),
240
+ revision: integer("revision").notNull(),
241
+ rules: jsonb("rules").notNull(),
242
+ /** Who made these the rules (0200). Never null, for the reason `loom_policy_revisions.actor` is not. */
243
+ actor: text("actor").notNull(),
244
+ recordedAt: text("recorded_at").notNull(),
245
+ }, (table) => [primaryKey({ columns: [table.applicationId, table.treeId, table.revision] })]);
246
+ /**
247
+ * The delta each audience earns, one row per audience per page.
248
+ *
249
+ * Rows rather than a second log, and the asymmetry with the table above is
250
+ * deliberate: a rule decides *who sees which form* and is therefore a decision
251
+ * to be attributed, where a form is a document being worked on and rebased onto
252
+ * a base that has moved. A log of every edit of a form would be a record of
253
+ * drafting rather than of deciding, and the record of how a form came to say
254
+ * what it says is the proposal that produced it.
255
+ *
256
+ * One row per audience rather than one row per page holding every form: two
257
+ * audiences' forms are then independent writes, which is what a deployment with
258
+ * four audiences and two editors needs.
259
+ *
260
+ * `base_revision` is the one denormalised value here, and it is a column for the
261
+ * query it exists for — the same argument `loom_policy_revisions.fingerprint` is
262
+ * a column on. A screen listing a page's audiences asks *which of these forms is
263
+ * behind the page*, and answering it from `delta` means loading every delta to
264
+ * read one integer off each. The write takes it from the delta beside it and
265
+ * never from a caller, so the two cannot disagree.
266
+ */
267
+ export const loomAudienceForms = pgTable("loom_audience_forms", {
268
+ /** See `loomTrees.applicationId`. */
269
+ applicationId: text("application_id").notNull().default("app_default"),
270
+ treeId: text("tree_id").notNull(),
271
+ audienceId: text("audience_id").notNull(),
272
+ delta: jsonb("delta").notNull(),
273
+ baseRevision: integer("base_revision").notNull(),
274
+ actor: text("actor").notNull(),
275
+ authoredAt: text("authored_at").notNull(),
276
+ /**
277
+ * Who took this form out of service and when, both `NULL` while it is the
278
+ * form its audience is served (0403).
279
+ *
280
+ * **Two nullable columns and not a delete**, which is what keeps the
281
+ * no-delete rule (0376): the row stays, carrying the delta it held, so the
282
+ * day the change is wanted again the work is there and `setForm` is the one
283
+ * call that puts it back. They are set and cleared together — `withdrawnAt`
284
+ * without `withdrawnBy` is a state no write here produces.
285
+ */
286
+ withdrawnBy: text("withdrawn_by"),
287
+ withdrawnAt: text("withdrawn_at"),
288
+ }, (table) => [
289
+ primaryKey({ columns: [table.applicationId, table.treeId, table.audienceId] }),
290
+ ]);
214
291
  //# sourceMappingURL=schema.js.map