@payloadcms/db-mongodb 3.0.0-canary.c13f9ba → 3.0.0-canary.ce278e4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. package/README.md +1 -1
  2. package/dist/connect.d.ts +1 -1
  3. package/dist/connect.d.ts.map +1 -1
  4. package/dist/connect.js.map +1 -1
  5. package/dist/count.d.ts +1 -1
  6. package/dist/count.d.ts.map +1 -1
  7. package/dist/count.js +1 -1
  8. package/dist/count.js.map +1 -1
  9. package/dist/create.d.ts +1 -1
  10. package/dist/create.d.ts.map +1 -1
  11. package/dist/create.js.map +1 -1
  12. package/dist/createGlobal.d.ts +1 -1
  13. package/dist/createGlobal.d.ts.map +1 -1
  14. package/dist/createGlobal.js.map +1 -1
  15. package/dist/createGlobalVersion.d.ts +1 -1
  16. package/dist/createGlobalVersion.d.ts.map +1 -1
  17. package/dist/createGlobalVersion.js.map +1 -1
  18. package/dist/createMigration.d.ts +1 -1
  19. package/dist/createMigration.d.ts.map +1 -1
  20. package/dist/createMigration.js +1 -1
  21. package/dist/createMigration.js.map +1 -1
  22. package/dist/createVersion.d.ts +1 -1
  23. package/dist/createVersion.d.ts.map +1 -1
  24. package/dist/createVersion.js.map +1 -1
  25. package/dist/deleteMany.d.ts +1 -1
  26. package/dist/deleteMany.d.ts.map +1 -1
  27. package/dist/deleteMany.js.map +1 -1
  28. package/dist/deleteOne.d.ts +1 -1
  29. package/dist/deleteOne.d.ts.map +1 -1
  30. package/dist/deleteOne.js.map +1 -1
  31. package/dist/deleteVersions.d.ts +1 -1
  32. package/dist/deleteVersions.d.ts.map +1 -1
  33. package/dist/deleteVersions.js.map +1 -1
  34. package/dist/destroy.d.ts +1 -1
  35. package/dist/destroy.d.ts.map +1 -1
  36. package/dist/destroy.js.map +1 -1
  37. package/dist/find.d.ts +1 -1
  38. package/dist/find.d.ts.map +1 -1
  39. package/dist/find.js +1 -1
  40. package/dist/find.js.map +1 -1
  41. package/dist/findGlobal.d.ts +1 -1
  42. package/dist/findGlobal.d.ts.map +1 -1
  43. package/dist/findGlobal.js +1 -1
  44. package/dist/findGlobal.js.map +1 -1
  45. package/dist/findGlobalVersions.d.ts +1 -1
  46. package/dist/findGlobalVersions.d.ts.map +1 -1
  47. package/dist/findGlobalVersions.js +1 -2
  48. package/dist/findGlobalVersions.js.map +1 -1
  49. package/dist/findOne.d.ts +1 -1
  50. package/dist/findOne.d.ts.map +1 -1
  51. package/dist/findOne.js.map +1 -1
  52. package/dist/findVersions.d.ts +1 -1
  53. package/dist/findVersions.d.ts.map +1 -1
  54. package/dist/findVersions.js +1 -1
  55. package/dist/findVersions.js.map +1 -1
  56. package/dist/index.d.ts +1 -1
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +1 -1
  59. package/dist/index.js.map +1 -1
  60. package/dist/init.d.ts +1 -1
  61. package/dist/init.d.ts.map +1 -1
  62. package/dist/init.js +1 -1
  63. package/dist/init.js.map +1 -1
  64. package/dist/migrateFresh.d.ts.map +1 -1
  65. package/dist/migrateFresh.js +1 -1
  66. package/dist/migrateFresh.js.map +1 -1
  67. package/dist/models/buildCollectionSchema.d.ts +1 -2
  68. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  69. package/dist/models/buildCollectionSchema.js.map +1 -1
  70. package/dist/models/buildGlobalModel.d.ts +1 -1
  71. package/dist/models/buildGlobalModel.d.ts.map +1 -1
  72. package/dist/models/buildGlobalModel.js.map +1 -1
  73. package/dist/models/buildSchema.d.ts +1 -2
  74. package/dist/models/buildSchema.d.ts.map +1 -1
  75. package/dist/models/buildSchema.js +1 -1
  76. package/dist/models/buildSchema.js.map +1 -1
  77. package/dist/queries/buildAndOrConditions.d.ts +1 -2
  78. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  79. package/dist/queries/buildAndOrConditions.js.map +1 -1
  80. package/dist/queries/buildQuery.d.ts +1 -2
  81. package/dist/queries/buildQuery.d.ts.map +1 -1
  82. package/dist/queries/buildQuery.js +1 -1
  83. package/dist/queries/buildQuery.js.map +1 -1
  84. package/dist/queries/buildSearchParams.d.ts +1 -2
  85. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  86. package/dist/queries/buildSearchParams.js +2 -2
  87. package/dist/queries/buildSearchParams.js.map +1 -1
  88. package/dist/queries/buildSortParam.d.ts +1 -2
  89. package/dist/queries/buildSortParam.d.ts.map +1 -1
  90. package/dist/queries/buildSortParam.js.map +1 -1
  91. package/dist/queries/getLocalizedSortProperty.d.ts +1 -2
  92. package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
  93. package/dist/queries/getLocalizedSortProperty.js +2 -2
  94. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  95. package/dist/queries/getLocalizedSortProperty.spec.js +1 -1
  96. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  97. package/dist/queries/parseParams.d.ts +1 -3
  98. package/dist/queries/parseParams.d.ts.map +1 -1
  99. package/dist/queries/parseParams.js +2 -2
  100. package/dist/queries/parseParams.js.map +1 -1
  101. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  102. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  103. package/dist/queries/sanitizeQueryValue.js +1 -1
  104. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  105. package/dist/queryDrafts.d.ts +1 -1
  106. package/dist/queryDrafts.d.ts.map +1 -1
  107. package/dist/queryDrafts.js +1 -1
  108. package/dist/queryDrafts.js.map +1 -1
  109. package/dist/transactions/beginTransaction.d.ts +1 -1
  110. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  111. package/dist/transactions/beginTransaction.js +1 -1
  112. package/dist/transactions/beginTransaction.js.map +1 -1
  113. package/dist/transactions/commitTransaction.d.ts +1 -1
  114. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  115. package/dist/transactions/commitTransaction.js.map +1 -1
  116. package/dist/transactions/rollbackTransaction.d.ts +1 -1
  117. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  118. package/dist/transactions/rollbackTransaction.js.map +1 -1
  119. package/dist/types.d.ts +1 -3
  120. package/dist/types.d.ts.map +1 -1
  121. package/dist/types.js.map +1 -1
  122. package/dist/updateGlobal.d.ts +1 -1
  123. package/dist/updateGlobal.d.ts.map +1 -1
  124. package/dist/updateGlobal.js.map +1 -1
  125. package/dist/updateGlobalVersion.d.ts +1 -2
  126. package/dist/updateGlobalVersion.d.ts.map +1 -1
  127. package/dist/updateGlobalVersion.js.map +1 -1
  128. package/dist/updateOne.d.ts +1 -1
  129. package/dist/updateOne.d.ts.map +1 -1
  130. package/dist/updateOne.js.map +1 -1
  131. package/dist/updateVersion.d.ts +1 -1
  132. package/dist/updateVersion.d.ts.map +1 -1
  133. package/dist/updateVersion.js.map +1 -1
  134. package/dist/utilities/getDBName.d.ts +1 -1
  135. package/dist/utilities/getDBName.d.ts.map +1 -1
  136. package/dist/utilities/getDBName.js.map +1 -1
  137. package/dist/utilities/handleError.js +1 -1
  138. package/dist/utilities/handleError.js.map +1 -1
  139. package/package.json +6 -7
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import mongoose from 'mongoose';
3
3
  import path from 'path';
4
- import { createDatabaseAdapter } from 'payload/database';
4
+ import { createDatabaseAdapter } from 'payload';
5
5
  import { connect } from './connect.js';
6
6
  import { count } from './count.js';
7
7
  import { create } from './create.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { TransactionOptions } from 'mongodb'\nimport type { MongoMemoryReplSet } from 'mongodb-memory-server'\nimport type { ClientSession, ConnectOptions, Connection } from 'mongoose'\nimport type { Payload } from 'payload'\nimport type { BaseDatabaseAdapter, DatabaseAdapterObj } from 'payload/database'\n\nimport fs from 'fs'\nimport mongoose from 'mongoose'\nimport path from 'path'\nimport { createDatabaseAdapter } from 'payload/database'\n\nimport type { CollectionModel, GlobalModel } from './types.js'\n\nimport { connect } from './connect.js'\nimport { count } from './count.js'\nimport { create } from './create.js'\nimport { createGlobal } from './createGlobal.js'\nimport { createGlobalVersion } from './createGlobalVersion.js'\nimport { createMigration } from './createMigration.js'\nimport { createVersion } from './createVersion.js'\nimport { deleteMany } from './deleteMany.js'\nimport { deleteOne } from './deleteOne.js'\nimport { deleteVersions } from './deleteVersions.js'\nimport { destroy } from './destroy.js'\nimport { find } from './find.js'\nimport { findGlobal } from './findGlobal.js'\nimport { findGlobalVersions } from './findGlobalVersions.js'\nimport { findOne } from './findOne.js'\nimport { findVersions } from './findVersions.js'\nimport { init } from './init.js'\nimport { migrateFresh } from './migrateFresh.js'\nimport { queryDrafts } from './queryDrafts.js'\nimport { beginTransaction } from './transactions/beginTransaction.js'\nimport { commitTransaction } from './transactions/commitTransaction.js'\nimport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nimport { updateGlobal } from './updateGlobal.js'\nimport { updateGlobalVersion } from './updateGlobalVersion.js'\nimport { updateOne } from './updateOne.js'\nimport { updateVersion } from './updateVersion.js'\n\nexport type { MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nexport interface Args {\n /** Set to false to disable auto-pluralization of collection names, Defaults to true */\n autoPluralization?: boolean\n /** Extra configuration options */\n connectOptions?: ConnectOptions & {\n /** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */\n useFacet?: boolean\n }\n /** Set to true to disable hinting to MongoDB to use 'id' as index. This is currently done when counting documents for pagination. Disabling this optimization might fix some problems with AWS DocumentDB. Defaults to false */\n disableIndexHints?: boolean\n migrationDir?: string\n /**\n * typed as any to avoid dependency\n */\n mongoMemoryServer?: MongoMemoryReplSet\n transactionOptions?: TransactionOptions | false\n /** The URL to connect to MongoDB or false to start payload and prevent connecting */\n url: false | string\n}\n\nexport type MongooseAdapter = BaseDatabaseAdapter &\n Args & {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n sessions: Record<number | string, ClientSession>\n versions: {\n [slug: string]: CollectionModel\n }\n }\n\ndeclare module 'payload' {\n export interface DatabaseAdapter\n extends Omit<BaseDatabaseAdapter, 'sessions'>,\n Omit<Args, 'migrationDir'> {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n sessions: Record<number | string, ClientSession>\n transactionOptions: TransactionOptions\n versions: {\n [slug: string]: CollectionModel\n }\n }\n}\n\nexport function mongooseAdapter({\n autoPluralization = true,\n connectOptions,\n disableIndexHints = false,\n migrationDir: migrationDirArg,\n mongoMemoryServer,\n transactionOptions = {},\n url,\n}: Args): DatabaseAdapterObj {\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(migrationDirArg)\n mongoose.set('strictQuery', false)\n\n return createDatabaseAdapter<MongooseAdapter>({\n name: 'mongoose',\n\n // Mongoose-specific\n autoPluralization,\n collections: {},\n connectOptions: connectOptions || {},\n connection: undefined,\n count,\n disableIndexHints,\n globals: undefined,\n mongoMemoryServer,\n sessions: {},\n transactionOptions: transactionOptions === false ? undefined : transactionOptions,\n url,\n versions: {},\n // DatabaseAdapter\n beginTransaction: transactionOptions ? beginTransaction : undefined,\n commitTransaction,\n connect,\n create,\n createGlobal,\n createGlobalVersion,\n createMigration,\n createVersion,\n defaultIDType: 'text',\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n init,\n migrateFresh,\n migrationDir,\n payload,\n queryDrafts,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n })\n }\n\n return {\n defaultIDType: 'text',\n init: adapter,\n }\n}\n\n/**\n * Attempt to find migrations directory.\n *\n * Checks for the following directories in order:\n * - `migrationDir` argument from Payload config\n * - `src/migrations`\n * - `dist/migrations`\n * - `migrations`\n *\n * Defaults to `src/migrations`\n *\n * @param migrationDir\n * @returns\n */\nfunction findMigrationDir(migrationDir?: string): string {\n const cwd = process.cwd()\n const srcDir = path.resolve(cwd, 'src/migrations')\n const distDir = path.resolve(cwd, 'dist/migrations')\n const relativeMigrations = path.resolve(cwd, 'migrations')\n\n // Use arg if provided\n if (migrationDir) return migrationDir\n\n // Check other common locations\n if (fs.existsSync(srcDir)) {\n return srcDir\n }\n\n if (fs.existsSync(distDir)) {\n return distDir\n }\n\n if (fs.existsSync(relativeMigrations)) {\n return relativeMigrations\n }\n\n return srcDir\n}\n"],"names":["fs","mongoose","path","createDatabaseAdapter","connect","count","create","createGlobal","createGlobalVersion","createMigration","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findOne","findVersions","init","migrateFresh","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateGlobal","updateGlobalVersion","updateOne","updateVersion","mongooseAdapter","autoPluralization","connectOptions","disableIndexHints","migrationDir","migrationDirArg","mongoMemoryServer","transactionOptions","url","adapter","payload","findMigrationDir","set","name","collections","connection","undefined","globals","sessions","versions","defaultIDType","cwd","process","srcDir","resolve","distDir","relativeMigrations","existsSync"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAMA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,cAAc,WAAU;AAC/B,OAAOC,UAAU,OAAM;AACvB,SAASC,qBAAqB,QAAQ,mBAAkB;AAIxD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,KAAK,QAAQ,aAAY;AAClC,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SA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Aa;YACAM;YACAlB;YACAG;YACAC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAO;QACLqB,eAAe;QACf9B,MAAMmB;IACR;AACF;AAEA;;;;;;;;;;;;;CAaC,GACD,SAASE,iBAAiBP,YAAqB;IAC7C,MAAMiB,MAAMC,QAAQD,GAAG;IACvB,MAAME,SAASnD,KAAKoD,OAAO,CAACH,KAAK;IACjC,MAAMI,UAAUrD,KAAKoD,OAAO,CAACH,KAAK;IAClC,MAAMK,qBAAqBtD,KAAKoD,OAAO,CAACH,KAAK;IAE7C,sBAAsB;IACtB,IAAIjB,cAAc,OAAOA;IAEzB,+BAA+B;IAC/B,IAAIlC,GAAGyD,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAIrD,GAAGyD,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAIvD,GAAGyD,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { TransactionOptions } from 'mongodb'\nimport type { MongoMemoryReplSet } from 'mongodb-memory-server'\nimport type { ClientSession, ConnectOptions, Connection } from 'mongoose'\nimport type { BaseDatabaseAdapter, DatabaseAdapterObj, Payload } from 'payload'\n\nimport fs from 'fs'\nimport mongoose from 'mongoose'\nimport path from 'path'\nimport { createDatabaseAdapter } from 'payload'\n\nimport type { CollectionModel, GlobalModel } from './types.js'\n\nimport { connect } from './connect.js'\nimport { count } from './count.js'\nimport { create } from './create.js'\nimport { createGlobal } from './createGlobal.js'\nimport { createGlobalVersion } from './createGlobalVersion.js'\nimport { createMigration } from './createMigration.js'\nimport { createVersion } from './createVersion.js'\nimport { deleteMany } from './deleteMany.js'\nimport { deleteOne } from './deleteOne.js'\nimport { deleteVersions } from './deleteVersions.js'\nimport { destroy } from './destroy.js'\nimport { find } from './find.js'\nimport { findGlobal } from './findGlobal.js'\nimport { findGlobalVersions } from './findGlobalVersions.js'\nimport { findOne } from './findOne.js'\nimport { findVersions } from './findVersions.js'\nimport { init } from './init.js'\nimport { migrateFresh } from './migrateFresh.js'\nimport { queryDrafts } from './queryDrafts.js'\nimport { beginTransaction } from './transactions/beginTransaction.js'\nimport { commitTransaction } from './transactions/commitTransaction.js'\nimport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nimport { updateGlobal } from './updateGlobal.js'\nimport { updateGlobalVersion } from './updateGlobalVersion.js'\nimport { updateOne } from './updateOne.js'\nimport { updateVersion } from './updateVersion.js'\n\nexport type { MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nexport interface Args {\n /** Set to false to disable auto-pluralization of collection names, Defaults to true */\n autoPluralization?: boolean\n /** Extra configuration options */\n connectOptions?: ConnectOptions & {\n /** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */\n useFacet?: boolean\n }\n /** Set to true to disable hinting to MongoDB to use 'id' as index. This is currently done when counting documents for pagination. Disabling this optimization might fix some problems with AWS DocumentDB. Defaults to false */\n disableIndexHints?: boolean\n migrationDir?: string\n /**\n * typed as any to avoid dependency\n */\n mongoMemoryServer?: MongoMemoryReplSet\n transactionOptions?: TransactionOptions | false\n /** The URL to connect to MongoDB or false to start payload and prevent connecting */\n url: false | string\n}\n\nexport type MongooseAdapter = BaseDatabaseAdapter &\n Args & {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n sessions: Record<number | string, ClientSession>\n versions: {\n [slug: string]: CollectionModel\n }\n }\n\ndeclare module 'payload' {\n export interface DatabaseAdapter\n extends Omit<BaseDatabaseAdapter, 'sessions'>,\n Omit<Args, 'migrationDir'> {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n sessions: Record<number | string, ClientSession>\n transactionOptions: TransactionOptions\n versions: {\n [slug: string]: CollectionModel\n }\n }\n}\n\nexport function mongooseAdapter({\n autoPluralization = true,\n connectOptions,\n disableIndexHints = false,\n migrationDir: migrationDirArg,\n mongoMemoryServer,\n transactionOptions = {},\n url,\n}: Args): DatabaseAdapterObj {\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(migrationDirArg)\n mongoose.set('strictQuery', false)\n\n return createDatabaseAdapter<MongooseAdapter>({\n name: 'mongoose',\n\n // Mongoose-specific\n autoPluralization,\n collections: {},\n connectOptions: connectOptions || {},\n connection: undefined,\n count,\n disableIndexHints,\n globals: undefined,\n mongoMemoryServer,\n sessions: {},\n transactionOptions: transactionOptions === false ? undefined : transactionOptions,\n url,\n versions: {},\n // DatabaseAdapter\n beginTransaction: transactionOptions ? beginTransaction : undefined,\n commitTransaction,\n connect,\n create,\n createGlobal,\n createGlobalVersion,\n createMigration,\n createVersion,\n defaultIDType: 'text',\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n init,\n migrateFresh,\n migrationDir,\n payload,\n queryDrafts,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n })\n }\n\n return {\n defaultIDType: 'text',\n init: adapter,\n }\n}\n\n/**\n * Attempt to find migrations directory.\n *\n * Checks for the following directories in order:\n * - `migrationDir` argument from Payload config\n * - `src/migrations`\n * - `dist/migrations`\n * - `migrations`\n *\n * Defaults to `src/migrations`\n *\n * @param migrationDir\n * @returns\n */\nfunction findMigrationDir(migrationDir?: string): string {\n const cwd = process.cwd()\n const srcDir = path.resolve(cwd, 'src/migrations')\n const distDir = path.resolve(cwd, 'dist/migrations')\n const relativeMigrations = path.resolve(cwd, 'migrations')\n\n // Use arg if provided\n if (migrationDir) return migrationDir\n\n // Check other common locations\n if (fs.existsSync(srcDir)) {\n return srcDir\n }\n\n if (fs.existsSync(distDir)) {\n return distDir\n }\n\n if (fs.existsSync(relativeMigrations)) {\n return relativeMigrations\n }\n\n return srcDir\n}\n"],"names":["fs","mongoose","path","createDatabaseAdapter","connect","count","create","createGlobal","createGlobalVersion","createMigration","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findOne","findVersions","init","migrateFresh","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateGlobal","updateGlobalVersion","updateOne","updateVersion","mongooseAdapter","autoPluralization","connectOptions","disableIndexHints","migrationDir","migrationDirArg","mongoMemoryServer","transactionOptions","url","adapter","payload","findMigrationDir","set","name","collections","connection","undefined","globals","sessions","versions","defaultIDType","cwd","process","srcDir","resolve","distDir","relativeMigrations","existsSync"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAKA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,cAAc,WAAU;AAC/B,OAAOC,UAAU,OAAM;AACvB,SAASC,qBAAqB,QAAQ,UAAS;AAI/C,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,KAAK,QAAQ,aAAY;AAClC,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAAS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AAKoD,OAAO,CAACH,KAAK;IAClC,MAAMK,qBAAqBtD,KAAKoD,OAAO,CAACH,KAAK;IAE7C,sBAAsB;IACtB,IAAIjB,cAAc,OAAOA;IAEzB,+BAA+B;IAC/B,IAAIlC,GAAGyD,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAIrD,GAAGyD,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAIvD,GAAGyD,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
