@elytracms/studio 0.0.13 → 0.0.15

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 (94) hide show
  1. package/convex/cms.ts +8 -22
  2. package/convex/content.ts +3 -44
  3. package/convex/delivery.ts +8 -42
  4. package/convex/functions.ts +17 -2
  5. package/convex/members.ts +2 -2
  6. package/convex/referenceMaintenance.ts +4 -73
  7. package/convex/references.ts +4 -2
  8. package/convex/revalidate.ts +42 -0
  9. package/convex/schema.ts +17 -37
  10. package/convex/sync.ts +10 -42
  11. package/convex/triggers.ts +57 -0
  12. package/convex/webhooks.ts +3 -2
  13. package/dist/components/builder/builder-store.d.ts +85 -39
  14. package/dist/components/builder/builder-store.js +29 -125
  15. package/dist/components/builder/builder-store.js.map +1 -1
  16. package/dist/components/builder/canvas.js +23 -55
  17. package/dist/components/builder/canvas.js.map +1 -1
  18. package/dist/components/builder/clipboard-actions.js +3 -3
  19. package/dist/components/builder/clipboard-actions.js.map +1 -1
  20. package/dist/components/builder/composition-field-editor.js +13 -23
  21. package/dist/components/builder/composition-field-editor.js.map +1 -1
  22. package/dist/components/builder/insert-context.js +1 -1
  23. package/dist/components/builder/insert-context.js.map +1 -1
  24. package/dist/components/builder/page-tree.js +3 -4
  25. package/dist/components/builder/page-tree.js.map +1 -1
  26. package/dist/components/builder/property-inspector.js +4 -64
  27. package/dist/components/builder/property-inspector.js.map +1 -1
  28. package/dist/components/cms/cell.d.ts +0 -4
  29. package/dist/components/cms/cell.js +1 -5
  30. package/dist/components/cms/cell.js.map +1 -1
  31. package/dist/components/cms/cms-store.d.ts +1 -1
  32. package/dist/components/cms/cms-store.js +4 -9
  33. package/dist/components/cms/cms-store.js.map +1 -1
  34. package/dist/components/cms/collection-table.js +1 -1
  35. package/dist/components/cms/collection-table.js.map +1 -1
  36. package/dist/components/cms/detail-editor.js +2 -2
  37. package/dist/components/cms/detail-editor.js.map +1 -1
  38. package/dist/components/cms/doc-state.d.ts +0 -5
  39. package/dist/components/cms/doc-state.js +1 -7
  40. package/dist/components/cms/doc-state.js.map +1 -1
  41. package/dist/components/cms/editable-cell.js +1 -1
  42. package/dist/components/cms/editable-cell.js.map +1 -1
  43. package/dist/components/collab/collab-context.d.ts +6 -14
  44. package/dist/components/collab/collab-context.js +3 -12
  45. package/dist/components/collab/collab-context.js.map +1 -1
  46. package/dist/components/collab/collab-seed.d.ts +7 -19
  47. package/dist/components/collab/collab-seed.js +9 -31
  48. package/dist/components/collab/collab-seed.js.map +1 -1
  49. package/dist/components/components/registry-browser.js +6 -12
  50. package/dist/components/components/registry-browser.js.map +1 -1
  51. package/dist/components/guards.d.ts +0 -9
  52. package/dist/components/guards.js +0 -12
  53. package/dist/components/guards.js.map +1 -1
  54. package/dist/components/section-state.d.ts +0 -2
  55. package/dist/components/section-state.js +0 -9
  56. package/dist/components/section-state.js.map +1 -1
  57. package/dist/components/section-surface.d.ts +3 -7
  58. package/dist/components/section-surface.js +5 -12
  59. package/dist/components/section-surface.js.map +1 -1
  60. package/dist/components/sections.d.ts +0 -1
  61. package/dist/components/sections.js +0 -10
  62. package/dist/components/sections.js.map +1 -1
  63. package/dist/components/studio-project-screen.js +13 -14
  64. package/dist/components/studio-project-screen.js.map +1 -1
  65. package/dist/components/studio-shell.d.ts +0 -4
  66. package/dist/components/studio-shell.js +1 -5
  67. package/dist/components/studio-shell.js.map +1 -1
  68. package/dist/lib/operations/graph-commands.d.ts +2 -6
  69. package/dist/lib/operations/graph-commands.js +1 -2
  70. package/dist/lib/operations/graph-commands.js.map +1 -1
  71. package/dist/lib/operations/index.d.ts +0 -2
  72. package/dist/lib/operations/index.js +0 -2
  73. package/dist/lib/operations/index.js.map +1 -1
  74. package/dist/lib/operations/session-hydration.d.ts +14 -24
  75. package/dist/lib/operations/session-hydration.js +15 -34
  76. package/dist/lib/operations/session-hydration.js.map +1 -1
  77. package/dist/lib/persistence/convex-adapter.d.ts +1 -3
  78. package/dist/lib/persistence/convex-adapter.js +1 -154
  79. package/dist/lib/persistence/convex-adapter.js.map +1 -1
  80. package/dist/lib/persona/labels.js +0 -2
  81. package/dist/lib/persona/labels.js.map +1 -1
  82. package/dist/lib/references/reference-model.d.ts +0 -16
  83. package/dist/lib/references/reference-model.js +2 -54
  84. package/dist/lib/references/reference-model.js.map +1 -1
  85. package/dist/lib/references/references-store.js +3 -4
  86. package/dist/lib/references/references-store.js.map +1 -1
  87. package/dist/lib/registry/index.d.ts +0 -16
  88. package/dist/lib/registry/index.js +0 -15
  89. package/dist/lib/registry/index.js.map +1 -1
  90. package/dist/lib/webhooks/tags.js +2 -16
  91. package/dist/lib/webhooks/tags.js.map +1 -1
  92. package/package.json +3 -2
  93. package/convex/graphs.ts +0 -55
  94. package/convex/publishing.ts +0 -108
