payload 3.66.0 → 3.67.0-internal.1ea538b

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.
Files changed (121) hide show
  1. package/dist/auth/operations/forgotPassword.d.ts.map +1 -1
  2. package/dist/auth/operations/forgotPassword.js +7 -12
  3. package/dist/auth/operations/forgotPassword.js.map +1 -1
  4. package/dist/auth/operations/login.d.ts.map +1 -1
  5. package/dist/auth/operations/login.js +7 -12
  6. package/dist/auth/operations/login.js.map +1 -1
  7. package/dist/auth/operations/refresh.d.ts.map +1 -1
  8. package/dist/auth/operations/refresh.js +7 -12
  9. package/dist/auth/operations/refresh.js.map +1 -1
  10. package/dist/auth/operations/resetPassword.d.ts.map +1 -1
  11. package/dist/auth/operations/resetPassword.js +7 -12
  12. package/dist/auth/operations/resetPassword.js.map +1 -1
  13. package/dist/auth/operations/unlock.d.ts.map +1 -1
  14. package/dist/auth/operations/unlock.js +14 -1
  15. package/dist/auth/operations/unlock.js.map +1 -1
  16. package/dist/collections/config/sanitize.d.ts.map +1 -1
  17. package/dist/collections/config/sanitize.js +2 -0
  18. package/dist/collections/config/sanitize.js.map +1 -1
  19. package/dist/collections/config/types.d.ts +7 -19
  20. package/dist/collections/config/types.d.ts.map +1 -1
  21. package/dist/collections/config/types.js.map +1 -1
  22. package/dist/collections/operations/count.d.ts.map +1 -1
  23. package/dist/collections/operations/count.js +7 -12
  24. package/dist/collections/operations/count.js.map +1 -1
  25. package/dist/collections/operations/countVersions.d.ts.map +1 -1
  26. package/dist/collections/operations/countVersions.js +7 -12
  27. package/dist/collections/operations/countVersions.js.map +1 -1
  28. package/dist/collections/operations/create.d.ts.map +1 -1
  29. package/dist/collections/operations/create.js +10 -14
  30. package/dist/collections/operations/create.js.map +1 -1
  31. package/dist/collections/operations/delete.d.ts.map +1 -1
  32. package/dist/collections/operations/delete.js +9 -13
  33. package/dist/collections/operations/delete.js.map +1 -1
  34. package/dist/collections/operations/deleteByID.d.ts.map +1 -1
  35. package/dist/collections/operations/deleteByID.js +9 -13
  36. package/dist/collections/operations/deleteByID.js.map +1 -1
  37. package/dist/collections/operations/find.d.ts.map +1 -1
  38. package/dist/collections/operations/find.js +9 -13
  39. package/dist/collections/operations/find.js.map +1 -1
  40. package/dist/collections/operations/findByID.d.ts.map +1 -1
  41. package/dist/collections/operations/findByID.js +22 -26
  42. package/dist/collections/operations/findByID.js.map +1 -1
  43. package/dist/collections/operations/findDistinct.d.ts.map +1 -1
  44. package/dist/collections/operations/findDistinct.js +7 -12
  45. package/dist/collections/operations/findDistinct.js.map +1 -1
  46. package/dist/collections/operations/findVersionByID.d.ts.map +1 -1
  47. package/dist/collections/operations/findVersionByID.js +20 -1
  48. package/dist/collections/operations/findVersionByID.js.map +1 -1
  49. package/dist/collections/operations/findVersions.d.ts.map +1 -1
  50. package/dist/collections/operations/findVersions.js +24 -5
  51. package/dist/collections/operations/findVersions.js.map +1 -1
  52. package/dist/collections/operations/restoreVersion.d.ts.map +1 -1
  53. package/dist/collections/operations/restoreVersion.js +9 -13
  54. package/dist/collections/operations/restoreVersion.js.map +1 -1
  55. package/dist/collections/operations/update.d.ts.map +1 -1
  56. package/dist/collections/operations/update.js +9 -13
  57. package/dist/collections/operations/update.js.map +1 -1
  58. package/dist/collections/operations/updateByID.d.ts.map +1 -1
  59. package/dist/collections/operations/updateByID.js +7 -12
  60. package/dist/collections/operations/updateByID.js.map +1 -1
  61. package/dist/collections/operations/utilities/buildAfterOperation.d.ts +6 -0
  62. package/dist/collections/operations/utilities/buildAfterOperation.d.ts.map +1 -0
  63. package/dist/collections/operations/{utils.js → utilities/buildAfterOperation.js} +1 -1
  64. package/dist/collections/operations/utilities/buildAfterOperation.js.map +1 -0
  65. package/dist/collections/operations/utilities/buildBeforeOperation.d.ts +47 -0
  66. package/dist/collections/operations/utilities/buildBeforeOperation.d.ts.map +1 -0
  67. package/dist/collections/operations/utilities/buildBeforeOperation.js +25 -0
  68. package/dist/collections/operations/utilities/buildBeforeOperation.js.map +1 -0
  69. package/dist/collections/operations/utilities/types.d.ts +216 -0
  70. package/dist/collections/operations/utilities/types.d.ts.map +1 -0
  71. package/dist/collections/operations/utilities/types.js +23 -0
  72. package/dist/collections/operations/utilities/types.js.map +1 -0
  73. package/dist/collections/operations/utilities/update.d.ts.map +1 -1
  74. package/dist/collections/operations/utilities/update.js +4 -2
  75. package/dist/collections/operations/utilities/update.js.map +1 -1
  76. package/dist/config/sanitize.d.ts.map +1 -1
  77. package/dist/config/sanitize.js +2 -2
  78. package/dist/config/sanitize.js.map +1 -1
  79. package/dist/exports/shared.d.ts +1 -0
  80. package/dist/exports/shared.d.ts.map +1 -1
  81. package/dist/exports/shared.js +1 -0
  82. package/dist/exports/shared.js.map +1 -1
  83. package/dist/fields/baseFields/slug/generateSlug.d.ts.map +1 -1
  84. package/dist/fields/baseFields/slug/generateSlug.js +2 -2
  85. package/dist/fields/baseFields/slug/generateSlug.js.map +1 -1
  86. package/dist/fields/config/types.d.ts +2 -0
  87. package/dist/fields/config/types.d.ts.map +1 -1
  88. package/dist/fields/config/types.js.map +1 -1
  89. package/dist/globals/config/types.d.ts +1 -1
  90. package/dist/globals/config/types.d.ts.map +1 -1
  91. package/dist/globals/config/types.js.map +1 -1
  92. package/dist/globals/operations/findOne.d.ts.map +1 -1
  93. package/dist/globals/operations/findOne.js +4 -3
  94. package/dist/globals/operations/findOne.js.map +1 -1
  95. package/dist/globals/operations/update.d.ts.map +1 -1
  96. package/dist/globals/operations/update.js +3 -2
  97. package/dist/globals/operations/update.js.map +1 -1
  98. package/dist/index.bundled.d.ts +200 -119
  99. package/dist/utilities/getVersionsConfig.d.ts +37 -0
  100. package/dist/utilities/getVersionsConfig.d.ts.map +1 -0
  101. package/dist/utilities/getVersionsConfig.js +44 -0
  102. package/dist/utilities/getVersionsConfig.js.map +1 -0
  103. package/dist/versions/buildCollectionFields.d.ts.map +1 -1
  104. package/dist/versions/buildCollectionFields.js +3 -2
  105. package/dist/versions/buildCollectionFields.js.map +1 -1
  106. package/dist/versions/buildGlobalFields.d.ts.map +1 -1
  107. package/dist/versions/buildGlobalFields.js +3 -2
  108. package/dist/versions/buildGlobalFields.js.map +1 -1
  109. package/dist/versions/getLatestCollectionVersion.d.ts.map +1 -1
  110. package/dist/versions/getLatestCollectionVersion.js +3 -1
  111. package/dist/versions/getLatestCollectionVersion.js.map +1 -1
  112. package/dist/versions/getLatestGlobalVersion.d.ts.map +1 -1
  113. package/dist/versions/getLatestGlobalVersion.js +3 -2
  114. package/dist/versions/getLatestGlobalVersion.js.map +1 -1
  115. package/dist/versions/saveVersion.d.ts.map +1 -1
  116. package/dist/versions/saveVersion.js +2 -1
  117. package/dist/versions/saveVersion.js.map +1 -1
  118. package/package.json +2 -2
  119. package/dist/collections/operations/utils.d.ts +0 -105
  120. package/dist/collections/operations/utils.d.ts.map +0 -1
  121. package/dist/collections/operations/utils.js.map +0 -1
@@ -1,3 +1,4 @@
1
+ import { hasAutosaveEnabled, hasDraftsEnabled } from '../utilities/getVersionsConfig.js';
1
2
  import { versionSnapshotField } from './baseFields.js';
