@payloadcms/db-mongodb 3.0.0-canary.98e0119 → 3.0.0-canary.99cbde3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/init.js +4 -4
- package/dist/init.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +2 -2
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +4 -4
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts +2 -2
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +4 -4
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +2 -2
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +82 -61
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +12 -7
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/predefinedMigrations/relationships-v2-v3.js +1 -1
- package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -1
- package/dist/predefinedMigrations/versions-v1-v2.js +1 -1
- package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
- package/dist/queries/buildSearchParams.js +1 -0
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +3 -2
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +145 -36
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +2 -1
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +2 -1
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +2 -1
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.js +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.spec.js +408 -0
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
- package/package.json +3 -4
- package/dist/queries/mock.js +0 -2
- package/dist/queries/mock.js.map +0 -1
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { CollationOptions, TransactionOptions } from 'mongodb';
|
2
2
|
import type { MongoMemoryReplSet } from 'mongodb-memory-server';
|
3
3
|
import type { ClientSession, Connection, ConnectOptions, QueryOptions } from 'mongoose';
|
4
|
-
import type { BaseDatabaseAdapter, DatabaseAdapterObj, UpdateOneArgs } from 'payload';
|
4
|
+
import type { BaseDatabaseAdapter, DatabaseAdapterObj, TypeWithID, TypeWithVersion, UpdateGlobalArgs, UpdateGlobalVersionArgs, UpdateOneArgs, UpdateVersionArgs } from 'payload';
|
5
5
|
import type { CollectionModel, GlobalModel, MigrateDownArgs, MigrateUpArgs } from './types.js';
|
6
6
|
export type { MigrateDownArgs, MigrateUpArgs } from './types.js';
|
7
7
|
export interface Args {
|
@@ -91,9 +91,18 @@ declare module 'payload' {
|
|
91
91
|
}[];
|
92
92
|
sessions: Record<number | string, ClientSession>;
|
93
93
|
transactionOptions: TransactionOptions;
|
94
|
+
updateGlobal: <T extends Record<string, unknown>>(args: {
|
95
|
+
options?: QueryOptions;
|
96
|
+
} & UpdateGlobalArgs<T>) => Promise<T>;
|
97
|
+
updateGlobalVersion: <T extends TypeWithID = TypeWithID>(args: {
|
98
|
+
options?: QueryOptions;
|
99
|
+
} & UpdateGlobalVersionArgs<T>) => Promise<TypeWithVersion<T>>;
|
94
100
|
updateOne: (args: {
|
95
101
|
options?: QueryOptions;
|
96
102
|
} & UpdateOneArgs) => Promise<Document>;
|
103
|
+
updateVersion: <T extends TypeWithID = TypeWithID>(args: {
|
104
|
+
options?: QueryOptions;
|
105
|
+
} & UpdateVersionArgs<T>) => Promise<TypeWithVersion<T>>;
|
97
106
|
versions: {
|
98
107
|
[slug: string]: CollectionModel;
|
99
108
|
};
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvF,OAAO,KAAK,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvF,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAElB,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EAClB,MAAM,SAAS,CAAA;AAOhB,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAgC9F,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEhE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CAAA;SAAE,GAAG,uBAAuB,CAAC,CAAC,CAAC,KAC1D,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAA;QAChC,SAAS,EAAE,CAAC,IAAI,EAAE;YAAE,OAAO,CAAC,EAAE,YAAY,CAAA;SAAE,GAAG,aAAa,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;QAClF,aAAa,EAAE,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EAC/C,IAAI,EAAE;YAAE,OAAO,CAAC,EAAE,YAAY,CAAA;SAAE,GAAG,iBAAiB,CAAC,CAAC,CAAC,KACpD,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAA;QAChC,QAAQ,EAAE;YACR,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;SAChC,CAAA;KACF;CACF;AAED,wBAAgB,eAAe,CAAC,EAC9B,iBAAwB,EACxB,cAAc,EACd,iBAAyB,EACzB,aAAa,EACb,YAAY,EAAE,eAAe,EAC7B,iBAAiB,EACjB,cAAc,EACd,kBAAuB,EACvB,GAAG,GACJ,EAAE,IAAI,GAAG,kBAAkB,CA+D3B"}
|
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, Connection, ConnectOptions, QueryOptions } from 'mongoose'\nimport type { BaseDatabaseAdapter, DatabaseAdapterObj, Payload, UpdateOneArgs } from 'payload'\n\nimport fs from 'fs'\nimport mongoose from 'mongoose'\nimport path from 'path'\nimport { createDatabaseAdapter, defaultBeginTransaction } from 'payload'\n\nimport type { CollectionModel, GlobalModel, MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nimport { connect } from './connect.js'\nimport { count } from './count.js'\nimport { countGlobalVersions } from './countGlobalVersions.js'\nimport { countVersions } from './countVersions.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'\nimport { upsert } from './upsert.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\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 /**\n * Set to `true` to ensure that indexes are ready before completing connection.\n * NOTE: not recommended for production. This can slow down the initialization of Payload.\n */\n ensureIndexes?: 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 ensureIndexes: boolean\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 ensureIndexes: boolean\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 updateOne: (args: { options?: QueryOptions } & UpdateOneArgs) => Promise<Document>\n versions: {\n [slug: string]: CollectionModel\n }\n }\n}\n\nexport function mongooseAdapter({\n autoPluralization = true,\n connectOptions,\n disableIndexHints = false,\n ensureIndexes,\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 disableIndexHints,\n ensureIndexes,\n globals: undefined,\n mongoMemoryServer,\n sessions: {},\n transactionOptions: transactionOptions === false ? undefined : transactionOptions,\n url,\n versions: {},\n // DatabaseAdapter\n beginTransaction: transactionOptions === false ? defaultBeginTransaction() : beginTransaction,\n commitTransaction,\n connect,\n count,\n countGlobalVersions,\n countVersions,\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 upsert,\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","defaultBeginTransaction","connect","count","countGlobalVersions","countVersions","create","createGlobal","createGlobalVersion","createMigration","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findOne","findVersions","init","migrateFresh","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateGlobal","updateGlobalVersion","updateOne","updateVersion","upsert","mongooseAdapter","autoPluralization","connectOptions","disableIndexHints","ensureIndexes","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,EAAEC,uBAAuB,QAAQ,UAAS;AAIxE,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,KAAK,QAAQ,aAAY;AAClC,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,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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C;YACAe;YACAkB,aAAa;YACbX;YACAJ;YACAjB;YACAG;YACAC;YACAC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAO;QACLuB,eAAe;QACfjC,MAAMsB;IACR;AACF;AAEA;;;;;;;;;;;;;CAaC,GACD,SAASE,iBAAiBR,YAAqB;IAC7C,MAAMmB,MAAMC,QAAQD,GAAG;IACvB,MAAME,SAAS1D,KAAK2D,OAAO,CAACH,KAAK;IACjC,MAAMI,UAAU5D,KAAK2D,OAAO,CAACH,KAAK;IAClC,MAAMK,qBAAqB7D,KAAK2D,OAAO,CAACH,KAAK;IAE7C,sBAAsB;IACtB,IAAInB,cAAc;QAChB,OAAOA;IACT;IAEA,+BAA+B;IAC/B,IAAIvC,GAAGgE,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAI5D,GAAGgE,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAI9D,GAAGgE,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, QueryOptions } from 'mongoose'\nimport type {\n BaseDatabaseAdapter,\n DatabaseAdapterObj,\n Payload,\n TypeWithID,\n TypeWithVersion,\n UpdateGlobalArgs,\n UpdateGlobalVersionArgs,\n UpdateOneArgs,\n UpdateVersionArgs,\n} from 'payload'\n\nimport fs from 'fs'\nimport mongoose from 'mongoose'\nimport path from 'path'\nimport { createDatabaseAdapter, defaultBeginTransaction } from 'payload'\n\nimport type { CollectionModel, GlobalModel, MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nimport { connect } from './connect.js'\nimport { count } from './count.js'\nimport { countGlobalVersions } from './countGlobalVersions.js'\nimport { countVersions } from './countVersions.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'\nimport { upsert } from './upsert.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\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 /**\n * Set to `true` to ensure that indexes are ready before completing connection.\n * NOTE: not recommended for production. This can slow down the initialization of Payload.\n */\n ensureIndexes?: 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 ensureIndexes: boolean\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 ensureIndexes: boolean\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 updateGlobal: <T extends Record<string, unknown>>(\n args: { options?: QueryOptions } & UpdateGlobalArgs<T>,\n ) => Promise<T>\n updateGlobalVersion: <T extends TypeWithID = TypeWithID>(\n args: { options?: QueryOptions } & UpdateGlobalVersionArgs<T>,\n ) => Promise<TypeWithVersion<T>>\n updateOne: (args: { options?: QueryOptions } & UpdateOneArgs) => Promise<Document>\n updateVersion: <T extends TypeWithID = TypeWithID>(\n args: { options?: QueryOptions } & UpdateVersionArgs<T>,\n ) => Promise<TypeWithVersion<T>>\n versions: {\n [slug: string]: CollectionModel\n }\n }\n}\n\nexport function mongooseAdapter({\n autoPluralization = true,\n connectOptions,\n disableIndexHints = false,\n ensureIndexes,\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 disableIndexHints,\n ensureIndexes,\n globals: undefined,\n mongoMemoryServer,\n sessions: {},\n transactionOptions: transactionOptions === false ? undefined : transactionOptions,\n url,\n versions: {},\n // DatabaseAdapter\n beginTransaction: transactionOptions === false ? defaultBeginTransaction() : beginTransaction,\n commitTransaction,\n connect,\n count,\n countGlobalVersions,\n countVersions,\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 upsert,\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","defaultBeginTransaction","connect","count","countGlobalVersions","countVersions","create","createGlobal","createGlobalVersion","createMigration","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findOne","findVersions","init","migrateFresh","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateGlobal","updateGlobalVersion","updateOne","updateVersion","upsert","mongooseAdapter","autoPluralization","connectOptions","disableIndexHints","ensureIndexes","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":"AAeA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,cAAc,WAAU;AAC/B,OAAOC,UAAU,OAAM;AACvB,SAASC,qBAAqB,EAAEC,uBAAuB,QAAQ,UAAS;AAIxE,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,KAAK,QAAQ,aAAY;AAClC,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;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AoBA,uBAAuB,QAAQS,YAAYT;YAC/DC;YACAW,UAAU,CAAC;YACX,kBAAkB;YAClB7B,kBAAkBiB,uBAAuB,QAAQvC,4BAA4BsB;YAC7EC;YACAtB;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACA2C,eAAe;YACf1C;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAe;YACAkB,aAAa;YACbX;YACAJ;YACAjB;YACAG;YACAC;YACAC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAO;QACLuB,eAAe;QACfjC,MAAMsB;IACR;AACF;AAEA;;;;;;;;;;;;;CAaC,GACD,SAASE,iBAAiBR,YAAqB;IAC7C,MAAMmB,MAAMC,QAAQD,GAAG;IACvB,MAAME,SAAS1D,KAAK2D,OAAO,CAACH,KAAK;IACjC,MAAMI,UAAU5D,KAAK2D,OAAO,CAACH,KAAK;IAClC,MAAMK,qBAAqB7D,KAAK2D,OAAO,CAACH,KAAK;IAE7C,sBAAsB;IACtB,IAAInB,cAAc;QAChB,OAAOA;IACT;IAEA,+BAA+B;IAC/B,IAAIvC,GAAGgE,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAI5D,GAAGgE,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAI9D,GAAGgE,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
|
package/dist/init.js
CHANGED
@@ -9,14 +9,14 @@ import { getBuildQueryPlugin } from './queries/buildQuery.js';
|
|
9
9
|
import { getDBName } from './utilities/getDBName.js';
|
10
10
|
export const init = function init() {
|
11
11
|
this.payload.config.collections.forEach((collection)=>{
|
12
|
-
const schema = buildCollectionSchema(collection, this.payload
|
12
|
+
const schema = buildCollectionSchema(collection, this.payload);
|
13
13
|
if (collection.versions) {
|
14
14
|
const versionModelName = getDBName({
|
15
15
|
config: collection,
|
16
16
|
versions: true
|
17
17
|
});
|
18
18
|
const versionCollectionFields = buildVersionCollectionFields(this.payload.config, collection);
|
19
|
-
const versionSchema = buildSchema(this.payload
|
19
|
+
const versionSchema = buildSchema(this.payload, versionCollectionFields, {
|
20
20
|
disableUnique: true,
|
21
21
|
draftsEnabled: true,
|
22
22
|
indexSortableFields: this.payload.config.indexSortableFields,
|
@@ -43,7 +43,7 @@ export const init = function init() {
|
|
43
43
|
const collectionName = this.autoPluralization === true && !collection.dbName ? undefined : modelName;
|
44
44
|
this.collections[collection.slug] = mongoose.model(modelName, schema, collectionName);
|
45
45
|
});
|
46
|
-
this.globals = buildGlobalModel(this.payload
|
46
|
+
this.globals = buildGlobalModel(this.payload);
|
47
47
|
this.payload.config.globals.forEach((global)=>{
|
48
48
|
if (global.versions) {
|
49
49
|
const versionModelName = getDBName({
|
@@ -51,7 +51,7 @@ export const init = function init() {
|
|
51
51
|
versions: true
|
52
52
|
});
|
53
53
|
const versionGlobalFields = buildVersionGlobalFields(this.payload.config, global);
|
54
|
-
const versionSchema = buildSchema(this.payload
|
54
|
+
const versionSchema = buildSchema(this.payload, versionGlobalFields, {
|
55
55
|
disableUnique: true,
|
56
56
|
draftsEnabled: true,
|
57
57
|
indexSortableFields: this.payload.config.indexSortableFields,
|
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 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
|
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)\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, 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 versionCollectionName =\n this.autoPluralization === true && !collection.dbName ? undefined : versionModelName\n\n this.versions[collection.slug] = mongoose.model(\n versionModelName,\n versionSchema,\n versionCollectionName,\n ) as CollectionModel\n }\n\n const modelName = getDBName({ config: collection })\n const collectionName =\n this.autoPluralization === true && !collection.dbName ? undefined : modelName\n\n this.collections[collection.slug] = mongoose.model(\n modelName,\n schema,\n collectionName,\n ) as CollectionModel\n })\n\n this.globals = buildGlobalModel(this.payload)\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, 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 this.versions[global.slug] = mongoose.model(\n versionModelName,\n versionSchema,\n versionModelName,\n ) as CollectionModel\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","versionCollectionName","autoPluralization","dbName","undefined","model","modelName","collectionName","globals","global","versionGlobalFields"],"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;AACzE,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,SAASC,WAAW,QAAQ,0BAAyB;AACrD,SAASC,mBAAmB,QAAQ,0BAAyB;AAC7D,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,OAAa,SAASA;IACjC,IA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B,IAAI,CAACK,OAAO;IAE5C,IAAI,CAACA,OAAO,CAACC,MAAM,CAAC+B,OAAO,CAAC7B,OAAO,CAAC,CAAC8B;QACnC,IAAIA,OAAO3B,QAAQ,EAAE;YACnB,MAAMC,mBAAmBT,UAAU;gBAAEG,QAAQgC;gBAAQ3B,UAAU;YAAK;YAEpE,MAAM4B,sBAAsBzC,yBAAyB,IAAI,CAACO,OAAO,CAACC,MAAM,EAAEgC;YAE1E,MAAMxB,gBAAgBb,YAAY,IAAI,CAACI,OAAO,EAAEkC,qBAAqB;gBACnExB,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,gBAAgBc;YAAoB;YAEpE,IAAI,CAAC5B,QAAQ,CAAC2B,OAAOd,IAAI,CAAC,GAAG9B,SAASwC,KAAK,CACzCtB,kBACAE,eACAF;QAEJ;IACF;AACF,EAAC"}
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import type { Schema } from 'mongoose';
|
2
|
-
import type {
|
3
|
-
export declare const buildCollectionSchema: (collection: SanitizedCollectionConfig,
|
2
|
+
import type { Payload, SanitizedCollectionConfig } from 'payload';
|
3
|
+
export declare const buildCollectionSchema: (collection: SanitizedCollectionConfig, payload: Payload, schemaOptions?: {}) => Schema;
|
4
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,
|
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,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAQjE,eAAO,MAAM,qBAAqB,eACpB,yBAAyB,WAC5B,OAAO,yBAEf,MAqCF,CAAA"}
|
@@ -2,10 +2,10 @@ import mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';
|
|
2
2
|
import paginate from 'mongoose-paginate-v2';
|
3
3
|
import { getBuildQueryPlugin } from '../queries/buildQuery.js';
|
4
4
|
import { buildSchema } from './buildSchema.js';
|
5
|
-
export const buildCollectionSchema = (collection,
|
6
|
-
const schema = buildSchema(
|
5
|
+
export const buildCollectionSchema = (collection, payload, schemaOptions = {})=>{
|
6
|
+
const schema = buildSchema(payload, collection.fields, {
|
7
7
|
draftsEnabled: Boolean(typeof collection?.versions === 'object' && collection.versions.drafts),
|
8
|
-
indexSortableFields: config.indexSortableFields,
|
8
|
+
indexSortableFields: payload.config.indexSortableFields,
|
9
9
|
options: {
|
10
10
|
minimize: false,
|
11
11
|
timestamps: collection.timestamps !== false,
|
@@ -21,7 +21,7 @@ export const buildCollectionSchema = (collection, config, schemaOptions = {})=>{
|
|
21
21
|
unique: true
|
22
22
|
});
|
23
23
|
}
|
24
|
-
if (config.indexSortableFields && collection.timestamps !== false) {
|
24
|
+
if (payload.config.indexSortableFields && collection.timestamps !== false) {
|
25
25
|
schema.index({
|
26
26
|
updatedAt: 1
|
27
27
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/models/buildCollectionSchema.ts"],"sourcesContent":["import type { PaginateOptions, Schema } from 'mongoose'\nimport type {
|
1
|
+
{"version":3,"sources":["../../src/models/buildCollectionSchema.ts"],"sourcesContent":["import type { PaginateOptions, Schema } from 'mongoose'\nimport type { Payload, SanitizedCollectionConfig } 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 payload: Payload,\n schemaOptions = {},\n): Schema => {\n const schema = buildSchema(payload, collection.fields, {\n draftsEnabled: Boolean(typeof collection?.versions === 'object' && collection.versions.drafts),\n indexSortableFields: payload.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 (payload.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","payload","schemaOptions","schema","fields","draftsEnabled","Boolean","versions","drafts","indexSortableFields","config","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,SACAC,gBAAgB,CAAC,CAAC;IAElB,MAAMC,SAASL,YAAYG,SAASD,WAAWI,MAAM,EAAE;QACrDC,eAAeC,QAAQ,OAAON,YAAYO,aAAa,YAAYP,WAAWO,QAAQ,CAACC,MAAM;QAC7FC,qBAAqBR,QAAQS,MAAM,CAACD,mBAAmB;QACvDE,SAAS;YACPC,UAAU;YACVC,YAAYb,WAAWa,UAAU,KAAK;YACtC,GAAGX,aAAa;QAClB;IACF;IAEA,IAAIY,MAAMC,OAAO,CAACf,WAAWgB,MAAM,CAACC,qBAAqB,GAAG;QAC1D,MAAMC,kBAAqClB,WAAWgB,MAAM,CAACC,qBAAqB,CAACE,MAAM,CACvF,CAACC,KAAKC;YACJD,GAAG,CAACC,MAAM,GAAG;YACb,OAAOD;QACT,GACA,CAAC;QAGHjB,OAAOkB,KAAK,CAACH,iBAAiB;YAAEI,QAAQ;QAAK;IAC/C;IAEA,IAAIrB,QAAQS,MAAM,CAACD,mBAAmB,IAAIT,WAAWa,UAAU,KAAK,OAAO;QACzEV,OAAOkB,KAAK,CAAC;YAAEE,WAAW;QAAE;QAC5BpB,OAAOkB,KAAK,CAAC;YAAEG,WAAW;QAAE;IAC9B;IAEArB,OACGsB,MAAM,CAAuB7B,UAAU;QAAE8B,mBAAmB;IAAK,GACjED,MAAM,CAAC5B,oBAAoB;QAAE8B,gBAAgB3B,WAAW4B,IAAI;IAAC;IAEhE,IAAIC,OAAOC,IAAI,CAAC9B,WAAW+B,KAAK,EAAEC,MAAM,GAAG,GAAG;QAC5C7B,OAAOsB,MAAM,CAAC9B;IAChB;IAEA,OAAOQ;AACT,EAAC"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type {
|
1
|
+
import type { Payload } from 'payload';
|
2
2
|
import type { GlobalModel } from '../types.js';
|
3
|
-
export declare const buildGlobalModel: (
|
3
|
+
export declare const buildGlobalModel: (payload: Payload) => 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,
|
1
|
+
{"version":3,"file":"buildGlobalModel.d.ts","sourceRoot":"","sources":["../../src/models/buildGlobalModel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAItC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAK9C,eAAO,MAAM,gBAAgB,YAAa,OAAO,KAAG,WAAW,GAAG,IAwBjE,CAAA"}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import mongoose from 'mongoose';
|
2
2
|
import { getBuildQueryPlugin } from '../queries/buildQuery.js';
|
3
3
|
import { buildSchema } from './buildSchema.js';
|
4
|
-
export const buildGlobalModel = (
|
5
|
-
if (config.globals && config.globals.length > 0) {
|
4
|
+
export const buildGlobalModel = (payload)=>{
|
5
|
+
if (payload.config.globals && payload.config.globals.length > 0) {
|
6
6
|
const globalsSchema = new mongoose.Schema({}, {
|
7
7
|
discriminatorKey: 'globalType',
|
8
8
|
minimize: false,
|
@@ -10,8 +10,8 @@ export const buildGlobalModel = (config)=>{
|
|
10
10
|
});
|
11
11
|
globalsSchema.plugin(getBuildQueryPlugin());
|
12
12
|
const Globals = mongoose.model('globals', globalsSchema, 'globals');
|
13
|
-
Object.values(config.globals).forEach((globalConfig)=>{
|
14
|
-
const globalSchema = buildSchema(
|
13
|
+
Object.values(payload.config.globals).forEach((globalConfig)=>{
|
14
|
+
const globalSchema = buildSchema(payload, globalConfig.fields, {
|
15
15
|
options: {
|
16
16
|
minimize: false
|
17
17
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/models/buildGlobalModel.ts"],"sourcesContent":["import type {
|
1
|
+
{"version":3,"sources":["../../src/models/buildGlobalModel.ts"],"sourcesContent":["import type { Payload } 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 = (payload: Payload): GlobalModel | null => {\n if (payload.config.globals && payload.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(payload.config.globals).forEach((globalConfig) => {\n const globalSchema = buildSchema(payload, 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","payload","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,QAAQC,MAAM,CAACC,OAAO,IAAIF,QAAQC,MAAM,CAACC,OAAO,CAACC,MAAM,GAAG,GAAG;QAC/D,MAAMC,gBAAgB,IAAIR,SAASS,MAAM,CACvC,CAAC,GACD;YAAEC,kBAAkB;YAAcC,UAAU;YAAOC,YAAY;QAAK;QAGtEJ,cAAcK,MAAM,CAACZ;QAErB,MAAMa,UAAUd,SAASe,KAAK,CAAC,WAAWP,eAAe;QAEzDQ,OAAOC,MAAM,CAACb,QAAQC,MAAM,CAACC,OAAO,EAAEY,OAAO,CAAC,CAACC;YAC7C,MAAMC,eAAelB,YAAYE,SAASe,aAAaE,MAAM,EAAE;gBAC7DC,SAAS;oBACPX,UAAU;gBACZ;YACF;YACAG,QAAQS,aAAa,CAACJ,aAAaK,IAAI,EAAEJ;QAC3C;QAEA,OAAON;IACT;IAEA,OAAO;AACT,EAAC"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { Schema, SchemaOptions } from 'mongoose';
|
2
|
-
import type
|
2
|
+
import { type Field, type Payload } from 'payload';
|
3
3
|
export type BuildSchemaOptions = {
|
4
4
|
allowIDField?: boolean;
|
5
5
|
disableUnique?: boolean;
|
@@ -7,5 +7,5 @@ export type BuildSchemaOptions = {
|
|
7
7
|
indexSortableFields?: boolean;
|
8
8
|
options?: SchemaOptions;
|
9
9
|
};
|
10
|
-
export declare const buildSchema: (
|
10
|
+
export declare const buildSchema: (payload: Payload, configFields: Field[], buildSchemaOptions?: BuildSchemaOptions) => Schema;
|
11
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;
|
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;AAGtF,OAAO,EASL,KAAK,KAAK,EAMV,KAAK,OAAO,EAab,MAAM,SAAS,CAAA;AAShB,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,YACb,OAAO,gBACF,KAAK,EAAE,uBACD,kBAAkB,KACrC,MAmCF,CAAA"}
|