payload 4.0.0-internal.5f0cd13 → 4.0.0-internal.a0ef1b8

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 (183) hide show
  1. package/dist/admin/RichText.d.ts +22 -2
  2. package/dist/admin/RichText.d.ts.map +1 -1
  3. package/dist/admin/RichText.js.map +1 -1
  4. package/dist/admin/adapters/devReload.d.ts +9 -0
  5. package/dist/admin/adapters/devReload.d.ts.map +1 -0
  6. package/dist/admin/adapters/devReload.js +6 -0
  7. package/dist/admin/adapters/devReload.js.map +1 -0
  8. package/dist/admin/adapters/index.d.ts +3 -0
  9. package/dist/admin/adapters/index.d.ts.map +1 -1
  10. package/dist/admin/adapters/index.js.map +1 -1
  11. package/dist/admin/adapters/render.d.ts +16 -0
  12. package/dist/admin/adapters/render.d.ts.map +1 -0
  13. package/dist/admin/adapters/render.js +7 -0
  14. package/dist/admin/adapters/render.js.map +1 -0
  15. package/dist/admin/adapters/views.d.ts +36 -0
  16. package/dist/admin/adapters/views.d.ts.map +1 -0
  17. package/dist/admin/adapters/views.js +7 -0
  18. package/dist/admin/adapters/views.js.map +1 -0
  19. package/dist/admin/forms/Field.d.ts +7 -0
  20. package/dist/admin/forms/Field.d.ts.map +1 -1
  21. package/dist/admin/forms/Field.js.map +1 -1
  22. package/dist/admin/forms/Form.d.ts +29 -0
  23. package/dist/admin/forms/Form.d.ts.map +1 -1
  24. package/dist/admin/forms/Form.js.map +1 -1
  25. package/dist/admin/functions/index.d.ts +9 -0
  26. package/dist/admin/functions/index.d.ts.map +1 -1
  27. package/dist/admin/functions/index.js.map +1 -1
  28. package/dist/admin/types.d.ts +1 -1
  29. package/dist/admin/types.d.ts.map +1 -1
  30. package/dist/admin/types.js.map +1 -1
  31. package/dist/admin/views/dashboard.d.ts +7 -0
  32. package/dist/admin/views/dashboard.d.ts.map +1 -1
  33. package/dist/admin/views/dashboard.js.map +1 -1
  34. package/dist/admin/views/document.d.ts +7 -1
  35. package/dist/admin/views/document.d.ts.map +1 -1
  36. package/dist/admin/views/document.js.map +1 -1
  37. package/dist/auth/defaultAccess.d.ts +1 -1
  38. package/dist/auth/defaultAccess.d.ts.map +1 -1
  39. package/dist/auth/defaultAccess.js +1 -1
  40. package/dist/auth/defaultAccess.js.map +1 -1
  41. package/dist/auth/defaultUser.d.ts.map +1 -1
  42. package/dist/auth/defaultUser.js +2 -1
  43. package/dist/auth/defaultUser.js.map +1 -1
  44. package/dist/bin/build.d.ts +25 -0
  45. package/dist/bin/build.d.ts.map +1 -0
  46. package/dist/bin/build.js +80 -0
  47. package/dist/bin/build.js.map +1 -0
  48. package/dist/bin/build.spec.js +170 -0
  49. package/dist/bin/build.spec.js.map +1 -0
  50. package/dist/bin/generateImportMap/index.d.ts.map +1 -1
  51. package/dist/bin/generateImportMap/index.js +8 -5
  52. package/dist/bin/generateImportMap/index.js.map +1 -1
  53. package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.d.ts +5 -1
  54. package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.d.ts.map +1 -1
  55. package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.js +24 -18
  56. package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.js.map +1 -1
  57. package/dist/bin/generateTypes.d.ts +3 -2
  58. package/dist/bin/generateTypes.d.ts.map +1 -1
  59. package/dist/bin/generateTypes.js +4 -0
  60. package/dist/bin/generateTypes.js.map +1 -1
  61. package/dist/bin/index.d.ts.map +1 -1
  62. package/dist/bin/index.js +9 -0
  63. package/dist/bin/index.js.map +1 -1
  64. package/dist/bin/loadEnv.d.ts +3 -1
  65. package/dist/bin/loadEnv.d.ts.map +1 -1
  66. package/dist/bin/loadEnv.js +40 -10
  67. package/dist/bin/loadEnv.js.map +1 -1
  68. package/dist/collections/config/defaults.js +2 -2
  69. package/dist/collections/config/defaults.js.map +1 -1
  70. package/dist/collections/config/defaults.spec.js +47 -0
  71. package/dist/collections/config/defaults.spec.js.map +1 -0
  72. package/dist/collections/operations/create.d.ts.map +1 -1
  73. package/dist/collections/operations/create.js +1 -0
  74. package/dist/collections/operations/create.js.map +1 -1
  75. package/dist/collections/operations/local/duplicate.d.ts.map +1 -1
  76. package/dist/collections/operations/local/duplicate.js.map +1 -1
  77. package/dist/collections/operations/local/find.d.ts.map +1 -1
  78. package/dist/collections/operations/local/find.js.map +1 -1
  79. package/dist/collections/operations/local/findByID.d.ts.map +1 -1
  80. package/dist/collections/operations/local/findByID.js.map +1 -1
  81. package/dist/collections/operations/local/findVersionByID.d.ts.map +1 -1
  82. package/dist/collections/operations/local/findVersionByID.js.map +1 -1
  83. package/dist/collections/operations/local/findVersions.d.ts.map +1 -1
  84. package/dist/collections/operations/local/findVersions.js.map +1 -1
  85. package/dist/collections/operations/local/restoreVersion.d.ts.map +1 -1
  86. package/dist/collections/operations/local/restoreVersion.js.map +1 -1
  87. package/dist/collections/operations/utilities/update.d.ts.map +1 -1
  88. package/dist/collections/operations/utilities/update.js +16 -8
  89. package/dist/collections/operations/utilities/update.js.map +1 -1
  90. package/dist/config/types.d.ts +10 -1
  91. package/dist/config/types.d.ts.map +1 -1
  92. package/dist/config/types.js +1 -0
  93. package/dist/config/types.js.map +1 -1
  94. package/dist/database/migrations/migrationsCollection.d.ts.map +1 -1
  95. package/dist/database/migrations/migrationsCollection.js +2 -1
  96. package/dist/database/migrations/migrationsCollection.js.map +1 -1
  97. package/dist/exports/shared.d.ts +20 -0
  98. package/dist/exports/shared.d.ts.map +1 -1
  99. package/dist/exports/shared.js +20 -0
  100. package/dist/exports/shared.js.map +1 -1
  101. package/dist/fields/config/client.d.ts +1 -1
  102. package/dist/fields/config/client.d.ts.map +1 -1
  103. package/dist/fields/config/client.js +1 -1
  104. package/dist/fields/config/client.js.map +1 -1
  105. package/dist/fields/validations.d.ts.map +1 -1
  106. package/dist/fields/validations.js +5 -4
  107. package/dist/fields/validations.js.map +1 -1
  108. package/dist/globals/config/sanitize.d.ts.map +1 -1
  109. package/dist/globals/config/sanitize.js +1 -0
  110. package/dist/globals/config/sanitize.js.map +1 -1
  111. package/dist/globals/config/sanitize.spec.js +43 -0
  112. package/dist/globals/config/sanitize.spec.js.map +1 -0
  113. package/dist/globals/operations/local/findOne.d.ts.map +1 -1
  114. package/dist/globals/operations/local/findOne.js.map +1 -1
  115. package/dist/globals/operations/local/update.d.ts.map +1 -1
  116. package/dist/globals/operations/local/update.js.map +1 -1
  117. package/dist/index.bundled.d.ts +178 -17
  118. package/dist/index.d.ts +8 -9
  119. package/dist/index.d.ts.map +1 -1
  120. package/dist/index.js +50 -33
  121. package/dist/index.js.map +1 -1
  122. package/dist/kv/adapters/DatabaseKVAdapter.d.ts.map +1 -1
  123. package/dist/kv/adapters/DatabaseKVAdapter.js +1 -0
  124. package/dist/kv/adapters/DatabaseKVAdapter.js.map +1 -1
  125. package/dist/locked-documents/config.d.ts.map +1 -1
  126. package/dist/locked-documents/config.js +2 -1
  127. package/dist/locked-documents/config.js.map +1 -1
  128. package/dist/preferences/config.d.ts.map +1 -1
  129. package/dist/preferences/config.js +2 -1
  130. package/dist/preferences/config.js.map +1 -1
  131. package/dist/query-presets/config.d.ts.map +1 -1
  132. package/dist/query-presets/config.js +2 -1
  133. package/dist/query-presets/config.js.map +1 -1
  134. package/dist/queues/config/collection.d.ts.map +1 -1
  135. package/dist/queues/config/collection.js +2 -1
  136. package/dist/queues/config/collection.js.map +1 -1
  137. package/dist/queues/config/generateJobsJSONSchemas.js +2 -2
  138. package/dist/queues/config/generateJobsJSONSchemas.js.map +1 -1
  139. package/dist/queues/config/global.d.ts.map +1 -1
  140. package/dist/queues/config/global.js +2 -1
  141. package/dist/queues/config/global.js.map +1 -1
  142. package/dist/uploads/fetchAPI-multipart/processMultipart.d.ts.map +1 -1
  143. package/dist/uploads/fetchAPI-multipart/processMultipart.js +14 -1
  144. package/dist/uploads/fetchAPI-multipart/processMultipart.js.map +1 -1
  145. package/dist/uploads/generateFileData.d.ts +2 -1
  146. package/dist/uploads/generateFileData.d.ts.map +1 -1
  147. package/dist/uploads/generateFileData.js +5 -2
  148. package/dist/uploads/generateFileData.js.map +1 -1
  149. package/dist/uploads/safeFetch.d.ts.map +1 -1
  150. package/dist/uploads/safeFetch.js +11 -5
  151. package/dist/uploads/safeFetch.js.map +1 -1
  152. package/dist/utilities/configToJSONSchema.d.ts +25 -0
  153. package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
  154. package/dist/utilities/configToJSONSchema.js +73 -31
  155. package/dist/utilities/configToJSONSchema.js.map +1 -1
  156. package/dist/utilities/configToJSONSchema.spec.js +216 -29
  157. package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
  158. package/dist/utilities/dependencies/dependencyChecker.js +1 -1
  159. package/dist/utilities/dependencies/dependencyChecker.js.map +1 -1
  160. package/dist/utilities/dependencies/getDependencies.d.ts.map +1 -1
  161. package/dist/utilities/dependencies/getDependencies.js +5 -5
  162. package/dist/utilities/dependencies/getDependencies.js.map +1 -1
  163. package/dist/utilities/dynamicImport.js +1 -1
  164. package/dist/utilities/dynamicImport.js.map +1 -1
  165. package/dist/utilities/formatErrors.d.ts.map +1 -1
  166. package/dist/utilities/formatErrors.js +3 -1
  167. package/dist/utilities/formatErrors.js.map +1 -1
  168. package/dist/utilities/getRequestLanguage.d.ts +2 -2
  169. package/dist/utilities/getRequestLanguage.d.ts.map +1 -1
  170. package/dist/utilities/getRequestLanguage.js.map +1 -1
  171. package/dist/utilities/handleEndpoints.d.ts.map +1 -1
  172. package/dist/utilities/handleEndpoints.js +7 -3
  173. package/dist/utilities/handleEndpoints.js.map +1 -1
  174. package/dist/utilities/isRSCEnabled.d.ts +12 -0
  175. package/dist/utilities/isRSCEnabled.d.ts.map +1 -0
  176. package/dist/utilities/isRSCEnabled.js +14 -0
  177. package/dist/utilities/isRSCEnabled.js.map +1 -0
  178. package/dist/utilities/telemetry/conf/envPaths.d.ts.map +1 -1
  179. package/dist/utilities/telemetry/conf/envPaths.js +31 -40
  180. package/dist/utilities/telemetry/conf/envPaths.js.map +1 -1
  181. package/dist/utilities/transformColumnPreferences.js +4 -2
  182. package/dist/utilities/transformColumnPreferences.js.map +1 -1
  183. package/package.json +8 -5
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/locked-documents/config.ts"],"sourcesContent":["import type { CollectionConfig } from '../collections/config/types.js'\nimport type { Config } from '../config/types.js'\n\nimport { defaultAccess } from '../auth/defaultAccess.js'\n\nexport const lockedDocumentsCollectionSlug = 'payload-locked-documents'\n\nexport const getLockedDocumentsCollection = (config: Config): CollectionConfig | null => {\n const lockableCollections = config\n .collections!.filter((collectionConfig) => collectionConfig.lockDocuments !== false)\n .map((collectionConfig) => collectionConfig.slug)\n\n const lockableGlobals = config.globals\n ? config.globals.filter((globalConfig) => globalConfig.lockDocuments !== false)\n : []\n\n const authCollections = config\n .collections!.filter((collectionConfig) => collectionConfig.auth)\n .map((collectionConfig) => collectionConfig.slug)\n\n // If there are no lockable collections AND no lockable globals, don't create the collection\n if (lockableCollections.length === 0 && lockableGlobals.length === 0) {\n return null\n }\n\n // If there are no auth collections, we can't track who locked the document\n // so we shouldn't create the locked-documents collection\n if (authCollections.length === 0) {\n return null\n }\n\n const fields: CollectionConfig['fields'] = []\n\n // Only include the document field if there are lockable collections\n if (lockableCollections.length > 0) {\n fields.push({\n name: 'document',\n type: 'relationship',\n index: true,\n maxDepth: 0,\n relationTo: lockableCollections,\n })\n }\n\n // Always include globalSlug field for tracking global locks\n fields.push({\n name: 'globalSlug',\n type: 'text',\n index: true,\n })\n\n // Always include user field\n fields.push({\n name: 'user',\n type: 'relationship',\n maxDepth: 1,\n relationTo: authCollections,\n required: true,\n })\n\n return {\n slug: lockedDocumentsCollectionSlug,\n access: {\n create: defaultAccess,\n delete: defaultAccess,\n read: defaultAccess,\n update: defaultAccess,\n },\n admin: {\n hidden: true,\n },\n fields,\n lockDocuments: false,\n }\n}\n"],"names":["defaultAccess","lockedDocumentsCollectionSlug","getLockedDocumentsCollection","config","lockableCollections","collections","filter","collectionConfig","lockDocuments","map","slug","lockableGlobals","globals","globalConfig","authCollections","auth","length","fields","push","name","type","index","maxDepth","relationTo","required","access","create","delete","read","update","admin","hidden"],"mappings":"AAGA,SAASA,aAAa,QAAQ,2BAA0B;AAExD,OAAO,MAAMC,gCAAgC,2BAA0B;AAEvE,OAAO,MAAMC,+BAA+B,CAACC;IAC3C,MAAMC,sBAAsBD,OACzBE,WAAW,CAAEC,MAAM,CAAC,CAACC,mBAAqBA,iBAAiBC,aAAa,KAAK,OAC7EC,GAAG,CAAC,CAACF,mBAAqBA,iBAAiBG,IAAI;IAElD,MAAMC,kBAAkBR,OAAOS,OAAO,GAClCT,OAAOS,OAAO,CAACN,MAAM,CAAC,CAACO,eAAiBA,aAAaL,aAAa,KAAK,SACvE,EAAE;IAEN,MAAMM,kBAAkBX,OACrBE,WAAW,CAAEC,MAAM,CAAC,CAACC,mBAAqBA,iBAAiBQ,IAAI,EAC/DN,GAAG,CAAC,CAACF,mBAAqBA,iBAAiBG,IAAI;IAElD,4FAA4F;IAC5F,IAAIN,oBAAoBY,MAAM,KAAK,KAAKL,gBAAgBK,MAAM,KAAK,GAAG;QACpE,OAAO;IACT;IAEA,2EAA2E;IAC3E,yDAAyD;IACzD,IAAIF,gBAAgBE,MAAM,KAAK,GAAG;QAChC,OAAO;IACT;IAEA,MAAMC,SAAqC,EAAE;IAE7C,oEAAoE;IACpE,IAAIb,oBAAoBY,MAAM,GAAG,GAAG;QAClCC,OAAOC,IAAI,CAAC;YACVC,MAAM;YACNC,MAAM;YACNC,OAAO;YACPC,UAAU;YACVC,YAAYnB;QACd;IACF;IAEA,4DAA4D;IAC5Da,OAAOC,IAAI,CAAC;QACVC,MAAM;QACNC,MAAM;QACNC,OAAO;IACT;IAEA,4BAA4B;IAC5BJ,OAAOC,IAAI,CAAC;QACVC,MAAM;QACNC,MAAM;QACNE,UAAU;QACVC,YAAYT;QACZU,UAAU;IACZ;IAEA,OAAO;QACLd,MAAMT;QACNwB,QAAQ;YACNC,QAAQ1B;YACR2B,QAAQ3B;YACR4B,MAAM5B;YACN6B,QAAQ7B;QACV;QACA8B,OAAO;YACLC,QAAQ;QACV;QACAd;QACAT,eAAe;IACjB;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/locked-documents/config.ts"],"sourcesContent":["import type { CollectionConfig } from '../collections/config/types.js'\nimport type { Config } from '../config/types.js'\n\nimport { defaultAccess } from '../auth/defaultAccess.js'\n\nexport const lockedDocumentsCollectionSlug = 'payload-locked-documents'\n\nexport const getLockedDocumentsCollection = (config: Config): CollectionConfig | null => {\n const lockableCollections = config\n .collections!.filter((collectionConfig) => collectionConfig.lockDocuments !== false)\n .map((collectionConfig) => collectionConfig.slug)\n\n const lockableGlobals = config.globals\n ? config.globals.filter((globalConfig) => globalConfig.lockDocuments !== false)\n : []\n\n const authCollections = config\n .collections!.filter((collectionConfig) => collectionConfig.auth)\n .map((collectionConfig) => collectionConfig.slug)\n\n // If there are no lockable collections AND no lockable globals, don't create the collection\n if (lockableCollections.length === 0 && lockableGlobals.length === 0) {\n return null\n }\n\n // If there are no auth collections, we can't track who locked the document\n // so we shouldn't create the locked-documents collection\n if (authCollections.length === 0) {\n return null\n }\n\n const fields: CollectionConfig['fields'] = []\n\n // Only include the document field if there are lockable collections\n if (lockableCollections.length > 0) {\n fields.push({\n name: 'document',\n type: 'relationship',\n index: true,\n maxDepth: 0,\n relationTo: lockableCollections,\n })\n }\n\n // Always include globalSlug field for tracking global locks\n fields.push({\n name: 'globalSlug',\n type: 'text',\n index: true,\n })\n\n // Always include user field\n fields.push({\n name: 'user',\n type: 'relationship',\n maxDepth: 1,\n relationTo: authCollections,\n required: true,\n })\n\n return {\n slug: lockedDocumentsCollectionSlug,\n access: {\n create: defaultAccess,\n delete: defaultAccess,\n read: defaultAccess,\n update: defaultAccess,\n },\n admin: {\n hidden: true,\n },\n fields,\n lockDocuments: false,\n versions: false,\n }\n}\n"],"names":["defaultAccess","lockedDocumentsCollectionSlug","getLockedDocumentsCollection","config","lockableCollections","collections","filter","collectionConfig","lockDocuments","map","slug","lockableGlobals","globals","globalConfig","authCollections","auth","length","fields","push","name","type","index","maxDepth","relationTo","required","access","create","delete","read","update","admin","hidden","versions"],"mappings":"AAGA,SAASA,aAAa,QAAQ,2BAA0B;AAExD,OAAO,MAAMC,gCAAgC,2BAA0B;AAEvE,OAAO,MAAMC,+BAA+B,CAACC;IAC3C,MAAMC,sBAAsBD,OACzBE,WAAW,CAAEC,MAAM,CAAC,CAACC,mBAAqBA,iBAAiBC,aAAa,KAAK,OAC7EC,GAAG,CAAC,CAACF,mBAAqBA,iBAAiBG,IAAI;IAElD,MAAMC,kBAAkBR,OAAOS,OAAO,GAClCT,OAAOS,OAAO,CAACN,MAAM,CAAC,CAACO,eAAiBA,aAAaL,aAAa,KAAK,SACvE,EAAE;IAEN,MAAMM,kBAAkBX,OACrBE,WAAW,CAAEC,MAAM,CAAC,CAACC,mBAAqBA,iBAAiBQ,IAAI,EAC/DN,GAAG,CAAC,CAACF,mBAAqBA,iBAAiBG,IAAI;IAElD,4FAA4F;IAC5F,IAAIN,oBAAoBY,MAAM,KAAK,KAAKL,gBAAgBK,MAAM,KAAK,GAAG;QACpE,OAAO;IACT;IAEA,2EAA2E;IAC3E,yDAAyD;IACzD,IAAIF,gBAAgBE,MAAM,KAAK,GAAG;QAChC,OAAO;IACT;IAEA,MAAMC,SAAqC,EAAE;IAE7C,oEAAoE;IACpE,IAAIb,oBAAoBY,MAAM,GAAG,GAAG;QAClCC,OAAOC,IAAI,CAAC;YACVC,MAAM;YACNC,MAAM;YACNC,OAAO;YACPC,UAAU;YACVC,YAAYnB;QACd;IACF;IAEA,4DAA4D;IAC5Da,OAAOC,IAAI,CAAC;QACVC,MAAM;QACNC,MAAM;QACNC,OAAO;IACT;IAEA,4BAA4B;IAC5BJ,OAAOC,IAAI,CAAC;QACVC,MAAM;QACNC,MAAM;QACNE,UAAU;QACVC,YAAYT;QACZU,UAAU;IACZ;IAEA,OAAO;QACLd,MAAMT;QACNwB,QAAQ;YACNC,QAAQ1B;YACR2B,QAAQ3B;YACR4B,MAAM5B;YACN6B,QAAQ7B;QACV;QACA8B,OAAO;YACLC,QAAQ;QACV;QACAd;QACAT,eAAe;QACfwB,UAAU;IACZ;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/preferences/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,oBAAoB,CAAA;AA6BxD,eAAO,MAAM,yBAAyB,wBAAwB,CAAA;AAE9D,eAAO,MAAM,wBAAwB,GAAI,QAAQ,MAAM,KAAG,gBAwExD,CAAA"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/preferences/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,oBAAoB,CAAA;AA6BxD,eAAO,MAAM,yBAAyB,wBAAwB,CAAA;AAE9D,eAAO,MAAM,wBAAwB,GAAI,QAAQ,MAAM,KAAG,gBAyExD,CAAA"}
@@ -90,7 +90,8 @@ export const getPreferencesCollection = (config)=>({
90
90
  }
91
91
  }
92
92
  ],
