@payloadcms/plugin-mcp 4.0.0-internal.5214550 → 4.0.0-internal.532221d
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/bin.js +7 -0
- package/dist/defaultAccess.d.ts.map +1 -1
- package/dist/defineTool.d.ts +8 -8
- package/dist/defineTool.d.ts.map +1 -1
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +92 -41
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.js +1 -2
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/fileInput.d.ts +28 -0
- package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.js +124 -0
- package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.spec.js +86 -0
- package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -0
- package/dist/mcp/builtin/collections/findTool.js +1 -1
- package/dist/mcp/builtin/collections/findTool.js.map +1 -1
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +1 -1
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/formatCollectionError.js +1 -1
- package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +25 -4
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js +23 -12
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +1 -2
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.js +1 -2
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -1
- package/dist/mcp/builtin/validateEntityData.js +1 -1
- package/dist/mcp/builtin/validateEntityData.js.map +1 -1
- package/dist/mcp/builtinTools.d.ts +6 -0
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/builtinTools.js +9 -3
- package/dist/mcp/builtinTools.js.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.js +4 -1
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
- package/dist/stdio.d.ts.map +1 -1
- package/dist/stdio.js +2 -1
- package/dist/stdio.js.map +1 -1
- package/dist/utils/camelCase.d.ts.map +1 -1
- package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
- package/dist/utils/toStandardSchema.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/mcp/builtin/collections/createTool.ts +95 -38
- package/src/mcp/builtin/collections/duplicateTool.ts +5 -5
- package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
- package/src/mcp/builtin/collections/fileInput.ts +164 -0
- package/src/mcp/builtin/collections/findTool.ts +1 -1
- package/src/mcp/builtin/collections/formatCollectionError.ts +2 -2
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +19 -3
- package/src/mcp/builtin/collections/updateTool.ts +30 -13
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +1 -2
- package/src/mcp/builtin/globals/updateTool.ts +5 -5
- package/src/mcp/builtin/validateEntityData.ts +3 -7
- package/src/mcp/builtinTools.ts +9 -2
- package/src/mcp/sanitizeMCPConfig.ts +4 -1
- package/src/stdio.ts +2 -1
- package/dist/utils/getVirtualFieldNames.d.ts +0 -14
- package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
- package/dist/utils/getVirtualFieldNames.js +0 -35
- package/dist/utils/getVirtualFieldNames.js.map +0 -1
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +0 -28
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +0 -1
- package/dist/utils/schemaConversion/filterFieldsByAccess.js +0 -71
- package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +0 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +0 -13
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -66
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -10
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -384
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -133
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
- package/dist/utils/transformPointDataToPayload.d.ts +0 -7
- package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
- package/dist/utils/transformPointDataToPayload.js +0 -28
- package/dist/utils/transformPointDataToPayload.js.map +0 -1
- package/src/utils/getVirtualFieldNames.ts +0 -53
- package/src/utils/schemaConversion/filterFieldsByAccess.ts +0 -123
- package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -96
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -96
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -432
- package/src/utils/transformPointDataToPayload.ts +0 -40
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { getUploadInstructions as getPayloadUploadInstructions } from 'payload/internal'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
5
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
6
|
+
|
|
7
|
+
export const getUploadInstructionsTool = defineCollectionTool({
|
|
8
|
+
access: (args) =>
|
|
9
|
+
defaultAccess(args) &&
|
|
10
|
+
Boolean(
|
|
11
|
+
args.permissions?.collections?.[args.collectionSlug]?.create ||
|
|
12
|
+
args.permissions?.collections?.[args.collectionSlug]?.update,
|
|
13
|
+
),
|
|
14
|
+
annotations: {
|
|
15
|
+
destructiveHint: false,
|
|
16
|
+
idempotentHint: false,
|
|
17
|
+
openWorldHint: true,
|
|
18
|
+
readOnlyHint: false,
|
|
19
|
+
title: 'Get Upload Instructions',
|
|
20
|
+
},
|
|
21
|
+
description:
|
|
22
|
+
'Prepare uploads for createDocuments or updateDocument. This does not upload bytes; finish the returned action before use.',
|
|
23
|
+
input: z.object({
|
|
24
|
+
docPrefix: z.string().describe('Optional document folder or prefix').optional(),
|
|
25
|
+
filename: z.string().describe('The original file name'),
|
|
26
|
+
filesize: z.number().int().nonnegative().describe('The file size in bytes'),
|
|
27
|
+
mimeType: z.string().describe('The file MIME type'),
|
|
28
|
+
}),
|
|
29
|
+
}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
|
|
30
|
+
try {
|
|
31
|
+
const instructions = await getPayloadUploadInstructions({
|
|
32
|
+
...input,
|
|
33
|
+
collectionSlug,
|
|
34
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
35
|
+
req,
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const nextStep =
|
|
39
|
+
instructions.type === 'http'
|
|
40
|
+
? 'Upload bytes with instructions.request. After success, pass { source: "uploadReference", file: instructions.file }.'
|
|
41
|
+
: `Call "${instructions.name}" with file and data. After success, pass { source: "uploadReference", file: instructions.file }.`
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
type: 'text',
|
|
47
|
+
text: `Upload instructions for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(instructions)}\n\`\`\`\n${nextStep}`,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
structuredContent: { instructions },
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
const message = error instanceof Error ? error.message : 'Unknown error'
|
|
54
|
+
return {
|
|
55
|
+
content: [
|
|
56
|
+
{
|
|
57
|
+
type: 'text',
|
|
58
|
+
text: `Error getting upload instructions for collection "${collectionSlug}": ${message}`,
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
isError: true,
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
})
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { getAccessResults } from 'payload'
|
|
1
|
+
import { getAccessResults, getGlobalInputSchema } from 'payload'
|
|
2
2
|
|
|
3
3
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
4
|
import { defineGlobalTool } from '../../../defineTool.js'
|
|
5
|
-
import { getGlobalInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'
|
|
6
5
|
|
|
7
6
|
export const getGlobalSchemaTool = defineGlobalTool({
|
|
8
7
|
access: (args) => {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { SelectType } from 'payload'
|
|
2
2
|
|
|
3
|
+
import {
|
|
4
|
+
getGlobalVirtualFieldNames,
|
|
5
|
+
stripVirtualFields,
|
|
6
|
+
transformPointDataToPayload,
|
|
7
|
+
} from 'payload'
|
|
3
8
|
import { z } from 'zod'
|
|
4
9
|
|
|
5
10
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
11
|
import { defineGlobalTool } from '../../../defineTool.js'
|
|
7
12
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import {
|
|
9
|
-
getGlobalVirtualFieldNames,
|
|
10
|
-
stripVirtualFields,
|
|
11
|
-
} from '../../../utils/getVirtualFieldNames.js'
|
|
12
|
-
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
|
|
13
13
|
import { validateGlobalData } from '../validateEntityData.js'
|
|
14
14
|
|
|
15
15
|
const DEFAULT_DESCRIPTION = 'Update any Payload global by passing the global slug and data.'
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { CollectionSlug, GlobalSlug, PayloadRequest, SanitizedConfig } from 'payload'
|
|
2
2
|
|
|
3
3
|
import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/server/validators/cf-worker'
|
|
4
|
+
import { getCollectionInputSchema, getGlobalInputSchema } from 'payload'
|
|
4
5
|
|
|
5
6
|
import type { JsonSchemaType, MCPToolResponse } from '../../types.js'
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
-
getCollectionInputSchema,
|
|
9
|
-
getGlobalInputSchema,
|
|
10
|
-
} from '../../utils/schemaConversion/getEntityInputSchema.js'
|
|
11
|
-
|
|
12
8
|
/**
|
|
13
9
|
* Keep the default `shortcircuit: true` - `false` makes validating nested rich text exponentially slow.
|
|
14
10
|
*/
|
|
@@ -38,7 +34,7 @@ export const validateCollectionData = ({
|
|
|
38
34
|
}): MCPToolResponse | null =>
|
|
39
35
|
validateData({
|
|
40
36
|
slug: collectionSlug,
|
|
41
|
-
buildSchema: () => getCollectionInputSchema({ collectionSlug, req }),
|
|
37
|
+
buildSchema: () => getCollectionInputSchema({ collectionSlug, req }) as JsonSchemaType | null,
|
|
42
38
|
data,
|
|
43
39
|
entity: 'collection',
|
|
44
40
|
partial,
|
|
@@ -56,7 +52,7 @@ export const validateGlobalData = ({
|
|
|
56
52
|
}): MCPToolResponse | null =>
|
|
57
53
|
validateData({
|
|
58
54
|
slug: globalSlug,
|
|
59
|
-
buildSchema: () => getGlobalInputSchema({ globalSlug, req }),
|
|
55
|
+
buildSchema: () => getGlobalInputSchema({ globalSlug, req }) as JsonSchemaType | null,
|
|
60
56
|
data,
|
|
61
57
|
entity: 'global',
|
|
62
58
|
partial: true,
|
package/src/mcp/builtinTools.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from './builtin/collections/authTools.js'
|
|
11
11
|
import { countDocumentsTool } from './builtin/collections/countTool.js'
|
|
12
12
|
import { countVersionsTool } from './builtin/collections/countVersionsTool.js'
|
|
13
|
-
import {
|
|
13
|
+
import { createDocumentsTool } from './builtin/collections/createTool.js'
|
|
14
14
|
import { deleteDocumentsTool } from './builtin/collections/deleteTool.js'
|
|
15
15
|
import { duplicateDocumentTool } from './builtin/collections/duplicateTool.js'
|
|
16
16
|
import { findDistinctTool } from './builtin/collections/findDistinctTool.js'
|
|
@@ -20,6 +20,7 @@ import { findVersionsTool } from './builtin/collections/findVersionsTool.js'
|
|
|
20
20
|
import { getCollectionSchemaTool } from './builtin/collections/getCollectionSchemaTool.js'
|
|
21
21
|
import { restoreVersionTool } from './builtin/collections/restoreVersionTool.js'
|
|
22
22
|
import { updateDocumentTool } from './builtin/collections/updateTool.js'
|
|
23
|
+
import { getUploadInstructionsTool } from './builtin/collections/uploadInstructionsTool.js'
|
|
23
24
|
import { getConfigInfoTool } from './builtin/getConfigInfoTool.js'
|
|
24
25
|
import { countGlobalVersionsTool } from './builtin/globals/countVersionsTool.js'
|
|
25
26
|
import { findGlobalTool } from './builtin/globals/findTool.js'
|
|
@@ -32,6 +33,7 @@ import { updateGlobalTool } from './builtin/globals/updateTool.js'
|
|
|
32
33
|
type CollectionBuiltin = {
|
|
33
34
|
mcpName: string
|
|
34
35
|
requiresDuplicateEnabled?: boolean
|
|
36
|
+
requiresUpload?: boolean
|
|
35
37
|
requiresVersions?: boolean
|
|
36
38
|
tool: CollectionTool
|
|
37
39
|
}
|
|
@@ -54,7 +56,7 @@ export const TOOL_BUILTINS = {
|
|
|
54
56
|
export const COLLECTION_BUILTINS = {
|
|
55
57
|
count: { mcpName: 'countDocuments', tool: countDocumentsTool },
|
|
56
58
|
countVersions: { mcpName: 'countVersions', requiresVersions: true, tool: countVersionsTool },
|
|
57
|
-
create: { mcpName: '
|
|
59
|
+
create: { mcpName: 'createDocuments', tool: createDocumentsTool },
|
|
58
60
|
delete: { mcpName: 'deleteDocuments', tool: deleteDocumentsTool },
|
|
59
61
|
duplicate: {
|
|
60
62
|
mcpName: 'duplicateDocument',
|
|
@@ -70,6 +72,11 @@ export const COLLECTION_BUILTINS = {
|
|
|
70
72
|
},
|
|
71
73
|
findVersions: { mcpName: 'findVersions', requiresVersions: true, tool: findVersionsTool },
|
|
72
74
|
getCollectionSchema: { mcpName: 'getCollectionSchema', tool: getCollectionSchemaTool },
|
|
75
|
+
getUploadInstructions: {
|
|
76
|
+
mcpName: 'getUploadInstructions',
|
|
77
|
+
requiresUpload: true,
|
|
78
|
+
tool: getUploadInstructionsTool,
|
|
79
|
+
},
|
|
73
80
|
restoreVersion: { mcpName: 'restoreVersion', requiresVersions: true, tool: restoreVersionTool },
|
|
74
81
|
update: { mcpName: 'updateDocument', tool: updateDocumentTool },
|
|
75
82
|
} satisfies Record<string, CollectionBuiltin>
|
|
@@ -127,7 +127,7 @@ const sanitizeCollectionConfig = ({
|
|
|
127
127
|
|
|
128
128
|
for (const [
|
|
129
129
|
toolKey,
|
|
130
|
-
{ mcpName, requiresDuplicateEnabled, requiresVersions, tool },
|
|
130
|
+
{ mcpName, requiresDuplicateEnabled, requiresUpload, requiresVersions, tool },
|
|
131
131
|
] of COLLECTION_BUILTIN_ENTRIES) {
|
|
132
132
|
if (requiresVersions && !collection.versions) {
|
|
133
133
|
continue
|
|
@@ -135,6 +135,9 @@ const sanitizeCollectionConfig = ({
|
|
|
135
135
|
if (requiresDuplicateEnabled && isDuplicateDisabled) {
|
|
136
136
|
continue
|
|
137
137
|
}
|
|
138
|
+
if (requiresUpload && !collection.upload) {
|
|
139
|
+
continue
|
|
140
|
+
}
|
|
138
141
|
const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey]
|
|
139
142
|
if (matchedConfigEntry === false) {
|
|
140
143
|
continue
|
package/src/stdio.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Config, Plugin, SanitizedConfig } from 'payload'
|
|
|
4
4
|
import { serveStdio } from '@modelcontextprotocol/server/stdio'
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
6
6
|
import { createLocalReq, getPayload } from 'payload'
|
|
7
|
-
import { findConfig } from 'payload/node'
|
|
7
|
+
import { findConfig, loadEnv } from 'payload/node'
|
|
8
8
|
|
|
9
9
|
import type { SanitizedMCPPluginConfig } from './types.js'
|
|
10
10
|
|
|
@@ -28,6 +28,7 @@ export const runMcpStdio = async (): Promise<void> => {
|
|
|
28
28
|
process.chdir(projectRoot)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
loadEnv()
|
|
31
32
|
const configPath = findConfig()
|
|
32
33
|
const configModule = await import(pathToFileURL(configPath).toString())
|
|
33
34
|
const config = (await (configModule.default ?? configModule)) as SanitizedConfig
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { SanitizedConfig } from 'payload';
|
|
2
|
-
/**
|
|
3
|
-
* Returns the names of all top-level virtual fields for a given collection slug.
|
|
4
|
-
*/
|
|
5
|
-
export declare function getCollectionVirtualFieldNames(config: SanitizedConfig, slug: string): string[];
|
|
6
|
-
/**
|
|
7
|
-
* Returns the names of all top-level virtual fields for a given global slug.
|
|
8
|
-
*/
|
|
9
|
-
export declare function getGlobalVirtualFieldNames(config: SanitizedConfig, slug: string): string[];
|
|
10
|
-
/**
|
|
11
|
-
* Strips virtual field values from a data object given a list of virtual field names.
|
|
12
|
-
*/
|
|
13
|
-
export declare function stripVirtualFields(data: Record<string, unknown>, virtualFieldNames: string[]): Record<string, unknown>;
|
|
14
|
-
//# sourceMappingURL=getVirtualFieldNames.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getVirtualFieldNames.d.ts","sourceRoot":"","sources":["../../src/utils/getVirtualFieldNames.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAI9C;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAU9F;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAU1F;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,iBAAiB,EAAE,MAAM,EAAE,GAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzB"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { fieldIsVirtual } from 'payload/shared';
|
|
2
|
-
/**
|
|
3
|
-
* Returns the names of all top-level virtual fields for a given collection slug.
|
|
4
|
-
*/ export function getCollectionVirtualFieldNames(config, slug) {
|
|
5
|
-
const collection = config.collections.find((c)=>c.slug === slug);
|
|
6
|
-
if (!collection) {
|
|
7
|
-
return [];
|
|
8
|
-
}
|
|
9
|
-
return collection.flattenedFields.filter((field)=>'name' in field && fieldIsVirtual(field)).map((field)=>field.name);
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Returns the names of all top-level virtual fields for a given global slug.
|
|
13
|
-
*/ export function getGlobalVirtualFieldNames(config, slug) {
|
|
14
|
-
const global = config.globals.find((g)=>g.slug === slug);
|
|
15
|
-
if (!global) {
|
|
16
|
-
return [];
|
|
17
|
-
}
|
|
18
|
-
return global.flattenedFields.filter((field)=>'name' in field && fieldIsVirtual(field)).map((field)=>field.name);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Strips virtual field values from a data object given a list of virtual field names.
|
|
22
|
-
*/ export function stripVirtualFields(data, virtualFieldNames) {
|
|
23
|
-
if (virtualFieldNames.length === 0) {
|
|
24
|
-
return data;
|
|
25
|
-
}
|
|
26
|
-
const stripped = {
|
|
27
|
-
...data
|
|
28
|
-
};
|
|
29
|
-
for (const name of virtualFieldNames){
|
|
30
|
-
delete stripped[name];
|
|
31
|
-
}
|
|
32
|
-
return stripped;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
//# sourceMappingURL=getVirtualFieldNames.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/getVirtualFieldNames.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload'\n\nimport { fieldIsVirtual } from 'payload/shared'\n\n/**\n * Returns the names of all top-level virtual fields for a given collection slug.\n */\nexport function getCollectionVirtualFieldNames(config: SanitizedConfig, slug: string): string[] {\n const collection = config.collections.find((c) => c.slug === slug)\n\n if (!collection) {\n return []\n }\n\n return collection.flattenedFields\n .filter((field) => 'name' in field && fieldIsVirtual(field))\n .map((field) => (field as { name: string }).name)\n}\n\n/**\n * Returns the names of all top-level virtual fields for a given global slug.\n */\nexport function getGlobalVirtualFieldNames(config: SanitizedConfig, slug: string): string[] {\n const global = config.globals.find((g) => g.slug === slug)\n\n if (!global) {\n return []\n }\n\n return global.flattenedFields\n .filter((field) => 'name' in field && fieldIsVirtual(field))\n .map((field) => (field as { name: string }).name)\n}\n\n/**\n * Strips virtual field values from a data object given a list of virtual field names.\n */\nexport function stripVirtualFields(\n data: Record<string, unknown>,\n virtualFieldNames: string[],\n): Record<string, unknown> {\n if (virtualFieldNames.length === 0) {\n return data\n }\n\n const stripped = { ...data }\n\n for (const name of virtualFieldNames) {\n delete stripped[name]\n }\n\n return stripped\n}\n"],"names":["fieldIsVirtual","getCollectionVirtualFieldNames","config","slug","collection","collections","find","c","flattenedFields","filter","field","map","name","getGlobalVirtualFieldNames","global","globals","g","stripVirtualFields","data","virtualFieldNames","length","stripped"],"mappings":"AAEA,SAASA,cAAc,QAAQ,iBAAgB;AAE/C;;CAEC,GACD,OAAO,SAASC,+BAA+BC,MAAuB,EAAEC,IAAY;IAClF,MAAMC,aAAaF,OAAOG,WAAW,CAACC,IAAI,CAAC,CAACC,IAAMA,EAAEJ,IAAI,KAAKA;IAE7D,IAAI,CAACC,YAAY;QACf,OAAO,EAAE;IACX;IAEA,OAAOA,WAAWI,eAAe,CAC9BC,MAAM,CAAC,CAACC,QAAU,UAAUA,SAASV,eAAeU,QACpDC,GAAG,CAAC,CAACD,QAAU,AAACA,MAA2BE,IAAI;AACpD;AAEA;;CAEC,GACD,OAAO,SAASC,2BAA2BX,MAAuB,EAAEC,IAAY;IAC9E,MAAMW,SAASZ,OAAOa,OAAO,CAACT,IAAI,CAAC,CAACU,IAAMA,EAAEb,IAAI,KAAKA;IAErD,IAAI,CAACW,QAAQ;QACX,OAAO,EAAE;IACX;IAEA,OAAOA,OAAON,eAAe,CAC1BC,MAAM,CAAC,CAACC,QAAU,UAAUA,SAASV,eAAeU,QACpDC,GAAG,CAAC,CAACD,QAAU,AAACA,MAA2BE,IAAI;AACpD;AAEA;;CAEC,GACD,OAAO,SAASK,mBACdC,IAA6B,EAC7BC,iBAA2B;IAE3B,IAAIA,kBAAkBC,MAAM,KAAK,GAAG;QAClC,OAAOF;IACT;IAEA,MAAMG,WAAW;QAAE,GAAGH,IAAI;IAAC;IAE3B,KAAK,MAAMN,QAAQO,kBAAmB;QACpC,OAAOE,QAAQ,CAACT,KAAK;IACvB;IAEA,OAAOS;AACT"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { FlattenedBlock, FlattenedField, Operation, SanitizedDocumentPermissions } from 'payload';
|
|
2
|
-
type FieldOperation = Exclude<Operation, 'delete'>;
|
|
3
|
-
type AllowedFieldOperations = Record<FieldOperation, boolean>;
|
|
4
|
-
/**
|
|
5
|
-
* Filters fields using the access results in `permissions`. `shouldExcludeField` receives the
|
|
6
|
-
* operations allowed by the entity, field, and its parents and decides whether to remove the
|
|
7
|
-
* field.
|
|
8
|
-
*
|
|
9
|
-
* Arrays, groups, named tabs, and blocks are filtered recursively. Rows and unnamed tabs are
|
|
10
|
-
* flattened by Payload, so their children are filtered at the containing level.
|
|
11
|
-
*
|
|
12
|
-
* @example Include fields writable through any collection operation the user can perform.
|
|
13
|
-
* ```ts
|
|
14
|
-
* filterFieldsByAccess({
|
|
15
|
-
* fields,
|
|
16
|
-
* permissions: collectionPermissions,
|
|
17
|
-
* shouldExcludeField: ({ create, update }) => !create && !update,
|
|
18
|
-
* })
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export declare const filterFieldsByAccess: ({ blocks, fields, permissions, shouldExcludeField, }: {
|
|
22
|
-
blocks?: FlattenedBlock[];
|
|
23
|
-
fields: FlattenedField[];
|
|
24
|
-
permissions: SanitizedDocumentPermissions;
|
|
25
|
-
shouldExcludeField: (allowedOperations: AllowedFieldOperations) => boolean;
|
|
26
|
-
}) => FlattenedField[];
|
|
27
|
-
export {};
|
|
28
|
-
//# sourceMappingURL=filterFieldsByAccess.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filterFieldsByAccess.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/filterFieldsByAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,SAAS,EACT,4BAA4B,EAE7B,MAAM,SAAS,CAAA;AAEhB,KAAK,cAAc,GAAG,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;AAClD,KAAK,sBAAsB,GAAG,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;AAE7D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,oBAAoB,GAAI,sDAKlC;IACD,MAAM,CAAC,EAAE,cAAc,EAAE,CAAA;IACzB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,WAAW,EAAE,4BAA4B,CAAA;IACzC,kBAAkB,EAAE,CAAC,iBAAiB,EAAE,sBAAsB,KAAK,OAAO,CAAA;CAC3E,KAAG,cAAc,EAoFjB,CAAA"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Filters fields using the access results in `permissions`. `shouldExcludeField` receives the
|
|
3
|
-
* operations allowed by the entity, field, and its parents and decides whether to remove the
|
|
4
|
-
* field.
|
|
5
|
-
*
|
|
6
|
-
* Arrays, groups, named tabs, and blocks are filtered recursively. Rows and unnamed tabs are
|
|
7
|
-
* flattened by Payload, so their children are filtered at the containing level.
|
|
8
|
-
*
|
|
9
|
-
* @example Include fields writable through any collection operation the user can perform.
|
|
10
|
-
* ```ts
|
|
11
|
-
* filterFieldsByAccess({
|
|
12
|
-
* fields,
|
|
13
|
-
* permissions: collectionPermissions,
|
|
14
|
-
* shouldExcludeField: ({ create, update }) => !create && !update,
|
|
15
|
-
* })
|
|
16
|
-
* ```
|
|
17
|
-
*/ export const filterFieldsByAccess = ({ blocks, fields, permissions, shouldExcludeField })=>{
|
|
18
|
-
const filterFields = (nestedFields, nestedPermissions, parentAllowedOperations)=>{
|
|
19
|
-
const accessibleFields = [];
|
|
20
|
-
for (const field of nestedFields){
|
|
21
|
-
const fieldPermissions = nestedPermissions === true ? true : nestedPermissions?.[field.name];
|
|
22
|
-
const isOperationAllowed = (operation)=>parentAllowedOperations[operation] && (fieldPermissions === true || fieldPermissions?.[operation] === true);
|
|
23
|
-
const allowedOperations = {
|
|
24
|
-
create: isOperationAllowed('create'),
|
|
25
|
-
read: isOperationAllowed('read'),
|
|
26
|
-
update: isOperationAllowed('update')
|
|
27
|
-
};
|
|
28
|
-
if (shouldExcludeField(allowedOperations)) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
if (field.type === 'blocks') {
|
|
32
|
-
const accessibleBlocks = [];
|
|
33
|
-
for (const blockOrReference of field.blocks){
|
|
34
|
-
const block = typeof blockOrReference === 'string' ? blocks?.find(({ slug })=>slug === blockOrReference) : blockOrReference;
|
|
35
|
-
if (!block) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
const blockPermissions = fieldPermissions === true ? true : fieldPermissions?.blocks === true ? true : fieldPermissions?.blocks?.[block.slug];
|
|
39
|
-
accessibleBlocks.push({
|
|
40
|
-
...block,
|
|
41
|
-
flattenedFields: filterFields(block.flattenedFields, blockPermissions === true ? true : blockPermissions?.fields, allowedOperations)
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
if (accessibleBlocks.length === 0) {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
accessibleFields.push({
|
|
48
|
-
...field,
|
|
49
|
-
blocks: accessibleBlocks
|
|
50
|
-
});
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
if (field.type === 'array' || field.type === 'group' || field.type === 'tab') {
|
|
54
|
-
accessibleFields.push({
|
|
55
|
-
...field,
|
|
56
|
-
flattenedFields: filterFields(field.flattenedFields, fieldPermissions === true ? true : fieldPermissions?.fields, allowedOperations)
|
|
57
|
-
});
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
accessibleFields.push(field);
|
|
61
|
-
}
|
|
62
|
-
return accessibleFields;
|
|
63
|
-
};
|
|
64
|
-
return filterFields(fields, permissions.fields, {
|
|
65
|
-
create: 'create' in permissions && permissions.create === true,
|
|
66
|
-
read: permissions.read === true,
|
|
67
|
-
update: permissions.update === true
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
//# sourceMappingURL=filterFieldsByAccess.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/schemaConversion/filterFieldsByAccess.ts"],"sourcesContent":["import type {\n FlattenedBlock,\n FlattenedField,\n Operation,\n SanitizedDocumentPermissions,\n SanitizedFieldsPermissions,\n} from 'payload'\n\ntype FieldOperation = Exclude<Operation, 'delete'>\ntype AllowedFieldOperations = Record<FieldOperation, boolean>\n\n/**\n * Filters fields using the access results in `permissions`. `shouldExcludeField` receives the\n * operations allowed by the entity, field, and its parents and decides whether to remove the\n * field.\n *\n * Arrays, groups, named tabs, and blocks are filtered recursively. Rows and unnamed tabs are\n * flattened by Payload, so their children are filtered at the containing level.\n *\n * @example Include fields writable through any collection operation the user can perform.\n * ```ts\n * filterFieldsByAccess({\n * fields,\n * permissions: collectionPermissions,\n * shouldExcludeField: ({ create, update }) => !create && !update,\n * })\n * ```\n */\nexport const filterFieldsByAccess = ({\n blocks,\n fields,\n permissions,\n shouldExcludeField,\n}: {\n blocks?: FlattenedBlock[]\n fields: FlattenedField[]\n permissions: SanitizedDocumentPermissions\n shouldExcludeField: (allowedOperations: AllowedFieldOperations) => boolean\n}): FlattenedField[] => {\n const filterFields = (\n nestedFields: FlattenedField[],\n nestedPermissions: SanitizedFieldsPermissions | undefined,\n parentAllowedOperations: AllowedFieldOperations,\n ): FlattenedField[] => {\n const accessibleFields: FlattenedField[] = []\n\n for (const field of nestedFields) {\n const fieldPermissions = nestedPermissions === true ? true : nestedPermissions?.[field.name]\n const isOperationAllowed = (operation: FieldOperation): boolean =>\n parentAllowedOperations[operation] &&\n (fieldPermissions === true || fieldPermissions?.[operation] === true)\n const allowedOperations: AllowedFieldOperations = {\n create: isOperationAllowed('create'),\n read: isOperationAllowed('read'),\n update: isOperationAllowed('update'),\n }\n\n if (shouldExcludeField(allowedOperations)) {\n continue\n }\n\n if (field.type === 'blocks') {\n const accessibleBlocks: (FlattenedBlock | string)[] = []\n\n for (const blockOrReference of field.blocks) {\n const block =\n typeof blockOrReference === 'string'\n ? blocks?.find(({ slug }) => slug === blockOrReference)\n : blockOrReference\n\n if (!block) {\n continue\n }\n\n const blockPermissions =\n fieldPermissions === true\n ? true\n : fieldPermissions?.blocks === true\n ? true\n : fieldPermissions?.blocks?.[block.slug]\n\n accessibleBlocks.push({\n ...block,\n flattenedFields: filterFields(\n block.flattenedFields,\n blockPermissions === true ? true : blockPermissions?.fields,\n allowedOperations,\n ),\n })\n }\n\n if (accessibleBlocks.length === 0) {\n continue\n }\n\n accessibleFields.push({ ...field, blocks: accessibleBlocks })\n continue\n }\n\n if (field.type === 'array' || field.type === 'group' || field.type === 'tab') {\n accessibleFields.push({\n ...field,\n flattenedFields: filterFields(\n field.flattenedFields,\n fieldPermissions === true ? true : fieldPermissions?.fields,\n allowedOperations,\n ),\n })\n continue\n }\n\n accessibleFields.push(field)\n }\n\n return accessibleFields\n }\n\n return filterFields(fields, permissions.fields, {\n create: 'create' in permissions && permissions.create === true,\n read: permissions.read === true,\n update: permissions.update === true,\n })\n}\n"],"names":["filterFieldsByAccess","blocks","fields","permissions","shouldExcludeField","filterFields","nestedFields","nestedPermissions","parentAllowedOperations","accessibleFields","field","fieldPermissions","name","isOperationAllowed","operation","allowedOperations","create","read","update","type","accessibleBlocks","blockOrReference","block","find","slug","blockPermissions","push","flattenedFields","length"],"mappings":"AAWA;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,MAAMA,uBAAuB,CAAC,EACnCC,MAAM,EACNC,MAAM,EACNC,WAAW,EACXC,kBAAkB,EAMnB;IACC,MAAMC,eAAe,CACnBC,cACAC,mBACAC;QAEA,MAAMC,mBAAqC,EAAE;QAE7C,KAAK,MAAMC,SAASJ,aAAc;YAChC,MAAMK,mBAAmBJ,sBAAsB,OAAO,OAAOA,mBAAmB,CAACG,MAAME,IAAI,CAAC;YAC5F,MAAMC,qBAAqB,CAACC,YAC1BN,uBAAuB,CAACM,UAAU,IACjCH,CAAAA,qBAAqB,QAAQA,kBAAkB,CAACG,UAAU,KAAK,IAAG;YACrE,MAAMC,oBAA4C;gBAChDC,QAAQH,mBAAmB;gBAC3BI,MAAMJ,mBAAmB;gBACzBK,QAAQL,mBAAmB;YAC7B;YAEA,IAAIT,mBAAmBW,oBAAoB;gBACzC;YACF;YAEA,IAAIL,MAAMS,IAAI,KAAK,UAAU;gBAC3B,MAAMC,mBAAgD,EAAE;gBAExD,KAAK,MAAMC,oBAAoBX,MAAMT,MAAM,CAAE;oBAC3C,MAAMqB,QACJ,OAAOD,qBAAqB,WACxBpB,QAAQsB,KAAK,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASH,oBACpCA;oBAEN,IAAI,CAACC,OAAO;wBACV;oBACF;oBAEA,MAAMG,mBACJd,qBAAqB,OACjB,OACAA,kBAAkBV,WAAW,OAC3B,OACAU,kBAAkBV,QAAQ,CAACqB,MAAME,IAAI,CAAC;oBAE9CJ,iBAAiBM,IAAI,CAAC;wBACpB,GAAGJ,KAAK;wBACRK,iBAAiBtB,aACfiB,MAAMK,eAAe,EACrBF,qBAAqB,OAAO,OAAOA,kBAAkBvB,QACrDa;oBAEJ;gBACF;gBAEA,IAAIK,iBAAiBQ,MAAM,KAAK,GAAG;oBACjC;gBACF;gBAEAnB,iBAAiBiB,IAAI,CAAC;oBAAE,GAAGhB,KAAK;oBAAET,QAAQmB;gBAAiB;gBAC3D;YACF;YAEA,IAAIV,MAAMS,IAAI,KAAK,WAAWT,MAAMS,IAAI,KAAK,WAAWT,MAAMS,IAAI,KAAK,OAAO;gBAC5EV,iBAAiBiB,IAAI,CAAC;oBACpB,GAAGhB,KAAK;oBACRiB,iBAAiBtB,aACfK,MAAMiB,eAAe,EACrBhB,qBAAqB,OAAO,OAAOA,kBAAkBT,QACrDa;gBAEJ;gBACA;YACF;YAEAN,iBAAiBiB,IAAI,CAAChB;QACxB;QAEA,OAAOD;IACT;IAEA,OAAOJ,aAAaH,QAAQC,YAAYD,MAAM,EAAE;QAC9Cc,QAAQ,YAAYb,eAAeA,YAAYa,MAAM,KAAK;QAC1DC,MAAMd,YAAYc,IAAI,KAAK;QAC3BC,QAAQf,YAAYe,MAAM,KAAK;IACjC;AACF,EAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type CollectionSlug, type GlobalSlug, type PayloadRequest, type SanitizedCollectionPermission, type SanitizedGlobalPermission } from 'payload';
|
|
2
|
-
import type { JsonSchemaType } from '../../types.js';
|
|
3
|
-
export declare const getCollectionInputSchema: ({ collectionSlug, permissions, req, }: {
|
|
4
|
-
collectionSlug: CollectionSlug;
|
|
5
|
-
permissions?: SanitizedCollectionPermission;
|
|
6
|
-
req: PayloadRequest;
|
|
7
|
-
}) => JsonSchemaType | null;
|
|
8
|
-
export declare const getGlobalInputSchema: ({ globalSlug, permissions, req, }: {
|
|
9
|
-
globalSlug: GlobalSlug;
|
|
10
|
-
permissions?: SanitizedGlobalPermission;
|
|
11
|
-
req: PayloadRequest;
|
|
12
|
-
}) => JsonSchemaType | null;
|
|
13
|
-
//# sourceMappingURL=getEntityInputSchema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getEntityInputSchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/getEntityInputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EAGnB,KAAK,UAAU,EACf,KAAK,cAAc,EAEnB,KAAK,6BAA6B,EAElC,KAAK,yBAAyB,EAC/B,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAKpD,eAAO,MAAM,wBAAwB,GAAI,uCAItC;IACD,cAAc,EAAE,cAAc,CAAA;IAC9B,WAAW,CAAC,EAAE,6BAA6B,CAAA;IAC3C,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,cAAc,GAAG,IAmBpB,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,mCAIlC;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,WAAW,CAAC,EAAE,yBAAyB,CAAA;IACvC,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,cAAc,GAAG,IAmBpB,CAAA"}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { entityToStandaloneJSONSchema } from 'payload';
|
|
2
|
-
import { filterFieldsByAccess } from './filterFieldsByAccess.js';
|
|
3
|
-
import { sanitizeEntitySchema } from './sanitizeEntitySchema.js';
|
|
4
|
-
export const getCollectionInputSchema = ({ collectionSlug, permissions, req })=>{
|
|
5
|
-
const collection = req.payload.collections[collectionSlug]?.config;
|
|
6
|
-
if (!collection) {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
if (!permissions) {
|
|
10
|
-
return buildEntityInputSchema({
|
|
11
|
-
entity: collection,
|
|
12
|
-
req
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
const fieldsAllowedByAccess = filterFieldsByAccess({
|
|
16
|
-
blocks: req.payload.config.blocks,
|
|
17
|
-
fields: collection.flattenedFields,
|
|
18
|
-
permissions,
|
|
19
|
-
shouldExcludeField: ({ create, update })=>!create && !update
|
|
20
|
-
});
|
|
21
|
-
return buildEntityInputSchema({
|
|
22
|
-
entity: collection,
|
|
23
|
-
fields: fieldsAllowedByAccess,
|
|
24
|
-
req
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
export const getGlobalInputSchema = ({ globalSlug, permissions, req })=>{
|
|
28
|
-
const global = req.payload.config.globals.find((globalConfig)=>globalConfig.slug === globalSlug);
|
|
29
|
-
if (!global) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
if (!permissions) {
|
|
33
|
-
return buildEntityInputSchema({
|
|
34
|
-
entity: global,
|
|
35
|
-
req
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
const fieldsAllowedByAccess = filterFieldsByAccess({
|
|
39
|
-
blocks: req.payload.config.blocks,
|
|
40
|
-
fields: global.flattenedFields,
|
|
41
|
-
permissions,
|
|
42
|
-
shouldExcludeField: ({ create, update })=>!create && !update
|
|
43
|
-
});
|
|
44
|
-
return buildEntityInputSchema({
|
|
45
|
-
entity: global,
|
|
46
|
-
fields: fieldsAllowedByAccess,
|
|
47
|
-
req
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
const buildEntityInputSchema = ({ entity, fields = entity.flattenedFields, req })=>{
|
|
51
|
-
// The core schema generator reads flattenedFields from the entity and has no fields argument.
|
|
52
|
-
const entityForSchema = {
|
|
53
|
-
...entity,
|
|
54
|
-
flattenedFields: fields
|
|
55
|
-
};
|
|
56
|
-
const schema = entityToStandaloneJSONSchema({
|
|
57
|
-
config: req.payload.config,
|
|
58
|
-
defaultIDType: req.payload.db.defaultIDType,
|
|
59
|
-
entity: entityForSchema,
|
|
60
|
-
i18n: req.i18n,
|
|
61
|
-
variant: 'input'
|
|
62
|
-
});
|
|
63
|
-
return sanitizeEntitySchema(schema);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
//# sourceMappingURL=getEntityInputSchema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/schemaConversion/getEntityInputSchema.ts"],"sourcesContent":["import {\n type CollectionSlug,\n entityToStandaloneJSONSchema,\n type FlattenedField,\n type GlobalSlug,\n type PayloadRequest,\n type SanitizedCollectionConfig,\n type SanitizedCollectionPermission,\n type SanitizedGlobalConfig,\n type SanitizedGlobalPermission,\n} from 'payload'\n\nimport type { JsonSchemaType } from '../../types.js'\n\nimport { filterFieldsByAccess } from './filterFieldsByAccess.js'\nimport { sanitizeEntitySchema } from './sanitizeEntitySchema.js'\n\nexport const getCollectionInputSchema = ({\n collectionSlug,\n permissions,\n req,\n}: {\n collectionSlug: CollectionSlug\n permissions?: SanitizedCollectionPermission\n req: PayloadRequest\n}): JsonSchemaType | null => {\n const collection = req.payload.collections[collectionSlug]?.config\n\n if (!collection) {\n return null\n }\n\n if (!permissions) {\n return buildEntityInputSchema({ entity: collection, req })\n }\n\n const fieldsAllowedByAccess = filterFieldsByAccess({\n blocks: req.payload.config.blocks,\n fields: collection.flattenedFields,\n permissions,\n shouldExcludeField: ({ create, update }) => !create && !update,\n })\n\n return buildEntityInputSchema({ entity: collection, fields: fieldsAllowedByAccess, req })\n}\n\nexport const getGlobalInputSchema = ({\n globalSlug,\n permissions,\n req,\n}: {\n globalSlug: GlobalSlug\n permissions?: SanitizedGlobalPermission\n req: PayloadRequest\n}): JsonSchemaType | null => {\n const global = req.payload.config.globals.find((globalConfig) => globalConfig.slug === globalSlug)\n\n if (!global) {\n return null\n }\n\n if (!permissions) {\n return buildEntityInputSchema({ entity: global, req })\n }\n\n const fieldsAllowedByAccess = filterFieldsByAccess({\n blocks: req.payload.config.blocks,\n fields: global.flattenedFields,\n permissions,\n shouldExcludeField: ({ create, update }) => !create && !update,\n })\n\n return buildEntityInputSchema({ entity: global, fields: fieldsAllowedByAccess, req })\n}\n\nconst buildEntityInputSchema = ({\n entity,\n fields = entity.flattenedFields,\n req,\n}: {\n entity: SanitizedCollectionConfig | SanitizedGlobalConfig\n fields?: FlattenedField[]\n req: PayloadRequest\n}): JsonSchemaType => {\n // The core schema generator reads flattenedFields from the entity and has no fields argument.\n const entityForSchema = { ...entity, flattenedFields: fields }\n const schema = entityToStandaloneJSONSchema({\n config: req.payload.config,\n defaultIDType: req.payload.db.defaultIDType,\n entity: entityForSchema,\n i18n: req.i18n,\n variant: 'input',\n }) as unknown as JsonSchemaType\n\n return sanitizeEntitySchema(schema)\n}\n"],"names":["entityToStandaloneJSONSchema","filterFieldsByAccess","sanitizeEntitySchema","getCollectionInputSchema","collectionSlug","permissions","req","collection","payload","collections","config","buildEntityInputSchema","entity","fieldsAllowedByAccess","blocks","fields","flattenedFields","shouldExcludeField","create","update","getGlobalInputSchema","globalSlug","global","globals","find","globalConfig","slug","entityForSchema","schema","defaultIDType","db","i18n","variant"],"mappings":"AAAA,SAEEA,4BAA4B,QAQvB,UAAS;AAIhB,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,oBAAoB,QAAQ,4BAA2B;AAEhE,OAAO,MAAMC,2BAA2B,CAAC,EACvCC,cAAc,EACdC,WAAW,EACXC,GAAG,EAKJ;IACC,MAAMC,aAAaD,IAAIE,OAAO,CAACC,WAAW,CAACL,eAAe,EAAEM;IAE5D,IAAI,CAACH,YAAY;QACf,OAAO;IACT;IAEA,IAAI,CAACF,aAAa;QAChB,OAAOM,uBAAuB;YAAEC,QAAQL;YAAYD;QAAI;IAC1D;IAEA,MAAMO,wBAAwBZ,qBAAqB;QACjDa,QAAQR,IAAIE,OAAO,CAACE,MAAM,CAACI,MAAM;QACjCC,QAAQR,WAAWS,eAAe;QAClCX;QACAY,oBAAoB,CAAC,EAAEC,MAAM,EAAEC,MAAM,EAAE,GAAK,CAACD,UAAU,CAACC;IAC1D;IAEA,OAAOR,uBAAuB;QAAEC,QAAQL;QAAYQ,QAAQF;QAAuBP;IAAI;AACzF,EAAC;AAED,OAAO,MAAMc,uBAAuB,CAAC,EACnCC,UAAU,EACVhB,WAAW,EACXC,GAAG,EAKJ;IACC,MAAMgB,SAAShB,IAAIE,OAAO,CAACE,MAAM,CAACa,OAAO,CAACC,IAAI,CAAC,CAACC,eAAiBA,aAAaC,IAAI,KAAKL;IAEvF,IAAI,CAACC,QAAQ;QACX,OAAO;IACT;IAEA,IAAI,CAACjB,aAAa;QAChB,OAAOM,uBAAuB;YAAEC,QAAQU;YAAQhB;QAAI;IACtD;IAEA,MAAMO,wBAAwBZ,qBAAqB;QACjDa,QAAQR,IAAIE,OAAO,CAACE,MAAM,CAACI,MAAM;QACjCC,QAAQO,OAAON,eAAe;QAC9BX;QACAY,oBAAoB,CAAC,EAAEC,MAAM,EAAEC,MAAM,EAAE,GAAK,CAACD,UAAU,CAACC;IAC1D;IAEA,OAAOR,uBAAuB;QAAEC,QAAQU;QAAQP,QAAQF;QAAuBP;IAAI;AACrF,EAAC;AAED,MAAMK,yBAAyB,CAAC,EAC9BC,MAAM,EACNG,SAASH,OAAOI,eAAe,EAC/BV,GAAG,EAKJ;IACC,8FAA8F;IAC9F,MAAMqB,kBAAkB;QAAE,GAAGf,MAAM;QAAEI,iBAAiBD;IAAO;IAC7D,MAAMa,SAAS5B,6BAA6B;QAC1CU,QAAQJ,IAAIE,OAAO,CAACE,MAAM;QAC1BmB,eAAevB,IAAIE,OAAO,CAACsB,EAAE,CAACD,aAAa;QAC3CjB,QAAQe;QACRI,MAAMzB,IAAIyB,IAAI;QACdC,SAAS;IACX;IAEA,OAAO9B,qBAAqB0B;AAC9B"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { JsonSchemaType } from '../../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Refines Payload's `input`-variant JSON Schema into an MCP create/update tool's input schema. The
|
|
4
|
-
* variant already covers correctness (ID-only relationships, no managed/virtual/join fields); the
|
|
5
|
-
* passes here are MCP-specific - reshaping fields for the model and shrinking the result - and keep
|
|
6
|
-
* every node valid JSON Schema draft 2020-12. Each is tagged **Correctness**, **Size**, or **LLM
|
|
7
|
-
* ergonomics**, with a before/after example on its definition.
|
|
8
|
-
*/
|
|
9
|
-
export declare const sanitizeEntitySchema: (schema: JsonSchemaType) => JsonSchemaType;
|
|
10
|
-
//# sourceMappingURL=sanitizeEntitySchema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizeEntitySchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/sanitizeEntitySchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,cAAc,KAAG,cA0B7D,CAAA"}
|