payload 3.91.0 → 3.92.0
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/bin/index.js +0 -0
- package/dist/bin/index.js.map +0 -0
- package/dist/errors/APIError.d.ts +4 -0
- package/dist/errors/APIError.d.ts.map +1 -1
- package/dist/errors/APIError.js +5 -1
- package/dist/errors/APIError.js.map +1 -1
- package/dist/errors/AuthenticationError.d.ts.map +1 -1
- package/dist/errors/AuthenticationError.js +1 -0
- package/dist/errors/AuthenticationError.js.map +1 -1
- package/dist/errors/DuplicateCollection.d.ts.map +1 -1
- package/dist/errors/DuplicateCollection.js +1 -0
- package/dist/errors/DuplicateCollection.js.map +1 -1
- package/dist/errors/DuplicateFieldName.d.ts.map +1 -1
- package/dist/errors/DuplicateFieldName.js +1 -0
- package/dist/errors/DuplicateFieldName.js.map +1 -1
- package/dist/errors/DuplicateGlobal.d.ts.map +1 -1
- package/dist/errors/DuplicateGlobal.js +1 -0
- package/dist/errors/DuplicateGlobal.js.map +1 -1
- package/dist/errors/ErrorDeletingFile.d.ts.map +1 -1
- package/dist/errors/ErrorDeletingFile.js +1 -0
- package/dist/errors/ErrorDeletingFile.js.map +1 -1
- package/dist/errors/FileRetrievalError.d.ts.map +1 -1
- package/dist/errors/FileRetrievalError.js +1 -0
- package/dist/errors/FileRetrievalError.js.map +1 -1
- package/dist/errors/FileUploadError.d.ts.map +1 -1
- package/dist/errors/FileUploadError.js +1 -0
- package/dist/errors/FileUploadError.js.map +1 -1
- package/dist/errors/Forbidden.d.ts.map +1 -1
- package/dist/errors/Forbidden.js +1 -0
- package/dist/errors/Forbidden.js.map +1 -1
- package/dist/errors/InvalidConfiguration.d.ts.map +1 -1
- package/dist/errors/InvalidConfiguration.js +1 -0
- package/dist/errors/InvalidConfiguration.js.map +1 -1
- package/dist/errors/InvalidFieldJoin.d.ts.map +1 -1
- package/dist/errors/InvalidFieldJoin.js +1 -0
- package/dist/errors/InvalidFieldJoin.js.map +1 -1
- package/dist/errors/InvalidFieldName.d.ts.map +1 -1
- package/dist/errors/InvalidFieldName.js +1 -0
- package/dist/errors/InvalidFieldName.js.map +1 -1
- package/dist/errors/InvalidFieldRelationship.d.ts.map +1 -1
- package/dist/errors/InvalidFieldRelationship.js +1 -0
- package/dist/errors/InvalidFieldRelationship.js.map +1 -1
- package/dist/errors/InvalidSchema.d.ts.map +1 -1
- package/dist/errors/InvalidSchema.js +1 -0
- package/dist/errors/InvalidSchema.js.map +1 -1
- package/dist/errors/Locked.d.ts.map +1 -1
- package/dist/errors/Locked.js +1 -0
- package/dist/errors/Locked.js.map +1 -1
- package/dist/errors/LockedAuth.d.ts.map +1 -1
- package/dist/errors/LockedAuth.js +1 -0
- package/dist/errors/LockedAuth.js.map +1 -1
- package/dist/errors/MissingCollectionLabel.d.ts.map +1 -1
- package/dist/errors/MissingCollectionLabel.js +1 -0
- package/dist/errors/MissingCollectionLabel.js.map +1 -1
- package/dist/errors/MissingEditorProp.d.ts.map +1 -1
- package/dist/errors/MissingEditorProp.js +1 -0
- package/dist/errors/MissingEditorProp.js.map +1 -1
- package/dist/errors/MissingFieldInputOptions.d.ts.map +1 -1
- package/dist/errors/MissingFieldInputOptions.js +1 -0
- package/dist/errors/MissingFieldInputOptions.js.map +1 -1
- package/dist/errors/MissingFieldType.d.ts.map +1 -1
- package/dist/errors/MissingFieldType.js +1 -0
- package/dist/errors/MissingFieldType.js.map +1 -1
- package/dist/errors/MissingFile.d.ts.map +1 -1
- package/dist/errors/MissingFile.js +1 -0
- package/dist/errors/MissingFile.js.map +1 -1
- package/dist/errors/NotFound.d.ts.map +1 -1
- package/dist/errors/NotFound.js +1 -0
- package/dist/errors/NotFound.js.map +1 -1
- package/dist/errors/QueryError.d.ts.map +1 -1
- package/dist/errors/QueryError.js +1 -0
- package/dist/errors/QueryError.js.map +1 -1
- package/dist/errors/ReservedFieldName.d.ts.map +1 -1
- package/dist/errors/ReservedFieldName.js +1 -0
- package/dist/errors/ReservedFieldName.js.map +1 -1
- package/dist/errors/TimestampsRequired.d.ts.map +1 -1
- package/dist/errors/TimestampsRequired.js +1 -0
- package/dist/errors/TimestampsRequired.js.map +1 -1
- package/dist/errors/UnauthorizedError.d.ts.map +1 -1
- package/dist/errors/UnauthorizedError.js +1 -0
- package/dist/errors/UnauthorizedError.js.map +1 -1
- package/dist/errors/UnverifiedEmail.d.ts.map +1 -1
- package/dist/errors/UnverifiedEmail.js +1 -0
- package/dist/errors/UnverifiedEmail.js.map +1 -1
- package/dist/errors/ValidationError.d.ts.map +1 -1
- package/dist/errors/ValidationError.js +1 -0
- package/dist/errors/ValidationError.js.map +1 -1
- package/dist/fields/hooks/beforeChange/flattenValidationData.d.ts +14 -0
- package/dist/fields/hooks/beforeChange/flattenValidationData.d.ts.map +1 -0
- package/dist/fields/hooks/beforeChange/flattenValidationData.js +36 -0
- package/dist/fields/hooks/beforeChange/flattenValidationData.js.map +1 -0
- package/dist/fields/hooks/beforeChange/promise.d.ts +2 -1
- package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.js +96 -22
- package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
- package/dist/fields/hooks/beforeChange/traverseFields.d.ts +2 -1
- package/dist/fields/hooks/beforeChange/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/traverseFields.js +2 -1
- package/dist/fields/hooks/beforeChange/traverseFields.js.map +1 -1
- package/dist/index.bundled.d.ts +6 -1
- package/dist/utilities/getEntityPermissions/getEntityPermissions.d.ts.map +1 -1
- package/dist/utilities/getEntityPermissions/getEntityPermissions.js +1 -0
- package/dist/utilities/getEntityPermissions/getEntityPermissions.js.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReservedFieldName.d.ts","sourceRoot":"","sources":["../../src/errors/ReservedFieldName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAEnE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,qBAAa,iBAAkB,SAAQ,QAAQ;gBACjC,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"ReservedFieldName.d.ts","sourceRoot":"","sources":["../../src/errors/ReservedFieldName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAEnE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,qBAAa,iBAAkB,SAAQ,QAAQ;gBACjC,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM;CAIzD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/errors/ReservedFieldName.ts"],"sourcesContent":["import type { FieldAffectingData } from '../fields/config/types.js'\n\nimport { APIError } from './APIError.js'\n\nexport class ReservedFieldName extends APIError {\n constructor(field: FieldAffectingData, fieldName: string) {\n super(`Field ${field.label} has reserved name '${fieldName}'.`)\n }\n}\n"],"names":["APIError","ReservedFieldName","field","fieldName","label"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,gBAAe;AAExC,OAAO,MAAMC,0BAA0BD;IACrC,YAAYE,KAAyB,EAAEC,SAAiB,CAAE;QACxD,KAAK,CAAC,CAAC,MAAM,EAAED,MAAME,KAAK,CAAC,oBAAoB,EAAED,UAAU,EAAE,CAAC;
|
|
1
|
+
{"version":3,"sources":["../../src/errors/ReservedFieldName.ts"],"sourcesContent":["import type { FieldAffectingData } from '../fields/config/types.js'\n\nimport { APIError } from './APIError.js'\n\nexport class ReservedFieldName extends APIError {\n constructor(field: FieldAffectingData, fieldName: string) {\n super(`Field ${field.label} has reserved name '${fieldName}'.`)\n this.name = 'ReservedFieldName'\n }\n}\n"],"names":["APIError","ReservedFieldName","field","fieldName","label","name"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,gBAAe;AAExC,OAAO,MAAMC,0BAA0BD;IACrC,YAAYE,KAAyB,EAAEC,SAAiB,CAAE;QACxD,KAAK,CAAC,CAAC,MAAM,EAAED,MAAME,KAAK,CAAC,oBAAoB,EAAED,UAAU,EAAE,CAAC;QAC9D,IAAI,CAACE,IAAI,GAAG;IACd;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimestampsRequired.d.ts","sourceRoot":"","sources":["../../src/errors/TimestampsRequired.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AAEtE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,qBAAa,kBAAmB,SAAQ,QAAQ;gBAClC,UAAU,EAAE,gBAAgB;
|
|
1
|
+
{"version":3,"file":"TimestampsRequired.d.ts","sourceRoot":"","sources":["../../src/errors/TimestampsRequired.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AAEtE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,qBAAa,kBAAmB,SAAQ,QAAQ;gBAClC,UAAU,EAAE,gBAAgB;CAMzC"}
|
|
@@ -2,6 +2,7 @@ import { APIError } from './APIError.js';
|
|
|
2
2
|
export class TimestampsRequired extends APIError {
|
|
3
3
|
constructor(collection){
|
|
4
4
|
super(`Timestamps are required in the collection ${collection.slug} because you have opted in to Versions.`);
|
|
5
|
+
this.name = 'TimestampsRequired';
|
|
5
6
|
}
|
|
6
7
|
}
|
|
7
8
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/errors/TimestampsRequired.ts"],"sourcesContent":["import type { CollectionConfig } from '../collections/config/types.js'\n\nimport { APIError } from './APIError.js'\n\nexport class TimestampsRequired extends APIError {\n constructor(collection: CollectionConfig) {\n super(\n `Timestamps are required in the collection ${collection.slug} because you have opted in to Versions.`,\n )\n }\n}\n"],"names":["APIError","TimestampsRequired","collection","slug"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,gBAAe;AAExC,OAAO,MAAMC,2BAA2BD;IACtC,YAAYE,UAA4B,CAAE;QACxC,KAAK,CACH,CAAC,0CAA0C,EAAEA,WAAWC,IAAI,CAAC,uCAAuC,CAAC;
|
|
1
|
+
{"version":3,"sources":["../../src/errors/TimestampsRequired.ts"],"sourcesContent":["import type { CollectionConfig } from '../collections/config/types.js'\n\nimport { APIError } from './APIError.js'\n\nexport class TimestampsRequired extends APIError {\n constructor(collection: CollectionConfig) {\n super(\n `Timestamps are required in the collection ${collection.slug} because you have opted in to Versions.`,\n )\n this.name = 'TimestampsRequired'\n }\n}\n"],"names":["APIError","TimestampsRequired","collection","slug","name"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,gBAAe;AAExC,OAAO,MAAMC,2BAA2BD;IACtC,YAAYE,UAA4B,CAAE;QACxC,KAAK,CACH,CAAC,0CAA0C,EAAEA,WAAWC,IAAI,CAAC,uCAAuC,CAAC;QAEvG,IAAI,CAACC,IAAI,GAAG;IACd;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnauthorizedError.d.ts","sourceRoot":"","sources":["../../src/errors/UnauthorizedError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAKzD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,qBAAa,iBAAkB,SAAQ,QAAQ;gBACjC,CAAC,CAAC,EAAE,SAAS;
|
|
1
|
+
{"version":3,"file":"UnauthorizedError.d.ts","sourceRoot":"","sources":["../../src/errors/UnauthorizedError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAKzD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,qBAAa,iBAAkB,SAAQ,QAAQ;gBACjC,CAAC,CAAC,EAAE,SAAS;CAI1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/errors/UnauthorizedError.ts"],"sourcesContent":["import type { TFunction } from '@payloadcms/translations'\n\nimport { en } from '@payloadcms/translations/languages/en'\nimport { status as httpStatus } from 'http-status'\n\nimport { APIError } from './APIError.js'\n\nexport class UnauthorizedError extends APIError {\n constructor(t?: TFunction) {\n super(t ? t('error:unauthorized') : en.translations.error.unauthorized, httpStatus.UNAUTHORIZED)\n }\n}\n"],"names":["en","status","httpStatus","APIError","UnauthorizedError","t","translations","error","unauthorized","UNAUTHORIZED"],"mappings":"AAEA,SAASA,EAAE,QAAQ,wCAAuC;AAC1D,SAASC,UAAUC,UAAU,QAAQ,cAAa;AAElD,SAASC,QAAQ,QAAQ,gBAAe;AAExC,OAAO,MAAMC,0BAA0BD;IACrC,YAAYE,CAAa,CAAE;QACzB,KAAK,CAACA,IAAIA,EAAE,wBAAwBL,GAAGM,YAAY,CAACC,KAAK,CAACC,YAAY,EAAEN,WAAWO,YAAY;
|
|
1
|
+
{"version":3,"sources":["../../src/errors/UnauthorizedError.ts"],"sourcesContent":["import type { TFunction } from '@payloadcms/translations'\n\nimport { en } from '@payloadcms/translations/languages/en'\nimport { status as httpStatus } from 'http-status'\n\nimport { APIError } from './APIError.js'\n\nexport class UnauthorizedError extends APIError {\n constructor(t?: TFunction) {\n super(t ? t('error:unauthorized') : en.translations.error.unauthorized, httpStatus.UNAUTHORIZED)\n this.name = 'UnauthorizedError'\n }\n}\n"],"names":["en","status","httpStatus","APIError","UnauthorizedError","t","translations","error","unauthorized","UNAUTHORIZED","name"],"mappings":"AAEA,SAASA,EAAE,QAAQ,wCAAuC;AAC1D,SAASC,UAAUC,UAAU,QAAQ,cAAa;AAElD,SAASC,QAAQ,QAAQ,gBAAe;AAExC,OAAO,MAAMC,0BAA0BD;IACrC,YAAYE,CAAa,CAAE;QACzB,KAAK,CAACA,IAAIA,EAAE,wBAAwBL,GAAGM,YAAY,CAACC,KAAK,CAACC,YAAY,EAAEN,WAAWO,YAAY;QAC/F,IAAI,CAACC,IAAI,GAAG;IACd;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnverifiedEmail.d.ts","sourceRoot":"","sources":["../../src/errors/UnverifiedEmail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAKzD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,qBAAa,eAAgB,SAAQ,QAAQ;gBAC/B,EAAE,CAAC,EAAE,EAAE;QAAE,CAAC,CAAC,EAAE,SAAS,CAAA;KAAE;
|
|
1
|
+
{"version":3,"file":"UnverifiedEmail.d.ts","sourceRoot":"","sources":["../../src/errors/UnverifiedEmail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAKzD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,qBAAa,eAAgB,SAAQ,QAAQ;gBAC/B,EAAE,CAAC,EAAE,EAAE;QAAE,CAAC,CAAC,EAAE,SAAS,CAAA;KAAE;CAOrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/errors/UnverifiedEmail.ts"],"sourcesContent":["import type { TFunction } from '@payloadcms/translations'\n\nimport { en } from '@payloadcms/translations/languages/en'\nimport { status as httpStatus } from 'http-status'\n\nimport { APIError } from './APIError.js'\n\nexport class UnverifiedEmail extends APIError {\n constructor({ t }: { t?: TFunction }) {\n super(\n t ? t('error:unverifiedEmail') : en.translations.error.unverifiedEmail,\n httpStatus.FORBIDDEN,\n )\n }\n}\n"],"names":["en","status","httpStatus","APIError","UnverifiedEmail","t","translations","error","unverifiedEmail","FORBIDDEN"],"mappings":"AAEA,SAASA,EAAE,QAAQ,wCAAuC;AAC1D,SAASC,UAAUC,UAAU,QAAQ,cAAa;AAElD,SAASC,QAAQ,QAAQ,gBAAe;AAExC,OAAO,MAAMC,wBAAwBD;IACnC,YAAY,EAAEE,CAAC,EAAqB,CAAE;QACpC,KAAK,CACHA,IAAIA,EAAE,2BAA2BL,GAAGM,YAAY,CAACC,KAAK,CAACC,eAAe,EACtEN,WAAWO,SAAS;
|
|
1
|
+
{"version":3,"sources":["../../src/errors/UnverifiedEmail.ts"],"sourcesContent":["import type { TFunction } from '@payloadcms/translations'\n\nimport { en } from '@payloadcms/translations/languages/en'\nimport { status as httpStatus } from 'http-status'\n\nimport { APIError } from './APIError.js'\n\nexport class UnverifiedEmail extends APIError {\n constructor({ t }: { t?: TFunction }) {\n super(\n t ? t('error:unverifiedEmail') : en.translations.error.unverifiedEmail,\n httpStatus.FORBIDDEN,\n )\n this.name = 'UnverifiedEmail'\n }\n}\n"],"names":["en","status","httpStatus","APIError","UnverifiedEmail","t","translations","error","unverifiedEmail","FORBIDDEN","name"],"mappings":"AAEA,SAASA,EAAE,QAAQ,wCAAuC;AAC1D,SAASC,UAAUC,UAAU,QAAQ,cAAa;AAElD,SAASC,QAAQ,QAAQ,gBAAe;AAExC,OAAO,MAAMC,wBAAwBD;IACnC,YAAY,EAAEE,CAAC,EAAqB,CAAE;QACpC,KAAK,CACHA,IAAIA,EAAE,2BAA2BL,GAAGM,YAAY,CAACC,KAAK,CAACC,eAAe,EACtEN,WAAWO,SAAS;QAEtB,IAAI,CAACC,IAAI,GAAG;IACd;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValidationError.d.ts","sourceRoot":"","sources":["../../src/errors/ValidationError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAKzD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEvD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,+EAA+E;AAC/E,eAAO,MAAM,mBAAmB,oBAAoB,CAAA;AAEpD,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,CAAC,EAAE,aAAa,GAAG,WAAW,CAAA;IAEnC,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,qBAAa,eAAgB,SAAQ,QAAQ,CAAC;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,oBAAoB,EAAE,CAAA;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAC;gBAEE,OAAO,EAAE;QACP,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,MAAM,EAAE,oBAAoB,EAAE,CAAA;QAC9B,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;QACpB;;WAEG;QACH,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;KAC9B,EACD,CAAC,CAAC,EAAE,SAAS;
|
|
1
|
+
{"version":3,"file":"ValidationError.d.ts","sourceRoot":"","sources":["../../src/errors/ValidationError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAKzD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEvD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,+EAA+E;AAC/E,eAAO,MAAM,mBAAmB,oBAAoB,CAAA;AAEpD,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,CAAC,EAAE,aAAa,GAAG,WAAW,CAAA;IAEnC,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,qBAAa,eAAgB,SAAQ,QAAQ,CAAC;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,oBAAoB,EAAE,CAAA;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAC;gBAEE,OAAO,EAAE;QACP,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,MAAM,EAAE,oBAAoB,EAAE,CAAA;QAC9B,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;QACpB;;WAEG;QACH,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;KAC9B,EACD,CAAC,CAAC,EAAE,SAAS;CA2ChB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/errors/ValidationError.ts"],"sourcesContent":["import type { TFunction } from '@payloadcms/translations'\n\nimport { en } from '@payloadcms/translations/languages/en'\nimport { status as httpStatus } from 'http-status'\n\nimport type { LabelFunction, StaticLabel } from '../config/types.js'\nimport type { PayloadRequest } from '../types/index.js'\n\nimport { APIError } from './APIError.js'\n\n/** @deprecated Use `instanceof ValidationError` instead of name comparison. */\nexport const ValidationErrorName = 'ValidationError'\n\nexport type ValidationFieldError = {\n label?: LabelFunction | StaticLabel\n // The error message to display for this field\n message: string\n path: string\n tableName?: string\n}\n\nexport class ValidationError extends APIError<{\n collection?: string\n errors: ValidationFieldError[]\n global?: string\n}> {\n constructor(\n results: {\n collection?: string\n errors: ValidationFieldError[]\n global?: string\n id?: number | string\n /**\n * req needs to be passed through (if you have one) in order to resolve label functions that may be part of the errors array\n */\n req?: Partial<PayloadRequest>\n },\n t?: TFunction,\n ) {\n const message = t\n ? t('error:followingFieldsInvalid', { count: results.errors.length })\n : results.errors.length === 1\n ? en.translations.error.followingFieldsInvalid_one\n : en.translations.error.followingFieldsInvalid_other\n\n const req = results.req\n // delete to avoid logging the whole req\n delete results['req']\n\n super(\n `${message} ${results.errors\n .map((f) => {\n if (f.label) {\n if (typeof f.label === 'function') {\n if (!req || !req.i18n || !req.t) {\n return f.path\n }\n\n return f.label({ i18n: req.i18n, t: req.t })\n }\n\n if (typeof f.label === 'object') {\n if (req?.i18n?.language) {\n return f.label[req.i18n.language]\n }\n\n return f.label[Object.keys(f.label)[0]!]\n }\n\n return f.label\n }\n\n return f.path\n })\n .join(', ')}`,\n httpStatus.BAD_REQUEST,\n results,\n )\n }\n}\n"],"names":["en","status","httpStatus","APIError","ValidationErrorName","ValidationError","results","t","message","count","errors","length","translations","error","followingFieldsInvalid_one","followingFieldsInvalid_other","req","map","f","label","i18n","path","language","Object","keys","join","BAD_REQUEST"],"mappings":"AAEA,SAASA,EAAE,QAAQ,wCAAuC;AAC1D,SAASC,UAAUC,UAAU,QAAQ,cAAa;AAKlD,SAASC,QAAQ,QAAQ,gBAAe;AAExC,6EAA6E,GAC7E,OAAO,MAAMC,sBAAsB,kBAAiB;AAUpD,OAAO,MAAMC,wBAAwBF;IAKnC,YACEG,OASC,EACDC,CAAa,CACb;QACA,MAAMC,UAAUD,IACZA,EAAE,gCAAgC;YAAEE,OAAOH,QAAQI,MAAM,CAACC,MAAM;QAAC,KACjEL,QAAQI,MAAM,CAACC,MAAM,KAAK,IACxBX,GAAGY,YAAY,CAACC,KAAK,CAACC,0BAA0B,GAChDd,GAAGY,YAAY,CAACC,KAAK,CAACE,4BAA4B;QAExD,MAAMC,MAAMV,QAAQU,GAAG;QACvB,wCAAwC;QACxC,OAAOV,OAAO,CAAC,MAAM;QAErB,KAAK,CACH,GAAGE,QAAQ,CAAC,EAAEF,QAAQI,MAAM,CACzBO,GAAG,CAAC,CAACC;YACJ,IAAIA,EAAEC,KAAK,EAAE;gBACX,IAAI,OAAOD,EAAEC,KAAK,KAAK,YAAY;oBACjC,IAAI,CAACH,OAAO,CAACA,IAAII,IAAI,IAAI,CAACJ,IAAIT,CAAC,EAAE;wBAC/B,OAAOW,EAAEG,IAAI;oBACf;oBAEA,OAAOH,EAAEC,KAAK,CAAC;wBAAEC,MAAMJ,IAAII,IAAI;wBAAEb,GAAGS,IAAIT,CAAC;oBAAC;gBAC5C;gBAEA,IAAI,OAAOW,EAAEC,KAAK,KAAK,UAAU;oBAC/B,IAAIH,KAAKI,MAAME,UAAU;wBACvB,OAAOJ,EAAEC,KAAK,CAACH,IAAII,IAAI,CAACE,QAAQ,CAAC;oBACnC;oBAEA,OAAOJ,EAAEC,KAAK,CAACI,OAAOC,IAAI,CAACN,EAAEC,KAAK,CAAC,CAAC,EAAE,CAAE;gBAC1C;gBAEA,OAAOD,EAAEC,KAAK;YAChB;YAEA,OAAOD,EAAEG,IAAI;QACf,GACCI,IAAI,CAAC,OAAO,EACfvB,WAAWwB,WAAW,EACtBpB;
|
|
1
|
+
{"version":3,"sources":["../../src/errors/ValidationError.ts"],"sourcesContent":["import type { TFunction } from '@payloadcms/translations'\n\nimport { en } from '@payloadcms/translations/languages/en'\nimport { status as httpStatus } from 'http-status'\n\nimport type { LabelFunction, StaticLabel } from '../config/types.js'\nimport type { PayloadRequest } from '../types/index.js'\n\nimport { APIError } from './APIError.js'\n\n/** @deprecated Use `instanceof ValidationError` instead of name comparison. */\nexport const ValidationErrorName = 'ValidationError'\n\nexport type ValidationFieldError = {\n label?: LabelFunction | StaticLabel\n // The error message to display for this field\n message: string\n path: string\n tableName?: string\n}\n\nexport class ValidationError extends APIError<{\n collection?: string\n errors: ValidationFieldError[]\n global?: string\n}> {\n constructor(\n results: {\n collection?: string\n errors: ValidationFieldError[]\n global?: string\n id?: number | string\n /**\n * req needs to be passed through (if you have one) in order to resolve label functions that may be part of the errors array\n */\n req?: Partial<PayloadRequest>\n },\n t?: TFunction,\n ) {\n const message = t\n ? t('error:followingFieldsInvalid', { count: results.errors.length })\n : results.errors.length === 1\n ? en.translations.error.followingFieldsInvalid_one\n : en.translations.error.followingFieldsInvalid_other\n\n const req = results.req\n // delete to avoid logging the whole req\n delete results['req']\n\n super(\n `${message} ${results.errors\n .map((f) => {\n if (f.label) {\n if (typeof f.label === 'function') {\n if (!req || !req.i18n || !req.t) {\n return f.path\n }\n\n return f.label({ i18n: req.i18n, t: req.t })\n }\n\n if (typeof f.label === 'object') {\n if (req?.i18n?.language) {\n return f.label[req.i18n.language]\n }\n\n return f.label[Object.keys(f.label)[0]!]\n }\n\n return f.label\n }\n\n return f.path\n })\n .join(', ')}`,\n httpStatus.BAD_REQUEST,\n results,\n )\n this.name = 'ValidationError'\n }\n}\n"],"names":["en","status","httpStatus","APIError","ValidationErrorName","ValidationError","results","t","message","count","errors","length","translations","error","followingFieldsInvalid_one","followingFieldsInvalid_other","req","map","f","label","i18n","path","language","Object","keys","join","BAD_REQUEST","name"],"mappings":"AAEA,SAASA,EAAE,QAAQ,wCAAuC;AAC1D,SAASC,UAAUC,UAAU,QAAQ,cAAa;AAKlD,SAASC,QAAQ,QAAQ,gBAAe;AAExC,6EAA6E,GAC7E,OAAO,MAAMC,sBAAsB,kBAAiB;AAUpD,OAAO,MAAMC,wBAAwBF;IAKnC,YACEG,OASC,EACDC,CAAa,CACb;QACA,MAAMC,UAAUD,IACZA,EAAE,gCAAgC;YAAEE,OAAOH,QAAQI,MAAM,CAACC,MAAM;QAAC,KACjEL,QAAQI,MAAM,CAACC,MAAM,KAAK,IACxBX,GAAGY,YAAY,CAACC,KAAK,CAACC,0BAA0B,GAChDd,GAAGY,YAAY,CAACC,KAAK,CAACE,4BAA4B;QAExD,MAAMC,MAAMV,QAAQU,GAAG;QACvB,wCAAwC;QACxC,OAAOV,OAAO,CAAC,MAAM;QAErB,KAAK,CACH,GAAGE,QAAQ,CAAC,EAAEF,QAAQI,MAAM,CACzBO,GAAG,CAAC,CAACC;YACJ,IAAIA,EAAEC,KAAK,EAAE;gBACX,IAAI,OAAOD,EAAEC,KAAK,KAAK,YAAY;oBACjC,IAAI,CAACH,OAAO,CAACA,IAAII,IAAI,IAAI,CAACJ,IAAIT,CAAC,EAAE;wBAC/B,OAAOW,EAAEG,IAAI;oBACf;oBAEA,OAAOH,EAAEC,KAAK,CAAC;wBAAEC,MAAMJ,IAAII,IAAI;wBAAEb,GAAGS,IAAIT,CAAC;oBAAC;gBAC5C;gBAEA,IAAI,OAAOW,EAAEC,KAAK,KAAK,UAAU;oBAC/B,IAAIH,KAAKI,MAAME,UAAU;wBACvB,OAAOJ,EAAEC,KAAK,CAACH,IAAII,IAAI,CAACE,QAAQ,CAAC;oBACnC;oBAEA,OAAOJ,EAAEC,KAAK,CAACI,OAAOC,IAAI,CAACN,EAAEC,KAAK,CAAC,CAAC,EAAE,CAAE;gBAC1C;gBAEA,OAAOD,EAAEC,KAAK;YAChB;YAEA,OAAOD,EAAEG,IAAI;QACf,GACCI,IAAI,CAAC,OAAO,EACfvB,WAAWwB,WAAW,EACtBpB;QAEF,IAAI,CAACqB,IAAI,GAAG;IACd;AACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Payload } from '../../../index.js';
|
|
2
|
+
import type { JsonObject } from '../../../types/index.js';
|
|
3
|
+
import type { Field, TabAsField } from '../../config/types.js';
|
|
4
|
+
type Args = {
|
|
5
|
+
config: Payload['config'];
|
|
6
|
+
data: JsonObject;
|
|
7
|
+
fields: (Field | TabAsField)[];
|
|
8
|
+
locale: string;
|
|
9
|
+
parentIsLocalized?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/** Projects validation context to one locale without running hooks or changing the write data. */
|
|
12
|
+
export declare function flattenValidationData({ config, data, fields, locale, parentIsLocalized, }: Args): JsonObject;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=flattenValidationData.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flattenValidationData.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/flattenValidationData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAM9D,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAA;IACzB,IAAI,EAAE,UAAU,CAAA;IAChB,MAAM,EAAE,CAAC,KAAK,GAAG,UAAU,CAAC,EAAE,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B,CAAA;AAED,kGAAkG;AAClG,wBAAgB,qBAAqB,CAAC,EACpC,MAAM,EACN,IAAI,EACJ,MAAM,EACN,MAAM,EACN,iBAAyB,GAC1B,EAAE,IAAI,GAAG,UAAU,CAgCnB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js';
|
|
2
|
+
import { traverseFields } from '../../../utilities/traverseFields.js';
|
|
3
|
+
import { fieldAffectsData, fieldShouldBeLocalized } from '../../config/types.js';
|
|
4
|
+
/** Projects validation context to one locale without running hooks or changing the write data. */ export function flattenValidationData({ config, data, fields, locale, parentIsLocalized = false }) {
|
|
5
|
+
// Each locale needs its own projection. Merged contexts also retain source array references.
|
|
6
|
+
const result = deepCopyObjectSimple(data);
|
|
7
|
+
const localizedFields = [];
|
|
8
|
+
traverseFields({
|
|
9
|
+
callback: ({ field, parentIsLocalized, ref })=>{
|
|
10
|
+
if (fieldAffectsData(field) && field.name && fieldShouldBeLocalized({
|
|
11
|
+
field,
|
|
12
|
+
parentIsLocalized
|
|
13
|
+
})) {
|
|
14
|
+
localizedFields.push({
|
|
15
|
+
name: field.name,
|
|
16
|
+
ref: ref
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
config,
|
|
21
|
+
fields,
|
|
22
|
+
fillEmpty: false,
|
|
23
|
+
parentIsLocalized,
|
|
24
|
+
ref: result
|
|
25
|
+
});
|
|
26
|
+
// Keep locale maps intact while traversing, then project children before their containers.
|
|
27
|
+
for (const { name, ref } of localizedFields.reverse()){
|
|
28
|
+
const value = ref[name];
|
|
29
|
+
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
30
|
+
ref[name] = value[locale];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=flattenValidationData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/beforeChange/flattenValidationData.ts"],"sourcesContent":["import type { Payload } from '../../../index.js'\nimport type { JsonObject } from '../../../types/index.js'\nimport type { Field, TabAsField } from '../../config/types.js'\n\nimport { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js'\nimport { traverseFields } from '../../../utilities/traverseFields.js'\nimport { fieldAffectsData, fieldShouldBeLocalized } from '../../config/types.js'\n\ntype Args = {\n config: Payload['config']\n data: JsonObject\n fields: (Field | TabAsField)[]\n locale: string\n parentIsLocalized?: boolean\n}\n\n/** Projects validation context to one locale without running hooks or changing the write data. */\nexport function flattenValidationData({\n config,\n data,\n fields,\n locale,\n parentIsLocalized = false,\n}: Args): JsonObject {\n // Each locale needs its own projection. Merged contexts also retain source array references.\n const result = deepCopyObjectSimple(data)\n const localizedFields: { name: string; ref: JsonObject }[] = []\n\n traverseFields({\n callback: ({ field, parentIsLocalized, ref }) => {\n if (\n fieldAffectsData(field) &&\n field.name &&\n fieldShouldBeLocalized({ field, parentIsLocalized })\n ) {\n localizedFields.push({ name: field.name, ref: ref as JsonObject })\n }\n },\n config,\n fields,\n fillEmpty: false,\n parentIsLocalized,\n ref: result,\n })\n\n // Keep locale maps intact while traversing, then project children before their containers.\n for (const { name, ref } of localizedFields.reverse()) {\n const value = ref[name]\n\n if (value !== null && typeof value === 'object' && !Array.isArray(value)) {\n ref[name] = value[locale]\n }\n }\n\n return result\n}\n"],"names":["deepCopyObjectSimple","traverseFields","fieldAffectsData","fieldShouldBeLocalized","flattenValidationData","config","data","fields","locale","parentIsLocalized","result","localizedFields","callback","field","ref","name","push","fillEmpty","reverse","value","Array","isArray"],"mappings":"AAIA,SAASA,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,gBAAgB,EAAEC,sBAAsB,QAAQ,wBAAuB;AAUhF,gGAAgG,GAChG,OAAO,SAASC,sBAAsB,EACpCC,MAAM,EACNC,IAAI,EACJC,MAAM,EACNC,MAAM,EACNC,oBAAoB,KAAK,EACpB;IACL,6FAA6F;IAC7F,MAAMC,SAASV,qBAAqBM;IACpC,MAAMK,kBAAuD,EAAE;IAE/DV,eAAe;QACbW,UAAU,CAAC,EAAEC,KAAK,EAAEJ,iBAAiB,EAAEK,GAAG,EAAE;YAC1C,IACEZ,iBAAiBW,UACjBA,MAAME,IAAI,IACVZ,uBAAuB;gBAAEU;gBAAOJ;YAAkB,IAClD;gBACAE,gBAAgBK,IAAI,CAAC;oBAAED,MAAMF,MAAME,IAAI;oBAAED,KAAKA;gBAAkB;YAClE;QACF;QACAT;QACAE;QACAU,WAAW;QACXR;QACAK,KAAKJ;IACP;IAEA,2FAA2F;IAC3F,KAAK,MAAM,EAAEK,IAAI,EAAED,GAAG,EAAE,IAAIH,gBAAgBO,OAAO,GAAI;QACrD,MAAMC,QAAQL,GAAG,CAACC,KAAK;QAEvB,IAAII,UAAU,QAAQ,OAAOA,UAAU,YAAY,CAACC,MAAMC,OAAO,CAACF,QAAQ;YACxEL,GAAG,CAACC,KAAK,GAAGI,KAAK,CAACX,OAAO;QAC3B;IACF;IAEA,OAAOE;AACT"}
|
|
@@ -9,6 +9,7 @@ type Args = {
|
|
|
9
9
|
* Data of the nearest parent block. If no parent block exists, this will be the `undefined`
|
|
10
10
|
*/
|
|
11
11
|
blockData?: JsonObject;
|
|
12
|
+
blockFields?: Field[];
|
|
12
13
|
collection: null | SanitizedCollectionConfig;
|
|
13
14
|
context: RequestContext;
|
|
14
15
|
data: JsonObject;
|
|
@@ -40,6 +41,6 @@ type Args = {
|
|
|
40
41
|
skipValidation: boolean;
|
|
41
42
|
submittedTopLevelFieldNames?: ReadonlySet<string>;
|
|
42
43
|
};
|
|
43
|
-
export declare const promise: ({ id, blockData, collection, context, data, doc, docWithLocales, errors, field, fieldIndex, fieldLabelPath, global, mergeLocaleActions, operation, overrideAccess, parentIndexPath, parentIsLocalized, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, siblingFields, skipValidation, submittedTopLevelFieldNames, }: Args) => Promise<void>;
|
|
44
|
+
export declare const promise: ({ id, blockData, blockFields, collection, context, data, doc, docWithLocales, errors, field, fieldIndex, fieldLabelPath, global, mergeLocaleActions, operation, overrideAccess, parentIndexPath, parentIsLocalized, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, siblingFields, skipValidation, submittedTopLevelFieldNames, }: Args) => Promise<void>;
|
|
44
45
|
export {};
|
|
45
46
|
//# sourceMappingURL=promise.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/promise.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AACpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACpF,OAAO,KAAK,EAAS,KAAK,EAAE,UAAU,EAAY,MAAM,uBAAuB,CAAA;AAG/E,OAAO,EAAE,KAAK,cAAc,EAA+B,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/promise.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AACpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACpF,OAAO,KAAK,EAAS,KAAK,EAAE,UAAU,EAAY,MAAM,uBAAuB,CAAA;AAG/E,OAAO,EAAE,KAAK,cAAc,EAA+B,MAAM,mBAAmB,CAAA;AAoBpF,KAAK,IAAI,GAAG;IACV;;OAEG;IACH,SAAS,CAAC,EAAE,UAAU,CAAA;IACtB,WAAW,CAAC,EAAE,KAAK,EAAE,CAAA;IACrB,UAAU,EAAE,IAAI,GAAG,yBAAyB,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,UAAU,CAAA;IAChB,GAAG,EAAE,UAAU,CAAA;IACf,cAAc,EAAE,UAAU,CAAA;IAC1B,MAAM,EAAE,oBAAoB,EAAE,CAAA;IAC9B,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB,UAAU,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,IAAI,GAAG,qBAAqB,CAAA;IACpC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,kBAAkB,EAAE,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,CAAA;IAClD,SAAS,EAAE,SAAS,CAAA;IACpB,cAAc,EAAE,OAAO,CAAA;IACvB,eAAe,EAAE,MAAM,CAAA;IACvB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,UAAU,EAAE,MAAM,CAAA;IAClB,gBAAgB,EAAE,MAAM,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;IACnB,WAAW,EAAE,UAAU,CAAA;IACvB,UAAU,EAAE,UAAU,CAAA;IACtB,qBAAqB,CAAC,EAAE,UAAU,CAAA;IAClC,aAAa,CAAC,EAAE,CAAC,KAAK,GAAG,UAAU,CAAC,EAAE,CAAA;IACtC,cAAc,EAAE,OAAO,CAAA;IACvB,2BAA2B,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAClD,CAAA;AAUD,eAAO,MAAM,OAAO,yWA4BjB,IAAI,KAAG,OAAO,CAAC,IAAI,CAisBrB,CAAA"}
|
|
@@ -2,8 +2,10 @@ import { MissingEditorProp } from '../../../errors/index.js';
|
|
|
2
2
|
import { validateBlocksFilterOptions } from '../../../index.js';
|
|
3
3
|
import { deepMergeWithSourceArrays } from '../../../utilities/deepMerge.js';
|
|
4
4
|
import { getTranslatedLabel } from '../../../utilities/getTranslatedLabel.js';
|
|
5
|
+
import { isolateObjectProperty } from '../../../utilities/isolateObjectProperty.js';
|
|
5
6
|
import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../../config/types.js';
|
|
6
7
|
import { getFieldPaths } from '../../getFieldPaths.js';
|
|
8
|
+
import { flattenValidationData } from './flattenValidationData.js';
|
|
7
9
|
import { getExistingRowDoc } from './getExistingRowDoc.js';
|
|
8
10
|
import { traverseFields } from './traverseFields.js';
|
|
9
11
|
function buildFieldLabel(parentLabel, label) {
|
|
@@ -20,7 +22,7 @@ function buildFieldLabel(parentLabel, label) {
|
|
|
20
22
|
// - Transform data for storage
|
|
21
23
|
// - beforeDuplicate hooks (if duplicate)
|
|
22
24
|
// - Unflatten locales
|
|
23
|
-
export const promise = async ({ id, blockData, collection, context, data, doc, docWithLocales, errors, field, fieldIndex, fieldLabelPath, global, mergeLocaleActions, operation, overrideAccess, parentIndexPath, parentIsLocalized, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, siblingFields, skipValidation, submittedTopLevelFieldNames })=>{
|
|
25
|
+
export const promise = async ({ id, blockData, blockFields, collection, context, data, doc, docWithLocales, errors, field, fieldIndex, fieldLabelPath, global, mergeLocaleActions, operation, overrideAccess, parentIndexPath, parentIsLocalized, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, siblingFields, skipValidation, submittedTopLevelFieldNames })=>{
|
|
24
26
|
const { indexPath, path, schemaPath } = getFieldPaths({
|
|
25
27
|
field,
|
|
26
28
|
index: fieldIndex,
|
|
@@ -97,6 +99,26 @@ export const promise = async ({ id, blockData, collection, context, data, doc, d
|
|
|
97
99
|
// Validate
|
|
98
100
|
if (!skipValidationFromHere && 'validate' in field && field.validate) {
|
|
99
101
|
const valueToValidate = siblingData[field.name];
|
|
102
|
+
// With `locale: 'all'` a localized scalar is a locale-keyed object; validate each locale, not the
|
|
103
|
+
// wrapper. Containers (`group`/`array`/`blocks`) are excluded - per-locale child validation is a follow-up.
|
|
104
|
+
const isLocaleKeyedValue = operationLocale === 'all' && localization && fieldShouldBeLocalized({
|
|
105
|
+
field,
|
|
106
|
+
parentIsLocalized
|
|
107
|
+
}) && field.type !== 'group' && valueToValidate !== null && typeof valueToValidate === 'object' && !Array.isArray(valueToValidate);
|
|
108
|
+
const localizedValuesToValidate = isLocaleKeyedValue ? localization.localeCodes.filter((locale)=>locale in valueToValidate).map((locale)=>({
|
|
109
|
+
locale,
|
|
110
|
+
value: valueToValidate[locale]
|
|
111
|
+
})) : [
|
|
112
|
+
{
|
|
113
|
+
value: valueToValidate
|
|
114
|
+
}
|
|
115
|
+
];
|
|
116
|
+
// No recognized locales (e.g. `{}`): validate `undefined` once so required/optional still apply.
|
|
117
|
+
if (localizedValuesToValidate.length === 0) {
|
|
118
|
+
localizedValuesToValidate.push({
|
|
119
|
+
value: undefined
|
|
120
|
+
});
|
|
121
|
+
}
|
|
100
122
|
let jsonError;
|
|
101
123
|
if (field.type === 'json' && typeof siblingData[field.name] === 'string') {
|
|
102
124
|
try {
|
|
@@ -106,25 +128,66 @@ export const promise = async ({ id, blockData, collection, context, data, doc, d
|
|
|
106
128
|
}
|
|
107
129
|
}
|
|
108
130
|
const validateFn = field.validate;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
131
|
+
let validationResult = true;
|
|
132
|
+
let failedLocale;
|
|
133
|
+
const validationData = deepMergeWithSourceArrays(doc, data);
|
|
134
|
+
const validationSiblingData = deepMergeWithSourceArrays(siblingDoc, siblingData);
|
|
135
|
+
for (const { locale, value } of localizedValuesToValidate){
|
|
136
|
+
// Scope `req.locale` to the current locale via a proxy, without mutating the shared request.
|
|
137
|
+
const validationReq = locale ? isolateObjectProperty(req, 'locale') : req;
|
|
138
|
+
if (locale) {
|
|
139
|
+
validationReq.locale = locale;
|
|
140
|
+
}
|
|
141
|
+
const localeContext = locale ? {
|
|
142
|
+
blockData: blockData && blockFields ? flattenValidationData({
|
|
143
|
+
config: req.payload.config,
|
|
144
|
+
data: blockData,
|
|
145
|
+
fields: blockFields,
|
|
146
|
+
locale,
|
|
147
|
+
parentIsLocalized
|
|
148
|
+
}) : blockData,
|
|
149
|
+
data: flattenValidationData({
|
|
150
|
+
config: req.payload.config,
|
|
151
|
+
data: validationData,
|
|
152
|
+
fields: collection?.fields || global?.fields,
|
|
153
|
+
locale
|
|
154
|
+
}),
|
|
155
|
+
siblingData: flattenValidationData({
|
|
156
|
+
config: req.payload.config,
|
|
157
|
+
data: validationSiblingData,
|
|
158
|
+
fields: siblingFields,
|
|
159
|
+
locale,
|
|
160
|
+
parentIsLocalized
|
|
161
|
+
})
|
|
162
|
+
} : {
|
|
163
|
+
blockData,
|
|
164
|
+
data: validationData,
|
|
165
|
+
siblingData: validationSiblingData
|
|
166
|
+
};
|
|
167
|
+
validationResult = await validateFn(value, {
|
|
168
|
+
...field,
|
|
169
|
+
id,
|
|
170
|
+
blockData: localeContext.blockData,
|
|
171
|
+
collectionSlug: collection?.slug,
|
|
172
|
+
data: localeContext.data,
|
|
173
|
+
event: 'submit',
|
|
174
|
+
// @ts-expect-error generic validation options cannot infer JSON fields
|
|
175
|
+
jsonError,
|
|
176
|
+
operation,
|
|
177
|
+
overrideAccess,
|
|
178
|
+
path: pathSegments,
|
|
179
|
+
preferences: {
|
|
180
|
+
fields: {}
|
|
181
|
+
},
|
|
182
|
+
previousValue: locale ? siblingDoc[field.name]?.[locale] : siblingDoc[field.name],
|
|
183
|
+
req: validationReq,
|
|
184
|
+
siblingData: localeContext.siblingData
|
|
185
|
+
});
|
|
186
|
+
if (typeof validationResult === 'string') {
|
|
187
|
+
failedLocale = locale;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
128
191
|
if (typeof validationResult === 'string') {
|
|
129
192
|
let filterOptionsError = false;
|
|
130
193
|
if (field.type === 'blocks' && field.filterOptions) {
|
|
@@ -163,7 +226,7 @@ export const promise = async ({ id, blockData, collection, context, data, doc, d
|
|
|
163
226
|
// field itself => only push the error if the field is not a block field with validation failure due to filterOptions
|
|
164
227
|
const fieldLabel = buildFieldLabel(fieldLabelPath, getTranslatedLabel(field?.label || field?.name, req.i18n));
|
|
165
228
|
errors.push({
|
|
166
|
-
label: fieldLabel,
|
|
229
|
+
label: failedLocale ? `${fieldLabel} (${failedLocale})` : fieldLabel,
|
|
167
230
|
message: validationResult,
|
|
168
231
|
path
|
|
169
232
|
});
|
|
@@ -177,8 +240,13 @@ export const promise = async ({ id, blockData, collection, context, data, doc, d
|
|
|
177
240
|
})) {
|
|
178
241
|
mergeLocaleActions.push(()=>{
|
|
179
242
|
const localeData = {};
|
|
243
|
+
// With `locale: 'all'`, siblingData holds a locale-keyed object (`{ en, es }`) rather than a single
|
|
244
|
+
// locale's value - take each submitted locale, falling back to the existing doc for ones not sent.
|
|
245
|
+
const submittedValue = siblingData[field.name];
|
|
246
|
+
const isAllLocales = req.locale === 'all' && submittedValue !== null && typeof submittedValue === 'object' && !Array.isArray(submittedValue);
|
|
180
247
|
for (const locale of localization.localeCodes){
|
|
181
|
-
const
|
|
248
|
+
const existingValue = siblingDocWithLocales?.[field.name]?.[locale];
|
|
249
|
+
const fieldValue = isAllLocales ? locale in submittedValue ? submittedValue[locale] : existingValue : locale === req.locale ? submittedValue : existingValue;
|
|
182
250
|
// update locale value if it's not undefined
|
|
183
251
|
if (typeof fieldValue !== 'undefined') {
|
|
184
252
|
localeData[locale] = fieldValue;
|
|
@@ -201,6 +269,7 @@ export const promise = async ({ id, blockData, collection, context, data, doc, d
|
|
|
201
269
|
promises.push(traverseFields({
|
|
202
270
|
id,
|
|
203
271
|
blockData,
|
|
272
|
+
blockFields,
|
|
204
273
|
collection,
|
|
205
274
|
context,
|
|
206
275
|
data,
|
|
@@ -244,6 +313,7 @@ export const promise = async ({ id, blockData, collection, context, data, doc, d
|
|
|
244
313
|
promises.push(traverseFields({
|
|
245
314
|
id,
|
|
246
315
|
blockData: row,
|
|
316
|
+
blockFields: block.fields,
|
|
247
317
|
collection,
|
|
248
318
|
context,
|
|
249
319
|
data,
|
|
@@ -279,6 +349,7 @@ export const promise = async ({ id, blockData, collection, context, data, doc, d
|
|
|
279
349
|
await traverseFields({
|
|
280
350
|
id,
|
|
281
351
|
blockData,
|
|
352
|
+
blockFields,
|
|
282
353
|
collection,
|
|
283
354
|
context,
|
|
284
355
|
data,
|
|
@@ -337,6 +408,7 @@ export const promise = async ({ id, blockData, collection, context, data, doc, d
|
|
|
337
408
|
await traverseFields({
|
|
338
409
|
id,
|
|
339
410
|
blockData,
|
|
411
|
+
blockFields,
|
|
340
412
|
collection,
|
|
341
413
|
context,
|
|
342
414
|
data,
|
|
@@ -443,6 +515,7 @@ export const promise = async ({ id, blockData, collection, context, data, doc, d
|
|
|
443
515
|
await traverseFields({
|
|
444
516
|
id,
|
|
445
517
|
blockData,
|
|
518
|
+
blockFields,
|
|
446
519
|
collection,
|
|
447
520
|
context,
|
|
448
521
|
data,
|
|
@@ -473,6 +546,7 @@ export const promise = async ({ id, blockData, collection, context, data, doc, d
|
|
|
473
546
|
await traverseFields({
|
|
474
547
|
id,
|
|
475
548
|
blockData,
|
|
549
|
+
blockFields,
|
|
476
550
|
collection,
|
|
477
551
|
context,
|
|
478
552
|
data,
|