@payloadcms/db-mongodb 3.77.0-internal.8cf758f → 3.77.0-internal.fd50432
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/create.d.ts.map +1 -1
- package/dist/create.js +7 -1
- package/dist/create.js.map +1 -1
- package/package.json +3 -3
package/dist/create.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAWrC,eAAO,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAWrC,eAAO,MAAM,MAAM,EAAE,MA+DpB,CAAA"}
|
package/dist/create.js
CHANGED
|
@@ -3,7 +3,7 @@ import { getCollection } from './utilities/getEntity.js';
|
|
|
3
3
|
import { getSession } from './utilities/getSession.js';
|
|
4
4
|
import { handleError } from './utilities/handleError.js';
|
|
5
5
|
import { transform } from './utilities/transform.js';
|
|
6
|
-
export const create = async function create({ collection: collectionSlug, data, req, returning }) {
|
|
6
|
+
export const create = async function create({ collection: collectionSlug, customID, data, req, returning }) {
|
|
7
7
|
const { collectionConfig, customIDType, Model } = getCollection({
|
|
8
8
|
adapter: this,
|
|
9
9
|
collectionSlug
|
|
@@ -20,6 +20,12 @@ export const create = async function create({ collection: collectionSlug, data,
|
|
|
20
20
|
});
|
|
21
21
|
if (customIDType) {
|
|
22
22
|
data._id = data.id;
|
|
23
|
+
} else if (customID) {
|
|
24
|
+
if (Types.ObjectId.isValid(customID)) {
|
|
25
|
+
data._id = new Types.ObjectId(customID);
|
|
26
|
+
} else {
|
|
27
|
+
data._id = customID;
|
|
28
|
+
}
|
|
23
29
|
} else if (this.allowIDOnCreate && data.id) {
|
|
24
30
|
try {
|
|
25
31
|
data._id = new Types.ObjectId(data.id);
|
package/dist/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { Create } from 'payload'\n\nimport { type CreateOptions, Types } from 'mongoose'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const create: Create = async function create(\n this: MongooseAdapter,\n { collection: collectionSlug, data, req, returning },\n) {\n const { collectionConfig, customIDType, Model } = getCollection({ adapter: this, collectionSlug })\n\n let doc\n\n if (!data.createdAt) {\n data.createdAt = new Date().toISOString()\n }\n\n transform({\n adapter: this,\n data,\n fields: collectionConfig.fields,\n operation: 'write',\n })\n\n if (customIDType) {\n data._id = data.id\n } else if (this.allowIDOnCreate && data.id) {\n try {\n data._id = new Types.ObjectId(data.id as string)\n } catch (error) {\n this.payload.logger.error(\n `It appears you passed ID to create operation data but it cannot be sanitized to ObjectID, value - ${JSON.stringify(data.id)}`,\n )\n throw error\n }\n }\n\n const options: CreateOptions = {\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n try {\n ;[doc] = await Model.create([data], options)\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n if (returning === false) {\n return null\n }\n\n doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["Types","getCollection","getSession","handleError","transform","create","collection","collectionSlug","data","req","returning","collectionConfig","customIDType","Model","adapter","doc","createdAt","Date","toISOString","fields","operation","_id","id","
|
|
1
|
+
{"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { Create } from 'payload'\n\nimport { type CreateOptions, Types } from 'mongoose'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const create: Create = async function create(\n this: MongooseAdapter,\n { collection: collectionSlug, customID, data, req, returning },\n) {\n const { collectionConfig, customIDType, Model } = getCollection({ adapter: this, collectionSlug })\n\n let doc\n\n if (!data.createdAt) {\n data.createdAt = new Date().toISOString()\n }\n\n transform({\n adapter: this,\n data,\n fields: collectionConfig.fields,\n operation: 'write',\n })\n\n if (customIDType) {\n data._id = data.id\n } else if (customID) {\n if (Types.ObjectId.isValid(customID)) {\n data._id = new Types.ObjectId(customID)\n } else {\n data._id = customID\n }\n } else if (this.allowIDOnCreate && data.id) {\n try {\n data._id = new Types.ObjectId(data.id as string)\n } catch (error) {\n this.payload.logger.error(\n `It appears you passed ID to create operation data but it cannot be sanitized to ObjectID, value - ${JSON.stringify(data.id)}`,\n )\n throw error\n }\n }\n\n const options: CreateOptions = {\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n try {\n ;[doc] = await Model.create([data], options)\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n if (returning === false) {\n return null\n }\n\n doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["Types","getCollection","getSession","handleError","transform","create","collection","collectionSlug","customID","data","req","returning","collectionConfig","customIDType","Model","adapter","doc","createdAt","Date","toISOString","fields","operation","_id","id","ObjectId","isValid","allowIDOnCreate","error","payload","logger","JSON","stringify","options","session","timestamps","toObject"],"mappings":"AAEA,SAA6BA,KAAK,QAAQ,WAAU;AAIpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,SAAiB,eAAeA,OAE3C,EAAEC,YAAYC,cAAc,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AImB,QAAQ;IAElB/B,UAAU;QACRW,SAAS,IAAI;QACbN,MAAMO;QACNI,QAAQR,iBAAiBQ,MAAM;QAC/BC,WAAW;IACb;IAEA,OAAOL;AACT,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/db-mongodb",
|
|
3
|
-
"version": "3.77.0-internal.
|
|
3
|
+
"version": "3.77.0-internal.fd50432",
|
|
4
4
|
"description": "The officially supported MongoDB database adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"mongodb": "6.16.0",
|
|
56
56
|
"mongodb-memory-server": "10.1.4",
|
|
57
57
|
"@payloadcms/eslint-config": "3.28.0",
|
|
58
|
-
"payload": "3.77.0-internal.
|
|
58
|
+
"payload": "3.77.0-internal.fd50432"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"payload": "3.77.0-internal.
|
|
61
|
+
"payload": "3.77.0-internal.fd50432"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "pnpm build:types && pnpm build:swc",
|