@elytracms/studio 0.0.86 → 0.0.88

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 (248) hide show
  1. package/convex/asset-revalidate.test.ts +186 -0
  2. package/convex/assets.ts +53 -19
  3. package/convex/cms.ts +22 -0
  4. package/convex/delivery.ts +33 -116
  5. package/convex/functions.ts +3 -3
  6. package/convex/rail-write-parity.test.ts +180 -0
  7. package/convex/redirects.ts +33 -11
  8. package/convex/revalidate.ts +7 -5
  9. package/convex/triggers.ts +53 -3
  10. package/dist/components/ai/ai-chat-panel.js +8 -1
  11. package/dist/components/ai/ai-chat-panel.js.map +1 -1
  12. package/dist/components/app-views/default-modules.d.ts +20 -20
  13. package/dist/components/app-views/default-modules.js +27 -48
  14. package/dist/components/app-views/default-modules.js.map +1 -1
  15. package/dist/components/app-views/studio-config.d.ts +5 -6
  16. package/dist/components/app-views/studio-config.js.map +1 -1
  17. package/dist/components/assets/asset-metadata.d.ts +28 -19
  18. package/dist/components/assets/asset-metadata.js +24 -31
  19. package/dist/components/assets/asset-metadata.js.map +1 -1
  20. package/dist/components/assets/asset-selection.d.ts +24 -5
  21. package/dist/components/assets/asset-selection.js +39 -9
  22. package/dist/components/assets/asset-selection.js.map +1 -1
  23. package/dist/components/assets/assets-collection-view-source.d.ts +17 -14
  24. package/dist/components/assets/assets-collection-view-source.js +25 -31
  25. package/dist/components/assets/assets-collection-view-source.js.map +1 -1
  26. package/dist/components/assets/assets-store.d.ts +11 -1
  27. package/dist/components/assets/assets-store.js +10 -0
  28. package/dist/components/assets/assets-store.js.map +1 -1
  29. package/dist/components/assets/focal-point.d.ts +0 -7
  30. package/dist/components/assets/focal-point.js +0 -10
  31. package/dist/components/assets/focal-point.js.map +1 -1
  32. package/dist/components/builder/blocks-panel.js +3 -3
  33. package/dist/components/builder/blocks-panel.js.map +1 -1
  34. package/dist/components/builder/builder-store.d.ts +25 -1
  35. package/dist/components/builder/builder-store.js +3 -2
  36. package/dist/components/builder/builder-store.js.map +1 -1
  37. package/dist/components/builder/canvas-chrome-css.js +0 -17
  38. package/dist/components/builder/canvas-chrome-css.js.map +1 -1
  39. package/dist/components/builder/canvas-chrome.d.ts +10 -12
  40. package/dist/components/builder/canvas-chrome.js +12 -13
  41. package/dist/components/builder/canvas-chrome.js.map +1 -1
  42. package/dist/components/builder/canvas-dnd.d.ts +8 -0
  43. package/dist/components/builder/canvas-dnd.js +5 -3
  44. package/dist/components/builder/canvas-dnd.js.map +1 -1
  45. package/dist/components/builder/canvas-render-context.d.ts +23 -24
  46. package/dist/components/builder/canvas-render-context.js +35 -60
  47. package/dist/components/builder/canvas-render-context.js.map +1 -1
  48. package/dist/components/builder/canvas.js +5 -11
  49. package/dist/components/builder/canvas.js.map +1 -1
  50. package/dist/components/builder/clipboard-actions.d.ts +14 -6
  51. package/dist/components/builder/clipboard-actions.js +29 -20
  52. package/dist/components/builder/clipboard-actions.js.map +1 -1
  53. package/dist/components/builder/composition-field-editor.d.ts +19 -26
  54. package/dist/components/builder/composition-field-editor.js +30 -52
  55. package/dist/components/builder/composition-field-editor.js.map +1 -1
  56. package/dist/components/builder/insert-context.d.ts +3 -1
  57. package/dist/components/builder/insert-context.js +15 -10
  58. package/dist/components/builder/insert-context.js.map +1 -1
  59. package/dist/components/builder/page-tree.d.ts +29 -0
  60. package/dist/components/builder/page-tree.js +56 -58
  61. package/dist/components/builder/page-tree.js.map +1 -1
  62. package/dist/components/builder/reuse.js +5 -2
  63. package/dist/components/builder/reuse.js.map +1 -1
  64. package/dist/components/cms/asset-field.d.ts +2 -1
  65. package/dist/components/cms/asset-field.js +39 -83
  66. package/dist/components/cms/asset-field.js.map +1 -1
  67. package/dist/components/cms/asset-picker-core.d.ts +77 -40
  68. package/dist/components/cms/asset-picker-core.js +73 -46
  69. package/dist/components/cms/asset-picker-core.js.map +1 -1
  70. package/dist/components/cms/asset-picker.d.ts +48 -19
  71. package/dist/components/cms/asset-picker.js +69 -30
  72. package/dist/components/cms/asset-picker.js.map +1 -1
  73. package/dist/components/cms/cell-edit.d.ts +3 -1
  74. package/dist/components/cms/cell-edit.js +2 -2
  75. package/dist/components/cms/cell-edit.js.map +1 -1
  76. package/dist/components/cms/cms-composition-validators.js +11 -2
  77. package/dist/components/cms/cms-composition-validators.js.map +1 -1
  78. package/dist/components/cms/cms-store.js +15 -23
  79. package/dist/components/cms/cms-store.js.map +1 -1
  80. package/dist/components/cms/editable-cell.js +3 -3
  81. package/dist/components/cms/editable-cell.js.map +1 -1
  82. package/dist/components/cms/gate-validation.d.ts +27 -2
  83. package/dist/components/cms/gate-validation.js +19 -1
  84. package/dist/components/cms/gate-validation.js.map +1 -1
  85. package/dist/components/cms/rich-text/editor.js +2 -2
  86. package/dist/components/cms/rich-text/editor.js.map +1 -1
  87. package/dist/components/cms/rich-text/insert.d.ts +7 -0
  88. package/dist/components/cms/rich-text/insert.js +7 -0
  89. package/dist/components/cms/rich-text/insert.js.map +1 -1
  90. package/dist/components/cms/use-document-versions.js +1 -0
  91. package/dist/components/cms/use-document-versions.js.map +1 -1
  92. package/dist/components/cms/versions-model.d.ts +0 -12
  93. package/dist/components/cms/versions-model.js +3 -15
  94. package/dist/components/cms/versions-model.js.map +1 -1
  95. package/dist/components/components/component-detail.js +1 -1
  96. package/dist/components/components/component-detail.js.map +1 -1
  97. package/dist/components/components/transfer-dialog.js +2 -4
  98. package/dist/components/components/transfer-dialog.js.map +1 -1
  99. package/dist/components/components/transfer.d.ts +13 -10
  100. package/dist/components/components/transfer.js +21 -19
  101. package/dist/components/components/transfer.js.map +1 -1
  102. package/dist/components/nav-issues.d.ts +23 -3
  103. package/dist/components/nav-issues.js +38 -2
  104. package/dist/components/nav-issues.js.map +1 -1
  105. package/dist/components/project-session.d.ts +9 -0
  106. package/dist/components/project-session.js +1 -1
  107. package/dist/components/project-session.js.map +1 -1
  108. package/dist/components/redirects/redirects-collection-view-source.d.ts +17 -2
  109. package/dist/components/redirects/redirects-collection-view-source.js +20 -6
  110. package/dist/components/redirects/redirects-collection-view-source.js.map +1 -1
  111. package/dist/components/section-nav.js +26 -2
  112. package/dist/components/section-nav.js.map +1 -1
  113. package/dist/components/section-surface.js +3 -2
  114. package/dist/components/section-surface.js.map +1 -1
  115. package/dist/components/settings-form.js +1 -2
  116. package/dist/components/settings-form.js.map +1 -1
  117. package/dist/components/studio-context.js +1 -18
  118. package/dist/components/studio-context.js.map +1 -1
  119. package/dist/components/studio-project-screen.js +3 -5
  120. package/dist/components/studio-project-screen.js.map +1 -1
  121. package/dist/lib/ai/apply-content.js +73 -29
  122. package/dist/lib/ai/apply-content.js.map +1 -1
  123. package/dist/lib/ai/constraints.d.ts +35 -0
  124. package/dist/lib/ai/constraints.js +104 -4
  125. package/dist/lib/ai/constraints.js.map +1 -1
  126. package/dist/lib/ai/route.js +4 -1
  127. package/dist/lib/ai/route.js.map +1 -1
  128. package/dist/lib/ai/shape.d.ts +3 -2
  129. package/dist/lib/ai/shape.js +16 -24
  130. package/dist/lib/ai/shape.js.map +1 -1
  131. package/dist/lib/ai/tools.d.ts +10 -4
  132. package/dist/lib/ai/tools.js +12 -4
  133. package/dist/lib/ai/tools.js.map +1 -1
  134. package/dist/lib/ai/types.d.ts +8 -0
  135. package/dist/lib/ai/types.js.map +1 -1
  136. package/dist/lib/ai/update-fields.js +33 -12
  137. package/dist/lib/ai/update-fields.js.map +1 -1
  138. package/dist/lib/assets/asset-placements.d.ts +35 -0
  139. package/dist/lib/assets/asset-placements.js +74 -0
  140. package/dist/lib/assets/asset-placements.js.map +1 -0
  141. package/dist/lib/assets/backfill-thumbs.d.ts +9 -8
  142. package/dist/lib/assets/backfill-thumbs.js +13 -25
  143. package/dist/lib/assets/backfill-thumbs.js.map +1 -1
  144. package/dist/lib/clipboard/paste-issues.d.ts +17 -15
  145. package/dist/lib/clipboard/paste-issues.js +8 -45
  146. package/dist/lib/clipboard/paste-issues.js.map +1 -1
  147. package/dist/lib/clipboard/paste-target.d.ts +25 -1
  148. package/dist/lib/clipboard/paste-target.js +13 -6
  149. package/dist/lib/clipboard/paste-target.js.map +1 -1
  150. package/dist/lib/cms/published-documents.js +1 -0
  151. package/dist/lib/cms/published-documents.js.map +1 -1
  152. package/dist/lib/cms-views/view-model.d.ts +3 -3
  153. package/dist/lib/data/collection-content.d.ts +22 -1
  154. package/dist/lib/data/collection-content.js +15 -0
  155. package/dist/lib/data/collection-content.js.map +1 -1
  156. package/dist/lib/data/index.d.ts +0 -3
  157. package/dist/lib/data/index.js +4 -6
  158. package/dist/lib/data/index.js.map +1 -1
  159. package/dist/lib/dnd/drop-rules.d.ts +45 -2
  160. package/dist/lib/dnd/drop-rules.js +64 -9
  161. package/dist/lib/dnd/drop-rules.js.map +1 -1
  162. package/dist/lib/engine-version.d.ts +3 -3
  163. package/dist/lib/engine-version.js +3 -3
  164. package/dist/lib/engine-version.js.map +1 -1
  165. package/dist/lib/i18n/messages.de.js +9 -56
  166. package/dist/lib/i18n/messages.de.js.map +1 -1
  167. package/dist/lib/i18n/messages.en.d.ts +8 -53
  168. package/dist/lib/i18n/messages.en.js +14 -57
  169. package/dist/lib/i18n/messages.en.js.map +1 -1
  170. package/dist/lib/locale/fallback.js +8 -2
  171. package/dist/lib/locale/fallback.js.map +1 -1
  172. package/dist/lib/locale/index.d.ts +0 -1
  173. package/dist/lib/locale/index.js +0 -1
  174. package/dist/lib/locale/index.js.map +1 -1
  175. package/dist/lib/locale/locale-store.d.ts +10 -3
  176. package/dist/lib/locale/locale-store.js +12 -5
  177. package/dist/lib/locale/locale-store.js.map +1 -1
  178. package/dist/lib/operations/session-hydration.d.ts +24 -22
  179. package/dist/lib/operations/session-hydration.js +15 -53
  180. package/dist/lib/operations/session-hydration.js.map +1 -1
  181. package/dist/lib/persistence/convex-adapter.js +63 -75
  182. package/dist/lib/persistence/convex-adapter.js.map +1 -1
  183. package/dist/lib/persona/labels.d.ts +0 -2
  184. package/dist/lib/persona/labels.js +1 -7
  185. package/dist/lib/persona/labels.js.map +1 -1
  186. package/dist/lib/registry/index.d.ts +4 -2
  187. package/dist/lib/registry/index.js +26 -21
  188. package/dist/lib/registry/index.js.map +1 -1
  189. package/dist/lib/registry/project-components.js +0 -3
  190. package/dist/lib/registry/project-components.js.map +1 -1
  191. package/dist/lib/routes/route-issues.js +4 -5
  192. package/dist/lib/routes/route-issues.js.map +1 -1
  193. package/dist/lib/theme.js +3 -2
  194. package/dist/lib/theme.js.map +1 -1
  195. package/dist/lib/webhooks/tags.js +11 -14
  196. package/dist/lib/webhooks/tags.js.map +1 -1
  197. package/dist/lib/workspace/config-issues.d.ts +6 -0
  198. package/dist/lib/workspace/config-issues.js +8 -4
  199. package/dist/lib/workspace/config-issues.js.map +1 -1
  200. package/dist/lib/workspace/index.d.ts +2 -2
  201. package/dist/lib/workspace/index.js +2 -2
  202. package/dist/lib/workspace/index.js.map +1 -1
  203. package/dist/previews/enumerate.d.ts +27 -9
  204. package/dist/previews/enumerate.js +27 -6
  205. package/dist/previews/enumerate.js.map +1 -1
  206. package/dist/previews/manifest-format.d.ts +9 -0
  207. package/dist/previews/manifest-format.js.map +1 -1
  208. package/dist/router/match.d.ts +0 -2
  209. package/dist/router/match.js +0 -2
  210. package/dist/router/match.js.map +1 -1
  211. package/dist/router/navigate-once.d.ts +19 -4
  212. package/dist/router/navigate-once.js +22 -5
  213. package/dist/router/navigate-once.js.map +1 -1
  214. package/dist/ui/badge.d.ts +1 -1
  215. package/package.json +3 -3
  216. package/src/styles/studio.css +5 -4
  217. package/src/styles/tokens.css +72 -55
  218. package/convex/content.ts +0 -291
  219. package/dist/components/collab/collab-context.d.ts +0 -27
  220. package/dist/components/collab/collab-context.js +0 -39
  221. package/dist/components/collab/collab-context.js.map +0 -1
  222. package/dist/components/collab/collab-seed.d.ts +0 -15
  223. package/dist/components/collab/collab-seed.js +0 -20
  224. package/dist/components/collab/collab-seed.js.map +0 -1
  225. package/dist/components/extensions/extensions-view.d.ts +0 -7
  226. package/dist/components/extensions/extensions-view.js +0 -127
  227. package/dist/components/extensions/extensions-view.js.map +0 -1
  228. package/dist/lib/bindings/section-bindings.d.ts +0 -24
  229. package/dist/lib/bindings/section-bindings.js +0 -9
  230. package/dist/lib/bindings/section-bindings.js.map +0 -1
  231. package/dist/lib/data/data-store.d.ts +0 -98
  232. package/dist/lib/data/data-store.js +0 -211
  233. package/dist/lib/data/data-store.js.map +0 -1
  234. package/dist/lib/data/providers.d.ts +0 -143
  235. package/dist/lib/data/providers.js +0 -255
  236. package/dist/lib/data/providers.js.map +0 -1
  237. package/dist/lib/data/sample-capture.d.ts +0 -30
  238. package/dist/lib/data/sample-capture.js +0 -70
  239. package/dist/lib/data/sample-capture.js.map +0 -1
  240. package/dist/lib/data/sources-store.d.ts +0 -42
  241. package/dist/lib/data/sources-store.js +0 -120
  242. package/dist/lib/data/sources-store.js.map +0 -1
  243. package/dist/lib/locale/binding-fallback.d.ts +0 -35
  244. package/dist/lib/locale/binding-fallback.js +0 -73
  245. package/dist/lib/locale/binding-fallback.js.map +0 -1
  246. package/dist/lib/starters/kit-session.d.ts +0 -5
  247. package/dist/lib/starters/kit-session.js +0 -17
  248. package/dist/lib/starters/kit-session.js.map +0 -1