93
- lockDocuments: false
93
+ lockDocuments: false,
94
+ versions: false
94
95
  });
95
96
 
96
97
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/preferences/config.ts"],"sourcesContent":["import type { CollectionConfig } from '../collections/config/types.js'\nimport type { Access, Config } from '../config/types.js'\nimport type { Where } from '../types/index.js'\n\nimport { deleteHandler } from './requestHandlers/delete.js'\nimport { findByIDHandler } from './requestHandlers/findOne.js'\nimport { updateHandler } from './requestHandlers/update.js'\n\nconst preferenceAccess: Access = ({ req }) => {\n if (!req.user) {\n return false\n }\n\n const userValueCondition: Where = {\n 'user.value': {\n equals: req.user.id,\n },\n }\n\n const userRelationCondition: Where = {\n 'user.relationTo': {\n equals: req.user.collection,\n },\n }\n\n return {\n and: [userValueCondition, userRelationCondition],\n }\n}\n\nexport const preferencesCollectionSlug = 'payload-preferences'\n\nexport const getPreferencesCollection = (config: Config): CollectionConfig => ({\n slug: preferencesCollectionSlug,\n access: {\n delete: preferenceAccess,\n read: preferenceAccess,\n },\n admin: {\n hidden: true,\n },\n endpoints: [\n {\n handler: findByIDHandler,\n method: 'get',\n path: '/:key',\n },\n {\n handler: deleteHandler,\n method: 'delete',\n path: '/:key',\n },\n {\n handler: updateHandler,\n method: 'post',\n path: '/:key',\n },\n ],\n fields: [\n {\n name: 'user',\n type: 'relationship',\n hooks: {\n beforeValidate: [\n ({ req }) => {\n if (!req?.user) {\n return null\n }\n\n return {\n relationTo: req?.user.collection,\n value: req?.user.id,\n }\n },\n ],\n },\n index: true,\n relationTo: config\n .collections!.filter((collectionConfig) => collectionConfig.auth)\n .map((collectionConfig) => collectionConfig.slug),\n required: true,\n },\n {\n name: 'key',\n type: 'text',\n index: true,\n },\n {\n name: 'value',\n type: 'json',\n validate: (value) => {\n if (value) {\n try {\n JSON.parse(JSON.stringify(value))\n } catch {\n return 'Invalid JSON'\n }\n }\n\n return true\n },\n },\n ],\n lockDocuments: false,\n})\n"],"names":["deleteHandler","findByIDHandler","updateHandler","preferenceAccess","req","user","userValueCondition","equals","id","userRelationCondition","collection","and","preferencesCollectionSlug","getPreferencesCollection","config","slug","access","delete","read","admin","hidden","endpoints","handler","method","path","fields","name","type","hooks","beforeValidate","relationTo","value","index","collections","filter","collectionConfig","auth","map","required","validate","JSON","parse","stringify","lockDocuments"],"mappings":"AAIA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,eAAe,QAAQ,+BAA8B;AAC9D,SAASC,aAAa,QAAQ,8BAA6B;AAE3D,MAAMC,mBAA2B,CAAC,EAAEC,GAAG,EAAE;IACvC,IAAI,CAACA,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OAAM;4BACN,OAAO;wBACT;oBACF;oBAEA,OAAO;gBACT;YACF;SACD;QACDY,eAAe;IACjB,CAAA,EAAE"}
1
+ {"version":3,"sources":["../../src/preferences/config.ts"],"sourcesContent":["import type { CollectionConfig } from '../collections/config/types.js'\nimport type { Access, Config } from '../config/types.js'\nimport type { Where } from '../types/index.js'\n\nimport { deleteHandler } from './requestHandlers/delete.js'\nimport { findByIDHandler } from './requestHandlers/findOne.js'\nimport { updateHandler } from './requestHandlers/update.js'\n\nconst preferenceAccess: Access = ({ req }) => {\n if (!req.user) {\n return false\n }\n\n const userValueCondition: Where = {\n 'user.value': {\n equals: req.user.id,\n },\n }\n\n const userRelationCondition: Where = {\n 'user.relationTo': {\n equals: req.user.collection,\n },\n }\n\n return {\n and: [userValueCondition, userRelationCondition],\n }\n}\n\nexport const preferencesCollectionSlug = 'payload-preferences'\n\nexport const getPreferencesCollection = (config: Config): CollectionConfig => ({\n slug: preferencesCollectionSlug,\n access: {\n delete: preferenceAccess,\n read: preferenceAccess,\n },\n admin: {\n hidden: true,\n },\n endpoints: [\n {\n handler: findByIDHandler,\n method: 'get',\n path: '/:key',\n },\n {\n handler: deleteHandler,\n method: 'delete',\n path: '/:key',\n },\n {\n handler: updateHandler,\n method: 'post',\n path: '/:key',\n },\n ],\n fields: [\n {\n name: 'user',\n type: 'relationship',\n hooks: {\n beforeValidate: [\n ({ req }) => {\n if (!req?.user) {\n return null\n }\n\n return {\n relationTo: req?.user.collection,\n value: req?.user.id,\n }\n },\n ],\n },\n index: true,\n relationTo: config\n .collections!.filter((collectionConfig) => collectionConfig.auth)\n .map((collectionConfig) => collectionConfig.slug),\n required: true,\n },\n {\n name: 'key',\n type: 'text',\n index: true,\n },\n {\n name: 'value',\n type: 'json',\n validate: (value) => {\n if (value) {\n try {\n JSON.parse(JSON.stringify(value))\n } catch {\n return 'Invalid JSON'\n }\n }\n\n return true\n },\n },\n ],\n lockDocuments: false,\n versions: false,\n})\n"],"names":["deleteHandler","findByIDHandler","updateHandler","preferenceAccess","req","user","userValueCondition","equals","id","userRelationCondition","collection","and","preferencesCollectionSlug","getPreferencesCollection","config","slug","access","delete","read","admin","hidden","endpoints","handler","method","path","fields","name","type","hooks","beforeValidate","relationTo","value","index","collections","filter","collectionConfig","auth","map","required","validate","JSON","parse","stringify","lockDocuments","versions"],"mappings":"AAIA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,eAAe,QAAQ,+BAA8B;AAC9D,SAASC,aAAa,QAAQ,8BAA6B;AAE3D,MAAMC,mBAA2B,CAAC,EAAEC,GAAG,EAAE;IACvC,IAAI,CAACA,IAAIC,IAAI,EAAE;QACb,OAAO;IACT;IAEA,MAAMC,qBAA4B;QAChC,cAAc;YACZC,QAAQH,IAAIC,IAAI,CAACG,EAAE;QACrB;IACF;IAEA,MAAMC,wBAA+B;QACnC,mBAAmB;YACjBF,QAAQH,IAAIC,IAAI,CAACK,UAAU;QAC7B;IACF;IAEA,OAAO;QACLC,KAAK;YAACL;YAAoBG;SAAsB;IAClD;AACF;AAEA,OAAO,MAAMG,4BAA4B,sBAAqB;AAE9D,OAAO,MAAMC,2BAA2B,CAACC,SAAsC,CAAA;QAC7EC,MAAMH;QACNI,QAAQ;YACNC,QAAQd;YACRe,MAAMf;QACR;QACAgB,OAAO;YACLC,QAAQ;QACV;QACAC,WAAW;YACT;gBACEC,SAASrB;gBACTsB,QAAQ;gBACRC,MAAM;YACR;YACA;gBACEF,SAAStB;gBACTuB,QAAQ;gBACRC,MAAM;YACR;YACA;gBACEF,SAASpB;gBACTqB,QAAQ;gBACRC,MAAM;YACR;SACD;QACDC,QAAQ;YACN;gBACEC,MAAM;gBACNC,MAAM;gBACNC,OAAO;oBACLC,gBAAgB;wBACd,CAAC,EAAEzB,GAAG,EAAE;4BACN,IAAI,CAACA,KAAKC,MAAM;gCACd,OAAO;4BACT;4BAEA,OAAO;gCACLyB,YAAY1B,KAAKC,KAAKK;gCACtBqB,OAAO3B,KAAKC,KAAKG;4BACnB;wBACF;qBACD;gBACH;gBACAwB,OAAO;gBACPF,YAAYhB,OACTmB,WAAW,CAAEC,MAAM,CAAC,CAACC,mBAAqBA,iBAAiBC,IAAI,EAC/DC,GAAG,CAAC,CAACF,mBAAqBA,iBAAiBpB,IAAI;gBAClDuB,UAAU;YACZ;YACA;gBACEZ,MAAM;gBACNC,MAAM;gBACNK,OAAO;YACT;YACA;gBACEN,MAAM;gBACNC,MAAM;gBACNY,UAAU,CAACR;oBACT,IAAIA,OAAO;wBACT,IAAI;4BACFS,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACX;wBAC5B,EAAE,OAAM;4BACN,OAAO;wBACT;oBACF;oBAEA,OAAO;gBACT;YACF;SACD;QACDY,eAAe;QACfC,UAAU;IACZ,CAAA,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/query-presets/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAShD,eAAO,MAAM,0BAA0B,0BAA0B,CAAA;AAEjE,eAAO,MAAM,qBAAqB,GAAI,QAAQ,MAAM,KAAG,gBA6KrD,CAAA"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/query-presets/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAShD,eAAO,MAAM,0BAA0B,0BAA0B,CAAA;AAEjE,eAAO,MAAM,qBAAqB,GAAI,QAAQ,MAAM,KAAG,gBA8KrD,CAAA"}
@@ -168,7 +168,8 @@ export const getQueryPresetsConfig = (config)=>({
168
168
  select: ({ select })=>select ? {
169
169
  ...select,
170
170
  relatedCollection: true
171
- } : undefined
171
+ } : undefined,
172
+ versions: false
172
173
  });
