@valkyrianlabs/payload-markdown-docs 0.4.3 → 0.5.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.
- package/dist/collections/docs.js +5 -0
- package/dist/collections/docs.js.map +1 -1
- package/dist/collections/docsSets.d.ts +2 -1
- package/dist/collections/docsSets.js +3 -2
- package/dist/collections/docsSets.js.map +1 -1
- package/dist/endpoints/publishGeneratedDocs.d.ts +2 -1
- package/dist/endpoints/publishGeneratedDocs.js +2 -1
- package/dist/endpoints/publishGeneratedDocs.js.map +1 -1
- package/dist/payload/docsConflicts.js +12 -1
- package/dist/payload/docsConflicts.js.map +1 -1
- package/dist/payload/docsData.js +2 -0
- package/dist/payload/docsData.js.map +1 -1
- package/dist/payload/existingDocs.d.ts +1 -0
- package/dist/payload/existingDocs.js +1 -0
- package/dist/payload/existingDocs.js.map +1 -1
- package/dist/payload/publishGeneratedDocs.d.ts +2 -1
- package/dist/payload/publishGeneratedDocs.js +20 -6
- package/dist/payload/publishGeneratedDocs.js.map +1 -1
- package/dist/plugin.js +1 -0
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/dist/collections/docs.js
CHANGED
|
@@ -130,6 +130,11 @@ export const createDocsCollection = ({ slug, docsSetsCollectionSlug, enableDraft
|
|
|
130
130
|
type: 'text',
|
|
131
131
|
index: true
|
|
132
132
|
},
|
|
133
|
+
{
|
|
134
|
+
name: 'contentHashAtLastSync',
|
|
135
|
+
type: 'text',
|
|
136
|
+
index: true
|
|
137
|
+
},
|
|
133
138
|
{
|
|
134
139
|
name: 'lastSyncedAt',
|
|
135
140
|
type: 'date'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/docs.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport { markdownField } from '@valkyrianlabs/payload-markdown'\n\nimport { MANAGED_BY } from '../constants.js'\n\nexport type CreateDocsCollectionOptions = {\n docsSetsCollectionSlug?: string\n enableDrafts?: boolean\n heroImageMediaCollectionSlugs?: string[]\n markdownFieldName: string\n slug: string\n syncRunsCollectionSlug?: string\n}\n\nconst createHeroImageField = (relationToSlugs: string[]): Field => {\n const fieldBase = {\n name: 'heroImage',\n type: 'upload' as const,\n admin: {\n description: 'Optional hero image rendered above generated docs content.',\n },\n displayPreview: true,\n label: 'Hero Image',\n maxDepth: 1,\n }\n\n if (relationToSlugs.length === 1) {\n return {\n ...fieldBase,\n relationTo: relationToSlugs[0] ?? 'media',\n }\n }\n\n return {\n ...fieldBase,\n relationTo: relationToSlugs,\n }\n}\n\nexport const createDocsCollection = ({\n slug,\n docsSetsCollectionSlug,\n enableDrafts = false,\n heroImageMediaCollectionSlugs,\n markdownFieldName,\n syncRunsCollectionSlug,\n}: CreateDocsCollectionOptions): CollectionConfig => ({\n slug,\n admin: {\n defaultColumns: ['title', 'route', 'sourcePath', 'updatedAt'],\n hidden: true,\n useAsTitle: 'title',\n },\n fields: [\n {\n name: 'title',\n type: 'text',\n required: true,\n },\n {\n name: 'navTitle',\n type: 'text',\n },\n {\n name: 'description',\n type: 'textarea',\n },\n {\n name: 'route',\n type: 'text',\n index: true,\n required: true,\n unique: true,\n },\n {\n name: 'sourcePath',\n type: 'text',\n index: true,\n required: true,\n },\n ...(docsSetsCollectionSlug\n ? [\n {\n name: 'docsSet',\n type: 'relationship' as const,\n index: true,\n relationTo: docsSetsCollectionSlug,\n },\n ]\n : []),\n {\n name: 'sourceHash',\n type: 'text',\n index: true,\n },\n {\n name: 'depth',\n type: 'number',\n defaultValue: 0,\n },\n {\n name: 'order',\n type: 'number',\n defaultValue: 0,\n },\n {\n name: 'parent',\n type: 'relationship',\n relationTo: slug,\n },\n ...(heroImageMediaCollectionSlugs?.length\n ? [createHeroImageField(heroImageMediaCollectionSlugs)]\n : []),\n markdownField({\n name: markdownFieldName,\n label: 'Content',\n }),\n {\n name: 'overrides',\n type: 'group',\n fields: [\n {\n name: 'navTitle',\n type: 'text',\n },\n {\n name: 'hideFromNav',\n type: 'checkbox',\n defaultValue: false,\n },\n ],\n },\n {\n name: 'sync',\n type: 'group',\n fields: [\n {\n name: 'sourceId',\n type: 'text',\n index: true,\n },\n {\n name: 'sourcePath',\n type: 'text',\n index: true,\n },\n {\n name: 'sourceHashAtLastSync',\n type: 'text',\n index: true,\n },\n {\n name: 'lastSyncedAt',\n type: 'date',\n },\n ...(syncRunsCollectionSlug\n ? [\n {\n name: 'lastSyncRunId',\n type: 'relationship' as const,\n relationTo: syncRunsCollectionSlug,\n },\n ]\n : []),\n {\n name: 'managedBy',\n type: 'text',\n defaultValue: MANAGED_BY,\n },\n {\n name: 'archived',\n type: 'checkbox',\n defaultValue: false,\n index: true,\n },\n {\n name: 'archivedAt',\n type: 'date',\n },\n ],\n },\n ],\n ...(enableDrafts\n ? {\n versions: {\n drafts: true,\n },\n }\n : {}),\n})\n"],"names":["markdownField","MANAGED_BY","createHeroImageField","relationToSlugs","fieldBase","name","type","admin","description","displayPreview","label","maxDepth","length","relationTo","createDocsCollection","slug","docsSetsCollectionSlug","enableDrafts","heroImageMediaCollectionSlugs","markdownFieldName","syncRunsCollectionSlug","defaultColumns","hidden","useAsTitle","fields","required","index","unique","defaultValue","versions","drafts"],"mappings":"AAEA,SAASA,aAAa,QAAQ,kCAAiC;AAE/D,SAASC,UAAU,QAAQ,kBAAiB;AAW5C,MAAMC,uBAAuB,CAACC;IAC5B,MAAMC,YAAY;QAChBC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aAAa;QACf;QACAC,gBAAgB;QAChBC,OAAO;QACPC,UAAU;IACZ;IAEA,IAAIR,gBAAgBS,MAAM,KAAK,GAAG;QAChC,OAAO;YACL,GAAGR,SAAS;YACZS,YAAYV,eAAe,CAAC,EAAE,IAAI;QACpC;IACF;IAEA,OAAO;QACL,GAAGC,SAAS;QACZS,YAAYV;IACd;AACF;AAEA,OAAO,MAAMW,uBAAuB,CAAC,EACnCC,IAAI,EACJC,sBAAsB,EACtBC,eAAe,KAAK,EACpBC,6BAA6B,EAC7BC,iBAAiB,EACjBC,sBAAsB,EACM,GAAwB,CAAA;QACpDL;QACAR,OAAO;YACLc,gBAAgB;gBAAC;gBAAS;gBAAS;gBAAc;aAAY;YAC7DC,QAAQ;YACRC,YAAY;QACd;QACAC,QAAQ;YACN;gBACEnB,MAAM;gBACNC,MAAM;gBACNmB,UAAU;YACZ;YACA;gBACEpB,MAAM;gBACNC,MAAM;YACR;YACA;gBACED,MAAM;gBACNC,MAAM;YACR;YACA;gBACED,MAAM;gBACNC,MAAM;gBACNoB,OAAO;gBACPD,UAAU;gBACVE,QAAQ;YACV;YACA;gBACEtB,MAAM;gBACNC,MAAM;gBACNoB,OAAO;gBACPD,UAAU;YACZ;eACIT,yBACA;gBACE;oBACEX,MAAM;oBACNC,MAAM;oBACNoB,OAAO;oBACPb,YAAYG;gBACd;aACD,GACD,EAAE;YACN;gBACEX,MAAM;gBACNC,MAAM;gBACNoB,OAAO;YACT;YACA;gBACErB,MAAM;gBACNC,MAAM;gBACNsB,cAAc;YAChB;YACA;gBACEvB,MAAM;gBACNC,MAAM;gBACNsB,cAAc;YAChB;YACA;gBACEvB,MAAM;gBACNC,MAAM;gBACNO,YAAYE;YACd;eACIG,+BAA+BN,SAC/B;gBAACV,qBAAqBgB;aAA+B,GACrD,EAAE;YACNlB,cAAc;gBACZK,MAAMc;gBACNT,OAAO;YACT;YACA;gBACEL,MAAM;gBACNC,MAAM;gBACNkB,QAAQ;oBACN;wBACEnB,MAAM;wBACNC,MAAM;oBACR;oBACA;wBACED,MAAM;wBACNC,MAAM;wBACNsB,cAAc;oBAChB;iBACD;YACH;YACA;gBACEvB,MAAM;gBACNC,MAAM;gBACNkB,QAAQ;oBACN;wBACEnB,MAAM;wBACNC,MAAM;wBACNoB,OAAO;oBACT;oBACA;wBACErB,MAAM;wBACNC,MAAM;wBACNoB,OAAO;oBACT;oBACA;wBACErB,MAAM;wBACNC,MAAM;wBACNoB,OAAO;oBACT;oBACA;wBACErB,MAAM;wBACNC,MAAM;oBACR;uBACIc,yBACA;wBACE;4BACEf,MAAM;4BACNC,MAAM;4BACNO,YAAYO;wBACd;qBACD,GACD,EAAE;oBACN;wBACEf,MAAM;wBACNC,MAAM;wBACNsB,cAAc3B;oBAChB;oBACA;wBACEI,MAAM;wBACNC,MAAM;wBACNsB,cAAc;wBACdF,OAAO;oBACT;oBACA;wBACErB,MAAM;wBACNC,MAAM;oBACR;iBACD;YACH;SACD;QACD,GAAIW,eACA;YACEY,UAAU;gBACRC,QAAQ;YACV;QACF,IACA,CAAC,CAAC;IACR,CAAA,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../src/collections/docs.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport { markdownField } from '@valkyrianlabs/payload-markdown'\n\nimport { MANAGED_BY } from '../constants.js'\n\nexport type CreateDocsCollectionOptions = {\n docsSetsCollectionSlug?: string\n enableDrafts?: boolean\n heroImageMediaCollectionSlugs?: string[]\n markdownFieldName: string\n slug: string\n syncRunsCollectionSlug?: string\n}\n\nconst createHeroImageField = (relationToSlugs: string[]): Field => {\n const fieldBase = {\n name: 'heroImage',\n type: 'upload' as const,\n admin: {\n description: 'Optional hero image rendered above generated docs content.',\n },\n displayPreview: true,\n label: 'Hero Image',\n maxDepth: 1,\n }\n\n if (relationToSlugs.length === 1) {\n return {\n ...fieldBase,\n relationTo: relationToSlugs[0] ?? 'media',\n }\n }\n\n return {\n ...fieldBase,\n relationTo: relationToSlugs,\n }\n}\n\nexport const createDocsCollection = ({\n slug,\n docsSetsCollectionSlug,\n enableDrafts = false,\n heroImageMediaCollectionSlugs,\n markdownFieldName,\n syncRunsCollectionSlug,\n}: CreateDocsCollectionOptions): CollectionConfig => ({\n slug,\n admin: {\n defaultColumns: ['title', 'route', 'sourcePath', 'updatedAt'],\n hidden: true,\n useAsTitle: 'title',\n },\n fields: [\n {\n name: 'title',\n type: 'text',\n required: true,\n },\n {\n name: 'navTitle',\n type: 'text',\n },\n {\n name: 'description',\n type: 'textarea',\n },\n {\n name: 'route',\n type: 'text',\n index: true,\n required: true,\n unique: true,\n },\n {\n name: 'sourcePath',\n type: 'text',\n index: true,\n required: true,\n },\n ...(docsSetsCollectionSlug\n ? [\n {\n name: 'docsSet',\n type: 'relationship' as const,\n index: true,\n relationTo: docsSetsCollectionSlug,\n },\n ]\n : []),\n {\n name: 'sourceHash',\n type: 'text',\n index: true,\n },\n {\n name: 'depth',\n type: 'number',\n defaultValue: 0,\n },\n {\n name: 'order',\n type: 'number',\n defaultValue: 0,\n },\n {\n name: 'parent',\n type: 'relationship',\n relationTo: slug,\n },\n ...(heroImageMediaCollectionSlugs?.length\n ? [createHeroImageField(heroImageMediaCollectionSlugs)]\n : []),\n markdownField({\n name: markdownFieldName,\n label: 'Content',\n }),\n {\n name: 'overrides',\n type: 'group',\n fields: [\n {\n name: 'navTitle',\n type: 'text',\n },\n {\n name: 'hideFromNav',\n type: 'checkbox',\n defaultValue: false,\n },\n ],\n },\n {\n name: 'sync',\n type: 'group',\n fields: [\n {\n name: 'sourceId',\n type: 'text',\n index: true,\n },\n {\n name: 'sourcePath',\n type: 'text',\n index: true,\n },\n {\n name: 'sourceHashAtLastSync',\n type: 'text',\n index: true,\n },\n {\n name: 'contentHashAtLastSync',\n type: 'text',\n index: true,\n },\n {\n name: 'lastSyncedAt',\n type: 'date',\n },\n ...(syncRunsCollectionSlug\n ? [\n {\n name: 'lastSyncRunId',\n type: 'relationship' as const,\n relationTo: syncRunsCollectionSlug,\n },\n ]\n : []),\n {\n name: 'managedBy',\n type: 'text',\n defaultValue: MANAGED_BY,\n },\n {\n name: 'archived',\n type: 'checkbox',\n defaultValue: false,\n index: true,\n },\n {\n name: 'archivedAt',\n type: 'date',\n },\n ],\n },\n ],\n ...(enableDrafts\n ? {\n versions: {\n drafts: true,\n },\n }\n : {}),\n})\n"],"names":["markdownField","MANAGED_BY","createHeroImageField","relationToSlugs","fieldBase","name","type","admin","description","displayPreview","label","maxDepth","length","relationTo","createDocsCollection","slug","docsSetsCollectionSlug","enableDrafts","heroImageMediaCollectionSlugs","markdownFieldName","syncRunsCollectionSlug","defaultColumns","hidden","useAsTitle","fields","required","index","unique","defaultValue","versions","drafts"],"mappings":"AAEA,SAASA,aAAa,QAAQ,kCAAiC;AAE/D,SAASC,UAAU,QAAQ,kBAAiB;AAW5C,MAAMC,uBAAuB,CAACC;IAC5B,MAAMC,YAAY;QAChBC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aAAa;QACf;QACAC,gBAAgB;QAChBC,OAAO;QACPC,UAAU;IACZ;IAEA,IAAIR,gBAAgBS,MAAM,KAAK,GAAG;QAChC,OAAO;YACL,GAAGR,SAAS;YACZS,YAAYV,eAAe,CAAC,EAAE,IAAI;QACpC;IACF;IAEA,OAAO;QACL,GAAGC,SAAS;QACZS,YAAYV;IACd;AACF;AAEA,OAAO,MAAMW,uBAAuB,CAAC,EACnCC,IAAI,EACJC,sBAAsB,EACtBC,eAAe,KAAK,EACpBC,6BAA6B,EAC7BC,iBAAiB,EACjBC,sBAAsB,EACM,GAAwB,CAAA;QACpDL;QACAR,OAAO;YACLc,gBAAgB;gBAAC;gBAAS;gBAAS;gBAAc;aAAY;YAC7DC,QAAQ;YACRC,YAAY;QACd;QACAC,QAAQ;YACN;gBACEnB,MAAM;gBACNC,MAAM;gBACNmB,UAAU;YACZ;YACA;gBACEpB,MAAM;gBACNC,MAAM;YACR;YACA;gBACED,MAAM;gBACNC,MAAM;YACR;YACA;gBACED,MAAM;gBACNC,MAAM;gBACNoB,OAAO;gBACPD,UAAU;gBACVE,QAAQ;YACV;YACA;gBACEtB,MAAM;gBACNC,MAAM;gBACNoB,OAAO;gBACPD,UAAU;YACZ;eACIT,yBACA;gBACE;oBACEX,MAAM;oBACNC,MAAM;oBACNoB,OAAO;oBACPb,YAAYG;gBACd;aACD,GACD,EAAE;YACN;gBACEX,MAAM;gBACNC,MAAM;gBACNoB,OAAO;YACT;YACA;gBACErB,MAAM;gBACNC,MAAM;gBACNsB,cAAc;YAChB;YACA;gBACEvB,MAAM;gBACNC,MAAM;gBACNsB,cAAc;YAChB;YACA;gBACEvB,MAAM;gBACNC,MAAM;gBACNO,YAAYE;YACd;eACIG,+BAA+BN,SAC/B;gBAACV,qBAAqBgB;aAA+B,GACrD,EAAE;YACNlB,cAAc;gBACZK,MAAMc;gBACNT,OAAO;YACT;YACA;gBACEL,MAAM;gBACNC,MAAM;gBACNkB,QAAQ;oBACN;wBACEnB,MAAM;wBACNC,MAAM;oBACR;oBACA;wBACED,MAAM;wBACNC,MAAM;wBACNsB,cAAc;oBAChB;iBACD;YACH;YACA;gBACEvB,MAAM;gBACNC,MAAM;gBACNkB,QAAQ;oBACN;wBACEnB,MAAM;wBACNC,MAAM;wBACNoB,OAAO;oBACT;oBACA;wBACErB,MAAM;wBACNC,MAAM;wBACNoB,OAAO;oBACT;oBACA;wBACErB,MAAM;wBACNC,MAAM;wBACNoB,OAAO;oBACT;oBACA;wBACErB,MAAM;wBACNC,MAAM;wBACNoB,OAAO;oBACT;oBACA;wBACErB,MAAM;wBACNC,MAAM;oBACR;uBACIc,yBACA;wBACE;4BACEf,MAAM;4BACNC,MAAM;4BACNO,YAAYO;wBACd;qBACD,GACD,EAAE;oBACN;wBACEf,MAAM;wBACNC,MAAM;wBACNsB,cAAc3B;oBAChB;oBACA;wBACEI,MAAM;wBACNC,MAAM;wBACNsB,cAAc;wBACdF,OAAO;oBACT;oBACA;wBACErB,MAAM;wBACNC,MAAM;oBACR;iBACD;YACH;SACD;QACD,GAAIW,eACA;YACEY,UAAU;gBACRC,QAAQ;YACV;QACF,IACA,CAAC,CAAC;IACR,CAAA,EAAE"}
|
|
@@ -4,7 +4,8 @@ export type CreateDocsSetsCollectionOptions = {
|
|
|
4
4
|
docsCollectionSlug?: string;
|
|
5
5
|
docsEnableDrafts?: boolean;
|
|
6
6
|
docsGroupsCollectionSlug: string;
|
|
7
|
+
markdownFieldName: string;
|
|
7
8
|
slug: string;
|
|
8
9
|
syncRunsCollectionSlug?: string;
|
|
9
10
|
};
|
|
10
|
-
export declare const createDocsSetsCollection: ({ slug, allowPublish, docsCollectionSlug, docsEnableDrafts, docsGroupsCollectionSlug, syncRunsCollectionSlug, }: CreateDocsSetsCollectionOptions) => CollectionConfig;
|
|
11
|
+
export declare const createDocsSetsCollection: ({ slug, allowPublish, docsCollectionSlug, docsEnableDrafts, docsGroupsCollectionSlug, markdownFieldName, syncRunsCollectionSlug, }: CreateDocsSetsCollectionOptions) => CollectionConfig;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DOCS_GLOBALS_ADMIN_GROUP, DOCS_SET_MANAGER_COMPONENT } from '../constants.js';
|
|
2
2
|
import { createPublishGeneratedDocsEndpoint } from '../endpoints/publishGeneratedDocs.js';
|
|
3
|
-
export const createDocsSetsCollection = ({ slug, allowPublish = false, docsCollectionSlug, docsEnableDrafts = false, docsGroupsCollectionSlug, syncRunsCollectionSlug })=>({
|
|
3
|
+
export const createDocsSetsCollection = ({ slug, allowPublish = false, docsCollectionSlug, docsEnableDrafts = false, docsGroupsCollectionSlug, markdownFieldName, syncRunsCollectionSlug })=>({
|
|
4
4
|
slug,
|
|
5
5
|
admin: {
|
|
6
6
|
defaultColumns: [
|
|
@@ -15,7 +15,8 @@ export const createDocsSetsCollection = ({ slug, allowPublish = false, docsColle
|
|
|
15
15
|
endpoints: docsCollectionSlug && docsEnableDrafts && allowPublish ? [
|
|
16
16
|
createPublishGeneratedDocsEndpoint({
|
|
17
17
|
docsCollectionSlug,
|
|
18
|
-
docsSetsCollectionSlug: slug
|
|
18
|
+
docsSetsCollectionSlug: slug,
|
|
19
|
+
markdownFieldName
|
|
19
20
|
})
|
|
20
21
|
] : undefined,
|
|
21
22
|
fields: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/docsSets.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nimport { DOCS_GLOBALS_ADMIN_GROUP, DOCS_SET_MANAGER_COMPONENT } from '../constants.js'\nimport { createPublishGeneratedDocsEndpoint } from '../endpoints/publishGeneratedDocs.js'\n\nexport type CreateDocsSetsCollectionOptions = {\n allowPublish?: boolean\n docsCollectionSlug?: string\n docsEnableDrafts?: boolean\n docsGroupsCollectionSlug: string\n slug: string\n syncRunsCollectionSlug?: string\n}\n\nexport const createDocsSetsCollection = ({\n slug,\n allowPublish = false,\n docsCollectionSlug,\n docsEnableDrafts = false,\n docsGroupsCollectionSlug,\n syncRunsCollectionSlug,\n}: CreateDocsSetsCollectionOptions): CollectionConfig => ({\n slug,\n admin: {\n defaultColumns: ['title', 'slug', 'branch', 'updatedAt'],\n group: DOCS_GLOBALS_ADMIN_GROUP,\n useAsTitle: 'title',\n },\n endpoints:\n docsCollectionSlug && docsEnableDrafts && allowPublish\n ? [\n createPublishGeneratedDocsEndpoint({\n docsCollectionSlug,\n docsSetsCollectionSlug: slug,\n }),\n ]\n : undefined,\n fields: [\n {\n name: 'title',\n type: 'text',\n required: true,\n },\n {\n name: 'slug',\n type: 'text',\n index: true,\n required: true,\n unique: true,\n },\n {\n name: 'group',\n type: 'relationship',\n relationTo: docsGroupsCollectionSlug,\n },\n {\n name: 'branch',\n type: 'text',\n admin: {\n description:\n 'Git branch allowed to publish this docs set. The full Git ref is handled internally.',\n },\n defaultValue: 'main',\n },\n {\n name: 'allowPullRequests',\n type: 'checkbox',\n admin: {\n description: 'Allow GitHub pull request events to dry-run or publish this docs set.',\n },\n defaultValue: false,\n },\n {\n name: 'description',\n type: 'textarea',\n },\n {\n name: 'advancedSecurity',\n type: 'group',\n admin: {\n description:\n 'Optional workflow lock-down. Leave disabled to allow any workflow from a trusted GitHub owner/repository and branch.',\n },\n fields: [\n {\n name: 'enabled',\n type: 'checkbox',\n admin: {\n description:\n 'When enabled, only the workflow refs listed below can publish this docs set.',\n },\n defaultValue: false,\n },\n {\n name: 'allowedWorkflowRefs',\n type: 'array',\n admin: {\n condition: (_data, siblingData) => siblingData?.enabled === true,\n description:\n 'Exact GitHub workflow refs, for example owner/repo/.github/workflows/publish-docs.yml@refs/heads/main.',\n },\n fields: [\n {\n name: 'value',\n type: 'text',\n required: true,\n },\n ],\n validate: (value, { siblingData }) => {\n const advancedSecurityData =\n typeof siblingData === 'object' && siblingData !== null\n ? (siblingData as { enabled?: unknown })\n : undefined\n\n if (\n advancedSecurityData?.enabled === true &&\n (!Array.isArray(value) || value.length === 0)\n ) {\n return 'Add at least one workflow ref or disable advanced security.'\n }\n\n return true\n },\n },\n ],\n },\n {\n name: 'aiExport',\n type: 'json',\n admin: {\n description: 'Parsed index.ai.yml control data for the raw Markdown AI export route.',\n },\n },\n {\n name: 'sync',\n type: 'group',\n fields: [\n {\n name: 'lastSyncedAt',\n type: 'date',\n },\n ...(syncRunsCollectionSlug\n ? [\n {\n name: 'lastSyncRunId',\n type: 'relationship' as const,\n relationTo: syncRunsCollectionSlug,\n },\n ]\n : []),\n {\n name: 'lastStatus',\n type: 'select',\n options: ['failed', 'pending', 'success'],\n },\n {\n name: 'docsCount',\n type: 'number',\n defaultValue: 0,\n },\n ],\n },\n ...(docsCollectionSlug\n ? [\n {\n name: 'docsSetManager',\n type: 'ui' as const,\n admin: {\n components: {\n Field: DOCS_SET_MANAGER_COMPONENT,\n },\n custom: {\n allowPublish,\n docsCollectionSlug,\n docsEnableDrafts,\n docsGroupsCollectionSlug,\n docsSetsCollectionSlug: slug,\n },\n },\n },\n ]\n : []),\n ],\n labels: {\n plural: 'Sets',\n singular: 'Set',\n },\n})\n"],"names":["DOCS_GLOBALS_ADMIN_GROUP","DOCS_SET_MANAGER_COMPONENT","createPublishGeneratedDocsEndpoint","createDocsSetsCollection","slug","allowPublish","docsCollectionSlug","docsEnableDrafts","docsGroupsCollectionSlug","syncRunsCollectionSlug","admin","defaultColumns","group","useAsTitle","endpoints","docsSetsCollectionSlug","undefined","fields","name","type","required","index","unique","relationTo","description","defaultValue","condition","_data","siblingData","enabled","validate","value","advancedSecurityData","Array","isArray","length","options","components","Field","custom","labels","plural","singular"],"mappings":"AAEA,SAASA,wBAAwB,EAAEC,0BAA0B,QAAQ,kBAAiB;AACtF,SAASC,kCAAkC,QAAQ,uCAAsC;
|
|
1
|
+
{"version":3,"sources":["../../src/collections/docsSets.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nimport { DOCS_GLOBALS_ADMIN_GROUP, DOCS_SET_MANAGER_COMPONENT } from '../constants.js'\nimport { createPublishGeneratedDocsEndpoint } from '../endpoints/publishGeneratedDocs.js'\n\nexport type CreateDocsSetsCollectionOptions = {\n allowPublish?: boolean\n docsCollectionSlug?: string\n docsEnableDrafts?: boolean\n docsGroupsCollectionSlug: string\n markdownFieldName: string\n slug: string\n syncRunsCollectionSlug?: string\n}\n\nexport const createDocsSetsCollection = ({\n slug,\n allowPublish = false,\n docsCollectionSlug,\n docsEnableDrafts = false,\n docsGroupsCollectionSlug,\n markdownFieldName,\n syncRunsCollectionSlug,\n}: CreateDocsSetsCollectionOptions): CollectionConfig => ({\n slug,\n admin: {\n defaultColumns: ['title', 'slug', 'branch', 'updatedAt'],\n group: DOCS_GLOBALS_ADMIN_GROUP,\n useAsTitle: 'title',\n },\n endpoints:\n docsCollectionSlug && docsEnableDrafts && allowPublish\n ? [\n createPublishGeneratedDocsEndpoint({\n docsCollectionSlug,\n docsSetsCollectionSlug: slug,\n markdownFieldName,\n }),\n ]\n : undefined,\n fields: [\n {\n name: 'title',\n type: 'text',\n required: true,\n },\n {\n name: 'slug',\n type: 'text',\n index: true,\n required: true,\n unique: true,\n },\n {\n name: 'group',\n type: 'relationship',\n relationTo: docsGroupsCollectionSlug,\n },\n {\n name: 'branch',\n type: 'text',\n admin: {\n description:\n 'Git branch allowed to publish this docs set. The full Git ref is handled internally.',\n },\n defaultValue: 'main',\n },\n {\n name: 'allowPullRequests',\n type: 'checkbox',\n admin: {\n description: 'Allow GitHub pull request events to dry-run or publish this docs set.',\n },\n defaultValue: false,\n },\n {\n name: 'description',\n type: 'textarea',\n },\n {\n name: 'advancedSecurity',\n type: 'group',\n admin: {\n description:\n 'Optional workflow lock-down. Leave disabled to allow any workflow from a trusted GitHub owner/repository and branch.',\n },\n fields: [\n {\n name: 'enabled',\n type: 'checkbox',\n admin: {\n description:\n 'When enabled, only the workflow refs listed below can publish this docs set.',\n },\n defaultValue: false,\n },\n {\n name: 'allowedWorkflowRefs',\n type: 'array',\n admin: {\n condition: (_data, siblingData) => siblingData?.enabled === true,\n description:\n 'Exact GitHub workflow refs, for example owner/repo/.github/workflows/publish-docs.yml@refs/heads/main.',\n },\n fields: [\n {\n name: 'value',\n type: 'text',\n required: true,\n },\n ],\n validate: (value, { siblingData }) => {\n const advancedSecurityData =\n typeof siblingData === 'object' && siblingData !== null\n ? (siblingData as { enabled?: unknown })\n : undefined\n\n if (\n advancedSecurityData?.enabled === true &&\n (!Array.isArray(value) || value.length === 0)\n ) {\n return 'Add at least one workflow ref or disable advanced security.'\n }\n\n return true\n },\n },\n ],\n },\n {\n name: 'aiExport',\n type: 'json',\n admin: {\n description: 'Parsed index.ai.yml control data for the raw Markdown AI export route.',\n },\n },\n {\n name: 'sync',\n type: 'group',\n fields: [\n {\n name: 'lastSyncedAt',\n type: 'date',\n },\n ...(syncRunsCollectionSlug\n ? [\n {\n name: 'lastSyncRunId',\n type: 'relationship' as const,\n relationTo: syncRunsCollectionSlug,\n },\n ]\n : []),\n {\n name: 'lastStatus',\n type: 'select',\n options: ['failed', 'pending', 'success'],\n },\n {\n name: 'docsCount',\n type: 'number',\n defaultValue: 0,\n },\n ],\n },\n ...(docsCollectionSlug\n ? [\n {\n name: 'docsSetManager',\n type: 'ui' as const,\n admin: {\n components: {\n Field: DOCS_SET_MANAGER_COMPONENT,\n },\n custom: {\n allowPublish,\n docsCollectionSlug,\n docsEnableDrafts,\n docsGroupsCollectionSlug,\n docsSetsCollectionSlug: slug,\n },\n },\n },\n ]\n : []),\n ],\n labels: {\n plural: 'Sets',\n singular: 'Set',\n },\n})\n"],"names":["DOCS_GLOBALS_ADMIN_GROUP","DOCS_SET_MANAGER_COMPONENT","createPublishGeneratedDocsEndpoint","createDocsSetsCollection","slug","allowPublish","docsCollectionSlug","docsEnableDrafts","docsGroupsCollectionSlug","markdownFieldName","syncRunsCollectionSlug","admin","defaultColumns","group","useAsTitle","endpoints","docsSetsCollectionSlug","undefined","fields","name","type","required","index","unique","relationTo","description","defaultValue","condition","_data","siblingData","enabled","validate","value","advancedSecurityData","Array","isArray","length","options","components","Field","custom","labels","plural","singular"],"mappings":"AAEA,SAASA,wBAAwB,EAAEC,0BAA0B,QAAQ,kBAAiB;AACtF,SAASC,kCAAkC,QAAQ,uCAAsC;AAYzF,OAAO,MAAMC,2BAA2B,CAAC,EACvCC,IAAI,EACJC,eAAe,KAAK,EACpBC,kBAAkB,EAClBC,mBAAmB,KAAK,EACxBC,wBAAwB,EACxBC,iBAAiB,EACjBC,sBAAsB,EACU,GAAwB,CAAA;QACxDN;QACAO,OAAO;YACLC,gBAAgB;gBAAC;gBAAS;gBAAQ;gBAAU;aAAY;YACxDC,OAAOb;YACPc,YAAY;QACd;QACAC,WACET,sBAAsBC,oBAAoBF,eACtC;YACEH,mCAAmC;gBACjCI;gBACAU,wBAAwBZ;gBACxBK;YACF;SACD,GACDQ;QACNC,QAAQ;YACN;gBACEC,MAAM;gBACNC,MAAM;gBACNC,UAAU;YACZ;YACA;gBACEF,MAAM;gBACNC,MAAM;gBACNE,OAAO;gBACPD,UAAU;gBACVE,QAAQ;YACV;YACA;gBACEJ,MAAM;gBACNC,MAAM;gBACNI,YAAYhB;YACd;YACA;gBACEW,MAAM;gBACNC,MAAM;gBACNT,OAAO;oBACLc,aACE;gBACJ;gBACAC,cAAc;YAChB;YACA;gBACEP,MAAM;gBACNC,MAAM;gBACNT,OAAO;oBACLc,aAAa;gBACf;gBACAC,cAAc;YAChB;YACA;gBACEP,MAAM;gBACNC,MAAM;YACR;YACA;gBACED,MAAM;gBACNC,MAAM;gBACNT,OAAO;oBACLc,aACE;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2,5 +2,6 @@ import type { Endpoint } from 'payload';
|
|
|
2
2
|
export type CreatePublishGeneratedDocsEndpointOptions = {
|
|
3
3
|
docsCollectionSlug: string;
|
|
4
4
|
docsSetsCollectionSlug: string;
|
|
5
|
+
markdownFieldName: string;
|
|
5
6
|
};
|
|
6
|
-
export declare const createPublishGeneratedDocsEndpoint: ({ docsCollectionSlug, docsSetsCollectionSlug, }: CreatePublishGeneratedDocsEndpointOptions) => Endpoint;
|
|
7
|
+
export declare const createPublishGeneratedDocsEndpoint: ({ docsCollectionSlug, docsSetsCollectionSlug, markdownFieldName, }: CreatePublishGeneratedDocsEndpointOptions) => Endpoint;
|
|
@@ -26,7 +26,7 @@ const redirectResponse = (location)=>new Response(null, {
|
|
|
26
26
|
},
|
|
27
27
|
status: 303
|
|
28
28
|
});
|
|
29
|
-
export const createPublishGeneratedDocsEndpoint = ({ docsCollectionSlug, docsSetsCollectionSlug })=>({
|
|
29
|
+
export const createPublishGeneratedDocsEndpoint = ({ docsCollectionSlug, docsSetsCollectionSlug, markdownFieldName })=>({
|
|
30
30
|
handler: async (req)=>{
|
|
31
31
|
if (!req.user) {
|
|
32
32
|
return jsonResponse({
|
|
@@ -58,6 +58,7 @@ export const createPublishGeneratedDocsEndpoint = ({ docsCollectionSlug, docsSet
|
|
|
58
58
|
const summary = await publishGeneratedDocsForSet({
|
|
59
59
|
docsCollectionSlug,
|
|
60
60
|
docsSetId,
|
|
61
|
+
markdownFieldName,
|
|
61
62
|
payload: req.payload
|
|
62
63
|
});
|
|
63
64
|
const redirect = getRedirectTarget(req);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/endpoints/publishGeneratedDocs.ts"],"sourcesContent":["import type { Endpoint, PayloadRequest } from 'payload'\n\nimport type { PublishGeneratedDocsPayloadOperations } from '../payload/publishGeneratedDocs.js'\n\nimport { publishGeneratedDocsForSet } from '../payload/publishGeneratedDocs.js'\n\nexport type CreatePublishGeneratedDocsEndpointOptions = {\n docsCollectionSlug: string\n docsSetsCollectionSlug: string\n}\n\ntype AccessCheckedPayload = {\n findByID: (args: Record<string, unknown>) => Promise<unknown>\n}\n\nconst jsonResponse = (body: Record<string, unknown>, status = 200): Response =>\n Response.json(body, {\n status,\n })\n\nconst getRouteParam = (req: PayloadRequest, key: string): number | string | undefined => {\n const value = req.routeParams?.[key]\n\n if (typeof value === 'string' || typeof value === 'number') {\n return value\n }\n\n return undefined\n}\n\nconst getRedirectTarget = (req: PayloadRequest): string | undefined => {\n if (!req.url) {\n return undefined\n }\n\n const url = new URL(req.url)\n const redirect = url.searchParams.get('redirect')\n\n if (!redirect || !redirect.startsWith('/') || redirect.startsWith('//')) {\n return undefined\n }\n\n return redirect\n}\n\nconst redirectResponse = (location: string): Response =>\n new Response(null, {\n headers: {\n Location: location,\n },\n status: 303,\n })\n\nexport const createPublishGeneratedDocsEndpoint = ({\n docsCollectionSlug,\n docsSetsCollectionSlug,\n}: CreatePublishGeneratedDocsEndpointOptions): Endpoint => ({\n handler: async (req) => {\n if (!req.user) {\n return jsonResponse(\n {\n error: 'Unauthorized',\n ok: false,\n },\n 401,\n )\n }\n\n const docsSetId = getRouteParam(req, 'id')\n\n if (docsSetId === undefined) {\n return jsonResponse(\n {\n error: 'Missing docs set id.',\n ok: false,\n },\n 400,\n )\n }\n\n try {\n await (req.payload as unknown as AccessCheckedPayload).findByID({\n id: docsSetId,\n collection: docsSetsCollectionSlug,\n depth: 0,\n overrideAccess: false,\n user: req.user,\n })\n } catch {\n return jsonResponse(\n {\n error: 'Forbidden',\n ok: false,\n },\n 403,\n )\n }\n\n const summary = await publishGeneratedDocsForSet({\n docsCollectionSlug,\n docsSetId,\n payload: req.payload as unknown as PublishGeneratedDocsPayloadOperations,\n })\n const redirect = getRedirectTarget(req)\n\n if (redirect) {\n return redirectResponse(redirect)\n }\n\n return jsonResponse({\n ok: true,\n summary,\n })\n },\n method: 'post',\n path: '/:id/publish-generated-docs',\n})\n"],"names":["publishGeneratedDocsForSet","jsonResponse","body","status","Response","json","getRouteParam","req","key","value","routeParams","undefined","getRedirectTarget","url","URL","redirect","searchParams","get","startsWith","redirectResponse","location","headers","Location","createPublishGeneratedDocsEndpoint","docsCollectionSlug","docsSetsCollectionSlug","handler","user","error","ok","docsSetId","payload","findByID","id","collection","depth","overrideAccess","summary","method","path"],"mappings":"AAIA,SAASA,0BAA0B,QAAQ,qCAAoC;
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/publishGeneratedDocs.ts"],"sourcesContent":["import type { Endpoint, PayloadRequest } from 'payload'\n\nimport type { PublishGeneratedDocsPayloadOperations } from '../payload/publishGeneratedDocs.js'\n\nimport { publishGeneratedDocsForSet } from '../payload/publishGeneratedDocs.js'\n\nexport type CreatePublishGeneratedDocsEndpointOptions = {\n docsCollectionSlug: string\n docsSetsCollectionSlug: string\n markdownFieldName: string\n}\n\ntype AccessCheckedPayload = {\n findByID: (args: Record<string, unknown>) => Promise<unknown>\n}\n\nconst jsonResponse = (body: Record<string, unknown>, status = 200): Response =>\n Response.json(body, {\n status,\n })\n\nconst getRouteParam = (req: PayloadRequest, key: string): number | string | undefined => {\n const value = req.routeParams?.[key]\n\n if (typeof value === 'string' || typeof value === 'number') {\n return value\n }\n\n return undefined\n}\n\nconst getRedirectTarget = (req: PayloadRequest): string | undefined => {\n if (!req.url) {\n return undefined\n }\n\n const url = new URL(req.url)\n const redirect = url.searchParams.get('redirect')\n\n if (!redirect || !redirect.startsWith('/') || redirect.startsWith('//')) {\n return undefined\n }\n\n return redirect\n}\n\nconst redirectResponse = (location: string): Response =>\n new Response(null, {\n headers: {\n Location: location,\n },\n status: 303,\n })\n\nexport const createPublishGeneratedDocsEndpoint = ({\n docsCollectionSlug,\n docsSetsCollectionSlug,\n markdownFieldName,\n}: CreatePublishGeneratedDocsEndpointOptions): Endpoint => ({\n handler: async (req) => {\n if (!req.user) {\n return jsonResponse(\n {\n error: 'Unauthorized',\n ok: false,\n },\n 401,\n )\n }\n\n const docsSetId = getRouteParam(req, 'id')\n\n if (docsSetId === undefined) {\n return jsonResponse(\n {\n error: 'Missing docs set id.',\n ok: false,\n },\n 400,\n )\n }\n\n try {\n await (req.payload as unknown as AccessCheckedPayload).findByID({\n id: docsSetId,\n collection: docsSetsCollectionSlug,\n depth: 0,\n overrideAccess: false,\n user: req.user,\n })\n } catch {\n return jsonResponse(\n {\n error: 'Forbidden',\n ok: false,\n },\n 403,\n )\n }\n\n const summary = await publishGeneratedDocsForSet({\n docsCollectionSlug,\n docsSetId,\n markdownFieldName,\n payload: req.payload as unknown as PublishGeneratedDocsPayloadOperations,\n })\n const redirect = getRedirectTarget(req)\n\n if (redirect) {\n return redirectResponse(redirect)\n }\n\n return jsonResponse({\n ok: true,\n summary,\n })\n },\n method: 'post',\n path: '/:id/publish-generated-docs',\n})\n"],"names":["publishGeneratedDocsForSet","jsonResponse","body","status","Response","json","getRouteParam","req","key","value","routeParams","undefined","getRedirectTarget","url","URL","redirect","searchParams","get","startsWith","redirectResponse","location","headers","Location","createPublishGeneratedDocsEndpoint","docsCollectionSlug","docsSetsCollectionSlug","markdownFieldName","handler","user","error","ok","docsSetId","payload","findByID","id","collection","depth","overrideAccess","summary","method","path"],"mappings":"AAIA,SAASA,0BAA0B,QAAQ,qCAAoC;AAY/E,MAAMC,eAAe,CAACC,MAA+BC,SAAS,GAAG,GAC/DC,SAASC,IAAI,CAACH,MAAM;QAClBC;IACF;AAEF,MAAMG,gBAAgB,CAACC,KAAqBC;IAC1C,MAAMC,QAAQF,IAAIG,WAAW,EAAE,CAACF,IAAI;IAEpC,IAAI,OAAOC,UAAU,YAAY,OAAOA,UAAU,UAAU;QAC1D,OAAOA;IACT;IAEA,OAAOE;AACT;AAEA,MAAMC,oBAAoB,CAACL;IACzB,IAAI,CAACA,IAAIM,GAAG,EAAE;QACZ,OAAOF;IACT;IAEA,MAAME,MAAM,IAAIC,IAAIP,IAAIM,GAAG;IAC3B,MAAME,WAAWF,IAAIG,YAAY,CAACC,GAAG,CAAC;IAEtC,IAAI,CAACF,YAAY,CAACA,SAASG,UAAU,CAAC,QAAQH,SAASG,UAAU,CAAC,OAAO;QACvE,OAAOP;IACT;IAEA,OAAOI;AACT;AAEA,MAAMI,mBAAmB,CAACC,WACxB,IAAIhB,SAAS,MAAM;QACjBiB,SAAS;YACPC,UAAUF;QACZ;QACAjB,QAAQ;IACV;AAEF,OAAO,MAAMoB,qCAAqC,CAAC,EACjDC,kBAAkB,EAClBC,sBAAsB,EACtBC,iBAAiB,EACyB,GAAgB,CAAA;QAC1DC,SAAS,OAAOpB;YACd,IAAI,CAACA,IAAIqB,IAAI,EAAE;gBACb,OAAO3B,aACL;oBACE4B,OAAO;oBACPC,IAAI;gBACN,GACA;YAEJ;YAEA,MAAMC,YAAYzB,cAAcC,KAAK;YAErC,IAAIwB,cAAcpB,WAAW;gBAC3B,OAAOV,aACL;oBACE4B,OAAO;oBACPC,IAAI;gBACN,GACA;YAEJ;YAEA,IAAI;gBACF,MAAM,AAACvB,IAAIyB,OAAO,CAAqCC,QAAQ,CAAC;oBAC9DC,IAAIH;oBACJI,YAAYV;oBACZW,OAAO;oBACPC,gBAAgB;oBAChBT,MAAMrB,IAAIqB,IAAI;gBAChB;YACF,EAAE,OAAM;gBACN,OAAO3B,aACL;oBACE4B,OAAO;oBACPC,IAAI;gBACN,GACA;YAEJ;YAEA,MAAMQ,UAAU,MAAMtC,2BAA2B;gBAC/CwB;gBACAO;gBACAL;gBACAM,SAASzB,IAAIyB,OAAO;YACtB;YACA,MAAMjB,WAAWH,kBAAkBL;YAEnC,IAAIQ,UAAU;gBACZ,OAAOI,iBAAiBJ;YAC1B;YAEA,OAAOd,aAAa;gBAClB6B,IAAI;gBACJQ;YACF;QACF;QACAC,QAAQ;QACRC,MAAM;IACR,CAAA,EAAE"}
|
|
@@ -20,7 +20,18 @@ export const findDocsSyncConflicts = ({ existingBySourcePath, plannedChanges })=
|
|
|
20
20
|
continue;
|
|
21
21
|
}
|
|
22
22
|
const currentContentHash = sha256Hex(current.content ?? '');
|
|
23
|
-
|
|
23
|
+
const expectedContentHash = current.sync.contentHashAtLastSync;
|
|
24
|
+
if (expectedContentHash) {
|
|
25
|
+
if (currentContentHash !== expectedContentHash) {
|
|
26
|
+
conflicts.push({
|
|
27
|
+
reason: 'current_content_hash_mismatch',
|
|
28
|
+
route: current.route,
|
|
29
|
+
sourcePath: current.sourcePath
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (currentContentHash !== current.sync.sourceHashAtLastSync && current.sourceHash !== current.sync.sourceHashAtLastSync) {
|
|
24
35
|
conflicts.push({
|
|
25
36
|
reason: 'current_content_hash_mismatch',
|
|
26
37
|
route: current.route,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/payload/docsConflicts.ts"],"sourcesContent":["import type { PlannedDocChange } from '../sync/index.js'\nimport type { ExistingPayloadDocsRecord } from './existingDocs.js'\n\nimport { MANAGED_BY } from '../constants.js'\nimport { sha256Hex } from '../sync/index.js'\n\nexport type DocsSyncConflictReason =\n | 'current_content_hash_mismatch'\n | 'missing_current_record'\n | 'unmanaged_record'\n\nexport type DocsSyncConflict = {\n reason: DocsSyncConflictReason\n route?: string\n sourcePath: string\n}\n\nexport const findDocsSyncConflicts = ({\n existingBySourcePath,\n plannedChanges,\n}: {\n existingBySourcePath: Map<string, ExistingPayloadDocsRecord>\n plannedChanges: PlannedDocChange[]\n}): DocsSyncConflict[] => {\n const conflicts: DocsSyncConflict[] = []\n\n for (const change of plannedChanges) {\n const current = existingBySourcePath.get(change.sourcePath)\n\n if (!current) {\n conflicts.push({\n reason: 'missing_current_record',\n sourcePath: change.sourcePath,\n })\n continue\n }\n\n if (current.sync?.managedBy !== MANAGED_BY) {\n conflicts.push({\n reason: 'unmanaged_record',\n route: current.route,\n sourcePath: current.sourcePath,\n })\n continue\n }\n\n const currentContentHash = sha256Hex(current.content ?? '')\n\n if (currentContentHash !== current.sync.sourceHashAtLastSync) {\n conflicts.push({\n reason: 'current_content_hash_mismatch',\n route: current.route,\n sourcePath: current.sourcePath,\n })\n }\n }\n\n return conflicts\n}\n
|
|
1
|
+
{"version":3,"sources":["../../src/payload/docsConflicts.ts"],"sourcesContent":["import type { PlannedDocChange } from '../sync/index.js'\nimport type { ExistingPayloadDocsRecord } from './existingDocs.js'\n\nimport { MANAGED_BY } from '../constants.js'\nimport { sha256Hex } from '../sync/index.js'\n\nexport type DocsSyncConflictReason =\n | 'current_content_hash_mismatch'\n | 'missing_current_record'\n | 'unmanaged_record'\n\nexport type DocsSyncConflict = {\n reason: DocsSyncConflictReason\n route?: string\n sourcePath: string\n}\n\nexport const findDocsSyncConflicts = ({\n existingBySourcePath,\n plannedChanges,\n}: {\n existingBySourcePath: Map<string, ExistingPayloadDocsRecord>\n plannedChanges: PlannedDocChange[]\n}): DocsSyncConflict[] => {\n const conflicts: DocsSyncConflict[] = []\n\n for (const change of plannedChanges) {\n const current = existingBySourcePath.get(change.sourcePath)\n\n if (!current) {\n conflicts.push({\n reason: 'missing_current_record',\n sourcePath: change.sourcePath,\n })\n continue\n }\n\n if (current.sync?.managedBy !== MANAGED_BY) {\n conflicts.push({\n reason: 'unmanaged_record',\n route: current.route,\n sourcePath: current.sourcePath,\n })\n continue\n }\n\n const currentContentHash = sha256Hex(current.content ?? '')\n const expectedContentHash = current.sync.contentHashAtLastSync\n\n if (expectedContentHash) {\n if (currentContentHash !== expectedContentHash) {\n conflicts.push({\n reason: 'current_content_hash_mismatch',\n route: current.route,\n sourcePath: current.sourcePath,\n })\n }\n\n continue\n }\n\n if (\n currentContentHash !== current.sync.sourceHashAtLastSync &&\n current.sourceHash !== current.sync.sourceHashAtLastSync\n ) {\n conflicts.push({\n reason: 'current_content_hash_mismatch',\n route: current.route,\n sourcePath: current.sourcePath,\n })\n }\n }\n\n return conflicts\n}\n"],"names":["MANAGED_BY","sha256Hex","findDocsSyncConflicts","existingBySourcePath","plannedChanges","conflicts","change","current","get","sourcePath","push","reason","sync","managedBy","route","currentContentHash","content","expectedContentHash","contentHashAtLastSync","sourceHashAtLastSync","sourceHash"],"mappings":"AAGA,SAASA,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,mBAAkB;AAa5C,OAAO,MAAMC,wBAAwB,CAAC,EACpCC,oBAAoB,EACpBC,cAAc,EAIf;IACC,MAAMC,YAAgC,EAAE;IAExC,KAAK,MAAMC,UAAUF,eAAgB;QACnC,MAAMG,UAAUJ,qBAAqBK,GAAG,CAACF,OAAOG,UAAU;QAE1D,IAAI,CAACF,SAAS;YACZF,UAAUK,IAAI,CAAC;gBACbC,QAAQ;gBACRF,YAAYH,OAAOG,UAAU;YAC/B;YACA;QACF;QAEA,IAAIF,QAAQK,IAAI,EAAEC,cAAcb,YAAY;YAC1CK,UAAUK,IAAI,CAAC;gBACbC,QAAQ;gBACRG,OAAOP,QAAQO,KAAK;gBACpBL,YAAYF,QAAQE,UAAU;YAChC;YACA;QACF;QAEA,MAAMM,qBAAqBd,UAAUM,QAAQS,OAAO,IAAI;QACxD,MAAMC,sBAAsBV,QAAQK,IAAI,CAACM,qBAAqB;QAE9D,IAAID,qBAAqB;YACvB,IAAIF,uBAAuBE,qBAAqB;gBAC9CZ,UAAUK,IAAI,CAAC;oBACbC,QAAQ;oBACRG,OAAOP,QAAQO,KAAK;oBACpBL,YAAYF,QAAQE,UAAU;gBAChC;YACF;YAEA;QACF;QAEA,IACEM,uBAAuBR,QAAQK,IAAI,CAACO,oBAAoB,IACxDZ,QAAQa,UAAU,KAAKb,QAAQK,IAAI,CAACO,oBAAoB,EACxD;YACAd,UAAUK,IAAI,CAAC;gBACbC,QAAQ;gBACRG,OAAOP,QAAQO,KAAK;gBACpBL,YAAYF,QAAQE,UAAU;YAChC;QACF;IACF;IAEA,OAAOJ;AACT,EAAC"}
|
package/dist/payload/docsData.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MANAGED_BY } from '../constants.js';
|
|
2
|
+
import { sha256Hex } from '../sync/index.js';
|
|
2
3
|
export const getDocsDepth = (sourcePath)=>sourcePath === 'index.md' ? 0 : Math.max(0, sourcePath.split('/').length - 1);
|
|
3
4
|
const getDraftStatusForDocsData = ({ current, docsEnableDrafts, publishMode })=>{
|
|
4
5
|
if (!docsEnableDrafts) {
|
|
@@ -33,6 +34,7 @@ export const buildDocsData = ({ current, desired, docsEnableDrafts, docsSetId, m
|
|
|
33
34
|
sync: {
|
|
34
35
|
archived: false,
|
|
35
36
|
archivedAt: null,
|
|
37
|
+
contentHashAtLastSync: sha256Hex(desired.content),
|
|
36
38
|
lastSyncedAt: now.toISOString(),
|
|
37
39
|
lastSyncRunId: syncRunId,
|
|
38
40
|
managedBy: MANAGED_BY,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/payload/docsData.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../src/payload/docsData.ts"],"sourcesContent":["import type { ValidatedDocsManifest, ValidatedDocsManifestFile } from '../sync/index.js'\nimport type { ExistingPayloadDocsRecord } from './existingDocs.js'\n\nimport { MANAGED_BY } from '../constants.js'\nimport { sha256Hex } from '../sync/index.js'\n\nexport type BuildDocsDataInput = {\n current?: ExistingPayloadDocsRecord\n desired: ValidatedDocsManifestFile\n docsEnableDrafts: boolean\n docsSetId?: number | string\n manifest: ValidatedDocsManifest\n markdownFieldName: string\n now: Date\n publishMode: DocsPublishMode\n syncRunId?: number | string\n}\n\nexport type DocsDraftStatus = 'draft' | 'published'\n\nexport type DocsPublishMode = 'draft' | 'preserve' | 'published'\n\nexport const getDocsDepth = (sourcePath: string): number =>\n sourcePath === 'index.md' ? 0 : Math.max(0, sourcePath.split('/').length - 1)\n\nconst getDraftStatusForDocsData = ({\n current,\n docsEnableDrafts,\n publishMode,\n}: {\n current?: ExistingPayloadDocsRecord\n docsEnableDrafts: boolean\n publishMode: DocsPublishMode\n}): DocsDraftStatus | undefined => {\n if (!docsEnableDrafts) {\n return undefined\n }\n\n if (publishMode === 'draft' || publishMode === 'published') {\n return publishMode\n }\n\n return current ? current.status : 'draft'\n}\n\nexport const buildDocsData = ({\n current,\n desired,\n docsEnableDrafts,\n docsSetId,\n manifest,\n markdownFieldName,\n now,\n publishMode,\n syncRunId,\n}: BuildDocsDataInput): Record<string, unknown> => {\n const draftStatus = getDraftStatusForDocsData({\n current,\n docsEnableDrafts,\n publishMode,\n })\n\n return {\n ...(draftStatus ? { _status: draftStatus } : {}),\n depth: getDocsDepth(desired.path),\n description: desired.frontmatter.description,\n ...(docsSetId ? { docsSet: docsSetId } : {}),\n [markdownFieldName]: desired.content,\n navTitle: desired.frontmatter.navTitle,\n order: desired.frontmatter.order ?? 0,\n route: desired.route,\n sourceHash: desired.sha256,\n sourcePath: desired.path,\n sync: {\n archived: false,\n archivedAt: null,\n contentHashAtLastSync: sha256Hex(desired.content),\n lastSyncedAt: now.toISOString(),\n lastSyncRunId: syncRunId,\n managedBy: MANAGED_BY,\n sourceHashAtLastSync: desired.sha256,\n sourceId: manifest.source.id,\n sourcePath: desired.path,\n },\n title: desired.title,\n }\n}\n\nexport const buildArchiveData = ({\n docsEnableDrafts = false,\n draftMissing = false,\n now,\n syncRunId,\n}: {\n docsEnableDrafts?: boolean\n draftMissing?: boolean\n now: Date\n syncRunId?: number | string\n}): Record<string, unknown> => ({\n ...(draftMissing && docsEnableDrafts ? { _status: 'draft' } : {}),\n sync: {\n archived: true,\n archivedAt: now.toISOString(),\n lastSyncedAt: now.toISOString(),\n lastSyncRunId: syncRunId,\n managedBy: MANAGED_BY,\n },\n})\n"],"names":["MANAGED_BY","sha256Hex","getDocsDepth","sourcePath","Math","max","split","length","getDraftStatusForDocsData","current","docsEnableDrafts","publishMode","undefined","status","buildDocsData","desired","docsSetId","manifest","markdownFieldName","now","syncRunId","draftStatus","_status","depth","path","description","frontmatter","docsSet","content","navTitle","order","route","sourceHash","sha256","sync","archived","archivedAt","contentHashAtLastSync","lastSyncedAt","toISOString","lastSyncRunId","managedBy","sourceHashAtLastSync","sourceId","source","id","title","buildArchiveData","draftMissing"],"mappings":"AAGA,SAASA,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,mBAAkB;AAkB5C,OAAO,MAAMC,eAAe,CAACC,aAC3BA,eAAe,aAAa,IAAIC,KAAKC,GAAG,CAAC,GAAGF,WAAWG,KAAK,CAAC,KAAKC,MAAM,GAAG,GAAE;AAE/E,MAAMC,4BAA4B,CAAC,EACjCC,OAAO,EACPC,gBAAgB,EAChBC,WAAW,EAKZ;IACC,IAAI,CAACD,kBAAkB;QACrB,OAAOE;IACT;IAEA,IAAID,gBAAgB,WAAWA,gBAAgB,aAAa;QAC1D,OAAOA;IACT;IAEA,OAAOF,UAAUA,QAAQI,MAAM,GAAG;AACpC;AAEA,OAAO,MAAMC,gBAAgB,CAAC,EAC5BL,OAAO,EACPM,OAAO,EACPL,gBAAgB,EAChBM,SAAS,EACTC,QAAQ,EACRC,iBAAiB,EACjBC,GAAG,EACHR,WAAW,EACXS,SAAS,EACU;IACnB,MAAMC,cAAcb,0BAA0B;QAC5CC;QACAC;QACAC;IACF;IAEA,OAAO;QACL,GAAIU,cAAc;YAAEC,SAASD;QAAY,IAAI,CAAC,CAAC;QAC/CE,OAAOrB,aAAaa,QAAQS,IAAI;QAChCC,aAAaV,QAAQW,WAAW,CAACD,WAAW;QAC5C,GAAIT,YAAY;YAAEW,SAASX;QAAU,IAAI,CAAC,CAAC;QAC3C,CAACE,kBAAkB,EAAEH,QAAQa,OAAO;QACpCC,UAAUd,QAAQW,WAAW,CAACG,QAAQ;QACtCC,OAAOf,QAAQW,WAAW,CAACI,KAAK,IAAI;QACpCC,OAAOhB,QAAQgB,KAAK;QACpBC,YAAYjB,QAAQkB,MAAM;QAC1B9B,YAAYY,QAAQS,IAAI;QACxBU,MAAM;YACJC,UAAU;YACVC,YAAY;YACZC,uBAAuBpC,UAAUc,QAAQa,OAAO;YAChDU,cAAcnB,IAAIoB,WAAW;YAC7BC,eAAepB;YACfqB,WAAWzC;YACX0C,sBAAsB3B,QAAQkB,MAAM;YACpCU,UAAU1B,SAAS2B,MAAM,CAACC,EAAE;YAC5B1C,YAAYY,QAAQS,IAAI;QAC1B;QACAsB,OAAO/B,QAAQ+B,KAAK;IACtB;AACF,EAAC;AAED,OAAO,MAAMC,mBAAmB,CAAC,EAC/BrC,mBAAmB,KAAK,EACxBsC,eAAe,KAAK,EACpB7B,GAAG,EACHC,SAAS,EAMV,GAA+B,CAAA;QAC9B,GAAI4B,gBAAgBtC,mBAAmB;YAAEY,SAAS;QAAQ,IAAI,CAAC,CAAC;QAChEY,MAAM;YACJC,UAAU;YACVC,YAAYjB,IAAIoB,WAAW;YAC3BD,cAAcnB,IAAIoB,WAAW;YAC7BC,eAAepB;YACfqB,WAAWzC;QACb;IACF,CAAA,EAAE"}
|
|
@@ -36,6 +36,7 @@ const toExistingPayloadDocsRecord = ({ doc, markdownFieldName })=>{
|
|
|
36
36
|
sync: sync ? {
|
|
37
37
|
archived: typeof sync.archived === 'boolean' ? sync.archived : undefined,
|
|
38
38
|
archivedAt: typeof sync.archivedAt === 'string' || sync.archivedAt === null ? sync.archivedAt : undefined,
|
|
39
|
+
contentHashAtLastSync: typeof sync.contentHashAtLastSync === 'string' ? sync.contentHashAtLastSync : undefined,
|
|
39
40
|
lastSyncedAt: typeof sync.lastSyncedAt === 'string' ? sync.lastSyncedAt : undefined,
|
|
40
41
|
lastSyncRunId: typeof sync.lastSyncRunId === 'string' ? sync.lastSyncRunId : undefined,
|
|
41
42
|
managedBy: typeof sync.managedBy === 'string' ? sync.managedBy : undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/payload/existingDocs.ts"],"sourcesContent":["import type { ExistingDocsRecord } from '../sync/index.js'\n\nexport type ExistingDocsPayloadOperations = {\n find: (args: {\n collection: string\n depth?: number\n limit?: number\n overrideAccess?: boolean\n where?: unknown\n }) => Promise<{\n docs: unknown[]\n }>\n}\n\nexport type ExistingPayloadDocsRecord = {\n content?: string\n docsSetId?: number | string\n id: string\n status?: 'draft' | 'published'\n sync?: {\n archived?: boolean\n archivedAt?: null | string\n lastSyncedAt?: string\n lastSyncRunId?: string\n managedBy?: string\n sourceHashAtLastSync?: string\n sourceId?: string\n sourcePath?: string\n }\n} & ExistingDocsRecord\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\nconst getRecordId = (doc: Record<string, unknown>): string | undefined => {\n if (typeof doc.id === 'string' || typeof doc.id === 'number') {\n return String(doc.id)\n }\n\n return undefined\n}\n\nconst getRelationshipId = (value: unknown): string | undefined => {\n if (typeof value === 'string' || typeof value === 'number') {\n return String(value)\n }\n\n if (isRecord(value)) {\n return getRecordId(value)\n }\n\n return undefined\n}\n\nconst toExistingPayloadDocsRecord = ({\n doc,\n markdownFieldName,\n}: {\n doc: unknown\n markdownFieldName: string\n}): ExistingPayloadDocsRecord | undefined => {\n if (!isRecord(doc)) {\n return undefined\n }\n\n const id = getRecordId(doc)\n\n if (!id || typeof doc.route !== 'string' || typeof doc.sourcePath !== 'string') {\n return undefined\n }\n\n const sync = isRecord(doc.sync) ? doc.sync : undefined\n const status
|
|
1
|
+
{"version":3,"sources":["../../src/payload/existingDocs.ts"],"sourcesContent":["import type { ExistingDocsRecord } from '../sync/index.js'\n\nexport type ExistingDocsPayloadOperations = {\n find: (args: {\n collection: string\n depth?: number\n limit?: number\n overrideAccess?: boolean\n where?: unknown\n }) => Promise<{\n docs: unknown[]\n }>\n}\n\nexport type ExistingPayloadDocsRecord = {\n content?: string\n docsSetId?: number | string\n id: string\n status?: 'draft' | 'published'\n sync?: {\n archived?: boolean\n archivedAt?: null | string\n contentHashAtLastSync?: string\n lastSyncedAt?: string\n lastSyncRunId?: string\n managedBy?: string\n sourceHashAtLastSync?: string\n sourceId?: string\n sourcePath?: string\n }\n} & ExistingDocsRecord\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\nconst getRecordId = (doc: Record<string, unknown>): string | undefined => {\n if (typeof doc.id === 'string' || typeof doc.id === 'number') {\n return String(doc.id)\n }\n\n return undefined\n}\n\nconst getRelationshipId = (value: unknown): string | undefined => {\n if (typeof value === 'string' || typeof value === 'number') {\n return String(value)\n }\n\n if (isRecord(value)) {\n return getRecordId(value)\n }\n\n return undefined\n}\n\nconst toExistingPayloadDocsRecord = ({\n doc,\n markdownFieldName,\n}: {\n doc: unknown\n markdownFieldName: string\n}): ExistingPayloadDocsRecord | undefined => {\n if (!isRecord(doc)) {\n return undefined\n }\n\n const id = getRecordId(doc)\n\n if (!id || typeof doc.route !== 'string' || typeof doc.sourcePath !== 'string') {\n return undefined\n }\n\n const sync = isRecord(doc.sync) ? doc.sync : undefined\n const status = doc._status === 'draft' || doc._status === 'published' ? doc._status : undefined\n\n return {\n id,\n archived: typeof sync?.archived === 'boolean' ? sync.archived : undefined,\n content: typeof doc[markdownFieldName] === 'string' ? doc[markdownFieldName] : undefined,\n docsSetId: getRelationshipId(doc.docsSet),\n route: doc.route,\n sourceHash: typeof doc.sourceHash === 'string' ? doc.sourceHash : undefined,\n sourcePath: doc.sourcePath,\n status,\n sync: sync\n ? {\n archived: typeof sync.archived === 'boolean' ? sync.archived : undefined,\n archivedAt:\n typeof sync.archivedAt === 'string' || sync.archivedAt === null\n ? sync.archivedAt\n : undefined,\n contentHashAtLastSync:\n typeof sync.contentHashAtLastSync === 'string' ? sync.contentHashAtLastSync : undefined,\n lastSyncedAt: typeof sync.lastSyncedAt === 'string' ? sync.lastSyncedAt : undefined,\n lastSyncRunId: typeof sync.lastSyncRunId === 'string' ? sync.lastSyncRunId : undefined,\n managedBy: typeof sync.managedBy === 'string' ? sync.managedBy : undefined,\n sourceHashAtLastSync:\n typeof sync.sourceHashAtLastSync === 'string' ? sync.sourceHashAtLastSync : undefined,\n sourceId: typeof sync.sourceId === 'string' ? sync.sourceId : undefined,\n sourcePath: typeof sync.sourcePath === 'string' ? sync.sourcePath : undefined,\n }\n : undefined,\n title: typeof doc.title === 'string' ? doc.title : undefined,\n }\n}\n\nexport const toExistingDocsRecord = (doc: ExistingPayloadDocsRecord): ExistingDocsRecord => ({\n archived: doc.archived,\n route: doc.route,\n sourceHash: doc.sourceHash,\n sourcePath: doc.sourcePath,\n title: doc.title,\n})\n\nexport const findExistingPayloadDocsRecords = async ({\n collectionSlug,\n docsSetId,\n markdownFieldName,\n payload,\n sourceId,\n}: {\n collectionSlug: string\n docsSetId?: number | string\n markdownFieldName: string\n payload: ExistingDocsPayloadOperations\n sourceId: string\n}): Promise<ExistingPayloadDocsRecord[]> => {\n const result = await payload.find({\n collection: collectionSlug,\n depth: 0,\n limit: 1000,\n overrideAccess: true,\n where: docsSetId\n ? {\n or: [\n {\n docsSet: {\n equals: docsSetId,\n },\n },\n {\n 'sync.sourceId': {\n equals: sourceId,\n },\n },\n ],\n }\n : {\n 'sync.sourceId': {\n equals: sourceId,\n },\n },\n })\n\n return result.docs\n .map((doc) =>\n toExistingPayloadDocsRecord({\n doc,\n markdownFieldName,\n }),\n )\n .filter((doc): doc is ExistingPayloadDocsRecord => doc !== undefined)\n}\n\nexport const findExistingDocsRecords = async ({\n collectionSlug,\n docsSetId,\n markdownFieldName,\n payload,\n sourceId,\n}: {\n collectionSlug: string\n docsSetId?: number | string\n markdownFieldName: string\n payload: ExistingDocsPayloadOperations\n sourceId: string\n}): Promise<ExistingDocsRecord[]> => {\n const docs = await findExistingPayloadDocsRecords({\n collectionSlug,\n docsSetId,\n markdownFieldName,\n payload,\n sourceId,\n })\n\n return docs.map(toExistingDocsRecord)\n}\n"],"names":["isRecord","value","Array","isArray","getRecordId","doc","id","String","undefined","getRelationshipId","toExistingPayloadDocsRecord","markdownFieldName","route","sourcePath","sync","status","_status","archived","content","docsSetId","docsSet","sourceHash","archivedAt","contentHashAtLastSync","lastSyncedAt","lastSyncRunId","managedBy","sourceHashAtLastSync","sourceId","title","toExistingDocsRecord","findExistingPayloadDocsRecords","collectionSlug","payload","result","find","collection","depth","limit","overrideAccess","where","or","equals","docs","map","filter","findExistingDocsRecords"],"mappings":"AAgCA,MAAMA,WAAW,CAACC,QAChB,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACC,MAAMC,OAAO,CAACF;AAEhE,MAAMG,cAAc,CAACC;IACnB,IAAI,OAAOA,IAAIC,EAAE,KAAK,YAAY,OAAOD,IAAIC,EAAE,KAAK,UAAU;QAC5D,OAAOC,OAAOF,IAAIC,EAAE;IACtB;IAEA,OAAOE;AACT;AAEA,MAAMC,oBAAoB,CAACR;IACzB,IAAI,OAAOA,UAAU,YAAY,OAAOA,UAAU,UAAU;QAC1D,OAAOM,OAAON;IAChB;IAEA,IAAID,SAASC,QAAQ;QACnB,OAAOG,YAAYH;IACrB;IAEA,OAAOO;AACT;AAEA,MAAME,8BAA8B,CAAC,EACnCL,GAAG,EACHM,iBAAiB,EAIlB;IACC,IAAI,CAACX,SAASK,MAAM;QAClB,OAAOG;IACT;IAEA,MAAMF,KAAKF,YAAYC;IAEvB,IAAI,CAACC,MAAM,OAAOD,IAAIO,KAAK,KAAK,YAAY,OAAOP,IAAIQ,UAAU,KAAK,UAAU;QAC9E,OAAOL;IACT;IAEA,MAAMM,OAAOd,SAASK,IAAIS,IAAI,IAAIT,IAAIS,IAAI,GAAGN;IAC7C,MAAMO,SAASV,IAAIW,OAAO,KAAK,WAAWX,IAAIW,OAAO,KAAK,cAAcX,IAAIW,OAAO,GAAGR;IAEtF,OAAO;QACLF;QACAW,UAAU,OAAOH,MAAMG,aAAa,YAAYH,KAAKG,QAAQ,GAAGT;QAChEU,SAAS,OAAOb,GAAG,CAACM,kBAAkB,KAAK,WAAWN,GAAG,CAACM,kBAAkB,GAAGH;QAC/EW,WAAWV,kBAAkBJ,IAAIe,OAAO;QACxCR,OAAOP,IAAIO,KAAK;QAChBS,YAAY,OAAOhB,IAAIgB,UAAU,KAAK,WAAWhB,IAAIgB,UAA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OAAO;QACPC,gBAAgB;QAChBC,OAAOrB,YACH;YACEsB,IAAI;gBACF;oBACErB,SAAS;wBACPsB,QAAQvB;oBACV;gBACF;gBACA;oBACE,iBAAiB;wBACfuB,QAAQd;oBACV;gBACF;aACD;QACH,IACA;YACE,iBAAiB;gBACfc,QAAQd;YACV;QACF;IACN;IAEA,OAAOM,OAAOS,IAAI,CACfC,GAAG,CAAC,CAACvC,MACJK,4BAA4B;YAC1BL;YACAM;QACF,IAEDkC,MAAM,CAAC,CAACxC,MAA0CA,QAAQG;AAC/D,EAAC;AAED,OAAO,MAAMsC,0BAA0B,OAAO,EAC5Cd,cAAc,EACdb,SAAS,EACTR,iBAAiB,EACjBsB,OAAO,EACPL,QAAQ,EAOT;IACC,MAAMe,OAAO,MAAMZ,+BAA+B;QAChDC;QACAb;QACAR;QACAsB;QACAL;IACF;IAEA,OAAOe,KAAKC,GAAG,CAACd;AAClB,EAAC"}
|
|
@@ -22,8 +22,9 @@ export type PublishGeneratedDocsResult = {
|
|
|
22
22
|
total: number;
|
|
23
23
|
updated: number;
|
|
24
24
|
};
|
|
25
|
-
export declare const publishGeneratedDocsForSet: ({ docsCollectionSlug, docsSetId, payload, }: {
|
|
25
|
+
export declare const publishGeneratedDocsForSet: ({ docsCollectionSlug, docsSetId, markdownFieldName, payload, }: {
|
|
26
26
|
docsCollectionSlug: string;
|
|
27
27
|
docsSetId: number | string;
|
|
28
|
+
markdownFieldName: string;
|
|
28
29
|
payload: PublishGeneratedDocsPayloadOperations;
|
|
29
30
|
}) => Promise<PublishGeneratedDocsResult>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sha256Hex } from '../sync/index.js';
|
|
1
2
|
const isRecord = (value)=>typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
2
3
|
const getRecordId = (doc)=>{
|
|
3
4
|
if (typeof doc.id === 'string' || typeof doc.id === 'number') {
|
|
@@ -19,7 +20,7 @@ const isArchived = (doc)=>{
|
|
|
19
20
|
const sync = isRecord(doc.sync) ? doc.sync : undefined;
|
|
20
21
|
return sync?.archived === true;
|
|
21
22
|
};
|
|
22
|
-
export const publishGeneratedDocsForSet = async ({ docsCollectionSlug, docsSetId, payload })=>{
|
|
23
|
+
export const publishGeneratedDocsForSet = async ({ docsCollectionSlug, docsSetId, markdownFieldName, payload })=>{
|
|
23
24
|
const result = await payload.find({
|
|
24
25
|
collection: docsCollectionSlug,
|
|
25
26
|
depth: 0,
|
|
@@ -50,11 +51,16 @@ export const publishGeneratedDocsForSet = async ({ docsCollectionSlug, docsSetId
|
|
|
50
51
|
summary.archived += 1;
|
|
51
52
|
continue;
|
|
52
53
|
}
|
|
54
|
+
const sync = isRecord(rawDoc.sync) ? rawDoc.sync : {};
|
|
55
|
+
const content = typeof rawDoc[markdownFieldName] === 'string' ? rawDoc[markdownFieldName] : '';
|
|
56
|
+
const contentHashAtLastSync = sha256Hex(content);
|
|
57
|
+
const needsContentHashUpdate = sync.contentHashAtLastSync !== contentHashAtLastSync;
|
|
53
58
|
if (rawDoc._status === 'published') {
|
|
54
59
|
summary.published += 1;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
if (!needsContentHashUpdate) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
} else if (rawDoc._status === 'draft') {
|
|
58
64
|
summary.drafts += 1;
|
|
59
65
|
}
|
|
60
66
|
const id = getRecordId(rawDoc);
|
|
@@ -65,12 +71,20 @@ export const publishGeneratedDocsForSet = async ({ docsCollectionSlug, docsSetId
|
|
|
65
71
|
id,
|
|
66
72
|
collection: docsCollectionSlug,
|
|
67
73
|
data: {
|
|
68
|
-
_status
|
|
74
|
+
...rawDoc._status === 'published' ? {} : {
|
|
75
|
+
_status: 'published'
|
|
76
|
+
},
|
|
77
|
+
sync: {
|
|
78
|
+
...sync,
|
|
79
|
+
contentHashAtLastSync
|
|
80
|
+
}
|
|
69
81
|
},
|
|
70
82
|
overrideAccess: true
|
|
71
83
|
});
|
|
72
84
|
summary.updated += 1;
|
|
73
|
-
|
|
85
|
+
if (rawDoc._status !== 'published') {
|
|
86
|
+
summary.published += 1;
|
|
87
|
+
}
|
|
74
88
|
}
|
|
75
89
|
return summary;
|
|
76
90
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/payload/publishGeneratedDocs.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/payload/publishGeneratedDocs.ts"],"sourcesContent":["import { sha256Hex } from '../sync/index.js'\n\nexport type PublishGeneratedDocsPayloadOperations = {\n find: (args: {\n collection: string\n depth?: number\n limit?: number\n overrideAccess?: boolean\n where?: unknown\n }) => Promise<{\n docs: unknown[]\n }>\n update: (args: {\n collection: string\n data: Record<string, unknown>\n id: number | string\n overrideAccess?: boolean\n }) => Promise<unknown>\n}\n\nexport type PublishGeneratedDocsResult = {\n archived: number\n drafts: number\n published: number\n total: number\n updated: number\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\nconst getRecordId = (doc: Record<string, unknown>): number | string | undefined => {\n if (typeof doc.id === 'string' || typeof doc.id === 'number') {\n return doc.id\n }\n\n return undefined\n}\n\nconst getRelationshipId = (value: unknown): string | undefined => {\n if (typeof value === 'string' || typeof value === 'number') {\n return String(value)\n }\n\n if (isRecord(value)) {\n const id = getRecordId(value)\n\n return id === undefined ? undefined : String(id)\n }\n\n return undefined\n}\n\nconst isArchived = (doc: Record<string, unknown>): boolean => {\n const sync = isRecord(doc.sync) ? doc.sync : undefined\n\n return sync?.archived === true\n}\n\nexport const publishGeneratedDocsForSet = async ({\n docsCollectionSlug,\n docsSetId,\n markdownFieldName,\n payload,\n}: {\n docsCollectionSlug: string\n docsSetId: number | string\n markdownFieldName: string\n payload: PublishGeneratedDocsPayloadOperations\n}): Promise<PublishGeneratedDocsResult> => {\n const result = await payload.find({\n collection: docsCollectionSlug,\n depth: 0,\n limit: 1000,\n overrideAccess: true,\n where: {\n docsSet: {\n equals: docsSetId,\n },\n },\n })\n\n const summary: PublishGeneratedDocsResult = {\n archived: 0,\n drafts: 0,\n published: 0,\n total: 0,\n updated: 0,\n }\n\n for (const rawDoc of result.docs) {\n if (!isRecord(rawDoc)) {\n continue\n }\n\n if (getRelationshipId(rawDoc.docsSet) !== String(docsSetId)) {\n continue\n }\n\n summary.total += 1\n\n if (isArchived(rawDoc)) {\n summary.archived += 1\n continue\n }\n\n const sync = isRecord(rawDoc.sync) ? rawDoc.sync : {}\n const content = typeof rawDoc[markdownFieldName] === 'string' ? rawDoc[markdownFieldName] : ''\n const contentHashAtLastSync = sha256Hex(content)\n const needsContentHashUpdate = sync.contentHashAtLastSync !== contentHashAtLastSync\n\n if (rawDoc._status === 'published') {\n summary.published += 1\n\n if (!needsContentHashUpdate) {\n continue\n }\n } else if (rawDoc._status === 'draft') {\n summary.drafts += 1\n }\n\n const id = getRecordId(rawDoc)\n\n if (id === undefined) {\n continue\n }\n\n await payload.update({\n id,\n collection: docsCollectionSlug,\n data: {\n ...(rawDoc._status === 'published' ? {} : { _status: 'published' }),\n sync: {\n ...sync,\n contentHashAtLastSync,\n },\n },\n overrideAccess: true,\n })\n summary.updated += 1\n\n if (rawDoc._status !== 'published') {\n summary.published += 1\n }\n }\n\n return summary\n}\n"],"names":["sha256Hex","isRecord","value","Array","isArray","getRecordId","doc","id","undefined","getRelationshipId","String","isArchived","sync","archived","publishGeneratedDocsForSet","docsCollectionSlug","docsSetId","markdownFieldName","payload","result","find","collection","depth","limit","overrideAccess","where","docsSet","equals","summary","drafts","published","total","updated","rawDoc","docs","content","contentHashAtLastSync","needsContentHashUpdate","_status","update","data"],"mappings":"AAAA,SAASA,SAAS,QAAQ,mBAAkB;AA4B5C,MAAMC,WAAW,CAACC,QAChB,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACC,MAAMC,OAAO,CAACF;AAEhE,MAAMG,cAAc,CAACC;IACnB,IAAI,OAAOA,IAAIC,EAAE,KAAK,YA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pC,UAAUmC;QACxC,MAAME,yBAAyBzB,KAAKwB,qBAAqB,KAAKA;QAE9D,IAAIH,OAAOK,OAAO,KAAK,aAAa;YAClCV,QAAQE,SAAS,IAAI;YAErB,IAAI,CAACO,wBAAwB;gBAC3B;YACF;QACF,OAAO,IAAIJ,OAAOK,OAAO,KAAK,SAAS;YACrCV,QAAQC,MAAM,IAAI;QACpB;QAEA,MAAMtB,KAAKF,YAAY4B;QAEvB,IAAI1B,OAAOC,WAAW;YACpB;QACF;QAEA,MAAMU,QAAQqB,MAAM,CAAC;YACnBhC;YACAc,YAAYN;YACZyB,MAAM;gBACJ,GAAIP,OAAOK,OAAO,KAAK,cAAc,CAAC,IAAI;oBAAEA,SAAS;gBAAY,CAAC;gBAClE1B,MAAM;oBACJ,GAAGA,IAAI;oBACPwB;gBACF;YACF;YACAZ,gBAAgB;QAClB;QACAI,QAAQI,OAAO,IAAI;QAEnB,IAAIC,OAAOK,OAAO,KAAK,aAAa;YAClCV,QAAQE,SAAS,IAAI;QACvB;IACF;IAEA,OAAOF;AACT,EAAC"}
|
package/dist/plugin.js
CHANGED
|
@@ -124,6 +124,7 @@ export const payloadMarkdownDocs = (pluginOptions = {})=>(incomingConfig)=>{
|
|
|
124
124
|
docsCollectionSlug: docsEnabled ? docsCollectionSlug : undefined,
|
|
125
125
|
docsEnableDrafts: enableDrafts,
|
|
126
126
|
docsGroupsCollectionSlug,
|
|
127
|
+
markdownFieldName,
|
|
127
128
|
syncRunsCollectionSlug: syncRunsEnabled ? syncRunsCollectionSlug : undefined
|
|
128
129
|
})
|
|
129
130
|
] : [],
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { Config, Plugin } from 'payload'\n\nimport type { PayloadMarkdownDocsConfig } from './types.js'\n\nimport {\n createDocsCollection,\n createDocsGroupsCollection,\n createDocsKeysCollection,\n createDocsSetsCollection,\n createDocsTrustedCollection,\n createNoncesCollection,\n createSyncRunsCollection,\n} from './collections/index.js'\nimport {\n DEFAULT_DOCS_COLLECTION_SLUG,\n DEFAULT_DOCS_GROUPS_COLLECTION_SLUG,\n DEFAULT_DOCS_KEYS_COLLECTION_SLUG,\n DEFAULT_DOCS_SETS_COLLECTION_SLUG,\n DEFAULT_DOCS_SYNC_ENDPOINT_PATH,\n DEFAULT_DOCS_SYNC_NONCES_COLLECTION_SLUG,\n DEFAULT_DOCS_SYNC_RUNS_COLLECTION_SLUG,\n DEFAULT_DOCS_TRUSTED_COLLECTION_SLUG,\n DEFAULT_MARKDOWN_FIELD_NAME,\n DEFAULT_MAX_BODY_BYTES,\n DEFAULT_MEDIA_COLLECTION_SLUG,\n DEFAULT_PAGES_BRIDGE_FIELD,\n DEFAULT_PAGES_COLLECTION_SLUG,\n DEFAULT_PAGES_ROUTE_FIELD,\n} from './constants.js'\nimport { createSyncEndpoint } from './endpoints/index.js'\n\ntype ResolvedCollectionOptions = {\n docsCollectionSlug: string\n docsEnabled: boolean\n docsGroupsCollectionSlug: string\n docsGroupsEnabled: boolean\n docsKeysCollectionSlug: string\n docsKeysEnabled: boolean\n docsSetsCollectionSlug: string\n docsSetsEnabled: boolean\n docsTrustedCollectionSlug: string\n docsTrustedEnabled: boolean\n enableDrafts: boolean\n heroImageMediaCollectionSlugs?: string[]\n markdownFieldName: string\n noncesCollectionSlug: string\n noncesEnabled: boolean\n syncRunsCollectionSlug: string\n syncRunsEnabled: boolean\n}\n\nconst normalizeEndpointPath = (path: string): string => {\n const normalized = `/${path.trim()}`.replace(/\\/+/g, '/')\n\n return normalized.length > 1 ? normalized.replace(/\\/+$/g, '') : normalized\n}\n\nconst resolveHeroImageMediaCollectionSlugs = (\n pluginOptions: PayloadMarkdownDocsConfig,\n): string[] | undefined => {\n if (pluginOptions.target?.heroImage === false) {\n return undefined\n }\n\n const additionalMediaCollections =\n typeof pluginOptions.target?.heroImage === 'object'\n ? (pluginOptions.target.heroImage.additionalMediaCollections ?? [])\n : []\n\n return [\n ...new Set([\n DEFAULT_MEDIA_COLLECTION_SLUG,\n ...additionalMediaCollections.map((slug) => slug.trim()).filter(Boolean),\n ]),\n ]\n}\n\nconst resolveCollectionOptions = (\n pluginOptions: PayloadMarkdownDocsConfig,\n): ResolvedCollectionOptions => {\n if (pluginOptions.target?.type !== undefined && pluginOptions.target.type !== 'docsCollection') {\n throw new Error(\n 'payloadMarkdownDocs: target.type only supports \"docsCollection\". existingCollection is not supported.',\n )\n }\n\n const docsSlugFromTarget = pluginOptions.target?.slug\n const docsSlugFromCollections = pluginOptions.collections?.docs?.slug\n\n if (\n docsSlugFromTarget &&\n docsSlugFromCollections &&\n docsSlugFromTarget !== docsSlugFromCollections\n ) {\n throw new Error(\n 'payloadMarkdownDocs: target.slug and collections.docs.slug must match when both are provided.',\n )\n }\n\n return {\n docsCollectionSlug:\n docsSlugFromTarget ?? docsSlugFromCollections ?? DEFAULT_DOCS_COLLECTION_SLUG,\n docsEnabled: pluginOptions.collections?.docs?.enabled !== false,\n docsGroupsCollectionSlug:\n pluginOptions.collections?.docsGroups?.slug ?? DEFAULT_DOCS_GROUPS_COLLECTION_SLUG,\n docsGroupsEnabled: pluginOptions.collections?.docsGroups?.enabled !== false,\n docsKeysCollectionSlug:\n pluginOptions.collections?.docsKeys?.slug ?? DEFAULT_DOCS_KEYS_COLLECTION_SLUG,\n docsKeysEnabled: pluginOptions.collections?.docsKeys?.enabled !== false,\n docsSetsCollectionSlug:\n pluginOptions.collections?.docsSets?.slug ?? DEFAULT_DOCS_SETS_COLLECTION_SLUG,\n docsSetsEnabled: pluginOptions.collections?.docsSets?.enabled !== false,\n docsTrustedCollectionSlug:\n pluginOptions.collections?.docsTrusted?.slug ?? DEFAULT_DOCS_TRUSTED_COLLECTION_SLUG,\n docsTrustedEnabled: pluginOptions.collections?.docsTrusted?.enabled !== false,\n enableDrafts: pluginOptions.target?.enableDrafts === true,\n heroImageMediaCollectionSlugs: resolveHeroImageMediaCollectionSlugs(pluginOptions),\n markdownFieldName: pluginOptions.target?.markdownField ?? DEFAULT_MARKDOWN_FIELD_NAME,\n noncesCollectionSlug:\n pluginOptions.collections?.nonces?.slug ?? DEFAULT_DOCS_SYNC_NONCES_COLLECTION_SLUG,\n noncesEnabled: pluginOptions.collections?.nonces?.enabled !== false,\n syncRunsCollectionSlug:\n pluginOptions.collections?.syncRuns?.slug ?? DEFAULT_DOCS_SYNC_RUNS_COLLECTION_SLUG,\n syncRunsEnabled: pluginOptions.collections?.syncRuns?.enabled !== false,\n }\n}\n\nconst assertCollectionOptionCompatibility = ({\n docsGroupsEnabled,\n docsSetsEnabled,\n}: ResolvedCollectionOptions) => {\n if (docsSetsEnabled && !docsGroupsEnabled) {\n throw new Error(\n 'payloadMarkdownDocs: collections.docsSets requires collections.docsGroups to be enabled.',\n )\n }\n}\n\nconst assertNoCollectionSlugConflicts = (\n incomingConfig: Config,\n collectionSlugsToAdd: string[],\n) => {\n const duplicateRequestedSlug = collectionSlugsToAdd.find(\n (slug, index) => collectionSlugsToAdd.indexOf(slug) !== index,\n )\n\n if (duplicateRequestedSlug) {\n throw new Error(\n `payloadMarkdownDocs: collection slug \"${duplicateRequestedSlug}\" is configured more than once.`,\n )\n }\n\n const existingCollectionSlugs = new Set(\n incomingConfig.collections?.map((collection) => collection.slug) ?? [],\n )\n\n const conflictingSlug = collectionSlugsToAdd.find((slug) => existingCollectionSlugs.has(slug))\n\n if (conflictingSlug) {\n throw new Error(\n `payloadMarkdownDocs: collection slug \"${conflictingSlug}\" already exists in the Payload config.`,\n )\n }\n}\n\nexport const payloadMarkdownDocs =\n (pluginOptions: PayloadMarkdownDocsConfig = {}): Plugin =>\n (incomingConfig: Config): Config => {\n if (pluginOptions.enabled === false) {\n return incomingConfig\n }\n\n const {\n docsCollectionSlug,\n docsEnabled,\n docsGroupsCollectionSlug,\n docsGroupsEnabled,\n docsKeysCollectionSlug,\n docsKeysEnabled,\n docsSetsCollectionSlug,\n docsSetsEnabled,\n docsTrustedCollectionSlug,\n docsTrustedEnabled,\n enableDrafts,\n heroImageMediaCollectionSlugs,\n markdownFieldName,\n noncesCollectionSlug,\n noncesEnabled,\n syncRunsCollectionSlug,\n syncRunsEnabled,\n } = resolveCollectionOptions(pluginOptions)\n assertCollectionOptionCompatibility({\n docsCollectionSlug,\n docsEnabled,\n docsGroupsCollectionSlug,\n docsGroupsEnabled,\n docsKeysCollectionSlug,\n docsKeysEnabled,\n docsSetsCollectionSlug,\n docsSetsEnabled,\n docsTrustedCollectionSlug,\n docsTrustedEnabled,\n enableDrafts,\n heroImageMediaCollectionSlugs,\n markdownFieldName,\n noncesCollectionSlug,\n noncesEnabled,\n syncRunsCollectionSlug,\n syncRunsEnabled,\n })\n const endpointPath = normalizeEndpointPath(\n pluginOptions.endpoint?.path ?? DEFAULT_DOCS_SYNC_ENDPOINT_PATH,\n )\n\n const collectionSlugsToAdd = [\n ...(docsGroupsEnabled ? [docsGroupsCollectionSlug] : []),\n ...(docsSetsEnabled ? [docsSetsCollectionSlug] : []),\n ...(docsKeysEnabled ? [docsKeysCollectionSlug] : []),\n ...(docsTrustedEnabled ? [docsTrustedCollectionSlug] : []),\n ...(docsEnabled ? [docsCollectionSlug] : []),\n ...(syncRunsEnabled ? [syncRunsCollectionSlug] : []),\n ...(noncesEnabled ? [noncesCollectionSlug] : []),\n ]\n\n assertNoCollectionSlugConflicts(incomingConfig, collectionSlugsToAdd)\n\n const addedCollections = [\n ...(docsGroupsEnabled\n ? [\n createDocsGroupsCollection({\n slug: docsGroupsCollectionSlug,\n }),\n ]\n : []),\n ...(docsSetsEnabled\n ? [\n createDocsSetsCollection({\n slug: docsSetsCollectionSlug,\n allowPublish: pluginOptions.sync?.allowPublish === true,\n docsCollectionSlug: docsEnabled ? docsCollectionSlug : undefined,\n docsEnableDrafts: enableDrafts,\n docsGroupsCollectionSlug,\n syncRunsCollectionSlug: syncRunsEnabled ? syncRunsCollectionSlug : undefined,\n }),\n ]\n : []),\n ...(docsKeysEnabled\n ? [\n createDocsKeysCollection({\n slug: docsKeysCollectionSlug,\n }),\n ]\n : []),\n ...(docsTrustedEnabled\n ? [\n createDocsTrustedCollection({\n slug: docsTrustedCollectionSlug,\n }),\n ]\n : []),\n ...(docsEnabled\n ? [\n createDocsCollection({\n slug: docsCollectionSlug,\n docsSetsCollectionSlug: docsSetsEnabled ? docsSetsCollectionSlug : undefined,\n enableDrafts,\n heroImageMediaCollectionSlugs,\n markdownFieldName,\n syncRunsCollectionSlug: syncRunsEnabled ? syncRunsCollectionSlug : undefined,\n }),\n ]\n : []),\n ...(syncRunsEnabled\n ? [\n createSyncRunsCollection({\n slug: syncRunsCollectionSlug,\n }),\n ]\n : []),\n ...(noncesEnabled\n ? [\n createNoncesCollection({\n slug: noncesCollectionSlug,\n syncRunsCollectionSlug: syncRunsEnabled ? syncRunsCollectionSlug : undefined,\n }),\n ]\n : []),\n ]\n\n return {\n ...incomingConfig,\n collections: [...(incomingConfig.collections ?? []), ...addedCollections],\n endpoints: [\n ...(incomingConfig.endpoints ?? []),\n createSyncEndpoint({\n allowHardDelete: pluginOptions.sync?.allowHardDelete,\n allowPublish: pluginOptions.sync?.allowPublish,\n allowWrites: pluginOptions.sync?.allowWrites,\n auth: pluginOptions.auth,\n defaultPublishMode: pluginOptions.sync?.defaultPublishMode,\n deleteBehavior: pluginOptions.sync?.deleteBehavior,\n docsCollectionSlug,\n docsEnabled,\n docsEnableDrafts: enableDrafts,\n docsGroupsCollectionSlug,\n docsKeysCollectionSlug,\n docsKeysEnabled,\n docsSetsCollectionSlug,\n docsSetsEnabled,\n docsTrustedCollectionSlug,\n docsTrustedEnabled,\n endpointPath,\n markdownFieldName,\n maxBodyBytes: pluginOptions.endpoint?.maxBodyBytes ?? DEFAULT_MAX_BODY_BYTES,\n noncesCollectionSlug,\n noncesEnabled,\n requireDryRunBeforeApply: pluginOptions.sync?.requireDryRunBeforeApply,\n routing: {\n pages: {\n allowBridgePages: pluginOptions.routing?.pages?.allowBridgePages ?? true,\n bridgeField: pluginOptions.routing?.pages?.bridgeField ?? DEFAULT_PAGES_BRIDGE_FIELD,\n collection: pluginOptions.routing?.pages?.collection ?? DEFAULT_PAGES_COLLECTION_SLUG,\n enabled: pluginOptions.routing?.pages?.enabled === true,\n routeField: pluginOptions.routing?.pages?.routeField ?? DEFAULT_PAGES_ROUTE_FIELD,\n },\n },\n syncRunsCollectionSlug,\n syncRunsEnabled,\n }),\n ],\n }\n }\n"],"names":["createDocsCollection","createDocsGroupsCollection","createDocsKeysCollection","createDocsSetsCollection","createDocsTrustedCollection","createNoncesCollection","createSyncRunsCollection","DEFAULT_DOCS_COLLECTION_SLUG","DEFAULT_DOCS_GROUPS_COLLECTION_SLUG","DEFAULT_DOCS_KEYS_COLLECTION_SLUG","DEFAULT_DOCS_SETS_COLLECTION_SLUG","DEFAULT_DOCS_SYNC_ENDPOINT_PATH","DEFAULT_DOCS_SYNC_NONCES_COLLECTION_SLUG","DEFAULT_DOCS_SYNC_RUNS_COLLECTION_SLUG","DEFAULT_DOCS_TRUSTED_COLLECTION_SLUG","DEFAULT_MARKDOWN_FIELD_NAME","DEFAULT_MAX_BODY_BYTES","DEFAULT_MEDIA_COLLECTION_SLUG","DEFAULT_PAGES_BRIDGE_FIELD","DEFAULT_PAGES_COLLECTION_SLUG","DEFAULT_PAGES_ROUTE_FIELD","createSyncEndpoint","normalizeEndpointPath","path","normalized","trim","replace","length","resolveHeroImageMediaCollectionSlugs","pluginOptions","target","heroImage","undefined","additionalMediaCollections","Set","map","slug","filter","Boolean","resolveCollectionOptions","type","Error","docsSlugFromTarget","docsSlugFromCollections","collections","docs","docsCollectionSlug","docsEnabled","enabled","docsGroupsCollectionSlug","docsGroups","docsGroupsEnabled","docsKeysCollectionSlug","docsKeys","docsKeysEnabled","docsSetsCollectionSlug","docsSets","docsSetsEnabled","docsTrustedCollectionSlug","docsTrusted","docsTrustedEnabled","enableDrafts","heroImageMediaCollectionSlugs","markdownFieldName","markdownField","noncesCollectionSlug","nonces","noncesEnabled","syncRunsCollectionSlug","syncRuns","syncRunsEnabled","assertCollectionOptionCompatibility","assertNoCollectionSlugConflicts","incomingConfig","collectionSlugsToAdd","duplicateRequestedSlug","find","index","indexOf","existingCollectionSlugs","collection","conflictingSlug","has","payloadMarkdownDocs","endpointPath","endpoint","addedCollections","allowPublish","sync","docsEnableDrafts","endpoints","allowHardDelete","allowWrites","auth","defaultPublishMode","deleteBehavior","maxBodyBytes","requireDryRunBeforeApply","routing","pages","allowBridgePages","bridgeField","routeField"],"mappings":"AAIA,SACEA,oBAAoB,EACpBC,0BAA0B,EAC1BC,wBAAwB,EACxBC,wBAAwB,EACxBC,2BAA2B,EAC3BC,sBAAsB,EACtBC,wBAAwB,QACnB,yBAAwB;AAC/B,SACEC,4BAA4B,EAC5BC,mCAAmC,EACnCC,iCAAiC,EACjCC,iCAAiC,EACjCC,+BAA+B,EAC/BC,wCAAwC,EACxCC,sCAAsC,EACtCC,oCAAoC,EACpCC,2BAA2B,EAC3BC,sBAAsB,EACtBC,6BAA6B,EAC7BC,0BAA0B,EAC1BC,6BAA6B,EAC7BC,yBAAyB,QACpB,iBAAgB;AACvB,SAASC,kBAAkB,QAAQ,uBAAsB;AAsBzD,MAAMC,wBAAwB,CAACC;IAC7B,MAAMC,aAAa,CAAC,CAAC,EAAED,KAAKE,IAAI,IAAI,CAACC,OAAO,CAAC,QAAQ;IAErD,OAAOF,WAAWG,MAAM,GAAG,IAAIH,WAAWE,OAAO,CAAC,SAAS,MAAMF;AACnE;AAEA,MAAMI,uCAAuC,CAC3CC;IAEA,IAAIA,cAAcC,MAAM,EAAEC,cAAc,OAAO;QAC7C,OAAOC;IACT;IAEA,MAAMC,6BACJ,OAAOJ,cAAcC,MAAM,EAAEC,cAAc,WACtCF,cAAcC,MAAM,CAACC,SAAS,CAACE,0BAA0B,IAAI,EAAE,GAChE,EAAE;IAER,OAAO;WACF,IAAIC,IAAI;YACTjB;eACGgB,2BAA2BE,GAAG,CAAC,CAACC,OAASA,KAAKX,IA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a;mBAAK6B,eAAe7B,WAAW,IAAI,EAAE;mBAAM0C;aAAiB;YACzEI,WAAW;mBACLjB,eAAeiB,SAAS,IAAI,EAAE;gBAClCrE,mBAAmB;oBACjBsE,iBAAiB9D,cAAc2D,IAAI,EAAEG;oBACrCJ,cAAc1D,cAAc2D,IAAI,EAAED;oBAClCK,aAAa/D,cAAc2D,IAAI,EAAEI;oBACjCC,MAAMhE,cAAcgE,IAAI;oBACxBC,oBAAoBjE,cAAc2D,IAAI,EAAEM;oBACxCC,gBAAgBlE,cAAc2D,IAAI,EAAEO;oBACpCjD;oBACAC;oBACA0C,kBAAkB5B;oBAClBZ;oBACAG;oBACAE;oBACAC;oBACAE;oBACAC;oBACAE;oBACAwB;oBACArB;oBACAiC,cAAcnE,cAAcwD,QAAQ,EAAEW,gBAAgBhF;oBACtDiD;oBACAE;oBACA8B,0BAA0BpE,cAAc2D,IAAI,EAAES;oBAC9CC,SAAS;wBACPC,OAAO;4BACLC,kBAAkBvE,cAAcqE,OAAO,EAAEC,OAAOC,oBAAoB;4BACpEC,aAAaxE,cAAcqE,OAAO,EAAEC,OAAOE,eAAenF;4BAC1D8D,YAAYnD,cAAcqE,OAAO,EAAEC,OAAOnB,cAAc7D;4BACxD6B,SAASnB,cAAcqE,OAAO,EAAEC,OAAOnD,YAAY;4BACnDsD,YAAYzE,cAAcqE,OAAO,EAAEC,OAAOG,cAAclF;wBAC1D;oBACF;oBACAgD;oBACAE;gBACF;aACD;QACH;IACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { Config, Plugin } from 'payload'\n\nimport type { PayloadMarkdownDocsConfig } from './types.js'\n\nimport {\n createDocsCollection,\n createDocsGroupsCollection,\n createDocsKeysCollection,\n createDocsSetsCollection,\n createDocsTrustedCollection,\n createNoncesCollection,\n createSyncRunsCollection,\n} from './collections/index.js'\nimport {\n DEFAULT_DOCS_COLLECTION_SLUG,\n DEFAULT_DOCS_GROUPS_COLLECTION_SLUG,\n DEFAULT_DOCS_KEYS_COLLECTION_SLUG,\n DEFAULT_DOCS_SETS_COLLECTION_SLUG,\n DEFAULT_DOCS_SYNC_ENDPOINT_PATH,\n DEFAULT_DOCS_SYNC_NONCES_COLLECTION_SLUG,\n DEFAULT_DOCS_SYNC_RUNS_COLLECTION_SLUG,\n DEFAULT_DOCS_TRUSTED_COLLECTION_SLUG,\n DEFAULT_MARKDOWN_FIELD_NAME,\n DEFAULT_MAX_BODY_BYTES,\n DEFAULT_MEDIA_COLLECTION_SLUG,\n DEFAULT_PAGES_BRIDGE_FIELD,\n DEFAULT_PAGES_COLLECTION_SLUG,\n DEFAULT_PAGES_ROUTE_FIELD,\n} from './constants.js'\nimport { createSyncEndpoint } from './endpoints/index.js'\n\ntype ResolvedCollectionOptions = {\n docsCollectionSlug: string\n docsEnabled: boolean\n docsGroupsCollectionSlug: string\n docsGroupsEnabled: boolean\n docsKeysCollectionSlug: string\n docsKeysEnabled: boolean\n docsSetsCollectionSlug: string\n docsSetsEnabled: boolean\n docsTrustedCollectionSlug: string\n docsTrustedEnabled: boolean\n enableDrafts: boolean\n heroImageMediaCollectionSlugs?: string[]\n markdownFieldName: string\n noncesCollectionSlug: string\n noncesEnabled: boolean\n syncRunsCollectionSlug: string\n syncRunsEnabled: boolean\n}\n\nconst normalizeEndpointPath = (path: string): string => {\n const normalized = `/${path.trim()}`.replace(/\\/+/g, '/')\n\n return normalized.length > 1 ? normalized.replace(/\\/+$/g, '') : normalized\n}\n\nconst resolveHeroImageMediaCollectionSlugs = (\n pluginOptions: PayloadMarkdownDocsConfig,\n): string[] | undefined => {\n if (pluginOptions.target?.heroImage === false) {\n return undefined\n }\n\n const additionalMediaCollections =\n typeof pluginOptions.target?.heroImage === 'object'\n ? (pluginOptions.target.heroImage.additionalMediaCollections ?? [])\n : []\n\n return [\n ...new Set([\n DEFAULT_MEDIA_COLLECTION_SLUG,\n ...additionalMediaCollections.map((slug) => slug.trim()).filter(Boolean),\n ]),\n ]\n}\n\nconst resolveCollectionOptions = (\n pluginOptions: PayloadMarkdownDocsConfig,\n): ResolvedCollectionOptions => {\n if (pluginOptions.target?.type !== undefined && pluginOptions.target.type !== 'docsCollection') {\n throw new Error(\n 'payloadMarkdownDocs: target.type only supports \"docsCollection\". existingCollection is not supported.',\n )\n }\n\n const docsSlugFromTarget = pluginOptions.target?.slug\n const docsSlugFromCollections = pluginOptions.collections?.docs?.slug\n\n if (\n docsSlugFromTarget &&\n docsSlugFromCollections &&\n docsSlugFromTarget !== docsSlugFromCollections\n ) {\n throw new Error(\n 'payloadMarkdownDocs: target.slug and collections.docs.slug must match when both are provided.',\n )\n }\n\n return {\n docsCollectionSlug:\n docsSlugFromTarget ?? docsSlugFromCollections ?? DEFAULT_DOCS_COLLECTION_SLUG,\n docsEnabled: pluginOptions.collections?.docs?.enabled !== false,\n docsGroupsCollectionSlug:\n pluginOptions.collections?.docsGroups?.slug ?? DEFAULT_DOCS_GROUPS_COLLECTION_SLUG,\n docsGroupsEnabled: pluginOptions.collections?.docsGroups?.enabled !== false,\n docsKeysCollectionSlug:\n pluginOptions.collections?.docsKeys?.slug ?? DEFAULT_DOCS_KEYS_COLLECTION_SLUG,\n docsKeysEnabled: pluginOptions.collections?.docsKeys?.enabled !== false,\n docsSetsCollectionSlug:\n pluginOptions.collections?.docsSets?.slug ?? DEFAULT_DOCS_SETS_COLLECTION_SLUG,\n docsSetsEnabled: pluginOptions.collections?.docsSets?.enabled !== false,\n docsTrustedCollectionSlug:\n pluginOptions.collections?.docsTrusted?.slug ?? DEFAULT_DOCS_TRUSTED_COLLECTION_SLUG,\n docsTrustedEnabled: pluginOptions.collections?.docsTrusted?.enabled !== false,\n enableDrafts: pluginOptions.target?.enableDrafts === true,\n heroImageMediaCollectionSlugs: resolveHeroImageMediaCollectionSlugs(pluginOptions),\n markdownFieldName: pluginOptions.target?.markdownField ?? DEFAULT_MARKDOWN_FIELD_NAME,\n noncesCollectionSlug:\n pluginOptions.collections?.nonces?.slug ?? DEFAULT_DOCS_SYNC_NONCES_COLLECTION_SLUG,\n noncesEnabled: pluginOptions.collections?.nonces?.enabled !== false,\n syncRunsCollectionSlug:\n pluginOptions.collections?.syncRuns?.slug ?? DEFAULT_DOCS_SYNC_RUNS_COLLECTION_SLUG,\n syncRunsEnabled: pluginOptions.collections?.syncRuns?.enabled !== false,\n }\n}\n\nconst assertCollectionOptionCompatibility = ({\n docsGroupsEnabled,\n docsSetsEnabled,\n}: ResolvedCollectionOptions) => {\n if (docsSetsEnabled && !docsGroupsEnabled) {\n throw new Error(\n 'payloadMarkdownDocs: collections.docsSets requires collections.docsGroups to be enabled.',\n )\n }\n}\n\nconst assertNoCollectionSlugConflicts = (\n incomingConfig: Config,\n collectionSlugsToAdd: string[],\n) => {\n const duplicateRequestedSlug = collectionSlugsToAdd.find(\n (slug, index) => collectionSlugsToAdd.indexOf(slug) !== index,\n )\n\n if (duplicateRequestedSlug) {\n throw new Error(\n `payloadMarkdownDocs: collection slug \"${duplicateRequestedSlug}\" is configured more than once.`,\n )\n }\n\n const existingCollectionSlugs = new Set(\n incomingConfig.collections?.map((collection) => collection.slug) ?? [],\n )\n\n const conflictingSlug = collectionSlugsToAdd.find((slug) => existingCollectionSlugs.has(slug))\n\n if (conflictingSlug) {\n throw new Error(\n `payloadMarkdownDocs: collection slug \"${conflictingSlug}\" already exists in the Payload config.`,\n )\n }\n}\n\nexport const payloadMarkdownDocs =\n (pluginOptions: PayloadMarkdownDocsConfig = {}): Plugin =>\n (incomingConfig: Config): Config => {\n if (pluginOptions.enabled === false) {\n return incomingConfig\n }\n\n const {\n docsCollectionSlug,\n docsEnabled,\n docsGroupsCollectionSlug,\n docsGroupsEnabled,\n docsKeysCollectionSlug,\n docsKeysEnabled,\n docsSetsCollectionSlug,\n docsSetsEnabled,\n docsTrustedCollectionSlug,\n docsTrustedEnabled,\n enableDrafts,\n heroImageMediaCollectionSlugs,\n markdownFieldName,\n noncesCollectionSlug,\n noncesEnabled,\n syncRunsCollectionSlug,\n syncRunsEnabled,\n } = resolveCollectionOptions(pluginOptions)\n assertCollectionOptionCompatibility({\n docsCollectionSlug,\n docsEnabled,\n docsGroupsCollectionSlug,\n docsGroupsEnabled,\n docsKeysCollectionSlug,\n docsKeysEnabled,\n docsSetsCollectionSlug,\n docsSetsEnabled,\n docsTrustedCollectionSlug,\n docsTrustedEnabled,\n enableDrafts,\n heroImageMediaCollectionSlugs,\n markdownFieldName,\n noncesCollectionSlug,\n noncesEnabled,\n syncRunsCollectionSlug,\n syncRunsEnabled,\n })\n const endpointPath = normalizeEndpointPath(\n pluginOptions.endpoint?.path ?? DEFAULT_DOCS_SYNC_ENDPOINT_PATH,\n )\n\n const collectionSlugsToAdd = [\n ...(docsGroupsEnabled ? [docsGroupsCollectionSlug] : []),\n ...(docsSetsEnabled ? [docsSetsCollectionSlug] : []),\n ...(docsKeysEnabled ? [docsKeysCollectionSlug] : []),\n ...(docsTrustedEnabled ? [docsTrustedCollectionSlug] : []),\n ...(docsEnabled ? [docsCollectionSlug] : []),\n ...(syncRunsEnabled ? [syncRunsCollectionSlug] : []),\n ...(noncesEnabled ? [noncesCollectionSlug] : []),\n ]\n\n assertNoCollectionSlugConflicts(incomingConfig, collectionSlugsToAdd)\n\n const addedCollections = [\n ...(docsGroupsEnabled\n ? [\n createDocsGroupsCollection({\n slug: docsGroupsCollectionSlug,\n }),\n ]\n : []),\n ...(docsSetsEnabled\n ? [\n createDocsSetsCollection({\n slug: docsSetsCollectionSlug,\n allowPublish: pluginOptions.sync?.allowPublish === true,\n docsCollectionSlug: docsEnabled ? docsCollectionSlug : undefined,\n docsEnableDrafts: enableDrafts,\n docsGroupsCollectionSlug,\n markdownFieldName,\n syncRunsCollectionSlug: syncRunsEnabled ? syncRunsCollectionSlug : undefined,\n }),\n ]\n : []),\n ...(docsKeysEnabled\n ? [\n createDocsKeysCollection({\n slug: docsKeysCollectionSlug,\n }),\n ]\n : []),\n ...(docsTrustedEnabled\n ? [\n createDocsTrustedCollection({\n slug: docsTrustedCollectionSlug,\n }),\n ]\n : []),\n ...(docsEnabled\n ? [\n createDocsCollection({\n slug: docsCollectionSlug,\n docsSetsCollectionSlug: docsSetsEnabled ? docsSetsCollectionSlug : undefined,\n enableDrafts,\n heroImageMediaCollectionSlugs,\n markdownFieldName,\n syncRunsCollectionSlug: syncRunsEnabled ? syncRunsCollectionSlug : undefined,\n }),\n ]\n : []),\n ...(syncRunsEnabled\n ? [\n createSyncRunsCollection({\n slug: syncRunsCollectionSlug,\n }),\n ]\n : []),\n ...(noncesEnabled\n ? [\n createNoncesCollection({\n slug: noncesCollectionSlug,\n syncRunsCollectionSlug: syncRunsEnabled ? syncRunsCollectionSlug : undefined,\n }),\n ]\n : []),\n ]\n\n return {\n ...incomingConfig,\n collections: [...(incomingConfig.collections ?? []), ...addedCollections],\n endpoints: [\n ...(incomingConfig.endpoints ?? []),\n createSyncEndpoint({\n allowHardDelete: pluginOptions.sync?.allowHardDelete,\n allowPublish: pluginOptions.sync?.allowPublish,\n allowWrites: pluginOptions.sync?.allowWrites,\n auth: pluginOptions.auth,\n defaultPublishMode: pluginOptions.sync?.defaultPublishMode,\n deleteBehavior: pluginOptions.sync?.deleteBehavior,\n docsCollectionSlug,\n docsEnabled,\n docsEnableDrafts: enableDrafts,\n docsGroupsCollectionSlug,\n docsKeysCollectionSlug,\n docsKeysEnabled,\n docsSetsCollectionSlug,\n docsSetsEnabled,\n docsTrustedCollectionSlug,\n docsTrustedEnabled,\n endpointPath,\n markdownFieldName,\n maxBodyBytes: pluginOptions.endpoint?.maxBodyBytes ?? DEFAULT_MAX_BODY_BYTES,\n noncesCollectionSlug,\n noncesEnabled,\n requireDryRunBeforeApply: pluginOptions.sync?.requireDryRunBeforeApply,\n routing: {\n pages: {\n allowBridgePages: pluginOptions.routing?.pages?.allowBridgePages ?? true,\n bridgeField: pluginOptions.routing?.pages?.bridgeField ?? DEFAULT_PAGES_BRIDGE_FIELD,\n collection: pluginOptions.routing?.pages?.collection ?? DEFAULT_PAGES_COLLECTION_SLUG,\n enabled: pluginOptions.routing?.pages?.enabled === true,\n routeField: pluginOptions.routing?.pages?.routeField ?? DEFAULT_PAGES_ROUTE_FIELD,\n },\n },\n syncRunsCollectionSlug,\n syncRunsEnabled,\n }),\n ],\n }\n }\n"],"names":["createDocsCollection","createDocsGroupsCollection","createDocsKeysCollection","createDocsSetsCollection","createDocsTrustedCollection","createNoncesCollection","createSyncRunsCollection","DEFAULT_DOCS_COLLECTION_SLUG","DEFAULT_DOCS_GROUPS_COLLECTION_SLUG","DEFAULT_DOCS_KEYS_COLLECTION_SLUG","DEFAULT_DOCS_SETS_COLLECTION_SLUG","DEFAULT_DOCS_SYNC_ENDPOINT_PATH","DEFAULT_DOCS_SYNC_NONCES_COLLECTION_SLUG","DEFAULT_DOCS_SYNC_RUNS_COLLECTION_SLUG","DEFAULT_DOCS_TRUSTED_COLLECTION_SLUG","DEFAULT_MARKDOWN_FIELD_NAME","DEFAULT_MAX_BODY_BYTES","DEFAULT_MEDIA_COLLECTION_SLUG","DEFAULT_PAGES_BRIDGE_FIELD","DEFAULT_PAGES_COLLECTION_SLUG","DEFAULT_PAGES_ROUTE_FIELD","createSyncEndpoint","normalizeEndpointPath","path","normalized","trim","replace","length","resolveHeroImageMediaCollectionSlugs","pluginOptions","target","heroImage","undefined","additionalMediaCollections","Set","map","slug","filter","Boolean","resolveCollectionOptions","type","Error","docsSlugFromTarget","docsSlugFromCollections","collections","docs","docsCollectionSlug","docsEnabled","enabled","docsGroupsCollectionSlug","docsGroups","docsGroupsEnabled","docsKeysCollectionSlug","docsKeys","docsKeysEnabled","docsSetsCollectionSlug","docsSets","docsSetsEnabled","docsTrustedCollectionSlug","docsTrusted","docsTrustedEnabled","enableDrafts","heroImageMediaCollectionSlugs","markdownFieldName","markdownField","noncesCollectionSlug","nonces","noncesEnabled","syncRunsCollectionSlug","syncRuns","syncRunsEnabled","assertCollectionOptionCompatibility","assertNoCollectionSlugConflicts","incomingConfig","collectionSlugsToAdd","duplicateRequestedSlug","find","index","indexOf","existingCollectionSlugs","collection","conflictingSlug","has","payloadMarkdownDocs","endpointPath","endpoint","addedCollections","allowPublish","sync","docsEnableDrafts","endpoints","allowHardDelete","allowWrites","auth","defaultPublishMode","deleteBehavior","maxBodyBytes","requireDryRunBeforeApply","routing","pages","allowBridgePages","bridgeField","routeField"],"mappings":"AAIA,SACEA,oBAAoB,EACpBC,0BAA0B,EAC1BC,wBAAwB,EACxBC,wBAAwB,EACxBC,2BAA2B,EAC3BC,sBAAsB,EACtBC,wBAAwB,QACnB,yBAAwB;AAC/B,SACEC,4BAA4B,EAC5BC,mCAAmC,EACnCC,iCAAiC,EACjCC,iCAAiC,EACjCC,+BAA+B,EAC/BC,wCAAwC,EACxCC,sCAAsC,EACtCC,oCAAoC,EACpCC,2BAA2B,EAC3BC,sBAAsB,EACtBC,6BAA6B,EAC7BC,0BAA0B,EAC1BC,6BAA6B,EAC7BC,yBAAyB,QACpB,iBAAgB;AACvB,SAASC,kBAAkB,QAAQ,uBAAsB;AAsBzD,MAAMC,wBAAwB,CAACC;IAC7B,MAAMC,aAAa,CAAC,CAAC,EAAED,KAAKE,IAAI,IAAI,CAACC,OAAO,CAAC,QAAQ;IAErD,OAAOF,WAAWG,MAAM,GAAG,IAAIH,WAAWE,OAAO,CAAC,SAAS,MAAMF;AACnE;AAEA,MAAMI,uCAAuC,CAC3CC;IAEA,IAAIA,cAAcC,MAAM,EAAEC,cAAc,OAAO;QAC7C,OAAOC;IACT;IAEA,MAAMC,6BACJ,OAAOJ,cAAcC,MAAM,EAAEC,cAAc,WACtCF,cAAcC,MAAM,CAACC,SAAS,CAACE,0BAA0B,IAAI,EAAE,GAChE,EAAE;IAER,OAAO;WACF,IAAIC,IAAI;YACTjB;eACGgB,2BAA2BE,GAAG,CAAC,CAACC,OAASA,KAAKX,IAAI,IAAIY,MAAM,CAACC;SACjE;KACF;AACH;AAEA,MAAMC,2BAA2B,CAC/BV;IAEA,IAAIA,cAAcC,MAAM,E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