@payloadcms/plugin-mcp 4.0.0-internal.c3ac604 → 4.0.0-internal.cc18726
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/endpoint/access.js +2 -2
- package/dist/endpoint/access.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +1 -1
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +35 -23
- package/dist/mcp/buildMcpServer.js.map +1 -1
- package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/authTools.js +79 -56
- package/dist/mcp/builtin/collections/authTools.js.map +1 -1
- package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/countTool.js +9 -14
- package/dist/mcp/builtin/collections/countTool.js.map +1 -1
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/countVersionsTool.js +9 -13
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +20 -28
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.js +40 -43
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.js +15 -34
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/fileInput.d.ts +21 -21
- package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/fileInput.js +19 -20
- package/dist/mcp/builtin/collections/fileInput.js.map +1 -1
- package/dist/mcp/builtin/collections/fileInput.spec.js +2 -2
- package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -1
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findDistinctTool.js +11 -26
- package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findTool.js +21 -43
- package/dist/mcp/builtin/collections/findTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.js +17 -26
- package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findVersionsTool.js +16 -30
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +2 -2
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/formatCollectionError.js +6 -6
- 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 +12 -12
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/restoreVersionTool.js +14 -26
- package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js +35 -77
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js +11 -11
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.js +3 -2
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/countVersionsTool.js +9 -13
- package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findTool.js +10 -16
- package/dist/mcp/builtin/globals/findTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.js +13 -24
- package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findVersionsTool.js +13 -29
- package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +11 -11
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/restoreVersionTool.js +15 -22
- package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.js +18 -23
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtin/validateEntityData.d.ts +4 -4
- package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -1
- package/dist/mcp/builtin/validateEntityData.js +7 -7
- package/dist/mcp/builtin/validateEntityData.js.map +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +4 -6
- package/src/endpoint/access.ts +2 -3
- package/src/mcp/buildMcpServer.ts +39 -29
- package/src/mcp/builtin/collections/authTools.ts +77 -69
- package/src/mcp/builtin/collections/countTool.ts +9 -21
- package/src/mcp/builtin/collections/countVersionsTool.ts +9 -18
- package/src/mcp/builtin/collections/createTool.ts +25 -69
- package/src/mcp/builtin/collections/deleteTool.ts +36 -64
- package/src/mcp/builtin/collections/duplicateTool.ts +21 -83
- package/src/mcp/builtin/collections/fileInput.spec.ts +2 -2
- package/src/mcp/builtin/collections/fileInput.ts +30 -25
- package/src/mcp/builtin/collections/findDistinctTool.ts +11 -63
- package/src/mcp/builtin/collections/findTool.ts +21 -103
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +15 -58
- package/src/mcp/builtin/collections/findVersionsTool.ts +14 -85
- package/src/mcp/builtin/collections/formatCollectionError.ts +8 -8
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +11 -11
- package/src/mcp/builtin/collections/restoreVersionTool.ts +14 -56
- package/src/mcp/builtin/collections/updateTool.ts +45 -99
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +12 -12
- package/src/mcp/builtin/getConfigInfoTool.ts +2 -1
- package/src/mcp/builtin/globals/countVersionsTool.ts +9 -17
- package/src/mcp/builtin/globals/findTool.ts +12 -51
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +13 -52
- package/src/mcp/builtin/globals/findVersionsTool.ts +14 -92
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +10 -10
- package/src/mcp/builtin/globals/restoreVersionTool.ts +14 -45
- package/src/mcp/builtin/globals/updateTool.ts +34 -52
- package/src/mcp/builtin/validateEntityData.ts +10 -13
- package/src/types.ts +4 -4
- 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/dist/utils/whereSchema.d.ts +0 -9
- package/dist/utils/whereSchema.d.ts.map +0 -1
- package/dist/utils/whereSchema.js +0 -13
- package/dist/utils/whereSchema.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
- package/src/utils/whereSchema.ts +0 -24
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
getGlobalVirtualFieldNames,
|
|
3
|
+
stripVirtualFields,
|
|
4
|
+
transformPointDataToPayload,
|
|
5
|
+
updateGlobalInputSchema,
|
|
6
|
+
} from 'payload'
|
|
4
7
|
|
|
5
8
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
9
|
import { defineGlobalTool } from '../../../defineTool.js'
|
|
7
10
|
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
11
|
import { validateGlobalData } from '../validateEntityData.js'
|
|
14
12
|
|
|
15
13
|
const DEFAULT_DESCRIPTION = 'Update any Payload global by passing the global slug and data.'
|
|
16
14
|
|
|
17
15
|
export const updateGlobalTool = defineGlobalTool({
|
|
18
|
-
access: (args) =>
|
|
19
|
-
defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.update),
|
|
16
|
+
access: (args) => defaultAccess(args) && Boolean(args.permissions?.globals?.[args.slug]?.update),
|
|
20
17
|
annotations: {
|
|
21
18
|
destructiveHint: true,
|
|
22
19
|
idempotentHint: false,
|
|
@@ -25,49 +22,30 @@ export const updateGlobalTool = defineGlobalTool({
|
|
|
25
22
|
title: 'Update Global',
|
|
26
23
|
},
|
|
27
24
|
description: DEFAULT_DESCRIPTION,
|
|
28
|
-
input:
|
|
29
|
-
|
|
30
|
-
depth: z
|
|
31
|
-
.number()
|
|
32
|
-
.describe('Optional: Depth of relationships to populate')
|
|
33
|
-
.optional()
|
|
34
|
-
.default(0),
|
|
35
|
-
draft: z
|
|
36
|
-
.boolean()
|
|
37
|
-
.describe('Optional: Whether to save as draft (default: false)')
|
|
38
|
-
.optional()
|
|
39
|
-
.default(false),
|
|
40
|
-
fallbackLocale: z
|
|
41
|
-
.string()
|
|
42
|
-
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
43
|
-
.optional(),
|
|
44
|
-
locale: z
|
|
45
|
-
.string()
|
|
46
|
-
.describe(
|
|
47
|
-
'Optional: locale code to update data in (e.g., "en", "es"). Use "all" to update all locales for localized fields',
|
|
48
|
-
)
|
|
49
|
-
.optional(),
|
|
50
|
-
select: z
|
|
51
|
-
.record(z.string(), z.unknown())
|
|
52
|
-
.describe(
|
|
53
|
-
'Optional: define exactly which fields you\'d like to return in the response, e.g., {"siteName": true}',
|
|
54
|
-
)
|
|
55
|
-
.optional(),
|
|
56
|
-
}),
|
|
57
|
-
}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
|
|
25
|
+
input: updateGlobalInputSchema,
|
|
26
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
58
27
|
const payload = req.payload
|
|
59
28
|
const logger = getLogger({ payload })
|
|
60
29
|
|
|
61
|
-
const {
|
|
30
|
+
const {
|
|
31
|
+
data,
|
|
32
|
+
depth,
|
|
33
|
+
draft,
|
|
34
|
+
fallbackLocale,
|
|
35
|
+
locale,
|
|
36
|
+
overrideLock,
|
|
37
|
+
populate,
|
|
38
|
+
publishAllLocales,
|
|
39
|
+
select,
|
|
40
|
+
unpublishAllLocales,
|
|
41
|
+
} = input
|
|
62
42
|
|
|
63
|
-
logger.info(
|
|
64
|
-
`Updating global: ${globalSlug}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,
|
|
65
|
-
)
|
|
43
|
+
logger.info(`Updating global: ${slug}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`)
|
|
66
44
|
|
|
67
45
|
try {
|
|
68
|
-
const virtualFieldNames = getGlobalVirtualFieldNames(payload.config,
|
|
46
|
+
const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, slug)
|
|
69
47
|
const inputData = stripVirtualFields(data, virtualFieldNames)
|
|
70
|
-
const validationError = validateGlobalData({ data: inputData,
|
|
48
|
+
const validationError = validateGlobalData({ slug, data: inputData, req })
|
|
71
49
|
|
|
72
50
|
if (validationError) {
|
|
73
51
|
return validationError
|
|
@@ -76,22 +54,26 @@ export const updateGlobalTool = defineGlobalTool({
|
|
|
76
54
|
const parsedData = transformPointDataToPayload(inputData)
|
|
77
55
|
|
|
78
56
|
const updateOptions: Parameters<typeof payload.updateGlobal>[0] = {
|
|
79
|
-
slug
|
|
57
|
+
slug,
|
|
80
58
|
data: parsedData,
|
|
81
59
|
depth,
|
|
82
60
|
draft,
|
|
83
61
|
overrideAccess: authorizedMCP.overrideAccess,
|
|
62
|
+
overrideLock,
|
|
63
|
+
populate,
|
|
64
|
+
publishAllLocales,
|
|
84
65
|
req,
|
|
66
|
+
unpublishAllLocales,
|
|
85
67
|
}
|
|
86
68
|
|
|
87
69
|
if (locale) {
|
|
88
70
|
updateOptions.locale = locale
|
|
89
71
|
}
|
|
90
|
-
if (fallbackLocale) {
|
|
72
|
+
if (fallbackLocale !== undefined) {
|
|
91
73
|
updateOptions.fallbackLocale = fallbackLocale
|
|
92
74
|
}
|
|
93
75
|
if (select) {
|
|
94
|
-
updateOptions.select = select
|
|
76
|
+
updateOptions.select = select
|
|
95
77
|
}
|
|
96
78
|
|
|
97
79
|
const result = await payload.updateGlobal(updateOptions)
|
|
@@ -100,16 +82,16 @@ export const updateGlobalTool = defineGlobalTool({
|
|
|
100
82
|
content: [
|
|
101
83
|
{
|
|
102
84
|
type: 'text',
|
|
103
|
-
text: `Global "${
|
|
85
|
+
text: `Global "${slug}" updated successfully!\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
104
86
|
},
|
|
105
87
|
],
|
|
106
88
|
doc: result as Record<string, unknown>,
|
|
107
89
|
}
|
|
108
90
|
} catch (error) {
|
|
109
91
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
110
|
-
logger.error(`Error updating global ${
|
|
92
|
+
logger.error(`Error updating global ${slug}: ${errorMessage}`)
|
|
111
93
|
return {
|
|
112
|
-
content: [{ type: 'text', text: `Error updating global "${
|
|
94
|
+
content: [{ type: 'text', text: `Error updating global "${slug}": ${errorMessage}` }],
|
|
113
95
|
}
|
|
114
96
|
}
|
|
115
97
|
})
|
|
@@ -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
|
*/
|
|
@@ -26,19 +22,20 @@ type EntityValidator = {
|
|
|
26
22
|
const validatorCache = new WeakMap<SanitizedConfig, Map<string, EntityValidator>>()
|
|
27
23
|
|
|
28
24
|
export const validateCollectionData = ({
|
|
29
|
-
|
|
25
|
+
slug,
|
|
30
26
|
data,
|
|
31
27
|
partial,
|
|
32
28
|
req,
|
|
33
29
|
}: {
|
|
34
|
-
collectionSlug: CollectionSlug
|
|
35
30
|
data: Record<string, unknown>
|
|
36
31
|
partial?: boolean
|
|
37
32
|
req: PayloadRequest
|
|
33
|
+
slug: CollectionSlug
|
|
38
34
|
}): MCPToolResponse | null =>
|
|
39
35
|
validateData({
|
|
40
|
-
slug
|
|
41
|
-
buildSchema: () =>
|
|
36
|
+
slug,
|
|
37
|
+
buildSchema: () =>
|
|
38
|
+
getCollectionInputSchema({ collectionSlug: slug, req }) as JsonSchemaType | null,
|
|
42
39
|
data,
|
|
43
40
|
entity: 'collection',
|
|
44
41
|
partial,
|
|
@@ -46,17 +43,17 @@ export const validateCollectionData = ({
|
|
|
46
43
|
})
|
|
47
44
|
|
|
48
45
|
export const validateGlobalData = ({
|
|
46
|
+
slug,
|
|
49
47
|
data,
|
|
50
|
-
globalSlug,
|
|
51
48
|
req,
|
|
52
49
|
}: {
|
|
53
50
|
data: Record<string, unknown>
|
|
54
|
-
globalSlug: GlobalSlug
|
|
55
51
|
req: PayloadRequest
|
|
52
|
+
slug: GlobalSlug
|
|
56
53
|
}): MCPToolResponse | null =>
|
|
57
54
|
validateData({
|
|
58
|
-
slug
|
|
59
|
-
buildSchema: () => getGlobalInputSchema({ globalSlug, req }),
|
|
55
|
+
slug,
|
|
56
|
+
buildSchema: () => getGlobalInputSchema({ globalSlug: slug, req }) as JsonSchemaType | null,
|
|
60
57
|
data,
|
|
61
58
|
entity: 'global',
|
|
62
59
|
partial: true,
|
package/src/types.ts
CHANGED
|
@@ -75,11 +75,11 @@ export type MCPAccessArgs = {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
export type CollectionMCPAccessArgs = {
|
|
78
|
-
|
|
78
|
+
slug: CollectionSlug
|
|
79
79
|
} & MCPAccessArgs
|
|
80
80
|
|
|
81
81
|
export type GlobalMCPAccessArgs = {
|
|
82
|
-
|
|
82
|
+
slug: GlobalSlug
|
|
83
83
|
} & MCPAccessArgs
|
|
84
84
|
|
|
85
85
|
export type ToolHandlerArgs<TSchema = undefined> = {
|
|
@@ -90,11 +90,11 @@ export type ToolHandlerArgs<TSchema = undefined> = {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
export type CollectionToolHandlerArgs<TSchema = undefined> = {
|
|
93
|
-
|
|
93
|
+
slug: CollectionSlug
|
|
94
94
|
} & ToolHandlerArgs<TSchema>
|
|
95
95
|
|
|
96
96
|
export type GlobalToolHandlerArgs<TSchema = undefined> = {
|
|
97
|
-
|
|
97
|
+
slug: GlobalSlug
|
|
98
98
|
} & ToolHandlerArgs<TSchema>
|
|
99
99
|
|
|
100
100
|
export type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> = {
|
|
@@ -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,yDAK9B;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,0CAIlC;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,sCAI9B;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,WAAY,cAAc,KAAG,cA0B7D,CAAA"}
|