2
3
  export const buildVersionCollectionFields = (config, collection, flatten)=>{
3
4
  const fields = [
@@ -32,7 +33,7 @@ export const buildVersionCollectionFields = (config, collection, flatten)=>{
32
33
  index: true
33
34
  }
34
35
  ];
35
- if (collection?.versions?.drafts) {
36
+ if (hasDraftsEnabled(collection)) {
36
37
  if (config.localization) {
37
38
  fields.push(versionSnapshotField);
38
39
  fields.push({
@@ -59,7 +60,7 @@ export const buildVersionCollectionFields = (config, collection, flatten)=>{
59
60
  },
60
61
  index: true
61
62
  });
62
- if (collection?.versions?.drafts?.autosave) {
63
+ if (hasAutosaveEnabled(collection)) {
63
64
  fields.push({
64
65
  name: 'autosave',
65
66
  type: 'checkbox',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/versions/buildCollectionFields.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedConfig } from '../config/types.js'\nimport type { Field, FlattenedField } from '../fields/config/types.js'\n\nimport { versionSnapshotField } from './baseFields.js'\n\nexport const buildVersionCollectionFields = <T extends boolean = false>(\n config: SanitizedConfig,\n collection: SanitizedCollectionConfig,\n flatten?: T,\n): true extends T ? FlattenedField[] : Field[] => {\n const fields: FlattenedField[] = [\n {\n name: 'parent',\n type: 'relationship',\n index: true,\n relationTo: collection.slug,\n },\n {\n name: 'version',\n type: 'group',\n fields: collection.fields.filter((field) => !('name' in field) || field.name !== 'id'),\n ...(flatten && {\n flattenedFields: collection.flattenedFields.filter((each) => each.name !== 'id'),\n })!,\n },\n {\n name: 'createdAt',\n type: 'date',\n admin: {\n disabled: true,\n },\n index: true,\n },\n {\n name: 'updatedAt',\n type: 'date',\n admin: {\n disabled: true,\n },\n index: true,\n },\n ]\n\n if (collection?.versions?.drafts) {\n if (config.localization) {\n fields.push(versionSnapshotField)\n\n fields.push({\n name: 'publishedLocale',\n type: 'select',\n admin: {\n disableBulkEdit: true,\n disabled: true,\n },\n index: true,\n options: config.localization.locales.map((locale) => {\n if (typeof locale === 'string') {\n return locale\n }\n\n return locale.code\n }),\n })\n }\n\n fields.push({\n name: 'latest',\n type: 'checkbox',\n admin: {\n disabled: true,\n },\n index: true,\n })\n\n if (collection?.versions?.drafts?.autosave) {\n fields.push({\n name: 'autosave',\n type: 'checkbox',\n index: true,\n })\n }\n }\n\n return fields as true extends T ? FlattenedField[] : Field[]\n}\n"],"names":["versionSnapshotField","buildVersionCollectionFields","config","collection","flatten","fields","name","type","index","relationTo","slug","filter","field","flattenedFields","each","admin","disabled","versions","drafts","localization","push","disableBulkEdit","options","locales","map","locale","code","autosave"],"mappings":"AAIA,SAASA,oBAAoB,QAAQ,kBAAiB;AAEtD,OAAO,MAAMC,+BAA+B,CAC1CC,QACAC,YACAC;IAEA,MAAMC,SAA2B;QAC/B;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO;YACPC,YAAYN,WAAWO,IAAI;QAC7B;QACA;YACEJ,MAAM;YACNC,MAAM;YACNF,QAAQF,WAAWE,MAAM,CAACM,MAAM,CAAC,CAACC,QAAU,CAAE,CAAA,UAAUA,KAAI,KAAMA,MAAMN,IAAI,KAAK;YACjF,GAAIF,WAAW;gBACbS,iBAAiBV,WAAWU,eAAe,CAACF,MAAM,CAAC,CAACG,OAASA,KAAKR,IAAI,KAAK;YAC7E,CAAC;QACH;QACA;YACEA,MAAM;YACNC,MAAM;YACNQ,OAAO;gBACLC,UAAU;YACZ;YACAR,OAAO;QACT;QACA;YACEF,MAAM;YACNC,MAAM;YACNQ,OAAO;gBACLC,UAAU;YACZ;YACAR,OAAO;QACT;KACD;IAED,IAAIL,YAAYc,UAAUC,QAAQ;QAChC,IAAIhB,OAAOiB,YAAY,EAAE;YACvBd,OAAOe,IAAI,CAACpB;YAEZK,OAAOe,IAAI,CAAC;gBACVd,MAAM;gBACNC,MAAM;gBACNQ,OAAO;oBACLM,iBAAiB;oBACjBL,UAAU;gBACZ;gBACAR,OAAO;gBACPc,SAASpB,OAAOiB,YAAY,CAACI,OAAO,CAACC,GAAG,CAAC,CAACC;oBACxC,IAAI,OAAOA,WAAW,UAAU;wBAC9B,OAAOA;oBACT;oBAEA,OAAOA,OAAOC,IAAI;gBACpB;YACF;QACF;QAEArB,OAAOe,IAAI,CAAC;YACVd,MAAM;YACNC,MAAM;YACNQ,OAAO;gBACLC,UAAU;YACZ;YACAR,OAAO;QACT;QAEA,IAAIL,YAAYc,UAAUC,QAAQS,UAAU;YAC1CtB,OAAOe,IAAI,CAAC;gBACVd,MAAM;gBACNC,MAAM;gBACNC,OAAO;YACT;QACF;IACF;IAEA,OAAOH;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/versions/buildCollectionFields.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedConfig } from '../config/types.js'\nimport type { Field, FlattenedField } from '../fields/config/types.js'\n\nimport { hasAutosaveEnabled, hasDraftsEnabled } from '../utilities/getVersionsConfig.js'\nimport { versionSnapshotField } from './baseFields.js'\n\nexport const buildVersionCollectionFields = <T extends boolean = false>(\n config: SanitizedConfig,\n collection: SanitizedCollectionConfig,\n flatten?: T,\n): true extends T ? FlattenedField[] : Field[] => {\n const fields: FlattenedField[] = [\n {\n name: 'parent',\n type: 'relationship',\n index: true,\n relationTo: collection.slug,\n },\n {\n name: 'version',\n type: 'group',\n fields: collection.fields.filter((field) => !('name' in field) || field.name !== 'id'),\n ...(flatten && {\n flattenedFields: collection.flattenedFields.filter((each) => each.name !== 'id'),\n })!,\n },\n {\n name: 'createdAt',\n type: 'date',\n admin: {\n disabled: true,\n },\n index: true,\n },\n {\n name: 'updatedAt',\n type: 'date',\n admin: {\n disabled: true,\n },\n index: true,\n },\n ]\n\n if (hasDraftsEnabled(collection)) {\n if (config.localization) {\n fields.push(versionSnapshotField)\n\n fields.push({\n name: 'publishedLocale',\n type: 'select',\n admin: {\n disableBulkEdit: true,\n disabled: true,\n },\n index: true,\n options: config.localization.locales.map((locale) => {\n if (typeof locale === 'string') {\n return locale\n }\n\n return locale.code\n }),\n })\n }\n\n fields.push({\n name: 'latest',\n type: 'checkbox',\n admin: {\n disabled: true,\n },\n index: true,\n })\n\n if (hasAutosaveEnabled(collection)) {\n fields.push({\n name: 'autosave',\n type: 'checkbox',\n index: true,\n })\n }\n }\n\n return fields as true extends T ? FlattenedField[] : Field[]\n}\n"],"names":["hasAutosaveEnabled","hasDraftsEnabled","versionSnapshotField","buildVersionCollectionFields","config","collection","flatten","fields","name","type","index","relationTo","slug","filter","field","flattenedFields","each","admin","disabled","localization","push","disableBulkEdit","options","locales","map","locale","code"],"mappings":"AAIA,SAASA,kBAAkB,EAAEC,gBAAgB,QAAQ,oCAAmC;AACxF,SAASC,oBAAoB,QAAQ,kBAAiB;AAEtD,OAAO,MAAMC,+BAA+B,CAC1CC,QACAC,YACAC;IAEA,MAAMC,SAA2B;QAC/B;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO;YACPC,YAAYN,WAAWO,IAAI;QAC7B;QACA;YACEJ,MAAM;YACNC,MAAM;YACNF,QAAQF,WAAWE,MAAM,CAACM,MAAM,CAAC,CAACC,QAAU,CAAE,CAAA,UAAUA,KAAI,KAAMA,MAAMN,IAAI,KAAK;YACjF,GAAIF,WAAW;gBACbS,iBAAiBV,WAAWU,eAAe,CAACF,MAAM,CAAC,CAACG,OAASA,KAAKR,IAAI,KAAK;YAC7E,CAAC;QACH;QACA;YACEA,MAAM;YACNC,MAAM;YACNQ,OAAO;gBACLC,UAAU;YACZ;YACAR,OAAO;QACT;QACA;YACEF,MAAM;YACNC,MAAM;YACNQ,OAAO;gBACLC,UAAU;YACZ;YACAR,OAAO;QACT;KACD;IAED,IAAIT,iBAAiBI,aAAa;QAChC,IAAID,OAAOe,YAAY,EAAE;YACvBZ,OAAOa,IAAI,CAAClB;YAEZK,OAAOa,IAAI,CAAC;gBACVZ,MAAM;gBACNC,MAAM;gBACNQ,OAAO;oBACLI,iBAAiB;oBACjBH,UAAU;gBACZ;gBACAR,OAAO;gBACPY,SAASlB,OAAOe,YAAY,CAACI,OAAO,CAACC,GAAG,CAAC,CAACC;oBACxC,IAAI,OAAOA,WAAW,UAAU;wBAC9B,OAAOA;oBACT;oBAEA,OAAOA,OAAOC,IAAI;gBACpB;YACF;QACF;QAEAnB,OAAOa,IAAI,CAAC;YACVZ,MAAM;YACNC,MAAM;YACNQ,OAAO;gBACLC,UAAU;YACZ;YACAR,OAAO;QACT;QAEA,IAAIV,mBAAmBK,aAAa;YAClCE,OAAOa,IAAI,CAAC;gBACVZ,MAAM;gBACNC,MAAM;gBACNC,OAAO;YACT;QACF;IACF;IAEA,OAAOH;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"buildGlobalFields.d.ts","sourceRoot":"","sources":["../../src/versions/buildGlobalFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AACtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAIvE,eAAO,MAAM,wBAAwB,GAAI,CAAC,SAAS,OAAO,kBAChD,eAAe,UACf,qBAAqB,YACnB,CAAC,KACV,IAAI,SAAS,CAAC,GAAG,cAAc,EAAE,GAAG,KAAK,EAqE3C,CAAA"}
1
+ {"version":3,"file":"buildGlobalFields.d.ts","sourceRoot":"","sources":["../../src/versions/buildGlobalFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AACtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAKvE,eAAO,MAAM,wBAAwB,GAAI,CAAC,SAAS,OAAO,kBAChD,eAAe,UACf,qBAAqB,YACnB,CAAC,KACV,IAAI,SAAS,CAAC,GAAG,cAAc,EAAE,GAAG,KAAK,EAqE3C,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { hasAutosaveEnabled, hasDraftsEnabled } from '../utilities/getVersionsConfig.js';
1
2
  import { versionSnapshotField } from './baseFields.js';
2
3
  export const buildVersionGlobalFields = (config, global, flatten)=>{
3
4
  const fields = [
@@ -26,7 +27,7 @@ export const buildVersionGlobalFields = (config, global, flatten)=>{
26
27
  index: true
27
28
  }
28
29
  ];
29
- if (global?.versions?.drafts) {
30
+ if (hasDraftsEnabled(global)) {
30
31
  if (config.localization) {
31
32
  fields.push(versionSnapshotField);
32
33
  fields.push({
@@ -53,7 +54,7 @@ export const buildVersionGlobalFields = (config, global, flatten)=>{
53
54
  },
54
55
  index: true
55
56
  });
56
- if (global?.versions?.drafts?.autosave) {
57
+ if (hasAutosaveEnabled(global)) {
57
58
  fields.push({
58
59
  name: 'autosave',
59
60
  type: 'checkbox',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/versions/buildGlobalFields.ts"],"sourcesContent":["import type { SanitizedConfig } from '../config/types.js'\nimport type { Field, FlattenedField } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\n\nimport { versionSnapshotField } from './baseFields.js'\n\nexport const buildVersionGlobalFields = <T extends boolean = false>(\n config: SanitizedConfig,\n global: SanitizedGlobalConfig,\n flatten?: T,\n): true extends T ? FlattenedField[] : Field[] => {\n const fields: FlattenedField[] = [\n {\n name: 'version',\n type: 'group',\n fields: global.fields,\n ...(flatten && {\n flattenedFields: global.flattenedFields,\n })!,\n },\n {\n name: 'createdAt',\n type: 'date',\n admin: {\n disabled: true,\n },\n index: true,\n },\n {\n name: 'updatedAt',\n type: 'date',\n admin: {\n disabled: true,\n },\n index: true,\n },\n ]\n\n if (global?.versions?.drafts) {\n if (config.localization) {\n fields.push(versionSnapshotField)\n\n fields.push({\n name: 'publishedLocale',\n type: 'select',\n admin: {\n disableBulkEdit: true,\n disabled: true,\n },\n index: true,\n options: config.localization.locales.map((locale) => {\n if (typeof locale === 'string') {\n return locale\n }\n\n return locale.code\n }),\n })\n }\n\n fields.push({\n name: 'latest',\n type: 'checkbox',\n admin: {\n disabled: true,\n },\n index: true,\n })\n\n if (global?.versions?.drafts?.autosave) {\n fields.push({\n name: 'autosave',\n type: 'checkbox',\n index: true,\n })\n }\n }\n\n return fields as true extends T ? FlattenedField[] : Field[]\n}\n"],"names":["versionSnapshotField","buildVersionGlobalFields","config","global","flatten","fields","name","type","flattenedFields","admin","disabled","index","versions","drafts","localization","push","disableBulkEdit","options","locales","map","locale","code","autosave"],"mappings":"AAIA,SAASA,oBAAoB,QAAQ,kBAAiB;AAEtD,OAAO,MAAMC,2BAA2B,CACtCC,QACAC,QACAC;IAEA,MAAMC,SAA2B;QAC/B;YACEC,MAAM;YACNC,MAAM;YACNF,QAAQF,OAAOE,MAAM;YACrB,GAAID,WAAW;gBACbI,iBAAiBL,OAAOK,eAAe;YACzC,CAAC;QACH;QACA;YACEF,MAAM;YACNC,MAAM;YACNE,OAAO;gBACLC,UAAU;YACZ;YACAC,OAAO;QACT;QACA;YACEL,MAAM;YACNC,MAAM;YACNE,OAAO;gBACLC,UAAU;YACZ;YACAC,OAAO;QACT;KACD;IAED,IAAIR,QAAQS,UAAUC,QAAQ;QAC5B,IAAIX,OAAOY,YAAY,EAAE;YACvBT,OAAOU,IAAI,CAACf;YAEZK,OAAOU,IAAI,CAAC;gBACVT,MAAM;gBACNC,MAAM;gBACNE,OAAO;oBACLO,iBAAiB;oBACjBN,UAAU;gBACZ;gBACAC,OAAO;gBACPM,SAASf,OAAOY,YAAY,CAACI,OAAO,CAACC,GAAG,CAAC,CAACC;oBACxC,IAAI,OAAOA,WAAW,UAAU;wBAC9B,OAAOA;oBACT;oBAEA,OAAOA,OAAOC,IAAI;gBACpB;YACF;QACF;QAEAhB,OAAOU,IAAI,CAAC;YACVT,MAAM;YACNC,MAAM;YACNE,OAAO;gBACLC,UAAU;YACZ;YACAC,OAAO;QACT;QAEA,IAAIR,QAAQS,UAAUC,QAAQS,UAAU;YACtCjB,OAAOU,IAAI,CAAC;gBACVT,MAAM;gBACNC,MAAM;gBACNI,OAAO;YACT;QACF;IACF;IAEA,OAAON;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/versions/buildGlobalFields.ts"],"sourcesContent":["import type { SanitizedConfig } from '../config/types.js'\nimport type { Field, FlattenedField } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\n\nimport { hasAutosaveEnabled, hasDraftsEnabled } from '../utilities/getVersionsConfig.js'\nimport { versionSnapshotField } from './baseFields.js'\n\nexport const buildVersionGlobalFields = <T extends boolean = false>(\n config: SanitizedConfig,\n global: SanitizedGlobalConfig,\n flatten?: T,\n): true extends T ? FlattenedField[] : Field[] => {\n const fields: FlattenedField[] = [\n {\n name: 'version',\n type: 'group',\n fields: global.fields,\n ...(flatten && {\n flattenedFields: global.flattenedFields,\n })!,\n },\n {\n name: 'createdAt',\n type: 'date',\n admin: {\n disabled: true,\n },\n index: true,\n },\n {\n name: 'updatedAt',\n type: 'date',\n admin: {\n disabled: true,\n },\n index: true,\n },\n ]\n\n if (hasDraftsEnabled(global)) {\n if (config.localization) {\n fields.push(versionSnapshotField)\n\n fields.push({\n name: 'publishedLocale',\n type: 'select',\n admin: {\n disableBulkEdit: true,\n disabled: true,\n },\n index: true,\n options: config.localization.locales.map((locale) => {\n if (typeof locale === 'string') {\n return locale\n }\n\n return locale.code\n }),\n })\n }\n\n fields.push({\n name: 'latest',\n type: 'checkbox',\n admin: {\n disabled: true,\n },\n index: true,\n })\n\n if (hasAutosaveEnabled(global)) {\n fields.push({\n name: 'autosave',\n type: 'checkbox',\n index: true,\n })\n }\n }\n\n return fields as true extends T ? FlattenedField[] : Field[]\n}\n"],"names":["hasAutosaveEnabled","hasDraftsEnabled","versionSnapshotField","buildVersionGlobalFields","config","global","flatten","fields","name","type","flattenedFields","admin","disabled","index","localization","push","disableBulkEdit","options","locales","map","locale","code"],"mappings":"AAIA,SAASA,kBAAkB,EAAEC,gBAAgB,QAAQ,oCAAmC;AACxF,SAASC,oBAAoB,QAAQ,kBAAiB;AAEtD,OAAO,MAAMC,2BAA2B,CACtCC,QACAC,QACAC;IAEA,MAAMC,SAA2B;QAC/B;YACEC,MAAM;YACNC,MAAM;YACNF,QAAQF,OAAOE,MAAM;YACrB,GAAID,WAAW;gBACbI,iBAAiBL,OAAOK,eAAe;YACzC,CAAC;QACH;QACA;YACEF,MAAM;YACNC,MAAM;YACNE,OAAO;gBACLC,UAAU;YACZ;YACAC,OAAO;QACT;QACA;YACEL,MAAM;YACNC,MAAM;YACNE,OAAO;gBACLC,UAAU;YACZ;YACAC,OAAO;QACT;KACD;IAED,IAAIZ,iBAAiBI,SAAS;QAC5B,IAAID,OAAOU,YAAY,EAAE;YACvBP,OAAOQ,IAAI,CAACb;YAEZK,OAAOQ,IAAI,CAAC;gBACVP,MAAM;gBACNC,MAAM;gBACNE,OAAO;oBACLK,iBAAiB;oBACjBJ,UAAU;gBACZ;gBACAC,OAAO;gBACPI,SAASb,OAAOU,YAAY,CAACI,OAAO,CAACC,GAAG,CAAC,CAACC;oBACxC,IAAI,OAAOA,WAAW,UAAU;wBAC9B,OAAOA;oBACT;oBAEA,OAAOA,OAAOC,IAAI;gBACpB;YACF;QACF;QAEAd,OAAOQ,IAAI,CAAC;YACVP,MAAM;YACNC,MAAM;YACNE,OAAO;gBACLC,UAAU;YACZ;YACAC,OAAO;QACT;QAEA,IAAIb,mBAAmBK,SAAS;YAC9BE,OAAOQ,IAAI,CAAC;gBACVP,MAAM;gBACNC,MAAM;gBACNI,OAAO;YACT;QACF;IACF;IAEA,OAAON;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getLatestCollectionVersion.d.ts","sourceRoot":"","sources":["../../src/versions/getLatestCollectionVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAC3F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAS,MAAM,mBAAmB,CAAA;AAMvE,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,yBAAyB,CAAA;IACjC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,KAAK,EAAE,WAAW,CAAA;IAClB,GAAG,CAAC,EAAE,cAAc,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,0BAA0B,GAAU,CAAC,SAAS,UAAU,yDAOlE,IAAI,KAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAgC9B,CAAA"}
1
+ {"version":3,"file":"getLatestCollectionVersion.d.ts","sourceRoot":"","sources":["../../src/versions/getLatestCollectionVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAC3F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAS,MAAM,mBAAmB,CAAA;AAOvE,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,yBAAyB,CAAA;IACjC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,KAAK,EAAE,WAAW,CAAA;IAClB,GAAG,CAAC,EAAE,cAAc,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,0BAA0B,GAAU,CAAC,SAAS,UAAU,yDAOlE,IAAI,KAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAiC9B,CAAA"}
@@ -1,4 +1,5 @@
1
1
  import { combineQueries } from '../database/combineQueries.js';
2
+ import { hasDraftsEnabled } from '../utilities/getVersionsConfig.js';
2
3
  import { appendVersionToQueryKey } from './drafts/appendVersionToQueryKey.js';
3
4
  export const getLatestCollectionVersion = async ({ id, config, payload, published, query, req })=>{
4
5
  let latestVersion;
@@ -29,10 +30,11 @@ export const getLatestCollectionVersion = async ({ id, config, payload, publishe
29
30
  }
30
31
  ]
31
32
  };
32
- if (config.versions?.drafts) {
33
+ if (hasDraftsEnabled(config)) {
33
34
  const { docs } = await payload.db.findVersions({
34
35
  collection: config.slug,
35
36
  limit: 1,
37
+ locale: req?.locale || query.locale,
36
38
  pagination: false,
37
39
  req,
38
40
  sort: '-updatedAt',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/versions/getLatestCollectionVersion.ts"],"sourcesContent":["import type { SanitizedCollectionConfig, TypeWithID } from '../collections/config/types.js'\nimport type { FindOneArgs } from '../database/types.js'\nimport type { Payload, PayloadRequest, Where } from '../types/index.js'\nimport type { TypeWithVersion } from './types.js'\n\nimport { combineQueries } from '../database/combineQueries.js'\nimport { appendVersionToQueryKey } from './drafts/appendVersionToQueryKey.js'\n\ntype Args = {\n config: SanitizedCollectionConfig\n id: number | string\n payload: Payload\n published?: boolean\n query: FindOneArgs\n req?: PayloadRequest\n}\n\nexport const getLatestCollectionVersion = async <T extends TypeWithID = any>({\n id,\n config,\n payload,\n published,\n query,\n req,\n}: Args): Promise<T | undefined> => {\n let latestVersion!: TypeWithVersion<T>\n\n const whereQuery = published\n ? { and: [{ parent: { equals: id } }, { 'version._status': { equals: 'published' } }] }\n : { and: [{ parent: { equals: id } }, { latest: { equals: true } }] }\n\n if (config.versions?.drafts) {\n const { docs } = await payload.db.findVersions<T>({\n collection: config.slug,\n limit: 1,\n pagination: false,\n req,\n sort: '-updatedAt',\n where: combineQueries(appendVersionToQueryKey(query.where), whereQuery as unknown as Where),\n })\n latestVersion = docs[0]!\n }\n\n if (!latestVersion) {\n if (!published) {\n const doc = await payload.db.findOne<T>({ ...query, req })\n\n return doc ?? undefined\n }\n\n return undefined\n }\n\n latestVersion.version.id = id\n\n return latestVersion.version\n}\n"],"names":["combineQueries","appendVersionToQueryKey","getLatestCollectionVersion","id","config","payload","published","query","req","latestVersion","whereQuery","and","parent","equals","latest","versions","drafts","docs","db","findVersions","collection","slug","limit","pagination","sort","where","doc","findOne","undefined","version"],"mappings":"AAKA,SAASA,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,uBAAuB,QAAQ,sCAAqC;AAW7E,OAAO,MAAMC,6BAA6B,OAAmC,EAC3EC,EAAE,EACFC,MAAM,EACNC,OAAO,EACPC,SAAS,EACTC,KAAK,EACLC,GAAG,EACE;IACL,IAAIC;IAEJ,MAAMC,aAAaJ,YACf;QAAEK,KAAK;YAAC;gBAAEC,QAAQ;oBAAEC,QAAQV;gBAAG;YAAE;YAAG;gBAAE,mBAAmB;oBAAEU,QAAQ;gBAAY;YAAE;SAAE;IAAC,IACpF;QAAEF,KAAK;YAAC;gBAAEC,QAAQ;oBAAEC,QAAQV;gBAAG;YAAE;YAAG;gBAAEW,QAAQ;oBAAED,QAAQ;gBAAK;YAAE;SAAE;IAAC;IAEtE,IAAIT,OAAOW,QAAQ,EAAEC,QAAQ;QAC3B,MAAM,EAAEC,IAAI,EAAE,GAAG,MAAMZ,QAAQa,EAAE,CAACC,YAAY,CAAI;YAChDC,YAAYhB,OAAOiB,IAAI;YACvBC,OAAO;YACPC,YAAY;YACZf;YACAgB,MAAM;YACNC,OAAOzB,eAAeC,wBAAwBM,MAAMkB,KAAK,GAAGf;QAC9D;QACAD,gBAAgBQ,IAAI,CAAC,EAAE;IACzB;IAEA,IAAI,CAACR,eAAe;QAClB,IAAI,CAACH,WAAW;YACd,MAAMoB,MAAM,MAAMrB,QAAQa,EAAE,CAACS,OAAO,CAAI;gBAAE,GAAGpB,KAAK;gBAAEC;YAAI;YAExD,OAAOkB,OAAOE;QAChB;QAEA,OAAOA;IACT;IAEAnB,cAAcoB,OAAO,CAAC1B,EAAE,GAAGA;IAE3B,OAAOM,cAAcoB,OAAO;AAC9B,EAAC"}
1
+ {"version":3,"sources":["../../src/versions/getLatestCollectionVersion.ts"],"sourcesContent":["import type { SanitizedCollectionConfig, TypeWithID } from '../collections/config/types.js'\nimport type { FindOneArgs } from '../database/types.js'\nimport type { Payload, PayloadRequest, Where } from '../types/index.js'\nimport type { TypeWithVersion } from './types.js'\n\nimport { combineQueries } from '../database/combineQueries.js'\nimport { hasDraftsEnabled } from '../utilities/getVersionsConfig.js'\nimport { appendVersionToQueryKey } from './drafts/appendVersionToQueryKey.js'\n\ntype Args = {\n config: SanitizedCollectionConfig\n id: number | string\n payload: Payload\n published?: boolean\n query: FindOneArgs\n req?: PayloadRequest\n}\n\nexport const getLatestCollectionVersion = async <T extends TypeWithID = any>({\n id,\n config,\n payload,\n published,\n query,\n req,\n}: Args): Promise<T | undefined> => {\n let latestVersion!: TypeWithVersion<T>\n\n const whereQuery = published\n ? { and: [{ parent: { equals: id } }, { 'version._status': { equals: 'published' } }] }\n : { and: [{ parent: { equals: id } }, { latest: { equals: true } }] }\n\n if (hasDraftsEnabled(config)) {\n const { docs } = await payload.db.findVersions<T>({\n collection: config.slug,\n limit: 1,\n locale: req?.locale || query.locale,\n pagination: false,\n req,\n sort: '-updatedAt',\n where: combineQueries(appendVersionToQueryKey(query.where), whereQuery as unknown as Where),\n })\n latestVersion = docs[0]!\n }\n\n if (!latestVersion) {\n if (!published) {\n const doc = await payload.db.findOne<T>({ ...query, req })\n\n return doc ?? undefined\n }\n\n return undefined\n }\n\n latestVersion.version.id = id\n\n return latestVersion.version\n}\n"],"names":["combineQueries","hasDraftsEnabled","appendVersionToQueryKey","getLatestCollectionVersion","id","config","payload","published","query","req","latestVersion","whereQuery","and","parent","equals","latest","docs","db","findVersions","collection","slug","limit","locale","pagination","sort","where","doc","findOne","undefined","version"],"mappings":"AAKA,SAASA,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,gBAAgB,QAAQ,oCAAmC;AACpE,SAASC,uBAAuB,QAAQ,sCAAqC;AAW7E,OAAO,MAAMC,6BAA6B,OAAmC,EAC3EC,EAAE,EACFC,MAAM,EACNC,OAAO,EACPC,SAAS,EACTC,KAAK,EACLC,GAAG,EACE;IACL,IAAIC;IAEJ,MAAMC,aAAaJ,YACf;QAAEK,KAAK;YAAC;gBAAEC,QAAQ;oBAAEC,QAAQV;gBAAG;YAAE;YAAG;gBAAE,mBAAmB;oBAAEU,QAAQ;gBAAY;YAAE;SAAE;IAAC,IACpF;QAAEF,KAAK;YAAC;gBAAEC,QAAQ;oBAAEC,QAAQV;gBAAG;YAAE;YAAG;gBAAEW,QAAQ;oBAAED,QAAQ;gBAAK;YAAE;SAAE;IAAC;IAEtE,IAAIb,iBAAiBI,SAAS;QAC5B,MAAM,EAAEW,IAAI,EAAE,GAAG,MAAMV,QAAQW,EAAE,CAACC,YAAY,CAAI;YAChDC,YAAYd,OAAOe,IAAI;YACvBC,OAAO;YACPC,QAAQb,KAAKa,UAAUd,MAAMc,MAAM;YACnCC,YAAY;YACZd;YACAe,MAAM;YACNC,OAAOzB,eAAeE,wBAAwBM,MAAMiB,KAAK,GAAGd;QAC9D;QACAD,gBAAgBM,IAAI,CAAC,EAAE;IACzB;IAEA,IAAI,CAACN,eAAe;QAClB,IAAI,CAACH,WAAW;YACd,MAAMmB,MAAM,MAAMpB,QAAQW,EAAE,CAACU,OAAO,CAAI;gBAAE,GAAGnB,KAAK;gBAAEC;YAAI;YAExD,OAAOiB,OAAOE;QAChB;QAEA,OAAOA;IACT;IAEAlB,cAAcmB,OAAO,CAACzB,EAAE,GAAGA;IAE3B,OAAOM,cAAcmB,OAAO;AAC9B,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getLatestGlobalVersion.d.ts","sourceRoot":"","sources":["../../src/versions/getLatestGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAGjF,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,qBAAqB,CAAA;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,GAAG,CAAC,EAAE,cAAc,CAAA;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,eAAO,MAAM,sBAAsB,8DAQhC,IAAI,KAAG,OAAO,CAAC;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,YAAY,EAAE,OAAO,CAAA;CAAE,CA+C5D,CAAA"}
1
+ {"version":3,"file":"getLatestGlobalVersion.d.ts","sourceRoot":"","sources":["../../src/versions/getLatestGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAKjF,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,qBAAqB,CAAA;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,GAAG,CAAC,EAAE,cAAc,CAAA;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,eAAO,MAAM,sBAAsB,8DAQhC,IAAI,KAAG,OAAO,CAAC;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,YAAY,EAAE,OAAO,CAAA;CAAE,CA+C5D,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { hasDraftsEnabled } from '../utilities/getVersionsConfig.js';
1
2
  export const getLatestGlobalVersion = async ({ slug, config, locale, payload, published, req, where })=>{
2
3
  let latestVersion;
3
4
  const whereQuery = published ? {
@@ -9,11 +10,11 @@ export const getLatestGlobalVersion = async ({ slug, config, locale, payload, pu
9
10
  equals: true
10
11
  }
11
12
  };
12
- if (config.versions?.drafts) {
13
+ if (hasDraftsEnabled(config)) {
13
14
  latestVersion = (await payload.db.findGlobalVersions({
14
15
  global: slug,
15
16
  limit: 1,
16
- locale,
17
+ locale: locale || req?.locale || undefined,
17
18
  pagination: false,
18
19
  req,
19
20
  where: whereQuery
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/versions/getLatestGlobalVersion.ts"],"sourcesContent":["import type { SanitizedGlobalConfig } from '../globals/config/types.js'\nimport type { Document, Payload, PayloadRequest, Where } from '../types/index.js'\nimport type { TypeWithVersion } from './types.js'\n\ntype Args = {\n config: SanitizedGlobalConfig\n locale?: string\n payload: Payload\n published?: boolean\n req?: PayloadRequest\n slug: string\n where: Where\n}\n\nexport const getLatestGlobalVersion = async ({\n slug,\n config,\n locale,\n payload,\n published,\n req,\n where,\n}: Args): Promise<{ global: Document; globalExists: boolean }> => {\n let latestVersion: TypeWithVersion<Document> | undefined\n\n const whereQuery = published\n ? { 'version._status': { equals: 'published' } }\n : { latest: { equals: true } }\n\n if (config.versions?.drafts) {\n latestVersion = (\n await payload.db.findGlobalVersions({\n global: slug,\n limit: 1,\n locale,\n pagination: false,\n req,\n where: whereQuery as unknown as Where,\n })\n ).docs[0]\n }\n\n const global = await payload.db.findGlobal({\n slug,\n locale,\n req,\n where,\n })\n const globalExists = Boolean(global)\n\n if (!latestVersion) {\n return {\n global,\n globalExists,\n }\n }\n\n if (!latestVersion.version.createdAt) {\n latestVersion.version.createdAt = latestVersion.createdAt\n }\n\n if (!latestVersion.version.updatedAt) {\n latestVersion.version.updatedAt = latestVersion.updatedAt\n }\n\n return {\n global: latestVersion.version,\n globalExists,\n }\n}\n"],"names":["getLatestGlobalVersion","slug","config","locale","payload","published","req","where","latestVersion","whereQuery","equals","latest","versions","drafts","db","findGlobalVersions","global","limit","pagination","docs","findGlobal","globalExists","Boolean","version","createdAt","updatedAt"],"mappings":"AAcA,OAAO,MAAMA,yBAAyB,OAAO,EAC3CC,IAAI,EACJC,MAAM,EACNC,MAAM,EACNC,OAAO,EACPC,SAAS,EACTC,GAAG,EACHC,KAAK,EACA;IACL,IAAIC;IAEJ,MAAMC,aAAaJ,YACf;QAAE,mBAAmB;YAAEK,QAAQ;QAAY;IAAE,IAC7C;QAAEC,QAAQ;YAAED,QAAQ;QAAK;IAAE;IAE/B,IAAIR,OAAOU,QAAQ,EAAEC,QAAQ;QAC3BL,gBAAgB,AACd,CAAA,MAAMJ,QAAQU,EAAE,CAACC,kBAAkB,CAAC;YAClCC,QAAQf;YACRgB,OAAO;YACPd;YACAe,YAAY;YACZZ;YACAC,OAAOE;QACT,EAAC,EACDU,IAAI,CAAC,EAAE;IACX;IAEA,MAAMH,SAAS,MAAMZ,QAAQU,EAAE,CAACM,UAAU,CAAC;QACzCnB;QACAE;QACAG;QACAC;IACF;IACA,MAAMc,eAAeC,QAAQN;IAE7B,IAAI,CAACR,eAAe;QAClB,OAAO;YACLQ;YACAK;QACF;IACF;IAEA,IAAI,CAACb,cAAce,OAAO,CAACC,SAAS,EAAE;QACpChB,cAAce,OAAO,CAACC,SAAS,GAAGhB,cAAcgB,SAAS;IAC3D;IAEA,IAAI,CAAChB,cAAce,OAAO,CAACE,SAAS,EAAE;QACpCjB,cAAce,OAAO,CAACE,SAAS,GAAGjB,cAAciB,SAAS;IAC3D;IAEA,OAAO;QACLT,QAAQR,cAAce,OAAO;QAC7BF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/versions/getLatestGlobalVersion.ts"],"sourcesContent":["import type { SanitizedGlobalConfig } from '../globals/config/types.js'\nimport type { Document, Payload, PayloadRequest, Where } from '../types/index.js'\nimport type { TypeWithVersion } from './types.js'\n\nimport { hasDraftsEnabled } from '../utilities/getVersionsConfig.js'\n\ntype Args = {\n config: SanitizedGlobalConfig\n locale?: string\n payload: Payload\n published?: boolean\n req?: PayloadRequest\n slug: string\n where: Where\n}\n\nexport const getLatestGlobalVersion = async ({\n slug,\n config,\n locale,\n payload,\n published,\n req,\n where,\n}: Args): Promise<{ global: Document; globalExists: boolean }> => {\n let latestVersion: TypeWithVersion<Document> | undefined\n\n const whereQuery = published\n ? { 'version._status': { equals: 'published' } }\n : { latest: { equals: true } }\n\n if (hasDraftsEnabled(config)) {\n latestVersion = (\n await payload.db.findGlobalVersions({\n global: slug,\n limit: 1,\n locale: locale || req?.locale || undefined,\n pagination: false,\n req,\n where: whereQuery as unknown as Where,\n })\n ).docs[0]\n }\n\n const global = await payload.db.findGlobal({\n slug,\n locale,\n req,\n where,\n })\n const globalExists = Boolean(global)\n\n if (!latestVersion) {\n return {\n global,\n globalExists,\n }\n }\n\n if (!latestVersion.version.createdAt) {\n latestVersion.version.createdAt = latestVersion.createdAt\n }\n\n if (!latestVersion.version.updatedAt) {\n latestVersion.version.updatedAt = latestVersion.updatedAt\n }\n\n return {\n global: latestVersion.version,\n globalExists,\n }\n}\n"],"names":["hasDraftsEnabled","getLatestGlobalVersion","slug","config","locale","payload","published","req","where","latestVersion","whereQuery","equals","latest","db","findGlobalVersions","global","limit","undefined","pagination","docs","findGlobal","globalExists","Boolean","version","createdAt","updatedAt"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,oCAAmC;AAYpE,OAAO,MAAMC,yBAAyB,OAAO,EAC3CC,IAAI,EACJC,MAAM,EACNC,MAAM,EACNC,OAAO,EACPC,SAAS,EACTC,GAAG,EACHC,KAAK,EACA;IACL,IAAIC;IAEJ,MAAMC,aAAaJ,YACf;QAAE,mBAAmB;YAAEK,QAAQ;QAAY;IAAE,IAC7C;QAAEC,QAAQ;YAAED,QAAQ;QAAK;IAAE;IAE/B,IAAIX,iBAAiBG,SAAS;QAC5BM,gBAAgB,AACd,CAAA,MAAMJ,QAAQQ,EAAE,CAACC,kBAAkB,CAAC;YAClCC,QAAQb;YACRc,OAAO;YACPZ,QAAQA,UAAUG,KAAKH,UAAUa;YACjCC,YAAY;YACZX;YACAC,OAAOE;QACT,EAAC,EACDS,IAAI,CAAC,EAAE;IACX;IAEA,MAAMJ,SAAS,MAAMV,QAAQQ,EAAE,CAACO,UAAU,CAAC;QACzClB;QACAE;QACAG;QACAC;IACF;IACA,MAAMa,eAAeC,QAAQP;IAE7B,IAAI,CAACN,eAAe;QAClB,OAAO;YACLM;YACAM;QACF;IACF;IAEA,IAAI,CAACZ,cAAcc,OAAO,CAACC,SAAS,EAAE;QACpCf,cAAcc,OAAO,CAACC,SAAS,GAAGf,cAAce,SAAS;IAC3D;IAEA,IAAI,CAACf,cAAcc,OAAO,CAACE,SAAS,EAAE;QACpChB,cAAcc,OAAO,CAACE,SAAS,GAAGhB,cAAcgB,SAAS;IAC3D;IAEA,OAAO;QACLV,QAAQN,cAAcc,OAAO;QAC7BF;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"saveVersion.d.ts","sourceRoot":"","sources":["../../src/versions/save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E,cAAc,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAS/E,KAAK,IAAI,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,IAAI;IAC7C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,UAAU,CAAC,EAAE,yBAAyB,CAAA;IACtC,cAAc,EAAE,CAAC,CAAA;IACjB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,qBAAqB,CAAA;IAC9B,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,QAAQ,GAAG,gBAAgB,GAAG,QAAQ,CAAA;IAClD,OAAO,EAAE,OAAO,CAAA;IAChB,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,GAAG,CAAC,EAAE,cAAc,CAAA;IACpB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,QAAQ,CAAC,EAAE,GAAG,CAAA;CACf,CAAA;AAED,eAAO,MAAM,WAAW,GAAU,KAAK,SAAS,UAAU,+IAavD,IAAI,CAAC,KAAK,CAAC,KAAG,OAAO,CAAC,UAAU,CA+JlC,CAAA"}
@@ -1,4 +1,5 @@
1
1
  import { deepCopyObjectSimple } from '../index.js';
2
+ import { getVersionsMax } from '../utilities/getVersionsConfig.js';
2
3
  import { sanitizeInternalFields } from '../utilities/sanitizeInternalFields.js';
3
4
  import { getQueryDraftsSelect } from './drafts/getQueryDraftsSelect.js';
4
5
  import { enforceMaxVersions } from './enforceMaxVersions.js';
@@ -133,7 +134,7 @@ export const saveVersion = async ({ id, autosave, collection, docWithLocales, dr
133
134
  });
134
135
  return undefined;
135
136
  }
136
- const max = collection ? collection.versions.maxPerDoc : global.versions.max;
137
+ const max = getVersionsMax(collection || global);
137
138
  if (createNewVersion && max > 0) {
138
139
  await enforceMaxVersions({
139
140
  id,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/versions/saveVersion.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\nimport type { CreateGlobalVersionArgs, CreateVersionArgs, Payload } from '../index.js'\nimport type { JsonObject, PayloadRequest, SelectType } from '../types/index.js'\n\nimport { deepCopyObjectSimple } from '../index.js'\nimport { sanitizeInternalFields } from '../utilities/sanitizeInternalFields.js'\nimport { getQueryDraftsSelect } from './drafts/getQueryDraftsSelect.js'\nimport { enforceMaxVersions } from './enforceMaxVersions.js'\nimport { saveSnapshot } from './saveSnapshot.js'\n\ntype Args<T extends JsonObject = JsonObject> = {\n autosave?: boolean\n collection?: SanitizedCollectionConfig\n docWithLocales: T\n draft?: boolean\n global?: SanitizedGlobalConfig\n id?: number | string\n operation?: 'create' | 'restoreVersion' | 'update'\n payload: Payload\n publishSpecificLocale?: string\n req?: PayloadRequest\n select?: SelectType\n snapshot?: any\n}\n\nexport const saveVersion = async <TData extends JsonObject = JsonObject>({\n id,\n autosave,\n collection,\n docWithLocales,\n draft,\n global,\n operation,\n payload,\n publishSpecificLocale,\n req,\n select,\n snapshot,\n}: Args<TData>): Promise<JsonObject> => {\n let result: JsonObject | undefined\n let createNewVersion = true\n const now = new Date().toISOString()\n const versionData: {\n _status?: 'draft'\n updatedAt?: string\n } & TData = deepCopyObjectSimple(docWithLocales)\n\n if (draft) {\n versionData._status = 'draft'\n }\n\n if (collection?.timestamps && draft) {\n versionData.updatedAt = now\n }\n\n if (versionData._id) {\n delete versionData._id\n }\n\n try {\n if (autosave) {\n let docs\n const findVersionArgs = {\n limit: 1,\n pagination: false,\n req,\n sort: '-updatedAt',\n }\n\n if (collection) {\n ;({ docs } = await payload.db.findVersions<TData>({\n ...findVersionArgs,\n collection: collection.slug,\n limit: 1,\n pagination: false,\n req,\n where: {\n parent: {\n equals: id,\n },\n },\n }))\n } else {\n ;({ docs } = await payload.db.findGlobalVersions<TData>({\n ...findVersionArgs,\n global: global!.slug,\n limit: 1,\n pagination: false,\n req,\n }))\n }\n const [latestVersion] = docs\n\n // overwrite the latest version if it's set to autosave\n if (latestVersion && 'autosave' in latestVersion && latestVersion.autosave === true) {\n createNewVersion = false\n\n const updateVersionArgs = {\n id: latestVersion.id,\n req,\n versionData: {\n createdAt: new Date(latestVersion.createdAt).toISOString(),\n latest: true,\n parent: id,\n updatedAt: now,\n version: {\n ...versionData,\n },\n },\n }\n\n if (collection) {\n result = await payload.db.updateVersion<TData>({\n ...updateVersionArgs,\n collection: collection.slug,\n req,\n })\n } else {\n result = await payload.db.updateGlobalVersion<TData>({\n ...updateVersionArgs,\n global: global!.slug,\n req,\n })\n }\n }\n }\n\n if (createNewVersion) {\n const createVersionArgs = {\n autosave: Boolean(autosave),\n collectionSlug: undefined as string | undefined,\n createdAt: operation === 'restoreVersion' ? versionData.createdAt : now,\n globalSlug: undefined as string | undefined,\n parent: collection ? id : undefined,\n publishedLocale: publishSpecificLocale || undefined,\n req,\n select: getQueryDraftsSelect({ select }),\n updatedAt: now,\n versionData,\n }\n\n if (collection) {\n createVersionArgs.collectionSlug = collection.slug\n result = await payload.db.createVersion(createVersionArgs as CreateVersionArgs)\n }\n\n if (global) {\n createVersionArgs.globalSlug = global.slug\n result = await payload.db.createGlobalVersion(createVersionArgs as CreateGlobalVersionArgs)\n }\n\n if (snapshot) {\n await saveSnapshot<TData>({\n id,\n autosave,\n collection,\n data: snapshot,\n global,\n payload,\n publishSpecificLocale,\n req,\n select,\n })\n }\n }\n } catch (err) {\n let errorMessage: string | undefined\n\n if (collection) {\n errorMessage = `There was an error while saving a version for the ${typeof collection.labels.singular === 'string' ? collection.labels.singular : collection.slug} with ID ${id}.`\n }\n if (global) {\n errorMessage = `There was an error while saving a version for the global ${typeof global.label === 'string' ? global.label : global.slug}.`\n }\n payload.logger.error({ err, msg: errorMessage })\n return undefined!\n }\n\n const max = collection ? collection.versions.maxPerDoc : global!.versions.max\n\n if (createNewVersion && max > 0) {\n await enforceMaxVersions({\n id,\n collection,\n global,\n max,\n payload,\n req,\n })\n }\n\n let createdVersion = (result as any).version\n\n createdVersion = sanitizeInternalFields(createdVersion)\n createdVersion.id = (result as any).parent\n\n return createdVersion\n}\n"],"names":["deepCopyObjectSimple","sanitizeInternalFields","getQueryDraftsSelect","enforceMaxVersions","saveSnapshot","saveVersion","id","autosave","collection","docWithLocales","draft","global","operation","payload","publishSpecificLocale","req","select","snapshot","result","createNewVersion","now","Date","toISOString","versionData","_status","timestamps","updatedAt","_id","docs","findVersionArgs","limit","pagination","sort","db","findVersions","slug","where","parent","equals","findGlobalVersions","latestVersion","updateVersionArgs","createdAt","latest","version","updateVersion","updateGlobalVersion","createVersionArgs","Boolean","collectionSlug","undefined","globalSlug","publishedLocale","createVersion","createGlobalVersion","data","err","errorMessage","labels","singular","label","logger","error","msg","max","versions","maxPerDoc","createdVersion"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,cAAa;AAClD,SAASC,sBAAsB,QAAQ,yCAAwC;AAC/E,SAASC,oBAAoB,QAAQ,mCAAkC;AACvE,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,YAAY,QAAQ,oBAAmB;AAiBhD,OAAO,MAAMC,cAAc,OAA8C,EACvEC,EAAE,EACFC,QAAQ,EACRC,UAAU,EACVC,cAAc,EACdC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,OAAO,EACPC,qBAAqB,EACrBC,GAAG,EACHC,MAAM,EACNC,QAAQ,EACI;IACZ,IAAIC;IACJ,IAAIC,mBAAmB;IACvB,MAAMC,MAAM,IAAIC,OAAOC,WAAW;IAClC,MAAMC,cAGMvB,qBAAqBS;IAEjC,IAAIC,OAAO;QACTa,YAAYC,OAAO,GAAG;IACxB;IAEA,IAAIhB,YAAYiB,cAAcf,OAAO;QACnCa,YAAYG,SAAS,GAAGN;IAC1B;IAEA,IAAIG,YAAYI,GAAG,EAAE;QACnB,OAAOJ,YAAYI,GAAG;IACxB;IAEA,IAAI;QACF,IAAIpB,UAAU;YACZ,IAAIqB;YACJ,MAAMC,kBAAkB;gBACtBC,OAAO;g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MAAM,GAAG;QAC/B,MAAM7D,mBAAmB;YACvBG;YACAE;YACAG;YACAqD;YACAnD;YACAE;QACF;IACF;IAEA,IAAIoD,iBAAiB,AAACjD,OAAe0B,OAAO;IAE5CuB,iBAAiBlE,uBAAuBkE;IACxCA,eAAe7D,EAAE,GAAG,AAACY,OAAemB,MAAM;IAE1C,OAAO8B;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/versions/saveVersion.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\nimport type { CreateGlobalVersionArgs, CreateVersionArgs, Payload } from '../index.js'\nimport type { JsonObject, PayloadRequest, SelectType } from '../types/index.js'\n\nimport { deepCopyObjectSimple } from '../index.js'\nimport { getVersionsMax } from '../utilities/getVersionsConfig.js'\nimport { sanitizeInternalFields } from '../utilities/sanitizeInternalFields.js'\nimport { getQueryDraftsSelect } from './drafts/getQueryDraftsSelect.js'\nimport { enforceMaxVersions } from './enforceMaxVersions.js'\nimport { saveSnapshot } from './saveSnapshot.js'\n\ntype Args<T extends JsonObject = JsonObject> = {\n autosave?: boolean\n collection?: SanitizedCollectionConfig\n docWithLocales: T\n draft?: boolean\n global?: SanitizedGlobalConfig\n id?: number | string\n operation?: 'create' | 'restoreVersion' | 'update'\n payload: Payload\n publishSpecificLocale?: string\n req?: PayloadRequest\n select?: SelectType\n snapshot?: any\n}\n\nexport const saveVersion = async <TData extends JsonObject = JsonObject>({\n id,\n autosave,\n collection,\n docWithLocales,\n draft,\n global,\n operation,\n payload,\n publishSpecificLocale,\n req,\n select,\n snapshot,\n}: Args<TData>): Promise<JsonObject> => {\n let result: JsonObject | undefined\n let createNewVersion = true\n const now = new Date().toISOString()\n const versionData: {\n _status?: 'draft'\n updatedAt?: string\n } & TData = deepCopyObjectSimple(docWithLocales)\n\n if (draft) {\n versionData._status = 'draft'\n }\n\n if (collection?.timestamps && draft) {\n versionData.updatedAt = now\n }\n\n if (versionData._id) {\n delete versionData._id\n }\n\n try {\n if (autosave) {\n let docs\n const findVersionArgs = {\n limit: 1,\n pagination: false,\n req,\n sort: '-updatedAt',\n }\n\n if (collection) {\n ;({ docs } = await payload.db.findVersions<TData>({\n ...findVersionArgs,\n collection: collection.slug,\n limit: 1,\n pagination: false,\n req,\n where: {\n parent: {\n equals: id,\n },\n },\n }))\n } else {\n ;({ docs } = await payload.db.findGlobalVersions<TData>({\n ...findVersionArgs,\n global: global!.slug,\n limit: 1,\n pagination: false,\n req,\n }))\n }\n const [latestVersion] = docs\n\n // overwrite the latest version if it's set to autosave\n if (latestVersion && 'autosave' in latestVersion && latestVersion.autosave === true) {\n createNewVersion = false\n\n const updateVersionArgs = {\n id: latestVersion.id,\n req,\n versionData: {\n createdAt: new Date(latestVersion.createdAt).toISOString(),\n latest: true,\n parent: id,\n updatedAt: now,\n version: {\n ...versionData,\n },\n },\n }\n\n if (collection) {\n result = await payload.db.updateVersion<TData>({\n ...updateVersionArgs,\n collection: collection.slug,\n req,\n })\n } else {\n result = await payload.db.updateGlobalVersion<TData>({\n ...updateVersionArgs,\n global: global!.slug,\n req,\n })\n }\n }\n }\n\n if (createNewVersion) {\n const createVersionArgs = {\n autosave: Boolean(autosave),\n collectionSlug: undefined as string | undefined,\n createdAt: operation === 'restoreVersion' ? versionData.createdAt : now,\n globalSlug: undefined as string | undefined,\n parent: collection ? id : undefined,\n publishedLocale: publishSpecificLocale || undefined,\n req,\n select: getQueryDraftsSelect({ select }),\n updatedAt: now,\n versionData,\n }\n\n if (collection) {\n createVersionArgs.collectionSlug = collection.slug\n result = await payload.db.createVersion(createVersionArgs as CreateVersionArgs)\n }\n\n if (global) {\n createVersionArgs.globalSlug = global.slug\n result = await payload.db.createGlobalVersion(createVersionArgs as CreateGlobalVersionArgs)\n }\n\n if (snapshot) {\n await saveSnapshot<TData>({\n id,\n autosave,\n collection,\n data: snapshot,\n global,\n payload,\n publishSpecificLocale,\n req,\n select,\n })\n }\n }\n } catch (err) {\n let errorMessage: string | undefined\n\n if (collection) {\n errorMessage = `There was an error while saving a version for the ${typeof collection.labels.singular === 'string' ? collection.labels.singular : collection.slug} with ID ${id}.`\n }\n if (global) {\n errorMessage = `There was an error while saving a version for the global ${typeof global.label === 'string' ? global.label : global.slug}.`\n }\n payload.logger.error({ err, msg: errorMessage })\n return undefined!\n }\n\n const max = getVersionsMax(collection || global!)\n\n if (createNewVersion && max > 0) {\n await enforceMaxVersions({\n id,\n collection,\n global,\n max,\n payload,\n req,\n })\n }\n\n let createdVersion = (result as any).version\n\n createdVersion = sanitizeInternalFields(createdVersion)\n createdVersion.id = (result as any).parent\n\n return createdVersion\n}\n"],"names":["deepCopyObjectSimple","getVersionsMax","sanitizeInternalFields","getQueryDraftsSelect","enforceMaxVersions","saveSnapshot","saveVersion","id","autosave","collection","docWithLocales","draft","global","operation","payload","publishSpecificLocale","req","select","snapshot","result","createNewVersion","now","Date","toISOString","versionData","_status","timestamps","updatedAt","_id","docs","findVersionArgs","limit","pagination","sort","db","findVersions","slug","where","parent","equals","findGlobalVersions","latestVersion","updateVersionArgs","createdAt","latest","version","updateVersion","updateGlobalVersion","createVersionArgs","Boolean","collectionSlug","undefined","globalSlug","publishedLocale","createVersion","createGlobalVersion","data","err","errorMessage","labels","singular","label","logger","error","msg","max","createdVersion"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,cAAa;AAClD,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,sBAAsB,QAAQ,yCAAwC;AAC/E,SAASC,oBAAoB,QAAQ,mCAAkC;AACvE,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,YAAY,QAAQ,oBAAmB;AAiBhD,OAAO,MAAMC,cAAc,OAA8C,EACvEC,EAAE,EACFC,QAAQ,EACRC,UAAU,EACVC,cAAc,EACdC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,OAAO,EACPC,qBAAqB,EACrBC,GAAG,EACHC,MAAM,EACNC,QAAQ,EACI;IACZ,IAAI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C;QACpL;QACA,IAAIK,QAAQ;YACV8C,eAAe,CAAC,yDAAyD,EAAE,OAAO9C,OAAOiD,KAAK,KAAK,WAAWjD,OAAOiD,KAAK,GAAGjD,OAAOwB,IAAI,CAAC,CAAC,CAAC;QAC7I;QACAtB,QAAQgD,MAAM,CAACC,KAAK,CAAC;YAAEN;YAAKO,KAAKN;QAAa;QAC9C,OAAOP;IACT;IAEA,MAAMc,MAAMhE,eAAeQ,cAAcG;IAEzC,IAAIQ,oBAAoB6C,MAAM,GAAG;QAC/B,MAAM7D,mBAAmB;YACvBG;YACAE;YACAG;YACAqD;YACAnD;YACAE;QACF;IACF;IAEA,IAAIkD,iBAAiB,AAAC/C,OAAe0B,OAAO;IAE5CqB,iBAAiBhE,uBAAuBgE;IACxCA,eAAe3D,EAAE,GAAG,AAACY,OAAemB,MAAM;IAE1C,OAAO4B;AACT,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload",
3
- "version": "3.66.0",
3
+ "version": "3.67.0-internal.1ea538b",
4
4
  "description": "Node, React, Headless CMS and Application Framework built on Next.js",
5
5
  "keywords": [
6
6
  "admin panel",
@@ -106,7 +106,7 @@
106
106
  "undici": "7.10.0",
107
107
  "uuid": "10.0.0",
108
108
  "ws": "^8.16.0",
109
- "@payloadcms/translations": "3.66.0"
109
+ "@payloadcms/translations": "3.67.0-internal.1ea538b"
110
110
  },
111
111
  "devDependencies": {
112
112
  "@hyrious/esbuild-plugin-commonjs": "0.2.6",
@@ -1,105 +0,0 @@
1
- import type { forgotPasswordOperation } from '../../auth/operations/forgotPassword.js';
2
- import type { loginOperation } from '../../auth/operations/login.js';
3
- import type { refreshOperation } from '../../auth/operations/refresh.js';
4
- import type { resetPasswordOperation } from '../../auth/operations/resetPassword.js';
5
- import type { CollectionSlug, restoreVersionOperation } from '../../index.js';
6
- import type { PayloadRequest } from '../../types/index.js';
7
- import type { SanitizedCollectionConfig, SelectFromCollectionSlug } from '../config/types.js';
8
- import type { countOperation } from './count.js';
9
- import type { countVersionsOperation } from './countVersions.js';
10
- import type { createOperation } from './create.js';
11
- import type { deleteOperation } from './delete.js';
12
- import type { deleteByIDOperation } from './deleteByID.js';
13
- import type { findOperation } from './find.js';
14
- import type { findByIDOperation } from './findByID.js';
15
- import type { findDistinctOperation } from './findDistinct.js';
16
- import type { updateOperation } from './update.js';
17
- import type { updateByIDOperation } from './updateByID.js';
18
- export type AfterOperationMap<TOperationGeneric extends CollectionSlug> = {
19
- count: typeof countOperation<TOperationGeneric>;
20
- countVersions: typeof countVersionsOperation<TOperationGeneric>;
21
- create: typeof createOperation<TOperationGeneric, SelectFromCollectionSlug<TOperationGeneric>>;
22
- delete: typeof deleteOperation<TOperationGeneric, SelectFromCollectionSlug<TOperationGeneric>>;
23
- deleteByID: typeof deleteByIDOperation<TOperationGeneric, SelectFromCollectionSlug<TOperationGeneric>>;
24
- find: typeof findOperation<TOperationGeneric, SelectFromCollectionSlug<TOperationGeneric>>;
25
- findByID: typeof findByIDOperation<TOperationGeneric, boolean, SelectFromCollectionSlug<TOperationGeneric>>;
26
- findDistinct: typeof findDistinctOperation;
27
- forgotPassword: typeof forgotPasswordOperation;
28
- login: typeof loginOperation<TOperationGeneric>;
29
- refresh: typeof refreshOperation;
30
- resetPassword: typeof resetPasswordOperation<TOperationGeneric>;
31
- restoreVersion: typeof restoreVersionOperation;
32
- update: typeof updateOperation<TOperationGeneric, SelectFromCollectionSlug<TOperationGeneric>>;
33
- updateByID: typeof updateByIDOperation<TOperationGeneric, SelectFromCollectionSlug<TOperationGeneric>>;
34
- };
35
- export type AfterOperationArg<TOperationGeneric extends CollectionSlug> = {
36
- /** The collection which this hook is being run on */
37
- collection: SanitizedCollectionConfig;
38
- req: PayloadRequest;
39
- } & ({
40
- args: Parameters<AfterOperationMap<TOperationGeneric>['count']>[0];
41
- operation: 'count';
42
- result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['count']>>;
43
- } | {
44
- args: Parameters<AfterOperationMap<TOperationGeneric>['countVersions']>[0];
45
- operation: 'countVersions';
46
- result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['countVersions']>>;
47
- } | {
48
- args: Parameters<AfterOperationMap<TOperationGeneric>['create']>[0];
49
- operation: 'create';
50
- result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['create']>>;
51
- } | {
52
- args: Parameters<AfterOperationMap<TOperationGeneric>['delete']>[0];
53
- operation: 'delete';
54
- result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['delete']>>;
55
- } | {
56
- args: Parameters<AfterOperationMap<TOperationGeneric>['deleteByID']>[0];
57
- operation: 'deleteByID';
58
- result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['deleteByID']>>;
59
- } | {
60
- args: Parameters<AfterOperationMap<TOperationGeneric>['find']>[0];
61
- operation: 'find';
62
- result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['find']>>;
63
- } | {
64
- args: Parameters<AfterOperationMap<TOperationGeneric>['findByID']>[0];
65
- operation: 'findByID';
66
- result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['findByID']>>;
67
- } | {
68
- args: Parameters<AfterOperationMap<TOperationGeneric>['findDistinct']>[0];
69
- operation: 'findDistinct';
70
- result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['findDistinct']>>;
71
- } | {
72
- args: Parameters<AfterOperationMap<TOperationGeneric>['forgotPassword']>[0];
73
- operation: 'forgotPassword';
74
- result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['forgotPassword']>>;
75
- } | {
76
- args: Parameters<AfterOperationMap<TOperationGeneric>['login']>[0];
77
- operation: 'login';
78
- result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['login']>>;
79
- } | {
80
- args: Parameters<AfterOperationMap<TOperationGeneric>['refresh']>[0];
81
- operation: 'refresh';
82
- result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['refresh']>>;
83
- } | {
84
- args: Parameters<AfterOperationMap<TOperationGeneric>['resetPassword']>[0];
85
- operation: 'resetPassword';
86
- result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['resetPassword']>>;
87
- } | {
88
- args: Parameters<AfterOperationMap<TOperationGeneric>['restoreVersion']>[0];
89
- operation: 'restoreVersion';
90
- result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['restoreVersion']>>;
91
- } | {
92
- args: Parameters<AfterOperationMap<TOperationGeneric>['update']>[0];
93
- operation: 'update';
94
- result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['update']>>;
95
- } | {
96
- args: Parameters<AfterOperationMap<TOperationGeneric>['updateByID']>[0];
97
- operation: 'updateByID';
98
- result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['updateByID']>>;
99
- });
100
- type OperationResult<TOperationGeneric extends CollectionSlug, O extends keyof AfterOperationMap<TOperationGeneric>> = Awaited<ReturnType<AfterOperationMap<TOperationGeneric>[O]>>;
101
- export declare const buildAfterOperation: <TOperationGeneric extends CollectionSlug, O extends keyof AfterOperationMap<TOperationGeneric> = keyof AfterOperationMap<TOperationGeneric>>(operationArgs: {
102
- operation: O;
103
- } & Omit<AfterOperationArg<TOperationGeneric>, "req">) => Promise<any | OperationResult<TOperationGeneric, O>>;
104
- export {};
105
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAA;AACtF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAA;AACxE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAA;AACpF,OAAO,KAAK,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAC7E,OAAO,KAAK,EAAE,cAAc,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AAI,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,EAAE,KAAK,CAAC,KAClF,OAAO,CAAC,GAAG,GAAG,eAAe,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAsBrD,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/collections/operations/utils.ts"],"sourcesContent":["import type { forgotPasswordOperation } from '../../auth/operations/forgotPassword.js'\nimport type { loginOperation } from '../../auth/operations/login.js'\nimport type { refreshOperation } from '../../auth/operations/refresh.js'\nimport type { resetPasswordOperation } from '../../auth/operations/resetPassword.js'\nimport type { CollectionSlug, restoreVersionOperation } from '../../index.js'\nimport type { PayloadRequest } from '../../types/index.js'\nimport type { SanitizedCollectionConfig, SelectFromCollectionSlug } from '../config/types.js'\nimport type { countOperation } from './count.js'\nimport type { countVersionsOperation } from './countVersions.js'\nimport type { createOperation } from './create.js'\nimport type { deleteOperation } from './delete.js'\nimport type { deleteByIDOperation } from './deleteByID.js'\nimport type { findOperation } from './find.js'\nimport type { findByIDOperation } from './findByID.js'\nimport type { findDistinctOperation } from './findDistinct.js'\nimport type { updateOperation } from './update.js'\nimport type { updateByIDOperation } from './updateByID.js'\n\nexport type AfterOperationMap<TOperationGeneric extends CollectionSlug> = {\n count: typeof countOperation<TOperationGeneric>\n countVersions: typeof countVersionsOperation<TOperationGeneric>\n create: typeof createOperation<TOperationGeneric, SelectFromCollectionSlug<TOperationGeneric>>\n delete: typeof deleteOperation<TOperationGeneric, SelectFromCollectionSlug<TOperationGeneric>>\n deleteByID: typeof deleteByIDOperation<\n TOperationGeneric,\n SelectFromCollectionSlug<TOperationGeneric>\n >\n find: typeof findOperation<TOperationGeneric, SelectFromCollectionSlug<TOperationGeneric>>\n findByID: typeof findByIDOperation<\n TOperationGeneric,\n boolean,\n SelectFromCollectionSlug<TOperationGeneric>\n >\n findDistinct: typeof findDistinctOperation\n forgotPassword: typeof forgotPasswordOperation\n login: typeof loginOperation<TOperationGeneric>\n refresh: typeof refreshOperation\n resetPassword: typeof resetPasswordOperation<TOperationGeneric>\n restoreVersion: typeof restoreVersionOperation\n update: typeof updateOperation<TOperationGeneric, SelectFromCollectionSlug<TOperationGeneric>>\n updateByID: typeof updateByIDOperation<\n TOperationGeneric,\n SelectFromCollectionSlug<TOperationGeneric>\n >\n}\n\nexport type AfterOperationArg<TOperationGeneric extends CollectionSlug> = {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n req: PayloadRequest\n} & (\n | {\n args: Parameters<AfterOperationMap<TOperationGeneric>['count']>[0]\n operation: 'count'\n result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['count']>>\n }\n | {\n args: Parameters<AfterOperationMap<TOperationGeneric>['countVersions']>[0]\n operation: 'countVersions'\n result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['countVersions']>>\n }\n | {\n args: Parameters<AfterOperationMap<TOperationGeneric>['create']>[0]\n operation: 'create'\n result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['create']>>\n }\n | {\n args: Parameters<AfterOperationMap<TOperationGeneric>['delete']>[0]\n operation: 'delete'\n result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['delete']>>\n }\n | {\n args: Parameters<AfterOperationMap<TOperationGeneric>['deleteByID']>[0]\n operation: 'deleteByID'\n result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['deleteByID']>>\n }\n | {\n args: Parameters<AfterOperationMap<TOperationGeneric>['find']>[0]\n operation: 'find'\n result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['find']>>\n }\n | {\n args: Parameters<AfterOperationMap<TOperationGeneric>['findByID']>[0]\n operation: 'findByID'\n result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['findByID']>>\n }\n | {\n args: Parameters<AfterOperationMap<TOperationGeneric>['findDistinct']>[0]\n operation: 'findDistinct'\n result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['findDistinct']>>\n }\n | {\n args: Parameters<AfterOperationMap<TOperationGeneric>['forgotPassword']>[0]\n operation: 'forgotPassword'\n result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['forgotPassword']>>\n }\n | {\n args: Parameters<AfterOperationMap<TOperationGeneric>['login']>[0]\n operation: 'login'\n result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['login']>>\n }\n | {\n args: Parameters<AfterOperationMap<TOperationGeneric>['refresh']>[0]\n operation: 'refresh'\n result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['refresh']>>\n }\n | {\n args: Parameters<AfterOperationMap<TOperationGeneric>['resetPassword']>[0]\n operation: 'resetPassword'\n result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['resetPassword']>>\n }\n | {\n args: Parameters<AfterOperationMap<TOperationGeneric>['restoreVersion']>[0]\n operation: 'restoreVersion'\n result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['restoreVersion']>>\n }\n | {\n args: Parameters<AfterOperationMap<TOperationGeneric>['update']>[0]\n operation: 'update'\n result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['update']>>\n }\n | {\n args: Parameters<AfterOperationMap<TOperationGeneric>['updateByID']>[0]\n operation: 'updateByID'\n result: Awaited<ReturnType<AfterOperationMap<TOperationGeneric>['updateByID']>>\n }\n)\n\ntype OperationResult<\n TOperationGeneric extends CollectionSlug,\n O extends keyof AfterOperationMap<TOperationGeneric>,\n> = Awaited<ReturnType<AfterOperationMap<TOperationGeneric>[O]>>\n\nexport const buildAfterOperation = async <\n TOperationGeneric extends CollectionSlug,\n O extends keyof AfterOperationMap<TOperationGeneric> = keyof AfterOperationMap<TOperationGeneric>,\n>(\n operationArgs: { operation: O } & Omit<AfterOperationArg<TOperationGeneric>, 'req'>,\n): Promise<any | OperationResult<TOperationGeneric, O>> => {\n const { args, collection, operation, result } = operationArgs\n\n let newResult = result as OperationResult<TOperationGeneric, O>\n\n if (args.collection.config.hooks?.afterOperation?.length) {\n for (const hook of args.collection.config.hooks.afterOperation) {\n const hookResult = await hook({\n args,\n collection,\n operation,\n req: args.req,\n result: newResult,\n } as AfterOperationArg<TOperationGeneric>)\n\n if (hookResult !== undefined) {\n newResult = hookResult as OperationResult<TOperationGeneric, O>\n }\n }\n }\n\n return newResult\n}\n"],"names":["buildAfterOperation","operationArgs","args","collection","operation","result","newResult","config","hooks","afterOperation","length","hook","hookResult","req","undefined"],"mappings":"AAqIA,OAAO,MAAMA,sBAAsB,OAIjCC;IAEA,MAAM,EAAEC,IAAI,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAE,GAAGJ;IAEhD,IAAIK,YAAYD;IAEhB,IAAIH,KAAKC,UAAU,CAACI,MAAM,CAACC,KAAK,EAAEC,gBAAgBC,QAAQ;QACxD,KAAK,MAAMC,QAAQT,KAAKC,UAAU,CAACI,MAAM,CAACC,KAAK,CAACC,cAAc,CAAE;YAC9D,MAAMG,aAAa,MAAMD,KAAK;gBAC5BT;gBACAC;gBACAC;gBACAS,KAAKX,KAAKW,GAAG;gBACbR,QAAQC;YACV;YAEA,IAAIM,eAAeE,WAAW;gBAC5BR,YAAYM;YACd;QACF;IACF;IAEA,OAAON;AACT,EAAC"}