@@ -1,108 +0,0 @@
1
- import { makeFunctionReference } from 'convex/server'
2
- import { v } from 'convex/values'
3
- import { mutation, query } from './functions'
4
- import type { MutationCtx } from './functions'
5
- import { requireRole } from './guard'
6
- import { maintainGraphPublishedReferences } from './referenceMaintenance'
7
-
8
- // EC-223: the studio's convex functions are package-shipped and deployment-agnostic
9
- // — they address each other by STRING ref (resolved against the consumer's deployment),
10
- // never the per-deployment `_generated/api`. Mirrors the lib's `queryRef`/`actionRef`.
11
- const webhooksDeliver = makeFunctionReference<'action'>('webhooks:deliver')
12
-
13
- /**
14
- * Publishing state (EC-045). Single-environment (EC-179, vision AD-8): a
15
- * deployment IS one environment, so there is exactly ONE publishingState row —
16
- * see `env-is-deployment-boundary`.
17
- */
18
-
19
- /**
20
- * EC-180 / EC-146 — fire the host revalidation webhook on a publish-state change.
21
- *
22
- * A mutation cannot `fetch`, so we hand off to the `webhooks.deliver` internal
23
- * action (it signs + POSTs server-side; the secret never leaves Convex). A graph
24
- * publish/unpublish can affect any page, so the honest v1 invalidation is the
25
- * whole-project sweep tag `p:<scope>:project` — a mirror of
26
- * `projectSweepWebhookTag` (`src/lib/webhooks/tags.ts`) / `@elytracms/next`'s
27
- * `projectSweepTag`; the tests on those two sides pin the literal.
28
- *
29
- * `scope` must equal the host's `cache.scope` (its `ELYTRA_PROJECT_ID`) for the
30
- * tag to match what the host stamped on its cached fetches; it comes from the
31
- * `CANVAS_PROJECT_SCOPE` Convex env var. Unconfigured deployments (local dev,
32
- * no env) are a silent no-op — publishing must never depend on a reachable host.
33
- */
34
- async function scheduleRevalidate(
35
- ctx: MutationCtx,
36
- event: 'publishing.publish' | 'publishing.unpublish',
37
- ): Promise<void> {
38
- const env =
39
- (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env ?? {}
40
- const scope = env['CANVAS_PROJECT_SCOPE']
41
- if (!scope) return
42
- await ctx.scheduler.runAfter(0, webhooksDeliver, {
43
- projectId: scope,
44
- event,
45
- tags: [`p:${scope}:project`],
46
- })
47
- }
48
-
49
- export const publish = mutation({
50
- args: {
51
- revisionId: v.string(),
52
- revision: v.number(),
53
- publishedAt: v.string(),
54
- },
55
- handler: async (ctx, args) => {
56
- await requireRole(ctx, 'editor') // EC-150
57
- const existing = await ctx.db.query('publishingState').first()
58
- const record = {
59
- status: 'published' as const,
60
- publishedRevisionId: args.revisionId,
61
- publishedRevision: args.revision,
62
- publishedAt: args.publishedAt,
63
- createdAt: existing?.createdAt ?? args.publishedAt,
64
- updatedAt: args.publishedAt,
65
- }
66
- // EC-153 parity: republish preserves `createdAt`; return the stored record.
67
- const id = existing ? existing._id : await ctx.db.insert('publishingState', record)
68
- if (existing) await ctx.db.patch(existing._id, record)
69
- // EC-277: the newly pinned revision becomes the published graph — reindex its
70
- // published reference rows in-transaction (AD-6 "at the source").
71
- await maintainGraphPublishedReferences(ctx)
72
- // EC-180: drop the host's cached pages for this project (fire-and-forget).
73
- await scheduleRevalidate(ctx, 'publishing.publish')
74
- return ctx.db.get(id)
75
- },
76
- })
77
-
78
- export const unpublish = mutation({
79
- args: { updatedAt: v.string() },
80
- handler: async (ctx, args) => {
81
- await requireRole(ctx, 'editor') // EC-150
82
- const existing = await ctx.db.query('publishingState').first()
83
- if (!existing || existing.status !== 'published') {
84
- throw new Error('invalid-transition: nothing is currently published')
85
- }
86
- await ctx.db.patch(existing._id, {
87
- status: 'draft',
88
- publishedRevisionId: undefined,
89
- publishedRevision: undefined,
90
- publishedAt: undefined,
91
- updatedAt: args.updatedAt,
92
- })
93
- // EC-277: a graph going dark drops every published graph reference row.
94
- await maintainGraphPublishedReferences(ctx)
95
- // EC-180: a graph going dark must also drop the host's cached pages.
96
- await scheduleRevalidate(ctx, 'publishing.unpublish')
97
- // EC-153 parity: return the stored record (createdAt preserved).
98
- return ctx.db.get(existing._id)
99
- },
100
- })
101
-
102
- export const getState = query({
103
- args: {},
104
- handler: async (ctx) => {
105
- await requireRole(ctx, 'viewer') // EC-150
106
- return ctx.db.query('publishingState').first()
107
- },
108
- })