@basedigital/base-cms-payload-core 0.1.39 → 0.1.41

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.
Files changed (60) hide show
  1. package/dist/cms/collections/page-templates.collection.js +1 -1
  2. package/dist/cms/collections/page-templates.collection.js.map +1 -1
  3. package/dist/cms/collections/pages.collection.js +1 -1
  4. package/dist/cms/collections/pages.collection.js.map +1 -1
  5. package/dist/cms/collections/reusable-blocks.collection.js +1 -1
  6. package/dist/cms/collections/reusable-blocks.collection.js.map +1 -1
  7. package/dist/cms/fields/factory/create-layout-blocks-field.d.ts +2 -2
  8. package/dist/cms/fields/factory/create-layout-blocks-field.d.ts.map +1 -1
  9. package/dist/cms/fields/factory/create-layout-blocks-field.js +4 -8
  10. package/dist/cms/fields/factory/create-layout-blocks-field.js.map +1 -1
  11. package/dist/cms/fields/references/discover-field-references.d.ts.map +1 -1
  12. package/dist/cms/fields/references/discover-field-references.js +5 -0
  13. package/dist/cms/fields/references/discover-field-references.js.map +1 -1
  14. package/dist/cms/layout-blocks/create-layout-field.d.ts +13 -0
  15. package/dist/cms/layout-blocks/create-layout-field.d.ts.map +1 -0
  16. package/dist/cms/layout-blocks/create-layout-field.js +264 -0
  17. package/dist/cms/layout-blocks/create-layout-field.js.map +1 -0
  18. package/dist/cms/layout-blocks/layout-blocks.collection.d.ts +10 -0
  19. package/dist/cms/layout-blocks/layout-blocks.collection.d.ts.map +1 -0
  20. package/dist/cms/layout-blocks/layout-blocks.collection.js +57 -0
  21. package/dist/cms/layout-blocks/layout-blocks.collection.js.map +1 -0
  22. package/dist/cms/layout-blocks/layout-blocks.constants.d.ts +4 -0
  23. package/dist/cms/layout-blocks/layout-blocks.constants.d.ts.map +1 -0
  24. package/dist/cms/layout-blocks/layout-blocks.constants.js +5 -0
  25. package/dist/cms/layout-blocks/layout-blocks.constants.js.map +1 -0
  26. package/dist/cms/layout-blocks/layout-blocks.plugin.d.ts +4 -0
  27. package/dist/cms/layout-blocks/layout-blocks.plugin.d.ts.map +1 -0
  28. package/dist/cms/layout-blocks/layout-blocks.plugin.js +161 -0
  29. package/dist/cms/layout-blocks/layout-blocks.plugin.js.map +1 -0
  30. package/dist/cms/layout-blocks/layout-blocks.types.d.ts +23 -0
  31. package/dist/cms/layout-blocks/layout-blocks.types.d.ts.map +1 -0
  32. package/dist/cms/layout-blocks/layout-blocks.types.js +2 -0
  33. package/dist/cms/layout-blocks/layout-blocks.types.js.map +1 -0
  34. package/dist/cms/layout-blocks/layout-ref-diff.d.ts +2 -0
  35. package/dist/cms/layout-blocks/layout-ref-diff.d.ts.map +1 -0
  36. package/dist/cms/layout-blocks/layout-ref-diff.js +5 -0
  37. package/dist/cms/layout-blocks/layout-ref-diff.js.map +1 -0
  38. package/dist/cms/layout-blocks/scripts/layout-blocks-gc.d.ts +3 -0
  39. package/dist/cms/layout-blocks/scripts/layout-blocks-gc.d.ts.map +1 -0
  40. package/dist/cms/layout-blocks/scripts/layout-blocks-gc.js +37 -0
  41. package/dist/cms/layout-blocks/scripts/layout-blocks-gc.js.map +1 -0
  42. package/dist/cms/layout-blocks/services/layout-entry.repository.d.ts +74 -0
  43. package/dist/cms/layout-blocks/services/layout-entry.repository.d.ts.map +1 -0
  44. package/dist/cms/layout-blocks/services/layout-entry.repository.js +263 -0
  45. package/dist/cms/layout-blocks/services/layout-entry.repository.js.map +1 -0
  46. package/dist/cms/layout-blocks/utils/block-fields.d.ts +4 -0
  47. package/dist/cms/layout-blocks/utils/block-fields.d.ts.map +1 -0
  48. package/dist/cms/layout-blocks/utils/block-fields.js +51 -0
  49. package/dist/cms/layout-blocks/utils/block-fields.js.map +1 -0
  50. package/dist/cms/layout-blocks/utils/layout-content.d.ts +10 -0
  51. package/dist/cms/layout-blocks/utils/layout-content.d.ts.map +1 -0
  52. package/dist/cms/layout-blocks/utils/layout-content.js +82 -0
  53. package/dist/cms/layout-blocks/utils/layout-content.js.map +1 -0
  54. package/dist/cms/layout-blocks/utils/layout-entry-ids.d.ts +12 -0
  55. package/dist/cms/layout-blocks/utils/layout-entry-ids.d.ts.map +1 -0
  56. package/dist/cms/layout-blocks/utils/layout-entry-ids.js +36 -0
  57. package/dist/cms/layout-blocks/utils/layout-entry-ids.js.map +1 -0
  58. package/dist/services/i18n/get-content-translations.js +1 -1
  59. package/dist/services/i18n/get-content-translations.js.map +1 -1
  60. package/package.json +1 -1
