@payloadcms/plugin-mcp 3.85.0 → 4.0.0-internal.1f9ae9a
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/README.md +2 -2
- package/bin.js +39 -0
- package/dist/collection/getAccessField.d.ts +12 -0
- package/dist/collection/getAccessField.d.ts.map +1 -0
- package/dist/collection/getAccessField.js +57 -0
- package/dist/collection/getAccessField.js.map +1 -0
- package/dist/collection/index.d.ts +6 -0
- package/dist/collection/index.d.ts.map +1 -0
- package/dist/collection/index.js +59 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/components/AccessField/index.client.d.ts +10 -0
- package/dist/components/AccessField/index.client.d.ts.map +1 -0
- package/dist/components/AccessField/index.client.js +305 -0
- package/dist/components/AccessField/index.client.js.map +1 -0
- package/dist/components/AccessField/index.css +93 -0
- package/dist/defineTool.d.ts +26 -0
- package/dist/defineTool.d.ts.map +1 -0
- package/dist/defineTool.js +37 -0
- package/dist/defineTool.js.map +1 -0
- package/dist/endpoint/access.d.ts +10 -0
- package/dist/endpoint/access.d.ts.map +1 -0
- package/dist/endpoint/access.js +106 -0
- package/dist/endpoint/access.js.map +1 -0
- package/dist/endpoint/index.d.ts +3 -0
- package/dist/endpoint/index.d.ts.map +1 -0
- package/dist/endpoint/index.js +36 -0
- package/dist/endpoint/index.js.map +1 -0
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/index.d.ts +4 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -67
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +19 -0
- package/dist/mcp/buildMcpServer.d.ts.map +1 -0
- package/dist/mcp/buildMcpServer.js +163 -0
- package/dist/mcp/buildMcpServer.js.map +1 -0
- package/dist/mcp/builtin/collections/authTools.d.ts +7 -0
- package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/authTools.js +250 -0
- package/dist/mcp/builtin/collections/authTools.js.map +1 -0
- package/dist/mcp/builtin/collections/createTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/createTool.js +87 -0
- package/dist/mcp/builtin/collections/createTool.js.map +1 -0
- package/dist/mcp/builtin/collections/deleteTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/deleteTool.js +117 -0
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findTool.js +159 -0
- package/dist/mcp/builtin/collections/findTool.js.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.js +187 -0
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findTool.js +76 -0
- package/dist/mcp/builtin/globals/findTool.js.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.js +92 -0
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
- package/dist/mcp/builtinTools.d.ts +37 -0
- package/dist/mcp/builtinTools.d.ts.map +1 -0
- package/dist/mcp/builtinTools.js +64 -0
- package/dist/mcp/builtinTools.js.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts +17 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.js +167 -0
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
- package/dist/stdio.d.ts +8 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +89 -0
- package/dist/stdio.js.map +1 -0
- package/dist/types.d.ts +262 -455
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/camelCase.d.ts.map +1 -1
- package/dist/utils/getLogger.d.ts +10 -0
- package/dist/utils/getLogger.d.ts.map +1 -0
- package/dist/utils/getLogger.js +22 -0
- package/dist/utils/getLogger.js.map +1 -0
- package/dist/utils/getPluginConfig.d.ts +12 -0
- package/dist/utils/getPluginConfig.d.ts.map +1 -0
- package/dist/utils/getPluginConfig.js +15 -0
- package/dist/utils/getPluginConfig.js.map +1 -0
- package/dist/utils/localAPIDefaults.d.ts +20 -0
- package/dist/utils/localAPIDefaults.d.ts.map +1 -0
- package/dist/utils/localAPIDefaults.js +19 -0
- package/dist/utils/localAPIDefaults.js.map +1 -0
- package/dist/utils/resolveProjectRoot.d.ts +7 -0
- package/dist/utils/resolveProjectRoot.d.ts.map +1 -0
- package/dist/utils/resolveProjectRoot.js +15 -0
- package/dist/utils/resolveProjectRoot.js.map +1 -0
- package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts +7 -0
- package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/prepareCollectionSchema.js +37 -0
- package/dist/utils/schemaConversion/prepareCollectionSchema.js.map +1 -0
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +2 -2
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +1 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +2 -2
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +1 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +2 -2
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +1 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js +7 -4
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +1 -1
- package/dist/utils/schemaConversion/transformPointFields.d.ts +2 -2
- package/dist/utils/schemaConversion/transformPointFields.d.ts.map +1 -1
- package/dist/utils/schemaConversion/transformPointFields.js +7 -1
- package/dist/utils/schemaConversion/transformPointFields.js.map +1 -1
- package/dist/utils/toStandardSchema.d.ts +5 -0
- package/dist/utils/toStandardSchema.d.ts.map +1 -0
- package/dist/utils/toStandardSchema.js +4 -0
- package/dist/utils/toStandardSchema.js.map +1 -0
- package/package.json +35 -10
- package/src/collection/getAccessField.ts +64 -0
- package/src/collection/index.ts +63 -0
- package/src/components/AccessField/index.client.tsx +344 -0
- package/src/components/AccessField/index.css +93 -0
- package/src/defineTool.ts +44 -0
- package/src/endpoint/access.ts +132 -0
- package/src/endpoint/index.ts +35 -0
- package/src/exports/client.ts +2 -0
- package/src/index.ts +35 -85
- package/src/mcp/buildMcpServer.ts +224 -0
- package/src/mcp/builtin/collections/authTools.ts +233 -0
- package/src/mcp/builtin/collections/createTool.ts +116 -0
- package/src/mcp/builtin/collections/deleteTool.ts +123 -0
- package/src/mcp/builtin/collections/findTool.ts +187 -0
- package/src/mcp/builtin/collections/updateTool.ts +205 -0
- package/src/mcp/builtin/globals/findTool.ts +96 -0
- package/src/mcp/builtin/globals/updateTool.ts +118 -0
- package/src/mcp/builtinTools.ts +84 -0
- package/src/mcp/sanitizeMCPConfig.ts +239 -0
- package/src/stdio.ts +98 -0
- package/src/types.ts +295 -490
- package/src/utils/getLogger.ts +22 -0
- package/src/utils/getPluginConfig.ts +24 -0
- package/src/utils/localAPIDefaults.ts +22 -0
- package/src/utils/resolveProjectRoot.ts +17 -0
- package/src/utils/schemaConversion/prepareCollectionSchema.ts +39 -0
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +3 -3
- package/src/utils/schemaConversion/sanitizeJsonSchema.ts +4 -4
- package/src/utils/schemaConversion/simplifyRelationshipFields.ts +11 -6
- package/src/utils/schemaConversion/transformPointFields.ts +6 -5
- package/src/utils/toStandardSchema.ts +9 -0
- package/dist/collections/createApiKeysCollection.d.ts +0 -7
- package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
- package/dist/collections/createApiKeysCollection.js +0 -317
- package/dist/collections/createApiKeysCollection.js.map +0 -1
- package/dist/defaults.d.ts +0 -4
- package/dist/defaults.d.ts.map +0 -1
- package/dist/defaults.js +0 -5
- package/dist/defaults.js.map +0 -1
- package/dist/endpoints/mcp.d.ts +0 -4
- package/dist/endpoints/mcp.d.ts.map +0 -1
- package/dist/endpoints/mcp.js +0 -71
- package/dist/endpoints/mcp.js.map +0 -1
- package/dist/mcp/createRequest.d.ts +0 -3
- package/dist/mcp/createRequest.d.ts.map +0 -1
- package/dist/mcp/createRequest.js +0 -14
- package/dist/mcp/createRequest.js.map +0 -1
- package/dist/mcp/getMcpHandler.d.ts +0 -4
- package/dist/mcp/getMcpHandler.d.ts.map +0 -1
- package/dist/mcp/getMcpHandler.js +0 -231
- package/dist/mcp/getMcpHandler.js.map +0 -1
- package/dist/mcp/helpers/config.d.ts +0 -22
- package/dist/mcp/helpers/config.d.ts.map +0 -1
- package/dist/mcp/helpers/config.js +0 -153
- package/dist/mcp/helpers/config.js.map +0 -1
- package/dist/mcp/helpers/fields.d.ts +0 -19
- package/dist/mcp/helpers/fields.d.ts.map +0 -1
- package/dist/mcp/helpers/fields.js +0 -102
- package/dist/mcp/helpers/fields.js.map +0 -1
- package/dist/mcp/helpers/fileValidation.d.ts +0 -67
- package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
- package/dist/mcp/helpers/fileValidation.js +0 -267
- package/dist/mcp/helpers/fileValidation.js.map +0 -1
- package/dist/mcp/registerTool.d.ts +0 -6
- package/dist/mcp/registerTool.d.ts.map +0 -1
- package/dist/mcp/registerTool.js +0 -18
- package/dist/mcp/registerTool.js.map +0 -1
- package/dist/mcp/tools/auth/auth.d.ts +0 -4
- package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
- package/dist/mcp/tools/auth/auth.js +0 -57
- package/dist/mcp/tools/auth/auth.js.map +0 -1
- package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
- package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
- package/dist/mcp/tools/auth/forgotPassword.js +0 -48
- package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
- package/dist/mcp/tools/auth/login.d.ts +0 -4
- package/dist/mcp/tools/auth/login.d.ts.map +0 -1
- package/dist/mcp/tools/auth/login.js +0 -51
- package/dist/mcp/tools/auth/login.js.map +0 -1
- package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
- package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
- package/dist/mcp/tools/auth/resetPassword.js +0 -49
- package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
- package/dist/mcp/tools/auth/unlock.d.ts +0 -4
- package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
- package/dist/mcp/tools/auth/unlock.js +0 -48
- package/dist/mcp/tools/auth/unlock.js.map +0 -1
- package/dist/mcp/tools/auth/verify.d.ts +0 -4
- package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
- package/dist/mcp/tools/auth/verify.js +0 -45
- package/dist/mcp/tools/auth/verify.js.map +0 -1
- package/dist/mcp/tools/collection/create.d.ts +0 -10
- package/dist/mcp/tools/collection/create.d.ts.map +0 -1
- package/dist/mcp/tools/collection/create.js +0 -139
- package/dist/mcp/tools/collection/create.js.map +0 -1
- package/dist/mcp/tools/collection/delete.d.ts +0 -10
- package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
- package/dist/mcp/tools/collection/delete.js +0 -154
- package/dist/mcp/tools/collection/delete.js.map +0 -1
- package/dist/mcp/tools/collection/find.d.ts +0 -10
- package/dist/mcp/tools/collection/find.d.ts.map +0 -1
- package/dist/mcp/tools/collection/find.js +0 -165
- package/dist/mcp/tools/collection/find.js.map +0 -1
- package/dist/mcp/tools/collection/update.d.ts +0 -10
- package/dist/mcp/tools/collection/update.d.ts.map +0 -1
- package/dist/mcp/tools/collection/update.js +0 -209
- package/dist/mcp/tools/collection/update.js.map +0 -1
- package/dist/mcp/tools/config/find.d.ts +0 -10
- package/dist/mcp/tools/config/find.d.ts.map +0 -1
- package/dist/mcp/tools/config/find.js +0 -97
- package/dist/mcp/tools/config/find.js.map +0 -1
- package/dist/mcp/tools/config/update.d.ts +0 -10
- package/dist/mcp/tools/config/update.d.ts.map +0 -1
- package/dist/mcp/tools/config/update.js +0 -215
- package/dist/mcp/tools/config/update.js.map +0 -1
- package/dist/mcp/tools/global/find.d.ts +0 -5
- package/dist/mcp/tools/global/find.d.ts.map +0 -1
- package/dist/mcp/tools/global/find.js +0 -82
- package/dist/mcp/tools/global/find.js.map +0 -1
- package/dist/mcp/tools/global/update.d.ts +0 -6
- package/dist/mcp/tools/global/update.d.ts.map +0 -1
- package/dist/mcp/tools/global/update.js +0 -124
- package/dist/mcp/tools/global/update.js.map +0 -1
- package/dist/mcp/tools/job/create.d.ts +0 -10
- package/dist/mcp/tools/job/create.d.ts.map +0 -1
- package/dist/mcp/tools/job/create.js +0 -293
- package/dist/mcp/tools/job/create.js.map +0 -1
- package/dist/mcp/tools/job/run.d.ts +0 -10
- package/dist/mcp/tools/job/run.d.ts.map +0 -1
- package/dist/mcp/tools/job/run.js +0 -129
- package/dist/mcp/tools/job/run.js.map +0 -1
- package/dist/mcp/tools/job/update.d.ts +0 -11
- package/dist/mcp/tools/job/update.d.ts.map +0 -1
- package/dist/mcp/tools/job/update.js +0 -186
- package/dist/mcp/tools/job/update.js.map +0 -1
- package/dist/mcp/tools/resource/create.d.ts +0 -6
- package/dist/mcp/tools/resource/create.d.ts.map +0 -1
- package/dist/mcp/tools/resource/create.js +0 -124
- package/dist/mcp/tools/resource/create.js.map +0 -1
- package/dist/mcp/tools/resource/delete.d.ts +0 -5
- package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
- package/dist/mcp/tools/resource/delete.js +0 -151
- package/dist/mcp/tools/resource/delete.js.map +0 -1
- package/dist/mcp/tools/resource/find.d.ts +0 -5
- package/dist/mcp/tools/resource/find.d.ts.map +0 -1
- package/dist/mcp/tools/resource/find.js +0 -170
- package/dist/mcp/tools/resource/find.js.map +0 -1
- package/dist/mcp/tools/resource/update.d.ts +0 -6
- package/dist/mcp/tools/resource/update.d.ts.map +0 -1
- package/dist/mcp/tools/resource/update.js +0 -256
- package/dist/mcp/tools/resource/update.js.map +0 -1
- package/dist/mcp/tools/schemas.d.ts +0 -457
- package/dist/mcp/tools/schemas.d.ts.map +0 -1
- package/dist/mcp/tools/schemas.js +0 -243
- package/dist/mcp/tools/schemas.js.map +0 -1
- package/dist/utils/adminEntitySettings.d.ts +0 -17
- package/dist/utils/adminEntitySettings.d.ts.map +0 -1
- package/dist/utils/adminEntitySettings.js +0 -41
- package/dist/utils/adminEntitySettings.js.map +0 -1
- package/dist/utils/createApiKeyFields.d.ts +0 -15
- package/dist/utils/createApiKeyFields.d.ts.map +0 -1
- package/dist/utils/createApiKeyFields.js +0 -57
- package/dist/utils/createApiKeyFields.js.map +0 -1
- package/dist/utils/getEnabledSlugs.d.ts +0 -13
- package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
- package/dist/utils/getEnabledSlugs.js +0 -32
- package/dist/utils/getEnabledSlugs.js.map +0 -1
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +0 -1
- package/src/collections/createApiKeysCollection.ts +0 -373
- package/src/defaults.ts +0 -3
- package/src/endpoints/mcp.ts +0 -91
- package/src/mcp/createRequest.ts +0 -13
- package/src/mcp/getMcpHandler.ts +0 -545
- package/src/mcp/helpers/config.ts +0 -213
- package/src/mcp/helpers/fields.ts +0 -154
- package/src/mcp/helpers/fileValidation.ts +0 -362
- package/src/mcp/registerTool.ts +0 -22
- package/src/mcp/tools/auth/auth.ts +0 -71
- package/src/mcp/tools/auth/forgotPassword.ts +0 -70
- package/src/mcp/tools/auth/login.ts +0 -72
- package/src/mcp/tools/auth/resetPassword.ts +0 -61
- package/src/mcp/tools/auth/unlock.ts +0 -64
- package/src/mcp/tools/auth/verify.ts +0 -57
- package/src/mcp/tools/collection/create.ts +0 -210
- package/src/mcp/tools/collection/delete.ts +0 -211
- package/src/mcp/tools/collection/find.ts +0 -224
- package/src/mcp/tools/collection/update.ts +0 -290
- package/src/mcp/tools/config/find.ts +0 -128
- package/src/mcp/tools/config/update.ts +0 -280
- package/src/mcp/tools/global/find.ts +0 -128
- package/src/mcp/tools/global/update.ts +0 -207
- package/src/mcp/tools/job/create.ts +0 -416
- package/src/mcp/tools/job/run.ts +0 -167
- package/src/mcp/tools/job/update.ts +0 -274
- package/src/mcp/tools/resource/create.ts +0 -211
- package/src/mcp/tools/resource/delete.ts +0 -218
- package/src/mcp/tools/resource/find.ts +0 -246
- package/src/mcp/tools/resource/update.ts +0 -383
- package/src/mcp/tools/schemas.ts +0 -520
- package/src/utils/adminEntitySettings.ts +0 -40
- package/src/utils/createApiKeyFields.ts +0 -72
- package/src/utils/getEnabledSlugs.ts +0 -42
- package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import type { AdminConfig, DatabaseConfig, PluginUpdates } from '../../types.js'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Adds a collection to the payload.config.ts file
|
|
5
|
-
*/
|
|
6
|
-
export function addCollectionToConfig(content: string, collectionName: string): string {
|
|
7
|
-
const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1)
|
|
8
|
-
|
|
9
|
-
// Add import statement
|
|
10
|
-
const importRegex = /import.*from\s*['"]\.\/collections\/.*['"]/g
|
|
11
|
-
const importMatches = content.match(importRegex)
|
|
12
|
-
|
|
13
|
-
if (importMatches && importMatches.length > 0) {
|
|
14
|
-
const lastImport = importMatches[importMatches.length - 1]
|
|
15
|
-
const newImport = `import { ${capitalizedName} } from './collections/${capitalizedName}'`
|
|
16
|
-
|
|
17
|
-
// Check if import already exists
|
|
18
|
-
if (lastImport && !content.includes(newImport)) {
|
|
19
|
-
content = content.replace(lastImport, `${lastImport}\n${newImport}`)
|
|
20
|
-
}
|
|
21
|
-
} else {
|
|
22
|
-
// Add import after existing imports
|
|
23
|
-
const importInsertPoint = content.indexOf("import sharp from 'sharp'")
|
|
24
|
-
if (importInsertPoint !== -1) {
|
|
25
|
-
const lineEnd = content.indexOf('\n', importInsertPoint)
|
|
26
|
-
const newImport = `import { ${capitalizedName} } from './collections/${capitalizedName}'`
|
|
27
|
-
content = content.slice(0, lineEnd + 1) + newImport + '\n' + content.slice(lineEnd + 1)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Add to collections array
|
|
32
|
-
const collectionsRegex = /collections:\s*\[([\s\S]*?)\]/
|
|
33
|
-
const collectionsMatch = content.match(collectionsRegex)
|
|
34
|
-
|
|
35
|
-
if (collectionsMatch && collectionsMatch[1]) {
|
|
36
|
-
const collectionsContent = collectionsMatch[1].trim()
|
|
37
|
-
if (!collectionsContent.includes(capitalizedName)) {
|
|
38
|
-
const newCollections = collectionsContent
|
|
39
|
-
? `${collectionsContent}, ${capitalizedName}`
|
|
40
|
-
: capitalizedName
|
|
41
|
-
content = content.replace(collectionsRegex, `collections: [${newCollections}]`)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return content
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Removes a collection from the payload.config.ts file
|
|
50
|
-
*/
|
|
51
|
-
export function removeCollectionFromConfig(content: string, collectionName: string): string {
|
|
52
|
-
const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1)
|
|
53
|
-
|
|
54
|
-
// Remove import statement
|
|
55
|
-
const importRegex = new RegExp(
|
|
56
|
-
`import\\s*{\\s*${capitalizedName}\\s*}\\s*from\\s*['"]\\./collections/${capitalizedName}['"]\\s*\\n?`,
|
|
57
|
-
'g',
|
|
58
|
-
)
|
|
59
|
-
content = content.replace(importRegex, '')
|
|
60
|
-
|
|
61
|
-
// Remove from collections array
|
|
62
|
-
const collectionsRegex = /collections:\s*\[([\s\S]*?)\]/
|
|
63
|
-
const collectionsMatch = content.match(collectionsRegex)
|
|
64
|
-
|
|
65
|
-
if (collectionsMatch && collectionsMatch[1]) {
|
|
66
|
-
let collectionsContent = collectionsMatch[1]
|
|
67
|
-
|
|
68
|
-
// Remove the collection name and clean up commas
|
|
69
|
-
collectionsContent = collectionsContent.replace(
|
|
70
|
-
new RegExp(`\\s*,?\\s*${capitalizedName}\\s*,?`, 'g'),
|
|
71
|
-
'',
|
|
72
|
-
)
|
|
73
|
-
collectionsContent = collectionsContent.replace(/,\s*,/g, ',') // Remove double commas
|
|
74
|
-
collectionsContent = collectionsContent.replace(/^\s*,|,\s*$/g, '') // Remove leading/trailing commas
|
|
75
|
-
|
|
76
|
-
content = content.replace(collectionsRegex, `collections: [${collectionsContent}]`)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Clean up any double newlines from removed imports
|
|
80
|
-
content = content.replace(/\n{3,}/g, '\n\n')
|
|
81
|
-
|
|
82
|
-
return content
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Updates admin configuration in payload.config.ts
|
|
87
|
-
*/
|
|
88
|
-
export function updateAdminConfig(content: string, adminConfig: AdminConfig): string {
|
|
89
|
-
const adminRegex = /admin:\s*\{([^}]*)\}/
|
|
90
|
-
const adminMatch = content.match(adminRegex)
|
|
91
|
-
|
|
92
|
-
if (adminMatch && adminMatch[1]) {
|
|
93
|
-
let adminContent = adminMatch[1]
|
|
94
|
-
|
|
95
|
-
// Update specific admin properties
|
|
96
|
-
if (adminConfig.user) {
|
|
97
|
-
if (adminContent.includes('user:')) {
|
|
98
|
-
adminContent = adminContent.replace(/user:[^,}]*/, `user: ${adminConfig.user}.slug`)
|
|
99
|
-
} else {
|
|
100
|
-
adminContent = `\n user: ${adminConfig.user}.slug,${adminContent}`
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (adminConfig.meta) {
|
|
105
|
-
const metaConfig = Object.entries(adminConfig.meta)
|
|
106
|
-
.map(([key, value]) => ` ${key}: '${value}'`)
|
|
107
|
-
.join(',\n')
|
|
108
|
-
|
|
109
|
-
if (adminContent.includes('meta:')) {
|
|
110
|
-
adminContent = adminContent.replace(/meta:\s*\{[^}]*\}/, `meta: {\n${metaConfig}\n }`)
|
|
111
|
-
} else {
|
|
112
|
-
adminContent = `${adminContent}\n meta: {\n${metaConfig}\n },`
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
content = content.replace(adminRegex, `admin: {${adminContent}\n }`)
|
|
117
|
-
} else {
|
|
118
|
-
// Add admin config if it doesn't exist
|
|
119
|
-
const adminConfigEntries = []
|
|
120
|
-
|
|
121
|
-
if (adminConfig.user) {
|
|
122
|
-
adminConfigEntries.push(` user: ${adminConfig.user}.slug`)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (adminConfig.meta) {
|
|
126
|
-
const metaConfig = Object.entries(adminConfig.meta)
|
|
127
|
-
.map(([key, value]) => ` ${key}: '${value}'`)
|
|
128
|
-
.join(',\n')
|
|
129
|
-
adminConfigEntries.push(` meta: {\n${metaConfig}\n }`)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const adminConfigString = `admin: {\n${adminConfigEntries.join(',\n')}\n },`
|
|
133
|
-
content = content.replace(
|
|
134
|
-
/export default buildConfig\(\{/,
|
|
135
|
-
`export default buildConfig({\n ${adminConfigString}`,
|
|
136
|
-
)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return content
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Updates database configuration in payload.config.ts
|
|
144
|
-
*/
|
|
145
|
-
export function updateDatabaseConfig(content: string, databaseConfig: DatabaseConfig): string {
|
|
146
|
-
if (databaseConfig.type === 'mongodb') {
|
|
147
|
-
// Update to MongoDB adapter
|
|
148
|
-
const dbRegex = /db:[^,}]*(?:,|\})/
|
|
149
|
-
const mongoImportRegex = /import.*mongooseAdapter.*from.*@payloadcms\/db-mongodb.*/
|
|
150
|
-
|
|
151
|
-
if (!content.match(mongoImportRegex)) {
|
|
152
|
-
content = content.replace(
|
|
153
|
-
/(import.*from.*payload.*\n)/,
|
|
154
|
-
`$1import { mongooseAdapter } from '@payloadcms/db-mongodb'\n`,
|
|
155
|
-
)
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const dbConfig = `db: mongooseAdapter({\n url: process.env.DATABASE_URL || '${databaseConfig.url || ''}',\n })`
|
|
159
|
-
content = content.replace(dbRegex, `${dbConfig},`)
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return content
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Updates plugins configuration in payload.config.ts
|
|
167
|
-
*/
|
|
168
|
-
export function updatePluginsConfig(content: string, pluginUpdates: PluginUpdates): string {
|
|
169
|
-
// Add plugin imports
|
|
170
|
-
if (pluginUpdates.add) {
|
|
171
|
-
pluginUpdates.add.forEach((pluginImport: string) => {
|
|
172
|
-
if (!content.includes(pluginImport)) {
|
|
173
|
-
content = content.replace(/(import.*from.*payload.*\n)/, `$1${pluginImport}\n`)
|
|
174
|
-
}
|
|
175
|
-
})
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Handle plugins array
|
|
179
|
-
const pluginsRegex = /plugins:\s*\[([\s\S]*?)\]/
|
|
180
|
-
const pluginsMatch = content.match(pluginsRegex)
|
|
181
|
-
|
|
182
|
-
if (pluginsMatch && pluginsMatch[1]) {
|
|
183
|
-
let pluginsContent = pluginsMatch[1]
|
|
184
|
-
|
|
185
|
-
// Remove plugins
|
|
186
|
-
if (pluginUpdates.remove) {
|
|
187
|
-
pluginUpdates.remove.forEach((pluginName: string) => {
|
|
188
|
-
const pluginRegex = new RegExp(`\\s*${pluginName}\\(\\)\\s*,?`, 'g')
|
|
189
|
-
pluginsContent = pluginsContent.replace(pluginRegex, '')
|
|
190
|
-
})
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Add plugins
|
|
194
|
-
if (pluginUpdates.add) {
|
|
195
|
-
pluginUpdates.add.forEach((pluginImport: string) => {
|
|
196
|
-
// This will match: import { PluginName } from '...';
|
|
197
|
-
const match = pluginImport.match(/import\s*\{\s*(\w+)\s*\}/)
|
|
198
|
-
if (match && match[1]) {
|
|
199
|
-
const pluginName = match[1]
|
|
200
|
-
if (!pluginsContent.includes(`${pluginName}(`)) {
|
|
201
|
-
pluginsContent = pluginsContent.trim()
|
|
202
|
-
? `${pluginsContent}\n ${pluginName}(),`
|
|
203
|
-
: `\n ${pluginName}(),`
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
})
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
content = content.replace(pluginsRegex, `plugins: [${pluginsContent}\n ]`)
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return content
|
|
213
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import type { FieldDefinition, FieldModification } from '../../types.js'
|
|
2
|
-
|
|
3
|
-
/** Escapes a value for safe embedding inside a single-quoted TypeScript string literal. */
|
|
4
|
-
function escapeSingleQuotedString(value: string): string {
|
|
5
|
-
return value
|
|
6
|
-
.replace(/\\/g, '\\\\')
|
|
7
|
-
.replace(/'/g, "\\'")
|
|
8
|
-
.replace(/\r/g, '\\r')
|
|
9
|
-
.replace(/\n/g, '\\n')
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Generates the TypeScript source string for a single field definition block.
|
|
14
|
-
* Used when writing collection files to disk.
|
|
15
|
-
*/
|
|
16
|
-
export function generateFieldDefinitionString(field: FieldDefinition): string {
|
|
17
|
-
const lines: string[] = []
|
|
18
|
-
lines.push(` {`)
|
|
19
|
-
lines.push(` name: '${escapeSingleQuotedString(field.name)}',`)
|
|
20
|
-
lines.push(` type: '${escapeSingleQuotedString(field.type)}',`)
|
|
21
|
-
|
|
22
|
-
if (field.required) {
|
|
23
|
-
lines.push(` required: true,`)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (field.description || field.position) {
|
|
27
|
-
lines.push(` admin: {`)
|
|
28
|
-
if (field.description) {
|
|
29
|
-
lines.push(` description: '${escapeSingleQuotedString(field.description)}',`)
|
|
30
|
-
}
|
|
31
|
-
if (field.position) {
|
|
32
|
-
lines.push(` position: '${escapeSingleQuotedString(field.position)}',`)
|
|
33
|
-
}
|
|
34
|
-
lines.push(` },`)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (field.options && field.type === 'select') {
|
|
38
|
-
lines.push(` options: [`)
|
|
39
|
-
field.options.forEach((option) => {
|
|
40
|
-
lines.push(
|
|
41
|
-
` { label: '${escapeSingleQuotedString(option.label)}', value: '${escapeSingleQuotedString(option.value)}' },`,
|
|
42
|
-
)
|
|
43
|
-
})
|
|
44
|
-
lines.push(` ],`)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
lines.push(` },`)
|
|
48
|
-
return lines.join('\n')
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Adds new fields to a collection file content
|
|
53
|
-
*/
|
|
54
|
-
export function addFieldsToCollection(content: string, newFields: FieldDefinition[]): string {
|
|
55
|
-
// Find the fields array closing bracket
|
|
56
|
-
const fieldsRegex = /fields:\s*\[([\s\S]*?)\]\s*(?:,\s*)?\}/
|
|
57
|
-
const match = content.match(fieldsRegex)
|
|
58
|
-
|
|
59
|
-
if (!match) {
|
|
60
|
-
throw new Error('Could not find fields array in collection file')
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const newFieldDefinitions = newFields.map(generateFieldDefinitionString).join('\n')
|
|
64
|
-
|
|
65
|
-
// Add new fields before the closing bracket
|
|
66
|
-
const existingFields = match[1] || ''
|
|
67
|
-
const hasTrailingComma = existingFields.trim().endsWith(',')
|
|
68
|
-
const separator = hasTrailingComma ? '\n' : ',\n'
|
|
69
|
-
|
|
70
|
-
return content.replace(
|
|
71
|
-
fieldsRegex,
|
|
72
|
-
`fields: [${existingFields}${separator}${newFieldDefinitions}\n ],
|
|
73
|
-
}`,
|
|
74
|
-
)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Removes fields from a collection file content
|
|
79
|
-
*/
|
|
80
|
-
export function removeFieldsFromCollection(content: string, fieldNames: string[]): string {
|
|
81
|
-
let updatedContent = content
|
|
82
|
-
|
|
83
|
-
fieldNames.forEach((fieldName) => {
|
|
84
|
-
// Create regex to match the field definition
|
|
85
|
-
const fieldRegex = new RegExp(
|
|
86
|
-
`\\s*{[^}]*name:\\s*['"]${fieldName}['"][^}]*}[^}]*(?:},?|,?\\s*})`,
|
|
87
|
-
'gs',
|
|
88
|
-
)
|
|
89
|
-
updatedContent = updatedContent.replace(fieldRegex, '')
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
// Clean up any double commas or trailing commas
|
|
93
|
-
updatedContent = updatedContent.replace(/,\s*,/g, ',')
|
|
94
|
-
updatedContent = updatedContent.replace(/,\s*\]/g, '\n ]')
|
|
95
|
-
|
|
96
|
-
return updatedContent
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Modifies existing fields in a collection file content
|
|
101
|
-
*/
|
|
102
|
-
export function modifyFieldsInCollection(
|
|
103
|
-
content: string,
|
|
104
|
-
modifications: FieldModification[],
|
|
105
|
-
): string {
|
|
106
|
-
let updatedContent = content
|
|
107
|
-
|
|
108
|
-
modifications.forEach((mod) => {
|
|
109
|
-
const { changes, fieldName } = mod
|
|
110
|
-
|
|
111
|
-
// Find the field definition
|
|
112
|
-
const fieldRegex = new RegExp(`({[^}]*name:\\s*['"]${fieldName}['"][^}]*})`, 'gs')
|
|
113
|
-
const fieldMatch = updatedContent.match(fieldRegex)
|
|
114
|
-
|
|
115
|
-
if (fieldMatch) {
|
|
116
|
-
let fieldDef = fieldMatch[0]
|
|
117
|
-
|
|
118
|
-
// Apply changes
|
|
119
|
-
if (changes.type) {
|
|
120
|
-
fieldDef = fieldDef.replace(/type:\s*'[^']*'/, `type: '${changes.type}'`)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (changes.required !== undefined) {
|
|
124
|
-
if (fieldDef.includes('required:')) {
|
|
125
|
-
fieldDef = fieldDef.replace(/required:[^,]*/, `required: ${changes.required}`)
|
|
126
|
-
} else {
|
|
127
|
-
fieldDef = fieldDef.replace(
|
|
128
|
-
/type:\s*'[^']*',/,
|
|
129
|
-
`type: '${changes.type}',\n required: ${changes.required},`,
|
|
130
|
-
)
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (changes.description) {
|
|
135
|
-
const adminRegex = /admin:\s*\{[^}]*\}/
|
|
136
|
-
if (fieldDef.match(adminRegex)) {
|
|
137
|
-
fieldDef = fieldDef.replace(
|
|
138
|
-
/description:\s*'[^']*'/,
|
|
139
|
-
`description: '${changes.description}'`,
|
|
140
|
-
)
|
|
141
|
-
} else {
|
|
142
|
-
fieldDef = fieldDef.replace(
|
|
143
|
-
/\},?\s*$/,
|
|
144
|
-
`,\n admin: {\n description: '${changes.description}',\n },\n }`,
|
|
145
|
-
)
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
updatedContent = updatedContent.replace(fieldRegex, fieldDef)
|
|
150
|
-
}
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
return updatedContent
|
|
154
|
-
}
|