@payloadcms/plugin-nested-docs 3.67.0-internal.8383bda → 3.67.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,7 +1,7 @@
|
|
|
1
1
|
import { APIError, ValidationErrorName } from 'payload';
|
|
2
2
|
import { populateBreadcrumbs } from '../utilities/populateBreadcrumbs.js';
|
|
3
3
|
export const resaveChildren = (pluginConfig)=>async ({ collection, doc, req })=>{
|
|
4
|
-
if (collection
|
|
4
|
+
if (collection?.versions?.drafts && doc._status !== 'published') {
|
|
5
5
|
// If the parent is a draft, don't resave children
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/resaveChildren.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, JsonObject, ValidationError } from 'payload'\n\nimport { APIError, ValidationErrorName } from 'payload'\n\nimport type { NestedDocsPluginConfig } from '../types.js'\n\nimport { populateBreadcrumbs } from '../utilities/populateBreadcrumbs.js'\n\nexport const resaveChildren =\n (pluginConfig: NestedDocsPluginConfig): CollectionAfterChangeHook =>\n async ({ collection, doc, req }) => {\n if (collection
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/resaveChildren.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, JsonObject, ValidationError } from 'payload'\n\nimport { APIError, ValidationErrorName } from 'payload'\n\nimport type { NestedDocsPluginConfig } from '../types.js'\n\nimport { populateBreadcrumbs } from '../utilities/populateBreadcrumbs.js'\n\nexport const resaveChildren =\n (pluginConfig: NestedDocsPluginConfig): CollectionAfterChangeHook =>\n async ({ collection, doc, req }) => {\n if (collection?.versions?.drafts && doc._status !== 'published') {\n // If the parent is a draft, don't resave children\n return\n }\n\n const parentSlug = pluginConfig?.parentFieldSlug || 'parent'\n\n const initialDraftChildren = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n draft: true,\n limit: 0,\n locale: req.locale,\n req,\n where: {\n [parentSlug]: {\n equals: doc.id,\n },\n },\n })\n\n const draftChildren = initialDraftChildren.docs.filter((child) => child._status === 'draft')\n\n const publishedChildren = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n draft: false,\n limit: 0,\n locale: req.locale,\n req,\n where: {\n [parentSlug]: {\n equals: doc.id,\n },\n },\n })\n\n const childrenById = [...draftChildren, ...publishedChildren.docs].reduce<\n Record<string, JsonObject[]>\n >((acc, child) => {\n acc[child.id] = acc[child.id] || []\n acc[child.id]!.push(child)\n return acc\n }, {})\n\n const sortedChildren = Object.values(childrenById).flatMap((group: JsonObject[]) => {\n return group.sort((a, b) => {\n if (a.updatedAt !== b.updatedAt) {\n return a.updatedAt > b.updatedAt ? 1 : -1\n }\n return a._status === 'published' ? 1 : -1\n })\n })\n\n if (sortedChildren.length) {\n try {\n for (const child of sortedChildren) {\n const isDraft = child._status !== 'published'\n\n await req.payload.update({\n id: child.id,\n collection: collection.slug,\n data: populateBreadcrumbs({\n collection,\n data: child,\n generateLabel: pluginConfig.generateLabel,\n generateURL: pluginConfig.generateURL,\n parentFieldName: pluginConfig.parentFieldSlug,\n req,\n }),\n depth: 0,\n draft: isDraft,\n locale: req.locale,\n req,\n })\n }\n } catch (err: unknown) {\n req.payload.logger.error(\n `Nested Docs plugin encountered an error while re-saving a child document.`,\n )\n req.payload.logger.error(err)\n\n if (\n (err as ValidationError)?.name === ValidationErrorName &&\n (err as ValidationError)?.data?.errors?.length\n ) {\n throw new APIError(\n 'Could not publish or save changes: One or more children are invalid.',\n 400,\n )\n }\n }\n }\n\n return undefined\n }\n"],"names":["APIError","ValidationErrorName","populateBreadcrumbs","resaveChildren","pluginConfig","collection","doc","req","versions","drafts","_status","parentSlug","parentFieldSlug","initialDraftChildren","payload","find","slug","depth","draft","limit","locale","where","equals","id","draftChildren","docs","filter","child","publishedChildren","childrenById","reduce","acc","push","sortedChildren","Object","values","flatMap","group","sort","a","b","updatedAt","length","isDraft","update","data","generateLabel","generateURL","parentFieldName","err","logger","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CAAC,CAACC;YAC1D,OAAOA,MAAMC,IAAI,CAAC,CAACC,GAAGC;gBACpB,IAAID,EAAEE,SAAS,KAAKD,EAAEC,SAAS,EAAE;oBAC/B,OAAOF,EAAEE,SAAS,GAAGD,EAAEC,SAAS,GAAG,IAAI,CAAC;gBAC1C;gBACA,OAAOF,EAAE7B,OAAO,KAAK,cAAc,IAAI,CAAC;YAC1C;QACF;QAEA,IAAIuB,eAAeS,MAAM,EAAE;YACzB,IAAI;gBACF,KAAK,MAAMf,SAASM,eAAgB;oBAClC,MAAMU,UAAUhB,MAAMjB,OAAO,KAAK;oBAElC,MAAMH,IAAIO,OAAO,CAAC8B,MAAM,CAAC;wBACvBrB,IAAII,MAAMJ,EAAE;wBACZlB,YAAYA,WAAWW,IAAI;wBAC3B6B,MAAM3C,oBAAoB;4BACxBG;4BACAwC,MAAMlB;4BACNmB,eAAe1C,aAAa0C,aAAa;4BACzCC,aAAa3C,aAAa2C,WAAW;4BACrCC,iBAAiB5C,aAAaQ,eAAe;4BAC7CL;wBACF;wBACAU,OAAO;wBACPC,OAAOyB;wBACPvB,QAAQb,IAAIa,MAAM;wBAClBb;oBACF;gBACF;YACF,EAAE,OAAO0C,KAAc;gBACrB1C,IAAIO,OAAO,CAACoC,MAAM,CAACC,KAAK,CACtB,CAAC,yEAAyE,CAAC;gBAE7E5C,IAAIO,OAAO,CAACoC,MAAM,CAACC,KAAK,CAACF;gBAEzB,IACE,AAACA,KAAyBG,SAASnD,uBAClCgD,KAAyBJ,MAAMQ,QAAQX,QACxC;oBACA,MAAM,IAAI1C,SACR,wEACA;gBAEJ;YACF;QACF;QAEA,OAAOsD;IACT,EAAC"}
|
|
@@ -18,7 +18,7 @@ export const resaveSelfAfterCreate = (pluginConfig)=>async ({ collection, doc, o
|
|
|
18
18
|
})) || []
|
|
19
19
|
},
|
|
20
20
|
depth: 0,
|
|
21
|
-
draft: collection
|
|
21
|
+
draft: collection?.versions?.drafts && doc._status !== 'published',
|
|
22
22
|
locale,
|
|
23
23
|
req
|
|
24
24
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/resaveSelfAfterCreate.ts"],"sourcesContent":["import type { CollectionAfterChangeHook } from 'payload'\n\nimport type { Breadcrumb, NestedDocsPluginConfig } from '../types.js'\n\n// This hook automatically re-saves a document after it is created\n// so that we can build its breadcrumbs with the newly created document's ID.\n\nexport const resaveSelfAfterCreate =\n (pluginConfig: NestedDocsPluginConfig): CollectionAfterChangeHook =>\n async ({ collection, doc, operation, req }) => {\n if (operation !== 'create') {\n return undefined\n }\n\n const { locale, payload } = req\n const breadcrumbSlug = pluginConfig.breadcrumbsFieldSlug || 'breadcrumbs'\n const breadcrumbs = doc[breadcrumbSlug] as unknown as Breadcrumb[]\n\n try {\n await payload.update({\n id: doc.id,\n collection: collection.slug,\n data: {\n [breadcrumbSlug]:\n breadcrumbs?.map((crumb, i) => ({\n ...crumb,\n doc: breadcrumbs.length === i + 1 ? doc.id : crumb.doc,\n })) || [],\n },\n depth: 0,\n draft: collection
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/resaveSelfAfterCreate.ts"],"sourcesContent":["import type { CollectionAfterChangeHook } from 'payload'\n\nimport type { Breadcrumb, NestedDocsPluginConfig } from '../types.js'\n\n// This hook automatically re-saves a document after it is created\n// so that we can build its breadcrumbs with the newly created document's ID.\n\nexport const resaveSelfAfterCreate =\n (pluginConfig: NestedDocsPluginConfig): CollectionAfterChangeHook =>\n async ({ collection, doc, operation, req }) => {\n if (operation !== 'create') {\n return undefined\n }\n\n const { locale, payload } = req\n const breadcrumbSlug = pluginConfig.breadcrumbsFieldSlug || 'breadcrumbs'\n const breadcrumbs = doc[breadcrumbSlug] as unknown as Breadcrumb[]\n\n try {\n await payload.update({\n id: doc.id,\n collection: collection.slug,\n data: {\n [breadcrumbSlug]:\n breadcrumbs?.map((crumb, i) => ({\n ...crumb,\n doc: breadcrumbs.length === i + 1 ? doc.id : crumb.doc,\n })) || [],\n },\n depth: 0,\n draft: collection?.versions?.drafts && doc._status !== 'published',\n locale,\n req,\n })\n } catch (err: unknown) {\n payload.logger.error(\n `Nested Docs plugin has had an error while adding breadcrumbs during document creation.`,\n )\n payload.logger.error(err)\n }\n }\n"],"names":["resaveSelfAfterCreate","pluginConfig","collection","doc","operation","req","undefined","locale","payload","breadcrumbSlug","breadcrumbsFieldSlug","breadcrumbs","update","id","slug","data","map","crumb","i","length","depth","draft","versions","drafts","_status","err","logger","error"],"mappings":"AAIA,kEAAkE;AAClE,6EAA6E;AAE7E,OAAO,MAAMA,wBACX,CAACC,eACD,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAEC,SAAS,EAAEC,GAAG,EAAE;QACxC,IAAID,cAAc,UAAU;YAC1B,OAAOE;QACT;QAEA,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGH;QAC5B,MAAMI,iBAAiBR,aAAaS,oBAAoB,IAAI;QAC5D,MAAMC,cAAcR,GAAG,CAACM,eAAe;QAEvC,IAAI;YACF,MAAMD,QAAQI,MAAM,CAAC;gBACnBC,IAAIV,IAAIU,EAAE;gBACVX,YAAYA,WAAWY,IAAI;gBAC3BC,MAAM;oBACJ,CAACN,eAAe,EACdE,aAAaK,IAAI,CAACC,OAAOC,IAAO,CAAA;4BAC9B,GAAGD,KAAK;4BACRd,KAAKQ,YAAYQ,MAAM,KAAKD,IAAI,IAAIf,IAAIU,EAAE,GAAGI,MAAMd,GAAG;wBACxD,CAAA,MAAO,EAAE;gBACb;gBACAiB,OAAO;gBACPC,OAAOnB,YAAYoB,UAAUC,UAAUpB,IAAIqB,OAAO,KAAK;gBACvDjB;gBACAF;YACF;QACF,EAAE,OAAOoB,KAAc;YACrBjB,QAAQkB,MAAM,CAACC,KAAK,CAClB,CAAC,sFAAsF,CAAC;YAE1FnB,QAAQkB,MAAM,CAACC,KAAK,CAACF;QACvB;IACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-nested-docs",
|
|
3
|
-
"version": "3.67.0
|
|
3
|
+
"version": "3.67.0",
|
|
4
4
|
"description": "The official Nested Docs plugin for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
],
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@payloadcms/eslint-config": "3.28.0",
|
|
41
|
-
"payload": "3.67.0
|
|
41
|
+
"payload": "3.67.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"payload": "3.67.0
|
|
44
|
+
"payload": "3.67.0"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"registry": "https://registry.npmjs.org/"
|