@mvriu5/payload-ai 1.1.1 → 1.2.0

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.
@@ -1,5 +1,5 @@
1
1
  import { getCollectionPermissions, getCollectionSlugsForAction } from "./collectionPermissions.js";
2
- import { getCollectionFields, isAuthCollection } from "./normalizeData.js";
2
+ import { getSchemaFields as getNormalizeSchemaFields, hasDrafts, isAuthCollection } from "./normalizeData.js";
3
3
  import { getSerializableLabel, isInternalCollection, isRecord } from "./shared.js";
4
4
  const getSerializableRelationTo = (relationTo)=>{
5
5
  if (typeof relationTo === "string") return relationTo;
@@ -66,12 +66,6 @@ const getSerializableOptions = (options)=>{
66
66
  }).filter(Boolean);
67
67
  return serializedOptions.length > 0 ? serializedOptions : undefined;
68
68
  };
69
- const hasDrafts = (config)=>{
70
- const versions = config?.versions;
71
- if (!versions || versions === true) return false;
72
- if (!isRecord(versions)) return false;
73
- return Boolean(versions.drafts);
74
- };
75
69
  const toNormalizeCollectionConfig = (config)=>{
76
70
  if (!config) return undefined;
77
71
  return {
@@ -82,22 +76,7 @@ const toNormalizeCollectionConfig = (config)=>{
82
76
  };
83
77
  const getSchemaFields = (config)=>{
84
78
  const normalizedConfig = toNormalizeCollectionConfig(config);
85
- const fields = isAuthCollection(normalizedConfig) ? getCollectionFields(normalizedConfig) : [
86
- ...config?.fields || []
87
- ];
88
- if (hasDrafts(config)) {
89
- fields.push({
90
- label: "Status",
91
- name: "_status",
92
- options: [
93
- "draft",
94
- "published"
95
- ],
96
- required: true,
97
- type: "select"
98
- });
99
- }
100
- return fields;
79
+ return getNormalizeSchemaFields(normalizedConfig);
101
80
  };
102
81
  const getLocalizedFieldNames = (fields, path = "")=>{
103
82
  return fields.flatMap((field)=>{
@@ -191,6 +170,14 @@ const describeField = (field)=>{
191
170
  ...options ? {
192
171
  options
193
172
  } : {},
173
+ ...field.type === "blocks" && field.blocks ? {
174
+ acceptedBlockTypes: field.blocks.map((block)=>block.slug),
175
+ blockExample: [
176
+ {
177
+ ...getBlockExample(field.blocks[0])
178
+ }
179
+ ]
180
+ } : {},
194
181
  ...field.admin?.condition ? {
195
182
  hasCondition: true
196
183
  } : {},
@@ -208,6 +195,8 @@ const describeBlock = (block)=>{
208
195
  const cached = blockDescriptionCache.get(block);
209
196
  if (cached) return cached;
210
197
  const description = {
198
+ blockType: block.slug,
199
+ example: getBlockExample(block),
211
200
  fields: (block.fields || []).map(describeField),
212
201
  label: getSerializableLabel(block.labels?.singular) || block.slug,
213
202
  slug: block.slug
@@ -215,6 +204,43 @@ const describeBlock = (block)=>{
215
204
  blockDescriptionCache.set(block, description);
216
205
  return description;
217
206
  };
207
+ const getBlockExample = (block)=>{
208
+ if (!block) return {};
209
+ const example = {
210
+ blockType: block.slug
211
+ };
212
+ for (const field of block.fields || []){
213
+ if (!field.name) continue;
214
+ if (field.type === "array") {
215
+ example[field.name] = field.fields?.length ? [
216
+ Object.fromEntries(field.fields.filter((childField)=>Boolean(childField.name)).slice(0, 2).map((childField)=>[
217
+ childField.name,
218
+ childField.type === "checkbox" ? false : `<${childField.name}>`
219
+ ]))
220
+ ] : [];
221
+ continue;
222
+ }
223
+ if (field.type === "blocks") {
224
+ example[field.name] = field.blocks?.length ? [
225
+ getBlockExample(field.blocks[0])
226
+ ] : [];
227
+ continue;
228
+ }
229
+ if (field.type === "group") {
230
+ example[field.name] = Object.fromEntries((field.fields || []).filter((childField)=>Boolean(childField.name)).slice(0, 2).map((childField)=>[
231
+ childField.name,
232
+ childField.type === "checkbox" ? false : `<${childField.name}>`
233
+ ]));
234
+ continue;
235
+ }
236
+ if (field.type === "checkbox") {
237
+ example[field.name] = false;
238
+ continue;
239
+ }
240
+ example[field.name] = `<${field.name}>`;
241
+ }
242
+ return example;
243
+ };
218
244
  export const describeCollectionLikeConfig = ({ config, permissions, type })=>{
219
245
  return {
220
246
  ...describeCollectionLikeSummary({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mvriu5/payload-ai",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "AI assistant plugin for Payload CMS with provider selection, CMS mentions, and signed action proposals.",
5
5
  "keywords": [
6
6
  "payload",