@@ -1,5 +1,6 @@
1
+ import { ConvexError } from 'convex/values';
1
2
  import { documentKey, documentSchema } from '@elytracms/core/cms-core';
2
- import { RecordNotFoundError, PersistenceValidationError, compareReferenceEntries, highestRole, isKnownRole, validateForPersistence, } from '@elytracms/core/persistence';
3
+ import { RecordNotFoundError, PersistenceValidationError, assetCreateDefaults, assetRecordFromRow, compareReferenceEntries, highestRole, isKnownRole, persistenceIssueSchema, presentWriteKeys, redirectEntryFromRow, validateForPersistence, } from '@elytracms/core/persistence';
3
4
  import { normalizeInviteEmail } from '@elytracms/core/persistence';
4
5
  import { queryRef, mutationRef } from './convex-client.js';
5
6
  import { ConvexBlobStorage } from './convex-blob-storage.js';
@@ -17,9 +18,14 @@ function newId(prefix) {
17
18
  * carries a stable placeholder rather than DB-row timestamps.
18
19
  */
19
20
  const CONFIG_SCHEMA_TIMESTAMP = '2026-01-01T00:00:00.000Z';
20
- function docRecordFromDoc(doc) {
21
+ /**
22
+ * Row → contract record. `projectId` is the caller's (the row has none): before
23
+ * EC-577 this copied the row's nonexistent `projectId`, so every connected
24
+ * `CmsDocumentRecord.projectId` was `undefined` against a `min(1)` schema (MODE #6).
25
+ */
26
+ function docRecordFromDoc(doc, projectId) {
21
27
  return {
22
- projectId: doc.projectId,
28
+ projectId,
23
29
  document: doc.document,
24
30
  ...(doc.publishedVersion !== undefined ? { publishedVersion: doc.publishedVersion } : {}),
25
31
  // EC-447: carry the materialized publish instant onto the contract record so the
@@ -104,7 +110,7 @@ class ConvexCmsRepository {
104
110
  createdAt: now,
105
111
  updatedAt: now,
106
112
  }));
107
- return docRecordFromDoc(doc);
113
+ return docRecordFromDoc(doc, projectId);
108
114
  }
109
115
  async getDocument(projectId, ref) {
110
116
  const found = await this.findDocument(projectId, ref);
@@ -117,7 +123,7 @@ class ConvexCmsRepository {
117
123
  collection: ref.collection,
118
124
  docId: ref.id,
119
125
  }));
120
- return doc ? docRecordFromDoc(doc) : undefined;
126
+ return doc ? docRecordFromDoc(doc, projectId) : undefined;
121
127
  }
