payload 3.0.0-beta.45 → 3.0.0-beta.47
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/admin/views/types.d.ts +1 -1
- package/dist/admin/views/types.d.ts.map +1 -1
- package/dist/admin/views/types.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/operations/local/login.d.ts +1 -2
- package/dist/auth/operations/local/login.d.ts.map +1 -1
- package/dist/auth/operations/local/login.js.map +1 -1
- package/dist/auth/operations/local/resetPassword.d.ts +1 -2
- package/dist/auth/operations/local/resetPassword.d.ts.map +1 -1
- package/dist/auth/operations/local/resetPassword.js.map +1 -1
- package/dist/auth/operations/local/unlock.d.ts +1 -2
- package/dist/auth/operations/local/unlock.d.ts.map +1 -1
- package/dist/auth/operations/local/unlock.js.map +1 -1
- package/dist/auth/operations/local/verifyEmail.d.ts +1 -2
- package/dist/auth/operations/local/verifyEmail.d.ts.map +1 -1
- package/dist/auth/operations/local/verifyEmail.js.map +1 -1
- package/dist/auth/operations/refresh.d.ts +1 -2
- package/dist/auth/operations/refresh.d.ts.map +1 -1
- package/dist/auth/operations/refresh.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/collections/operations/local/create.d.ts +1 -2
- package/dist/collections/operations/local/create.d.ts.map +1 -1
- package/dist/collections/operations/local/create.js.map +1 -1
- package/dist/collections/operations/local/delete.d.ts +2 -4
- package/dist/collections/operations/local/delete.d.ts.map +1 -1
- package/dist/collections/operations/local/delete.js.map +1 -1
- package/dist/config/defaults.js +1 -1
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +9 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/config/shared/openGraphSchema.js +2 -2
- package/dist/config/shared/openGraphSchema.js.map +1 -1
- package/dist/config/types.d.ts +1 -1
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.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/dist/globals/config/types.d.ts +1 -2
- package/dist/globals/config/types.d.ts.map +1 -1
- package/dist/globals/config/types.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/uploads/cropImage.js +2 -2
- package/dist/uploads/cropImage.js.map +1 -1
- package/dist/uploads/generateFileData.js +4 -4
- package/dist/uploads/generateFileData.js.map +1 -1
- package/dist/uploads/getBaseFields.js +1 -1
- package/dist/uploads/getBaseFields.js.map +1 -1
- package/dist/uploads/imageResizer.d.ts.map +1 -1
- package/dist/uploads/imageResizer.js +21 -11
- package/dist/uploads/imageResizer.js.map +1 -1
- package/package.json +2 -2
|
@@ -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,IAAI,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5B,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACvC,SAAS,EAAE,OAAO,CAAA;IAClB,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAC5C,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAAA;IACpC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,kBAAkB,EAAE,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAA;IAC3C,SAAS,EAAE,SAAS,CAAA;IACpB;;OAEG;IACH,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IAC/B;;OAEG;IACH,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B,GAAG,EAAE,sBAAsB,CAAA;IAC3B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/C,cAAc,EAAE,OAAO,CAAA;CACxB,CAAA;AAUD,eAAO,MAAM,OAAO,gOAoBjB,IAAI,KAAG,QAAQ,IAAI,CAmarB,CAAA"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import merge from 'deepmerge';
|
|
2
|
+
import { MissingEditorProp } from '../../../errors/index.js';
|
|
2
3
|
import { fieldAffectsData, tabHasName } from '../../config/types.js';
|
|
4
|
+
import { getFieldPaths } from '../../getFieldPaths.js';
|
|
3
5
|
import { beforeDuplicate } from './beforeDuplicate.js';
|
|
4
6
|
import { getExistingRowDoc } from './getExistingRowDoc.js';
|
|
5
7
|
import { traverseFields } from './traverseFields.js';
|
|
@@ -10,7 +12,7 @@ import { traverseFields } from './traverseFields.js';
|
|
|
10
12
|
// - Transform data for storage
|
|
11
13
|
// - beforeDuplicate hooks (if duplicate)
|
|
12
14
|
// - Unflatten locales
|
|
13
|
-
export const promise = async ({ id, collection, context, data, doc, docWithLocales, duplicate, errors, field, global, mergeLocaleActions, operation,
|
|
15
|
+
export const promise = async ({ id, collection, context, data, doc, docWithLocales, duplicate, errors, field, global, mergeLocaleActions, operation, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, skipValidation })=>{
|
|
14
16
|
const passesCondition = field.admin?.condition ? Boolean(field.admin.condition(data, siblingData, {
|
|
15
17
|
user: req.user
|
|
16
18
|
})) : true;
|
|
@@ -18,6 +20,11 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
18
20
|
const { localization } = req.payload.config;
|
|
19
21
|
const defaultLocale = localization ? localization?.defaultLocale : 'en';
|
|
20
22
|
const operationLocale = req.locale || defaultLocale;
|
|
23
|
+
const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({
|
|
24
|
+
field,
|
|
25
|
+
parentPath,
|
|
26
|
+
parentSchemaPath
|
|
27
|
+
});
|
|
21
28
|
if (fieldAffectsData(field)) {
|
|
22
29
|
// skip validation if the field is localized and the incoming data is null
|
|
23
30
|
if (field.localized && operationLocale !== defaultLocale) {
|
|
@@ -40,10 +47,13 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
40
47
|
global,
|
|
41
48
|
operation,
|
|
42
49
|
originalDoc: doc,
|
|
50
|
+
path: fieldPath,
|
|
43
51
|
previousSiblingDoc: siblingDoc,
|
|
44
52
|
previousValue: siblingDoc[field.name],
|
|
45
53
|
req,
|
|
54
|
+
schemaPath: parentSchemaPath,
|
|
46
55
|
siblingData,
|
|
56
|
+
siblingDocWithLocales,
|
|
47
57
|
value: siblingData[field.name]
|
|
48
58
|
});
|
|
49
59
|
if (hookedValue !== undefined) {
|
|
@@ -80,7 +90,7 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
80
90
|
});
|
|
81
91
|
if (typeof validationResult === 'string') {
|
|
82
92
|
errors.push({
|
|
83
|
-
field:
|
|
93
|
+
field: fieldPath.join('.'),
|
|
84
94
|
message: validationResult
|
|
85
95
|
});
|
|
86
96
|
}
|
|
@@ -91,8 +101,13 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
91
101
|
data,
|
|
92
102
|
field,
|
|
93
103
|
global: undefined,
|
|
104
|
+
path: fieldPath,
|
|
105
|
+
previousSiblingDoc: siblingDoc,
|
|
106
|
+
previousValue: siblingDoc[field.name],
|
|
94
107
|
req,
|
|
108
|
+
schemaPath: parentSchemaPath,
|
|
95
109
|
siblingData,
|
|
110
|
+
siblingDocWithLocales,
|
|
96
111
|
value: siblingData[field.name]
|
|
97
112
|
};
|
|
98
113
|
// Push merge locale action if applicable
|
|
@@ -159,8 +174,9 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
159
174
|
global,
|
|
160
175
|
mergeLocaleActions,
|
|
161
176
|
operation,
|
|
162
|
-
path:
|
|
177
|
+
path: fieldPath,
|
|
163
178
|
req,
|
|
179
|
+
schemaPath: fieldSchemaPath,
|
|
164
180
|
siblingData: siblingData[field.name],
|
|
165
181
|
siblingDoc: siblingDoc[field.name],
|
|
166
182
|
siblingDocWithLocales: siblingDocWithLocales[field.name],
|
|
@@ -187,8 +203,12 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
187
203
|
global,
|
|
188
204
|
mergeLocaleActions,
|
|
189
205
|
operation,
|
|
190
|
-
path:
|
|
206
|
+
path: [
|
|
207
|
+
...fieldPath,
|
|
208
|
+
i
|
|
209
|
+
],
|
|
191
210
|
req,
|
|
211
|
+
schemaPath: fieldSchemaPath,
|
|
192
212
|
siblingData: row,
|
|
193
213
|
siblingDoc: getExistingRowDoc(row, siblingDoc[field.name]),
|
|
194
214
|
siblingDocWithLocales: getExistingRowDoc(row, siblingDocWithLocales[field.name]),
|
|
@@ -223,8 +243,12 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
223
243
|
global,
|
|
224
244
|
mergeLocaleActions,
|
|
225
245
|
operation,
|
|
226
|
-
path:
|
|
246
|
+
path: [
|
|
247
|
+
...fieldPath,
|
|
248
|
+
i
|
|
249
|
+
],
|
|
227
250
|
req,
|
|
251
|
+
schemaPath: fieldSchemaPath,
|
|
228
252
|
siblingData: row,
|
|
229
253
|
siblingDoc: rowSiblingDoc,
|
|
230
254
|
siblingDocWithLocales: rowSiblingDocWithLocales,
|
|
@@ -252,8 +276,9 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
252
276
|
global,
|
|
253
277
|
mergeLocaleActions,
|
|
254
278
|
operation,
|
|
255
|
-
path,
|
|
279
|
+
path: fieldPath,
|
|
256
280
|
req,
|
|
281
|
+
schemaPath: fieldSchemaPath,
|
|
257
282
|
siblingData,
|
|
258
283
|
siblingDoc,
|
|
259
284
|
siblingDocWithLocales,
|
|
@@ -263,12 +288,10 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
263
288
|
}
|
|
264
289
|
case 'tab':
|
|
265
290
|
{
|
|
266
|
-
let tabPath = path;
|
|
267
291
|
let tabSiblingData = siblingData;
|
|
268
292
|
let tabSiblingDoc = siblingDoc;
|
|
269
293
|
let tabSiblingDocWithLocales = siblingDocWithLocales;
|
|
270
294
|
if (tabHasName(field)) {
|
|
271
|
-
tabPath = `${path}${field.name}.`;
|
|
272
295
|
if (typeof siblingData[field.name] !== 'object') siblingData[field.name] = {};
|
|
273
296
|
if (typeof siblingDoc[field.name] !== 'object') siblingDoc[field.name] = {};
|
|
274
297
|
if (typeof siblingDocWithLocales[field.name] !== 'object') siblingDocWithLocales[field.name] = {};
|
|
@@ -289,8 +312,9 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
289
312
|
global,
|
|
290
313
|
mergeLocaleActions,
|
|
291
314
|
operation,
|
|
292
|
-
path:
|
|
315
|
+
path: fieldPath,
|
|
293
316
|
req,
|
|
317
|
+
schemaPath: fieldSchemaPath,
|
|
294
318
|
siblingData: tabSiblingData,
|
|
295
319
|
siblingDoc: tabSiblingDoc,
|
|
296
320
|
siblingDocWithLocales: tabSiblingDocWithLocales,
|
|
@@ -316,8 +340,9 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
316
340
|
global,
|
|
317
341
|
mergeLocaleActions,
|
|
318
342
|
operation,
|
|
319
|
-
path,
|
|
343
|
+
path: fieldPath,
|
|
320
344
|
req,
|
|
345
|
+
schemaPath: fieldSchemaPath,
|
|
321
346
|
siblingData,
|
|
322
347
|
siblingDoc,
|
|
323
348
|
siblingDocWithLocales,
|
|
@@ -325,6 +350,48 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
325
350
|
});
|
|
326
351
|
break;
|
|
327
352
|
}
|
|
353
|
+
case 'richText':
|
|
354
|
+
{
|
|
355
|
+
if (!field?.editor) {
|
|
356
|
+
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
|
|
357
|
+
;
|
|
358
|
+
}
|
|
359
|
+
if (typeof field?.editor === 'function') {
|
|
360
|
+
throw new Error('Attempted to access unsanitized rich text editor.');
|
|
361
|
+
}
|
|
362
|
+
const editor = field?.editor;
|
|
363
|
+
if (editor?.hooks?.beforeChange?.length) {
|
|
364
|
+
await editor.hooks.beforeChange.reduce(async (priorHook, currentHook)=>{
|
|
365
|
+
await priorHook;
|
|
366
|
+
const hookedValue = await currentHook({
|
|
367
|
+
collection,
|
|
368
|
+
context,
|
|
369
|
+
data,
|
|
370
|
+
docWithLocales,
|
|
371
|
+
duplicate,
|
|
372
|
+
errors,
|
|
373
|
+
field,
|
|
374
|
+
global,
|
|
375
|
+
mergeLocaleActions,
|
|
376
|
+
operation,
|
|
377
|
+
originalDoc: doc,
|
|
378
|
+
path: fieldPath,
|
|
379
|
+
previousSiblingDoc: siblingDoc,
|
|
380
|
+
previousValue: siblingDoc[field.name],
|
|
381
|
+
req,
|
|
382
|
+
schemaPath: parentSchemaPath,
|
|
383
|
+
siblingData,
|
|
384
|
+
siblingDocWithLocales,
|
|
385
|
+
skipValidation,
|
|
386
|
+
value: siblingData[field.name]
|
|
387
|
+
});
|
|
388
|
+
if (hookedValue !== undefined) {
|
|
389
|
+
siblingData[field.name] = hookedValue;
|
|
390
|
+
}
|
|
391
|
+
}, Promise.resolve());
|
|
392
|
+
}
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
328
395
|
default:
|
|
329
396
|
{
|
|
330
397
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/beforeChange/promise.ts"],"sourcesContent":["import merge from 'deepmerge'\n\nimport type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { Operation, PayloadRequestWithData, RequestContext } from '../../../types/index.js'\nimport type { Field, FieldHookArgs, TabAsField, ValidateOptions } from '../../config/types.js'\n\nimport { fieldAffectsData, tabHasName } from '../../config/types.js'\nimport { beforeDuplicate } from './beforeDuplicate.js'\nimport { getExistingRowDoc } from './getExistingRowDoc.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n collection: SanitizedCollectionConfig | null\n context: RequestContext\n data: Record<string, unknown>\n doc: Record<string, unknown>\n docWithLocales: Record<string, unknown>\n duplicate: boolean\n errors: { field: string; message: string }[]\n field: Field | TabAsField\n global: SanitizedGlobalConfig | null\n id?: number | string\n mergeLocaleActions: (() => Promise<void>)[]\n operation: Operation\n path: string\n req: PayloadRequestWithData\n siblingData: Record<string, unknown>\n siblingDoc: Record<string, unknown>\n siblingDocWithLocales?: Record<string, unknown>\n skipValidation: boolean\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\n\nexport const promise = async ({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n field,\n global,\n mergeLocaleActions,\n operation,\n path,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation,\n}: Args): Promise<void> => {\n const passesCondition = field.admin?.condition\n ? Boolean(field.admin.condition(data, siblingData, { user: req.user }))\n : true\n let skipValidationFromHere = skipValidation || !passesCondition\n const { localization } = req.payload.config\n const defaultLocale = localization ? localization?.defaultLocale : 'en'\n const operationLocale = req.locale || defaultLocale\n\n if (fieldAffectsData(field)) {\n // skip validation if the field is localized and the incoming data is null\n if (field.localized && operationLocale !== defaultLocale) {\n if (['array', 'blocks'].includes(field.type) && siblingData[field.name] === null) {\n skipValidationFromHere = true\n }\n }\n\n // Execute hooks\n if (field.hooks?.beforeChange) {\n await field.hooks.beforeChange.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const hookedValue = await currentHook({\n collection,\n context,\n data,\n field,\n global,\n operation,\n originalDoc: doc,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n siblingData,\n value: siblingData[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingData[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n\n // Validate\n if (!skipValidationFromHere && field.validate) {\n const valueToValidate = siblingData[field.name]\n let jsonError: object\n\n if (field.type === 'json' && typeof siblingData[field.name] === 'string') {\n try {\n JSON.parse(siblingData[field.name] as string)\n } catch (e) {\n jsonError = e\n }\n }\n\n const validationResult = await field.validate(valueToValidate, {\n ...field,\n id,\n data: merge(doc, data, { arrayMerge: (_, source) => source }),\n jsonError,\n operation,\n preferences: { fields: {} },\n req,\n siblingData: merge(siblingDoc, siblingData, { arrayMerge: (_, source) => source }),\n } as ValidateOptions<any, any, { jsonError: object }>)\n\n if (typeof validationResult === 'string') {\n errors.push({\n field: `${path}${field.name}`,\n message: validationResult,\n })\n }\n }\n\n const beforeDuplicateArgs: FieldHookArgs = {\n collection,\n context,\n data,\n field,\n global: undefined,\n req,\n siblingData,\n value: siblingData[field.name],\n }\n\n // Push merge locale action if applicable\n if (localization && field.localized) {\n mergeLocaleActions.push(async () => {\n const localeData = await localization.localeCodes.reduce(\n async (localizedValuesPromise: Promise<Record<string, unknown>>, locale) => {\n const localizedValues = await localizedValuesPromise\n let fieldValue =\n locale === req.locale\n ? siblingData[field.name]\n : siblingDocWithLocales?.[field.name]?.[locale]\n\n if (duplicate && field.hooks?.beforeDuplicate?.length) {\n beforeDuplicateArgs.value = fieldValue\n fieldValue = await beforeDuplicate(beforeDuplicateArgs)\n }\n\n // const result = await localizedValues\n // update locale value if it's not undefined\n if (typeof fieldValue !== 'undefined') {\n return {\n ...localizedValues,\n [locale]: fieldValue,\n }\n }\n\n return localizedValuesPromise\n },\n Promise.resolve({}),\n )\n\n // If there are locales with data, set the data\n if (Object.keys(localeData).length > 0) {\n siblingData[field.name] = localeData\n }\n })\n } else if (duplicate && field.hooks?.beforeDuplicate?.length) {\n mergeLocaleActions.push(async () => {\n siblingData[field.name] = await beforeDuplicate(beforeDuplicateArgs)\n })\n }\n }\n\n switch (field.type) {\n case 'point': {\n // Transform point data for storage\n if (\n Array.isArray(siblingData[field.name]) &&\n siblingData[field.name][0] !== null &&\n siblingData[field.name][1] !== null\n ) {\n siblingData[field.name] = {\n type: 'Point',\n coordinates: [\n parseFloat(siblingData[field.name][0]),\n parseFloat(siblingData[field.name][1]),\n ],\n }\n }\n\n break\n }\n\n case 'group': {\n if (typeof siblingData[field.name] !== 'object') siblingData[field.name] = {}\n if (typeof siblingDoc[field.name] !== 'object') siblingDoc[field.name] = {}\n if (typeof siblingDocWithLocales[field.name] !== 'object')\n siblingDocWithLocales[field.name] = {}\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: `${path}${field.name}.`,\n req,\n siblingData: siblingData[field.name] as Record<string, unknown>,\n siblingDoc: siblingDoc[field.name] as Record<string, unknown>,\n siblingDocWithLocales: siblingDocWithLocales[field.name] as Record<string, unknown>,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'array': {\n const rows = siblingData[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n promises.push(\n traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: `${path}${field.name}.${i}.`,\n req,\n siblingData: row,\n siblingDoc: getExistingRowDoc(row, siblingDoc[field.name]),\n siblingDocWithLocales: getExistingRowDoc(row, siblingDocWithLocales[field.name]),\n skipValidation: skipValidationFromHere,\n }),\n )\n })\n\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'blocks': {\n const rows = siblingData[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n const rowSiblingDoc = getExistingRowDoc(row, siblingDoc[field.name])\n const rowSiblingDocWithLocales = getExistingRowDoc(row, siblingDocWithLocales[field.name])\n\n const blockTypeToMatch = row.blockType || rowSiblingDoc.blockType\n const block = field.blocks.find((blockType) => blockType.slug === blockTypeToMatch)\n\n if (block) {\n promises.push(\n traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: block.fields,\n global,\n mergeLocaleActions,\n operation,\n path: `${path}${field.name}.${i}.`,\n req,\n siblingData: row,\n siblingDoc: rowSiblingDoc,\n siblingDocWithLocales: rowSiblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n }),\n )\n }\n })\n\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'row':\n case 'collapsible': {\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'tab': {\n let tabPath = path\n let tabSiblingData = siblingData\n let tabSiblingDoc = siblingDoc\n let tabSiblingDocWithLocales = siblingDocWithLocales\n\n if (tabHasName(field)) {\n tabPath = `${path}${field.name}.`\n if (typeof siblingData[field.name] !== 'object') siblingData[field.name] = {}\n if (typeof siblingDoc[field.name] !== 'object') siblingDoc[field.name] = {}\n if (typeof siblingDocWithLocales[field.name] !== 'object')\n siblingDocWithLocales[field.name] = {}\n\n tabSiblingData = siblingData[field.name] as Record<string, unknown>\n tabSiblingDoc = siblingDoc[field.name] as Record<string, unknown>\n tabSiblingDocWithLocales = siblingDocWithLocales[field.name] as Record<string, unknown>\n }\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: tabPath,\n req,\n siblingData: tabSiblingData,\n siblingDoc: tabSiblingDoc,\n siblingDocWithLocales: tabSiblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'tabs': {\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n global,\n mergeLocaleActions,\n operation,\n path,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["merge","fieldAffectsData","tabHasName","beforeDuplicate","getExistingRowDoc","traverseFields","promise","id","collection","context","data","doc","docWithLocales","duplicate","errors","field","global","mergeLocaleActions","operation","path","req","siblingData","siblingDoc","siblingDocWithLocales","skipValidation","passesCondition","admin","condition","Boolean","user","skipValidationFromHere","localization","payload","config","defaultLocale","operationLocale","locale","localized","includes","type","name","hooks","beforeChange","reduce","priorHook","currentHook","hookedValue","originalDoc","previousSiblingDoc","previousValue","value","undefined","Promise","resolve","validate","valueToValidate","jsonError","JSON","parse","e","validationResult","arrayMerge","_","source","preferences","fields","push","message","beforeDuplicateArgs","localeData","localeCodes","localizedValuesPromise","localizedValues","fieldValue","length","Object","keys","Array","isArray","coordinates","parseFloat","rows","promises","forEach","row","i","all","rowSiblingDoc","rowSiblingDocWithLocales","blockTypeToMatch","blockType","block","blocks","find","slug","tabPath","tabSiblingData","tabSiblingDoc","tabSiblingDocWithLocales","tabs","map","tab"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAC,KAAK,UAC/CjB,qBAAqB,CAACR,MAAMyB,IAAI,CAAC,GAAG,CAAC;oBAEvCwD,iBAAiB3E,WAAW,CAACN,MAAMyB,IAAI,CAAC;oBACxCyD,gBAAgB3E,UAAU,CAACP,MAAMyB,IAAI,CAAC;oBACtC0D,2BAA2B3E,qBAAqB,CAACR,MAAMyB,IAAI,CAAC;gBAC9D;gBAEA,MAAMnC,eAAe;oBACnBE;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAmD,QAAQlD,MAAMkD,MAAM;oBACpBjD;oBACAC;oBACAC;oBACAC,MAAM4E;oBACN3E;oBACAC,aAAa2E;oBACb1E,YAAY2E;oBACZ1E,uBAAuB2E;oBACvB1E,gBAAgBM;gBAClB;gBAEA;YACF;QAEA,KAAK;YAAQ;gBACX,MAAMzB,eAAe;oBACnBE;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAmD,QAAQlD,MAAMoF,IAAI,CAACC,GAAG,CAAC,CAACC,MAAS,CAAA;4BAAE,GAAGA,GAAG;4BAAE9D,MAAM;wBAAM,CAAA;oBACvDvB;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC,gBAAgBM;gBAClB;gBAEA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/beforeChange/promise.ts"],"sourcesContent":["import merge from 'deepmerge'\n\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 { Operation, PayloadRequestWithData, RequestContext } from '../../../types/index.js'\nimport type { Field, FieldHookArgs, TabAsField, ValidateOptions } from '../../config/types.js'\n\nimport { MissingEditorProp } from '../../../errors/index.js'\nimport { fieldAffectsData, tabHasName } from '../../config/types.js'\nimport { getFieldPaths } from '../../getFieldPaths.js'\nimport { beforeDuplicate } from './beforeDuplicate.js'\nimport { getExistingRowDoc } from './getExistingRowDoc.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n collection: SanitizedCollectionConfig | null\n context: RequestContext\n data: Record<string, unknown>\n doc: Record<string, unknown>\n docWithLocales: Record<string, unknown>\n duplicate: boolean\n errors: { field: string; message: string }[]\n field: Field | TabAsField\n global: SanitizedGlobalConfig | null\n id?: number | string\n mergeLocaleActions: (() => Promise<void>)[]\n operation: Operation\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 req: PayloadRequestWithData\n siblingData: Record<string, unknown>\n siblingDoc: Record<string, unknown>\n siblingDocWithLocales?: Record<string, unknown>\n skipValidation: boolean\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\n\nexport const promise = async ({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n field,\n global,\n mergeLocaleActions,\n operation,\n parentPath,\n parentSchemaPath,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation,\n}: Args): Promise<void> => {\n const passesCondition = field.admin?.condition\n ? Boolean(field.admin.condition(data, siblingData, { user: req.user }))\n : true\n let skipValidationFromHere = skipValidation || !passesCondition\n const { localization } = req.payload.config\n const defaultLocale = localization ? localization?.defaultLocale : 'en'\n const operationLocale = req.locale || defaultLocale\n\n const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({\n field,\n parentPath,\n parentSchemaPath,\n })\n\n if (fieldAffectsData(field)) {\n // skip validation if the field is localized and the incoming data is null\n if (field.localized && operationLocale !== defaultLocale) {\n if (['array', 'blocks'].includes(field.type) && siblingData[field.name] === null) {\n skipValidationFromHere = true\n }\n }\n\n // Execute hooks\n if (field.hooks?.beforeChange) {\n await field.hooks.beforeChange.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const hookedValue = await currentHook({\n collection,\n context,\n data,\n field,\n global,\n operation,\n originalDoc: doc,\n path: fieldPath,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n schemaPath: parentSchemaPath,\n siblingData,\n siblingDocWithLocales,\n value: siblingData[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingData[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n\n // Validate\n if (!skipValidationFromHere && field.validate) {\n const valueToValidate = siblingData[field.name]\n let jsonError: object\n\n if (field.type === 'json' && typeof siblingData[field.name] === 'string') {\n try {\n JSON.parse(siblingData[field.name] as string)\n } catch (e) {\n jsonError = e\n }\n }\n\n const validationResult = await field.validate(valueToValidate, {\n ...field,\n id,\n data: merge(doc, data, { arrayMerge: (_, source) => source }),\n jsonError,\n operation,\n preferences: { fields: {} },\n req,\n siblingData: merge(siblingDoc, siblingData, { arrayMerge: (_, source) => source }),\n } as ValidateOptions<any, any, { jsonError: object }>)\n\n if (typeof validationResult === 'string') {\n errors.push({\n field: fieldPath.join('.'),\n message: validationResult,\n })\n }\n }\n\n const beforeDuplicateArgs: FieldHookArgs = {\n collection,\n context,\n data,\n field,\n global: undefined,\n path: fieldPath,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n schemaPath: parentSchemaPath,\n siblingData,\n siblingDocWithLocales,\n value: siblingData[field.name],\n }\n\n // Push merge locale action if applicable\n if (localization && field.localized) {\n mergeLocaleActions.push(async () => {\n const localeData = await localization.localeCodes.reduce(\n async (localizedValuesPromise: Promise<Record<string, unknown>>, locale) => {\n const localizedValues = await localizedValuesPromise\n let fieldValue =\n locale === req.locale\n ? siblingData[field.name]\n : siblingDocWithLocales?.[field.name]?.[locale]\n\n if (duplicate && field.hooks?.beforeDuplicate?.length) {\n beforeDuplicateArgs.value = fieldValue\n fieldValue = await beforeDuplicate(beforeDuplicateArgs)\n }\n\n // const result = await localizedValues\n // update locale value if it's not undefined\n if (typeof fieldValue !== 'undefined') {\n return {\n ...localizedValues,\n [locale]: fieldValue,\n }\n }\n\n return localizedValuesPromise\n },\n Promise.resolve({}),\n )\n\n // If there are locales with data, set the data\n if (Object.keys(localeData).length > 0) {\n siblingData[field.name] = localeData\n }\n })\n } else if (duplicate && field.hooks?.beforeDuplicate?.length) {\n mergeLocaleActions.push(async () => {\n siblingData[field.name] = await beforeDuplicate(beforeDuplicateArgs)\n })\n }\n }\n\n switch (field.type) {\n case 'point': {\n // Transform point data for storage\n if (\n Array.isArray(siblingData[field.name]) &&\n siblingData[field.name][0] !== null &&\n siblingData[field.name][1] !== null\n ) {\n siblingData[field.name] = {\n type: 'Point',\n coordinates: [\n parseFloat(siblingData[field.name][0]),\n parseFloat(siblingData[field.name][1]),\n ],\n }\n }\n\n break\n }\n\n case 'group': {\n if (typeof siblingData[field.name] !== 'object') siblingData[field.name] = {}\n if (typeof siblingDoc[field.name] !== 'object') siblingDoc[field.name] = {}\n if (typeof siblingDocWithLocales[field.name] !== 'object')\n siblingDocWithLocales[field.name] = {}\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData[field.name] as Record<string, unknown>,\n siblingDoc: siblingDoc[field.name] as Record<string, unknown>,\n siblingDocWithLocales: siblingDocWithLocales[field.name] as Record<string, unknown>,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'array': {\n const rows = siblingData[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n promises.push(\n traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: [...fieldPath, i],\n req,\n schemaPath: fieldSchemaPath,\n siblingData: row,\n siblingDoc: getExistingRowDoc(row, siblingDoc[field.name]),\n siblingDocWithLocales: getExistingRowDoc(row, siblingDocWithLocales[field.name]),\n skipValidation: skipValidationFromHere,\n }),\n )\n })\n\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'blocks': {\n const rows = siblingData[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n const rowSiblingDoc = getExistingRowDoc(row, siblingDoc[field.name])\n const rowSiblingDocWithLocales = getExistingRowDoc(row, siblingDocWithLocales[field.name])\n\n const blockTypeToMatch = row.blockType || rowSiblingDoc.blockType\n const block = field.blocks.find((blockType) => blockType.slug === blockTypeToMatch)\n\n if (block) {\n promises.push(\n traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: block.fields,\n global,\n mergeLocaleActions,\n operation,\n path: [...fieldPath, i],\n req,\n schemaPath: fieldSchemaPath,\n siblingData: row,\n siblingDoc: rowSiblingDoc,\n siblingDocWithLocales: rowSiblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n }),\n )\n }\n })\n\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'row':\n case 'collapsible': {\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'tab': {\n let tabSiblingData = siblingData\n let tabSiblingDoc = siblingDoc\n let tabSiblingDocWithLocales = siblingDocWithLocales\n\n if (tabHasName(field)) {\n if (typeof siblingData[field.name] !== 'object') siblingData[field.name] = {}\n if (typeof siblingDoc[field.name] !== 'object') siblingDoc[field.name] = {}\n if (typeof siblingDocWithLocales[field.name] !== 'object')\n siblingDocWithLocales[field.name] = {}\n\n tabSiblingData = siblingData[field.name] as Record<string, unknown>\n tabSiblingDoc = siblingDoc[field.name] as Record<string, unknown>\n tabSiblingDocWithLocales = siblingDocWithLocales[field.name] as Record<string, unknown>\n }\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: tabSiblingData,\n siblingDoc: tabSiblingDoc,\n siblingDocWithLocales: tabSiblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'tabs': {\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation: skipValidationFromHere,\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\n if (editor?.hooks?.beforeChange?.length) {\n await editor.hooks.beforeChange.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const hookedValue = await currentHook({\n collection,\n context,\n data,\n docWithLocales,\n duplicate,\n errors,\n field,\n global,\n mergeLocaleActions,\n operation,\n originalDoc: doc,\n path: fieldPath,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n schemaPath: parentSchemaPath,\n siblingData,\n siblingDocWithLocales,\n skipValidation,\n value: siblingData[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingData[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["merge","MissingEditorProp","fieldAffectsData","tabHasName","getFieldPaths","beforeDuplicate","getExistingRowDoc","traverseFields","promise","id","collection","context","data","doc","docWithLocales","duplicate","errors","field","global","mergeLocaleActions","operation","parentPath","parentSchemaPath","req","siblingData","siblingDoc","siblingDocWithLocales","skipValidation","passesCondition","admin","condition","Boolean","user","skipValidationFromHere","localization","payload","config","defaultLocale","operationLocale","locale","path","fieldPath","schemaPath","fieldSchemaPath","localized","includes","type","name","hooks","beforeChange","reduce","priorHook","currentHook","hookedValue","originalDoc","previousSiblingDoc","previousValue","value","undefined","Promise","resolve","validate","valueToValidate","jsonError","JSON","parse","e","validationResult","arrayMerge","_","source","preferences","fields","push","join","message","beforeDuplicateArgs","localeData","localeCodes","localizedValuesPromise","localizedValues","fieldValue","length","Object","keys","Array","isArray","coordinates","parseFloat","rows","promises","forEach","row","i","all","rowSiblingDoc","rowSiblingDocWithLocales","blockTypeToMatch","blockType","block","blocks","find","slug","tabSiblingData","tabSiblingDoc","tabSiblingDocWithLocales","tabs","map","tab","editor","Error"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,WAAW,YAAW;AAQ7B,SAASC,iBAAiB,QAAQ,2BAA0B;AAC5D,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,wBAAuB;AACpE,SAASC,aAAa,QAAQ,yBAAwB;A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ACAE;4BACAC;4BACA8B,OAAOjC,WAAW,CAACP,MAAM8B,IAAI,CAAC;wBAChC;wBAEA,IAAIM,gBAAgBK,WAAW;4BAC7BlC,WAAW,CAACP,MAAM8B,IAAI,CAAC,GAAGM;wBAC5B;oBACF,GAAGM,QAAQC,OAAO;gBACpB;gBAEA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
|
|
@@ -24,8 +24,9 @@ type Args = {
|
|
|
24
24
|
id?: number | string;
|
|
25
25
|
mergeLocaleActions: (() => Promise<void>)[];
|
|
26
26
|
operation: Operation;
|
|
27
|
-
path: string;
|
|
27
|
+
path: (number | string)[];
|
|
28
28
|
req: PayloadRequestWithData;
|
|
29
|
+
schemaPath: string[];
|
|
29
30
|
siblingData: Record<string, unknown>;
|
|
30
31
|
/**
|
|
31
32
|
* The original siblingData (not modified by any hooks)
|
|
@@ -43,8 +44,8 @@ type Args = {
|
|
|
43
44
|
* - Execute field hooks
|
|
44
45
|
* - Validate data
|
|
45
46
|
* - Transform data for storage
|
|
46
|
-
* - Unflatten locales
|
|
47
|
+
* - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.
|
|
47
48
|
*/
|
|
48
|
-
export declare const traverseFields: ({ id, collection, context, data, doc, docWithLocales, duplicate, errors, fields, global, mergeLocaleActions, operation, path, req, siblingData, siblingDoc, siblingDocWithLocales, skipValidation, }: Args) => Promise<void>;
|
|
49
|
+
export declare const traverseFields: ({ id, collection, context, data, doc, docWithLocales, duplicate, errors, fields, global, mergeLocaleActions, operation, path, req, schemaPath, siblingData, siblingDoc, siblingDocWithLocales, skipValidation, }: Args) => Promise<void>;
|
|
49
50
|
export {};
|
|
50
51
|
//# sourceMappingURL=traverseFields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,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B,IAAI,KAAG,QAAQ,IAAI,CA8BrB,CAAA"}
|
|
@@ -5,8 +5,8 @@ import { promise } from './promise.js';
|
|
|
5
5
|
* - Execute field hooks
|
|
6
6
|
* - Validate data
|
|
7
7
|
* - Transform data for storage
|
|
8
|
-
* - Unflatten locales
|
|
9
|
-
*/ export const traverseFields = async ({ id, collection, context, data, doc, docWithLocales, duplicate, errors, fields, global, mergeLocaleActions, operation, path, req, siblingData, siblingDoc, siblingDocWithLocales, skipValidation })=>{
|
|
8
|
+
* - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.
|
|
9
|
+
*/ export const traverseFields = async ({ id, collection, context, data, doc, docWithLocales, duplicate, errors, fields, global, mergeLocaleActions, operation, path, req, schemaPath, siblingData, siblingDoc, siblingDocWithLocales, skipValidation })=>{
|
|
10
10
|
const promises = [];
|
|
11
11
|
fields.forEach((field)=>{
|
|
12
12
|
promises.push(promise({
|
|
@@ -22,7 +22,8 @@ import { promise } from './promise.js';
|
|
|
22
22
|
global,
|
|
23
23
|
mergeLocaleActions,
|
|
24
24
|
operation,
|
|
25
|
-
path,
|
|
25
|
+
parentPath: path,
|
|
26
|
+
parentSchemaPath: schemaPath,
|
|
26
27
|
req,
|
|
27
28
|
siblingData,
|
|
28
29
|
siblingDoc,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/beforeChange/traverseFields.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'\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 data: Record<string, unknown>\n /**\n * The original data (not modified by any hooks)\n */\n doc: Record<string, unknown>\n /**\n * The original data with locales (not modified by any hooks)\n */\n docWithLocales: Record<string, unknown>\n duplicate: boolean\n errors: { field: string; message: string }[]\n fields: (Field | TabAsField)[]\n global: SanitizedGlobalConfig | null\n id?: number | string\n mergeLocaleActions: (() => Promise<void>)[]\n operation: Operation\n path: string\n req: PayloadRequestWithData\n siblingData: Record<string, unknown>\n /**\n * The original siblingData (not modified by any hooks)\n */\n siblingDoc: Record<string, unknown>\n /**\n * The original siblingData with locales (not modified by any hooks)\n */\n siblingDocWithLocales: Record<string, unknown>\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 * - Unflatten locales
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/beforeChange/traverseFields.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'\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 data: Record<string, unknown>\n /**\n * The original data (not modified by any hooks)\n */\n doc: Record<string, unknown>\n /**\n * The original data with locales (not modified by any hooks)\n */\n docWithLocales: Record<string, unknown>\n duplicate: boolean\n errors: { field: string; message: string }[]\n fields: (Field | TabAsField)[]\n global: SanitizedGlobalConfig | null\n id?: number | string\n mergeLocaleActions: (() => Promise<void>)[]\n operation: Operation\n path: (number | string)[]\n req: PayloadRequestWithData\n schemaPath: string[]\n siblingData: Record<string, unknown>\n /**\n * The original siblingData (not modified by any hooks)\n */\n siblingDoc: Record<string, unknown>\n /**\n * The original siblingData with locales (not modified by any hooks)\n */\n siblingDocWithLocales: Record<string, unknown>\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 * - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.\n */\nexport const traverseFields = async ({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields,\n global,\n mergeLocaleActions,\n operation,\n path,\n req,\n schemaPath,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation,\n}: Args): Promise<void> => {\n const promises = []\n\n fields.forEach((field) => {\n promises.push(\n promise({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n field,\n global,\n mergeLocaleActions,\n operation,\n parentPath: path,\n parentSchemaPath: schemaPath,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation,\n }),\n )\n })\n\n await Promise.all(promises)\n}\n"],"names":["promise","traverseFields","id","collection","context","data","doc","docWithLocales","duplicate","errors","fields","global","mergeLocaleActions","operation","path","req","schemaPath","siblingData","siblingDoc","siblingDocWithLocales","skipValidation","promises","forEach","field","push","parentPath","parentSchemaPath","Promise","all"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAKA,SAASA,OAAO,QAAQ,eAAc;AAoCtC;;;;;;;CAOC,GACD,OAAO,MAAMC,iBAAiB,OAAO,EACnCC,EAAE,EACFC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,GAAG,EACHC,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,kBAAkB,EAClBC,SAAS,EACTC,IAAI,EACJC,GAAG,EACHC,UAAU,EACVC,WAAW,EACXC,UAAU,EACVC,qBAAqB,EACrBC,cAAc,EACT;IACL,MAAMC,WAAW,EAAE;IAEnBX,OAAOY,OAAO,CAAC,CAACC;QACdF,SAASG,IAAI,CACXxB,QAAQ;YACNE;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAc;YACAZ;YACAC;YACAC;YACAY,YAAYX;YACZY,kBAAkBV;YAClBD;YACAE;YACAC;YACAC;YACAC;QACF;IAEJ;IAEA,MAAMO,QAAQC,GAAG,CAACP;AACpB,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeValidate/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,sBAAsB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAKrF,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,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IACjC,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAAA;IACpC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC9B,cAAc,EAAE,OAAO,CAAA;IACvB,GAAG,EAAE,sBAAsB,CAAA;CAC5B,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,qIAUxB,KAAK,CAAC,CAAC,KAAG,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeValidate/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,sBAAsB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAKrF,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,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IACjC,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAAA;IACpC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC9B,cAAc,EAAE,OAAO,CAAA;IACvB,GAAG,EAAE,sBAAsB,CAAA;CAC5B,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,qIAUxB,KAAK,CAAC,CAAC,KAAG,QAAQ,CAAC,CAqBrB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/beforeValidate/index.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'\n\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 duplicate?: boolean\n global: SanitizedGlobalConfig | null\n id?: number | string\n operation: 'create' | 'update'\n overrideAccess: boolean\n req: PayloadRequestWithData\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Sanitize incoming data\n * - Execute field hooks\n * - Execute field access control\n * - Merge original document data into incoming data\n * - Compute default values for undefined fields\n */\nexport const beforeValidate = async <T extends Record<string, unknown>>({\n id,\n collection,\n context,\n data: incomingData,\n doc,\n global,\n operation,\n overrideAccess,\n req,\n}: Args<T>): Promise<T> => {\n const data = deepCopyObject(incomingData)\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n fields: collection?.fields || global?.fields,\n global,\n operation,\n overrideAccess,\n req,\n siblingData: data,\n siblingDoc: doc,\n })\n\n return data\n}\n"],"names":["deepCopyObject","traverseFields","beforeValidate","id","collection","context","data","incomingData","doc","global","operation","overrideAccess","req","fields","siblingData","siblingDoc"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/beforeValidate/index.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'\n\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 duplicate?: boolean\n global: SanitizedGlobalConfig | null\n id?: number | string\n operation: 'create' | 'update'\n overrideAccess: boolean\n req: PayloadRequestWithData\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Sanitize incoming data\n * - Execute field hooks\n * - Execute field access control\n * - Merge original document data into incoming data\n * - Compute default values for undefined fields\n */\nexport const beforeValidate = async <T extends Record<string, unknown>>({\n id,\n collection,\n context,\n data: incomingData,\n doc,\n global,\n operation,\n overrideAccess,\n req,\n}: Args<T>): Promise<T> => {\n const data = deepCopyObject(incomingData)\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n fields: collection?.fields || global?.fields,\n global,\n operation,\n overrideAccess,\n path: [],\n req,\n schemaPath: [],\n siblingData: data,\n siblingDoc: doc,\n })\n\n return data\n}\n"],"names":["deepCopyObject","traverseFields","beforeValidate","id","collection","context","data","incomingData","doc","global","operation","overrideAccess","req","fields","path","schemaPath","siblingData","siblingDoc"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,cAAc,QAAQ,uCAAsC;AACrE,SAASC,cAAc,QAAQ,sBAAqB;AAepD;;;;;;;CAOC,GACD,OAAO,MAAMC,iBAAiB,OAA0C,EACtEC,EAAE,EACFC,UAAU,EACVC,OAAO,EACPC,MAAMC,YAAY,EAClBC,GAAG,EACHC,MAAM,EACNC,SAAS,EACTC,cAAc,EACdC,GAAG,EACK;IACR,MAAMN,OAAON,eAAeO;IAE5B,MAAMN,eAAe;QACnBE;QACAC;QACAC;QACAC;QACAE;QACAK,QAAQT,YAAYS,UAAUJ,QAAQI;QACtCJ;QACAC;QACAC;QACAG,MAAM,EAAE;QACRF;QACAG,YAAY,EAAE;QACdC,aAAaV;QACbW,YAAYT;IACd;IAEA,OAAOF;AACT,EAAC"}
|
|
@@ -15,6 +15,8 @@ type Args<T> = {
|
|
|
15
15
|
id?: number | string;
|
|
16
16
|
operation: 'create' | 'update';
|
|
17
17
|
overrideAccess: boolean;
|
|
18
|
+
parentPath: (number | string)[];
|
|
19
|
+
parentSchemaPath: string[];
|
|
18
20
|
req: PayloadRequestWithData;
|
|
19
21
|
siblingData: Record<string, unknown>;
|
|
20
22
|
/**
|
|
@@ -22,6 +24,6 @@ type Args<T> = {
|
|
|
22
24
|
*/
|
|
23
25
|
siblingDoc: Record<string, unknown>;
|
|
24
26
|
};
|
|
25
|
-
export declare const promise: <T>({ id, collection, context, data, doc, field, global, operation, overrideAccess, req, siblingData, siblingDoc, }: Args<T>) => Promise<void>;
|
|
27
|
+
export declare const promise: <T>({ id, collection, context, data, doc, field, global, operation, overrideAccess, parentPath, parentSchemaPath, req, siblingData, siblingDoc, }: Args<T>) => Promise<void>;
|
|
26
28
|
export {};
|
|
27
29
|
//# sourceMappingURL=promise.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeValidate/promise.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeValidate/promise.ts"],"names":[],"mappings":"AAEA,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;AAU9D,KAAK,IAAI,CAAC,CAAC,IAAI;IACb,UAAU,EAAE,yBAAyB,GAAG,IAAI,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,CAAC,CAAA;IACP;;OAEG;IACH,GAAG,EAAE,CAAC,CAAA;IACN,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAAA;IACpC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC9B,cAAc,EAAE,OAAO,CAAA;IACvB,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IAC/B,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B,GAAG,EAAE,sBAAsB,CAAA;IAC3B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACpC,CAAA;AASD,eAAO,MAAM,OAAO,qJAejB,KAAK,CAAC,CAAC,KAAG,QAAQ,IAAI,CA8bxB,CAAA"}
|