package/dist/init.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { Init } from 'payload/database';
1
+ import type { Init } from 'payload';
2
2
  export declare const init: Init;
3
3
  //# sourceMappingURL=init.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAgB5C,eAAO,MAAM,IAAI,EAAE,IA0ElB,CAAA"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAA;AAe9D,eAAO,MAAM,IAAI,EAAE,IA0ElB,CAAA"}
package/dist/init.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable no-param-reassign */ import mongoose from 'mongoose';
2
2
  import paginate from 'mongoose-paginate-v2';
3
- import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload/versions';
3
+ import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
4
4
  import buildCollectionSchema from './models/buildCollectionSchema.js';
5
5
  import { buildGlobalModel } from './models/buildGlobalModel.js';
6
6
  import buildSchema from './models/buildSchema.js';
package/dist/init.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/init.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { PaginateOptions } from 'mongoose'\nimport type { Init } from 'payload/database'\nimport type { SanitizedCollectionConfig } from 'payload/types'\n\nimport mongoose from 'mongoose'\nimport paginate from 'mongoose-paginate-v2'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload/versions'\n\nimport type { MongooseAdapter } from './index.js'\nimport type { CollectionModel } from './types.js'\n\nimport buildCollectionSchema from './models/buildCollectionSchema.js'\nimport { buildGlobalModel } from './models/buildGlobalModel.js'\nimport buildSchema from './models/buildSchema.js'\nimport getBuildQueryPlugin from './queries/buildQuery.js'\nimport { getDBName } from './utilities/getDBName.js'\n\nexport const init: Init = function init(this: MongooseAdapter) {\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n const schema = buildCollectionSchema(collection, this.payload.config)\n\n if (collection.versions) {\n const versionModelName = getDBName({ config: collection, versions: true })\n\n const versionCollectionFields = buildVersionCollectionFields(collection)\n\n const versionSchema = buildSchema(this.payload.config, versionCollectionFields, {\n disableUnique: true,\n draftsEnabled: true,\n indexSortableFields: this.payload.config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: false,\n },\n })\n\n versionSchema.plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true }).plugin(\n getBuildQueryPlugin({\n collectionSlug: collection.slug,\n versionsFields: versionCollectionFields,\n }),\n )\n\n const model = mongoose.model(\n versionModelName,\n versionSchema,\n this.autoPluralization === true ? undefined : versionModelName,\n ) as CollectionModel\n // this.payload.versions[collection.slug] = model;\n this.versions[collection.slug] = model\n }\n\n const model = mongoose.model(\n getDBName({ config: collection }),\n schema,\n this.autoPluralization === true ? undefined : collection.slug,\n ) as CollectionModel\n this.collections[collection.slug] = model\n })\n\n const model = buildGlobalModel(this.payload.config)\n this.globals = model\n\n this.payload.config.globals.forEach((global) => {\n if (global.versions) {\n const versionModelName = getDBName({ config: global, versions: true })\n\n const versionGlobalFields = buildVersionGlobalFields(global)\n\n const versionSchema = buildSchema(this.payload.config, versionGlobalFields, {\n disableUnique: true,\n draftsEnabled: true,\n indexSortableFields: this.payload.config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: false,\n },\n })\n\n versionSchema\n .plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true })\n .plugin(getBuildQueryPlugin({ versionsFields: versionGlobalFields }))\n\n const versionsModel = mongoose.model(\n versionModelName,\n versionSchema,\n versionModelName,\n ) as CollectionModel\n this.versions[global.slug] = versionsModel\n }\n })\n}\n"],"names":["mongoose","paginate","buildVersionCollectionFields","buildVersionGlobalFields","buildCollectionSchema","buildGlobalModel","buildSchema","getBuildQueryPlugin","getDBName","init","payload","config","collections","forEach","collection","schema","versions","versionModelName","versionCollectionFields","versionSchema","disableUnique","draftsEnabled","indexSortableFields","options","minimize","timestamps","plugin","useEstimatedCount","collectionSlug","slug","versionsFields","model","autoPluralization","undefined","globals","global","versionGlobalFields","versionsModel"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAKpC,OAAOA,cAAc,WAAU;AAC/B,OAAOC,cAAc,uBAAsB;AAC3C,SAASC,4BAA4B,EAAEC,wBAAwB,QAAQ,mBAAkB;AAKzF,OAAOC,2BAA2B,oCAAmC;AACrE,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,OAAOC,iBAAiB,0BAAyB;AACjD,OAAOC,yBAAyB,0BAAyB;AACzD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,OAAa,SAASA;IACjC,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,WAAW,CAACC,OAAO,CAAC,CAACC;QACvC,MAAMC,SAASX,sBAAsBU,YAAY,IAAI,CAACJ,OAAO,CAACC,MAAM;QAEpE,IAAIG,WAAWE,QAAQ,EAAE;YACvB,MAAMC,mBAAmBT,UAAU;gBAAEG,QAAQG;gBAAYE,UAAU;YAAK;YAExE,MAAME,0BAA0BhB,6BAA6BY;YAE7D,MAAMK,g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AS;oBACPC,UAAU;oBACVC,YAAY;gBACd;YACF;YAEAN,cACGO,MAAM,CAAuBzB,UAAU;gBAAE0B,mBAAmB;YAAK,GACjED,MAAM,CAACnB,oBAAoB;gBAAEuB,gBAAgBM;YAAoB;YAEpE,MAAMC,gBAAgBrC,SAAS+B,KAAK,CAClCd,kBACAE,eACAF;YAEF,IAAI,CAACD,QAAQ,CAACmB,OAAON,IAAI,CAAC,GAAGQ;QAC/B;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/init.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { PaginateOptions } from 'mongoose'\nimport type { Init, SanitizedCollectionConfig } from 'payload'\n\nimport mongoose from 'mongoose'\nimport paginate from 'mongoose-paginate-v2'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\nimport type { CollectionModel } from './types.js'\n\nimport buildCollectionSchema from './models/buildCollectionSchema.js'\nimport { buildGlobalModel } from './models/buildGlobalModel.js'\nimport buildSchema from './models/buildSchema.js'\nimport getBuildQueryPlugin from './queries/buildQuery.js'\nimport { getDBName } from './utilities/getDBName.js'\n\nexport const init: Init = function init(this: MongooseAdapter) {\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n const schema = buildCollectionSchema(collection, this.payload.config)\n\n if (collection.versions) {\n const versionModelName = getDBName({ config: collection, versions: true })\n\n const versionCollectionFields = buildVersionCollectionFields(collection)\n\n const versionSchema = buildSchema(this.payload.config, versionCollectionFields, {\n disableUnique: true,\n draftsEnabled: true,\n indexSortableFields: this.payload.config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: false,\n },\n })\n\n versionSchema.plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true }).plugin(\n getBuildQueryPlugin({\n collectionSlug: collection.slug,\n versionsFields: versionCollectionFields,\n }),\n )\n\n const model = mongoose.model(\n versionModelName,\n versionSchema,\n this.autoPluralization === true ? undefined : versionModelName,\n ) as CollectionModel\n // this.payload.versions[collection.slug] = model;\n this.versions[collection.slug] = model\n }\n\n const model = mongoose.model(\n getDBName({ config: collection }),\n schema,\n this.autoPluralization === true ? undefined : collection.slug,\n ) as CollectionModel\n this.collections[collection.slug] = model\n })\n\n const model = buildGlobalModel(this.payload.config)\n this.globals = model\n\n this.payload.config.globals.forEach((global) => {\n if (global.versions) {\n const versionModelName = getDBName({ config: global, versions: true })\n\n const versionGlobalFields = buildVersionGlobalFields(global)\n\n const versionSchema = buildSchema(this.payload.config, versionGlobalFields, {\n disableUnique: true,\n draftsEnabled: true,\n indexSortableFields: this.payload.config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: false,\n },\n })\n\n versionSchema\n .plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true })\n .plugin(getBuildQueryPlugin({ versionsFields: versionGlobalFields }))\n\n const versionsModel = mongoose.model(\n versionModelName,\n versionSchema,\n versionModelName,\n ) as CollectionModel\n this.versions[global.slug] = versionsModel\n }\n })\n}\n"],"names":["mongoose","paginate","buildVersionCollectionFields","buildVersionGlobalFields","buildCollectionSchema","buildGlobalModel","buildSchema","getBuildQueryPlugin","getDBName","init","payload","config","collections","forEach","collection","schema","versions","versionModelName","versionCollectionFields","versionSchema","disableUnique","draftsEnabled","indexSortableFields","options","minimize","timestamps","plugin","useEstimatedCount","collectionSlug","slug","versionsFields","model","autoPluralization","undefined","globals","global","versionGlobalFields","versionsModel"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAIpC,OAAOA,cAAc,WAAU;AAC/B,OAAOC,cAAc,uBAAsB;AAC3C,SAASC,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAKhF,OAAOC,2BAA2B,oCAAmC;AACrE,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,OAAOC,iBAAiB,0BAAyB;AACjD,OAAOC,yBAAyB,0BAAyB;AACzD,S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AACrB,OAAO,CAAC,CAACsB;QACnC,IAAIA,OAAOnB,QAAQ,EAAE;YACnB,MAAMC,mBAAmBT,UAAU;gBAAEG,QAAQwB;gBAAQnB,UAAU;YAAK;YAEpE,MAAMoB,sBAAsBjC,yBAAyBgC;YAErD,MAAMhB,gBAAgBb,YAAY,IAAI,CAACI,OAAO,CAACC,MAAM,EAAEyB,qBAAqB;gBAC1EhB,eAAe;gBACfC,eAAe;gBACfC,qBAAqB,IAAI,CAACZ,OAAO,CAACC,MAAM,CAACW,mBAAmB;gBAC5DC,SAAS;oBACPC,UAAU;oBACVC,YAAY;gBACd;YACF;YAEAN,cACGO,MAAM,CAAuBzB,UAAU;gBAAE0B,mBAAmB;YAAK,GACjED,MAAM,CAACnB,oBAAoB;gBAAEuB,gBAAgBM;YAAoB;YAEpE,MAAMC,gBAAgBrC,SAAS+B,KAAK,CAClCd,kBACAE,eACAF;YAEF,IAAI,CAACD,QAAQ,CAACmB,OAAON,IAAI,CAAC,GAAGQ;QAC/B;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"migrateFresh.d.ts","sourceRoot":"","sources":["../src/migrateFresh.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;GAEG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,eAAe,EACrB,EAAE,kBAA0B,EAAE,EAAE;IAAE,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAAE,GAC/D,OAAO,CAAC,IAAI,CAAC,CAgEf"}
1
+ {"version":3,"file":"migrateFresh.d.ts","sourceRoot":"","sources":["../src/migrateFresh.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;GAEG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,eAAe,EACrB,EAAE,kBAA0B,EAAE,EAAE;IAAE,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAAE,GAC/D,OAAO,CAAC,IAAI,CAAC,CAgEf"}
@@ -1,4 +1,4 @@
1
- import { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload/database';
1
+ import { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload';
2
2
  import prompts from 'prompts';
3
3
  /**
4
4
  * Drop the current database and run all migrate up functions
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import type { PayloadRequestWithData } from 'payload/types'\n\nimport {\n commitTransaction,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload/database'\nimport prompts from 'prompts'\n\nimport type { MongooseAdapter } from './index.js'\n\n/**\n * Drop the current database and run all migrate up functions\n */\nexport async function migrateFresh(\n this: MongooseAdapter,\n { forceAcceptWarning = false }: { forceAcceptWarning?: boolean },\n): Promise<void> {\n const { payload } = this\n\n if (!forceAcceptWarning) {\n const { confirm: acceptWarning } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: `WARNING: This will drop your database and run all migrations. Are you sure you want to proceed?`,\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!acceptWarning) {\n process.exit(0)\n }\n }\n\n payload.logger.info({\n msg: `Dropping database.`,\n })\n\n await this.connection.dropDatabase()\n\n const migrationFiles = await readMigrationFiles({ payload })\n payload.logger.debug({\n msg: `Found ${migrationFiles.length} migration files.`,\n })\n\n const req = { payload } as PayloadRequestWithData\n\n // Run all migrate up\n for (const migration of migrationFiles) {\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n try {\n const start = Date.now()\n await initTransaction(req)\n await migration.up({ payload, req })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n batch: 1,\n },\n req,\n })\n\n await commitTransaction(req)\n\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({\n err,\n msg: `Error running migration ${migration.name}. Rolling back.`,\n })\n throw err\n }\n }\n}\n"],"names":["commitTransaction","initTransaction","killTransaction","readMigrationFiles","prompts","migrateFresh","forceAcceptWarning","payload","confirm","acceptWarning","name","type","initial","message","onCancel","process","exit","logger","info","msg","connection","dropDatabase","migrationFiles","debug","length","req","migration","start","Date","now","up","create","collection","data","batch","err","error"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SACEA,iBAAiB,EACjBC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,mBAAkB;AACzB,OAAOC,aAAa,UAAS;AAI7B;;CAEC,GACD,OAAO,eAAeC,aAEpB,EAAEC,qBAAqB,KAAK,EAAoC;IAEhE,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IAExB,IAAI,CAACD,oBAAoB;QACvB,MAAM,EAAEE,SAASC,aAAa,EAAE,GAAG,MAAML,QACvC;YACEM,MAAM;YACNC,MAAM;YACNC,SAAS;YACTC,SAAS,CAAC,+FAA+F,CAAC;QAC5G,GACA;YACEC,UAAU;gBACRC,QAAQC,IAAI,CAAC;YACf;QACF;QAGF,IAAI,CAACP,eAAe;YAClBM,QAAQC,IAAI,CAAC;QACf;IACF;IAEAT,QAAQU,MAAM,CAACC,IAAI,CAAC;QAClBC,KAAK,CAAC,kBAAkB,CAAC;IAC3B;IAEA,MAAM,IAAI,CAACC,UAAU,CAACC,YAAY;IAElC,MAAMC,iBAAiB,MAAMnB,mBAAmB;QAAEI;IAAQ;IAC1DA,QAAQU,MAAM,CAACM,KAAK,CAAC;QACnBJ,KAAK,CAAC,MAAM,EAAEG,eAAeE,MAAM,CAAC,iBAAiB,CAAC;IACxD;IAEA,MAAMC,MAAM;QAAElB;IAAQ;IAEtB,qBAAqB;IACrB,KAAK,MAAMmB,aAAaJ,eAAgB;QACtCf,QAAQU,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK,CAAC,WAAW,EAAEO,UAAUhB,IAAI,CAAC,CAAC;QAAC;QAC1D,IAAI;YACF,MAAMiB,QAAQC,KAAKC,GAAG;YACtB,MAAM5B,gBAAgBwB;YACtB,MAAMC,UAAUI,EAAE,CAAC;gBAAEvB;gBAASkB;YAAI;YAClC,MAAMlB,QAAQwB,MAAM,CAAC;gBACnBC,YAAY;gBACZC,MAAM;oBACJvB,MAAMgB,UAAUhB,IAAI;oBACpBwB,OAAO;gBACT;gBACAT;YACF;YAEA,MAAMzB,kBAAkByB;YAExBlB,QAAQU,MAAM,CAACC,IAAI,CAAC;gBAAEC,KAAK,CAAC,WAAW,EAAEO,UAAUhB,IAAI,CAAC,EAAE,EAAEkB,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YAAC;QACtF,EAAE,OAAOQ,KAAc;YACrB,MAAMjC,gBAAgBuB;YACtBlB,QAAQU,MAAM,CAACmB,KAAK,CAAC;gBACnBD;gBACAhB,KAAK,CAAC,wBAAwB,EAAEO,UAAUhB,IAAI,CAAC,eAAe,CAAC;YACjE;YACA,MAAMyB;QACR;IACF;AACF"}
1
+ {"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import type { PayloadRequestWithData } from 'payload'\n\nimport { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload'\nimport prompts from 'prompts'\n\nimport type { MongooseAdapter } from './index.js'\n\n/**\n * Drop the current database and run all migrate up functions\n */\nexport async function migrateFresh(\n this: MongooseAdapter,\n { forceAcceptWarning = false }: { forceAcceptWarning?: boolean },\n): Promise<void> {\n const { payload } = this\n\n if (!forceAcceptWarning) {\n const { confirm: acceptWarning } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: `WARNING: This will drop your database and run all migrations. Are you sure you want to proceed?`,\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!acceptWarning) {\n process.exit(0)\n }\n }\n\n payload.logger.info({\n msg: `Dropping database.`,\n })\n\n await this.connection.dropDatabase()\n\n const migrationFiles = await readMigrationFiles({ payload })\n payload.logger.debug({\n msg: `Found ${migrationFiles.length} migration files.`,\n })\n\n const req = { payload } as PayloadRequestWithData\n\n // Run all migrate up\n for (const migration of migrationFiles) {\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n try {\n const start = Date.now()\n await initTransaction(req)\n await migration.up({ payload, req })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n batch: 1,\n },\n req,\n })\n\n await commitTransaction(req)\n\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({\n err,\n msg: `Error running migration ${migration.name}. Rolling back.`,\n })\n throw err\n }\n }\n}\n"],"names":["commitTransaction","initTransaction","killTransaction","readMigrationFiles","prompts","migrateFresh","forceAcceptWarning","payload","confirm","acceptWarning","name","type","initial","message","onCancel","process","exit","logger","info","msg","connection","dropDatabase","migrationFiles","debug","length","req","migration","start","Date","now","up","create","collection","data","batch","err","error"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,iBAAiB,EAAEC,eAAe,EAAEC,eAAe,EAAEC,kBAAkB,QAAQ,UAAS;AACjG,OAAOC,aAAa,UAAS;AAI7B;;CAEC,GACD,OAAO,eAAeC,aAEpB,EAAEC,qBAAqB,KAAK,EAAoC;IAEhE,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IAExB,IAAI,CAACD,oBAAoB;QACvB,MAAM,EAAEE,SAASC,aAAa,EAAE,GAAG,MAAML,QACvC;YACEM,MAAM;YACNC,MAAM;YACNC,SAAS;YACTC,SAAS,CAAC,+FAA+F,CAAC;QAC5G,GACA;YACEC,UAAU;gBACRC,QAAQC,IAAI,CAAC;YACf;QACF;QAGF,IAAI,CAACP,eAAe;YAClBM,QAAQC,IAAI,CAAC;QACf;IACF;IAEAT,QAAQU,MAAM,CAACC,IAAI,CAAC;QAClBC,KAAK,CAAC,kBAAkB,CAAC;IAC3B;IAEA,MAAM,IAAI,CAACC,UAAU,CAACC,YAAY;IAElC,MAAMC,iBAAiB,MAAMnB,mBAAmB;QAAEI;IAAQ;IAC1DA,QAAQU,MAAM,CAACM,KAAK,CAAC;QACnBJ,KAAK,CAAC,MAAM,EAAEG,eAAeE,MAAM,CAAC,iBAAiB,CAAC;IACxD;IAEA,MAAMC,MAAM;QAAElB;IAAQ;IAEtB,qBAAqB;IACrB,KAAK,MAAMmB,aAAaJ,eAAgB;QACtCf,QAAQU,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK,CAAC,WAAW,EAAEO,UAAUhB,IAAI,CAAC,CAAC;QAAC;QAC1D,IAAI;YACF,MAAMiB,QAAQC,KAAKC,GAAG;YACtB,MAAM5B,gBAAgBwB;YACtB,MAAMC,UAAUI,EAAE,CAAC;gBAAEvB;gBAASkB;YAAI;YAClC,MAAMlB,QAAQwB,MAAM,CAAC;gBACnBC,YAAY;gBACZC,MAAM;oBACJvB,MAAMgB,UAAUhB,IAAI;oBACpBwB,OAAO;gBACT;gBACAT;YACF;YAEA,MAAMzB,kBAAkByB;YAExBlB,QAAQU,MAAM,CAACC,IAAI,CAAC;gBAAEC,KAAK,CAAC,WAAW,EAAEO,UAAUhB,IAAI,CAAC,EAAE,EAAEkB,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YAAC;QACtF,EAAE,OAAOQ,KAAc;YACrB,MAAMjC,gBAAgBuB;YACtBlB,QAAQU,MAAM,CAACmB,KAAK,CAAC;gBACnBD;gBACAhB,KAAK,CAAC,wBAAwB,EAAEO,UAAUhB,IAAI,CAAC,eAAe,CAAC;YACjE;YACA,MAAMyB;QACR;IACF;AACF"}
@@ -24,8 +24,7 @@
24
24
  /// <reference types="mongoose/types/inferschematype.js" />
25
25
  /// <reference types="mongoose-paginate-v2" />
26
26
  import type { Schema } from 'mongoose';
27
- import type { SanitizedConfig } from 'payload/config';
28
- import type { SanitizedCollectionConfig } from 'payload/types';
27
+ import type { SanitizedCollectionConfig, SanitizedConfig } from 'payload';
29
28
  declare const buildCollectionSchema: (collection: SanitizedCollectionConfig, config: SanitizedConfig, schemaOptions?: {}) => Schema;
30
29
  export default buildCollectionSchema;
31
30
  //# sourceMappingURL=buildCollectionSchema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildCollectionSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildCollectionSchema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAA;AAO9D,QAAA,MAAM,qBAAqB,eACb,yBAAyB,UAC7B,eAAe,yBAEtB,MAqBF,CAAA;AAED,eAAe,qBAAqB,CAAA"}
1
+ {"version":3,"file":"buildCollectionSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildCollectionSchema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,KAAK,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAOzE,QAAA,MAAM,qBAAqB,eACb,yBAAyB,UAC7B,eAAe,yBAEtB,MAqBF,CAAA;AAED,eAAe,qBAAqB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/models/buildCollectionSchema.ts"],"sourcesContent":["import type { PaginateOptions, Schema } from 'mongoose'\nimport type { SanitizedConfig } from 'payload/config'\nimport type { SanitizedCollectionConfig } from 'payload/types'\n\nimport paginate from 'mongoose-paginate-v2'\n\nimport getBuildQueryPlugin from '../queries/buildQuery.js'\nimport buildSchema from './buildSchema.js'\n\nconst buildCollectionSchema = (\n collection: SanitizedCollectionConfig,\n config: SanitizedConfig,\n schemaOptions = {},\n): Schema => {\n const schema = buildSchema(config, collection.fields, {\n draftsEnabled: Boolean(typeof collection?.versions === 'object' && collection.versions.drafts),\n indexSortableFields: config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: collection.timestamps !== false,\n ...schemaOptions,\n },\n })\n\n if (config.indexSortableFields && collection.timestamps !== false) {\n schema.index({ updatedAt: 1 })\n schema.index({ createdAt: 1 })\n }\n\n schema\n .plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true })\n .plugin(getBuildQueryPlugin({ collectionSlug: collection.slug }))\n\n return schema\n}\n\nexport default buildCollectionSchema\n"],"names":["paginate","getBuildQueryPlugin","buildSchema","buildCollectionSchema","collection","config","schemaOptions","schema","fields","draftsEnabled","Boolean","versions","drafts","indexSortableFields","options","minimize","timestamps","index","updatedAt","createdAt","plugin","useEstimatedCount","collectionSlug","slug"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,OAAOA,cAAc,uBAAsB;AAE3C,OAAOC,yBAAyB,2BAA0B;AAC1D,OAAOC,iBAAiB,mBAAkB;AAE1C,MAAMC,wBAAwB,CAC5BC,YACAC,QACAC,gBAAgB,CAAC,CAAC;IAElB,MAAMC,SAASL,YAAYG,QAAQD,WAAWI,MAAM,EAAE;QACpDC,eAAeC,QAAQ,OAAON,YAAYO,aAAa,YAAYP,WAAWO,QAAQ,CAACC,MAAM;QAC7FC,qBAAqBR,OAAOQ,mBAAmB;QAC/CC,SAAS;YACPC,UAAU;YACVC,YAAYZ,WAAWY,UAAU,KAAK;YACtC,GAAGV,aAAa;QAClB;IACF;IAEA,IAAID,OAAOQ,mBAAmB,IAAIT,WAAWY,UAAU,KAAK,OAAO;QACjET,OAAOU,KAAK,CAAC;YAAEC,WAAW;QAAE;QAC5BX,OAAOU,KAAK,CAAC;YAAEE,WAAW;QAAE;IAC9B;IAEAZ,OACGa,MAAM,CAAuBpB,UAAU;QAAEqB,mBAAmB;IAAK,GACjED,MAAM,CAACnB,oBAAoB;QAAEqB,gBAAgBlB,WAAWmB,IAAI;IAAC;IAEhE,OAAOhB;AACT;AAEA,eAAeJ,sBAAqB"}
1
+ {"version":3,"sources":["../../src/models/buildCollectionSchema.ts"],"sourcesContent":["import type { PaginateOptions, Schema } from 'mongoose'\nimport type { SanitizedCollectionConfig, SanitizedConfig } from 'payload'\n\nimport paginate from 'mongoose-paginate-v2'\n\nimport getBuildQueryPlugin from '../queries/buildQuery.js'\nimport buildSchema from './buildSchema.js'\n\nconst buildCollectionSchema = (\n collection: SanitizedCollectionConfig,\n config: SanitizedConfig,\n schemaOptions = {},\n): Schema => {\n const schema = buildSchema(config, collection.fields, {\n draftsEnabled: Boolean(typeof collection?.versions === 'object' && collection.versions.drafts),\n indexSortableFields: config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: collection.timestamps !== false,\n ...schemaOptions,\n },\n })\n\n if (config.indexSortableFields && collection.timestamps !== false) {\n schema.index({ updatedAt: 1 })\n schema.index({ createdAt: 1 })\n }\n\n schema\n .plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true })\n .plugin(getBuildQueryPlugin({ collectionSlug: collection.slug }))\n\n return schema\n}\n\nexport default buildCollectionSchema\n"],"names":["paginate","getBuildQueryPlugin","buildSchema","buildCollectionSchema","collection","config","schemaOptions","schema","fields","draftsEnabled","Boolean","versions","drafts","indexSortableFields","options","minimize","timestamps","index","updatedAt","createdAt","plugin","useEstimatedCount","collectionSlug","slug"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,OAAOA,cAAc,uBAAsB;AAE3C,OAAOC,yBAAyB,2BAA0B;AAC1D,OAAOC,iBAAiB,mBAAkB;AAE1C,MAAMC,wBAAwB,CAC5BC,YACAC,QACAC,gBAAgB,CAAC,CAAC;IAElB,MAAMC,SAASL,YAAYG,QAAQD,WAAWI,MAAM,EAAE;QACpDC,eAAeC,QAAQ,OAAON,YAAYO,aAAa,YAAYP,WAAWO,QAAQ,CAACC,MAAM;QAC7FC,qBAAqBR,OAAOQ,mBAAmB;QAC/CC,SAAS;YACPC,UAAU;YACVC,YAAYZ,WAAWY,UAAU,KAAK;YACtC,GAAGV,aAAa;QAClB;IACF;IAEA,IAAID,OAAOQ,mBAAmB,IAAIT,WAAWY,UAAU,KAAK,OAAO;QACjET,OAAOU,KAAK,CAAC;YAAEC,WAAW;QAAE;QAC5BX,OAAOU,KAAK,CAAC;YAAEE,WAAW;QAAE;IAC9B;IAEAZ,OACGa,MAAM,CAAuBpB,UAAU;QAAEqB,mBAAmB;IAAK,GACjED,MAAM,CAACnB,oBAAoB;QAAEqB,gBAAgBlB,WAAWmB,IAAI;IAAC;IAEhE,OAAOhB;AACT;AAEA,eAAeJ,sBAAqB"}
@@ -1,4 +1,4 @@
1
- import type { SanitizedConfig } from 'payload/config';
1
+ import type { SanitizedConfig } from 'payload';
2
2
  import type { GlobalModel } from '../types.js';
3
3
  export declare const buildGlobalModel: (config: SanitizedConfig) => GlobalModel | null;
4
4
  //# sourceMappingURL=buildGlobalModel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildGlobalModel.d.ts","sourceRoot":"","sources":["../../src/models/buildGlobalModel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAIrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAK9C,eAAO,MAAM,gBAAgB,WAAY,eAAe,KAAG,WAAW,GAAG,IAwBxE,CAAA"}
1
+ {"version":3,"file":"buildGlobalModel.d.ts","sourceRoot":"","sources":["../../src/models/buildGlobalModel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAI9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAK9C,eAAO,MAAM,gBAAgB,WAAY,eAAe,KAAG,WAAW,GAAG,IAwBxE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/models/buildGlobalModel.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload/config'\n\nimport mongoose from 'mongoose'\n\nimport type { GlobalModel } from '../types.js'\n\nimport getBuildQueryPlugin from '../queries/buildQuery.js'\nimport buildSchema from './buildSchema.js'\n\nexport const buildGlobalModel = (config: SanitizedConfig): GlobalModel | null => {\n if (config.globals && config.globals.length > 0) {\n const globalsSchema = new mongoose.Schema(\n {},\n { discriminatorKey: 'globalType', minimize: false, timestamps: true },\n )\n\n globalsSchema.plugin(getBuildQueryPlugin())\n\n const Globals = mongoose.model('globals', globalsSchema, 'globals') as unknown as GlobalModel\n\n Object.values(config.globals).forEach((globalConfig) => {\n const globalSchema = buildSchema(config, globalConfig.fields, {\n options: {\n minimize: false,\n },\n })\n Globals.discriminator(globalConfig.slug, globalSchema)\n })\n\n return Globals\n }\n\n return null\n}\n"],"names":["mongoose","getBuildQueryPlugin","buildSchema","buildGlobalModel","config","globals","length","globalsSchema","Schema","discriminatorKey","minimize","timestamps","plugin","Globals","model","Object","values","forEach","globalConfig","globalSchema","fields","options","discriminator","slug"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,cAAc,WAAU;AAI/B,OAAOC,yBAAyB,2BAA0B;AAC1D,OAAOC,iBAAiB,mBAAkB;AAE1C,OAAO,MAAMC,mBAAmB,CAACC;IAC/B,IAAIA,OAAOC,OAAO,IAAID,OAAOC,OAAO,CAACC,MAAM,GAAG,GAAG;QAC/C,MAAMC,gBAAgB,IAAIP,SAASQ,MAAM,CACvC,CAAC,GACD;YAAEC,kBAAkB;YAAcC,UAAU;YAAOC,YAAY;QAAK;QAGtEJ,cAAcK,MAAM,CAACX;QAErB,MAAMY,UAAUb,SAASc,KAAK,CAAC,WAAWP,eAAe;QAEzDQ,OAAOC,MAAM,CAACZ,OAAOC,OAAO,EAAEY,OAAO,CAAC,CAACC;YACrC,MAAMC,eAAejB,YAAYE,QAAQc,aAAaE,MAAM,EAAE;gBAC5DC,SAAS;oBACPX,UAAU;gBACZ;YACF;YACAG,QAAQS,aAAa,CAACJ,aAAaK,IAAI,EAAEJ;QAC3C;QAEA,OAAON;IACT;IAEA,OAAO;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/models/buildGlobalModel.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload'\n\nimport mongoose from 'mongoose'\n\nimport type { GlobalModel } from '../types.js'\n\nimport getBuildQueryPlugin from '../queries/buildQuery.js'\nimport buildSchema from './buildSchema.js'\n\nexport const buildGlobalModel = (config: SanitizedConfig): GlobalModel | null => {\n if (config.globals && config.globals.length > 0) {\n const globalsSchema = new mongoose.Schema(\n {},\n { discriminatorKey: 'globalType', minimize: false, timestamps: true },\n )\n\n globalsSchema.plugin(getBuildQueryPlugin())\n\n const Globals = mongoose.model('globals', globalsSchema, 'globals') as unknown as GlobalModel\n\n Object.values(config.globals).forEach((globalConfig) => {\n const globalSchema = buildSchema(config, globalConfig.fields, {\n options: {\n minimize: false,\n },\n })\n Globals.discriminator(globalConfig.slug, globalSchema)\n })\n\n return Globals\n }\n\n return null\n}\n"],"names":["mongoose","getBuildQueryPlugin","buildSchema","buildGlobalModel","config","globals","length","globalsSchema","Schema","discriminatorKey","minimize","timestamps","plugin","Globals","model","Object","values","forEach","globalConfig","globalSchema","fields","options","discriminator","slug"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,cAAc,WAAU;AAI/B,OAAOC,yBAAyB,2BAA0B;AAC1D,OAAOC,iBAAiB,mBAAkB;AAE1C,OAAO,MAAMC,mBAAmB,CAACC;IAC/B,IAAIA,OAAOC,OAAO,IAAID,OAAOC,OAAO,CAACC,MAAM,GAAG,GAAG;QAC/C,MAAMC,gBAAgB,IAAIP,SAASQ,MAAM,CACvC,CAAC,GACD;YAAEC,kBAAkB;YAAcC,UAAU;YAAOC,YAAY;QAAK;QAGtEJ,cAAcK,MAAM,CAACX;QAErB,MAAMY,UAAUb,SAASc,KAAK,CAAC,WAAWP,eAAe;QAEzDQ,OAAOC,MAAM,CAACZ,OAAOC,OAAO,EAAEY,OAAO,CAAC,CAACC;YACrC,MAAMC,eAAejB,YAAYE,QAAQc,aAAaE,MAAM,EAAE;gBAC5DC,SAAS;oBACPX,UAAU;gBACZ;YACF;YACAG,QAAQS,aAAa,CAACJ,aAAaK,IAAI,EAAEJ;QAC3C;QAEA,OAAON;IACT;IAEA,OAAO;AACT,EAAC"}
@@ -24,8 +24,7 @@
24
24
  /// <reference types="mongoose/types/inferschematype.js" />
25
25
  /// <reference types="mongoose-paginate-v2" />
26
26
  import type { Schema, SchemaOptions } from 'mongoose';
27
- import type { SanitizedConfig } from 'payload/config';
28
- import type { Field } from 'payload/types';
27
+ import type { Field, SanitizedConfig } from 'payload';
29
28
  export type BuildSchemaOptions = {
30
29
  allowIDField?: boolean;
31
30
  disableUnique?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"buildSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildSchema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAGA,OAAO,KAAK,EAAgB,MAAM,EAAE,aAAa,EAAqB,MAAM,UAAU,CAAA;AACtF,OAAO,KAAK,EAAE,eAAe,EAA+B,MAAM,gBAAgB,CAAA;AAClF,OAAO,KAAK,EASV,KAAK,EAiBN,MAAM,eAAe,CAAA;AAUtB,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,OAAO,CAAC,EAAE,aAAa,CAAA;CACxB,CAAA;AA0DD,QAAA,MAAM,WAAW,WACP,eAAe,gBACT,KAAK,EAAE,uBACD,kBAAkB,KACrC,MA+BF,CAAA;AA+cD,eAAe,WAAW,CAAA"}
1
+ {"version":3,"file":"buildSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildSchema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAGA,OAAO,KAAK,EAAgB,MAAM,EAAE,aAAa,EAAqB,MAAM,UAAU,CAAA;AACtF,OAAO,KAAK,EASV,KAAK,EAWL,eAAe,EAQhB,MAAM,SAAS,CAAA;AAUhB,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,OAAO,CAAC,EAAE,aAAa,CAAA;CACxB,CAAA;AA0DD,QAAA,MAAM,WAAW,WACP,eAAe,gBACT,KAAK,EAAE,uBACD,kBAAkB,KACrC,MA+BF,CAAA;AA+cD,eAAe,WAAW,CAAA"}
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/ban-ts-comment */ /* eslint-disable class-methods-use-this */ /* eslint-disable @typescript-eslint/no-use-before-define */ import mongoose from 'mongoose';
2
- import { fieldAffectsData, fieldIsLocalized, fieldIsPresentationalOnly, tabHasName } from 'payload/types';
2
+ import { fieldAffectsData, fieldIsLocalized, fieldIsPresentationalOnly, tabHasName } from 'payload/shared';
3
3
  const formatBaseSchema = (field, buildSchemaOptions)=>{
4
4
  const { disableUnique, draftsEnabled, indexSortableFields } = buildSchemaOptions;
5
5
  const schema = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/models/buildSchema.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\n/* eslint-disable class-methods-use-this */\n/* eslint-disable @typescript-eslint/no-use-before-define */\nimport type { IndexOptions, Schema, SchemaOptions, SchemaTypeOptions } from 'mongoose'\nimport type { SanitizedConfig, SanitizedLocalizationConfig } from 'payload/config'\nimport type {\n ArrayField,\n Block,\n BlockField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n FieldAffectingData,\n GroupField,\n JSONField,\n NonPresentationalField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SelectField,\n Tab,\n TabsField,\n TextField,\n TextareaField,\n UploadField,\n} from 'payload/types'\n\nimport mongoose from 'mongoose'\nimport {\n fieldAffectsData,\n fieldIsLocalized,\n fieldIsPresentationalOnly,\n tabHasName,\n} from 'payload/types'\n\nexport type BuildSchemaOptions = {\n allowIDField?: boolean\n disableUnique?: boolean\n draftsEnabled?: boolean\n indexSortableFields?: boolean\n options?: SchemaOptions\n}\n\ntype FieldSchemaGenerator = (\n field: Field,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n) => void\n\nconst formatBaseSchema = (field: FieldAffectingData, buildSchemaOptions: BuildSchemaOptions) => {\n const { disableUnique, draftsEnabled, indexSortableFields } = buildSchemaOptions\n const schema: SchemaTypeOptions<unknown> = {\n index: field.index || (!disableUnique && field.unique) || indexSortableFields || false,\n required: false,\n unique: (!disableUnique && field.unique) || false,\n }\n\n if (\n schema.unique &&\n (field.localized ||\n draftsEnabled ||\n (fieldAffectsData(field) &&\n field.type !== 'group' &&\n field.type !== 'tab' &&\n field.required !== true))\n ) {\n schema.sparse = true\n }\n\n if (field.hidden) {\n schema.hidden = true\n }\n\n return schema\n}\n\nconst localizeSchema = (\n entity: NonPresentationalField | Tab,\n schema,\n localization: SanitizedLocalizationConfig | false,\n) => {\n if (fieldIsLocalized(entity) && localization && Array.isArray(localization.locales)) {\n return {\n type: localization.localeCodes.reduce(\n (localeSchema, locale) => ({\n ...localeSchema,\n [locale]: schema,\n }),\n {\n _id: false,\n },\n ),\n localized: true,\n }\n }\n return schema\n}\n\nconst buildSchema = (\n config: SanitizedConfig,\n configFields: Field[],\n buildSchemaOptions: BuildSchemaOptions = {},\n): Schema => {\n const { allowIDField, options } = buildSchemaOptions\n let fields = {}\n\n let schemaFields = configFields\n\n if (!allowIDField) {\n const idField = schemaFields.find((field) => fieldAffectsData(field) && field.name === 'id')\n if (idField) {\n fields = {\n _id: idField.type === 'number' ? Number : String,\n }\n schemaFields = schemaFields.filter(\n (field) => !(fieldAffectsData(field) && field.name === 'id'),\n )\n }\n }\n\n const schema = new mongoose.Schema(fields, options)\n\n schemaFields.forEach((field) => {\n if (!fieldIsPresentationalOnly(field)) {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[field.type]\n\n if (addFieldSchema) {\n addFieldSchema(field, schema, config, buildSchemaOptions)\n }\n }\n })\n\n return schema\n}\n\nconst fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {\n array: (\n field: ArrayField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ) => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: [\n buildSchema(config, field.fields, {\n allowIDField: true,\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n ],\n default: undefined,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n blocks: (\n field: BlockField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const fieldSchema = {\n type: [new mongoose.Schema({}, { _id: false, discriminatorKey: 'blockType' })],\n default: undefined,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, fieldSchema, config.localization),\n })\n\n field.blocks.forEach((blockItem: Block) => {\n const blockSchema = new mongoose.Schema({}, { _id: false, id: false })\n\n blockItem.fields.forEach((blockField) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[blockField.type]\n if (addFieldSchema) {\n addFieldSchema(blockField, blockSchema, config, buildSchemaOptions)\n }\n })\n\n if (field.localized && config.localization) {\n config.localization.localeCodes.forEach((localeCode) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error Possible incorrect typing in mongoose types, this works\n schema.path(`${field.name}.${localeCode}`).discriminator(blockItem.slug, blockSchema)\n })\n } else {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error Possible incorrect typing in mongoose types, this works\n schema.path(field.name).discriminator(blockItem.slug, blockSchema)\n }\n })\n },\n checkbox: (\n field: CheckboxField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Boolean }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n code: (\n field: CodeField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n collapsible: (\n field: CollapsibleField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n },\n date: (\n field: DateField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Date }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n email: (\n field: EmailField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n group: (\n field: GroupField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const formattedBaseSchema = formatBaseSchema(field, buildSchemaOptions)\n\n // carry indexSortableFields through to versions if drafts enabled\n const indexSortableFields =\n buildSchemaOptions.indexSortableFields &&\n field.name === 'version' &&\n buildSchemaOptions.draftsEnabled\n\n const baseSchema = {\n ...formattedBaseSchema,\n type: buildSchema(config, field.fields, {\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n indexSortableFields,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n json: (\n field: JSONField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n number: (\n field: NumberField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: field.hasMany ? [Number] : Number,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n point: (\n field: PointField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema: SchemaTypeOptions<unknown> = {\n type: {\n type: String,\n enum: ['Point'],\n },\n coordinates: {\n type: [Number],\n default: field.defaultValue || undefined,\n required: false,\n },\n }\n if (buildSchemaOptions.disableUnique && field.unique && field.localized) {\n baseSchema.coordinates.sparse = true\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n\n if (field.index === true || field.index === undefined) {\n const indexOptions: IndexOptions = {}\n if (!buildSchemaOptions.disableUnique && field.unique) {\n indexOptions.sparse = true\n indexOptions.unique = true\n }\n if (field.localized && config.localization) {\n config.localization.locales.forEach((locale) => {\n schema.index({ [`${field.name}.${locale.code}`]: '2dsphere' }, indexOptions)\n })\n } else {\n schema.index({ [field.name]: '2dsphere' }, indexOptions)\n }\n }\n },\n radio: (\n field: RadioField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: String,\n enum: field.options.map((option) => {\n if (typeof option === 'object') return option.value\n return option\n }),\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n relationship: (\n field: RelationshipField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ) => {\n const hasManyRelations = Array.isArray(field.relationTo)\n let schemaToReturn: { [key: string]: any } = {}\n\n if (field.localized && config.localization) {\n schemaToReturn = {\n type: config.localization.localeCodes.reduce((locales, locale) => {\n let localeSchema: { [key: string]: any } = {}\n\n if (hasManyRelations) {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.${locale}.relationTo`,\n },\n }\n } else {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n }\n\n return {\n ...locales,\n [locale]: field.hasMany ? { type: [localeSchema], default: undefined } : localeSchema,\n }\n }, {}),\n localized: true,\n }\n } else if (hasManyRelations) {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.relationTo`,\n },\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: undefined,\n }\n }\n } else {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: undefined,\n }\n }\n }\n\n schema.add({\n [field.name]: schemaToReturn,\n })\n },\n richText: (\n field: RichTextField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n row: (\n field: RowField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n },\n select: (\n field: SelectField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: String,\n enum: field.options.map((option) => {\n if (typeof option === 'object') return option.value\n return option\n }),\n }\n\n if (buildSchemaOptions.draftsEnabled || !field.required) {\n baseSchema.enum.push(null)\n }\n\n schema.add({\n [field.name]: localizeSchema(\n field,\n field.hasMany ? [baseSchema] : baseSchema,\n config.localization,\n ),\n })\n },\n tabs: (\n field: TabsField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.tabs.forEach((tab) => {\n if (tabHasName(tab)) {\n const baseSchema = {\n type: buildSchema(config, tab.fields, {\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n }\n\n schema.add({\n [tab.name]: localizeSchema(tab, baseSchema, config.localization),\n })\n } else {\n tab.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n }\n })\n },\n text: (\n field: TextField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: field.hasMany ? [String] : String,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n textarea: (\n field: TextareaField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n upload: (\n field: UploadField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n}\n\nexport default buildSchema\n"],"names":["mongoose","fieldAffectsData","fieldIsLocalized","fieldIsPresentationalOnly","tabHasName","formatBaseSchema","field","buildSchemaOptions","disableUnique","draftsEnabled","indexSortableFields","schema","index","unique","required","localized","type","sparse","hidden","localizeSchema","entity","localization","Array","isArray","locales","localeCodes","reduce","localeSchema","locale","_id","buildSchema","config","configFields","allowIDField","options","fields","schemaFields","idField","find","name","Number","String","filter","Schema","forEach","addFieldSchema","fieldToSchemaMap","array","baseSchema","id","minimize","default","undefined","add","blocks","fieldSchema","discriminatorKey","blockItem","blockSchema","blockField","localeCode","path","discriminator","slug","checkbox","Boolean","code","collapsible","subField","date","Date","email","group","formattedBaseSchema","json","Types","Mixed","number","hasMany","point","enum","coordinates","defaultValue","indexOptions","radio","map","option","value","relationship","hasManyRelations","relationTo","schemaToReturn","refPath","ref","richText","row","select","push","tabs","tab","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AAMvB,iBAAuCC,gBAAgB,CAACsB,SAASpD,IAAI,CAAC;oBAE5E,IAAI6B,gBAAgB;wBAClBA,eAAeuB,UAAUzD,QAAQoB,QAAQxB;oBAC3C;gBACF;YACF;QACF;IACF;IACA6F,MAAM,CACJ9F,OACAK,QACAoB,QACAxB;QAEA,MAAMyC,aAAa;YACjB,GAAG3C,iBAAiBC,OAAOC,mBAAmB;YAC9CS,MAAMV,MAAMwE,OAAO,GAAG;gBAACrC;aAAO,GAAGA;QACnC;QAEA9B,OAAO0C,GAAG,CAAC;YACT,CAAC/C,MAAMiC,IAAI,CAAC,EAAEpB,eAAeb,OAAO0C,YAAYjB,OAAOV,YAAY;QACrE;IACF;IACAgF,UAAU,CACR/F,OACAK,QACAoB,QACAxB;QAEA,MAAMyC,aAAa;YAAE,GAAG3C,iBAAiBC,OAAOC,mBAAmB;YAAES,MAAMyB;QAAO;QAElF9B,OAAO0C,GAAG,CAAC;YACT,CAAC/C,MAAMiC,IAAI,CAAC,EAAEpB,eAAeb,OAAO0C,YAAYjB,OAAOV,YAAY;QACrE;IACF;IACAiF,QAAQ,CACNhG,OACAK,QACAoB,QACAxB;QAEA,MAAMyC,aAAa;YACjB,GAAG3C,iBAAiBC,OAAOC,mBAAmB;YAC9CS,MAAMhB,SAAS2C,MAAM,CAACgC,KAAK,CAACC,KAAK;YACjCiB,KAAKvF,MAAMoF,UAAU;QACvB;QAEA/E,OAAO0C,GAAG,CAAC;YACT,CAAC/C,MAAMiC,IAAI,CAAC,EAAEpB,eAAeb,OAAO0C,YAAYjB,OAAOV,YAAY;QACrE;IACF;AACF;AAEA,eAAeS,YAAW"}
1
+ {"version":3,"sources":["../../src/models/buildSchema.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\n/* eslint-disable class-methods-use-this */\n/* eslint-disable @typescript-eslint/no-use-before-define */\nimport type { IndexOptions, Schema, SchemaOptions, SchemaTypeOptions } from 'mongoose'\nimport type {\n ArrayField,\n Block,\n BlockField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n FieldAffectingData,\n GroupField,\n JSONField,\n NonPresentationalField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedConfig,\n SanitizedLocalizationConfig,\n SelectField,\n Tab,\n TabsField,\n TextField,\n TextareaField,\n UploadField,\n} from 'payload'\n\nimport mongoose from 'mongoose'\nimport {\n fieldAffectsData,\n fieldIsLocalized,\n fieldIsPresentationalOnly,\n tabHasName,\n} from 'payload/shared'\n\nexport type BuildSchemaOptions = {\n allowIDField?: boolean\n disableUnique?: boolean\n draftsEnabled?: boolean\n indexSortableFields?: boolean\n options?: SchemaOptions\n}\n\ntype FieldSchemaGenerator = (\n field: Field,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n) => void\n\nconst formatBaseSchema = (field: FieldAffectingData, buildSchemaOptions: BuildSchemaOptions) => {\n const { disableUnique, draftsEnabled, indexSortableFields } = buildSchemaOptions\n const schema: SchemaTypeOptions<unknown> = {\n index: field.index || (!disableUnique && field.unique) || indexSortableFields || false,\n required: false,\n unique: (!disableUnique && field.unique) || false,\n }\n\n if (\n schema.unique &&\n (field.localized ||\n draftsEnabled ||\n (fieldAffectsData(field) &&\n field.type !== 'group' &&\n field.type !== 'tab' &&\n field.required !== true))\n ) {\n schema.sparse = true\n }\n\n if (field.hidden) {\n schema.hidden = true\n }\n\n return schema\n}\n\nconst localizeSchema = (\n entity: NonPresentationalField | Tab,\n schema,\n localization: SanitizedLocalizationConfig | false,\n) => {\n if (fieldIsLocalized(entity) && localization && Array.isArray(localization.locales)) {\n return {\n type: localization.localeCodes.reduce(\n (localeSchema, locale) => ({\n ...localeSchema,\n [locale]: schema,\n }),\n {\n _id: false,\n },\n ),\n localized: true,\n }\n }\n return schema\n}\n\nconst buildSchema = (\n config: SanitizedConfig,\n configFields: Field[],\n buildSchemaOptions: BuildSchemaOptions = {},\n): Schema => {\n const { allowIDField, options } = buildSchemaOptions\n let fields = {}\n\n let schemaFields = configFields\n\n if (!allowIDField) {\n const idField = schemaFields.find((field) => fieldAffectsData(field) && field.name === 'id')\n if (idField) {\n fields = {\n _id: idField.type === 'number' ? Number : String,\n }\n schemaFields = schemaFields.filter(\n (field) => !(fieldAffectsData(field) && field.name === 'id'),\n )\n }\n }\n\n const schema = new mongoose.Schema(fields, options)\n\n schemaFields.forEach((field) => {\n if (!fieldIsPresentationalOnly(field)) {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[field.type]\n\n if (addFieldSchema) {\n addFieldSchema(field, schema, config, buildSchemaOptions)\n }\n }\n })\n\n return schema\n}\n\nconst fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {\n array: (\n field: ArrayField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ) => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: [\n buildSchema(config, field.fields, {\n allowIDField: true,\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n ],\n default: undefined,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n blocks: (\n field: BlockField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const fieldSchema = {\n type: [new mongoose.Schema({}, { _id: false, discriminatorKey: 'blockType' })],\n default: undefined,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, fieldSchema, config.localization),\n })\n\n field.blocks.forEach((blockItem: Block) => {\n const blockSchema = new mongoose.Schema({}, { _id: false, id: false })\n\n blockItem.fields.forEach((blockField) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[blockField.type]\n if (addFieldSchema) {\n addFieldSchema(blockField, blockSchema, config, buildSchemaOptions)\n }\n })\n\n if (field.localized && config.localization) {\n config.localization.localeCodes.forEach((localeCode) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error Possible incorrect typing in mongoose types, this works\n schema.path(`${field.name}.${localeCode}`).discriminator(blockItem.slug, blockSchema)\n })\n } else {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error Possible incorrect typing in mongoose types, this works\n schema.path(field.name).discriminator(blockItem.slug, blockSchema)\n }\n })\n },\n checkbox: (\n field: CheckboxField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Boolean }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n code: (\n field: CodeField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n collapsible: (\n field: CollapsibleField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n },\n date: (\n field: DateField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Date }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n email: (\n field: EmailField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n group: (\n field: GroupField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const formattedBaseSchema = formatBaseSchema(field, buildSchemaOptions)\n\n // carry indexSortableFields through to versions if drafts enabled\n const indexSortableFields =\n buildSchemaOptions.indexSortableFields &&\n field.name === 'version' &&\n buildSchemaOptions.draftsEnabled\n\n const baseSchema = {\n ...formattedBaseSchema,\n type: buildSchema(config, field.fields, {\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n indexSortableFields,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n json: (\n field: JSONField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n number: (\n field: NumberField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: field.hasMany ? [Number] : Number,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n point: (\n field: PointField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema: SchemaTypeOptions<unknown> = {\n type: {\n type: String,\n enum: ['Point'],\n },\n coordinates: {\n type: [Number],\n default: field.defaultValue || undefined,\n required: false,\n },\n }\n if (buildSchemaOptions.disableUnique && field.unique && field.localized) {\n baseSchema.coordinates.sparse = true\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n\n if (field.index === true || field.index === undefined) {\n const indexOptions: IndexOptions = {}\n if (!buildSchemaOptions.disableUnique && field.unique) {\n indexOptions.sparse = true\n indexOptions.unique = true\n }\n if (field.localized && config.localization) {\n config.localization.locales.forEach((locale) => {\n schema.index({ [`${field.name}.${locale.code}`]: '2dsphere' }, indexOptions)\n })\n } else {\n schema.index({ [field.name]: '2dsphere' }, indexOptions)\n }\n }\n },\n radio: (\n field: RadioField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: String,\n enum: field.options.map((option) => {\n if (typeof option === 'object') return option.value\n return option\n }),\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n relationship: (\n field: RelationshipField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ) => {\n const hasManyRelations = Array.isArray(field.relationTo)\n let schemaToReturn: { [key: string]: any } = {}\n\n if (field.localized && config.localization) {\n schemaToReturn = {\n type: config.localization.localeCodes.reduce((locales, locale) => {\n let localeSchema: { [key: string]: any } = {}\n\n if (hasManyRelations) {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.${locale}.relationTo`,\n },\n }\n } else {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n }\n\n return {\n ...locales,\n [locale]: field.hasMany ? { type: [localeSchema], default: undefined } : localeSchema,\n }\n }, {}),\n localized: true,\n }\n } else if (hasManyRelations) {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.relationTo`,\n },\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: undefined,\n }\n }\n } else {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: undefined,\n }\n }\n }\n\n schema.add({\n [field.name]: schemaToReturn,\n })\n },\n richText: (\n field: RichTextField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n row: (\n field: RowField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n },\n select: (\n field: SelectField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: String,\n enum: field.options.map((option) => {\n if (typeof option === 'object') return option.value\n return option\n }),\n }\n\n if (buildSchemaOptions.draftsEnabled || !field.required) {\n baseSchema.enum.push(null)\n }\n\n schema.add({\n [field.name]: localizeSchema(\n field,\n field.hasMany ? [baseSchema] : baseSchema,\n config.localization,\n ),\n })\n },\n tabs: (\n field: TabsField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.tabs.forEach((tab) => {\n if (tabHasName(tab)) {\n const baseSchema = {\n type: buildSchema(config, tab.fields, {\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n }\n\n schema.add({\n [tab.name]: localizeSchema(tab, baseSchema, config.localization),\n })\n } else {\n tab.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n }\n })\n },\n text: (\n field: TextField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: field.hasMany ? [String] : String,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n textarea: (\n field: TextareaField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n upload: (\n field: UploadField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n}\n\nexport default buildSchema\n"],"names":["mongoose","fieldAffectsData","fieldIsLocalized","fieldIsPresentationalOnly","tabHasName","formatBaseSchema","field","buildSchemaOptions","disableUnique","draftsEnabled","indexSortableFields","schema","index","unique","required","localized","type","sparse","hidden","localizeSchema","entity","localization","Array","isArray","locales","localeCodes","reduce","localeSchema","locale","_id","buildSchema","config","configFields","allowIDField","options","fields","schemaFields","idField","find","name","Number","String","filter","Schema","forEach","addFieldSchema","fieldToSchemaMap","array","baseSchema","id","minimize","default","undefined","add","blocks","fieldSchema","discriminatorKey","blockItem","blockSchema","blockField","localeCode","path","discriminator","slug","checkbox","Boolean","code","collapsible","subField","date","Date","email","group","formattedBaseSchema","json","Types","Mixed","number","hasMany","point","enum","coordinates","defaultValue","indexOptions","radio","map","option","value","relationship","hasManyRelations","relationTo","schemaToReturn","refPath","ref","richText","row","select","push","tabs","tab","text","textarea","upload"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oDAAoD,GACpD,yCAAyC,GACzC,0DAA0D,GAgC1D,OAAOA,cAAc,WAAU;AAC/B,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,yBAAyB,EACzBC,UAAU,QACL,iBAAgB;AAiBvB,MAAMC,mBAAmB,CAACC,OAA2BC;IACnD,MAAM,EAAEC,aAAa,EAAEC,aAAa,EAAEC,mBAAmB,EAAE,GAAGH;IAC9D,MAAMI,SAAqC;QACzCC,OAAON,MAAMM,KAAK,IAAK,CAACJ,iBAAiBF,MAAMO,MAAM,IAAKH,uBAAuB;QACjFI,UAAU;QACVD,QAAQ,AAAC,CAACL,iBAAiBF,MAAMO,MAAM,IAAK;IAC9C;IAEA,IACEF,OAAOE,MAAM,IACZP,CAAAA,MAAMS,SAAS,IACdN,iBACCR,iBAAiBK,UAChBA,MAAMU,IAAI,KAAK,WACfV,MAAMU,IAAI,KAAK,SACfV,MAAMQ,QAAQ,KAAK,IAAI,GAC3B;QACAH,OAAOM,MAAM,GAAG;IAClB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OAAO;gBACL8E,IAAIhE,MAAM,CAACS,OAAO,CAAC,CAACwB;oBAClB,MAAMvB,iBAAuCC,gBAAgB,CAACsB,SAASpD,IAAI,CAAC;oBAE5E,IAAI6B,gBAAgB;wBAClBA,eAAeuB,UAAUzD,QAAQoB,QAAQxB;oBAC3C;gBACF;YACF;QACF;IACF;IACA6F,MAAM,CACJ9F,OACAK,QACAoB,QACAxB;QAEA,MAAMyC,aAAa;YACjB,GAAG3C,iBAAiBC,OAAOC,mBAAmB;YAC9CS,MAAMV,MAAMwE,OAAO,GAAG;gBAACrC;aAAO,GAAGA;QACnC;QAEA9B,OAAO0C,GAAG,CAAC;YACT,CAAC/C,MAAMiC,IAAI,CAAC,EAAEpB,eAAeb,OAAO0C,YAAYjB,OAAOV,YAAY;QACrE;IACF;IACAgF,UAAU,CACR/F,OACAK,QACAoB,QACAxB;QAEA,MAAMyC,aAAa;YAAE,GAAG3C,iBAAiBC,OAAOC,mBAAmB;YAAES,MAAMyB;QAAO;QAElF9B,OAAO0C,GAAG,CAAC;YACT,CAAC/C,MAAMiC,IAAI,CAAC,EAAEpB,eAAeb,OAAO0C,YAAYjB,OAAOV,YAAY;QACrE;IACF;IACAiF,QAAQ,CACNhG,OACAK,QACAoB,QACAxB;QAEA,MAAMyC,aAAa;YACjB,GAAG3C,iBAAiBC,OAAOC,mBAAmB;YAC9CS,MAAMhB,SAAS2C,MAAM,CAACgC,KAAK,CAACC,KAAK;YACjCiB,KAAKvF,MAAMoF,UAAU;QACvB;QAEA/E,OAAO0C,GAAG,CAAC;YACT,CAAC/C,MAAMiC,IAAI,CAAC,EAAEpB,eAAeb,OAAO0C,YAAYjB,OAAOV,YAAY;QACrE;IACF;AACF;AAEA,eAAeS,YAAW"}
@@ -1,5 +1,4 @@
1
- import type { Payload } from 'payload';
2
- import type { Field, Where } from 'payload/types';
1
+ import type { Field, Payload, Where } from 'payload';
3
2
  export declare function buildAndOrConditions({ collectionSlug, fields, globalSlug, locale, payload, where, }: {
4
3
  collectionSlug?: string;
5
4
  fields: Field[];
@@ -1 +1 @@
1
- {"version":3,"file":"buildAndOrConditions.d.ts","sourceRoot":"","sources":["../../src/queries/buildAndOrConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAIjD,wBAAsB,oBAAoB,CAAC,EACzC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,GACN,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,EAAE,CAAA;CACf,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAuBrC"}
1
+ {"version":3,"file":"buildAndOrConditions.d.ts","sourceRoot":"","sources":["../../src/queries/buildAndOrConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpD,wBAAsB,oBAAoB,CAAC,EACzC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,GACN,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,EAAE,CAAA;CACf,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAuBrC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport type { Field, Where } from 'payload/types'\n\nimport { parseParams } from './parseParams.js'\n\nexport async function buildAndOrConditions({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n}: {\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n locale?: string\n payload: Payload\n where: Where[]\n}): Promise<Record<string, unknown>[]> {\n const completedConditions = []\n // Loop over all AND / OR operations and add them to the AND / OR query param\n // Operations should come through as an array\n // eslint-disable-next-line no-restricted-syntax\n for (const condition of where) {\n // If the operation is properly formatted as an object\n if (typeof condition === 'object') {\n // eslint-disable-next-line no-await-in-loop\n const result = await parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where: condition,\n })\n if (Object.keys(result).length > 0) {\n completedConditions.push(result)\n }\n }\n }\n return completedConditions\n}\n"],"names":["parseParams","buildAndOrConditions","collectionSlug","fields","globalSlug","locale","payload","where","completedConditions","condition","result","Object","keys","length","push"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,qBAAqB,EACzCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EAQN;IACC,MAAMC,sBAAsB,EAAE;IAC9B,6EAA6E;IAC7E,6CAA6C;IAC7C,gDAAgD;IAChD,KAAK,MAAMC,aAAaF,MAAO;QAC7B,sDAAsD;QACtD,IAAI,OAAOE,cAAc,UAAU;YACjC,4CAA4C;YAC5C,MAAMC,SAAS,MAAMV,YAAY;gBAC/BE;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,OAAOE;YACT;YACA,IAAIE,OAAOC,IAAI,CAACF,QAAQG,MAAM,GAAG,GAAG;gBAClCL,oBAAoBM,IAAI,CAACJ;YAC3B;QACF;IACF;IACA,OAAOF;AACT"}
1
+ {"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { Field, Payload, Where } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\nexport async function buildAndOrConditions({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n}: {\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n locale?: string\n payload: Payload\n where: Where[]\n}): Promise<Record<string, unknown>[]> {\n const completedConditions = []\n // Loop over all AND / OR operations and add them to the AND / OR query param\n // Operations should come through as an array\n // eslint-disable-next-line no-restricted-syntax\n for (const condition of where) {\n // If the operation is properly formatted as an object\n if (typeof condition === 'object') {\n // eslint-disable-next-line no-await-in-loop\n const result = await parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where: condition,\n })\n if (Object.keys(result).length > 0) {\n completedConditions.push(result)\n }\n }\n }\n return completedConditions\n}\n"],"names":["parseParams","buildAndOrConditions","collectionSlug","fields","globalSlug","locale","payload","where","completedConditions","condition","result","Object","keys","length","push"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,qBAAqB,EACzCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EAQN;IACC,MAAMC,sBAAsB,EAAE;IAC9B,6EAA6E;IAC7E,6CAA6C;IAC7C,gDAAgD;IAChD,KAAK,MAAMC,aAAaF,MAAO;QAC7B,sDAAsD;QACtD,IAAI,OAAOE,cAAc,UAAU;YACjC,4CAA4C;YAC5C,MAAMC,SAAS,MAAMV,YAAY;gBAC/BE;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,OAAOE;YACT;YACA,IAAIE,OAAOC,IAAI,CAACF,QAAQG,MAAM,GAAG,GAAG;gBAClCL,oBAAoBM,IAAI,CAACJ;YAC3B;QACF;IACF;IACA,OAAOF;AACT"}
@@ -1,5 +1,4 @@
1
- import type { Payload } from 'payload';
2
- import type { Field, Where } from 'payload/types';
1
+ import type { Field, Payload, Where } from 'payload';
3
2
  type GetBuildQueryPluginArgs = {
4
3
  collectionSlug?: string;
5
4
  versionsFields?: Field[];
@@ -1 +1 @@
1
- {"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAMjD,KAAK,uBAAuB,GAAG;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,KAAK,EAAE,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAID,QAAA,MAAM,mBAAmB,wCAAwC,uBAAuB,0BAsCvF,CAAA;AAED,eAAe,mBAAmB,CAAA"}
1
+ {"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAMpD,KAAK,uBAAuB,GAAG;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,KAAK,EAAE,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAID,QAAA,MAAM,mBAAmB,wCAAwC,uBAAuB,0BAsCvF,CAAA;AAED,eAAe,mBAAmB,CAAA"}
@@ -1,4 +1,4 @@
1
- import { QueryError } from 'payload/errors';
1
+ import { QueryError } from 'payload';
2
2
  import { parseParams } from './parseParams.js';
3
3
  // This plugin asynchronously builds a list of Mongoose query constraints
4
4
  // which can then be used in subsequent Mongoose queries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport type { Field, Where } from 'payload/types'\n\nimport { QueryError } from 'payload/errors'\n\nimport { parseParams } from './parseParams.js'\n\ntype GetBuildQueryPluginArgs = {\n collectionSlug?: string\n versionsFields?: Field[]\n}\n\nexport type BuildQueryArgs = {\n globalSlug?: string\n locale?: string\n payload: Payload\n where: Where\n}\n\n// This plugin asynchronously builds a list of Mongoose query constraints\n// which can then be used in subsequent Mongoose queries.\nconst getBuildQueryPlugin = ({ collectionSlug, versionsFields }: GetBuildQueryPluginArgs = {}) => {\n return function buildQueryPlugin(schema) {\n const modifiedSchema = schema\n async function buildQuery({\n globalSlug,\n locale,\n payload,\n where,\n }: BuildQueryArgs): Promise<Record<string, unknown>> {\n let fields = versionsFields\n if (!fields) {\n if (globalSlug) {\n const globalConfig = payload.globals.config.find(({ slug }) => slug === globalSlug)\n fields = globalConfig.fields\n }\n if (collectionSlug) {\n const collectionConfig = payload.collections[collectionSlug].config\n fields = collectionConfig.fields\n }\n }\n const errors = []\n const result = await parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n })\n\n if (errors.length > 0) {\n throw new QueryError(errors)\n }\n\n return result\n }\n modifiedSchema.statics.buildQuery = buildQuery\n }\n}\n\nexport default getBuildQueryPlugin\n"],"names":["QueryError","parseParams","getBuildQueryPlugin","collectionSlug","versionsFields","buildQueryPlugin","schema","modifiedSchema","buildQuery","globalSlug","locale","payload","where","fields","globalConfig","globals","config","find","slug","collectionConfig","collections","errors","result","length","statics"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,UAAU,QAAQ,iBAAgB;AAE3C,SAASC,WAAW,QAAQ,mBAAkB;AAc9C,yEAAyE;AACzE,yDAAyD;AACzD,MAAMC,sBAAsB,CAAC,EAAEC,cAAc,EAAEC,cAAc,EAA2B,GAAG,CAAC,CAAC;IAC3F,OAAO,SAASC,iBAAiBC,MAAM;QACrC,MAAMC,iBAAiBD;QACvB,eAAeE,WAAW,EACxBC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EACU;YACf,IAAIC,SAAST;YACb,IAAI,CAACS,QAAQ;gBACX,IAAIJ,YAAY;oBACd,MAAMK,eAAeH,QAAQI,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAAST;oBACxEI,SAASC,aAAaD,MAAM;gBAC9B;gBACA,IAAIV,gBAAgB;oBAClB,MAAMgB,mBAAmBR,QAAQS,WAAW,CAACjB,eAAe,CAACa,MAAM;oBACnEH,SAASM,iBAAiBN,MAAM;gBAClC;YACF;YACA,MAAMQ,SAAS,EAAE;YACjB,MAAMC,SAAS,MAAMrB,YAAY;gBAC/BE;gBACAU;gBACAJ;gBACAC;gBACAC;gBACAC;YACF;YAEA,IAAIS,OAAOE,MAAM,GAAG,GAAG;gBACrB,MAAM,IAAIvB,WAAWqB;YACvB;YAEA,OAAOC;QACT;QACAf,eAAeiB,OAAO,CAAChB,UAAU,GAAGA;IACtC;AACF;AAEA,eAAeN,oBAAmB"}
1
+ {"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { Field, Payload, Where } from 'payload'\n\nimport { QueryError } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\ntype GetBuildQueryPluginArgs = {\n collectionSlug?: string\n versionsFields?: Field[]\n}\n\nexport type BuildQueryArgs = {\n globalSlug?: string\n locale?: string\n payload: Payload\n where: Where\n}\n\n// This plugin asynchronously builds a list of Mongoose query constraints\n// which can then be used in subsequent Mongoose queries.\nconst getBuildQueryPlugin = ({ collectionSlug, versionsFields }: GetBuildQueryPluginArgs = {}) => {\n return function buildQueryPlugin(schema) {\n const modifiedSchema = schema\n async function buildQuery({\n globalSlug,\n locale,\n payload,\n where,\n }: BuildQueryArgs): Promise<Record<string, unknown>> {\n let fields = versionsFields\n if (!fields) {\n if (globalSlug) {\n const globalConfig = payload.globals.config.find(({ slug }) => slug === globalSlug)\n fields = globalConfig.fields\n }\n if (collectionSlug) {\n const collectionConfig = payload.collections[collectionSlug].config\n fields = collectionConfig.fields\n }\n }\n const errors = []\n const result = await parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n })\n\n if (errors.length > 0) {\n throw new QueryError(errors)\n }\n\n return result\n }\n modifiedSchema.statics.buildQuery = buildQuery\n }\n}\n\nexport default getBuildQueryPlugin\n"],"names":["QueryError","parseParams","getBuildQueryPlugin","collectionSlug","versionsFields","buildQueryPlugin","schema","modifiedSchema","buildQuery","globalSlug","locale","payload","where","fields","globalConfig","globals","config","find","slug","collectionConfig","collections","errors","result","length","statics"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,UAAU,QAAQ,UAAS;AAEpC,SAASC,WAAW,QAAQ,mBAAkB;AAc9C,yEAAyE;AACzE,yDAAyD;AACzD,MAAMC,sBAAsB,CAAC,EAAEC,cAAc,EAAEC,cAAc,EAA2B,GAAG,CAAC,CAAC;IAC3F,OAAO,SAASC,iBAAiBC,MAAM;QACrC,MAAMC,iBAAiBD;QACvB,eAAeE,WAAW,EACxBC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EACU;YACf,IAAIC,SAAST;YACb,IAAI,CAACS,QAAQ;gBACX,IAAIJ,YAAY;oBACd,MAAMK,eAAeH,QAAQI,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAAST;oBACxEI,SAASC,aAAaD,MAAM;gBAC9B;gBACA,IAAIV,gBAAgB;oBAClB,MAAMgB,mBAAmBR,QAAQS,WAAW,CAACjB,eAAe,CAACa,MAAM;oBACnEH,SAASM,iBAAiBN,MAAM;gBAClC;YACF;YACA,MAAMQ,SAAS,EAAE;YACjB,MAAMC,SAAS,MAAMrB,YAAY;gBAC/BE;gBACAU;gBACAJ;gBACAC;gBACAC;gBACAC;YACF;YAEA,IAAIS,OAAOE,MAAM,GAAG,GAAG;gBACrB,MAAM,IAAIvB,WAAWqB;YACvB;YAEA,OAAOC;QACT;QACAf,eAAeiB,OAAO,CAAChB,UAAU,GAAGA;IACtC;AACF;AAEA,eAAeN,oBAAmB"}
@@ -1,5 +1,4 @@
1
- import type { Payload } from 'payload';
2
- import type { Field } from 'payload/types';
1
+ import type { Field, Payload } from 'payload';
3
2
  type SearchParam = {
4
3
  path?: string;
5
4
  rawQuery?: unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"buildSearchParams.d.ts","sourceRoot":"","sources":["../../src/queries/buildSearchParams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAiB1C,KAAK,WAAW,GAAG;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAOD;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,cAAc,EACd,MAAM,EACN,UAAU,EACV,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,OAAO,EACP,GAAG,GACJ,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,OAAO,CAAA;CACb,GAAG,OAAO,CAAC,WAAW,CAAC,CAuNvB"}
1
+ {"version":3,"file":"buildSearchParams.d.ts","sourceRoot":"","sources":["../../src/queries/buildSearchParams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAyB,OAAO,EAAE,MAAM,SAAS,CAAA;AAepE,KAAK,WAAW,GAAG;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAOD;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,cAAc,EACd,MAAM,EACN,UAAU,EACV,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,OAAO,EACP,GAAG,GACJ,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,OAAO,CAAA;CACb,GAAG,OAAO,CAAC,WAAW,CAAC,CAuNvB"}
@@ -1,7 +1,7 @@
1
1
  import ObjectIdImport from 'bson-objectid';
2
2
  import mongoose from 'mongoose';
3
- import { getLocalizedPaths } from 'payload/database';
4
- import { validOperators } from 'payload/types';
3
+ import { getLocalizedPaths } from 'payload';
4
+ import { validOperators } from 'payload/shared';
5
5
  import { operatorMap } from './operatorMap.js';
6
6
  import { sanitizeQueryValue } from './sanitizeQueryValue.js';
7
7
  const ObjectId = ObjectIdImport.default || ObjectIdImport;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildSearchParams.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport type { PathToQuery } from 'payload/database'\nimport type { Field } from 'payload/types'\nimport type { Operator } from 'payload/types'\n\nimport ObjectIdImport from 'bson-objectid'\nimport mongoose from 'mongoose'\nimport { getLocalizedPaths } from 'payload/database'\nimport { fieldAffectsData } from 'payload/types'\nimport { validOperators } from 'payload/types'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { operatorMap } from './operatorMap.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\nconst ObjectId = (ObjectIdImport.default ||\n ObjectIdImport) as unknown as typeof ObjectIdImport.default\n\ntype SearchParam = {\n path?: string\n rawQuery?: unknown\n value?: unknown\n}\n\nconst subQueryOptions = {\n lean: true,\n limit: 50,\n}\n\n/**\n * Convert the Payload key / value / operator into a MongoDB query\n */\nexport async function buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath,\n locale,\n operator,\n payload,\n val,\n}: {\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n incomingPath: string\n locale?: string\n operator: string\n payload: Payload\n val: unknown\n}): Promise<SearchParam> {\n // Replace GraphQL nested field double underscore formatting\n let sanitizedPath = incomingPath.replace(/__/g, '.')\n if (sanitizedPath === 'id') sanitizedPath = '_id'\n\n let paths: PathToQuery[] = []\n\n let hasCustomID = false\n\n if (sanitizedPath === '_id') {\n const customIDFieldType = payload.collections[collectionSlug]?.customIDType\n\n let idFieldType: 'number' | 'text' = 'text'\n\n if (customIDFieldType) {\n idFieldType = customIDFieldType\n hasCustomID = true\n }\n\n paths.push({\n collectionSlug,\n complete: true,\n field: {\n name: 'id',\n type: idFieldType,\n } as Field,\n path: '_id',\n })\n } else {\n paths = await getLocalizedPaths({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: sanitizedPath,\n locale,\n payload,\n })\n }\n\n const [{ field, path }] = paths\n\n if (path) {\n const {\n operator: formattedOperator,\n rawQuery,\n val: formattedValue,\n } = sanitizeQueryValue({\n field,\n hasCustomID,\n operator,\n path,\n val,\n })\n\n if (rawQuery) return { value: rawQuery }\n\n // If there are multiple collections to search through,\n // Recursively build up a list of query constraints\n if (paths.length > 1) {\n // Remove top collection and reverse array\n // to work backwards from top\n const pathsToQuery = paths.slice(1).reverse()\n\n const initialRelationshipQuery = {\n value: {},\n } as SearchParam\n\n const relationshipQuery = await pathsToQuery.reduce(\n async (priorQuery, { collectionSlug: slug, path: subPath }, i) => {\n const priorQueryResult = await priorQuery\n\n const SubModel = (payload.db as MongooseAdapter).collections[slug]\n\n // On the \"deepest\" collection,\n // Search on the value passed through the query\n if (i === 0) {\n const subQuery = await SubModel.buildQuery({\n locale,\n payload,\n where: {\n [subPath]: {\n [formattedOperator]: val,\n },\n },\n })\n\n const result = await SubModel.find(subQuery, subQueryOptions)\n\n const $in: unknown[] = []\n\n result.forEach((doc) => {\n const stringID = doc._id.toString()\n $in.push(stringID)\n\n if (mongoose.Types.ObjectId.isValid(stringID)) {\n $in.push(doc._id)\n }\n })\n\n if (pathsToQuery.length === 1) {\n return {\n path,\n value: { $in },\n }\n }\n\n const nextSubPath = pathsToQuery[i + 1].path\n\n return {\n value: { [nextSubPath]: { $in } },\n }\n }\n\n const subQuery = priorQueryResult.value\n const result = await SubModel.find(subQuery, subQueryOptions)\n\n const $in = result.map((doc) => doc._id.toString())\n\n // If it is the last recursion\n // then pass through the search param\n if (i + 1 === pathsToQuery.length) {\n return {\n path,\n value: { $in },\n }\n }\n\n return {\n value: {\n _id: { $in },\n },\n }\n },\n Promise.resolve(initialRelationshipQuery),\n )\n\n return relationshipQuery\n }\n\n if (formattedOperator && validOperators.includes(formattedOperator as Operator)) {\n const operatorKey = operatorMap[formattedOperator]\n\n if (field.type === 'relationship' || field.type === 'upload') {\n let hasNumberIDRelation\n let multiIDCondition = '$or'\n if (operatorKey === '$ne') multiIDCondition = '$and'\n\n const result = {\n value: {\n [multiIDCondition]: [{ [path]: { [operatorKey]: formattedValue } }],\n },\n }\n\n if (typeof formattedValue === 'string') {\n if (mongoose.Types.ObjectId.isValid(formattedValue)) {\n result.value[multiIDCondition].push({\n [path]: { [operatorKey]: ObjectId(formattedValue) },\n })\n } else {\n ;(Array.isArray(field.relationTo) ? field.relationTo : [field.relationTo]).forEach(\n (relationTo) => {\n const isRelatedToCustomNumberID =\n payload.collections[relationTo]?.customIDType === 'number'\n\n if (isRelatedToCustomNumberID) {\n hasNumberIDRelation = true\n }\n },\n )\n\n if (hasNumberIDRelation)\n result.value[multiIDCondition].push({\n [path]: { [operatorKey]: parseFloat(formattedValue) },\n })\n }\n }\n\n if (result.value[multiIDCondition].length > 1) {\n return result\n }\n }\n\n if (formattedOperator === 'like' && typeof formattedValue === 'string') {\n const words = formattedValue.split(' ')\n\n const result = {\n value: {\n $and: words.map((word) => ({\n [path]: {\n $options: 'i',\n $regex: word.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n },\n })),\n },\n }\n\n return result\n }\n\n // Some operators like 'near' need to define a full query\n // so if there is no operator key, just return the value\n if (!operatorKey) {\n return {\n path,\n value: formattedValue,\n }\n }\n\n return {\n path,\n value: { [operatorKey]: formattedValue },\n }\n }\n }\n return undefined\n}\n"],"names":["ObjectIdImport","mongoose","getLocalizedPaths","validOperators","operatorMap","sanitizeQueryValue","ObjectId","default","subQueryOptions","lean","limit","buildSearchParam","collectionSlug","fields","globalSlug","incomingPath","locale","operator","payload","val","sanitizedPath","replace","paths","hasCustomID","customIDFieldType","collections","customIDType","idFieldType","push","complete","field","name","type","path","formattedOperator","rawQuery","formattedValue","value","length","pathsToQuery","slice","reverse","initialRelationshipQuery","relationshipQuery","reduce","priorQuery","slug","subPath","i","priorQueryResult","SubModel","db","subQuery","buildQuery","where","result","find","$in","forEach","doc","stringID","_id","toString","Types","isValid","nextSubPath","map","Promise","resolve","includes","operatorKey","hasNumberIDRelation","multiIDCondition","Array","isArray","relationTo","isRelatedToCustomNumberID","parseFloat","words","split","$and","word","$options","$regex","undefined"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;wBACpD;oBACF,OAAO;wBACHqC,CAAAA,MAAMC,OAAO,CAAC5C,MAAM6C,UAAU,IAAI7C,MAAM6C,UAAU,GAAG;4BAAC7C,MAAM6C,UAAU;yBAAC,AAAD,EAAGjB,OAAO,CAChF,CAACiB;4BACC,MAAMC,4BACJ1D,QAAQO,WAAW,CAACkD,WAAW,EAAEjD,iBAAiB;4BAEpD,IAAIkD,2BAA2B;gCAC7BL,sBAAsB;4BACxB;wBACF;wBAGF,IAAIA,qBACFhB,OAAOlB,KAAK,CAACmC,iBAAiB,CAAC5C,IAAI,CAAC;4BAClC,CAACK,KAAK,EAAE;gCAAE,CAACqC,YAAY,EAAEO,WAAWzC;4BAAgB;wBACtD;oBACJ;gBACF;gBAEA,IAAImB,OAAOlB,KAAK,CAACmC,iBAAiB,CAAClC,MAAM,GAAG,GAAG;oBAC7C,OAAOiB;gBACT;YACF;YAEA,IAAIrB,sBAAsB,UAAU,OAAOE,mBAAmB,UAAU;gBACtE,MAAM0C,QAAQ1C,eAAe2C,KAAK,CAAC;gBAEnC,MAAMxB,SAAS;oBACblB,OAAO;wBACL2C,MAAMF,MAAMZ,GAAG,CAAC,CAACe,OAAU,CAAA;gCACzB,CAAChD,KAAK,EAAE;oCACNiD,UAAU;oCACVC,QAAQF,KAAK5D,OAAO,CAAC,uBAAuB;gCAC9C;4BACF,CAAA;oBACF;gBACF;gBAEA,OAAOkC;YACT;YAEA,yDAAyD;YACzD,wDAAwD;YACxD,IAAI,CAACe,aAAa;gBAChB,OAAO;oBACLrC;oBACAI,OAAOD;gBACT;YACF;YAEA,OAAO;gBACLH;gBACAI,OAAO;oBAAE,CAACiC,YAAY,EAAElC;gBAAe;YACzC;QACF;IACF;IACA,OAAOgD;AACT"}
1
+ {"version":3,"sources":["../../src/queries/buildSearchParams.ts"],"sourcesContent":["import type { Field, Operator, PathToQuery, Payload } from 'payload'\n\nimport ObjectIdImport from 'bson-objectid'\nimport mongoose from 'mongoose'\nimport { getLocalizedPaths } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { operatorMap } from './operatorMap.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\nconst ObjectId = (ObjectIdImport.default ||\n ObjectIdImport) as unknown as typeof ObjectIdImport.default\n\ntype SearchParam = {\n path?: string\n rawQuery?: unknown\n value?: unknown\n}\n\nconst subQueryOptions = {\n lean: true,\n limit: 50,\n}\n\n/**\n * Convert the Payload key / value / operator into a MongoDB query\n */\nexport async function buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath,\n locale,\n operator,\n payload,\n val,\n}: {\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n incomingPath: string\n locale?: string\n operator: string\n payload: Payload\n val: unknown\n}): Promise<SearchParam> {\n // Replace GraphQL nested field double underscore formatting\n let sanitizedPath = incomingPath.replace(/__/g, '.')\n if (sanitizedPath === 'id') sanitizedPath = '_id'\n\n let paths: PathToQuery[] = []\n\n let hasCustomID = false\n\n if (sanitizedPath === '_id') {\n const customIDFieldType = payload.collections[collectionSlug]?.customIDType\n\n let idFieldType: 'number' | 'text' = 'text'\n\n if (customIDFieldType) {\n idFieldType = customIDFieldType\n hasCustomID = true\n }\n\n paths.push({\n collectionSlug,\n complete: true,\n field: {\n name: 'id',\n type: idFieldType,\n } as Field,\n path: '_id',\n })\n } else {\n paths = await getLocalizedPaths({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: sanitizedPath,\n locale,\n payload,\n })\n }\n\n const [{ field, path }] = paths\n\n if (path) {\n const {\n operator: formattedOperator,\n rawQuery,\n val: formattedValue,\n } = sanitizeQueryValue({\n field,\n hasCustomID,\n operator,\n path,\n val,\n })\n\n if (rawQuery) return { value: rawQuery }\n\n // If there are multiple collections to search through,\n // Recursively build up a list of query constraints\n if (paths.length > 1) {\n // Remove top collection and reverse array\n // to work backwards from top\n const pathsToQuery = paths.slice(1).reverse()\n\n const initialRelationshipQuery = {\n value: {},\n } as SearchParam\n\n const relationshipQuery = await pathsToQuery.reduce(\n async (priorQuery, { collectionSlug: slug, path: subPath }, i) => {\n const priorQueryResult = await priorQuery\n\n const SubModel = (payload.db as MongooseAdapter).collections[slug]\n\n // On the \"deepest\" collection,\n // Search on the value passed through the query\n if (i === 0) {\n const subQuery = await SubModel.buildQuery({\n locale,\n payload,\n where: {\n [subPath]: {\n [formattedOperator]: val,\n },\n },\n })\n\n const result = await SubModel.find(subQuery, subQueryOptions)\n\n const $in: unknown[] = []\n\n result.forEach((doc) => {\n const stringID = doc._id.toString()\n $in.push(stringID)\n\n if (mongoose.Types.ObjectId.isValid(stringID)) {\n $in.push(doc._id)\n }\n })\n\n if (pathsToQuery.length === 1) {\n return {\n path,\n value: { $in },\n }\n }\n\n const nextSubPath = pathsToQuery[i + 1].path\n\n return {\n value: { [nextSubPath]: { $in } },\n }\n }\n\n const subQuery = priorQueryResult.value\n const result = await SubModel.find(subQuery, subQueryOptions)\n\n const $in = result.map((doc) => doc._id.toString())\n\n // If it is the last recursion\n // then pass through the search param\n if (i + 1 === pathsToQuery.length) {\n return {\n path,\n value: { $in },\n }\n }\n\n return {\n value: {\n _id: { $in },\n },\n }\n },\n Promise.resolve(initialRelationshipQuery),\n )\n\n return relationshipQuery\n }\n\n if (formattedOperator && validOperators.includes(formattedOperator as Operator)) {\n const operatorKey = operatorMap[formattedOperator]\n\n if (field.type === 'relationship' || field.type === 'upload') {\n let hasNumberIDRelation\n let multiIDCondition = '$or'\n if (operatorKey === '$ne') multiIDCondition = '$and'\n\n const result = {\n value: {\n [multiIDCondition]: [{ [path]: { [operatorKey]: formattedValue } }],\n },\n }\n\n if (typeof formattedValue === 'string') {\n if (mongoose.Types.ObjectId.isValid(formattedValue)) {\n result.value[multiIDCondition].push({\n [path]: { [operatorKey]: ObjectId(formattedValue) },\n })\n } else {\n ;(Array.isArray(field.relationTo) ? field.relationTo : [field.relationTo]).forEach(\n (relationTo) => {\n const isRelatedToCustomNumberID =\n payload.collections[relationTo]?.customIDType === 'number'\n\n if (isRelatedToCustomNumberID) {\n hasNumberIDRelation = true\n }\n },\n )\n\n if (hasNumberIDRelation)\n result.value[multiIDCondition].push({\n [path]: { [operatorKey]: parseFloat(formattedValue) },\n })\n }\n }\n\n if (result.value[multiIDCondition].length > 1) {\n return result\n }\n }\n\n if (formattedOperator === 'like' && typeof formattedValue === 'string') {\n const words = formattedValue.split(' ')\n\n const result = {\n value: {\n $and: words.map((word) => ({\n [path]: {\n $options: 'i',\n $regex: word.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n },\n })),\n },\n }\n\n return result\n }\n\n // Some operators like 'near' need to define a full query\n // so if there is no operator key, just return the value\n if (!operatorKey) {\n return {\n path,\n value: formattedValue,\n }\n }\n\n return {\n path,\n value: { [operatorKey]: formattedValue },\n }\n }\n }\n return undefined\n}\n"],"names":["ObjectIdImport","mongoose","getLocalizedPaths","validOperators","operatorMap","sanitizeQueryValue","ObjectId","default","subQueryOptions","lean","limit","buildSearchParam","collectionSlug","fields","globalSlug","incomingPath","locale","operator","payload","val","sanitizedPath","replace","paths","hasCustomID","customIDFieldType","collections","customIDType","idFieldType","push","complete","field","name","type","path","formattedOperator","rawQuery","formattedValue","value","length","pathsToQuery","slice","reverse","initialRelationshipQuery","relationshipQuery","reduce","priorQuery","slug","subPath","i","priorQueryResult","SubModel","db","subQuery","buildQuery","where","result","find","$in","forEach","doc","stringID","_id","toString","Types","isValid","nextSubPath","map","Promise","resolve","includes","operatorKey","hasNumberIDRelation","multiIDCondition","Array","isArray","relationTo","isRelatedToCustomNumberID","parseFloat","words","split","$and","word","$options","$regex","undefined"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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D,EAAGjB,OAAO,CAChF,CAACiB;4BACC,MAAMC,4BACJ1D,QAAQO,WAAW,CAACkD,WAAW,EAAEjD,iBAAiB;4BAEpD,IAAIkD,2BAA2B;gCAC7BL,sBAAsB;4BACxB;wBACF;wBAGF,IAAIA,qBACFhB,OAAOlB,KAAK,CAACmC,iBAAiB,CAAC5C,IAAI,CAAC;4BAClC,CAACK,KAAK,EAAE;gCAAE,CAACqC,YAAY,EAAEO,WAAWzC;4BAAgB;wBACtD;oBACJ;gBACF;gBAEA,IAAImB,OAAOlB,KAAK,CAACmC,iBAAiB,CAAClC,MAAM,GAAG,GAAG;oBAC7C,OAAOiB;gBACT;YACF;YAEA,IAAIrB,sBAAsB,UAAU,OAAOE,mBAAmB,UAAU;gBACtE,MAAM0C,QAAQ1C,eAAe2C,KAAK,CAAC;gBAEnC,MAAMxB,SAAS;oBACblB,OAAO;wBACL2C,MAAMF,MAAMZ,GAAG,CAAC,CAACe,OAAU,CAAA;gCACzB,CAAChD,KAAK,EAAE;oCACNiD,UAAU;oCACVC,QAAQF,KAAK5D,OAAO,CAAC,uBAAuB;gCAC9C;4BACF,CAAA;oBACF;gBACF;gBAEA,OAAOkC;YACT;YAEA,yDAAyD;YACzD,wDAAwD;YACxD,IAAI,CAACe,aAAa;gBAChB,OAAO;oBACLrC;oBACAI,OAAOD;gBACT;YACF;YAEA,OAAO;gBACLH;gBACAI,OAAO;oBAAE,CAACiC,YAAY,EAAElC;gBAAe;YACzC;QACF;IACF;IACA,OAAOgD;AACT"}
@@ -24,8 +24,7 @@
24
24
  /// <reference types="mongoose/types/inferschematype.js" />
25
25
  /// <reference types="mongoose-paginate-v2" />
26
26
  import type { PaginateOptions } from 'mongoose';
27
- import type { SanitizedConfig } from 'payload/config';
28
- import type { Field } from 'payload/types';
27
+ import type { Field, SanitizedConfig } from 'payload';
29
28
  type Args = {
30
29
  config: SanitizedConfig;
31
30
  fields: Field[];
@@ -1 +1 @@
1
- {"version":3,"file":"buildSortParam.d.ts","sourceRoot":"","sources":["../../src/queries/buildSortParam.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAI1C,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,SAAS,EAAE,aAAa,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;CACjB,EAAE,CAAA;AAEH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAA;AAE1C,eAAO,MAAM,cAAc,kDAMxB,IAAI,KAAG,eAAe,CAAC,MAAM,CA6B/B,CAAA"}
1
+ {"version":3,"file":"buildSortParam.d.ts","sourceRoot":"","sources":["../../src/queries/buildSortParam.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAIrD,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,SAAS,EAAE,aAAa,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;CACjB,EAAE,CAAA;AAEH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAA;AAE1C,eAAO,MAAM,cAAc,kDAMxB,IAAI,KAAG,eAAe,CAAC,MAAM,CA6B/B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildSortParam.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { SanitizedConfig } from 'payload/config'\nimport type { Field } from 'payload/types'\n\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\ntype Args = {\n config: SanitizedConfig\n fields: Field[]\n locale: string\n sort: string\n timestamps: boolean\n}\n\nexport type SortArgs = {\n direction: SortDirection\n property: string\n}[]\n\nexport type SortDirection = 'asc' | 'desc'\n\nexport const buildSortParam = ({\n config,\n fields,\n locale,\n sort,\n timestamps,\n}: Args): PaginateOptions['sort'] => {\n let sortProperty: string\n let sortDirection: SortDirection = 'desc'\n\n if (!sort) {\n if (timestamps) {\n sortProperty = 'createdAt'\n } else {\n sortProperty = '_id'\n }\n } else if (sort.indexOf('-') === 0) {\n sortProperty = sort.substring(1)\n } else {\n sortProperty = sort\n sortDirection = 'asc'\n }\n\n if (sortProperty === 'id') {\n sortProperty = '_id'\n } else {\n sortProperty = getLocalizedSortProperty({\n config,\n fields,\n locale,\n segments: sortProperty.split('.'),\n })\n }\n\n return { [sortProperty]: sortDirection }\n}\n"],"names":["getLocalizedSortProperty","buildSortParam","config","fields","locale","sort","timestamps","sortProperty","sortDirection","indexOf","substring","segments","split"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,wBAAwB,QAAQ,gCAA+B;AAiBxE,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,UAAU,EACL;IACL,IAAIC;IACJ,IAAIC,gBAA+B;IAEnC,IAAI,CAACH,MAAM;QACT,IAAIC,YAAY;YACdC,eAAe;QACjB,OAAO;YACLA,eAAe;QACjB;IACF,OAAO,IAAIF,KAAKI,OAAO,CAAC,SAAS,GAAG;QAClCF,eAAeF,KAAKK,SAAS,CAAC;IAChC,OAAO;QACLH,eAAeF;QACfG,gBAAgB;IAClB;IAEA,IAAID,iBAAiB,MAAM;QACzBA,eAAe;IACjB,OAAO;QACLA,eAAeP,yBAAyB;YACtCE;YACAC;YACAC;YACAO,UAAUJ,aAAaK,KAAK,CAAC;QAC/B;IACF;IAEA,OAAO;QAAE,CAACL,aAAa,EAAEC;IAAc;AACzC,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/buildSortParam.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Field, SanitizedConfig } from 'payload'\n\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\ntype Args = {\n config: SanitizedConfig\n fields: Field[]\n locale: string\n sort: string\n timestamps: boolean\n}\n\nexport type SortArgs = {\n direction: SortDirection\n property: string\n}[]\n\nexport type SortDirection = 'asc' | 'desc'\n\nexport const buildSortParam = ({\n config,\n fields,\n locale,\n sort,\n timestamps,\n}: Args): PaginateOptions['sort'] => {\n let sortProperty: string\n let sortDirection: SortDirection = 'desc'\n\n if (!sort) {\n if (timestamps) {\n sortProperty = 'createdAt'\n } else {\n sortProperty = '_id'\n }\n } else if (sort.indexOf('-') === 0) {\n sortProperty = sort.substring(1)\n } else {\n sortProperty = sort\n sortDirection = 'asc'\n }\n\n if (sortProperty === 'id') {\n sortProperty = '_id'\n } else {\n sortProperty = getLocalizedSortProperty({\n config,\n fields,\n locale,\n segments: sortProperty.split('.'),\n })\n }\n\n return { [sortProperty]: sortDirection }\n}\n"],"names":["getLocalizedSortProperty","buildSortParam","config","fields","locale","sort","timestamps","sortProperty","sortDirection","indexOf","substring","segments","split"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,wBAAwB,QAAQ,gCAA+B;AAiBxE,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,UAAU,EACL;IACL,IAAIC;IACJ,IAAIC,gBAA+B;IAEnC,IAAI,CAACH,MAAM;QACT,IAAIC,YAAY;YACdC,eAAe;QACjB,OAAO;YACLA,eAAe;QACjB;IACF,OAAO,IAAIF,KAAKI,OAAO,CAAC,SAAS,GAAG;QAClCF,eAAeF,KAAKK,SAAS,CAAC;IAChC,OAAO;QACLH,eAAeF;QACfG,gBAAgB;IAClB;IAEA,IAAID,iBAAiB,MAAM;QACzBA,eAAe;IACjB,OAAO;QACLA,eAAeP,yBAAyB;YACtCE;YACAC;YACAC;YACAO,UAAUJ,aAAaK,KAAK,CAAC;QAC/B;IACF;IAEA,OAAO;QAAE,CAACL,aAAa,EAAEC;IAAc;AACzC,EAAC"}