@payloadcms/plugin-nested-docs 3.6.1-canary.cc3861e → 3.7.1-canary.a7f8738
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,EACV,yBAAyB,EACzB,gBAAgB,EAIjB,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"resaveChildren.d.ts","sourceRoot":"","sources":["../../src/hooks/resaveChildren.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,gBAAgB,EAIjB,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AA6EzD,eAAO,MAAM,cAAc,iBACV,sBAAsB,cAAc,gBAAgB,KAAG,yBAqBrE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/resaveChildren.ts"],"sourcesContent":["import type {\n CollectionAfterChangeHook,\n CollectionConfig,\n JsonObject,\n PayloadRequest,\n ValidationError,\n} from 'payload'\n\nimport { APIError } from 'payload'\n\nimport type { NestedDocsPluginConfig } from '../types.js'\n\nimport { populateBreadcrumbs } from '../utilities/populateBreadcrumbs.js'\n\ntype ResaveArgs = {\n collection: CollectionConfig\n doc: JsonObject\n draft: boolean\n pluginConfig: NestedDocsPluginConfig\n req: PayloadRequest\n}\n\nconst resave = async ({ collection, doc, draft, pluginConfig, req }: ResaveArgs) => {\n const parentSlug = pluginConfig?.parentFieldSlug || 'parent'\n const parentDocIsPublished = doc._status === 'published'\n
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/resaveChildren.ts"],"sourcesContent":["import type {\n CollectionAfterChangeHook,\n CollectionConfig,\n JsonObject,\n PayloadRequest,\n ValidationError,\n} from 'payload'\n\nimport { APIError } from 'payload'\n\nimport type { NestedDocsPluginConfig } from '../types.js'\n\nimport { populateBreadcrumbs } from '../utilities/populateBreadcrumbs.js'\n\ntype ResaveArgs = {\n collection: CollectionConfig\n doc: JsonObject\n draft: boolean\n pluginConfig: NestedDocsPluginConfig\n req: PayloadRequest\n}\n\nconst resave = async ({ collection, doc, draft, pluginConfig, req }: ResaveArgs) => {\n const parentSlug = pluginConfig?.parentFieldSlug || 'parent'\n const parentDocIsPublished = doc._status === 'published'\n const children = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n draft: true,\n locale: req.locale,\n req,\n where: {\n [parentSlug]: {\n equals: doc.id,\n },\n },\n })\n\n const breadcrumbSlug = pluginConfig.breadcrumbsFieldSlug || 'breadcrumbs'\n\n try {\n await children.docs.reduce(async (priorSave, child) => {\n await priorSave\n\n const childIsPublished =\n typeof collection.versions === 'object' &&\n collection.versions.drafts &&\n child._status === 'published'\n\n if (!parentDocIsPublished && childIsPublished) {\n return\n }\n\n await req.payload.update({\n id: child.id,\n collection: collection.slug,\n data: {\n ...child,\n [breadcrumbSlug]: await populateBreadcrumbs(req, pluginConfig, collection, child),\n },\n depth: 0,\n draft: !childIsPublished,\n locale: req.locale,\n req,\n })\n }, Promise.resolve())\n } catch (err: unknown) {\n req.payload.logger.error(\n `Nested Docs plugin has had an error while re-saving a child document${\n draft ? ' as draft' : ' as published'\n }.`,\n )\n req.payload.logger.error(err)\n\n // Use type assertion until we can use instanceof reliably with our Error types\n if (\n (err as ValidationError)?.name === 'ValidationError' &&\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\nexport const resaveChildren =\n (pluginConfig: NestedDocsPluginConfig, collection: CollectionConfig): CollectionAfterChangeHook =>\n async ({ doc, req }) => {\n await resave({\n collection,\n doc,\n draft: true,\n pluginConfig,\n req,\n })\n\n if (doc._status === 'published') {\n await resave({\n collection,\n doc,\n draft: false,\n pluginConfig,\n req,\n })\n }\n\n return undefined\n }\n"],"names":["APIError","populateBreadcrumbs","resave","collection","doc","draft","pluginConfig","req","parentSlug","parentFieldSlug","parentDocIsPublished","_status","children","payload","find","slug","depth","locale","where","equals","id","breadcrumbSlug","breadcrumbsFieldSlug","docs","reduce","priorSave","child","childIsPublished","versions","drafts","update","data","Promise","resolve","err","logger","error","name","errors","length","resaveChildren","undefined"],"mappings":"AAQA,SAASA,QAAQ,QAAQ,UAAS;AAIlC,SAASC,mBAAmB,QAAQ,sCAAqC;AAUzE,MAAMC,SAAS,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAEC,KAAK,EAAEC,YAAY,EAAEC,GAAG,EAAc;IAC7E,MAAMC,aAAaF,cAAcG,mBAAmB;IACpD,MAAMC,uBAAuBN,IAAIO,OAAO,KAAK;IAC7C,MAAMC,WAAW,MAAML,IAAIM,OAAO,CAACC,IAAI,CAAC;QACtCX,YAAYA,WAAWY,IAAI;QAC3BC,OAAO;QACPX,OAAO;QACPY,QAAQV,IAAIU,MAAM;QAClBV;QACAW,OAAO;YACL,CAACV,WAAW,EAAE;gBACZW,QAAQf,IAAIgB,EAAE;YAChB;QACF;IACF;IAEA,MAAMC,iBAAiBf,aAAagB,oBAAoB,IAAI;IAE5D,IAAI;QACF,MAAMV,SAASW,IAAI,CAACC,MAAM,CAAC,OAAOC,WAAWC;YAC3C,MAAMD;YAEN,MAAME,mBACJ,OAAOxB,WAAWyB,QAAQ,KAAK,YAC/BzB,WAAWyB,QAAQ,CAACC,MAAM,IAC1BH,MAAMf,OAAO,KAAK;YAEpB,IAAI,CAACD,wBAAwBiB,kBAAkB;gBAC7C;YACF;YAEA,MAAMpB,IAAIM,OAAO,CAACiB,MAAM,CAAC;gBACvBV,IAAIM,MAAMN,EAAE;gBACZjB,YAAYA,WAAWY,IAAI;gBAC3BgB,MAAM;oBACJ,GAAGL,KAAK;oBACR,CAACL,eAAe,EAAE,MAAMpB,oBAAoBM,KAAKD,cAAcH,YAAYuB;gBAC7E;gBACAV,OAAO;gBACPX,OAAO,CAACsB;gBACRV,QAAQV,IAAIU,MAAM;gBAClBV;YACF;QACF,GAAGyB,QAAQC,OAAO;IACpB,EAAE,OAAOC,KAAc;QACrB3B,IAAIM,OAAO,CAACsB,MAAM,CAACC,KAAK,CACtB,CAAC,oEAAoE,EACnE/B,QAAQ,cAAc,gBACvB,CAAC,CAAC;QAELE,IAAIM,OAAO,CAACsB,MAAM,CAACC,KAAK,CAACF;QAEzB,+EAA+E;QAC/E,IACE,AAACA,KAAyBG,SAAS,qBAClCH,KAAyBH,MAAMO,QAAQC,QACxC;YACA,MAAM,IAAIvC,SACR,wEACA;QAEJ;IACF;AACF;AAEA,OAAO,MAAMwC,iBACX,CAAClC,cAAsCH,aACvC,OAAO,EAAEC,GAAG,EAAEG,GAAG,EAAE;QACjB,MAAML,OAAO;YACXC;YACAC;YACAC,OAAO;YACPC;YACAC;QACF;QAEA,IAAIH,IAAIO,OAAO,KAAK,aAAa;YAC/B,MAAMT,OAAO;gBACXC;gBACAC;gBACAC,OAAO;gBACPC;gBACAC;YACF;QACF;QAEA,OAAOkC;IACT,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-nested-docs",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.1-canary.a7f8738",
|
|
4
4
|
"description": "The official Nested Docs plugin for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
],
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@payloadcms/eslint-config": "3.0.0",
|
|
40
|
-
"payload": "3.
|
|
40
|
+
"payload": "3.7.1-canary.a7f8738"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"payload": "3.
|
|
43
|
+
"payload": "3.7.1-canary.a7f8738"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"registry": "https://registry.npmjs.org/"
|