convex-cms 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands/admin.d.ts +16 -0
- package/dist/cli/commands/admin.d.ts.map +1 -0
- package/dist/cli/commands/admin.js +88 -0
- package/dist/cli/commands/admin.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +18 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/utils/detectConvexUrl.d.ts +13 -0
- package/dist/cli/utils/detectConvexUrl.d.ts.map +1 -0
- package/dist/cli/utils/detectConvexUrl.js +48 -0
- package/dist/cli/utils/detectConvexUrl.js.map +1 -0
- package/dist/cli/utils/openBrowser.d.ts +7 -0
- package/dist/cli/utils/openBrowser.d.ts.map +1 -0
- package/dist/cli/utils/openBrowser.js +17 -0
- package/dist/cli/utils/openBrowser.js.map +1 -0
- package/dist/client/admin-config.d.ts +126 -0
- package/dist/client/admin-config.d.ts.map +1 -0
- package/dist/client/admin-config.js +117 -0
- package/dist/client/admin-config.js.map +1 -0
- package/dist/client/adminApi.d.ts +2273 -0
- package/dist/client/adminApi.d.ts.map +1 -0
- package/dist/client/adminApi.js +716 -0
- package/dist/client/adminApi.js.map +1 -0
- package/dist/client/agentTools.d.ts +933 -0
- package/dist/client/agentTools.d.ts.map +1 -0
- package/dist/client/agentTools.js +1004 -0
- package/dist/client/agentTools.js.map +1 -0
- package/dist/client/argTypes.d.ts +212 -0
- package/dist/client/argTypes.d.ts.map +1 -0
- package/dist/client/argTypes.js +5 -0
- package/dist/client/argTypes.js.map +1 -0
- package/dist/client/field-types.d.ts +55 -0
- package/dist/client/field-types.d.ts.map +1 -0
- package/dist/client/field-types.js +152 -0
- package/dist/client/field-types.js.map +1 -0
- package/dist/client/index.d.ts +189 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +668 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/queryBuilder.d.ts +765 -0
- package/dist/client/queryBuilder.d.ts.map +1 -0
- package/dist/client/queryBuilder.js +970 -0
- package/dist/client/queryBuilder.js.map +1 -0
- package/dist/client/schema/codegen.d.ts +128 -0
- package/dist/client/schema/codegen.d.ts.map +1 -0
- package/dist/client/schema/codegen.js +318 -0
- package/dist/client/schema/codegen.js.map +1 -0
- package/dist/client/schema/defineContentType.d.ts +221 -0
- package/dist/client/schema/defineContentType.d.ts.map +1 -0
- package/dist/client/schema/defineContentType.js +380 -0
- package/dist/client/schema/defineContentType.js.map +1 -0
- package/dist/client/schema/index.d.ts +85 -0
- package/dist/client/schema/index.d.ts.map +1 -0
- package/dist/client/schema/index.js +92 -0
- package/dist/client/schema/index.js.map +1 -0
- package/dist/client/schema/schemaDrift.d.ts +199 -0
- package/dist/client/schema/schemaDrift.d.ts.map +1 -0
- package/dist/client/schema/schemaDrift.js +340 -0
- package/dist/client/schema/schemaDrift.js.map +1 -0
- package/dist/client/schema/typedClient.d.ts +401 -0
- package/dist/client/schema/typedClient.d.ts.map +1 -0
- package/dist/client/schema/typedClient.js +269 -0
- package/dist/client/schema/typedClient.js.map +1 -0
- package/dist/client/schema/types.d.ts +477 -0
- package/dist/client/schema/types.d.ts.map +1 -0
- package/dist/client/schema/types.js +39 -0
- package/dist/client/schema/types.js.map +1 -0
- package/dist/client/types.d.ts +449 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +149 -0
- package/dist/client/types.js.map +1 -0
- package/dist/client/workflows.d.ts +51 -0
- package/dist/client/workflows.d.ts.map +1 -0
- package/dist/client/workflows.js +103 -0
- package/dist/client/workflows.js.map +1 -0
- package/dist/client/wrapper.d.ts +2198 -0
- package/dist/client/wrapper.d.ts.map +1 -0
- package/dist/client/wrapper.js +2651 -0
- package/dist/client/wrapper.js.map +1 -0
- package/dist/component/_generated/api.d.ts +124 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +4321 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +121 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +78 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/auditLog.d.ts +410 -0
- package/dist/component/auditLog.d.ts.map +1 -0
- package/dist/component/auditLog.js +607 -0
- package/dist/component/auditLog.js.map +1 -0
- package/dist/component/authorization.d.ts +323 -0
- package/dist/component/authorization.d.ts.map +1 -0
- package/dist/component/authorization.js +464 -0
- package/dist/component/authorization.js.map +1 -0
- package/dist/component/authorizationHooks.d.ts +184 -0
- package/dist/component/authorizationHooks.d.ts.map +1 -0
- package/dist/component/authorizationHooks.js +521 -0
- package/dist/component/authorizationHooks.js.map +1 -0
- package/dist/component/bulkOperations.d.ts +200 -0
- package/dist/component/bulkOperations.d.ts.map +1 -0
- package/dist/component/bulkOperations.js +568 -0
- package/dist/component/bulkOperations.js.map +1 -0
- package/dist/component/contentEntries.d.ts +719 -0
- package/dist/component/contentEntries.d.ts.map +1 -0
- package/dist/component/contentEntries.js +1617 -0
- package/dist/component/contentEntries.js.map +1 -0
- package/dist/component/contentEntryMutations.d.ts +505 -0
- package/dist/component/contentEntryMutations.d.ts.map +1 -0
- package/dist/component/contentEntryMutations.js +1009 -0
- package/dist/component/contentEntryMutations.js.map +1 -0
- package/dist/component/contentEntryValidation.d.ts +115 -0
- package/dist/component/contentEntryValidation.d.ts.map +1 -0
- package/dist/component/contentEntryValidation.js +546 -0
- package/dist/component/contentEntryValidation.js.map +1 -0
- package/dist/component/contentLock.d.ts +328 -0
- package/dist/component/contentLock.d.ts.map +1 -0
- package/dist/component/contentLock.js +471 -0
- package/dist/component/contentLock.js.map +1 -0
- package/dist/component/contentTypeMigration.d.ts +411 -0
- package/dist/component/contentTypeMigration.d.ts.map +1 -0
- package/dist/component/contentTypeMigration.js +805 -0
- package/dist/component/contentTypeMigration.js.map +1 -0
- package/dist/component/contentTypeMutations.d.ts +975 -0
- package/dist/component/contentTypeMutations.d.ts.map +1 -0
- package/dist/component/contentTypeMutations.js +768 -0
- package/dist/component/contentTypeMutations.js.map +1 -0
- package/dist/component/contentTypes.d.ts +538 -0
- package/dist/component/contentTypes.d.ts.map +1 -0
- package/dist/component/contentTypes.js +304 -0
- package/dist/component/contentTypes.js.map +1 -0
- package/dist/component/convex.config.d.ts +42 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +43 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/documentTypes.d.ts +186 -0
- package/dist/component/documentTypes.d.ts.map +1 -0
- package/dist/component/documentTypes.js +23 -0
- package/dist/component/documentTypes.js.map +1 -0
- package/dist/component/eventEmitter.d.ts +281 -0
- package/dist/component/eventEmitter.d.ts.map +1 -0
- package/dist/component/eventEmitter.js +300 -0
- package/dist/component/eventEmitter.js.map +1 -0
- package/dist/component/exportImport.d.ts +1120 -0
- package/dist/component/exportImport.d.ts.map +1 -0
- package/dist/component/exportImport.js +931 -0
- package/dist/component/exportImport.js.map +1 -0
- package/dist/component/index.d.ts +28 -0
- package/dist/component/index.d.ts.map +1 -0
- package/dist/component/index.js +142 -0
- package/dist/component/index.js.map +1 -0
- package/dist/component/lib/deepReferenceResolver.d.ts +252 -0
- package/dist/component/lib/deepReferenceResolver.d.ts.map +1 -0
- package/dist/component/lib/deepReferenceResolver.js +601 -0
- package/dist/component/lib/deepReferenceResolver.js.map +1 -0
- package/dist/component/lib/errors.d.ts +306 -0
- package/dist/component/lib/errors.d.ts.map +1 -0
- package/dist/component/lib/errors.js +407 -0
- package/dist/component/lib/errors.js.map +1 -0
- package/dist/component/lib/index.d.ts +10 -0
- package/dist/component/lib/index.d.ts.map +1 -0
- package/dist/component/lib/index.js +33 -0
- package/dist/component/lib/index.js.map +1 -0
- package/dist/component/lib/mediaReferenceResolver.d.ts +217 -0
- package/dist/component/lib/mediaReferenceResolver.d.ts.map +1 -0
- package/dist/component/lib/mediaReferenceResolver.js +326 -0
- package/dist/component/lib/mediaReferenceResolver.js.map +1 -0
- package/dist/component/lib/metadataExtractor.d.ts +245 -0
- package/dist/component/lib/metadataExtractor.d.ts.map +1 -0
- package/dist/component/lib/metadataExtractor.js +548 -0
- package/dist/component/lib/metadataExtractor.js.map +1 -0
- package/dist/component/lib/mutationAuth.d.ts +95 -0
- package/dist/component/lib/mutationAuth.d.ts.map +1 -0
- package/dist/component/lib/mutationAuth.js +146 -0
- package/dist/component/lib/mutationAuth.js.map +1 -0
- package/dist/component/lib/queries.d.ts +17 -0
- package/dist/component/lib/queries.d.ts.map +1 -0
- package/dist/component/lib/queries.js +49 -0
- package/dist/component/lib/queries.js.map +1 -0
- package/dist/component/lib/ragContentChunker.d.ts +423 -0
- package/dist/component/lib/ragContentChunker.d.ts.map +1 -0
- package/dist/component/lib/ragContentChunker.js +897 -0
- package/dist/component/lib/ragContentChunker.js.map +1 -0
- package/dist/component/lib/referenceResolver.d.ts +175 -0
- package/dist/component/lib/referenceResolver.d.ts.map +1 -0
- package/dist/component/lib/referenceResolver.js +293 -0
- package/dist/component/lib/referenceResolver.js.map +1 -0
- package/dist/component/lib/slugGenerator.d.ts +71 -0
- package/dist/component/lib/slugGenerator.d.ts.map +1 -0
- package/dist/component/lib/slugGenerator.js +207 -0
- package/dist/component/lib/slugGenerator.js.map +1 -0
- package/dist/component/lib/slugUniqueness.d.ts +131 -0
- package/dist/component/lib/slugUniqueness.d.ts.map +1 -0
- package/dist/component/lib/slugUniqueness.js +229 -0
- package/dist/component/lib/slugUniqueness.js.map +1 -0
- package/dist/component/lib/softDelete.d.ts +18 -0
- package/dist/component/lib/softDelete.d.ts.map +1 -0
- package/dist/component/lib/softDelete.js +29 -0
- package/dist/component/lib/softDelete.js.map +1 -0
- package/dist/component/localeFallbackChain.d.ts +410 -0
- package/dist/component/localeFallbackChain.d.ts.map +1 -0
- package/dist/component/localeFallbackChain.js +467 -0
- package/dist/component/localeFallbackChain.js.map +1 -0
- package/dist/component/localeFields.d.ts +508 -0
- package/dist/component/localeFields.d.ts.map +1 -0
- package/dist/component/localeFields.js +592 -0
- package/dist/component/localeFields.js.map +1 -0
- package/dist/component/mediaAssetMutations.d.ts +235 -0
- package/dist/component/mediaAssetMutations.d.ts.map +1 -0
- package/dist/component/mediaAssetMutations.js +558 -0
- package/dist/component/mediaAssetMutations.js.map +1 -0
- package/dist/component/mediaAssets.d.ts +168 -0
- package/dist/component/mediaAssets.d.ts.map +1 -0
- package/dist/component/mediaAssets.js +618 -0
- package/dist/component/mediaAssets.js.map +1 -0
- package/dist/component/mediaFolderMutations.d.ts +642 -0
- package/dist/component/mediaFolderMutations.d.ts.map +1 -0
- package/dist/component/mediaFolderMutations.js +849 -0
- package/dist/component/mediaFolderMutations.js.map +1 -0
- package/dist/component/mediaUploadMutations.d.ts +136 -0
- package/dist/component/mediaUploadMutations.d.ts.map +1 -0
- package/dist/component/mediaUploadMutations.js +205 -0
- package/dist/component/mediaUploadMutations.js.map +1 -0
- package/dist/component/mediaVariantMutations.d.ts +468 -0
- package/dist/component/mediaVariantMutations.d.ts.map +1 -0
- package/dist/component/mediaVariantMutations.js +737 -0
- package/dist/component/mediaVariantMutations.js.map +1 -0
- package/dist/component/mediaVariants.d.ts +525 -0
- package/dist/component/mediaVariants.d.ts.map +1 -0
- package/dist/component/mediaVariants.js +661 -0
- package/dist/component/mediaVariants.js.map +1 -0
- package/dist/component/ragContentIndexer.d.ts +595 -0
- package/dist/component/ragContentIndexer.d.ts.map +1 -0
- package/dist/component/ragContentIndexer.js +794 -0
- package/dist/component/ragContentIndexer.js.map +1 -0
- package/dist/component/rateLimitHooks.d.ts +266 -0
- package/dist/component/rateLimitHooks.d.ts.map +1 -0
- package/dist/component/rateLimitHooks.js +412 -0
- package/dist/component/rateLimitHooks.js.map +1 -0
- package/dist/component/roles.d.ts +649 -0
- package/dist/component/roles.d.ts.map +1 -0
- package/dist/component/roles.js +884 -0
- package/dist/component/roles.js.map +1 -0
- package/dist/component/scheduledPublish.d.ts +182 -0
- package/dist/component/scheduledPublish.d.ts.map +1 -0
- package/dist/component/scheduledPublish.js +304 -0
- package/dist/component/scheduledPublish.js.map +1 -0
- package/dist/component/schema.d.ts +4114 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +469 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/component/taxonomies.d.ts +476 -0
- package/dist/component/taxonomies.d.ts.map +1 -0
- package/dist/component/taxonomies.js +785 -0
- package/dist/component/taxonomies.js.map +1 -0
- package/dist/component/taxonomyMutations.d.ts +206 -0
- package/dist/component/taxonomyMutations.d.ts.map +1 -0
- package/dist/component/taxonomyMutations.js +1001 -0
- package/dist/component/taxonomyMutations.js.map +1 -0
- package/dist/component/trash.d.ts +265 -0
- package/dist/component/trash.d.ts.map +1 -0
- package/dist/component/trash.js +621 -0
- package/dist/component/trash.js.map +1 -0
- package/dist/component/types.d.ts +4 -0
- package/dist/component/types.d.ts.map +1 -0
- package/dist/component/types.js +2 -0
- package/dist/component/types.js.map +1 -0
- package/dist/component/userContext.d.ts +508 -0
- package/dist/component/userContext.d.ts.map +1 -0
- package/dist/component/userContext.js +615 -0
- package/dist/component/userContext.js.map +1 -0
- package/dist/component/validation.d.ts +387 -0
- package/dist/component/validation.d.ts.map +1 -0
- package/dist/component/validation.js +1052 -0
- package/dist/component/validation.js.map +1 -0
- package/dist/component/validators.d.ts +4645 -0
- package/dist/component/validators.d.ts.map +1 -0
- package/dist/component/validators.js +641 -0
- package/dist/component/validators.js.map +1 -0
- package/dist/component/versionMutations.d.ts +216 -0
- package/dist/component/versionMutations.d.ts.map +1 -0
- package/dist/component/versionMutations.js +321 -0
- package/dist/component/versionMutations.js.map +1 -0
- package/dist/component/webhookTrigger.d.ts +770 -0
- package/dist/component/webhookTrigger.d.ts.map +1 -0
- package/dist/component/webhookTrigger.js +1413 -0
- package/dist/component/webhookTrigger.js.map +1 -0
- package/dist/react/index.d.ts +316 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +558 -0
- package/dist/react/index.js.map +1 -0
- package/dist/test.d.ts +2230 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +1107 -0
- package/dist/test.js.map +1 -0
- package/package.json +95 -0
- package/src/cli/commands/admin.ts +104 -0
- package/src/cli/index.ts +21 -0
- package/src/cli/utils/detectConvexUrl.ts +54 -0
- package/src/cli/utils/openBrowser.ts +16 -0
- package/src/client/admin-config.ts +138 -0
- package/src/client/adminApi.ts +942 -0
- package/src/client/agentTools.ts +1311 -0
- package/src/client/argTypes.ts +316 -0
- package/src/client/field-types.ts +187 -0
- package/src/client/index.ts +1301 -0
- package/src/client/queryBuilder.ts +1100 -0
- package/src/client/schema/codegen.ts +500 -0
- package/src/client/schema/defineContentType.ts +501 -0
- package/src/client/schema/index.ts +169 -0
- package/src/client/schema/schemaDrift.ts +574 -0
- package/src/client/schema/typedClient.ts +688 -0
- package/src/client/schema/types.ts +666 -0
- package/src/client/types.ts +723 -0
- package/src/client/workflows.ts +141 -0
- package/src/client/wrapper.ts +4304 -0
- package/src/component/_generated/api.ts +140 -0
- package/src/component/_generated/component.ts +5029 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +156 -0
- package/src/component/authorization.ts +647 -0
- package/src/component/authorizationHooks.ts +668 -0
- package/src/component/bulkOperations.ts +687 -0
- package/src/component/contentEntries.ts +1976 -0
- package/src/component/contentEntryMutations.ts +1223 -0
- package/src/component/contentEntryValidation.ts +707 -0
- package/src/component/contentLock.ts +550 -0
- package/src/component/contentTypeMigration.ts +1064 -0
- package/src/component/contentTypeMutations.ts +969 -0
- package/src/component/contentTypes.ts +346 -0
- package/src/component/convex.config.ts +44 -0
- package/src/component/documentTypes.ts +240 -0
- package/src/component/eventEmitter.ts +485 -0
- package/src/component/exportImport.ts +1169 -0
- package/src/component/index.ts +491 -0
- package/src/component/lib/deepReferenceResolver.ts +999 -0
- package/src/component/lib/errors.ts +816 -0
- package/src/component/lib/index.ts +145 -0
- package/src/component/lib/mediaReferenceResolver.ts +495 -0
- package/src/component/lib/metadataExtractor.ts +792 -0
- package/src/component/lib/mutationAuth.ts +199 -0
- package/src/component/lib/queries.ts +79 -0
- package/src/component/lib/ragContentChunker.ts +1371 -0
- package/src/component/lib/referenceResolver.ts +430 -0
- package/src/component/lib/slugGenerator.ts +262 -0
- package/src/component/lib/slugUniqueness.ts +333 -0
- package/src/component/lib/softDelete.ts +44 -0
- package/src/component/localeFallbackChain.ts +673 -0
- package/src/component/localeFields.ts +896 -0
- package/src/component/mediaAssetMutations.ts +725 -0
- package/src/component/mediaAssets.ts +932 -0
- package/src/component/mediaFolderMutations.ts +1046 -0
- package/src/component/mediaUploadMutations.ts +224 -0
- package/src/component/mediaVariantMutations.ts +900 -0
- package/src/component/mediaVariants.ts +793 -0
- package/src/component/ragContentIndexer.ts +1067 -0
- package/src/component/rateLimitHooks.ts +572 -0
- package/src/component/roles.ts +1360 -0
- package/src/component/scheduledPublish.ts +358 -0
- package/src/component/schema.ts +617 -0
- package/src/component/taxonomies.ts +949 -0
- package/src/component/taxonomyMutations.ts +1210 -0
- package/src/component/trash.ts +724 -0
- package/src/component/userContext.ts +898 -0
- package/src/component/validation.ts +1388 -0
- package/src/component/validators.ts +949 -0
- package/src/component/versionMutations.ts +392 -0
- package/src/component/webhookTrigger.ts +1922 -0
- package/src/react/index.ts +898 -0
- package/src/test.ts +1580 -0
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type Code Generation
|
|
3
|
+
*
|
|
4
|
+
* Generates TypeScript types from content types stored in the database.
|
|
5
|
+
* This allows type safety for content types created via admin UI.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // In a build script or CLI tool
|
|
10
|
+
* import { generateTypesFromDatabase } from "@convex-cms/core";
|
|
11
|
+
*
|
|
12
|
+
* const output = await generateTypesFromDatabase(ctx, cms);
|
|
13
|
+
* await fs.writeFile("./src/generated/cms-types.ts", output);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @example CLI Usage
|
|
17
|
+
* ```bash
|
|
18
|
+
* npx convex-cms codegen --output ./src/generated/cms-types.ts
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import type { ConvexContext } from "../wrapper.js";
|
|
23
|
+
import type { CmsClient } from "../wrapper.js";
|
|
24
|
+
import type { ContentType, FieldDefinition } from "../types.js";
|
|
25
|
+
|
|
26
|
+
// =============================================================================
|
|
27
|
+
// Types
|
|
28
|
+
// =============================================================================
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Options for code generation.
|
|
32
|
+
*/
|
|
33
|
+
export interface CodegenOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Header comment to include at the top of the generated file.
|
|
36
|
+
* @default "Auto-generated by @convex-cms/core codegen"
|
|
37
|
+
*/
|
|
38
|
+
header?: string;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Whether to include JSDoc comments for fields.
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
includeJsDoc?: boolean;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Content type names to include. If not provided, includes all.
|
|
48
|
+
*/
|
|
49
|
+
contentTypes?: string[];
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Content type names to exclude.
|
|
53
|
+
*/
|
|
54
|
+
exclude?: string[];
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Whether to generate a union type of all content type names.
|
|
58
|
+
* @default true
|
|
59
|
+
*/
|
|
60
|
+
includeNameUnion?: boolean;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Whether to generate a discriminated union type.
|
|
64
|
+
* @default false
|
|
65
|
+
*/
|
|
66
|
+
includeDiscriminatedUnion?: boolean;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Custom type name suffix for generated types.
|
|
70
|
+
* @default "Data"
|
|
71
|
+
*/
|
|
72
|
+
typeSuffix?: string;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Whether to mark all fields as optional (for partial updates).
|
|
76
|
+
* @default false
|
|
77
|
+
*/
|
|
78
|
+
allOptional?: boolean;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Result of code generation.
|
|
83
|
+
*/
|
|
84
|
+
export interface CodegenResult {
|
|
85
|
+
/**
|
|
86
|
+
* The generated TypeScript code.
|
|
87
|
+
*/
|
|
88
|
+
code: string;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Content types that were included.
|
|
92
|
+
*/
|
|
93
|
+
includedTypes: string[];
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Content types that were excluded.
|
|
97
|
+
*/
|
|
98
|
+
excludedTypes: string[];
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Timestamp of generation.
|
|
102
|
+
*/
|
|
103
|
+
generatedAt: number;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// =============================================================================
|
|
107
|
+
// Code Generation
|
|
108
|
+
// =============================================================================
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Generate TypeScript types from content types in the database.
|
|
112
|
+
*
|
|
113
|
+
* @param ctx - Convex context
|
|
114
|
+
* @param cmsClient - CMS client to query content types
|
|
115
|
+
* @param options - Code generation options
|
|
116
|
+
* @returns Generated TypeScript code
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const result = await generateTypesFromDatabase(ctx, cms);
|
|
121
|
+
*
|
|
122
|
+
* // Write to file
|
|
123
|
+
* await fs.writeFile("./src/generated/cms-types.ts", result.code);
|
|
124
|
+
*
|
|
125
|
+
* // Now you can import the types
|
|
126
|
+
* import type { BlogPostData, AuthorData } from "./generated/cms-types";
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export async function generateTypesFromDatabase(
|
|
130
|
+
ctx: ConvexContext,
|
|
131
|
+
cmsClient: CmsClient,
|
|
132
|
+
options: CodegenOptions = {},
|
|
133
|
+
): Promise<CodegenResult> {
|
|
134
|
+
const {
|
|
135
|
+
header = "Auto-generated by @convex-cms/core codegen",
|
|
136
|
+
includeJsDoc = true,
|
|
137
|
+
contentTypes: includeTypes,
|
|
138
|
+
exclude = [],
|
|
139
|
+
includeNameUnion = true,
|
|
140
|
+
includeDiscriminatedUnion = false,
|
|
141
|
+
typeSuffix = "Data",
|
|
142
|
+
allOptional = false,
|
|
143
|
+
} = options;
|
|
144
|
+
|
|
145
|
+
// Fetch all content types
|
|
146
|
+
const allTypes = await cmsClient.contentTypes.getAll(ctx);
|
|
147
|
+
|
|
148
|
+
// Filter content types
|
|
149
|
+
let filteredTypes: ContentType[] = allTypes;
|
|
150
|
+
if (includeTypes) {
|
|
151
|
+
filteredTypes = filteredTypes.filter((t: ContentType) => includeTypes.includes(t.name));
|
|
152
|
+
}
|
|
153
|
+
filteredTypes = filteredTypes.filter((t: ContentType) => !exclude.includes(t.name));
|
|
154
|
+
|
|
155
|
+
const includedTypes = filteredTypes.map((t: ContentType) => t.name);
|
|
156
|
+
const excludedTypes = allTypes
|
|
157
|
+
.filter((t: ContentType) => !includedTypes.includes(t.name))
|
|
158
|
+
.map((t: ContentType) => t.name);
|
|
159
|
+
|
|
160
|
+
// Build output
|
|
161
|
+
const lines: string[] = [];
|
|
162
|
+
|
|
163
|
+
// Header
|
|
164
|
+
lines.push(`/**`);
|
|
165
|
+
lines.push(` * ${header}`);
|
|
166
|
+
lines.push(` *`);
|
|
167
|
+
lines.push(` * DO NOT EDIT - Regenerate with: npx convex-cms codegen`);
|
|
168
|
+
lines.push(` *`);
|
|
169
|
+
lines.push(` * Generated: ${new Date().toISOString()}`);
|
|
170
|
+
lines.push(` * Content types: ${includedTypes.length}`);
|
|
171
|
+
lines.push(` */`);
|
|
172
|
+
lines.push("");
|
|
173
|
+
lines.push("/* eslint-disable */");
|
|
174
|
+
lines.push("");
|
|
175
|
+
|
|
176
|
+
// Generate types for each content type
|
|
177
|
+
for (const contentType of filteredTypes) {
|
|
178
|
+
lines.push(
|
|
179
|
+
...generateTypeForContentType(contentType, {
|
|
180
|
+
includeJsDoc,
|
|
181
|
+
typeSuffix,
|
|
182
|
+
allOptional,
|
|
183
|
+
}),
|
|
184
|
+
);
|
|
185
|
+
lines.push("");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Generate name union
|
|
189
|
+
if (includeNameUnion && filteredTypes.length > 0) {
|
|
190
|
+
lines.push("/**");
|
|
191
|
+
lines.push(" * All content type names.");
|
|
192
|
+
lines.push(" */");
|
|
193
|
+
const typeNames = filteredTypes.map((t) => `"${t.name}"`).join(" | ");
|
|
194
|
+
lines.push(`export type ContentTypeName = ${typeNames};`);
|
|
195
|
+
lines.push("");
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Generate discriminated union
|
|
199
|
+
if (includeDiscriminatedUnion && filteredTypes.length > 0) {
|
|
200
|
+
lines.push("/**");
|
|
201
|
+
lines.push(" * Discriminated union of all content data types.");
|
|
202
|
+
lines.push(" */");
|
|
203
|
+
lines.push("export type ContentData =");
|
|
204
|
+
for (let i = 0; i < filteredTypes.length; i++) {
|
|
205
|
+
const t = filteredTypes[i];
|
|
206
|
+
const typeName = toPascalCase(t.name) + typeSuffix;
|
|
207
|
+
const suffix = i < filteredTypes.length - 1 ? "" : ";";
|
|
208
|
+
lines.push(` | { _type: "${t.name}"; data: ${typeName} }${suffix}`);
|
|
209
|
+
}
|
|
210
|
+
lines.push("");
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Generate type map
|
|
214
|
+
if (filteredTypes.length > 0) {
|
|
215
|
+
lines.push("/**");
|
|
216
|
+
lines.push(" * Map from content type name to data type.");
|
|
217
|
+
lines.push(" */");
|
|
218
|
+
lines.push("export interface ContentTypeMap {");
|
|
219
|
+
for (const t of filteredTypes) {
|
|
220
|
+
const typeName = toPascalCase(t.name) + typeSuffix;
|
|
221
|
+
lines.push(` "${t.name}": ${typeName};`);
|
|
222
|
+
}
|
|
223
|
+
lines.push("}");
|
|
224
|
+
lines.push("");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Helper type
|
|
228
|
+
lines.push("/**");
|
|
229
|
+
lines.push(" * Get the data type for a content type name.");
|
|
230
|
+
lines.push(" */");
|
|
231
|
+
lines.push(
|
|
232
|
+
"export type DataForType<T extends ContentTypeName> = ContentTypeMap[T];",
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
return {
|
|
236
|
+
code: lines.join("\n"),
|
|
237
|
+
includedTypes,
|
|
238
|
+
excludedTypes,
|
|
239
|
+
generatedAt: Date.now(),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Generate TypeScript interface for a single content type.
|
|
245
|
+
*/
|
|
246
|
+
function generateTypeForContentType(
|
|
247
|
+
contentType: ContentType,
|
|
248
|
+
options: {
|
|
249
|
+
includeJsDoc: boolean;
|
|
250
|
+
typeSuffix: string;
|
|
251
|
+
allOptional: boolean;
|
|
252
|
+
},
|
|
253
|
+
): string[] {
|
|
254
|
+
const { includeJsDoc, typeSuffix, allOptional } = options;
|
|
255
|
+
const lines: string[] = [];
|
|
256
|
+
|
|
257
|
+
const typeName = toPascalCase(contentType.name) + typeSuffix;
|
|
258
|
+
|
|
259
|
+
// JSDoc
|
|
260
|
+
if (includeJsDoc) {
|
|
261
|
+
lines.push("/**");
|
|
262
|
+
lines.push(
|
|
263
|
+
` * Data type for "${contentType.displayName}" content entries.`,
|
|
264
|
+
);
|
|
265
|
+
if (contentType.description) {
|
|
266
|
+
lines.push(` *`);
|
|
267
|
+
lines.push(` * ${contentType.description}`);
|
|
268
|
+
}
|
|
269
|
+
lines.push(` *`);
|
|
270
|
+
lines.push(` * @contentType ${contentType.name}`);
|
|
271
|
+
lines.push(" */");
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Interface
|
|
275
|
+
lines.push(`export interface ${typeName} {`);
|
|
276
|
+
|
|
277
|
+
for (const field of contentType.fields) {
|
|
278
|
+
// Field JSDoc
|
|
279
|
+
if (includeJsDoc && field.description) {
|
|
280
|
+
lines.push(` /** ${field.description} */`);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const tsType = fieldTypeToTsType(field);
|
|
284
|
+
const optional = allOptional || !field.required ? "?" : "";
|
|
285
|
+
lines.push(` ${field.name}${optional}: ${tsType};`);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
lines.push("}");
|
|
289
|
+
|
|
290
|
+
return lines;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Convert a field definition to a TypeScript type.
|
|
295
|
+
*
|
|
296
|
+
* Note: We cast field.type to string because the database may contain
|
|
297
|
+
* field types (like "tags", "category") that aren't in the client FieldType union.
|
|
298
|
+
*/
|
|
299
|
+
function fieldTypeToTsType(field: FieldDefinition): string {
|
|
300
|
+
// Cast to string to handle potential extra field types from the database
|
|
301
|
+
const fieldType = field.type as string;
|
|
302
|
+
|
|
303
|
+
switch (fieldType) {
|
|
304
|
+
case "text":
|
|
305
|
+
case "richText":
|
|
306
|
+
return "string";
|
|
307
|
+
|
|
308
|
+
case "number":
|
|
309
|
+
return "number";
|
|
310
|
+
|
|
311
|
+
case "boolean":
|
|
312
|
+
return "boolean";
|
|
313
|
+
|
|
314
|
+
case "date":
|
|
315
|
+
case "datetime":
|
|
316
|
+
return "number"; // Unix timestamp
|
|
317
|
+
|
|
318
|
+
case "reference": {
|
|
319
|
+
// Type narrowing: field.type === "reference" means options has reference shape
|
|
320
|
+
const refOpts = field.options as { multiple?: boolean } | undefined;
|
|
321
|
+
if (refOpts?.multiple) {
|
|
322
|
+
return "string[]";
|
|
323
|
+
}
|
|
324
|
+
return "string";
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
case "media": {
|
|
328
|
+
// Type narrowing: field.type === "media" means options has media shape
|
|
329
|
+
const mediaOpts = field.options as { multiple?: boolean } | undefined;
|
|
330
|
+
if (mediaOpts?.multiple) {
|
|
331
|
+
return "string[]";
|
|
332
|
+
}
|
|
333
|
+
return "string";
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
case "select": {
|
|
337
|
+
const selectOpts = field.options as
|
|
338
|
+
| { options?: Array<{ value: string; label?: string }> }
|
|
339
|
+
| undefined;
|
|
340
|
+
return generateSelectUnion(selectOpts?.options);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
case "multiSelect": {
|
|
344
|
+
const multiOpts = field.options as
|
|
345
|
+
| { options?: Array<{ value: string; label?: string }> }
|
|
346
|
+
| undefined;
|
|
347
|
+
const unionType = generateSelectUnion(multiOpts?.options);
|
|
348
|
+
return `(${unionType})[]`;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
case "json":
|
|
352
|
+
return "unknown";
|
|
353
|
+
|
|
354
|
+
// Handle taxonomy fields (may not be in FieldType union)
|
|
355
|
+
case "tags":
|
|
356
|
+
case "category":
|
|
357
|
+
return "string[]";
|
|
358
|
+
|
|
359
|
+
default:
|
|
360
|
+
return "unknown";
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Generate a union type from select options.
|
|
366
|
+
*/
|
|
367
|
+
function generateSelectUnion(
|
|
368
|
+
options?: Array<{ value: string; label?: string }>,
|
|
369
|
+
): string {
|
|
370
|
+
if (!options || options.length === 0) {
|
|
371
|
+
return "string";
|
|
372
|
+
}
|
|
373
|
+
return options.map((o) => `"${escapeString(o.value)}"`).join(" | ");
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Convert a string to PascalCase.
|
|
378
|
+
*/
|
|
379
|
+
function toPascalCase(str: string): string {
|
|
380
|
+
return str
|
|
381
|
+
.split(/[-_\s]+/)
|
|
382
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
383
|
+
.join("");
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Escape special characters in a string for use in TypeScript.
|
|
388
|
+
*/
|
|
389
|
+
function escapeString(str: string): string {
|
|
390
|
+
return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n");
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// =============================================================================
|
|
394
|
+
// String-based Generation (No Convex Context)
|
|
395
|
+
// =============================================================================
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Generate TypeScript types from an array of content type definitions.
|
|
399
|
+
*
|
|
400
|
+
* Useful when you already have the content types loaded (e.g., from a JSON file).
|
|
401
|
+
*
|
|
402
|
+
* @param contentTypes - Array of content type definitions
|
|
403
|
+
* @param options - Code generation options
|
|
404
|
+
* @returns Generated TypeScript code
|
|
405
|
+
*/
|
|
406
|
+
export function generateTypesFromDefinitions(
|
|
407
|
+
contentTypes: ContentType[],
|
|
408
|
+
options: CodegenOptions = {},
|
|
409
|
+
): string {
|
|
410
|
+
const {
|
|
411
|
+
header = "Auto-generated by @convex-cms/core codegen",
|
|
412
|
+
includeJsDoc = true,
|
|
413
|
+
exclude = [],
|
|
414
|
+
includeNameUnion = true,
|
|
415
|
+
typeSuffix = "Data",
|
|
416
|
+
allOptional = false,
|
|
417
|
+
} = options;
|
|
418
|
+
|
|
419
|
+
// Filter content types
|
|
420
|
+
const filteredTypes = contentTypes.filter((t) => !exclude.includes(t.name));
|
|
421
|
+
|
|
422
|
+
const lines: string[] = [];
|
|
423
|
+
|
|
424
|
+
// Header
|
|
425
|
+
lines.push(`/**`);
|
|
426
|
+
lines.push(` * ${header}`);
|
|
427
|
+
lines.push(` *`);
|
|
428
|
+
lines.push(` * DO NOT EDIT`);
|
|
429
|
+
lines.push(` */`);
|
|
430
|
+
lines.push("");
|
|
431
|
+
lines.push("/* eslint-disable */");
|
|
432
|
+
lines.push("");
|
|
433
|
+
|
|
434
|
+
// Generate types
|
|
435
|
+
for (const contentType of filteredTypes) {
|
|
436
|
+
lines.push(
|
|
437
|
+
...generateTypeForContentType(contentType, {
|
|
438
|
+
includeJsDoc,
|
|
439
|
+
typeSuffix,
|
|
440
|
+
allOptional,
|
|
441
|
+
}),
|
|
442
|
+
);
|
|
443
|
+
lines.push("");
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// Name union
|
|
447
|
+
if (includeNameUnion && filteredTypes.length > 0) {
|
|
448
|
+
const typeNames = filteredTypes.map((t) => `"${t.name}"`).join(" | ");
|
|
449
|
+
lines.push(`export type ContentTypeName = ${typeNames};`);
|
|
450
|
+
lines.push("");
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// Type map
|
|
454
|
+
if (filteredTypes.length > 0) {
|
|
455
|
+
lines.push("export interface ContentTypeMap {");
|
|
456
|
+
for (const t of filteredTypes) {
|
|
457
|
+
const typeName = toPascalCase(t.name) + typeSuffix;
|
|
458
|
+
lines.push(` "${t.name}": ${typeName};`);
|
|
459
|
+
}
|
|
460
|
+
lines.push("}");
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return lines.join("\n");
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// =============================================================================
|
|
467
|
+
// Validation
|
|
468
|
+
// =============================================================================
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Validate that generated types match the expected structure.
|
|
472
|
+
*
|
|
473
|
+
* @param code - Generated TypeScript code
|
|
474
|
+
* @returns Validation result
|
|
475
|
+
*/
|
|
476
|
+
export function validateGeneratedCode(
|
|
477
|
+
code: string,
|
|
478
|
+
): {
|
|
479
|
+
valid: boolean;
|
|
480
|
+
errors: string[];
|
|
481
|
+
} {
|
|
482
|
+
const errors: string[] = [];
|
|
483
|
+
|
|
484
|
+
// Check for basic structure
|
|
485
|
+
if (!code.includes("export interface") && !code.includes("export type")) {
|
|
486
|
+
errors.push("No exported types found in generated code");
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// Check for syntax issues
|
|
490
|
+
const openBraces = (code.match(/{/g) || []).length;
|
|
491
|
+
const closeBraces = (code.match(/}/g) || []).length;
|
|
492
|
+
if (openBraces !== closeBraces) {
|
|
493
|
+
errors.push(`Mismatched braces: ${openBraces} open, ${closeBraces} close`);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
return {
|
|
497
|
+
valid: errors.length === 0,
|
|
498
|
+
errors,
|
|
499
|
+
};
|
|
500
|
+
}
|