payload 3.0.0-beta.45 → 3.0.0-beta.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/RichText.d.ts +117 -17
- package/dist/admin/RichText.d.ts.map +1 -1
- package/dist/admin/RichText.js.map +1 -1
- package/dist/auth/operations/forgotPassword.d.ts.map +1 -1
- package/dist/auth/operations/forgotPassword.js +1 -2
- package/dist/auth/operations/forgotPassword.js.map +1 -1
- package/dist/auth/sendVerificationEmail.d.ts.map +1 -1
- package/dist/auth/sendVerificationEmail.js +1 -2
- package/dist/auth/sendVerificationEmail.js.map +1 -1
- package/dist/bin/generateTypes.d.ts.map +1 -1
- package/dist/bin/generateTypes.js +9 -0
- package/dist/bin/generateTypes.js.map +1 -1
- package/dist/collections/operations/create.d.ts.map +1 -1
- package/dist/collections/operations/create.js +1 -2
- package/dist/collections/operations/create.js.map +1 -1
- package/dist/fields/config/sanitize.d.ts.map +1 -1
- package/dist/fields/config/sanitize.js +0 -15
- package/dist/fields/config/sanitize.js.map +1 -1
- package/dist/fields/config/schema.js +1 -1
- package/dist/fields/config/schema.js.map +1 -1
- package/dist/fields/config/types.d.ts +14 -2
- package/dist/fields/config/types.d.ts.map +1 -1
- package/dist/fields/config/types.js.map +1 -1
- package/dist/fields/getFieldPaths.d.ts +10 -0
- package/dist/fields/getFieldPaths.d.ts.map +1 -0
- package/dist/fields/getFieldPaths.js +45 -0
- package/dist/fields/getFieldPaths.js.map +1 -0
- package/dist/fields/hooks/afterChange/index.d.ts +6 -0
- package/dist/fields/hooks/afterChange/index.d.ts.map +1 -1
- package/dist/fields/hooks/afterChange/index.js +2 -0
- package/dist/fields/hooks/afterChange/index.js.map +1 -1
- package/dist/fields/hooks/afterChange/promise.d.ts +9 -1
- package/dist/fields/hooks/afterChange/promise.d.ts.map +1 -1
- package/dist/fields/hooks/afterChange/promise.js +67 -3
- package/dist/fields/hooks/afterChange/promise.js.map +1 -1
- package/dist/fields/hooks/afterChange/traverseFields.d.ts +3 -1
- package/dist/fields/hooks/afterChange/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/afterChange/traverseFields.js +3 -1
- package/dist/fields/hooks/afterChange/traverseFields.js.map +1 -1
- package/dist/fields/hooks/afterRead/index.d.ts +1 -1
- package/dist/fields/hooks/afterRead/index.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/index.js +3 -1
- package/dist/fields/hooks/afterRead/index.js.map +1 -1
- package/dist/fields/hooks/afterRead/promise.d.ts +9 -1
- package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/promise.js +129 -25
- package/dist/fields/hooks/afterRead/promise.js.map +1 -1
- package/dist/fields/hooks/afterRead/traverseFields.d.ts +3 -1
- package/dist/fields/hooks/afterRead/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/traverseFields.js +3 -1
- package/dist/fields/hooks/afterRead/traverseFields.js.map +1 -1
- package/dist/fields/hooks/beforeChange/index.d.ts +1 -1
- package/dist/fields/hooks/beforeChange/index.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/index.js +3 -2
- package/dist/fields/hooks/beforeChange/index.js.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.d.ts +9 -2
- package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.js +77 -10
- package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
- package/dist/fields/hooks/beforeChange/traverseFields.d.ts +4 -3
- package/dist/fields/hooks/beforeChange/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/traverseFields.js +4 -3
- package/dist/fields/hooks/beforeChange/traverseFields.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/index.d.ts.map +1 -1
- package/dist/fields/hooks/beforeValidate/index.js +2 -0
- package/dist/fields/hooks/beforeValidate/index.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/promise.d.ts +3 -1
- package/dist/fields/hooks/beforeValidate/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeValidate/promise.js +69 -4
- package/dist/fields/hooks/beforeValidate/promise.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/traverseFields.d.ts +3 -1
- package/dist/fields/hooks/beforeValidate/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/beforeValidate/traverseFields.js +3 -1
- package/dist/fields/hooks/beforeValidate/traverseFields.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */ import { MissingEditorProp } from '../../../errors/index.js';
|
|
2
2
|
import { fieldAffectsData, tabHasName } from '../../config/types.js';
|
|
3
3
|
import getValueWithDefault from '../../getDefaultValue.js';
|
|
4
|
+
import { getFieldPaths } from '../../getFieldPaths.js';
|
|
4
5
|
import { relationshipPopulationPromise } from './relationshipPopulationPromise.js';
|
|
5
6
|
import { traverseFields } from './traverseFields.js';
|
|
6
7
|
// This function is responsible for the following actions, in order:
|
|
@@ -10,7 +11,12 @@ import { traverseFields } from './traverseFields.js';
|
|
|
10
11
|
// - Execute field hooks
|
|
11
12
|
// - Execute read access control
|
|
12
13
|
// - Populate relationships
|
|
13
|
-
export const promise = async ({ collection, context, currentDepth, depth, doc, draft, fallbackLocale, field, fieldPromises, findMany, flattenLocales, global, locale, overrideAccess, populationPromises, req, showHiddenFields, siblingDoc, triggerAccessControl = true, triggerHooks = true })=>{
|
|
14
|
+
export const promise = async ({ collection, context, currentDepth, depth, doc, draft, fallbackLocale, field, fieldPromises, findMany, flattenLocales, global, locale, overrideAccess, parentPath, parentSchemaPath, populationPromises, req, showHiddenFields, siblingDoc, triggerAccessControl = true, triggerHooks = true })=>{
|
|
15
|
+
const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({
|
|
16
|
+
field,
|
|
17
|
+
parentPath,
|
|
18
|
+
parentSchemaPath
|
|
19
|
+
});
|
|
14
20
|
if (fieldAffectsData(field) && field.hidden && typeof siblingDoc[field.name] !== 'undefined' && !showHiddenFields) {
|
|
15
21
|
delete siblingDoc[field.name];
|
|
16
22
|
}
|
|
@@ -74,26 +80,6 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
74
80
|
if (typeof field?.editor === 'function') {
|
|
75
81
|
throw new Error('Attempted to access unsanitized rich text editor.');
|
|
76
82
|
}
|
|
77
|
-
const editor = field?.editor;
|
|
78
|
-
// This is run here AND in the GraphQL Resolver
|
|
79
|
-
if (editor?.populationPromises) {
|
|
80
|
-
const populateDepth = field?.maxDepth !== undefined && field?.maxDepth < depth ? field?.maxDepth : depth;
|
|
81
|
-
editor.populationPromises({
|
|
82
|
-
context,
|
|
83
|
-
currentDepth,
|
|
84
|
-
depth: populateDepth,
|
|
85
|
-
draft,
|
|
86
|
-
field,
|
|
87
|
-
fieldPromises,
|
|
88
|
-
findMany,
|
|
89
|
-
flattenLocales,
|
|
90
|
-
overrideAccess,
|
|
91
|
-
populationPromises,
|
|
92
|
-
req,
|
|
93
|
-
showHiddenFields,
|
|
94
|
-
siblingDoc
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
83
|
break;
|
|
98
84
|
}
|
|
99
85
|
case 'point':
|
|
@@ -124,10 +110,14 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
124
110
|
context,
|
|
125
111
|
data: doc,
|
|
126
112
|
field,
|
|
113
|
+
findMany,
|
|
127
114
|
global,
|
|
128
115
|
operation: 'read',
|
|
129
116
|
originalDoc: doc,
|
|
117
|
+
overrideAccess,
|
|
118
|
+
path: fieldPath,
|
|
130
119
|
req,
|
|
120
|
+
schemaPath: fieldSchemaPath,
|
|
131
121
|
siblingData: siblingDoc,
|
|
132
122
|
value
|
|
133
123
|
});
|
|
@@ -147,7 +137,9 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
147
137
|
operation: 'read',
|
|
148
138
|
originalDoc: doc,
|
|
149
139
|
overrideAccess,
|
|
140
|
+
path: fieldPath,
|
|
150
141
|
req,
|
|
142
|
+
schemaPath: fieldSchemaPath,
|
|
151
143
|
siblingData: siblingDoc,
|
|
152
144
|
value: siblingDoc[field.name]
|
|
153
145
|
});
|
|
@@ -217,8 +209,10 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
217
209
|
global,
|
|
218
210
|
locale,
|
|
219
211
|
overrideAccess,
|
|
212
|
+
path: fieldPath,
|
|
220
213
|
populationPromises,
|
|
221
214
|
req,
|
|
215
|
+
schemaPath: fieldSchemaPath,
|
|
222
216
|
showHiddenFields,
|
|
223
217
|
siblingDoc: groupDoc,
|
|
224
218
|
triggerAccessControl,
|
|
@@ -230,7 +224,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
230
224
|
{
|
|
231
225
|
const rows = siblingDoc[field.name];
|
|
232
226
|
if (Array.isArray(rows)) {
|
|
233
|
-
rows.forEach((row)=>{
|
|
227
|
+
rows.forEach((row, i)=>{
|
|
234
228
|
traverseFields({
|
|
235
229
|
collection,
|
|
236
230
|
context,
|
|
@@ -246,8 +240,13 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
246
240
|
global,
|
|
247
241
|
locale,
|
|
248
242
|
overrideAccess,
|
|
243
|
+
path: [
|
|
244
|
+
...fieldPath,
|
|
245
|
+
i
|
|
246
|
+
],
|
|
249
247
|
populationPromises,
|
|
250
248
|
req,
|
|
249
|
+
schemaPath: fieldSchemaPath,
|
|
251
250
|
showHiddenFields,
|
|
252
251
|
siblingDoc: row || {},
|
|
253
252
|
triggerAccessControl,
|
|
@@ -257,7 +256,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
257
256
|
} else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {
|
|
258
257
|
Object.values(rows).forEach((localeRows)=>{
|
|
259
258
|
if (Array.isArray(localeRows)) {
|
|
260
|
-
localeRows.forEach((row)=>{
|
|
259
|
+
localeRows.forEach((row, i)=>{
|
|
261
260
|
traverseFields({
|
|
262
261
|
collection,
|
|
263
262
|
context,
|
|
@@ -273,8 +272,13 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
273
272
|
global,
|
|
274
273
|
locale,
|
|
275
274
|
overrideAccess,
|
|
275
|
+
path: [
|
|
276
|
+
...fieldPath,
|
|
277
|
+
i
|
|
278
|
+
],
|
|
276
279
|
populationPromises,
|
|
277
280
|
req,
|
|
281
|
+
schemaPath: fieldSchemaPath,
|
|
278
282
|
showHiddenFields,
|
|
279
283
|
siblingDoc: row || {},
|
|
280
284
|
triggerAccessControl,
|
|
@@ -292,7 +296,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
292
296
|
{
|
|
293
297
|
const rows = siblingDoc[field.name];
|
|
294
298
|
if (Array.isArray(rows)) {
|
|
295
|
-
rows.forEach((row)=>{
|
|
299
|
+
rows.forEach((row, i)=>{
|
|
296
300
|
const block = field.blocks.find((blockType)=>blockType.slug === row.blockType);
|
|
297
301
|
if (block) {
|
|
298
302
|
traverseFields({
|
|
@@ -310,8 +314,13 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
310
314
|
global,
|
|
311
315
|
locale,
|
|
312
316
|
overrideAccess,
|
|
317
|
+
path: [
|
|
318
|
+
...fieldPath,
|
|
319
|
+
i
|
|
320
|
+
],
|
|
313
321
|
populationPromises,
|
|
314
322
|
req,
|
|
323
|
+
schemaPath: fieldSchemaPath,
|
|
315
324
|
showHiddenFields,
|
|
316
325
|
siblingDoc: row || {},
|
|
317
326
|
triggerAccessControl,
|
|
@@ -322,7 +331,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
322
331
|
} else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {
|
|
323
332
|
Object.values(rows).forEach((localeRows)=>{
|
|
324
333
|
if (Array.isArray(localeRows)) {
|
|
325
|
-
localeRows.forEach((row)=>{
|
|
334
|
+
localeRows.forEach((row, i)=>{
|
|
326
335
|
const block = field.blocks.find((blockType)=>blockType.slug === row.blockType);
|
|
327
336
|
if (block) {
|
|
328
337
|
traverseFields({
|
|
@@ -340,8 +349,13 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
340
349
|
global,
|
|
341
350
|
locale,
|
|
342
351
|
overrideAccess,
|
|
352
|
+
path: [
|
|
353
|
+
...fieldPath,
|
|
354
|
+
i
|
|
355
|
+
],
|
|
343
356
|
populationPromises,
|
|
344
357
|
req,
|
|
358
|
+
schemaPath: fieldSchemaPath,
|
|
345
359
|
showHiddenFields,
|
|
346
360
|
siblingDoc: row || {},
|
|
347
361
|
triggerAccessControl,
|
|
@@ -374,8 +388,10 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
374
388
|
global,
|
|
375
389
|
locale,
|
|
376
390
|
overrideAccess,
|
|
391
|
+
path: fieldPath,
|
|
377
392
|
populationPromises,
|
|
378
393
|
req,
|
|
394
|
+
schemaPath: fieldSchemaPath,
|
|
379
395
|
showHiddenFields,
|
|
380
396
|
siblingDoc,
|
|
381
397
|
triggerAccessControl,
|
|
@@ -405,8 +421,10 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
405
421
|
global,
|
|
406
422
|
locale,
|
|
407
423
|
overrideAccess,
|
|
424
|
+
path: fieldPath,
|
|
408
425
|
populationPromises,
|
|
409
426
|
req,
|
|
427
|
+
schemaPath: fieldSchemaPath,
|
|
410
428
|
showHiddenFields,
|
|
411
429
|
siblingDoc: tabDoc,
|
|
412
430
|
triggerAccessControl,
|
|
@@ -434,8 +452,10 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
434
452
|
global,
|
|
435
453
|
locale,
|
|
436
454
|
overrideAccess,
|
|
455
|
+
path: fieldPath,
|
|
437
456
|
populationPromises,
|
|
438
457
|
req,
|
|
458
|
+
schemaPath: fieldSchemaPath,
|
|
439
459
|
showHiddenFields,
|
|
440
460
|
siblingDoc,
|
|
441
461
|
triggerAccessControl,
|
|
@@ -443,6 +463,90 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
443
463
|
});
|
|
444
464
|
break;
|
|
445
465
|
}
|
|
466
|
+
case 'richText':
|
|
467
|
+
{
|
|
468
|
+
if (!field?.editor) {
|
|
469
|
+
throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor
|
|
470
|
+
;
|
|
471
|
+
}
|
|
472
|
+
if (typeof field?.editor === 'function') {
|
|
473
|
+
throw new Error('Attempted to access unsanitized rich text editor.');
|
|
474
|
+
}
|
|
475
|
+
const editor = field?.editor;
|
|
476
|
+
if (editor?.hooks?.afterRead?.length) {
|
|
477
|
+
await editor.hooks.afterRead.reduce(async (priorHook, currentHook)=>{
|
|
478
|
+
await priorHook;
|
|
479
|
+
const shouldRunHookOnAllLocales = field.localized && (locale === 'all' || !flattenLocales) && typeof siblingDoc[field.name] === 'object';
|
|
480
|
+
if (shouldRunHookOnAllLocales) {
|
|
481
|
+
const hookPromises = Object.entries(siblingDoc[field.name]).map(([locale, value])=>(async ()=>{
|
|
482
|
+
const hookedValue = await currentHook({
|
|
483
|
+
collection,
|
|
484
|
+
context,
|
|
485
|
+
currentDepth,
|
|
486
|
+
data: doc,
|
|
487
|
+
depth,
|
|
488
|
+
draft,
|
|
489
|
+
fallbackLocale,
|
|
490
|
+
field,
|
|
491
|
+
fieldPromises,
|
|
492
|
+
findMany,
|
|
493
|
+
flattenLocales,
|
|
494
|
+
global,
|
|
495
|
+
locale,
|
|
496
|
+
operation: 'read',
|
|
497
|
+
originalDoc: doc,
|
|
498
|
+
overrideAccess,
|
|
499
|
+
path: fieldPath,
|
|
500
|
+
populationPromises,
|
|
501
|
+
req,
|
|
502
|
+
schemaPath: fieldSchemaPath,
|
|
503
|
+
showHiddenFields,
|
|
504
|
+
siblingData: siblingDoc,
|
|
505
|
+
triggerAccessControl,
|
|
506
|
+
triggerHooks,
|
|
507
|
+
value
|
|
508
|
+
});
|
|
509
|
+
if (hookedValue !== undefined) {
|
|
510
|
+
siblingDoc[field.name][locale] = hookedValue;
|
|
511
|
+
}
|
|
512
|
+
})());
|
|
513
|
+
await Promise.all(hookPromises);
|
|
514
|
+
} else {
|
|
515
|
+
const hookedValue = await currentHook({
|
|
516
|
+
collection,
|
|
517
|
+
context,
|
|
518
|
+
currentDepth,
|
|
519
|
+
data: doc,
|
|
520
|
+
depth,
|
|
521
|
+
draft,
|
|
522
|
+
fallbackLocale,
|
|
523
|
+
field,
|
|
524
|
+
fieldPromises,
|
|
525
|
+
findMany,
|
|
526
|
+
flattenLocales,
|
|
527
|
+
global,
|
|
528
|
+
locale,
|
|
529
|
+
operation: 'read',
|
|
530
|
+
originalDoc: doc,
|
|
531
|
+
overrideAccess,
|
|
532
|
+
path: fieldPath,
|
|
533
|
+
populationPromises,
|
|
534
|
+
req,
|
|
535
|
+
schemaPath: fieldSchemaPath,
|
|
536
|
+
showHiddenFields,
|
|
537
|
+
siblingData: siblingDoc,
|
|
538
|
+
triggerAccessControl,
|
|
539
|
+
triggerHooks,
|
|
540
|
+
value: siblingDoc[field.name]
|
|
541
|
+
});
|
|
542
|
+
if (hookedValue !== undefined) {
|
|
543
|
+
siblingDoc[field.name] = hookedValue;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}, Promise.resolve());
|
|
547
|
+
}
|
|
548
|
+
break;
|
|
549
|
+
}
|
|
446
550
|
default:
|
|
447
551
|
{
|
|
448
552
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/afterRead/promise.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { RichTextAdapter } from '../../../admin/types.js'\nimport type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { PayloadRequestWithData, RequestContext } from '../../../types/index.js'\nimport type { Field, TabAsField } from '../../config/types.js'\n\nimport { MissingEditorProp } from '../../../errors/index.js'\nimport { fieldAffectsData, tabHasName } from '../../config/types.js'\nimport getValueWithDefault from '../../getDefaultValue.js'\nimport { relationshipPopulationPromise } from './relationshipPopulationPromise.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n collection: SanitizedCollectionConfig | null\n context: RequestContext\n currentDepth: number\n depth: number\n doc: Record<string, unknown>\n draft: boolean\n fallbackLocale: null | string\n field: Field | TabAsField\n /**\n * fieldPromises are used for things like field hooks. They should be awaited before awaiting populationPromises\n */\n fieldPromises: Promise<void>[]\n findMany: boolean\n flattenLocales: boolean\n global: SanitizedGlobalConfig | null\n locale: null | string\n overrideAccess: boolean\n populationPromises: Promise<void>[]\n req: PayloadRequestWithData\n showHiddenFields: boolean\n siblingDoc: Record<string, unknown>\n triggerAccessControl?: boolean\n triggerHooks?: boolean\n}\n\n// This function is responsible for the following actions, in order:\n// - Remove hidden fields from response\n// - Flatten locales into requested locale\n// - Sanitize outgoing data (point field, etc.)\n// - Execute field hooks\n// - Execute read access control\n// - Populate relationships\n\nexport const promise = async ({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl = true,\n triggerHooks = true,\n}: Args): Promise<void> => {\n if (\n fieldAffectsData(field) &&\n field.hidden &&\n typeof siblingDoc[field.name] !== 'undefined' &&\n !showHiddenFields\n ) {\n delete siblingDoc[field.name]\n }\n\n const shouldHoistLocalizedValue =\n flattenLocales &&\n fieldAffectsData(field) &&\n typeof siblingDoc[field.name] === 'object' &&\n siblingDoc[field.name] !== null &&\n field.localized &&\n locale !== 'all' &&\n req.payload.config.localization\n\n if (shouldHoistLocalizedValue) {\n // replace actual value with localized value before sanitizing\n // { [locale]: fields } -> fields\n const value = siblingDoc[field.name][locale]\n\n let hoistedValue = value\n\n if (fallbackLocale && fallbackLocale !== locale) {\n const fallbackValue = siblingDoc[field.name][fallbackLocale]\n const isNullOrUndefined = typeof value === 'undefined' || value === null\n\n if (fallbackValue) {\n switch (field.type) {\n case 'text':\n case 'textarea': {\n if (value === '' || isNullOrUndefined) {\n hoistedValue = fallbackValue\n }\n break\n }\n\n default: {\n if (isNullOrUndefined) {\n hoistedValue = fallbackValue\n }\n break\n }\n }\n }\n }\n\n siblingDoc[field.name] = hoistedValue\n }\n\n // Sanitize outgoing field value\n switch (field.type) {\n case 'group': {\n // Fill groups with empty objects so fields with hooks within groups can populate\n // themselves virtually as necessary\n if (typeof siblingDoc[field.name] === 'undefined') {\n siblingDoc[field.name] = {}\n }\n\n break\n }\n case 'tabs': {\n field.tabs.forEach((tab) => {\n if (\n tabHasName(tab) &&\n (typeof siblingDoc[tab.name] === 'undefined' || siblingDoc[tab.name] === null)\n ) {\n siblingDoc[tab.name] = {}\n }\n })\n\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n if (typeof field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n const editor: RichTextAdapter = field?.editor\n // This is run here AND in the GraphQL Resolver\n if (editor?.populationPromises) {\n const populateDepth =\n field?.maxDepth !== undefined && field?.maxDepth < depth ? field?.maxDepth : depth\n\n editor.populationPromises({\n context,\n currentDepth,\n depth: populateDepth,\n draft,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n })\n }\n\n break\n }\n\n case 'point': {\n const pointDoc = siblingDoc[field.name] as Record<string, unknown>\n if (Array.isArray(pointDoc?.coordinates) && pointDoc.coordinates.length === 2) {\n siblingDoc[field.name] = pointDoc.coordinates\n } else {\n siblingDoc[field.name] = undefined\n }\n\n break\n }\n\n default: {\n break\n }\n }\n\n if (fieldAffectsData(field)) {\n // Execute hooks\n if (triggerHooks && field.hooks?.afterRead) {\n await field.hooks.afterRead.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const shouldRunHookOnAllLocales =\n field.localized &&\n (locale === 'all' || !flattenLocales) &&\n typeof siblingDoc[field.name] === 'object'\n\n if (shouldRunHookOnAllLocales) {\n const hookPromises = Object.entries(siblingDoc[field.name]).map(([locale, value]) =>\n (async () => {\n const hookedValue = await currentHook({\n collection,\n context,\n data: doc,\n field,\n global,\n operation: 'read',\n originalDoc: doc,\n req,\n siblingData: siblingDoc,\n value,\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name][locale] = hookedValue\n }\n })(),\n )\n\n await Promise.all(hookPromises)\n } else {\n const hookedValue = await currentHook({\n collection,\n context,\n data: doc,\n field,\n findMany,\n global,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n req,\n siblingData: siblingDoc,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }\n }, Promise.resolve())\n }\n\n // Execute access control\n let allowDefaultValue = true\n if (triggerAccessControl && field.access && field.access.read) {\n const result = overrideAccess\n ? true\n : await field.access.read({\n id: doc.id as number | string,\n data: doc,\n doc,\n req,\n siblingData: siblingDoc,\n })\n\n if (!result) {\n allowDefaultValue = false\n delete siblingDoc[field.name]\n }\n }\n\n // Set defaultValue on the field for globals being returned without being first created\n // or collection documents created prior to having a default\n if (\n allowDefaultValue &&\n typeof siblingDoc[field.name] === 'undefined' &&\n typeof field.defaultValue !== 'undefined'\n ) {\n siblingDoc[field.name] = await getValueWithDefault({\n defaultValue: field.defaultValue,\n locale,\n user: req.user,\n value: siblingDoc[field.name],\n })\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n populationPromises.push(\n relationshipPopulationPromise({\n currentDepth,\n depth,\n draft,\n fallbackLocale,\n field,\n locale,\n overrideAccess,\n req,\n showHiddenFields,\n siblingDoc,\n }),\n )\n }\n }\n\n switch (field.type) {\n case 'group': {\n let groupDoc = siblingDoc[field.name] as Record<string, unknown>\n if (typeof siblingDoc[field.name] !== 'object') groupDoc = {}\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: groupDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'array': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n rows.forEach((row) => {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n })\n } else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {\n Object.values(rows).forEach((localeRows) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row) => {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n })\n }\n })\n } else {\n siblingDoc[field.name] = []\n }\n break\n }\n\n case 'blocks': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n rows.forEach((row) => {\n const block = field.blocks.find((blockType) => blockType.slug === row.blockType)\n\n if (block) {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: block.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n }\n })\n } else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {\n Object.values(rows).forEach((localeRows) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row) => {\n const block = field.blocks.find((blockType) => blockType.slug === row.blockType)\n\n if (block) {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: block.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n }\n })\n }\n })\n } else {\n siblingDoc[field.name] = []\n }\n\n break\n }\n\n case 'row':\n case 'collapsible': {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'tab': {\n let tabDoc = siblingDoc\n if (tabHasName(field)) {\n tabDoc = siblingDoc[field.name] as Record<string, unknown>\n if (typeof siblingDoc[field.name] !== 'object') tabDoc = {}\n }\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: tabDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'tabs': {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["MissingEditorProp","fieldAffectsData","tabHasName","getValueWithDefault","relationshipPopulationPromise","traverseFields","promise","collection","context","currentDepth","depth","doc","draft","fallbackLocale","field","fieldPromises","findMany","flattenLocales","global","locale","overrideAccess","populationPromises","req","showHiddenFields","siblingDoc","triggerAccessControl","triggerHooks","hidden","name","shouldHoistLocalizedValue","localized","payload","config","localization","value","hoistedValue","fallbackValue","isNullOrUndefined","type","tabs","forEach","tab","editor","Error","populateDepth","maxDepth","undefined","pointDoc","Array","isArray","coordinates","length","hooks","afterRead","reduce","priorHook","currentHook","shouldRunHookOnAllLocales","hookPromises","Object","entries","map","hookedValue","data","operation","originalDoc","siblingData","Promise","all","resolve","allowDefaultValue","access","read","result","id","defaultValue","user","push","groupDoc","fields","rows","row","values","localeRows","block","blocks","find","blockType","slug","tabDoc"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAOpC,SAASA,iBAAiB,QAAQ,2BAA0B;AAC5D,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,wBAAuB;AACpE,OAAOC,yBAAyB,2BAA0B;AAC1D,SAASC,6BAA6B,QAAQ,qCAAoC;AAClF,SAASC,cAAc,QAAQ,sBAAqB;AA4BpD,oEAAoE;AACpE,uCAAuC;AACvC,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ACF;gBAEA;YACF;QAEA,KAAK;YAAO;gBACV,IAAI+D,SAASjE;gBACb,IAAItB,WAAWY,QAAQ;oBACrB2E,SAASjE,UAAU,CAACV,MAAMc,IAAI,CAAC;oBAC/B,IAAI,OAAOJ,UAAU,CAACV,MAAMc,IAAI,CAAC,KAAK,UAAU6D,SAAS,CAAC;gBAC5D;gBAEApF,eAAe;oBACbE;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAE;oBACAgE,QAAQjE,MAAMiE,MAAM;oBACpB/D;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC,YAAYiE;oBACZhE;oBACAC;gBACF;gBAEA;YACF;QAEA,KAAK;YAAQ;gBACXrB,eAAe;oBACbE;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAE;oBACAgE,QAAQjE,MAAMyB,IAAI,CAACsB,GAAG,CAAC,CAACpB,MAAS,CAAA;4BAAE,GAAGA,GAAG;4BAAEH,MAAM;wBAAM,CAAA;oBACvDtB;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;gBACF;gBACA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/afterRead/promise.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { RichTextAdapter } from '../../../admin/RichText.js'\nimport type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { PayloadRequestWithData, RequestContext } from '../../../types/index.js'\nimport type { Field, TabAsField } from '../../config/types.js'\n\nimport { MissingEditorProp } from '../../../errors/index.js'\nimport { fieldAffectsData, tabHasName } from '../../config/types.js'\nimport getValueWithDefault from '../../getDefaultValue.js'\nimport { getFieldPaths } from '../../getFieldPaths.js'\nimport { relationshipPopulationPromise } from './relationshipPopulationPromise.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n collection: SanitizedCollectionConfig | null\n context: RequestContext\n currentDepth: number\n depth: number\n doc: Record<string, unknown>\n draft: boolean\n fallbackLocale: null | string\n field: Field | TabAsField\n /**\n * fieldPromises are used for things like field hooks. They should be awaited before awaiting populationPromises\n */\n fieldPromises: Promise<void>[]\n findMany: boolean\n flattenLocales: boolean\n global: SanitizedGlobalConfig | null\n locale: null | string\n overrideAccess: boolean\n /**\n * The parent's path.\n */\n parentPath: (number | string)[]\n /**\n * The parent's schemaPath (path without indexes).\n */\n parentSchemaPath: string[]\n populationPromises: Promise<void>[]\n req: PayloadRequestWithData\n showHiddenFields: boolean\n siblingDoc: Record<string, unknown>\n triggerAccessControl?: boolean\n triggerHooks?: boolean\n}\n\n// This function is responsible for the following actions, in order:\n// - Remove hidden fields from response\n// - Flatten locales into requested locale\n// - Sanitize outgoing data (point field, etc.)\n// - Execute field hooks\n// - Execute read access control\n// - Populate relationships\n\nexport const promise = async ({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentPath,\n parentSchemaPath,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl = true,\n triggerHooks = true,\n}: Args): Promise<void> => {\n const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({\n field,\n parentPath,\n parentSchemaPath,\n })\n\n if (\n fieldAffectsData(field) &&\n field.hidden &&\n typeof siblingDoc[field.name] !== 'undefined' &&\n !showHiddenFields\n ) {\n delete siblingDoc[field.name]\n }\n\n const shouldHoistLocalizedValue =\n flattenLocales &&\n fieldAffectsData(field) &&\n typeof siblingDoc[field.name] === 'object' &&\n siblingDoc[field.name] !== null &&\n field.localized &&\n locale !== 'all' &&\n req.payload.config.localization\n\n if (shouldHoistLocalizedValue) {\n // replace actual value with localized value before sanitizing\n // { [locale]: fields } -> fields\n const value = siblingDoc[field.name][locale]\n\n let hoistedValue = value\n\n if (fallbackLocale && fallbackLocale !== locale) {\n const fallbackValue = siblingDoc[field.name][fallbackLocale]\n const isNullOrUndefined = typeof value === 'undefined' || value === null\n\n if (fallbackValue) {\n switch (field.type) {\n case 'text':\n case 'textarea': {\n if (value === '' || isNullOrUndefined) {\n hoistedValue = fallbackValue\n }\n break\n }\n\n default: {\n if (isNullOrUndefined) {\n hoistedValue = fallbackValue\n }\n break\n }\n }\n }\n }\n\n siblingDoc[field.name] = hoistedValue\n }\n\n // Sanitize outgoing field value\n switch (field.type) {\n case 'group': {\n // Fill groups with empty objects so fields with hooks within groups can populate\n // themselves virtually as necessary\n if (typeof siblingDoc[field.name] === 'undefined') {\n siblingDoc[field.name] = {}\n }\n\n break\n }\n case 'tabs': {\n field.tabs.forEach((tab) => {\n if (\n tabHasName(tab) &&\n (typeof siblingDoc[tab.name] === 'undefined' || siblingDoc[tab.name] === null)\n ) {\n siblingDoc[tab.name] = {}\n }\n })\n\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n if (typeof field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n // Rich Text fields should use afterRead hooks to do population. The previous editor.populationPromises have been renamed to editor.graphQLPopulationPromises\n break\n }\n\n case 'point': {\n const pointDoc = siblingDoc[field.name] as Record<string, unknown>\n if (Array.isArray(pointDoc?.coordinates) && pointDoc.coordinates.length === 2) {\n siblingDoc[field.name] = pointDoc.coordinates\n } else {\n siblingDoc[field.name] = undefined\n }\n\n break\n }\n\n default: {\n break\n }\n }\n\n if (fieldAffectsData(field)) {\n // Execute hooks\n if (triggerHooks && field.hooks?.afterRead) {\n await field.hooks.afterRead.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const shouldRunHookOnAllLocales =\n field.localized &&\n (locale === 'all' || !flattenLocales) &&\n typeof siblingDoc[field.name] === 'object'\n\n if (shouldRunHookOnAllLocales) {\n const hookPromises = Object.entries(siblingDoc[field.name]).map(([locale, value]) =>\n (async () => {\n const hookedValue = await currentHook({\n collection,\n context,\n data: doc,\n field,\n findMany,\n global,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingDoc,\n value,\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name][locale] = hookedValue\n }\n })(),\n )\n\n await Promise.all(hookPromises)\n } else {\n const hookedValue = await currentHook({\n collection,\n context,\n data: doc,\n field,\n findMany,\n global,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingDoc,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }\n }, Promise.resolve())\n }\n\n // Execute access control\n let allowDefaultValue = true\n if (triggerAccessControl && field.access && field.access.read) {\n const result = overrideAccess\n ? true\n : await field.access.read({\n id: doc.id as number | string,\n data: doc,\n doc,\n req,\n siblingData: siblingDoc,\n })\n\n if (!result) {\n allowDefaultValue = false\n delete siblingDoc[field.name]\n }\n }\n\n // Set defaultValue on the field for globals being returned without being first created\n // or collection documents created prior to having a default\n if (\n allowDefaultValue &&\n typeof siblingDoc[field.name] === 'undefined' &&\n typeof field.defaultValue !== 'undefined'\n ) {\n siblingDoc[field.name] = await getValueWithDefault({\n defaultValue: field.defaultValue,\n locale,\n user: req.user,\n value: siblingDoc[field.name],\n })\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n populationPromises.push(\n relationshipPopulationPromise({\n currentDepth,\n depth,\n draft,\n fallbackLocale,\n field,\n locale,\n overrideAccess,\n req,\n showHiddenFields,\n siblingDoc,\n }),\n )\n }\n }\n\n switch (field.type) {\n case 'group': {\n let groupDoc = siblingDoc[field.name] as Record<string, unknown>\n if (typeof siblingDoc[field.name] !== 'object') groupDoc = {}\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: fieldPath,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingDoc: groupDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'array': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n rows.forEach((row, i) => {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: [...fieldPath, i],\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n })\n } else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {\n Object.values(rows).forEach((localeRows) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, i) => {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: [...fieldPath, i],\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n })\n }\n })\n } else {\n siblingDoc[field.name] = []\n }\n break\n }\n\n case 'blocks': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n rows.forEach((row, i) => {\n const block = field.blocks.find((blockType) => blockType.slug === row.blockType)\n\n if (block) {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: block.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: [...fieldPath, i],\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n }\n })\n } else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {\n Object.values(rows).forEach((localeRows) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, i) => {\n const block = field.blocks.find((blockType) => blockType.slug === row.blockType)\n\n if (block) {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: block.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: [...fieldPath, i],\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n }\n })\n }\n })\n } else {\n siblingDoc[field.name] = []\n }\n\n break\n }\n\n case 'row':\n case 'collapsible': {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: fieldPath,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'tab': {\n let tabDoc = siblingDoc\n if (tabHasName(field)) {\n tabDoc = siblingDoc[field.name] as Record<string, unknown>\n if (typeof siblingDoc[field.name] !== 'object') tabDoc = {}\n }\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: fieldPath,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingDoc: tabDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'tabs': {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: fieldPath,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n if (typeof field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n const editor: RichTextAdapter = field?.editor\n\n if (editor?.hooks?.afterRead?.length) {\n await editor.hooks.afterRead.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const shouldRunHookOnAllLocales =\n field.localized &&\n (locale === 'all' || !flattenLocales) &&\n typeof siblingDoc[field.name] === 'object'\n\n if (shouldRunHookOnAllLocales) {\n const hookPromises = Object.entries(siblingDoc[field.name]).map(([locale, value]) =>\n (async () => {\n const hookedValue = await currentHook({\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n fallbackLocale,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n locale,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n path: fieldPath,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingData: siblingDoc,\n triggerAccessControl,\n triggerHooks,\n value,\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name][locale] = hookedValue\n }\n })(),\n )\n\n await Promise.all(hookPromises)\n } else {\n const hookedValue = await currentHook({\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n fallbackLocale,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n locale,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n path: fieldPath,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingData: siblingDoc,\n triggerAccessControl,\n triggerHooks,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }\n }, Promise.resolve())\n }\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["MissingEditorProp","fieldAffectsData","tabHasName","getValueWithDefault","getFieldPaths","relationshipPopulationPromise","traverseFields","promise","collection","context","currentDepth","depth","doc","draft","fallbackLocale","field","fieldPromises","findMany","flattenLocales","global","locale","overrideAccess","parentPath","parentSchemaPath","populationPromises","req","showHiddenFields","siblingDoc","triggerAccessControl","triggerHooks","path","fieldPath","schemaPath","fieldSchemaPath","hidden","name","shouldHoistLocalizedValue","localized","payload","config","localization","value","hoistedValue","fallbackValue","isNullOrUndefined","type","tabs","forEach","tab","editor","Error","pointDoc","Array","isArray","coordinates","length","undefined","hooks","afterRead","reduce","priorHook","currentHook","shouldRunHookOnAllLocales","hookPromises","Object","entries","map","hookedValue","data","operation","originalDoc","siblingData","Promise","all","resolve","allowDefaultValue","access","read","result","id","defaultValue","user","push","groupDoc","fields","rows","row","i","values","localeRows","block","blocks","find","blockType","slug","tabDoc"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AACV;wBACpB,OAAO;4BACL,MAAMI,cAAc,MAAMN,YAAY;gCACpCrD;gCACAC;gCACAC;gCACA0D,MAAMxD;gCACND;gCACAE;gCACAC;gCACAC;gCACAC;gCACAC;gCACAC;gCACAC;gCACAC;gCACAiD,WAAW;gCACXC,aAAa1D;gCACbS;gCACAS,MAAMC;gCACNP;gCACAC;gCACAO,YAAYC;gCACZP;gCACA6C,aAAa5C;gCACbC;gCACAC;gCACAY,OAAOd,UAAU,CAACZ,MAAMoB,IAAI,CAAC;4BAC/B;4BAEA,IAAIgC,gBAAgBX,WAAW;gCAC7B7B,UAAU,CAACZ,MAAMoB,IAAI,CAAC,GAAGgC;4BAC3B;wBACF;oBACF,GAAGK,QAAQE,OAAO;gBACpB;gBACA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
|
|
@@ -20,13 +20,15 @@ type Args = {
|
|
|
20
20
|
global: SanitizedGlobalConfig | null;
|
|
21
21
|
locale: null | string;
|
|
22
22
|
overrideAccess: boolean;
|
|
23
|
+
path: (number | string)[];
|
|
23
24
|
populationPromises: Promise<void>[];
|
|
24
25
|
req: PayloadRequestWithData;
|
|
26
|
+
schemaPath: string[];
|
|
25
27
|
showHiddenFields: boolean;
|
|
26
28
|
siblingDoc: Record<string, unknown>;
|
|
27
29
|
triggerAccessControl?: boolean;
|
|
28
30
|
triggerHooks?: boolean;
|
|
29
31
|
};
|
|
30
|
-
export declare const traverseFields: ({ collection, context, currentDepth, depth, doc, draft, fallbackLocale, fieldPromises, fields, findMany, flattenLocales, global, locale, overrideAccess, populationPromises, req, showHiddenFields, siblingDoc, triggerAccessControl, triggerHooks, }: Args) => void;
|
|
32
|
+
export declare const traverseFields: ({ collection, context, currentDepth, depth, doc, draft, fallbackLocale, fieldPromises, fields, findMany, flattenLocales, global, locale, overrideAccess, path, populationPromises, req, schemaPath, showHiddenFields, siblingDoc, triggerAccessControl, triggerHooks, }: Args) => void;
|
|
31
33
|
export {};
|
|
32
34
|
//# sourceMappingURL=traverseFields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACrF,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAI9D,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,yBAAyB,GAAG,IAAI,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5B,KAAK,EAAE,OAAO,CAAA;IACd,cAAc,EAAE,IAAI,GAAG,MAAM,CAAA;IAC7B;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAA;IAC9B,MAAM,EAAE,CAAC,KAAK,GAAG,UAAU,CAAC,EAAE,CAAA;IAC9B,QAAQ,EAAE,OAAO,CAAA;IACjB,cAAc,EAAE,OAAO,CAAA;IACvB,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAAA;IACpC,MAAM,EAAE,IAAI,GAAG,MAAM,CAAA;IACrB,cAAc,EAAE,OAAO,CAAA;IACvB,kBAAkB,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAA;IACnC,GAAG,EAAE,sBAAsB,CAAA;IAC3B,gBAAgB,EAAE,OAAO,CAAA;IACzB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,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AAO,CAAA;IACzB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,cAAc,4QAuBxB,IAAI,KAAG,IA6BT,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { promise } from './promise.js';
|
|
2
|
-
export const traverseFields = ({ collection, context, currentDepth, depth, doc, draft, fallbackLocale, fieldPromises, fields, findMany, flattenLocales, global, locale, overrideAccess, populationPromises, req, showHiddenFields, siblingDoc, triggerAccessControl = true, triggerHooks = true })=>{
|
|
2
|
+
export const traverseFields = ({ collection, context, currentDepth, depth, doc, draft, fallbackLocale, fieldPromises, fields, findMany, flattenLocales, global, locale, overrideAccess, path, populationPromises, req, schemaPath, showHiddenFields, siblingDoc, triggerAccessControl = true, triggerHooks = true })=>{
|
|
3
3
|
fields.forEach((field)=>{
|
|
4
4
|
fieldPromises.push(promise({
|
|
5
5
|
collection,
|
|
@@ -16,6 +16,8 @@ export const traverseFields = ({ collection, context, currentDepth, depth, doc,
|
|
|
16
16
|
global,
|
|
17
17
|
locale,
|
|
18
18
|
overrideAccess,
|
|
19
|
+
parentPath: path,
|
|
20
|
+
parentSchemaPath: schemaPath,
|
|
19
21
|
populationPromises,
|
|
20
22
|
req,
|
|
21
23
|
showHiddenFields,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/afterRead/traverseFields.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { PayloadRequestWithData, RequestContext } from '../../../types/index.js'\nimport type { Field, TabAsField } from '../../config/types.js'\n\nimport { promise } from './promise.js'\n\ntype Args = {\n collection: SanitizedCollectionConfig | null\n context: RequestContext\n currentDepth: number\n depth: number\n doc: Record<string, unknown>\n draft: boolean\n fallbackLocale: null | string\n /**\n * fieldPromises are used for things like field hooks. They should be awaited before awaiting populationPromises\n */\n fieldPromises: Promise<void>[]\n fields: (Field | TabAsField)[]\n findMany: boolean\n flattenLocales: boolean\n global: SanitizedGlobalConfig | null\n locale: null | string\n overrideAccess: boolean\n populationPromises: Promise<void>[]\n req: PayloadRequestWithData\n showHiddenFields: boolean\n siblingDoc: Record<string, unknown>\n triggerAccessControl?: boolean\n triggerHooks?: boolean\n}\n\nexport const traverseFields = ({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl = true,\n triggerHooks = true,\n}: Args): void => {\n fields.forEach((field) => {\n fieldPromises.push(\n promise({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n }),\n )\n })\n}\n"],"names":["promise","traverseFields","collection","context","currentDepth","depth","doc","draft","fallbackLocale","fieldPromises","fields","findMany","flattenLocales","global","locale","overrideAccess","populationPromises","req","showHiddenFields","siblingDoc","triggerAccessControl","triggerHooks","forEach","field","push"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/afterRead/traverseFields.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { PayloadRequestWithData, RequestContext } from '../../../types/index.js'\nimport type { Field, TabAsField } from '../../config/types.js'\n\nimport { promise } from './promise.js'\n\ntype Args = {\n collection: SanitizedCollectionConfig | null\n context: RequestContext\n currentDepth: number\n depth: number\n doc: Record<string, unknown>\n draft: boolean\n fallbackLocale: null | string\n /**\n * fieldPromises are used for things like field hooks. They should be awaited before awaiting populationPromises\n */\n fieldPromises: Promise<void>[]\n fields: (Field | TabAsField)[]\n findMany: boolean\n flattenLocales: boolean\n global: SanitizedGlobalConfig | null\n locale: null | string\n overrideAccess: boolean\n path: (number | string)[]\n populationPromises: Promise<void>[]\n req: PayloadRequestWithData\n schemaPath: string[]\n showHiddenFields: boolean\n siblingDoc: Record<string, unknown>\n triggerAccessControl?: boolean\n triggerHooks?: boolean\n}\n\nexport const traverseFields = ({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path,\n populationPromises,\n req,\n schemaPath,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl = true,\n triggerHooks = true,\n}: Args): void => {\n fields.forEach((field) => {\n fieldPromises.push(\n promise({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentPath: path,\n parentSchemaPath: schemaPath,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n }),\n )\n })\n}\n"],"names":["promise","traverseFields","collection","context","currentDepth","depth","doc","draft","fallbackLocale","fieldPromises","fields","findMany","flattenLocales","global","locale","overrideAccess","path","populationPromises","req","schemaPath","showHiddenFields","siblingDoc","triggerAccessControl","triggerHooks","forEach","field","push","parentPath","parentSchemaPath"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAKA,SAASA,OAAO,QAAQ,eAAc;AA8BtC,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,UAAU,EACVC,OAAO,EACPC,YAAY,EACZC,KAAK,EACLC,GAAG,EACHC,KAAK,EACLC,cAAc,EACdC,aAAa,EACbC,MAAM,EACNC,QAAQ,EACRC,cAAc,EACdC,MAAM,EACNC,MAAM,EACNC,cAAc,EACdC,IAAI,EACJC,kBAAkB,EAClBC,GAAG,EACHC,UAAU,EACVC,gBAAgB,EAChBC,UAAU,EACVC,uBAAuB,IAAI,EAC3BC,eAAe,IAAI,EACd;IACLb,OAAOc,OAAO,CAAC,CAACC;QACdhB,cAAciB,IAAI,CAChB1B,QAAQ;YACNE;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAiB;YACAhB;YACAE;YACAC;YACAC;YACAC;YACAC;YACAY,YAAYX;YACZY,kBAAkBT;YAClBF;YACAC;YACAE;YACAC;YACAC;YACAC;QACF;IAEJ;AACF,EAAC"}
|
|
@@ -21,7 +21,7 @@ type Args<T> = {
|
|
|
21
21
|
* - Validate data
|
|
22
22
|
* - Transform data for storage
|
|
23
23
|
* - beforeDuplicate hooks (if duplicate)
|
|
24
|
-
* - Unflatten locales
|
|
24
|
+
* - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.
|
|
25
25
|
*/
|
|
26
26
|
export declare const beforeChange: <T extends Record<string, unknown>>({ id, collection, context, data: incomingData, doc, docWithLocales, duplicate, global, operation, req, skipValidation, }: Args<T>) => Promise<T>;
|
|
27
27
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAMhG,KAAK,IAAI,CAAC,CAAC,IAAI;IACb,UAAU,EAAE,yBAAyB,GAAG,IAAI,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IACjC,GAAG,EAAE,M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AAsB,CAAA;IAC3B,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,gKAYtB,KAAK,CAAC,CAAC,KAAG,QAAQ,CAAC,CAqCrB,CAAA"}
|
|
@@ -8,7 +8,7 @@ import { traverseFields } from './traverseFields.js';
|
|
|
8
8
|
* - Validate data
|
|
9
9
|
* - Transform data for storage
|
|
10
10
|
* - beforeDuplicate hooks (if duplicate)
|
|
11
|
-
* - Unflatten locales
|
|
11
|
+
* - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.
|
|
12
12
|
*/ export const beforeChange = async ({ id, collection, context, data: incomingData, doc, docWithLocales, duplicate = false, global, operation, req, skipValidation })=>{
|
|
13
13
|
const data = deepCopyObject(incomingData);
|
|
14
14
|
const mergeLocaleActions = [];
|
|
@@ -26,8 +26,9 @@ import { traverseFields } from './traverseFields.js';
|
|
|
26
26
|
global,
|
|
27
27
|
mergeLocaleActions,
|
|
28
28
|
operation,
|
|
29
|
-
path:
|
|
29
|
+
path: [],
|
|
30
30
|
req,
|
|
31
|
+
schemaPath: [],
|
|
31
32
|
siblingData: data,
|
|
32
33
|
siblingDoc: doc,
|
|
33
34
|
siblingDocWithLocales: docWithLocales,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/beforeChange/index.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { Operation, PayloadRequestWithData, RequestContext } from '../../../types/index.js'\n\nimport { ValidationError } from '../../../errors/index.js'\nimport { deepCopyObject } from '../../../utilities/deepCopyObject.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args<T> = {\n collection: SanitizedCollectionConfig | null\n context: RequestContext\n data: Record<string, unknown> | T\n doc: Record<string, unknown> | T\n docWithLocales: Record<string, unknown>\n duplicate?: boolean\n global: SanitizedGlobalConfig | null\n id?: number | string\n operation: Operation\n req: PayloadRequestWithData\n skipValidation?: boolean\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Run condition\n * - Execute field hooks\n * - Validate data\n * - Transform data for storage\n * - beforeDuplicate hooks (if duplicate)\n * - Unflatten locales
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/beforeChange/index.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { Operation, PayloadRequestWithData, RequestContext } from '../../../types/index.js'\n\nimport { ValidationError } from '../../../errors/index.js'\nimport { deepCopyObject } from '../../../utilities/deepCopyObject.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args<T> = {\n collection: SanitizedCollectionConfig | null\n context: RequestContext\n data: Record<string, unknown> | T\n doc: Record<string, unknown> | T\n docWithLocales: Record<string, unknown>\n duplicate?: boolean\n global: SanitizedGlobalConfig | null\n id?: number | string\n operation: Operation\n req: PayloadRequestWithData\n skipValidation?: boolean\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Run condition\n * - Execute field hooks\n * - Validate data\n * - Transform data for storage\n * - beforeDuplicate hooks (if duplicate)\n * - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.\n */\nexport const beforeChange = async <T extends Record<string, unknown>>({\n id,\n collection,\n context,\n data: incomingData,\n doc,\n docWithLocales,\n duplicate = false,\n global,\n operation,\n req,\n skipValidation,\n}: Args<T>): Promise<T> => {\n const data = deepCopyObject(incomingData)\n const mergeLocaleActions = []\n const errors: { field: string; message: string }[] = []\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: collection?.fields || global?.fields,\n global,\n mergeLocaleActions,\n operation,\n path: [],\n req,\n schemaPath: [],\n siblingData: data,\n siblingDoc: doc,\n siblingDocWithLocales: docWithLocales,\n skipValidation,\n })\n\n if (errors.length > 0) {\n throw new ValidationError(errors, req.t)\n }\n\n await mergeLocaleActions.reduce(async (priorAction, action) => {\n await priorAction\n await action()\n }, Promise.resolve())\n\n return data\n}\n"],"names":["ValidationError","deepCopyObject","traverseFields","beforeChange","id","collection","context","data","incomingData","doc","docWithLocales","duplicate","global","operation","req","skipValidation","mergeLocaleActions","errors","fields","path","schemaPath","siblingData","siblingDoc","siblingDocWithLocales","length","t","reduce","priorAction","action","Promise","resolve"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,cAAc,QAAQ,sBAAqB;AAgBpD;;;;;;;;CAQC,GACD,OAAO,MAAMC,eAAe,OAA0C,EACpEC,EAAE,EACFC,UAAU,EACVC,OAAO,EACPC,MAAMC,YAAY,EAClBC,GAAG,EACHC,cAAc,EACdC,YAAY,KAAK,EACjBC,MAAM,EACNC,SAAS,EACTC,GAAG,EACHC,cAAc,EACN;IACR,MAAMR,OAAON,eAAeO;IAC5B,MAAMQ,qBAAqB,EAAE;IAC7B,MAAMC,SAA+C,EAAE;IAEvD,MAAMf,eAAe;QACnBE;QACAC;QACAC;QACAC;QACAE;QACAC;QACAC;QACAM;QACAC,QAAQb,YAAYa,UAAUN,QAAQM;QACtCN;QACAI;QACAH;QACAM,MAAM,EAAE;QACRL;QACAM,YAAY,EAAE;QACdC,aAAad;QACbe,YAAYb;QACZc,uBAAuBb;QACvBK;IACF;IAEA,IAAIE,OAAOO,MAAM,GAAG,GAAG;QACrB,MAAM,IAAIxB,gBAAgBiB,QAAQH,IAAIW,CAAC;IACzC;IAEA,MAAMT,mBAAmBU,MAAM,CAAC,OAAOC,aAAaC;QAClD,MAAMD;QACN,MAAMC;IACR,GAAGC,QAAQC,OAAO;IAElB,OAAOvB;AACT,EAAC"}
|
|
@@ -18,13 +18,20 @@ type Args = {
|
|
|
18
18
|
id?: number | string;
|
|
19
19
|
mergeLocaleActions: (() => Promise<void>)[];
|
|
20
20
|
operation: Operation;
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* The parent's path.
|
|
23
|
+
*/
|
|
24
|
+
parentPath: (number | string)[];
|
|
25
|
+
/**
|
|
26
|
+
* The parent's schemaPath (path without indexes).
|
|
27
|
+
*/
|
|
28
|
+
parentSchemaPath: string[];
|
|
22
29
|
req: PayloadRequestWithData;
|
|
23
30
|
siblingData: Record<string, unknown>;
|
|
24
31
|
siblingDoc: Record<string, unknown>;
|
|
25
32
|
siblingDocWithLocales?: Record<string, unknown>;
|
|
26
33
|
skipValidation: boolean;
|
|
27
34
|
};
|
|
28
|
-
export declare const promise: ({ id, collection, context, data, doc, docWithLocales, duplicate, errors, field, global, mergeLocaleActions, operation,
|
|
35
|
+
export declare const promise: ({ id, collection, context, data, doc, docWithLocales, duplicate, errors, field, global, mergeLocaleActions, operation, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, skipValidation, }: Args) => Promise<void>;
|
|
29
36
|
export {};
|
|
30
37
|
//# sourceMappingURL=promise.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/promise.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/promise.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAChG,OAAO,KAAK,EAAE,KAAK,EAAiB,UAAU,EAAmB,MAAM,uBAAuB,CAAA;AAS9F,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,yBAAyB,GAAG,IAA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