@payloadcms/db-mongodb 3.0.0-canary.a192632 → 3.0.0-canary.a5aaf21
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +7 -3
- package/dist/connect.js.map +1 -1
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +7 -1
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +10 -5
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +13 -4
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +14 -5
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteOne.js +1 -1
- package/dist/deleteOne.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +20 -3
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.js +1 -1
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +2 -2
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +19 -3
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.js +1 -1
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +9 -6
- package/dist/init.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +1 -2
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +7 -4
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.js +2 -2
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +1 -2
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +88 -11
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +2 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +1 -2
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +19 -11
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +3 -1
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +83 -24
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.js +1 -1
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +2 -0
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +3 -1
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/types.d.ts +5 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +8 -2
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts +2 -2
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +10 -3
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +8 -2
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +8 -1
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.d.ts +15 -0
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
- package/dist/utilities/buildJoinAggregation.js +148 -0
- package/dist/utilities/buildJoinAggregation.js.map +1 -0
- package/dist/utilities/getDBName.d.ts.map +1 -1
- package/dist/utilities/getDBName.js +3 -1
- package/dist/utilities/getDBName.js.map +1 -1
- package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
- package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
- package/dist/utilities/sanitizeInternalFields.js +1 -2
- package/dist/utilities/sanitizeInternalFields.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.js +111 -0
- package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
- package/dist/withSession.d.ts +1 -1
- package/dist/withSession.d.ts.map +1 -1
- package/dist/withSession.js +5 -3
- package/dist/withSession.js.map +1 -1
- package/package.json +9 -6
package/dist/index.js
CHANGED
@@ -37,8 +37,8 @@ export function mongooseAdapter({ autoPluralization = true, connectOptions, disa
|
|
37
37
|
// Mongoose-specific
|
38
38
|
autoPluralization,
|
39
39
|
collections: {},
|
40
|
-
connectOptions: connectOptions || {},
|
41
40
|
connection: undefined,
|
41
|
+
connectOptions: connectOptions || {},
|
42
42
|
count,
|
43
43
|
disableIndexHints,
|
44
44
|
globals: undefined,
|
@@ -69,6 +69,7 @@ export function mongooseAdapter({ autoPluralization = true, connectOptions, disa
|
|
69
69
|
init,
|
70
70
|
migrateFresh,
|
71
71
|
migrationDir,
|
72
|
+
packageName: '@payloadcms/db-mongodb',
|
72
73
|
payload,
|
73
74
|
prodMigrations,
|
74
75
|
queryDrafts,
|
@@ -103,7 +104,9 @@ export function mongooseAdapter({ autoPluralization = true, connectOptions, disa
|
|
103
104
|
const distDir = path.resolve(cwd, 'dist/migrations');
|
104
105
|
const relativeMigrations = path.resolve(cwd, 'migrations');
|
105
106
|
// Use arg if provided
|
106
|
-
if (migrationDir)
|
107
|
+
if (migrationDir) {
|
108
|
+
return migrationDir;
|
109
|
+
}
|
107
110
|
// Check other common locations
|
108
111
|
if (fs.existsSync(srcDir)) {
|
109
112
|
return srcDir;
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollationOptions, 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, MigrateDownArgs, MigrateUpArgs } 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 /**\n * If enabled, collation allows for language-specific rules for string comparison.\n * This configuration can include the following options:\n *\n * - `strength` (number): Comparison level (1: Primary, 2: Secondary, 3: Tertiary (default), 4: Quaternary, 5: Identical)\n * - `caseLevel` (boolean): Include case comparison at strength level 1 or 2.\n * - `caseFirst` (string): Sort order of case differences during tertiary level comparisons (\"upper\", \"lower\", \"off\").\n * - `numericOrdering` (boolean): Compare numeric strings as numbers.\n * - `alternate` (string): Consider whitespace and punctuation as base characters (\"non-ignorable\", \"shifted\").\n * - `maxVariable` (string): Characters considered ignorable when `alternate` is \"shifted\" (\"punct\", \"space\").\n * - `backwards` (boolean): Sort strings with diacritics from back of the string.\n * - `normalization` (boolean): Check if text requires normalization and perform normalization.\n *\n * Available on MongoDB version 3.4 and up.\n * The locale that gets passed is your current project's locale but defaults to \"en\".\n *\n * Example:\n * {\n * strength: 3\n * }\n *\n * Defaults to disabled.\n */\n collation?: Omit<CollationOptions, 'locale'>\n /** Extra configuration options */\n connectOptions?: {\n /** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */\n useFacet?: boolean\n } & ConnectOptions\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 prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\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 = {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n sessions: Record<number | string, ClientSession>\n versions: {\n [slug: string]: CollectionModel\n }\n} & Args &\n BaseDatabaseAdapter\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 prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\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 prodMigrations,\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 prodMigrations,\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","prodMigrations","transactionOptions","url","adapter","payload","findMigrationDir","set","name","collections","connection","undefined","globals","sessions","versions","defaultIDType","cwd","process","srcDir","resolve","distDir","relativeMigrations","existsSync"],"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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mBwB;YAC1DvB;YACApB;YACAE;YACAC;YACAC;YACAC;YACAC;YACAyC,eAAe;YACfxC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAa;YACAO;YACAJ;YACAf;YACAG;YACAC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAO;QACLsB,eAAe;QACf/B,MAAMoB;IACR;AACF;AAEA;;;;;;;;;;;;;CAaC,GACD,SAASE,iBAAiBR,YAAqB;IAC7C,MAAMkB,MAAMC,QAAQD,GAAG;IACvB,MAAME,SAASpD,KAAKqD,OAAO,CAACH,KAAK;IACjC,MAAMI,UAAUtD,KAAKqD,OAAO,CAACH,KAAK;IAClC,MAAMK,qBAAqBvD,KAAKqD,OAAO,CAACH,KAAK;IAE7C,sBAAsB;IACtB,IAAIlB,cAAc,OAAOA;IAEzB,+BAA+B;IAC/B,IAAIlC,GAAG0D,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAItD,GAAG0D,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAIxD,GAAG0D,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollationOptions, TransactionOptions } from 'mongodb'\nimport type { MongoMemoryReplSet } from 'mongodb-memory-server'\nimport type { ClientSession, Connection, ConnectOptions } 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, MigrateDownArgs, MigrateUpArgs } 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 /**\n * If enabled, collation allows for language-specific rules for string comparison.\n * This configuration can include the following options:\n *\n * - `strength` (number): Comparison level (1: Primary, 2: Secondary, 3: Tertiary (default), 4: Quaternary, 5: Identical)\n * - `caseLevel` (boolean): Include case comparison at strength level 1 or 2.\n * - `caseFirst` (string): Sort order of case differences during tertiary level comparisons (\"upper\", \"lower\", \"off\").\n * - `numericOrdering` (boolean): Compare numeric strings as numbers.\n * - `alternate` (string): Consider whitespace and punctuation as base characters (\"non-ignorable\", \"shifted\").\n * - `maxVariable` (string): Characters considered ignorable when `alternate` is \"shifted\" (\"punct\", \"space\").\n * - `backwards` (boolean): Sort strings with diacritics from back of the string.\n * - `normalization` (boolean): Check if text requires normalization and perform normalization.\n *\n * Available on MongoDB version 3.4 and up.\n * The locale that gets passed is your current project's locale but defaults to \"en\".\n *\n * Example:\n * {\n * strength: 3\n * }\n *\n * Defaults to disabled.\n */\n collation?: Omit<CollationOptions, 'locale'>\n /** Extra configuration options */\n connectOptions?: {\n /** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */\n useFacet?: boolean\n } & ConnectOptions\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 prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n transactionOptions?: false | TransactionOptions\n /** The URL to connect to MongoDB or false to start payload and prevent connecting */\n url: false | string\n}\n\nexport type MongooseAdapter = {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n sessions: Record<number | string, ClientSession>\n versions: {\n [slug: string]: CollectionModel\n }\n} & Args &\n BaseDatabaseAdapter\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 prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\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 prodMigrations,\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 connection: undefined,\n connectOptions: connectOptions || {},\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 packageName: '@payloadcms/db-mongodb',\n payload,\n prodMigrations,\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) {\n return migrationDir\n }\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","prodMigrations","transactionOptions","url","adapter","payload","findMigrationDir","set","name","collections","connection","undefined","globals","sessions","versions","defaultIDType","packageName","cwd","process","srcDir","resolve","distDir","relativeMigrations","existsSync"],"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,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,mBAAmB,QAAQ,wCAAuC;AAC3E,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,aAAa,QAAQ,qBAAoB;AA+FlD,OAAO,SAASC,gBAAg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,IAAIzD,GAAG2D,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
|
package/dist/init.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAA;
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAA;AAgB9D,eAAO,MAAM,IAAI,EAAE,IA8ElB,CAAA"}
|
package/dist/init.js
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
import mongoose from 'mongoose';
|
2
|
+
import mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';
|
2
3
|
import paginate from 'mongoose-paginate-v2';
|
3
4
|
import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
|
4
|
-
import buildCollectionSchema from './models/buildCollectionSchema.js';
|
5
|
+
import { buildCollectionSchema } from './models/buildCollectionSchema.js';
|
5
6
|
import { buildGlobalModel } from './models/buildGlobalModel.js';
|
6
|
-
import buildSchema from './models/buildSchema.js';
|
7
|
-
import getBuildQueryPlugin from './queries/buildQuery.js';
|
7
|
+
import { buildSchema } from './models/buildSchema.js';
|
8
|
+
import { getBuildQueryPlugin } from './queries/buildQuery.js';
|
8
9
|
import { getDBName } from './utilities/getDBName.js';
|
9
10
|
export const init = function init() {
|
10
11
|
this.payload.config.collections.forEach((collection)=>{
|
@@ -14,7 +15,7 @@ export const init = function init() {
|
|
14
15
|
config: collection,
|
15
16
|
versions: true
|
16
17
|
});
|
17
|
-
const versionCollectionFields = buildVersionCollectionFields(collection);
|
18
|
+
const versionCollectionFields = buildVersionCollectionFields(this.payload.config, collection);
|
18
19
|
const versionSchema = buildSchema(this.payload.config, versionCollectionFields, {
|
19
20
|
disableUnique: true,
|
20
21
|
draftsEnabled: true,
|
@@ -30,8 +31,10 @@ export const init = function init() {
|
|
30
31
|
collectionSlug: collection.slug,
|
31
32
|
versionsFields: versionCollectionFields
|
32
33
|
}));
|
34
|
+
if (Object.keys(collection.joins).length > 0) {
|
35
|
+
versionSchema.plugin(mongooseAggregatePaginate);
|
36
|
+
}
|
33
37
|
const model = mongoose.model(versionModelName, versionSchema, this.autoPluralization === true ? undefined : versionModelName);
|
34
|
-
// this.payload.versions[collection.slug] = model;
|
35
38
|
this.versions[collection.slug] = model;
|
36
39
|
}
|
37
40
|
const model = mongoose.model(getDBName({
|
@@ -47,7 +50,7 @@ export const init = function init() {
|
|
47
50
|
config: global,
|
48
51
|
versions: true
|
49
52
|
});
|
50
|
-
const versionGlobalFields = buildVersionGlobalFields(global);
|
53
|
+
const versionGlobalFields = buildVersionGlobalFields(this.payload.config, global);
|
51
54
|
const versionSchema = buildSchema(this.payload.config, versionGlobalFields, {
|
52
55
|
disableUnique: true,
|
53
56
|
draftsEnabled: true,
|
package/dist/init.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/init.ts"],"sourcesContent":["import 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
|
1
|
+
{"version":3,"sources":["../src/init.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Init, SanitizedCollectionConfig } from 'payload'\n\nimport mongoose from 'mongoose'\nimport mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2'\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(this.payload.config, 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 if (Object.keys(collection.joins).length > 0) {\n versionSchema.plugin(mongooseAggregatePaginate)\n }\n\n const model = mongoose.model(\n versionModelName,\n versionSchema,\n this.autoPluralization === true ? undefined : versionModelName,\n ) as CollectionModel\n\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(this.payload.config, 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","mongooseAggregatePaginate","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","Object","keys","joins","length","model","autoPluralization","undefined","globals","global","versionGlobalFields","versionsModel"],"mappings":"AAGA,OAAOA,cAAc,WAAU;AAC/B,OAAOC,+BAA+B,iCAAgC;AACtE,OAAOC,cAAc,uBAAsB;AAC3C,SAASC,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAKhF,SAASC,qBAAqB,QAAQ,oCAAmC;A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KAAK,OAAOC,YAAYvB,WAAWe,IAAI;QAE/D,IAAI,CAACjB,WAAW,CAACE,WAAWe,IAAI,CAAC,GAAGM;IACtC;IAEA,MAAMA,QAAQ9B,iBAAiB,IAAI,CAACK,OAAO,CAACC,MAAM;IAClD,IAAI,CAAC2B,OAAO,GAAGH;IAEf,IAAI,CAACzB,OAAO,CAACC,MAAM,CAAC2B,OAAO,CAACzB,OAAO,CAAC,CAAC0B;QACnC,IAAIA,OAAOvB,QAAQ,EAAE;YACnB,MAAMC,mBAAmBT,UAAU;gBAAEG,QAAQ4B;gBAAQvB,UAAU;YAAK;YAEpE,MAAMwB,sBAAsBrC,yBAAyB,IAAI,CAACO,OAAO,CAACC,MAAM,EAAE4B;YAE1E,MAAMpB,gBAAgBb,YAAY,IAAI,CAACI,OAAO,CAACC,MAAM,EAAE6B,qBAAqB;gBAC1EpB,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,gBAAgBU;YAAoB;YAEpE,MAAMC,gBAAgB1C,SAASoC,KAAK,CAClClB,kBACAE,eACAF;YAEF,IAAI,CAACD,QAAQ,CAACuB,OAAOV,IAAI,CAAC,GAAGY;QAC/B;IACF;AACF,EAAC"}
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import type { Schema } from 'mongoose';
|
2
2
|
import type { SanitizedCollectionConfig, SanitizedConfig } from 'payload';
|
3
|
-
declare const buildCollectionSchema: (collection: SanitizedCollectionConfig, config: SanitizedConfig, schemaOptions?: {}) => Schema;
|
4
|
-
export default buildCollectionSchema;
|
3
|
+
export declare const buildCollectionSchema: (collection: SanitizedCollectionConfig, config: SanitizedConfig, schemaOptions?: {}) => Schema;
|
5
4
|
//# 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,yBAAyB,EAAE,eAAe,EAAE,MAAM,SAAS,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;AAQzE,eAAO,MAAM,qBAAqB,eACpB,yBAAyB,UAC7B,eAAe,yBAEtB,MAqCF,CAAA"}
|
@@ -1,7 +1,8 @@
|
|
1
|
+
import mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';
|
1
2
|
import paginate from 'mongoose-paginate-v2';
|
2
|
-
import getBuildQueryPlugin from '../queries/buildQuery.js';
|
3
|
-
import buildSchema from './buildSchema.js';
|
4
|
-
const buildCollectionSchema = (collection, config, schemaOptions = {})=>{
|
3
|
+
import { getBuildQueryPlugin } from '../queries/buildQuery.js';
|
4
|
+
import { buildSchema } from './buildSchema.js';
|
5
|
+
export const buildCollectionSchema = (collection, config, schemaOptions = {})=>{
|
5
6
|
const schema = buildSchema(config, collection.fields, {
|
6
7
|
draftsEnabled: Boolean(typeof collection?.versions === 'object' && collection.versions.drafts),
|
7
8
|
indexSortableFields: config.indexSortableFields,
|
@@ -33,8 +34,10 @@ const buildCollectionSchema = (collection, config, schemaOptions = {})=>{
|
|
33
34
|
}).plugin(getBuildQueryPlugin({
|
34
35
|
collectionSlug: collection.slug
|
35
36
|
}));
|
37
|
+
if (Object.keys(collection.joins).length > 0) {
|
38
|
+
schema.plugin(mongooseAggregatePaginate);
|
39
|
+
}
|
36
40
|
return schema;
|
37
41
|
};
|
38
|
-
export default buildCollectionSchema;
|
39
42
|
|
40
43
|
//# sourceMappingURL=buildCollectionSchema.js.map
|
@@ -1 +1 @@
|
|
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\
|
1
|
+
{"version":3,"sources":["../../src/models/buildCollectionSchema.ts"],"sourcesContent":["import type { PaginateOptions, Schema } from 'mongoose'\nimport type { SanitizedCollectionConfig, SanitizedConfig } from 'payload'\n\nimport mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2'\nimport paginate from 'mongoose-paginate-v2'\n\nimport { getBuildQueryPlugin } from '../queries/buildQuery.js'\nimport { buildSchema } from './buildSchema.js'\n\nexport const 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 (Array.isArray(collection.upload.filenameCompoundIndex)) {\n const indexDefinition: Record<string, 1> = collection.upload.filenameCompoundIndex.reduce(\n (acc, index) => {\n acc[index] = 1\n return acc\n },\n {},\n )\n\n schema.index(indexDefinition, { unique: true })\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 if (Object.keys(collection.joins).length > 0) {\n schema.plugin(mongooseAggregatePaginate)\n }\n\n return schema\n}\n"],"names":["mongooseAggregatePaginate","paginate","getBuildQueryPlugin","buildSchema","buildCollectionSchema","collection","config","schemaOptions","schema","fields","draftsEnabled","Boolean","versions","drafts","indexSortableFields","options","minimize","timestamps","Array","isArray","upload","filenameCompoundIndex","indexDefinition","reduce","acc","index","unique","updatedAt","createdAt","plugin","useEstimatedCount","collectionSlug","slug","Object","keys","joins","length"],"mappings":"AAGA,OAAOA,+BAA+B,iCAAgC;AACtE,OAAOC,cAAc,uBAAsB;AAE3C,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,wBAAwB,CACnCC,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,IAAIW,MAAMC,OAAO,CAACd,WAAWe,MAAM,CAACC,qBAAqB,GAAG;QAC1D,MAAMC,kBAAqCjB,WAAWe,MAAM,CAACC,qBAAqB,CAACE,MAAM,CACvF,CAACC,KAAKC;YACJD,GAAG,CAACC,MAAM,GAAG;YACb,OAAOD;QACT,GACA,CAAC;QAGHhB,OAAOiB,KAAK,CAACH,iBAAiB;YAAEI,QAAQ;QAAK;IAC/C;IAEA,IAAIpB,OAAOQ,mBAAmB,IAAIT,WAAWY,UAAU,KAAK,OAAO;QACjET,OAAOiB,KAAK,CAAC;YAAEE,WAAW;QAAE;QAC5BnB,OAAOiB,KAAK,CAAC;YAAEG,WAAW;QAAE;IAC9B;IAEApB,OACGqB,MAAM,CAAuB5B,UAAU;QAAE6B,mBAAmB;IAAK,GACjED,MAAM,CAAC3B,oBAAoB;QAAE6B,gBAAgB1B,WAAW2B,IAAI;IAAC;IAEhE,IAAIC,OAAOC,IAAI,CAAC7B,WAAW8B,KAAK,EAAEC,MAAM,GAAG,GAAG;QAC5C5B,OAAOqB,MAAM,CAAC7B;IAChB;IAEA,OAAOQ;AACT,EAAC"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import mongoose from 'mongoose';
|
2
|
-
import getBuildQueryPlugin from '../queries/buildQuery.js';
|
3
|
-
import buildSchema from './buildSchema.js';
|
2
|
+
import { getBuildQueryPlugin } from '../queries/buildQuery.js';
|
3
|
+
import { buildSchema } from './buildSchema.js';
|
4
4
|
export const buildGlobalModel = (config)=>{
|
5
5
|
if (config.globals && config.globals.length > 0) {
|
6
6
|
const globalsSchema = new mongoose.Schema({}, {
|
@@ -1 +1 @@
|
|
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"],"mappings":"AAEA,OAAOA,cAAc,WAAU;AAI/B,
|
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"],"mappings":"AAEA,OAAOA,cAAc,WAAU;AAI/B,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,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"}
|
@@ -7,6 +7,5 @@ export type BuildSchemaOptions = {
|
|
7
7
|
indexSortableFields?: boolean;
|
8
8
|
options?: SchemaOptions;
|
9
9
|
};
|
10
|
-
declare const buildSchema: (config: SanitizedConfig, configFields: Field[], buildSchemaOptions?: BuildSchemaOptions) => Schema;
|
11
|
-
export default buildSchema;
|
10
|
+
export declare const buildSchema: (config: SanitizedConfig, configFields: Field[], buildSchemaOptions?: BuildSchemaOptions) => Schema;
|
12
11
|
//# sourceMappingURL=buildSchema.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,MAAM,EAAE,aAAa,EAAqB,MAAM,UAAU,CAAA;AACtF,OAAO,KAAK,EASV,KAAK,EAWL,eAAe,EAQhB,MAAM,SAAS,CAAA;
|
1
|
+
{"version":3,"file":"buildSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,MAAM,EAAE,aAAa,EAAqB,MAAM,UAAU,CAAA;AACtF,OAAO,KAAK,EASV,KAAK,EAWL,eAAe,EAQhB,MAAM,SAAS,CAAA;AAWhB,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;AAoED,eAAO,MAAM,WAAW,WACd,eAAe,gBACT,KAAK,EAAE,uBACD,kBAAkB,KACrC,MAmCF,CAAA"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import mongoose from 'mongoose';
|
2
|
-
import { fieldAffectsData, fieldIsLocalized, fieldIsPresentationalOnly, tabHasName } from 'payload/shared';
|
2
|
+
import { fieldAffectsData, fieldIsLocalized, fieldIsPresentationalOnly, fieldIsVirtual, tabHasName } from 'payload/shared';
|
3
3
|
/**
|
4
4
|
* get a field's defaultValue only if defined and not dynamic so that it can be set on the field schema
|
5
5
|
* @param field
|
@@ -34,7 +34,7 @@ const localizeSchema = (entity, schema, localization)=>{
|
|
34
34
|
}
|
35
35
|
return schema;
|
36
36
|
};
|
37
|
-
const buildSchema = (config, configFields, buildSchemaOptions = {})=>{
|
37
|
+
export const buildSchema = (config, configFields, buildSchemaOptions = {})=>{
|
38
38
|
const { allowIDField, options } = buildSchemaOptions;
|
39
39
|
let fields = {};
|
40
40
|
let schemaFields = configFields;
|
@@ -49,6 +49,9 @@ const buildSchema = (config, configFields, buildSchemaOptions = {})=>{
|
|
49
49
|
}
|
50
50
|
const schema = new mongoose.Schema(fields, options);
|
51
51
|
schemaFields.forEach((field)=>{
|
52
|
+
if (fieldIsVirtual(field)) {
|
53
|
+
return;
|
54
|
+
}
|
52
55
|
if (!fieldIsPresentationalOnly(field)) {
|
53
56
|
const addFieldSchema = fieldToSchemaMap[field.type];
|
54
57
|
if (addFieldSchema) {
|
@@ -244,7 +247,9 @@ const fieldToSchemaMap = {
|
|
244
247
|
...formatBaseSchema(field, buildSchemaOptions),
|
245
248
|
type: String,
|
246
249
|
enum: field.options.map((option)=>{
|
247
|
-
if (typeof option === 'object')
|
250
|
+
if (typeof option === 'object') {
|
251
|
+
return option.value;
|
252
|
+
}
|
248
253
|
return option;
|
249
254
|
})
|
250
255
|
};
|
@@ -355,7 +360,9 @@ const fieldToSchemaMap = {
|
|
355
360
|
...formatBaseSchema(field, buildSchemaOptions),
|
356
361
|
type: String,
|
357
362
|
enum: field.options.map((option)=>{
|
358
|
-
if (typeof option === 'object')
|
363
|
+
if (typeof option === 'object') {
|
364
|
+
return option.value;
|
365
|
+
}
|
359
366
|
return option;
|
360
367
|
})
|
361
368
|
};
|
@@ -416,16 +423,86 @@ const fieldToSchemaMap = {
|
|
416
423
|
});
|
417
424
|
},
|
418
425
|
upload: (field, schema, config, buildSchemaOptions)=>{
|
419
|
-
const
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
426
|
+
const hasManyRelations = Array.isArray(field.relationTo);
|
427
|
+
let schemaToReturn = {};
|
428
|
+
if (field.localized && config.localization) {
|
429
|
+
schemaToReturn = {
|
430
|
+
type: config.localization.localeCodes.reduce((locales, locale)=>{
|
431
|
+
let localeSchema = {};
|
432
|
+
if (hasManyRelations) {
|
433
|
+
localeSchema = {
|
434
|
+
...formatBaseSchema(field, buildSchemaOptions),
|
435
|
+
_id: false,
|
436
|
+
type: mongoose.Schema.Types.Mixed,
|
437
|
+
relationTo: {
|
438
|
+
type: String,
|
439
|
+
enum: field.relationTo
|
440
|
+
},
|
441
|
+
value: {
|
442
|
+
type: mongoose.Schema.Types.Mixed,
|
443
|
+
refPath: `${field.name}.${locale}.relationTo`
|
444
|
+
}
|
445
|
+
};
|
446
|
+
} else {
|
447
|
+
localeSchema = {
|
448
|
+
...formatBaseSchema(field, buildSchemaOptions),
|
449
|
+
type: mongoose.Schema.Types.Mixed,
|
450
|
+
ref: field.relationTo
|
451
|
+
};
|
452
|
+
}
|
453
|
+
return {
|
454
|
+
...locales,
|
455
|
+
[locale]: field.hasMany ? {
|
456
|
+
type: [
|
457
|
+
localeSchema
|
458
|
+
],
|
459
|
+
default: formatDefaultValue(field)
|
460
|
+
} : localeSchema
|
461
|
+
};
|
462
|
+
}, {}),
|
463
|
+
localized: true
|
464
|
+
};
|
465
|
+
} else if (hasManyRelations) {
|
466
|
+
schemaToReturn = {
|
467
|
+
...formatBaseSchema(field, buildSchemaOptions),
|
468
|
+
_id: false,
|
469
|
+
type: mongoose.Schema.Types.Mixed,
|
470
|
+
relationTo: {
|
471
|
+
type: String,
|
472
|
+
enum: field.relationTo
|
473
|
+
},
|
474
|
+
value: {
|
475
|
+
type: mongoose.Schema.Types.Mixed,
|
476
|
+
refPath: `${field.name}.relationTo`
|
477
|
+
}
|
478
|
+
};
|
479
|
+
if (field.hasMany) {
|
480
|
+
schemaToReturn = {
|
481
|
+
type: [
|
482
|
+
schemaToReturn
|
483
|
+
],
|
484
|
+
default: formatDefaultValue(field)
|
485
|
+
};
|
486
|
+
}
|
487
|
+
} else {
|
488
|
+
schemaToReturn = {
|
489
|
+
...formatBaseSchema(field, buildSchemaOptions),
|
490
|
+
type: mongoose.Schema.Types.Mixed,
|
491
|
+
ref: field.relationTo
|
492
|
+
};
|
493
|
+
if (field.hasMany) {
|
494
|
+
schemaToReturn = {
|
495
|
+
type: [
|
496
|
+
schemaToReturn
|
497
|
+
],
|
498
|
+
default: formatDefaultValue(field)
|
499
|
+
};
|
500
|
+
}
|
501
|
+
}
|
424
502
|
schema.add({
|
425
|
-
[field.name]:
|
503
|
+
[field.name]: schemaToReturn
|
426
504
|
});
|
427
505
|
}
|
428
506
|
};
|
429
|
-
export default buildSchema;
|
430
507
|
|
431
508
|
//# sourceMappingURL=buildSchema.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/models/buildSchema.ts"],"sourcesContent":["import 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\n/**\n * get a field's defaultValue only if defined and not dynamic so that it can be set on the field schema\n * @param field\n */\nconst formatDefaultValue = (field: FieldAffectingData) =>\n typeof field.defaultValue !== 'undefined' && typeof field.defaultValue !== 'function'\n ? field.defaultValue\n : undefined\n\nconst formatBaseSchema = (field: FieldAffectingData, buildSchemaOptions: BuildSchemaOptions) => {\n const { disableUnique, draftsEnabled, indexSortableFields } = buildSchemaOptions\n const schema: SchemaTypeOptions<unknown> = {\n default: formatDefaultValue(field),\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 }\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 }\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 // @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 // @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: formatDefaultValue(field),\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\n ? { type: [localeSchema], default: formatDefaultValue(field) }\n : 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: formatDefaultValue(field),\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: formatDefaultValue(field),\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","formatDefaultValue","field","defaultValue","undefined","formatBaseSchema","buildSchemaOptions","disableUnique","draftsEnabled","indexSortableFields","schema","default","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","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","indexOptions","radio","map","option","value","relationship","hasManyRelations","relationTo","schemaToReturn","refPath","ref","richText","row","select","push","tabs","tab","text","textarea","upload"],"mappings":"AA+BA,OAAOA,cAAc,WAAU;AAC/B,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,yBAAyB,EACzBC,UAAU,QACL,iBAAgB;AAiBvB;;;CAGC,GACD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AAG,CAAC;YACT,CAACjD,MAAMqC,IAAI,CAAC,EAAEpB,eAAejB,OAAO8C,YAAYjB,OAAOV,YAAY;QACrE;IACF;IACA8E,QAAQ,CACNjG,OACAQ,QACAqB,QACAzB;QAEA,MAAM0C,aAAa;YACjB,GAAG3C,iBAAiBH,OAAOI,mBAAmB;YAC9CU,MAAMpB,SAAS+C,MAAM,CAAC8B,KAAK,CAACC,KAAK;YACjCgB,KAAKxF,MAAMqF,UAAU;QACvB;QAEA7E,OAAOyC,GAAG,CAAC;YACT,CAACjD,MAAMqC,IAAI,CAAC,EAAEpB,eAAejB,OAAO8C,YAAYjB,OAAOV,YAAY;QACrE;IACF;AACF;AAEA,eAAeS,YAAW"}
|
1
|
+
{"version":3,"sources":["../../src/models/buildSchema.ts"],"sourcesContent":["import type { IndexOptions, Schema, SchemaOptions, SchemaTypeOptions } from 'mongoose'\nimport type {\n ArrayField,\n Block,\n BlocksField,\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 TextareaField,\n TextField,\n UploadField,\n} from 'payload'\n\nimport mongoose from 'mongoose'\nimport {\n fieldAffectsData,\n fieldIsLocalized,\n fieldIsPresentationalOnly,\n fieldIsVirtual,\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\n/**\n * get a field's defaultValue only if defined and not dynamic so that it can be set on the field schema\n * @param field\n */\nconst formatDefaultValue = (field: FieldAffectingData) =>\n typeof field.defaultValue !== 'undefined' && typeof field.defaultValue !== 'function'\n ? field.defaultValue\n : undefined\n\nconst formatBaseSchema = (field: FieldAffectingData, buildSchemaOptions: BuildSchemaOptions) => {\n const { disableUnique, draftsEnabled, indexSortableFields } = buildSchemaOptions\n const schema: SchemaTypeOptions<unknown> = {\n default: formatDefaultValue(field),\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: false | SanitizedLocalizationConfig,\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\nexport const 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 (fieldIsVirtual(field)) {\n return\n }\n\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 }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n blocks: (\n field: BlocksField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const fieldSchema = {\n type: [new mongoose.Schema({}, { _id: false, discriminatorKey: 'blockType' })],\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 // @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 // @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: formatDefaultValue(field),\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') {\n return option.value\n }\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\n ? { type: [localeSchema], default: formatDefaultValue(field) }\n : 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: formatDefaultValue(field),\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: formatDefaultValue(field),\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') {\n return option.value\n }\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 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\n ? { type: [localeSchema], default: formatDefaultValue(field) }\n : 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: formatDefaultValue(field),\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: formatDefaultValue(field),\n }\n }\n }\n\n schema.add({\n [field.name]: schemaToReturn,\n })\n },\n}\n"],"names":["mongoose","fieldAffectsData","fieldIsLocalized","fieldIsPresentationalOnly","fieldIsVirtual","tabHasName","formatDefaultValue","field","defaultValue","undefined","formatBaseSchema","buildSchemaOptions","disableUnique","draftsEnabled","indexSortableFields","schema","default","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","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","indexOptions","radio","map","option","value","relationship","hasManyRelations","relationTo","schemaToReturn","refPath","ref","richText","row","select","push","tabs","tab","text","textarea","upload"],"mappings":"AA+BA,OAAOA,cAAc,WAAU;AAC/B,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,yBAAyB,EACzBC,cAAc,EACdC,UAAU,QACL,iBAAgB;AAiBvB;;;CAGC,GACD,MAAMC,qBAAqB,CAACC,QAC1B,OAAOA,MAAMC,YAAY,KAAK,eAAe,OAAOD,MAAMC,YAAY,KAAK,aACvED,MAAMC,YAAY,GAClBC;AAEN,MAAMC,mBAAmB,CAACH,OAA2BI;IACnD,MAAM,EAAEC,aAAa,EAAEC,aAAa,EAAEC,mBAAmB,EAAE,GAAGH;IAC9D,MAAMI,SAAqC;QACzCC,SAASV,mBAAmBC;QAC5BU,OAAOV,MAAMU,KAAK,IAAK,CAACL,iBAAiBL,MAAMW,MAAM,IAAKJ,uBAAuB;QACjFK,UAAU;QACVD,QAAQ,AAAC,CAACN,iBAAiBL,MAAMW,MAAM,IAAK;IAC9C;IAEA,IACEH,OAAOG,MAAM,IACZX,CAAAA,MAAMa,SAAS,IACdP,iBACCZ,iBAAiBM,UAChBA,MAAMc,IAAI,KAAK,WACfd,MAAMc,IAAI,KAAK,SACfd,MAAMY,QAAQ,KAAK,IAAI,GAC3B;QACAJ,OAAOO,MAAM,GAAG;IAClB;IAEA,IAAIf,MAAM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,UAAU;YACvB;YAEA,IAAIrF,MAAM0E,OAAO,EAAE;gBACjBY,iBAAiB;oBACfxE,MAAM;wBAACwE;qBAAe;oBACtB7E,SAASV,mBAAmBC;gBAC9B;YACF;QACF;QAEAQ,OAAOyC,GAAG,CAAC;YACT,CAACjD,MAAMqC,IAAI,CAAC,EAAEiD;QAChB;IACF;AACF"}
|
@@ -9,6 +9,6 @@ export type BuildQueryArgs = {
|
|
9
9
|
payload: Payload;
|
10
10
|
where: Where;
|
11
11
|
};
|
12
|
-
declare const getBuildQueryPlugin: ({ collectionSlug, versionsFields }?: GetBuildQueryPluginArgs) => (schema: any) => void;
|
13
|
-
export
|
12
|
+
export declare const getBuildQueryPlugin: ({ collectionSlug, versionsFields, }?: GetBuildQueryPluginArgs) => (schema: any) => void;
|
13
|
+
export {};
|
14
14
|
//# sourceMappingURL=buildQuery.d.ts.map
|
@@ -1 +1 @@
|
|
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,
|
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,eAAO,MAAM,mBAAmB,yCAG7B,uBAAuB,0BAsCzB,CAAA"}
|
@@ -2,7 +2,7 @@ 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.
|
5
|
-
const getBuildQueryPlugin = ({ collectionSlug, versionsFields } = {})=>{
|
5
|
+
export const getBuildQueryPlugin = ({ collectionSlug, versionsFields } = {})=>{
|
6
6
|
return function buildQueryPlugin(schema) {
|
7
7
|
const modifiedSchema = schema;
|
8
8
|
async function buildQuery({ globalSlug, locale, payload, where }) {
|
@@ -34,6 +34,5 @@ const getBuildQueryPlugin = ({ collectionSlug, versionsFields } = {})=>{
|
|
34
34
|
modifiedSchema.statics.buildQuery = buildQuery;
|
35
35
|
};
|
36
36
|
};
|
37
|
-
export default getBuildQueryPlugin;
|
38
37
|
|
39
38
|
//# sourceMappingURL=buildQuery.js.map
|
@@ -1 +1 @@
|
|
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.\
|
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.\nexport const getBuildQueryPlugin = ({\n collectionSlug,\n versionsFields,\n}: 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"],"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"],"mappings":"AAEA,SAASA,UAAU,QAAQ,UAAS;AAEpC,SAASC,WAAW,QAAQ,mBAAkB;AAc9C,yEAAyE;AACzE,yDAAyD;AACzD,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,cAAc,EACdC,cAAc,EACU,GAAG,CAAC,CAAC;IAC7B,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,EAAC"}
|