convex-cms 0.0.2 → 0.0.3

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 (265) hide show
  1. package/admin-dist/nitro.json +15 -0
  2. package/admin-dist/public/assets/CmsEmptyState-CRswfTzk.js +5 -0
  3. package/admin-dist/public/assets/CmsPageHeader-CirpXndm.js +1 -0
  4. package/admin-dist/public/assets/CmsStatusBadge-CbEUpQu-.js +1 -0
  5. package/admin-dist/public/assets/CmsToolbar-BI2nZOXp.js +1 -0
  6. package/admin-dist/public/assets/ContentEntryEditor-CBeCyK_m.js +4 -0
  7. package/admin-dist/public/assets/ErrorState-BIVaWmom.js +1 -0
  8. package/admin-dist/public/assets/TaxonomyFilter-ChaY6Y_x.js +1 -0
  9. package/admin-dist/public/assets/_contentTypeId-DQ8k_Rvw.js +1 -0
  10. package/admin-dist/public/assets/_entryId-CKU_glsK.js +1 -0
  11. package/admin-dist/public/assets/alert-BXjTqrwQ.js +1 -0
  12. package/admin-dist/public/assets/badge-hvUOzpVZ.js +1 -0
  13. package/admin-dist/public/assets/circle-check-big-CF_pR17r.js +1 -0
  14. package/admin-dist/public/assets/command-DU82cJlt.js +1 -0
  15. package/admin-dist/public/assets/content-_LXl3pp7.js +1 -0
  16. package/admin-dist/public/assets/content-types-KjxaXGxY.js +2 -0
  17. package/admin-dist/public/assets/globals-CS6BZ0zp.css +1 -0
  18. package/admin-dist/public/assets/index-DNGIZHL-.js +1 -0
  19. package/admin-dist/public/assets/label-KNtpL71g.js +1 -0
  20. package/admin-dist/public/assets/link-2-Bw2aI4V4.js +1 -0
  21. package/admin-dist/public/assets/list-sYepHjt_.js +1 -0
  22. package/admin-dist/public/assets/main-CKj5yfEi.js +97 -0
  23. package/admin-dist/public/assets/media-Bkrkffm7.js +1 -0
  24. package/admin-dist/public/assets/new._contentTypeId-C3LstjNs.js +1 -0
  25. package/admin-dist/public/assets/plus-DUn8v_Xf.js +1 -0
  26. package/admin-dist/public/assets/rotate-ccw-DJEoHcRI.js +1 -0
  27. package/admin-dist/public/assets/scroll-area-DfIlT0in.js +1 -0
  28. package/admin-dist/public/assets/search-MuAUDJKR.js +1 -0
  29. package/admin-dist/public/assets/select-BD29IXCI.js +1 -0
  30. package/admin-dist/public/assets/settings-DmMyn_6A.js +1 -0
  31. package/admin-dist/public/assets/switch-h3Rrnl5i.js +1 -0
  32. package/admin-dist/public/assets/tabs-imc8h-Dp.js +1 -0
  33. package/admin-dist/public/assets/taxonomies-dAsrT65H.js +1 -0
  34. package/admin-dist/public/assets/textarea-BTy7nwzR.js +1 -0
  35. package/admin-dist/public/assets/trash-SAWKZZHv.js +1 -0
  36. package/admin-dist/public/assets/triangle-alert-E52Vfeuh.js +1 -0
  37. package/admin-dist/public/assets/useBreadcrumbLabel-BECBMCzM.js +1 -0
  38. package/admin-dist/public/assets/usePermissions-Basjs9BT.js +1 -0
  39. package/admin-dist/public/favicon.ico +0 -0
  40. package/admin-dist/server/_chunks/_libs/@date-fns/tz.mjs +217 -0
  41. package/admin-dist/server/_chunks/_libs/@floating-ui/core.mjs +719 -0
  42. package/admin-dist/server/_chunks/_libs/@floating-ui/dom.mjs +622 -0
  43. package/admin-dist/server/_chunks/_libs/@floating-ui/react-dom.mjs +292 -0
  44. package/admin-dist/server/_chunks/_libs/@floating-ui/utils.mjs +320 -0
  45. package/admin-dist/server/_chunks/_libs/@radix-ui/number.mjs +6 -0
  46. package/admin-dist/server/_chunks/_libs/@radix-ui/primitive.mjs +11 -0
  47. package/admin-dist/server/_chunks/_libs/@radix-ui/react-arrow.mjs +23 -0
  48. package/admin-dist/server/_chunks/_libs/@radix-ui/react-avatar.mjs +119 -0
  49. package/admin-dist/server/_chunks/_libs/@radix-ui/react-checkbox.mjs +270 -0
  50. package/admin-dist/server/_chunks/_libs/@radix-ui/react-collection.mjs +69 -0
  51. package/admin-dist/server/_chunks/_libs/@radix-ui/react-compose-refs.mjs +39 -0
  52. package/admin-dist/server/_chunks/_libs/@radix-ui/react-context.mjs +137 -0
  53. package/admin-dist/server/_chunks/_libs/@radix-ui/react-dialog.mjs +325 -0
  54. package/admin-dist/server/_chunks/_libs/@radix-ui/react-direction.mjs +9 -0
  55. package/admin-dist/server/_chunks/_libs/@radix-ui/react-dismissable-layer.mjs +210 -0
  56. package/admin-dist/server/_chunks/_libs/@radix-ui/react-dropdown-menu.mjs +253 -0
  57. package/admin-dist/server/_chunks/_libs/@radix-ui/react-focus-guards.mjs +29 -0
  58. package/admin-dist/server/_chunks/_libs/@radix-ui/react-focus-scope.mjs +206 -0
  59. package/admin-dist/server/_chunks/_libs/@radix-ui/react-id.mjs +14 -0
  60. package/admin-dist/server/_chunks/_libs/@radix-ui/react-label.mjs +23 -0
  61. package/admin-dist/server/_chunks/_libs/@radix-ui/react-menu.mjs +812 -0
  62. package/admin-dist/server/_chunks/_libs/@radix-ui/react-popover.mjs +300 -0
  63. package/admin-dist/server/_chunks/_libs/@radix-ui/react-popper.mjs +286 -0
  64. package/admin-dist/server/_chunks/_libs/@radix-ui/react-portal.mjs +16 -0
  65. package/admin-dist/server/_chunks/_libs/@radix-ui/react-presence.mjs +128 -0
  66. package/admin-dist/server/_chunks/_libs/@radix-ui/react-primitive.mjs +141 -0
  67. package/admin-dist/server/_chunks/_libs/@radix-ui/react-roving-focus.mjs +224 -0
  68. package/admin-dist/server/_chunks/_libs/@radix-ui/react-scroll-area.mjs +721 -0
  69. package/admin-dist/server/_chunks/_libs/@radix-ui/react-select.mjs +1163 -0
  70. package/admin-dist/server/_chunks/_libs/@radix-ui/react-separator.mjs +28 -0
  71. package/admin-dist/server/_chunks/_libs/@radix-ui/react-slot.mjs +601 -0
  72. package/admin-dist/server/_chunks/_libs/@radix-ui/react-switch.mjs +152 -0
  73. package/admin-dist/server/_chunks/_libs/@radix-ui/react-tabs.mjs +189 -0
  74. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-callback-ref.mjs +11 -0
  75. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-controllable-state.mjs +69 -0
  76. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-effect-event.mjs +1 -0
  77. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-escape-keydown.mjs +17 -0
  78. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-is-hydrated.mjs +15 -0
  79. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-layout-effect.mjs +6 -0
  80. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-previous.mjs +14 -0
  81. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-size.mjs +39 -0
  82. package/admin-dist/server/_chunks/_libs/@radix-ui/react-visually-hidden.mjs +33 -0
  83. package/admin-dist/server/_chunks/_libs/@tanstack/history.mjs +409 -0
  84. package/admin-dist/server/_chunks/_libs/@tanstack/react-router.mjs +1711 -0
  85. package/admin-dist/server/_chunks/_libs/@tanstack/react-store.mjs +56 -0
  86. package/admin-dist/server/_chunks/_libs/@tanstack/router-core.mjs +4829 -0
  87. package/admin-dist/server/_chunks/_libs/@tanstack/store.mjs +134 -0
  88. package/admin-dist/server/_chunks/_libs/react-dom.mjs +10781 -0
  89. package/admin-dist/server/_chunks/_libs/react.mjs +513 -0
  90. package/admin-dist/server/_libs/aria-hidden.mjs +122 -0
  91. package/admin-dist/server/_libs/class-variance-authority.mjs +44 -0
  92. package/admin-dist/server/_libs/clsx.mjs +16 -0
  93. package/admin-dist/server/_libs/cmdk.mjs +315 -0
  94. package/admin-dist/server/_libs/convex.mjs +4841 -0
  95. package/admin-dist/server/_libs/cookie-es.mjs +58 -0
  96. package/admin-dist/server/_libs/croner.mjs +1 -0
  97. package/admin-dist/server/_libs/crossws.mjs +1 -0
  98. package/admin-dist/server/_libs/date-fns.mjs +1716 -0
  99. package/admin-dist/server/_libs/detect-node-es.mjs +1 -0
  100. package/admin-dist/server/_libs/get-nonce.mjs +9 -0
  101. package/admin-dist/server/_libs/h3-v2.mjs +277 -0
  102. package/admin-dist/server/_libs/h3.mjs +401 -0
  103. package/admin-dist/server/_libs/hookable.mjs +1 -0
  104. package/admin-dist/server/_libs/isbot.mjs +20 -0
  105. package/admin-dist/server/_libs/lucide-react.mjs +850 -0
  106. package/admin-dist/server/_libs/ohash.mjs +1 -0
  107. package/admin-dist/server/_libs/react-day-picker.mjs +2201 -0
  108. package/admin-dist/server/_libs/react-remove-scroll-bar.mjs +82 -0
  109. package/admin-dist/server/_libs/react-remove-scroll.mjs +328 -0
  110. package/admin-dist/server/_libs/react-style-singleton.mjs +69 -0
  111. package/admin-dist/server/_libs/rou3.mjs +8 -0
  112. package/admin-dist/server/_libs/seroval-plugins.mjs +58 -0
  113. package/admin-dist/server/_libs/seroval.mjs +1765 -0
  114. package/admin-dist/server/_libs/srvx.mjs +719 -0
  115. package/admin-dist/server/_libs/tailwind-merge.mjs +3010 -0
  116. package/admin-dist/server/_libs/tiny-invariant.mjs +12 -0
  117. package/admin-dist/server/_libs/tiny-warning.mjs +5 -0
  118. package/admin-dist/server/_libs/tslib.mjs +39 -0
  119. package/admin-dist/server/_libs/ufo.mjs +54 -0
  120. package/admin-dist/server/_libs/unctx.mjs +1 -0
  121. package/admin-dist/server/_libs/unstorage.mjs +1 -0
  122. package/admin-dist/server/_libs/use-callback-ref.mjs +66 -0
  123. package/admin-dist/server/_libs/use-sidecar.mjs +106 -0
  124. package/admin-dist/server/_libs/use-sync-external-store.mjs +139 -0
  125. package/admin-dist/server/_libs/zod.mjs +4223 -0
  126. package/admin-dist/server/_ssr/CmsEmptyState-DU7-7-mV.mjs +290 -0
  127. package/admin-dist/server/_ssr/CmsPageHeader-CseW0AHm.mjs +24 -0
  128. package/admin-dist/server/_ssr/CmsStatusBadge-B_pi4KCp.mjs +127 -0
  129. package/admin-dist/server/_ssr/CmsToolbar-X75ex6ek.mjs +49 -0
  130. package/admin-dist/server/_ssr/ContentEntryEditor-CepusRsA.mjs +3720 -0
  131. package/admin-dist/server/_ssr/ErrorState-cI-bKLez.mjs +89 -0
  132. package/admin-dist/server/_ssr/TaxonomyFilter-Bwrq0-cz.mjs +188 -0
  133. package/admin-dist/server/_ssr/_contentTypeId-BqYKEcLr.mjs +379 -0
  134. package/admin-dist/server/_ssr/_entryId-CRfnqeDf.mjs +161 -0
  135. package/admin-dist/server/_ssr/_tanstack-start-manifest_v-BwDlABVk.mjs +4 -0
  136. package/admin-dist/server/_ssr/alert-CVt45UUP.mjs +92 -0
  137. package/admin-dist/server/_ssr/badge-6BsP37vG.mjs +125 -0
  138. package/admin-dist/server/_ssr/command-fy8epIKf.mjs +128 -0
  139. package/admin-dist/server/_ssr/config.server-D7JHDcDv.mjs +117 -0
  140. package/admin-dist/server/_ssr/content-B5RhL7uW.mjs +532 -0
  141. package/admin-dist/server/_ssr/content-types-BIOqCQYN.mjs +1166 -0
  142. package/admin-dist/server/_ssr/index-DHSHDPt1.mjs +193 -0
  143. package/admin-dist/server/_ssr/index.mjs +1275 -0
  144. package/admin-dist/server/_ssr/label-C8Dko1j7.mjs +22 -0
  145. package/admin-dist/server/_ssr/media-CSx3XttC.mjs +1832 -0
  146. package/admin-dist/server/_ssr/new._contentTypeId-DzanEZQM.mjs +144 -0
  147. package/admin-dist/server/_ssr/router-DDWcF-kt.mjs +1556 -0
  148. package/admin-dist/server/_ssr/scroll-area-bjPYwhXN.mjs +59 -0
  149. package/admin-dist/server/_ssr/select-BUhDDf4T.mjs +142 -0
  150. package/admin-dist/server/_ssr/settings-DAsxnw2q.mjs +348 -0
  151. package/admin-dist/server/_ssr/start-HYkvq4Ni.mjs +4 -0
  152. package/admin-dist/server/_ssr/switch-BgyRtQ1Z.mjs +31 -0
  153. package/admin-dist/server/_ssr/tabs-DzMdRB1A.mjs +628 -0
  154. package/admin-dist/server/_ssr/taxonomies-C8j8g5Q5.mjs +915 -0
  155. package/admin-dist/server/_ssr/textarea-9jNeYJSc.mjs +18 -0
  156. package/admin-dist/server/_ssr/trash-DYMxwhZB.mjs +291 -0
  157. package/admin-dist/server/_ssr/useBreadcrumbLabel-FNSAr2Ha.mjs +16 -0
  158. package/admin-dist/server/_ssr/usePermissions-BJGGahrJ.mjs +68 -0
  159. package/admin-dist/server/favicon.ico +0 -0
  160. package/admin-dist/server/index.mjs +627 -0
  161. package/dist/cli/index.js +0 -0
  162. package/dist/client/admin-config.d.ts +0 -1
  163. package/dist/client/admin-config.d.ts.map +1 -1
  164. package/dist/client/admin-config.js +0 -1
  165. package/dist/client/admin-config.js.map +1 -1
  166. package/dist/client/adminApi.d.ts.map +1 -1
  167. package/dist/client/agentTools.d.ts +1237 -135
  168. package/dist/client/agentTools.d.ts.map +1 -1
  169. package/dist/client/agentTools.js +33 -9
  170. package/dist/client/agentTools.js.map +1 -1
  171. package/dist/client/index.d.ts +1 -1
  172. package/dist/client/index.d.ts.map +1 -1
  173. package/dist/client/index.js.map +1 -1
  174. package/dist/component/_generated/component.d.ts +9 -0
  175. package/dist/component/_generated/component.d.ts.map +1 -1
  176. package/dist/component/mediaAssets.d.ts +35 -0
  177. package/dist/component/mediaAssets.d.ts.map +1 -1
  178. package/dist/component/mediaAssets.js +81 -0
  179. package/dist/component/mediaAssets.js.map +1 -1
  180. package/dist/test.d.ts.map +1 -1
  181. package/dist/test.js +2 -1
  182. package/dist/test.js.map +1 -1
  183. package/package.json +9 -5
  184. package/dist/component/auditLog.d.ts +0 -410
  185. package/dist/component/auditLog.d.ts.map +0 -1
  186. package/dist/component/auditLog.js +0 -607
  187. package/dist/component/auditLog.js.map +0 -1
  188. package/dist/component/types.d.ts +0 -4
  189. package/dist/component/types.d.ts.map +0 -1
  190. package/dist/component/types.js +0 -2
  191. package/dist/component/types.js.map +0 -1
  192. package/src/cli/commands/admin.ts +0 -104
  193. package/src/cli/index.ts +0 -21
  194. package/src/cli/utils/detectConvexUrl.ts +0 -54
  195. package/src/cli/utils/openBrowser.ts +0 -16
  196. package/src/client/admin-config.ts +0 -138
  197. package/src/client/adminApi.ts +0 -942
  198. package/src/client/agentTools.ts +0 -1311
  199. package/src/client/argTypes.ts +0 -316
  200. package/src/client/field-types.ts +0 -187
  201. package/src/client/index.ts +0 -1301
  202. package/src/client/queryBuilder.ts +0 -1100
  203. package/src/client/schema/codegen.ts +0 -500
  204. package/src/client/schema/defineContentType.ts +0 -501
  205. package/src/client/schema/index.ts +0 -169
  206. package/src/client/schema/schemaDrift.ts +0 -574
  207. package/src/client/schema/typedClient.ts +0 -688
  208. package/src/client/schema/types.ts +0 -666
  209. package/src/client/types.ts +0 -723
  210. package/src/client/workflows.ts +0 -141
  211. package/src/client/wrapper.ts +0 -4304
  212. package/src/component/_generated/api.ts +0 -140
  213. package/src/component/_generated/component.ts +0 -5029
  214. package/src/component/_generated/dataModel.ts +0 -60
  215. package/src/component/_generated/server.ts +0 -156
  216. package/src/component/authorization.ts +0 -647
  217. package/src/component/authorizationHooks.ts +0 -668
  218. package/src/component/bulkOperations.ts +0 -687
  219. package/src/component/contentEntries.ts +0 -1976
  220. package/src/component/contentEntryMutations.ts +0 -1223
  221. package/src/component/contentEntryValidation.ts +0 -707
  222. package/src/component/contentLock.ts +0 -550
  223. package/src/component/contentTypeMigration.ts +0 -1064
  224. package/src/component/contentTypeMutations.ts +0 -969
  225. package/src/component/contentTypes.ts +0 -346
  226. package/src/component/convex.config.ts +0 -44
  227. package/src/component/documentTypes.ts +0 -240
  228. package/src/component/eventEmitter.ts +0 -485
  229. package/src/component/exportImport.ts +0 -1169
  230. package/src/component/index.ts +0 -491
  231. package/src/component/lib/deepReferenceResolver.ts +0 -999
  232. package/src/component/lib/errors.ts +0 -816
  233. package/src/component/lib/index.ts +0 -145
  234. package/src/component/lib/mediaReferenceResolver.ts +0 -495
  235. package/src/component/lib/metadataExtractor.ts +0 -792
  236. package/src/component/lib/mutationAuth.ts +0 -199
  237. package/src/component/lib/queries.ts +0 -79
  238. package/src/component/lib/ragContentChunker.ts +0 -1371
  239. package/src/component/lib/referenceResolver.ts +0 -430
  240. package/src/component/lib/slugGenerator.ts +0 -262
  241. package/src/component/lib/slugUniqueness.ts +0 -333
  242. package/src/component/lib/softDelete.ts +0 -44
  243. package/src/component/localeFallbackChain.ts +0 -673
  244. package/src/component/localeFields.ts +0 -896
  245. package/src/component/mediaAssetMutations.ts +0 -725
  246. package/src/component/mediaAssets.ts +0 -932
  247. package/src/component/mediaFolderMutations.ts +0 -1046
  248. package/src/component/mediaUploadMutations.ts +0 -224
  249. package/src/component/mediaVariantMutations.ts +0 -900
  250. package/src/component/mediaVariants.ts +0 -793
  251. package/src/component/ragContentIndexer.ts +0 -1067
  252. package/src/component/rateLimitHooks.ts +0 -572
  253. package/src/component/roles.ts +0 -1360
  254. package/src/component/scheduledPublish.ts +0 -358
  255. package/src/component/schema.ts +0 -617
  256. package/src/component/taxonomies.ts +0 -949
  257. package/src/component/taxonomyMutations.ts +0 -1210
  258. package/src/component/trash.ts +0 -724
  259. package/src/component/userContext.ts +0 -898
  260. package/src/component/validation.ts +0 -1388
  261. package/src/component/validators.ts +0 -949
  262. package/src/component/versionMutations.ts +0 -392
  263. package/src/component/webhookTrigger.ts +0 -1922
  264. package/src/react/index.ts +0 -898
  265. package/src/test.ts +0 -1580
