@payloadcms/live-preview 3.44.0-internal.6b79dc2 → 3.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mergeData.js +1 -1
- package/dist/mergeData.js.map +1 -1
- package/package.json +2 -2
package/dist/mergeData.js
CHANGED
|
@@ -33,7 +33,7 @@ export const mergeData = async (args)=>{
|
|
|
33
33
|
try {
|
|
34
34
|
res = await requestHandler({
|
|
35
35
|
apiPath: apiRoute || '/api',
|
|
36
|
-
endpoint: encodeURI(`${collection}?depth=${depth}&where[id][in]=${Array.from(ids).join(',')}${locale ? `&locale=${locale}` : ''}`),
|
|
36
|
+
endpoint: encodeURI(`${collection}?depth=${depth}&limit=${ids.size}&where[id][in]=${Array.from(ids).join(',')}${locale ? `&locale=${locale}` : ''}`),
|
|
37
37
|
serverURL
|
|
38
38
|
}).then((res)=>res.json());
|
|
39
39
|
if (res?.docs?.length > 0) {
|
package/dist/mergeData.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mergeData.ts"],"sourcesContent":["import type { DocumentEvent, FieldSchemaJSON, PaginatedDocs } from 'payload'\n\nimport type { CollectionPopulationRequestHandler, PopulationsByCollection } from './types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\nconst defaultRequestHandler = ({\n apiPath,\n endpoint,\n serverURL,\n}: {\n apiPath: string\n endpoint: string\n serverURL: string\n}) => {\n const url = `${serverURL}${apiPath}/${endpoint}`\n return fetch(url, {\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n}\n\n// Relationships are only updated when their `id` or `relationTo` changes, by comparing the old and new values\n// This needs to also happen when locale changes, except this is not not part of the API response\n// Instead, we keep track of the old locale ourselves and trigger a re-population when it changes\nlet prevLocale: string | undefined\n\nexport const mergeData = async <T extends Record<string, any>>(args: {\n apiRoute?: string\n /**\n * @deprecated Use `requestHandler` instead\n */\n collectionPopulationRequestHandler?: CollectionPopulationRequestHandler\n depth?: number\n externallyUpdatedRelationship?: DocumentEvent\n fieldSchema: FieldSchemaJSON\n incomingData: Partial<T>\n initialData: T\n locale?: string\n requestHandler?: CollectionPopulationRequestHandler\n returnNumberOfRequests?: boolean\n serverURL: string\n}): Promise<\n {\n _numberOfRequests?: number\n } & T\n> => {\n const {\n apiRoute,\n depth,\n externallyUpdatedRelationship,\n fieldSchema,\n incomingData,\n initialData,\n locale,\n returnNumberOfRequests,\n serverURL,\n } = args\n\n const result = { ...initialData }\n\n const populationsByCollection: PopulationsByCollection = {}\n\n traverseFields({\n externallyUpdatedRelationship,\n fieldSchema,\n incomingData,\n localeChanged: prevLocale !== locale,\n populationsByCollection,\n result,\n })\n\n await Promise.all(\n Object.entries(populationsByCollection).map(async ([collection, populations]) => {\n let res: PaginatedDocs\n\n const ids = new Set(populations.map(({ id }) => id))\n const requestHandler =\n args.collectionPopulationRequestHandler || args.requestHandler || defaultRequestHandler\n\n try {\n res = await requestHandler({\n apiPath: apiRoute || '/api',\n endpoint: encodeURI(\n `${collection}?depth=${depth}&where[id][in]=${Array.from(ids).join(',')}${locale ? `&locale=${locale}` : ''}`,\n ),\n serverURL,\n }).then((res) => res.json())\n\n if (res?.docs?.length > 0) {\n res.docs.forEach((doc) => {\n populationsByCollection[collection]?.forEach((population) => {\n if (population.id === doc.id) {\n population.ref[population.accessor] = doc\n }\n })\n })\n }\n } catch (err) {\n console.error(err) // eslint-disable-line no-console\n }\n }),\n )\n\n prevLocale = locale\n\n return {\n ...result,\n ...(returnNumberOfRequests\n ? { _numberOfRequests: Object.keys(populationsByCollection).length }\n : {}),\n }\n}\n"],"names":["traverseFields","defaultRequestHandler","apiPath","endpoint","serverURL","url","fetch","credentials","headers","prevLocale","mergeData","args","apiRoute","depth","externallyUpdatedRelationship","fieldSchema","incomingData","initialData","locale","returnNumberOfRequests","result","populationsByCollection","localeChanged","Promise","all","Object","entries","map","collection","populations","res","ids","Set","id","requestHandler","collectionPopulationRequestHandler","encodeURI","Array","from","join","then","json","docs","length","forEach","doc","population","ref","accessor","err","console","error","_numberOfRequests","keys"],"mappings":"AAIA,SAASA,cAAc,QAAQ,sBAAqB;AAEpD,MAAMC,wBAAwB,CAAC,EAC7BC,OAAO,EACPC,QAAQ,EACRC,SAAS,EAKV;IACC,MAAMC,MAAM,GAAGD,YAAYF,QAAQ,CAAC,EAAEC,UAAU;IAChD,OAAOG,MAAMD,KAAK;QAChBE,aAAa;QACbC,SAAS;YACP,gBAAgB;QAClB;IACF;AACF;AAEA,8GAA8G;AAC9G,iGAAiG;AACjG,iGAAiG;AACjG,IAAIC;AAEJ,OAAO,MAAMC,YAAY,OAAsCC;IAoB7D,MAAM,EACJC,QAAQ,EACRC,KAAK,EACLC,6BAA6B,EAC7BC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,MAAM,EACNC,sBAAsB,EACtBf,SAAS,EACV,GAAGO;IAEJ,MAAMS,SAAS;QAAE,GAAGH,WAAW;IAAC;IAEhC,MAAMI,0BAAmD,CAAC;IAE1DrB,eAAe;QACbc;QACAC;QACAC;QACAM,eAAeb,eAAeS;QAC9BG;QACAD;IACF;IAEA,MAAMG,QAAQC,GAAG,CACfC,OAAOC,OAAO,CAACL,yBAAyBM,GAAG,CAAC,OAAO,CAACC,YAAYC,YAAY;QAC1E,IAAIC;QAEJ,MAAMC,MAAM,IAAIC,IAAIH,YAAYF,GAAG,CAAC,CAAC,EAAEM,EAAE,EAAE,GAAKA;QAChD,MAAMC,iBACJvB,KAAKwB,kCAAkC,IAAIxB,KAAKuB,cAAc,IAAIjC;QAEpE,IAAI;YACF6B,MAAM,MAAMI,eAAe;gBACzBhC,SAASU,YAAY;gBACrBT,UAAUiC,UACR,GAAGR,WAAW,OAAO,EAAEf,MAAM,eAAe,
|
|
1
|
+
{"version":3,"sources":["../src/mergeData.ts"],"sourcesContent":["import type { DocumentEvent, FieldSchemaJSON, PaginatedDocs } from 'payload'\n\nimport type { CollectionPopulationRequestHandler, PopulationsByCollection } from './types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\nconst defaultRequestHandler = ({\n apiPath,\n endpoint,\n serverURL,\n}: {\n apiPath: string\n endpoint: string\n serverURL: string\n}) => {\n const url = `${serverURL}${apiPath}/${endpoint}`\n return fetch(url, {\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n}\n\n// Relationships are only updated when their `id` or `relationTo` changes, by comparing the old and new values\n// This needs to also happen when locale changes, except this is not not part of the API response\n// Instead, we keep track of the old locale ourselves and trigger a re-population when it changes\nlet prevLocale: string | undefined\n\nexport const mergeData = async <T extends Record<string, any>>(args: {\n apiRoute?: string\n /**\n * @deprecated Use `requestHandler` instead\n */\n collectionPopulationRequestHandler?: CollectionPopulationRequestHandler\n depth?: number\n externallyUpdatedRelationship?: DocumentEvent\n fieldSchema: FieldSchemaJSON\n incomingData: Partial<T>\n initialData: T\n locale?: string\n requestHandler?: CollectionPopulationRequestHandler\n returnNumberOfRequests?: boolean\n serverURL: string\n}): Promise<\n {\n _numberOfRequests?: number\n } & T\n> => {\n const {\n apiRoute,\n depth,\n externallyUpdatedRelationship,\n fieldSchema,\n incomingData,\n initialData,\n locale,\n returnNumberOfRequests,\n serverURL,\n } = args\n\n const result = { ...initialData }\n\n const populationsByCollection: PopulationsByCollection = {}\n\n traverseFields({\n externallyUpdatedRelationship,\n fieldSchema,\n incomingData,\n localeChanged: prevLocale !== locale,\n populationsByCollection,\n result,\n })\n\n await Promise.all(\n Object.entries(populationsByCollection).map(async ([collection, populations]) => {\n let res: PaginatedDocs\n\n const ids = new Set(populations.map(({ id }) => id))\n const requestHandler =\n args.collectionPopulationRequestHandler || args.requestHandler || defaultRequestHandler\n\n try {\n res = await requestHandler({\n apiPath: apiRoute || '/api',\n endpoint: encodeURI(\n `${collection}?depth=${depth}&limit=${ids.size}&where[id][in]=${Array.from(ids).join(',')}${locale ? `&locale=${locale}` : ''}`,\n ),\n serverURL,\n }).then((res) => res.json())\n\n if (res?.docs?.length > 0) {\n res.docs.forEach((doc) => {\n populationsByCollection[collection]?.forEach((population) => {\n if (population.id === doc.id) {\n population.ref[population.accessor] = doc\n }\n })\n })\n }\n } catch (err) {\n console.error(err) // eslint-disable-line no-console\n }\n }),\n )\n\n prevLocale = locale\n\n return {\n ...result,\n ...(returnNumberOfRequests\n ? { _numberOfRequests: Object.keys(populationsByCollection).length }\n : {}),\n }\n}\n"],"names":["traverseFields","defaultRequestHandler","apiPath","endpoint","serverURL","url","fetch","credentials","headers","prevLocale","mergeData","args","apiRoute","depth","externallyUpdatedRelationship","fieldSchema","incomingData","initialData","locale","returnNumberOfRequests","result","populationsByCollection","localeChanged","Promise","all","Object","entries","map","collection","populations","res","ids","Set","id","requestHandler","collectionPopulationRequestHandler","encodeURI","size","Array","from","join","then","json","docs","length","forEach","doc","population","ref","accessor","err","console","error","_numberOfRequests","keys"],"mappings":"AAIA,SAASA,cAAc,QAAQ,sBAAqB;AAEpD,MAAMC,wBAAwB,CAAC,EAC7BC,OAAO,EACPC,QAAQ,EACRC,SAAS,EAKV;IACC,MAAMC,MAAM,GAAGD,YAAYF,QAAQ,CAAC,EAAEC,UAAU;IAChD,OAAOG,MAAMD,KAAK;QAChBE,aAAa;QACbC,SAAS;YACP,gBAAgB;QAClB;IACF;AACF;AAEA,8GAA8G;AAC9G,iGAAiG;AACjG,iGAAiG;AACjG,IAAIC;AAEJ,OAAO,MAAMC,YAAY,OAAsCC;IAoB7D,MAAM,EACJC,QAAQ,EACRC,KAAK,EACLC,6BAA6B,EAC7BC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,MAAM,EACNC,sBAAsB,EACtBf,SAAS,EACV,GAAGO;IAEJ,MAAMS,SAAS;QAAE,GAAGH,WAAW;IAAC;IAEhC,MAAMI,0BAAmD,CAAC;IAE1DrB,eAAe;QACbc;QACAC;QACAC;QACAM,eAAeb,eAAeS;QAC9BG;QACAD;IACF;IAEA,MAAMG,QAAQC,GAAG,CACfC,OAAOC,OAAO,CAACL,yBAAyBM,GAAG,CAAC,OAAO,CAACC,YAAYC,YAAY;QAC1E,IAAIC;QAEJ,MAAMC,MAAM,IAAIC,IAAIH,YAAYF,GAAG,CAAC,CAAC,EAAEM,EAAE,EAAE,GAAKA;QAChD,MAAMC,iBACJvB,KAAKwB,kCAAkC,IAAIxB,KAAKuB,cAAc,IAAIjC;QAEpE,IAAI;YACF6B,MAAM,MAAMI,eAAe;gBACzBhC,SAASU,YAAY;gBACrBT,UAAUiC,UACR,GAAGR,WAAW,OAAO,EAAEf,MAAM,OAAO,EAAEkB,IAAIM,IAAI,CAAC,eAAe,EAAEC,MAAMC,IAAI,CAACR,KAAKS,IAAI,CAAC,OAAOtB,SAAS,CAAC,QAAQ,EAAEA,QAAQ,GAAG,IAAI;gBAEjId;YACF,GAAGqC,IAAI,CAAC,CAACX,MAAQA,IAAIY,IAAI;YAEzB,IAAIZ,KAAKa,MAAMC,SAAS,GAAG;gBACzBd,IAAIa,IAAI,CAACE,OAAO,CAAC,CAACC;oBAChBzB,uBAAuB,CAACO,WAAW,EAAEiB,QAAQ,CAACE;wBAC5C,IAAIA,WAAWd,EAAE,KAAKa,IAAIb,EAAE,EAAE;4BAC5Bc,WAAWC,GAAG,CAACD,WAAWE,QAAQ,CAAC,GAAGH;wBACxC;oBACF;gBACF;YACF;QACF,EAAE,OAAOI,KAAK;YACZC,QAAQC,KAAK,CAACF,KAAK,iCAAiC;;QACtD;IACF;IAGFzC,aAAaS;IAEb,OAAO;QACL,GAAGE,MAAM;QACT,GAAID,yBACA;YAAEkC,mBAAmB5B,OAAO6B,IAAI,CAACjC,yBAAyBuB,MAAM;QAAC,IACjE,CAAC,CAAC;IACR;AACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/live-preview",
|
|
3
|
-
"version": "3.44.0
|
|
3
|
+
"version": "3.44.0",
|
|
4
4
|
"description": "The official live preview JavaScript SDK for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@payloadcms/eslint-config": "3.28.0",
|
|
36
|
-
"payload": "3.44.0
|
|
36
|
+
"payload": "3.44.0"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"registry": "https://registry.npmjs.org/"
|