173
174
 
174
175
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/query-presets/config.ts"],"sourcesContent":["import type { CollectionConfig } from '../collections/config/types.js'\nimport type { Config } from '../config/types.js'\nimport type { Option } from '../fields/config/types.js'\n\nimport { transformWhereQuery } from '../utilities/transformWhereQuery.js'\nimport { validateWhereQuery } from '../utilities/validateWhereQuery.js'\nimport { getAccess } from './access.js'\nimport { getConstraints } from './constraints.js'\nimport { operations, type QueryPreset } from './types.js'\n\nexport const queryPresetsCollectionSlug = 'payload-query-presets'\n\nexport const getQueryPresetsConfig = (config: Config): CollectionConfig => ({\n slug: queryPresetsCollectionSlug,\n access: getAccess(config),\n admin: {\n defaultColumns: ['title', 'isShared', 'access', 'where', 'columns', 'groupBy'],\n hidden: true,\n useAsTitle: 'title',\n },\n fields: [\n {\n name: 'title',\n type: 'text',\n required: true,\n },\n {\n name: 'isShared',\n type: 'checkbox',\n defaultValue: false,\n validate: (isShared, { data }) => {\n const typedData = data as QueryPreset\n\n // ensure the `isShared` is only true if all constraints are 'onlyMe'\n if (typedData?.access) {\n const someOperationsAreShared = Object.values(typedData.access).some(\n (operation) => operation.constraint !== 'onlyMe',\n )\n\n if (!isShared && someOperationsAreShared) {\n return 'If any constraint is not \"onlyMe\", the preset must be shared'\n }\n }\n\n return true\n },\n },\n getConstraints(config),\n {\n name: 'where',\n type: 'json',\n admin: {\n components: {\n Cell: '@payloadcms/ui#QueryPresetsWhereCell',\n Field: '@payloadcms/ui#QueryPresetsWhereField',\n },\n },\n hooks: {\n beforeValidate: [\n ({ data }) => {\n // transform the \"where\" query here so that the client-side doesn't have to\n if (data?.where) {\n if (validateWhereQuery(data.where)) {\n return data.where\n } else {\n return transformWhereQuery(data.where)\n }\n }\n\n return data?.where\n },\n ],\n },\n label: 'Filters',\n },\n {\n name: 'columns',\n type: 'json',\n admin: {\n components: {\n Cell: '@payloadcms/ui#QueryPresetsColumnsCell',\n Field: '@payloadcms/ui#QueryPresetsColumnField',\n },\n },\n validate: (value) => {\n if (value) {\n try {\n JSON.parse(JSON.stringify(value))\n } catch {\n return 'Invalid JSON'\n }\n }\n\n return true\n },\n },\n {\n name: 'groupBy',\n type: 'text',\n admin: {\n components: {\n Cell: '@payloadcms/ui#QueryPresetsGroupByCell',\n Field: '@payloadcms/ui#QueryPresetsGroupByField',\n },\n },\n label: 'Group By',\n },\n {\n name: 'relatedCollection',\n type: 'select',\n admin: {\n hidden: true,\n },\n options: config.collections\n ? config.collections.reduce((acc, collection) => {\n if (collection.enableQueryPresets) {\n acc.push({\n label: collection.labels?.plural || collection.slug,\n value: collection.slug,\n })\n }\n return acc\n }, [] as Option[])\n : [],\n required: true,\n },\n {\n name: 'isTemp',\n type: 'checkbox',\n admin: {\n description:\n \"This is a temporary field used to determine if updating the preset would remove the user's access to it. When `true`, this record will be deleted after running the preset's `validate` function.\",\n disabled: true,\n hidden: true,\n },\n },\n ],\n hooks: {\n beforeValidate: [\n ({ data, operation }) => {\n // TODO: type this\n const typedData = data as any\n\n if (operation === 'create' || operation === 'update') {\n // Ensure all operations have a constraint\n operations.forEach((operation) => {\n if (!typedData.access) {\n typedData.access = {}\n }\n\n if (!typedData.access?.[operation]) {\n typedData[operation] = {}\n }\n\n // Ensure all operations have a constraint\n if (!typedData.access[operation]?.constraint) {\n typedData.access[operation] = {\n ...typedData.access[operation],\n constraint: 'onlyMe',\n }\n }\n })\n\n // If at least one constraint is not `onlyMe` then `isShared` must be true\n if (typedData?.access) {\n const someOperationsAreShared = Object.values(typedData.access).some(\n // TODO: remove the `any` here\n (operation: any) => operation.constraint !== 'onlyMe',\n )\n\n typedData.isShared = someOperationsAreShared\n }\n }\n\n return typedData\n },\n ],\n },\n labels: {\n plural: 'Presets',\n singular: 'Preset',\n ...(config.queryPresets?.labels || {}),\n },\n lockDocuments: false,\n select: ({ select }) => (select ? { ...select, relatedCollection: true } : undefined),\n})\n"],"names":["transformWhereQuery","validateWhereQuery","getAccess","getConstraints","operations","queryPresetsCollectionSlug","getQueryPresetsConfig","config","slug","access","admin","defaultColumns","hidden","useAsTitle","fields","name","type","required","defaultValue","validate","isShared","data","typedData","someOperationsAreShared","Object","values","some","operation","constraint","components","Cell","Field","hooks","beforeValidate","where","label","value","JSON","parse","stringify","options","collections","reduce","acc","collection","enableQueryPresets","push","labels","plural","description","disabled","forEach","singular","queryPresets","lockDocuments","select","relatedCollection","undefined"],"mappings":"AAIA,SAASA,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,SAAS,QAAQ,cAAa;AACvC,SAASC,cAAc,QAAQ,mBAAkB;AACjD,SAASC,UAAU,QAA0B,aAAY;AAEzD,OAAO,MAAMC,6BAA6B,wBAAuB;AAEjE,OAAO,MAAMC,wBAAwB,CAACC,SAAsC,CAAA;QAC1EC,MAAMH;QACNI,QAAQP,UAAUK;QAClBG,OAAO;YACLC,gBAAgB;gBAAC;gBAAS;gBAAY;gBAAU;gBAAS;gBAAW;aAAU;YAC9EC,QAAQ;YACRC,YAAY;QACd;QACAC,QAAQ;YACN;gBACEC,MAAM;gBACNC,MAAM;gBACNC,UAAU;YACZ;YACA;gBACEF,MAAM;gBACNC,MAAM;gBACNE,cAAc;gBACdC,UAAU,CAACC,UAAU,EAAEC,IAAI,EAAE;oBAC3B,MAAMC,YAAYD;oBAElB,qEAAqE;oBACrE,IAAIC,WAAWb,QAAQ;wBACrB,MAAMc,0BAA0BC,OAAOC,MAAM,CAACH,UAAUb,MAAM,EAAEiB,IAAI,CAClE,CAACC,YAAcA,UAAUC,UAAU,KAAK;wBAG1C,IAAI,CAACR,YAAYG,yBAAyB;4BACxC,OAAO;wBACT;oBACF;oBAEA,OAAO;gBACT;YACF;YACApB,eAAeI;YACf;gBACEQ,MAAM;gBACNC,MAAM;gBACNN,OAAO;oBACLmB,YAAY;wBACVC,MAAM;wBACNC,OAAO;oBACT;gBACF;gBACAC,OAAO;oBACLC,gBAAgB;wBACd,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,YAAYD;oBAElB,IAAIM,cAAc,YAAYA,cAAc,UAAU;wBACpD,0CAA0C;wBAC1CvB,WAAW+C,OAAO,CAAC,CAACxB;4BAClB,IAAI,CAACL,UAAUb,MAAM,EAAE;gCACrBa,UAAUb,MAAM,GAAG,CAAC;4BACtB;4BAEA,IAAI,CAACa,UAAUb,MAAM,EAAE,CAACkB,UAAU,EAAE;gCAClCL,SAAS,CAACK,UAAU,GAAG,CAAC;4BAC1B;4BAEA,0CAA0C;4BAC1C,IAAI,CAACL,UAAUb,MAAM,CAACkB,UAAU,EAAEC,YAAY;gCAC5CN,UAAUb,MAAM,CAACkB,UAAU,GAAG;oCAC5B,GAAGL,UAAUb,MAAM,CAACkB,UAAU;oCAC9BC,YAAY;gCACd;4BACF;wBACF;wBAEA,0EAA0E;wBAC1E,IAAIN,WAAWb,QAAQ;4BACrB,MAAMc,0BAA0BC,OAAOC,MAAM,CAACH,UAAUb,MAAM,EAAEiB,IAAI,CAClE,8BAA8B;4BAC9B,CAACC,YAAmBA,UAAUC,UAAU,KAAK;4BAG/CN,UAAUF,QAAQ,GAAGG;wBACvB;oBACF;oBAEA,OAAOD;gBACT;aACD;QACH;QACAyB,QAAQ;YACNC,QAAQ;YACRI,UAAU;YACV,GAAI7C,OAAO8C,YAAY,EAAEN,UAAU,CAAC,CAAC;QACvC;QACAO,eAAe;QACfC,QAAQ,CAAC,EAAEA,MAAM,EAAE,GAAMA,SAAS;gBAAE,GAAGA,MAAM;gBAAEC,mBAAmB;YAAK,IAAIC;IAC7E,CAAA,EAAE"}
1
+ {"version":3,"sources":["../../src/query-presets/config.ts"],"sourcesContent":["import type { CollectionConfig } from '../collections/config/types.js'\nimport type { Config } from '../config/types.js'\nimport type { Option } from '../fields/config/types.js'\n\nimport { transformWhereQuery } from '../utilities/transformWhereQuery.js'\nimport { validateWhereQuery } from '../utilities/validateWhereQuery.js'\nimport { getAccess } from './access.js'\nimport { getConstraints } from './constraints.js'\nimport { operations, type QueryPreset } from './types.js'\n\nexport const queryPresetsCollectionSlug = 'payload-query-presets'\n\nexport const getQueryPresetsConfig = (config: Config): CollectionConfig => ({\n slug: queryPresetsCollectionSlug,\n access: getAccess(config),\n admin: {\n defaultColumns: ['title', 'isShared', 'access', 'where', 'columns', 'groupBy'],\n hidden: true,\n useAsTitle: 'title',\n },\n fields: [\n {\n name: 'title',\n type: 'text',\n required: true,\n },\n {\n name: 'isShared',\n type: 'checkbox',\n defaultValue: false,\n validate: (isShared, { data }) => {\n const typedData = data as QueryPreset\n\n // ensure the `isShared` is only true if all constraints are 'onlyMe'\n if (typedData?.access) {\n const someOperationsAreShared = Object.values(typedData.access).some(\n (operation) => operation.constraint !== 'onlyMe',\n )\n\n if (!isShared && someOperationsAreShared) {\n return 'If any constraint is not \"onlyMe\", the preset must be shared'\n }\n }\n\n return true\n },\n },\n getConstraints(config),\n {\n name: 'where',\n type: 'json',\n admin: {\n components: {\n Cell: '@payloadcms/ui#QueryPresetsWhereCell',\n Field: '@payloadcms/ui#QueryPresetsWhereField',\n },\n },\n hooks: {\n beforeValidate: [\n ({ data }) => {\n // transform the \"where\" query here so that the client-side doesn't have to\n if (data?.where) {\n if (validateWhereQuery(data.where)) {\n return data.where\n } else {\n return transformWhereQuery(data.where)\n }\n }\n\n return data?.where\n },\n ],\n },\n label: 'Filters',\n },\n {\n name: 'columns',\n type: 'json',\n admin: {\n components: {\n Cell: '@payloadcms/ui#QueryPresetsColumnsCell',\n Field: '@payloadcms/ui#QueryPresetsColumnField',\n },\n },\n validate: (value) => {\n if (value) {\n try {\n JSON.parse(JSON.stringify(value))\n } catch {\n return 'Invalid JSON'\n }\n }\n\n return true\n },\n },\n {\n name: 'groupBy',\n type: 'text',\n admin: {\n components: {\n Cell: '@payloadcms/ui#QueryPresetsGroupByCell',\n Field: '@payloadcms/ui#QueryPresetsGroupByField',\n },\n },\n label: 'Group By',\n },\n {\n name: 'relatedCollection',\n type: 'select',\n admin: {\n hidden: true,\n },\n options: config.collections\n ? config.collections.reduce((acc, collection) => {\n if (collection.enableQueryPresets) {\n acc.push({\n label: collection.labels?.plural || collection.slug,\n value: collection.slug,\n })\n }\n return acc\n }, [] as Option[])\n : [],\n required: true,\n },\n {\n name: 'isTemp',\n type: 'checkbox',\n admin: {\n description:\n \"This is a temporary field used to determine if updating the preset would remove the user's access to it. When `true`, this record will be deleted after running the preset's `validate` function.\",\n disabled: true,\n hidden: true,\n },\n },\n ],\n hooks: {\n beforeValidate: [\n ({ data, operation }) => {\n // TODO: type this\n const typedData = data as any\n\n if (operation === 'create' || operation === 'update') {\n // Ensure all operations have a constraint\n operations.forEach((operation) => {\n if (!typedData.access) {\n typedData.access = {}\n }\n\n if (!typedData.access?.[operation]) {\n typedData[operation] = {}\n }\n\n // Ensure all operations have a constraint\n if (!typedData.access[operation]?.constraint) {\n typedData.access[operation] = {\n ...typedData.access[operation],\n constraint: 'onlyMe',\n }\n }\n })\n\n // If at least one constraint is not `onlyMe` then `isShared` must be true\n if (typedData?.access) {\n const someOperationsAreShared = Object.values(typedData.access).some(\n // TODO: remove the `any` here\n (operation: any) => operation.constraint !== 'onlyMe',\n )\n\n typedData.isShared = someOperationsAreShared\n }\n }\n\n return typedData\n },\n ],\n },\n labels: {\n plural: 'Presets',\n singular: 'Preset',\n ...(config.queryPresets?.labels || {}),\n },\n lockDocuments: false,\n select: ({ select }) => (select ? { ...select, relatedCollection: true } : undefined),\n versions: false,\n})\n"],"names":["transformWhereQuery","validateWhereQuery","getAccess","getConstraints","operations","queryPresetsCollectionSlug","getQueryPresetsConfig","config","slug","access","admin","defaultColumns","hidden","useAsTitle","fields","name","type","required","defaultValue","validate","isShared","data","typedData","someOperationsAreShared","Object","values","some","operation","constraint","components","Cell","Field","hooks","beforeValidate","where","label","value","JSON","parse","stringify","options","collections","reduce","acc","collection","enableQueryPresets","push","labels","plural","description","disabled","forEach","singular","queryPresets","lockDocuments","select","relatedCollection","undefined","versions"],"mappings":"AAIA,SAASA,mBAAmB,QAAQ,sCAAqC;AACzE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AAI,CAACL,UAAUb,MAAM,CAACkB,UAAU,EAAEC,YAAY;gCAC5CN,UAAUb,MAAM,CAACkB,UAAU,GAAG;oCAC5B,GAAGL,UAAUb,MAAM,CAACkB,UAAU;oCAC9BC,YAAY;gCACd;4BACF;wBACF;wBAEA,0EAA0E;wBAC1E,IAAIN,WAAWb,QAAQ;4BACrB,MAAMc,0BAA0BC,OAAOC,MAAM,CAACH,UAAUb,MAAM,EAAEiB,IAAI,CAClE,8BAA8B;4BAC9B,CAACC,YAAmBA,UAAUC,UAAU,KAAK;4BAG/CN,UAAUF,QAAQ,GAAGG;wBACvB;oBACF;oBAEA,OAAOD;gBACT;aACD;QACH;QACAyB,QAAQ;YACNC,QAAQ;YACRI,UAAU;YACV,GAAI7C,OAAO8C,YAAY,EAAEN,UAAU,CAAC,CAAC;QACvC;QACAO,eAAe;QACfC,QAAQ,CAAC,EAAEA,MAAM,EAAE,GAAMA,SAAS;gBAAE,GAAGA,MAAM;gBAAEC,mBAAmB;YAAK,IAAIC;QAC3EC,UAAU;IACZ,CAAA,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../../../src/queues/config/collection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AACzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAE5D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAMzC,eAAO,MAAM,kBAAkB,iBAAiB,CAAA;AAEhD,eAAO,MAAM,wBAAwB,EAAE,CAAC,UAAU,EAAE,eAAe,CAAC,MAAM,CAAC,KAAK,gBAuR/E,CAAA;AAGD,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE;IAAE,MAAM,EAAE,eAAe,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAE,GAAG,GAAG,CAMxF"}
1
+ {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../../../src/queues/config/collection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AACzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAE5D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAMzC,eAAO,MAAM,kBAAkB,iBAAiB,CAAA;AAEhD,eAAO,MAAM,wBAAwB,EAAE,CAAC,UAAU,EAAE,eAAe,CAAC,MAAM,CAAC,KAAK,gBAwR/E,CAAA;AAGD,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE;IAAE,MAAM,EAAE,eAAe,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAE,GAAG,GAAG,CAMxF"}
@@ -261,7 +261,8 @@ export const getDefaultJobsCollection = (jobsConfig)=>{
261
261
  }
262
262
  ]
263
263
  },
264
- lockDocuments: false
264
+ lockDocuments: false,
265
+ versions: false
265
266
  };
266
267
  if (jobsConfig.stats) {
267
268
  // TODO: In 4.0, this should be added by default.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/queues/config/collection.ts"],"sourcesContent":["import type { CollectionConfig } from '../../collections/config/types.js'\nimport type { SanitizedConfig } from '../../config/types.js'\nimport type { Field } from '../../fields/config/types.js'\nimport type { Job } from '../../index.js'\n\nimport { handleSchedulesJobsEndpoint } from '../endpoints/handleSchedules.js'\nimport { runJobsEndpoint } from '../endpoints/run.js'\nimport { getJobTaskStatus } from '../utilities/getJobTaskStatus.js'\n\nexport const jobsCollectionSlug = 'payload-jobs'\n\nexport const getDefaultJobsCollection: (jobsConfig: SanitizedConfig['jobs']) => CollectionConfig = (\n jobsConfig,\n) => {\n const workflowSlugs: Set<string> = new Set()\n const taskSlugs: Set<string> = new Set(['inline'])\n\n if (jobsConfig.workflows?.length) {\n jobsConfig.workflows.forEach((workflow) => {\n workflowSlugs.add(workflow.slug)\n\n // Validate concurrency config requires enableConcurrencyControl flag\n if (workflow.concurrency && !jobsConfig.enableConcurrencyControl) {\n throw new Error(\n `Workflow \"${workflow.slug}\" uses concurrency controls but \"jobs.enableConcurrencyControl\" is not enabled. ` +\n `Set \"jobs.enableConcurrencyControl: true\" in your Payload config to use concurrency controls. ` +\n `Note: This adds a new indexed field to the jobs collection schema and may require a database migration.`,\n )\n }\n })\n }\n\n if (jobsConfig.tasks?.length) {\n jobsConfig.tasks.forEach((task) => {\n if (workflowSlugs.has(task.slug)) {\n throw new Error(\n `Task slug \"${task.slug}\" is already used by a workflow. No tasks are allowed to have the same slug as a workflow.`,\n )\n }\n\n // Validate concurrency config requires enableConcurrencyControl flag\n if (task.concurrency && !jobsConfig.enableConcurrencyControl) {\n throw new Error(\n `Task \"${task.slug}\" uses concurrency controls but \"jobs.enableConcurrencyControl\" is not enabled. ` +\n `Set \"jobs.enableConcurrencyControl: true\" in your Payload config to use concurrency controls. ` +\n `Note: This adds a new indexed field to the jobs collection schema and may require a database migration.`,\n )\n }\n\n taskSlugs.add(task.slug)\n })\n }\n\n const logFields: Field[] = [\n {\n name: 'executedAt',\n type: 'date',\n required: true,\n },\n {\n name: 'completedAt',\n type: 'date',\n required: true,\n },\n {\n name: 'taskSlug',\n type: 'select',\n options: [...taskSlugs],\n required: true,\n },\n {\n name: 'taskID',\n type: 'text',\n required: true,\n },\n /**\n * @todo make required in 4.0\n */\n {\n name: 'input',\n type: 'json',\n },\n {\n name: 'output',\n type: 'json',\n },\n {\n name: 'state',\n type: 'radio',\n options: ['failed', 'succeeded'],\n required: true,\n },\n {\n name: 'error',\n type: 'json',\n admin: {\n condition: (_, data) => data.state === 'failed',\n },\n required: true,\n },\n ]\n\n if (jobsConfig.addParentToTaskLog) {\n logFields.push({\n name: 'parent',\n type: 'group',\n fields: [\n {\n name: 'taskSlug',\n type: 'select',\n options: [...taskSlugs],\n },\n {\n name: 'taskID',\n type: 'text',\n },\n ],\n })\n }\n\n const jobsCollection: CollectionConfig = {\n slug: jobsCollectionSlug,\n admin: {\n group: 'System',\n hidden: true,\n },\n endpoints: [runJobsEndpoint, handleSchedulesJobsEndpoint],\n fields: [\n {\n name: 'input',\n type: 'json',\n admin: {\n description: 'Input data provided to the job',\n },\n },\n {\n name: 'taskStatus',\n type: 'json',\n virtual: true,\n },\n {\n type: 'tabs',\n tabs: [\n {\n fields: [\n {\n name: 'completedAt',\n type: 'date',\n index: true,\n },\n {\n name: 'totalTried',\n type: 'number',\n defaultValue: 0,\n index: true,\n },\n {\n name: 'hasError',\n type: 'checkbox',\n admin: {\n description: 'If hasError is true this job will not be retried',\n },\n defaultValue: false,\n index: true,\n },\n {\n name: 'error',\n type: 'json',\n admin: {\n condition: (data) => data.hasError,\n description: 'If hasError is true, this is the error that caused it',\n },\n },\n {\n name: 'log',\n type: 'array',\n admin: {\n description: 'Task execution log',\n },\n fields: logFields,\n },\n ],\n label: 'Status',\n },\n ],\n },\n // only include the workflowSlugs field if workflows exist\n ...((workflowSlugs.size > 0\n ? [\n {\n name: 'workflowSlug',\n type: 'select',\n admin: {\n position: 'sidebar',\n },\n index: true,\n options: [...workflowSlugs],\n },\n ]\n : []) as Field[]),\n {\n name: 'taskSlug',\n type: 'select',\n admin: {\n position: 'sidebar',\n },\n index: true,\n options: [...taskSlugs],\n required: false,\n },\n {\n name: 'queue',\n type: 'text',\n admin: {\n position: 'sidebar',\n },\n defaultValue: 'default',\n index: true,\n },\n {\n name: 'waitUntil',\n type: 'date',\n admin: {\n date: { pickerAppearance: 'dayAndTime' },\n },\n index: true,\n },\n {\n name: 'processing',\n type: 'checkbox',\n admin: {\n position: 'sidebar',\n },\n defaultValue: false,\n index: true,\n },\n // Only add concurrencyKey field if concurrency control is enabled\n ...(jobsConfig.enableConcurrencyControl\n ? [\n {\n name: 'concurrencyKey',\n type: 'text',\n admin: {\n description:\n 'Used for concurrency control. Jobs with the same key are subject to exclusive/supersedes rules.',\n position: 'sidebar',\n readOnly: true,\n },\n index: true,\n } as Field,\n ]\n : []),\n ],\n hooks: {\n afterRead: [\n ({ doc, req }) => {\n // This hook is used to add the virtual `tasks` field to the document, that is computed from the `log` field\n\n return jobAfterRead({ config: req.payload.config, doc })\n },\n ],\n /**\n * If another update comes in after a job as already been cancelled, we need to make sure that update doesn't\n * change the state of the job.\n */\n beforeChange: [\n ({ data, originalDoc }) => {\n if (originalDoc?.error?.cancelled) {\n data.processing = false\n data.hasError = true\n delete data.completedAt\n delete data.waitUntil\n }\n return data\n },\n ],\n },\n lockDocuments: false,\n }\n\n if (jobsConfig.stats) {\n // TODO: In 4.0, this should be added by default.\n // The meta field can be used to store arbitrary data about the job. The scheduling system uses this to store\n // `scheduled: true` to indicate that the job was queued by the scheduling system.\n jobsCollection.fields.push({\n name: 'meta',\n type: 'json',\n })\n }\n return jobsCollection\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function jobAfterRead({ config, doc }: { config: SanitizedConfig; doc: Job }): Job {\n doc.taskStatus = getJobTaskStatus({\n jobLog: doc.log || [],\n })\n doc.input = doc.input || {}\n return doc\n}\n"],"names":["handleSchedulesJobsEndpoint","runJobsEndpoint","getJobTaskStatus","jobsCollectionSlug","getDefaultJobsCollection","jobsConfig","workflowSlugs","Set","taskSlugs","workflows","length","forEach","workflow","add","slug","concurrency","enableConcurrencyControl","Error","tasks","task","has","logFields","name","type","required","options","admin","condition","_","data","state","addParentToTaskLog","push","fields","jobsCollection","group","hidden","endpoints","description","virtual","tabs","index","defaultValue","hasError","label","size","position","date","pickerAppearance","readOnly","hooks","afterRead","doc","req","jobAfterRead","config","payload","beforeChange","originalDoc","error","cancelled","processing","completedAt","waitUntil","lockDocuments","stats","taskStatus","jobLog","log","input"],"mappings":"AAKA,SAASA,2BAA2B,QAAQ,kCAAiC;AAC7E,SAASC,eAAe,QAAQ,sBAAqB;AACrD,SAASC,gBAAgB,QAAQ,mCAAkC;AAEnE,OAAO,MAAMC,qBAAqB,eAAc;AAEhD,OAAO,MAAMC,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,IAAI3D,WAAW4D,KAAK,EAAE;QACpB,iDAAiD;QACjD,6GAA6G;QAC7G,kFAAkF;QAClF/B,eAAeD,MAAM,CAACD,IAAI,CAAC;YACzBV,MAAM;YACNC,MAAM;QACR;IACF;IACA,OAAOW;AACT,EAAC;AAED,6DAA6D;AAC7D,OAAO,SAASoB,aAAa,EAAEC,MAAM,EAAEH,GAAG,EAAyC;IACjFA,IAAIc,UAAU,GAAGhE,iBAAiB;QAChCiE,QAAQf,IAAIgB,GAAG,IAAI,EAAE;IACvB;IACAhB,IAAIiB,KAAK,GAAGjB,IAAIiB,KAAK,IAAI,CAAC;IAC1B,OAAOjB;AACT"}
1
+ {"version":3,"sources":["../../../src/queues/config/collection.ts"],"sourcesContent":["import type { CollectionConfig } from '../../collections/config/types.js'\nimport type { SanitizedConfig } from '../../config/types.js'\nimport type { Field } from '../../fields/config/types.js'\nimport type { Job } from '../../index.js'\n\nimport { handleSchedulesJobsEndpoint } from '../endpoints/handleSchedules.js'\nimport { runJobsEndpoint } from '../endpoints/run.js'\nimport { getJobTaskStatus } from '../utilities/getJobTaskStatus.js'\n\nexport const jobsCollectionSlug = 'payload-jobs'\n\nexport const getDefaultJobsCollection: (jobsConfig: SanitizedConfig['jobs']) => CollectionConfig = (\n jobsConfig,\n) => {\n const workflowSlugs: Set<string> = new Set()\n const taskSlugs: Set<string> = new Set(['inline'])\n\n if (jobsConfig.workflows?.length) {\n jobsConfig.workflows.forEach((workflow) => {\n workflowSlugs.add(workflow.slug)\n\n // Validate concurrency config requires enableConcurrencyControl flag\n if (workflow.concurrency && !jobsConfig.enableConcurrencyControl) {\n throw new Error(\n `Workflow \"${workflow.slug}\" uses concurrency controls but \"jobs.enableConcurrencyControl\" is not enabled. ` +\n `Set \"jobs.enableConcurrencyControl: true\" in your Payload config to use concurrency controls. ` +\n `Note: This adds a new indexed field to the jobs collection schema and may require a database migration.`,\n )\n }\n })\n }\n\n if (jobsConfig.tasks?.length) {\n jobsConfig.tasks.forEach((task) => {\n if (workflowSlugs.has(task.slug)) {\n throw new Error(\n `Task slug \"${task.slug}\" is already used by a workflow. No tasks are allowed to have the same slug as a workflow.`,\n )\n }\n\n // Validate concurrency config requires enableConcurrencyControl flag\n if (task.concurrency && !jobsConfig.enableConcurrencyControl) {\n throw new Error(\n `Task \"${task.slug}\" uses concurrency controls but \"jobs.enableConcurrencyControl\" is not enabled. ` +\n `Set \"jobs.enableConcurrencyControl: true\" in your Payload config to use concurrency controls. ` +\n `Note: This adds a new indexed field to the jobs collection schema and may require a database migration.`,\n )\n }\n\n taskSlugs.add(task.slug)\n })\n }\n\n const logFields: Field[] = [\n {\n name: 'executedAt',\n type: 'date',\n required: true,\n },\n {\n name: 'completedAt',\n type: 'date',\n required: true,\n },\n {\n name: 'taskSlug',\n type: 'select',\n options: [...taskSlugs],\n required: true,\n },\n {\n name: 'taskID',\n type: 'text',\n required: true,\n },\n /**\n * @todo make required in 4.0\n */\n {\n name: 'input',\n type: 'json',\n },\n {\n name: 'output',\n type: 'json',\n },\n {\n name: 'state',\n type: 'radio',\n options: ['failed', 'succeeded'],\n required: true,\n },\n {\n name: 'error',\n type: 'json',\n admin: {\n condition: (_, data) => data.state === 'failed',\n },\n required: true,\n },\n ]\n\n if (jobsConfig.addParentToTaskLog) {\n logFields.push({\n name: 'parent',\n type: 'group',\n fields: [\n {\n name: 'taskSlug',\n type: 'select',\n options: [...taskSlugs],\n },\n {\n name: 'taskID',\n type: 'text',\n },\n ],\n })\n }\n\n const jobsCollection: CollectionConfig = {\n slug: jobsCollectionSlug,\n admin: {\n group: 'System',\n hidden: true,\n },\n endpoints: [runJobsEndpoint, handleSchedulesJobsEndpoint],\n fields: [\n {\n name: 'input',\n type: 'json',\n admin: {\n description: 'Input data provided to the job',\n },\n },\n {\n name: 'taskStatus',\n type: 'json',\n virtual: true,\n },\n {\n type: 'tabs',\n tabs: [\n {\n fields: [\n {\n name: 'completedAt',\n type: 'date',\n index: true,\n },\n {\n name: 'totalTried',\n type: 'number',\n defaultValue: 0,\n index: true,\n },\n {\n name: 'hasError',\n type: 'checkbox',\n admin: {\n description: 'If hasError is true this job will not be retried',\n },\n defaultValue: false,\n index: true,\n },\n {\n name: 'error',\n type: 'json',\n admin: {\n condition: (data) => data.hasError,\n description: 'If hasError is true, this is the error that caused it',\n },\n },\n {\n name: 'log',\n type: 'array',\n admin: {\n description: 'Task execution log',\n },\n fields: logFields,\n },\n ],\n label: 'Status',\n },\n ],\n },\n // only include the workflowSlugs field if workflows exist\n ...((workflowSlugs.size > 0\n ? [\n {\n name: 'workflowSlug',\n type: 'select',\n admin: {\n position: 'sidebar',\n },\n index: true,\n options: [...workflowSlugs],\n },\n ]\n : []) as Field[]),\n {\n name: 'taskSlug',\n type: 'select',\n admin: {\n position: 'sidebar',\n },\n index: true,\n options: [...taskSlugs],\n required: false,\n },\n {\n name: 'queue',\n type: 'text',\n admin: {\n position: 'sidebar',\n },\n defaultValue: 'default',\n index: true,\n },\n {\n name: 'waitUntil',\n type: 'date',\n admin: {\n date: { pickerAppearance: 'dayAndTime' },\n },\n index: true,\n },\n {\n name: 'processing',\n type: 'checkbox',\n admin: {\n position: 'sidebar',\n },\n defaultValue: false,\n index: true,\n },\n // Only add concurrencyKey field if concurrency control is enabled\n ...(jobsConfig.enableConcurrencyControl\n ? [\n {\n name: 'concurrencyKey',\n type: 'text',\n admin: {\n description:\n 'Used for concurrency control. Jobs with the same key are subject to exclusive/supersedes rules.',\n position: 'sidebar',\n readOnly: true,\n },\n index: true,\n } as Field,\n ]\n : []),\n ],\n hooks: {\n afterRead: [\n ({ doc, req }) => {\n // This hook is used to add the virtual `tasks` field to the document, that is computed from the `log` field\n\n return jobAfterRead({ config: req.payload.config, doc })\n },\n ],\n /**\n * If another update comes in after a job as already been cancelled, we need to make sure that update doesn't\n * change the state of the job.\n */\n beforeChange: [\n ({ data, originalDoc }) => {\n if (originalDoc?.error?.cancelled) {\n data.processing = false\n data.hasError = true\n delete data.completedAt\n delete data.waitUntil\n }\n return data\n },\n ],\n },\n lockDocuments: false,\n versions: false,\n }\n\n if (jobsConfig.stats) {\n // TODO: In 4.0, this should be added by default.\n // The meta field can be used to store arbitrary data about the job. The scheduling system uses this to store\n // `scheduled: true` to indicate that the job was queued by the scheduling system.\n jobsCollection.fields.push({\n name: 'meta',\n type: 'json',\n })\n }\n return jobsCollection\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function jobAfterRead({ config, doc }: { config: SanitizedConfig; doc: Job }): Job {\n doc.taskStatus = getJobTaskStatus({\n jobLog: doc.log || [],\n })\n doc.input = doc.input || {}\n return doc\n}\n"],"names":["handleSchedulesJobsEndpoint","runJobsEndpoint","getJobTaskStatus","jobsCollectionSlug","getDefaultJobsCollection","jobsConfig","workflowSlugs","Set","taskSlugs","workflows","length","forEach","workflow","add","slug","concurrency","enableConcurrencyControl","Error","tasks","task","has","logFields","name","type","required","options","admin","condition","_","data","state","addParentToTaskLog","push","fields","jobsCollection","group","hidden","endpoints","description","virtual","tabs","index","defaultValue","hasError","label","size","position","date","pickerAppearance","readOnly","hooks","afterRead","doc","req","jobAfterRead","config","payload","beforeChange","originalDoc","error","cancelled","processing","completedAt","waitUntil","lockDocuments","versions","stats","taskStatus","jobLog","log","input"],"mappings":"AAKA,SAASA,2BAA2B,QAAQ,kCAAiC;AAC7E,SAASC,eAAe,QAAQ,sBAAqB;AACrD,SAASC,gBAAgB,QAAQ,mCAAkC;AAEnE,OAAO,MAAMC,qBAAqB,eAAc;AAEhD,OAAO,MAAMC,2BAAsF,CACjGC;IAEA,MAAMC,gBAA6B,IAAIC;IACvC,MAAMC,YAAyB,IAAID,IAAI;QAAC;KAAS;IAEjD,IAAIF,WAAWI,SAAS,EAAEC,QAAQ;QAChCL,WAAWI,SAAS,CAACE,OAAO,CAAC,CAACC;YAC5BN,cAAcO,GAAG,CAACD,SAASE,IAAI;YAE/B,qEAAqE;YACrE,IAAIF,SAASG,WAAW,IAAI,CAACV,WAAWW,wBAAwB,EAAE;gBA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;QAChCkE,QAAQhB,IAAIiB,GAAG,IAAI,EAAE;IACvB;IACAjB,IAAIkB,KAAK,GAAGlB,IAAIkB,KAAK,IAAI,CAAC;IAC1B,OAAOlB;AACT"}
@@ -72,7 +72,7 @@ export function generateJobsJSONSchemas(config, jobsConfig, interfaceNameDefinit
72
72
  ...Object.fromEntries((jobsConfig.tasks ?? []).map((task)=>{
73
73
  const normalizedTaskSlug = task.slug[0].toUpperCase() + task.slug.slice(1);
74
74
  const toReturn = {
75
- $ref: task.interfaceName ? `#/definitions/${task.interfaceName}` : `#/definitions/Task${normalizedTaskSlug}`
75
+ $ref: task.interfaceName ? `#/$defs/${task.interfaceName}` : `#/$defs/Task${normalizedTaskSlug}`
76
76
  };
77
77
  return [
78
78
  task.slug,
@@ -136,7 +136,7 @@ export function generateJobsJSONSchemas(config, jobsConfig, interfaceNameDefinit
136
136
  properties: Object.fromEntries(jobsConfig.workflows.map((workflow)=>{
137
137
  const normalizedWorkflowSlug = workflow.slug[0].toUpperCase() + workflow.slug.slice(1);
138
138
  const toReturn = {
139
- $ref: workflow.interfaceName ? `#/definitions/${workflow.interfaceName}` : `#/definitions/Workflow${normalizedWorkflowSlug}`
139
+ $ref: workflow.interfaceName ? `#/$defs/${workflow.interfaceName}` : `#/$defs/Workflow${normalizedWorkflowSlug}`
140
140
  };
141
141
  return [
142
142
  workflow.slug,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/queues/config/generateJobsJSONSchemas.ts"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\nimport type { JSONSchema4 } from 'json-schema'\n\nimport type { SanitizedConfig } from '../../config/types.js'\nimport type { JobsConfig } from './types/index.js'\n\nimport { fieldsToJSONSchema } from '../../utilities/configToJSONSchema.js'\nimport { flattenAllFields } from '../../utilities/flattenAllFields.js'\nexport function generateJobsJSONSchemas(\n config: SanitizedConfig,\n jobsConfig: JobsConfig,\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n /**\n * Used for relationship fields, to determine whether to use a string or number type for the ID.\n * While there is a default ID field type set by the db adapter, they can differ on a collection-level\n * if they have custom ID fields.\n */\n collectionIDFieldTypes: { [key: string]: 'number' | 'string' },\n typeStringDefinitions: Set<string>,\n i18n?: I18n,\n): {\n definitions?: Map<string, JSONSchema4>\n properties?: { tasks: JSONSchema4 }\n} {\n const properties: { tasks: JSONSchema4; workflows: JSONSchema4 } = {\n tasks: {},\n workflows: {},\n }\n const definitions: Map<string, JSONSchema4> = new Map()\n\n if (jobsConfig?.tasks?.length) {\n for (const task of jobsConfig.tasks) {\n const fullTaskJsonSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {\n input: {},\n output: {},\n },\n required: [],\n }\n if (task?.inputSchema?.length) {\n const inputJsonSchema = fieldsToJSONSchema({\n collectionIDFieldTypes,\n config,\n fields: flattenAllFields({ fields: task.inputSchema }),\n i18n,\n interfaceNameDefinitions,\n typeStringDefinitions,\n })\n\n const fullInputJsonSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: inputJsonSchema.properties,\n required: inputJsonSchema.required,\n }\n\n fullTaskJsonSchema.properties!.input = fullInputJsonSchema\n ;(fullTaskJsonSchema.required as string[]).push('input')\n }\n if (task?.outputSchema?.length) {\n const outputJsonSchema = fieldsToJSONSchema({\n collectionIDFieldTypes,\n config,\n fields: flattenAllFields({ fields: task.outputSchema }),\n i18n,\n interfaceNameDefinitions,\n typeStringDefinitions,\n })\n\n const fullOutputJsonSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: outputJsonSchema.properties,\n required: outputJsonSchema.required,\n }\n\n fullTaskJsonSchema.properties!.output = fullOutputJsonSchema\n ;(fullTaskJsonSchema.required as string[]).push('output')\n }\n\n const normalizedTaskSlug = task.slug[0].toUpperCase() + task.slug.slice(1)\n\n definitions.set(task.interfaceName ?? `Task${normalizedTaskSlug}`, fullTaskJsonSchema)\n }\n // Now add properties.tasks definition that references the types in definitions keyed by task slug:\n properties.tasks = {\n type: 'object',\n additionalProperties: false,\n properties: {\n ...Object.fromEntries(\n (jobsConfig.tasks ?? []).map((task) => {\n const normalizedTaskSlug = task.slug[0].toUpperCase() + task.slug.slice(1)\n\n const toReturn: JSONSchema4 = {\n $ref: task.interfaceName\n ? `#/definitions/${task.interfaceName}`\n : `#/definitions/Task${normalizedTaskSlug}`,\n }\n\n return [task.slug, toReturn]\n }),\n ),\n inline: {\n type: 'object',\n additionalProperties: false,\n properties: {\n input: {},\n output: {},\n },\n required: ['input', 'output'],\n },\n },\n required: [...(jobsConfig.tasks ?? []).map((task) => task.slug), 'inline'],\n }\n }\n\n if (jobsConfig?.workflows?.length) {\n for (const workflow of jobsConfig.workflows) {\n const fullWorkflowJsonSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {\n input: {},\n },\n required: [],\n }\n\n if (workflow?.inputSchema?.length) {\n const inputJsonSchema = fieldsToJSONSchema({\n collectionIDFieldTypes,\n config,\n fields: flattenAllFields({ fields: workflow.inputSchema }),\n i18n,\n interfaceNameDefinitions,\n typeStringDefinitions,\n })\n\n const fullInputJsonSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: inputJsonSchema.properties,\n required: inputJsonSchema.required,\n }\n\n fullWorkflowJsonSchema.properties!.input = fullInputJsonSchema\n ;(fullWorkflowJsonSchema.required as string[]).push('input')\n }\n const normalizedWorkflowSlug = workflow.slug[0].toUpperCase() + workflow.slug.slice(1)\n\n definitions.set(\n workflow.interfaceName ?? `Workflow${normalizedWorkflowSlug}`,\n fullWorkflowJsonSchema,\n )\n\n properties.workflows = {\n type: 'object',\n additionalProperties: false,\n properties: Object.fromEntries(\n jobsConfig.workflows.map((workflow) => {\n const normalizedWorkflowSlug = workflow.slug[0].toUpperCase() + workflow.slug.slice(1)\n\n const toReturn: JSONSchema4 = {\n $ref: workflow.interfaceName\n ? `#/definitions/${workflow.interfaceName}`\n : `#/definitions/Workflow${normalizedWorkflowSlug}`,\n }\n\n return [workflow.slug, toReturn]\n }),\n ),\n required: jobsConfig.workflows.map((workflow) => workflow.slug),\n }\n }\n }\n\n return {\n definitions,\n properties,\n }\n}\n"],"names":["fieldsToJSONSchema","flattenAllFields","generateJobsJSONSchemas","config","jobsConfig","interfaceNameDefinitions","collectionIDFieldTypes","typeStringDefinitions","i18n","properties","tasks","workflows","definitions","Map","length","task","fullTaskJsonSchema","type","additionalProperties","input","output","required","inputSchema","inputJsonSchema","fields","fullInputJsonSchema","push","outputSchema","outputJsonSchema","fullOutputJsonSchema","normalizedTaskSlug","slug","toUpperCase","slice","set","interfaceName","Object","fromEntries","map","toReturn","$ref","inline","workflow","fullWorkflowJsonSchema","normalizedWorkflowSlug"],"mappings":"AAMA,SAASA,kBAAkB,QAAQ,wCAAuC;AAC1E,SAASC,gBAAgB,QAAQ,sCAAqC;AACtE,OAAO,SAASC,wBACdC,MAAuB,EACvBC,UAAsB,EACtBC,wBAAkD,EAClD;;;;GAIC,GACDC,sBAA8D,EAC9DC,qBAAkC,EAClCC,IAAW;IAKX,MAAMC,aAA6D;QACjEC,OAAO,CAAC;QACRC,WAAW,CAAC;IACd;IACA,MAAMC,cAAwC,IAAIC;IAElD,IAAIT,YAAYM,OAAOI,QAAQ;QAC7B,KAAK,MAAMC,QAAQX,WAAWM,KAAK,CAAE;YACnC,MAAMM,qBAAkC;gBACtCC,MAAM;gBACNC,sBAAsB;gBACtBT,YAAY;oBACVU,OAAO,CAAC;oBACRC,QAAQ,CAAC;gBACX;gBACAC,UAAU,EAAE;YACd;YACA,IAAIN,MAAMO,aAAaR,QAAQ;gBAC7B,MAAMS,kBAAkBvB,mBAAmB;oBACzCM;oBACAH;oBACAqB,QAAQvB,iBAAiB;wBAAEuB,QAAQT,KAAKO,WAAW;oBAAC;oBACpDd;oBACAH;oBACAE;gBACF;gBAEA,MAAMkB,sBAAmC;oBACvCR,MAAM;oBACNC,sBAAsB;oBACtBT,YAAYc,gBAAgBd,UAAU;oBACtCY,UAAUE,gBAAgBF,QAAQ;gBACpC;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WAAW,KAAKU,SAASX,IAAI,CAACE,KAAK,CAAC;oBAEpF,MAAMM,WAAwB;wBAC5BC,MAAME,SAASP,aAAa,GACxB,CAAC,cAAc,EAAEO,SAASP,aAAa,EAAE,GACzC,CAAC,sBAAsB,EAAES,wBAAwB;oBACvD;oBAEA,OAAO;wBAACF,SAASX,IAAI;wBAAEQ;qBAAS;gBAClC;gBAEFlB,UAAUjB,WAAWO,SAAS,CAAC2B,GAAG,CAAC,CAACI,WAAaA,SAASX,IAAI;YAChE;QACF;IACF;IAEA,OAAO;QACLnB;QACAH;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/queues/config/generateJobsJSONSchemas.ts"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\nimport type { JSONSchema4 } from 'json-schema'\n\nimport type { SanitizedConfig } from '../../config/types.js'\nimport type { JobsConfig } from './types/index.js'\n\nimport { fieldsToJSONSchema } from '../../utilities/configToJSONSchema.js'\nimport { flattenAllFields } from '../../utilities/flattenAllFields.js'\nexport function generateJobsJSONSchemas(\n config: SanitizedConfig,\n jobsConfig: JobsConfig,\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n /**\n * Used for relationship fields, to determine whether to use a string or number type for the ID.\n * While there is a default ID field type set by the db adapter, they can differ on a collection-level\n * if they have custom ID fields.\n */\n collectionIDFieldTypes: { [key: string]: 'number' | 'string' },\n typeStringDefinitions: Set<string>,\n i18n?: I18n,\n): {\n definitions?: Map<string, JSONSchema4>\n properties?: { tasks: JSONSchema4 }\n} {\n const properties: { tasks: JSONSchema4; workflows: JSONSchema4 } = {\n tasks: {},\n workflows: {},\n }\n const definitions: Map<string, JSONSchema4> = new Map()\n\n if (jobsConfig?.tasks?.length) {\n for (const task of jobsConfig.tasks) {\n const fullTaskJsonSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {\n input: {},\n output: {},\n },\n required: [],\n }\n if (task?.inputSchema?.length) {\n const inputJsonSchema = fieldsToJSONSchema({\n collectionIDFieldTypes,\n config,\n fields: flattenAllFields({ fields: task.inputSchema }),\n i18n,\n interfaceNameDefinitions,\n typeStringDefinitions,\n })\n\n const fullInputJsonSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: inputJsonSchema.properties,\n required: inputJsonSchema.required,\n }\n\n fullTaskJsonSchema.properties!.input = fullInputJsonSchema\n ;(fullTaskJsonSchema.required as string[]).push('input')\n }\n if (task?.outputSchema?.length) {\n const outputJsonSchema = fieldsToJSONSchema({\n collectionIDFieldTypes,\n config,\n fields: flattenAllFields({ fields: task.outputSchema }),\n i18n,\n interfaceNameDefinitions,\n typeStringDefinitions,\n })\n\n const fullOutputJsonSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: outputJsonSchema.properties,\n required: outputJsonSchema.required,\n }\n\n fullTaskJsonSchema.properties!.output = fullOutputJsonSchema\n ;(fullTaskJsonSchema.required as string[]).push('output')\n }\n\n const normalizedTaskSlug = task.slug[0].toUpperCase() + task.slug.slice(1)\n\n definitions.set(task.interfaceName ?? `Task${normalizedTaskSlug}`, fullTaskJsonSchema)\n }\n // Now add properties.tasks definition that references the types in definitions keyed by task slug:\n properties.tasks = {\n type: 'object',\n additionalProperties: false,\n properties: {\n ...Object.fromEntries(\n (jobsConfig.tasks ?? []).map((task) => {\n const normalizedTaskSlug = task.slug[0].toUpperCase() + task.slug.slice(1)\n\n const toReturn: JSONSchema4 = {\n $ref: task.interfaceName\n ? `#/$defs/${task.interfaceName}`\n : `#/$defs/Task${normalizedTaskSlug}`,\n }\n\n return [task.slug, toReturn]\n }),\n ),\n inline: {\n type: 'object',\n additionalProperties: false,\n properties: {\n input: {},\n output: {},\n },\n required: ['input', 'output'],\n },\n },\n required: [...(jobsConfig.tasks ?? []).map((task) => task.slug), 'inline'],\n }\n }\n\n if (jobsConfig?.workflows?.length) {\n for (const workflow of jobsConfig.workflows) {\n const fullWorkflowJsonSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {\n input: {},\n },\n required: [],\n }\n\n if (workflow?.inputSchema?.length) {\n const inputJsonSchema = fieldsToJSONSchema({\n collectionIDFieldTypes,\n config,\n fields: flattenAllFields({ fields: workflow.inputSchema }),\n i18n,\n interfaceNameDefinitions,\n typeStringDefinitions,\n })\n\n const fullInputJsonSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: inputJsonSchema.properties,\n required: inputJsonSchema.required,\n }\n\n fullWorkflowJsonSchema.properties!.input = fullInputJsonSchema\n ;(fullWorkflowJsonSchema.required as string[]).push('input')\n }\n const normalizedWorkflowSlug = workflow.slug[0].toUpperCase() + workflow.slug.slice(1)\n\n definitions.set(\n workflow.interfaceName ?? `Workflow${normalizedWorkflowSlug}`,\n fullWorkflowJsonSchema,\n )\n\n properties.workflows = {\n type: 'object',\n additionalProperties: false,\n properties: Object.fromEntries(\n jobsConfig.workflows.map((workflow) => {\n const normalizedWorkflowSlug = workflow.slug[0].toUpperCase() + workflow.slug.slice(1)\n\n const toReturn: JSONSchema4 = {\n $ref: workflow.interfaceName\n ? `#/$defs/${workflow.interfaceName}`\n : `#/$defs/Workflow${normalizedWorkflowSlug}`,\n }\n\n return [workflow.slug, toReturn]\n }),\n ),\n required: jobsConfig.workflows.map((workflow) => workflow.slug),\n }\n }\n }\n\n return {\n definitions,\n properties,\n }\n}\n"],"names":["fieldsToJSONSchema","flattenAllFields","generateJobsJSONSchemas","config","jobsConfig","interfaceNameDefinitions","collectionIDFieldTypes","typeStringDefinitions","i18n","properties","tasks","workflows","definitions","Map","length","task","fullTaskJsonSchema","type","additionalProperties","input","output","required","inputSchema","inputJsonSchema","fields","fullInputJsonSchema","push","outputSchema","outputJsonSchema","fullOutputJsonSchema","normalizedTaskSlug","slug","toUpperCase","slice","set","interfaceName","Object","fromEntries","map","toReturn","$ref","inline","workflow","fullWorkflowJsonSchema","normalizedWorkflowSlug"],"mappings":"AAMA,SAASA,kBAAkB,QAAQ,wCAAuC;AAC1E,SAASC,gBAAgB,QAAQ,sC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jC,MAAMS,kBAAkBvB,mBAAmB;oBACzCM;oBACAH;oBACAqB,QAAQvB,iBAAiB;wBAAEuB,QAAQkB,SAASpB,WAAW;oBAAC;oBACxDd;oBACAH;oBACAE;gBACF;gBAEA,MAAMkB,sBAAmC;oBACvCR,MAAM;oBACNC,sBAAsB;oBACtBT,YAAYc,gBAAgBd,UAAU;oBACtCY,UAAUE,gBAAgBF,QAAQ;gBACpC;gBAEAsB,uBAAuBlC,UAAU,CAAEU,KAAK,GAAGM;gBACzCkB,uBAAuBtB,QAAQ,CAAcK,IAAI,CAAC;YACtD;YACA,MAAMkB,yBAAyBF,SAASX,IAAI,CAAC,EAAE,CAACC,WAAW,KAAKU,SAASX,IAAI,CAACE,KAAK,CAAC;YAEpFrB,YAAYsB,GAAG,CACbQ,SAASP,aAAa,IAAI,CAAC,QAAQ,EAAES,wBAAwB,EAC7DD;YAGFlC,WAAWE,SAAS,GAAG;gBACrBM,MAAM;gBACNC,sBAAsB;gBACtBT,YAAY2B,OAAOC,WAAW,CAC5BjC,WAAWO,SAAS,CAAC2B,GAAG,CAAC,CAACI;oBACxB,MAAME,yBAAyBF,SAASX,IAAI,CAAC,EAAE,CAACC,WAAW,KAAKU,SAASX,IAAI,CAACE,KAAK,CAAC;oBAEpF,MAAMM,WAAwB;wBAC5BC,MAAME,SAASP,aAAa,GACxB,CAAC,QAAQ,EAAEO,SAASP,aAAa,EAAE,GACnC,CAAC,gBAAgB,EAAES,wBAAwB;oBACjD;oBAEA,OAAO;wBAACF,SAASX,IAAI;wBAAEQ;qBAAS;gBAClC;gBAEFlB,UAAUjB,WAAWO,SAAS,CAAC2B,GAAG,CAAC,CAACI,WAAaA,SAASX,IAAI;YAChE;QACF;IACF;IAEA,OAAO;QACLnB;QACAH;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../../../src/queues/config/global.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,u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,SAAS,EAAE,MAAM,GAAG;oBACnB,KAAK,CAAC,EAAE;wBACN,CAAC,QAAQ,EAAE,QAAQ,GAAG;4BACpB,gBAAgB,EAAE,MAAM,CAAA;yBACzB,CAAA;qBACF,CAAA;oBACD,SAAS,CAAC,EAAE;wBACV,CAAC,YAAY,EAAE,aAAa,GAAG;4BAC7B,gBAAgB,EAAE,MAAM,CAAA;yBACzB,CAAA;qBACF,CAAA;iBACF,CAAA;aACF,CAAA;SACF,CAAA;KACF,CAAA;CACF,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,YAenD,CAAA"}
@@ -13,7 +13,8 @@ export const jobStatsGlobalSlug = 'payload-jobs-stats';
13
13
  name: 'stats',
14
14
  type: 'json'
15
15
  }
16
- ]
16
+ ],
17
+ versions: false
17
18
  };
18
19
  };
19
20
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/queues/config/global.ts"],"sourcesContent":["import type { Config } from '../../config/types.js'\nimport type { GlobalConfig } from '../../globals/config/types.js'\nimport type { TaskType } from './types/taskTypes.js'\nimport type { WorkflowTypes } from './types/workflowTypes.js'\n\nexport const jobStatsGlobalSlug = 'payload-jobs-stats'\n\n/**\n * Type for data stored in the payload-jobs-stats global.\n */\nexport type JobStats = {\n stats?: {\n scheduledRuns?: {\n queues?: {\n [queueSlug: string]: {\n tasks?: {\n [taskSlug: TaskType]: {\n lastScheduledRun: string\n }\n }\n workflows?: {\n [workflowSlug: WorkflowTypes]: {\n lastScheduledRun: string\n }\n }\n }\n }\n }\n }\n}\n\n/**\n * Global config for job statistics.\n */\nexport const getJobStatsGlobal: (config: Config) => GlobalConfig = (config) => {\n return {\n slug: jobStatsGlobalSlug,\n admin: {\n group: 'System',\n hidden: true,\n },\n fields: [\n {\n name: 'stats',\n type: 'json',\n },\n ],\n }\n}\n"],"names":["jobStatsGlobalSlug","getJobStatsGlobal","config","slug","admin","group","hidden","fields","name","type"],"mappings":"AAKA,OAAO,MAAMA,qBAAqB,qBAAoB;AA0BtD;;CAEC,GACD,OAAO,MAAMC,oBAAsD,CAACC;IAClE,OAAO;QACLC,MAAMH;QACNI,OAAO;YACLC,OAAO;YACPC,QAAQ;QACV;QACAC,QAAQ;YACN;gBACEC,MAAM;gBACNC,MAAM;YACR;SACD;IACH;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/queues/config/global.ts"],"sourcesContent":["import type { Config } from '../../config/types.js'\nimport type { GlobalConfig } from '../../globals/config/types.js'\nimport type { TaskType } from './types/taskTypes.js'\nimport type { WorkflowTypes } from './types/workflowTypes.js'\n\nexport const jobStatsGlobalSlug = 'payload-jobs-stats'\n\n/**\n * Type for data stored in the payload-jobs-stats global.\n */\nexport type JobStats = {\n stats?: {\n scheduledRuns?: {\n queues?: {\n [queueSlug: string]: {\n tasks?: {\n [taskSlug: TaskType]: {\n lastScheduledRun: string\n }\n }\n workflows?: {\n [workflowSlug: WorkflowTypes]: {\n lastScheduledRun: string\n }\n }\n }\n }\n }\n }\n}\n\n/**\n * Global config for job statistics.\n */\nexport const getJobStatsGlobal: (config: Config) => GlobalConfig = (config) => {\n return {\n slug: jobStatsGlobalSlug,\n admin: {\n group: 'System',\n hidden: true,\n },\n fields: [\n {\n name: 'stats',\n type: 'json',\n },\n ],\n versions: false,\n }\n}\n"],"names":["jobStatsGlobalSlug","getJobStatsGlobal","config","slug","admin","group","hidden","fields","name","type","versions"],"mappings":"AAKA,OAAO,MAAMA,qBAAqB,qBAAoB;AA0BtD;;CAEC,GACD,OAAO,MAAMC,oBAAsD,CAACC;IAClE,OAAO;QACLC,MAAMH;QACNI,OAAO;YACLC,OAAO;YACPC,QAAQ;QACV;QACAC,QAAQ;YACN;gBACEC,MAAM;gBACNC,MAAM;YACR;SACD;QACDC,UAAU;IACZ;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"processMultipart.d.ts","sourceRoot":"","sources":["../../../src/uploads/fetchAPI-multipart/processMultipart.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAS5D,QAAA,MAAM,iBAAiB,eAAuC,CAAA;AAE9D,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO;QACf,CAAC,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAA;KACrC;CACF;AAED,KAAK,gBAAgB,GAAG,CAAC,IAAI,EAAE;IAC7B,OAAO,EAAE,yBAAyB,CAAA;IAClC,OAAO,EAAE,OAAO,CAAA;CACjB,KAAK,OAAO,CAAC,0BAA0B,CAAC,CAAA;AACzC,eAAO,MAAM,gBAAgB,EAAE,gBAuN9B,CAAA"}
1
+ {"version":3,"file":"processMultipart.d.ts","sourceRoot":"","sources":["../../../src/uploads/fetchAPI-multipart/processMultipart.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAS5D,QAAA,MAAM,iBAAiB,eAAuC,CAAA;AAE9D,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO;QACf,CAAC,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAA;KACrC;CACF;AAED,KAAK,gBAAgB,GAAG,CAAC,IAAI,EAAE;IAC7B,OAAO,EAAE,yBAAyB,CAAA;IAClC,OAAO,EAAE,OAAO,CAAA;CACjB,KAAK,OAAO,CAAC,0BAA0B,CAAC,CAAA;AACzC,eAAO,MAAM,gBAAgB,EAAE,gBAgO9B,CAAA"}
@@ -20,10 +20,17 @@ export const processMultipart = async ({ options, request })=>{
20
20
  allFilesHaveResolved = res;
21
21
  failedResolvingFiles = rej;
22
22
  });
23
+ // Attach a no-op catch handler immediately to prevent Node.js from treating this as
24
+ // an unhandled rejection if failedResolvingFiles() is called while the read loop is
25
+ // still suspended at `await reader.read()`. The real error is rethrown below.
26
+ allFilesComplete.catch(()=>{});
23
27
  const busboyFinished = new Promise((resolve, reject)=>{
24
28
  busboyFinishedResolve = resolve;
25
29
  busboyFinishedReject = reject;
26
30
  });
31
+ // Prevent unhandled rejection when abortOnLimit rejects allFilesComplete
32
+ // (which throws at line ~241) before execution reaches `await busboyFinished`.
33
+ busboyFinished.catch(()=>{});
27
34
  const result = {
28
35
  fields: undefined,
29
36
  files: undefined
@@ -41,6 +48,9 @@ export const processMultipart = async ({ options, request })=>{
41
48
  file.destroy();
42
49
  shouldAbortProccessing = true;
43
50
  failedResolvingFiles(err);
51
+ // Cancel the reader so the while loop exits immediately rather than draining
52
+ // the rest of the request body after an abort.
53
+ void reader?.cancel();
44
54
  }
45
55
  // Build multipart req.body fields
46
56
  busboy.on('field', (field, val)=>{
@@ -144,9 +154,12 @@ export const processMultipart = async ({ options, request })=>{
144
154
  }
145
155
  busboyFinishedResolve();
146
156
  });
147
- busboy.on('error', (err = new APIError('Busboy error parsing multipart request', httpStatus.BAD_REQUEST))=>{
157
+ busboy.on('error', (err)=>{
148
158
  debugLog(options, `Busboy error`);
159
+ shouldAbortProccessing = true;
149
160
  const busboyError = err instanceof Error ? err : new APIError('Busboy error parsing multipart request', httpStatus.BAD_REQUEST);
161
+ // Reject both promises so neither hangs regardless of whether files were in-flight.
162
+ failedResolvingFiles(busboyError);
150
163
  busboyFinishedReject(busboyError);
151
164
  });
152
165
  while(parsingRequest){
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/uploads/fetchAPI-multipart/processMultipart.ts"],"sourcesContent":["import type { Readable } from 'stream'\n\nimport Busboy from 'busboy'\nimport { status as httpStatus } from 'http-status'\n\nimport type { FetchAPIFileUploadOptions } from '../../config/types.js'\nimport type { FetchAPIFileUploadResponse } from './index.js'\n\nimport { APIError } from '../../errors/APIError.js'\nimport { fileFactory } from './fileFactory.js'\nimport { memHandler, tempFileHandler } from './handlers.js'\nimport { processNested } from './processNested.js'\nimport { createUploadTimer } from './uploadTimer.js'\nimport { buildFields, debugLog, isFunc, parseFileName } from './utilities.js'\n\nconst waitFlushProperty = Symbol('wait flush property symbol')\n\ndeclare global {\n interface Request {\n [waitFlushProperty]?: Promise<any>[]\n }\n}\n\ntype ProcessMultipart = (args: {\n options: FetchAPIFileUploadOptions\n request: Request\n}) => Promise<FetchAPIFileUploadResponse>\nexport const processMultipart: ProcessMultipart = async ({ options, request }) => {\n let parsingRequest = true\n\n let shouldAbortProccessing = false\n let fileCount = 0\n let filesCompleted = 0\n let allFilesHaveResolved: (value?: unknown) => void\n let failedResolvingFiles: (err: Error) => void\n let busboyFinishedResolve: () => void\n let busboyFinishedReject: (err: Error) => void\n\n const allFilesComplete = new Promise((res, rej) => {\n allFilesHaveResolved = res\n failedResolvingFiles = rej\n })\n\n const busboyFinished = new Promise<void>((resolve, reject) => {\n busboyFinishedResolve = resolve\n busboyFinishedReject = reject\n })\n\n const result: FetchAPIFileUploadResponse = {\n fields: undefined!,\n files: undefined!,\n }\n\n const headersObject: Record<string, string> = {}\n request.headers.forEach((value, name) => {\n headersObject[name] = value\n })\n\n const reader = request.body?.getReader()\n\n const busboy = Busboy({ ...options, headers: headersObject })\n\n function abortAndDestroyFile(file: Readable, err: APIError) {\n file.destroy()\n shouldAbortProccessing = true\n failedResolvingFiles(err)\n }\n\n // Build multipart req.body fields\n busboy.on('field', (field, val) => {\n result.fields = buildFields(result.fields, field, val)\n })\n\n // Build req.files fields\n busboy.on('file', (field, file, info) => {\n fileCount += 1\n // Parse file name(cutting huge names, decoding, etc..).\n const { encoding, filename: name, mimeType: mime } = info\n const filename = parseFileName(options, name)\n\n const inferredMimeType =\n (filename && filename.endsWith('.glb') && 'model/gltf-binary') ||\n (filename && filename.endsWith('.gltf') && 'model/gltf+json') ||\n mime\n\n // Define methods and handlers for upload process.\n const { cleanup, complete, dataHandler, getFilePath, getFileSize, getHash, getWritePromise } =\n options.useTempFiles\n ? tempFileHandler(options, field, filename) // Upload into temporary file.\n : memHandler(options, field, filename) // Upload into RAM.\n\n const writePromise = options.useTempFiles\n ? getWritePromise().catch(() => {\n busboy.end()\n cleanup()\n })\n : getWritePromise()\n\n const uploadTimer = createUploadTimer(options.uploadTimeout, () => {\n return abortAndDestroyFile(\n file,\n new APIError(`Upload timeout for ${field}->${filename}, bytes:${getFileSize()}`),\n )\n })\n\n file.on('limit', () => {\n debugLog(options, `Size limit reached for ${field}->${filename}, bytes:${getFileSize()}`)\n uploadTimer.clear()\n\n if (isFunc(options.limitHandler)) {\n options.limitHandler({ request, size: getFileSize() })\n }\n\n // Return error and cleanup files if abortOnLimit set.\n if (options.abortOnLimit) {\n debugLog(options, `Upload file size limit reached ${field}->${filename}.`)\n cleanup()\n abortAndDestroyFile(\n file,\n new APIError(options.responseOnLimit!, httpStatus.REQUEST_ENTITY_TOO_LARGE, {\n size: getFileSize(),\n }),\n )\n }\n })\n\n file.on('data', (data) => {\n uploadTimer.set()\n dataHandler(data)\n })\n\n file.on('end', () => {\n const size = getFileSize()\n debugLog(options, `Upload finished ${field}->${filename}, bytes:${size}`)\n uploadTimer.clear()\n\n if (!name && size === 0) {\n fileCount -= 1\n if (options.useTempFiles) {\n cleanup()\n debugLog(options, `Removing the empty file ${field}->${filename}`)\n }\n return debugLog(options, `Don't add file instance if original name and size are empty`)\n }\n\n filesCompleted += 1\n\n result.files = buildFields(\n result.files,\n field,\n fileFactory(\n {\n name: filename,\n buffer: complete(),\n encoding,\n hash: getHash(),\n mimetype: inferredMimeType,\n size,\n tempFilePath: getFilePath(),\n truncated: Boolean('truncated' in file && file.truncated) || false,\n },\n options,\n ),\n )\n\n if (!request[waitFlushProperty]) {\n request[waitFlushProperty] = []\n }\n request[waitFlushProperty].push(writePromise)\n\n if (filesCompleted === fileCount) {\n allFilesHaveResolved()\n }\n })\n\n file.on('error', (err) => {\n uploadTimer.clear()\n debugLog(options, `File Error: ${err.message}`)\n cleanup()\n failedResolvingFiles(err)\n })\n\n // Start upload process.\n debugLog(options, `New upload started ${field}->${filename}, bytes:${getFileSize()}`)\n uploadTimer.set()\n })\n\n busboy.on('finish', async () => {\n debugLog(options, `Busboy finished parsing request.`)\n if (options.parseNested) {\n result.fields = processNested(result.fields)\n result.files = processNested(result.files)\n }\n\n if (request[waitFlushProperty]) {\n try {\n await Promise.all(request[waitFlushProperty]).then(() => {\n delete request[waitFlushProperty]\n })\n } catch (err) {\n debugLog(options, `Error waiting for file write promises: ${err}`)\n }\n }\n\n busboyFinishedResolve()\n })\n\n busboy.on(\n 'error',\n (err = new APIError('Busboy error parsing multipart request', httpStatus.BAD_REQUEST)) => {\n debugLog(options, `Busboy error`)\n const busboyError =\n err instanceof Error\n ? err\n : new APIError('Busboy error parsing multipart request', httpStatus.BAD_REQUEST)\n\n busboyFinishedReject(busboyError)\n },\n )\n\n while (parsingRequest) {\n const { done, value } = await reader!.read()\n\n if (done) {\n parsingRequest = false\n busboy.end()\n }\n\n if (value && !shouldAbortProccessing) {\n busboy.write(value)\n }\n }\n\n if (fileCount !== 0) {\n await allFilesComplete.catch((e) => {\n throw e\n })\n }\n\n await busboyFinished\n\n return result\n}\n"],"names":["Busboy","status","httpStatus","APIError","fileFactory","memHandler","tempFileHandler","processNested","createUploadTimer","buildFields","debugLog","isFunc","parseFileName","waitFlushProperty","Symbol","processMultipart","options","request","parsingRequest","shouldAbortProccessing","fileCount","filesCompleted","allFilesHaveResolved","failedResolvingFiles","busboyFinishedResolve","busboyFinishedReject","allFilesComplete","Promise","res","rej","busboyFinished","resolve","reject","result","fields","undefined","files","headersObject","headers","forEach","value","name","reader","body","getReader","busboy","abortAndDestroyFile","file","err","destroy","on","field","val","info","encoding","filename","mimeType","mime","inferredMimeType","endsWith","cleanup","complete","dataHandler","getFilePath","getFileSize","getHash","getWritePromise","useTempFiles","writePromise","catch","end","uploadTimer","uploadTimeout","clear","limitHandler","size","abortOnLimit","responseOnLimit","REQUEST_ENTITY_TOO_LARGE","data","set","buffer","hash","mimetype","tempFilePath","truncated","Boolean","push","message","parseNested","all","then","BAD_REQUEST","busboyError","Error","done","read","write","e"],"mappings":"AAEA,OAAOA,YAAY,SAAQ;AAC3B,SAASC,UAAUC,UAAU,QAAQ,cAAa;AAKlD,SAASC,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,UAAU,EAAEC,eAAe,QAAQ,gBAAe;AAC3D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,iBAAiB,QAAQ,mBAAkB;AACpD,SAASC,WAAW,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,aAAa,QAAQ,iBAAgB;AAE7E,MAAMC,oBAAoBC,OAAO;AAYjC,OAAO,MAAMC,mBAAqC,OAAO,EAAEC,OAAO,EAAEC,OAAO,EAAE;IAC3E,IAAIC,iBAAiB;IAErB,IAAIC,yBAAyB;IAC7B,IAAIC,YAAY;IAChB,IAAIC,iBAAiB;IACrB,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IAEJ,MAAMC,mBAAmB,IAAIC,QAAQ,CAACC,KAAKC;QACzCP,uBAAuBM;QACvBL,uBAAuBM;IACzB;IAEA,MAAMC,iBAAiB,IAAIH,QAAc,CAACI,SAASC;QACjDR,wBAAwBO;QACxBN,uBAAuBO;IACzB;IAEA,MAAMC,SAAqC;QACzCC,QAAQC;QACRC,OAAOD;IACT;IAEA,MAAME,gBAAwC,CAAC;IAC/CpB,QAAQqB,OAAO,CAACC,OAAO,CAAC,CAACC,OAAOC;QAC9BJ,aAAa,CAACI,KAAK,GAAGD;IACxB;IAEA,MAAME,SAASzB,QAAQ0B,IAAI,EAAEC;IAE7B,MAAMC,SAAS7C,OAAO;QAAE,GAAGgB,OAAO;QAAEsB,SAASD;IAAc;IAE3D,SAASS,oBAAoBC,IAAc,EAAEC,GAAa;QACxDD,KAAKE,OAAO;QACZ9B,yBAAyB;QACzBI,qBAAqByB;IAC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AAMM,iBAAiB2C,KAAK,CAAC,CAAC6B;YAC5B,MAAMA;QACR;IACF;IAEA,MAAMpE;IAEN,OAAOG;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../src/uploads/fetchAPI-multipart/processMultipart.ts"],"sourcesContent":["import type { Readable } from 'stream'\n\nimport Busboy from 'busboy'\nimport { status as httpStatus } from 'http-status'\n\nimport type { FetchAPIFileUploadOptions } from '../../config/types.js'\nimport type { FetchAPIFileUploadResponse } from './index.js'\n\nimport { APIError } from '../../errors/APIError.js'\nimport { fileFactory } from './fileFactory.js'\nimport { memHandler, tempFileHandler } from './handlers.js'\nimport { processNested } from './processNested.js'\nimport { createUploadTimer } from './uploadTimer.js'\nimport { buildFields, debugLog, isFunc, parseFileName } from './utilities.js'\n\nconst waitFlushProperty = Symbol('wait flush property symbol')\n\ndeclare global {\n interface Request {\n [waitFlushProperty]?: Promise<any>[]\n }\n}\n\ntype ProcessMultipart = (args: {\n options: FetchAPIFileUploadOptions\n request: Request\n}) => Promise<FetchAPIFileUploadResponse>\nexport const processMultipart: ProcessMultipart = async ({ options, request }) => {\n let parsingRequest = true\n\n let shouldAbortProccessing = false\n let fileCount = 0\n let filesCompleted = 0\n let allFilesHaveResolved: (value?: unknown) => void\n let failedResolvingFiles: (err: Error) => void\n let busboyFinishedResolve: () => void\n let busboyFinishedReject: (err: Error) => void\n\n const allFilesComplete = new Promise((res, rej) => {\n allFilesHaveResolved = res\n failedResolvingFiles = rej\n })\n // Attach a no-op catch handler immediately to prevent Node.js from treating this as\n // an unhandled rejection if failedResolvingFiles() is called while the read loop is\n // still suspended at `await reader.read()`. The real error is rethrown below.\n allFilesComplete.catch(() => {})\n\n const busboyFinished = new Promise<void>((resolve, reject) => {\n busboyFinishedResolve = resolve\n busboyFinishedReject = reject\n })\n // Prevent unhandled rejection when abortOnLimit rejects allFilesComplete\n // (which throws at line ~241) before execution reaches `await busboyFinished`.\n busboyFinished.catch(() => {})\n\n const result: FetchAPIFileUploadResponse = {\n fields: undefined!,\n files: undefined!,\n }\n\n const headersObject: Record<string, string> = {}\n request.headers.forEach((value, name) => {\n headersObject[name] = value\n })\n\n const reader = request.body?.getReader()\n\n const busboy = Busboy({ ...options, headers: headersObject })\n\n function abortAndDestroyFile(file: Readable, err: APIError) {\n file.destroy()\n shouldAbortProccessing = true\n failedResolvingFiles(err)\n // Cancel the reader so the while loop exits immediately rather than draining\n // the rest of the request body after an abort.\n void reader?.cancel()\n }\n\n // Build multipart req.body fields\n busboy.on('field', (field, val) => {\n result.fields = buildFields(result.fields, field, val)\n })\n\n // Build req.files fields\n busboy.on('file', (field, file, info) => {\n fileCount += 1\n // Parse file name(cutting huge names, decoding, etc..).\n const { encoding, filename: name, mimeType: mime } = info\n const filename = parseFileName(options, name)\n\n const inferredMimeType =\n (filename && filename.endsWith('.glb') && 'model/gltf-binary') ||\n (filename && filename.endsWith('.gltf') && 'model/gltf+json') ||\n mime\n\n // Define methods and handlers for upload process.\n const { cleanup, complete, dataHandler, getFilePath, getFileSize, getHash, getWritePromise } =\n options.useTempFiles\n ? tempFileHandler(options, field, filename) // Upload into temporary file.\n : memHandler(options, field, filename) // Upload into RAM.\n\n const writePromise = options.useTempFiles\n ? getWritePromise().catch(() => {\n busboy.end()\n cleanup()\n })\n : getWritePromise()\n\n const uploadTimer = createUploadTimer(options.uploadTimeout, () => {\n return abortAndDestroyFile(\n file,\n new APIError(`Upload timeout for ${field}->${filename}, bytes:${getFileSize()}`),\n )\n })\n\n file.on('limit', () => {\n debugLog(options, `Size limit reached for ${field}->${filename}, bytes:${getFileSize()}`)\n uploadTimer.clear()\n\n if (isFunc(options.limitHandler)) {\n options.limitHandler({ request, size: getFileSize() })\n }\n\n // Return error and cleanup files if abortOnLimit set.\n if (options.abortOnLimit) {\n debugLog(options, `Upload file size limit reached ${field}->${filename}.`)\n cleanup()\n abortAndDestroyFile(\n file,\n new APIError(options.responseOnLimit!, httpStatus.REQUEST_ENTITY_TOO_LARGE, {\n size: getFileSize(),\n }),\n )\n }\n })\n\n file.on('data', (data) => {\n uploadTimer.set()\n dataHandler(data)\n })\n\n file.on('end', () => {\n const size = getFileSize()\n debugLog(options, `Upload finished ${field}->${filename}, bytes:${size}`)\n uploadTimer.clear()\n\n if (!name && size === 0) {\n fileCount -= 1\n if (options.useTempFiles) {\n cleanup()\n debugLog(options, `Removing the empty file ${field}->${filename}`)\n }\n return debugLog(options, `Don't add file instance if original name and size are empty`)\n }\n\n filesCompleted += 1\n\n result.files = buildFields(\n result.files,\n field,\n fileFactory(\n {\n name: filename,\n buffer: complete(),\n encoding,\n hash: getHash(),\n mimetype: inferredMimeType,\n size,\n tempFilePath: getFilePath(),\n truncated: Boolean('truncated' in file && file.truncated) || false,\n },\n options,\n ),\n )\n\n if (!request[waitFlushProperty]) {\n request[waitFlushProperty] = []\n }\n request[waitFlushProperty].push(writePromise)\n\n if (filesCompleted === fileCount) {\n allFilesHaveResolved()\n }\n })\n\n file.on('error', (err) => {\n uploadTimer.clear()\n debugLog(options, `File Error: ${err.message}`)\n cleanup()\n failedResolvingFiles(err)\n })\n\n // Start upload process.\n debugLog(options, `New upload started ${field}->${filename}, bytes:${getFileSize()}`)\n uploadTimer.set()\n })\n\n busboy.on('finish', async () => {\n debugLog(options, `Busboy finished parsing request.`)\n if (options.parseNested) {\n result.fields = processNested(result.fields)\n result.files = processNested(result.files)\n }\n\n if (request[waitFlushProperty]) {\n try {\n await Promise.all(request[waitFlushProperty]).then(() => {\n delete request[waitFlushProperty]\n })\n } catch (err) {\n debugLog(options, `Error waiting for file write promises: ${err}`)\n }\n }\n\n busboyFinishedResolve()\n })\n\n busboy.on('error', (err?: Error) => {\n debugLog(options, `Busboy error`)\n shouldAbortProccessing = true\n const busboyError =\n err instanceof Error\n ? err\n : new APIError('Busboy error parsing multipart request', httpStatus.BAD_REQUEST)\n // Reject both promises so neither hangs regardless of whether files were in-flight.\n failedResolvingFiles(busboyError)\n busboyFinishedReject(busboyError)\n })\n\n while (parsingRequest) {\n const { done, value } = await reader!.read()\n\n if (done) {\n parsingRequest = false\n busboy.end()\n }\n\n if (value && !shouldAbortProccessing) {\n busboy.write(value)\n }\n }\n\n if (fileCount !== 0) {\n await allFilesComplete.catch((e) => {\n throw e\n })\n }\n\n await busboyFinished\n\n return result\n}\n"],"names":["Busboy","status","httpStatus","APIError","fileFactory","memHandler","tempFileHandler","processNested","createUploadTimer","buildFields","debugLog","isFunc","parseFileName","waitFlushProperty","Symbol","processMultipart","options","request","parsingRequest","shouldAbortProccessing","fileCount","filesCompleted","allFilesHaveResolved","failedResolvingFiles","busboyFinishedResolve","busboyFinishedReject","allFilesComplete","Promise","res","rej","catch","busboyFinished","resolve","reject","result","fields","undefined","files","headersObject","headers","forEach","value","name","reader","body","getReader","busboy","abortAndDestroyFile","file","err","destroy","cancel","on","field","val","info","encoding","filename","mimeType","mime","inferredMimeType","endsWith","cleanup","complete","dataHandler","getFilePath","getFileSize","getHash","getWritePromise","useTempFiles","writePromise","end","uploadTimer","uploadTimeout","clear","limitHandler","size","abortOnLimit","responseOnLimit","REQUEST_ENTITY_TOO_LARGE","data","set","buffer","hash","mimetype","tempFilePath","truncated","Boolean","push","message","parseNested","all","then","busboyError","Error","BAD_REQUEST","done","read","write","e"],"mappings":"AAEA,OAAOA,YAAY,SAAQ;AAC3B,SAASC,UAAUC,UAAU,QAAQ,cAAa;AAKlD,SAASC,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,UAAU,EAAEC,eAAe,QAAQ,gBAAe;AAC3D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,iBAAiB,QAAQ,mBAAkB;AACpD,SAASC,WAAW,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,aAAa,QAAQ,iBAAgB;AAE7E,MAAMC,oBAAoBC,OAAO;AAYjC,OAAO,MAAMC,mBAAqC,OAAO,EAAEC,OAAO,EAAEC,OAAO,EAAE;IAC3E,IAAIC,iBAAiB;IAErB,IAAIC,yB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MAAM,GAAG5B,cAAc2B,OAAOC,MAAM;YAC3CD,OAAOG,KAAK,GAAG9B,cAAc2B,OAAOG,KAAK;QAC3C;QAEA,IAAIpB,OAAO,CAACJ,kBAAkB,EAAE;YAC9B,IAAI;gBACF,MAAMc,QAAQgE,GAAG,CAAC1E,OAAO,CAACJ,kBAAkB,EAAE+E,IAAI,CAAC;oBACjD,OAAO3E,OAAO,CAACJ,kBAAkB;gBACnC;YACF,EAAE,OAAOoC,KAAK;gBACZvC,SAASM,SAAS,CAAC,uCAAuC,EAAEiC,KAAK;YACnE;QACF;QAEAzB;IACF;IAEAsB,OAAOM,EAAE,CAAC,SAAS,CAACH;QAClBvC,SAASM,SAAS,CAAC,YAAY,CAAC;QAChCG,yBAAyB;QACzB,MAAM0E,cACJ5C,eAAe6C,QACX7C,MACA,IAAI9C,SAAS,0CAA0CD,WAAW6F,WAAW;QACnF,oFAAoF;QACpFxE,qBAAqBsE;QACrBpE,qBAAqBoE;IACvB;IAEA,MAAO3E,eAAgB;QACrB,MAAM,EAAE8E,IAAI,EAAEvD,KAAK,EAAE,GAAG,MAAME,OAAQsD,IAAI;QAE1C,IAAID,MAAM;YACR9E,iBAAiB;YACjB4B,OAAOyB,GAAG;QACZ;QAEA,IAAI9B,SAAS,CAACtB,wBAAwB;YACpC2B,OAAOoD,KAAK,CAACzD;QACf;IACF;IAEA,IAAIrB,cAAc,GAAG;QACnB,MAAMM,iBAAiBI,KAAK,CAAC,CAACqE;YAC5B,MAAMA;QACR;IACF;IAEA,MAAMpE;IAEN,OAAOG;AACT,EAAC"}
@@ -6,6 +6,7 @@ type Args<T> = {
6
6
  collection: Collection;
7
7
  config: SanitizedConfig;
8
8
  data: T;
9
+ draft?: boolean;
9
10
  isDuplicating?: boolean;
10
11
  operation: 'create' | 'update';
11
12
  originalDoc?: T;
@@ -17,6 +18,6 @@ type Result<T> = Promise<{
17
18
  data: T;
18
19
  files: FileToSave[];
19
20
  }>;
20
- export declare const generateFileData: <T>({ collection: { config: collectionConfig }, data, isDuplicating, operation, originalDoc, overwriteExistingFiles, req, throwOnMissingFile, }: Args<T>) => Result<T>;
21
+ export declare const generateFileData: <T>({ collection: { config: collectionConfig }, data, draft, isDuplicating, operation, originalDoc, overwriteExistingFiles, req, throwOnMissingFile, }: Args<T>) => Result<T>;
21
22
  export {};
22
23
  //# sourceMappingURL=generateFileData.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateFileData.d.ts","sourceRoot":"","sources":["../../src/uploads/generateFileData.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACjE,OAAO,KAAK,EAAY,UAAU,EAAgC,MAAM,YAAY,CAAA;AAcpF,KAAK,IAAI,CAAC,CAAC,IAAI;IACb,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,eAAe,CAAA;IACvB,IAAI,EAAE,CAAC,CAAA;IACP,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC9B,WAAW,CAAC,EAAE,CAAC,CAAA;IACf,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,GAAG,EAAE,cAAc,CAAA;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,KAAK,MAAM,CAAC,CAAC,IAAI,OAAO,CAAC;IACvB,IAAI,EAAE,CAAC,CAAA;IACP,KAAK,EAAE,UAAU,EAAE,CAAA;CACpB,CAAC,CAAA;AA6BF,eAAO,MAAM,gBAAgB,GAAU,CAAC,EAAE,6IASvC,IAAI,CAAC,CAAC,CAAC,KAAG,MAAM,CAAC,CAAC,CAkWpB,CAAA"}
1
+ {"version":3,"file":"generateFileData.d.ts","sourceRoot":"","sources":["../../src/uploads/generateFileData.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACjE,OAAO,KAAK,EAAY,UAAU,EAAgC,MAAM,YAAY,CAAA;AAcpF,KAAK,IAAI,CAAC,CAAC,IAAI;IACb,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,eAAe,CAAA;IACvB,IAAI,EAAE,CAAC,CAAA;IACP,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC9B,WAAW,CAAC,EAAE,CAAC,CAAA;IACf,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,GAAG,EAAE,cAAc,CAAA;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,KAAK,MAAM,CAAC,CAAC,IAAI,OAAO,CAAC;IACvB,IAAI,EAAE,CAAC,CAAA;IACP,KAAK,EAAE,UAAU,EAAE,CAAA;CACpB,CAAC,CAAA;AA6BF,eAAO,MAAM,gBAAgB,GAAU,CAAC,EAAE,oJAUvC,IAAI,CAAC,CAAC,CAAC,KAAG,MAAM,CAAC,CAAC,CAmWpB,CAAA"}
@@ -31,7 +31,7 @@ const shouldReupload = (uploadEdits, fileData)=>{
31
31
  }
32
32
  return false;
33
33
  };
34
- export const generateFileData = async ({ collection: { config: collectionConfig }, data, isDuplicating, operation, originalDoc, overwriteExistingFiles, req, throwOnMissingFile })=>{
34
+ export const generateFileData = async ({ collection: { config: collectionConfig }, data, draft, isDuplicating, operation, originalDoc, overwriteExistingFiles, req, throwOnMissingFile })=>{
35
35
  if (!collectionConfig.upload) {
36
36
  return {
37
37
  data,
@@ -321,7 +321,10 @@ export const generateFileData = async ({ collection: { config: collectionConfig
321
321
  }
322
322
  newData = {
323
323
  ...newData,
324
- ...fileData
324
+ ...fileData,
325
+ ...draft ? {
326
+ _status: 'draft'
327
+ } : {}
325
328
  };
326
329
  return {
327
330
  data: newData,