payload 3.56.0-canary.3 → 3.56.0-internal.457de85
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/forms/Form.d.ts +0 -8
- package/dist/admin/forms/Form.d.ts.map +1 -1
- package/dist/admin/forms/Form.js.map +1 -1
- package/dist/collections/endpoints/findByID.d.ts.map +1 -1
- package/dist/collections/endpoints/findByID.js +2 -0
- package/dist/collections/endpoints/findByID.js.map +1 -1
- package/dist/collections/operations/findByID.d.ts +5 -4
- package/dist/collections/operations/findByID.d.ts.map +1 -1
- package/dist/collections/operations/findByID.js +2 -1
- package/dist/collections/operations/findByID.js.map +1 -1
- package/dist/collections/operations/local/findByID.d.ts +2 -1
- package/dist/collections/operations/local/findByID.d.ts.map +1 -1
- package/dist/collections/operations/local/findByID.js +2 -1
- package/dist/collections/operations/local/findByID.js.map +1 -1
- package/dist/config/client.d.ts +3 -9
- package/dist/config/client.d.ts.map +1 -1
- package/dist/config/client.js +1 -7
- package/dist/config/client.js.map +1 -1
- package/dist/fields/hooks/afterRead/index.d.ts +8 -3
- package/dist/fields/hooks/afterRead/index.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/index.js.map +1 -1
- package/dist/fields/hooks/afterRead/promise.d.ts +2 -2
- package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/promise.js +9 -8
- package/dist/fields/hooks/afterRead/promise.js.map +1 -1
- package/dist/globals/endpoints/findOne.d.ts.map +1 -1
- package/dist/globals/endpoints/findOne.js +2 -0
- package/dist/globals/endpoints/findOne.js.map +1 -1
- package/dist/globals/operations/findOne.d.ts +5 -5
- package/dist/globals/operations/findOne.d.ts.map +1 -1
- package/dist/globals/operations/findOne.js +2 -1
- package/dist/globals/operations/findOne.js.map +1 -1
- package/dist/globals/operations/local/findOne.d.ts +2 -1
- package/dist/globals/operations/local/findOne.d.ts.map +1 -1
- package/dist/globals/operations/local/findOne.js +2 -1
- package/dist/globals/operations/local/findOne.js.map +1 -1
- package/package.json +2 -2
|
@@ -120,14 +120,6 @@ export type BuildFormStateArgs = {
|
|
|
120
120
|
returnLockStatus?: boolean;
|
|
121
121
|
schemaPath: string;
|
|
122
122
|
select?: SelectType;
|
|
123
|
-
/**
|
|
124
|
-
* When true, sets `user: true` when calling `getClientConfig`.
|
|
125
|
-
* This will retrieve the client config in its entirety, even when unauthenticated.
|
|
126
|
-
* For example, the create-first-user view needs the entire config, but there is no user yet.
|
|
127
|
-
*
|
|
128
|
-
* @experimental This property is experimental and may change in the future. Use at your own discretion.
|
|
129
|
-
*/
|
|
130
|
-
skipClientConfigAuth?: boolean;
|
|
131
123
|
skipValidation?: boolean;
|
|
132
124
|
updateLastEdited?: boolean;
|
|
133
125
|
} & ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../src/admin/forms/Form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAElE,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAA;AACvE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAE7E,MAAM,MAAM,IAAI,GAAG;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,GAAG,GAAG;IAChB,aAAa,CAAC,EAAE,UAAU,CAAC,eAAe,CAAC,CAAA;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,O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E,MAAM,GAAG,2BAA2B,CAAA;CAC5C,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,cAAc,EAAE,4BAA4B,GAAG,SAAS,CAAA;IACxD,cAAc,EAAE,mBAAmB,CAAA;IACnC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,SAAS,CAAA;IAC7B,cAAc,CAAC,EAAE,KAAK,GAAG,WAAW,CAAA;IACpC,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,gBAAgB,CAAC,EAAE,IAAI,CAAA;IACvB,qBAAqB,CAAC,EAAE,SAAS,CAAA;IAIjC,QAAQ,CAAC,EAAE,MAAM,kBAAkB,CAAA;IACnC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,SAAS,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,GAAG,EAAE,cAAc,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,GAAG,CACA;IACE,cAAc,EAAE,MAAM,CAAA;IAGtB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,GACD;IACE,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;CACnB,CACJ,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/admin/forms/Form.ts"],"sourcesContent":["import { type SupportedLanguages } from '@payloadcms/translations'\n\nimport type { SanitizedDocumentPermissions } from '../../auth/types.js'\nimport type { Field, Option, Validate } from '../../fields/config/types.js'\nimport type { TypedLocale } from '../../index.js'\nimport type { DocumentPreferences } from '../../preferences/types.js'\nimport type { PayloadRequest, SelectType, Where } from '../../types/index.js'\n\nexport type Data = {\n [key: string]: any\n}\n\nexport type Row = {\n addedByServer?: FieldState['addedByServer']\n blockType?: string\n collapsed?: boolean\n customComponents?: {\n RowLabel?: React.ReactNode\n }\n id: string\n isLoading?: boolean\n lastRenderedPath?: string\n}\n\nexport type FilterOptionsResult = {\n [relation: string]: boolean | Where\n}\n\nexport type FieldState = {\n /**\n * This is used to determine if the field was added by the server.\n * This ensures the field is not ignored by the client when merging form state.\n * This can happen because the current local state is treated as the source of truth.\n * See `mergeServerFormState` for more details.\n */\n addedByServer?: boolean\n customComponents?: {\n /**\n * This is used by UI fields, as they can have arbitrary components defined if used\n * as a vessel to bring in custom components.\n */\n [key: string]: React.ReactNode | React.ReactNode[] | undefined\n AfterInput?: React.ReactNode\n BeforeInput?: React.ReactNode\n Description?: React.ReactNode\n Error?: React.ReactNode\n Field?: React.ReactNode\n Label?: React.ReactNode\n }\n disableFormData?: boolean\n errorMessage?: string\n errorPaths?: string[]\n /**\n * The fieldSchema may be part of the form state if `includeSchema: true` is passed to buildFormState.\n * This will never be in the form state of the client.\n */\n fieldSchema?: Field\n filterOptions?: FilterOptionsResult\n initialValue?: unknown\n /**\n * Every time a field is changed locally, this flag is set to true. Prevents form state from server from overwriting local changes.\n * After merging server form state, this flag is reset.\n *\n * @experimental This property is experimental and may change in the future. Use at your own discretion.\n */\n isModified?: boolean\n /**\n * The path of the field when its custom components were last rendered.\n * This is used to denote if a field has been rendered, and if so,\n * what path it was rendered under last.\n *\n * If this path is undefined, or, if it is different\n * from the current path of a given field, the field's components will be re-rendered.\n */\n lastRenderedPath?: string\n passesCondition?: boolean\n rows?: Row[]\n /**\n * The result of running `field.filterOptions` on select fields.\n */\n selectFilterOptions?: Option[]\n valid?: boolean\n validate?: Validate\n value?: unknown\n}\n\nexport type FieldStateWithoutComponents = Omit<FieldState, 'customComponents'>\n\nexport type FormState = {\n [path: string]: FieldState\n}\n\nexport type FormStateWithoutComponents = {\n [path: string]: FieldStateWithoutComponents\n}\n\nexport type BuildFormStateArgs = {\n data?: Data\n docPermissions: SanitizedDocumentPermissions | undefined\n docPreferences: DocumentPreferences\n /**\n * In case `formState` is not the top-level, document form state, this can be passed to\n * provide the top-level form state.\n */\n documentFormState?: FormState\n fallbackLocale?: false | TypedLocale\n formState?: FormState\n id?: number | string\n initialBlockData?: Data\n initialBlockFormState?: FormState\n /*\n If not i18n was passed, the language can be passed to init i18n\n */\n language?: keyof SupportedLanguages\n locale?: string\n /**\n * If true, will not render RSCs and instead return a simple string in their place.\n * This is useful for environments that lack RSC support, such as Jest.\n * Form state can still be built, but any server components will be omitted.\n * @default false\n */\n mockRSCs?: boolean\n operation?: 'create' | 'update'\n readOnly?: boolean\n /**\n * If true, will render field components within their state object.\n * Performance optimization: Setting to `false` ensures that only fields that have changed paths will re-render, e.g. new array rows, etc.\n * For example, you only need to render ALL fields on initial render, not on every onChange.\n */\n renderAllFields?: boolean\n req: PayloadRequest\n returnLockStatus?: boolean\n schemaPath: string\n select?: SelectType\n
|
|
1
|
+
{"version":3,"sources":["../../../src/admin/forms/Form.ts"],"sourcesContent":["import { type SupportedLanguages } from '@payloadcms/translations'\n\nimport type { SanitizedDocumentPermissions } from '../../auth/types.js'\nimport type { Field, Option, Validate } from '../../fields/config/types.js'\nimport type { TypedLocale } from '../../index.js'\nimport type { DocumentPreferences } from '../../preferences/types.js'\nimport type { PayloadRequest, SelectType, Where } from '../../types/index.js'\n\nexport type Data = {\n [key: string]: any\n}\n\nexport type Row = {\n addedByServer?: FieldState['addedByServer']\n blockType?: string\n collapsed?: boolean\n customComponents?: {\n RowLabel?: React.ReactNode\n }\n id: string\n isLoading?: boolean\n lastRenderedPath?: string\n}\n\nexport type FilterOptionsResult = {\n [relation: string]: boolean | Where\n}\n\nexport type FieldState = {\n /**\n * This is used to determine if the field was added by the server.\n * This ensures the field is not ignored by the client when merging form state.\n * This can happen because the current local state is treated as the source of truth.\n * See `mergeServerFormState` for more details.\n */\n addedByServer?: boolean\n customComponents?: {\n /**\n * This is used by UI fields, as they can have arbitrary components defined if used\n * as a vessel to bring in custom components.\n */\n [key: string]: React.ReactNode | React.ReactNode[] | undefined\n AfterInput?: React.ReactNode\n BeforeInput?: React.ReactNode\n Description?: React.ReactNode\n Error?: React.ReactNode\n Field?: React.ReactNode\n Label?: React.ReactNode\n }\n disableFormData?: boolean\n errorMessage?: string\n errorPaths?: string[]\n /**\n * The fieldSchema may be part of the form state if `includeSchema: true` is passed to buildFormState.\n * This will never be in the form state of the client.\n */\n fieldSchema?: Field\n filterOptions?: FilterOptionsResult\n initialValue?: unknown\n /**\n * Every time a field is changed locally, this flag is set to true. Prevents form state from server from overwriting local changes.\n * After merging server form state, this flag is reset.\n *\n * @experimental This property is experimental and may change in the future. Use at your own discretion.\n */\n isModified?: boolean\n /**\n * The path of the field when its custom components were last rendered.\n * This is used to denote if a field has been rendered, and if so,\n * what path it was rendered under last.\n *\n * If this path is undefined, or, if it is different\n * from the current path of a given field, the field's components will be re-rendered.\n */\n lastRenderedPath?: string\n passesCondition?: boolean\n rows?: Row[]\n /**\n * The result of running `field.filterOptions` on select fields.\n */\n selectFilterOptions?: Option[]\n valid?: boolean\n validate?: Validate\n value?: unknown\n}\n\nexport type FieldStateWithoutComponents = Omit<FieldState, 'customComponents'>\n\nexport type FormState = {\n [path: string]: FieldState\n}\n\nexport type FormStateWithoutComponents = {\n [path: string]: FieldStateWithoutComponents\n}\n\nexport type BuildFormStateArgs = {\n data?: Data\n docPermissions: SanitizedDocumentPermissions | undefined\n docPreferences: DocumentPreferences\n /**\n * In case `formState` is not the top-level, document form state, this can be passed to\n * provide the top-level form state.\n */\n documentFormState?: FormState\n fallbackLocale?: false | TypedLocale\n formState?: FormState\n id?: number | string\n initialBlockData?: Data\n initialBlockFormState?: FormState\n /*\n If not i18n was passed, the language can be passed to init i18n\n */\n language?: keyof SupportedLanguages\n locale?: string\n /**\n * If true, will not render RSCs and instead return a simple string in their place.\n * This is useful for environments that lack RSC support, such as Jest.\n * Form state can still be built, but any server components will be omitted.\n * @default false\n */\n mockRSCs?: boolean\n operation?: 'create' | 'update'\n readOnly?: boolean\n /**\n * If true, will render field components within their state object.\n * Performance optimization: Setting to `false` ensures that only fields that have changed paths will re-render, e.g. new array rows, etc.\n * For example, you only need to render ALL fields on initial render, not on every onChange.\n */\n renderAllFields?: boolean\n req: PayloadRequest\n returnLockStatus?: boolean\n schemaPath: string\n select?: SelectType\n skipValidation?: boolean\n updateLastEdited?: boolean\n} & (\n | {\n collectionSlug: string\n // Do not type it as never. This still makes it so that either collectionSlug or globalSlug is required, but makes it easier to provide both collectionSlug and globalSlug if it's\n // unclear which one is actually available.\n globalSlug?: string\n }\n | {\n collectionSlug?: string\n globalSlug: string\n }\n)\n"],"names":[],"mappings":"AAgGA,WAmDC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findByID.d.ts","sourceRoot":"","sources":["../../../src/collections/endpoints/findByID.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAU3D,eAAO,MAAM,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"findByID.d.ts","sourceRoot":"","sources":["../../../src/collections/endpoints/findByID.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAU3D,eAAO,MAAM,eAAe,EAAE,cAqC7B,CAAA"}
|
|
@@ -11,12 +11,14 @@ export const findByIDHandler = async (req)=>{
|
|
|
11
11
|
const { id, collection } = getRequestCollectionWithID(req);
|
|
12
12
|
const depth = data ? data.depth : searchParams.get('depth');
|
|
13
13
|
const trash = data ? data.trash : searchParams.get('trash') === 'true';
|
|
14
|
+
const flattenLocales = data ? data.flattenLocales : searchParams.has('flattenLocales') ? searchParams.get('flattenLocales') === 'true' : undefined;
|
|
14
15
|
const result = await findByIDOperation({
|
|
15
16
|
id,
|
|
16
17
|
collection,
|
|
17
18
|
data: data ? data?.data : searchParams.get('data') ? JSON.parse(searchParams.get('data')) : undefined,
|
|
18
19
|
depth: isNumber(depth) ? Number(depth) : undefined,
|
|
19
20
|
draft: data ? data.draft : searchParams.get('draft') === 'true',
|
|
21
|
+
flattenLocales,
|
|
20
22
|
joins: sanitizeJoinParams(req.query.joins),
|
|
21
23
|
populate: sanitizePopulateParam(req.query.populate),
|
|
22
24
|
req,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/endpoints/findByID.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\n\nimport { getRequestCollectionWithID } from '../../utilities/getRequestEntity.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { isNumber } from '../../utilities/isNumber.js'\nimport { type JoinParams, sanitizeJoinParams } from '../../utilities/sanitizeJoinParams.js'\nimport { sanitizePopulateParam } from '../../utilities/sanitizePopulateParam.js'\nimport { sanitizeSelectParam } from '../../utilities/sanitizeSelectParam.js'\nimport { findByIDOperation } from '../operations/findByID.js'\n\nexport const findByIDHandler: PayloadHandler = async (req) => {\n const { data, searchParams } = req\n const { id, collection } = getRequestCollectionWithID(req)\n const depth = data ? data.depth : searchParams.get('depth')\n const trash = data ? data.trash : searchParams.get('trash') === 'true'\n\n const result = await findByIDOperation({\n id,\n collection,\n data: data\n ? data?.data\n : searchParams.get('data')\n ? JSON.parse(searchParams.get('data') as string)\n : undefined,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: data ? data.draft : searchParams.get('draft') === 'true',\n joins: sanitizeJoinParams(req.query.joins as JoinParams),\n populate: sanitizePopulateParam(req.query.populate),\n req,\n select: sanitizeSelectParam(req.query.select),\n trash,\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"names":["status","httpStatus","getRequestCollectionWithID","headersWithCors","isNumber","sanitizeJoinParams","sanitizePopulateParam","sanitizeSelectParam","findByIDOperation","findByIDHandler","req","data","searchParams","id","collection","depth","get","trash","result","JSON","parse","
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/endpoints/findByID.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\n\nimport { getRequestCollectionWithID } from '../../utilities/getRequestEntity.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { isNumber } from '../../utilities/isNumber.js'\nimport { type JoinParams, sanitizeJoinParams } from '../../utilities/sanitizeJoinParams.js'\nimport { sanitizePopulateParam } from '../../utilities/sanitizePopulateParam.js'\nimport { sanitizeSelectParam } from '../../utilities/sanitizeSelectParam.js'\nimport { findByIDOperation } from '../operations/findByID.js'\n\nexport const findByIDHandler: PayloadHandler = async (req) => {\n const { data, searchParams } = req\n const { id, collection } = getRequestCollectionWithID(req)\n const depth = data ? data.depth : searchParams.get('depth')\n const trash = data ? data.trash : searchParams.get('trash') === 'true'\n const flattenLocales = data\n ? data.flattenLocales\n : searchParams.has('flattenLocales')\n ? searchParams.get('flattenLocales') === 'true'\n : // flattenLocales should be undefined if not provided, so that the default (true) is applied in the operation\n undefined\n\n const result = await findByIDOperation({\n id,\n collection,\n data: data\n ? data?.data\n : searchParams.get('data')\n ? JSON.parse(searchParams.get('data') as string)\n : undefined,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: data ? data.draft : searchParams.get('draft') === 'true',\n flattenLocales,\n joins: sanitizeJoinParams(req.query.joins as JoinParams),\n populate: sanitizePopulateParam(req.query.populate),\n req,\n select: sanitizeSelectParam(req.query.select),\n trash,\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"names":["status","httpStatus","getRequestCollectionWithID","headersWithCors","isNumber","sanitizeJoinParams","sanitizePopulateParam","sanitizeSelectParam","findByIDOperation","findByIDHandler","req","data","searchParams","id","collection","depth","get","trash","flattenLocales","has","undefined","result","JSON","parse","Number","draft","joins","query","populate","select","Response","json","headers","Headers","OK"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAIlD,SAASC,0BAA0B,QAAQ,sCAAqC;AAChF,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,QAAQ,QAAQ,8BAA6B;AACtD,SAA0BC,kBAAkB,QAAQ,wCAAuC;AAC3F,SAASC,qBAAqB,QAAQ,2CAA0C;AAChF,SAASC,mBAAmB,QAAQ,yCAAwC;AAC5E,SAASC,iBAAiB,QAAQ,4BAA2B;AAE7D,OAAO,MAAMC,kBAAkC,OAAOC;IACpD,MAAM,EAAEC,IAAI,EAAEC,YAAY,EAAE,GAAGF;IAC/B,MAAM,EAAEG,EAAE,EAAEC,UAAU,EAAE,GAAGZ,2BAA2BQ;IACtD,MAAMK,QAAQJ,OAAOA,KAAKI,KAAK,GAAGH,aAAaI,GAAG,CAAC;IACnD,MAAMC,QAAQN,OAAOA,KAAKM,KAAK,GAAGL,aAAaI,GAAG,CAAC,aAAa;IAChE,MAAME,iBAAiBP,OACnBA,KAAKO,cAAc,GACnBN,aAAaO,GAAG,CAAC,oBACfP,aAAaI,GAAG,CAAC,sBAAsB,SAEvCI;IAEN,MAAMC,SAAS,MAAMb,kBAAkB;QACrCK;QACAC;QACAH,MAAMA,OACFA,MAAMA,OACNC,aAAaI,GAAG,CAAC,UACfM,KAAKC,KAAK,CAACX,aAAaI,GAAG,CAAC,WAC5BI;QACNL,OAAOX,SAASW,SAASS,OAAOT,SAASK;QACzCK,OAAOd,OAAOA,KAAKc,KAAK,GAAGb,aAAaI,GAAG,CAAC,aAAa;QACzDE;QACAQ,OAAOrB,mBAAmBK,IAAIiB,KAAK,CAACD,KAAK;QACzCE,UAAUtB,sBAAsBI,IAAIiB,KAAK,CAACC,QAAQ;QAClDlB;QACAmB,QAAQtB,oBAAoBG,IAAIiB,KAAK,CAACE,MAAM;QAC5CZ;IACF;IAEA,OAAOa,SAASC,IAAI,CAACV,QAAQ;QAC3BW,SAAS7B,gBAAgB;YACvB6B,SAAS,IAAIC;YACbvB;QACF;QACAV,QAAQC,WAAWiC,EAAE;IACvB;AACF,EAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { CollectionSlug, JoinQuery } from '../../index.js';
|
|
2
|
-
import type { ApplyDisableErrors, PayloadRequest, PopulateType, SelectType, TransformCollectionWithSelect } from '../../types/index.js';
|
|
2
|
+
import type { ApplyDisableErrors, JsonObject, PayloadRequest, PopulateType, SelectType, TransformCollectionWithSelect } from '../../types/index.js';
|
|
3
3
|
import type { Collection, SelectFromCollectionSlug } from '../config/types.js';
|
|
4
|
-
|
|
4
|
+
import { type AfterReadArgs } from '../../fields/hooks/afterRead/index.js';
|
|
5
|
+
export type FindByIDArgs = {
|
|
5
6
|
collection: Collection;
|
|
6
7
|
currentDepth?: number;
|
|
7
8
|
/**
|
|
@@ -21,6 +22,6 @@ export type Arguments = {
|
|
|
21
22
|
select?: SelectType;
|
|
22
23
|
showHiddenFields?: boolean;
|
|
23
24
|
trash?: boolean;
|
|
24
|
-
}
|
|
25
|
-
export declare const findByIDOperation: <TSlug extends CollectionSlug, TDisableErrors extends boolean, TSelect extends SelectFromCollectionSlug<TSlug>>(incomingArgs:
|
|
25
|
+
} & Pick<AfterReadArgs<JsonObject>, 'flattenLocales'>;
|
|
26
|
+
export declare const findByIDOperation: <TSlug extends CollectionSlug, TDisableErrors extends boolean, TSelect extends SelectFromCollectionSlug<TSlug>>(incomingArgs: FindByIDArgs) => Promise<ApplyDisableErrors<TransformCollectionWithSelect<TSlug, TSelect>, TDisableErrors>>;
|
|
26
27
|
//# sourceMappingURL=findByID.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findByID.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/findByID.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,KAAK,EACV,kBAAkB,
|
|
1
|
+
{"version":3,"file":"findByID.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/findByID.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,KAAK,EACV,kBAAkB,EAClB,UAAU,EACV,cAAc,EACd,YAAY,EACZ,UAAU,EACV,6BAA6B,EAC9B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EACV,UAAU,EAEV,wBAAwB,EAEzB,MAAM,oBAAoB,CAAA;AAO3B,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,uCAAuC,CAAA;AASrF,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,EAAE,UAAU,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,GAAG,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC,CAAA;AAErD,eAAO,MAAM,iBAAiB,GAC5B,KAAK,SAAS,cAAc,EAC5B,cAAc,SAAS,OAAO,EAC9B,OAAO,SAAS,wBAAwB,CAAC,KAAK,CAAC,gBAEjC,YAAY,KACzB,OAAO,CAAC,kBAAkB,CAAC,6BAA6B,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,CAiR3F,CAAA"}
|
|
@@ -28,7 +28,7 @@ export const findByIDOperation = async (incomingArgs)=>{
|
|
|
28
28
|
}) || args;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
const { id, collection: { config: collectionConfig }, currentDepth, depth, disableErrors, draft: draftEnabled = false, includeLockStatus, joins, overrideAccess = false, populate, req: { fallbackLocale, locale, t }, req, select: incomingSelect, showHiddenFields, trash = false } = args;
|
|
31
|
+
const { id, collection: { config: collectionConfig }, currentDepth, depth, disableErrors, draft: draftEnabled = false, flattenLocales, includeLockStatus, joins, overrideAccess = false, populate, req: { fallbackLocale, locale, t }, req, select: incomingSelect, showHiddenFields, trash = false } = args;
|
|
32
32
|
const select = sanitizeSelect({
|
|
33
33
|
fields: collectionConfig.flattenedFields,
|
|
34
34
|
forceSelect: collectionConfig.forceSelect,
|
|
@@ -189,6 +189,7 @@ export const findByIDOperation = async (incomingArgs)=>{
|
|
|
189
189
|
doc: result,
|
|
190
190
|
draft: draftEnabled,
|
|
191
191
|
fallbackLocale: fallbackLocale,
|
|
192
|
+
flattenLocales,
|
|
192
193
|
global: null,
|
|
193
194
|
locale: locale,
|
|
194
195
|
overrideAccess,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/operations/findByID.ts"],"sourcesContent":["import type { FindOneArgs } from '../../database/types.js'\nimport type { CollectionSlug, JoinQuery } from '../../index.js'\nimport type {\n ApplyDisableErrors,\n JsonObject,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n SelectFromCollectionSlug,\n TypeWithID,\n} from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { sanitizeJoinQuery } from '../../database/sanitizeJoinQuery.js'\nimport { sanitizeWhereQuery } from '../../database/sanitizeWhereQuery.js'\nimport { NotFound } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { validateQueryPaths } from '../../index.js'\nimport { lockedDocumentsCollectionSlug } from '../../locked-documents/config.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { replaceWithDraftIfAvailable } from '../../versions/drafts/replaceWithDraftIfAvailable.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments = {\n collection: Collection\n currentDepth?: number\n /**\n * You may pass the document data directly which will skip the `db.findOne` database query.\n * This is useful if you want to use this endpoint solely for running hooks and populating data.\n */\n data?: Record<string, unknown>\n depth?: number\n disableErrors?: boolean\n draft?: boolean\n id: number | string\n includeLockStatus?: boolean\n joins?: JoinQuery\n overrideAccess?: boolean\n populate?: PopulateType\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n trash?: boolean\n}\n\nexport const findByIDOperation = async <\n TSlug extends CollectionSlug,\n TDisableErrors extends boolean,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments,\n): Promise<ApplyDisableErrors<TransformCollectionWithSelect<TSlug, TSelect>, TDisableErrors>> => {\n let args = incomingArgs\n\n try {\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n if (args.collection.config.hooks?.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation: 'read',\n req: args.req,\n })) || args\n }\n }\n\n const {\n id,\n collection: { config: collectionConfig },\n currentDepth,\n depth,\n disableErrors,\n draft: draftEnabled = false,\n includeLockStatus,\n joins,\n overrideAccess = false,\n populate,\n req: { fallbackLocale, locale, t },\n req,\n select: incomingSelect,\n showHiddenFields,\n trash = false,\n } = args\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResult = !overrideAccess\n ? await executeAccess({ id, disableErrors, req }, collectionConfig.access.read)\n : true\n\n // If errors are disabled, and access returns false, return null\n if (accessResult === false) {\n return null!\n }\n\n const where = { id: { equals: id } }\n\n let fullWhere = combineQueries(where, accessResult)\n\n // Exclude trashed documents when trash: false\n fullWhere = appendNonTrashedFilter({\n enableTrash: collectionConfig.trash,\n trash,\n where: fullWhere,\n })\n\n sanitizeWhereQuery({\n fields: collectionConfig.flattenedFields,\n payload: args.req.payload,\n where: fullWhere,\n })\n\n const sanitizedJoins = await sanitizeJoinQuery({\n collectionConfig,\n joins,\n overrideAccess,\n req,\n })\n\n const findOneArgs: FindOneArgs = {\n collection: collectionConfig.slug,\n draftsEnabled: draftEnabled,\n joins: req.payloadAPI === 'GraphQL' ? false : sanitizedJoins,\n locale: locale!,\n req: {\n transactionID: req.transactionID,\n } as PayloadRequest,\n select,\n where: fullWhere,\n }\n\n // execute only if there's a custom ID and potentially overwriten access on id\n if (req.payload.collections[collectionConfig.slug]!.customIDType) {\n await validateQueryPaths({\n collectionConfig,\n overrideAccess,\n req,\n where,\n })\n }\n // /////////////////////////////////////\n // Find by ID\n // /////////////////////////////////////\n\n if (!findOneArgs.where?.and?.[0]?.id) {\n throw new NotFound(t)\n }\n\n let result: DataFromCollectionSlug<TSlug> =\n (args.data as DataFromCollectionSlug<TSlug>) ?? (await req.payload.db.findOne(findOneArgs))!\n\n if (!result) {\n if (!disableErrors) {\n throw new NotFound(req.t)\n }\n\n return null!\n }\n\n // /////////////////////////////////////\n // Include Lock Status if required\n // /////////////////////////////////////\n\n if (includeLockStatus && id) {\n let lockStatus: (JsonObject & TypeWithID) | null = null\n\n try {\n const lockDocumentsProp = collectionConfig?.lockDocuments\n\n const lockDurationDefault = 300 // Default 5 minutes in seconds\n const lockDuration =\n typeof lockDocumentsProp === 'object' ? lockDocumentsProp.duration : lockDurationDefault\n const lockDurationInMilliseconds = lockDuration * 1000\n\n const lockedDocument = await req.payload.find({\n collection: lockedDocumentsCollectionSlug,\n depth: 1,\n limit: 1,\n overrideAccess: false,\n pagination: false,\n req,\n where: {\n and: [\n {\n 'document.relationTo': {\n equals: collectionConfig.slug,\n },\n },\n {\n 'document.value': {\n equals: id,\n },\n },\n // Query where the lock is newer than the current time minus lock time\n {\n updatedAt: {\n greater_than: new Date(new Date().getTime() - lockDurationInMilliseconds),\n },\n },\n ],\n },\n })\n\n if (lockedDocument && lockedDocument.docs.length > 0) {\n lockStatus = lockedDocument.docs[0]!\n }\n } catch {\n // swallow error\n }\n\n result._isLocked = !!lockStatus\n result._userEditing = lockStatus?.user?.value ?? null\n }\n\n // /////////////////////////////////////\n // Replace document with draft if available\n // /////////////////////////////////////\n\n if (collectionConfig.versions?.drafts && draftEnabled) {\n result = await replaceWithDraftIfAvailable({\n accessResult,\n doc: result,\n entity: collectionConfig,\n entityType: 'collection',\n overrideAccess,\n req,\n select,\n })\n }\n\n // /////////////////////////////////////\n // beforeRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeRead?.length) {\n for (const hook of collectionConfig.hooks.beforeRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n query: findOneArgs.where,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n currentDepth,\n depth: depth!,\n doc: result,\n draft: draftEnabled,\n fallbackLocale: fallbackLocale!,\n global: null,\n locale: locale!,\n overrideAccess,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n query: findOneArgs.where,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'findByID',\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n return result as ApplyDisableErrors<\n TransformCollectionWithSelect<TSlug, TSelect>,\n TDisableErrors\n >\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["executeAccess","combineQueries","sanitizeJoinQuery","sanitizeWhereQuery","NotFound","afterRead","validateQueryPaths","lockedDocumentsCollectionSlug","appendNonTrashedFilter","killTransaction","sanitizeSelect","replaceWithDraftIfAvailable","buildAfterOperation","findByIDOperation","incomingArgs","args","collection","config","hooks","beforeOperation","length","hook","context","req","operation","id","collectionConfig","currentDepth","depth","disableErrors","draft","draftEnabled","includeLockStatus","joins","overrideAccess","populate","fallbackLocale","locale","t","select","incomingSelect","showHiddenFields","trash","fields","flattenedFields","forceSelect","accessResult","access","read","where","equals","fullWhere","enableTrash","payload","sanitizedJoins","findOneArgs","slug","draftsEnabled","payloadAPI","transactionID","collections","customIDType","and","result","data","db","findOne","lockStatus","lockDocumentsProp","lockDocuments","lockDurationDefault","lockDuration","duration","lockDurationInMilliseconds","lockedDocument","find","limit","pagination","updatedAt","greater_than","Date","getTime","docs","_isLocked","_userEditing","user","value","versions","drafts","doc","entity","entityType","beforeRead","query","global","error"],"mappings":"AAiBA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,kBAAkB,QAAQ,uCAAsC;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,"sources":["../../../src/collections/operations/findByID.ts"],"sourcesContent":["import type { FindOneArgs } from '../../database/types.js'\nimport type { CollectionSlug, JoinQuery } from '../../index.js'\nimport type {\n ApplyDisableErrors,\n JsonObject,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n SelectFromCollectionSlug,\n TypeWithID,\n} from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { sanitizeJoinQuery } from '../../database/sanitizeJoinQuery.js'\nimport { sanitizeWhereQuery } from '../../database/sanitizeWhereQuery.js'\nimport { NotFound } from '../../errors/index.js'\nimport { afterRead, type AfterReadArgs } from '../../fields/hooks/afterRead/index.js'\nimport { validateQueryPaths } from '../../index.js'\nimport { lockedDocumentsCollectionSlug } from '../../locked-documents/config.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { replaceWithDraftIfAvailable } from '../../versions/drafts/replaceWithDraftIfAvailable.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type FindByIDArgs = {\n collection: Collection\n currentDepth?: number\n /**\n * You may pass the document data directly which will skip the `db.findOne` database query.\n * This is useful if you want to use this endpoint solely for running hooks and populating data.\n */\n data?: Record<string, unknown>\n depth?: number\n disableErrors?: boolean\n draft?: boolean\n id: number | string\n includeLockStatus?: boolean\n joins?: JoinQuery\n overrideAccess?: boolean\n populate?: PopulateType\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n trash?: boolean\n} & Pick<AfterReadArgs<JsonObject>, 'flattenLocales'>\n\nexport const findByIDOperation = async <\n TSlug extends CollectionSlug,\n TDisableErrors extends boolean,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: FindByIDArgs,\n): Promise<ApplyDisableErrors<TransformCollectionWithSelect<TSlug, TSelect>, TDisableErrors>> => {\n let args = incomingArgs\n\n try {\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n if (args.collection.config.hooks?.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation: 'read',\n req: args.req,\n })) || args\n }\n }\n\n const {\n id,\n collection: { config: collectionConfig },\n currentDepth,\n depth,\n disableErrors,\n draft: draftEnabled = false,\n flattenLocales,\n includeLockStatus,\n joins,\n overrideAccess = false,\n populate,\n req: { fallbackLocale, locale, t },\n req,\n select: incomingSelect,\n showHiddenFields,\n trash = false,\n } = args\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResult = !overrideAccess\n ? await executeAccess({ id, disableErrors, req }, collectionConfig.access.read)\n : true\n\n // If errors are disabled, and access returns false, return null\n if (accessResult === false) {\n return null!\n }\n\n const where = { id: { equals: id } }\n\n let fullWhere = combineQueries(where, accessResult)\n\n // Exclude trashed documents when trash: false\n fullWhere = appendNonTrashedFilter({\n enableTrash: collectionConfig.trash,\n trash,\n where: fullWhere,\n })\n\n sanitizeWhereQuery({\n fields: collectionConfig.flattenedFields,\n payload: args.req.payload,\n where: fullWhere,\n })\n\n const sanitizedJoins = await sanitizeJoinQuery({\n collectionConfig,\n joins,\n overrideAccess,\n req,\n })\n\n const findOneArgs: FindOneArgs = {\n collection: collectionConfig.slug,\n draftsEnabled: draftEnabled,\n joins: req.payloadAPI === 'GraphQL' ? false : sanitizedJoins,\n locale: locale!,\n req: {\n transactionID: req.transactionID,\n } as PayloadRequest,\n select,\n where: fullWhere,\n }\n\n // execute only if there's a custom ID and potentially overwriten access on id\n if (req.payload.collections[collectionConfig.slug]!.customIDType) {\n await validateQueryPaths({\n collectionConfig,\n overrideAccess,\n req,\n where,\n })\n }\n // /////////////////////////////////////\n // Find by ID\n // /////////////////////////////////////\n\n if (!findOneArgs.where?.and?.[0]?.id) {\n throw new NotFound(t)\n }\n\n let result: DataFromCollectionSlug<TSlug> =\n (args.data as DataFromCollectionSlug<TSlug>) ?? (await req.payload.db.findOne(findOneArgs))!\n\n if (!result) {\n if (!disableErrors) {\n throw new NotFound(req.t)\n }\n\n return null!\n }\n\n // /////////////////////////////////////\n // Include Lock Status if required\n // /////////////////////////////////////\n\n if (includeLockStatus && id) {\n let lockStatus: (JsonObject & TypeWithID) | null = null\n\n try {\n const lockDocumentsProp = collectionConfig?.lockDocuments\n\n const lockDurationDefault = 300 // Default 5 minutes in seconds\n const lockDuration =\n typeof lockDocumentsProp === 'object' ? lockDocumentsProp.duration : lockDurationDefault\n const lockDurationInMilliseconds = lockDuration * 1000\n\n const lockedDocument = await req.payload.find({\n collection: lockedDocumentsCollectionSlug,\n depth: 1,\n limit: 1,\n overrideAccess: false,\n pagination: false,\n req,\n where: {\n and: [\n {\n 'document.relationTo': {\n equals: collectionConfig.slug,\n },\n },\n {\n 'document.value': {\n equals: id,\n },\n },\n // Query where the lock is newer than the current time minus lock time\n {\n updatedAt: {\n greater_than: new Date(new Date().getTime() - lockDurationInMilliseconds),\n },\n },\n ],\n },\n })\n\n if (lockedDocument && lockedDocument.docs.length > 0) {\n lockStatus = lockedDocument.docs[0]!\n }\n } catch {\n // swallow error\n }\n\n result._isLocked = !!lockStatus\n result._userEditing = lockStatus?.user?.value ?? null\n }\n\n // /////////////////////////////////////\n // Replace document with draft if available\n // /////////////////////////////////////\n\n if (collectionConfig.versions?.drafts && draftEnabled) {\n result = await replaceWithDraftIfAvailable({\n accessResult,\n doc: result,\n entity: collectionConfig,\n entityType: 'collection',\n overrideAccess,\n req,\n select,\n })\n }\n\n // /////////////////////////////////////\n // beforeRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeRead?.length) {\n for (const hook of collectionConfig.hooks.beforeRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n query: findOneArgs.where,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n currentDepth,\n depth: depth!,\n doc: result,\n draft: draftEnabled,\n fallbackLocale: fallbackLocale!,\n flattenLocales,\n global: null,\n locale: locale!,\n overrideAccess,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n query: findOneArgs.where,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'findByID',\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n return result as ApplyDisableErrors<\n TransformCollectionWithSelect<TSlug, TSelect>,\n TDisableErrors\n >\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["executeAccess","combineQueries","sanitizeJoinQuery","sanitizeWhereQuery","NotFound","afterRead","validateQueryPaths","lockedDocumentsCollectionSlug","appendNonTrashedFilter","killTransaction","sanitizeSelect","replaceWithDraftIfAvailable","buildAfterOperation","findByIDOperation","incomingArgs","args","collection","config","hooks","beforeOperation","length","hook","context","req","operation","id","collectionConfig","currentDepth","depth","disableErrors","draft","draftEnabled","flattenLocales","includeLockStatus","joins","overrideAccess","populate","fallbackLocale","locale","t","select","incomingSelect","showHiddenFields","trash","fields","flattenedFields","forceSelect","accessResult","access","read","where","equals","fullWhere","enableTrash","payload","sanitizedJoins","findOneArgs","slug","draftsEnabled","payloadAPI","transactionID","collections","customIDType","and","result","data","db","findOne","lockStatus","lockDocumentsProp","lockDocuments","lockDurationDefault","lockDuration","duration","lockDurationInMilliseconds","lockedDocument","find","limit","pagination","updatedAt","greater_than","Date","getTime","docs","_isLocked","_userEditing","user","value","versions","drafts","doc","entity","entityType","beforeRead","query","global","error"],"mappings":"AAiBA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,kBAAkB,QAAQ,uCAAsC;AACzE,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,SAAS,QAA4B,wCAAuC;AACrF,SAASC,kBAAkB,QAAQ,iBAAgB;AACnD,SAASC,6BAA6B,QAAQ,mCAAkC;AAChF,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,2BAA2B,QAAQ,uDAAsD;AAClG,SAASC,mBAAmB,QAAQ,aAAY;AAwBhD,OAAO,MAAMC,oBAAoB,OAK/BC;IAEA,IAAIC,OAAOD;IAEX,IAAI;QACF,wCAAwC;QACxC,+BAA+B;QAC/B,wCAAwC;QAExC,IAAIC,KAAKC,UAAU,CAACC,MAAM,CAACC,KAAK,EAAEC,iBAAiBC,QAAQ;YACzD,KAAK,MAAMC,QAAQN,KAAKC,UAAU,CAACC,MAAM,CAACC,KAAK,CAACC,eAAe,CAAE;gBAC/DJ,OACE,AAAC,MAAMM,KAAK;oBACVN;oBACAC,YAAYD,KAAKC,UAAU,CAACC,MAAM;oBAClCK,SAASP,KAAKQ,GAAG,CAACD,OAAO;oBACzBE,WAAW;oBACXD,KAAKR,KAAKQ,GAAG;gBACf,MAAOR;YACX;QACF;QAEA,MAAM,EACJU,EAAE,EACFT,YAAY,EAAEC,QAAQS,gBAAgB,EAAE,EACxCC,YAAY,EACZC,KAAK,EACLC,aAAa,EACbC,OAAOC,eAAe,KAAK,EAC3BC,cAAc,E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,YAAYN,KAAK;oBACxB3B;gBACF,MAAOyC;YACX;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCA,SAAS,MAAMpD,oBAAoB;YACjCG;YACAC,YAAYU;YACZF,WAAW;YACXwC;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,OAAOA;IAIT,EAAE,OAAOgC,OAAgB;QACvB,MAAMvF,gBAAgBM,KAAKQ,GAAG;QAC9B,MAAMyE;IACR;AACF,EAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CollectionSlug, JoinQuery, Payload, RequestContext, SelectType, TypedLocale } from '../../../index.js';
|
|
2
2
|
import type { ApplyDisableErrors, Document, PayloadRequest, PopulateType, TransformCollectionWithSelect } from '../../../types/index.js';
|
|
3
3
|
import type { SelectFromCollectionSlug } from '../../config/types.js';
|
|
4
|
+
import { type FindByIDArgs } from '../findByID.js';
|
|
4
5
|
export type Options<TSlug extends CollectionSlug, TDisableErrors extends boolean, TSelect extends SelectType> = {
|
|
5
6
|
/**
|
|
6
7
|
* the Collection slug to operate against.
|
|
@@ -94,6 +95,6 @@ export type Options<TSlug extends CollectionSlug, TDisableErrors extends boolean
|
|
|
94
95
|
* If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.
|
|
95
96
|
*/
|
|
96
97
|
user?: Document;
|
|
97
|
-
}
|
|
98
|
+
} & Pick<FindByIDArgs, 'flattenLocales'>;
|
|
98
99
|
export declare function findByIDLocal<TSlug extends CollectionSlug, TDisableErrors extends boolean, TSelect extends SelectFromCollectionSlug<TSlug>>(payload: Payload, options: Options<TSlug, TDisableErrors, TSelect>): Promise<ApplyDisableErrors<TransformCollectionWithSelect<TSlug, TSelect>, TDisableErrors>>;
|
|
99
100
|
//# sourceMappingURL=findByID.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findByID.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/local/findByID.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,OAAO,EACP,cAAc,EACd,UAAU,EACV,WAAW,EACZ,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EACV,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,6BAA6B,EAC9B,MAAM,yBAAyB,CAAA;AAEhC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"findByID.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/local/findByID.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,OAAO,EACP,cAAc,EACd,UAAU,EACV,WAAW,EACZ,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EACV,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,6BAA6B,EAC9B,MAAM,yBAAyB,CAAA;AAEhC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAIrE,OAAO,EAAE,KAAK,YAAY,EAAqB,MAAM,gBAAgB,CAAA;AAErE,MAAM,MAAM,OAAO,CACjB,KAAK,SAAS,cAAc,EAC5B,cAAc,SAAS,OAAO,EAC9B,OAAO,SAAS,UAAU,IACxB;IACF;;OAEG;IACH,UAAU,EAAE,KAAK,CAAA;IACjB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,aAAa,CAAC,EAAE,cAAc,CAAA;IAC9B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;OAEG;IACH,cAAc,CAAC,EAAE,KAAK,GAAG,WAAW,CAAA;IACpC;;OAEG;IACH,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,CAAA;IACxB;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,GAAG,WAAW,CAAA;IAC5B;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB,GAAG,IAAI,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAA;AAExC,wBAAsB,aAAa,CACjC,KAAK,SAAS,cAAc,EAC5B,cAAc,SAAS,OAAO,EAC9B,OAAO,SAAS,wBAAwB,CAAC,KAAK,CAAC,EAE/C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,cAAc,EAAE,OAAO,CAAC,GAC/C,OAAO,CAAC,kBAAkB,CAAC,6BAA6B,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,CAAC,CA6C5F"}
|
|
@@ -2,7 +2,7 @@ import { APIError } from '../../../errors/index.js';
|
|
|
2
2
|
import { createLocalReq } from '../../../utilities/createLocalReq.js';
|
|
3
3
|
import { findByIDOperation } from '../findByID.js';
|
|
4
4
|
export async function findByIDLocal(payload, options) {
|
|
5
|
-
const { id, collection: collectionSlug, currentDepth, data, depth, disableErrors = false, draft = false, includeLockStatus, joins, overrideAccess = true, populate, select, showHiddenFields, trash = false } = options;
|
|
5
|
+
const { id, collection: collectionSlug, currentDepth, data, depth, disableErrors = false, draft = false, flattenLocales, includeLockStatus, joins, overrideAccess = true, populate, select, showHiddenFields, trash = false } = options;
|
|
6
6
|
const collection = payload.collections[collectionSlug];
|
|
7
7
|
if (!collection) {
|
|
8
8
|
throw new APIError(`The collection with slug ${String(collectionSlug)} can't be found. Find By ID Operation.`);
|
|
@@ -15,6 +15,7 @@ export async function findByIDLocal(payload, options) {
|
|
|
15
15
|
depth,
|
|
16
16
|
disableErrors,
|
|
17
17
|
draft,
|
|
18
|
+
flattenLocales,
|
|
18
19
|
includeLockStatus,
|
|
19
20
|
joins,
|
|
20
21
|
overrideAccess,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/collections/operations/local/findByID.ts"],"sourcesContent":["import type {\n CollectionSlug,\n JoinQuery,\n Payload,\n RequestContext,\n SelectType,\n TypedLocale,\n} from '../../../index.js'\nimport type {\n ApplyDisableErrors,\n Document,\n PayloadRequest,\n PopulateType,\n TransformCollectionWithSelect,\n} from '../../../types/index.js'\nimport type { CreateLocalReqOptions } from '../../../utilities/createLocalReq.js'\nimport type { SelectFromCollectionSlug } from '../../config/types.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { findByIDOperation } from '../findByID.js'\n\nexport type Options<\n TSlug extends CollectionSlug,\n TDisableErrors extends boolean,\n TSelect extends SelectType,\n> = {\n /**\n * the Collection slug to operate against.\n */\n collection: TSlug\n /**\n * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,\n * which can be read by hooks. Useful if you want to pass additional information to the hooks which\n * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook\n * to determine if it should run or not.\n */\n context?: RequestContext\n /**\n * The current population depth, used internally for relationships population.\n * @internal\n */\n currentDepth?: number\n /**\n * You may pass the document data directly which will skip the `db.findOne` database query.\n * This is useful if you want to use this endpoint solely for running hooks and populating data.\n */\n data?: Record<string, unknown>\n /**\n * [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.\n */\n depth?: number\n /**\n * When set to `true`, errors will not be thrown.\n * `null` will be returned instead, if the document on this ID was not found.\n */\n disableErrors?: TDisableErrors\n /**\n * Whether the document should be queried from the versions table/collection or not. [More](https://payloadcms.com/docs/versions/drafts#draft-api)\n */\n draft?: boolean\n /**\n * Specify a [fallback locale](https://payloadcms.com/docs/configuration/localization) to use for any returned documents.\n */\n fallbackLocale?: false | TypedLocale\n /**\n * The ID of the document to find.\n */\n id: number | string\n /**\n * Include info about the lock status to the result with fields: `_isLocked` and `_userEditing`\n */\n includeLockStatus?: boolean\n /**\n * The [Join Field Query](https://payloadcms.com/docs/fields/join#query-options).\n * Pass `false` to disable all join fields from the result.\n */\n joins?: JoinQuery<TSlug>\n /**\n * Specify [locale](https://payloadcms.com/docs/configuration/localization) for any returned documents.\n */\n locale?: 'all' | TypedLocale\n /**\n * Skip access control.\n * Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.\n * @default true\n */\n overrideAccess?: boolean\n /**\n * Specify [populate](https://payloadcms.com/docs/queries/select#populate) to control which fields to include to the result from populated documents.\n */\n populate?: PopulateType\n /**\n * The `PayloadRequest` object. You can pass it to thread the current [transaction](https://payloadcms.com/docs/database/transactions), user and locale to the operation.\n * Recommended to pass when using the Local API from hooks, as usually you want to execute the operation within the current transaction.\n */\n req?: Partial<PayloadRequest>\n /**\n * Specify [select](https://payloadcms.com/docs/queries/select) to control which fields to include to the result.\n */\n select?: TSelect\n /**\n * Opt-in to receiving hidden fields. By default, they are hidden from returned documents in accordance to your config.\n * @default false\n */\n showHiddenFields?: boolean\n /**\n * When set to `true`, the operation will return a document by ID, even if it is trashed (soft-deleted).\n * By default (`false`), the operation will exclude trashed documents.\n * To fetch a trashed document, set `trash: true`.\n *\n * This argument has no effect unless `trash` is enabled on the collection.\n * @default false\n */\n trash?: boolean\n /**\n * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.\n */\n user?: Document\n}
|
|
1
|
+
{"version":3,"sources":["../../../../src/collections/operations/local/findByID.ts"],"sourcesContent":["import type {\n CollectionSlug,\n JoinQuery,\n Payload,\n RequestContext,\n SelectType,\n TypedLocale,\n} from '../../../index.js'\nimport type {\n ApplyDisableErrors,\n Document,\n PayloadRequest,\n PopulateType,\n TransformCollectionWithSelect,\n} from '../../../types/index.js'\nimport type { CreateLocalReqOptions } from '../../../utilities/createLocalReq.js'\nimport type { SelectFromCollectionSlug } from '../../config/types.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { type FindByIDArgs, findByIDOperation } from '../findByID.js'\n\nexport type Options<\n TSlug extends CollectionSlug,\n TDisableErrors extends boolean,\n TSelect extends SelectType,\n> = {\n /**\n * the Collection slug to operate against.\n */\n collection: TSlug\n /**\n * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,\n * which can be read by hooks. Useful if you want to pass additional information to the hooks which\n * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook\n * to determine if it should run or not.\n */\n context?: RequestContext\n /**\n * The current population depth, used internally for relationships population.\n * @internal\n */\n currentDepth?: number\n /**\n * You may pass the document data directly which will skip the `db.findOne` database query.\n * This is useful if you want to use this endpoint solely for running hooks and populating data.\n */\n data?: Record<string, unknown>\n /**\n * [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.\n */\n depth?: number\n /**\n * When set to `true`, errors will not be thrown.\n * `null` will be returned instead, if the document on this ID was not found.\n */\n disableErrors?: TDisableErrors\n /**\n * Whether the document should be queried from the versions table/collection or not. [More](https://payloadcms.com/docs/versions/drafts#draft-api)\n */\n draft?: boolean\n /**\n * Specify a [fallback locale](https://payloadcms.com/docs/configuration/localization) to use for any returned documents.\n */\n fallbackLocale?: false | TypedLocale\n /**\n * The ID of the document to find.\n */\n id: number | string\n /**\n * Include info about the lock status to the result with fields: `_isLocked` and `_userEditing`\n */\n includeLockStatus?: boolean\n /**\n * The [Join Field Query](https://payloadcms.com/docs/fields/join#query-options).\n * Pass `false` to disable all join fields from the result.\n */\n joins?: JoinQuery<TSlug>\n /**\n * Specify [locale](https://payloadcms.com/docs/configuration/localization) for any returned documents.\n */\n locale?: 'all' | TypedLocale\n /**\n * Skip access control.\n * Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.\n * @default true\n */\n overrideAccess?: boolean\n /**\n * Specify [populate](https://payloadcms.com/docs/queries/select#populate) to control which fields to include to the result from populated documents.\n */\n populate?: PopulateType\n /**\n * The `PayloadRequest` object. You can pass it to thread the current [transaction](https://payloadcms.com/docs/database/transactions), user and locale to the operation.\n * Recommended to pass when using the Local API from hooks, as usually you want to execute the operation within the current transaction.\n */\n req?: Partial<PayloadRequest>\n /**\n * Specify [select](https://payloadcms.com/docs/queries/select) to control which fields to include to the result.\n */\n select?: TSelect\n /**\n * Opt-in to receiving hidden fields. By default, they are hidden from returned documents in accordance to your config.\n * @default false\n */\n showHiddenFields?: boolean\n /**\n * When set to `true`, the operation will return a document by ID, even if it is trashed (soft-deleted).\n * By default (`false`), the operation will exclude trashed documents.\n * To fetch a trashed document, set `trash: true`.\n *\n * This argument has no effect unless `trash` is enabled on the collection.\n * @default false\n */\n trash?: boolean\n /**\n * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.\n */\n user?: Document\n} & Pick<FindByIDArgs, 'flattenLocales'>\n\nexport async function findByIDLocal<\n TSlug extends CollectionSlug,\n TDisableErrors extends boolean,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n payload: Payload,\n options: Options<TSlug, TDisableErrors, TSelect>,\n): Promise<ApplyDisableErrors<TransformCollectionWithSelect<TSlug, TSelect>, TDisableErrors>> {\n const {\n id,\n collection: collectionSlug,\n currentDepth,\n data,\n depth,\n disableErrors = false,\n draft = false,\n flattenLocales,\n includeLockStatus,\n joins,\n overrideAccess = true,\n populate,\n select,\n showHiddenFields,\n trash = false,\n } = options\n\n const collection = payload.collections[collectionSlug]\n\n if (!collection) {\n throw new APIError(\n `The collection with slug ${String(collectionSlug)} can't be found. Find By ID Operation.`,\n )\n }\n\n return findByIDOperation<TSlug, TDisableErrors, TSelect>({\n id,\n collection,\n currentDepth,\n data,\n depth,\n disableErrors,\n draft,\n flattenLocales,\n includeLockStatus,\n joins,\n overrideAccess,\n populate,\n req: await createLocalReq(options as CreateLocalReqOptions, payload),\n select,\n showHiddenFields,\n trash,\n })\n}\n"],"names":["APIError","createLocalReq","findByIDOperation","findByIDLocal","payload","options","id","collection","collectionSlug","currentDepth","data","depth","disableErrors","draft","flattenLocales","includeLockStatus","joins","overrideAccess","populate","select","showHiddenFields","trash","collections","String","req"],"mappings":"AAkBA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAA4BC,iBAAiB,QAAQ,iBAAgB;AAqGrE,OAAO,eAAeC,cAKpBC,OAAgB,EAChBC,OAAgD;IAEhD,MAAM,EACJC,EAAE,EACFC,YAAYC,cAAc,EAC1BC,YAAY,EACZC,IAAI,EACJC,KAAK,EACLC,gBAAgB,KAAK,EACrBC,QAAQ,KAAK,EACbC,cAAc,EACdC,iBAAiB,EACjBC,KAAK,EACLC,iBAAiB,IAAI,EACrBC,QAAQ,EACRC,MAAM,EACNC,gBAAgB,EAChBC,QAAQ,KAAK,EACd,GAAGhB;IAEJ,MAAME,aAAaH,QAAQkB,WAAW,CAACd,eAAe;IAEtD,IAAI,CAACD,YAAY;QACf,MAAM,IAAIP,SACR,CAAC,yBAAyB,EAAEuB,OAAOf,gBAAgB,sCAAsC,CAAC;IAE9F;IAEA,OAAON,kBAAkD;QACvDI;QACAC;QACAE;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAM,KAAK,MAAMvB,eAAeI,SAAkCD;QAC5De;QACAC;QACAC;IACF;AACF"}
|
package/dist/config/client.d.ts
CHANGED
|
@@ -23,12 +23,7 @@ export type UnauthenticatedClientConfig = {
|
|
|
23
23
|
routes: ClientConfig['admin']['routes'];
|
|
24
24
|
user: ClientConfig['admin']['user'];
|
|
25
25
|
};
|
|
26
|
-
collections: [
|
|
27
|
-
{
|
|
28
|
-
auth: ClientCollectionConfig['auth'];
|
|
29
|
-
slug: string;
|
|
30
|
-
}
|
|
31
|
-
];
|
|
26
|
+
collections: [ClientCollectionConfig];
|
|
32
27
|
globals: [];
|
|
33
28
|
routes: ClientConfig['routes'];
|
|
34
29
|
serverURL: ClientConfig['serverURL'];
|
|
@@ -44,9 +39,8 @@ export type CreateClientConfigArgs = {
|
|
|
44
39
|
* If unauthenticated, the client config will omit some sensitive properties
|
|
45
40
|
* such as field schemas, etc. This is useful for login and error pages where
|
|
46
41
|
* the page source should not contain this information.
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* where there is no user yet, but the config should still be complete.
|
|
42
|
+
* Allow `true` to generate a client config for the "create first user" page
|
|
43
|
+
* where there is no user yet, but the config should be as complete.
|
|
50
44
|
*/
|
|
51
45
|
user: true | TypedUser;
|
|
52
46
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/config/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAG1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAA;AAClE,OAAO,KAAK,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/config/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAG1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAA;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,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AAG,MAAM,GAAG,wBAAwB,CAAC,CAAA;AAElG,MAAM,MAAM,2BAA2B,GAAG;IACxC,KAAK,EAAE;QACL,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAA;QACvC,IAAI,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAA;KACpC,CAAA;IACD,WAAW,EAAE,CAAC,sBAAsB,CAAC,CAAA;IACrC,OAAO,EAAE,EAAE,CAAA;IACX,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAA;IAC9B,SAAS,EAAE,YAAY,CAAC,WAAW,CAAC,CAAA;IACpC,eAAe,EAAE,IAAI,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,+BAA+B,EAAE,SAAS,OAAO,CAAC,6BAA6B,CAAC,EAAO,CAAA;AAEpG,eAAO,MAAM,0BAA0B,EAAE,SAAS,OAAO,CAAC,wBAAwB,CAAC,EAqBlF,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,eAAe,CAAA;IACvB,IAAI,EAAE,UAAU,CAAA;IAChB,SAAS,EAAE,SAAS,CAAA;IACpB;;;;;;OAMG;IACH,IAAI,EAAE,IAAI,GAAG,SAAS,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,iCAAiC,sBAE3C;IACD;;;OAGG;IACH,YAAY,EAAE,YAAY,CAAA;CAC3B,KAAG,2BAYH,CAAA;AAED,eAAO,MAAM,kBAAkB,iCAI5B,sBAAsB,KAAG,YAoK3B,CAAA"}
|
package/dist/config/client.js
CHANGED
|
@@ -24,19 +24,13 @@ export const serverOnlyConfigProperties = [
|
|
|
24
24
|
'queryPresets'
|
|
25
25
|
];
|
|
26
26
|
export const createUnauthenticatedClientConfig = ({ clientConfig })=>{
|
|
27
|
-
/**
|
|
28
|
-
* To share memory, find the admin user collection from the existing client config.
|
|
29
|
-
*/ const adminUserCollection = clientConfig.collections.find(({ slug })=>slug === clientConfig.admin.user);
|
|
30
27
|
return {
|
|
31
28
|
admin: {
|
|
32
29
|
routes: clientConfig.admin.routes,
|
|
33
30
|
user: clientConfig.admin.user
|
|
34
31
|
},
|
|
35
32
|
collections: [
|
|
36
|
-
{
|
|
37
|
-
slug: adminUserCollection.slug,
|
|
38
|
-
auth: adminUserCollection.auth
|
|
39
|
-
}
|
|
33
|
+
clientConfig.collections.find(({ slug })=>slug === clientConfig.admin.user)
|
|
40
34
|
],
|
|
41
35
|
globals: [],
|
|
42
36
|
routes: clientConfig.routes,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/config/client.ts"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type { DeepPartial } from 'ts-essentials'\n\nimport type { ImportMap } from '../bin/generateImportMap/index.js'\nimport type { ClientBlock, ClientField, Field } from '../fields/config/types.js'\nimport type { BlockSlug, TypedUser } from '../index.js'\nimport type {\n RootLivePreviewConfig,\n SanitizedConfig,\n ServerOnlyLivePreviewProperties,\n} from './types.js'\n\nimport {\n type ClientCollectionConfig,\n createClientCollectionConfigs,\n} from '../collections/config/client.js'\nimport { createClientBlocks } from '../fields/config/client.js'\nimport { type ClientGlobalConfig, createClientGlobalConfigs } from '../globals/config/client.js'\n\nexport type ServerOnlyRootProperties = keyof Pick<\n SanitizedConfig,\n | 'bin'\n | 'cors'\n | 'csrf'\n | 'custom'\n | 'db'\n | 'editor'\n | 'email'\n | 'endpoints'\n | 'graphQL'\n | 'hooks'\n | 'i18n'\n | 'jobs'\n | 'logger'\n | 'onInit'\n | 'plugins'\n | 'queryPresets'\n | 'secret'\n | 'sharp'\n | 'typescript'\n>\n\nexport type ServerOnlyRootAdminProperties = keyof Pick<SanitizedConfig['admin'], 'components'>\n\nexport type ClientConfig = {\n admin: {\n livePreview?: Omit<RootLivePreviewConfig, ServerOnlyLivePreviewProperties>\n } & Omit<SanitizedConfig['admin'], 'components' | 'dependencies' | 'livePreview'>\n blocks: ClientBlock[]\n blocksMap: Record<BlockSlug, ClientBlock>\n collections: ClientCollectionConfig[]\n custom?: Record<string, any>\n globals: ClientGlobalConfig[]\n unauthenticated?: boolean\n} & Omit<SanitizedConfig, 'admin' | 'collections' | 'globals' | 'i18n' | ServerOnlyRootProperties>\n\nexport type UnauthenticatedClientConfig = {\n admin: {\n routes: ClientConfig['admin']['routes']\n user: ClientConfig['admin']['user']\n }\n collections: [\n {\n auth: ClientCollectionConfig['auth']\n slug: string\n },\n ]\n globals: []\n routes: ClientConfig['routes']\n serverURL: ClientConfig['serverURL']\n unauthenticated: true\n}\n\nexport const serverOnlyAdminConfigProperties: readonly Partial<ServerOnlyRootAdminProperties>[] = []\n\nexport const serverOnlyConfigProperties: readonly Partial<ServerOnlyRootProperties>[] = [\n 'endpoints',\n 'db',\n 'editor',\n 'plugins',\n 'sharp',\n 'onInit',\n 'secret',\n 'hooks',\n 'bin',\n 'i18n',\n 'typescript',\n 'cors',\n 'csrf',\n 'email',\n 'custom',\n 'graphQL',\n 'jobs',\n 'logger',\n 'queryPresets',\n // `admin`, `onInit`, `localization`, `collections`, and `globals` are all handled separately\n]\n\nexport type CreateClientConfigArgs = {\n config: SanitizedConfig\n i18n: I18nClient\n importMap: ImportMap\n /**\n * If unauthenticated, the client config will omit some sensitive properties\n * such as field schemas, etc. This is useful for login and error pages where\n * the page source should not contain this information.\n *\n * For example, allow `true` to generate a client config for the \"create first user\" page\n * where there is no user yet, but the config should still be complete.\n */\n user: true | TypedUser\n}\n\nexport const createUnauthenticatedClientConfig = ({\n clientConfig,\n}: {\n /**\n * Send the previously generated client config to share memory when applicable.\n * E.g. the admin-enabled collection config can reference the existing collection rather than creating a new object.\n */\n clientConfig: ClientConfig\n}): UnauthenticatedClientConfig => {\n /**\n * To share memory, find the admin user collection from the existing client config.\n */\n const adminUserCollection = clientConfig.collections.find(\n ({ slug }) => slug === clientConfig.admin.user,\n )!\n\n return {\n admin: {\n routes: clientConfig.admin.routes,\n user: clientConfig.admin.user,\n },\n collections: [\n {\n slug: adminUserCollection.slug,\n auth: adminUserCollection.auth,\n },\n ],\n globals: [],\n routes: clientConfig.routes,\n serverURL: clientConfig.serverURL,\n unauthenticated: true,\n }\n}\n\nexport const createClientConfig = ({\n config,\n i18n,\n importMap,\n}: CreateClientConfigArgs): ClientConfig => {\n const clientConfig = {} as DeepPartial<ClientConfig>\n\n for (const key in config) {\n if (serverOnlyConfigProperties.includes(key as any)) {\n continue\n }\n\n switch (key) {\n case 'admin':\n clientConfig.admin = {\n autoLogin: config.admin.autoLogin,\n avatar: config.admin.avatar,\n custom: config.admin.custom,\n dateFormat: config.admin.dateFormat,\n importMap: config.admin.importMap,\n meta: config.admin.meta,\n routes: config.admin.routes,\n theme: config.admin.theme,\n timezones: config.admin.timezones,\n toast: config.admin.toast,\n user: config.admin.user,\n }\n\n if (config.admin.livePreview) {\n clientConfig.admin.livePreview = {}\n\n if (config.admin.livePreview.breakpoints) {\n clientConfig.admin.livePreview.breakpoints = config.admin.livePreview.breakpoints\n }\n\n if (config.admin.livePreview.collections) {\n clientConfig.admin.livePreview.collections = config.admin.livePreview.collections\n }\n\n if (config.admin.livePreview.globals) {\n clientConfig.admin.livePreview.globals = config.admin.livePreview.globals\n }\n }\n\n break\n\n case 'blocks': {\n ;(clientConfig.blocks as ClientBlock[]) = createClientBlocks({\n blocks: config.blocks!,\n defaultIDType: config.db.defaultIDType,\n i18n,\n importMap,\n }).filter((block) => typeof block !== 'string') as ClientBlock[]\n\n clientConfig.blocksMap = {}\n if (clientConfig.blocks?.length) {\n for (const block of clientConfig.blocks) {\n if (!block?.slug) {\n continue\n }\n\n clientConfig.blocksMap[block.slug] = block as ClientBlock\n }\n }\n\n break\n }\n\n case 'collections':\n ;(clientConfig.collections as ClientCollectionConfig[]) = createClientCollectionConfigs({\n collections: config.collections,\n defaultIDType: config.db.defaultIDType,\n i18n,\n importMap,\n })\n\n break\n\n case 'experimental':\n if (config.experimental) {\n clientConfig.experimental = {}\n if (config.experimental?.localizeStatus) {\n clientConfig.experimental.localizeStatus = config.experimental.localizeStatus\n }\n }\n\n break\n\n case 'folders':\n if (config.folders) {\n clientConfig.folders = {\n slug: config.folders.slug,\n browseByFolder: config.folders.browseByFolder,\n debug: config.folders.debug,\n fieldName: config.folders.fieldName,\n }\n }\n\n break\n\n case 'globals':\n ;(clientConfig.globals as ClientGlobalConfig[]) = createClientGlobalConfigs({\n defaultIDType: config.db.defaultIDType,\n globals: config.globals,\n i18n,\n importMap,\n })\n\n break\n\n case 'localization':\n if (typeof config.localization === 'object' && config.localization) {\n clientConfig.localization = {}\n\n if (config.localization.defaultLocale) {\n clientConfig.localization.defaultLocale = config.localization.defaultLocale\n }\n\n if (config.localization.defaultLocalePublishOption) {\n clientConfig.localization.defaultLocalePublishOption =\n config.localization.defaultLocalePublishOption\n }\n\n if (config.localization.fallback) {\n clientConfig.localization.fallback = config.localization.fallback\n }\n\n if (config.localization.localeCodes) {\n clientConfig.localization.localeCodes = config.localization.localeCodes\n }\n\n if (config.localization.locales) {\n clientConfig.localization.locales = []\n\n for (const locale of config.localization.locales) {\n if (locale) {\n const clientLocale: Partial<(typeof config.localization.locales)[0]> = {}\n\n if (locale.code) {\n clientLocale.code = locale.code\n }\n\n if (locale.fallbackLocale) {\n clientLocale.fallbackLocale = locale.fallbackLocale\n }\n\n if (locale.label) {\n clientLocale.label = locale.label\n }\n\n if (locale.rtl) {\n clientLocale.rtl = locale.rtl\n }\n\n clientConfig.localization.locales.push(clientLocale)\n }\n }\n }\n }\n\n break\n\n default:\n ;(clientConfig as any)[key] = config[key as keyof SanitizedConfig]\n }\n }\n\n return clientConfig as ClientConfig\n}\n"],"names":["createClientCollectionConfigs","createClientBlocks","createClientGlobalConfigs","serverOnlyAdminConfigProperties","serverOnlyConfigProperties","createUnauthenticatedClientConfig","clientConfig","adminUserCollection","collections","find","slug","admin","user","routes","auth","globals","serverURL","unauthenticated","createClientConfig","config","i18n","importMap","key","includes","autoLogin","avatar","custom","dateFormat","meta","theme","timezones","toast","livePreview","breakpoints","blocks","defaultIDType","db","filter","block","blocksMap","length","experimental","localizeStatus","folders","browseByFolder","debug","fieldName","localization","defaultLocale","defaultLocalePublishOption","fallback","localeCodes","locales","locale","clientLocale","code","fallbackLocale","label","rtl","push"],"mappings":"AAYA,SAEEA,6BAA6B,QACxB,kCAAiC;AACxC,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAAkCC,yBAAyB,QAAQ,8BAA6B;AAwDhG,OAAO,MAAMC,kCAAqF,EAAE,CAAA;AAEpG,OAAO,MAAMC,6BAA2E;IACtF;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CAED,CAAA;AAiBD,OAAO,MAAMC,oCAAoC,CAAC,EAChDC,YAAY,EAOb;IACC;;GAEC,GACD,MAAMC,sBAAsBD,aAAaE,WAAW,CAACC,IAAI,CACvD,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASJ,aAAaK,KAAK,CAACC,IAAI;IAGhD,OAAO;QACLD,OAAO;YACLE,QAAQP,aAAaK,KAAK,CAACE,MAAM;YACjCD,MAAMN,aAAaK,KAAK,CAACC,IAAI;QAC/B;QACAJ,aAAa;YACX;gBACEE,MAAMH,oBAAoBG,IAAI;gBAC9BI,MAAMP,oBAAoBO,IAAI;YAChC;SACD;QACDC,SAAS,EAAE;QACXF,QAAQP,aAAaO,MAAM;QAC3BG,WAAWV,aAAaU,SAAS;QACjCC,iBAAiB;IACnB;AACF,EAAC;AAED,OAAO,MAAMC,qBAAqB,CAAC,EACjCC,MAAM,EACNC,IAAI,EACJC,SAAS,EACc;IACvB,MAAMf,eAAe,CAAC;IAEtB,IAAK,MAAMgB,OAAOH,OAAQ;QACxB,IAAIf,2BAA2BmB,QAAQ,CAACD,MAAa;YACnD;QACF;QAEA,OAAQA;YACN,KAAK;gBACHhB,aAAaK,KAAK,GAAG;oBACnBa,WAAWL,OAAOR,KAAK,CAACa,SAAS;oBACjCC,QAAQN,OA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,CAACC,aAAa,GAAG7B,OAAO4B,YAAY,CAACC,aAAa;oBAC7E;oBAEA,IAAI7B,OAAO4B,YAAY,CAACE,0BAA0B,EAAE;wBAClD3C,aAAayC,YAAY,CAACE,0BAA0B,GAClD9B,OAAO4B,YAAY,CAACE,0BAA0B;oBAClD;oBAEA,IAAI9B,OAAO4B,YAAY,CAACG,QAAQ,EAAE;wBAChC5C,aAAayC,YAAY,CAACG,QAAQ,GAAG/B,OAAO4B,YAAY,CAACG,QAAQ;oBACnE;oBAEA,IAAI/B,OAAO4B,YAAY,CAACI,WAAW,EAAE;wBACnC7C,aAAayC,YAAY,CAACI,WAAW,GAAGhC,OAAO4B,YAAY,CAACI,WAAW;oBACzE;oBAEA,IAAIhC,OAAO4B,YAAY,CAACK,OAAO,EAAE;wBAC/B9C,aAAayC,YAAY,CAACK,OAAO,GAAG,EAAE;wBAEtC,KAAK,MAAMC,UAAUlC,OAAO4B,YAAY,CAACK,OAAO,CAAE;4BAChD,IAAIC,QAAQ;gCACV,MAAMC,eAAiE,CAAC;gCAExE,IAAID,OAAOE,IAAI,EAAE;oCACfD,aAAaC,IAAI,GAAGF,OAAOE,IAAI;gCACjC;gCAEA,IAAIF,OAAOG,cAAc,EAAE;oCACzBF,aAAaE,cAAc,GAAGH,OAAOG,cAAc;gCACrD;gCAEA,IAAIH,OAAOI,KAAK,EAAE;oCAChBH,aAAaG,KAAK,GAAGJ,OAAOI,KAAK;gCACnC;gCAEA,IAAIJ,OAAOK,GAAG,EAAE;oCACdJ,aAAaI,GAAG,GAAGL,OAAOK,GAAG;gCAC/B;gCAEApD,aAAayC,YAAY,CAACK,OAAO,CAACO,IAAI,CAACL;4BACzC;wBACF;oBACF;gBACF;gBAEA;YAEF;;gBACIhD,YAAoB,CAACgB,IAAI,GAAGH,MAAM,CAACG,IAA6B;QACtE;IACF;IAEA,OAAOhB;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/config/client.ts"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type { DeepPartial } from 'ts-essentials'\n\nimport type { ImportMap } from '../bin/generateImportMap/index.js'\nimport type { ClientBlock } from '../fields/config/types.js'\nimport type { BlockSlug, TypedUser } from '../index.js'\nimport type {\n RootLivePreviewConfig,\n SanitizedConfig,\n ServerOnlyLivePreviewProperties,\n} from './types.js'\n\nimport {\n type ClientCollectionConfig,\n createClientCollectionConfigs,\n} from '../collections/config/client.js'\nimport { createClientBlocks } from '../fields/config/client.js'\nimport { type ClientGlobalConfig, createClientGlobalConfigs } from '../globals/config/client.js'\n\nexport type ServerOnlyRootProperties = keyof Pick<\n SanitizedConfig,\n | 'bin'\n | 'cors'\n | 'csrf'\n | 'custom'\n | 'db'\n | 'editor'\n | 'email'\n | 'endpoints'\n | 'graphQL'\n | 'hooks'\n | 'i18n'\n | 'jobs'\n | 'logger'\n | 'onInit'\n | 'plugins'\n | 'queryPresets'\n | 'secret'\n | 'sharp'\n | 'typescript'\n>\n\nexport type ServerOnlyRootAdminProperties = keyof Pick<SanitizedConfig['admin'], 'components'>\n\nexport type ClientConfig = {\n admin: {\n livePreview?: Omit<RootLivePreviewConfig, ServerOnlyLivePreviewProperties>\n } & Omit<SanitizedConfig['admin'], 'components' | 'dependencies' | 'livePreview'>\n blocks: ClientBlock[]\n blocksMap: Record<BlockSlug, ClientBlock>\n collections: ClientCollectionConfig[]\n custom?: Record<string, any>\n globals: ClientGlobalConfig[]\n unauthenticated?: boolean\n} & Omit<SanitizedConfig, 'admin' | 'collections' | 'globals' | 'i18n' | ServerOnlyRootProperties>\n\nexport type UnauthenticatedClientConfig = {\n admin: {\n routes: ClientConfig['admin']['routes']\n user: ClientConfig['admin']['user']\n }\n collections: [ClientCollectionConfig]\n globals: []\n routes: ClientConfig['routes']\n serverURL: ClientConfig['serverURL']\n unauthenticated: true\n}\n\nexport const serverOnlyAdminConfigProperties: readonly Partial<ServerOnlyRootAdminProperties>[] = []\n\nexport const serverOnlyConfigProperties: readonly Partial<ServerOnlyRootProperties>[] = [\n 'endpoints',\n 'db',\n 'editor',\n 'plugins',\n 'sharp',\n 'onInit',\n 'secret',\n 'hooks',\n 'bin',\n 'i18n',\n 'typescript',\n 'cors',\n 'csrf',\n 'email',\n 'custom',\n 'graphQL',\n 'jobs',\n 'logger',\n 'queryPresets',\n // `admin`, `onInit`, `localization`, `collections`, and `globals` are all handled separately\n]\n\nexport type CreateClientConfigArgs = {\n config: SanitizedConfig\n i18n: I18nClient\n importMap: ImportMap\n /**\n * If unauthenticated, the client config will omit some sensitive properties\n * such as field schemas, etc. This is useful for login and error pages where\n * the page source should not contain this information.\n * Allow `true` to generate a client config for the \"create first user\" page\n * where there is no user yet, but the config should be as complete.\n */\n user: true | TypedUser\n}\n\nexport const createUnauthenticatedClientConfig = ({\n clientConfig,\n}: {\n /**\n * Send the previously generated client config to share memory when applicable.\n * E.g. the admin-enabled collection config can reference the existing collection rather than creating a new object.\n */\n clientConfig: ClientConfig\n}): UnauthenticatedClientConfig => {\n return {\n admin: {\n routes: clientConfig.admin.routes,\n user: clientConfig.admin.user,\n },\n collections: [clientConfig.collections.find(({ slug }) => slug === clientConfig.admin.user)!],\n globals: [],\n routes: clientConfig.routes,\n serverURL: clientConfig.serverURL,\n unauthenticated: true,\n }\n}\n\nexport const createClientConfig = ({\n config,\n i18n,\n importMap,\n}: CreateClientConfigArgs): ClientConfig => {\n const clientConfig = {} as DeepPartial<ClientConfig>\n\n for (const key in config) {\n if (serverOnlyConfigProperties.includes(key as any)) {\n continue\n }\n\n switch (key) {\n case 'admin':\n clientConfig.admin = {\n autoLogin: config.admin.autoLogin,\n avatar: config.admin.avatar,\n custom: config.admin.custom,\n dateFormat: config.admin.dateFormat,\n importMap: config.admin.importMap,\n meta: config.admin.meta,\n routes: config.admin.routes,\n theme: config.admin.theme,\n timezones: config.admin.timezones,\n toast: config.admin.toast,\n user: config.admin.user,\n }\n\n if (config.admin.livePreview) {\n clientConfig.admin.livePreview = {}\n\n if (config.admin.livePreview.breakpoints) {\n clientConfig.admin.livePreview.breakpoints = config.admin.livePreview.breakpoints\n }\n\n if (config.admin.livePreview.collections) {\n clientConfig.admin.livePreview.collections = config.admin.livePreview.collections\n }\n\n if (config.admin.livePreview.globals) {\n clientConfig.admin.livePreview.globals = config.admin.livePreview.globals\n }\n }\n\n break\n\n case 'blocks': {\n ;(clientConfig.blocks as ClientBlock[]) = createClientBlocks({\n blocks: config.blocks!,\n defaultIDType: config.db.defaultIDType,\n i18n,\n importMap,\n }).filter((block) => typeof block !== 'string') as ClientBlock[]\n\n clientConfig.blocksMap = {}\n if (clientConfig.blocks?.length) {\n for (const block of clientConfig.blocks) {\n if (!block?.slug) {\n continue\n }\n\n clientConfig.blocksMap[block.slug] = block as ClientBlock\n }\n }\n\n break\n }\n\n case 'collections':\n ;(clientConfig.collections as ClientCollectionConfig[]) = createClientCollectionConfigs({\n collections: config.collections,\n defaultIDType: config.db.defaultIDType,\n i18n,\n importMap,\n })\n\n break\n\n case 'experimental':\n if (config.experimental) {\n clientConfig.experimental = {}\n if (config.experimental?.localizeStatus) {\n clientConfig.experimental.localizeStatus = config.experimental.localizeStatus\n }\n }\n\n break\n\n case 'folders':\n if (config.folders) {\n clientConfig.folders = {\n slug: config.folders.slug,\n browseByFolder: config.folders.browseByFolder,\n debug: config.folders.debug,\n fieldName: config.folders.fieldName,\n }\n }\n\n break\n\n case 'globals':\n ;(clientConfig.globals as ClientGlobalConfig[]) = createClientGlobalConfigs({\n defaultIDType: config.db.defaultIDType,\n globals: config.globals,\n i18n,\n importMap,\n })\n\n break\n\n case 'localization':\n if (typeof config.localization === 'object' && config.localization) {\n clientConfig.localization = {}\n\n if (config.localization.defaultLocale) {\n clientConfig.localization.defaultLocale = config.localization.defaultLocale\n }\n\n if (config.localization.defaultLocalePublishOption) {\n clientConfig.localization.defaultLocalePublishOption =\n config.localization.defaultLocalePublishOption\n }\n\n if (config.localization.fallback) {\n clientConfig.localization.fallback = config.localization.fallback\n }\n\n if (config.localization.localeCodes) {\n clientConfig.localization.localeCodes = config.localization.localeCodes\n }\n\n if (config.localization.locales) {\n clientConfig.localization.locales = []\n\n for (const locale of config.localization.locales) {\n if (locale) {\n const clientLocale: Partial<(typeof config.localization.locales)[0]> = {}\n\n if (locale.code) {\n clientLocale.code = locale.code\n }\n\n if (locale.fallbackLocale) {\n clientLocale.fallbackLocale = locale.fallbackLocale\n }\n\n if (locale.label) {\n clientLocale.label = locale.label\n }\n\n if (locale.rtl) {\n clientLocale.rtl = locale.rtl\n }\n\n clientConfig.localization.locales.push(clientLocale)\n }\n }\n }\n }\n\n break\n\n default:\n ;(clientConfig as any)[key] = config[key as keyof SanitizedConfig]\n }\n }\n\n return clientConfig as ClientConfig\n}\n"],"names":["createClientCollectionConfigs","createClientBlocks","createClientGlobalConfigs","serverOnlyAdminConfigProperties","serverOnlyConfigProperties","createUnauthenticatedClientConfig","clientConfig","admin","routes","user","collections","find","slug","globals","serverURL","unauthenticated","createClientConfig","config","i18n","importMap","key","includes","autoLogin","avatar","custom","dateFormat","meta","theme","timezones","toast","livePreview","breakpoints","blocks","defaultIDType","db","filter","block","blocksMap","length","experimental","localizeStatus","folders","browseByFolder","debug","fieldName","localization","defaultLocale","defaultLocalePublishOption","fallback","localeCodes","locales","locale","clientLocale","code","fallbackLocale","label","rtl","push"],"mappings":"AAYA,SAEEA,6BAA6B,QACxB,kCAAiC;AACxC,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAAkCC,yBAAyB,QAAQ,8BAA6B;AAmDhG,OAAO,MAAMC,kCAAqF,EAAE,CAAA;AAEpG,OAAO,MAAMC,6BAA2E;IACtF;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CAED,CAAA;AAgBD,OAAO,MAAMC,oCAAoC,CAAC,EAChDC,YAAY,EAOb;IACC,OAAO;QACLC,OAAO;YACLC,QAAQF,aAAaC,KAAK,CAACC,MAAM;YACjCC,MAAMH,aAAaC,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AAI,EAAE;oCACfD,aAAaC,IAAI,GAAGF,OAAOE,IAAI;gCACjC;gCAEA,IAAIF,OAAOG,cAAc,EAAE;oCACzBF,aAAaE,cAAc,GAAGH,OAAOG,cAAc;gCACrD;gCAEA,IAAIH,OAAOI,KAAK,EAAE;oCAChBH,aAAaG,KAAK,GAAGJ,OAAOI,KAAK;gCACnC;gCAEA,IAAIJ,OAAOK,GAAG,EAAE;oCACdJ,aAAaI,GAAG,GAAGL,OAAOK,GAAG;gCAC/B;gCAEAlD,aAAauC,YAAY,CAACK,OAAO,CAACO,IAAI,CAACL;4BACzC;wBACF;oBACF;gBACF;gBAEA;YAEF;;gBACI9C,YAAoB,CAACc,IAAI,GAAGH,MAAM,CAACG,IAA6B;QACtE;IACF;IAEA,OAAOd;AACT,EAAC"}
|
|
@@ -2,7 +2,7 @@ import type { SanitizedCollectionConfig } from '../../../collections/config/type
|
|
|
2
2
|
import type { SanitizedGlobalConfig } from '../../../globals/config/types.js';
|
|
3
3
|
import type { RequestContext } from '../../../index.js';
|
|
4
4
|
import type { JsonObject, PayloadRequest, PopulateType, SelectType } from '../../../types/index.js';
|
|
5
|
-
type
|
|
5
|
+
export type AfterReadArgs<T extends JsonObject> = {
|
|
6
6
|
collection: null | SanitizedCollectionConfig;
|
|
7
7
|
context: RequestContext;
|
|
8
8
|
currentDepth?: number;
|
|
@@ -11,6 +11,12 @@ type Args<T extends JsonObject> = {
|
|
|
11
11
|
draft: boolean;
|
|
12
12
|
fallbackLocale: null | string;
|
|
13
13
|
findMany?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Controls whether locales should be flattened into the requested locale.
|
|
16
|
+
* E.g.: { [locale]: fields } -> fields
|
|
17
|
+
*
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
14
20
|
flattenLocales?: boolean;
|
|
15
21
|
global: null | SanitizedGlobalConfig;
|
|
16
22
|
locale: string;
|
|
@@ -29,6 +35,5 @@ type Args<T extends JsonObject> = {
|
|
|
29
35
|
* - Execute read access control
|
|
30
36
|
* - Populate relationships
|
|
31
37
|
*/
|
|
32
|
-
export declare function afterRead<T extends JsonObject>(args:
|
|
33
|
-
export {};
|
|
38
|
+
export declare function afterRead<T extends JsonObject>(args: AfterReadArgs<T>): Promise<T>;
|
|
34
39
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAKnG,
|
|
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,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAKnG,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,UAAU,IAAI;IAChD,UAAU,EAAE,IAAI,GAAG,yBAAyB,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,CAAC,CAAA;IACN,KAAK,EAAE,OAAO,CAAA;IACd,cAAc,EAAE,IAAI,GAAG,MAAM,CAAA;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,MAAM,EAAE,IAAI,GAAG,qBAAqB,CAAA;IACpC,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,gBAAgB,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED;;;;;;;;GAQG;AAEH,wBAAsB,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAmFxF"}
|
|
@@ -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 { RequestContext } from '../../../index.js'\nimport type { JsonObject, PayloadRequest, PopulateType, SelectType } from '../../../types/index.js'\n\nimport { getSelectMode } from '../../../utilities/getSelectMode.js'\nimport { traverseFields } from './traverseFields.js'\n\
|
|
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 { RequestContext } from '../../../index.js'\nimport type { JsonObject, PayloadRequest, PopulateType, SelectType } from '../../../types/index.js'\n\nimport { getSelectMode } from '../../../utilities/getSelectMode.js'\nimport { traverseFields } from './traverseFields.js'\n\nexport type AfterReadArgs<T extends JsonObject> = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n currentDepth?: number\n depth: number\n doc: T\n draft: boolean\n fallbackLocale: null | string\n findMany?: boolean\n /**\n * Controls whether locales should be flattened into the requested locale.\n * E.g.: { [locale]: fields } -> fields\n *\n * @default true\n */\n flattenLocales?: boolean\n global: null | SanitizedGlobalConfig\n locale: string\n overrideAccess: boolean\n populate?: PopulateType\n req: PayloadRequest\n select?: SelectType\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 extends JsonObject>(args: AfterReadArgs<T>): 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 populate,\n req,\n select,\n showHiddenFields,\n } = args\n\n const fieldPromises: Promise<void>[] = []\n const populationPromises: Promise<void>[] = []\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) {\n depth = req.payload.config.maxDepth\n }\n\n const currentDepth = incomingCurrentDepth || 1\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc: incomingDoc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: (collection?.fields || global?.fields)!,\n findMany: findMany!,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: '',\n parentIsLocalized: false,\n parentPath: '',\n parentSchemaPath: '',\n populate,\n populationPromises,\n req,\n select,\n selectMode: select ? getSelectMode(select) : undefined,\n showHiddenFields,\n siblingDoc: incomingDoc,\n })\n\n /**\n * Await all field and population promises in parallel.\n * A field promise is able to add more field promises to the fieldPromises array, which will not be\n * awaited in the first run.\n * This is why we need to loop again to process the new field promises, until there are no more field promises left.\n */\n let iterations = 0\n while (fieldPromises.length > 0 || populationPromises.length > 0) {\n const currentFieldPromises = fieldPromises.splice(0, fieldPromises.length)\n const currentPopulationPromises = populationPromises.splice(0, populationPromises.length)\n\n await Promise.all(currentFieldPromises)\n await Promise.all(currentPopulationPromises)\n\n iterations++\n if (iterations >= 100) {\n throw new Error(\n 'Infinite afterRead promise loop detected. A hook is likely adding field promises in an infinitely recursive way.',\n )\n }\n }\n return incomingDoc\n}\n"],"names":["getSelectMode","traverseFields","afterRead","args","collection","context","currentDepth","incomingCurrentDepth","depth","incomingDepth","doc","incomingDoc","draft","fallbackLocale","findMany","flattenLocales","global","locale","overrideAccess","populate","req","select","showHiddenFields","fieldPromises","populationPromises","parseInt","String","payload","config","defaultDepth","maxDepth","fields","parentIndexPath","parentIsLocalized","parentPath","parentSchemaPath","selectMode","undefined","siblingDoc","iterations","length","currentFieldPromises","splice","currentPopulationPromises","Promise","all","Error"],"mappings":"AAKA,SAASA,aAAa,QAAQ,sCAAqC;AACnE,SAASC,cAAc,QAAQ,sBAAqB;AA2BpD;;;;;;;;CAQC,GAED,OAAO,eAAeC,UAAgCC,IAAsB;IAC1E,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,QAAQ,EACRC,GAAG,EACHC,MAAM,EACNC,gBAAgB,EACjB,GAAGnB;IAEJ,MAAMoB,gBAAiC,EAAE;IACzC,MAAMC,qBAAsC,EAAE;IAE9C,IAAIhB,QACFC,iBAAiBA,kBAAkB,IAC/BgB,SAASC,OAAOjB,gBAAgB,MAChCW,IAAIO,OAAO,CAACC,MAAM,CAACC,YAAY;IACrC,IAAIrB,QAAQY,IAAIO,OAAO,CAACC,MAAM,CAACE,QAAQ,EAAE;QACvCtB,QAAQY,IAAIO,OAAO,CAACC,MAAM,CAACE,QAAQ;IACrC;IAEA,MAAMxB,eAAeC,wBAAwB;IAE7CN,eAAe;QACbG;QACAC;QACAC;QACAE;QACAE,KAAKC;QACLC;QACAC;QACAU;QACAQ,QAAS3B,YAAY2B,UAAUf,QAAQe;QACvCjB,UAAUA;QACVC;QACAC;QACAC;QACAC;QACAc,iBAAiB;QACjBC,mBAAmB;QACnBC,YAAY;QACZC,kBAAkB;QAClBhB;QACAK;QACAJ;QACAC;QACAe,YAAYf,SAASrB,cAAcqB,UAAUgB;QAC7Cf;QACAgB,YAAY3B;IACd;IAEA;;;;;GAKC,GACD,IAAI4B,aAAa;IACjB,MAAOhB,cAAciB,MAAM,GAAG,KAAKhB,mBAAmBgB,MAAM,GAAG,EAAG;QAChE,MAAMC,uBAAuBlB,cAAcmB,MAAM,CAAC,GAAGnB,cAAciB,MAAM;QACzE,MAAMG,4BAA4BnB,mBAAmBkB,MAAM,CAAC,GAAGlB,mBAAmBgB,MAAM;QAExF,MAAMI,QAAQC,GAAG,CAACJ;QAClB,MAAMG,QAAQC,GAAG,CAACF;QAElBJ;QACA,IAAIA,cAAc,KAAK;YACrB,MAAM,IAAIO,MACR;QAEJ;IACF;IACA,OAAOnC;AACT"}
|
|
@@ -2,6 +2,7 @@ import type { SanitizedCollectionConfig } from '../../../collections/config/type
|
|
|
2
2
|
import type { SanitizedGlobalConfig } from '../../../globals/config/types.js';
|
|
3
3
|
import type { JsonObject, PayloadRequest, PopulateType, SelectMode, SelectType } from '../../../types/index.js';
|
|
4
4
|
import type { Field, TabAsField } from '../../config/types.js';
|
|
5
|
+
import type { AfterReadArgs } from './index.js';
|
|
5
6
|
import { type RequestContext } from '../../../index.js';
|
|
6
7
|
type Args = {
|
|
7
8
|
/**
|
|
@@ -22,7 +23,6 @@ type Args = {
|
|
|
22
23
|
*/
|
|
23
24
|
fieldPromises: Promise<void>[];
|
|
24
25
|
findMany: boolean;
|
|
25
|
-
flattenLocales: boolean;
|
|
26
26
|
global: null | SanitizedGlobalConfig;
|
|
27
27
|
locale: null | string;
|
|
28
28
|
overrideAccess: boolean;
|
|
@@ -43,7 +43,7 @@ type Args = {
|
|
|
43
43
|
siblingFields?: (Field | TabAsField)[];
|
|
44
44
|
triggerAccessControl?: boolean;
|
|
45
45
|
triggerHooks?: boolean;
|
|
46
|
-
}
|
|
46
|
+
} & Required<Pick<AfterReadArgs<JsonObject>, 'flattenLocales'>>;
|
|
47
47
|
export declare const promise: ({ blockData, collection, context, currentDepth, depth, doc, draft, fallbackLocale, field, fieldIndex, fieldPromises, findMany, flattenLocales, global, locale, overrideAccess, parentIndexPath, parentIsLocalized, parentPath, parentSchemaPath, populate, populationPromises, req, select, selectMode, showHiddenFields, siblingDoc, siblingFields, triggerAccessControl, triggerHooks, }: Args) => Promise<void>;
|
|
48
48
|
export {};
|
|
49
49
|
//# sourceMappingURL=promise.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/promise.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,YAAY,EACZ,UAAU,EACV,UAAU,EACX,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAS,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/promise.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,YAAY,EACZ,UAAU,EACV,UAAU,EACX,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAS,KAAK,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AC,EAAE,OAAO,CAAA;IAC9B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAA;AAU/D,eAAO,MAAM,OAAO,+XA+BjB,IAAI,KAAG,OAAO,CAAC,IAAI,CAuxBrB,CAAA"}
|
|
@@ -122,14 +122,19 @@ export const promise = async ({ blockData, collection, context, currentDepth, de
|
|
|
122
122
|
break;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
+
// If locale is `all`, siblingDoc[field.name] will be an object mapping locales to values - locales won't be flattened.
|
|
126
|
+
// In this case, run the hook for each locale and value pair
|
|
127
|
+
const shouldRunHookOnAllLocales = locale === 'all' && 'name' in field && typeof field.name === 'string' && // If localized values were hoisted, siblingDoc[field.name] will not be an object mapping locales to values
|
|
128
|
+
// => Object.entries(siblingDoc[field.name]) will be the value of a single locale, not all locales
|
|
129
|
+
// => do not run the hook for each locale
|
|
130
|
+
!shouldHoistLocalizedValue && fieldShouldBeLocalized({
|
|
131
|
+
field,
|
|
132
|
+
parentIsLocalized: parentIsLocalized
|
|
133
|
+
}) && typeof siblingDoc[field.name] === 'object';
|
|
125
134
|
if (fieldAffectsDataResult) {
|
|
126
135
|
// Execute hooks
|
|
127
136
|
if (triggerHooks && 'hooks' in field && field.hooks?.afterRead) {
|
|
128
137
|
for (const hook of field.hooks.afterRead){
|
|
129
|
-
const shouldRunHookOnAllLocales = fieldShouldBeLocalized({
|
|
130
|
-
field,
|
|
131
|
-
parentIsLocalized: parentIsLocalized
|
|
132
|
-
}) && (locale === 'all' || !flattenLocales) && typeof siblingDoc[field.name] === 'object';
|
|
133
138
|
if (shouldRunHookOnAllLocales) {
|
|
134
139
|
const localesAndValues = Object.entries(siblingDoc[field.name]);
|
|
135
140
|
await Promise.all(localesAndValues.map(async ([localeKey, value])=>{
|
|
@@ -547,10 +552,6 @@ export const promise = async ({ blockData, collection, context, currentDepth, de
|
|
|
547
552
|
const editor = field?.editor;
|
|
548
553
|
if (editor?.hooks?.afterRead?.length) {
|
|
549
554
|
for (const hook of editor.hooks.afterRead){
|
|
550
|
-
const shouldRunHookOnAllLocales = fieldShouldBeLocalized({
|
|
551
|
-
field,
|
|
552
|
-
parentIsLocalized: parentIsLocalized
|
|
553
|
-
}) && (locale === 'all' || !flattenLocales) && typeof siblingDoc[field.name] === 'object';
|
|
554
555
|
if (shouldRunHookOnAllLocales) {
|
|
555
556
|
const localesAndValues = Object.entries(siblingDoc[field.name]);
|
|
556
557
|
await Promise.all(localesAndValues.map(async ([locale, value])=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/afterRead/promise.ts"],"sourcesContent":["import type { RichTextAdapter } from '../../../admin/RichText.js'\nimport type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type {\n JsonObject,\n PayloadRequest,\n PopulateType,\n SelectMode,\n SelectType,\n} from '../../../types/index.js'\nimport type { Block, Field, TabAsField } from '../../config/types.js'\n\nimport { MissingEditorProp } from '../../../errors/index.js'\nimport { type RequestContext } from '../../../index.js'\nimport { getBlockSelect } from '../../../utilities/getBlockSelect.js'\nimport { stripUnselectedFields } from '../../../utilities/stripUnselectedFields.js'\nimport { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../../config/types.js'\nimport { getDefaultValue } from '../../getDefaultValue.js'\nimport { getFieldPathsModified as getFieldPaths } from '../../getFieldPaths.js'\nimport { relationshipPopulationPromise } from './relationshipPopulationPromise.js'\nimport { traverseFields } from './traverseFields.js'\nimport { virtualFieldPopulationPromise } from './virtualFieldPopulationPromise.js'\n\ntype Args = {\n /**\n * Data of the nearest parent block. If no parent block exists, this will be the `undefined`\n */\n blockData?: JsonObject\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n currentDepth: number\n depth: number\n doc: JsonObject\n draft: boolean\n fallbackLocale: null | string\n field: Field | TabAsField\n fieldIndex: number\n /**\n * fieldPromises are used for things like field hooks. They should be awaited before awaiting populationPromises\n */\n fieldPromises: Promise<void>[]\n findMany: boolean\n flattenLocales: boolean\n global: null | SanitizedGlobalConfig\n locale: null | string\n overrideAccess: boolean\n parentIndexPath: string\n /**\n * @todo make required in v4.0\n */\n parentIsLocalized?: boolean\n parentPath: string\n parentSchemaPath: string\n populate?: PopulateType\n populationPromises: Promise<void>[]\n req: PayloadRequest\n select?: SelectType\n selectMode?: SelectMode\n showHiddenFields: boolean\n siblingDoc: JsonObject\n siblingFields?: (Field | TabAsField)[]\n triggerAccessControl?: boolean\n triggerHooks?: boolean\n}\n\n// This function is responsible for the following actions, in order:\n// - Remove hidden fields from response\n// - Flatten locales into requested locale\n// - Sanitize outgoing data (point field, etc.)\n// - Execute field hooks\n// - Execute read access control\n// - Populate relationships\n\nexport const promise = async ({\n blockData,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n field,\n fieldIndex,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath,\n parentIsLocalized,\n parentPath,\n parentSchemaPath,\n populate,\n populationPromises,\n req,\n select,\n selectMode,\n showHiddenFields,\n siblingDoc,\n siblingFields,\n triggerAccessControl = true,\n triggerHooks = true,\n}: Args): Promise<void> => {\n const { indexPath, path, schemaPath } = getFieldPaths({\n field,\n index: fieldIndex,\n parentIndexPath,\n parentPath,\n parentSchemaPath,\n })\n\n const fieldAffectsDataResult = fieldAffectsData(field)\n const pathSegments = path ? path.split('.') : []\n const schemaPathSegments = schemaPath ? schemaPath.split('.') : []\n const indexPathSegments = indexPath ? indexPath.split('-').filter(Boolean)?.map(Number) : []\n let removedFieldValue = false\n\n if (\n fieldAffectsDataResult &&\n field.hidden &&\n typeof siblingDoc[field.name!] !== 'undefined' &&\n !showHiddenFields\n ) {\n removedFieldValue = true\n delete siblingDoc[field.name!]\n }\n\n if (path !== 'id') {\n const shouldContinue = stripUnselectedFields({\n field,\n select: select!,\n selectMode: selectMode!,\n siblingDoc,\n })\n\n if (!shouldContinue) {\n return\n }\n }\n\n const shouldHoistLocalizedValue: boolean = Boolean(\n flattenLocales &&\n fieldAffectsDataResult &&\n typeof siblingDoc[field.name!] === 'object' &&\n siblingDoc[field.name!] !== null &&\n fieldShouldBeLocalized({ field, parentIsLocalized: parentIsLocalized! }) &&\n locale !== 'all' &&\n req.payload.config.localization,\n )\n\n if (fieldAffectsDataResult && shouldHoistLocalizedValue) {\n // replace actual value with localized value before sanitizing\n // { [locale]: fields } -> fields\n const value = siblingDoc[field.name!][locale!]\n\n let hoistedValue = value\n\n if (fallbackLocale && fallbackLocale !== locale) {\n const fallbackValue = siblingDoc[field.name!][fallbackLocale]\n const isNullOrUndefined = typeof value === 'undefined' || value === null\n\n if (fallbackValue) {\n switch (field.type) {\n case 'text':\n case 'textarea': {\n if (value === '' || isNullOrUndefined) {\n hoistedValue = fallbackValue\n }\n break\n }\n\n default: {\n if (isNullOrUndefined) {\n hoistedValue = fallbackValue\n }\n break\n }\n }\n }\n }\n\n siblingDoc[field.name!] = hoistedValue\n }\n\n // Sanitize outgoing field value\n switch (field.type) {\n case 'group': {\n // Fill groups with empty objects so fields with hooks within groups can populate\n // themselves virtually as necessary\n if (fieldAffectsDataResult && typeof siblingDoc[field.name] === 'undefined') {\n siblingDoc[field.name] = {}\n }\n\n break\n }\n case 'point': {\n const pointDoc = siblingDoc[field.name] as Record<string, unknown>\n if (Array.isArray(pointDoc?.coordinates) && pointDoc.coordinates.length === 2) {\n siblingDoc[field.name] = pointDoc.coordinates\n } else {\n siblingDoc[field.name] = undefined\n }\n\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n if (typeof field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n // Rich Text fields should use afterRead hooks to do population. The previous editor.populationPromises have been renamed to editor.graphQLPopulationPromises\n break\n }\n\n case 'tabs': {\n field.tabs.forEach((tab) => {\n if (\n tabHasName(tab) &&\n (typeof siblingDoc[tab.name] === 'undefined' || siblingDoc[tab.name] === null)\n ) {\n siblingDoc[tab.name] = {}\n }\n })\n\n break\n }\n\n default: {\n break\n }\n }\n\n if (fieldAffectsDataResult) {\n // Execute hooks\n if (triggerHooks && 'hooks' in field && field.hooks?.afterRead) {\n for (const hook of field.hooks.afterRead) {\n const shouldRunHookOnAllLocales =\n fieldShouldBeLocalized({ field, parentIsLocalized: parentIsLocalized! }) &&\n (locale === 'all' || !flattenLocales) &&\n typeof siblingDoc[field.name] === 'object'\n\n if (shouldRunHookOnAllLocales) {\n const localesAndValues = Object.entries(siblingDoc[field.name])\n await Promise.all(\n localesAndValues.map(async ([localeKey, value]) => {\n const hookedValue = await hook({\n blockData,\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n field,\n findMany,\n global,\n indexPath: indexPathSegments,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n path: pathSegments,\n req,\n schemaPath: schemaPathSegments,\n showHiddenFields,\n siblingData: siblingDoc,\n siblingFields: siblingFields!,\n value,\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name][localeKey] = hookedValue\n }\n }),\n )\n } else {\n const hookedValue = await hook({\n blockData,\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n field,\n findMany,\n global,\n indexPath: indexPathSegments,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n path: pathSegments,\n req,\n schemaPath: schemaPathSegments,\n showHiddenFields,\n siblingData: siblingDoc,\n siblingFields: siblingFields!,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }\n }\n }\n\n if (\n 'virtual' in field &&\n typeof field.virtual === 'string' &&\n (!field.hidden || showHiddenFields)\n ) {\n populationPromises.push(\n virtualFieldPopulationPromise({\n name: field.name,\n draft,\n fallbackLocale: fallbackLocale!,\n fields: (collection || global)!.flattenedFields,\n locale: locale!,\n overrideAccess,\n ref: doc,\n req,\n segments: field.virtual.split('.'),\n showHiddenFields,\n siblingDoc,\n }),\n )\n }\n\n // Execute access control\n let allowDefaultValue = true\n if (triggerAccessControl && field.access && field.access.read) {\n const canReadField = overrideAccess\n ? true\n : await field.access.read({\n id: doc.id as number | string,\n blockData,\n data: doc,\n doc,\n req,\n siblingData: siblingDoc,\n })\n\n if (!canReadField) {\n allowDefaultValue = false\n delete siblingDoc[field.name!]\n }\n }\n\n // Set defaultValue on the field for globals being returned without being first created\n // or collection documents created prior to having a default\n if (\n !removedFieldValue &&\n allowDefaultValue &&\n typeof siblingDoc[field.name!] === 'undefined' &&\n typeof field.defaultValue !== 'undefined'\n ) {\n siblingDoc[field.name!] = await getDefaultValue({\n defaultValue: field.defaultValue,\n locale: locale!,\n req,\n user: req.user,\n value: siblingDoc[field.name!],\n })\n }\n\n if (field.type === 'relationship' || field.type === 'upload' || field.type === 'join') {\n populationPromises.push(\n relationshipPopulationPromise({\n currentDepth,\n depth,\n draft,\n fallbackLocale,\n field,\n locale,\n overrideAccess,\n parentIsLocalized: parentIsLocalized!,\n populate,\n req,\n showHiddenFields,\n siblingDoc,\n }),\n )\n }\n }\n\n switch (field.type) {\n case 'array': {\n const rows = siblingDoc[field.name] as JsonObject\n\n let arraySelect = select?.[field.name]\n\n if (selectMode === 'include' && typeof arraySelect === 'object') {\n arraySelect = {\n ...arraySelect,\n id: true,\n }\n }\n\n if (Array.isArray(rows) && rows.length > 0) {\n rows.forEach((row, rowIndex) => {\n traverseFields({\n blockData,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: '',\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: path + '.' + rowIndex,\n parentSchemaPath: schemaPath,\n populate,\n populationPromises,\n req,\n select: typeof arraySelect === 'object' ? arraySelect : undefined,\n selectMode,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n })\n } else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {\n Object.values(rows).forEach((localeRows) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, rowIndex) => {\n traverseFields({\n blockData,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: '',\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: path + '.' + rowIndex,\n parentSchemaPath: schemaPath,\n populate,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: (row as JsonObject) || {},\n triggerAccessControl,\n triggerHooks,\n })\n })\n }\n })\n } else if (shouldHoistLocalizedValue && (!rows || rows.length === 0)) {\n siblingDoc[field.name] = null\n } else if (field.hidden !== true || showHiddenFields === true) {\n siblingDoc[field.name] = []\n }\n break\n }\n\n case 'blocks': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows) && rows.length > 0) {\n rows.forEach((row, rowIndex) => {\n const blockTypeToMatch = (row as JsonObject).blockType\n\n const block: Block | undefined =\n req.payload.blocks[blockTypeToMatch] ??\n ((field.blockReferences ?? field.blocks).find(\n (curBlock) => typeof curBlock !== 'string' && curBlock.slug === blockTypeToMatch,\n ) as Block | undefined)\n\n const { blockSelect, blockSelectMode } = getBlockSelect({\n block: block!,\n // TODO: fix this\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n select: select?.[field.name]!,\n selectMode: selectMode!,\n })\n\n if (block) {\n traverseFields({\n blockData: row,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: block.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: '',\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: path + '.' + rowIndex,\n parentSchemaPath: schemaPath + '.' + block.slug,\n populate,\n populationPromises,\n req,\n select: typeof blockSelect === 'object' ? blockSelect : undefined,\n selectMode: blockSelectMode,\n showHiddenFields,\n siblingDoc: (row as JsonObject) || {},\n triggerAccessControl,\n triggerHooks,\n })\n }\n })\n } else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {\n Object.values(rows).forEach((localeRows) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, rowIndex) => {\n const blockTypeToMatch = row.blockType\n\n const block: Block | undefined =\n req.payload.blocks[blockTypeToMatch] ??\n ((field.blockReferences ?? field.blocks).find(\n (curBlock) => typeof curBlock !== 'string' && curBlock.slug === blockTypeToMatch,\n ) as Block | undefined)\n\n if (block) {\n traverseFields({\n blockData: row,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: block.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: '',\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: path + '.' + rowIndex,\n parentSchemaPath: schemaPath + '.' + block.slug,\n populate,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: (row as JsonObject) || {},\n triggerAccessControl,\n triggerHooks,\n })\n }\n })\n }\n })\n } else if (shouldHoistLocalizedValue && (!rows || rows.length === 0)) {\n siblingDoc[field.name] = null\n } else if (field.hidden !== true || showHiddenFields === true) {\n siblingDoc[field.name] = []\n }\n\n break\n }\n\n case 'collapsible':\n case 'row': {\n traverseFields({\n blockData,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: indexPath,\n parentIsLocalized,\n parentPath,\n parentSchemaPath: schemaPath,\n populate,\n populationPromises,\n req,\n select,\n selectMode,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'group': {\n if (fieldAffectsDataResult) {\n let groupDoc = siblingDoc[field.name] as JsonObject\n\n if (typeof siblingDoc[field.name] !== 'object') {\n groupDoc = {}\n }\n\n const groupSelect = select?.[field.name]\n\n traverseFields({\n blockData,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: '',\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: path,\n parentSchemaPath: schemaPath,\n populate,\n populationPromises,\n req,\n select: typeof groupSelect === 'object' ? groupSelect : undefined,\n selectMode,\n showHiddenFields,\n siblingDoc: groupDoc,\n triggerAccessControl,\n triggerHooks,\n })\n } else {\n traverseFields({\n blockData,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: indexPath,\n parentIsLocalized,\n parentPath,\n parentSchemaPath: schemaPath,\n populate,\n populationPromises,\n req,\n select,\n selectMode,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n }\n\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n\n if (typeof field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n const editor: RichTextAdapter = field?.editor\n\n if (editor?.hooks?.afterRead?.length) {\n for (const hook of editor.hooks.afterRead) {\n const shouldRunHookOnAllLocales =\n fieldShouldBeLocalized({ field, parentIsLocalized: parentIsLocalized! }) &&\n (locale === 'all' || !flattenLocales) &&\n typeof siblingDoc[field.name] === 'object'\n\n if (shouldRunHookOnAllLocales) {\n const localesAndValues = Object.entries(siblingDoc[field.name])\n\n await Promise.all(\n localesAndValues.map(async ([locale, value]) => {\n const hookedValue = await hook({\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n fallbackLocale: fallbackLocale!,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n indexPath: indexPathSegments,\n locale,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n parentIsLocalized: parentIsLocalized!,\n path: pathSegments,\n populate,\n populationPromises,\n req,\n schemaPath: schemaPathSegments,\n showHiddenFields,\n siblingData: siblingDoc,\n triggerAccessControl,\n triggerHooks,\n value,\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name][locale] = hookedValue\n }\n }),\n )\n } else {\n const hookedValue = await hook({\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n fallbackLocale: fallbackLocale!,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n indexPath: indexPathSegments,\n locale: locale!,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n parentIsLocalized: parentIsLocalized!,\n path: pathSegments,\n populate,\n populationPromises,\n req,\n schemaPath: schemaPathSegments,\n showHiddenFields,\n siblingData: siblingDoc,\n triggerAccessControl,\n triggerHooks,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }\n }\n }\n break\n }\n\n case 'tab': {\n let tabDoc = siblingDoc\n let tabSelect: SelectType | undefined\n\n const isNamedTab = tabHasName(field)\n\n if (isNamedTab) {\n tabDoc = siblingDoc[field.name] as JsonObject\n\n if (typeof siblingDoc[field.name] !== 'object') {\n tabDoc = {}\n }\n\n if (typeof select?.[field.name] === 'object') {\n tabSelect = select?.[field.name] as SelectType\n }\n } else {\n tabSelect = select\n }\n\n traverseFields({\n blockData,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: isNamedTab ? '' : indexPath,\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: isNamedTab ? path : parentPath,\n parentSchemaPath: schemaPath,\n populate,\n populationPromises,\n req,\n select: tabSelect,\n selectMode,\n showHiddenFields,\n siblingDoc: tabDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'tabs': {\n traverseFields({\n blockData,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: indexPath,\n parentIsLocalized,\n parentPath: path,\n parentSchemaPath: schemaPath,\n populate,\n populationPromises,\n req,\n select,\n selectMode,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n default: {\n break\n }\n }\n}\n"],"names":["MissingEditorProp","getBlockSelect","stripUnselectedFields","fieldAffectsData","fieldShouldBeLocalized","tabHasName","getDefaultValue","getFieldPathsModified","getFieldPaths","relationshipPopulationPromise","traverseFields","virtualFieldPopulationPromise","promise","blockData","collection","context","currentDepth","depth","doc","draft","fallbackLocale","field","fieldIndex","fieldPromises","findMany","flattenLocales","global","locale","overrideAccess","parentIndexPath","parentIsLocalized","parentPath","parentSchemaPath","populate","populationPromises","req","select","selectMode","showHiddenFields","siblingDoc","siblingFields","triggerAccessControl","triggerHooks","indexPath","path","schemaPath","index","fieldAffectsDataResult","pathSegments","split","schemaPathSegments","indexPathSegments","filter","Boolean","map","Number","removedFieldValue","hidden","name","shouldContinue","shouldHoistLocalizedValue","payload","config","localization","value","hoistedValue","fallbackValue","isNullOrUndefined","type","pointDoc","Array","isArray","coordinates","length","undefined","editor","Error","tabs","forEach","tab","hooks","afterRead","hook","shouldRunHookOnAllLocales","localesAndValues","Object","entries","Promise","all","localeKey","hookedValue","data","operation","originalDoc","siblingData","virtual","push","fields","flattenedFields","ref","segments","allowDefaultValue","access","read","canReadField","id","defaultValue","user","rows","arraySelect","row","rowIndex","localized","values","localeRows","blockTypeToMatch","blockType","block","blocks","blockReferences","find","curBlock","slug","blockSelect","blockSelectMode","groupDoc","groupSelect","tabDoc","tabSelect","isNamedTab"],"mappings":"AAYA,SAASA,iBAAiB,QAAQ,2BAA0B;AAE5D,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,qBAAqB,QAAQ,8CAA6C;AACnF,SAASC,gBAAgB,EAAEC,sBAAsB,EAAEC,UAAU,QAAQ,wBAAuB;AAC5F,SAASC,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,yBAAyBC,aAAa,QAAQ,yBAAwB;AAC/E,SAASC,6BAA6B,QAAQ,qCAAoC;AAClF,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,6BAA6B,QAAQ,qCAAoC;AA4ClF,oEAAoE;AACpE,uCAAuC;AACvC,0CAA0C;AAC1C,+CAA+C;AAC/C,wBAAwB;AACxB,gCAAgC;AAChC,2BAA2B;AAE3B,OAAO,MAAMC,UAAU,OAAO,EAC5BC,SAAS,EACTC,UAAU,EACVC,OAAO,EACPC,YAAY,EACZC,KAAK,EACLC,GAAG,EACHC,KAAK,EACLC,cAAc,EACdC,KAAK,EACLC,UAAU,EACVC,aAAa,EACbC,QAAQ,EACRC,cAAc,EACdC,MAAM,EACNC,MAAM,EACNC,cAAc,EACdC,eAAe,EACfC,iBAAiB,EACjBC,UAAU,EACVC,gBAAgB,EAChBC,QAAQ,EACRC,kBAAkB,EAClBC,GAAG,EACHC,MAAM,EACNC,UAAU,EACVC,gBAAgB,EAChBC,UAAU,EACVC,aAAa,EACbC,uBAAuB,IAAI,EAC3BC,eAAe,IAAI,EACd;IACL,MAAM,EAAEC,SAAS,EAAEC,IAAI,EAAEC,UAAU,EAAE,GAAGrC,cAAc;QACpDa;QACAyB,OAAOxB;QACPO;QACAE;QACAC;IACF;IAEA,MAAMe,yBAAyB5C,iBAAiBkB;IAChD,MAAM2B,eAAeJ,OAAOA,KAAKK,KAAK,CAAC,OAAO,EAAE;IAChD,MAAMC,qBAAqBL,aAAaA,WA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AY5F;gBACd;gBAEA1B,eAAe;oBACbG;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAG;oBACA0E,QAAQ5E,MAAM4E,MAAM;oBACpBzE;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC,iBAAiBoG,aAAa,KAAKtF;oBACnCb,mBAAmBA,qBAAqBT,MAAM2F,SAAS;oBACvDjF,YAAYkG,aAAarF,OAAOb;oBAChCC,kBAAkBa;oBAClBZ;oBACAC;oBACAC;oBACAC,QAAQ4F;oBACR3F;oBACAC;oBACAC,YAAYwF;oBACZtF;oBACAC;gBACF;gBAEA;YACF;QAEA,KAAK;YAAQ;gBACXhC,eAAe;oBACbG;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAG;oBACA0E,QAAQ5E,MAAMwD,IAAI,CAACvB,GAAG,CAAC,CAACyB,MAAS,CAAA;4BAAE,GAAGA,GAAG;4BAAEX,MAAM;wBAAM,CAAA;oBACvD5C;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC,iBAAiBc;oBACjBb;oBACAC,YAAYa;oBACZZ,kBAAkBa;oBAClBZ;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAE;oBACAC;gBACF;gBAEA;YACF;QACA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/afterRead/promise.ts"],"sourcesContent":["import type { RichTextAdapter } from '../../../admin/RichText.js'\nimport type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type {\n JsonObject,\n PayloadRequest,\n PopulateType,\n SelectMode,\n SelectType,\n} from '../../../types/index.js'\nimport type { Block, Field, TabAsField } from '../../config/types.js'\nimport type { AfterReadArgs } from './index.js'\n\nimport { MissingEditorProp } from '../../../errors/index.js'\nimport { type RequestContext } from '../../../index.js'\nimport { getBlockSelect } from '../../../utilities/getBlockSelect.js'\nimport { stripUnselectedFields } from '../../../utilities/stripUnselectedFields.js'\nimport { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../../config/types.js'\nimport { getDefaultValue } from '../../getDefaultValue.js'\nimport { getFieldPathsModified as getFieldPaths } from '../../getFieldPaths.js'\nimport { relationshipPopulationPromise } from './relationshipPopulationPromise.js'\nimport { traverseFields } from './traverseFields.js'\nimport { virtualFieldPopulationPromise } from './virtualFieldPopulationPromise.js'\n\ntype Args = {\n /**\n * Data of the nearest parent block. If no parent block exists, this will be the `undefined`\n */\n blockData?: JsonObject\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n currentDepth: number\n depth: number\n doc: JsonObject\n draft: boolean\n fallbackLocale: null | string\n field: Field | TabAsField\n fieldIndex: number\n /**\n * fieldPromises are used for things like field hooks. They should be awaited before awaiting populationPromises\n */\n fieldPromises: Promise<void>[]\n findMany: boolean\n global: null | SanitizedGlobalConfig\n locale: null | string\n overrideAccess: boolean\n parentIndexPath: string\n /**\n * @todo make required in v4.0\n */\n parentIsLocalized?: boolean\n parentPath: string\n parentSchemaPath: string\n populate?: PopulateType\n populationPromises: Promise<void>[]\n req: PayloadRequest\n select?: SelectType\n selectMode?: SelectMode\n showHiddenFields: boolean\n siblingDoc: JsonObject\n siblingFields?: (Field | TabAsField)[]\n triggerAccessControl?: boolean\n triggerHooks?: boolean\n} & Required<Pick<AfterReadArgs<JsonObject>, 'flattenLocales'>>\n\n// This function is responsible for the following actions, in order:\n// - Remove hidden fields from response\n// - Flatten locales into requested locale\n// - Sanitize outgoing data (point field, etc.)\n// - Execute field hooks\n// - Execute read access control\n// - Populate relationships\n\nexport const promise = async ({\n blockData,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n field,\n fieldIndex,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath,\n parentIsLocalized,\n parentPath,\n parentSchemaPath,\n populate,\n populationPromises,\n req,\n select,\n selectMode,\n showHiddenFields,\n siblingDoc,\n siblingFields,\n triggerAccessControl = true,\n triggerHooks = true,\n}: Args): Promise<void> => {\n const { indexPath, path, schemaPath } = getFieldPaths({\n field,\n index: fieldIndex,\n parentIndexPath,\n parentPath,\n parentSchemaPath,\n })\n\n const fieldAffectsDataResult = fieldAffectsData(field)\n const pathSegments = path ? path.split('.') : []\n const schemaPathSegments = schemaPath ? schemaPath.split('.') : []\n const indexPathSegments = indexPath ? indexPath.split('-').filter(Boolean)?.map(Number) : []\n let removedFieldValue = false\n\n if (\n fieldAffectsDataResult &&\n field.hidden &&\n typeof siblingDoc[field.name!] !== 'undefined' &&\n !showHiddenFields\n ) {\n removedFieldValue = true\n delete siblingDoc[field.name!]\n }\n\n if (path !== 'id') {\n const shouldContinue = stripUnselectedFields({\n field,\n select: select!,\n selectMode: selectMode!,\n siblingDoc,\n })\n\n if (!shouldContinue) {\n return\n }\n }\n\n const shouldHoistLocalizedValue: boolean = Boolean(\n flattenLocales &&\n fieldAffectsDataResult &&\n typeof siblingDoc[field.name!] === 'object' &&\n siblingDoc[field.name!] !== null &&\n fieldShouldBeLocalized({ field, parentIsLocalized: parentIsLocalized! }) &&\n locale !== 'all' &&\n req.payload.config.localization,\n )\n\n if (fieldAffectsDataResult && shouldHoistLocalizedValue) {\n // replace actual value with localized value before sanitizing\n // { [locale]: fields } -> fields\n const value = siblingDoc[field.name!][locale!]\n\n let hoistedValue = value\n\n if (fallbackLocale && fallbackLocale !== locale) {\n const fallbackValue = siblingDoc[field.name!][fallbackLocale]\n const isNullOrUndefined = typeof value === 'undefined' || value === null\n\n if (fallbackValue) {\n switch (field.type) {\n case 'text':\n case 'textarea': {\n if (value === '' || isNullOrUndefined) {\n hoistedValue = fallbackValue\n }\n break\n }\n\n default: {\n if (isNullOrUndefined) {\n hoistedValue = fallbackValue\n }\n break\n }\n }\n }\n }\n\n siblingDoc[field.name!] = hoistedValue\n }\n\n // Sanitize outgoing field value\n switch (field.type) {\n case 'group': {\n // Fill groups with empty objects so fields with hooks within groups can populate\n // themselves virtually as necessary\n if (fieldAffectsDataResult && typeof siblingDoc[field.name] === 'undefined') {\n siblingDoc[field.name] = {}\n }\n\n break\n }\n case 'point': {\n const pointDoc = siblingDoc[field.name] as Record<string, unknown>\n if (Array.isArray(pointDoc?.coordinates) && pointDoc.coordinates.length === 2) {\n siblingDoc[field.name] = pointDoc.coordinates\n } else {\n siblingDoc[field.name] = undefined\n }\n\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n if (typeof field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n // Rich Text fields should use afterRead hooks to do population. The previous editor.populationPromises have been renamed to editor.graphQLPopulationPromises\n break\n }\n\n case 'tabs': {\n field.tabs.forEach((tab) => {\n if (\n tabHasName(tab) &&\n (typeof siblingDoc[tab.name] === 'undefined' || siblingDoc[tab.name] === null)\n ) {\n siblingDoc[tab.name] = {}\n }\n })\n\n break\n }\n\n default: {\n break\n }\n }\n\n // If locale is `all`, siblingDoc[field.name] will be an object mapping locales to values - locales won't be flattened.\n // In this case, run the hook for each locale and value pair\n const shouldRunHookOnAllLocales =\n locale === 'all' &&\n 'name' in field &&\n typeof field.name === 'string' &&\n // If localized values were hoisted, siblingDoc[field.name] will not be an object mapping locales to values\n // => Object.entries(siblingDoc[field.name]) will be the value of a single locale, not all locales\n // => do not run the hook for each locale\n !shouldHoistLocalizedValue &&\n fieldShouldBeLocalized({ field, parentIsLocalized: parentIsLocalized! }) &&\n typeof siblingDoc[field.name] === 'object'\n\n if (fieldAffectsDataResult) {\n // Execute hooks\n if (triggerHooks && 'hooks' in field && field.hooks?.afterRead) {\n for (const hook of field.hooks.afterRead) {\n if (shouldRunHookOnAllLocales) {\n const localesAndValues = Object.entries(siblingDoc[field.name])\n await Promise.all(\n localesAndValues.map(async ([localeKey, value]) => {\n const hookedValue = await hook({\n blockData,\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n field,\n findMany,\n global,\n indexPath: indexPathSegments,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n path: pathSegments,\n req,\n schemaPath: schemaPathSegments,\n showHiddenFields,\n siblingData: siblingDoc,\n siblingFields: siblingFields!,\n value,\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name][localeKey] = hookedValue\n }\n }),\n )\n } else {\n const hookedValue = await hook({\n blockData,\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n field,\n findMany,\n global,\n indexPath: indexPathSegments,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n path: pathSegments,\n req,\n schemaPath: schemaPathSegments,\n showHiddenFields,\n siblingData: siblingDoc,\n siblingFields: siblingFields!,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }\n }\n }\n\n if (\n 'virtual' in field &&\n typeof field.virtual === 'string' &&\n (!field.hidden || showHiddenFields)\n ) {\n populationPromises.push(\n virtualFieldPopulationPromise({\n name: field.name,\n draft,\n fallbackLocale: fallbackLocale!,\n fields: (collection || global)!.flattenedFields,\n locale: locale!,\n overrideAccess,\n ref: doc,\n req,\n segments: field.virtual.split('.'),\n showHiddenFields,\n siblingDoc,\n }),\n )\n }\n\n // Execute access control\n let allowDefaultValue = true\n if (triggerAccessControl && field.access && field.access.read) {\n const canReadField = overrideAccess\n ? true\n : await field.access.read({\n id: doc.id as number | string,\n blockData,\n data: doc,\n doc,\n req,\n siblingData: siblingDoc,\n })\n\n if (!canReadField) {\n allowDefaultValue = false\n delete siblingDoc[field.name!]\n }\n }\n\n // Set defaultValue on the field for globals being returned without being first created\n // or collection documents created prior to having a default\n if (\n !removedFieldValue &&\n allowDefaultValue &&\n typeof siblingDoc[field.name!] === 'undefined' &&\n typeof field.defaultValue !== 'undefined'\n ) {\n siblingDoc[field.name!] = await getDefaultValue({\n defaultValue: field.defaultValue,\n locale: locale!,\n req,\n user: req.user,\n value: siblingDoc[field.name!],\n })\n }\n\n if (field.type === 'relationship' || field.type === 'upload' || field.type === 'join') {\n populationPromises.push(\n relationshipPopulationPromise({\n currentDepth,\n depth,\n draft,\n fallbackLocale,\n field,\n locale,\n overrideAccess,\n parentIsLocalized: parentIsLocalized!,\n populate,\n req,\n showHiddenFields,\n siblingDoc,\n }),\n )\n }\n }\n\n switch (field.type) {\n case 'array': {\n const rows = siblingDoc[field.name] as JsonObject\n\n let arraySelect = select?.[field.name]\n\n if (selectMode === 'include' && typeof arraySelect === 'object') {\n arraySelect = {\n ...arraySelect,\n id: true,\n }\n }\n\n if (Array.isArray(rows) && rows.length > 0) {\n rows.forEach((row, rowIndex) => {\n traverseFields({\n blockData,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: '',\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: path + '.' + rowIndex,\n parentSchemaPath: schemaPath,\n populate,\n populationPromises,\n req,\n select: typeof arraySelect === 'object' ? arraySelect : undefined,\n selectMode,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n })\n } else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {\n Object.values(rows).forEach((localeRows) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, rowIndex) => {\n traverseFields({\n blockData,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: '',\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: path + '.' + rowIndex,\n parentSchemaPath: schemaPath,\n populate,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: (row as JsonObject) || {},\n triggerAccessControl,\n triggerHooks,\n })\n })\n }\n })\n } else if (shouldHoistLocalizedValue && (!rows || rows.length === 0)) {\n siblingDoc[field.name] = null\n } else if (field.hidden !== true || showHiddenFields === true) {\n siblingDoc[field.name] = []\n }\n break\n }\n\n case 'blocks': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows) && rows.length > 0) {\n rows.forEach((row, rowIndex) => {\n const blockTypeToMatch = (row as JsonObject).blockType\n\n const block: Block | undefined =\n req.payload.blocks[blockTypeToMatch] ??\n ((field.blockReferences ?? field.blocks).find(\n (curBlock) => typeof curBlock !== 'string' && curBlock.slug === blockTypeToMatch,\n ) as Block | undefined)\n\n const { blockSelect, blockSelectMode } = getBlockSelect({\n block: block!,\n // TODO: fix this\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n select: select?.[field.name]!,\n selectMode: selectMode!,\n })\n\n if (block) {\n traverseFields({\n blockData: row,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: block.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: '',\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: path + '.' + rowIndex,\n parentSchemaPath: schemaPath + '.' + block.slug,\n populate,\n populationPromises,\n req,\n select: typeof blockSelect === 'object' ? blockSelect : undefined,\n selectMode: blockSelectMode,\n showHiddenFields,\n siblingDoc: (row as JsonObject) || {},\n triggerAccessControl,\n triggerHooks,\n })\n }\n })\n } else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {\n Object.values(rows).forEach((localeRows) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, rowIndex) => {\n const blockTypeToMatch = row.blockType\n\n const block: Block | undefined =\n req.payload.blocks[blockTypeToMatch] ??\n ((field.blockReferences ?? field.blocks).find(\n (curBlock) => typeof curBlock !== 'string' && curBlock.slug === blockTypeToMatch,\n ) as Block | undefined)\n\n if (block) {\n traverseFields({\n blockData: row,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: block.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: '',\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: path + '.' + rowIndex,\n parentSchemaPath: schemaPath + '.' + block.slug,\n populate,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: (row as JsonObject) || {},\n triggerAccessControl,\n triggerHooks,\n })\n }\n })\n }\n })\n } else if (shouldHoistLocalizedValue && (!rows || rows.length === 0)) {\n siblingDoc[field.name] = null\n } else if (field.hidden !== true || showHiddenFields === true) {\n siblingDoc[field.name] = []\n }\n\n break\n }\n\n case 'collapsible':\n case 'row': {\n traverseFields({\n blockData,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: indexPath,\n parentIsLocalized,\n parentPath,\n parentSchemaPath: schemaPath,\n populate,\n populationPromises,\n req,\n select,\n selectMode,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'group': {\n if (fieldAffectsDataResult) {\n let groupDoc = siblingDoc[field.name] as JsonObject\n\n if (typeof siblingDoc[field.name] !== 'object') {\n groupDoc = {}\n }\n\n const groupSelect = select?.[field.name]\n\n traverseFields({\n blockData,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: '',\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: path,\n parentSchemaPath: schemaPath,\n populate,\n populationPromises,\n req,\n select: typeof groupSelect === 'object' ? groupSelect : undefined,\n selectMode,\n showHiddenFields,\n siblingDoc: groupDoc,\n triggerAccessControl,\n triggerHooks,\n })\n } else {\n traverseFields({\n blockData,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: indexPath,\n parentIsLocalized,\n parentPath,\n parentSchemaPath: schemaPath,\n populate,\n populationPromises,\n req,\n select,\n selectMode,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n }\n\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n\n if (typeof field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n const editor: RichTextAdapter = field?.editor\n\n if (editor?.hooks?.afterRead?.length) {\n for (const hook of editor.hooks.afterRead) {\n if (shouldRunHookOnAllLocales) {\n const localesAndValues = Object.entries(siblingDoc[field.name])\n\n await Promise.all(\n localesAndValues.map(async ([locale, value]) => {\n const hookedValue = await hook({\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n fallbackLocale: fallbackLocale!,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n indexPath: indexPathSegments,\n locale,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n parentIsLocalized: parentIsLocalized!,\n path: pathSegments,\n populate,\n populationPromises,\n req,\n schemaPath: schemaPathSegments,\n showHiddenFields,\n siblingData: siblingDoc,\n triggerAccessControl,\n triggerHooks,\n value,\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name][locale] = hookedValue\n }\n }),\n )\n } else {\n const hookedValue = await hook({\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n fallbackLocale: fallbackLocale!,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n indexPath: indexPathSegments,\n locale: locale!,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n parentIsLocalized: parentIsLocalized!,\n path: pathSegments,\n populate,\n populationPromises,\n req,\n schemaPath: schemaPathSegments,\n showHiddenFields,\n siblingData: siblingDoc,\n triggerAccessControl,\n triggerHooks,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }\n }\n }\n break\n }\n\n case 'tab': {\n let tabDoc = siblingDoc\n let tabSelect: SelectType | undefined\n\n const isNamedTab = tabHasName(field)\n\n if (isNamedTab) {\n tabDoc = siblingDoc[field.name] as JsonObject\n\n if (typeof siblingDoc[field.name] !== 'object') {\n tabDoc = {}\n }\n\n if (typeof select?.[field.name] === 'object') {\n tabSelect = select?.[field.name] as SelectType\n }\n } else {\n tabSelect = select\n }\n\n traverseFields({\n blockData,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: isNamedTab ? '' : indexPath,\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: isNamedTab ? path : parentPath,\n parentSchemaPath: schemaPath,\n populate,\n populationPromises,\n req,\n select: tabSelect,\n selectMode,\n showHiddenFields,\n siblingDoc: tabDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'tabs': {\n traverseFields({\n blockData,\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: indexPath,\n parentIsLocalized,\n parentPath: path,\n parentSchemaPath: schemaPath,\n populate,\n populationPromises,\n req,\n select,\n selectMode,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n default: {\n break\n }\n }\n}\n"],"names":["MissingEditorProp","getBlockSelect","stripUnselectedFields","fieldAffectsData","fieldShouldBeLocalized","tabHasName","getDefaultValue","getFieldPathsModified","getFieldPaths","relationshipPopulationPromise","traverseFields","virtualFieldPopulationPromise","promise","blockData","collection","context","currentDepth","depth","doc","draft","fallbackLocale","field","fieldIndex","fieldPromises","findMany","flattenLocales","global","locale","overrideAccess","parentIndexPath","parentIsLocalized","parentPath","parentSchemaPath","populate","populationPromises","req","select","selectMode","showHiddenFields","siblingDoc","siblingFields","triggerAccessControl","triggerHooks","indexPath","path","schemaPath","index","fieldAffectsDataResult","pathSegments","split","schemaPathSegments","indexPathSegments","filter","Boolean","map","Number","removedFieldValue","hidden","name","shouldContinue","shouldHoistLocalizedValue","payload","config","localization","value","hoistedValue","fallbackValue","isNullOrUndefined","type","pointDoc","Array","isArray","coordinates","length","undefined","editor","Error","tabs","forEach","tab","shouldRunHookOnAllLocales","hooks","afterRead","hook","localesAndValues","Object","entries","Promise","all","localeKey","hookedValue","data","operation","originalDoc","siblingData","virtual","push","fields","flattenedFields","ref","segments","allowDefaultValue","access","read","canReadField","id","defaultValue","user","rows","arraySelect","row","rowIndex","localized","values","localeRows","blockTypeToMatch","blockType","block","blocks","blockReferences","find","curBlock","slug","blockSelect","blockSelectMode","groupDoc","groupSelect","tabDoc","tabSelect","isNamedTab"],"mappings":"AAaA,SAASA,iBAAiB,QAAQ,2BAA0B;AAE5D,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,qBAAqB,QAAQ,8CAA6C;AACnF,SAASC,gBAAgB,EAAEC,sBAAsB,EAAEC,UAAU,QAAQ,wBAAuB;AAC5F,SAASC,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,yBAAyBC,aAAa,QAAQ,yBAAwB;AAC/E,SAASC,6BAA6B,QAAQ,qCAAoC;AAClF,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,6BAA6B,QAAQ,qCAAoC;AA2ClF,oEAAoE;AACpE,uCAAuC;AACvC,0CAA0C;AAC1C,+CAA+C;AAC/C,wBAAwB;AACxB,gCAAgC;AAChC,2BAA2B;AAE3B,OAAO,MAAMC,UAAU,OAAO,EAC5BC,SAAS,EACTC,UAAU,EACVC,OAAO,EACPC,YAAY,EACZC,KAAK,EACLC,GAAG,E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BACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAE;oBACAC;gBACF;gBAEA;YACF;QACA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../../../src/globals/endpoints/findOne.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAS3D,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../../../src/globals/endpoints/findOne.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAS3D,eAAO,MAAM,cAAc,EAAE,cAkC5B,CAAA"}
|
|
@@ -9,11 +9,13 @@ export const findOneHandler = async (req)=>{
|
|
|
9
9
|
const globalConfig = getRequestGlobal(req);
|
|
10
10
|
const { data, searchParams } = req;
|
|
11
11
|
const depth = data ? data.depth : searchParams.get('depth');
|
|
12
|
+
const flattenLocales = data ? data.flattenLocales : searchParams.has('flattenLocales') ? searchParams.get('flattenLocales') === 'true' : undefined;
|
|
12
13
|
const result = await findOneOperation({
|
|
13
14
|
slug: globalConfig.slug,
|
|
14
15
|
data: data ? data?.data : searchParams.get('data') ? JSON.parse(searchParams.get('data')) : undefined,
|
|
15
16
|
depth: isNumber(depth) ? Number(depth) : undefined,
|
|
16
17
|
draft: data ? data.draft : searchParams.get('draft') === 'true',
|
|
18
|
+
flattenLocales,
|
|
17
19
|
globalConfig,
|
|
18
20
|
populate: sanitizePopulateParam(req.query.populate),
|
|
19
21
|
req,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/globals/endpoints/findOne.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\n\nimport { getRequestGlobal } from '../../utilities/getRequestEntity.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { isNumber } from '../../utilities/isNumber.js'\nimport { sanitizePopulateParam } from '../../utilities/sanitizePopulateParam.js'\nimport { sanitizeSelectParam } from '../../utilities/sanitizeSelectParam.js'\nimport { findOneOperation } from '../operations/findOne.js'\n\nexport const findOneHandler: PayloadHandler = async (req) => {\n const globalConfig = getRequestGlobal(req)\n const { data, searchParams } = req\n const depth = data ? data.depth : searchParams.get('depth')\n\n const result = await findOneOperation({\n slug: globalConfig.slug,\n data: data\n ? data?.data\n : searchParams.get('data')\n ? JSON.parse(searchParams.get('data') as string)\n : undefined,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: data ? data.draft : searchParams.get('draft') === 'true',\n globalConfig,\n populate: sanitizePopulateParam(req.query.populate),\n req,\n select: sanitizeSelectParam(req.query.select),\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"names":["status","httpStatus","getRequestGlobal","headersWithCors","isNumber","sanitizePopulateParam","sanitizeSelectParam","findOneOperation","findOneHandler","req","globalConfig","data","searchParams","depth","get","result","slug","JSON","parse","
|
|
1
|
+
{"version":3,"sources":["../../../src/globals/endpoints/findOne.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\n\nimport { getRequestGlobal } from '../../utilities/getRequestEntity.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { isNumber } from '../../utilities/isNumber.js'\nimport { sanitizePopulateParam } from '../../utilities/sanitizePopulateParam.js'\nimport { sanitizeSelectParam } from '../../utilities/sanitizeSelectParam.js'\nimport { findOneOperation } from '../operations/findOne.js'\n\nexport const findOneHandler: PayloadHandler = async (req) => {\n const globalConfig = getRequestGlobal(req)\n const { data, searchParams } = req\n const depth = data ? data.depth : searchParams.get('depth')\n const flattenLocales = data\n ? data.flattenLocales\n : searchParams.has('flattenLocales')\n ? searchParams.get('flattenLocales') === 'true'\n : // flattenLocales should be undfined if not provided, so that the default (true) is applied in the operation\n undefined\n\n const result = await findOneOperation({\n slug: globalConfig.slug,\n data: data\n ? data?.data\n : searchParams.get('data')\n ? JSON.parse(searchParams.get('data') as string)\n : undefined,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: data ? data.draft : searchParams.get('draft') === 'true',\n flattenLocales,\n globalConfig,\n populate: sanitizePopulateParam(req.query.populate),\n req,\n select: sanitizeSelectParam(req.query.select),\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"names":["status","httpStatus","getRequestGlobal","headersWithCors","isNumber","sanitizePopulateParam","sanitizeSelectParam","findOneOperation","findOneHandler","req","globalConfig","data","searchParams","depth","get","flattenLocales","has","undefined","result","slug","JSON","parse","Number","draft","populate","query","select","Response","json","headers","Headers","OK"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAIlD,SAASC,gBAAgB,QAAQ,sCAAqC;AACtE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,QAAQ,QAAQ,8BAA6B;AACtD,SAASC,qBAAqB,QAAQ,2CAA0C;AAChF,SAASC,mBAAmB,QAAQ,yCAAwC;AAC5E,SAASC,gBAAgB,QAAQ,2BAA0B;AAE3D,OAAO,MAAMC,iBAAiC,OAAOC;IACnD,MAAMC,eAAeR,iBAAiBO;IACtC,MAAM,EAAEE,IAAI,EAAEC,YAAY,EAAE,GAAGH;IAC/B,MAAMI,QAAQF,OAAOA,KAAKE,KAAK,GAAGD,aAAaE,GAAG,CAAC;IACnD,MAAMC,iBAAiBJ,OACnBA,KAAKI,cAAc,GACnBH,aAAaI,GAAG,CAAC,oBACfJ,aAAaE,GAAG,CAAC,sBAAsB,SAEvCG;IAEN,MAAMC,SAAS,MAAMX,iBAAiB;QACpCY,MAAMT,aAAaS,IAAI;QACvBR,MAAMA,OACFA,MAAMA,OACNC,aAAaE,GAAG,CAAC,UACfM,KAAKC,KAAK,CAACT,aAAaE,GAAG,CAAC,WAC5BG;QACNJ,OAAOT,SAASS,SAASS,OAAOT,SAASI;QACzCM,OAAOZ,OAAOA,KAAKY,KAAK,GAAGX,aAAaE,GAAG,CAAC,aAAa;QACzDC;QACAL;QACAc,UAAUnB,sBAAsBI,IAAIgB,KAAK,CAACD,QAAQ;QAClDf;QACAiB,QAAQpB,oBAAoBG,IAAIgB,KAAK,CAACC,MAAM;IAC9C;IAEA,OAAOC,SAASC,IAAI,CAACV,QAAQ;QAC3BW,SAAS1B,gBAAgB;YACvB0B,SAAS,IAAIC;YACbrB;QACF;QACAT,QAAQC,WAAW8B,EAAE;IACvB;AACF,EAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { PayloadRequest, PopulateType, SelectType } from '../../types/index.js';
|
|
1
|
+
import type { JsonObject, PayloadRequest, PopulateType, SelectType } from '../../types/index.js';
|
|
2
2
|
import type { SanitizedGlobalConfig } from '../config/types.js';
|
|
3
|
-
type
|
|
3
|
+
import { type AfterReadArgs } from '../../fields/hooks/afterRead/index.js';
|
|
4
|
+
export type GlobalFindOneArgs = {
|
|
4
5
|
/**
|
|
5
6
|
* You may pass the document data directly which will skip the `db.findOne` database query.
|
|
6
7
|
* This is useful if you want to use this endpoint solely for running hooks and populating data.
|
|
@@ -16,7 +17,6 @@ type Args = {
|
|
|
16
17
|
select?: SelectType;
|
|
17
18
|
showHiddenFields?: boolean;
|
|
18
19
|
slug: string;
|
|
19
|
-
}
|
|
20
|
-
export declare const findOneOperation: <T extends Record<string, unknown>>(args:
|
|
21
|
-
export {};
|
|
20
|
+
} & Pick<AfterReadArgs<JsonObject>, 'flattenLocales'>;
|
|
21
|
+
export declare const findOneOperation: <T extends Record<string, unknown>>(args: GlobalFindOneArgs) => Promise<T>;
|
|
22
22
|
//# sourceMappingURL=findOne.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../../../src/globals/operations/findOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../../../src/globals/operations/findOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,YAAY,EACZ,UAAU,EAEX,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAG/D,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,uCAAuC,CAAA;AAOrF,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,YAAY,EAAE,qBAAqB,CAAA;IACnC,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;CACb,GAAG,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC,CAAA;AAErD,eAAO,MAAM,gBAAgB,GAAU,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAChE,iBAAiB,KACtB,OAAO,CAAC,CAAC,CA8MX,CAAA"}
|
|
@@ -6,7 +6,7 @@ import { killTransaction } from '../../utilities/killTransaction.js';
|
|
|
6
6
|
import { sanitizeSelect } from '../../utilities/sanitizeSelect.js';
|
|
7
7
|
import { replaceWithDraftIfAvailable } from '../../versions/drafts/replaceWithDraftIfAvailable.js';
|
|
8
8
|
export const findOneOperation = async (args)=>{
|
|
9
|
-
const { slug, depth, draft: draftEnabled = false, globalConfig, includeLockStatus, overrideAccess = false, populate, req: { fallbackLocale, locale }, req, select: incomingSelect, showHiddenFields } = args;
|
|
9
|
+
const { slug, depth, draft: draftEnabled = false, flattenLocales, globalConfig, includeLockStatus, overrideAccess = false, populate, req: { fallbackLocale, locale }, req, select: incomingSelect, showHiddenFields } = args;
|
|
10
10
|
try {
|
|
11
11
|
// /////////////////////////////////////
|
|
12
12
|
// beforeOperation - Global
|
|
@@ -137,6 +137,7 @@ export const findOneOperation = async (args)=>{
|
|
|
137
137
|
doc,
|
|
138
138
|
draft: draftEnabled,
|
|
139
139
|
fallbackLocale: fallbackLocale,
|
|
140
|
+
flattenLocales,
|
|
140
141
|
global: globalConfig,
|
|
141
142
|
locale: locale,
|
|
142
143
|
overrideAccess,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/globals/operations/findOne.ts"],"sourcesContent":["import type { AccessResult } from '../../config/types.js'\nimport type {\n JsonObject,\n PayloadRequest,\n PopulateType,\n SelectType,\n Where,\n} from '../../types/index.js'\nimport type { SanitizedGlobalConfig } from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { lockedDocumentsCollectionSlug } from '../../locked-documents/config.js'\nimport { getSelectMode } from '../../utilities/getSelectMode.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { replaceWithDraftIfAvailable } from '../../versions/drafts/replaceWithDraftIfAvailable.js'\n\ntype Args = {\n /**\n * You may pass the document data directly which will skip the `db.findOne` database query.\n * This is useful if you want to use this endpoint solely for running hooks and populating data.\n */\n data?: Record<string, unknown>\n depth?: number\n draft?: boolean\n globalConfig: SanitizedGlobalConfig\n includeLockStatus?: boolean\n overrideAccess?: boolean\n populate?: PopulateType\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n slug: string\n}\n\nexport const findOneOperation = async <T extends Record<string, unknown>>(\n args: Args,\n): Promise<T> => {\n const {\n slug,\n depth,\n draft: draftEnabled = false,\n globalConfig,\n includeLockStatus,\n overrideAccess = false,\n populate,\n req: { fallbackLocale, locale },\n req,\n select: incomingSelect,\n showHiddenFields,\n } = args\n\n try {\n // /////////////////////////////////////\n // beforeOperation - Global\n // /////////////////////////////////////\n\n if (globalConfig.hooks?.beforeOperation?.length) {\n for (const hook of globalConfig.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n context: args.req.context,\n global: globalConfig,\n operation: 'read',\n req: args.req,\n })) || args\n }\n }\n\n // /////////////////////////////////////\n // Retrieve and execute access\n // /////////////////////////////////////\n\n let accessResult!: AccessResult\n\n if (!overrideAccess) {\n accessResult = await executeAccess({ req }, globalConfig.access.read)\n }\n\n const select = sanitizeSelect({\n fields: globalConfig.flattenedFields,\n forceSelect: globalConfig.forceSelect,\n select: incomingSelect,\n })\n\n // /////////////////////////////////////\n // Perform database operation\n // /////////////////////////////////////\n\n let doc =\n (args.data as any) ??\n (await req.payload.db.findGlobal({\n slug,\n locale: locale!,\n req,\n select,\n where: overrideAccess ? undefined : (accessResult as Where),\n }))\n if (!doc) {\n doc = {}\n }\n\n // /////////////////////////////////////\n // Include Lock Status if required\n // /////////////////////////////////////\n if (includeLockStatus && slug) {\n let lockStatus: JsonObject | null = null\n\n try {\n const lockDocumentsProp = globalConfig?.lockDocuments\n\n const lockDurationDefault = 300 // Default 5 minutes in seconds\n const lockDuration =\n typeof lockDocumentsProp === 'object' ? lockDocumentsProp.duration : lockDurationDefault\n const lockDurationInMilliseconds = lockDuration * 1000\n\n const lockedDocument = await req.payload.find({\n collection: lockedDocumentsCollectionSlug,\n depth: 1,\n limit: 1,\n overrideAccess: false,\n pagination: false,\n req,\n where: {\n and: [\n {\n globalSlug: {\n equals: slug,\n },\n },\n {\n updatedAt: {\n greater_than: new Date(new Date().getTime() - lockDurationInMilliseconds),\n },\n },\n ],\n },\n })\n\n if (lockedDocument && lockedDocument.docs.length > 0) {\n lockStatus = lockedDocument.docs[0]!\n }\n } catch {\n // swallow error\n }\n\n doc._isLocked = !!lockStatus\n doc._userEditing = lockStatus?.user?.value ?? null\n }\n\n // /////////////////////////////////////\n // Replace document with draft if available\n // /////////////////////////////////////\n\n if (globalConfig.versions?.drafts && draftEnabled) {\n doc = await replaceWithDraftIfAvailable({\n accessResult,\n doc,\n entity: globalConfig,\n entityType: 'global',\n overrideAccess,\n req,\n select,\n })\n }\n\n // /////////////////////////////////////\n // Execute before global hook\n // /////////////////////////////////////\n\n if (globalConfig.hooks?.beforeRead?.length) {\n for (const hook of globalConfig.hooks.beforeRead) {\n doc =\n (await hook({\n context: req.context,\n doc,\n global: globalConfig,\n req,\n })) || doc\n }\n }\n\n // /////////////////////////////////////\n // Execute globalType field if not selected\n // /////////////////////////////////////\n if (select && doc.globalType) {\n const selectMode = getSelectMode(select)\n if (\n (selectMode === 'include' && !select['globalType']) ||\n (selectMode === 'exclude' && select['globalType'] === false)\n ) {\n delete doc['globalType']\n }\n }\n\n // /////////////////////////////////////\n // Execute field-level hooks and access\n // /////////////////////////////////////\n\n doc = await afterRead({\n collection: null,\n context: req.context,\n depth: depth!,\n doc,\n draft: draftEnabled,\n fallbackLocale: fallbackLocale!,\n global: globalConfig,\n locale: locale!,\n overrideAccess,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // Execute after global hook\n // /////////////////////////////////////\n\n if (globalConfig.hooks?.afterRead?.length) {\n for (const hook of globalConfig.hooks.afterRead) {\n doc =\n (await hook({\n context: req.context,\n doc,\n global: globalConfig,\n req,\n })) || doc\n }\n }\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n return doc\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["executeAccess","afterRead","lockedDocumentsCollectionSlug","getSelectMode","killTransaction","sanitizeSelect","replaceWithDraftIfAvailable","findOneOperation","args","slug","depth","draft","draftEnabled","globalConfig","includeLockStatus","overrideAccess","populate","req","fallbackLocale","locale","select","incomingSelect","showHiddenFields","hooks","beforeOperation","length","hook","context","global","operation","accessResult","access","read","fields","flattenedFields","forceSelect","doc","data","payload","db","findGlobal","where","undefined","lockStatus","lockDocumentsProp","lockDocuments","lockDurationDefault","lockDuration","duration","lockDurationInMilliseconds","lockedDocument","find","collection","limit","pagination","and","globalSlug","equals","updatedAt","greater_than","Date","getTime","docs","_isLocked","_userEditing","user","value","versions","drafts","entity","entityType","beforeRead","globalType","selectMode","error"],"mappings":"AAUA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,6BAA6B,QAAQ,mCAAkC;AAChF,SAASC,aAAa,QAAQ,mCAAkC;AAChE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,2BAA2B,QAAQ,uDAAsD;AAoBlG,OAAO,MAAMC,mBAAmB,OAC9BC;IAEA,MAAM,EACJC,IAAI,EACJC,KAAK,EACLC,OAAOC,eAAe,KAAK,EAC3BC,YAAY,EACZC,iBAAiB,EACjBC,iBAAiB,KAAK,EACtBC,QAAQ,EACRC,KAAK,EAAEC,cAAc,EAAEC,MAAM,EAAE,EAC/BF,GAAG,EACHG,QAAQC,cAAc,EACtBC,gBAAgB,EACjB,GAAGd;IAEJ,IAAI;QACF,wCAAwC;QACxC,2BAA2B;QAC3B,wCAAwC;QAExC,IAAIK,aAAaU,KAAK,EAAEC,iBAAiBC,QAAQ;YAC/C,KAAK,MAAMC,QAAQb,aAAaU,KAAK,CAACC,eAAe,CAAE;gBACrDhB,OACE,AAAC,MAAMkB,KAAK;oBACVlB;oBACAmB,SAASnB,KAAKS,GAAG,CAACU,OAAO;oBACzBC,QAAQf;oBACRgB,WAAW;oBACXZ,KAAKT,KAAKS,GAAG;gBACf,MAAOT;YACX;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9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QAAQb,aAAaU,KAAK,CAACtB,SAAS,CAAE;gBAC/CmC,MACE,AAAC,MAAMV,KAAK;oBACVC,SAASV,IAAIU,OAAO;oBACpBS;oBACAR,QAAQf;oBACRI;gBACF,MAAOmB;YACX;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,OAAOA;IACT,EAAE,OAAOsC,OAAgB;QACvB,MAAMtE,gBAAgBa;QACtB,MAAMyD;IACR;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/globals/operations/findOne.ts"],"sourcesContent":["import type { AccessResult } from '../../config/types.js'\nimport type {\n JsonObject,\n PayloadRequest,\n PopulateType,\n SelectType,\n Where,\n} from '../../types/index.js'\nimport type { SanitizedGlobalConfig } from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { afterRead, type AfterReadArgs } from '../../fields/hooks/afterRead/index.js'\nimport { lockedDocumentsCollectionSlug } from '../../locked-documents/config.js'\nimport { getSelectMode } from '../../utilities/getSelectMode.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { replaceWithDraftIfAvailable } from '../../versions/drafts/replaceWithDraftIfAvailable.js'\n\nexport type GlobalFindOneArgs = {\n /**\n * You may pass the document data directly which will skip the `db.findOne` database query.\n * This is useful if you want to use this endpoint solely for running hooks and populating data.\n */\n data?: Record<string, unknown>\n depth?: number\n draft?: boolean\n globalConfig: SanitizedGlobalConfig\n includeLockStatus?: boolean\n overrideAccess?: boolean\n populate?: PopulateType\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n slug: string\n} & Pick<AfterReadArgs<JsonObject>, 'flattenLocales'>\n\nexport const findOneOperation = async <T extends Record<string, unknown>>(\n args: GlobalFindOneArgs,\n): Promise<T> => {\n const {\n slug,\n depth,\n draft: draftEnabled = false,\n flattenLocales,\n globalConfig,\n includeLockStatus,\n overrideAccess = false,\n populate,\n req: { fallbackLocale, locale },\n req,\n select: incomingSelect,\n showHiddenFields,\n } = args\n\n try {\n // /////////////////////////////////////\n // beforeOperation - Global\n // /////////////////////////////////////\n\n if (globalConfig.hooks?.beforeOperation?.length) {\n for (const hook of globalConfig.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n context: args.req.context,\n global: globalConfig,\n operation: 'read',\n req: args.req,\n })) || args\n }\n }\n\n // /////////////////////////////////////\n // Retrieve and execute access\n // /////////////////////////////////////\n\n let accessResult!: AccessResult\n\n if (!overrideAccess) {\n accessResult = await executeAccess({ req }, globalConfig.access.read)\n }\n\n const select = sanitizeSelect({\n fields: globalConfig.flattenedFields,\n forceSelect: globalConfig.forceSelect,\n select: incomingSelect,\n })\n\n // /////////////////////////////////////\n // Perform database operation\n // /////////////////////////////////////\n\n let doc =\n (args.data as any) ??\n (await req.payload.db.findGlobal({\n slug,\n locale: locale!,\n req,\n select,\n where: overrideAccess ? undefined : (accessResult as Where),\n }))\n if (!doc) {\n doc = {}\n }\n\n // /////////////////////////////////////\n // Include Lock Status if required\n // /////////////////////////////////////\n if (includeLockStatus && slug) {\n let lockStatus: JsonObject | null = null\n\n try {\n const lockDocumentsProp = globalConfig?.lockDocuments\n\n const lockDurationDefault = 300 // Default 5 minutes in seconds\n const lockDuration =\n typeof lockDocumentsProp === 'object' ? lockDocumentsProp.duration : lockDurationDefault\n const lockDurationInMilliseconds = lockDuration * 1000\n\n const lockedDocument = await req.payload.find({\n collection: lockedDocumentsCollectionSlug,\n depth: 1,\n limit: 1,\n overrideAccess: false,\n pagination: false,\n req,\n where: {\n and: [\n {\n globalSlug: {\n equals: slug,\n },\n },\n {\n updatedAt: {\n greater_than: new Date(new Date().getTime() - lockDurationInMilliseconds),\n },\n },\n ],\n },\n })\n\n if (lockedDocument && lockedDocument.docs.length > 0) {\n lockStatus = lockedDocument.docs[0]!\n }\n } catch {\n // swallow error\n }\n\n doc._isLocked = !!lockStatus\n doc._userEditing = lockStatus?.user?.value ?? null\n }\n\n // /////////////////////////////////////\n // Replace document with draft if available\n // /////////////////////////////////////\n\n if (globalConfig.versions?.drafts && draftEnabled) {\n doc = await replaceWithDraftIfAvailable({\n accessResult,\n doc,\n entity: globalConfig,\n entityType: 'global',\n overrideAccess,\n req,\n select,\n })\n }\n\n // /////////////////////////////////////\n // Execute before global hook\n // /////////////////////////////////////\n\n if (globalConfig.hooks?.beforeRead?.length) {\n for (const hook of globalConfig.hooks.beforeRead) {\n doc =\n (await hook({\n context: req.context,\n doc,\n global: globalConfig,\n req,\n })) || doc\n }\n }\n\n // /////////////////////////////////////\n // Execute globalType field if not selected\n // /////////////////////////////////////\n if (select && doc.globalType) {\n const selectMode = getSelectMode(select)\n if (\n (selectMode === 'include' && !select['globalType']) ||\n (selectMode === 'exclude' && select['globalType'] === false)\n ) {\n delete doc['globalType']\n }\n }\n\n // /////////////////////////////////////\n // Execute field-level hooks and access\n // /////////////////////////////////////\n\n doc = await afterRead({\n collection: null,\n context: req.context,\n depth: depth!,\n doc,\n draft: draftEnabled,\n fallbackLocale: fallbackLocale!,\n flattenLocales,\n global: globalConfig,\n locale: locale!,\n overrideAccess,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // Execute after global hook\n // /////////////////////////////////////\n\n if (globalConfig.hooks?.afterRead?.length) {\n for (const hook of globalConfig.hooks.afterRead) {\n doc =\n (await hook({\n context: req.context,\n doc,\n global: globalConfig,\n req,\n })) || doc\n }\n }\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n return doc\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["executeAccess","afterRead","lockedDocumentsCollectionSlug","getSelectMode","killTransaction","sanitizeSelect","replaceWithDraftIfAvailable","findOneOperation","args","slug","depth","draft","draftEnabled","flattenLocales","globalConfig","includeLockStatus","overrideAccess","populate","req","fallbackLocale","locale","select","incomingSelect","showHiddenFields","hooks","beforeOperation","length","hook","context","global","operation","accessResult","access","read","fields","flattenedFields","forceSelect","doc","data","payload","db","findGlobal","where","undefined","lockStatus","lockDocumentsProp","lockDocuments","lockDurationDefault","lockDuration","duration","lockDurationInMilliseconds","lockedDocument","find","collection","limit","pagination","and","globalSlug","equals","updatedAt","greater_than","Date","getTime","docs","_isLocked","_userEditing","user","value","versions","drafts","entity","entityType","beforeRead","globalType","selectMode","error"],"mappings":"AAUA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,SAAS,QAA4B,wCAAuC;AACrF,SAASC,6BAA6B,QAAQ,mCAAkC;AAChF,SAASC,aAAa,QAAQ,mCAAkC;AAChE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,2BAA2B,QAAQ,uDAAsD;AAoBlG,OAAO,MAAMC,mBAAmB,OAC9BC;IAEA,MAAM,EACJC,IAAI,EACJC,KAAK,EACLC,OAAOC,eAAe,KAAK,EAC3BC,cAAc,EACdC,YAAY,EACZC,iBAAiB,EACjBC,iBAAiB,KAAK,EACtBC,QAAQ,EACRC,KAAK,EAAEC,cAAc,EAAEC,MAAM,EAAE,EAC/BF,GAAG,EACHG,QAAQC,cAAc,EACtBC,gBAAgB,EACjB,GAAGf;IAEJ,IAAI;QACF,wCAAwC;QACxC,2BAA2B;QAC3B,wCAAwC;QAExC,IAAIM,aAAaU,KAAK,EAAEC,iBAAiBC,QAAQ;YAC/C,KAAK,MAAMC,QAAQb,aAAaU,KAAK,CAACC,eAAe,CAAE;gBACrDjB,OACE,AAAC,MAAMmB,KAAK;oBACVnB;oBACAoB,SAASpB,KAAKU,GAAG,CAACU,OAAO;oBACzBC,QAAQf;oBACRgB,WAAW;oBACXZ,KAAKV,KAAKU,GAAG;gBACf,MAAOV;YACX;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExC,IAAIuB;QAEJ,IAAI,CAACf,gBAAgB;YACnBe,eAAe,MAAM/B,cAAc;gBAAEkB;YAAI,GAAGJ,aAAakB,M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BS;oBACAR,QAAQf;oBACRI;gBACF,MAAOmB;YACX;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,OAAOA;IACT,EAAE,OAAOsC,OAAgB;QACvB,MAAMvE,gBAAgBc;QACtB,MAAMyD;IACR;AACF,EAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { GlobalSlug, Payload, RequestContext, TypedLocale } from '../../../index.js';
|
|
2
2
|
import type { Document, PayloadRequest, PopulateType, SelectType, TransformGlobalWithSelect } from '../../../types/index.js';
|
|
3
3
|
import type { SelectFromGlobalSlug } from '../../config/types.js';
|
|
4
|
+
import { type GlobalFindOneArgs } from '../findOne.js';
|
|
4
5
|
export type Options<TSlug extends GlobalSlug, TSelect extends SelectType> = {
|
|
5
6
|
/**
|
|
6
7
|
* [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,
|
|
@@ -66,6 +67,6 @@ export type Options<TSlug extends GlobalSlug, TSelect extends SelectType> = {
|
|
|
66
67
|
* If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.
|
|
67
68
|
*/
|
|
68
69
|
user?: Document;
|
|
69
|
-
}
|
|
70
|
+
} & Pick<GlobalFindOneArgs, 'flattenLocales'>;
|
|
70
71
|
export declare function findOneGlobalLocal<TSlug extends GlobalSlug, TSelect extends SelectFromGlobalSlug<TSlug>>(payload: Payload, options: Options<TSlug, TSelect>): Promise<TransformGlobalWithSelect<TSlug, TSelect>>;
|
|
71
72
|
//# sourceMappingURL=findOne.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../../../../src/globals/operations/local/findOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACzF,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,UAAU,EACV,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,EAAE,OAAO,CAAA;IAC1B;;OAEG;IACH,IAAI,EAAE,KAAK,CAAA;IACX;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB,GAAG,IAAI,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAA;AAE7C,wBAAsB,kBAAkB,CACtC,KAAK,SAAS,UAAU,EACxB,OAAO,SAAS,oBAAoB,CAAC,KAAK,CAAC,EAE3C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,yBAAyB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAkCpD"}
|
|
@@ -2,7 +2,7 @@ import { APIError } from '../../../errors/index.js';
|
|
|
2
2
|
import { createLocalReq } from '../../../utilities/createLocalReq.js';
|
|
3
3
|
import { findOneOperation } from '../findOne.js';
|
|
4
4
|
export async function findOneGlobalLocal(payload, options) {
|
|
5
|
-
const { slug: globalSlug, data, depth, draft = false, includeLockStatus, overrideAccess = true, populate, select, showHiddenFields } = options;
|
|
5
|
+
const { slug: globalSlug, data, depth, draft = false, flattenLocales, includeLockStatus, overrideAccess = true, populate, select, showHiddenFields } = options;
|
|
6
6
|
const globalConfig = payload.globals.config.find((config)=>config.slug === globalSlug);
|
|
7
7
|
if (!globalConfig) {
|
|
8
8
|
throw new APIError(`The global with slug ${String(globalSlug)} can't be found.`);
|
|
@@ -12,6 +12,7 @@ export async function findOneGlobalLocal(payload, options) {
|
|
|
12
12
|
data,
|
|
13
13
|
depth,
|
|
14
14
|
draft,
|
|
15
|
+
flattenLocales,
|
|
15
16
|
globalConfig,
|
|
16
17
|
includeLockStatus,
|
|
17
18
|
overrideAccess,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/globals/operations/local/findOne.ts"],"sourcesContent":["import type { GlobalSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformGlobalWithSelect,\n} from '../../../types/index.js'\nimport type { CreateLocalReqOptions } from '../../../utilities/createLocalReq.js'\nimport type { SelectFromGlobalSlug } from '../../config/types.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { findOneOperation } from '../findOne.js'\n\nexport type Options<TSlug extends GlobalSlug, TSelect extends SelectType> = {\n /**\n * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,\n * which can be read by hooks. Useful if you want to pass additional information to the hooks which\n * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook\n * to determine if it should run or not.\n */\n context?: RequestContext\n /**\n * You may pass the document data directly which will skip the `db.findOne` database query.\n * This is useful if you want to use this endpoint solely for running hooks and populating data.\n */\n data?: Record<string, unknown>\n /**\n * [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.\n */\n depth?: number\n /**\n * Whether the document should be queried from the versions table/collection or not. [More](https://payloadcms.com/docs/versions/drafts#draft-api)\n */\n draft?: boolean\n /**\n * Specify a [fallback locale](https://payloadcms.com/docs/configuration/localization) to use for any returned documents.\n */\n fallbackLocale?: false | TypedLocale\n /**\n * Include info about the lock status to the result with fields: `_isLocked` and `_userEditing`\n */\n includeLockStatus?: boolean\n /**\n * Specify [locale](https://payloadcms.com/docs/configuration/localization) for any returned documents.\n */\n locale?: 'all' | TypedLocale\n /**\n * Skip access control.\n * Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.\n * @default true\n */\n overrideAccess?: boolean\n /**\n * Specify [populate](https://payloadcms.com/docs/queries/select#populate) to control which fields to include to the result from populated documents.\n */\n populate?: PopulateType\n /**\n * The `PayloadRequest` object. You can pass it to thread the current [transaction](https://payloadcms.com/docs/database/transactions), user and locale to the operation.\n * Recommended to pass when using the Local API from hooks, as usually you want to execute the operation within the current transaction.\n */\n req?: Partial<PayloadRequest>\n /**\n * Specify [select](https://payloadcms.com/docs/queries/select) to control which fields to include to the result.\n */\n select?: TSelect\n /**\n * Opt-in to receiving hidden fields. By default, they are hidden from returned documents in accordance to your config.\n * @default false\n */\n showHiddenFields?: boolean\n /**\n * the Global slug to operate against.\n */\n slug: TSlug\n /**\n * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.\n */\n user?: Document\n}
|
|
1
|
+
{"version":3,"sources":["../../../../src/globals/operations/local/findOne.ts"],"sourcesContent":["import type { GlobalSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformGlobalWithSelect,\n} from '../../../types/index.js'\nimport type { CreateLocalReqOptions } from '../../../utilities/createLocalReq.js'\nimport type { SelectFromGlobalSlug } from '../../config/types.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { findOneOperation, type GlobalFindOneArgs } from '../findOne.js'\n\nexport type Options<TSlug extends GlobalSlug, TSelect extends SelectType> = {\n /**\n * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,\n * which can be read by hooks. Useful if you want to pass additional information to the hooks which\n * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook\n * to determine if it should run or not.\n */\n context?: RequestContext\n /**\n * You may pass the document data directly which will skip the `db.findOne` database query.\n * This is useful if you want to use this endpoint solely for running hooks and populating data.\n */\n data?: Record<string, unknown>\n /**\n * [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.\n */\n depth?: number\n /**\n * Whether the document should be queried from the versions table/collection or not. [More](https://payloadcms.com/docs/versions/drafts#draft-api)\n */\n draft?: boolean\n /**\n * Specify a [fallback locale](https://payloadcms.com/docs/configuration/localization) to use for any returned documents.\n */\n fallbackLocale?: false | TypedLocale\n /**\n * Include info about the lock status to the result with fields: `_isLocked` and `_userEditing`\n */\n includeLockStatus?: boolean\n /**\n * Specify [locale](https://payloadcms.com/docs/configuration/localization) for any returned documents.\n */\n locale?: 'all' | TypedLocale\n /**\n * Skip access control.\n * Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.\n * @default true\n */\n overrideAccess?: boolean\n /**\n * Specify [populate](https://payloadcms.com/docs/queries/select#populate) to control which fields to include to the result from populated documents.\n */\n populate?: PopulateType\n /**\n * The `PayloadRequest` object. You can pass it to thread the current [transaction](https://payloadcms.com/docs/database/transactions), user and locale to the operation.\n * Recommended to pass when using the Local API from hooks, as usually you want to execute the operation within the current transaction.\n */\n req?: Partial<PayloadRequest>\n /**\n * Specify [select](https://payloadcms.com/docs/queries/select) to control which fields to include to the result.\n */\n select?: TSelect\n /**\n * Opt-in to receiving hidden fields. By default, they are hidden from returned documents in accordance to your config.\n * @default false\n */\n showHiddenFields?: boolean\n /**\n * the Global slug to operate against.\n */\n slug: TSlug\n /**\n * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.\n */\n user?: Document\n} & Pick<GlobalFindOneArgs, 'flattenLocales'>\n\nexport async function findOneGlobalLocal<\n TSlug extends GlobalSlug,\n TSelect extends SelectFromGlobalSlug<TSlug>,\n>(\n payload: Payload,\n options: Options<TSlug, TSelect>,\n): Promise<TransformGlobalWithSelect<TSlug, TSelect>> {\n const {\n slug: globalSlug,\n data,\n depth,\n draft = false,\n flattenLocales,\n includeLockStatus,\n overrideAccess = true,\n populate,\n select,\n showHiddenFields,\n } = options\n\n const globalConfig = payload.globals.config.find((config) => config.slug === globalSlug)\n\n if (!globalConfig) {\n throw new APIError(`The global with slug ${String(globalSlug)} can't be found.`)\n }\n\n return findOneOperation({\n slug: globalSlug as string,\n data,\n depth,\n draft,\n flattenLocales,\n globalConfig,\n includeLockStatus,\n overrideAccess,\n populate,\n req: await createLocalReq(options as CreateLocalReqOptions, payload),\n select,\n showHiddenFields,\n })\n}\n"],"names":["APIError","createLocalReq","findOneOperation","findOneGlobalLocal","payload","options","slug","globalSlug","data","depth","draft","flattenLocales","includeLockStatus","overrideAccess","populate","select","showHiddenFields","globalConfig","globals","config","find","String","req"],"mappings":"AAWA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,gBAAgB,QAAgC,gBAAe;AAqExE,OAAO,eAAeC,mBAIpBC,OAAgB,EAChBC,OAAgC;IAEhC,MAAM,EACJC,MAAMC,UAAU,EAChBC,IAAI,EACJC,KAAK,EACLC,QAAQ,KAAK,EACbC,cAAc,EACdC,iBAAiB,EACjBC,iBAAiB,IAAI,EACrBC,QAAQ,EACRC,MAAM,EACNC,gBAAgB,EACjB,GAAGX;IAEJ,MAAMY,eAAeb,QAAQc,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOb,IAAI,KAAKC;IAE7E,IAAI,CAACU,cAAc;QACjB,MAAM,IAAIjB,SAAS,CAAC,qBAAqB,EAAEqB,OAAOd,YAAY,gBAAgB,CAAC;IACjF;IAEA,OAAOL,iBAAiB;QACtBI,MAAMC;QACNC;QACAC;QACAC;QACAC;QACAM;QACAL;QACAC;QACAC;QACAQ,KAAK,MAAMrB,eAAeI,SAAkCD;QAC5DW;QACAC;IACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payload",
|
|
3
|
-
"version": "3.56.0-
|
|
3
|
+
"version": "3.56.0-internal.457de85",
|
|
4
4
|
"description": "Node, React, Headless CMS and Application Framework built on Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"admin panel",
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"undici": "7.10.0",
|
|
102
102
|
"uuid": "10.0.0",
|
|
103
103
|
"ws": "^8.16.0",
|
|
104
|
-
"@payloadcms/translations": "3.56.0-
|
|
104
|
+
"@payloadcms/translations": "3.56.0-internal.457de85"
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|
|
107
107
|
"@hyrious/esbuild-plugin-commonjs": "0.2.6",
|