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
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { tabHasName } from './config/types.js';
|
|
2
|
+
export function getFieldPaths({ field, parentPath, parentSchemaPath }) {
|
|
3
|
+
if (field.type === 'tabs' || field.type === 'row' || field.type === 'collapsible') {
|
|
4
|
+
return {
|
|
5
|
+
path: parentPath,
|
|
6
|
+
schemaPath: parentSchemaPath
|
|
7
|
+
};
|
|
8
|
+
} else if (field.type === 'tab') {
|
|
9
|
+
if (tabHasName(field)) {
|
|
10
|
+
return {
|
|
11
|
+
path: [
|
|
12
|
+
...parentPath,
|
|
13
|
+
field.name
|
|
14
|
+
],
|
|
15
|
+
schemaPath: [
|
|
16
|
+
...parentSchemaPath,
|
|
17
|
+
field.name
|
|
18
|
+
]
|
|
19
|
+
};
|
|
20
|
+
} else {
|
|
21
|
+
return {
|
|
22
|
+
path: parentPath,
|
|
23
|
+
schemaPath: parentSchemaPath
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const path = parentPath?.length ? [
|
|
28
|
+
...parentPath,
|
|
29
|
+
field.name
|
|
30
|
+
] : [
|
|
31
|
+
field.name
|
|
32
|
+
];
|
|
33
|
+
const schemaPath = parentSchemaPath?.length ? [
|
|
34
|
+
...parentSchemaPath,
|
|
35
|
+
field.name
|
|
36
|
+
] : [
|
|
37
|
+
field.name
|
|
38
|
+
];
|
|
39
|
+
return {
|
|
40
|
+
path,
|
|
41
|
+
schemaPath
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=getFieldPaths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fields/getFieldPaths.ts"],"sourcesContent":["import type { Field, TabAsField } from './config/types.js'\n\nimport { tabHasName } from './config/types.js'\n\nexport function getFieldPaths({\n field,\n parentPath,\n parentSchemaPath,\n}: {\n field: Field | TabAsField\n parentPath: (number | string)[]\n parentSchemaPath: string[]\n}): {\n path: (number | string)[]\n schemaPath: string[]\n} {\n if (field.type === 'tabs' || field.type === 'row' || field.type === 'collapsible') {\n return {\n path: parentPath,\n schemaPath: parentSchemaPath,\n }\n } else if (field.type === 'tab') {\n if (tabHasName(field)) {\n return {\n path: [...parentPath, field.name],\n schemaPath: [...parentSchemaPath, field.name],\n }\n } else {\n return {\n path: parentPath,\n schemaPath: parentSchemaPath,\n }\n }\n }\n const path = parentPath?.length ? [...parentPath, field.name] : [field.name]\n const schemaPath = parentSchemaPath?.length ? [...parentSchemaPath, field.name] : [field.name]\n\n return { path, schemaPath }\n}\n"],"names":["tabHasName","getFieldPaths","field","parentPath","parentSchemaPath","type","path","schemaPath","name","length"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,UAAU,QAAQ,oBAAmB;AAE9C,OAAO,SAASC,cAAc,EAC5BC,KAAK,EACLC,UAAU,EACVC,gBAAgB,EAKjB;IAIC,IAAIF,MAAMG,IAAI,KAAK,UAAUH,MAAMG,IAAI,KAAK,SAASH,MAAMG,IAAI,KAAK,eAAe;QACjF,OAAO;YACLC,MAAMH;YACNI,YAAYH;QACd;IACF,OAAO,IAAIF,MAAMG,IAAI,KAAK,OAAO;QAC/B,IAAIL,WAAWE,QAAQ;YACrB,OAAO;gBACLI,MAAM;uBAAIH;oBAAYD,MAAMM,IAAI;iBAAC;gBACjCD,YAAY;uBAAIH;oBAAkBF,MAAMM,IAAI;iBAAC;YAC/C;QACF,OAAO;YACL,OAAO;gBACLF,MAAMH;gBACNI,YAAYH;YACd;QACF;IACF;IACA,MAAME,OAAOH,YAAYM,SAAS;WAAIN;QAAYD,MAAMM,IAAI;KAAC,GAAG;QAACN,MAAMM,IAAI;KAAC;IAC5E,MAAMD,aAAaH,kBAAkBK,SAAS;WAAIL;QAAkBF,MAAMM,IAAI;KAAC,GAAG;QAACN,MAAMM,IAAI;KAAC;IAE9F,OAAO;QAAEF;QAAMC;IAAW;AAC5B"}
|
|
@@ -4,7 +4,13 @@ import type { PayloadRequestWithData, RequestContext } from '../../../types/inde
|
|
|
4
4
|
type Args<T> = {
|
|
5
5
|
collection: SanitizedCollectionConfig | null;
|
|
6
6
|
context: RequestContext;
|
|
7
|
+
/**
|
|
8
|
+
* The data before hooks
|
|
9
|
+
*/
|
|
7
10
|
data: Record<string, unknown> | T;
|
|
11
|
+
/**
|
|
12
|
+
* The data after hooks
|
|
13
|
+
*/
|
|
8
14
|
doc: Record<string, unknown> | T;
|
|
9
15
|
global: SanitizedGlobalConfig | null;
|
|
10
16
|
operation: 'create' | 'update';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterChange/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,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IAChC,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAAA;IACpC,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC9B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IACxC,GAAG,EAAE,sBAAsB,CAAA;CAC5B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterChange/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;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IACjC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IAChC,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAAA;IACpC,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC9B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IACxC,GAAG,EAAE,sBAAsB,CAAA;CAC5B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,6HASrB,KAAK,CAAC,CAAC,KAAG,QAAQ,CAAC,CAqBrB,CAAA"}
|
|
@@ -13,9 +13,11 @@ import { traverseFields } from './traverseFields.js';
|
|
|
13
13
|
fields: collection?.fields || global?.fields,
|
|
14
14
|
global,
|
|
15
15
|
operation,
|
|
16
|
+
path: [],
|
|
16
17
|
previousDoc,
|
|
17
18
|
previousSiblingDoc: previousDoc,
|
|
18
19
|
req,
|
|
20
|
+
schemaPath: [],
|
|
19
21
|
siblingData: data,
|
|
20
22
|
siblingDoc: doc
|
|
21
23
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/afterChange/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 global: SanitizedGlobalConfig | null\n operation: 'create' | 'update'\n previousDoc: Record<string, unknown> | T\n req: PayloadRequestWithData\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Execute field hooks\n */\nexport const afterChange = async <T extends Record<string, unknown>>({\n collection,\n context,\n data,\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/afterChange/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 /**\n * The data before hooks\n */\n data: Record<string, unknown> | T\n /**\n * The data after hooks\n */\n doc: Record<string, unknown> | T\n global: SanitizedGlobalConfig | null\n operation: 'create' | 'update'\n previousDoc: Record<string, unknown> | T\n req: PayloadRequestWithData\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Execute field hooks\n */\nexport const afterChange = async <T extends Record<string, unknown>>({\n collection,\n context,\n data,\n doc: incomingDoc,\n global,\n operation,\n previousDoc,\n req,\n}: Args<T>): Promise<T> => {\n const doc = deepCopyObject(incomingDoc)\n\n await traverseFields({\n collection,\n context,\n data,\n doc,\n fields: collection?.fields || global?.fields,\n global,\n operation,\n path: [],\n previousDoc,\n previousSiblingDoc: previousDoc,\n req,\n schemaPath: [],\n siblingData: data,\n siblingDoc: doc,\n })\n\n return doc\n}\n"],"names":["deepCopyObject","traverseFields","afterChange","collection","context","data","doc","incomingDoc","global","operation","previousDoc","req","fields","path","previousSiblingDoc","schemaPath","siblingData","siblingDoc"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,cAAc,QAAQ,uCAAsC;AACrE,SAASC,cAAc,QAAQ,sBAAqB;AAmBpD;;;CAGC,GACD,OAAO,MAAMC,cAAc,OAA0C,EACnEC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,KAAKC,WAAW,EAChBC,MAAM,EACNC,SAAS,EACTC,WAAW,EACXC,GAAG,EACK;IACR,MAAML,MAAMN,eAAeO;IAE3B,MAAMN,eAAe;QACnBE;QACAC;QACAC;QACAC;QACAM,QAAQT,YAAYS,UAAUJ,QAAQI;QACtCJ;QACAC;QACAI,MAAM,EAAE;QACRH;QACAI,oBAAoBJ;QACpBC;QACAI,YAAY,EAAE;QACdC,aAAaX;QACbY,YAAYX;IACd;IAEA,OAAOA;AACT,EAAC"}
|
|
@@ -10,12 +10,20 @@ type Args = {
|
|
|
10
10
|
field: Field | TabAsField;
|
|
11
11
|
global: SanitizedGlobalConfig | null;
|
|
12
12
|
operation: 'create' | 'update';
|
|
13
|
+
/**
|
|
14
|
+
* The parent's path
|
|
15
|
+
*/
|
|
16
|
+
parentPath: (number | string)[];
|
|
17
|
+
/**
|
|
18
|
+
* The parent's schemaPath (path without indexes).
|
|
19
|
+
*/
|
|
20
|
+
parentSchemaPath: string[];
|
|
13
21
|
previousDoc: Record<string, unknown>;
|
|
14
22
|
previousSiblingDoc: Record<string, unknown>;
|
|
15
23
|
req: PayloadRequestWithData;
|
|
16
24
|
siblingData: Record<string, unknown>;
|
|
17
25
|
siblingDoc: Record<string, unknown>;
|
|
18
26
|
};
|
|
19
|
-
export declare const promise: ({ collection, context, data, doc, field, global, operation, previousDoc, previousSiblingDoc, req, siblingData, siblingDoc, }: Args) => Promise<void>;
|
|
27
|
+
export declare const promise: ({ collection, context, data, doc, field, global, operation, parentPath, parentSchemaPath, previousDoc, previousSiblingDoc, req, siblingData, siblingDoc, }: Args) => Promise<void>;
|
|
20
28
|
export {};
|
|
21
29
|
//# sourceMappingURL=promise.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterChange/promise.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterChange/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;AAO9D,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,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAAA;IACpC,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC9B;;OAEG;IACH,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IAC/B;;OAEG;IACH,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC3C,GAAG,EAAE,sBAAsB,CAAA;IAC3B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACpC,CAAA;AAKD,eAAO,MAAM,OAAO,+JAejB,IAAI,KAAG,QAAQ,IAAI,CAoPrB,CAAA"}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
/* eslint-disable no-param-reassign */ import {
|
|
1
|
+
/* eslint-disable no-param-reassign */ import { MissingEditorProp } from '../../../errors/index.js';
|
|
2
|
+
import { fieldAffectsData, tabHasName } from '../../config/types.js';
|
|
3
|
+
import { getFieldPaths } from '../../getFieldPaths.js';
|
|
2
4
|
import { traverseFields } from './traverseFields.js';
|
|
3
5
|
// This function is responsible for the following actions, in order:
|
|
4
6
|
// - Execute field hooks
|
|
5
|
-
export const promise = async ({ collection, context, data, doc, field, global, operation, previousDoc, previousSiblingDoc, req, siblingData, siblingDoc })=>{
|
|
7
|
+
export const promise = async ({ collection, context, data, doc, field, global, operation, parentPath, parentSchemaPath, previousDoc, previousSiblingDoc, req, siblingData, siblingDoc })=>{
|
|
8
|
+
const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({
|
|
9
|
+
field,
|
|
10
|
+
parentPath,
|
|
11
|
+
parentSchemaPath
|
|
12
|
+
});
|
|
6
13
|
if (fieldAffectsData(field)) {
|
|
7
14
|
// Execute hooks
|
|
8
15
|
if (field.hooks?.afterChange) {
|
|
@@ -16,12 +23,14 @@ export const promise = async ({ collection, context, data, doc, field, global, o
|
|
|
16
23
|
global,
|
|
17
24
|
operation,
|
|
18
25
|
originalDoc: doc,
|
|
26
|
+
path: fieldPath,
|
|
19
27
|
previousDoc,
|
|
20
28
|
previousSiblingDoc,
|
|
21
29
|
previousValue: previousDoc[field.name],
|
|
22
30
|
req,
|
|
31
|
+
schemaPath: fieldSchemaPath,
|
|
23
32
|
siblingData,
|
|
24
|
-
value:
|
|
33
|
+
value: siblingDoc[field.name]
|
|
25
34
|
});
|
|
26
35
|
if (hookedValue !== undefined) {
|
|
27
36
|
siblingDoc[field.name] = hookedValue;
|
|
@@ -41,9 +50,11 @@ export const promise = async ({ collection, context, data, doc, field, global, o
|
|
|
41
50
|
fields: field.fields,
|
|
42
51
|
global,
|
|
43
52
|
operation,
|
|
53
|
+
path: fieldPath,
|
|
44
54
|
previousDoc,
|
|
45
55
|
previousSiblingDoc: previousDoc[field.name],
|
|
46
56
|
req,
|
|
57
|
+
schemaPath: fieldSchemaPath,
|
|
47
58
|
siblingData: siblingData?.[field.name] || {},
|
|
48
59
|
siblingDoc: siblingDoc[field.name]
|
|
49
60
|
});
|
|
@@ -63,9 +74,14 @@ export const promise = async ({ collection, context, data, doc, field, global, o
|
|
|
63
74
|
fields: field.fields,
|
|
64
75
|
global,
|
|
65
76
|
operation,
|
|
77
|
+
path: [
|
|
78
|
+
...fieldPath,
|
|
79
|
+
i
|
|
80
|
+
],
|
|
66
81
|
previousDoc,
|
|
67
82
|
previousSiblingDoc: previousDoc?.[field.name]?.[i] || {},
|
|
68
83
|
req,
|
|
84
|
+
schemaPath: fieldSchemaPath,
|
|
69
85
|
siblingData: siblingData?.[field.name]?.[i] || {},
|
|
70
86
|
siblingDoc: {
|
|
71
87
|
...row
|
|
@@ -92,9 +108,14 @@ export const promise = async ({ collection, context, data, doc, field, global, o
|
|
|
92
108
|
fields: block.fields,
|
|
93
109
|
global,
|
|
94
110
|
operation,
|
|
111
|
+
path: [
|
|
112
|
+
...fieldPath,
|
|
113
|
+
i
|
|
114
|
+
],
|
|
95
115
|
previousDoc,
|
|
96
116
|
previousSiblingDoc: previousDoc?.[field.name]?.[i] || {},
|
|
97
117
|
req,
|
|
118
|
+
schemaPath: fieldSchemaPath,
|
|
98
119
|
siblingData: siblingData?.[field.name]?.[i] || {},
|
|
99
120
|
siblingDoc: {
|
|
100
121
|
...row
|
|
@@ -117,11 +138,13 @@ export const promise = async ({ collection, context, data, doc, field, global, o
|
|
|
117
138
|
fields: field.fields,
|
|
118
139
|
global,
|
|
119
140
|
operation,
|
|
141
|
+
path: fieldPath,
|
|
120
142
|
previousDoc,
|
|
121
143
|
previousSiblingDoc: {
|
|
122
144
|
...previousSiblingDoc
|
|
123
145
|
},
|
|
124
146
|
req,
|
|
147
|
+
schemaPath: fieldSchemaPath,
|
|
125
148
|
siblingData: siblingData || {},
|
|
126
149
|
siblingDoc: {
|
|
127
150
|
...siblingDoc
|
|
@@ -147,9 +170,11 @@ export const promise = async ({ collection, context, data, doc, field, global, o
|
|
|
147
170
|
fields: field.fields,
|
|
148
171
|
global,
|
|
149
172
|
operation,
|
|
173
|
+
path: fieldPath,
|
|
150
174
|
previousDoc,
|
|
151
175
|
previousSiblingDoc: tabPreviousSiblingDoc,
|
|
152
176
|
req,
|
|
177
|
+
schemaPath: fieldSchemaPath,
|
|
153
178
|
siblingData: tabSiblingData,
|
|
154
179
|
siblingDoc: tabSiblingDoc
|
|
155
180
|
});
|
|
@@ -168,11 +193,13 @@ export const promise = async ({ collection, context, data, doc, field, global, o
|
|
|
168
193
|
})),
|
|
169
194
|
global,
|
|
170
195
|
operation,
|
|
196
|
+
path: fieldPath,
|
|
171
197
|
previousDoc,
|
|
172
198
|
previousSiblingDoc: {
|
|
173
199
|
...previousSiblingDoc
|
|
174
200
|
},
|
|
175
201
|
req,
|
|
202
|
+
schemaPath: fieldSchemaPath,
|
|
176
203
|
siblingData: siblingData || {},
|
|
177
204
|
siblingDoc: {
|
|
178
205
|
...siblingDoc
|
|
@@ -180,6 +207,43 @@ export const promise = async ({ collection, context, data, doc, field, global, o
|
|
|
180
207
|
});
|
|
181
208
|
break;
|
|
182
209
|
}
|
|
210
|
+
case 'richText':
|
|
211
|
+
{
|
|
212
|
+
if (!field?.editor) {
|
|
213
|
+
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
|
|
214
|
+
;
|
|
215
|
+
}
|
|
216
|
+
if (typeof field?.editor === 'function') {
|
|
217
|
+
throw new Error('Attempted to access unsanitized rich text editor.');
|
|
218
|
+
}
|
|
219
|
+
const editor = field?.editor;
|
|
220
|
+
if (editor?.hooks?.afterChange?.length) {
|
|
221
|
+
await editor.hooks.afterChange.reduce(async (priorHook, currentHook)=>{
|
|
222
|
+
await priorHook;
|
|
223
|
+
const hookedValue = await currentHook({
|
|
224
|
+
collection,
|
|
225
|
+
context,
|
|
226
|
+
data,
|
|
227
|
+
field,
|
|
228
|
+
global,
|
|
229
|
+
operation,
|
|
230
|
+
originalDoc: doc,
|
|
231
|
+
path: fieldPath,
|
|
232
|
+
previousDoc,
|
|
233
|
+
previousSiblingDoc,
|
|
234
|
+
previousValue: previousDoc[field.name],
|
|
235
|
+
req,
|
|
236
|
+
schemaPath: fieldSchemaPath,
|
|
237
|
+
siblingData,
|
|
238
|
+
value: siblingDoc[field.name]
|
|
239
|
+
});
|
|
240
|
+
if (hookedValue !== undefined) {
|
|
241
|
+
siblingDoc[field.name] = hookedValue;
|
|
242
|
+
}
|
|
243
|
+
}, Promise.resolve());
|
|
244
|
+
}
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
183
247
|
default:
|
|
184
248
|
{
|
|
185
249
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/afterChange/promise.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\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 { fieldAffectsData, tabHasName } from '../../config/types.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 field: Field | TabAsField\n global: SanitizedGlobalConfig | null\n operation: 'create' | 'update'\n previousDoc: Record<string, unknown>\n previousSiblingDoc: Record<string, unknown>\n req: PayloadRequestWithData\n siblingData: Record<string, unknown>\n siblingDoc: Record<string, unknown>\n}\n\n// This function is responsible for the following actions, in order:\n// - Execute field hooks\n\nexport const promise = async ({\n collection,\n context,\n data,\n doc,\n field,\n global,\n operation,\n previousDoc,\n previousSiblingDoc,\n req,\n siblingData,\n siblingDoc,\n}: Args): Promise<void> => {\n if (fieldAffectsData(field)) {\n // Execute hooks\n if (field.hooks?.afterChange) {\n await field.hooks.afterChange.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 previousDoc,\n previousSiblingDoc,\n previousValue: previousDoc[field.name],\n req,\n siblingData,\n value: siblingData[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n }\n\n // Traverse subfields\n switch (field.type) {\n case 'group': {\n await traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.fields,\n global,\n operation,\n previousDoc,\n previousSiblingDoc: previousDoc[field.name] as Record<string, unknown>,\n req,\n siblingData: (siblingData?.[field.name] as Record<string, unknown>) || {},\n siblingDoc: siblingDoc[field.name] as Record<string, unknown>,\n })\n\n break\n }\n\n case 'array': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n promises.push(\n traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.fields,\n global,\n operation,\n previousDoc,\n previousSiblingDoc: previousDoc?.[field.name]?.[i] || ({} as Record<string, unknown>),\n req,\n siblingData: siblingData?.[field.name]?.[i] || {},\n siblingDoc: { ...row } || {},\n }),\n )\n })\n await Promise.all(promises)\n }\n break\n }\n\n case 'blocks': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n const block = field.blocks.find((blockType) => blockType.slug === row.blockType)\n\n if (block) {\n promises.push(\n traverseFields({\n collection,\n context,\n data,\n doc,\n fields: block.fields,\n global,\n operation,\n previousDoc,\n previousSiblingDoc:\n previousDoc?.[field.name]?.[i] || ({} as Record<string, unknown>),\n req,\n siblingData: siblingData?.[field.name]?.[i] || {},\n siblingDoc: { ...row } || {},\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 collection,\n context,\n data,\n doc,\n fields: field.fields,\n global,\n operation,\n previousDoc,\n previousSiblingDoc: { ...previousSiblingDoc },\n req,\n siblingData: siblingData || {},\n siblingDoc: { ...siblingDoc },\n })\n\n break\n }\n\n case 'tab': {\n let tabSiblingData = siblingData\n let tabSiblingDoc = siblingDoc\n let tabPreviousSiblingDoc = siblingDoc\n\n if (tabHasName(field)) {\n tabSiblingData = siblingData[field.name] as Record<string, unknown>\n tabSiblingDoc = siblingDoc[field.name] as Record<string, unknown>\n tabPreviousSiblingDoc = previousDoc[field.name] as Record<string, unknown>\n }\n\n await traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.fields,\n global,\n operation,\n previousDoc,\n previousSiblingDoc: tabPreviousSiblingDoc,\n req,\n siblingData: tabSiblingData,\n siblingDoc: tabSiblingDoc,\n })\n\n break\n }\n\n case 'tabs': {\n await traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n global,\n operation,\n previousDoc,\n previousSiblingDoc: { ...previousSiblingDoc },\n req,\n siblingData: siblingData || {},\n siblingDoc: { ...siblingDoc },\n })\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["fieldAffectsData","tabHasName","traverseFields","promise","collection","context","data","doc","field","global","operation","previousDoc","previousSiblingDoc","req","siblingData","siblingDoc","hooks","afterChange","reduce","priorHook","currentHook","hookedValue","originalDoc","previousValue","name","value","undefined","Promise","resolve","type","fields","rows","Array","isArray","promises","forEach","row","i","push","all","block","blocks","find","blockType","slug","tabSiblingData","tabSiblingDoc","tabPreviousSiblingDoc","tabs","map","tab"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAMpC,SAASA,gBAAgB,EAAEC,UAAU,QAAQ,wBAAuB;AACpE,SAASC,cAAc,QAAQ,sBAAqB;AAiBpD,oEAAoE;AACpE,wBAAwB;AAExB,OAAO,MAAMC,UAAU,OAAO,EAC5BC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,GAAG,EACHC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,WAAW,EACXC,kBAAkB,EAClBC,GAAG,EACHC,WAAW,EACXC,UAAU,EACL;IACL,IAAIf,iBAAiBQ,QAAQ;QAC3B,gBAAgB;QAChB,IAAIA,MAAMQ,KAAK,EAAEC,aAAa;YAC5B,MAAMT,MAAMQ,KAAK,CAACC,WAAW,CAACC,MAAM,CAAC,OAAOC,WAAWC;gBACrD,MAAMD;gBAEN,MAAME,cAAc,MAAMD,YAAY;oBACpChB;oBACAC;oBACAC;oBACAE;oBACAC;oBACAC;oBACAY,aAAaf;oBACbI;oBACAC;oBACAW,eAAeZ,WAAW,CAACH,MAAMgB,IAAI,CAAC;oBACtCX;oBACAC;oBACAW,OAAOX,WAAW,CAACN,MAAMgB,IAAI,CAAC;gBAChC;gBAEA,IAAIH,gBAAgBK,WAAW;oBA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AC,aAAa+B;oBACb9B,YAAY+B;gBACd;gBAEA;YACF;QAEA,KAAK;YAAQ;gBACX,MAAM5C,eAAe;oBACnBE;oBACAC;oBACAC;oBACAC;oBACAuB,QAAQtB,MAAMwC,IAAI,CAACC,GAAG,CAAC,CAACC,MAAS,CAAA;4BAAE,GAAGA,GAAG;4BAAErB,MAAM;wBAAM,CAAA;oBACvDpB;oBACAC;oBACAC;oBACAC,oBAAoB;wBAAE,GAAGA,kBAAkB;oBAAC;oBAC5CC;oBACAC,aAAaA,eAAe,CAAC;oBAC7BC,YAAY;wBAAE,GAAGA,UAAU;oBAAC;gBAC9B;gBACA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/afterChange/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 { getFieldPaths } from '../../getFieldPaths.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 field: Field | TabAsField\n global: SanitizedGlobalConfig | null\n operation: 'create' | 'update'\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 previousDoc: Record<string, unknown>\n previousSiblingDoc: Record<string, unknown>\n req: PayloadRequestWithData\n siblingData: Record<string, unknown>\n siblingDoc: Record<string, unknown>\n}\n\n// This function is responsible for the following actions, in order:\n// - Execute field hooks\n\nexport const promise = async ({\n collection,\n context,\n data,\n doc,\n field,\n global,\n operation,\n parentPath,\n parentSchemaPath,\n previousDoc,\n previousSiblingDoc,\n req,\n siblingData,\n siblingDoc,\n}: Args): Promise<void> => {\n const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({\n field,\n parentPath,\n parentSchemaPath,\n })\n\n if (fieldAffectsData(field)) {\n // Execute hooks\n if (field.hooks?.afterChange) {\n await field.hooks.afterChange.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 previousDoc,\n previousSiblingDoc,\n previousValue: previousDoc[field.name],\n req,\n schemaPath: fieldSchemaPath,\n siblingData,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n }\n\n // Traverse subfields\n switch (field.type) {\n case 'group': {\n await traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.fields,\n global,\n operation,\n path: fieldPath,\n previousDoc,\n previousSiblingDoc: previousDoc[field.name] as Record<string, unknown>,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: (siblingData?.[field.name] as Record<string, unknown>) || {},\n siblingDoc: siblingDoc[field.name] as Record<string, unknown>,\n })\n\n break\n }\n\n case 'array': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n promises.push(\n traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.fields,\n global,\n operation,\n path: [...fieldPath, i],\n previousDoc,\n previousSiblingDoc: previousDoc?.[field.name]?.[i] || ({} as Record<string, unknown>),\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData?.[field.name]?.[i] || {},\n siblingDoc: { ...row } || {},\n }),\n )\n })\n await Promise.all(promises)\n }\n break\n }\n\n case 'blocks': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n const block = field.blocks.find((blockType) => blockType.slug === row.blockType)\n\n if (block) {\n promises.push(\n traverseFields({\n collection,\n context,\n data,\n doc,\n fields: block.fields,\n global,\n operation,\n path: [...fieldPath, i],\n previousDoc,\n previousSiblingDoc:\n previousDoc?.[field.name]?.[i] || ({} as Record<string, unknown>),\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData?.[field.name]?.[i] || {},\n siblingDoc: { ...row } || {},\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 collection,\n context,\n data,\n doc,\n fields: field.fields,\n global,\n operation,\n path: fieldPath,\n previousDoc,\n previousSiblingDoc: { ...previousSiblingDoc },\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData || {},\n siblingDoc: { ...siblingDoc },\n })\n\n break\n }\n\n case 'tab': {\n let tabSiblingData = siblingData\n let tabSiblingDoc = siblingDoc\n let tabPreviousSiblingDoc = siblingDoc\n\n if (tabHasName(field)) {\n tabSiblingData = siblingData[field.name] as Record<string, unknown>\n tabSiblingDoc = siblingDoc[field.name] as Record<string, unknown>\n tabPreviousSiblingDoc = previousDoc[field.name] as Record<string, unknown>\n }\n\n await traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.fields,\n global,\n operation,\n path: fieldPath,\n previousDoc,\n previousSiblingDoc: tabPreviousSiblingDoc,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: tabSiblingData,\n siblingDoc: tabSiblingDoc,\n })\n\n break\n }\n\n case 'tabs': {\n await traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n global,\n operation,\n path: fieldPath,\n previousDoc,\n previousSiblingDoc: { ...previousSiblingDoc },\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData || {},\n siblingDoc: { ...siblingDoc },\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?.afterChange?.length) {\n await editor.hooks.afterChange.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 previousDoc,\n previousSiblingDoc,\n previousValue: previousDoc[field.name],\n req,\n schemaPath: fieldSchemaPath,\n siblingData,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["MissingEditorProp","fieldAffectsData","tabHasName","getFieldPaths","traverseFields","promise","collection","context","data","doc","field","global","operation","parentPath","parentSchemaPath","previousDoc","previousSiblingDoc","req","siblingData","siblingDoc","path","fieldPath","schemaPath","fieldSchemaPath","hooks","afterChange","reduce","priorHook","currentHook","hookedValue","originalDoc","previousValue","name","value","undefined","Promise","resolve","type","fields","rows","Array","isArray","promises","forEach","row","i","push","all","block","blocks","find","blockType","slug","tabSiblingData","tabSiblingDoc","tabPreviousSiblingDoc","tabs","map","tab","editor","Error","length"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAOpC,SAASA,iBAAiB,QAAQ,2BAA0B;AAC5D,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,wBAAuB;AACpE,SAASC,aAAa,QA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AACC,MAAS,CAAA;4BAAE,GAAGA,GAAG;4BAAErB,MAAM;wBAAM,CAAA;oBACvD1B;oBACAC;oBACAQ,MAAMC;oBACNN;oBACAC,oBAAoB;wBAAE,GAAGA,kBAAkB;oBAAC;oBAC5CC;oBACAK,YAAYC;oBACZL,aAAaA,eAAe,CAAC;oBAC7BC,YAAY;wBAAE,GAAGA,UAAU;oBAAC;gBAC9B;gBACA;YACF;QAEA,KAAK;YAAY;gBACf,IAAI,CAACT,OAAOiD,QAAQ;oBAClB,MAAM,IAAI3D,kBAAkBU,OAAO,8HAA8H;;gBACnK;gBACA,IAAI,OAAOA,OAAOiD,WAAW,YAAY;oBACvC,MAAM,IAAIC,MAAM;gBAClB;gBAEA,MAAMD,SAA0BjD,OAAOiD;gBAEvC,IAAIA,QAAQnC,OAAOC,aAAaoC,QAAQ;oBACtC,MAAMF,OAAOnC,KAAK,CAACC,WAAW,CAACC,MAAM,CAAC,OAAOC,WAAWC;wBACtD,MAAMD;wBAEN,MAAME,cAAc,MAAMD,YAAY;4BACpCtB;4BACAC;4BACAC;4BACAE;4BACAC;4BACAC;4BACAkB,aAAarB;4BACbW,MAAMC;4BACNN;4BACAC;4BACAe,eAAehB,WAAW,CAACL,MAAMsB,IAAI,CAAC;4BACtCf;4BACAK,YAAYC;4BACZL;4BACAe,OAAOd,UAAU,CAACT,MAAMsB,IAAI,CAAC;wBAC/B;wBAEA,IAAIH,gBAAgBK,WAAW;4BAC7Bf,UAAU,CAACT,MAAMsB,IAAI,CAAC,GAAGH;wBAC3B;oBACF,GAAGM,QAAQC,OAAO;gBACpB;gBACA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
|
|
@@ -10,12 +10,14 @@ type Args = {
|
|
|
10
10
|
fields: (Field | TabAsField)[];
|
|
11
11
|
global: SanitizedGlobalConfig | null;
|
|
12
12
|
operation: 'create' | 'update';
|
|
13
|
+
path: (number | string)[];
|
|
13
14
|
previousDoc: Record<string, unknown>;
|
|
14
15
|
previousSiblingDoc: Record<string, unknown>;
|
|
15
16
|
req: PayloadRequestWithData;
|
|
17
|
+
schemaPath: string[];
|
|
16
18
|
siblingData: Record<string, unknown>;
|
|
17
19
|
siblingDoc: Record<string, unknown>;
|
|
18
20
|
};
|
|
19
|
-
export declare const traverseFields: ({ collection, context, data, doc, fields, global, operation, previousDoc, previousSiblingDoc, req, siblingData, siblingDoc, }: Args) => Promise<void>;
|
|
21
|
+
export declare const traverseFields: ({ collection, context, data, doc, fields, global, operation, path, previousDoc, previousSiblingDoc, req, schemaPath, siblingData, siblingDoc, }: Args) => Promise<void>;
|
|
20
22
|
export {};
|
|
21
23
|
//# sourceMappingURL=traverseFields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterChange/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,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5B,MAAM,EAAE,CAAC,KAAK,GAAG,UAAU,CAAC,EAAE,CAAA;IAC9B,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAAA;IACpC,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC9B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAA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AAE,MAAM,EAAE,CAAA;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACpC,CAAA;AAED,eAAO,MAAM,cAAc,oJAexB,IAAI,KAAG,QAAQ,IAAI,CAyBrB,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { promise } from './promise.js';
|
|
2
|
-
export const traverseFields = async ({ collection, context, data, doc, fields, global, operation, previousDoc, previousSiblingDoc, req, siblingData, siblingDoc })=>{
|
|
2
|
+
export const traverseFields = async ({ collection, context, data, doc, fields, global, operation, path, previousDoc, previousSiblingDoc, req, schemaPath, siblingData, siblingDoc })=>{
|
|
3
3
|
const promises = [];
|
|
4
4
|
fields.forEach((field)=>{
|
|
5
5
|
promises.push(promise({
|
|
@@ -10,6 +10,8 @@ export const traverseFields = async ({ collection, context, data, doc, fields, g
|
|
|
10
10
|
field,
|
|
11
11
|
global,
|
|
12
12
|
operation,
|
|
13
|
+
parentPath: path,
|
|
14
|
+
parentSchemaPath: schemaPath,
|
|
13
15
|
previousDoc,
|
|
14
16
|
previousSiblingDoc,
|
|
15
17
|
req,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/afterChange/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 data: Record<string, unknown>\n doc: Record<string, unknown>\n fields: (Field | TabAsField)[]\n global: SanitizedGlobalConfig | null\n operation: 'create' | 'update'\n previousDoc: Record<string, unknown>\n previousSiblingDoc: Record<string, unknown>\n req: PayloadRequestWithData\n siblingData: Record<string, unknown>\n siblingDoc: Record<string, unknown>\n}\n\nexport const traverseFields = async ({\n collection,\n context,\n data,\n doc,\n fields,\n global,\n operation,\n previousDoc,\n previousSiblingDoc,\n req,\n siblingData,\n siblingDoc,\n}: Args): Promise<void> => {\n const promises = []\n\n fields.forEach((field) => {\n promises.push(\n promise({\n collection,\n context,\n data,\n doc,\n field,\n global,\n operation,\n previousDoc,\n previousSiblingDoc,\n req,\n siblingData,\n siblingDoc,\n }),\n )\n })\n\n await Promise.all(promises)\n}\n"],"names":["promise","traverseFields","collection","context","data","doc","fields","global","operation","previousDoc","previousSiblingDoc","req","siblingData","siblingDoc","promises","forEach","field","push","Promise","all"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/afterChange/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 data: Record<string, unknown>\n doc: Record<string, unknown>\n fields: (Field | TabAsField)[]\n global: SanitizedGlobalConfig | null\n operation: 'create' | 'update'\n path: (number | string)[]\n previousDoc: Record<string, unknown>\n previousSiblingDoc: Record<string, unknown>\n req: PayloadRequestWithData\n schemaPath: string[]\n siblingData: Record<string, unknown>\n siblingDoc: Record<string, unknown>\n}\n\nexport const traverseFields = async ({\n collection,\n context,\n data,\n doc,\n fields,\n global,\n operation,\n path,\n previousDoc,\n previousSiblingDoc,\n req,\n schemaPath,\n siblingData,\n siblingDoc,\n}: Args): Promise<void> => {\n const promises = []\n\n fields.forEach((field) => {\n promises.push(\n promise({\n collection,\n context,\n data,\n doc,\n field,\n global,\n operation,\n parentPath: path,\n parentSchemaPath: schemaPath,\n previousDoc,\n previousSiblingDoc,\n req,\n siblingData,\n siblingDoc,\n }),\n )\n })\n\n await Promise.all(promises)\n}\n"],"names":["promise","traverseFields","collection","context","data","doc","fields","global","operation","path","previousDoc","previousSiblingDoc","req","schemaPath","siblingData","siblingDoc","promises","forEach","field","push","parentPath","parentSchemaPath","Promise","all"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;","mappings":"AAKA,SAASA,OAAO,QAAQ,eAAc;AAmBtC,OAAO,MAAMC,iBAAiB,OAAO,EACnCC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,GAAG,EACHC,MAAM,EACNC,MAAM,EACNC,SAAS,EACTC,IAAI,EACJC,WAAW,EACXC,kBAAkB,EAClBC,GAAG,EACHC,UAAU,EACVC,WAAW,EACXC,UAAU,EACL;IACL,MAAMC,WAAW,EAAE;IAEnBV,OAAOW,OAAO,CAAC,CAACC;QACdF,SAASG,IAAI,CACXnB,QAAQ;YACNE;YACAC;YACAC;YACAC;YACAa;YACAX;YACAC;YACAY,YAAYX;YACZY,kBAAkBR;YAClBH;YACAC;YACAC;YACAE;YACAC;QACF;IAEJ;IAEA,MAAMO,QAAQC,GAAG,CAACP;AACpB,EAAC"}
|
|
@@ -20,7 +20,7 @@ type Args = {
|
|
|
20
20
|
/**
|
|
21
21
|
* This function is responsible for the following actions, in order:
|
|
22
22
|
* - Remove hidden fields from response
|
|
23
|
-
* - Flatten locales into requested locale
|
|
23
|
+
* - Flatten locales into requested locale. If the input doc contains all locales, the output doc after this function will only contain the requested locale.
|
|
24
24
|
* - Sanitize outgoing data (point field, etc.)
|
|
25
25
|
* - Execute field hooks
|
|
26
26
|
* - Execute read access control
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/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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;IAC5B,KAAK,EAAE,OAAO,CAAA;IACd,cAAc,EAAE,IAAI,GAAG,MAAM,CAAA;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAAA;IACpC,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,OAAO,CAAA;IACvB,GAAG,EAAE,sBAAsB,CAAA;IAC3B,gBAAgB,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED;;;;;;;;GAQG;AAEH,wBAAsB,SAAS,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAyD/D"}
|
|
@@ -3,7 +3,7 @@ import { traverseFields } from './traverseFields.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* This function is responsible for the following actions, in order:
|
|
5
5
|
* - Remove hidden fields from response
|
|
6
|
-
* - Flatten locales into requested locale
|
|
6
|
+
* - Flatten locales into requested locale. If the input doc contains all locales, the output doc after this function will only contain the requested locale.
|
|
7
7
|
* - Sanitize outgoing data (point field, etc.)
|
|
8
8
|
* - Execute field hooks
|
|
9
9
|
* - Execute read access control
|
|
@@ -31,8 +31,10 @@ import { traverseFields } from './traverseFields.js';
|
|
|
31
31
|
global,
|
|
32
32
|
locale,
|
|
33
33
|
overrideAccess,
|
|
34
|
+
path: [],
|
|
34
35
|
populationPromises,
|
|
35
36
|
req,
|
|
37
|
+
schemaPath: [],
|
|
36
38
|
showHiddenFields,
|
|
37
39
|
siblingDoc: doc
|
|
38
40
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/afterRead/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 = {\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 findMany?: boolean\n flattenLocales?: boolean\n global: SanitizedGlobalConfig | null\n locale: string\n overrideAccess: boolean\n req: PayloadRequestWithData\n showHiddenFields: boolean\n}\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
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/afterRead/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 = {\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 findMany?: boolean\n flattenLocales?: boolean\n global: SanitizedGlobalConfig | null\n locale: string\n overrideAccess: boolean\n req: PayloadRequestWithData\n showHiddenFields: boolean\n}\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. If the input doc contains all locales, the output doc after this function will only contain the requested locale.\n * - Sanitize outgoing data (point field, etc.)\n * - Execute field hooks\n * - Execute read access control\n * - Populate relationships\n */\n\nexport async function afterRead<T = any>(args: Args): Promise<T> {\n const {\n collection,\n context,\n currentDepth: incomingCurrentDepth,\n depth: incomingDepth,\n doc: incomingDoc,\n draft,\n fallbackLocale,\n findMany,\n flattenLocales = true,\n global,\n locale,\n overrideAccess,\n req,\n showHiddenFields,\n } = args\n\n const doc = deepCopyObject(incomingDoc)\n const fieldPromises = []\n const populationPromises = []\n\n let depth =\n incomingDepth || incomingDepth === 0\n ? parseInt(String(incomingDepth), 10)\n : req.payload.config.defaultDepth\n if (depth > req.payload.config.maxDepth) depth = req.payload.config.maxDepth\n\n const currentDepth = incomingCurrentDepth || 1\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: collection?.fields || global?.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: [],\n populationPromises,\n req,\n schemaPath: [],\n showHiddenFields,\n siblingDoc: doc,\n })\n\n await Promise.all(fieldPromises)\n await Promise.all(populationPromises)\n\n return doc\n}\n"],"names":["deepCopyObject","traverseFields","afterRead","args","collection","context","currentDepth","incomingCurrentDepth","depth","incomingDepth","doc","incomingDoc","draft","fallbackLocale","findMany","flattenLocales","global","locale","overrideAccess","req","showHiddenFields","fieldPromises","populationPromises","parseInt","String","payload","config","defaultDepth","maxDepth","fields","path","schemaPath","siblingDoc","Promise","all"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,cAAc,QAAQ,uCAAsC;AACrE,SAASC,cAAc,QAAQ,sBAAqB;AAmBpD;;;;;;;;CAQC,GAED,OAAO,eAAeC,UAAmBC,IAAU;IACjD,MAAM,EACJC,UAAU,EACVC,OAAO,EACPC,cAAcC,oBAAoB,EAClCC,OAAOC,aAAa,EACpBC,KAAKC,WAAW,EAChBC,KAAK,EACLC,cAAc,EACdC,QAAQ,EACRC,iBAAiB,IAAI,EACrBC,MAAM,EACNC,MAAM,EACNC,cAAc,EACdC,GAAG,EACHC,gBAAgB,EACjB,GAAGjB;IAEJ,MAAMO,MAAMV,eAAeW;IAC3B,MAAMU,gBAAgB,EAAE;IACxB,MAAMC,qBAAqB,EAAE;IAE7B,IAAId,QACFC,iBAAiBA,kBAAkB,IAC/Bc,SAASC,OAAOf,gBAAgB,MAChCU,IAAIM,OAAO,CAACC,MAAM,CAACC,YAAY;IACrC,IAAInB,QAAQW,IAAIM,OAAO,CAACC,MAAM,CAACE,QAAQ,EAAEpB,QAAQW,IAAIM,OAAO,CAACC,MAAM,CAACE,QAAQ;IAE5E,MAAMtB,eAAeC,wBAAwB;IAE7CN,eAAe;QACbG;QACAC;QACAC;QACAE;QACAE;QACAE;QACAC;QACAQ;QACAQ,QAAQzB,YAAYyB,UAAUb,QAAQa;QACtCf;QACAC;QACAC;QACAC;QACAC;QACAY,MAAM,EAAE;QACRR;QACAH;QACAY,YAAY,EAAE;QACdX;QACAY,YAAYtB;IACd;IAEA,MAAMuB,QAAQC,GAAG,CAACb;IAClB,MAAMY,QAAQC,GAAG,CAACZ;IAElB,OAAOZ;AACT"}
|
|
@@ -20,6 +20,14 @@ type Args = {
|
|
|
20
20
|
global: SanitizedGlobalConfig | null;
|
|
21
21
|
locale: null | string;
|
|
22
22
|
overrideAccess: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The parent's path.
|
|
25
|
+
*/
|
|
26
|
+
parentPath: (number | string)[];
|
|
27
|
+
/**
|
|
28
|
+
* The parent's schemaPath (path without indexes).
|
|
29
|
+
*/
|
|
30
|
+
parentSchemaPath: string[];
|
|
23
31
|
populationPromises: Promise<void>[];
|
|
24
32
|
req: PayloadRequestWithData;
|
|
25
33
|
showHiddenFields: boolean;
|
|
@@ -27,6 +35,6 @@ type Args = {
|
|
|
27
35
|
triggerAccessControl?: boolean;
|
|
28
36
|
triggerHooks?: boolean;
|
|
29
37
|
};
|
|
30
|
-
export declare const promise: ({ collection, context, currentDepth, depth, doc, draft, fallbackLocale, field, fieldPromises, findMany, flattenLocales, global, locale, overrideAccess, populationPromises, req, showHiddenFields, siblingDoc, triggerAccessControl, triggerHooks, }: Args) => Promise<void>;
|
|
38
|
+
export declare const promise: ({ collection, context, currentDepth, depth, doc, draft, fallbackLocale, field, fieldPromises, findMany, flattenLocales, global, locale, overrideAccess, parentPath, parentSchemaPath, populationPromises, req, showHiddenFields, siblingDoc, triggerAccessControl, triggerHooks, }: Args) => Promise<void>;
|
|
31
39
|
export {};
|
|
32
40
|
//# sourceMappingURL=promise.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/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;
|
|
1
|
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/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;AAS9D,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,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAA;IAC9B,QAAQ,EAAE,OAAO,CAAA;IACjB,cAAc,EAAE,OAAO,CAAA;IAC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