payload-nested-docs-page-tree 1.2.4 → 1.4.1
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/README.md +356 -222
- package/dist/components/PageTreeContext.d.ts +13 -1
- package/dist/components/PageTreeContext.js +11 -1
- package/dist/components/PageTreeContext.js.map +1 -1
- package/dist/components/PageTreeListView.client.d.ts +4 -5
- package/dist/components/PageTreeListView.client.js +668 -128
- package/dist/components/PageTreeListView.client.js.map +1 -1
- package/dist/components/PageTreeListView.module.css +399 -376
- package/dist/components/PageTreeListView.server.js +18 -28
- package/dist/components/PageTreeListView.server.js.map +1 -1
- package/dist/components/PageTreeTitleCell.js +80 -18
- package/dist/components/PageTreeTitleCell.js.map +1 -1
- package/dist/endpoints/createMovePageEndpoint.d.ts +3 -0
- package/dist/endpoints/createMovePageEndpoint.js +186 -125
- package/dist/endpoints/createMovePageEndpoint.js.map +1 -1
- package/dist/endpoints/createReorderPageEndpoint.d.ts +8 -0
- package/dist/endpoints/createReorderPageEndpoint.js +706 -0
- package/dist/endpoints/createReorderPageEndpoint.js.map +1 -0
- package/dist/endpoints/shared.d.ts +40 -0
- package/dist/endpoints/shared.js +93 -0
- package/dist/endpoints/shared.js.map +1 -0
- package/dist/index.js +110 -27
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +47 -2
- package/dist/types.js +22 -3
- package/dist/types.js.map +1 -1
- package/dist/utilities/diagnostics.d.ts +42 -0
- package/dist/utilities/diagnostics.js +83 -0
- package/dist/utilities/diagnostics.js.map +1 -0
- package/dist/utilities/dropTargets.d.ts +2 -2
- package/dist/utilities/dropTargets.js +9 -7
- package/dist/utilities/dropTargets.js.map +1 -1
- package/dist/utilities/moveValidation.js.map +1 -1
- package/dist/utilities/pageTree.js +4 -6
- package/dist/utilities/pageTree.js.map +1 -1
- package/dist/utilities/pageTreeCollision.d.ts +6 -0
- package/dist/utilities/pageTreeCollision.js +39 -4
- package/dist/utilities/pageTreeCollision.js.map +1 -1
- package/dist/utilities/pageTreeConfig.js.map +1 -1
- package/dist/utilities/status.d.ts +1 -1
- package/dist/utilities/status.js +7 -3
- package/dist/utilities/status.js.map +1 -1
- package/package.json +54 -32
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/createReorderPageEndpoint.ts"],"sourcesContent":["import type { Endpoint, PayloadRequest, Where } from 'payload'\n\nimport { combineWhereConstraints, generateNKeysBetween } from 'payload/shared'\n\nimport {\n pageTreeMoveContextKey,\n type PageTreeSourceDoc,\n pageTreeWriteContextKey,\n} from '../types.js'\nimport {\n createFlowID,\n type Diagnostics,\n DIAGNOSTICS_FLOW_CONTEXT_KEY,\n readMainRowSnapshot,\n} from '../utilities/diagnostics.js'\nimport { getDocParentID, stringifyDocID } from '../utilities/pageTree.js'\nimport {\n assertUpdateAccess,\n collectionHasDrafts,\n getRequestedLocale,\n normalizeID,\n respond,\n toCollectionID,\n} from './shared.js'\n\ntype ReorderDocumentRequestBody = {\n docsToMove: string[]\n frontendOrder?: ReorderFrontendOrderDiagnostic\n newKeyWillBe: 'greater' | 'less'\n orderableFieldName: string\n target: {\n id: string\n key: null | string\n }\n}\n\ntype ReorderFrontendOrderDiagnostic = {\n activeSlug: null | string\n after: ReorderFrontendOrderEntry[]\n before: ReorderFrontendOrderEntry[]\n moveFromIndex: number\n moveToIndex: number\n newAfterRowSlug: null | string\n newBeforeRowSlug: null | string\n sort: null | string\n targetSlug: null | string\n}\n\ntype ReorderFrontendOrderEntry = {\n index: number\n orderKey: null | string\n slug: null | string\n}\n\ntype ReorderBackendOrderEntry = {\n index: number\n orderKey: null | string\n slug: null | string\n status: null | string\n}\n\ntype RawBodyAttempt = {\n raw: unknown\n source: 'req.data' | 'req.json' | 'req.text'\n}\n\ntype VersionRecord = {\n createdAt?: string\n id?: number | string\n latest?: boolean\n parent?: number | string\n publishedLocale?: string\n updatedAt?: string\n version?: Record<string, unknown>\n} & Record<string, unknown>\n\nconst SNAPSHOT_FIELDS = ['_status'] as const\n\nfunction hasOwnProperty(value: object, key: PropertyKey): boolean {\n return Object.prototype.hasOwnProperty.call(value, key)\n}\n\nfunction normalizeOptionalString(value: unknown): null | string {\n return typeof value === 'string' && value.length > 0 ? value : null\n}\n\nfunction normalizeFrontendOrderEntry(\n value: unknown,\n fallbackIndex: number,\n): null | ReorderFrontendOrderEntry {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n return null\n }\n\n const data = value as Record<string, unknown>\n\n return {\n slug: normalizeOptionalString(data.slug),\n index: typeof data.index === 'number' && Number.isFinite(data.index) ? data.index : fallbackIndex,\n orderKey: normalizeOptionalString(data.orderKey),\n }\n}\n\nfunction normalizeFrontendOrder(value: unknown): ReorderFrontendOrderDiagnostic | undefined {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n return undefined\n }\n\n const data = value as Record<string, unknown>\n\n if (!Array.isArray(data.before) || !Array.isArray(data.after)) {\n return undefined\n }\n\n const before = data.before\n .slice(0, 250)\n .map((entry, index) => normalizeFrontendOrderEntry(entry, index))\n .filter((entry): entry is ReorderFrontendOrderEntry => Boolean(entry))\n const after = data.after\n .slice(0, 250)\n .map((entry, index) => normalizeFrontendOrderEntry(entry, index))\n .filter((entry): entry is ReorderFrontendOrderEntry => Boolean(entry))\n\n return {\n activeSlug: normalizeOptionalString(data.activeSlug),\n after,\n before,\n moveFromIndex:\n typeof data.moveFromIndex === 'number' && Number.isFinite(data.moveFromIndex)\n ? data.moveFromIndex\n : -1,\n moveToIndex:\n typeof data.moveToIndex === 'number' && Number.isFinite(data.moveToIndex)\n ? data.moveToIndex\n : -1,\n newAfterRowSlug: normalizeOptionalString(data.newAfterRowSlug),\n newBeforeRowSlug: normalizeOptionalString(data.newBeforeRowSlug),\n sort: normalizeOptionalString(data.sort),\n targetSlug: normalizeOptionalString(data.targetSlug),\n }\n}\n\nfunction normalizeReorderDocumentBody(value: unknown): null | ReorderDocumentRequestBody {\n const incomingData =\n typeof value === 'string'\n ? (() => {\n try {\n return JSON.parse(value) as unknown\n } catch {\n return null\n }\n })()\n : value\n\n if (!incomingData || typeof incomingData !== 'object' || Array.isArray(incomingData)) {\n return null\n }\n\n const data = incomingData as Record<string, unknown>\n const target = data.target\n\n if (!Array.isArray(data.docsToMove) || data.docsToMove.length !== 1) {\n return null\n }\n\n if (data.newKeyWillBe !== 'greater' && data.newKeyWillBe !== 'less') {\n return null\n }\n\n if (typeof data.orderableFieldName !== 'string' || data.orderableFieldName.length === 0) {\n return null\n }\n\n if (!target || typeof target !== 'object' || Array.isArray(target)) {\n return null\n }\n\n const targetData = target as Record<string, unknown>\n const movedID = normalizeID(data.docsToMove[0])\n const targetID = normalizeID(targetData.id)\n\n if (!movedID || !targetID) {\n return null\n }\n\n const key = hasOwnProperty(targetData, 'key') ? targetData.key : null\n\n if (key !== null && key !== undefined && typeof key !== 'string') {\n return null\n }\n\n return {\n docsToMove: [movedID],\n frontendOrder: normalizeFrontendOrder(data.frontendOrder),\n newKeyWillBe: data.newKeyWillBe,\n orderableFieldName: data.orderableFieldName,\n target: {\n id: targetID,\n key: key || null,\n },\n }\n}\n\nasync function readBodyFromRequest(\n req: PayloadRequest,\n): Promise<{ body: null | ReorderDocumentRequestBody; lastAttempt: null | RawBodyAttempt }> {\n let lastAttempt: null | RawBodyAttempt = null\n\n if (req.data !== undefined && req.data !== null) {\n lastAttempt = { raw: req.data, source: 'req.data' }\n const directBody = normalizeReorderDocumentBody(req.data)\n\n if (directBody) {\n return { body: directBody, lastAttempt }\n }\n }\n\n if (typeof req.json === 'function') {\n try {\n const raw = await req.json()\n lastAttempt = { raw, source: 'req.json' }\n const jsonBody = normalizeReorderDocumentBody(raw)\n\n if (jsonBody) {\n return { body: jsonBody, lastAttempt }\n }\n } catch {\n // Fall through to the text-based fallback when the runtime does not hydrate req.data.\n }\n }\n\n if (typeof req.text === 'function') {\n try {\n const raw = await req.text()\n lastAttempt = { raw, source: 'req.text' }\n const textBody = normalizeReorderDocumentBody(raw)\n\n if (textBody) {\n return { body: textBody, lastAttempt }\n }\n } catch {\n return { body: null, lastAttempt }\n }\n }\n\n return { body: null, lastAttempt }\n}\n\nfunction getParentScopeWhere(args: {\n parentFieldSlug: string\n parentID: null | number | string\n}): Where {\n const { parentFieldSlug, parentID } = args\n\n return {\n [parentFieldSlug]: {\n equals: parentID,\n },\n } as Where\n}\n\nfunction getOrderableKey(doc: PageTreeSourceDoc | undefined, orderableFieldName: string) {\n const value = doc?.[orderableFieldName]\n\n return typeof value === 'string' && value.length > 0 ? value : null\n}\n\nfunction getDiagnosticDocString(value: unknown, locale?: string): null | string {\n if (typeof value === 'string' && value.length > 0) {\n return value\n }\n\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n return null\n }\n\n const localizedValue = value as Record<string, unknown>\n const localeValue = locale ? localizedValue[locale] : undefined\n\n if (typeof localeValue === 'string' && localeValue.length > 0) {\n return localeValue\n }\n\n const firstString = Object.values(localizedValue).find(\n (entry): entry is string => typeof entry === 'string' && entry.length > 0,\n )\n\n return firstString ?? null\n}\n\nfunction getBackendOrderEntry(args: {\n doc: PageTreeSourceDoc\n index: number\n locale?: string\n orderableFieldName: string\n}): ReorderBackendOrderEntry {\n const { doc, index, locale, orderableFieldName } = args\n\n return {\n slug: getDiagnosticDocString(doc.slug, locale),\n index,\n orderKey: getOrderableKey(doc, orderableFieldName),\n status: getDiagnosticDocString(doc._status, locale),\n }\n}\n\nfunction getMainRowOrderSnapshot(\n snapshot: null | Record<string, unknown>,\n orderableFieldName: string,\n): { orderKey: null | string; status: null | string } | null {\n if (!snapshot) {\n return null\n }\n\n return {\n orderKey: normalizeOptionalString(snapshot[orderableFieldName]),\n status: normalizeOptionalString(snapshot._status),\n }\n}\n\nasync function readBackendSiblingOrder(args: {\n collectionSlug: string\n draft?: boolean\n orderableFieldName: string\n parentScopeWhere: Where\n req: PayloadRequest\n}): Promise<ReorderBackendOrderEntry[]> {\n const { collectionSlug, draft, orderableFieldName, parentScopeWhere, req } = args\n const locale = getRequestedLocale(req)\n\n try {\n const result = await req.payload.find({\n collection: collectionSlug as never,\n depth: 0,\n draft: draft as never,\n limit: 250,\n locale: locale as never,\n overrideAccess: true,\n pagination: false,\n req,\n sort: orderableFieldName,\n where: parentScopeWhere as never,\n } as never)\n\n return (result.docs as unknown as PageTreeSourceDoc[]).map((doc, index) =>\n getBackendOrderEntry({\n doc,\n index,\n locale,\n orderableFieldName,\n }),\n )\n } catch {\n return []\n }\n}\n\nfunction getOrderValuesBetween(args: {\n adjacentDocKey: null | string\n docsToMoveLength: number\n movedBoundaryKey: null | string\n newKeyWillBe: ReorderDocumentRequestBody['newKeyWillBe']\n targetKey: string\n}): { orderValues: string[]; usedMovedKeyBoundary: boolean } {\n const { adjacentDocKey, docsToMoveLength, movedBoundaryKey, newKeyWillBe, targetKey } = args\n const orderValues =\n newKeyWillBe === 'greater'\n ? generateNKeysBetween(targetKey, adjacentDocKey, docsToMoveLength)\n : generateNKeysBetween(adjacentDocKey, targetKey, docsToMoveLength)\n\n if (orderValues[0] !== movedBoundaryKey) {\n return { orderValues, usedMovedKeyBoundary: false }\n }\n\n if (newKeyWillBe === 'greater' && movedBoundaryKey && movedBoundaryKey > targetKey) {\n return {\n orderValues: generateNKeysBetween(targetKey, movedBoundaryKey, docsToMoveLength),\n usedMovedKeyBoundary: true,\n }\n }\n\n if (newKeyWillBe === 'less' && movedBoundaryKey && movedBoundaryKey < targetKey) {\n return {\n orderValues: generateNKeysBetween(movedBoundaryKey, targetKey, docsToMoveLength),\n usedMovedKeyBoundary: true,\n }\n }\n\n return { orderValues, usedMovedKeyBoundary: false }\n}\n\nasync function readLatestVersion(args: {\n collectionSlug: string\n id: number | string\n req: PayloadRequest\n}): Promise<null | VersionRecord> {\n const { id, collectionSlug, req } = args\n const versions = await req.payload.db.findVersions({\n collection: collectionSlug as never,\n limit: 1,\n pagination: false,\n req,\n sort: '-updatedAt',\n where: {\n latest: {\n equals: true,\n },\n parent: {\n equals: id,\n },\n },\n } as never)\n const latestVersion = versions.docs[0] as undefined | VersionRecord\n\n if (!latestVersion?.version) {\n return null\n }\n\n return latestVersion\n}\n\nasync function updateLatestVersionOrder(args: {\n collectionSlug: string\n id: number | string\n orderableFieldName: string\n orderValue: string\n req: PayloadRequest\n}): Promise<boolean> {\n const { id, collectionSlug, orderableFieldName, orderValue, req } = args\n const latestVersion = await readLatestVersion({\n id,\n collectionSlug,\n req,\n })\n\n if (!latestVersion?.id || !latestVersion.version) {\n return false\n }\n\n await req.payload.db.updateVersion({\n id: latestVersion.id as never,\n collection: collectionSlug as never,\n locale: getRequestedLocale(req) as never,\n req,\n returning: false,\n versionData: {\n createdAt: latestVersion.createdAt,\n latest: latestVersion.latest,\n parent: id,\n publishedLocale: latestVersion.publishedLocale,\n updatedAt: latestVersion.updatedAt,\n version: {\n ...latestVersion.version,\n [orderableFieldName]: orderValue,\n },\n },\n } as never)\n\n return true\n}\n\nasync function updateOrderValueSilently(args: {\n collectionSlug: string\n hasDrafts: boolean\n id: number | string\n orderableFieldName: string\n orderValue: string\n req: PayloadRequest\n}): Promise<{ updatedDraftVersion: boolean }> {\n const { id, collectionSlug, hasDrafts, orderableFieldName, orderValue, req } = args\n\n await req.payload.db.updateOne({\n id: id as never,\n collection: collectionSlug as never,\n data: {\n [orderableFieldName]: orderValue,\n updatedAt: null,\n },\n locale: getRequestedLocale(req) as never,\n req,\n returning: false,\n } as never)\n\n const updatedDraftVersion = hasDrafts\n ? await updateLatestVersionOrder({\n id,\n collectionSlug,\n orderableFieldName,\n orderValue,\n req,\n })\n : false\n\n return {\n updatedDraftVersion,\n }\n}\n\nasync function initializeMissingOrderKeys(args: {\n collectionSlug: string\n diagnostics: Diagnostics\n flow: string\n hasDrafts: boolean\n orderableFieldName: string\n parentScopeWhere: Where\n req: PayloadRequest\n}): Promise<Response> {\n const { collectionSlug, diagnostics, flow, hasDrafts, orderableFieldName, parentScopeWhere, req } =\n args\n const existingOrderedDocs = await req.payload.find({\n collection: collectionSlug as never,\n depth: 0,\n draft: hasDrafts ? true : undefined,\n limit: 1,\n locale: getRequestedLocale(req) as never,\n overrideAccess: true,\n pagination: false,\n req,\n select: { [orderableFieldName]: true } as never,\n sort: `-${orderableFieldName}`,\n where: combineWhereConstraints([\n {\n [orderableFieldName]: {\n exists: true,\n },\n },\n parentScopeWhere,\n ]) as never,\n } as never)\n const missingOrderDocs = await req.payload.find({\n collection: collectionSlug as never,\n depth: 0,\n draft: hasDrafts ? true : undefined,\n limit: 0,\n locale: getRequestedLocale(req) as never,\n overrideAccess: true,\n pagination: false,\n req,\n select: { [orderableFieldName]: true } as never,\n where: combineWhereConstraints([\n {\n [orderableFieldName]: {\n exists: false,\n },\n },\n parentScopeWhere,\n ]) as never,\n } as never)\n const lastOrderValue = getOrderableKey(\n existingOrderedDocs.docs[0] as unknown as PageTreeSourceDoc | undefined,\n orderableFieldName,\n )\n const orderValues = generateNKeysBetween(lastOrderValue, null, missingOrderDocs.docs.length)\n\n for (const [index, doc] of (missingOrderDocs.docs as unknown as PageTreeSourceDoc[]).entries()) {\n const docID = doc.id\n const orderValue = orderValues[index]\n\n if (\n orderValue &&\n (typeof docID === 'number' || typeof docID === 'string')\n ) {\n await updateOrderValueSilently({\n id: docID,\n collectionSlug,\n hasDrafts,\n orderableFieldName,\n orderValue,\n req,\n })\n }\n }\n\n diagnostics.log({\n collection: collectionSlug,\n data: {\n initializedCount: missingOrderDocs.docs.length,\n orderableFieldName,\n },\n flow,\n level: 'info',\n message: 'reorder endpoint initialized missing order keys',\n source: 'reorder-endpoint:initial-migration',\n })\n\n return respond(200, {\n message: 'initial migration',\n success: true,\n })\n}\n\nexport function createReorderPageEndpoint(args: {\n collectionSlug: string\n diagnostics: Diagnostics\n orderableFieldName: string\n parentFieldSlug: string\n}): Endpoint {\n const { collectionSlug, diagnostics, orderableFieldName, parentFieldSlug } = args\n const snapshotFields = [...SNAPSHOT_FIELDS, parentFieldSlug, orderableFieldName]\n\n return {\n handler: async (req) => {\n const movedIDFromRoute = normalizeID(req.routeParams?.id)\n\n if (!movedIDFromRoute) {\n return respond(400, {\n message: 'Document ID was not specified.',\n })\n }\n\n const { body, lastAttempt } = await readBodyFromRequest(req)\n\n if (\n !body ||\n body.orderableFieldName !== orderableFieldName ||\n body.docsToMove[0] !== movedIDFromRoute\n ) {\n if (diagnostics.enabled) {\n diagnostics.log({\n collection: collectionSlug,\n data: {\n movedID: movedIDFromRoute,\n rawBody: lastAttempt?.raw ?? null,\n rawBodySource: lastAttempt?.source ?? null,\n },\n flow: createFlowID('reorder-endpoint'),\n level: 'warn',\n message: 'reorder endpoint rejected request body',\n source: 'reorder-endpoint:body-rejected',\n })\n }\n\n return respond(400, {\n message: 'A valid reorder request is required.',\n })\n }\n\n if (body.target.id === movedIDFromRoute) {\n return respond(400, {\n message: 'Document is already in that position.',\n })\n }\n\n const movedID = toCollectionID({\n id: movedIDFromRoute,\n collectionSlug,\n req,\n })\n const targetID = toCollectionID({\n id: body.target.id,\n collectionSlug,\n req,\n })\n const accessError = await assertUpdateAccess({\n id: movedID,\n collectionSlug,\n data: {},\n req,\n })\n\n if (accessError) {\n return accessError\n }\n\n const flow = createFlowID('reorder-endpoint')\n const reorderStart = Date.now()\n const hasDrafts = collectionHasDrafts({ collectionSlug, req })\n\n if (!req.context) {\n req.context = {}\n }\n\n // A reorder only writes the order key, never publishing state, so it\n // always carries the deploy opt-out flag.\n ;(req.context as Record<string, unknown>)[pageTreeMoveContextKey] = true\n ;(req.context as Record<string, unknown>)[pageTreeWriteContextKey] = true\n ;(req.context as Record<string, unknown>)[DIAGNOSTICS_FLOW_CONTEXT_KEY] = flow\n\n const relatedDocsResult = await req.payload.find({\n collection: collectionSlug as never,\n depth: 0,\n draft: hasDrafts ? true : undefined,\n limit: 2,\n locale: getRequestedLocale(req) as never,\n overrideAccess: true,\n req,\n where: {\n id: {\n in: [movedID, targetID],\n },\n },\n } as never)\n const docsByID = new Map(\n (relatedDocsResult.docs as unknown as PageTreeSourceDoc[]).map((doc) => [\n stringifyDocID(doc.id),\n doc,\n ]),\n )\n const movedDoc = docsByID.get(movedIDFromRoute)\n const targetDoc = docsByID.get(body.target.id)\n\n if (!movedDoc) {\n return respond(404, {\n message: 'Document not found.',\n })\n }\n\n if (!targetDoc) {\n return respond(400, {\n message: 'Target document not found.',\n })\n }\n\n const movedParentID = getDocParentID(movedDoc, parentFieldSlug)\n const targetParentID = getDocParentID(targetDoc, parentFieldSlug)\n\n if (movedParentID !== targetParentID) {\n return respond(400, {\n message: 'Documents can only be reordered within the same parent.',\n })\n }\n\n const parentScopeWhere = getParentScopeWhere({\n parentFieldSlug,\n parentID:\n movedParentID === null\n ? null\n : toCollectionID({\n id: movedParentID,\n collectionSlug,\n req,\n }),\n })\n\n if (!body.target.key) {\n return initializeMissingOrderKeys({\n collectionSlug,\n diagnostics,\n flow,\n hasDrafts,\n orderableFieldName,\n parentScopeWhere,\n req,\n })\n }\n\n const beforeSnapshot = await readMainRowSnapshot({\n id: movedID,\n collectionSlug,\n fields: snapshotFields,\n req,\n })\n const backendDraftOrderBefore = diagnostics.enabled\n ? await readBackendSiblingOrder({\n collectionSlug,\n draft: hasDrafts ? true : undefined,\n orderableFieldName,\n parentScopeWhere,\n req,\n })\n : null\n const backendMainOrderBefore = diagnostics.enabled\n ? await readBackendSiblingOrder({\n collectionSlug,\n draft: false,\n orderableFieldName,\n parentScopeWhere,\n req,\n })\n : null\n const adjacentDoc = await req.payload.find({\n collection: collectionSlug as never,\n depth: 0,\n draft: hasDrafts ? true : undefined,\n limit: 1,\n locale: getRequestedLocale(req) as never,\n overrideAccess: true,\n pagination: false,\n req,\n select: { [orderableFieldName]: true } as never,\n sort: body.newKeyWillBe === 'greater' ? orderableFieldName : `-${orderableFieldName}`,\n where: combineWhereConstraints([\n {\n [orderableFieldName]: {\n [body.newKeyWillBe === 'greater' ? 'greater_than' : 'less_than']: body.target.key,\n },\n },\n parentScopeWhere,\n ]) as never,\n } as never)\n const adjacentDocKey = getOrderableKey(\n adjacentDoc.docs[0] as unknown as PageTreeSourceDoc | undefined,\n orderableFieldName,\n )\n const movedDocKey = getOrderableKey(movedDoc, orderableFieldName)\n const movedSlug = getDiagnosticDocString(movedDoc.slug, getRequestedLocale(req))\n const targetSlug = getDiagnosticDocString(targetDoc.slug, getRequestedLocale(req))\n const movedMainRowKey =\n typeof beforeSnapshot?.[orderableFieldName] === 'string' &&\n beforeSnapshot[orderableFieldName].length > 0\n ? beforeSnapshot[orderableFieldName]\n : movedDocKey\n const { orderValues, usedMovedKeyBoundary } = getOrderValuesBetween({\n adjacentDocKey,\n docsToMoveLength: body.docsToMove.length,\n movedBoundaryKey: movedMainRowKey,\n newKeyWillBe: body.newKeyWillBe,\n targetKey: body.target.key,\n })\n const orderValue = orderValues[0]\n\n if (!orderValue) {\n return respond(500, {\n message: 'Could not generate a new order key.',\n })\n }\n\n if (diagnostics.enabled) {\n diagnostics.log({\n collection: collectionSlug,\n data: {\n adjacentDocKey,\n backendOrderBefore: {\n draft: backendDraftOrderBefore,\n main: backendMainOrderBefore,\n },\n frontendOrder: body.frontendOrder ?? null,\n mainRowBefore: getMainRowOrderSnapshot(beforeSnapshot, orderableFieldName),\n movedDocKey,\n movedMainRowKey,\n movedSlug,\n newKeyWillBe: body.newKeyWillBe,\n orderableFieldName,\n orderValue,\n target: {\n slug: targetSlug,\n key: body.target.key,\n },\n usedMovedKeyBoundary,\n },\n flow,\n level: 'info',\n message: 'reorder endpoint entering: order key update only',\n source: 'reorder-endpoint:enter',\n })\n }\n\n try {\n const updateResult = await updateOrderValueSilently({\n id: movedID,\n collectionSlug,\n hasDrafts,\n orderableFieldName,\n orderValue,\n req,\n })\n\n if (diagnostics.enabled) {\n const afterSnapshot = await readMainRowSnapshot({\n id: movedID,\n collectionSlug,\n fields: snapshotFields,\n req,\n })\n const backendDraftOrderAfter = await readBackendSiblingOrder({\n collectionSlug,\n draft: hasDrafts ? true : undefined,\n orderableFieldName,\n parentScopeWhere,\n req,\n })\n const backendMainOrderAfter = await readBackendSiblingOrder({\n collectionSlug,\n draft: false,\n orderableFieldName,\n parentScopeWhere,\n req,\n })\n\n diagnostics.log({\n collection: collectionSlug,\n data: {\n backendOrderAfter: {\n draft: backendDraftOrderAfter,\n main: backendMainOrderAfter,\n },\n durMs: Date.now() - reorderStart,\n mainRowAfter: getMainRowOrderSnapshot(afterSnapshot, orderableFieldName),\n movedSlug,\n orderValue,\n updatedDraftVersion: updateResult.updatedDraftVersion,\n },\n flow,\n level: 'info',\n message: 'reorder endpoint order key update succeeded',\n source: 'reorder-endpoint:ok',\n })\n }\n } catch (err) {\n const error = err as { data?: unknown; message?: string; name?: string } & Error\n\n diagnostics.log({\n collection: collectionSlug,\n data: {\n name: error?.name,\n data: error?.data ?? null,\n durMs: Date.now() - reorderStart,\n message: error?.message,\n movedSlug,\n },\n flow,\n level: 'error',\n message: `reorder endpoint order key update failed: ${error?.message ?? 'unknown error'}`,\n source: 'reorder-endpoint:error',\n })\n\n throw err\n }\n\n return respond(200, {\n movedID: movedIDFromRoute,\n orderValues,\n success: true,\n })\n },\n method: 'post',\n path: '/:id/reorder',\n }\n}\n"],"names":["combineWhereConstraints","generateNKeysBetween","pageTreeMoveContextKey","pageTreeWriteContextKey","createFlowID","DIAGNOSTICS_FLOW_CONTEXT_KEY","readMainRowSnapshot","getDocParentID","stringifyDocID","assertUpdateAccess","collectionHasDrafts","getRequestedLocale","normalizeID","respond","toCollectionID","SNAPSHOT_FIELDS","hasOwnProperty","value","key","Object","prototype","call","normalizeOptionalString","length","normalizeFrontendOrderEntry","fallbackIndex","Array","isArray","data","slug","index","Number","isFinite","orderKey","normalizeFrontendOrder","undefined","before","after","slice","map","entry","filter","Boolean","activeSlug","moveFromIndex","moveToIndex","newAfterRowSlug","newBeforeRowSlug","sort","targetSlug","normalizeReorderDocumentBody","incomingData","JSON","parse","target","docsToMove","newKeyWillBe","orderableFieldName","targetData","movedID","targetID","id","frontendOrder","readBodyFromRequest","req","lastAttempt","raw","source","directBody","body","json","jsonBody","text","textBody","getParentScopeWhere","args","parentFieldSlug","parentID","equals","getOrderableKey","doc","getDiagnosticDocString","locale","localizedValue","localeValue","firstString","values","find","getBackendOrderEntry","status","_status","getMainRowOrderSnapshot","snapshot","readBackendSiblingOrder","collectionSlug","draft","parentScopeWhere","result","payload","collection","depth","limit","overrideAccess","pagination","where","docs","getOrderValuesBetween","adjacentDocKey","docsToMoveLength","movedBoundaryKey","targetKey","orderValues","usedMovedKeyBoundary","readLatestVersion","versions","db","findVersions","latest","parent","latestVersion","version","updateLatestVersionOrder","orderValue","updateVersion","returning","versionData","createdAt","publishedLocale","updatedAt","updateOrderValueSilently","hasDrafts","updateOne","updatedDraftVersion","initializeMissingOrderKeys","diagnostics","flow","existingOrderedDocs","select","exists","missingOrderDocs","lastOrderValue","entries","docID","log","initializedCount","level","message","success","createReorderPageEndpoint","snapshotFields","handler","movedIDFromRoute","routeParams","enabled","rawBody","rawBodySource","accessError","reorderStart","Date","now","context","relatedDocsResult","in","docsByID","Map","movedDoc","get","targetDoc","movedParentID","targetParentID","beforeSnapshot","fields","backendDraftOrderBefore","backendMainOrderBefore","adjacentDoc","movedDocKey","movedSlug","movedMainRowKey","backendOrderBefore","main","mainRowBefore","updateResult","afterSnapshot","backendDraftOrderAfter","backendMainOrderAfter","backendOrderAfter","durMs","mainRowAfter","err","error","name","method","path"],"mappings":"AAEA,SAASA,uBAAuB,EAAEC,oBAAoB,QAAQ,iBAAgB;AAE9E,SACEC,sBAAsB,EAEtBC,uBAAuB,QAClB,cAAa;AACpB,SACEC,YAAY,EAEZC,4BAA4B,EAC5BC,mBAAmB,QACd,8BAA6B;AACpC,SAASC,cAAc,EAAEC,cAAc,QAAQ,2BAA0B;AACzE,SACEC,kBAAkB,EAClBC,mBAAmB,EACnBC,kBAAkB,EAClBC,WAAW,EACXC,OAAO,EACPC,cAAc,QACT,cAAa;AAqDpB,MAAMC,kBAAkB;IAAC;CAAU;AAEnC,SAASC,eAAeC,KAAa,EAAEC,GAAgB;IACrD,OAAOC,OAA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C;oBACF;oBAEAsE,YAAYS,GAAG,CAAC;wBACd5C,YAAYL;wBACZlE,MAAM;4BACJ6J,mBAAmB;gCACjB1F,OAAOwF;gCACPJ,MAAMK;4BACR;4BACAE,OAAO5B,KAAKC,GAAG,KAAKF;4BACpB8B,cAAchG,wBAAwB2F,eAAe7H;4BACrDuH;4BACAtD;4BACAU,qBAAqBiD,aAAajD,mBAAmB;wBACvD;wBACAG;wBACAU,OAAO;wBACPC,SAAS;wBACT/E,QAAQ;oBACV;gBACF;YACF,EAAE,OAAOyH,KAAK;gBACZ,MAAMC,QAAQD;gBAEdtD,YAAYS,GAAG,CAAC;oBACd5C,YAAYL;oBACVlE,MAAM;wBACJkK,MAAMD,OAAOC;wBACblK,MAAMiK,OAAOjK,QAAQ;wBACrB8J,OAAO5B,KAAKC,GAAG,KAAKF;wBACpBX,SAAS2C,OAAO3C;wBAChB8B;oBACF;oBACFzC;oBACAU,OAAO;oBACPC,SAAS,CAAC,0CAA0C,EAAE2C,OAAO3C,WAAW,iBAAiB;oBACzF/E,QAAQ;gBACV;gBAEA,MAAMyH;YACR;YAEA,OAAO/K,QAAQ,KAAK;gBAClB8C,SAAS4F;gBACTxC;gBACAoC,SAAS;YACX;QACF;QACA4C,QAAQ;QACRC,MAAM;IACR;AACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
export type PayloadCollectionLike = {
|
|
3
|
+
config?: {
|
|
4
|
+
access?: {
|
|
5
|
+
update?: ((args: Record<string, unknown>) => boolean | Promise<boolean | Record<string, unknown>> | Record<string, unknown>) | undefined;
|
|
6
|
+
};
|
|
7
|
+
versions?: {
|
|
8
|
+
drafts?: {
|
|
9
|
+
autosave?: boolean | Record<string, unknown>;
|
|
10
|
+
} | boolean;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
customIDType?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function getPayloadCollection({ collectionSlug, req, }: {
|
|
16
|
+
collectionSlug: string;
|
|
17
|
+
req: PayloadRequest;
|
|
18
|
+
}): PayloadCollectionLike | undefined;
|
|
19
|
+
export declare function getRequestedLocale(req: PayloadRequest): string | undefined;
|
|
20
|
+
export declare function collectionHasDrafts(args: {
|
|
21
|
+
collectionSlug: string;
|
|
22
|
+
req: PayloadRequest;
|
|
23
|
+
}): boolean;
|
|
24
|
+
export declare function collectionHasAutosaveDrafts(args: {
|
|
25
|
+
collectionSlug: string;
|
|
26
|
+
req: PayloadRequest;
|
|
27
|
+
}): boolean;
|
|
28
|
+
export declare function normalizeID(value: unknown): null | string;
|
|
29
|
+
export declare function respond(status: number, body: Record<string, unknown>): Response;
|
|
30
|
+
export declare function toCollectionID(args: {
|
|
31
|
+
collectionSlug: string;
|
|
32
|
+
id: string;
|
|
33
|
+
req: PayloadRequest;
|
|
34
|
+
}): number | string;
|
|
35
|
+
export declare function assertUpdateAccess(args: {
|
|
36
|
+
collectionSlug: string;
|
|
37
|
+
data: Record<string, unknown>;
|
|
38
|
+
id: number | string;
|
|
39
|
+
req: PayloadRequest;
|
|
40
|
+
}): Promise<null | Response>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { stringifyDocID } from '../utilities/pageTree.js';
|
|
2
|
+
export function getPayloadCollection({ collectionSlug, req }) {
|
|
3
|
+
return req.payload.collections[collectionSlug];
|
|
4
|
+
}
|
|
5
|
+
export function getRequestedLocale(req) {
|
|
6
|
+
return req.locale && req.locale !== 'all' ? req.locale : undefined;
|
|
7
|
+
}
|
|
8
|
+
export function collectionHasDrafts(args) {
|
|
9
|
+
return Boolean(getPayloadCollection(args)?.config?.versions?.drafts);
|
|
10
|
+
}
|
|
11
|
+
export function collectionHasAutosaveDrafts(args) {
|
|
12
|
+
const drafts = getPayloadCollection(args)?.config?.versions?.drafts;
|
|
13
|
+
if (!drafts || drafts === true) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return Boolean(drafts.autosave);
|
|
17
|
+
}
|
|
18
|
+
export function normalizeID(value) {
|
|
19
|
+
if (value === null || value === undefined || value === '') {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
if (typeof value === 'number' || typeof value === 'string') {
|
|
23
|
+
return stringifyDocID(value);
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
export function respond(status, body) {
|
|
28
|
+
return Response.json(body, {
|
|
29
|
+
status
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export function toCollectionID(args) {
|
|
33
|
+
const { id, collectionSlug, req } = args;
|
|
34
|
+
const collection = getPayloadCollection({
|
|
35
|
+
collectionSlug,
|
|
36
|
+
req
|
|
37
|
+
});
|
|
38
|
+
const idType = collection?.customIDType ?? req.payload.db.defaultIDType;
|
|
39
|
+
return idType === 'number' ? Number(id) : id;
|
|
40
|
+
}
|
|
41
|
+
export async function assertUpdateAccess(args) {
|
|
42
|
+
const { id, collectionSlug, data, req } = args;
|
|
43
|
+
const collection = getPayloadCollection({
|
|
44
|
+
collectionSlug,
|
|
45
|
+
req
|
|
46
|
+
});
|
|
47
|
+
const updateAccess = collection?.config?.access?.update;
|
|
48
|
+
if (!updateAccess) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const accessResult = await updateAccess({
|
|
52
|
+
id: id,
|
|
53
|
+
data: data,
|
|
54
|
+
req
|
|
55
|
+
});
|
|
56
|
+
if (accessResult === false) {
|
|
57
|
+
return respond(403, {
|
|
58
|
+
message: req.i18n.t('error:unauthorized')
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (accessResult && typeof accessResult === 'object') {
|
|
62
|
+
const matchingDocs = await req.payload.find({
|
|
63
|
+
collection: collectionSlug,
|
|
64
|
+
depth: 0,
|
|
65
|
+
draft: collectionHasDrafts({
|
|
66
|
+
collectionSlug,
|
|
67
|
+
req
|
|
68
|
+
}) ? true : undefined,
|
|
69
|
+
limit: 1,
|
|
70
|
+
locale: getRequestedLocale(req),
|
|
71
|
+
overrideAccess: true,
|
|
72
|
+
req,
|
|
73
|
+
where: {
|
|
74
|
+
and: [
|
|
75
|
+
{
|
|
76
|
+
id: {
|
|
77
|
+
equals: id
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
accessResult
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
if (matchingDocs.docs.length === 0) {
|
|
85
|
+
return respond(403, {
|
|
86
|
+
message: req.i18n.t('error:unauthorized')
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/shared.ts"],"sourcesContent":["import type { PayloadRequest, Where } from 'payload'\n\nimport { stringifyDocID } from '../utilities/pageTree.js'\n\nexport type PayloadCollectionLike = {\n config?: {\n access?: {\n update?:\n | ((\n args: Record<string, unknown>,\n ) => boolean | Promise<boolean | Record<string, unknown>> | Record<string, unknown>)\n | undefined\n }\n versions?: {\n drafts?:\n | {\n autosave?: boolean | Record<string, unknown>\n }\n | boolean\n }\n }\n customIDType?: string\n}\n\nexport function getPayloadCollection({\n collectionSlug,\n req,\n}: {\n collectionSlug: string\n req: PayloadRequest\n}): PayloadCollectionLike | undefined {\n return (req.payload.collections as unknown as Record<string, PayloadCollectionLike | undefined>)[\n collectionSlug\n ]\n}\n\nexport function getRequestedLocale(req: PayloadRequest): string | undefined {\n return req.locale && req.locale !== 'all' ? req.locale : undefined\n}\n\nexport function collectionHasDrafts(args: {\n collectionSlug: string\n req: PayloadRequest\n}): boolean {\n return Boolean(getPayloadCollection(args)?.config?.versions?.drafts)\n}\n\nexport function collectionHasAutosaveDrafts(args: {\n collectionSlug: string\n req: PayloadRequest\n}): boolean {\n const drafts = getPayloadCollection(args)?.config?.versions?.drafts\n\n if (!drafts || drafts === true) {\n return false\n }\n\n return Boolean(drafts.autosave)\n}\n\nexport function normalizeID(value: unknown): null | string {\n if (value === null || value === undefined || value === '') {\n return null\n }\n\n if (typeof value === 'number' || typeof value === 'string') {\n return stringifyDocID(value)\n }\n\n return null\n}\n\nexport function respond(status: number, body: Record<string, unknown>) {\n return Response.json(body, { status })\n}\n\nexport function toCollectionID(args: {\n collectionSlug: string\n id: string\n req: PayloadRequest\n}): number | string {\n const { id, collectionSlug, req } = args\n const collection = getPayloadCollection({ collectionSlug, req })\n const idType = collection?.customIDType ?? req.payload.db.defaultIDType\n\n return idType === 'number' ? Number(id) : id\n}\n\nexport async function assertUpdateAccess(args: {\n collectionSlug: string\n data: Record<string, unknown>\n id: number | string\n req: PayloadRequest\n}): Promise<null | Response> {\n const { id, collectionSlug, data, req } = args\n const collection = getPayloadCollection({ collectionSlug, req })\n const updateAccess = collection?.config?.access?.update\n\n if (!updateAccess) {\n return null\n }\n\n const accessResult = await updateAccess({\n id: id as never,\n data: data as never,\n req,\n })\n\n if (accessResult === false) {\n return respond(403, {\n message: req.i18n.t('error:unauthorized'),\n })\n }\n\n if (accessResult && typeof accessResult === 'object') {\n const matchingDocs = await req.payload.find({\n collection: collectionSlug as never,\n depth: 0,\n draft: collectionHasDrafts({ collectionSlug, req }) ? true : undefined,\n limit: 1,\n locale: getRequestedLocale(req) as never,\n overrideAccess: true,\n req,\n where: {\n and: [\n {\n id: {\n equals: id,\n },\n },\n accessResult as Where,\n ],\n } as never,\n } as never)\n\n if (matchingDocs.docs.length === 0) {\n return respond(403, {\n message: req.i18n.t('error:unauthorized'),\n })\n }\n }\n\n return null\n}\n"],"names":["stringifyDocID","getPayloadCollection","collectionSlug","req","payload","collections","getRequestedLocale","locale","undefined","collectionHasDrafts","args","Boolean","config","versions","drafts","collectionHasAutosaveDrafts","autosave","normalizeID","value","respond","status","body","Response","json","toCollectionID","id","collection","idType","customIDType","db","defaultIDType","Number","assertUpdateAccess","data","updateAccess","access","update","accessResult","message","i18n","t","matchingDocs","find","depth","draft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EvB,cAAc,EAAE+B,IAAI,EAAE9B,GAAG,EAAE,GAAGO;IAC1C,MAAMgB,aAAazB,qBAAqB;QAAEC;QAAgBC;IAAI;IAC9D,MAAM+B,eAAeR,YAAYd,QAAQuB,QAAQC;IAEjD,IAAI,CAACF,cAAc;QACjB,OAAO;IACT;IAEA,MAAMG,eAAe,MAAMH,aAAa;QACtCT,IAAIA;QACJQ,MAAMA;QACN9B;IACF;IAEA,IAAIkC,iBAAiB,OAAO;QAC1B,OAAOlB,QAAQ,KAAK;YAClBmB,SAASnC,IAAIoC,IAAI,CAACC,CAAC,CAAC;QACtB;IACF;IAEA,IAAIH,gBAAgB,OAAOA,iBAAiB,UAAU;QACpD,MAAMI,eAAe,MAAMtC,IAAIC,OAAO,CAACsC,IAAI,CAAC;YAC1ChB,YAAYxB;YACZyC,OAAO;YACPC,OAAOnC,oBAAoB;gBAAEP;gBAAgBC;YAAI,KAAK,OAAOK;YAC7DqC,OAAO;YACPtC,QAAQD,mBAAmBH;YAC3B2C,gBAAgB;YAChB3C;YACA4C,OAAO;gBACLC,KAAK;oBACH;wBACEvB,IAAI;4BACFwB,QAAQxB;wBACV;oBACF;oBACAY;iBACD;YACH;QACF;QAEA,IAAII,aAAaS,IAAI,CAACC,MAAM,KAAK,GAAG;YAClC,OAAOhC,QAAQ,KAAK;gBAClBmB,SAASnC,IAAIoC,IAAI,CAACC,CAAC,CAAC;YACtB;QACF;IACF;IAEA,OAAO;AACT"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createMovePageEndpoint } from './endpoints/createMovePageEndpoint.js';
|
|
2
|
-
import {
|
|
2
|
+
import { createReorderPageEndpoint } from './endpoints/createReorderPageEndpoint.js';
|
|
3
|
+
import { nestedDocsPageTreePluginCustomKey, pageTreeWriteContextKey } from './types.js';
|
|
3
4
|
import { normalizeNestedDocsPageTreePluginBadgeConfig } from './utilities/badgeConfig.js';
|
|
5
|
+
import { DIAGNOSTICS_FLOW_CONTEXT_KEY, createFlowID, projectField, resolveDiagnostics } from './utilities/diagnostics.js';
|
|
4
6
|
const DEFAULT_BREADCRUMBS_FIELD_SLUG = 'breadcrumbs';
|
|
5
7
|
const DEFAULT_HOME_INDICATOR_COLLECTIONS = [
|
|
6
8
|
'pages'
|
|
@@ -8,25 +10,81 @@ const DEFAULT_HOME_INDICATOR_COLLECTIONS = [
|
|
|
8
10
|
const DEFAULT_LIMIT = 100;
|
|
9
11
|
const DEFAULT_PARENT_FIELD_SLUG = 'parent';
|
|
10
12
|
const PAGE_TREE_LIST_VIEW_PATH = 'payload-nested-docs-page-tree/rsc#NestedDocsPageTreeListView';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
if (!req.context) {
|
|
25
|
-
req.context = {};
|
|
13
|
+
/**
|
|
14
|
+
* When diagnostics are enabled this hook emits a structured event for each
|
|
15
|
+
* page-tree-tagged create/update, including a small before/after diff of the
|
|
16
|
+
* fields most relevant to tree publish/draft regressions.
|
|
17
|
+
*/ function createDiagnosticsAfterChangeHook(args) {
|
|
18
|
+
const { collectionSlug, diagnostics, orderableFieldName, parentFieldSlug } = args;
|
|
19
|
+
const snapshotFields = [
|
|
20
|
+
'_status',
|
|
21
|
+
parentFieldSlug
|
|
22
|
+
];
|
|
23
|
+
if (orderableFieldName) {
|
|
24
|
+
snapshotFields.push(orderableFieldName);
|
|
26
25
|
}
|
|
27
|
-
req
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
return async ({ doc, operation, previousDoc, req })=>{
|
|
27
|
+
if (!diagnostics.enabled) {
|
|
28
|
+
return doc;
|
|
29
|
+
}
|
|
30
|
+
if (operation !== 'update' && operation !== 'create') {
|
|
31
|
+
return doc;
|
|
32
|
+
}
|
|
33
|
+
// Gated on the write flag, not the deploy opt-out flag: a published move
|
|
34
|
+
// withholds the latter, and that is the case most worth tracing.
|
|
35
|
+
if (!req.context?.[pageTreeWriteContextKey]) {
|
|
36
|
+
return doc;
|
|
37
|
+
}
|
|
38
|
+
const docID = doc?.id;
|
|
39
|
+
if (typeof docID !== 'string' && typeof docID !== 'number') {
|
|
40
|
+
return doc;
|
|
41
|
+
}
|
|
42
|
+
const flow = req.context?.[DIAGNOSTICS_FLOW_CONTEXT_KEY] ?? createFlowID('page-tree-change');
|
|
43
|
+
const before = {};
|
|
44
|
+
const after = {};
|
|
45
|
+
const changed = [];
|
|
46
|
+
for (const field of snapshotFields){
|
|
47
|
+
const beforeValue = projectField(previousDoc?.[field]);
|
|
48
|
+
const afterValue = projectField(doc?.[field]);
|
|
49
|
+
before[field] = beforeValue;
|
|
50
|
+
after[field] = afterValue;
|
|
51
|
+
if (JSON.stringify(beforeValue) !== JSON.stringify(afterValue)) {
|
|
52
|
+
changed.push(field);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
diagnostics.log({
|
|
56
|
+
collection: collectionSlug,
|
|
57
|
+
data: {
|
|
58
|
+
after,
|
|
59
|
+
before,
|
|
60
|
+
changed,
|
|
61
|
+
docID: String(docID),
|
|
62
|
+
operation
|
|
63
|
+
},
|
|
64
|
+
flow,
|
|
65
|
+
level: 'info',
|
|
66
|
+
message: `${operation} on ${collectionSlug}#${String(docID)}`,
|
|
67
|
+
source: 'page-tree-change:after'
|
|
68
|
+
});
|
|
69
|
+
const beforeStatus = previousDoc?._status;
|
|
70
|
+
const afterStatus = doc?._status;
|
|
71
|
+
if (beforeStatus === 'published' && afterStatus !== 'published') {
|
|
72
|
+
diagnostics.log({
|
|
73
|
+
collection: collectionSlug,
|
|
74
|
+
data: {
|
|
75
|
+
afterStatus,
|
|
76
|
+
beforeStatus,
|
|
77
|
+
docID: String(docID)
|
|
78
|
+
},
|
|
79
|
+
flow,
|
|
80
|
+
level: 'warn',
|
|
81
|
+
message: `Published doc was demoted to "${String(afterStatus ?? 'missing')}" by a page-tree operation. Inspect the move-endpoint:enter/ok snapshots in flow ${flow} to confirm whether the main row was touched.`,
|
|
82
|
+
source: 'page-tree-change:status-flip'
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return doc;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
30
88
|
function getTopLevelField(collection, fieldName) {
|
|
31
89
|
return collection.fields.find((field)=>'name' in field && field.name === fieldName);
|
|
32
90
|
}
|
|
@@ -67,9 +125,13 @@ function validateTargetCollection(args) {
|
|
|
67
125
|
throw new Error(`payload-nested-docs-page-tree cannot own the "${collection.slug}" list view because the collection already defines a custom admin.components.views.list.Component.`);
|
|
68
126
|
}
|
|
69
127
|
const existingMoveEndpoint = getCollectionEndpoints(collection).find((endpoint)=>endpoint.path === '/:id/move');
|
|
128
|
+
const existingReorderEndpoint = getCollectionEndpoints(collection).find((endpoint)=>endpoint.path === '/:id/reorder');
|
|
70
129
|
if (existingMoveEndpoint) {
|
|
71
130
|
throw new Error(`payload-nested-docs-page-tree cannot add the move endpoint to "${collection.slug}" because the collection already defines POST /:id/move.`);
|
|
72
131
|
}
|
|
132
|
+
if (existingReorderEndpoint) {
|
|
133
|
+
throw new Error(`payload-nested-docs-page-tree cannot add the reorder endpoint to "${collection.slug}" because the collection already defines POST /:id/reorder.`);
|
|
134
|
+
}
|
|
73
135
|
}
|
|
74
136
|
function buildCollectionCustom(args) {
|
|
75
137
|
const { badges, breadcrumbsFieldSlug, defaultLimit, hideBreadcrumbs, homeIndicator, parentFieldSlug } = args;
|
|
@@ -100,7 +162,9 @@ export const nestedDocsPageTreePlugin = (pluginOptions)=>(config)=>{
|
|
|
100
162
|
const defaultLimit = pluginOptions.defaultLimit ?? DEFAULT_LIMIT;
|
|
101
163
|
const hideBreadcrumbs = pluginOptions.hideBreadcrumbs ?? true;
|
|
102
164
|
const parentFieldSlug = pluginOptions.parentFieldSlug ?? DEFAULT_PARENT_FIELD_SLUG;
|
|
165
|
+
const publishOnMove = pluginOptions.publishOnMove ?? false;
|
|
103
166
|
const badges = normalizeNestedDocsPageTreePluginBadgeConfig(pluginOptions.badges);
|
|
167
|
+
const diagnostics = resolveDiagnostics(pluginOptions.diagnostics);
|
|
104
168
|
const homeIndicatorCollectionSlugs = getHomeIndicatorCollectionSlugs(pluginOptions.homeIndicator);
|
|
105
169
|
const targetedCollectionSlugs = new Set(pluginOptions.collections);
|
|
106
170
|
if (!config.collections?.length) {
|
|
@@ -117,6 +181,13 @@ export const nestedDocsPageTreePlugin = (pluginOptions)=>(config)=>{
|
|
|
117
181
|
collection,
|
|
118
182
|
parentFieldSlug
|
|
119
183
|
});
|
|
184
|
+
const orderableFieldName = typeof collection.orderable === 'string' ? collection.orderable : collection.orderable ? '_order' : null;
|
|
185
|
+
const diagnosticsAfterChangeHook = diagnostics.enabled ? createDiagnosticsAfterChangeHook({
|
|
186
|
+
collectionSlug: collection.slug,
|
|
187
|
+
diagnostics,
|
|
188
|
+
orderableFieldName,
|
|
189
|
+
parentFieldSlug
|
|
190
|
+
}) : null;
|
|
120
191
|
return {
|
|
121
192
|
...collection,
|
|
122
193
|
admin: {
|
|
@@ -153,21 +224,33 @@ export const nestedDocsPageTreePlugin = (pluginOptions)=>(config)=>{
|
|
|
153
224
|
...getCollectionEndpoints(collection),
|
|
154
225
|
createMovePageEndpoint({
|
|
155
226
|
collectionSlug: collection.slug,
|
|
156
|
-
|
|
157
|
-
|
|
227
|
+
diagnostics,
|
|
228
|
+
parentFieldSlug,
|
|
229
|
+
publishOnMove
|
|
230
|
+
}),
|
|
231
|
+
...orderableFieldName ? [
|
|
232
|
+
createReorderPageEndpoint({
|
|
233
|
+
collectionSlug: collection.slug,
|
|
234
|
+
diagnostics,
|
|
235
|
+
orderableFieldName,
|
|
236
|
+
parentFieldSlug
|
|
237
|
+
})
|
|
238
|
+
] : []
|
|
158
239
|
],
|
|
159
240
|
fields: collection.fields.map((field)=>patchBreadcrumbField({
|
|
160
241
|
breadcrumbsFieldSlug,
|
|
161
242
|
field,
|
|
162
243
|
hideBreadcrumbs
|
|
163
244
|
})),
|
|
164
|
-
hooks:
|
|
245
|
+
hooks: {
|
|
165
246
|
...collection.hooks ?? {},
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
247
|
+
...diagnosticsAfterChangeHook ? {
|
|
248
|
+
afterChange: [
|
|
249
|
+
...collection.hooks?.afterChange ?? [],
|
|
250
|
+
diagnosticsAfterChangeHook
|
|
251
|
+
]
|
|
252
|
+
} : {}
|
|
253
|
+
}
|
|
171
254
|
};
|
|
172
255
|
});
|
|
173
256
|
const missingCollections = pluginOptions.collections.filter((collectionSlug)=>!foundCollectionSlugs.has(collectionSlug));
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionBeforeChangeHook, CollectionConfig, Config } from 'payload'\r\n\r\nimport { createMovePageEndpoint } from './endpoints/createMovePageEndpoint.js'\r\nimport type {\r\n NestedDocsPageTreePluginCollectionCustom,\r\n NestedDocsPageTreePluginConfig,\r\n} from './types.js'\r\nimport {\r\n nestedDocsPageTreePluginCustomKey,\r\n pageTreeMoveContextKey,\r\n pageTreeMoveRequestHeader,\r\n pageTreeMoveRequestHeaderValue,\r\n} from './types.js'\r\nimport { normalizeNestedDocsPageTreePluginBadgeConfig } from './utilities/badgeConfig.js'\r\n\r\nconst DEFAULT_BREADCRUMBS_FIELD_SLUG = 'breadcrumbs'\r\nconst DEFAULT_HOME_INDICATOR_COLLECTIONS = ['pages']\r\nconst DEFAULT_LIMIT = 100\r\nconst DEFAULT_PARENT_FIELD_SLUG = 'parent'\r\nconst PAGE_TREE_LIST_VIEW_PATH =\r\n 'payload-nested-docs-page-tree/rsc#NestedDocsPageTreeListView'\r\ntype CollectionEndpoint = NonNullable<Exclude<CollectionConfig['endpoints'], false>>[number]\r\n\r\n// Page-tree owns parent moves, so those pass Local API context directly.\r\n// Reorders go through Payload's shared /api/reorder endpoint; this hook\r\n// bridges the plugin-owned request signal into the same hook context flag.\r\n// The bridge requires an authenticated request — the header alone is not a\r\n// trust boundary, but rejecting anonymous callers closes the only path that\r\n// could set the flag without already holding update access.\r\nconst tagPageTreeMoveContextHook: CollectionBeforeChangeHook = ({ data, req }) => {\r\n if (req.headers?.get(pageTreeMoveRequestHeader) !== pageTreeMoveRequestHeaderValue) {\r\n return data\r\n }\r\n\r\n if (!req.user) {\r\n return data\r\n }\r\n\r\n if (!req.context) {\r\n req.context = {}\r\n }\r\n\r\n req.context[pageTreeMoveContextKey] = true\r\n\r\n return data\r\n}\r\n\r\nfunction getTopLevelField(\r\n collection: Pick<CollectionConfig, 'fields'>,\r\n fieldName: string,\r\n) {\r\n return collection.fields.find((field) => 'name' in field && field.name === fieldName)\r\n}\r\n\r\nfunction getCollectionEndpoints(collection: CollectionConfig): CollectionEndpoint[] {\r\n return Array.isArray(collection.endpoints) ? [...collection.endpoints] : []\r\n}\r\n\r\nfunction patchBreadcrumbField<TField extends CollectionConfig['fields'][number]>(args: {\r\n breadcrumbsFieldSlug: string\r\n field: TField\r\n hideBreadcrumbs: boolean\r\n}): TField {\r\n const { breadcrumbsFieldSlug, field, hideBreadcrumbs } = args\r\n\r\n if (!('name' in field) || field.name !== breadcrumbsFieldSlug) {\r\n return field\r\n }\r\n\r\n return {\r\n ...field,\r\n admin: {\r\n ...(field.admin ?? {}),\r\n hidden: hideBreadcrumbs,\r\n },\r\n } as TField\r\n}\r\n\r\nfunction validateTargetCollection(args: {\r\n breadcrumbsFieldSlug: string\r\n collection: CollectionConfig\r\n parentFieldSlug: string\r\n}) {\r\n const { breadcrumbsFieldSlug, collection, parentFieldSlug } = args\r\n\r\n if (typeof collection.admin?.useAsTitle !== 'string' || collection.admin.useAsTitle.includes('.')) {\r\n throw new Error(\r\n `payload-nested-docs-page-tree requires \"${collection.slug}\" to define a top-level admin.useAsTitle field.`,\r\n )\r\n }\r\n\r\n if (!getTopLevelField(collection, collection.admin.useAsTitle)) {\r\n throw new Error(\r\n `payload-nested-docs-page-tree could not find the useAsTitle field \"${collection.admin.useAsTitle}\" on \"${collection.slug}\".`,\r\n )\r\n }\r\n\r\n if (!getTopLevelField(collection, parentFieldSlug)) {\r\n throw new Error(\r\n `payload-nested-docs-page-tree requires \"${collection.slug}\" to already define the nested docs parent field \"${parentFieldSlug}\". Register @payloadcms/plugin-nested-docs before payload-nested-docs-page-tree.`,\r\n )\r\n }\r\n\r\n if (!getTopLevelField(collection, breadcrumbsFieldSlug)) {\r\n throw new Error(\r\n `payload-nested-docs-page-tree requires \"${collection.slug}\" to already define the nested docs breadcrumbs field \"${breadcrumbsFieldSlug}\". Register @payloadcms/plugin-nested-docs before payload-nested-docs-page-tree.`,\r\n )\r\n }\r\n\r\n const existingListView = collection.admin?.components?.views?.list?.Component\r\n\r\n if (existingListView && existingListView !== PAGE_TREE_LIST_VIEW_PATH) {\r\n throw new Error(\r\n `payload-nested-docs-page-tree cannot own the \"${collection.slug}\" list view because the collection already defines a custom admin.components.views.list.Component.`,\r\n )\r\n }\r\n\r\n const existingMoveEndpoint = getCollectionEndpoints(collection).find(\r\n (endpoint) => endpoint.path === '/:id/move',\r\n )\r\n\r\n if (existingMoveEndpoint) {\r\n throw new Error(\r\n `payload-nested-docs-page-tree cannot add the move endpoint to \"${collection.slug}\" because the collection already defines POST /:id/move.`,\r\n )\r\n }\r\n}\r\n\r\nfunction buildCollectionCustom(args: {\r\n badges: NestedDocsPageTreePluginCollectionCustom['badges']\r\n breadcrumbsFieldSlug: string\r\n defaultLimit: number\r\n hideBreadcrumbs: boolean\r\n homeIndicator: NestedDocsPageTreePluginCollectionCustom['homeIndicator']\r\n parentFieldSlug: string\r\n}): NestedDocsPageTreePluginCollectionCustom {\r\n const {\r\n badges,\r\n breadcrumbsFieldSlug,\r\n defaultLimit,\r\n hideBreadcrumbs,\r\n homeIndicator,\r\n parentFieldSlug,\r\n } = args\r\n\r\n return {\r\n badges,\r\n breadcrumbsFieldSlug,\r\n defaultLimit,\r\n hideBreadcrumbs,\r\n homeIndicator,\r\n parentFieldSlug,\r\n }\r\n}\r\n\r\nfunction getHomeIndicatorCollectionSlugs(\r\n homeIndicator: NestedDocsPageTreePluginConfig['homeIndicator'],\r\n): Set<string> {\r\n if (homeIndicator === false) {\r\n return new Set()\r\n }\r\n\r\n return new Set(homeIndicator?.collections ?? DEFAULT_HOME_INDICATOR_COLLECTIONS)\r\n}\r\n\r\nexport type {\r\n NestedDocsPageTreePluginBadgeConfig,\r\n NestedDocsPageTreePluginBadgeMap,\r\n NestedDocsPageTreePluginBadgeStatus,\r\n NestedDocsPageTreePluginConfig,\r\n NestedDocsPageTreePluginHomeIndicatorConfig,\r\n PageTreeMoveContext,\r\n} from './types.js'\r\n\r\nexport { pageTreeMoveContextKey } from './types.js'\r\n\r\nexport const nestedDocsPageTreePlugin =\r\n (pluginOptions: NestedDocsPageTreePluginConfig) =>\r\n (config: Config): Config => {\r\n if (!pluginOptions.collections?.length) {\r\n throw new Error('payload-nested-docs-page-tree requires at least one collection slug.')\r\n }\r\n\r\n if (pluginOptions.disabled) {\r\n return config\r\n }\r\n\r\n const breadcrumbsFieldSlug =\r\n pluginOptions.breadcrumbsFieldSlug ?? DEFAULT_BREADCRUMBS_FIELD_SLUG\r\n const defaultLimit = pluginOptions.defaultLimit ?? DEFAULT_LIMIT\r\n const hideBreadcrumbs = pluginOptions.hideBreadcrumbs ?? true\r\n const parentFieldSlug = pluginOptions.parentFieldSlug ?? DEFAULT_PARENT_FIELD_SLUG\r\n const badges = normalizeNestedDocsPageTreePluginBadgeConfig(pluginOptions.badges)\r\n const homeIndicatorCollectionSlugs = getHomeIndicatorCollectionSlugs(\r\n pluginOptions.homeIndicator,\r\n )\r\n const targetedCollectionSlugs = new Set<string>(pluginOptions.collections)\r\n\r\n if (!config.collections?.length) {\r\n throw new Error('payload-nested-docs-page-tree could not find any collections to patch.')\r\n }\r\n\r\n const foundCollectionSlugs = new Set<string>()\r\n const nextCollections = config.collections.map((collection) => {\r\n if (!targetedCollectionSlugs.has(collection.slug)) {\r\n return collection\r\n }\r\n\r\n foundCollectionSlugs.add(collection.slug)\r\n validateTargetCollection({\r\n breadcrumbsFieldSlug,\r\n collection,\r\n parentFieldSlug,\r\n })\r\n\r\n return {\r\n ...collection,\r\n admin: {\r\n ...(collection.admin ?? {}),\r\n components: {\r\n ...(collection.admin?.components ?? {}),\r\n views: {\r\n ...(collection.admin?.components?.views ?? {}),\r\n list: {\r\n ...(collection.admin?.components?.views?.list ?? {}),\r\n Component: PAGE_TREE_LIST_VIEW_PATH,\r\n },\r\n },\r\n },\r\n pagination: {\r\n ...(collection.admin?.pagination ?? {}),\r\n defaultLimit:\r\n collection.admin?.pagination?.defaultLimit === undefined\r\n ? defaultLimit\r\n : collection.admin.pagination.defaultLimit,\r\n },\r\n },\r\n custom: {\r\n ...(collection.custom ?? {}),\r\n [nestedDocsPageTreePluginCustomKey]: buildCollectionCustom({\r\n badges,\r\n breadcrumbsFieldSlug,\r\n defaultLimit,\r\n hideBreadcrumbs,\r\n homeIndicator: {\r\n enabled: homeIndicatorCollectionSlugs.has(collection.slug),\r\n },\r\n parentFieldSlug,\r\n }),\r\n },\r\n endpoints: [\r\n ...getCollectionEndpoints(collection),\r\n createMovePageEndpoint({\r\n collectionSlug: collection.slug,\r\n parentFieldSlug,\r\n }),\r\n ],\r\n fields: collection.fields.map((field) =>\r\n patchBreadcrumbField({\r\n breadcrumbsFieldSlug,\r\n field,\r\n hideBreadcrumbs,\r\n }),\r\n ),\r\n hooks: collection.orderable\r\n ? {\r\n ...(collection.hooks ?? {}),\r\n beforeChange: [\r\n tagPageTreeMoveContextHook,\r\n ...(collection.hooks?.beforeChange ?? []),\r\n ],\r\n }\r\n : collection.hooks,\r\n }\r\n })\r\n\r\n const missingCollections = pluginOptions.collections.filter(\r\n (collectionSlug) => !foundCollectionSlugs.has(collectionSlug),\r\n )\r\n\r\n if (missingCollections.length > 0) {\r\n throw new Error(\r\n `payload-nested-docs-page-tree could not find the following collections: ${missingCollections.join(', ')}`,\r\n )\r\n }\r\n\r\n return {\r\n ...config,\r\n collections: nextCollections as CollectionConfig[],\r\n }\r\n }\r\n"],"names":["createMovePageEndpoint","nestedDocsPageTreePluginCustomKey","pageTreeMoveContextKey","pageTreeMoveRequestHeader","pageTreeMoveRequestHeaderValue","normalizeNestedDocsPageTreePluginBadgeConfig","DEFAULT_BREADCRUMBS_FIELD_SLUG","DEFAULT_HOME_INDICATOR_COLLECTIONS","DEFAULT_LIMIT","DEFAULT_PARENT_FIELD_SLUG","PAGE_TREE_LIST_VIEW_PATH","tagPageTreeMoveContextHook","data","req","headers","get","user","context","getTopLevelField","collection","fieldName","fields","find","field","name","getCollectionEndpoints","Array","isArray","endpoints","patchBreadcrumbField","args","breadcrumbsFieldSlug","hideBreadcrumbs","admin","hidden","validateTargetCollection","parentFieldSlug","useAsTitle","includes","Error","slug","existingListView","components","views","list","Component","existingMoveEndpoint","endpoint","path","buildCollectionCustom","badges","defaultLimit","homeIndicator","getHomeIndicatorCollectionSlugs","Set","collections","nestedDocsPageTreePlugin","pluginOptions","config","length","disabled","homeIndicatorCollectionSlugs","targetedCollectionSlugs","foundCollectionSlugs","nextCollections","map","has","add","pagination","undefined","custom","enabled","collectionSlug","hooks","orderable","beforeChange","missingCollections","filter","join"],"mappings":"AAEA,SAASA,sBAAsB,QAAQ,wCAAuC;AAK9E,SACEC,iCAAiC,EACjCC,sBAAsB,EACtBC,yBAAyB,EACzBC,8BAA8B,QACzB,aAAY;AACnB,SAASC,4CAA4C,QAAQ,6BAA4B;AAEzF,MAAMC,iCAAiC;AACvC,MAAMC,qCAAqC;IAAC;CAAQ;AACpD,MAAMC,gBAAgB;AACtB,MAAMC,4BAA4B;AAClC,MAAMC,2BACJ;AAGF,yEAAyE;AACzE,wEAAwE;AACxE,2EAA2E;AAC3E,2EAA2E;AAC3E,4EAA4E;AAC5E,4DAA4D;AAC5D,MAAMC,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,WAAWc,KAAK,EAAEmC,cAAc,CAAC,CAAC;wBACtCjB,cACEhC,WAAWc,KAAK,EAAEmC,YAAYjB,iBAAiBkB,YAC3ClB,eACAhC,WAAWc,KAAK,CAACmC,UAAU,CAACjB,YAAY;oBAChD;gBACF;gBACAmB,QAAQ;oBACN,GAAInD,WAAWmD,MAAM,IAAI,CAAC,CAAC;oBAC3B,CAACrE,kCAAkC,EAAEgD,sBAAsB;wBACzDC;wBACAnB;wBACAoB;wBACAnB;wBACAoB,eAAe;4BACbmB,SAASV,6BAA6BK,GAAG,CAAC/C,WAAWqB,IAAI;wBAC3D;wBACAJ;oBACF;gBACF;gBACAR,WAAW;uBACNH,uBAAuBN;oBAC1BnB,uBAAuB;wBACrBwE,gBAAgBrD,WAAWqB,IAAI;wBAC/BJ;oBACF;iBACD;gBACDf,QAAQF,WAAWE,MAAM,CAAC4C,GAAG,CAAC,CAAC1C,QAC7BM,qBAAqB;wBACnBE;wBACAR;wBACAS;oBACF;gBAEFyC,OAAOtD,WAAWuD,SAAS,GACvB;oBACE,GAAIvD,WAAWsD,KAAK,IAAI,CAAC,CAAC;oBAC1BE,cAAc;wBACZhE;2BACIQ,WAAWsD,KAAK,EAAEE,gBAAgB,EAAE;qBACzC;gBACH,IACAxD,WAAWsD,KAAK;YACtB;QACF;QAEA,MAAMG,qBAAqBnB,cAAcF,WAAW,CAACsB,MAAM,CACzD,CAACL,iBAAmB,CAACT,qBAAqBG,GAAG,CAACM;QAGhD,IAAII,mBAAmBjB,MAAM,GAAG,GAAG;YACjC,MAAM,IAAIpB,MACR,CAAC,wEAAwE,EAAEqC,mBAAmBE,IAAI,CAAC,OAAO;QAE9G;QAEA,OAAO;YACL,GAAGpB,MAAM;YACTH,aAAaS;QACf;IACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n CollectionAfterChangeHook,\n CollectionConfig,\n Config,\n} from 'payload'\n\nimport { createMovePageEndpoint } from './endpoints/createMovePageEndpoint.js'\nimport { createReorderPageEndpoint } from './endpoints/createReorderPageEndpoint.js'\nimport type {\n NestedDocsPageTreePluginCollectionCustom,\n NestedDocsPageTreePluginConfig,\n} from './types.js'\nimport { nestedDocsPageTreePluginCustomKey, pageTreeWriteContextKey } from './types.js'\nimport { normalizeNestedDocsPageTreePluginBadgeConfig } from './utilities/badgeConfig.js'\nimport {\n DIAGNOSTICS_FLOW_CONTEXT_KEY,\n type Diagnostics,\n createFlowID,\n projectField,\n resolveDiagnostics,\n} from './utilities/diagnostics.js'\n\nconst DEFAULT_BREADCRUMBS_FIELD_SLUG = 'breadcrumbs'\nconst DEFAULT_HOME_INDICATOR_COLLECTIONS = ['pages']\nconst DEFAULT_LIMIT = 100\nconst DEFAULT_PARENT_FIELD_SLUG = 'parent'\nconst PAGE_TREE_LIST_VIEW_PATH =\n 'payload-nested-docs-page-tree/rsc#NestedDocsPageTreeListView'\ntype CollectionEndpoint = NonNullable<Exclude<CollectionConfig['endpoints'], false>>[number]\n\n/**\n * When diagnostics are enabled this hook emits a structured event for each\n * page-tree-tagged create/update, including a small before/after diff of the\n * fields most relevant to tree publish/draft regressions.\n */\nfunction createDiagnosticsAfterChangeHook(args: {\n collectionSlug: string\n diagnostics: Diagnostics\n orderableFieldName: null | string\n parentFieldSlug: string\n}): CollectionAfterChangeHook {\n const { collectionSlug, diagnostics, orderableFieldName, parentFieldSlug } = args\n const snapshotFields: string[] = ['_status', parentFieldSlug]\n\n if (orderableFieldName) {\n snapshotFields.push(orderableFieldName)\n }\n\n return async ({ doc, operation, previousDoc, req }) => {\n if (!diagnostics.enabled) {\n return doc\n }\n\n if (operation !== 'update' && operation !== 'create') {\n return doc\n }\n\n // Gated on the write flag, not the deploy opt-out flag: a published move\n // withholds the latter, and that is the case most worth tracing.\n if (!req.context?.[pageTreeWriteContextKey]) {\n return doc\n }\n\n const docID = (doc as Record<string, unknown>)?.id\n\n if (typeof docID !== 'string' && typeof docID !== 'number') {\n return doc\n }\n\n const flow =\n (req.context?.[DIAGNOSTICS_FLOW_CONTEXT_KEY] as string | undefined) ??\n createFlowID('page-tree-change')\n const before: Record<string, unknown> = {}\n const after: Record<string, unknown> = {}\n const changed: string[] = []\n\n for (const field of snapshotFields) {\n const beforeValue = projectField((previousDoc as Record<string, unknown> | undefined)?.[field])\n const afterValue = projectField((doc as Record<string, unknown>)?.[field])\n\n before[field] = beforeValue\n after[field] = afterValue\n\n if (JSON.stringify(beforeValue) !== JSON.stringify(afterValue)) {\n changed.push(field)\n }\n }\n\n diagnostics.log({\n collection: collectionSlug,\n data: {\n after,\n before,\n changed,\n docID: String(docID),\n operation,\n },\n flow,\n level: 'info',\n message: `${operation} on ${collectionSlug}#${String(docID)}`,\n source: 'page-tree-change:after',\n })\n\n const beforeStatus = (previousDoc as Record<string, unknown> | undefined)?._status\n const afterStatus = (doc as Record<string, unknown>)?._status\n\n if (beforeStatus === 'published' && afterStatus !== 'published') {\n diagnostics.log({\n collection: collectionSlug,\n data: {\n afterStatus,\n beforeStatus,\n docID: String(docID),\n },\n flow,\n level: 'warn',\n message: `Published doc was demoted to \"${String(afterStatus ?? 'missing')}\" by a page-tree operation. Inspect the move-endpoint:enter/ok snapshots in flow ${flow} to confirm whether the main row was touched.`,\n source: 'page-tree-change:status-flip',\n })\n }\n\n return doc\n }\n}\n\nfunction getTopLevelField(\n collection: Pick<CollectionConfig, 'fields'>,\n fieldName: string,\n) {\n return collection.fields.find((field) => 'name' in field && field.name === fieldName)\n}\n\nfunction getCollectionEndpoints(collection: CollectionConfig): CollectionEndpoint[] {\n return Array.isArray(collection.endpoints) ? [...collection.endpoints] : []\n}\n\nfunction patchBreadcrumbField<TField extends CollectionConfig['fields'][number]>(args: {\n breadcrumbsFieldSlug: string\n field: TField\n hideBreadcrumbs: boolean\n}): TField {\n const { breadcrumbsFieldSlug, field, hideBreadcrumbs } = args\n\n if (!('name' in field) || field.name !== breadcrumbsFieldSlug) {\n return field\n }\n\n return {\n ...field,\n admin: {\n ...(field.admin ?? {}),\n hidden: hideBreadcrumbs,\n },\n } as TField\n}\n\nfunction validateTargetCollection(args: {\n breadcrumbsFieldSlug: string\n collection: CollectionConfig\n parentFieldSlug: string\n}) {\n const { breadcrumbsFieldSlug, collection, parentFieldSlug } = args\n\n if (typeof collection.admin?.useAsTitle !== 'string' || collection.admin.useAsTitle.includes('.')) {\n throw new Error(\n `payload-nested-docs-page-tree requires \"${collection.slug}\" to define a top-level admin.useAsTitle field.`,\n )\n }\n\n if (!getTopLevelField(collection, collection.admin.useAsTitle)) {\n throw new Error(\n `payload-nested-docs-page-tree could not find the useAsTitle field \"${collection.admin.useAsTitle}\" on \"${collection.slug}\".`,\n )\n }\n\n if (!getTopLevelField(collection, parentFieldSlug)) {\n throw new Error(\n `payload-nested-docs-page-tree requires \"${collection.slug}\" to already define the nested docs parent field \"${parentFieldSlug}\". Register @payloadcms/plugin-nested-docs before payload-nested-docs-page-tree.`,\n )\n }\n\n if (!getTopLevelField(collection, breadcrumbsFieldSlug)) {\n throw new Error(\n `payload-nested-docs-page-tree requires \"${collection.slug}\" to already define the nested docs breadcrumbs field \"${breadcrumbsFieldSlug}\". Register @payloadcms/plugin-nested-docs before payload-nested-docs-page-tree.`,\n )\n }\n\n const existingListView = collection.admin?.components?.views?.list?.Component\n\n if (existingListView && existingListView !== PAGE_TREE_LIST_VIEW_PATH) {\n throw new Error(\n `payload-nested-docs-page-tree cannot own the \"${collection.slug}\" list view because the collection already defines a custom admin.components.views.list.Component.`,\n )\n }\n\n const existingMoveEndpoint = getCollectionEndpoints(collection).find(\n (endpoint) => endpoint.path === '/:id/move',\n )\n const existingReorderEndpoint = getCollectionEndpoints(collection).find(\n (endpoint) => endpoint.path === '/:id/reorder',\n )\n\n if (existingMoveEndpoint) {\n throw new Error(\n `payload-nested-docs-page-tree cannot add the move endpoint to \"${collection.slug}\" because the collection already defines POST /:id/move.`,\n )\n }\n\n if (existingReorderEndpoint) {\n throw new Error(\n `payload-nested-docs-page-tree cannot add the reorder endpoint to \"${collection.slug}\" because the collection already defines POST /:id/reorder.`,\n )\n }\n}\n\nfunction buildCollectionCustom(args: {\n badges: NestedDocsPageTreePluginCollectionCustom['badges']\n breadcrumbsFieldSlug: string\n defaultLimit: number\n hideBreadcrumbs: boolean\n homeIndicator: NestedDocsPageTreePluginCollectionCustom['homeIndicator']\n parentFieldSlug: string\n}): NestedDocsPageTreePluginCollectionCustom {\n const {\n badges,\n breadcrumbsFieldSlug,\n defaultLimit,\n hideBreadcrumbs,\n homeIndicator,\n parentFieldSlug,\n } = args\n\n return {\n badges,\n breadcrumbsFieldSlug,\n defaultLimit,\n hideBreadcrumbs,\n homeIndicator,\n parentFieldSlug,\n }\n}\n\nfunction getHomeIndicatorCollectionSlugs(\n homeIndicator: NestedDocsPageTreePluginConfig['homeIndicator'],\n): Set<string> {\n if (homeIndicator === false) {\n return new Set()\n }\n\n return new Set(homeIndicator?.collections ?? DEFAULT_HOME_INDICATOR_COLLECTIONS)\n}\n\nexport type {\n NestedDocsPageTreePluginBadgeConfig,\n NestedDocsPageTreePluginBadgeMap,\n NestedDocsPageTreePluginBadgeStatus,\n NestedDocsPageTreePluginConfig,\n NestedDocsPageTreePluginHomeIndicatorConfig,\n PageTreeMoveContext,\n} from './types.js'\n\nexport { pageTreeMoveContextKey } from './types.js'\n\nexport const nestedDocsPageTreePlugin =\n (pluginOptions: NestedDocsPageTreePluginConfig) =>\n (config: Config): Config => {\n if (!pluginOptions.collections?.length) {\n throw new Error('payload-nested-docs-page-tree requires at least one collection slug.')\n }\n\n if (pluginOptions.disabled) {\n return config\n }\n\n const breadcrumbsFieldSlug =\n pluginOptions.breadcrumbsFieldSlug ?? DEFAULT_BREADCRUMBS_FIELD_SLUG\n const defaultLimit = pluginOptions.defaultLimit ?? DEFAULT_LIMIT\n const hideBreadcrumbs = pluginOptions.hideBreadcrumbs ?? true\n const parentFieldSlug = pluginOptions.parentFieldSlug ?? DEFAULT_PARENT_FIELD_SLUG\n const publishOnMove = pluginOptions.publishOnMove ?? false\n const badges = normalizeNestedDocsPageTreePluginBadgeConfig(pluginOptions.badges)\n const diagnostics = resolveDiagnostics(pluginOptions.diagnostics)\n const homeIndicatorCollectionSlugs = getHomeIndicatorCollectionSlugs(\n pluginOptions.homeIndicator,\n )\n const targetedCollectionSlugs = new Set<string>(pluginOptions.collections)\n\n if (!config.collections?.length) {\n throw new Error('payload-nested-docs-page-tree could not find any collections to patch.')\n }\n\n const foundCollectionSlugs = new Set<string>()\n const nextCollections = config.collections.map((collection) => {\n if (!targetedCollectionSlugs.has(collection.slug)) {\n return collection\n }\n\n foundCollectionSlugs.add(collection.slug)\n validateTargetCollection({\n breadcrumbsFieldSlug,\n collection,\n parentFieldSlug,\n })\n const orderableFieldName =\n typeof collection.orderable === 'string'\n ? collection.orderable\n : collection.orderable\n ? '_order'\n : null\n const diagnosticsAfterChangeHook = diagnostics.enabled\n ? createDiagnosticsAfterChangeHook({\n collectionSlug: collection.slug,\n diagnostics,\n orderableFieldName,\n parentFieldSlug,\n })\n : null\n\n return {\n ...collection,\n admin: {\n ...(collection.admin ?? {}),\n components: {\n ...(collection.admin?.components ?? {}),\n views: {\n ...(collection.admin?.components?.views ?? {}),\n list: {\n ...(collection.admin?.components?.views?.list ?? {}),\n Component: PAGE_TREE_LIST_VIEW_PATH,\n },\n },\n },\n pagination: {\n ...(collection.admin?.pagination ?? {}),\n defaultLimit:\n collection.admin?.pagination?.defaultLimit === undefined\n ? defaultLimit\n : collection.admin.pagination.defaultLimit,\n },\n },\n custom: {\n ...(collection.custom ?? {}),\n [nestedDocsPageTreePluginCustomKey]: buildCollectionCustom({\n badges,\n breadcrumbsFieldSlug,\n defaultLimit,\n hideBreadcrumbs,\n homeIndicator: {\n enabled: homeIndicatorCollectionSlugs.has(collection.slug),\n },\n parentFieldSlug,\n }),\n },\n endpoints: [\n ...getCollectionEndpoints(collection),\n createMovePageEndpoint({\n collectionSlug: collection.slug,\n diagnostics,\n parentFieldSlug,\n publishOnMove,\n }),\n ...(orderableFieldName\n ? [\n createReorderPageEndpoint({\n collectionSlug: collection.slug,\n diagnostics,\n orderableFieldName,\n parentFieldSlug,\n }),\n ]\n : []),\n ],\n fields: collection.fields.map((field) =>\n patchBreadcrumbField({\n breadcrumbsFieldSlug,\n field,\n hideBreadcrumbs,\n }),\n ),\n hooks: {\n ...(collection.hooks ?? {}),\n ...(diagnosticsAfterChangeHook\n ? {\n afterChange: [\n ...(collection.hooks?.afterChange ?? []),\n diagnosticsAfterChangeHook,\n ],\n }\n : {}),\n },\n }\n })\n\n const missingCollections = pluginOptions.collections.filter(\n (collectionSlug) => !foundCollectionSlugs.has(collectionSlug),\n )\n\n if (missingCollections.length > 0) {\n throw new Error(\n `payload-nested-docs-page-tree could not find the following collections: ${missingCollections.join(', ')}`,\n )\n }\n\n return {\n ...config,\n collections: nextCollections as CollectionConfig[],\n }\n }\n"],"names":["createMovePageEndpoint","createReorderPageEndpoint","nestedDocsPageTreePluginCustomKey","pageTreeWriteContextKey","normalizeNestedDocsPageTreePluginBadgeConfig","DIAGNOSTICS_FLOW_CONTEXT_KEY","createFlowID","projectField","resolveDiagnostics","DEFAULT_BREADCRUMBS_FIELD_SLUG","DEFAULT_HOME_INDICATOR_COLLECTIONS","DEFAULT_LIMIT","DEFAULT_PARENT_FIELD_SLUG","PAGE_TREE_LIST_VIEW_PATH","createDiagnosticsAfterChangeHook","args","collectionSlug","diagnostics","orderableFieldName","parentFieldSlug","snapshotFields","push","doc","operation","previousDoc","req","enabled","context","docID","id","flow","before","after","changed","field","beforeValue","afterValue","JSON","stringify","log","collection","data","String","level","message","source","beforeStatus","_status","afterStatus","getTopLevelField","fieldName","fields","find","name","getCollectionEndpoints","Array","isArray","endpoints","patchBreadcrumbField","breadcrumbsFieldSlug","hideBreadcrumbs","admin","hidden","validateTargetCollection","useAsTitle","includes","Error","slug","existingListView","components","views","list","Component","existingMoveEndpoint","endpoint","path","existingReorderEndpoint","buildCollectionCustom","badges","defaultLimit","homeIndicator","getHomeIndicatorCollectionSlugs","Set","collections","pageTreeMoveContextKey","nestedDocsPageTreePlugin","pluginOptions","config","length","disabled","publishOnMove","homeIndicatorCollectionSlugs","targetedCollectionSlugs","foundCollectionSlugs","nextCollections","map","has","add","orderable","diagnosticsAfterChangeHook","pagination","undefined","custom","hooks","afterChange","missingCollections","filter","join"],"mappings":"AAMA,SAASA,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,yBAAyB,QAAQ,2CAA0C;AAKpF,SAASC,iCAAiC,EAAEC,uBAAuB,QAAQ,aAAY;AACvF,SAASC,4CAA4C,QAAQ,6BAA4B;AACzF,SACEC,4BAA4B,EAE5BC,YAAY,EACZC,YAAY,EACZC,kBAAkB,QACb,6BAA4B;AAEnC,MAAMC,iCAAiC;AACvC,MAAMC,qCAAqC;IAAC;CAAQ;AACpD,MAAMC,gBAAgB;AACtB,MAAMC,4BAA4B;AAClC,MAAMC,2BACJ;AAGF;;;;CAIC,GACD,SAASC,iCAAiCC,IAKzC;IACC,MAAM,EAAEC,cAAc,EAAEC,WAAW,EAAEC,kBAAkB,EAAEC,eAAe,EAAE,GAAGJ;IAC7E,MAAMK,iBAA2B;QAAC;QAAWD;KAAgB;IAE7D,IAAID,oBAAoB;QACtBE,eAAeC,IAAI,CAACH;IACtB;IAEA,OAAO,OAAO,EAAEI,GAAG,EAAEC,SAAS,EAAEC,WAAW,EAAEC,GAAG,EAAE;QAChD,IAAI,CAACR,YAAYS,OAAO,EAAE;YACxB,OAAOJ;QACT;QAEA,IAAIC,cAAc,YAAYA,cAAc,UAAU;YACpD,OAAOD;QACT;QAEA,yEAAyE;QACzE,iEAAiE;QACjE,IAAI,CAACG,IAAIE,OAAO,EAAE,CAACxB,wBAAwB,EAAE;YAC3C,OAAOmB;QACT;QAEA,MAAMM,QAASN,KAAiCO;QAEhD,IAAI,OAAOD,UAAU,YAAY,OAAOA,UAAU,UAAU;YAC1D,OAAON;QACT;QAEA,MAAMQ,OACJ,AAACL,IAAIE,OAAO,EAAE,CAACtB,6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AAM;YACTJ,aAAaW;QACf;IACF,EAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { CollectionSlug } from 'payload';
|
|
2
|
+
import type { NestedDocsPageTreePluginDiagnosticsConfig } from './utilities/diagnostics.js';
|
|
3
|
+
export type { NestedDocsPageTreePluginDiagnosticEvent, NestedDocsPageTreePluginDiagnosticsConfig, } from './utilities/diagnostics.js';
|
|
2
4
|
export declare const nestedDocsPageTreePluginBadgeStatuses: readonly ["published", "changed", "draft"];
|
|
3
5
|
export type NestedDocsPageTreePluginBadgeStatus = (typeof nestedDocsPageTreePluginBadgeStatuses)[number];
|
|
4
6
|
export type NestedDocsPageTreePluginBadgeMap = Partial<Record<NestedDocsPageTreePluginBadgeStatus, string>>;
|
|
@@ -21,10 +23,31 @@ export type NestedDocsPageTreePluginConfig = {
|
|
|
21
23
|
breadcrumbsFieldSlug?: string;
|
|
22
24
|
collections: CollectionSlug[];
|
|
23
25
|
defaultLimit?: number;
|
|
26
|
+
/**
|
|
27
|
+
* When set, the plugin emits structured diagnostic events for page-tree
|
|
28
|
+
* triggered moves, including before/after snapshots of the published main row.
|
|
29
|
+
* Disabled by default. Pass `true` to log to `console`, or pass an object
|
|
30
|
+
* with a custom `logger` to route events elsewhere.
|
|
31
|
+
*/
|
|
32
|
+
diagnostics?: NestedDocsPageTreePluginDiagnosticsConfig;
|
|
24
33
|
disabled?: boolean;
|
|
25
34
|
hideBreadcrumbs?: boolean;
|
|
26
35
|
homeIndicator?: NestedDocsPageTreePluginHomeIndicatorConfig;
|
|
27
36
|
parentFieldSlug?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Publish a hierarchy move immediately instead of staging it as a draft — but
|
|
39
|
+
* ONLY when the moved document had no unpublished changes before the move (its
|
|
40
|
+
* latest version is already published). A document with pending draft edits (a
|
|
41
|
+
* "changed" or draft-only doc) always stays staged, so in-progress edits are
|
|
42
|
+
* never published as a side effect of a move. Only affects collections with
|
|
43
|
+
* drafts enabled; collections without drafts move live regardless.
|
|
44
|
+
*
|
|
45
|
+
* Disabled by default: every move is staged as a draft and the live URL/path
|
|
46
|
+
* changes only when the document is next published.
|
|
47
|
+
*
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
50
|
+
publishOnMove?: boolean;
|
|
28
51
|
};
|
|
29
52
|
export type NestedDocsPageTreePluginCollectionCustom = {
|
|
30
53
|
badges: NestedDocsPageTreePluginResolvedBadgeConfig;
|
|
@@ -41,9 +64,31 @@ export type PageTreeSourceDoc = Record<string, unknown> & {
|
|
|
41
64
|
slug?: null | string;
|
|
42
65
|
};
|
|
43
66
|
export declare const nestedDocsPageTreePluginCustomKey = "nestedDocsPageTreePlugin";
|
|
67
|
+
/**
|
|
68
|
+
* Set on Payload's hook context for every page-tree write that leaves the
|
|
69
|
+
* published site unchanged: sibling reorders, and parent moves staged as
|
|
70
|
+
* drafts. Deploy/revalidate hooks read it to skip rebuilds they do not need.
|
|
71
|
+
*
|
|
72
|
+
* It is deliberately NOT set when `publishOnMove` publishes a move, because
|
|
73
|
+
* that move changed the live URL of the page and its descendants and the site
|
|
74
|
+
* does need rebuilding. That way one guard covers every configuration:
|
|
75
|
+
*
|
|
76
|
+
* ```ts
|
|
77
|
+
* if (req.context?.[pageTreeMoveContextKey]) return
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* Note the flag describes the *effect* of the write, not its kind - it is
|
|
81
|
+
* absent on published moves even though those are still page-tree moves. Use
|
|
82
|
+
* `pageTreeWriteContextKey` when you need "was this a page-tree write at all".
|
|
83
|
+
*/
|
|
44
84
|
export declare const pageTreeMoveContextKey = "pageTreeMove";
|
|
45
|
-
|
|
46
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Internal: set on every page-tree write regardless of whether it published.
|
|
87
|
+
* Diagnostics uses it so that published moves are still traced, which is the
|
|
88
|
+
* case most worth observing. Not part of the public API.
|
|
89
|
+
*/
|
|
90
|
+
export declare const pageTreeWriteContextKey = "pageTreeWrite";
|
|
47
91
|
export type PageTreeMoveContext = {
|
|
48
92
|
[pageTreeMoveContextKey]?: boolean;
|
|
93
|
+
[pageTreeWriteContextKey]?: boolean;
|
|
49
94
|
};
|