{"version":3,"sources":["../../../../src/globals/operations/local/update.ts"],"sourcesContent":["import type { DeepPartial } from 'ts-essentials'\n\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 {\n DataFromGlobalSlug,\n DraftFlagFromGlobalSlug,\n SelectFromGlobalSlug,\n} from '../../config/types.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport {\n deepCopyObjectSimple,\n type FindOptions,\n type GlobalSlug,\n type Payload,\n type RequestContext,\n type TypedLocale,\n} from '../../../index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { updateOperation } from '../update.js'\n\ntype BaseOptions = {\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 global data to update.\n */\n data: DeepPartial, 'id'>>\n /**\n * [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.\n */\n depth?: number\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 * 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 * If you are uploading a file and would like to replace\n * the existing file instead of generating a new filename,\n * you can set the following property to `true`\n */\n overrideLock?: 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 * Publish the document / documents in all locales. Requires `versions.drafts.localizeStatus` to be enabled.\n *\n * @default undefined\n */\n publishAllLocales?: boolean\n /**\n * Publish the document / documents with a specific locale.\n */\n publishSpecificLocale?: TypedLocale\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\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 * Unpublish the document / documents in all locales. Requires `versions.drafts.localizeStatus` to be enabled.\n */\n unpublishAllLocales?: boolean\n // TODO: Strongly type User as TypedUser (= User in v4.0)\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, 'select'>\n\nexport type Options =\n BaseOptions & DraftFlagFromGlobalSlug\n\nexport async function updateGlobalLocal<\n TSlug extends GlobalSlug,\n TSelect extends SelectFromGlobalSlug,\n>(\n payload: Payload,\n options: Options,\n): Promise> {\n const {\n slug: globalSlug,\n data,\n depth,\n draft,\n overrideAccess = true,\n overrideLock,\n populate,\n publishAllLocales,\n publishSpecificLocale,\n select,\n showHiddenFields,\n unpublishAllLocales,\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 updateOperation({\n slug: globalSlug as string,\n data: deepCopyObjectSimple(data), // Ensure mutation of data in create operation hooks doesn't affect the original data\n depth,\n draft,\n globalConfig,\n overrideAccess,\n overrideLock,\n populate,\n publishAllLocales,\n publishSpecificLocale: publishSpecificLocale!,\n req: await createLocalReq(options as CreateLocalReqOptions, payload),\n select,\n showHiddenFields,\n unpublishAllLocales,\n })\n}\n"],"names":["APIError","deepCopyObjectSimple","createLocalReq","updateOperation","updateGlobalLocal","payload","options","slug","globalSlug","data","depth","draft","overrideAccess","overrideLock","populate","publishAllLocales","publishSpecificLocale","select","showHiddenFields","unpublishAllLocales","globalConfig","globals","config","find","String","req"],"mappings":"AAgBA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SACEC,oBAAoB,QAMf,oBAAmB;AAC1B,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,eAAe,QAAQ,eAAc;AAgF9C,OAAO,eAAeC,kBAIpBC,OAAgB,EAChBC,OAAgC;IAEhC,MAAM,EACJC,MAAMC,UAAU,EAChBC,IAAI,EACJC,KAAK,EACLC,KAAK,EACLC,iBAAiB,IAAI,EACrBC,YAAY,EACZC,QAAQ,EACRC,iBAAiB,EACjBC,qBAAqB,EACrBC,MAAM,EACNC,gBAAgB,EAChBC,mBAAmB,EACpB,GAAGb;IAEJ,MAAMc,eAAef,QAAQgB,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOf,IAAI,KAAKC;IAE7E,IAAI,CAACY,cAAc;QACjB,MAAM,IAAIpB,SAAS,CAAC,qBAAqB,EAAEwB,OAAOhB,YAAY,gBAAgB,CAAC;IACjF;IAEA,OAAOL,gBAAgC;QACrCI,MAAMC;QACNC,MAAMR,qBAAqBQ;QAC3BC;QACAC;QACAS;QACAR;QACAC;QACAC;QACAC;QACAC,uBAAuBA;QACvBS,KAAK,MAAMvB,eAAeI,SAAkCD;QAC5DY;QACAC;QACAC;IACF;AACF"}