@payloadcms/db-mongodb 3.0.0-beta.11 → 3.0.0-beta.111
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/README.md +1 -1
- package/dist/connect.d.ts +1 -1
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +13 -4
- package/dist/connect.js.map +1 -1
- package/dist/count.d.ts +3 -0
- package/dist/count.d.ts.map +1 -0
- package/dist/count.js +33 -0
- package/dist/count.js.map +1 -0
- package/dist/create.d.ts +1 -1
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +14 -4
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +11 -6
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +14 -5
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createMigration.d.ts +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +16 -30
- package/dist/createMigration.js.map +1 -1
- package/dist/createVersion.d.ts +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +32 -10
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +1 -1
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +2 -2
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +1 -1
- package/dist/deleteVersions.js.map +1 -1
- package/dist/destroy.d.ts +1 -1
- package/dist/destroy.d.ts.map +1 -1
- package/dist/destroy.js.map +1 -1
- package/dist/find.d.ts +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +29 -6
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +3 -3
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +12 -7
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +20 -4
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +10 -4
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +52 -35
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +11 -8
- package/dist/init.js.map +1 -1
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +1 -1
- package/dist/migrateFresh.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +2 -29
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +16 -4
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts +1 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +2 -2
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +2 -29
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +100 -22
- package/dist/models/buildSchema.js.map +1 -1
- package/{predefinedMigrations → dist/predefinedMigrations}/versions-v1-v2.js +3 -1
- package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -0
- package/dist/queries/buildAndOrConditions.d.ts +1 -2
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +0 -2
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +3 -4
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +2 -3
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts +1 -2
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +26 -16
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +2 -28
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.d.ts +1 -2
- package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
- package/dist/queries/getLocalizedSortProperty.js +2 -2
- package/dist/queries/getLocalizedSortProperty.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +53 -50
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
- package/dist/queries/mock.js.map +1 -1
- package/dist/queries/operatorMap.js.map +1 -1
- package/dist/queries/parseParams.d.ts +1 -3
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +6 -7
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +143 -27
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +10 -4
- package/dist/queryDrafts.js.map +1 -1
- package/dist/testCredentials.js.map +1 -1
- package/dist/transactions/beginTransaction.d.ts +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +3 -1
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +8 -1
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transactions/rollbackTransaction.d.ts +1 -1
- package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
- package/dist/transactions/rollbackTransaction.js +13 -7
- package/dist/transactions/rollbackTransaction.js.map +1 -1
- package/dist/types.d.ts +7 -31
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateGlobal.d.ts +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +9 -3
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts +2 -3
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +11 -4
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +17 -6
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +9 -2
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsert.d.ts +3 -0
- package/dist/upsert.d.ts.map +1 -0
- package/dist/upsert.js +14 -0
- package/dist/upsert.js.map +1 -0
- package/dist/utilities/buildJoinAggregation.d.ts +15 -0
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
- package/dist/utilities/buildJoinAggregation.js +148 -0
- package/dist/utilities/buildJoinAggregation.js.map +1 -0
- package/dist/utilities/getDBName.d.ts +1 -1
- package/dist/utilities/getDBName.d.ts.map +1 -1
- package/dist/utilities/getDBName.js +3 -1
- package/dist/utilities/getDBName.js.map +1 -1
- package/dist/utilities/handleError.d.ts +6 -2
- package/dist/utilities/handleError.d.ts.map +1 -1
- package/dist/utilities/handleError.js +12 -9
- package/dist/utilities/handleError.js.map +1 -1
- package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
- package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
- package/dist/utilities/sanitizeInternalFields.js +1 -2
- package/dist/utilities/sanitizeInternalFields.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.js +111 -0
- package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
- package/dist/withSession.d.ts +3 -27
- package/dist/withSession.d.ts.map +1 -1
- package/dist/withSession.js +10 -4
- package/dist/withSession.js.map +1 -1
- package/package.json +25 -28
- package/src/index.ts +0 -198
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const internalFields = [
|
|
2
2
|
'__v'
|
|
3
3
|
];
|
|
4
|
-
const sanitizeInternalFields = (incomingDoc)=>Object.entries(incomingDoc).reduce((newDoc, [key, val])=>{
|
|
4
|
+
export const sanitizeInternalFields = (incomingDoc)=>Object.entries(incomingDoc).reduce((newDoc, [key, val])=>{
|
|
5
5
|
if (key === '_id') {
|
|
6
6
|
return {
|
|
7
7
|
...newDoc,
|
|
@@ -16,6 +16,5 @@ const sanitizeInternalFields = (incomingDoc)=>Object.entries(incomingDoc).reduce
|
|
|
16
16
|
[key]: val
|
|
17
17
|
};
|
|
18
18
|
}, {});
|
|
19
|
-
export default sanitizeInternalFields;
|
|
20
19
|
|
|
21
20
|
//# sourceMappingURL=sanitizeInternalFields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/sanitizeInternalFields.ts"],"sourcesContent":["const internalFields = ['__v']\n\
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/sanitizeInternalFields.ts"],"sourcesContent":["const internalFields = ['__v']\n\nexport const sanitizeInternalFields = <T extends Record<string, unknown>>(incomingDoc: T): T =>\n Object.entries(incomingDoc).reduce((newDoc, [key, val]): T => {\n if (key === '_id') {\n return {\n ...newDoc,\n id: val,\n }\n }\n\n if (internalFields.indexOf(key) > -1) {\n return newDoc\n }\n\n return {\n ...newDoc,\n [key]: val,\n }\n }, {} as T)\n"],"names":["internalFields","sanitizeInternalFields","incomingDoc","Object","entries","reduce","newDoc","key","val","id","indexOf"],"mappings":"AAAA,MAAMA,iBAAiB;IAAC;CAAM;AAE9B,OAAO,MAAMC,yBAAyB,CAAoCC,cACxEC,OAAOC,OAAO,CAACF,aAAaG,MAAM,CAAC,CAACC,QAAQ,CAACC,KAAKC,IAAI;QACpD,IAAID,QAAQ,OAAO;YACjB,OAAO;gBACL,GAAGD,MAAM;gBACTG,IAAID;YACN;QACF;QAEA,IAAIR,eAAeU,OAAO,CAACH,OAAO,CAAC,GAAG;YACpC,OAAOD;QACT;QAEA,OAAO;YACL,GAAGA,MAAM;YACT,CAACC,IAAI,EAAEC;QACT;IACF,GAAG,CAAC,GAAO"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Field, SanitizedConfig } from 'payload';
|
|
2
|
+
type Args = {
|
|
3
|
+
config: SanitizedConfig;
|
|
4
|
+
data: Record<string, unknown>;
|
|
5
|
+
fields: Field[];
|
|
6
|
+
};
|
|
7
|
+
export declare const sanitizeRelationshipIDs: ({ config, data, fields, }: Args) => Record<string, unknown>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=sanitizeRelationshipIDs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizeRelationshipIDs.d.ts","sourceRoot":"","sources":["../../src/utilities/sanitizeRelationshipIDs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,KAAK,EAAE,eAAe,EAA0B,MAAM,SAAS,CAAA;AAM/F,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,MAAM,EAAE,KAAK,EAAE,CAAA;CAChB,CAAA;AAgGD,eAAO,MAAM,uBAAuB,8BAIjC,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CA6B/B,CAAA"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
import { traverseFields } from 'payload';
|
|
3
|
+
import { fieldAffectsData } from 'payload/shared';
|
|
4
|
+
function isValidRelationObject(value) {
|
|
5
|
+
return typeof value === 'object' && value !== null && 'relationTo' in value && 'value' in value;
|
|
6
|
+
}
|
|
7
|
+
const convertValue = ({ relatedCollection, value })=>{
|
|
8
|
+
const customIDField = relatedCollection.fields.find((field)=>fieldAffectsData(field) && field.name === 'id');
|
|
9
|
+
if (!customIDField) {
|
|
10
|
+
return new mongoose.Types.ObjectId(value);
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
};
|
|
14
|
+
const sanitizeRelationship = ({ config, field, locale, ref, value })=>{
|
|
15
|
+
let relatedCollection;
|
|
16
|
+
let result = value;
|
|
17
|
+
const hasManyRelations = typeof field.relationTo !== 'string';
|
|
18
|
+
if (!hasManyRelations) {
|
|
19
|
+
relatedCollection = config.collections?.find(({ slug })=>slug === field.relationTo);
|
|
20
|
+
}
|
|
21
|
+
if (Array.isArray(value)) {
|
|
22
|
+
result = value.map((val)=>{
|
|
23
|
+
// Handle has many
|
|
24
|
+
if (relatedCollection && val && (typeof val === 'string' || typeof val === 'number')) {
|
|
25
|
+
return convertValue({
|
|
26
|
+
relatedCollection,
|
|
27
|
+
value: val
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
// Handle has many - polymorphic
|
|
31
|
+
if (isValidRelationObject(val)) {
|
|
32
|
+
const relatedCollectionForSingleValue = config.collections?.find(({ slug })=>slug === val.relationTo);
|
|
33
|
+
if (relatedCollectionForSingleValue) {
|
|
34
|
+
return {
|
|
35
|
+
relationTo: val.relationTo,
|
|
36
|
+
value: convertValue({
|
|
37
|
+
relatedCollection: relatedCollectionForSingleValue,
|
|
38
|
+
value: val.value
|
|
39
|
+
})
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return val;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
// Handle has one - polymorphic
|
|
47
|
+
if (isValidRelationObject(value)) {
|
|
48
|
+
relatedCollection = config.collections?.find(({ slug })=>slug === value.relationTo);
|
|
49
|
+
if (relatedCollection) {
|
|
50
|
+
result = {
|
|
51
|
+
relationTo: value.relationTo,
|
|
52
|
+
value: convertValue({
|
|
53
|
+
relatedCollection,
|
|
54
|
+
value: value.value
|
|
55
|
+
})
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Handle has one
|
|
60
|
+
if (relatedCollection && value && (typeof value === 'string' || typeof value === 'number')) {
|
|
61
|
+
result = convertValue({
|
|
62
|
+
relatedCollection,
|
|
63
|
+
value
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (locale) {
|
|
67
|
+
ref[locale] = result;
|
|
68
|
+
} else {
|
|
69
|
+
ref[field.name] = result;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
export const sanitizeRelationshipIDs = ({ config, data, fields })=>{
|
|
73
|
+
const sanitize = ({ field, ref })=>{
|
|
74
|
+
if (field.type === 'relationship' || field.type === 'upload') {
|
|
75
|
+
// handle localized relationships
|
|
76
|
+
if (config.localization && field.localized) {
|
|
77
|
+
const locales = config.localization.locales;
|
|
78
|
+
const fieldRef = ref[field.name];
|
|
79
|
+
for (const { code } of locales){
|
|
80
|
+
if (ref[field.name]?.[code]) {
|
|
81
|
+
const value = ref[field.name][code];
|
|
82
|
+
sanitizeRelationship({
|
|
83
|
+
config,
|
|
84
|
+
field,
|
|
85
|
+
locale: code,
|
|
86
|
+
ref: fieldRef,
|
|
87
|
+
value
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
// handle non-localized relationships
|
|
93
|
+
sanitizeRelationship({
|
|
94
|
+
config,
|
|
95
|
+
field,
|
|
96
|
+
locale: undefined,
|
|
97
|
+
ref,
|
|
98
|
+
value: ref[field.name]
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
traverseFields({
|
|
104
|
+
callback: sanitize,
|
|
105
|
+
fields,
|
|
106
|
+
ref: data
|
|
107
|
+
});
|
|
108
|
+
return data;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=sanitizeRelationshipIDs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/sanitizeRelationshipIDs.ts"],"sourcesContent":["import type { CollectionConfig, Field, SanitizedConfig, TraverseFieldsCallback } from 'payload'\n\nimport mongoose from 'mongoose'\nimport { traverseFields } from 'payload'\nimport { fieldAffectsData } from 'payload/shared'\n\ntype Args = {\n config: SanitizedConfig\n data: Record<string, unknown>\n fields: Field[]\n}\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 convertValue = ({\n relatedCollection,\n value,\n}: {\n relatedCollection: CollectionConfig\n value: number | string\n}): mongoose.Types.ObjectId | number | string => {\n const customIDField = relatedCollection.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n\n if (!customIDField) {\n return new mongoose.Types.ObjectId(value)\n }\n\n return value\n}\n\nconst sanitizeRelationship = ({ config, field, locale, ref, value }) => {\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\n if (relatedCollection && val && (typeof val === 'string' || typeof val === 'number')) {\n return convertValue({\n relatedCollection,\n value: val,\n })\n }\n\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: convertValue({\n relatedCollection: relatedCollectionForSingleValue,\n value: val.value,\n }),\n }\n }\n }\n\n return val\n })\n }\n\n // Handle has one - polymorphic\n if (isValidRelationObject(value)) {\n relatedCollection = config.collections?.find(({ slug }) => slug === value.relationTo)\n\n if (relatedCollection) {\n result = {\n relationTo: value.relationTo,\n value: convertValue({ relatedCollection, value: value.value }),\n }\n }\n }\n\n // Handle has one\n if (relatedCollection && value && (typeof value === 'string' || typeof value === 'number')) {\n result = convertValue({\n relatedCollection,\n value,\n })\n }\n if (locale) {\n ref[locale] = result\n } else {\n ref[field.name] = result\n }\n}\n\nexport const sanitizeRelationshipIDs = ({\n config,\n data,\n fields,\n}: Args): Record<string, unknown> => {\n const sanitize: TraverseFieldsCallback = ({ field, ref }) => {\n if (field.type === 'relationship' || field.type === 'upload') {\n // handle localized relationships\n if (config.localization && field.localized) {\n const locales = config.localization.locales\n const fieldRef = ref[field.name]\n for (const { code } of locales) {\n if (ref[field.name]?.[code]) {\n const value = ref[field.name][code]\n sanitizeRelationship({ config, field, locale: code, ref: fieldRef, value })\n }\n }\n } else {\n // handle non-localized relationships\n sanitizeRelationship({\n config,\n field,\n locale: undefined,\n ref,\n value: ref[field.name],\n })\n }\n }\n }\n\n traverseFields({ callback: sanitize, fields, ref: data })\n\n return data\n}\n"],"names":["mongoose","traverseFields","fieldAffectsData","isValidRelationObject","value","convertValue","relatedCollection","customIDField","fields","find","field","name","Types","ObjectId","sanitizeRelationship","config","locale","ref","result","hasManyRelations","relationTo","collections","slug","Array","isArray","map","val","relatedCollectionForSingleValue","sanitizeRelationshipIDs","data","sanitize","type","localization","localized","locales","fieldRef","code","undefined","callback"],"mappings":"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"}
|
package/dist/withSession.d.ts
CHANGED
|
@@ -1,35 +1,11 @@
|
|
|
1
|
-
/// <reference types="mongoose/types/aggregate.js" />
|
|
2
|
-
/// <reference types="mongoose/types/callback.js" />
|
|
3
|
-
/// <reference types="mongoose/types/collection.js" />
|
|
4
|
-
/// <reference types="mongoose/types/connection.js" />
|
|
5
|
-
/// <reference types="mongoose/types/cursor.js" />
|
|
6
|
-
/// <reference types="mongoose/types/document.js" />
|
|
7
|
-
/// <reference types="mongoose/types/error.js" />
|
|
8
|
-
/// <reference types="mongoose/types/expressions.js" />
|
|
9
|
-
/// <reference types="mongoose/types/helpers.js" />
|
|
10
|
-
/// <reference types="mongoose/types/middlewares.js" />
|
|
11
|
-
/// <reference types="mongoose/types/indexes.js" />
|
|
12
|
-
/// <reference types="mongoose/types/models.js" />
|
|
13
|
-
/// <reference types="mongoose/types/mongooseoptions.js" />
|
|
14
|
-
/// <reference types="mongoose/types/pipelinestage.js" />
|
|
15
|
-
/// <reference types="mongoose/types/populate.js" />
|
|
16
|
-
/// <reference types="mongoose/types/query.js" />
|
|
17
|
-
/// <reference types="mongoose/types/schemaoptions.js" />
|
|
18
|
-
/// <reference types="mongoose/types/schematypes.js" />
|
|
19
|
-
/// <reference types="mongoose/types/session.js" />
|
|
20
|
-
/// <reference types="mongoose/types/types.js" />
|
|
21
|
-
/// <reference types="mongoose/types/utility.js" />
|
|
22
|
-
/// <reference types="mongoose/types/validation.js" />
|
|
23
|
-
/// <reference types="mongoose/types/virtuals.js" />
|
|
24
|
-
/// <reference types="mongoose/types/inferschematype.js" />
|
|
25
|
-
/// <reference types="mongoose-paginate-v2" />
|
|
26
1
|
import type { ClientSession } from 'mongoose';
|
|
2
|
+
import type { PayloadRequest } from 'payload';
|
|
27
3
|
import type { MongooseAdapter } from './index.js';
|
|
28
4
|
/**
|
|
29
5
|
* returns the session belonging to the transaction of the req.session if exists
|
|
30
6
|
* @returns ClientSession
|
|
31
7
|
*/
|
|
32
|
-
export declare function withSession(db: MongooseAdapter,
|
|
8
|
+
export declare function withSession(db: MongooseAdapter, req: PayloadRequest): Promise<{
|
|
33
9
|
session: ClientSession;
|
|
34
|
-
} |
|
|
10
|
+
} | Record<string, never>>;
|
|
35
11
|
//# sourceMappingURL=withSession.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withSession.d.ts","sourceRoot":"","sources":["../src/withSession.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"withSession.d.ts","sourceRoot":"","sources":["../src/withSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,EAAE,EAAE,eAAe,EACnB,GAAG,EAAE,cAAc,GAClB,OAAO,CAAC;IAAE,OAAO,EAAE,aAAa,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAU7D"}
|
package/dist/withSession.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* returns the session belonging to the transaction of the req.session if exists
|
|
3
3
|
* @returns ClientSession
|
|
4
|
-
*/ export function withSession(db,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
*/ export async function withSession(db, req) {
|
|
5
|
+
let transactionID = req.transactionID;
|
|
6
|
+
if (transactionID instanceof Promise) {
|
|
7
|
+
transactionID = await req.transactionID;
|
|
8
|
+
}
|
|
9
|
+
if (req) {
|
|
10
|
+
return db.sessions[transactionID] ? {
|
|
11
|
+
session: db.sessions[transactionID]
|
|
12
|
+
} : {};
|
|
13
|
+
}
|
|
8
14
|
}
|
|
9
15
|
|
|
10
16
|
//# sourceMappingURL=withSession.js.map
|
package/dist/withSession.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/withSession.ts"],"sourcesContent":["import type { ClientSession } from 'mongoose'\n\nimport type { MongooseAdapter } from './index.js'\n\n/**\n * returns the session belonging to the transaction of the req.session if exists\n * @returns ClientSession\n */\nexport function withSession(\n db: MongooseAdapter,\n
|
|
1
|
+
{"version":3,"sources":["../src/withSession.ts"],"sourcesContent":["import type { ClientSession } from 'mongoose'\nimport type { PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\n/**\n * returns the session belonging to the transaction of the req.session if exists\n * @returns ClientSession\n */\nexport async function withSession(\n db: MongooseAdapter,\n req: PayloadRequest,\n): Promise<{ session: ClientSession } | Record<string, never>> {\n let transactionID = req.transactionID\n\n if (transactionID instanceof Promise) {\n transactionID = await req.transactionID\n }\n\n if (req) {\n return db.sessions[transactionID] ? { session: db.sessions[transactionID] } : {}\n }\n}\n"],"names":["withSession","db","req","transactionID","Promise","sessions","session"],"mappings":"AAKA;;;CAGC,GACD,OAAO,eAAeA,YACpBC,EAAmB,EACnBC,GAAmB;IAEnB,IAAIC,gBAAgBD,IAAIC,aAAa;IAErC,IAAIA,yBAAyBC,SAAS;QACpCD,gBAAgB,MAAMD,IAAIC,aAAa;IACzC;IAEA,IAAID,KAAK;QACP,OAAOD,GAAGI,QAAQ,CAACF,cAAc,GAAG;YAAEG,SAASL,GAAGI,QAAQ,CAACF,cAAc;QAAC,IAAI,CAAC;IACjF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,58 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/db-mongodb",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.111",
|
|
4
4
|
"description": "The officially supported MongoDB database adapter for Payload",
|
|
5
|
+
"homepage": "https://payloadcms.com",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
8
|
"url": "https://github.com/payloadcms/payload.git",
|
|
8
9
|
"directory": "packages/db-mongodb"
|
|
9
10
|
},
|
|
10
11
|
"license": "MIT",
|
|
11
|
-
"
|
|
12
|
+
"author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
|
|
12
13
|
"type": "module",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
17
20
|
},
|
|
18
21
|
"main": "./dist/index.js",
|
|
19
22
|
"types": "./dist/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"mock.js",
|
|
26
|
+
"predefinedMigrations"
|
|
27
|
+
],
|
|
20
28
|
"dependencies": {
|
|
21
29
|
"bson-objectid": "2.0.4",
|
|
22
|
-
"deepmerge": "4.3.1",
|
|
23
|
-
"get-port": "5.1.1",
|
|
24
30
|
"http-status": "1.6.2",
|
|
25
31
|
"mongoose": "6.12.3",
|
|
32
|
+
"mongoose-aggregate-paginate-v2": "1.0.6",
|
|
26
33
|
"mongoose-paginate-v2": "1.7.22",
|
|
27
34
|
"prompts": "2.4.2",
|
|
28
|
-
"uuid": "
|
|
35
|
+
"uuid": "10.0.0"
|
|
29
36
|
},
|
|
30
37
|
"devDependencies": {
|
|
31
|
-
"@types/mongoose-aggregate-paginate-v2": "1.0.
|
|
38
|
+
"@types/mongoose-aggregate-paginate-v2": "1.0.6",
|
|
32
39
|
"mongodb": "4.17.1",
|
|
33
40
|
"mongodb-memory-server": "^9",
|
|
34
|
-
"@payloadcms/eslint-config": "
|
|
35
|
-
"payload": "3.0.0-beta.
|
|
41
|
+
"@payloadcms/eslint-config": "3.0.0-beta.97",
|
|
42
|
+
"payload": "3.0.0-beta.111"
|
|
36
43
|
},
|
|
37
44
|
"peerDependencies": {
|
|
38
|
-
"payload": "3.0.0-beta.
|
|
45
|
+
"payload": "3.0.0-beta.111"
|
|
39
46
|
},
|
|
40
|
-
"exports": {
|
|
41
|
-
".": {
|
|
42
|
-
"import": "./dist/index.js",
|
|
43
|
-
"require": "./dist/index.js",
|
|
44
|
-
"types": "./dist/index.d.ts"
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"files": [
|
|
48
|
-
"dist",
|
|
49
|
-
"mock.js",
|
|
50
|
-
"predefinedMigrations"
|
|
51
|
-
],
|
|
52
47
|
"scripts": {
|
|
53
|
-
"build": "pnpm build:
|
|
54
|
-
"build:swc": "swc ./src -d ./dist --config-file .swcrc-build",
|
|
48
|
+
"build": "pnpm build:types && pnpm build:swc",
|
|
49
|
+
"build:swc": "swc ./src -d ./dist --config-file .swcrc-build --strip-leading-paths",
|
|
55
50
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
56
|
-
"clean": "rimraf {dist,*.tsbuildinfo}"
|
|
51
|
+
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
52
|
+
"lint": "eslint .",
|
|
53
|
+
"lint:fix": "eslint . --fix"
|
|
57
54
|
}
|
|
58
55
|
}
|
package/src/index.ts
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import type { TransactionOptions } from 'mongodb'
|
|
2
|
-
import type { MongoMemoryReplSet } from 'mongodb-memory-server'
|
|
3
|
-
import type { ClientSession, ConnectOptions, Connection } from 'mongoose'
|
|
4
|
-
import type { Payload } from 'payload'
|
|
5
|
-
import type { BaseDatabaseAdapter, DatabaseAdapterObj } from 'payload/database'
|
|
6
|
-
|
|
7
|
-
import fs from 'fs'
|
|
8
|
-
import mongoose from 'mongoose'
|
|
9
|
-
import path from 'path'
|
|
10
|
-
import { createDatabaseAdapter } from 'payload/database'
|
|
11
|
-
|
|
12
|
-
import type { CollectionModel, GlobalModel } from './types.js'
|
|
13
|
-
|
|
14
|
-
import { connect } from './connect.js'
|
|
15
|
-
import { create } from './create.js'
|
|
16
|
-
import { createGlobal } from './createGlobal.js'
|
|
17
|
-
import { createGlobalVersion } from './createGlobalVersion.js'
|
|
18
|
-
import { createMigration } from './createMigration.js'
|
|
19
|
-
import { createVersion } from './createVersion.js'
|
|
20
|
-
import { deleteMany } from './deleteMany.js'
|
|
21
|
-
import { deleteOne } from './deleteOne.js'
|
|
22
|
-
import { deleteVersions } from './deleteVersions.js'
|
|
23
|
-
import { destroy } from './destroy.js'
|
|
24
|
-
import { find } from './find.js'
|
|
25
|
-
import { findGlobal } from './findGlobal.js'
|
|
26
|
-
import { findGlobalVersions } from './findGlobalVersions.js'
|
|
27
|
-
import { findOne } from './findOne.js'
|
|
28
|
-
import { findVersions } from './findVersions.js'
|
|
29
|
-
import { init } from './init.js'
|
|
30
|
-
import { migrateFresh } from './migrateFresh.js'
|
|
31
|
-
import { queryDrafts } from './queryDrafts.js'
|
|
32
|
-
import { beginTransaction } from './transactions/beginTransaction.js'
|
|
33
|
-
import { commitTransaction } from './transactions/commitTransaction.js'
|
|
34
|
-
import { rollbackTransaction } from './transactions/rollbackTransaction.js'
|
|
35
|
-
import { updateGlobal } from './updateGlobal.js'
|
|
36
|
-
import { updateGlobalVersion } from './updateGlobalVersion.js'
|
|
37
|
-
import { updateOne } from './updateOne.js'
|
|
38
|
-
import { updateVersion } from './updateVersion.js'
|
|
39
|
-
|
|
40
|
-
export type { MigrateDownArgs, MigrateUpArgs } from './types.js'
|
|
41
|
-
|
|
42
|
-
export interface Args {
|
|
43
|
-
/** Set to false to disable auto-pluralization of collection names, Defaults to true */
|
|
44
|
-
autoPluralization?: boolean
|
|
45
|
-
/** Extra configuration options */
|
|
46
|
-
connectOptions?: ConnectOptions & {
|
|
47
|
-
/** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */
|
|
48
|
-
useFacet?: boolean
|
|
49
|
-
}
|
|
50
|
-
/** 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 */
|
|
51
|
-
disableIndexHints?: boolean
|
|
52
|
-
migrationDir?: string
|
|
53
|
-
/**
|
|
54
|
-
* typed as any to avoid dependency
|
|
55
|
-
*/
|
|
56
|
-
mongoMemoryServer?: MongoMemoryReplSet
|
|
57
|
-
transactionOptions?: TransactionOptions | false
|
|
58
|
-
/** The URL to connect to MongoDB or false to start payload and prevent connecting */
|
|
59
|
-
url: false | string
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export type MongooseAdapter = BaseDatabaseAdapter &
|
|
63
|
-
Args & {
|
|
64
|
-
collections: {
|
|
65
|
-
[slug: string]: CollectionModel
|
|
66
|
-
}
|
|
67
|
-
connection: Connection
|
|
68
|
-
globals: GlobalModel
|
|
69
|
-
mongoMemoryServer: MongoMemoryReplSet
|
|
70
|
-
sessions: Record<number | string, ClientSession>
|
|
71
|
-
versions: {
|
|
72
|
-
[slug: string]: CollectionModel
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
declare module 'payload' {
|
|
77
|
-
export interface DatabaseAdapter
|
|
78
|
-
extends Omit<BaseDatabaseAdapter, 'sessions'>,
|
|
79
|
-
Omit<Args, 'migrationDir'> {
|
|
80
|
-
collections: {
|
|
81
|
-
[slug: string]: CollectionModel
|
|
82
|
-
}
|
|
83
|
-
connection: Connection
|
|
84
|
-
globals: GlobalModel
|
|
85
|
-
mongoMemoryServer: MongoMemoryReplSet
|
|
86
|
-
sessions: Record<number | string, ClientSession>
|
|
87
|
-
transactionOptions: TransactionOptions
|
|
88
|
-
versions: {
|
|
89
|
-
[slug: string]: CollectionModel
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function mongooseAdapter({
|
|
95
|
-
autoPluralization = true,
|
|
96
|
-
connectOptions,
|
|
97
|
-
disableIndexHints = false,
|
|
98
|
-
migrationDir: migrationDirArg,
|
|
99
|
-
mongoMemoryServer,
|
|
100
|
-
transactionOptions = {},
|
|
101
|
-
url,
|
|
102
|
-
}: Args): DatabaseAdapterObj {
|
|
103
|
-
function adapter({ payload }: { payload: Payload }) {
|
|
104
|
-
const migrationDir = findMigrationDir(migrationDirArg)
|
|
105
|
-
mongoose.set('strictQuery', false)
|
|
106
|
-
|
|
107
|
-
return createDatabaseAdapter<MongooseAdapter>({
|
|
108
|
-
name: 'mongoose',
|
|
109
|
-
|
|
110
|
-
// Mongoose-specific
|
|
111
|
-
autoPluralization,
|
|
112
|
-
collections: {},
|
|
113
|
-
connectOptions: connectOptions || {},
|
|
114
|
-
connection: undefined,
|
|
115
|
-
disableIndexHints,
|
|
116
|
-
globals: undefined,
|
|
117
|
-
mongoMemoryServer,
|
|
118
|
-
sessions: {},
|
|
119
|
-
transactionOptions: transactionOptions === false ? undefined : transactionOptions,
|
|
120
|
-
url,
|
|
121
|
-
versions: {},
|
|
122
|
-
|
|
123
|
-
// DatabaseAdapter
|
|
124
|
-
beginTransaction: transactionOptions ? beginTransaction : undefined,
|
|
125
|
-
commitTransaction,
|
|
126
|
-
connect,
|
|
127
|
-
create,
|
|
128
|
-
createGlobal,
|
|
129
|
-
createGlobalVersion,
|
|
130
|
-
createMigration,
|
|
131
|
-
createVersion,
|
|
132
|
-
defaultIDType: 'text',
|
|
133
|
-
deleteMany,
|
|
134
|
-
deleteOne,
|
|
135
|
-
deleteVersions,
|
|
136
|
-
destroy,
|
|
137
|
-
find,
|
|
138
|
-
findGlobal,
|
|
139
|
-
findGlobalVersions,
|
|
140
|
-
findOne,
|
|
141
|
-
findVersions,
|
|
142
|
-
init,
|
|
143
|
-
migrateFresh,
|
|
144
|
-
migrationDir,
|
|
145
|
-
payload,
|
|
146
|
-
queryDrafts,
|
|
147
|
-
rollbackTransaction,
|
|
148
|
-
updateGlobal,
|
|
149
|
-
updateGlobalVersion,
|
|
150
|
-
updateOne,
|
|
151
|
-
updateVersion,
|
|
152
|
-
})
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
defaultIDType: 'text',
|
|
157
|
-
init: adapter,
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Attempt to find migrations directory.
|
|
163
|
-
*
|
|
164
|
-
* Checks for the following directories in order:
|
|
165
|
-
* - `migrationDir` argument from Payload config
|
|
166
|
-
* - `src/migrations`
|
|
167
|
-
* - `dist/migrations`
|
|
168
|
-
* - `migrations`
|
|
169
|
-
*
|
|
170
|
-
* Defaults to `src/migrations`
|
|
171
|
-
*
|
|
172
|
-
* @param migrationDir
|
|
173
|
-
* @returns
|
|
174
|
-
*/
|
|
175
|
-
function findMigrationDir(migrationDir?: string): string {
|
|
176
|
-
const cwd = process.cwd()
|
|
177
|
-
const srcDir = path.resolve(cwd, 'src/migrations')
|
|
178
|
-
const distDir = path.resolve(cwd, 'dist/migrations')
|
|
179
|
-
const relativeMigrations = path.resolve(cwd, 'migrations')
|
|
180
|
-
|
|
181
|
-
// Use arg if provided
|
|
182
|
-
if (migrationDir) return migrationDir
|
|
183
|
-
|
|
184
|
-
// Check other common locations
|
|
185
|
-
if (fs.existsSync(srcDir)) {
|
|
186
|
-
return srcDir
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (fs.existsSync(distDir)) {
|
|
190
|
-
return distDir
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (fs.existsSync(relativeMigrations)) {
|
|
194
|
-
return relativeMigrations
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return srcDir
|
|
198
|
-
}
|