@valkyrianlabs/payload-markdown-docs 0.5.0 → 0.5.2
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/admin/DocsSetManager.js +7 -40
- package/dist/admin/DocsSetManager.js.map +1 -1
- package/dist/cli/commands/push.js.map +1 -1
- package/dist/cli/format.d.ts +1 -3
- package/dist/cli/format.js +1 -2
- package/dist/cli/format.js.map +1 -1
- package/dist/collections/docs.js +13 -0
- package/dist/collections/docs.js.map +1 -1
- package/dist/collections/docsSets.d.ts +1 -4
- package/dist/collections/docsSets.js +17 -11
- package/dist/collections/docsSets.js.map +1 -1
- package/dist/collections/syncRuns.js +0 -9
- package/dist/collections/syncRuns.js.map +1 -1
- package/dist/endpoints/index.d.ts +0 -2
- package/dist/endpoints/index.js +0 -1
- package/dist/endpoints/index.js.map +1 -1
- package/dist/endpoints/sync.d.ts +0 -2
- package/dist/endpoints/sync.js +8 -15
- package/dist/endpoints/sync.js.map +1 -1
- package/dist/next/links.js +5 -2
- package/dist/next/links.js.map +1 -1
- package/dist/next/markdown.js +18 -6
- package/dist/next/markdown.js.map +1 -1
- package/dist/next/records.d.ts +4 -0
- package/dist/next/records.js +7 -0
- package/dist/next/records.js.map +1 -1
- package/dist/next/route.js +39 -13
- package/dist/next/route.js.map +1 -1
- package/dist/next/sidebar.js +1 -0
- package/dist/next/sidebar.js.map +1 -1
- package/dist/next/types.d.ts +2 -0
- package/dist/next/types.js.map +1 -1
- package/dist/payload/applyDocsSync.d.ts +4 -3
- package/dist/payload/applyDocsSync.js +18 -6
- package/dist/payload/applyDocsSync.js.map +1 -1
- package/dist/payload/docsData.d.ts +2 -5
- package/dist/payload/docsData.js +4 -8
- package/dist/payload/docsData.js.map +1 -1
- package/dist/payload/docsSets.d.ts +6 -2
- package/dist/payload/docsSets.js +5 -2
- package/dist/payload/docsSets.js.map +1 -1
- package/dist/payload/existingDocs.d.ts +5 -2
- package/dist/payload/existingDocs.js +5 -2
- package/dist/payload/existingDocs.js.map +1 -1
- package/dist/payload/index.d.ts +11 -11
- package/dist/payload/index.js.map +1 -1
- package/dist/payload/populatePublishedAt.d.ts +2 -0
- package/dist/payload/populatePublishedAt.js +14 -0
- package/dist/payload/populatePublishedAt.js.map +1 -0
- package/dist/payload/routeCollisions.d.ts +3 -1
- package/dist/payload/routeCollisions.js +2 -1
- package/dist/payload/routeCollisions.js.map +1 -1
- package/dist/payload/syncRuns.d.ts +1 -2
- package/dist/payload/syncRuns.js +1 -2
- package/dist/payload/syncRuns.js.map +1 -1
- package/dist/plugin.js +0 -4
- package/dist/plugin.js.map +1 -1
- package/dist/skills/codex/reference/admin.md +0 -1
- package/dist/sync/plan.d.ts +1 -0
- package/dist/sync/plan.js +4 -2
- package/dist/sync/plan.js.map +1 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/dist/endpoints/publishGeneratedDocs.d.ts +0 -7
- package/dist/endpoints/publishGeneratedDocs.js +0 -77
- package/dist/endpoints/publishGeneratedDocs.js.map +0 -1
- package/dist/payload/publishGeneratedDocs.d.ts +0 -30
- package/dist/payload/publishGeneratedDocs.js +0 -92
- package/dist/payload/publishGeneratedDocs.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/payload/applyDocsSync.ts"],"sourcesContent":["import type {\n DocsDeleteBehavior,\n DocsSyncPlan,\n ValidatedDocsManifest,\n} from '../sync/index.js'\nimport type { DocsSyncConflict } from './docsConflicts.js'\nimport type { DocsPublishMode } from './docsData.js'\nimport type { ExistingPayloadDocsRecord } from './existingDocs.js'\n\nimport { findDocsSyncConflicts } from './docsConflicts.js'\nimport { buildArchiveData, buildDocsData } from './docsData.js'\n\nexport type ApplyDocsSyncPayloadOperations = {\n create: (args: {\n collection: string\n data: Record<string, unknown>\n overrideAccess?: boolean\n }) => Promise<Record<string, unknown>>\n delete?: (args: {\n collection: string\n id: string\n overrideAccess?: boolean\n }) => Promise<Record<string, unknown>>\n update: (args: {\n collection: string\n data: Record<string, unknown>\n id: string\n overrideAccess?: boolean\n }) => Promise<Record<string, unknown>>\n}\n\nexport type ApplyDocsSyncResult =\n | {\n conflicts: DocsSyncConflict[]\n ok: false\n }\n | {\n ok: true\n writes: {\n archive: number\n create: number\n delete: number\n draft: number\n reactivate: number\n update: number\n }\n }\n\nexport const assertApplyDeleteBehaviorSupported = (\n deleteBehavior: DocsDeleteBehavior,\n {\n allowHardDelete = false,\n docsEnableDrafts = false,\n }: {\n allowHardDelete?: boolean\n docsEnableDrafts?: boolean\n } = {},\n): boolean => {\n if (deleteBehavior === 'archive' || deleteBehavior === 'ignore') {\n return true\n }\n\n if (deleteBehavior === 'draft') {\n return docsEnableDrafts\n }\n\n return allowHardDelete\n}\n\nexport const applyDocsSync = async ({\n collectionSlug,\n deleteBehavior,\n docsEnableDrafts,\n docsSetId,\n existing,\n manifest,\n markdownFieldName,\n now,\n payload,\n plan,\n publishMode,\n syncRunId,\n}: {\n collectionSlug: string\n deleteBehavior: DocsDeleteBehavior\n docsEnableDrafts: boolean\n docsSetId?: number | string\n existing: ExistingPayloadDocsRecord[]\n manifest: ValidatedDocsManifest\n markdownFieldName: string\n now: Date\n payload: ApplyDocsSyncPayloadOperations\n plan: DocsSyncPlan\n publishMode: DocsPublishMode\n syncRunId?: number | string\n}): Promise<ApplyDocsSyncResult> => {\n const existingBySourcePath = new Map(\n existing.map((record) => [record.sourcePath, record]),\n )\n const reactivations = plan.unchanged.filter((change) => change.current?.archived)\n const conflicts = findDocsSyncConflicts({\n existingBySourcePath,\n plannedChanges: [\n ...plan.update,\n ...plan.archive,\n ...plan.draft,\n ...plan.delete,\n ...reactivations,\n ],\n })\n\n if (conflicts.length > 0) {\n return {\n conflicts,\n ok: false,\n }\n }\n\n const writes = {\n archive: 0,\n create: 0,\n delete: 0,\n draft: 0,\n reactivate: 0,\n update: 0,\n }\n\n for (const change of plan.create) {\n if (!change.desired) {\n continue\n }\n\n await payload.create({\n collection: collectionSlug,\n data: buildDocsData({\n desired: change.desired,\n docsEnableDrafts,\n docsSetId,\n manifest,\n markdownFieldName,\n now,\n publishMode,\n syncRunId,\n }),\n overrideAccess: true,\n })\n writes.create += 1\n }\n\n for (const change of plan.update) {\n if (!change.desired) {\n continue\n }\n\n const current = existingBySourcePath.get(change.sourcePath)\n\n if (!current) {\n continue\n }\n\n await payload.update({\n id: current.id,\n collection: collectionSlug,\n data: buildDocsData({\n current,\n desired: change.desired,\n docsEnableDrafts,\n docsSetId,\n manifest,\n markdownFieldName,\n now,\n publishMode,\n syncRunId,\n }),\n overrideAccess: true,\n })\n writes.update += 1\n }\n\n for (const change of reactivations) {\n if (!change.desired) {\n continue\n }\n\n const current = existingBySourcePath.get(change.sourcePath)\n\n if (!current) {\n continue\n }\n\n await payload.update({\n id: current.id,\n collection: collectionSlug,\n data: buildDocsData({\n current,\n desired: change.desired,\n docsEnableDrafts,\n docsSetId,\n manifest,\n markdownFieldName,\n now,\n publishMode,\n syncRunId,\n }),\n overrideAccess: true,\n })\n writes.reactivate += 1\n }\n\n if (deleteBehavior === 'archive') {\n for (const change of plan.archive) {\n const current = existingBySourcePath.get(change.sourcePath)\n\n if (!current) {\n continue\n }\n\n await payload.update({\n id: current.id,\n collection: collectionSlug,\n data: buildArchiveData({\n docsEnableDrafts,\n now,\n syncRunId,\n }),\n overrideAccess: true,\n })\n writes.archive += 1\n }\n }\n\n if (deleteBehavior === 'draft') {\n for (const change of plan.draft) {\n const current = existingBySourcePath.get(change.sourcePath)\n\n if (!current) {\n continue\n }\n\n await payload.update({\n id: current.id,\n collection: collectionSlug,\n data: buildArchiveData({\n docsEnableDrafts,\n draftMissing: true,\n now,\n syncRunId,\n }),\n overrideAccess: true,\n })\n writes.draft += 1\n }\n }\n\n if (deleteBehavior === 'delete') {\n if (!payload.delete) {\n throw new Error('Payload delete operation is required for hard delete.')\n }\n\n for (const change of plan.delete) {\n const current = existingBySourcePath.get(change.sourcePath)\n\n if (!current) {\n continue\n }\n\n await payload.delete({\n id: current.id,\n collection: collectionSlug,\n overrideAccess: true,\n })\n writes.delete += 1\n }\n }\n\n return {\n ok: true,\n writes,\n }\n}\n"],"names":["findDocsSyncConflicts","buildArchiveData","buildDocsData","assertApplyDeleteBehaviorSupported","deleteBehavior","allowHardDelete","docsEnableDrafts","applyDocsSync","collectionSlug","docsSetId","existing","manifest","markdownFieldName","now","payload","plan","publishMode","syncRunId","existingBySourcePath","Map","map","record","sourcePath","reactivations","unchanged","filter","change","current","archived","conflicts","plannedChanges","update","archive","draft","delete","length","ok","writes","create","reactivate","desired","collection","data","overrideAccess","get","id","draftMissing","Error"],"mappings":"AASA,SAASA,qBAAqB,QAAQ,qBAAoB;AAC1D,SAASC,gBAAgB,EAAEC,aAAa,QAAQ,gBAAe;AAsC/D,OAAO,MAAMC,qCAAqC,CAChDC,gBACA,EACEC,kBAAkB,KAAK,EACvBC,mBAAmB,KAAK,EAIzB,GAAG,CAAC,CAAC;IAEN,IAAIF,mBAAmB,aAAaA,mBAAmB,UAAU;QAC/D,OAAO;IACT;IAEA,IAAIA,mBAAmB,SAAS;QAC9B,OAAOE;IACT;IAEA,OAAOD;AACT,EAAC;AAED,OAAO,MAAME,gBAAgB,OAAO,EAClCC,cAAc,EACdJ,cAAc,EACdE,gBAAgB,EAChBG,SAAS,EACTC,QAAQ,EACRC,QAAQ,EACRC,iBAAiB,EACjBC,GAAG,EACHC,OAAO,EACPC,IAAI,EACJC,WAAW,EACXC,SAAS,EAcV;IACC,MAAMC,uBAAuB,IAAIC,IAC/BT,SAASU,GAAG,CAAC,CAACC,SAAW;YAACA,OAAOC,UAAU;YAAED;SAAO;IAEtD,MAAME,gBAAgBR,KAAKS,SAAS,CAACC,MAAM,CAAC,CAACC,SAAWA,OAAOC,OAAO,EAAEC;IACxE,MAAMC,YAAY7B,sBAAsB;QACtCkB;QACAY,gBAAgB;eACXf,KAAKgB,MAAM;eACXhB,KAAKiB,OAAO;eACZjB,KAAKkB,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jC;gBACZmC,gBAAgB;YAClB;YACAN,OAAOH,MAAM,IAAI;QACnB;IACF;IAEA,OAAO;QACLE,IAAI;QACJC;IACF;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/payload/applyDocsSync.ts"],"sourcesContent":["import type { DocsDeleteBehavior, DocsSyncPlan, ValidatedDocsManifest } from '../sync/index.js'\nimport type { DocsSyncConflict } from './docsConflicts.js'\nimport type { ExistingPayloadDocsRecord } from './existingDocs.js'\n\nimport { findDocsSyncConflicts } from './docsConflicts.js'\nimport { buildArchiveData, buildDocsData } from './docsData.js'\n\nexport type ApplyDocsSyncPayloadOperations = {\n create: (args: {\n collection: string\n data: Record<string, unknown>\n draft?: boolean\n overrideAccess?: boolean\n }) => Promise<Record<string, unknown>>\n delete?: (args: {\n collection: string\n id: string\n overrideAccess?: boolean\n }) => Promise<Record<string, unknown>>\n update: (args: {\n collection: string\n data: Record<string, unknown>\n draft?: boolean\n id: string\n overrideAccess?: boolean\n }) => Promise<Record<string, unknown>>\n}\n\nexport type ApplyDocsSyncResult =\n | {\n conflicts: DocsSyncConflict[]\n ok: false\n }\n | {\n ok: true\n writes: {\n archive: number\n create: number\n delete: number\n draft: number\n reactivate: number\n update: number\n }\n }\n\nexport const assertApplyDeleteBehaviorSupported = (\n deleteBehavior: DocsDeleteBehavior,\n {\n allowHardDelete = false,\n docsEnableDrafts = false,\n }: {\n allowHardDelete?: boolean\n docsEnableDrafts?: boolean\n } = {},\n): boolean => {\n if (deleteBehavior === 'archive' || deleteBehavior === 'ignore') {\n return true\n }\n\n if (deleteBehavior === 'draft') {\n return docsEnableDrafts\n }\n\n return allowHardDelete\n}\n\nconst getDocsWriteDraftOption = ({\n docsEnableDrafts,\n publish,\n}: {\n docsEnableDrafts: boolean\n publish: boolean\n}): { draft?: boolean } => (docsEnableDrafts ? { draft: !publish } : {})\n\nexport const applyDocsSync = async ({\n collectionSlug,\n deleteBehavior,\n docsEnableDrafts,\n docsSetId,\n existing,\n manifest,\n markdownFieldName,\n now,\n payload,\n plan,\n publish,\n syncRunId,\n}: {\n collectionSlug: string\n deleteBehavior: DocsDeleteBehavior\n docsEnableDrafts: boolean\n docsSetId?: number | string\n existing: ExistingPayloadDocsRecord[]\n manifest: ValidatedDocsManifest\n markdownFieldName: string\n now: Date\n payload: ApplyDocsSyncPayloadOperations\n plan: DocsSyncPlan\n publish: boolean\n syncRunId?: number | string\n}): Promise<ApplyDocsSyncResult> => {\n const existingBySourcePath = new Map(existing.map((record) => [record.sourcePath, record]))\n const reactivations = plan.unchanged.filter((change) => change.current?.archived)\n const conflicts = findDocsSyncConflicts({\n existingBySourcePath,\n plannedChanges: [\n ...plan.update,\n ...plan.archive,\n ...plan.draft,\n ...plan.delete,\n ...reactivations,\n ],\n })\n\n if (conflicts.length > 0) {\n return {\n conflicts,\n ok: false,\n }\n }\n\n const writes = {\n archive: 0,\n create: 0,\n delete: 0,\n draft: 0,\n reactivate: 0,\n update: 0,\n }\n const writeDraftOption = getDocsWriteDraftOption({\n docsEnableDrafts,\n publish,\n })\n\n for (const change of plan.create) {\n if (!change.desired) {\n continue\n }\n\n await payload.create({\n collection: collectionSlug,\n data: buildDocsData({\n desired: change.desired,\n docsEnableDrafts,\n docsSetId,\n manifest,\n markdownFieldName,\n now,\n publish,\n syncRunId,\n }),\n ...writeDraftOption,\n overrideAccess: true,\n })\n writes.create += 1\n }\n\n for (const change of plan.update) {\n if (!change.desired) {\n continue\n }\n\n const current = existingBySourcePath.get(change.sourcePath)\n\n if (!current) {\n continue\n }\n\n await payload.update({\n id: current.id,\n collection: collectionSlug,\n data: buildDocsData({\n desired: change.desired,\n docsEnableDrafts,\n docsSetId,\n manifest,\n markdownFieldName,\n now,\n publish,\n syncRunId,\n }),\n ...writeDraftOption,\n overrideAccess: true,\n })\n writes.update += 1\n }\n\n for (const change of reactivations) {\n if (!change.desired) {\n continue\n }\n\n const current = existingBySourcePath.get(change.sourcePath)\n\n if (!current) {\n continue\n }\n\n await payload.update({\n id: current.id,\n collection: collectionSlug,\n data: buildDocsData({\n desired: change.desired,\n docsEnableDrafts,\n docsSetId,\n manifest,\n markdownFieldName,\n now,\n publish,\n syncRunId,\n }),\n ...writeDraftOption,\n overrideAccess: true,\n })\n writes.reactivate += 1\n }\n\n if (deleteBehavior === 'archive') {\n for (const change of plan.archive) {\n const current = existingBySourcePath.get(change.sourcePath)\n\n if (!current) {\n continue\n }\n\n await payload.update({\n id: current.id,\n collection: collectionSlug,\n data: buildArchiveData({\n docsEnableDrafts,\n now,\n syncRunId,\n }),\n ...writeDraftOption,\n overrideAccess: true,\n })\n writes.archive += 1\n }\n }\n\n if (deleteBehavior === 'draft') {\n for (const change of plan.draft) {\n const current = existingBySourcePath.get(change.sourcePath)\n\n if (!current) {\n continue\n }\n\n await payload.update({\n id: current.id,\n collection: collectionSlug,\n data: buildArchiveData({\n docsEnableDrafts,\n draftMissing: true,\n now,\n syncRunId,\n }),\n ...(docsEnableDrafts ? { draft: true } : {}),\n overrideAccess: true,\n })\n writes.draft += 1\n }\n }\n\n if (deleteBehavior === 'delete') {\n if (!payload.delete) {\n throw new Error('Payload delete operation is required for hard delete.')\n }\n\n for (const change of plan.delete) {\n const current = existingBySourcePath.get(change.sourcePath)\n\n if (!current) {\n continue\n }\n\n await payload.delete({\n id: current.id,\n collection: collectionSlug,\n overrideAccess: true,\n })\n writes.delete += 1\n }\n }\n\n return {\n ok: true,\n writes,\n }\n}\n"],"names":["findDocsSyncConflicts","buildArchiveData","buildDocsData","assertApplyDeleteBehaviorSupported","deleteBehavior","allowHardDelete","docsEnableDrafts","getDocsWriteDraftOption","publish","draft","applyDocsSync","collectionSlug","docsSetId","existing","manifest","markdownFieldName","now","payload","plan","syncRunId","existingBySourcePath","Map","map","record","sourcePath","reactivations","unchanged","filter","change","current","archived","conflicts","plannedChanges","update","archive","delete","length","ok","writes","create","reactivate","writeDraftOption","desired","collection","data","overrideAccess","get","id","draftMissing","Error"],"mappings":"AAIA,SAASA,qBAAqB,QAAQ,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,17 @@
|
|
|
1
1
|
import type { ValidatedDocsManifest, ValidatedDocsManifestFile } from '../sync/index.js';
|
|
2
|
-
import type { ExistingPayloadDocsRecord } from './existingDocs.js';
|
|
3
2
|
export type BuildDocsDataInput = {
|
|
4
|
-
current?: ExistingPayloadDocsRecord;
|
|
5
3
|
desired: ValidatedDocsManifestFile;
|
|
6
4
|
docsEnableDrafts: boolean;
|
|
7
5
|
docsSetId?: number | string;
|
|
8
6
|
manifest: ValidatedDocsManifest;
|
|
9
7
|
markdownFieldName: string;
|
|
10
8
|
now: Date;
|
|
11
|
-
|
|
9
|
+
publish: boolean;
|
|
12
10
|
syncRunId?: number | string;
|
|
13
11
|
};
|
|
14
12
|
export type DocsDraftStatus = 'draft' | 'published';
|
|
15
|
-
export type DocsPublishMode = 'draft' | 'preserve' | 'published';
|
|
16
13
|
export declare const getDocsDepth: (sourcePath: string) => number;
|
|
17
|
-
export declare const buildDocsData: ({
|
|
14
|
+
export declare const buildDocsData: ({ desired, docsEnableDrafts, docsSetId, manifest, markdownFieldName, now, publish, syncRunId, }: BuildDocsDataInput) => Record<string, unknown>;
|
|
18
15
|
export declare const buildArchiveData: ({ docsEnableDrafts, draftMissing, now, syncRunId, }: {
|
|
19
16
|
docsEnableDrafts?: boolean;
|
|
20
17
|
draftMissing?: boolean;
|
package/dist/payload/docsData.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import { MANAGED_BY } from '../constants.js';
|
|
2
2
|
import { sha256Hex } from '../sync/index.js';
|
|
3
3
|
export const getDocsDepth = (sourcePath)=>sourcePath === 'index.md' ? 0 : Math.max(0, sourcePath.split('/').length - 1);
|
|
4
|
-
const getDraftStatusForDocsData = ({
|
|
4
|
+
const getDraftStatusForDocsData = ({ docsEnableDrafts, publish })=>{
|
|
5
5
|
if (!docsEnableDrafts) {
|
|
6
6
|
return undefined;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
return publishMode;
|
|
10
|
-
}
|
|
11
|
-
return current ? current.status : 'draft';
|
|
8
|
+
return publish ? 'published' : 'draft';
|
|
12
9
|
};
|
|
13
|
-
export const buildDocsData = ({
|
|
10
|
+
export const buildDocsData = ({ desired, docsEnableDrafts, docsSetId, manifest, markdownFieldName, now, publish, syncRunId })=>{
|
|
14
11
|
const draftStatus = getDraftStatusForDocsData({
|
|
15
|
-
current,
|
|
16
12
|
docsEnableDrafts,
|
|
17
|
-
|
|
13
|
+
publish
|
|
18
14
|
});
|
|
19
15
|
return {
|
|
20
16
|
...draftStatus ? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/payload/docsData.ts"],"sourcesContent":["import type { ValidatedDocsManifest, ValidatedDocsManifestFile } from '../sync/index.js'\
|
|
1
|
+
{"version":3,"sources":["../../src/payload/docsData.ts"],"sourcesContent":["import type { ValidatedDocsManifest, ValidatedDocsManifestFile } from '../sync/index.js'\n\nimport { MANAGED_BY } from '../constants.js'\nimport { sha256Hex } from '../sync/index.js'\n\nexport type BuildDocsDataInput = {\n desired: ValidatedDocsManifestFile\n docsEnableDrafts: boolean\n docsSetId?: number | string\n manifest: ValidatedDocsManifest\n markdownFieldName: string\n now: Date\n publish: boolean\n syncRunId?: number | string\n}\n\nexport type DocsDraftStatus = 'draft' | 'published'\n\nexport const getDocsDepth = (sourcePath: string): number =>\n sourcePath === 'index.md' ? 0 : Math.max(0, sourcePath.split('/').length - 1)\n\nconst getDraftStatusForDocsData = ({\n docsEnableDrafts,\n publish,\n}: {\n docsEnableDrafts: boolean\n publish: boolean\n}): DocsDraftStatus | undefined => {\n if (!docsEnableDrafts) {\n return undefined\n }\n\n return publish ? 'published' : 'draft'\n}\n\nexport const buildDocsData = ({\n desired,\n docsEnableDrafts,\n docsSetId,\n manifest,\n markdownFieldName,\n now,\n publish,\n syncRunId,\n}: BuildDocsDataInput): Record<string, unknown> => {\n const draftStatus = getDraftStatusForDocsData({\n docsEnableDrafts,\n publish,\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","docsEnableDrafts","publish","undefined","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":"AAEA,SAASA,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,mBAAkB;AAe5C,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,gB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;YACVC,YAAYjB,IAAIoB,WAAW;YAC3BD,cAAcnB,IAAIoB,WAAW;YAC7BC,eAAepB;YACfqB,WAAWvC;QACb;IACF,CAAA,EAAE"}
|
|
@@ -3,6 +3,7 @@ export type DocsSetPayloadOperations = {
|
|
|
3
3
|
find: (args: {
|
|
4
4
|
collection: string;
|
|
5
5
|
depth?: number;
|
|
6
|
+
draft?: boolean;
|
|
6
7
|
limit?: number;
|
|
7
8
|
overrideAccess?: boolean;
|
|
8
9
|
where?: unknown;
|
|
@@ -12,6 +13,7 @@ export type DocsSetPayloadOperations = {
|
|
|
12
13
|
update?: (args: {
|
|
13
14
|
collection: string;
|
|
14
15
|
data: Record<string, unknown>;
|
|
16
|
+
draft?: boolean;
|
|
15
17
|
id: string;
|
|
16
18
|
overrideAccess?: boolean;
|
|
17
19
|
}) => Promise<Record<string, unknown>>;
|
|
@@ -43,18 +45,20 @@ export declare const isEd25519AuthEnabled: (auth: {
|
|
|
43
45
|
ed25519?: boolean | PayloadMarkdownDocsAuthToggle;
|
|
44
46
|
mode?: "disabled";
|
|
45
47
|
} | undefined) => boolean;
|
|
46
|
-
export declare const updateDocsSetAfterSync: ({ aiExport, collectionSlug, docsCount, docsSetId, now, payload, syncRunId, }: {
|
|
48
|
+
export declare const updateDocsSetAfterSync: ({ aiExport, collectionSlug, docsCount, docsSetId, now, payload, publish, syncRunId, }: {
|
|
47
49
|
aiExport?: unknown;
|
|
48
50
|
collectionSlug: string;
|
|
49
51
|
docsCount: number;
|
|
50
52
|
docsSetId: PayloadRecordId;
|
|
51
53
|
now: Date;
|
|
52
54
|
payload: DocsSetPayloadOperations;
|
|
55
|
+
publish: boolean;
|
|
53
56
|
syncRunId?: PayloadRecordId;
|
|
54
57
|
}) => Promise<void>;
|
|
55
|
-
export declare const findDocsSetBySlug: ({ slug, collectionSlug, docsGroupsCollectionSlug, payload, }: {
|
|
58
|
+
export declare const findDocsSetBySlug: ({ slug, collectionSlug, docsGroupsCollectionSlug, includeDrafts, payload, }: {
|
|
56
59
|
collectionSlug: string;
|
|
57
60
|
docsGroupsCollectionSlug: string;
|
|
61
|
+
includeDrafts?: boolean;
|
|
58
62
|
payload: DocsSetPayloadOperations;
|
|
59
63
|
slug: string;
|
|
60
64
|
}) => Promise<ResolvedDocsSet | undefined>;
|
package/dist/payload/docsSets.js
CHANGED
|
@@ -47,7 +47,7 @@ const authToggleEnabled = (toggle, defaultValue)=>{
|
|
|
47
47
|
};
|
|
48
48
|
export const isGitHubOidcAuthEnabled = (auth)=>auth?.mode !== 'disabled' && authToggleEnabled(auth?.githubOidc, false);
|
|
49
49
|
export const isEd25519AuthEnabled = (auth)=>auth?.mode !== 'disabled' && authToggleEnabled(auth?.ed25519, false);
|
|
50
|
-
export const updateDocsSetAfterSync = async ({ aiExport, collectionSlug, docsCount, docsSetId, now, payload, syncRunId })=>{
|
|
50
|
+
export const updateDocsSetAfterSync = async ({ aiExport, collectionSlug, docsCount, docsSetId, now, payload, publish, syncRunId })=>{
|
|
51
51
|
if (!payload.update) {
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
@@ -55,6 +55,7 @@ export const updateDocsSetAfterSync = async ({ aiExport, collectionSlug, docsCou
|
|
|
55
55
|
id: String(docsSetId),
|
|
56
56
|
collection: collectionSlug,
|
|
57
57
|
data: {
|
|
58
|
+
_status: publish ? 'published' : 'draft',
|
|
58
59
|
aiExport: aiExport ?? null,
|
|
59
60
|
sync: {
|
|
60
61
|
docsCount,
|
|
@@ -63,6 +64,7 @@ export const updateDocsSetAfterSync = async ({ aiExport, collectionSlug, docsCou
|
|
|
63
64
|
lastSyncRunId: syncRunId
|
|
64
65
|
}
|
|
65
66
|
},
|
|
67
|
+
draft: !publish,
|
|
66
68
|
overrideAccess: true
|
|
67
69
|
});
|
|
68
70
|
};
|
|
@@ -147,11 +149,12 @@ const getGroupsById = async ({ collectionSlug, payload })=>{
|
|
|
147
149
|
];
|
|
148
150
|
}));
|
|
149
151
|
};
|
|
150
|
-
export const findDocsSetBySlug = async ({ slug, collectionSlug, docsGroupsCollectionSlug, payload })=>{
|
|
152
|
+
export const findDocsSetBySlug = async ({ slug, collectionSlug, docsGroupsCollectionSlug, includeDrafts = false, payload })=>{
|
|
151
153
|
const [result, groupsById] = await Promise.all([
|
|
152
154
|
payload.find({
|
|
153
155
|
collection: collectionSlug,
|
|
154
156
|
depth: 0,
|
|
157
|
+
draft: includeDrafts,
|
|
155
158
|
limit: 1,
|
|
156
159
|
overrideAccess: true,
|
|
157
160
|
where: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/payload/docsSets.ts"],"sourcesContent":["import type { PayloadMarkdownDocsAuthToggle } from '../types.js'\n\nimport {\n deriveDocsSetRouteBase,\n joinRouteSegments,\n normalizeRoutePath,\n} from '../routing/index.js'\n\nexport type DocsSetPayloadOperations = {\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: string\n overrideAccess?: boolean\n }) => Promise<Record<string, unknown>>\n}\n\nexport type PayloadRecordId = number | string\n\nexport type ResolvedDocsGroup = {\n id: PayloadRecordId\n parentId?: string\n routePath: string\n slug: string\n}\n\nexport type ResolvedDocsSet = {\n advancedSecurity?: {\n allowedWorkflowRefs: string[]\n enabled: boolean\n }\n allowPullRequests: boolean\n branch: string\n groupId?: string\n id: PayloadRecordId\n routeBase: string\n slug: string\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>): PayloadRecordId | 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 getString = (value: unknown): string | undefined =>\n typeof value === 'string' && value.trim() !== '' ? value.trim() : undefined\n\nconst getStringArray = (value: unknown): string[] => {\n if (!Array.isArray(value)) {\n return []\n }\n\n return value.flatMap((item) => {\n if (typeof item === 'string' && item.trim() !== '') {\n return [item.trim()]\n }\n\n if (isRecord(item)) {\n const nestedValue = getString(item.value)\n\n return nestedValue ? [nestedValue] : []\n }\n\n return []\n })\n}\n\nconst authToggleEnabled = (\n toggle: boolean | PayloadMarkdownDocsAuthToggle | undefined,\n defaultValue: boolean,\n): boolean => {\n if (toggle === undefined) {\n return defaultValue\n }\n\n if (typeof toggle === 'boolean') {\n return toggle\n }\n\n return toggle.enabled !== false\n}\n\nexport const isGitHubOidcAuthEnabled = (\n auth: { githubOidc?: boolean | PayloadMarkdownDocsAuthToggle; mode?: 'disabled' } | undefined,\n): boolean => auth?.mode !== 'disabled' && authToggleEnabled(auth?.githubOidc, false)\n\nexport const isEd25519AuthEnabled = (\n auth: { ed25519?: boolean | PayloadMarkdownDocsAuthToggle; mode?: 'disabled' } | undefined,\n): boolean => auth?.mode !== 'disabled' && authToggleEnabled(auth?.ed25519, false)\n\nexport const updateDocsSetAfterSync = async ({\n aiExport,\n collectionSlug,\n docsCount,\n docsSetId,\n now,\n payload,\n syncRunId,\n}: {\n aiExport?: unknown\n collectionSlug: string\n docsCount: number\n docsSetId: PayloadRecordId\n now: Date\n payload: DocsSetPayloadOperations\n syncRunId?: PayloadRecordId\n}): Promise<void> => {\n if (!payload.update) {\n return\n }\n\n await payload.update({\n id: String(docsSetId),\n collection: collectionSlug,\n data: {\n aiExport: aiExport ?? null,\n sync: {\n docsCount,\n lastStatus: 'success',\n lastSyncedAt: now.toISOString(),\n lastSyncRunId: syncRunId,\n },\n },\n overrideAccess: true,\n })\n}\n\nconst toResolvedGroup = (\n doc: unknown,\n groupsById: Map<string, unknown>,\n seen = new Set<string>(),\n): ResolvedDocsGroup | undefined => {\n if (!isRecord(doc)) {\n return undefined\n }\n\n const id = getRecordId(doc)\n const slug = getString(doc.slug)\n\n if (!id || !slug) {\n return undefined\n }\n\n const stringId = String(id)\n\n if (seen.has(stringId)) {\n return {\n id,\n slug,\n routePath: joinRouteSegments(slug),\n }\n }\n\n const parentId = getRelationshipId(doc.parent)\n const parentDoc = parentId ? groupsById.get(parentId) : undefined\n const parentGroup = parentDoc\n ? toResolvedGroup(parentDoc, groupsById, new Set([stringId, ...seen]))\n : undefined\n\n return {\n id,\n slug,\n parentId,\n routePath: joinRouteSegments(parentGroup?.routePath, slug),\n }\n}\n\nconst toResolvedDocsSet = ({\n doc,\n groupsById,\n}: {\n doc: unknown\n groupsById: Map<string, unknown>\n}): ResolvedDocsSet | undefined => {\n if (!isRecord(doc)) {\n return undefined\n }\n\n const id = getRecordId(doc)\n const slug = getString(doc.slug)\n\n if (!id || !slug) {\n return undefined\n }\n\n const groupId = getRelationshipId(doc.group)\n const group = groupId ? toResolvedGroup(groupsById.get(groupId), groupsById) : undefined\n const advancedSecurity = isRecord(doc.advancedSecurity)\n ? doc.advancedSecurity\n : undefined\n const advancedSecurityEnabled = advancedSecurity?.enabled === true\n\n return {\n id,\n ...(advancedSecurityEnabled\n ? {\n advancedSecurity: {\n allowedWorkflowRefs: getStringArray(advancedSecurity.allowedWorkflowRefs),\n enabled: true,\n },\n }\n : {}),\n slug,\n allowPullRequests: doc.allowPullRequests === true,\n branch: getString(doc.branch) ?? 'main',\n groupId,\n routeBase: normalizeRoutePath(\n deriveDocsSetRouteBase({\n docsSetSlug: slug,\n groupRoutePath: group?.routePath,\n }),\n ),\n }\n}\n\nconst getGroupsById = async ({\n collectionSlug,\n payload,\n}: {\n collectionSlug: string\n payload: DocsSetPayloadOperations\n}): Promise<Map<string, unknown>> => {\n const result = await payload.find({\n collection: collectionSlug,\n depth: 0,\n limit: 1000,\n overrideAccess: true,\n })\n\n return new Map(\n result.docs.flatMap((doc) => {\n if (!isRecord(doc)) {\n return []\n }\n\n const id = getRecordId(doc)\n\n return id === undefined ? [] : [[String(id), doc]]\n }),\n )\n}\n\nexport const findDocsSetBySlug = async ({\n slug,\n collectionSlug,\n docsGroupsCollectionSlug,\n payload,\n}: {\n collectionSlug: string\n docsGroupsCollectionSlug: string\n payload: DocsSetPayloadOperations\n slug: string\n}): Promise<ResolvedDocsSet | undefined> => {\n const [result, groupsById] = await Promise.all([\n payload.find({\n collection: collectionSlug,\n depth: 0,\n limit: 1,\n overrideAccess: true,\n where: {\n slug: {\n equals: slug,\n },\n },\n }),\n getGroupsById({\n collectionSlug: docsGroupsCollectionSlug,\n payload,\n }),\n ])\n\n return toResolvedDocsSet({\n doc: result.docs[0],\n groupsById,\n })\n}\n\nexport const findDocsSetByRouteBase = async ({\n collectionSlug,\n docsGroupsCollectionSlug,\n payload,\n routeBase,\n}: {\n collectionSlug: string\n docsGroupsCollectionSlug: string\n payload: DocsSetPayloadOperations\n routeBase: string\n}): Promise<ResolvedDocsSet | undefined> => {\n const [result, groupsById] = await Promise.all([\n payload.find({\n collection: collectionSlug,\n depth: 0,\n limit: 1000,\n overrideAccess: true,\n }),\n getGroupsById({\n collectionSlug: docsGroupsCollectionSlug,\n payload,\n }),\n ])\n const normalizedRouteBase = normalizeRoutePath(routeBase)\n\n return result.docs\n .map((doc) =>\n toResolvedDocsSet({\n doc,\n groupsById,\n }),\n )\n .find((docsSet) => docsSet?.routeBase === normalizedRouteBase)\n}\n"],"names":["deriveDocsSetRouteBase","joinRouteSegments","normalizeRoutePath","isRecord","value","Array","isArray","getRecordId","doc","id","undefined","getRelationshipId","String","getString","trim","getStringArray","flatMap","item","nestedValue","authToggleEnabled","toggle","defaultValue","enabled","isGitHubOidcAuthEnabled","auth","mode","githubOidc","isEd25519AuthEnabled","ed25519","updateDocsSetAfterSync","aiExport","collectionSlug","docsCount","docsSetId","now","payload","syncRunId","update","collection","data","sync","lastStatus","lastSyncedAt","toISOString","lastSyncRunId","overrideAccess","toResolvedGroup","groupsById","seen","Set","slug","stringId","has","routePath","parentId","parent","parentDoc","get","parentGroup","toResolvedDocsSet","groupId","group","advancedSecurity","advancedSecurityEnabled","allowedWorkflowRefs","allowPullRequests","branch","routeBase","docsSetSlug","groupRoutePath","getGroupsById","result","find","depth","limit","Map","docs","findDocsSetBySlug","docsGroupsCollectionSlug","Promise","all","where","equals","findDocsSetByRouteBase","normalizedRouteBase","map","docsSet"],"mappings":"AAEA,SACEA,sBAAsB,EACtBC,iBAAiB,EACjBC,kBAAkB,QACb,sBAAqB;AA0C5B,MAAMC,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,OAAOD,IAAIC,EAAE;IACf;IAEA,OAAOC;AACT;AAEA,MAAMC,oBAAoB,CAACP;IACzB,IAAI,OAAOA,UAAU,YAAY,OAAOA,UAAU,UAAU;QAC1D,OAAOQ,OAAOR;IAChB;IAEA,IAAID,SAASC,QAAQ;QACnB,MAAMK,KAAKF,YAAYH;QAEvB,OAAOK,OAAOC,YAAYA,YAAYE,OAAOH;IAC/C;IAEA,OAAOC;AACT;AAEA,MAAMG,YAAY,CAACT,QACjB,OAAOA,UAAU,YAAYA,MAAMU,IAAI,OAAO,KAAKV,MAAMU,IAAI,KAAKJ;AAEpE,MAAMK,iBAAiB,CAACX;IACtB,IAAI,CAACC,MAAMC,OAAO,CAACF,QAAQ;QACzB,OAAO,EAAE;IACX;IAEA,OAAOA,MAAMY,OAAO,CAAC,CAACC;QACpB,IAAI,OAAOA,SAAS,YAAYA,KAAKH,IAAI,OAAO,IAAI;YAClD,OAAO;gBAACG,KAAKH,IAAI;aAAG;QACtB;QAEA,IAAIX,SAASc,OAAO;YAClB,MAAMC,cAAcL,UAAUI,KAAKb,KAAK;YAExC,OAAOc,cAAc;gBAACA;aAAY,GAAG,EAAE;QACz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AO,CAAC,CAACR;QACnB,IAAI,CAACL,SAASK,MAAM;YAClB,OAAO,EAAE;QACX;QAEA,MAAMC,KAAKF,YAAYC;QAEvB,OAAOC,OAAOC,YAAY,EAAE,GAAG;YAAC;gBAACE,OAAOH;gBAAKD;aAAI;SAAC;IACpD;AAEJ;AAEA,OAAO,MAAMqE,oBAAoB,OAAO,EACtC3B,IAAI,EACJnB,cAAc,EACd+C,wBAAwB,EACxB3C,OAAO,EAMR;IACC,MAAM,CAACoC,QAAQxB,WAAW,GAAG,MAAMgC,QAAQC,GAAG,CAAC;QAC7C7C,QAAQqC,IAAI,CAAC;YACXlC,YAAYP;YACZ0C,OAAO;YACPC,OAAO;YACP7B,gBAAgB;YAChBoC,OAAO;gBACL/B,MAAM;oBACJgC,QAAQhC;gBACV;YACF;QACF;QACAoB,cAAc;YACZvC,gBAAgB+C;YAChB3C;QACF;KACD;IAED,OAAOwB,kBAAkB;QACvBnD,KAAK+D,OAAOK,IAAI,CAAC,EAAE;QACnB7B;IACF;AACF,EAAC;AAED,OAAO,MAAMoC,yBAAyB,OAAO,EAC3CpD,cAAc,EACd+C,wBAAwB,EACxB3C,OAAO,EACPgC,SAAS,EAMV;IACC,MAAM,CAACI,QAAQxB,WAAW,GAAG,MAAMgC,QAAQC,GAAG,CAAC;QAC7C7C,QAAQqC,IAAI,CAAC;YACXlC,YAAYP;YACZ0C,OAAO;YACPC,OAAO;YACP7B,gBAAgB;QAClB;QACAyB,cAAc;YACZvC,gBAAgB+C;YAChB3C;QACF;KACD;IACD,MAAMiD,sBAAsBlF,mBAAmBiE;IAE/C,OAAOI,OAAOK,IAAI,CACfS,GAAG,CAAC,CAAC7E,MACJmD,kBAAkB;YAChBnD;YACAuC;QACF,IAEDyB,IAAI,CAAC,CAACc,UAAYA,SAASnB,cAAciB;AAC9C,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/payload/docsSets.ts"],"sourcesContent":["import type { PayloadMarkdownDocsAuthToggle } from '../types.js'\n\nimport { deriveDocsSetRouteBase, joinRouteSegments, normalizeRoutePath } from '../routing/index.js'\n\nexport type DocsSetPayloadOperations = {\n find: (args: {\n collection: string\n depth?: number\n draft?: boolean\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 draft?: boolean\n id: string\n overrideAccess?: boolean\n }) => Promise<Record<string, unknown>>\n}\n\nexport type PayloadRecordId = number | string\n\nexport type ResolvedDocsGroup = {\n id: PayloadRecordId\n parentId?: string\n routePath: string\n slug: string\n}\n\nexport type ResolvedDocsSet = {\n advancedSecurity?: {\n allowedWorkflowRefs: string[]\n enabled: boolean\n }\n allowPullRequests: boolean\n branch: string\n groupId?: string\n id: PayloadRecordId\n routeBase: string\n slug: string\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>): PayloadRecordId | 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 getString = (value: unknown): string | undefined =>\n typeof value === 'string' && value.trim() !== '' ? value.trim() : undefined\n\nconst getStringArray = (value: unknown): string[] => {\n if (!Array.isArray(value)) {\n return []\n }\n\n return value.flatMap((item) => {\n if (typeof item === 'string' && item.trim() !== '') {\n return [item.trim()]\n }\n\n if (isRecord(item)) {\n const nestedValue = getString(item.value)\n\n return nestedValue ? [nestedValue] : []\n }\n\n return []\n })\n}\n\nconst authToggleEnabled = (\n toggle: boolean | PayloadMarkdownDocsAuthToggle | undefined,\n defaultValue: boolean,\n): boolean => {\n if (toggle === undefined) {\n return defaultValue\n }\n\n if (typeof toggle === 'boolean') {\n return toggle\n }\n\n return toggle.enabled !== false\n}\n\nexport const isGitHubOidcAuthEnabled = (\n auth: { githubOidc?: boolean | PayloadMarkdownDocsAuthToggle; mode?: 'disabled' } | undefined,\n): boolean => auth?.mode !== 'disabled' && authToggleEnabled(auth?.githubOidc, false)\n\nexport const isEd25519AuthEnabled = (\n auth: { ed25519?: boolean | PayloadMarkdownDocsAuthToggle; mode?: 'disabled' } | undefined,\n): boolean => auth?.mode !== 'disabled' && authToggleEnabled(auth?.ed25519, false)\n\nexport const updateDocsSetAfterSync = async ({\n aiExport,\n collectionSlug,\n docsCount,\n docsSetId,\n now,\n payload,\n publish,\n syncRunId,\n}: {\n aiExport?: unknown\n collectionSlug: string\n docsCount: number\n docsSetId: PayloadRecordId\n now: Date\n payload: DocsSetPayloadOperations\n publish: boolean\n syncRunId?: PayloadRecordId\n}): Promise<void> => {\n if (!payload.update) {\n return\n }\n\n await payload.update({\n id: String(docsSetId),\n collection: collectionSlug,\n data: {\n _status: publish ? 'published' : 'draft',\n aiExport: aiExport ?? null,\n sync: {\n docsCount,\n lastStatus: 'success',\n lastSyncedAt: now.toISOString(),\n lastSyncRunId: syncRunId,\n },\n },\n draft: !publish,\n overrideAccess: true,\n })\n}\n\nconst toResolvedGroup = (\n doc: unknown,\n groupsById: Map<string, unknown>,\n seen = new Set<string>(),\n): ResolvedDocsGroup | undefined => {\n if (!isRecord(doc)) {\n return undefined\n }\n\n const id = getRecordId(doc)\n const slug = getString(doc.slug)\n\n if (!id || !slug) {\n return undefined\n }\n\n const stringId = String(id)\n\n if (seen.has(stringId)) {\n return {\n id,\n slug,\n routePath: joinRouteSegments(slug),\n }\n }\n\n const parentId = getRelationshipId(doc.parent)\n const parentDoc = parentId ? groupsById.get(parentId) : undefined\n const parentGroup = parentDoc\n ? toResolvedGroup(parentDoc, groupsById, new Set([stringId, ...seen]))\n : undefined\n\n return {\n id,\n slug,\n parentId,\n routePath: joinRouteSegments(parentGroup?.routePath, slug),\n }\n}\n\nconst toResolvedDocsSet = ({\n doc,\n groupsById,\n}: {\n doc: unknown\n groupsById: Map<string, unknown>\n}): ResolvedDocsSet | undefined => {\n if (!isRecord(doc)) {\n return undefined\n }\n\n const id = getRecordId(doc)\n const slug = getString(doc.slug)\n\n if (!id || !slug) {\n return undefined\n }\n\n const groupId = getRelationshipId(doc.group)\n const group = groupId ? toResolvedGroup(groupsById.get(groupId), groupsById) : undefined\n const advancedSecurity = isRecord(doc.advancedSecurity) ? doc.advancedSecurity : undefined\n const advancedSecurityEnabled = advancedSecurity?.enabled === true\n\n return {\n id,\n ...(advancedSecurityEnabled\n ? {\n advancedSecurity: {\n allowedWorkflowRefs: getStringArray(advancedSecurity.allowedWorkflowRefs),\n enabled: true,\n },\n }\n : {}),\n slug,\n allowPullRequests: doc.allowPullRequests === true,\n branch: getString(doc.branch) ?? 'main',\n groupId,\n routeBase: normalizeRoutePath(\n deriveDocsSetRouteBase({\n docsSetSlug: slug,\n groupRoutePath: group?.routePath,\n }),\n ),\n }\n}\n\nconst getGroupsById = async ({\n collectionSlug,\n payload,\n}: {\n collectionSlug: string\n payload: DocsSetPayloadOperations\n}): Promise<Map<string, unknown>> => {\n const result = await payload.find({\n collection: collectionSlug,\n depth: 0,\n limit: 1000,\n overrideAccess: true,\n })\n\n return new Map(\n result.docs.flatMap((doc) => {\n if (!isRecord(doc)) {\n return []\n }\n\n const id = getRecordId(doc)\n\n return id === undefined ? [] : [[String(id), doc]]\n }),\n )\n}\n\nexport const findDocsSetBySlug = async ({\n slug,\n collectionSlug,\n docsGroupsCollectionSlug,\n includeDrafts = false,\n payload,\n}: {\n collectionSlug: string\n docsGroupsCollectionSlug: string\n includeDrafts?: boolean\n payload: DocsSetPayloadOperations\n slug: string\n}): Promise<ResolvedDocsSet | undefined> => {\n const [result, groupsById] = await Promise.all([\n payload.find({\n collection: collectionSlug,\n depth: 0,\n draft: includeDrafts,\n limit: 1,\n overrideAccess: true,\n where: {\n slug: {\n equals: slug,\n },\n },\n }),\n getGroupsById({\n collectionSlug: docsGroupsCollectionSlug,\n payload,\n }),\n ])\n\n return toResolvedDocsSet({\n doc: result.docs[0],\n groupsById,\n })\n}\n\nexport const findDocsSetByRouteBase = async ({\n collectionSlug,\n docsGroupsCollectionSlug,\n payload,\n routeBase,\n}: {\n collectionSlug: string\n docsGroupsCollectionSlug: string\n payload: DocsSetPayloadOperations\n routeBase: string\n}): Promise<ResolvedDocsSet | undefined> => {\n const [result, groupsById] = await Promise.all([\n payload.find({\n collection: collectionSlug,\n depth: 0,\n limit: 1000,\n overrideAccess: true,\n }),\n getGroupsById({\n collectionSlug: docsGroupsCollectionSlug,\n payload,\n }),\n ])\n const normalizedRouteBase = normalizeRoutePath(routeBase)\n\n return result.docs\n .map((doc) =>\n toResolvedDocsSet({\n doc,\n groupsById,\n }),\n )\n .find((docsSet) => docsSet?.routeBase === normalizedRouteBase)\n}\n"],"names":["deriveDocsSetRouteBase","joinRouteSegments","normalizeRoutePath","isRecord","value","Array","isArray","getRecordId","doc","id","undefined","getRelationshipId","String","getString","trim","getStringArray","flatMap","item","nestedValue","authToggleEnabled","toggle","defaultValue","enabled","isGitHubOidcAuthEnabled","auth","mode","githubOidc","isEd25519AuthEnabled","ed25519","updateDocsSetAfterSync","aiExport","collectionSlug","docsCount","docsSetId","now","payload","publish","syncRunId","update","collection","data","_status","sync","lastStatus","lastSyncedAt","toISOString","lastSyncRunId","draft","overrideAccess","toResolvedGroup","groupsById","seen","Set","slug","stringId","has","routePath","parentId","parent","parentDoc","get","parentGroup","toResolvedDocsSet","groupId","group","advancedSecurity","advancedSecurityEnabled","allowedWorkflowRefs","allowPullRequests","branch","routeBase","docsSetSlug","groupRoutePath","getGroupsById","result","find","depth","limit","Map","docs","findDocsSetBySlug","docsGroupsCollectionSlug","includeDrafts","Promise","all","where","equals","findDocsSetByRouteBase","normalizedRouteBase","map","docsSet"],"mappings":"AAEA,SAASA,sBAAsB,EAAEC,iBAAiB,EAAEC,kBAAkB,QAAQ,sBAAqB;AA4C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c,EACdkD,wBAAwB,EACxBC,gBAAgB,KAAK,EACrB/C,OAAO,EAOR;IACC,MAAM,CAACuC,QAAQxB,WAAW,GAAG,MAAMiC,QAAQC,GAAG,CAAC;QAC7CjD,QAAQwC,IAAI,CAAC;YACXpC,YAAYR;YACZ6C,OAAO;YACP7B,OAAOmC;YACPL,OAAO;YACP7B,gBAAgB;YAChBqC,OAAO;gBACLhC,MAAM;oBACJiC,QAAQjC;gBACV;YACF;QACF;QACAoB,cAAc;YACZ1C,gBAAgBkD;YAChB9C;QACF;KACD;IAED,OAAO2B,kBAAkB;QACvBtD,KAAKkE,OAAOK,IAAI,CAAC,EAAE;QACnB7B;IACF;AACF,EAAC;AAED,OAAO,MAAMqC,yBAAyB,OAAO,EAC3CxD,cAAc,EACdkD,wBAAwB,EACxB9C,OAAO,EACPmC,SAAS,EAMV;IACC,MAAM,CAACI,QAAQxB,WAAW,GAAG,MAAMiC,QAAQC,GAAG,CAAC;QAC7CjD,QAAQwC,IAAI,CAAC;YACXpC,YAAYR;YACZ6C,OAAO;YACPC,OAAO;YACP7B,gBAAgB;QAClB;QACAyB,cAAc;YACZ1C,gBAAgBkD;YAChB9C;QACF;KACD;IACD,MAAMqD,sBAAsBtF,mBAAmBoE;IAE/C,OAAOI,OAAOK,IAAI,CACfU,GAAG,CAAC,CAACjF,MACJsD,kBAAkB;YAChBtD;YACA0C;QACF,IAEDyB,IAAI,CAAC,CAACe,UAAYA,SAASpB,cAAckB;AAC9C,EAAC"}
|
|
@@ -3,6 +3,7 @@ export type ExistingDocsPayloadOperations = {
|
|
|
3
3
|
find: (args: {
|
|
4
4
|
collection: string;
|
|
5
5
|
depth?: number;
|
|
6
|
+
draft?: boolean;
|
|
6
7
|
limit?: number;
|
|
7
8
|
overrideAccess?: boolean;
|
|
8
9
|
where?: unknown;
|
|
@@ -28,16 +29,18 @@ export type ExistingPayloadDocsRecord = {
|
|
|
28
29
|
};
|
|
29
30
|
} & ExistingDocsRecord;
|
|
30
31
|
export declare const toExistingDocsRecord: (doc: ExistingPayloadDocsRecord) => ExistingDocsRecord;
|
|
31
|
-
export declare const findExistingPayloadDocsRecords: ({ collectionSlug, docsSetId, markdownFieldName, payload, sourceId, }: {
|
|
32
|
+
export declare const findExistingPayloadDocsRecords: ({ collectionSlug, docsSetId, draft, markdownFieldName, payload, sourceId, }: {
|
|
32
33
|
collectionSlug: string;
|
|
33
34
|
docsSetId?: number | string;
|
|
35
|
+
draft?: boolean;
|
|
34
36
|
markdownFieldName: string;
|
|
35
37
|
payload: ExistingDocsPayloadOperations;
|
|
36
38
|
sourceId: string;
|
|
37
39
|
}) => Promise<ExistingPayloadDocsRecord[]>;
|
|
38
|
-
export declare const findExistingDocsRecords: ({ collectionSlug, docsSetId, markdownFieldName, payload, sourceId, }: {
|
|
40
|
+
export declare const findExistingDocsRecords: ({ collectionSlug, docsSetId, draft, markdownFieldName, payload, sourceId, }: {
|
|
39
41
|
collectionSlug: string;
|
|
40
42
|
docsSetId?: number | string;
|
|
43
|
+
draft?: boolean;
|
|
41
44
|
markdownFieldName: string;
|
|
42
45
|
payload: ExistingDocsPayloadOperations;
|
|
43
46
|
sourceId: string;
|
|
@@ -52,12 +52,14 @@ export const toExistingDocsRecord = (doc)=>({
|
|
|
52
52
|
route: doc.route,
|
|
53
53
|
sourceHash: doc.sourceHash,
|
|
54
54
|
sourcePath: doc.sourcePath,
|
|
55
|
+
status: doc.status,
|
|
55
56
|
title: doc.title
|
|
56
57
|
});
|
|
57
|
-
export const findExistingPayloadDocsRecords = async ({ collectionSlug, docsSetId, markdownFieldName, payload, sourceId })=>{
|
|
58
|
+
export const findExistingPayloadDocsRecords = async ({ collectionSlug, docsSetId, draft, markdownFieldName, payload, sourceId })=>{
|
|
58
59
|
const result = await payload.find({
|
|
59
60
|
collection: collectionSlug,
|
|
60
61
|
depth: 0,
|
|
62
|
+
draft,
|
|
61
63
|
limit: 1000,
|
|
62
64
|
overrideAccess: true,
|
|
63
65
|
where: docsSetId ? {
|
|
@@ -84,10 +86,11 @@ export const findExistingPayloadDocsRecords = async ({ collectionSlug, docsSetId
|
|
|
84
86
|
markdownFieldName
|
|
85
87
|
})).filter((doc)=>doc !== undefined);
|
|
86
88
|
};
|
|
87
|
-
export const findExistingDocsRecords = async ({ collectionSlug, docsSetId, markdownFieldName, payload, sourceId })=>{
|
|
89
|
+
export const findExistingDocsRecords = async ({ collectionSlug, docsSetId, draft, markdownFieldName, payload, sourceId })=>{
|
|
88
90
|
const docs = await findExistingPayloadDocsRecords({
|
|
89
91
|
collectionSlug,
|
|
90
92
|
docsSetId,
|
|
93
|
+
draft,
|
|
91
94
|
markdownFieldName,
|
|
92
95
|
payload,
|
|
93
96
|
sourceId
|
|
@@ -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 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":"
|
|
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 draft?: boolean\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 status: doc.status,\n title: doc.title,\n})\n\nexport const findExistingPayloadDocsRecords = async ({\n collectionSlug,\n docsSetId,\n draft,\n markdownFieldName,\n payload,\n sourceId,\n}: {\n collectionSlug: string\n docsSetId?: number | string\n draft?: boolean\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 draft,\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 draft,\n markdownFieldName,\n payload,\n sourceId,\n}: {\n collectionSlug: string\n docsSetId?: number | string\n draft?: boolean\n markdownFieldName: string\n payload: ExistingDocsPayloadOperations\n sourceId: string\n}): Promise<ExistingDocsRecord[]> => {\n const docs = await findExistingPayloadDocsRecords({\n collectionSlug,\n docsSetId,\n draft,\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","draft","payload","result","find","collection","depth","limit","overrideAccess","where","or","equals","docs","map","filter","findExistingDocsRecords"],"mappings":"AAiCA,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,I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,IAAIY,QAAQ;QACtBL,OAAOP,IAAIO,KAAK;QAChBS,YAAYhB,IAAIgB,UAAU;QAC1BR,YAAYR,IAAIQ,UAAU;QAC1BE,QAAQV,IAAIU,MAAM;QAClBc,OAAOxB,IAAIwB,KAAK;IAClB,CAAA,EAAE;AAEF,OAAO,MAAME,iCAAiC,OAAO,EACnDC,cAAc,EACdb,SAAS,EACTc,KAAK,EACLtB,iBAAiB,EACjBuB,OAAO,EACPN,QAAQ,EAQT;IACC,MAAMO,SAAS,MAAMD,QAAQE,IAAI,CAAC;QAChCC,YAAYL;QACZM,OAAO;QACPL;QACAM,OAAO;QACPC,gBAAgB;QAChBC,OAAOtB,YACH;YACEuB,IAAI;gBACF;oBACEtB,SAAS;wBACPuB,QAAQxB;oBACV;gBACF;gBACA;oBACE,iBAAiB;wBACfwB,QAAQf;oBACV;gBACF;aACD;QACH,IACA;YACE,iBAAiB;gBACfe,QAAQf;YACV;QACF;IACN;IAEA,OAAOO,OAAOS,IAAI,CACfC,GAAG,CAAC,CAACxC,MACJK,4BAA4B;YAC1BL;YACAM;QACF,IAEDmC,MAAM,CAAC,CAACzC,MAA0CA,QAAQG;AAC/D,EAAC;AAED,OAAO,MAAMuC,0BAA0B,OAAO,EAC5Cf,cAAc,EACdb,SAAS,EACTc,KAAK,EACLtB,iBAAiB,EACjBuB,OAAO,EACPN,QAAQ,EAQT;IACC,MAAMgB,OAAO,MAAMb,+BAA+B;QAChDC;QACAb;QACAc;QACAtB;QACAuB;QACAN;IACF;IAEA,OAAOgB,KAAKC,GAAG,CAACf;AAClB,EAAC"}
|
package/dist/payload/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export { applyDocsSync, assertApplyDeleteBehaviorSupported
|
|
2
|
-
export type { ApplyDocsSyncPayloadOperations, ApplyDocsSyncResult
|
|
1
|
+
export { applyDocsSync, assertApplyDeleteBehaviorSupported } from './applyDocsSync.js';
|
|
2
|
+
export type { ApplyDocsSyncPayloadOperations, ApplyDocsSyncResult } from './applyDocsSync.js';
|
|
3
3
|
export { findDocsSyncConflicts } from './docsConflicts.js';
|
|
4
|
-
export type { DocsSyncConflict, DocsSyncConflictReason
|
|
5
|
-
export { buildArchiveData, buildDocsData, getDocsDepth
|
|
6
|
-
export type { BuildDocsDataInput, DocsDraftStatus
|
|
4
|
+
export type { DocsSyncConflict, DocsSyncConflictReason } from './docsConflicts.js';
|
|
5
|
+
export { buildArchiveData, buildDocsData, getDocsDepth } from './docsData.js';
|
|
6
|
+
export type { BuildDocsDataInput, DocsDraftStatus } from './docsData.js';
|
|
7
7
|
export { findDocsKeyById } from './docsKeys.js';
|
|
8
|
-
export type { DocsKeyPayloadOperations, ResolvedDocsKey
|
|
8
|
+
export type { DocsKeyPayloadOperations, ResolvedDocsKey } from './docsKeys.js';
|
|
9
9
|
export { findDocsSetByRouteBase, findDocsSetBySlug, isEd25519AuthEnabled, isGitHubOidcAuthEnabled, updateDocsSetAfterSync, } from './docsSets.js';
|
|
10
|
-
export type { DocsSetPayloadOperations, ResolvedDocsSet
|
|
10
|
+
export type { DocsSetPayloadOperations, ResolvedDocsSet } from './docsSets.js';
|
|
11
11
|
export { findTrustedGitHubSources } from './docsTrusted.js';
|
|
12
12
|
export type { DocsTrustedPayloadOperations } from './docsTrusted.js';
|
|
13
13
|
export { findExistingDocsRecords } from './existingDocs.js';
|
|
14
|
-
export { findExistingPayloadDocsRecords, toExistingDocsRecord
|
|
15
|
-
export type { ExistingDocsPayloadOperations, ExistingPayloadDocsRecord
|
|
14
|
+
export { findExistingPayloadDocsRecords, toExistingDocsRecord } from './existingDocs.js';
|
|
15
|
+
export type { ExistingDocsPayloadOperations, ExistingPayloadDocsRecord } from './existingDocs.js';
|
|
16
16
|
export { findConfiguredPagesRouteCollisions, findDuplicateDesiredRouteCollisions, findExistingDocsRouteCollisions, } from './routeCollisions.js';
|
|
17
|
-
export type { DocsRouteCollisionIssue, RouteCollisionPayloadOperations
|
|
18
|
-
export { createSyncRunAudit, getRecordId, updateSyncRunAudit
|
|
17
|
+
export type { DocsRouteCollisionIssue, RouteCollisionPayloadOperations } from './routeCollisions.js';
|
|
18
|
+
export { createSyncRunAudit, getRecordId, updateSyncRunAudit } from './syncRuns.js';
|
|
19
19
|
export type { CreateSyncRunAuditInput, SyncRunsPayloadOperations, SyncRunStatus, SyncRunSummary, } from './syncRuns.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/payload/index.ts"],"sourcesContent":["export {
|
|
1
|
+
{"version":3,"sources":["../../src/payload/index.ts"],"sourcesContent":["export { applyDocsSync, assertApplyDeleteBehaviorSupported } from './applyDocsSync.js'\nexport type { ApplyDocsSyncPayloadOperations, ApplyDocsSyncResult } from './applyDocsSync.js'\nexport { findDocsSyncConflicts } from './docsConflicts.js'\nexport type { DocsSyncConflict, DocsSyncConflictReason } from './docsConflicts.js'\nexport { buildArchiveData, buildDocsData, getDocsDepth } from './docsData.js'\nexport type { BuildDocsDataInput, DocsDraftStatus } from './docsData.js'\nexport { findDocsKeyById } from './docsKeys.js'\nexport type { DocsKeyPayloadOperations, ResolvedDocsKey } from './docsKeys.js'\nexport {\n findDocsSetByRouteBase,\n findDocsSetBySlug,\n isEd25519AuthEnabled,\n isGitHubOidcAuthEnabled,\n updateDocsSetAfterSync,\n} from './docsSets.js'\nexport type { DocsSetPayloadOperations, ResolvedDocsSet } from './docsSets.js'\nexport { findTrustedGitHubSources } from './docsTrusted.js'\nexport type { DocsTrustedPayloadOperations } from './docsTrusted.js'\nexport { findExistingDocsRecords } from './existingDocs.js'\nexport { findExistingPayloadDocsRecords, toExistingDocsRecord } from './existingDocs.js'\nexport type { ExistingDocsPayloadOperations, ExistingPayloadDocsRecord } from './existingDocs.js'\nexport {\n findConfiguredPagesRouteCollisions,\n findDuplicateDesiredRouteCollisions,\n findExistingDocsRouteCollisions,\n} from './routeCollisions.js'\nexport type { DocsRouteCollisionIssue, RouteCollisionPayloadOperations } from './routeCollisions.js'\nexport { createSyncRunAudit, getRecordId, updateSyncRunAudit } from './syncRuns.js'\nexport type {\n CreateSyncRunAuditInput,\n SyncRunsPayloadOperations,\n SyncRunStatus,\n SyncRunSummary,\n} from './syncRuns.js'\n"],"names":["applyDocsSync","assertApplyDeleteBehaviorSupported","findDocsSyncConflicts","buildArchiveData","buildDocsData","getDocsDepth","findDocsKeyById","findDocsSetByRouteBase","findDocsSetBySlug","isEd25519AuthEnabled","isGitHubOidcAuthEnabled","updateDocsSetAfterSync","findTrustedGitHubSources","findExistingDocsRecords","findExistingPayloadDocsRecords","toExistingDocsRecord","findConfiguredPagesRouteCollisions","findDuplicateDesiredRouteCollisions","findExistingDocsRouteCollisions","createSyncRunAudit","getRecordId","updateSyncRunAudit"],"mappings":"AAAA,SAASA,aAAa,EAAEC,kCAAkC,QAAQ,qBAAoB;AAEtF,SAASC,qBAAqB,QAAQ,qBAAoB;AAE1D,SAASC,gBAAgB,EAAEC,aAAa,EAAEC,YAAY,QAAQ,gBAAe;AAE7E,SAASC,eAAe,QAAQ,gBAAe;AAE/C,SACEC,sBAAsB,EACtBC,iBAAiB,EACjBC,oBAAoB,EACpBC,uBAAuB,EACvBC,sBAAsB,QACjB,gBAAe;AAEtB,SAASC,wBAAwB,QAAQ,mBAAkB;AAE3D,SAASC,uBAAuB,QAAQ,oBAAmB;AAC3D,SAASC,8BAA8B,EAAEC,oBAAoB,QAAQ,oBAAmB;AAExF,SACEC,kCAAkC,EAClCC,mCAAmC,EACnCC,+BAA+B,QAC1B,uBAAsB;AAE7B,SAASC,kBAAkB,EAAEC,WAAW,EAAEC,kBAAkB,QAAQ,gBAAe"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const populatePublishedAt = ({ data, operation, req })=>{
|
|
2
|
+
if (operation === 'create' || operation === 'update') {
|
|
3
|
+
if (req.data && !req.data.publishedAt) {
|
|
4
|
+
const now = new Date();
|
|
5
|
+
return {
|
|
6
|
+
...data,
|
|
7
|
+
publishedAt: now
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return data;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=populatePublishedAt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/payload/populatePublishedAt.ts"],"sourcesContent":["import type { CollectionBeforeChangeHook } from 'payload'\n\nexport const populatePublishedAt: CollectionBeforeChangeHook = ({ data, operation, req }) => {\n if (operation === 'create' || operation === 'update') {\n if (req.data && !req.data.publishedAt) {\n const now = new Date()\n\n return {\n ...data,\n publishedAt: now,\n }\n }\n }\n\n return data\n}\n"],"names":["populatePublishedAt","data","operation","req","publishedAt","now","Date"],"mappings":"AAEA,OAAO,MAAMA,sBAAkD,CAAC,EAAEC,IAAI,EAAEC,SAAS,EAAEC,GAAG,EAAE;IACtF,IAAID,cAAc,YAAYA,cAAc,UAAU;QACpD,IAAIC,IAAIF,IAAI,IAAI,CAACE,IAAIF,IAAI,CAACG,WAAW,EAAE;YACrC,MAAMC,MAAM,IAAIC;YAEhB,OAAO;gBACL,GAAGL,IAAI;gBACPG,aAAaC;YACf;QACF;IACF;IAEA,OAAOJ;AACT,EAAC"}
|
|
@@ -2,6 +2,7 @@ export type RouteCollisionPayloadOperations = {
|
|
|
2
2
|
find: (args: {
|
|
3
3
|
collection: string;
|
|
4
4
|
depth?: number;
|
|
5
|
+
draft?: boolean;
|
|
5
6
|
limit?: number;
|
|
6
7
|
overrideAccess?: boolean;
|
|
7
8
|
where?: unknown;
|
|
@@ -14,9 +15,10 @@ export type DocsRouteCollisionIssue = {
|
|
|
14
15
|
route: string;
|
|
15
16
|
};
|
|
16
17
|
export declare const findDuplicateDesiredRouteCollisions: (routes: string[]) => DocsRouteCollisionIssue[];
|
|
17
|
-
export declare const findExistingDocsRouteCollisions: ({ collectionSlug, docsSetId, payload, routes, sourceId, }: {
|
|
18
|
+
export declare const findExistingDocsRouteCollisions: ({ collectionSlug, docsSetId, includeDrafts, payload, routes, sourceId, }: {
|
|
18
19
|
collectionSlug: string;
|
|
19
20
|
docsSetId?: number | string;
|
|
21
|
+
includeDrafts?: boolean;
|
|
20
22
|
payload: RouteCollisionPayloadOperations;
|
|
21
23
|
routes: string[];
|
|
22
24
|
sourceId: string;
|
|
@@ -35,7 +35,7 @@ export const findDuplicateDesiredRouteCollisions = (routes)=>findRouteReservatio
|
|
|
35
35
|
ownerType: 'doc',
|
|
36
36
|
route
|
|
37
37
|
}))).map(collisionToIssue);
|
|
38
|
-
export const findExistingDocsRouteCollisions = async ({ collectionSlug, docsSetId, payload, routes, sourceId })=>{
|
|
38
|
+
export const findExistingDocsRouteCollisions = async ({ collectionSlug, docsSetId, includeDrafts = false, payload, routes, sourceId })=>{
|
|
39
39
|
const normalizedRoutes = [
|
|
40
40
|
...new Set(routes.map(normalizeRoutePath))
|
|
41
41
|
];
|
|
@@ -45,6 +45,7 @@ export const findExistingDocsRouteCollisions = async ({ collectionSlug, docsSetI
|
|
|
45
45
|
const result = await payload.find({
|
|
46
46
|
collection: collectionSlug,
|
|
47
47
|
depth: 0,
|
|
48
|
+
draft: includeDrafts,
|
|
48
49
|
limit: 1000,
|
|
49
50
|
overrideAccess: true,
|
|
50
51
|
where: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/payload/routeCollisions.ts"],"sourcesContent":["import type { DocsRouteCollision } from '../routing/index.js'\n\nimport {\n findPageRouteCollisions,\n findRouteReservationCollisions,\n normalizeRoutePath,\n} from '../routing/index.js'\n\nexport type RouteCollisionPayloadOperations = {\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 DocsRouteCollisionIssue = {\n reason: string\n route: string\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>): 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 getNestedString = (\n value: Record<string, unknown>,\n dottedPath: string,\n): string | undefined => {\n const segments = dottedPath.split('.')\n let current: unknown = value\n\n for (const segment of segments) {\n if (!isRecord(current)) {\n return undefined\n }\n\n current = current[segment]\n }\n\n return typeof current === 'string' ? current : undefined\n}\n\nconst collisionToIssue = (collision: DocsRouteCollision): DocsRouteCollisionIssue => ({\n reason: collision.reason,\n route
|
|
1
|
+
{"version":3,"sources":["../../src/payload/routeCollisions.ts"],"sourcesContent":["import type { DocsRouteCollision } from '../routing/index.js'\n\nimport {\n findPageRouteCollisions,\n findRouteReservationCollisions,\n normalizeRoutePath,\n} from '../routing/index.js'\n\nexport type RouteCollisionPayloadOperations = {\n find: (args: {\n collection: string\n depth?: number\n draft?: boolean\n limit?: number\n overrideAccess?: boolean\n where?: unknown\n }) => Promise<{\n docs: unknown[]\n }>\n}\n\nexport type DocsRouteCollisionIssue = {\n reason: string\n route: string\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>): 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 getNestedString = (\n value: Record<string, unknown>,\n dottedPath: string,\n): string | undefined => {\n const segments = dottedPath.split('.')\n let current: unknown = value\n\n for (const segment of segments) {\n if (!isRecord(current)) {\n return undefined\n }\n\n current = current[segment]\n }\n\n return typeof current === 'string' ? current : undefined\n}\n\nconst collisionToIssue = (collision: DocsRouteCollision): DocsRouteCollisionIssue => ({\n reason: collision.reason,\n route:\n collision.first.route === collision.second.route\n ? collision.first.route\n : `${collision.first.route} <> ${collision.second.route}`,\n})\n\nexport const findDuplicateDesiredRouteCollisions = (routes: string[]): DocsRouteCollisionIssue[] =>\n findRouteReservationCollisions(\n routes.map((route, index) => ({\n ownerId: `desired-${index}`,\n ownerType: 'doc',\n route,\n })),\n ).map(collisionToIssue)\n\nexport const findExistingDocsRouteCollisions = async ({\n collectionSlug,\n docsSetId,\n includeDrafts = false,\n payload,\n routes,\n sourceId,\n}: {\n collectionSlug: string\n docsSetId?: number | string\n includeDrafts?: boolean\n payload: RouteCollisionPayloadOperations\n routes: string[]\n sourceId: string\n}): Promise<DocsRouteCollisionIssue[]> => {\n const normalizedRoutes = [...new Set(routes.map(normalizeRoutePath))]\n\n if (normalizedRoutes.length === 0) {\n return []\n }\n\n const result = await payload.find({\n collection: collectionSlug,\n depth: 0,\n draft: includeDrafts,\n limit: 1000,\n overrideAccess: true,\n where: {\n route: {\n in: normalizedRoutes,\n },\n },\n })\n\n return result.docs.flatMap((doc) => {\n if (!isRecord(doc) || typeof doc.route !== 'string') {\n return []\n }\n\n const existingDocsSetId = getRelationshipId(doc.docsSet)\n const existingSourceId = getNestedString(doc, 'sync.sourceId')\n const sameOwner = docsSetId\n ? existingDocsSetId === String(docsSetId) ||\n (!existingDocsSetId && existingSourceId === sourceId)\n : !existingDocsSetId && existingSourceId === sourceId\n\n if (sameOwner) {\n return []\n }\n\n return [\n {\n reason: 'existing_doc_route_collision',\n route: normalizeRoutePath(doc.route),\n },\n ]\n })\n}\n\nexport const findConfiguredPagesRouteCollisions = async ({\n allowBridgePages,\n bridgeField,\n collectionSlug,\n docsSetRouteBase,\n payload,\n routeField,\n}: {\n allowBridgePages: boolean\n bridgeField: string\n collectionSlug: string\n docsSetRouteBase: string\n payload: RouteCollisionPayloadOperations\n routeField: string\n}): Promise<DocsRouteCollisionIssue[]> => {\n const result = await payload.find({\n collection: collectionSlug,\n depth: 0,\n limit: 1000,\n overrideAccess: true,\n })\n\n const collisions = findPageRouteCollisions({\n allowBridgePages,\n docsSetRouteBase,\n pages: result.docs.flatMap((doc) => {\n if (!isRecord(doc)) {\n return []\n }\n\n const route = getNestedString(doc, routeField)\n\n if (!route) {\n return []\n }\n\n return [\n {\n id: getRecordId(doc),\n bridge: doc[bridgeField] === true,\n route,\n },\n ]\n }),\n })\n\n return collisions.map(collisionToIssue)\n}\n"],"names":["findPageRouteCollisions","findRouteReservationCollisions","normalizeRoutePath","isRecord","value","Array","isArray","getRecordId","doc","id","String","undefined","getRelationshipId","getNestedString","dottedPath","segments","split","current","segment","collisionToIssue","collision","reason","route","first","second","findDuplicateDesiredRouteCollisions","routes","map","index","ownerId","ownerType","findExistingDocsRouteCollisions","collectionSlug","docsSetId","includeDrafts","payload","sourceId","normalizedRoutes","Set","length","result","find","collection","depth","draft","limit","overrideAccess","where","in","docs","flatMap","existingDocsSetId","docsSet","existingSourceId","sameOwner","findConfiguredPagesRouteCollisions","allowBridgePages","bridgeField","docsSetRouteBase","routeField","collisions","pages","bridge"],"mappings":"AAEA,SACEA,uBAAuB,EACvBC,8BAA8B,EAC9BC,kBAAkB,QACb,sBAAqB;AAoB5B,MAAMC,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,kBAAkB,CACtBT,O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AAK,KAAK,UAAU;YACnD,OAAO,EAAE;QACX;QAEA,MAAM6B,oBAAoBvC,kBAAkBJ,IAAI4C,OAAO;QACvD,MAAMC,mBAAmBxC,gBAAgBL,KAAK;QAC9C,MAAM8C,YAAYrB,YACdkB,sBAAsBzC,OAAOuB,cAC5B,CAACkB,qBAAqBE,qBAAqBjB,WAC5C,CAACe,qBAAqBE,qBAAqBjB;QAE/C,IAAIkB,WAAW;YACb,OAAO,EAAE;QACX;QAEA,OAAO;YACL;gBACEjC,QAAQ;gBACRC,OAAOpB,mBAAmBM,IAAIc,KAAK;YACrC;SACD;IACH;AACF,EAAC;AAED,OAAO,MAAMiC,qCAAqC,OAAO,EACvDC,gBAAgB,EAChBC,WAAW,EACXzB,cAAc,EACd0B,gBAAgB,EAChBvB,OAAO,EACPwB,UAAU,EAQX;IACC,MAAMnB,SAAS,MAAML,QAAQM,IAAI,CAAC;QAChCC,YAAYV;QACZW,OAAO;QACPE,OAAO;QACPC,gBAAgB;IAClB;IAEA,MAAMc,aAAa5D,wBAAwB;QACzCwD;QACAE;QACAG,OAAOrB,OAAOS,IAAI,CAACC,OAAO,CAAC,CAAC1C;YAC1B,IAAI,CAACL,SAASK,MAAM;gBAClB,OAAO,EAAE;YACX;YAEA,MAAMc,QAAQT,gBAAgBL,KAAKmD;YAEnC,IAAI,CAACrC,OAAO;gBACV,OAAO,EAAE;YACX;YAEA,OAAO;gBACL;oBACEb,IAAIF,YAAYC;oBAChBsD,QAAQtD,GAAG,CAACiD,YAAY,KAAK;oBAC7BnC;gBACF;aACD;QACH;IACF;IAEA,OAAOsC,WAAWjC,GAAG,CAACR;AACxB,EAAC"}
|
|
@@ -31,7 +31,6 @@ export type CreateSyncRunAuditInput = {
|
|
|
31
31
|
commit?: string;
|
|
32
32
|
completedAt: Date;
|
|
33
33
|
deleteBehavior: DocsDeleteBehavior;
|
|
34
|
-
effectivePublishMode?: 'draft' | 'preserve' | 'published';
|
|
35
34
|
errors: DocsValidationIssue[];
|
|
36
35
|
fileCount: number;
|
|
37
36
|
keyId: string;
|
|
@@ -46,7 +45,7 @@ export type CreateSyncRunAuditInput = {
|
|
|
46
45
|
totalBytes: number;
|
|
47
46
|
warnings: DocsValidationIssue[];
|
|
48
47
|
};
|
|
49
|
-
export declare const createSyncRunAudit: ({ actor, bodyHash, branch, collectionSlug, commit, completedAt, deleteBehavior,
|
|
48
|
+
export declare const createSyncRunAudit: ({ actor, bodyHash, branch, collectionSlug, commit, completedAt, deleteBehavior, errors, fileCount, keyId, mode, payload, publishRequested, repository, sourceId, startedAt, status, summary, totalBytes, warnings, }: CreateSyncRunAuditInput) => Promise<Record<string, unknown>>;
|
|
50
49
|
export declare const getRecordId: (record: Record<string, unknown>) => PayloadRecordId | undefined;
|
|
51
50
|
export declare const updateSyncRunAudit: ({ collectionSlug, completedAt, errors, payload, status, summary, syncRunId, warnings, }: {
|
|
52
51
|
collectionSlug: string;
|
package/dist/payload/syncRuns.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const issueToArrayRow = (issue)=>({
|
|
2
2
|
message: issue.path ? `${issue.path}: ${issue.message}` : issue.message
|
|
3
3
|
});
|
|
4
|
-
export const createSyncRunAudit = async ({ actor, bodyHash, branch, collectionSlug, commit, completedAt, deleteBehavior,
|
|
4
|
+
export const createSyncRunAudit = async ({ actor, bodyHash, branch, collectionSlug, commit, completedAt, deleteBehavior, errors, fileCount, keyId, mode, payload, publishRequested, repository, sourceId, startedAt, status, summary, totalBytes, warnings })=>payload.create({
|
|
5
5
|
collection: collectionSlug,
|
|
6
6
|
data: {
|
|
7
7
|
actor,
|
|
@@ -10,7 +10,6 @@ export const createSyncRunAudit = async ({ actor, bodyHash, branch, collectionSl
|
|
|
10
10
|
commit,
|
|
11
11
|
completedAt: completedAt.toISOString(),
|
|
12
12
|
deleteBehavior,
|
|
13
|
-
effectivePublishMode,
|
|
14
13
|
errors: errors.map(issueToArrayRow),
|
|
15
14
|
fileCount,
|
|
16
15
|
keyId,
|