122
128
  async listDocuments(projectId, collection) {
123
129
  const docs = (await this.client.query(queryRef('cms:listDocuments'), {
@@ -126,7 +132,7 @@ class ConvexCmsRepository {
126
132
  // EC-153 parity: deterministic document-key ordering (Convex index order
127
133
  // within a project is insertion order, so we sort client-side).
128
134
  return docs
129
- .map(docRecordFromDoc)
135
+ .map((doc) => docRecordFromDoc(doc, projectId))
130
136
  .sort((a, b) => (documentKey(a.document) < documentKey(b.document) ? -1 : 1));
131
137
  }
132
138
  async listPublishedDocuments(projectId, collection) {
@@ -148,6 +154,10 @@ class ConvexCmsRepository {
148
154
  docId: ref.id,
149
155
  });
150
156
  }
157
+ async clearDocuments(_projectId) {
158
+ // EC-576: one deployment is one project — the mutation clears both tables at once.
159
+ await this.client.mutation(mutationRef('cms:clearDocuments'), {});
160
+ }
151
161
  async saveDocumentVersion(projectId, snapshot, options = {}) {
152
162
  const parsed = documentSchema.parse(snapshot);
153
163
  const doc = (await this.client.mutation(mutationRef('cms:saveDocumentVersion'), {
@@ -198,7 +208,7 @@ class ConvexCmsRepository {
198
208
  updatedAt: now,
199
209
  publishedAt: now,
200
210
  }));
201
- return docRecordFromDoc(doc);
211
+ return docRecordFromDoc(doc, projectId);
202
212
  }
203
213
  async unpublishDocument(projectId, ref) {
204
214
  const existing = await this.getDocument(projectId, ref);
@@ -216,30 +226,24 @@ class ConvexCmsRepository {
216
226
  docId: ref.id,
217
227
  updatedAt: this.clock(),
218
228
  }));
219
- return docRecordFromDoc(doc);
229
+ return docRecordFromDoc(doc, projectId);
220
230
  }
221
231
  }
222
- /** Map a Convex asset doc onto the contract record (assetId → id, drop _id/_creationTime). */
223
- function assetRecordFromDoc(doc) {
224
- return {
225
- id: doc.assetId,
226
- projectId: doc.projectId,
227
- filename: doc.filename,
228
- contentType: doc.contentType,
229
- byteSize: doc.byteSize,
230
- ...(doc.width !== undefined ? { width: doc.width } : {}),
231
- ...(doc.height !== undefined ? { height: doc.height } : {}),
232
- ...(doc.alt !== undefined ? { alt: doc.alt } : {}),
233
- ...(doc.title !== undefined ? { title: doc.title } : {}),
234
- ...(doc.url !== undefined ? { url: doc.url } : {}),
235
- ...(doc.focalPoint !== undefined ? { focalPoint: doc.focalPoint } : {}),
236
- ...(doc.thumb !== undefined ? { thumb: doc.thumb } : {}),
237
- ...(doc.lqip !== undefined ? { lqip: doc.lqip } : {}),
238
- ...(doc.meta !== undefined ? { meta: doc.meta } : {}),
239
- storageKey: doc.storageKey,
240
- createdAt: doc.createdAt,
241
- updatedAt: doc.updatedAt,
242
- };
232
+ /**
233
+ * A rail write the handler rejected (EC-577): `resolveRecordWrite` found the write
234
+ * invalid inside the transaction and threw a `validation` `ConvexError` — mapped
235
+ * back onto the provider-neutral {@link PersistenceValidationError} the in-memory
236
+ * adapter throws for the same write. `ConvexError` data survives a production
237
+ * deployment's error redaction, unlike a plain thrown message.
238
+ */
239
+ function asRailWriteError(error) {
240
+ if (!(error instanceof ConvexError))
241
+ return error;
242
+ const data = error.data;
243
+ if (data?.code !== 'validation' || typeof data.message !== 'string')
244
+ return error;
245
+ const issues = persistenceIssueSchema.array().safeParse(data.issues);
246
+ return new PersistenceValidationError(data.message, issues.success ? issues.data : []);
243
247
  }
244
248
  class ConvexAssetRepository {
245
249
  client;
@@ -250,27 +254,23 @@ class ConvexAssetRepository {
250
254
  }
251
255
  async upsertAsset(projectId, input) {
252
256
  const now = this.clock();
253
- const id = input.id ?? newId('asset');
254
- const doc = (await this.client.mutation(mutationRef('assets:upsert'), {
257
+ const { id: givenId, ...write } = input;
258
+ const id = givenId ?? newId('asset');
259
+ // EC-577: send the write as written — absent keys stay absent (keep), `null`
260
+ // crosses the wire as the clear. The handler resolves it against the stored
261
+ // row inside the transaction; the create defaults ride along for a create.
262
+ const doc = (await this.client
263
+ .mutation(mutationRef('assets:upsert'), {
255
264
  assetId: id,
256
- filename: input.filename,
257
- contentType: input.contentType,
258
- byteSize: input.byteSize,
259
- ...(input.width !== undefined ? { width: input.width } : {}),
260
- ...(input.height !== undefined ? { height: input.height } : {}),
261
- ...(input.alt !== undefined ? { alt: input.alt } : {}),
262
- // EC-153 parity: `title` (EC-152 metadata) must persist, not silently drop.
263
- ...(input.title !== undefined ? { title: input.title } : {}),
264
- ...(input.url !== undefined ? { url: input.url } : {}),
265
- ...(input.focalPoint !== undefined ? { focalPoint: input.focalPoint } : {}),
266
- ...(input.thumb !== undefined ? { thumb: input.thumb } : {}),
267
- ...(input.lqip !== undefined ? { lqip: input.lqip } : {}),
268
- ...(input.meta !== undefined ? { meta: input.meta } : {}),
269
- storageKey: input.storageKey ?? `${projectId}/${id}`,
265
+ ...presentWriteKeys(write),
266
+ defaults: assetCreateDefaults(projectId, id),
270
267
  createdAt: now,
271
268
  updatedAt: now,
269
+ })
270
+ .catch((error) => {
271
+ throw asRailWriteError(error);
272
272
  }));
273
- return assetRecordFromDoc(doc);
273
+ return assetRecordFromRow(doc, projectId);
274
274
  }
275
275
  async getAsset(projectId, id) {
276
276
  const found = await this.findAsset(projectId, id);
@@ -282,11 +282,11 @@ class ConvexAssetRepository {
282
282
  const doc = (await this.client.query(queryRef('assets:get'), {
283
283
  assetId: id,
284
284
  }));
285
- return doc ? assetRecordFromDoc(doc) : undefined;
285
+ return doc ? assetRecordFromRow(doc, projectId) : undefined;
286
286
  }
287
- async listAssets(_projectId) {
287
+ async listAssets(projectId) {
288
288
  const docs = (await this.client.query(queryRef('assets:list'), {}));
289
- return docs.map(assetRecordFromDoc);
289
+ return docs.map((doc) => assetRecordFromRow(doc, projectId));
290
290
  }
291
291
  async removeAsset(projectId, id) {
292
292
  // EC-153 parity: removing an unknown asset is not-found, never a no-op.
@@ -612,25 +612,12 @@ class ConvexInviteRepository {
612
612
  }
613
613
  }
614
614
  }
615
- function redirectEntryFromDoc(doc, projectId) {
616
- return {
617
- id: doc.redirectId,
618
- projectId,
619
- from: doc.from,
620
- to: doc.to,
621
- permanent: doc.permanent,
622
- enabled: doc.enabled,
623
- ...(doc.meta !== undefined ? { meta: doc.meta } : {}),
624
- createdAt: doc.createdAt,
625
- updatedAt: doc.updatedAt,
626
- };
627
- }
628
615
  /**
629
616
  * Convex-backed {@link RedirectRepository} (EC-303) — editorial redirects as data
630
617
  * (not config). Content-gated CRUD over the `redirects` table; the studio's
631
- * editorial surface + the delivery snapshot both read through here. The editorial
632
- * surface sends a full record on save, so create-defaults (permanent/enabled) also
633
- * cover edits.
618
+ * editorial surface + the delivery snapshot both read through here. A save sends
619
+ * the write as written (EC-577): the create defaults live in the record schema and
620
+ * apply inside the handler's transaction, only when the save creates the redirect.
634
621
  */
635
622
  class ConvexRedirectRepository {
636
623
  client;
@@ -641,18 +628,19 @@ class ConvexRedirectRepository {
641
628
  }
642
629
  async saveRedirect(projectId, input) {
643
630
  const now = this.clock();
644
- const id = input.id ?? newId('redirect');
645
- const doc = (await this.client.mutation(mutationRef('redirects:save'), {
631
+ const { id: givenId, ...write } = input;
632
+ const id = givenId ?? newId('redirect');
633
+ const doc = (await this.client
634
+ .mutation(mutationRef('redirects:save'), {
646
635
  redirectId: id,
647
- from: input.from,
648
- to: input.to,
649
- permanent: input.permanent ?? true,
650
- enabled: input.enabled ?? true,
651
- ...(input.meta !== undefined ? { meta: input.meta } : {}),
636
+ ...presentWriteKeys(write),
652
637
  createdAt: now,
653
638
  updatedAt: now,
639
+ })
640
+ .catch((error) => {
641
+ throw asRailWriteError(error);
654
642
  }));
655
- return redirectEntryFromDoc(doc, projectId);
643
+ return redirectEntryFromRow(doc, projectId);
656
644
  }
657
645
  async getRedirect(projectId, id) {
658
646
  const found = await this.findRedirect(projectId, id);
@@ -664,12 +652,12 @@ class ConvexRedirectRepository {
664
652
  const doc = (await this.client.query(queryRef('redirects:get'), {
665
653
  redirectId: id,
666
654
  }));
667
- return doc ? redirectEntryFromDoc(doc, projectId) : undefined;
655
+ return doc ? redirectEntryFromRow(doc, projectId) : undefined;
668
656
  }
669
657
  async listRedirects(projectId) {
670
658
  const docs = (await this.client.query(queryRef('redirects:list'), {}));
671
659
  return docs
672
- .map((doc) => redirectEntryFromDoc(doc, projectId))
660
+ .map((doc) => redirectEntryFromRow(doc, projectId))
673
661
  .sort((a, b) => (a.from < b.from ? -1 : a.from > b.from ? 1 : 0));
674
662
  }
675
663
  async removeRedirect(projectId, id) {
@@ -1 +1 @@
1
- {"version":3,"file":"convex-adapter.js","sourceRoot":"","sources":["../../../src/lib/persistence/convex-adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAEtE,OAAO,EACL,mBAAmB,EACnB,0BAA0B,EAC1B,uBAAuB,EACvB,WAAW,EACX,WAAW,EACX,sBAAsB,GACvB,MAAM,6BAA6B,CAAA;AAwCpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AA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AAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA;QACxD,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,KAA6B;QACpC,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAA;IACtC,CAAC;CACF","sourcesContent":["import type { ConvexHttpClient } from 'convex/browser'\nimport { documentKey, documentSchema } from '@elytracms/core/cms-core'\nimport type { CmsDocument, CollectionDef, DocumentRef } from '@elytracms/core/cms-core'\nimport {\n RecordNotFoundError,\n PersistenceValidationError,\n compareReferenceEntries,\n highestRole,\n isKnownRole,\n validateForPersistence,\n} from '@elytracms/core/persistence'\nimport type {\n AssetRecord,\n AssetRepository,\n BackendStatus,\n BackendValidationInput,\n BackendValidationResult,\n BlobStorageAdapter,\n CmsRepository,\n DeliveryConfigStatus,\n DeliveryRepository,\n CmsSchemaRecord,\n CmsDocumentRecord,\n DocumentVersionRecord,\n SaveDocumentVersionOptions,\n MembersRepository,\n NewAssetInput,\n PersistenceAdapter,\n OutboundReference,\n ProjectMemberRecord,\n ProjectRole,\n ReferenceEntry,\n ReferenceEntryRecord,\n ReferenceIndexBuildMarker,\n ReferenceIndexRepository,\n ReferenceLookupOptions,\n ReferenceSource,\n ReferenceSourceType,\n ReferenceTarget,\n ReferenceVariant,\n RedirectEntry,\n RedirectRepository,\n SaveRedirectInput,\n SaveUserInput,\n UserRecord,\n UserRepository,\n InviteRecord,\n InviteRepository,\n SaveInviteInput,\n} from '@elytracms/core/persistence'\nimport { normalizeInviteEmail } from '@elytracms/core/persistence'\nimport { queryRef, mutationRef } from './convex-client'\nimport { ConvexBlobStorage } from './convex-blob-storage'\n\n/** Wall-clock for runtime writes (deterministic seeds use a fixed clock instead). */\ntype Clock = () => string\nconst realClock: Clock = () => new Date().toISOString()\n\nfunction newId(prefix: string): string {\n const rand =\n typeof globalThis.crypto?.randomUUID === 'function'\n ? globalThis.crypto.randomUUID()\n : Math.abs(Date.parse(new Date().toISOString())).toString(36)\n return `${prefix}_${rand}`\n}\n\n// --- CMS, Assets ----------------------------------------------------------\n\n/**\n * Deterministic, config-owned schema timestamps (EC-183). CMS collections live\n * in `elytra.config.ts`, not the backend, so the synthesized `CmsSchemaRecord`\n * carries a stable placeholder rather than DB-row timestamps.\n */\nconst CONFIG_SCHEMA_TIMESTAMP = '2026-01-01T00:00:00.000Z'\n\ninterface DocumentDoc {\n projectId: string\n document: CmsDocument\n publishedVersion?: number\n /** EC-447: the first-publish instant (set-once on publish, cleared on unpublish). */\n publishedAt?: string\n /** EC-449: the materialized \"draft differs from the pinned published snapshot\" flag. */\n hasUnpublishedChanges?: boolean\n createdAt: string\n updatedAt: string\n}\nfunction docRecordFromDoc(doc: DocumentDoc): CmsDocumentRecord {\n return {\n projectId: doc.projectId,\n document: doc.document,\n ...(doc.publishedVersion !== undefined ? { publishedVersion: doc.publishedVersion } : {}),\n // EC-447: carry the materialized publish instant onto the contract record so the\n // studio's $publishedAt column + its reconcile read the authoritative value.\n ...(doc.publishedAt !== undefined ? { publishedAt: doc.publishedAt } : {}),\n // EC-449: carry the materialized changed flag so hydration + the store's\n // save/publish/unpublish reconciles read the authoritative verdict.\n ...(doc.hasUnpublishedChanges !== undefined\n ? { hasUnpublishedChanges: doc.hasUnpublishedChanges }\n : {}),\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n}\n\ninterface VersionDoc {\n collection: string\n docId: string\n version: number\n snapshot: CmsDocument\n label?: string\n origin?: string\n createdAt: string\n}\n/** The backend row carries no `projectId` (single-tenant); stamp it from the call. */\nfunction versionRecordFromDoc(doc: VersionDoc, projectId: string): DocumentVersionRecord {\n return {\n projectId,\n collection: doc.collection,\n docId: doc.docId,\n version: doc.version,\n snapshot: doc.snapshot,\n createdAt: doc.createdAt,\n ...(doc.label ? { label: doc.label } : {}),\n ...(doc.origin ? { origin: doc.origin } : {}),\n }\n}\n\nclass ConvexCmsRepository implements CmsRepository {\n /**\n * @param collections the active project's config-owned CMS collections\n * (EC-183, AD-11), injected from `elytra.config.ts`. The Convex backend has\n * no `cmsSchemas` table — `findSchema`/`getSchema` serve these instead.\n */\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly collections: readonly CollectionDef[] = [],\n private readonly clock: Clock = realClock,\n ) {}\n\n async saveSchema(\n _projectId: string,\n _collections: readonly CollectionDef[],\n ): Promise<CmsSchemaRecord> {\n // Read-only (EC-183, AD-11): the CMS collection schema is owned by\n // `elytra.config.ts`; the backend stores documents only. A write here is a\n // visible, structured error rather than a silent no-op (the studio's CMS\n // schema surfaces are read-only; legitimate writers were removed in EC-183).\n throw new PersistenceValidationError(\n 'CMS collection schema is owned by elytra.config.ts and cannot be written to the backend.',\n [\n {\n code: 'schema-config-owned',\n message:\n 'Edit elytra.config.ts to change collections; the backend stores documents only.',\n path: [],\n domain: 'cms',\n },\n ],\n )\n }\n\n /** Config-owned schema (EC-183): the active project's collections from config. */\n private configSchema(projectId: string): CmsSchemaRecord {\n return {\n projectId,\n collections: [...this.collections],\n createdAt: CONFIG_SCHEMA_TIMESTAMP,\n updatedAt: CONFIG_SCHEMA_TIMESTAMP,\n }\n }\n\n async getSchema(projectId: string): Promise<CmsSchemaRecord> {\n return this.configSchema(projectId)\n }\n\n async findSchema(projectId: string): Promise<CmsSchemaRecord | undefined> {\n return this.configSchema(projectId)\n }\n\n async upsertDocument(projectId: string, document: CmsDocument): Promise<CmsDocumentRecord> {\n // The backend is a pure document store (EC-183, AD-11): collection-membership\n // validation lives in `@elytracms/core/cms-core` `validateDocument`, which the studio\n // runs pre-dispatch (cell edits, imports). We still parse the canonical\n // document shape so malformed blobs never reach storage.\n const parsedDoc = documentSchema.parse(document)\n const now = this.clock()\n const doc = (await this.client.mutation(mutationRef('cms:upsertDocument'), {\n collection: parsedDoc.collection,\n docId: parsedDoc.id,\n document: parsedDoc,\n createdAt: now,\n updatedAt: now,\n })) as DocumentDoc\n return docRecordFromDoc(doc)\n }\n\n async getDocument(projectId: string, ref: DocumentRef): Promise<CmsDocumentRecord> {\n const found = await this.findDocument(projectId, ref)\n if (!found)\n throw new RecordNotFoundError('cms-document', `${projectId}/${ref.collection}:${ref.id}`)\n return found\n }\n\n async findDocument(projectId: string, ref: DocumentRef): Promise<CmsDocumentRecord | undefined> {\n const doc = (await this.client.query(queryRef('cms:getDocument'), {\n collection: ref.collection,\n docId: ref.id,\n })) as DocumentDoc | null\n return doc ? docRecordFromDoc(doc) : undefined\n }\n\n async listDocuments(projectId: string, collection?: string): Promise<CmsDocumentRecord[]> {\n const docs = (await this.client.query(queryRef('cms:listDocuments'), {\n ...(collection ? { collection } : {}),\n })) as DocumentDoc[]\n // EC-153 parity: deterministic document-key ordering (Convex index order\n // within a project is insertion order, so we sort client-side).\n return docs\n .map(docRecordFromDoc)\n .sort((a, b) => (documentKey(a.document) < documentKey(b.document) ? -1 : 1))\n }\n\n async listPublishedDocuments(projectId: string, collection?: string): Promise<CmsDocument[]> {\n // EC-307: one bulk read for the published pool (collapses the per-document\n // `listVersions` fan-out). The handler resolves each pin to its snapshot.\n const snapshots = (await this.client.query(queryRef('cms:listPublishedDocuments'), {\n ...(collection ? { collection } : {}),\n })) as CmsDocument[]\n // Deterministic document-key order (parity with the in-memory adapter).\n return snapshots\n .map((doc) => documentSchema.parse(doc))\n .sort((a, b) => (documentKey(a) < documentKey(b) ? -1 : 1))\n }\n\n async deleteDocument(projectId: string, ref: DocumentRef): Promise<void> {\n // EC-153 parity: deleting a missing document is not-found, never a no-op.\n await this.getDocument(projectId, ref)\n await this.client.mutation(mutationRef('cms:deleteDocument'), {\n collection: ref.collection,\n docId: ref.id,\n })\n }\n\n async saveDocumentVersion(\n projectId: string,\n snapshot: CmsDocument,\n options: SaveDocumentVersionOptions = {},\n ): Promise<DocumentVersionRecord> {\n const parsed = documentSchema.parse(snapshot)\n const doc = (await this.client.mutation(mutationRef('cms:saveDocumentVersion'), {\n collection: parsed.collection,\n docId: parsed.id,\n snapshot: parsed,\n createdAt: this.clock(),\n ...(options.label ? { label: options.label } : {}),\n ...(options.origin ? { origin: options.origin } : {}),\n })) as VersionDoc\n return versionRecordFromDoc(doc, projectId)\n }\n\n async listDocumentVersions(\n projectId: string,\n ref: DocumentRef,\n ): Promise<DocumentVersionRecord[]> {\n const docs = (await this.client.query(queryRef('cms:listDocumentVersions'), {\n collection: ref.collection,\n docId: ref.id,\n })) as VersionDoc[]\n return docs.map((doc) => versionRecordFromDoc(doc, projectId))\n }\n\n async listAllDocumentVersions(projectId: string): Promise<DocumentVersionRecord[]> {\n const docs = (await this.client.query(\n queryRef('cms:listAllDocumentVersions'),\n {},\n )) as VersionDoc[]\n return docs.map((doc) => versionRecordFromDoc(doc, projectId))\n }\n\n async getDocumentVersion(\n projectId: string,\n ref: DocumentRef,\n version: number,\n ): Promise<DocumentVersionRecord> {\n const doc = (await this.client.query(queryRef('cms:getDocumentVersion'), {\n collection: ref.collection,\n docId: ref.id,\n version,\n })) as VersionDoc | null\n if (!doc) {\n throw new RecordNotFoundError(\n 'cms-document-version',\n `${projectId}/${ref.collection}:${ref.id}#${version}`,\n )\n }\n return versionRecordFromDoc(doc, projectId)\n }\n\n async publishDocumentVersion(\n projectId: string,\n ref: DocumentRef,\n version: number,\n ): Promise<CmsDocumentRecord> {\n // Taxonomy enforced adapter-side (the handler is lenient): the document and\n // the pinned version must both exist (each throws RecordNotFoundError).\n await this.getDocument(projectId, ref)\n await this.getDocumentVersion(projectId, ref, version)\n // EC-447: pass a fresh publish-action instant as the SET-ONCE candidate (the\n // handler writes it only when the row has no `publishedAt` yet). One `now` for\n // both stamps — this IS the publish moment.\n const now = this.clock()\n const doc = (await this.client.mutation(mutationRef('cms:publishDocumentVersion'), {\n collection: ref.collection,\n docId: ref.id,\n version,\n updatedAt: now,\n publishedAt: now,\n })) as DocumentDoc\n return docRecordFromDoc(doc)\n }\n\n async unpublishDocument(projectId: string, ref: DocumentRef): Promise<CmsDocumentRecord> {\n const existing = await this.getDocument(projectId, ref)\n if (existing.publishedVersion === undefined) {\n throw new PersistenceValidationError('Document is not currently published.', [\n {\n code: 'invalid-transition',\n message: 'Cannot unpublish: the document has no published version.',\n domain: 'cms',\n },\n ])\n }\n const doc = (await this.client.mutation(mutationRef('cms:unpublishDocument'), {\n collection: ref.collection,\n docId: ref.id,\n updatedAt: this.clock(),\n })) as DocumentDoc\n return docRecordFromDoc(doc)\n }\n}\n\ninterface AssetDoc {\n projectId: string\n assetId: string\n filename: string\n contentType: string\n byteSize: number\n width?: number\n height?: number\n alt?: string\n /** Editable display title (EC-152). */\n title?: string\n storageKey: string\n url?: string\n /** Normalized image focal point `{ x, y }` in 0–1 (EC-230). */\n focalPoint?: { x: number; y: number }\n /** Downscaled editorial preview variant (EC-400). */\n thumb?: { storageKey: string; url: string; width: number; height: number }\n /** Delivery LQIP blur-placeholder data URI (EC-420). */\n lqip?: string\n /** Schema-driven asset metadata bag (EC-301). */\n meta?: Record<string, unknown>\n createdAt: string\n updatedAt: string\n}\n\n/** Map a Convex asset doc onto the contract record (assetId → id, drop _id/_creationTime). */\nfunction assetRecordFromDoc(doc: AssetDoc): AssetRecord {\n return {\n id: doc.assetId,\n projectId: doc.projectId,\n filename: doc.filename,\n contentType: doc.contentType,\n byteSize: doc.byteSize,\n ...(doc.width !== undefined ? { width: doc.width } : {}),\n ...(doc.height !== undefined ? { height: doc.height } : {}),\n ...(doc.alt !== undefined ? { alt: doc.alt } : {}),\n ...(doc.title !== undefined ? { title: doc.title } : {}),\n ...(doc.url !== undefined ? { url: doc.url } : {}),\n ...(doc.focalPoint !== undefined ? { focalPoint: doc.focalPoint } : {}),\n ...(doc.thumb !== undefined ? { thumb: doc.thumb } : {}),\n ...(doc.lqip !== undefined ? { lqip: doc.lqip } : {}),\n ...(doc.meta !== undefined ? { meta: doc.meta } : {}),\n storageKey: doc.storageKey,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n}\n\nclass ConvexAssetRepository implements AssetRepository {\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly clock: Clock = realClock,\n ) {}\n\n async upsertAsset(projectId: string, input: NewAssetInput): Promise<AssetRecord> {\n const now = this.clock()\n const id = input.id ?? newId('asset')\n const doc = (await this.client.mutation(mutationRef('assets:upsert'), {\n assetId: id,\n filename: input.filename,\n contentType: input.contentType,\n byteSize: input.byteSize,\n ...(input.width !== undefined ? { width: input.width } : {}),\n ...(input.height !== undefined ? { height: input.height } : {}),\n ...(input.alt !== undefined ? { alt: input.alt } : {}),\n // EC-153 parity: `title` (EC-152 metadata) must persist, not silently drop.\n ...(input.title !== undefined ? { title: input.title } : {}),\n ...(input.url !== undefined ? { url: input.url } : {}),\n ...(input.focalPoint !== undefined ? { focalPoint: input.focalPoint } : {}),\n ...(input.thumb !== undefined ? { thumb: input.thumb } : {}),\n ...(input.lqip !== undefined ? { lqip: input.lqip } : {}),\n ...(input.meta !== undefined ? { meta: input.meta } : {}),\n storageKey: input.storageKey ?? `${projectId}/${id}`,\n createdAt: now,\n updatedAt: now,\n })) as AssetDoc\n return assetRecordFromDoc(doc)\n }\n\n async getAsset(projectId: string, id: string): Promise<AssetRecord> {\n const found = await this.findAsset(projectId, id)\n if (!found) throw new RecordNotFoundError('asset', `${projectId}/${id}`)\n return found\n }\n\n async findAsset(projectId: string, id: string): Promise<AssetRecord | undefined> {\n const doc = (await this.client.query(queryRef('assets:get'), {\n assetId: id,\n })) as AssetDoc | null\n return doc ? assetRecordFromDoc(doc) : undefined\n }\n\n async listAssets(_projectId: string): Promise<AssetRecord[]> {\n const docs = (await this.client.query(queryRef('assets:list'), {})) as AssetDoc[]\n return docs.map(assetRecordFromDoc)\n }\n\n async removeAsset(projectId: string, id: string): Promise<void> {\n // EC-153 parity: removing an unknown asset is not-found, never a no-op.\n await this.getAsset(projectId, id)\n await this.client.mutation(mutationRef('assets:remove'), { assetId: id })\n }\n\n async resolveMany(projectId: string, ids: readonly string[]): Promise<Map<string, AssetRecord>> {\n const all = await this.listAssets(projectId)\n const out = new Map<string, AssetRecord>()\n for (const asset of all) if (ids.includes(asset.id)) out.set(asset.id, asset)\n return out\n }\n}\n\n// --- Reference index (EC-155) ------------------------------------------------\n\n/** A Convex reference-entry doc (flattened source/target for index-backed lookups). */\ninterface ReferenceEntryDoc {\n projectId: string\n variant: ReferenceVariant\n sourceType: ReferenceSourceType\n sourceId: string\n path: string\n targetType: ReferenceTarget['type']\n targetId: string\n kind: ReferenceEntryRecord['kind']\n}\n\nfunction referenceRecordFromDoc(doc: ReferenceEntryDoc): ReferenceEntryRecord {\n return {\n projectId: doc.projectId,\n variant: doc.variant,\n source: { type: doc.sourceType, id: doc.sourceId },\n path: doc.path,\n target: { type: doc.targetType, id: doc.targetId },\n kind: doc.kind,\n }\n}\n\n/** Deterministic ordering is a repository contract; Convex docs sort client-side. */\nfunction sortedReferenceRecords(docs: ReferenceEntryDoc[]): ReferenceEntryRecord[] {\n return docs.map(referenceRecordFromDoc).sort(compareReferenceEntries)\n}\n\nclass ConvexReferenceIndexRepository implements ReferenceIndexRepository {\n constructor(private readonly client: ConvexHttpClient) {}\n\n async replaceForSource(\n projectId: string,\n variant: ReferenceVariant,\n source: ReferenceSource,\n references: readonly OutboundReference[],\n ): Promise<ReferenceEntryRecord[]> {\n await this.client.mutation(mutationRef('references:replaceForSource'), {\n variant,\n sourceType: source.type,\n sourceId: source.id,\n references: references.map((r) => ({\n path: r.path,\n targetType: r.target.type,\n targetId: r.target.id,\n kind: r.kind,\n })),\n })\n return this.outbound(projectId, source, { variant })\n }\n\n async replaceForSourceTypes(\n projectId: string,\n variant: ReferenceVariant,\n sourceTypes: readonly ReferenceSourceType[],\n entries: readonly ReferenceEntry[],\n ): Promise<ReferenceEntryRecord[]> {\n await this.client.mutation(mutationRef('references:replaceForSourceTypes'), {\n variant,\n sourceTypes: [...sourceTypes],\n entries: entries.map((e) => ({\n sourceType: e.source.type,\n sourceId: e.source.id,\n path: e.path,\n targetType: e.target.type,\n targetId: e.target.id,\n kind: e.kind,\n })),\n })\n const all = await this.listEntries(projectId, variant)\n const types = new Set(sourceTypes)\n return all.filter((record) => types.has(record.source.type))\n }\n\n async removeForSource(\n projectId: string,\n source: ReferenceSource,\n variant?: ReferenceVariant,\n ): Promise<void> {\n await this.client.mutation(mutationRef('references:removeForSource'), {\n sourceType: source.type,\n sourceId: source.id,\n ...(variant ? { variant } : {}),\n })\n }\n\n async outbound(\n projectId: string,\n source: ReferenceSource,\n options: ReferenceLookupOptions = {},\n ): Promise<ReferenceEntryRecord[]> {\n const docs = (await this.client.query(queryRef('references:outbound'), {\n sourceType: source.type,\n sourceId: source.id,\n ...(options.variant ? { variant: options.variant } : {}),\n })) as ReferenceEntryDoc[]\n return sortedReferenceRecords(docs)\n }\n\n async inbound(\n projectId: string,\n target: ReferenceTarget,\n options: ReferenceLookupOptions = {},\n ): Promise<ReferenceEntryRecord[]> {\n const docs = (await this.client.query(queryRef('references:inbound'), {\n targetType: target.type,\n targetId: target.id,\n ...(options.variant ? { variant: options.variant } : {}),\n })) as ReferenceEntryDoc[]\n return sortedReferenceRecords(docs)\n }\n\n async inboundMany(\n projectId: string,\n targets: readonly ReferenceTarget[],\n options: ReferenceLookupOptions = {},\n ): Promise<ReferenceEntryRecord[][]> {\n // EC-308: one round-trip for all targets (the handler loops the by_target\n // index server-side), replacing the client's per-target inbound fan-out.\n if (targets.length === 0) return []\n const groups = (await this.client.query(queryRef('references:inboundMany'), {\n targets: targets.map((target) => ({ targetType: target.type, targetId: target.id })),\n ...(options.variant ? { variant: options.variant } : {}),\n })) as ReferenceEntryDoc[][]\n return groups.map((docs) => sortedReferenceRecords(docs))\n }\n\n async listEntries(\n projectId: string,\n variant?: ReferenceVariant,\n ): Promise<ReferenceEntryRecord[]> {\n const docs = (await this.client.query(queryRef('references:list'), {\n ...(variant ? { variant } : {}),\n })) as ReferenceEntryDoc[]\n return sortedReferenceRecords(docs)\n }\n\n async getBuildMarker(_projectId: string): Promise<ReferenceIndexBuildMarker | null> {\n return (await this.client.query(queryRef('references:buildMarker'), {})) as\n | ReferenceIndexBuildMarker\n | null\n }\n\n async setBuildMarker(projectId: string, marker: ReferenceIndexBuildMarker): Promise<void> {\n await this.client.mutation(mutationRef('references:setBuildMarker'), {\n entryCount: marker.entryCount,\n })\n }\n\n async clearProject(_projectId: string): Promise<void> {\n await this.client.mutation(mutationRef('references:clearProject'), {})\n }\n}\n\n// --- Members + CLI tokens (EC-150) -------------------------------------------\n\ninterface MemberDoc {\n userId: string\n role: ProjectRole\n createdAt: string\n updatedAt: string\n}\n\n/**\n * Single-tenant (EC-179): membership is deployment-scoped, so the backend rows\n * carry no `projectId`. The contract record still does — this adapter is bound\n * to its deployment's project, so it stamps that slug onto every record.\n */\nfunction memberRecordFromDoc(doc: MemberDoc, projectId: string): ProjectMemberRecord {\n return {\n projectId,\n userId: doc.userId,\n role: doc.role,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n}\n\nclass ConvexMembersRepository implements MembersRepository {\n constructor(\n private readonly client: ConvexHttpClient,\n /** The slug of this deployment's one project — stamped onto records. */\n private readonly boundProjectId: string,\n private readonly clock: Clock = realClock,\n ) {}\n\n async setMember(\n projectId: string,\n userId: string,\n role: ProjectRole,\n ): Promise<ProjectMemberRecord> {\n const now = this.clock()\n const doc = (await this.client.mutation(mutationRef('members:set'), {\n userId,\n role,\n createdAt: now,\n updatedAt: now,\n })) as MemberDoc\n return memberRecordFromDoc(doc, projectId)\n }\n\n async findMember(projectId: string, userId: string): Promise<ProjectMemberRecord | undefined> {\n const doc = (await this.client.query(queryRef('members:get'), {\n userId,\n })) as MemberDoc | null\n return doc ? memberRecordFromDoc(doc, projectId) : undefined\n }\n\n async listMembers(projectId: string): Promise<ProjectMemberRecord[]> {\n const docs = (await this.client.query(queryRef('members:list'), {})) as MemberDoc[]\n return docs.map((d) => memberRecordFromDoc(d, projectId))\n }\n\n async listMembershipsForUser(userId: string): Promise<ProjectMemberRecord[]> {\n // `members:mine` is caller-scoped server-side and returns the caller's single\n // deployment membership (or null). The studio only ever asks about the\n // session user; records are stamped with this deployment's bound project.\n const doc = (await this.client.query(queryRef('members:mine'), {})) as MemberDoc | null\n return doc && doc.userId === userId ? [memberRecordFromDoc(doc, this.boundProjectId)] : []\n }\n\n async removeMember(projectId: string, userId: string): Promise<void> {\n try {\n await this.client.mutation(mutationRef('members:remove'), { userId })\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n if (/not-found/i.test(message)) {\n throw new RecordNotFoundError('project-member', `${projectId}/${userId}`)\n }\n throw error\n }\n }\n}\n\n// --- Users rail (EC-240, 240a) -----------------------------------------------\n\n/** The wire shape returned by the `users:list`/`users:get` join handlers. */\ninterface UserDoc {\n id: string\n email: string\n name?: string\n avatar?: string\n role: ProjectRole\n meta?: Record<string, unknown>\n createdAt: string\n updatedAt: string\n}\n\n/** Map a joined user doc onto the contract record; stamp the bound project. */\nfunction userRecordFromDoc(doc: UserDoc, projectId: string): UserRecord {\n return {\n id: doc.id,\n projectId,\n email: doc.email,\n ...(doc.name !== undefined ? { name: doc.name } : {}),\n ...(doc.avatar !== undefined ? { avatar: doc.avatar } : {}),\n // 240a bridge: the single `members.role` column ⇒ the 240c-ready `roles[]`.\n roles: [doc.role],\n ...(doc.meta !== undefined ? { meta: doc.meta } : {}),\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n}\n\n/**\n * Collapse the 240c-ready `roles[]` to the single `members.role` column by\n * applying the strongest role (the 240a→240c enforcement bridge). Unknown\n * strings are ignored; an empty/unknown set floors to `viewer`.\n */\nfunction strongestRole(roles: readonly string[]): ProjectRole {\n // Validate against the active role policy (EC-240c) rather than a hardcoded\n // enum, then take the canonical rank max; floor an empty/unknown set to `viewer`.\n const valid = roles.filter((r) => isKnownRole(r))\n return highestRole(valid) ?? 'viewer'\n}\n\n/**\n * Convex-backed {@link UserRepository} (EC-240, 240a). Reads are the admin-gated\n * `users:*` **join** handlers (members row + auth identity); the role write\n * reuses the member write path (`members:set`, extended with the `meta` bag) so\n * there is one source for role writes — 240c collapses enforcement onto it.\n */\nclass ConvexUserRepository implements UserRepository {\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly clock: Clock = realClock,\n ) {}\n\n async listUsers(projectId: string): Promise<UserRecord[]> {\n const docs = (await this.client.query(queryRef('users:list'), {})) as UserDoc[]\n return docs.map((doc) => userRecordFromDoc(doc, projectId))\n }\n\n async findUser(projectId: string, id: string): Promise<UserRecord | undefined> {\n const doc = (await this.client.query(queryRef('users:get'), { userId: id })) as UserDoc | null\n return doc ? userRecordFromDoc(doc, projectId) : undefined\n }\n\n async getUser(projectId: string, id: string): Promise<UserRecord> {\n const found = await this.findUser(projectId, id)\n if (!found) throw new RecordNotFoundError('user', `${projectId}/${id}`)\n return found\n }\n\n async getSelf(projectId: string): Promise<UserRecord | null> {\n // Self-permitted (EC-240 H-tail item 1): `users:getSelf` derives the caller\n // from the JWT server-side and returns ONLY their own join — never widened to\n // the admin-only `users:get`. The `selfId` the contract passes is ignored here;\n // the trust boundary is the server.\n const doc = (await this.client.query(queryRef('users:getSelf'), {})) as UserDoc | null\n return doc ? userRecordFromDoc(doc, projectId) : null\n }\n\n async saveUser(projectId: string, input: SaveUserInput): Promise<UserRecord> {\n const now = this.clock()\n await this.client.mutation(mutationRef('members:set'), {\n userId: input.id,\n role: strongestRole(input.roles),\n ...(input.meta !== undefined ? { meta: input.meta } : {}),\n createdAt: now,\n updatedAt: now,\n })\n // Return the full joined projection (identity + role + custom fields).\n return this.getUser(projectId, input.id)\n }\n\n async removeUser(projectId: string, id: string): Promise<void> {\n try {\n await this.client.mutation(mutationRef('members:remove'), { userId: id })\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n if (/not-found/i.test(message)) {\n throw new RecordNotFoundError('user', `${projectId}/${id}`)\n }\n throw error\n }\n }\n}\n\n// --- Invite allowlist rail (EC-324) ------------------------------------------\n\n/** The wire shape returned by the `invites:*` handlers. */\ninterface InviteDoc {\n email: string\n role: string\n invitedBy?: string\n createdAt: string\n updatedAt: string\n}\n\nfunction inviteRecordFromDoc(doc: InviteDoc): InviteRecord {\n return {\n email: doc.email,\n role: doc.role,\n ...(doc.invitedBy !== undefined ? { invitedBy: doc.invitedBy } : {}),\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n}\n\n/**\n * Convex-backed {@link InviteRepository} (EC-324). Admin-gated `invites:*`\n * handlers; the repo supplies timestamps (mirroring `ConvexUserRepository`). The\n * Convex auth boundary reads the same table in `beforeSessionCreation` to gate\n * open sign-up + grant the invited role.\n */\nclass ConvexInviteRepository implements InviteRepository {\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly clock: Clock = realClock,\n ) {}\n\n async listInvites(_projectId: string): Promise<InviteRecord[]> {\n const docs = (await this.client.query(queryRef('invites:list'), {})) as InviteDoc[]\n return docs.map(inviteRecordFromDoc)\n }\n\n async findInvite(projectId: string, email: string): Promise<InviteRecord | undefined> {\n const key = normalizeInviteEmail(email)\n const all = await this.listInvites(projectId)\n return all.find((invite) => invite.email === key)\n }\n\n async saveInvite(_projectId: string, input: SaveInviteInput): Promise<InviteRecord> {\n const now = this.clock()\n const doc = (await this.client.mutation(mutationRef('invites:create'), {\n email: normalizeInviteEmail(input.email),\n role: input.role,\n ...(input.invitedBy !== undefined ? { invitedBy: input.invitedBy } : {}),\n createdAt: now,\n updatedAt: now,\n })) as InviteDoc\n return inviteRecordFromDoc(doc)\n }\n\n async removeInvite(projectId: string, email: string): Promise<void> {\n try {\n await this.client.mutation(mutationRef('invites:revoke'), {\n email: normalizeInviteEmail(email),\n })\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n if (/not-found/i.test(message)) {\n throw new RecordNotFoundError('invite', `${projectId}/${normalizeInviteEmail(email)}`)\n }\n throw error\n }\n }\n}\n\n/** The `redirects` table row shape (EC-303). Single-tenant: no `projectId` column. */\ninterface RedirectDoc {\n redirectId: string\n from: string\n to: string\n permanent: boolean\n enabled: boolean\n /** Schema-driven additive-field bag (EC-311 Tier 2). */\n meta?: Record<string, unknown>\n createdAt: string\n updatedAt: string\n}\n\nfunction redirectEntryFromDoc(doc: RedirectDoc, projectId: string): RedirectEntry {\n return {\n id: doc.redirectId,\n projectId,\n from: doc.from,\n to: doc.to,\n permanent: doc.permanent,\n enabled: doc.enabled,\n ...(doc.meta !== undefined ? { meta: doc.meta } : {}),\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n}\n\n/**\n * Convex-backed {@link RedirectRepository} (EC-303) — editorial redirects as data\n * (not config). Content-gated CRUD over the `redirects` table; the studio's\n * editorial surface + the delivery snapshot both read through here. The editorial\n * surface sends a full record on save, so create-defaults (permanent/enabled) also\n * cover edits.\n */\nclass ConvexRedirectRepository implements RedirectRepository {\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly clock: Clock = realClock,\n ) {}\n\n async saveRedirect(projectId: string, input: SaveRedirectInput): Promise<RedirectEntry> {\n const now = this.clock()\n const id = input.id ?? newId('redirect')\n const doc = (await this.client.mutation(mutationRef('redirects:save'), {\n redirectId: id,\n from: input.from,\n to: input.to,\n permanent: input.permanent ?? true,\n enabled: input.enabled ?? true,\n ...(input.meta !== undefined ? { meta: input.meta } : {}),\n createdAt: now,\n updatedAt: now,\n })) as RedirectDoc\n return redirectEntryFromDoc(doc, projectId)\n }\n\n async getRedirect(projectId: string, id: string): Promise<RedirectEntry> {\n const found = await this.findRedirect(projectId, id)\n if (!found) throw new RecordNotFoundError('redirect', `${projectId}/${id}`)\n return found\n }\n\n async findRedirect(projectId: string, id: string): Promise<RedirectEntry | undefined> {\n const doc = (await this.client.query(queryRef('redirects:get'), {\n redirectId: id,\n })) as RedirectDoc | null\n return doc ? redirectEntryFromDoc(doc, projectId) : undefined\n }\n\n async listRedirects(projectId: string): Promise<RedirectEntry[]> {\n const docs = (await this.client.query(queryRef('redirects:list'), {})) as RedirectDoc[]\n return docs\n .map((doc) => redirectEntryFromDoc(doc, projectId))\n .sort((a, b) => (a.from < b.from ? -1 : a.from > b.from ? 1 : 0))\n }\n\n async removeRedirect(projectId: string, id: string): Promise<void> {\n await this.getRedirect(projectId, id) // not-found parity with the in-memory rail\n await this.client.mutation(mutationRef('redirects:remove'), { redirectId: id })\n }\n}\n\n/**\n * Convex-backed {@link DeliveryRepository} (EC-268/EC-329) — reads the\n * deployment's actual instant-publish env var status via the guarded\n * `delivery:deliveryConfig` query. Replaces the studio's former direct\n * `getConvexClient(...).query('delivery:deliveryConfig')` call in\n * `delivery-health-banner.tsx`, the only place that used to bypass both the\n * operations chokepoint and the shared `useOperationQuery` cache (AD-17).\n */\nclass ConvexDeliveryRepository implements DeliveryRepository {\n constructor(private readonly client: ConvexHttpClient) {}\n\n async getConfig(): Promise<DeliveryConfigStatus> {\n return (await this.client.query(\n queryRef('delivery:deliveryConfig'),\n {},\n )) as DeliveryConfigStatus\n }\n}\n\n/**\n * Convex-backed {@link PersistenceAdapter} (brief §10, EC-039). Every repository\n * is implemented against the Convex functions in `apps/builder/convex/*`, mapping\n * results and failures onto the provider-neutral contracts + error taxonomies.\n */\nexport class ConvexPersistenceAdapter implements PersistenceAdapter {\n readonly cms: CmsRepository\n readonly assets: AssetRepository\n /** Reference index — outbound/inbound entries per variant (EC-155, AD-6). */\n readonly references: ReferenceIndexRepository\n /** Per-project membership roles (EC-150). */\n readonly members: MembersRepository\n readonly invites: InviteRepository\n /** Studio users rail — role + custom fields joined to auth identity (EC-240). */\n readonly users: UserRepository\n /** Editorial redirects rail — data-backed 301/302 forwards (EC-303). */\n readonly redirects: RedirectRepository\n /** Convex file storage behind the EC-133 blob boundary (EC-151). */\n readonly blobs: BlobStorageAdapter\n /** Delivery-pipeline (instant-publish) health, read-only (EC-268/EC-329). */\n readonly delivery: DeliveryRepository\n /**\n * EC-277: the Convex mutations maintain the reference index in-transaction\n * (`convex/referenceMaintenance.ts`), so every writer — studio, CLI, webhook,\n * raw `convex run` — is caught at the source. The studio bootstrap therefore does\n * NOT attach the client-side `attachReferenceIndex` subscriber for this provider.\n */\n readonly maintainsReferenceIndex = true\n\n /**\n * @param client the Convex client bound to this deployment (one project).\n * @param projectId the slug of this deployment's one project (EC-179). Used to\n * stamp deployment-scoped member records onto the still-project-keyed contract.\n * @param collections the active project's config-owned CMS collections (EC-183,\n * AD-11), from `elytra.config.ts`. The backend has no `cmsSchemas` table, so\n * the CMS repository serves the schema from these.\n */\n constructor(\n private readonly client: ConvexHttpClient,\n projectId: string,\n collections: readonly CollectionDef[] = [],\n ) {\n this.cms = new ConvexCmsRepository(client, collections)\n this.assets = new ConvexAssetRepository(client)\n this.references = new ConvexReferenceIndexRepository(client)\n this.members = new ConvexMembersRepository(client, projectId)\n this.users = new ConvexUserRepository(client)\n this.invites = new ConvexInviteRepository(client)\n this.redirects = new ConvexRedirectRepository(client)\n this.blobs = new ConvexBlobStorage(client)\n this.delivery = new ConvexDeliveryRepository(client)\n }\n\n async status(): Promise<BackendStatus> {\n try {\n // Lightweight connectivity probe (EC-182: no `projects` table). `members:mine`\n // takes no args and is soft-guarded (EC-279): it answers `null` for an\n // unauthenticated caller rather than throwing, so the pre-sign-in boot probe\n // resolves cleanly — backend answered ⇒ `available: true` — with no scary\n // `Uncaught Error` in the Convex log.\n await this.client.query(queryRef('members:mine'), {})\n return { backend: 'convex', available: true }\n } catch (error) {\n const detail = error instanceof Error ? error.message : String(error)\n // EC-153: an `unauthorized` rejection *is* a healthy backend — the\n // deployment answered and enforced auth. Now that `members:mine` is\n // soft-guarded this branch is a defensive fallback (a protected probe could\n // still throw); only transport/server failures count as unavailable, so the\n // DeploymentSetupGate surfaces those visibly instead of falling back to in-memory.\n if (/unauthorized/i.test(detail)) return { backend: 'convex', available: true }\n return { backend: 'convex', available: false, detail }\n }\n }\n\n validate(input: BackendValidationInput): BackendValidationResult {\n return validateForPersistence(input)\n }\n}\n"]}
1
+ {"version":3,"file":"convex-adapter.js","sourceRoot":"","sources":["../../../src/lib/persistence/convex-adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,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CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YACrE,mEAAmE;YACnE,oEAAoE;YACpE,4EAA4E;YAC5E,4EAA4E;YAC5E,mFAAmF;YACnF,IAAI,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC;gBAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;YAC/E,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA;QACxD,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,KAA6B;QACpC,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAA;IACtC,CAAC;CACF","sourcesContent":["import type { ConvexHttpClient } from 'convex/browser'\nimport { ConvexError } from 'convex/values'\nimport { documentKey, documentSchema } from '@elytracms/core/cms-core'\nimport type { CmsDocument, CollectionDef, DocumentRef } from '@elytracms/core/cms-core'\nimport {\n RecordNotFoundError,\n PersistenceValidationError,\n assetCreateDefaults,\n assetRecordFromRow,\n compareReferenceEntries,\n highestRole,\n isKnownRole,\n persistenceIssueSchema,\n presentWriteKeys,\n redirectEntryFromRow,\n validateForPersistence,\n} from '@elytracms/core/persistence'\nimport type {\n AssetRecord,\n AssetRepository,\n AssetRow,\n AssetWriteInput,\n BackendStatus,\n BackendValidationInput,\n BackendValidationResult,\n BlobStorageAdapter,\n CmsRepository,\n DeliveryConfigStatus,\n DeliveryRepository,\n CmsSchemaRecord,\n CmsDocumentRecord,\n DocumentVersionRecord,\n SaveDocumentVersionOptions,\n MembersRepository,\n PersistenceAdapter,\n OutboundReference,\n ProjectMemberRecord,\n ProjectRole,\n ReferenceEntry,\n ReferenceEntryRecord,\n ReferenceIndexBuildMarker,\n ReferenceIndexRepository,\n ReferenceLookupOptions,\n ReferenceSource,\n ReferenceSourceType,\n ReferenceTarget,\n ReferenceVariant,\n RedirectEntry,\n RedirectRepository,\n RedirectRow,\n SaveRedirectInput,\n SaveUserInput,\n UserRecord,\n UserRepository,\n InviteRecord,\n InviteRepository,\n SaveInviteInput,\n} from '@elytracms/core/persistence'\nimport { normalizeInviteEmail } from '@elytracms/core/persistence'\nimport { queryRef, mutationRef } from './convex-client'\nimport { ConvexBlobStorage } from './convex-blob-storage'\n\n/** Wall-clock for runtime writes (deterministic seeds use a fixed clock instead). */\ntype Clock = () => string\nconst realClock: Clock = () => new Date().toISOString()\n\nfunction newId(prefix: string): string {\n const rand =\n typeof globalThis.crypto?.randomUUID === 'function'\n ? globalThis.crypto.randomUUID()\n : Math.abs(Date.parse(new Date().toISOString())).toString(36)\n return `${prefix}_${rand}`\n}\n\n// --- CMS, Assets ----------------------------------------------------------\n\n/**\n * Deterministic, config-owned schema timestamps (EC-183). CMS collections live\n * in `elytra.config.ts`, not the backend, so the synthesized `CmsSchemaRecord`\n * carries a stable placeholder rather than DB-row timestamps.\n */\nconst CONFIG_SCHEMA_TIMESTAMP = '2026-01-01T00:00:00.000Z'\n\n/** The `cmsDocuments` row. Single-tenant: no `projectId` column (EC-179). */\ninterface DocumentDoc {\n document: CmsDocument\n publishedVersion?: number\n /** EC-447: the first-publish instant (set-once on publish, cleared on unpublish). */\n publishedAt?: string\n /** EC-449: the materialized \"draft differs from the pinned published snapshot\" flag. */\n hasUnpublishedChanges?: boolean\n createdAt: string\n updatedAt: string\n}\n/**\n * Row → contract record. `projectId` is the caller's (the row has none): before\n * EC-577 this copied the row's nonexistent `projectId`, so every connected\n * `CmsDocumentRecord.projectId` was `undefined` against a `min(1)` schema (MODE #6).\n */\nfunction docRecordFromDoc(doc: DocumentDoc, projectId: string): CmsDocumentRecord {\n return {\n projectId,\n document: doc.document,\n ...(doc.publishedVersion !== undefined ? { publishedVersion: doc.publishedVersion } : {}),\n // EC-447: carry the materialized publish instant onto the contract record so the\n // studio's $publishedAt column + its reconcile read the authoritative value.\n ...(doc.publishedAt !== undefined ? { publishedAt: doc.publishedAt } : {}),\n // EC-449: carry the materialized changed flag so hydration + the store's\n // save/publish/unpublish reconciles read the authoritative verdict.\n ...(doc.hasUnpublishedChanges !== undefined\n ? { hasUnpublishedChanges: doc.hasUnpublishedChanges }\n : {}),\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n}\n\ninterface VersionDoc {\n collection: string\n docId: string\n version: number\n snapshot: CmsDocument\n label?: string\n origin?: string\n createdAt: string\n}\n/** The backend row carries no `projectId` (single-tenant); stamp it from the call. */\nfunction versionRecordFromDoc(doc: VersionDoc, projectId: string): DocumentVersionRecord {\n return {\n projectId,\n collection: doc.collection,\n docId: doc.docId,\n version: doc.version,\n snapshot: doc.snapshot,\n createdAt: doc.createdAt,\n ...(doc.label ? { label: doc.label } : {}),\n ...(doc.origin ? { origin: doc.origin } : {}),\n }\n}\n\nclass ConvexCmsRepository implements CmsRepository {\n /**\n * @param collections the active project's config-owned CMS collections\n * (EC-183, AD-11), injected from `elytra.config.ts`. The Convex backend has\n * no `cmsSchemas` table — `findSchema`/`getSchema` serve these instead.\n */\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly collections: readonly CollectionDef[] = [],\n private readonly clock: Clock = realClock,\n ) {}\n\n async saveSchema(\n _projectId: string,\n _collections: readonly CollectionDef[],\n ): Promise<CmsSchemaRecord> {\n // Read-only (EC-183, AD-11): the CMS collection schema is owned by\n // `elytra.config.ts`; the backend stores documents only. A write here is a\n // visible, structured error rather than a silent no-op (the studio's CMS\n // schema surfaces are read-only; legitimate writers were removed in EC-183).\n throw new PersistenceValidationError(\n 'CMS collection schema is owned by elytra.config.ts and cannot be written to the backend.',\n [\n {\n code: 'schema-config-owned',\n message:\n 'Edit elytra.config.ts to change collections; the backend stores documents only.',\n path: [],\n domain: 'cms',\n },\n ],\n )\n }\n\n /** Config-owned schema (EC-183): the active project's collections from config. */\n private configSchema(projectId: string): CmsSchemaRecord {\n return {\n projectId,\n collections: [...this.collections],\n createdAt: CONFIG_SCHEMA_TIMESTAMP,\n updatedAt: CONFIG_SCHEMA_TIMESTAMP,\n }\n }\n\n async getSchema(projectId: string): Promise<CmsSchemaRecord> {\n return this.configSchema(projectId)\n }\n\n async findSchema(projectId: string): Promise<CmsSchemaRecord | undefined> {\n return this.configSchema(projectId)\n }\n\n async upsertDocument(projectId: string, document: CmsDocument): Promise<CmsDocumentRecord> {\n // The backend is a pure document store (EC-183, AD-11): collection-membership\n // validation lives in `@elytracms/core/cms-core` `validateDocument`, which the studio\n // runs pre-dispatch (cell edits, imports). We still parse the canonical\n // document shape so malformed blobs never reach storage.\n const parsedDoc = documentSchema.parse(document)\n const now = this.clock()\n const doc = (await this.client.mutation(mutationRef('cms:upsertDocument'), {\n collection: parsedDoc.collection,\n docId: parsedDoc.id,\n document: parsedDoc,\n createdAt: now,\n updatedAt: now,\n })) as DocumentDoc\n return docRecordFromDoc(doc, projectId)\n }\n\n async getDocument(projectId: string, ref: DocumentRef): Promise<CmsDocumentRecord> {\n const found = await this.findDocument(projectId, ref)\n if (!found)\n throw new RecordNotFoundError('cms-document', `${projectId}/${ref.collection}:${ref.id}`)\n return found\n }\n\n async findDocument(projectId: string, ref: DocumentRef): Promise<CmsDocumentRecord | undefined> {\n const doc = (await this.client.query(queryRef('cms:getDocument'), {\n collection: ref.collection,\n docId: ref.id,\n })) as DocumentDoc | null\n return doc ? docRecordFromDoc(doc, projectId) : undefined\n }\n\n async listDocuments(projectId: string, collection?: string): Promise<CmsDocumentRecord[]> {\n const docs = (await this.client.query(queryRef('cms:listDocuments'), {\n ...(collection ? { collection } : {}),\n })) as DocumentDoc[]\n // EC-153 parity: deterministic document-key ordering (Convex index order\n // within a project is insertion order, so we sort client-side).\n return docs\n .map((doc) => docRecordFromDoc(doc, projectId))\n .sort((a, b) => (documentKey(a.document) < documentKey(b.document) ? -1 : 1))\n }\n\n async listPublishedDocuments(projectId: string, collection?: string): Promise<CmsDocument[]> {\n // EC-307: one bulk read for the published pool (collapses the per-document\n // `listVersions` fan-out). The handler resolves each pin to its snapshot.\n const snapshots = (await this.client.query(queryRef('cms:listPublishedDocuments'), {\n ...(collection ? { collection } : {}),\n })) as CmsDocument[]\n // Deterministic document-key order (parity with the in-memory adapter).\n return snapshots\n .map((doc) => documentSchema.parse(doc))\n .sort((a, b) => (documentKey(a) < documentKey(b) ? -1 : 1))\n }\n\n async deleteDocument(projectId: string, ref: DocumentRef): Promise<void> {\n // EC-153 parity: deleting a missing document is not-found, never a no-op.\n await this.getDocument(projectId, ref)\n await this.client.mutation(mutationRef('cms:deleteDocument'), {\n collection: ref.collection,\n docId: ref.id,\n })\n }\n\n async clearDocuments(_projectId: string): Promise<void> {\n // EC-576: one deployment is one project — the mutation clears both tables at once.\n await this.client.mutation(mutationRef('cms:clearDocuments'), {})\n }\n\n async saveDocumentVersion(\n projectId: string,\n snapshot: CmsDocument,\n options: SaveDocumentVersionOptions = {},\n ): Promise<DocumentVersionRecord> {\n const parsed = documentSchema.parse(snapshot)\n const doc = (await this.client.mutation(mutationRef('cms:saveDocumentVersion'), {\n collection: parsed.collection,\n docId: parsed.id,\n snapshot: parsed,\n createdAt: this.clock(),\n ...(options.label ? { label: options.label } : {}),\n ...(options.origin ? { origin: options.origin } : {}),\n })) as VersionDoc\n return versionRecordFromDoc(doc, projectId)\n }\n\n async listDocumentVersions(\n projectId: string,\n ref: DocumentRef,\n ): Promise<DocumentVersionRecord[]> {\n const docs = (await this.client.query(queryRef('cms:listDocumentVersions'), {\n collection: ref.collection,\n docId: ref.id,\n })) as VersionDoc[]\n return docs.map((doc) => versionRecordFromDoc(doc, projectId))\n }\n\n async listAllDocumentVersions(projectId: string): Promise<DocumentVersionRecord[]> {\n const docs = (await this.client.query(\n queryRef('cms:listAllDocumentVersions'),\n {},\n )) as VersionDoc[]\n return docs.map((doc) => versionRecordFromDoc(doc, projectId))\n }\n\n async getDocumentVersion(\n projectId: string,\n ref: DocumentRef,\n version: number,\n ): Promise<DocumentVersionRecord> {\n const doc = (await this.client.query(queryRef('cms:getDocumentVersion'), {\n collection: ref.collection,\n docId: ref.id,\n version,\n })) as VersionDoc | null\n if (!doc) {\n throw new RecordNotFoundError(\n 'cms-document-version',\n `${projectId}/${ref.collection}:${ref.id}#${version}`,\n )\n }\n return versionRecordFromDoc(doc, projectId)\n }\n\n async publishDocumentVersion(\n projectId: string,\n ref: DocumentRef,\n version: number,\n ): Promise<CmsDocumentRecord> {\n // Taxonomy enforced adapter-side (the handler is lenient): the document and\n // the pinned version must both exist (each throws RecordNotFoundError).\n await this.getDocument(projectId, ref)\n await this.getDocumentVersion(projectId, ref, version)\n // EC-447: pass a fresh publish-action instant as the SET-ONCE candidate (the\n // handler writes it only when the row has no `publishedAt` yet). One `now` for\n // both stamps — this IS the publish moment.\n const now = this.clock()\n const doc = (await this.client.mutation(mutationRef('cms:publishDocumentVersion'), {\n collection: ref.collection,\n docId: ref.id,\n version,\n updatedAt: now,\n publishedAt: now,\n })) as DocumentDoc\n return docRecordFromDoc(doc, projectId)\n }\n\n async unpublishDocument(projectId: string, ref: DocumentRef): Promise<CmsDocumentRecord> {\n const existing = await this.getDocument(projectId, ref)\n if (existing.publishedVersion === undefined) {\n throw new PersistenceValidationError('Document is not currently published.', [\n {\n code: 'invalid-transition',\n message: 'Cannot unpublish: the document has no published version.',\n domain: 'cms',\n },\n ])\n }\n const doc = (await this.client.mutation(mutationRef('cms:unpublishDocument'), {\n collection: ref.collection,\n docId: ref.id,\n updatedAt: this.clock(),\n })) as DocumentDoc\n return docRecordFromDoc(doc, projectId)\n }\n}\n\n/**\n * A rail write the handler rejected (EC-577): `resolveRecordWrite` found the write\n * invalid inside the transaction and threw a `validation` `ConvexError` — mapped\n * back onto the provider-neutral {@link PersistenceValidationError} the in-memory\n * adapter throws for the same write. `ConvexError` data survives a production\n * deployment's error redaction, unlike a plain thrown message.\n */\nfunction asRailWriteError(error: unknown): unknown {\n if (!(error instanceof ConvexError)) return error\n const data = error.data as { code?: unknown; message?: unknown; issues?: unknown } | undefined\n if (data?.code !== 'validation' || typeof data.message !== 'string') return error\n const issues = persistenceIssueSchema.array().safeParse(data.issues)\n return new PersistenceValidationError(data.message, issues.success ? issues.data : [])\n}\n\nclass ConvexAssetRepository implements AssetRepository {\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly clock: Clock = realClock,\n ) {}\n\n async upsertAsset(projectId: string, input: AssetWriteInput): Promise<AssetRecord> {\n const now = this.clock()\n const { id: givenId, ...write } = input\n const id = givenId ?? newId('asset')\n // EC-577: send the write as written — absent keys stay absent (keep), `null`\n // crosses the wire as the clear. The handler resolves it against the stored\n // row inside the transaction; the create defaults ride along for a create.\n const doc = (await this.client\n .mutation(mutationRef('assets:upsert'), {\n assetId: id,\n ...presentWriteKeys(write),\n defaults: assetCreateDefaults(projectId, id),\n createdAt: now,\n updatedAt: now,\n })\n .catch((error: unknown) => {\n throw asRailWriteError(error)\n })) as AssetRow\n return assetRecordFromRow(doc, projectId)\n }\n\n async getAsset(projectId: string, id: string): Promise<AssetRecord> {\n const found = await this.findAsset(projectId, id)\n if (!found) throw new RecordNotFoundError('asset', `${projectId}/${id}`)\n return found\n }\n\n async findAsset(projectId: string, id: string): Promise<AssetRecord | undefined> {\n const doc = (await this.client.query(queryRef('assets:get'), {\n assetId: id,\n })) as AssetRow | null\n return doc ? assetRecordFromRow(doc, projectId) : undefined\n }\n\n async listAssets(projectId: string): Promise<AssetRecord[]> {\n const docs = (await this.client.query(queryRef('assets:list'), {})) as AssetRow[]\n return docs.map((doc) => assetRecordFromRow(doc, projectId))\n }\n\n async removeAsset(projectId: string, id: string): Promise<void> {\n // EC-153 parity: removing an unknown asset is not-found, never a no-op.\n await this.getAsset(projectId, id)\n await this.client.mutation(mutationRef('assets:remove'), { assetId: id })\n }\n\n async resolveMany(projectId: string, ids: readonly string[]): Promise<Map<string, AssetRecord>> {\n const all = await this.listAssets(projectId)\n const out = new Map<string, AssetRecord>()\n for (const asset of all) if (ids.includes(asset.id)) out.set(asset.id, asset)\n return out\n }\n}\n\n// --- Reference index (EC-155) ------------------------------------------------\n\n/** A Convex reference-entry doc (flattened source/target for index-backed lookups). */\ninterface ReferenceEntryDoc {\n projectId: string\n variant: ReferenceVariant\n sourceType: ReferenceSourceType\n sourceId: string\n path: string\n targetType: ReferenceTarget['type']\n targetId: string\n kind: ReferenceEntryRecord['kind']\n}\n\nfunction referenceRecordFromDoc(doc: ReferenceEntryDoc): ReferenceEntryRecord {\n return {\n projectId: doc.projectId,\n variant: doc.variant,\n source: { type: doc.sourceType, id: doc.sourceId },\n path: doc.path,\n target: { type: doc.targetType, id: doc.targetId },\n kind: doc.kind,\n }\n}\n\n/** Deterministic ordering is a repository contract; Convex docs sort client-side. */\nfunction sortedReferenceRecords(docs: ReferenceEntryDoc[]): ReferenceEntryRecord[] {\n return docs.map(referenceRecordFromDoc).sort(compareReferenceEntries)\n}\n\nclass ConvexReferenceIndexRepository implements ReferenceIndexRepository {\n constructor(private readonly client: ConvexHttpClient) {}\n\n async replaceForSource(\n projectId: string,\n variant: ReferenceVariant,\n source: ReferenceSource,\n references: readonly OutboundReference[],\n ): Promise<ReferenceEntryRecord[]> {\n await this.client.mutation(mutationRef('references:replaceForSource'), {\n variant,\n sourceType: source.type,\n sourceId: source.id,\n references: references.map((r) => ({\n path: r.path,\n targetType: r.target.type,\n targetId: r.target.id,\n kind: r.kind,\n })),\n })\n return this.outbound(projectId, source, { variant })\n }\n\n async replaceForSourceTypes(\n projectId: string,\n variant: ReferenceVariant,\n sourceTypes: readonly ReferenceSourceType[],\n entries: readonly ReferenceEntry[],\n ): Promise<ReferenceEntryRecord[]> {\n await this.client.mutation(mutationRef('references:replaceForSourceTypes'), {\n variant,\n sourceTypes: [...sourceTypes],\n entries: entries.map((e) => ({\n sourceType: e.source.type,\n sourceId: e.source.id,\n path: e.path,\n targetType: e.target.type,\n targetId: e.target.id,\n kind: e.kind,\n })),\n })\n const all = await this.listEntries(projectId, variant)\n const types = new Set(sourceTypes)\n return all.filter((record) => types.has(record.source.type))\n }\n\n async removeForSource(\n projectId: string,\n source: ReferenceSource,\n variant?: ReferenceVariant,\n ): Promise<void> {\n await this.client.mutation(mutationRef('references:removeForSource'), {\n sourceType: source.type,\n sourceId: source.id,\n ...(variant ? { variant } : {}),\n })\n }\n\n async outbound(\n projectId: string,\n source: ReferenceSource,\n options: ReferenceLookupOptions = {},\n ): Promise<ReferenceEntryRecord[]> {\n const docs = (await this.client.query(queryRef('references:outbound'), {\n sourceType: source.type,\n sourceId: source.id,\n ...(options.variant ? { variant: options.variant } : {}),\n })) as ReferenceEntryDoc[]\n return sortedReferenceRecords(docs)\n }\n\n async inbound(\n projectId: string,\n target: ReferenceTarget,\n options: ReferenceLookupOptions = {},\n ): Promise<ReferenceEntryRecord[]> {\n const docs = (await this.client.query(queryRef('references:inbound'), {\n targetType: target.type,\n targetId: target.id,\n ...(options.variant ? { variant: options.variant } : {}),\n })) as ReferenceEntryDoc[]\n return sortedReferenceRecords(docs)\n }\n\n async inboundMany(\n projectId: string,\n targets: readonly ReferenceTarget[],\n options: ReferenceLookupOptions = {},\n ): Promise<ReferenceEntryRecord[][]> {\n // EC-308: one round-trip for all targets (the handler loops the by_target\n // index server-side), replacing the client's per-target inbound fan-out.\n if (targets.length === 0) return []\n const groups = (await this.client.query(queryRef('references:inboundMany'), {\n targets: targets.map((target) => ({ targetType: target.type, targetId: target.id })),\n ...(options.variant ? { variant: options.variant } : {}),\n })) as ReferenceEntryDoc[][]\n return groups.map((docs) => sortedReferenceRecords(docs))\n }\n\n async listEntries(\n projectId: string,\n variant?: ReferenceVariant,\n ): Promise<ReferenceEntryRecord[]> {\n const docs = (await this.client.query(queryRef('references:list'), {\n ...(variant ? { variant } : {}),\n })) as ReferenceEntryDoc[]\n return sortedReferenceRecords(docs)\n }\n\n async getBuildMarker(_projectId: string): Promise<ReferenceIndexBuildMarker | null> {\n return (await this.client.query(queryRef('references:buildMarker'), {})) as\n | ReferenceIndexBuildMarker\n | null\n }\n\n async setBuildMarker(projectId: string, marker: ReferenceIndexBuildMarker): Promise<void> {\n await this.client.mutation(mutationRef('references:setBuildMarker'), {\n entryCount: marker.entryCount,\n })\n }\n\n async clearProject(_projectId: string): Promise<void> {\n await this.client.mutation(mutationRef('references:clearProject'), {})\n }\n}\n\n// --- Members + CLI tokens (EC-150) -------------------------------------------\n\ninterface MemberDoc {\n userId: string\n role: ProjectRole\n createdAt: string\n updatedAt: string\n}\n\n/**\n * Single-tenant (EC-179): membership is deployment-scoped, so the backend rows\n * carry no `projectId`. The contract record still does — this adapter is bound\n * to its deployment's project, so it stamps that slug onto every record.\n */\nfunction memberRecordFromDoc(doc: MemberDoc, projectId: string): ProjectMemberRecord {\n return {\n projectId,\n userId: doc.userId,\n role: doc.role,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n}\n\nclass ConvexMembersRepository implements MembersRepository {\n constructor(\n private readonly client: ConvexHttpClient,\n /** The slug of this deployment's one project — stamped onto records. */\n private readonly boundProjectId: string,\n private readonly clock: Clock = realClock,\n ) {}\n\n async setMember(\n projectId: string,\n userId: string,\n role: ProjectRole,\n ): Promise<ProjectMemberRecord> {\n const now = this.clock()\n const doc = (await this.client.mutation(mutationRef('members:set'), {\n userId,\n role,\n createdAt: now,\n updatedAt: now,\n })) as MemberDoc\n return memberRecordFromDoc(doc, projectId)\n }\n\n async findMember(projectId: string, userId: string): Promise<ProjectMemberRecord | undefined> {\n const doc = (await this.client.query(queryRef('members:get'), {\n userId,\n })) as MemberDoc | null\n return doc ? memberRecordFromDoc(doc, projectId) : undefined\n }\n\n async listMembers(projectId: string): Promise<ProjectMemberRecord[]> {\n const docs = (await this.client.query(queryRef('members:list'), {})) as MemberDoc[]\n return docs.map((d) => memberRecordFromDoc(d, projectId))\n }\n\n async listMembershipsForUser(userId: string): Promise<ProjectMemberRecord[]> {\n // `members:mine` is caller-scoped server-side and returns the caller's single\n // deployment membership (or null). The studio only ever asks about the\n // session user; records are stamped with this deployment's bound project.\n const doc = (await this.client.query(queryRef('members:mine'), {})) as MemberDoc | null\n return doc && doc.userId === userId ? [memberRecordFromDoc(doc, this.boundProjectId)] : []\n }\n\n async removeMember(projectId: string, userId: string): Promise<void> {\n try {\n await this.client.mutation(mutationRef('members:remove'), { userId })\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n if (/not-found/i.test(message)) {\n throw new RecordNotFoundError('project-member', `${projectId}/${userId}`)\n }\n throw error\n }\n }\n}\n\n// --- Users rail (EC-240, 240a) -----------------------------------------------\n\n/** The wire shape returned by the `users:list`/`users:get` join handlers. */\ninterface UserDoc {\n id: string\n email: string\n name?: string\n avatar?: string\n role: ProjectRole\n meta?: Record<string, unknown>\n createdAt: string\n updatedAt: string\n}\n\n/** Map a joined user doc onto the contract record; stamp the bound project. */\nfunction userRecordFromDoc(doc: UserDoc, projectId: string): UserRecord {\n return {\n id: doc.id,\n projectId,\n email: doc.email,\n ...(doc.name !== undefined ? { name: doc.name } : {}),\n ...(doc.avatar !== undefined ? { avatar: doc.avatar } : {}),\n // 240a bridge: the single `members.role` column ⇒ the 240c-ready `roles[]`.\n roles: [doc.role],\n ...(doc.meta !== undefined ? { meta: doc.meta } : {}),\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n}\n\n/**\n * Collapse the 240c-ready `roles[]` to the single `members.role` column by\n * applying the strongest role (the 240a→240c enforcement bridge). Unknown\n * strings are ignored; an empty/unknown set floors to `viewer`.\n */\nfunction strongestRole(roles: readonly string[]): ProjectRole {\n // Validate against the active role policy (EC-240c) rather than a hardcoded\n // enum, then take the canonical rank max; floor an empty/unknown set to `viewer`.\n const valid = roles.filter((r) => isKnownRole(r))\n return highestRole(valid) ?? 'viewer'\n}\n\n/**\n * Convex-backed {@link UserRepository} (EC-240, 240a). Reads are the admin-gated\n * `users:*` **join** handlers (members row + auth identity); the role write\n * reuses the member write path (`members:set`, extended with the `meta` bag) so\n * there is one source for role writes — 240c collapses enforcement onto it.\n */\nclass ConvexUserRepository implements UserRepository {\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly clock: Clock = realClock,\n ) {}\n\n async listUsers(projectId: string): Promise<UserRecord[]> {\n const docs = (await this.client.query(queryRef('users:list'), {})) as UserDoc[]\n return docs.map((doc) => userRecordFromDoc(doc, projectId))\n }\n\n async findUser(projectId: string, id: string): Promise<UserRecord | undefined> {\n const doc = (await this.client.query(queryRef('users:get'), { userId: id })) as UserDoc | null\n return doc ? userRecordFromDoc(doc, projectId) : undefined\n }\n\n async getUser(projectId: string, id: string): Promise<UserRecord> {\n const found = await this.findUser(projectId, id)\n if (!found) throw new RecordNotFoundError('user', `${projectId}/${id}`)\n return found\n }\n\n async getSelf(projectId: string): Promise<UserRecord | null> {\n // Self-permitted (EC-240 H-tail item 1): `users:getSelf` derives the caller\n // from the JWT server-side and returns ONLY their own join — never widened to\n // the admin-only `users:get`. The `selfId` the contract passes is ignored here;\n // the trust boundary is the server.\n const doc = (await this.client.query(queryRef('users:getSelf'), {})) as UserDoc | null\n return doc ? userRecordFromDoc(doc, projectId) : null\n }\n\n async saveUser(projectId: string, input: SaveUserInput): Promise<UserRecord> {\n const now = this.clock()\n await this.client.mutation(mutationRef('members:set'), {\n userId: input.id,\n role: strongestRole(input.roles),\n ...(input.meta !== undefined ? { meta: input.meta } : {}),\n createdAt: now,\n updatedAt: now,\n })\n // Return the full joined projection (identity + role + custom fields).\n return this.getUser(projectId, input.id)\n }\n\n async removeUser(projectId: string, id: string): Promise<void> {\n try {\n await this.client.mutation(mutationRef('members:remove'), { userId: id })\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n if (/not-found/i.test(message)) {\n throw new RecordNotFoundError('user', `${projectId}/${id}`)\n }\n throw error\n }\n }\n}\n\n// --- Invite allowlist rail (EC-324) ------------------------------------------\n\n/** The wire shape returned by the `invites:*` handlers. */\ninterface InviteDoc {\n email: string\n role: string\n invitedBy?: string\n createdAt: string\n updatedAt: string\n}\n\nfunction inviteRecordFromDoc(doc: InviteDoc): InviteRecord {\n return {\n email: doc.email,\n role: doc.role,\n ...(doc.invitedBy !== undefined ? { invitedBy: doc.invitedBy } : {}),\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n}\n\n/**\n * Convex-backed {@link InviteRepository} (EC-324). Admin-gated `invites:*`\n * handlers; the repo supplies timestamps (mirroring `ConvexUserRepository`). The\n * Convex auth boundary reads the same table in `beforeSessionCreation` to gate\n * open sign-up + grant the invited role.\n */\nclass ConvexInviteRepository implements InviteRepository {\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly clock: Clock = realClock,\n ) {}\n\n async listInvites(_projectId: string): Promise<InviteRecord[]> {\n const docs = (await this.client.query(queryRef('invites:list'), {})) as InviteDoc[]\n return docs.map(inviteRecordFromDoc)\n }\n\n async findInvite(projectId: string, email: string): Promise<InviteRecord | undefined> {\n const key = normalizeInviteEmail(email)\n const all = await this.listInvites(projectId)\n return all.find((invite) => invite.email === key)\n }\n\n async saveInvite(_projectId: string, input: SaveInviteInput): Promise<InviteRecord> {\n const now = this.clock()\n const doc = (await this.client.mutation(mutationRef('invites:create'), {\n email: normalizeInviteEmail(input.email),\n role: input.role,\n ...(input.invitedBy !== undefined ? { invitedBy: input.invitedBy } : {}),\n createdAt: now,\n updatedAt: now,\n })) as InviteDoc\n return inviteRecordFromDoc(doc)\n }\n\n async removeInvite(projectId: string, email: string): Promise<void> {\n try {\n await this.client.mutation(mutationRef('invites:revoke'), {\n email: normalizeInviteEmail(email),\n })\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n if (/not-found/i.test(message)) {\n throw new RecordNotFoundError('invite', `${projectId}/${normalizeInviteEmail(email)}`)\n }\n throw error\n }\n }\n}\n\n/**\n * Convex-backed {@link RedirectRepository} (EC-303) — editorial redirects as data\n * (not config). Content-gated CRUD over the `redirects` table; the studio's\n * editorial surface + the delivery snapshot both read through here. A save sends\n * the write as written (EC-577): the create defaults live in the record schema and\n * apply inside the handler's transaction, only when the save creates the redirect.\n */\nclass ConvexRedirectRepository implements RedirectRepository {\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly clock: Clock = realClock,\n ) {}\n\n async saveRedirect(projectId: string, input: SaveRedirectInput): Promise<RedirectEntry> {\n const now = this.clock()\n const { id: givenId, ...write } = input\n const id = givenId ?? newId('redirect')\n const doc = (await this.client\n .mutation(mutationRef('redirects:save'), {\n redirectId: id,\n ...presentWriteKeys(write),\n createdAt: now,\n updatedAt: now,\n })\n .catch((error: unknown) => {\n throw asRailWriteError(error)\n })) as RedirectRow\n return redirectEntryFromRow(doc, projectId)\n }\n\n async getRedirect(projectId: string, id: string): Promise<RedirectEntry> {\n const found = await this.findRedirect(projectId, id)\n if (!found) throw new RecordNotFoundError('redirect', `${projectId}/${id}`)\n return found\n }\n\n async findRedirect(projectId: string, id: string): Promise<RedirectEntry | undefined> {\n const doc = (await this.client.query(queryRef('redirects:get'), {\n redirectId: id,\n })) as RedirectRow | null\n return doc ? redirectEntryFromRow(doc, projectId) : undefined\n }\n\n async listRedirects(projectId: string): Promise<RedirectEntry[]> {\n const docs = (await this.client.query(queryRef('redirects:list'), {})) as RedirectRow[]\n return docs\n .map((doc) => redirectEntryFromRow(doc, projectId))\n .sort((a, b) => (a.from < b.from ? -1 : a.from > b.from ? 1 : 0))\n }\n\n async removeRedirect(projectId: string, id: string): Promise<void> {\n await this.getRedirect(projectId, id) // not-found parity with the in-memory rail\n await this.client.mutation(mutationRef('redirects:remove'), { redirectId: id })\n }\n}\n\n/**\n * Convex-backed {@link DeliveryRepository} (EC-268/EC-329) — reads the\n * deployment's actual instant-publish env var status via the guarded\n * `delivery:deliveryConfig` query. Replaces the studio's former direct\n * `getConvexClient(...).query('delivery:deliveryConfig')` call in\n * `delivery-health-banner.tsx`, the only place that used to bypass both the\n * operations chokepoint and the shared `useOperationQuery` cache (AD-17).\n */\nclass ConvexDeliveryRepository implements DeliveryRepository {\n constructor(private readonly client: ConvexHttpClient) {}\n\n async getConfig(): Promise<DeliveryConfigStatus> {\n return (await this.client.query(\n queryRef('delivery:deliveryConfig'),\n {},\n )) as DeliveryConfigStatus\n }\n}\n\n/**\n * Convex-backed {@link PersistenceAdapter} (brief §10, EC-039). Every repository\n * is implemented against the Convex functions in `apps/builder/convex/*`, mapping\n * results and failures onto the provider-neutral contracts + error taxonomies.\n */\nexport class ConvexPersistenceAdapter implements PersistenceAdapter {\n readonly cms: CmsRepository\n readonly assets: AssetRepository\n /** Reference index — outbound/inbound entries per variant (EC-155, AD-6). */\n readonly references: ReferenceIndexRepository\n /** Per-project membership roles (EC-150). */\n readonly members: MembersRepository\n readonly invites: InviteRepository\n /** Studio users rail — role + custom fields joined to auth identity (EC-240). */\n readonly users: UserRepository\n /** Editorial redirects rail — data-backed 301/302 forwards (EC-303). */\n readonly redirects: RedirectRepository\n /** Convex file storage behind the EC-133 blob boundary (EC-151). */\n readonly blobs: BlobStorageAdapter\n /** Delivery-pipeline (instant-publish) health, read-only (EC-268/EC-329). */\n readonly delivery: DeliveryRepository\n /**\n * EC-277: the Convex mutations maintain the reference index in-transaction\n * (`convex/referenceMaintenance.ts`), so every writer — studio, CLI, webhook,\n * raw `convex run` — is caught at the source. The studio bootstrap therefore does\n * NOT attach the client-side `attachReferenceIndex` subscriber for this provider.\n */\n readonly maintainsReferenceIndex = true\n\n /**\n * @param client the Convex client bound to this deployment (one project).\n * @param projectId the slug of this deployment's one project (EC-179). Used to\n * stamp deployment-scoped member records onto the still-project-keyed contract.\n * @param collections the active project's config-owned CMS collections (EC-183,\n * AD-11), from `elytra.config.ts`. The backend has no `cmsSchemas` table, so\n * the CMS repository serves the schema from these.\n */\n constructor(\n private readonly client: ConvexHttpClient,\n projectId: string,\n collections: readonly CollectionDef[] = [],\n ) {\n this.cms = new ConvexCmsRepository(client, collections)\n this.assets = new ConvexAssetRepository(client)\n this.references = new ConvexReferenceIndexRepository(client)\n this.members = new ConvexMembersRepository(client, projectId)\n this.users = new ConvexUserRepository(client)\n this.invites = new ConvexInviteRepository(client)\n this.redirects = new ConvexRedirectRepository(client)\n this.blobs = new ConvexBlobStorage(client)\n this.delivery = new ConvexDeliveryRepository(client)\n }\n\n async status(): Promise<BackendStatus> {\n try {\n // Lightweight connectivity probe (EC-182: no `projects` table). `members:mine`\n // takes no args and is soft-guarded (EC-279): it answers `null` for an\n // unauthenticated caller rather than throwing, so the pre-sign-in boot probe\n // resolves cleanly — backend answered ⇒ `available: true` — with no scary\n // `Uncaught Error` in the Convex log.\n await this.client.query(queryRef('members:mine'), {})\n return { backend: 'convex', available: true }\n } catch (error) {\n const detail = error instanceof Error ? error.message : String(error)\n // EC-153: an `unauthorized` rejection *is* a healthy backend — the\n // deployment answered and enforced auth. Now that `members:mine` is\n // soft-guarded this branch is a defensive fallback (a protected probe could\n // still throw); only transport/server failures count as unavailable, so the\n // DeploymentSetupGate surfaces those visibly instead of falling back to in-memory.\n if (/unauthorized/i.test(detail)) return { backend: 'convex', available: true }\n return { backend: 'convex', available: false, detail }\n }\n }\n\n validate(input: BackendValidationInput): BackendValidationResult {\n return validateForPersistence(input)\n }\n}\n"]}
@@ -90,8 +90,6 @@ export declare function contentQueryErrorMessage(error: ContentQueryError): stri
90
90
  * one) degrades to the generic title, never the raw enum.
91
91
  */
92
92
  export declare function operationErrorLabel(code: OperationErrorCode): string;
93
- /** Friendly name for a project export target (`nextjs` → `Next.js`). */
94
- export declare function exportTargetLabel(target: string): string;
95
93
  /** The leaf of a component id, namespace stripped (`base.Heading` → `Heading`). */
96
94
  export declare function componentLeafId(componentId: string): string;
97
95
  /**
@@ -83,6 +83,7 @@ const CMS_ISSUE_LABEL_KEYS = {
83
83
  'unknown-alias': 'cms.issue.unknown-alias',
84
84
  'unfilled-slot': 'cms.issue.unfilled-slot',
85
85
  'custom-validation': 'cms.issue.custom-validation',
86
+ 'hidden-predicate-error': 'cms.issue.hidden-predicate-error',
86
87
  'unaddressable-url': 'cms.issue.unaddressable-url',
87
88
  'unknown-version': 'cms.issue.unknown-version',
88
89
  };
@@ -121,9 +122,6 @@ const OPERATION_ERROR_LABEL_KEYS = {
121
122
  unauthorized: 'operations.errorLabel.unauthorized',
122
123
  unknown: 'operations.errorLabel.unknown',
123
124
  };
124
- const EXPORT_TARGET_LABELS = {
125
- nextjs: 'Next.js',
126
- };
127
125
  /**
128
126
  * Plain-language title for a CMS validation issue code — localized against the
129
127
  * active studio-UI locale (EC-443). A runtime-unknown code (impossible typewise;
@@ -259,10 +257,6 @@ export function operationErrorLabel(code) {
259
257
  const key = OPERATION_ERROR_LABEL_KEYS[code];
260
258
  return translate(key ?? OPERATION_ERROR_LABEL_KEYS.unknown);
261
259
  }
262
- /** Friendly name for a project export target (`nextjs` → `Next.js`). */
263
- export function exportTargetLabel(target) {
264
- return EXPORT_TARGET_LABELS[target] ?? humanizeName(target);
265
- }
266
260
  /** The leaf of a component id, namespace stripped (`base.Heading` → `Heading`). */
267
261
  export function componentLeafId(componentId) {
268
262
  const dot = componentId.lastIndexOf('.');