@@ -1,574 +0,0 @@
1
- /**
2
- * Schema Drift Detection
3
- *
4
- * Compares code-defined schemas against database schemas to detect
5
- * discrepancies that could cause runtime issues.
6
- *
7
- * @example
8
- * ```typescript
9
- * import { detectSchemaDrift } from "@convex-cms/core";
10
- *
11
- * const report = await detectSchemaDrift(ctx, cms, contentSchema);
12
- *
13
- * if (report.hasDrift) {
14
- * console.warn("Schema drift detected:");
15
- * console.log(report.summary);
16
- *
17
- * for (const diff of report.fieldDifferences) {
18
- * console.log(`${diff.contentType}.${diff.field}: ${diff.message}`);
19
- * }
20
- * }
21
- * ```
22
- */
23
-
24
- import type { ContentTypeDefinition } from "./types.js";
25
- import type { ContentSchemaInstance } from "./defineContentType.js";
26
- import { toFieldDefinitions, type DatabaseFieldDefinition } from "./defineContentType.js";
27
- import type { ConvexContext } from "../wrapper.js";
28
- import type { CmsClient } from "../wrapper.js";
29
- import type { ContentType, FieldDefinition } from "../types.js";
30
-
31
- // =============================================================================
32
- // Types
33
- // =============================================================================
34
-
35
- /**
36
- * Severity level for drift issues.
37
- */
38
- export type DriftSeverity = "error" | "warning" | "info";
39
-
40
- /**
41
- * Type of schema difference detected.
42
- */
43
- export type DriftType =
44
- | "CONTENT_TYPE_MISSING_IN_DB"
45
- | "CONTENT_TYPE_MISSING_IN_CODE"
46
- | "FIELD_MISSING_IN_DB"
47
- | "FIELD_MISSING_IN_CODE"
48
- | "FIELD_TYPE_MISMATCH"
49
- | "FIELD_REQUIRED_MISMATCH"
50
- | "FIELD_OPTIONS_MISMATCH"
51
- | "CONTENT_TYPE_METADATA_MISMATCH";
52
-
53
- /**
54
- * A single schema drift issue.
55
- */
56
- export interface DriftIssue {
57
- /**
58
- * Type of drift detected.
59
- */
60
- type: DriftType;
61
-
62
- /**
63
- * Severity level.
64
- */
65
- severity: DriftSeverity;
66
-
67
- /**
68
- * Content type name involved.
69
- */
70
- contentType: string;
71
-
72
- /**
73
- * Field name (if applicable).
74
- */
75
- field?: string;
76
-
77
- /**
78
- * Human-readable description of the issue.
79
- */
80
- message: string;
81
-
82
- /**
83
- * Expected value (from code).
84
- */
85
- expected?: unknown;
86
-
87
- /**
88
- * Actual value (from database).
89
- */
90
- actual?: unknown;
91
- }
92
-
93
- /**
94
- * Summary statistics for the drift report.
95
- */
96
- export interface DriftSummary {
97
- /**
98
- * Number of content types only in code (not in database).
99
- */
100
- missingInDatabase: number;
101
-
102
- /**
103
- * Number of content types only in database (not in code).
104
- */
105
- missingInCode: number;
106
-
107
- /**
108
- * Number of field-level differences.
109
- */
110
- fieldDifferences: number;
111
-
112
- /**
113
- * Total number of issues found.
114
- */
115
- totalIssues: number;
116
-
117
- /**
118
- * Number of error-level issues.
119
- */
120
- errors: number;
121
-
122
- /**
123
- * Number of warning-level issues.
124
- */
125
- warnings: number;
126
- }
127
-
128
- /**
129
- * Full schema drift detection report.
130
- */
131
- export interface SchemaDriftReport {
132
- /**
133
- * Whether any drift was detected.
134
- */
135
- hasDrift: boolean;
136
-
137
- /**
138
- * Summary statistics.
139
- */
140
- summary: DriftSummary;
141
-
142
- /**
143
- * All detected issues.
144
- */
145
- issues: DriftIssue[];
146
-
147
- /**
148
- * Content types defined in code but not in database.
149
- */
150
- missingInDatabase: string[];
151
-
152
- /**
153
- * Content types in database but not in code.
154
- */
155
- missingInCode: string[];
156
-
157
- /**
158
- * Timestamp when the check was performed.
159
- */
160
- checkedAt: number;
161
- }
162
-
163
- /**
164
- * Options for drift detection.
165
- */
166
- export interface DetectDriftOptions {
167
- /**
168
- * Whether to include info-level issues in the report.
169
- * @default false
170
- */
171
- includeInfoLevel?: boolean;
172
-
173
- /**
174
- * Content type names to check. If not provided, checks all.
175
- */
176
- contentTypes?: string[];
177
-
178
- /**
179
- * Whether to treat missing-in-database as errors.
180
- * When true, code types not in DB are errors; when false, they're warnings.
181
- * @default true
182
- */
183
- strictMissingInDb?: boolean;
184
-
185
- /**
186
- * Whether to treat missing-in-code as errors.
187
- * When false, DB types not in code are warnings (allows admin-created types).
188
- * @default false
189
- */
190
- strictMissingInCode?: boolean;
191
- }
192
-
193
- // =============================================================================
194
- // Detection Functions
195
- // =============================================================================
196
-
197
- /**
198
- * Detects schema drift between code-defined schemas and database state.
199
- *
200
- * @param ctx - Convex context
201
- * @param cmsClient - The CMS client to use for database queries
202
- * @param schema - The code-defined content schema
203
- * @param options - Detection options
204
- * @returns A drift report with all detected issues
205
- *
206
- * @example
207
- * ```typescript
208
- * const report = await detectSchemaDrift(ctx, cms, contentSchema);
209
- *
210
- * if (report.hasDrift) {
211
- * console.error("Schema drift detected!");
212
- * console.log(`Errors: ${report.summary.errors}`);
213
- * console.log(`Warnings: ${report.summary.warnings}`);
214
- *
215
- * for (const issue of report.issues) {
216
- * console.log(`[${issue.severity}] ${issue.message}`);
217
- * }
218
- * }
219
- * ```
220
- */
221
- export async function detectSchemaDrift<
222
- TSchema extends ContentSchemaInstance<Record<string, ContentTypeDefinition>>
223
- >(
224
- ctx: ConvexContext,
225
- cmsClient: CmsClient,
226
- schema: TSchema,
227
- options: DetectDriftOptions = {}
228
- ): Promise<SchemaDriftReport> {
229
- const {
230
- includeInfoLevel = false,
231
- contentTypes: filterTypes,
232
- strictMissingInDb = true,
233
- strictMissingInCode = false,
234
- } = options;
235
-
236
- const issues: DriftIssue[] = [];
237
- const missingInDatabase: string[] = [];
238
- const missingInCode: string[] = [];
239
-
240
- // Get all content types from database
241
- const dbTypes = await cmsClient.contentTypes.getAll(ctx);
242
- const dbTypeMap = new Map(dbTypes.map((t) => [t.name, t]));
243
-
244
- // Get code-defined content types
245
- const codeDefinitions = Object.values(schema.definitions) as ContentTypeDefinition[];
246
- const codeTypeNames = new Set(codeDefinitions.map((d) => d.name));
247
-
248
- // Filter if specific types requested
249
- const typesToCheck = filterTypes
250
- ? codeDefinitions.filter((d) => filterTypes.includes(d.name))
251
- : codeDefinitions;
252
-
253
- // Check code types against database
254
- for (const codeDef of typesToCheck) {
255
- const dbType = dbTypeMap.get(codeDef.name);
256
-
257
- if (!dbType) {
258
- // Code type not in database
259
- missingInDatabase.push(codeDef.name);
260
- issues.push({
261
- type: "CONTENT_TYPE_MISSING_IN_DB",
262
- severity: strictMissingInDb ? "error" : "warning",
263
- contentType: codeDef.name,
264
- message: `Content type "${codeDef.name}" is defined in code but not registered in the database`,
265
- });
266
- continue;
267
- }
268
-
269
- // Compare fields
270
- const codeFields = toFieldDefinitions(codeDef);
271
- const fieldIssues = compareFields(codeDef.name, codeFields, dbType.fields);
272
- issues.push(...fieldIssues);
273
-
274
- // Compare metadata (info level)
275
- if (includeInfoLevel) {
276
- const metaIssues = compareMetadata(codeDef, dbType);
277
- issues.push(...metaIssues);
278
- }
279
- }
280
-
281
- // Check for database types not in code
282
- const dbTypeNames = filterTypes
283
- ? dbTypes.filter((t) => filterTypes.includes(t.name)).map((t) => t.name)
284
- : dbTypes.map((t) => t.name);
285
-
286
- for (const dbTypeName of dbTypeNames) {
287
- if (!codeTypeNames.has(dbTypeName)) {
288
- missingInCode.push(dbTypeName);
289
- issues.push({
290
- type: "CONTENT_TYPE_MISSING_IN_CODE",
291
- severity: strictMissingInCode ? "error" : "warning",
292
- contentType: dbTypeName,
293
- message: `Content type "${dbTypeName}" exists in database but is not defined in code`,
294
- });
295
- }
296
- }
297
-
298
- // Calculate summary
299
- const summary: DriftSummary = {
300
- missingInDatabase: missingInDatabase.length,
301
- missingInCode: missingInCode.length,
302
- fieldDifferences: issues.filter((i) => i.field !== undefined).length,
303
- totalIssues: issues.length,
304
- errors: issues.filter((i) => i.severity === "error").length,
305
- warnings: issues.filter((i) => i.severity === "warning").length,
306
- };
307
-
308
- return {
309
- hasDrift: issues.length > 0,
310
- summary,
311
- issues: includeInfoLevel ? issues : issues.filter((i) => i.severity !== "info"),
312
- missingInDatabase,
313
- missingInCode,
314
- checkedAt: Date.now(),
315
- };
316
- }
317
-
318
- /**
319
- * Compare field definitions between code and database.
320
- */
321
- function compareFields(
322
- contentTypeName: string,
323
- codeFields: DatabaseFieldDefinition[],
324
- dbFields: FieldDefinition[]
325
- ): DriftIssue[] {
326
- const issues: DriftIssue[] = [];
327
-
328
- const codeFieldMap = new Map(codeFields.map((f) => [f.name, f]));
329
- const dbFieldMap = new Map(dbFields.map((f) => [f.name, f]));
330
-
331
- // Check code fields against database
332
- for (const codeField of codeFields) {
333
- const dbField = dbFieldMap.get(codeField.name);
334
-
335
- if (!dbField) {
336
- issues.push({
337
- type: "FIELD_MISSING_IN_DB",
338
- severity: "error",
339
- contentType: contentTypeName,
340
- field: codeField.name,
341
- message: `Field "${codeField.name}" is defined in code but not in the database schema`,
342
- });
343
- continue;
344
- }
345
-
346
- // Check type
347
- if (codeField.type !== dbField.type) {
348
- issues.push({
349
- type: "FIELD_TYPE_MISMATCH",
350
- severity: "error",
351
- contentType: contentTypeName,
352
- field: codeField.name,
353
- message: `Field "${codeField.name}" type mismatch: code expects "${codeField.type}", database has "${dbField.type}"`,
354
- expected: codeField.type,
355
- actual: dbField.type,
356
- });
357
- }
358
-
359
- // Check required
360
- if (codeField.required !== dbField.required) {
361
- issues.push({
362
- type: "FIELD_REQUIRED_MISMATCH",
363
- severity: "warning",
364
- contentType: contentTypeName,
365
- field: codeField.name,
366
- message: `Field "${codeField.name}" required mismatch: code expects ${codeField.required ? "required" : "optional"}, database has ${dbField.required ? "required" : "optional"}`,
367
- expected: codeField.required,
368
- actual: dbField.required,
369
- });
370
- }
371
-
372
- // Check options (selective comparison)
373
- // Cast to Record<string, unknown> since FieldOptions shape may vary
374
- const optionsDiff = compareFieldOptions(
375
- codeField.options as Record<string, unknown> | undefined,
376
- dbField.options as Record<string, unknown> | undefined
377
- );
378
- if (optionsDiff) {
379
- issues.push({
380
- type: "FIELD_OPTIONS_MISMATCH",
381
- severity: "warning",
382
- contentType: contentTypeName,
383
- field: codeField.name,
384
- message: `Field "${codeField.name}" has different options: ${optionsDiff}`,
385
- });
386
- }
387
- }
388
-
389
- // Check for fields in database not in code
390
- for (const dbField of dbFields) {
391
- if (!codeFieldMap.has(dbField.name)) {
392
- issues.push({
393
- type: "FIELD_MISSING_IN_CODE",
394
- severity: "warning",
395
- contentType: contentTypeName,
396
- field: dbField.name,
397
- message: `Field "${dbField.name}" exists in database but is not defined in code`,
398
- });
399
- }
400
- }
401
-
402
- return issues;
403
- }
404
-
405
- /**
406
- * Compare field options and return a description of differences.
407
- */
408
- function compareFieldOptions(
409
- codeOptions: Record<string, unknown> | undefined,
410
- dbOptions: Record<string, unknown> | undefined
411
- ): string | null {
412
- if (!codeOptions && !dbOptions) return null;
413
- if (!codeOptions && dbOptions) return "database has options, code does not";
414
- if (codeOptions && !dbOptions) return "code has options, database does not";
415
-
416
- const differences: string[] = [];
417
-
418
- // Check for important option differences
419
- const importantOptions = [
420
- "minLength",
421
- "maxLength",
422
- "min",
423
- "max",
424
- "pattern",
425
- "allowedContentTypes",
426
- "allowedMimeTypes",
427
- "multiple",
428
- "options", // for select fields
429
- ];
430
-
431
- for (const key of importantOptions) {
432
- const codeValue = codeOptions![key];
433
- const dbValue = dbOptions![key];
434
-
435
- if (codeValue !== undefined && dbValue === undefined) {
436
- differences.push(`${key} missing in database`);
437
- } else if (codeValue === undefined && dbValue !== undefined) {
438
- differences.push(`${key} missing in code`);
439
- } else if (JSON.stringify(codeValue) !== JSON.stringify(dbValue)) {
440
- differences.push(`${key} differs`);
441
- }
442
- }
443
-
444
- return differences.length > 0 ? differences.join(", ") : null;
445
- }
446
-
447
- /**
448
- * Compare content type metadata.
449
- */
450
- function compareMetadata(
451
- codeDef: ContentTypeDefinition,
452
- dbType: ContentType
453
- ): DriftIssue[] {
454
- const issues: DriftIssue[] = [];
455
-
456
- if (codeDef.meta?.displayName && codeDef.meta.displayName !== dbType.displayName) {
457
- issues.push({
458
- type: "CONTENT_TYPE_METADATA_MISMATCH",
459
- severity: "info",
460
- contentType: codeDef.name,
461
- message: `Display name mismatch: code has "${codeDef.meta.displayName}", database has "${dbType.displayName}"`,
462
- expected: codeDef.meta.displayName,
463
- actual: dbType.displayName,
464
- });
465
- }
466
-
467
- if (codeDef.meta?.titleField && codeDef.meta.titleField !== dbType.titleField) {
468
- issues.push({
469
- type: "CONTENT_TYPE_METADATA_MISMATCH",
470
- severity: "info",
471
- contentType: codeDef.name,
472
- message: `Title field mismatch: code has "${codeDef.meta.titleField}", database has "${dbType.titleField}"`,
473
- expected: codeDef.meta.titleField,
474
- actual: dbType.titleField,
475
- });
476
- }
477
-
478
- return issues;
479
- }
480
-
481
- // =============================================================================
482
- // Formatting Utilities
483
- // =============================================================================
484
-
485
- /**
486
- * Format a drift report as a human-readable string.
487
- *
488
- * @param report - The drift report to format
489
- * @returns A formatted string suitable for console output
490
- */
491
- export function formatDriftReport(report: SchemaDriftReport): string {
492
- if (!report.hasDrift) {
493
- return "No schema drift detected. Code and database schemas are in sync.";
494
- }
495
-
496
- const lines: string[] = [
497
- "Schema Drift Report",
498
- "===================",
499
- "",
500
- `Total Issues: ${report.summary.totalIssues}`,
501
- ` Errors: ${report.summary.errors}`,
502
- ` Warnings: ${report.summary.warnings}`,
503
- "",
504
- ];
505
-
506
- if (report.missingInDatabase.length > 0) {
507
- lines.push("Content Types Missing in Database:");
508
- for (const name of report.missingInDatabase) {
509
- lines.push(` - ${name}`);
510
- }
511
- lines.push("");
512
- }
513
-
514
- if (report.missingInCode.length > 0) {
515
- lines.push("Content Types Missing in Code:");
516
- for (const name of report.missingInCode) {
517
- lines.push(` - ${name}`);
518
- }
519
- lines.push("");
520
- }
521
-
522
- const fieldIssues = report.issues.filter((i) => i.field);
523
- if (fieldIssues.length > 0) {
524
- lines.push("Field Differences:");
525
- for (const issue of fieldIssues) {
526
- const prefix = issue.severity === "error" ? "[ERROR]" : "[WARN]";
527
- lines.push(` ${prefix} ${issue.contentType}.${issue.field}: ${issue.message}`);
528
- }
529
- }
530
-
531
- return lines.join("\n");
532
- }
533
-
534
- /**
535
- * Check if a drift report h errors (not just warnings).
536
- *
537
- * @param report - The drift report to check
538
- * @returns true if there are error-level issues
539
- */
540
- export function hasErrors(report: SchemaDriftReport): boolean {
541
- return report.summary.errors > 0;
542
- }
543
-
544
- /**
545
- * Filter a drift report to only include specific content types.
546
- *
547
- * @param report - The full drift report
548
- * @param contentTypes - Content type names to include
549
- * @returns A filtered report
550
- */
551
- export function filterReportByContentTypes(
552
- report: SchemaDriftReport,
553
- contentTypes: string[]
554
- ): SchemaDriftReport {
555
- const typeSet = new Set(contentTypes);
556
-
557
- const filteredIssues = report.issues.filter((i) => typeSet.has(i.contentType));
558
-
559
- return {
560
- ...report,
561
- issues: filteredIssues,
562
- missingInDatabase: report.missingInDatabase.filter((n) => typeSet.has(n)),
563
- missingInCode: report.missingInCode.filter((n) => typeSet.has(n)),
564
- summary: {
565
- missingInDatabase: report.missingInDatabase.filter((n) => typeSet.has(n)).length,
566
- missingInCode: report.missingInCode.filter((n) => typeSet.has(n)).length,
567
- fieldDifferences: filteredIssues.filter((i) => i.field !== undefined).length,
568
- totalIssues: filteredIssues.length,
569
- errors: filteredIssues.filter((i) => i.severity === "error").length,
570
- warnings: filteredIssues.filter((i) => i.severity === "warning").length,
571
- },
572
- hasDrift: filteredIssues.length > 0,
573
- };
574
- }