@@ -0,0 +1,161 @@
1
+ import { createLayoutBlocksCollection } from './layout-blocks.collection.js';
2
+ import { LAYOUT_FIELD_NAME, LAYOUT_REF_CUSTOM_MARKER, LAYOUT_REF_FIELD_NAME } from './layout-blocks.constants.js';
3
+ import { deleteLayoutEntries, listOwnerLayoutEntries } from './services/layout-entry.repository.js';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ const GC_BIN_KEY = 'layout-blocks-gc';
7
+ const GC_SCRIPT_NAME = 'layout-blocks-gc';
8
+ const UNION_DB_NAME_PREFIX = 'lb_';
9
+ // Finds every collection that uses createLayoutField, checks its drafts config and attaches the owner-level hooks;
10
+ // adds the `layout-blocks` collection with the union of the owners' blocks and registers the `layout-blocks-gc` bin script.
11
+ // Must run on the final config: the union is taken from the virtual fields after createBaseCollections/mergeBlocks.
12
+ export function layoutBlocksPlugin() {
13
+ return function applyLayoutBlocksPlugin(config) {
14
+ const bin = [...(config.bin ?? []), { key: GC_BIN_KEY, scriptPath: resolveGcScriptPath(import.meta.url) }];
15
+ const collections = config.collections?.map(attachOwnerHooks);
16
+ const ownersBlocks = collectOwnersLayoutBlocks(collections ?? []);
17
+ if (!ownersBlocks) {
18
+ return { ...config, bin, collections };
19
+ }
20
+ assertNoLocalizedField(ownersBlocks);
21
+ return {
22
+ ...config,
23
+ bin,
24
+ collections: [...(collections ?? []), createLayoutBlocksCollection({ blocks: ownersBlocks })],
25
+ };
26
+ };
27
+ }
28
+ function attachOwnerHooks(collection) {
29
+ if (!findLayoutRefSiblings(collection.fields)) {
30
+ return collection;
31
+ }
32
+ assertAutosaveOnlyDrafts(collection);
33
+ return {
34
+ ...collection,
35
+ forceSelect: { ...collection.forceSelect, [LAYOUT_REF_FIELD_NAME]: true },
36
+ hooks: { ...collection.hooks, afterDelete: [...(collection.hooks?.afterDelete ?? []), deleteOwnerLayoutEntriesAfterDeleteHook] },
37
+ };
38
+ }
39
+ // Returns the field list that holds the owner's `layoutRef` (and so its virtual `layout`), walking unnamed containers only.
40
+ function findLayoutRefSiblings(fields) {
41
+ for (const field of fields) {
42
+ if (isLayoutRefField(field)) {
43
+ return fields;
44
+ }
45
+ for (const childFields of listUnnamedContainerFields(field)) {
46
+ const siblings = findLayoutRefSiblings(childFields);
47
+ if (siblings) {
48
+ return siblings;
49
+ }
50
+ }
51
+ }
52
+ return null;
53
+ }
54
+ function listUnnamedContainerFields(field) {
55
+ if (field.type === 'tabs') {
56
+ return field.tabs.filter((tab) => !('name' in tab && tab.name)).map((tab) => tab.fields);
57
+ }
58
+ if ((field.type === 'row' || field.type === 'collapsible') && 'fields' in field) {
59
+ return [field.fields];
60
+ }
61
+ return [];
62
+ }
63
+ function isLayoutRefField(field) {
64
+ return 'custom' in field && field.custom?.[LAYOUT_REF_CUSTOM_MARKER] === true;
65
+ }
66
+ // The draft slot is rewritten by every autosave; a manual "save draft" would create versions that all point to it.
67
+ function assertAutosaveOnlyDrafts(collection) {
68
+ const drafts = typeof collection.versions === 'object' ? collection.versions.drafts : undefined;
69
+ if (!drafts) {
70
+ return;
71
+ }
72
+ const autosave = typeof drafts === 'object' ? drafts.autosave : undefined;
73
+ if (!autosave || (typeof autosave === 'object' && autosave.showSaveDraftButton === true)) {
74
+ throw new Error(`layout-blocks: collection "${collection.slug}" uses a layout field, so drafts require autosave without showSaveDraftButton`);
75
+ }
76
+ }
77
+ // Union by slug, first occurrence wins. Owners share the stored data shape, so the same slug with different data fields
78
+ // is a config error. Blocks are copied: the owners keep their own objects and dbNames.
79
+ function collectOwnersLayoutBlocks(collections) {
80
+ const owners = collections.flatMap((collection) => {
81
+ const siblings = findLayoutRefSiblings(collection.fields);
82
+ return siblings ? [{ siblings, slug: collection.slug }] : [];
83
+ });
84
+ if (owners.length === 0) {
85
+ return null;
86
+ }
87
+ const union = new Map();
88
+ for (const { siblings, slug: ownerSlug } of owners) {
89
+ for (const block of findOwnerLayoutBlocks(siblings)) {
90
+ addToUnion(union, block, ownerSlug);
91
+ }
92
+ }
93
+ return [...union.values()].map(({ block }) => ({ ...block, dbName: `${UNION_DB_NAME_PREFIX}${block.slug.replace(/-/g, '_').toLowerCase()}` }));
94
+ }
95
+ function findOwnerLayoutBlocks(siblings) {
96
+ const layoutField = siblings.find((field) => field.type === 'blocks' && field.name === LAYOUT_FIELD_NAME);
97
+ return layoutField?.type === 'blocks' ? layoutField.blocks : [];
98
+ }
99
+ function addToUnion(union, block, ownerSlug) {
100
+ const dataFieldNames = listDataFieldNames(block.fields).sort();
101
+ const existing = union.get(block.slug);
102
+ if (!existing) {
103
+ union.set(block.slug, { block, dataFieldNames, ownerSlug });
104
+ return;
105
+ }
106
+ if (existing.dataFieldNames.join(',') !== dataFieldNames.join(',')) {
107
+ throw new Error(`layout-blocks: block "${block.slug}" has different data fields in "${existing.ownerSlug}" and "${ownerSlug}"; owners must share the same block shape`);
108
+ }
109
+ }
110
+ function listDataFieldNames(fields) {
111
+ return fields.flatMap((field) => {
112
+ if (field.type === 'tabs') {
113
+ return field.tabs.flatMap((tab) => ('name' in tab && tab.name ? [tab.name] : listDataFieldNames(tab.fields)));
114
+ }
115
+ if (field.type === 'ui') {
116
+ return [];
117
+ }
118
+ if ('name' in field && field.name) {
119
+ return [field.name];
120
+ }
121
+ return 'fields' in field ? listDataFieldNames(field.fields) : [];
122
+ });
123
+ }
124
+ // Localization lives on the owner's `layoutRef` (one entry per locale); a localized field inside a block would be silently dropped.
125
+ function assertNoLocalizedField(blocks) {
126
+ const localizedPath = findLocalizedFieldPath(blocks);
127
+ if (localizedPath) {
128
+ throw new Error(`layout-blocks: "${localizedPath}" is localized; fields inside layout blocks must not be localized`);
129
+ }
130
+ }
131
+ function findLocalizedFieldPath(node, path = []) {
132
+ if (Array.isArray(node)) {
133
+ for (const child of node) {
134
+ const found = findLocalizedFieldPath(child, path);
135
+ if (found) {
136
+ return found;
137
+ }
138
+ }
139
+ return null;
140
+ }
141
+ if (typeof node !== 'object' || node === null) {
142
+ return null;
143
+ }
144
+ const { blocks, fields, localized, name, slug, tabs } = node;
145
+ const label = name ?? slug;
146
+ const nodePath = typeof label === 'string' ? [...path, label] : path;
147
+ if (localized === true) {
148
+ return nodePath.join('.');
149
+ }
150
+ return findLocalizedFieldPath([fields, tabs, blocks], nodePath);
151
+ }
152
+ // Payload has no field-level delete hook, so the plugin adds this one to every collection that owns a layout.
153
+ const deleteOwnerLayoutEntriesAfterDeleteHook = async function ({ collection, id, req }) {
154
+ const layoutEntries = await listOwnerLayoutEntries({ owner: { collection: collection.slug, id: String(id) }, req });
155
+ await deleteLayoutEntries({ ids: layoutEntries.map((entry) => entry.id), req });
156
+ };
157
+ export function resolveGcScriptPath(moduleUrl) {
158
+ const modulePath = fileURLToPath(moduleUrl);
159
+ return path.resolve(path.dirname(modulePath), 'scripts', `${GC_SCRIPT_NAME}${path.extname(modulePath)}`);
160
+ }
161
+ //# sourceMappingURL=layout-blocks.plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-blocks.plugin.js","sourceRoot":"","sources":["../../../src/cms/layout-blocks/layout-blocks.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,kDAAkD,CAAC;AAChG,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AACrI,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,0DAA0D,CAAC;AACvH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,MAAM,UAAU,GAAG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AC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC;AAEF,MAAM,UAAU,mBAAmB,CAAC,SAAiB;IACnD,MAAM,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;IAC5C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,GAAG,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;AAC3G,CAAC"}
@@ -0,0 +1,23 @@
1
+ export type LayoutEntryState = 'draft' | 'published';
2
+ export type LayoutEntry = {
3
+ contentHash: string;
4
+ id: string;
5
+ ownerCollection: string;
6
+ ownerId: string | null;
7
+ state: LayoutEntryState;
8
+ };
9
+ export type LayoutEntryOwner = {
10
+ collection: string;
11
+ id: string | null;
12
+ locale: string | null;
13
+ };
14
+ export type OwnerReferences = {
15
+ entryIds: Set<string>;
16
+ ownerExists: boolean;
17
+ };
18
+ export type OwnerLayoutEntry = {
19
+ createdAt: string;
20
+ id: string;
21
+ state: LayoutEntryState;
22
+ };
23
+ //# sourceMappingURL=layout-blocks.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-blocks.types.d.ts","sourceRoot":"","sources":["../../../src/cms/layout-blocks/layout-blocks.types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,WAAW,CAAC;AAErD,MAAM,MAAM,WAAW,GAAG;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,EAAE,gBAAgB,CAAC;CACzB,CAAC;AAGF,MAAM,MAAM,gBAAgB,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAGhG,MAAM,MAAM,eAAe,GAAG;IAAE,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAAC,WAAW,EAAE,OAAO,CAAA;CAAE,CAAC;AAE9E,MAAM,MAAM,gBAAgB,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAA;CAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=layout-blocks.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-blocks.types.js","sourceRoot":"","sources":["../../../src/cms/layout-blocks/layout-blocks.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export declare function HiddenLayoutRefDiff(): null;
2
+ //# sourceMappingURL=layout-ref-diff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-ref-diff.d.ts","sourceRoot":"","sources":["../../../src/cms/layout-blocks/layout-ref-diff.tsx"],"names":[],"mappings":"AACA,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C"}
@@ -0,0 +1,5 @@
1
+ // The pointer only changes id between versions; showing that change in the version diff tells the editor nothing.
2
+ export function HiddenLayoutRefDiff() {
3
+ return null;
4
+ }
5
+ //# sourceMappingURL=layout-ref-diff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-ref-diff.js","sourceRoot":"","sources":["../../../src/cms/layout-blocks/layout-ref-diff.tsx"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,MAAM,UAAU,mBAAmB;IACjC,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type SanitizedConfig } from 'payload';
2
+ export declare const script: (config: SanitizedConfig) => Promise<void>;
3
+ //# sourceMappingURL=layout-blocks-gc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-blocks-gc.d.ts","sourceRoot":"","sources":["../../../../src/cms/layout-blocks/scripts/layout-blocks-gc.ts"],"names":[],"mappings":"AAOA,OAAgB,EAAkB,KAAK,eAAe,EAAE,MAAM,SAAS,CAAC;AAOxE,eAAO,MAAM,MAAM,WAAkB,eAAe,KAAG,OAAO,CAAC,IAAI,CAgClE,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { deleteLayoutEntries, listAllLayoutEntryOwners, listOwnerLayoutEntries, loadOwnerReferences, } from '../services/layout-entry.repository.js';
2
+ import { selectOrphanLayoutEntryIds } from '../utils/layout-entry-ids.js';
3
+ import payload, { createLocalReq } from 'payload';
4
+ const HOURS_PER_DAY = 24;
5
+ const MS_PER_HOUR = 60 * 60 * 1000;
6
+ // 24 hours: an entry younger than this may still be about to be referenced by an in-flight save.
7
+ const ORPHAN_GRACE_PERIOD_MS = HOURS_PER_DAY * MS_PER_HOUR;
8
+ export const script = async (config) => {
9
+ await payload.init({ config });
10
+ try {
11
+ const req = await createLocalReq({}, payload);
12
+ const collectionSlugs = new Set(config.collections.map((collection) => collection.slug));
13
+ let deletedCount = 0;
14
+ for (const owner of await listAllLayoutEntryOwners({ req })) {
15
+ if (!collectionSlugs.has(owner.collection)) {
16
+ continue;
17
+ }
18
+ const references = owner.id === null
19
+ ? { entryIds: new Set(), ownerExists: false }
20
+ : await loadOwnerReferences({ collection: owner.collection, id: owner.id, req });
21
+ const orphanIds = selectOrphanLayoutEntryIds({
22
+ gracePeriodMs: ORPHAN_GRACE_PERIOD_MS,
23
+ keepDraftSlots: references.ownerExists,
24
+ layoutEntries: await listOwnerLayoutEntries({ owner, req }),
25
+ now: new Date(),
26
+ referencedIds: references.entryIds,
27
+ });
28
+ await deleteLayoutEntries({ ids: orphanIds, req });
29
+ deletedCount += orphanIds.length;
30
+ }
31
+ payload.logger.info(`layout-blocks-gc: deleted ${deletedCount} orphan layout entry(s)`);
32
+ }
33
+ finally {
34
+ await payload.destroy();
35
+ }
36
+ };
37
+ //# sourceMappingURL=layout-blocks-gc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-blocks-gc.js","sourceRoot":"","sources":["../../../../src/cms/layout-blocks/scripts/layout-blocks-gc.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,0DAA0D,CAAC;AAClE,OAAO,EAAE,0BAA0B,EAAE,MAAM,gDAAgD,CAAC;AAC5F,OAAO,OAAO,EAAE,EAAE,cAAc,EAAwB,MAAM,SAAS,CAAC;AAExE,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,WAAW,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACnC,iGAAiG;AACjG,MAAM,sBAAsB,GAAG,aAAa,GAAG,WAAW,CAAC;AAE3D,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAE,MAAuB,EAAiB,EAAE;IACrE,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAE/B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAC9C,MAAM,eAAe,GAAG,IAAI,GAAG,CAAS,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;QACjG,IAAI,YAAY,GAAG,CAAC,CAAC;QAErB,KAAK,MAAM,KAAK,IAAI,MAAM,wBAAwB,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;YAC5D,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC3C,SAAS;YACX,CAAC;YACD,MAAM,UAAU,GACd,KAAK,CAAC,EAAE,KAAK,IAAI;gBACf,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAU,EAAE,WAAW,EAAE,KAAK,EAAE;gBACrD,CAAC,CAAC,MAAM,mBAAmB,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;YACrF,MAAM,SAAS,GAAG,0BAA0B,CAAC;gBAC3C,aAAa,EAAE,sBAAsB;gBACrC,cAAc,EAAE,UAAU,CAAC,WAAW;gBACtC,aAAa,EAAE,MAAM,sBAAsB,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;gBAC3D,GAAG,EAAE,IAAI,IAAI,EAAE;gBACf,aAAa,EAAE,UAAU,CAAC,QAAQ;aACnC,CAAC,CAAC;YAEH,MAAM,mBAAmB,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC;YACnD,YAAY,IAAI,SAAS,CAAC,MAAM,CAAC;QACnC,CAAC;QAED,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,6BAA6B,YAAY,yBAAyB,CAAC,CAAC;IAC1F,CAAC;YAAS,CAAC;QACT,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,74 @@
1
+ import type { LayoutEntry, LayoutEntryOwner, LayoutEntryState, OwnerLayoutEntry, OwnerReferences } from '../layout-blocks.types.js';
2
+ import type { Block, PayloadRequest } from 'payload';
3
+ type LayoutEntryWrite = {
4
+ blockItems: unknown[];
5
+ contentHash: string;
6
+ owner: LayoutEntryOwner;
7
+ req: PayloadRequest;
8
+ state: LayoutEntryState;
9
+ };
10
+ export declare function findLayoutEntry({ id, req }: {
11
+ id: string | null;
12
+ req: PayloadRequest;
13
+ }): Promise<LayoutEntry | null>;
14
+ export declare function findDraftSlot({ owner, req }: {
15
+ owner: LayoutEntryOwner;
16
+ req: PayloadRequest;
17
+ }): Promise<LayoutEntry | null>;
18
+ export declare function loadLayoutEntryBlockItems({ depth, draft, ids, overrideAccess, req, }: {
19
+ depth: number;
20
+ draft: boolean;
21
+ ids: string[];
22
+ overrideAccess: boolean;
23
+ req: PayloadRequest;
24
+ }): Promise<Map<string, unknown[]>>;
25
+ export declare function createLayoutEntry({ blockItems, contentHash, owner, req, state }: LayoutEntryWrite): Promise<string>;
26
+ export declare function updateLayoutEntryBlockItems({ blockItems, contentHash, id, req, }: {
27
+ blockItems: unknown[];
28
+ contentHash: string;
29
+ id: string;
30
+ req: PayloadRequest;
31
+ }): Promise<void>;
32
+ export declare function cloneLayoutEntry({ blocks, id, req }: {
33
+ blocks: Block[];
34
+ id: string;
35
+ req: PayloadRequest;
36
+ }): Promise<string>;
37
+ export declare function assignLayoutEntryOwner({ ids, ownerId, req }: {
38
+ ids: string[];
39
+ ownerId: string;
40
+ req: PayloadRequest;
41
+ }): Promise<void>;
42
+ export declare function freezeLayoutEntries({ ids, req }: {
43
+ ids: string[];
44
+ req: PayloadRequest;
45
+ }): Promise<void>;
46
+ export declare function deleteLayoutEntries({ ids, req }: {
47
+ ids: string[];
48
+ req: PayloadRequest;
49
+ }): Promise<void>;
50
+ export declare function rememberSubmittedRows({ entryId, req, rows }: {
51
+ entryId: string;
52
+ req: PayloadRequest;
53
+ rows: unknown[];
54
+ }): void;
55
+ export declare function loadOwnerReferences({ collection, id, req, }: {
56
+ collection: string;
57
+ id: string;
58
+ req: PayloadRequest;
59
+ }): Promise<OwnerReferences>;
60
+ export declare function listOwnerLayoutEntries({ owner, req, }: {
61
+ owner: {
62
+ collection: string;
63
+ id: string | null;
64
+ };
65
+ req: PayloadRequest;
66
+ }): Promise<OwnerLayoutEntry[]>;
67
+ export declare function listAllLayoutEntryOwners({ req }: {
68
+ req: PayloadRequest;
69
+ }): Promise<{
70
+ collection: string;
71
+ id: string | null;
72
+ }[]>;
73
+ export {};
74
+ //# sourceMappingURL=layout-entry.repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-entry.repository.d.ts","source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AAI,EAAE,OAAO,EAAE,CAAA;CAAE,GAAG,IAAI,CAE7H;AAMD,wBAAsB,mBAAmB,CAAC,EACxC,UAAU,EACV,EAAE,EACF,GAAG,GACJ,EAAE;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,cAAc,CAAC;CACrB,GAAG,OAAO,CAAC,eAAe,CAAC,CA+B3B;AAED,wBAAsB,sBAAsB,CAAC,EAC3C,KAAK,EACL,GAAG,GACJ,EAAE;IACD,KAAK,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IACjD,GAAG,EAAE,cAAc,CAAC;CACrB,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAsB9B;AAED,wBAAsB,wBAAwB,CAAC,EAAE,GAAG,EAAE,EAAE;IAAE,GAAG,EAAE,cAAc,CAAA;CAAE,GAAG,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EAAE,CAAC,CAkBrI"}
@@ -0,0 +1,263 @@
1
+ import { BLOCK_ITEMS_FIELD_NAME, LAYOUT_BLOCKS_SLUG, LAYOUT_ENTRY_READ_CONTEXT_KEY } from '../layout-blocks.collection.js';
2
+ import { LAYOUT_REF_FIELD_NAME } from '../layout-blocks.constants.js';
3
+ import { SKIP_VALIDATION_CONTEXT_KEY } from '../utils/block-fields.js';
4
+ import { removeRowIds } from '../utils/layout-content.js';
5
+ import { readLayoutRefIds } from '../utils/layout-entry-ids.js';
6
+ // The collection is not part of the generated CollectionSlug types, and owner slugs are runtime strings.
7
+ const LAYOUT_BLOCKS_COLLECTION = LAYOUT_BLOCKS_SLUG;
8
+ const SUBMITTED_ROWS_CONTEXT_KEY = 'layoutBlocksSubmittedRows';
9
+ const LAYOUT_ENTRY_SELECT = { contentHash: true, ownerCollection: true, ownerId: true, state: true };
10
+ // ---------------------------------------------------------------------------------------------------------------------
11
+ // Reading entries
12
+ // ---------------------------------------------------------------------------------------------------------------------
13
+ export async function findLayoutEntry({ id, req }) {
14
+ if (!id) {
15
+ return null;
16
+ }
17
+ const { docs } = await req.payload.find({
18
+ collection: LAYOUT_BLOCKS_COLLECTION,
19
+ depth: 0,
20
+ limit: 1,
21
+ overrideAccess: true,
22
+ req: isolateRequest(req),
23
+ select: LAYOUT_ENTRY_SELECT,
24
+ where: { id: { equals: id } },
25
+ });
26
+ const [doc] = docs;
27
+ return doc ? toLayoutEntry(doc) : null;
28
+ }
29
+ export async function findDraftSlot({ owner, req }) {
30
+ const { docs } = await req.payload.find({
31
+ collection: LAYOUT_BLOCKS_COLLECTION,
32
+ depth: 0,
33
+ limit: 1,
34
+ overrideAccess: true,
35
+ req: isolateRequest(req),
36
+ select: LAYOUT_ENTRY_SELECT,
37
+ sort: 'createdAt',
38
+ where: { and: [buildOwnerWhere(owner), { state: { equals: 'draft' } }] },
39
+ });
40
+ const [doc] = docs;
41
+ return doc ? toLayoutEntry(doc) : null;
42
+ }
43
+ // The entry is read with the caller's draft and access so the relations inside the blocks are populated as the caller
44
+ // would see them; the collection's read access lets the flagged req through (overrideAccess: true would populate everything).
45
+ export async function loadLayoutEntryBlockItems({ depth, draft, ids, overrideAccess, req, }) {
46
+ const result = new Map();
47
+ const submittedRows = depth === 0 ? readSubmittedRows(req) : {};
48
+ const pendingIds = [];
49
+ for (const id of ids) {
50
+ if (submittedRows[id]) {
51
+ result.set(id, submittedRows[id]);
52
+ }
53
+ else {
54
+ pendingIds.push(id);
55
+ }
56
+ }
57
+ if (pendingIds.length === 0) {
58
+ return result;
59
+ }
60
+ const { docs } = await req.payload.find({
61
+ collection: LAYOUT_BLOCKS_COLLECTION,
62
+ depth,
63
+ draft,
64
+ overrideAccess,
65
+ pagination: false,
66
+ req: createEntryReadRequest(req),
67
+ select: { [BLOCK_ITEMS_FIELD_NAME]: true },
68
+ where: { id: { in: pendingIds } },
69
+ });
70
+ for (const doc of docs) {
71
+ const blockItems = doc[BLOCK_ITEMS_FIELD_NAME];
72
+ result.set(toIdString(doc.id), Array.isArray(blockItems) ? blockItems : []);
73
+ }
74
+ return result;
75
+ }
76
+ // ---------------------------------------------------------------------------------------------------------------------
77
+ // Writing entries
78
+ // ---------------------------------------------------------------------------------------------------------------------
79
+ export async function createLayoutEntry({ blockItems, contentHash, owner, req, state }) {
80
+ const doc = await req.payload.create({
81
+ collection: LAYOUT_BLOCKS_COLLECTION,
82
+ data: {
83
+ contentHash,
84
+ [BLOCK_ITEMS_FIELD_NAME]: blockItems,
85
+ ownerCollection: owner.collection,
86
+ ownerId: owner.id,
87
+ ownerLocale: owner.locale,
88
+ state,
89
+ },
90
+ depth: 0,
91
+ overrideAccess: true,
92
+ req: createSkipValidationRequest(req),
93
+ });
94
+ return toIdString(doc.id);
95
+ }
96
+ export async function updateLayoutEntryBlockItems({ blockItems, contentHash, id, req, }) {
97
+ await req.payload.update({
98
+ collection: LAYOUT_BLOCKS_COLLECTION,
99
+ data: { contentHash, [BLOCK_ITEMS_FIELD_NAME]: blockItems },
100
+ depth: 0,
101
+ id,
102
+ overrideAccess: true,
103
+ req: createSkipValidationRequest(req),
104
+ });
105
+ }
106
+ // A clone starts as the (ownerless) draft slot of the duplicate; the owner is assigned after the duplicate is created.
107
+ export async function cloneLayoutEntry({ blocks, id, req }) {
108
+ const source = (await req.payload.findByID({
109
+ collection: LAYOUT_BLOCKS_COLLECTION,
110
+ depth: 0,
111
+ id,
112
+ overrideAccess: true,
113
+ req: isolateRequest(req),
114
+ }));
115
+ const blockItems = Array.isArray(source[BLOCK_ITEMS_FIELD_NAME]) ? source[BLOCK_ITEMS_FIELD_NAME] : [];
116
+ return createLayoutEntry({
117
+ blockItems: removeRowIds({ blocks, layout: blockItems }),
118
+ contentHash: String(source.contentHash ?? ''),
119
+ owner: { collection: String(source.ownerCollection), id: null, locale: source.ownerLocale ? String(source.ownerLocale) : null },
120
+ req,
121
+ state: 'draft',
122
+ });
123
+ }
124
+ export async function assignLayoutEntryOwner({ ids, ownerId, req }) {
125
+ if (ids.length === 0) {
126
+ return;
127
+ }
128
+ await updateLayoutEntryColumns({ data: { ownerId }, req, where: { and: [{ id: { in: ids } }, { ownerId: { exists: false } }] } });
129
+ }
130
+ export async function freezeLayoutEntries({ ids, req }) {
131
+ if (ids.length === 0) {
132
+ return;
133
+ }
134
+ await updateLayoutEntryColumns({ data: { state: 'published' }, req, where: { id: { in: ids } } });
135
+ }
136
+ export async function deleteLayoutEntries({ ids, req }) {
137
+ if (ids.length === 0) {
138
+ return;
139
+ }
140
+ await req.payload.delete({ collection: LAYOUT_BLOCKS_COLLECTION, overrideAccess: true, req: isolateRequest(req), where: { id: { in: ids } } });
141
+ }
142
+ // The admin merges the save response into the form by row id, so the request that wrote an entry must read it back as sent.
143
+ export function rememberSubmittedRows({ entryId, req, rows }) {
144
+ req.context[SUBMITTED_ROWS_CONTEXT_KEY] = { ...readSubmittedRows(req), [entryId]: rows };
145
+ }
146
+ // ---------------------------------------------------------------------------------------------------------------------
147
+ // Owners and their references (used by the cleanup)
148
+ // ---------------------------------------------------------------------------------------------------------------------
149
+ export async function loadOwnerReferences({ collection, id, req, }) {
150
+ const slug = collection;
151
+ const shared = { collection: slug, depth: 0, locale: 'all', overrideAccess: true, pagination: false, trash: true };
152
+ const main = await req.payload.find({
153
+ ...shared,
154
+ draft: false,
155
+ req: isolateRequest(req),
156
+ select: { [LAYOUT_REF_FIELD_NAME]: true },
157
+ where: { id: { equals: id } },
158
+ });
159
+ // findVersions on a collection without versions makes the drizzle adapter throw.
160
+ const versionDocs = req.payload.collections[slug]?.config.versions
161
+ ? (await req.payload.findVersions({
162
+ ...shared,
163
+ req: isolateRequest(req),
164
+ select: { version: { [LAYOUT_REF_FIELD_NAME]: true } },
165
+ where: { parent: { equals: id } },
166
+ })).docs
167
+ : [];
168
+ const entryIds = new Set();
169
+ for (const doc of main.docs) {
170
+ readLayoutRefIds(doc[LAYOUT_REF_FIELD_NAME]).forEach((entryId) => entryIds.add(entryId));
171
+ }
172
+ for (const versionDoc of versionDocs) {
173
+ readLayoutRefIds(versionDoc.version?.[LAYOUT_REF_FIELD_NAME]).forEach((entryId) => entryIds.add(entryId));
174
+ }
175
+ return { entryIds, ownerExists: main.docs.length > 0 };
176
+ }
177
+ export async function listOwnerLayoutEntries({ owner, req, }) {
178
+ const { docs } = await req.payload.find({
179
+ collection: LAYOUT_BLOCKS_COLLECTION,
180
+ depth: 0,
181
+ overrideAccess: true,
182
+ pagination: false,
183
+ req: isolateRequest(req),
184
+ select: { createdAt: true, state: true },
185
+ sort: 'createdAt',
186
+ where: {
187
+ and: [
188
+ { ownerCollection: { equals: owner.collection } },
189
+ owner.id === null ? { ownerId: { exists: false } } : { ownerId: { equals: owner.id } },
190
+ ],
191
+ },
192
+ });
193
+ return docs.map((doc) => ({
194
+ createdAt: String(doc.createdAt),
195
+ id: toIdString(doc.id),
196
+ state: doc.state,
197
+ }));
198
+ }
199
+ export async function listAllLayoutEntryOwners({ req }) {
200
+ const { docs } = await req.payload.find({
201
+ collection: LAYOUT_BLOCKS_COLLECTION,
202
+ depth: 0,
203
+ overrideAccess: true,
204
+ pagination: false,
205
+ req: isolateRequest(req),
206
+ select: { ownerCollection: true, ownerId: true },
207
+ });
208
+ const owners = new Map();
209
+ for (const doc of docs) {
210
+ const collection = String(doc.ownerCollection);
211
+ const id = doc.ownerId === null || doc.ownerId === undefined ? null : toIdString(doc.ownerId);
212
+ owners.set(`${collection}:${id}`, { collection, id });
213
+ }
214
+ return [...owners.values()];
215
+ }
216
+ // ---------------------------------------------------------------------------------------------------------------------
217
+ // Request and row helpers
218
+ // ---------------------------------------------------------------------------------------------------------------------
219
+ // The Local API writes locale/fallbackLocale into the req it receives; a shared owner req would then save in the wrong locale.
220
+ function isolateRequest(req) {
221
+ return Object.assign(Object.create(req), req);
222
+ }
223
+ function createEntryReadRequest(req) {
224
+ const isolated = isolateRequest(req);
225
+ isolated.context = { ...req.context, [LAYOUT_ENTRY_READ_CONTEXT_KEY]: true };
226
+ return isolated;
227
+ }
228
+ // The owner validates the virtual layout on publish and skips it on drafts; re-validating the copy would reject incomplete drafts.
229
+ function createSkipValidationRequest(req) {
230
+ const isolated = isolateRequest(req);
231
+ isolated.context = { ...req.context, [SKIP_VALIDATION_CONTEXT_KEY]: true };
232
+ return isolated;
233
+ }
234
+ // Metadata writes go straight to the adapter: the Local API would refill and rewrite the whole layout (every block table) and rerun hooks.
235
+ async function updateLayoutEntryColumns({ data, req, where }) {
236
+ await req.payload.db.updateMany({ collection: LAYOUT_BLOCKS_COLLECTION, data, req: isolateRequest(req), returning: false, where });
237
+ }
238
+ // Rows saved earlier in this same request, keyed by entry id. A depth-0 read returns them as sent so the admin form keeps its row ids.
239
+ function readSubmittedRows(req) {
240
+ return (req.context?.[SUBMITTED_ROWS_CONTEXT_KEY] ?? {});
241
+ }
242
+ function buildOwnerWhere({ collection, id, locale }) {
243
+ return {
244
+ and: [
245
+ { ownerCollection: { equals: collection } },
246
+ id === null ? { ownerId: { exists: false } } : { ownerId: { equals: id } },
247
+ locale === null ? { ownerLocale: { exists: false } } : { ownerLocale: { equals: locale } },
248
+ ],
249
+ };
250
+ }
251
+ function toLayoutEntry(doc) {
252
+ return {
253
+ contentHash: String(doc.contentHash ?? ''),
254
+ id: toIdString(doc.id),
255
+ ownerCollection: String(doc.ownerCollection ?? ''),
256
+ ownerId: doc.ownerId === null || doc.ownerId === undefined ? null : toIdString(doc.ownerId),
257
+ state: doc.state,
258
+ };
259
+ }
260
+ function toIdString(value) {
261
+ return String(value);
262
+ }
263
+ //# sourceMappingURL=layout-entry.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-entry.repository.js","sourceRoot":"","sources":["../../../../src/cms/layout-blocks/services/layout-entry.repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,kDAAkD,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