@payloadcms/db-mongodb 3.28.0-canary.8f6d2e7 → 3.28.0-internal.2b0876e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/updateVersion.js +1 -1
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/transform.d.ts.map +1 -1
- package/dist/utilities/transform.js +131 -1
- package/dist/utilities/transform.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,13 @@ import type { BaseDatabaseAdapter, CollectionSlug, DatabaseAdapterObj, Migration
|
|
|
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 {
|
|
8
|
+
/**
|
|
9
|
+
* By default, Payload strips all additional keys from MongoDB data that don't exist
|
|
10
|
+
* in the Payload schema. If you have some data that you want to include to the result
|
|
11
|
+
* but it doesn't exist in Payload, you can enable this flag
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
allowAdditionalKeys?: boolean;
|
|
8
15
|
/** Set to false to disable auto-pluralization of collection names, Defaults to true */
|
|
9
16
|
autoPluralization?: boolean;
|
|
10
17
|
/**
|
|
@@ -108,5 +115,5 @@ declare module 'payload' {
|
|
|
108
115
|
};
|
|
109
116
|
}
|
|
110
117
|
}
|
|
111
|
-
export declare function mongooseAdapter({ autoPluralization, collectionsSchemaOptions, connectOptions, disableIndexHints, ensureIndexes, migrationDir: migrationDirArg, mongoMemoryServer, prodMigrations, transactionOptions, url, }: Args): DatabaseAdapterObj;
|
|
118
|
+
export declare function mongooseAdapter({ allowAdditionalKeys, autoPluralization, collectionsSchemaOptions, connectOptions, disableIndexHints, ensureIndexes, migrationDir: migrationDirArg, mongoMemoryServer, prodMigrations, transactionOptions, url, }: Args): DatabaseAdapterObj;
|
|
112
119
|
//# sourceMappingURL=index.d.ts.map
|
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,EACV,aAAa,EACb,UAAU,EACV,cAAc,EACd,YAAY,EACZ,aAAa,EACd,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EACV,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,SAAS,EAET,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EAEvB,aAAa,EACb,iBAAiB,EAClB,MAAM,SAAS,CAAA;AAOhB,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAiC9F,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEhE,MAAM,WAAW,IAAI;IACnB,uFAAuF;IACvF,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAA;
|
|
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,EACV,aAAa,EACb,UAAU,EACV,cAAc,EACd,YAAY,EACZ,aAAa,EACd,MAAM,UAA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AAE,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9C,IAAI,EAAE;YAAE,OAAO,CAAC,EAAE,YAAY,CAAA;SAAE,GAAG,gBAAgB,CAAC,CAAC,CAAC,KACnD,OAAO,CAAC,CAAC,CAAC,CAAA;QACf,mBAAmB,EAAE,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EACrD,IAAI,EAAE;YAAE,OAAO,CAAC,EAAE,YAAY,CAAA;SAAE,GAAG,uBAAuB,CAAC,CAAC,CAAC,KAC1D,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAA;QAEhC,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,mBAA2B,EAC3B,iBAAwB,EACxB,wBAA6B,EAC7B,cAAc,EACd,iBAAyB,EACzB,aAAqB,EACrB,YAAY,EAAE,eAAe,EAC7B,iBAAiB,EACjB,cAAc,EACd,kBAAuB,EACvB,GAAG,GACJ,EAAE,IAAI,GAAG,kBAAkB,CAqE3B"}
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ import { updateMany } from './updateMany.js';
|
|
|
32
32
|
import { updateOne } from './updateOne.js';
|
|
33
33
|
import { updateVersion } from './updateVersion.js';
|
|
34
34
|
import { upsert } from './upsert.js';
|
|
35
|
-
export function mongooseAdapter({ autoPluralization = true, collectionsSchemaOptions = {}, connectOptions, disableIndexHints = false, ensureIndexes = false, migrationDir: migrationDirArg, mongoMemoryServer, prodMigrations, transactionOptions = {}, url }) {
|
|
35
|
+
export function mongooseAdapter({ allowAdditionalKeys = false, autoPluralization = true, collectionsSchemaOptions = {}, connectOptions, disableIndexHints = false, ensureIndexes = false, migrationDir: migrationDirArg, mongoMemoryServer, prodMigrations, transactionOptions = {}, url }) {
|
|
36
36
|
function adapter({ payload }) {
|
|
37
37
|
const migrationDir = findMigrationDir(migrationDirArg);
|
|
38
38
|
mongoose.set('strictQuery', false);
|
|
@@ -56,6 +56,7 @@ export function mongooseAdapter({ autoPluralization = true, collectionsSchemaOpt
|
|
|
56
56
|
url,
|
|
57
57
|
versions: {},
|
|
58
58
|
// DatabaseAdapter
|
|
59
|
+
allowAdditionalKeys,
|
|
59
60
|
beginTransaction: transactionOptions === false ? defaultBeginTransaction() : beginTransaction,
|
|
60
61
|
collectionsSchemaOptions,
|
|
61
62
|
commitTransaction,
|
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 {\n ClientSession,\n Connection,\n ConnectOptions,\n QueryOptions,\n SchemaOptions,\n} from 'mongoose'\nimport type {\n BaseDatabaseAdapter,\n CollectionSlug,\n DatabaseAdapterObj,\n Migration,\n Payload,\n TypeWithID,\n TypeWithVersion,\n UpdateGlobalArgs,\n UpdateGlobalVersionArgs,\n UpdateManyArgs,\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 { updateMany } from './updateMany.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 collectionsSchemaOptions?: Partial<Record<CollectionSlug, SchemaOptions>>\n\n /** Extra configuration options */\n connectOptions?: {\n /**\n * Set false to disable $facet aggregation in non-supporting databases, Defaults to true\n * @deprecated Payload doesn't use `$facet` anymore anywhere.\n */\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 /**\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?: Migration[]\n transactionOptions?: false | TransactionOptions\n\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\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 collectionsSchemaOptions = {},\n connectOptions,\n disableIndexHints = false,\n ensureIndexes = 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 // @ts-expect-error initialize without a connection\n connection: undefined,\n connectOptions: connectOptions || {},\n disableIndexHints,\n ensureIndexes,\n // @ts-expect-error don't have globals model yet\n globals: undefined,\n // @ts-expect-error Should not be required\n mongoMemoryServer,\n sessions: {},\n transactionOptions: transactionOptions === false ? undefined : transactionOptions,\n updateMany,\n url,\n versions: {},\n // DatabaseAdapter\n beginTransaction: transactionOptions === false ? defaultBeginTransaction() : beginTransaction,\n collectionsSchemaOptions,\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","updateMany","updateOne","updateVersion","upsert","mongooseAdapter","autoPluralization","collectionsSchemaOptions","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":"AAwBA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,cAAc,WAAU;AAC/B,OAAOC,UAAU,OAAM;AACvB,SAASC,qB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AIhE,GAAGkE,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 {\n ClientSession,\n Connection,\n ConnectOptions,\n QueryOptions,\n SchemaOptions,\n} from 'mongoose'\nimport type {\n BaseDatabaseAdapter,\n CollectionSlug,\n DatabaseAdapterObj,\n Migration,\n Payload,\n TypeWithID,\n TypeWithVersion,\n UpdateGlobalArgs,\n UpdateGlobalVersionArgs,\n UpdateManyArgs,\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 { updateMany } from './updateMany.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 /**\n * By default, Payload strips all additional keys from MongoDB data that don't exist\n * in the Payload schema. If you have some data that you want to include to the result\n * but it doesn't exist in Payload, you can enable this flag\n * @default false\n */\n allowAdditionalKeys?: boolean\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\n collectionsSchemaOptions?: Partial<Record<CollectionSlug, SchemaOptions>>\n\n /** Extra configuration options */\n connectOptions?: {\n /**\n * Set false to disable $facet aggregation in non-supporting databases, Defaults to true\n * @deprecated Payload doesn't use `$facet` anymore anywhere.\n */\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 /**\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?: Migration[]\n transactionOptions?: false | TransactionOptions\n\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\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 allowAdditionalKeys = false,\n autoPluralization = true,\n collectionsSchemaOptions = {},\n connectOptions,\n disableIndexHints = false,\n ensureIndexes = 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 // @ts-expect-error initialize without a connection\n connection: undefined,\n connectOptions: connectOptions || {},\n disableIndexHints,\n ensureIndexes,\n // @ts-expect-error don't have globals model yet\n globals: undefined,\n // @ts-expect-error Should not be required\n mongoMemoryServer,\n sessions: {},\n transactionOptions: transactionOptions === false ? undefined : transactionOptions,\n updateMany,\n url,\n versions: {},\n // DatabaseAdapter\n allowAdditionalKeys,\n beginTransaction: transactionOptions === false ? defaultBeginTransaction() : beginTransaction,\n collectionsSchemaOptions,\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","updateMany","updateOne","updateVersion","upsert","mongooseAdapter","allowAdditionalKeys","autoPluralization","collectionsSchemaOptions","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":"AAwBA,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,c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uB,QAAQS,YAAYT;YAC/Df;YACAgB;YACAW,UAAU,CAAC;YACX,kBAAkB;YAClBtB;YACAV,kBAAkBoB,uBAAuB,QAAQ1C,4BAA4BsB;YAC7EY;YACAX;YACAtB;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACA8C,eAAe;YACf7C;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAkB;YACAkB,aAAa;YACbX;YACAJ;YACApB;YACAG;YACAC;YACAC;YACAE;YACAC;YACAC;QACF;IACF;IAEA,OAAO;QACLyB,eAAe;QACfpC,MAAMyB;IACR;AACF;AAEA;;;;;;;;;;;;;CAaC,GACD,SAASE,iBAAiBR,YAAqB;IAC7C,MAAMmB,MAAMC,QAAQD,GAAG;IACvB,MAAME,SAAS7D,KAAK8D,OAAO,CAACH,KAAK;IACjC,MAAMI,UAAU/D,KAAK8D,OAAO,CAACH,KAAK;IAClC,MAAMK,qBAAqBhE,KAAK8D,OAAO,CAACH,KAAK;IAE7C,sBAAsB;IACtB,IAAInB,cAAc;QAChB,OAAOA;IACT;IAEA,+BAA+B;IAC/B,IAAI1C,GAAGmE,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAI/D,GAAGmE,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAIjE,GAAGmE,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
|
package/dist/updateVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { MongooseUpdateQueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n {\n id,\n collection: collectionSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n const flattenedFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n\n const options: MongooseUpdateQueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n where: whereToUse,\n })\n\n transform({ adapter: this, data: versionData, fields, operation: 'write' })\n\n if (returning === false) {\n await Model.updateOne(query, versionData, options)\n return null\n }\n\n const doc = await Model.findOneAndUpdate(query, versionData, options)\n\n if (!doc) {\n return null\n }\n\n transform({ adapter: this, data: doc, fields, operation: '
|
|
1
|
+
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { MongooseUpdateQueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n {\n id,\n collection: collectionSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n const flattenedFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n\n const options: MongooseUpdateQueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n where: whereToUse,\n })\n\n transform({ adapter: this, data: versionData, fields, operation: 'write' })\n\n if (returning === false) {\n await Model.updateOne(query, versionData, options)\n return null\n }\n\n const doc = await Model.findOneAndUpdate(query, versionData, options)\n\n if (!doc) {\n return null\n }\n\n transform({ adapter: this, data: doc, fields, operation: 'read' })\n\n return doc\n}\n"],"names":["buildVersionCollectionFields","buildQuery","buildProjectionFromSelect","getCollection","getSession","transform","updateVersion","id","collection","collectionSlug","locale","options","optionsArgs","req","returning","select","versionData","where","collectionConfig","Model","adapter","versions","whereToUse","equals","fields","payload","config","flattenedFields","lean","new","projection","session","query","data","operation","updateOne","doc","findOneAndUpdate"],"mappings":"AAEA,SAASA,4BAA4B,QAA4B,UAAS;AAI1E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,EAAE,EACFC,YAAYC,cAAc,EAC1BC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,WAAW,EACXC,KAAK,EACN;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGhB,cAAc;QAChDiB,SAAS,IAAI;QACbX;QACAY,UAAU;IACZ;IAEA,MAAMC,aAAaL,SAAS;QAAEV,IAAI;YAAEgB,QAAQhB;QAAG;IAAE;IACjD,MAAMiB,SAASxB,6BAA6B,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAER;IAEjE,MAAMS,kBAAkB3B,6BAA6B,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAER,kBAAkB;IAE5F,MAAMP,UAAsC;QAC1C,GAAGC,WAAW;QACdgB,MAAM;QACNC,KAAK;QACLC,YAAY5B,0BAA0B;YACpCkB,SAAS,IAAI;YACbI,QAAQG;YACRZ;QACF;QACAgB,SAAS,MAAM3B,WAAW,IAAI,EAAES;IAClC;IAEA,MAAMmB,QAAQ,MAAM/B,WAAW;QAC7BmB,SAAS,IAAI;QACbI,QAAQG;QACRjB;QACAO,OAAOK;IACT;IAEAjB,UAAU;QAAEe,SAAS,IAAI;QAAEa,MAAMjB;QAAaQ;QAAQU,WAAW;IAAQ;IAEzE,IAAIpB,cAAc,OAAO;QACvB,MAAMK,MAAMgB,SAAS,CAACH,OAAOhB,aAAaL;QAC1C,OAAO;IACT;IAEA,MAAMyB,MAAM,MAAMjB,MAAMkB,gBAAgB,CAACL,OAAOhB,aAAaL;IAE7D,IAAI,CAACyB,KAAK;QACR,OAAO;IACT;IAEA/B,UAAU;QAAEe,SAAS,IAAI;QAAEa,MAAMG;QAAKZ;QAAQU,WAAW;IAAO;IAEhE,OAAOE;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/utilities/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,KAAK,
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/utilities/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,KAAK,EAQN,MAAM,SAAS,CAAA;AAMhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAgMlD,KAAK,IAAI,GAAG;IACV,8BAA8B;IAC9B,OAAO,EAAE,eAAe,CAAA;IACxB,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IACzD,uCAAuC;IACvC,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,SAAS,EAAE,MAAM,GAAG,OAAO,CAAA;IAC3B,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,CAAA;AAyID,eAAO,MAAM,SAAS,gGAQnB,IAAI,SAuHN,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Types } from 'mongoose';
|
|
2
|
-
import { traverseFields } from 'payload';
|
|
2
|
+
import { flattenAllFields, traverseFields } from 'payload';
|
|
3
3
|
import { fieldAffectsData, fieldShouldBeLocalized } from 'payload/shared';
|
|
4
4
|
function isValidRelationObject(value) {
|
|
5
5
|
return typeof value === 'object' && value !== null && 'relationTo' in value && 'value' in value;
|
|
@@ -115,6 +115,122 @@ const sanitizeDate = ({ field, locale, ref, value })=>{
|
|
|
115
115
|
ref[field.name] = value;
|
|
116
116
|
}
|
|
117
117
|
};
|
|
118
|
+
const stripFields = ({ config, data, fields, reservedKeys = [] })=>{
|
|
119
|
+
for(const k in data){
|
|
120
|
+
if (!fields.some((field)=>field.name === k) && !reservedKeys.includes(k)) {
|
|
121
|
+
delete data[k];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
for (const field of fields){
|
|
125
|
+
reservedKeys = [];
|
|
126
|
+
const fieldData = data[field.name];
|
|
127
|
+
if (!fieldData || typeof fieldData !== 'object') {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (field.type === 'blocks') {
|
|
131
|
+
reservedKeys.push('blockType');
|
|
132
|
+
}
|
|
133
|
+
if ('flattenedFields' in field || 'blocks' in field) {
|
|
134
|
+
if (field.localized && config.localization) {
|
|
135
|
+
for(const localeKey in fieldData){
|
|
136
|
+
if (!config.localization.localeCodes.some((code)=>code === localeKey)) {
|
|
137
|
+
delete fieldData[localeKey];
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const localeData = fieldData[localeKey];
|
|
141
|
+
if (!localeData || typeof localeData !== 'object') {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (field.type === 'array' || field.type === 'blocks') {
|
|
145
|
+
if (!Array.isArray(localeData)) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
for (const data of localeData){
|
|
149
|
+
let fields = null;
|
|
150
|
+
if (field.type === 'array') {
|
|
151
|
+
fields = field.flattenedFields;
|
|
152
|
+
} else {
|
|
153
|
+
let maybeBlock = undefined;
|
|
154
|
+
if (field.blockReferences) {
|
|
155
|
+
const maybeBlockReference = field.blockReferences.find((each)=>typeof each === 'object' && each.slug === data.blockType);
|
|
156
|
+
if (maybeBlockReference && typeof maybeBlockReference === 'object') {
|
|
157
|
+
maybeBlock = maybeBlockReference;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (!maybeBlock) {
|
|
161
|
+
maybeBlock = field.blocks.find((each)=>each.slug === data.blockType);
|
|
162
|
+
}
|
|
163
|
+
if (maybeBlock) {
|
|
164
|
+
fields = maybeBlock.flattenedFields;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (!fields) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
stripFields({
|
|
171
|
+
config,
|
|
172
|
+
data,
|
|
173
|
+
fields,
|
|
174
|
+
reservedKeys
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
continue;
|
|
178
|
+
} else {
|
|
179
|
+
stripFields({
|
|
180
|
+
config,
|
|
181
|
+
data: localeData,
|
|
182
|
+
fields: field.flattenedFields,
|
|
183
|
+
reservedKeys
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (field.type === 'array' || field.type === 'blocks') {
|
|
190
|
+
if (!Array.isArray(fieldData)) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
for (const data of fieldData){
|
|
194
|
+
let fields = null;
|
|
195
|
+
if (field.type === 'array') {
|
|
196
|
+
fields = field.flattenedFields;
|
|
197
|
+
} else {
|
|
198
|
+
let maybeBlock = undefined;
|
|
199
|
+
if (field.blockReferences) {
|
|
200
|
+
const maybeBlockReference = field.blockReferences.find((each)=>typeof each === 'object' && each.slug === data.blockType);
|
|
201
|
+
if (maybeBlockReference && typeof maybeBlockReference === 'object') {
|
|
202
|
+
maybeBlock = maybeBlockReference;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (!maybeBlock) {
|
|
206
|
+
maybeBlock = field.blocks.find((each)=>each.slug === data.blockType);
|
|
207
|
+
}
|
|
208
|
+
if (maybeBlock) {
|
|
209
|
+
fields = maybeBlock.flattenedFields;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (!fields) {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
stripFields({
|
|
216
|
+
config,
|
|
217
|
+
data,
|
|
218
|
+
fields,
|
|
219
|
+
reservedKeys
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
continue;
|
|
223
|
+
} else {
|
|
224
|
+
stripFields({
|
|
225
|
+
config,
|
|
226
|
+
data: fieldData,
|
|
227
|
+
fields: field.flattenedFields,
|
|
228
|
+
reservedKeys
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
};
|
|
118
234
|
export const transform = ({ adapter, data, fields, globalSlug, operation, parentIsLocalized = false, validateRelationships = true })=>{
|
|
119
235
|
if (Array.isArray(data)) {
|
|
120
236
|
for (const item of data){
|
|
@@ -137,6 +253,20 @@ export const transform = ({ adapter, data, fields, globalSlug, operation, parent
|
|
|
137
253
|
if (data.id instanceof Types.ObjectId) {
|
|
138
254
|
data.id = data.id.toHexString();
|
|
139
255
|
}
|
|
256
|
+
if (!adapter.allowAdditionalKeys) {
|
|
257
|
+
stripFields({
|
|
258
|
+
config,
|
|
259
|
+
data,
|
|
260
|
+
fields: flattenAllFields({
|
|
261
|
+
cache: true,
|
|
262
|
+
fields
|
|
263
|
+
}),
|
|
264
|
+
reservedKeys: [
|
|
265
|
+
'id',
|
|
266
|
+
'globalType'
|
|
267
|
+
]
|
|
268
|
+
});
|
|
269
|
+
}
|
|
140
270
|
}
|
|
141
271
|
if (operation === 'write' && globalSlug) {
|
|
142
272
|
data.globalType = globalSlug;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/transform.ts"],"sourcesContent":["import type {\n CollectionConfig,\n DateField,\n Field,\n JoinField,\n RelationshipField,\n SanitizedConfig,\n TraverseFieldsCallback,\n UploadField,\n} from 'payload'\n\nimport { Types } from 'mongoose'\nimport { traverseFields } from 'payload'\nimport { fieldAffectsData, fieldShouldBeLocalized } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\ninterface RelationObject {\n relationTo: string\n value: number | string\n}\n\nfunction isValidRelationObject(value: unknown): value is RelationObject {\n return typeof value === 'object' && value !== null && 'relationTo' in value && 'value' in value\n}\n\nconst convertRelationshipValue = ({\n operation,\n relatedCollection,\n validateRelationships,\n value,\n}: {\n operation: Args['operation']\n relatedCollection: CollectionConfig\n validateRelationships?: boolean\n value: unknown\n}) => {\n const customIDField = relatedCollection.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n\n if (operation === 'read') {\n if (value instanceof Types.ObjectId) {\n return value.toHexString()\n }\n\n return value\n }\n\n if (customIDField) {\n return value\n }\n\n if (typeof value === 'string') {\n try {\n return new Types.ObjectId(value)\n } catch (e) {\n if (validateRelationships) {\n throw e\n }\n return value\n }\n }\n\n return value\n}\n\nconst sanitizeRelationship = ({\n config,\n field,\n locale,\n operation,\n ref,\n validateRelationships,\n value,\n}: {\n config: SanitizedConfig\n field: JoinField | RelationshipField | UploadField\n locale?: string\n operation: Args['operation']\n ref: Record<string, unknown>\n validateRelationships?: boolean\n value?: unknown\n}) => {\n if (field.type === 'join') {\n if (\n operation === 'read' &&\n value &&\n typeof value === 'object' &&\n 'docs' in value &&\n Array.isArray(value.docs)\n ) {\n for (let i = 0; i < value.docs.length; i++) {\n const item = value.docs[i]\n\n if (item instanceof Types.ObjectId) {\n value.docs[i] = item.toHexString()\n } else if (Array.isArray(field.collection) && item) {\n // Fields here for polymorphic joins cannot be determinted, JSON.parse needed\n value.docs[i] = JSON.parse(JSON.stringify(value.docs[i]))\n }\n }\n }\n\n return value\n }\n let relatedCollection: CollectionConfig | undefined\n let result = value\n\n const hasManyRelations = typeof field.relationTo !== 'string'\n\n if (!hasManyRelations) {\n relatedCollection = config.collections?.find(({ slug }) => slug === field.relationTo)\n }\n\n if (Array.isArray(value)) {\n result = value.map((val) => {\n // Handle has many - polymorphic\n if (isValidRelationObject(val)) {\n const relatedCollectionForSingleValue = config.collections?.find(\n ({ slug }) => slug === val.relationTo,\n )\n\n if (relatedCollectionForSingleValue) {\n return {\n relationTo: val.relationTo,\n value: convertRelationshipValue({\n operation,\n relatedCollection: relatedCollectionForSingleValue,\n validateRelationships,\n value: val.value,\n }),\n }\n }\n }\n\n if (relatedCollection) {\n return convertRelationshipValue({\n operation,\n relatedCollection,\n validateRelationships,\n value: val,\n })\n }\n\n return val\n })\n }\n // Handle has one - polymorphic\n else if (isValidRelationObject(value)) {\n relatedCollection = config.collections?.find(({ slug }) => slug === value.relationTo)\n\n if (relatedCollection) {\n result = {\n relationTo: value.relationTo,\n value: convertRelationshipValue({\n operation,\n relatedCollection,\n validateRelationships,\n value: value.value,\n }),\n }\n }\n }\n // Handle has one\n else if (relatedCollection) {\n result = convertRelationshipValue({\n operation,\n relatedCollection,\n validateRelationships,\n value,\n })\n }\n\n if (locale) {\n ref[locale] = result\n } else {\n ref[field.name] = result\n }\n}\n\nconst sanitizeDate = ({\n field,\n locale,\n ref,\n value,\n}: {\n field: DateField\n locale?: string\n ref: Record<string, unknown>\n value: unknown\n}) => {\n if (!value) {\n return\n }\n\n if (value instanceof Date) {\n value = value.toISOString()\n }\n\n if (locale) {\n ref[locale] = value\n } else {\n ref[field.name] = value\n }\n}\n\ntype Args = {\n /** instance of the adapter */\n adapter: MongooseAdapter\n /** data to transform, can be an array of documents or a single document */\n data: Record<string, unknown> | Record<string, unknown>[]\n /** fields accossiated with the data */\n fields: Field[]\n /** slug of the global, pass only when the operation is `write` */\n globalSlug?: string\n /**\n * Type of the operation\n * read - sanitizes ObjectIDs, Date to strings.\n * write - sanitizes string relationships to ObjectIDs.\n */\n operation: 'read' | 'write'\n parentIsLocalized?: boolean\n /**\n * Throw errors on invalid relationships\n * @default true\n */\n validateRelationships?: boolean\n}\n\nexport const transform = ({\n adapter,\n data,\n fields,\n globalSlug,\n operation,\n parentIsLocalized = false,\n validateRelationships = true,\n}: Args) => {\n if (Array.isArray(data)) {\n for (const item of data) {\n transform({ adapter, data: item, fields, globalSlug, operation, validateRelationships })\n }\n return\n }\n\n const {\n payload: { config },\n } = adapter\n\n if (operation === 'read') {\n delete data['__v']\n data.id = data._id\n delete data['_id']\n\n if (data.id instanceof Types.ObjectId) {\n data.id = data.id.toHexString()\n }\n }\n\n if (operation === 'write' && globalSlug) {\n data.globalType = globalSlug\n }\n\n const sanitize: TraverseFieldsCallback = ({ field, ref: incomingRef }) => {\n if (!incomingRef || typeof incomingRef !== 'object') {\n return\n }\n\n const ref = incomingRef as Record<string, unknown>\n\n if (field.type === 'date' && operation === 'read' && field.name in ref && ref[field.name]) {\n if (config.localization && fieldShouldBeLocalized({ field, parentIsLocalized })) {\n const fieldRef = ref[field.name] as Record<string, unknown>\n if (!fieldRef || typeof fieldRef !== 'object') {\n return\n }\n\n for (const locale of config.localization.localeCodes) {\n sanitizeDate({\n field,\n ref: fieldRef,\n value: fieldRef[locale],\n })\n }\n } else {\n sanitizeDate({\n field,\n ref,\n value: ref[field.name],\n })\n }\n }\n\n if (\n field.type === 'relationship' ||\n field.type === 'upload' ||\n (operation === 'read' && field.type === 'join')\n ) {\n if (!ref[field.name]) {\n return\n }\n\n // handle localized relationships\n if (config.localization && fieldShouldBeLocalized({ field, parentIsLocalized })) {\n const locales = config.localization.locales\n const fieldRef = ref[field.name] as Record<string, unknown>\n if (typeof fieldRef !== 'object') {\n return\n }\n\n for (const { code } of locales) {\n const value = fieldRef[code]\n if (value) {\n sanitizeRelationship({\n config,\n field,\n locale: code,\n operation,\n ref: fieldRef,\n validateRelationships,\n value,\n })\n }\n }\n } else {\n // handle non-localized relationships\n sanitizeRelationship({\n config,\n field,\n locale: undefined,\n operation,\n ref,\n validateRelationships,\n value: ref[field.name],\n })\n }\n }\n }\n\n traverseFields({\n callback: sanitize,\n config,\n fields,\n fillEmpty: false,\n parentIsLocalized,\n ref: data,\n })\n}\n"],"names":["Types","traverseFields","fieldAffectsData","fieldShouldBeLocalized","isValidRelationObject","value","convertRelationshipValue","operation","relatedCollection","validateRelationships","customIDField","fields","find","field","name","ObjectId","toHexString","e","sanitizeRelationship","config","locale","ref","type","Array","isArray","docs","i","length","item","collection","JSON","parse","stringify","result","hasManyRelations","relationTo","collections","slug","map","val","relatedCollectionForSingleValue","sanitizeDate","Date","toISOString","transform","adapter","data","globalSlug","parentIsLocalized","payload","id","_id","globalType","sanitize","incomingRef","localization","fieldRef","localeCodes","locales","code","undefined","callback","fillEmpty"],"mappings":"AAWA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,cAAc,QAAQ,UAAS;AACxC,SAASC,gBAAgB,EAAEC,sBAAsB,QAAQ,iBAAgB;AASzE,SAASC,sBAAsBC,KAAc;IAC3C,OAAO,OAAOA,UAAU,YAAYA,UAAU,QAAQ,gBAAgBA,SAAS,WAAWA;AAC5F;AAEA,MAAMC,2BAA2B,CAAC,EAChCC,SAAS,EACTC,iBAAiB,EACjBC,qBAAqB,EACrBJ,K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oBACAJ,OAAOgB,GAAG,CAACR,MAAMC,IAAI,CAAC;gBACxB;YACF;QACF;IACF;IAEAb,eAAe;QACb4D,UAAUR;QACVlC;QACAR;QACAmD,WAAW;QACXd;QACA3B,KAAKyB;IACP;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/transform.ts"],"sourcesContent":["import type {\n CollectionConfig,\n DateField,\n Field,\n FlattenedBlock,\n FlattenedField,\n JoinField,\n RelationshipField,\n SanitizedConfig,\n TraverseFieldsCallback,\n UploadField,\n} from 'payload'\n\nimport { Types } from 'mongoose'\nimport { flattenAllFields, traverseFields } from 'payload'\nimport { fieldAffectsData, fieldShouldBeLocalized } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\ninterface RelationObject {\n relationTo: string\n value: number | string\n}\n\nfunction isValidRelationObject(value: unknown): value is RelationObject {\n return typeof value === 'object' && value !== null && 'relationTo' in value && 'value' in value\n}\n\nconst convertRelationshipValue = ({\n operation,\n relatedCollection,\n validateRelationships,\n value,\n}: {\n operation: Args['operation']\n relatedCollection: CollectionConfig\n validateRelationships?: boolean\n value: unknown\n}) => {\n const customIDField = relatedCollection.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n\n if (operation === 'read') {\n if (value instanceof Types.ObjectId) {\n return value.toHexString()\n }\n\n return value\n }\n\n if (customIDField) {\n return value\n }\n\n if (typeof value === 'string') {\n try {\n return new Types.ObjectId(value)\n } catch (e) {\n if (validateRelationships) {\n throw e\n }\n return value\n }\n }\n\n return value\n}\n\nconst sanitizeRelationship = ({\n config,\n field,\n locale,\n operation,\n ref,\n validateRelationships,\n value,\n}: {\n config: SanitizedConfig\n field: JoinField | RelationshipField | UploadField\n locale?: string\n operation: Args['operation']\n ref: Record<string, unknown>\n validateRelationships?: boolean\n value?: unknown\n}) => {\n if (field.type === 'join') {\n if (\n operation === 'read' &&\n value &&\n typeof value === 'object' &&\n 'docs' in value &&\n Array.isArray(value.docs)\n ) {\n for (let i = 0; i < value.docs.length; i++) {\n const item = value.docs[i]\n\n if (item instanceof Types.ObjectId) {\n value.docs[i] = item.toHexString()\n } else if (Array.isArray(field.collection) && item) {\n // Fields here for polymorphic joins cannot be determinted, JSON.parse needed\n value.docs[i] = JSON.parse(JSON.stringify(value.docs[i]))\n }\n }\n }\n\n return value\n }\n let relatedCollection: CollectionConfig | undefined\n let result = value\n\n const hasManyRelations = typeof field.relationTo !== 'string'\n\n if (!hasManyRelations) {\n relatedCollection = config.collections?.find(({ slug }) => slug === field.relationTo)\n }\n\n if (Array.isArray(value)) {\n result = value.map((val) => {\n // Handle has many - polymorphic\n if (isValidRelationObject(val)) {\n const relatedCollectionForSingleValue = config.collections?.find(\n ({ slug }) => slug === val.relationTo,\n )\n\n if (relatedCollectionForSingleValue) {\n return {\n relationTo: val.relationTo,\n value: convertRelationshipValue({\n operation,\n relatedCollection: relatedCollectionForSingleValue,\n validateRelationships,\n value: val.value,\n }),\n }\n }\n }\n\n if (relatedCollection) {\n return convertRelationshipValue({\n operation,\n relatedCollection,\n validateRelationships,\n value: val,\n })\n }\n\n return val\n })\n }\n // Handle has one - polymorphic\n else if (isValidRelationObject(value)) {\n relatedCollection = config.collections?.find(({ slug }) => slug === value.relationTo)\n\n if (relatedCollection) {\n result = {\n relationTo: value.relationTo,\n value: convertRelationshipValue({\n operation,\n relatedCollection,\n validateRelationships,\n value: value.value,\n }),\n }\n }\n }\n // Handle has one\n else if (relatedCollection) {\n result = convertRelationshipValue({\n operation,\n relatedCollection,\n validateRelationships,\n value,\n })\n }\n\n if (locale) {\n ref[locale] = result\n } else {\n ref[field.name] = result\n }\n}\n\nconst sanitizeDate = ({\n field,\n locale,\n ref,\n value,\n}: {\n field: DateField\n locale?: string\n ref: Record<string, unknown>\n value: unknown\n}) => {\n if (!value) {\n return\n }\n\n if (value instanceof Date) {\n value = value.toISOString()\n }\n\n if (locale) {\n ref[locale] = value\n } else {\n ref[field.name] = value\n }\n}\n\ntype Args = {\n /** instance of the adapter */\n adapter: MongooseAdapter\n /** data to transform, can be an array of documents or a single document */\n data: Record<string, unknown> | Record<string, unknown>[]\n /** fields accossiated with the data */\n fields: Field[]\n /** slug of the global, pass only when the operation is `write` */\n globalSlug?: string\n /**\n * Type of the operation\n * read - sanitizes ObjectIDs, Date to strings.\n * write - sanitizes string relationships to ObjectIDs.\n */\n operation: 'read' | 'write'\n parentIsLocalized?: boolean\n /**\n * Throw errors on invalid relationships\n * @default true\n */\n validateRelationships?: boolean\n}\n\nconst stripFields = ({\n config,\n data,\n fields,\n reservedKeys = [],\n}: {\n config: SanitizedConfig\n data: any\n fields: FlattenedField[]\n reservedKeys?: string[]\n}) => {\n for (const k in data) {\n if (!fields.some((field) => field.name === k) && !reservedKeys.includes(k)) {\n delete data[k]\n }\n }\n\n for (const field of fields) {\n reservedKeys = []\n const fieldData = data[field.name]\n if (!fieldData || typeof fieldData !== 'object') {\n continue\n }\n\n if (field.type === 'blocks') {\n reservedKeys.push('blockType')\n }\n\n if ('flattenedFields' in field || 'blocks' in field) {\n if (field.localized && config.localization) {\n for (const localeKey in fieldData) {\n if (!config.localization.localeCodes.some((code) => code === localeKey)) {\n delete fieldData[localeKey]\n continue\n }\n\n const localeData = fieldData[localeKey]\n\n if (!localeData || typeof localeData !== 'object') {\n continue\n }\n\n if (field.type === 'array' || field.type === 'blocks') {\n if (!Array.isArray(localeData)) {\n continue\n }\n\n for (const data of localeData) {\n let fields: FlattenedField[] | null = null\n\n if (field.type === 'array') {\n fields = field.flattenedFields\n } else {\n let maybeBlock: FlattenedBlock | undefined = undefined\n\n if (field.blockReferences) {\n const maybeBlockReference = field.blockReferences.find(\n (each) => typeof each === 'object' && each.slug === data.blockType,\n )\n if (maybeBlockReference && typeof maybeBlockReference === 'object') {\n maybeBlock = maybeBlockReference\n }\n }\n\n if (!maybeBlock) {\n maybeBlock = field.blocks.find((each) => each.slug === data.blockType)\n }\n\n if (maybeBlock) {\n fields = maybeBlock.flattenedFields\n }\n }\n\n if (!fields) {\n continue\n }\n\n stripFields({ config, data, fields, reservedKeys })\n }\n\n continue\n } else {\n stripFields({ config, data: localeData, fields: field.flattenedFields, reservedKeys })\n }\n }\n continue\n }\n\n if (field.type === 'array' || field.type === 'blocks') {\n if (!Array.isArray(fieldData)) {\n continue\n }\n\n for (const data of fieldData) {\n let fields: FlattenedField[] | null = null\n\n if (field.type === 'array') {\n fields = field.flattenedFields\n } else {\n let maybeBlock: FlattenedBlock | undefined = undefined\n\n if (field.blockReferences) {\n const maybeBlockReference = field.blockReferences.find(\n (each) => typeof each === 'object' && each.slug === data.blockType,\n )\n\n if (maybeBlockReference && typeof maybeBlockReference === 'object') {\n maybeBlock = maybeBlockReference\n }\n }\n\n if (!maybeBlock) {\n maybeBlock = field.blocks.find((each) => each.slug === data.blockType)\n }\n\n if (maybeBlock) {\n fields = maybeBlock.flattenedFields\n }\n }\n\n if (!fields) {\n continue\n }\n\n stripFields({ config, data, fields, reservedKeys })\n }\n\n continue\n } else {\n stripFields({ config, data: fieldData, fields: field.flattenedFields, reservedKeys })\n }\n }\n }\n}\n\nexport const transform = ({\n adapter,\n data,\n fields,\n globalSlug,\n operation,\n parentIsLocalized = false,\n validateRelationships = true,\n}: Args) => {\n if (Array.isArray(data)) {\n for (const item of data) {\n transform({ adapter, data: item, fields, globalSlug, operation, validateRelationships })\n }\n return\n }\n\n const {\n payload: { config },\n } = adapter\n\n if (operation === 'read') {\n delete data['__v']\n data.id = data._id\n delete data['_id']\n\n if (data.id instanceof Types.ObjectId) {\n data.id = data.id.toHexString()\n }\n\n if (!adapter.allowAdditionalKeys) {\n stripFields({\n config,\n data,\n fields: flattenAllFields({ cache: true, fields }),\n reservedKeys: ['id', 'globalType'],\n })\n }\n }\n\n if (operation === 'write' && globalSlug) {\n data.globalType = globalSlug\n }\n\n const sanitize: TraverseFieldsCallback = ({ field, ref: incomingRef }) => {\n if (!incomingRef || typeof incomingRef !== 'object') {\n return\n }\n\n const ref = incomingRef as Record<string, unknown>\n\n if (field.type === 'date' && operation === 'read' && field.name in ref && ref[field.name]) {\n if (config.localization && fieldShouldBeLocalized({ field, parentIsLocalized })) {\n const fieldRef = ref[field.name] as Record<string, unknown>\n if (!fieldRef || typeof fieldRef !== 'object') {\n return\n }\n\n for (const locale of config.localization.localeCodes) {\n sanitizeDate({\n field,\n ref: fieldRef,\n value: fieldRef[locale],\n })\n }\n } else {\n sanitizeDate({\n field,\n ref,\n value: ref[field.name],\n })\n }\n }\n\n if (\n field.type === 'relationship' ||\n field.type === 'upload' ||\n (operation === 'read' && field.type === 'join')\n ) {\n if (!ref[field.name]) {\n return\n }\n\n // handle localized relationships\n if (config.localization && fieldShouldBeLocalized({ field, parentIsLocalized })) {\n const locales = config.localization.locales\n const fieldRef = ref[field.name] as Record<string, unknown>\n if (typeof fieldRef !== 'object') {\n return\n }\n\n for (const { code } of locales) {\n const value = fieldRef[code]\n if (value) {\n sanitizeRelationship({\n config,\n field,\n locale: code,\n operation,\n ref: fieldRef,\n validateRelationships,\n value,\n })\n }\n }\n } else {\n // handle non-localized relationships\n sanitizeRelationship({\n config,\n field,\n locale: undefined,\n operation,\n ref,\n validateRelationships,\n value: ref[field.name],\n })\n }\n }\n }\n\n traverseFields({\n callback: sanitize,\n config,\n fields,\n fillEmpty: false,\n parentIsLocalized,\n ref: data,\n })\n}\n"],"names":["Types","flattenAllFields","traverseFields","fieldAffectsData","fieldShouldBeLocalized","isValidRelationObject","value","convertRelationshipValue","operation","relatedCollection","validateRelationships","customIDField","fields","find","field","name","ObjectId","toHexString","e","sanitizeRelationship","config","locale","ref","type","Array","isArray","docs","i","length","item","collection","JSON","parse","stringify","result","hasManyRelations","relationTo","collections","slug","map","val","relatedCollectionForSingleValue","sanitizeDate","Date","toISOString","stripFields","data","reservedKeys","k","some","includes","fieldData","push","localized","localization","localeKey","localeCodes","code","localeData","flattenedFields","maybeBlock","undefined","blockReferences","maybeBlockReference","each","blockType","blocks","transform","adapter","globalSlug","parentIsLocalized","payload","id","_id","allowAdditionalK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3
|
+
"version": "3.28.0-internal.2b0876e",
|
|
4
4
|
"description": "The officially supported MongoDB database adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"mongodb": "6.12.0",
|
|
50
50
|
"mongodb-memory-server": "^10",
|
|
51
51
|
"@payloadcms/eslint-config": "3.9.0",
|
|
52
|
-
"payload": "3.28.0-
|
|
52
|
+
"payload": "3.28.0-internal.2b0876e"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"payload": "3.28.0-
|
|
55
|
+
"payload": "3.28.0-internal.2b0876e"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "pnpm build:types && pnpm build:swc",
|