@payloadcms/plugin-nested-docs 3.83.0-internal.06ac84e → 3.83.0-internal.ddc1147

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 +1 @@
1
- {"version":3,"file":"resaveChildren.d.ts","sourceRoot":"","sources":["../../src/hooks/resaveChildren.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAA+B,MAAM,SAAS,CAAA;AAIrF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,cAAc,iBACV,sBAAsB,KAAG,yBAiGvC,CAAA"}
1
+ {"version":3,"file":"resaveChildren.d.ts","sourceRoot":"","sources":["../../src/hooks/resaveChildren.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAc,MAAM,SAAS,CAAA;AAIpE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,cAAc,iBACV,sBAAsB,KAAG,yBA8FvC,CAAA"}
@@ -1,4 +1,4 @@
1
- import { APIError, ValidationErrorName } from 'payload';
1
+ import { APIError, ValidationError } from 'payload';
2
2
  import { populateBreadcrumbs } from '../utilities/populateBreadcrumbs.js';
3
3
  export const resaveChildren = (pluginConfig)=>async ({ collection, doc, req })=>{
4
4
  if (collection?.versions?.drafts && doc._status !== 'published') {
@@ -56,7 +56,7 @@ export const resaveChildren = (pluginConfig)=>async ({ collection, doc, req })=>
56
56
  await req.payload.update({
57
57
  id: child.id,
58
58
  collection: collection.slug,
59
- data: populateBreadcrumbs({
59
+ data: await populateBreadcrumbs({
60
60
  collection,
61
61
  data: child,
62
62
  generateLabel: pluginConfig.generateLabel,
@@ -73,7 +73,7 @@ export const resaveChildren = (pluginConfig)=>async ({ collection, doc, req })=>
73
73
  } catch (err) {
74
74
  req.payload.logger.error(`Nested Docs plugin encountered an error while re-saving a child document.`);
75
75
  req.payload.logger.error(err);
76
- if (err?.name === ValidationErrorName && err?.data?.errors?.length) {
76
+ if (err instanceof ValidationError && err.data?.errors?.length) {
77
77
  throw new APIError('Could not publish or save changes: One or more children are invalid.', 400);
78
78
  }
79
79
  }
@@ -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?.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","error","name","errors","undefined"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,mBAAmB,QAAQ,UAAS;AAIvD,SAASC,mBAAmB,QAAQ,sCAAqC;AAEzE,OAAO,MAAMC,iBACX,CAACC,eACD,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAEC,GAAG,EAAE;QAC7B,IAAIF,YAAYG,UAAUC,UAAUH,IAAII,OAAO,KAAK,aAAa;YAC/D,kDAAkD;YAClD;QACF;QAEA,MAAMC,aAAaP,cAAcQ,mBAAmB;QAEpD,MAAMC,uBAAuB,MAAMN,IAAIO,OAAO,CAACC,IAAI,CAAC;YAClDV,YAAYA,WAAWW,IAAI;YAC3BC,OAAO;YACPC,OAAO;YACPC,OAAO;YACPC,QAAQb,IAAIa,MAAM;YAClBb;YACAc,OAAO;gBACL,CAACV,WAAW,EAAE;oBACZW,QAAQhB,IAAIiB,EAAE;gBAChB;YACF;QACF;QAEA,MAAMC,gBAAgBX,qBAAq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W;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"}
1
+ {"version":3,"sources":["../../src/hooks/resaveChildren.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, JsonObject } from 'payload'\n\nimport { APIError, ValidationError } 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: await 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 (err instanceof ValidationError && err.data?.errors?.length) {\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","ValidationError","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","error","errors","undefined"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,eAAe,QAAQ,UAAS;AAInD,SAASC,mBAAmB,QAAQ,sCAAqC;AAEzE,OAAO,MAAMC,iBACX,CAACC,eACD,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAEC,GAAG,EAAE;QAC7B,IAAIF,YAAYG,UAAUC,UAAUH,IAAII,OAAO,KAAK,aAAa;YAC/D,kDAAkD;YAClD;QACF;QAEA,MAAMC,aAAaP,cAAcQ,mBAAmB;QAEpD,MAAMC,uBAAuB,MAAMN,IAAIO,OAAO,CA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,KAAK;oBAElC,MAAMH,IAAIO,OAAO,CAAC8B,MAAM,CAAC;wBACvBrB,IAAII,MAAMJ,EAAE;wBACZlB,YAAYA,WAAWW,IAAI;wBAC3B6B,MAAM,MAAM3C,oBAAoB;4BAC9BG;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,IAAIA,eAAehD,mBAAmBgD,IAAIJ,IAAI,EAAEO,QAAQV,QAAQ;oBAC9D,MAAM,IAAI1C,SACR,wEACA;gBAEJ;YACF;QACF;QAEA,OAAOqD;IACT,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-nested-docs",
3
- "version": "3.83.0-internal.06ac84e",
3
+ "version": "3.83.0-internal.ddc1147",
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.83.0-internal.06ac84e"
41
+ "payload": "3.83.0-internal.ddc1147"
42
42
  },
43
43
  "peerDependencies": {
44
- "payload": "3.83.0-internal.06ac84e"
44
+ "payload": "3.83.0-internal.ddc1147"
45
45
  },
46
46
  "publishConfig": {
47
47
  "registry": "https://registry.npmjs.org/"