@payloadcms/db-mongodb 3.0.0-canary.6041f49 → 3.0.0-canary.67aae47

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. package/README.md +1 -1
  2. package/dist/connect.d.ts +1 -1
  3. package/dist/connect.d.ts.map +1 -1
  4. package/dist/connect.js +13 -4
  5. package/dist/connect.js.map +1 -1
  6. package/dist/count.d.ts +1 -1
  7. package/dist/count.d.ts.map +1 -1
  8. package/dist/count.js +10 -3
  9. package/dist/count.js.map +1 -1
  10. package/dist/countGlobalVersions.d.ts +3 -0
  11. package/dist/countGlobalVersions.d.ts.map +1 -0
  12. package/dist/countGlobalVersions.js +40 -0
  13. package/dist/countGlobalVersions.js.map +1 -0
  14. package/dist/countVersions.d.ts +3 -0
  15. package/dist/countVersions.d.ts.map +1 -0
  16. package/dist/countVersions.js +40 -0
  17. package/dist/countVersions.js.map +1 -0
  18. package/dist/create.d.ts +1 -1
  19. package/dist/create.d.ts.map +1 -1
  20. package/dist/create.js +17 -4
  21. package/dist/create.js.map +1 -1
  22. package/dist/createGlobal.d.ts +1 -1
  23. package/dist/createGlobal.d.ts.map +1 -1
  24. package/dist/createGlobal.js +11 -6
  25. package/dist/createGlobal.js.map +1 -1
  26. package/dist/createGlobalVersion.d.ts +1 -1
  27. package/dist/createGlobalVersion.d.ts.map +1 -1
  28. package/dist/createGlobalVersion.js +14 -5
  29. package/dist/createGlobalVersion.js.map +1 -1
  30. package/dist/createMigration.d.ts +1 -1
  31. package/dist/createMigration.d.ts.map +1 -1
  32. package/dist/createMigration.js +20 -32
  33. package/dist/createMigration.js.map +1 -1
  34. package/dist/createVersion.d.ts +1 -1
  35. package/dist/createVersion.d.ts.map +1 -1
  36. package/dist/createVersion.js +32 -10
  37. package/dist/createVersion.js.map +1 -1
  38. package/dist/deleteMany.d.ts +1 -1
  39. package/dist/deleteMany.d.ts.map +1 -1
  40. package/dist/deleteMany.js +1 -1
  41. package/dist/deleteMany.js.map +1 -1
  42. package/dist/deleteOne.d.ts +1 -1
  43. package/dist/deleteOne.d.ts.map +1 -1
  44. package/dist/deleteOne.js +12 -4
  45. package/dist/deleteOne.js.map +1 -1
  46. package/dist/deleteVersions.d.ts +1 -1
  47. package/dist/deleteVersions.d.ts.map +1 -1
  48. package/dist/deleteVersions.js +1 -1
  49. package/dist/deleteVersions.js.map +1 -1
  50. package/dist/destroy.d.ts +1 -1
  51. package/dist/destroy.d.ts.map +1 -1
  52. package/dist/destroy.js.map +1 -1
  53. package/dist/find.d.ts +1 -1
  54. package/dist/find.d.ts.map +1 -1
  55. package/dist/find.js +36 -7
  56. package/dist/find.js.map +1 -1
  57. package/dist/findGlobal.d.ts +1 -1
  58. package/dist/findGlobal.d.ts.map +1 -1
  59. package/dist/findGlobal.js +11 -5
  60. package/dist/findGlobal.js.map +1 -1
  61. package/dist/findGlobalVersions.d.ts +1 -1
  62. package/dist/findGlobalVersions.d.ts.map +1 -1
  63. package/dist/findGlobalVersions.js +19 -9
  64. package/dist/findGlobalVersions.js.map +1 -1
  65. package/dist/findOne.d.ts +1 -1
  66. package/dist/findOne.d.ts.map +1 -1
  67. package/dist/findOne.js +28 -4
  68. package/dist/findOne.js.map +1 -1
  69. package/dist/findVersions.d.ts +1 -1
  70. package/dist/findVersions.d.ts.map +1 -1
  71. package/dist/findVersions.js +17 -6
  72. package/dist/findVersions.js.map +1 -1
  73. package/dist/index.d.ts +52 -35
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +17 -7
  76. package/dist/index.js.map +1 -1
  77. package/dist/init.d.ts +1 -1
  78. package/dist/init.d.ts.map +1 -1
  79. package/dist/init.js +11 -8
  80. package/dist/init.js.map +1 -1
  81. package/dist/migrateFresh.d.ts.map +1 -1
  82. package/dist/migrateFresh.js +1 -1
  83. package/dist/migrateFresh.js.map +1 -1
  84. package/dist/models/buildCollectionSchema.d.ts +2 -29
  85. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  86. package/dist/models/buildCollectionSchema.js +16 -4
  87. package/dist/models/buildCollectionSchema.js.map +1 -1
  88. package/dist/models/buildGlobalModel.d.ts +1 -1
  89. package/dist/models/buildGlobalModel.d.ts.map +1 -1
  90. package/dist/models/buildGlobalModel.js +2 -2
  91. package/dist/models/buildGlobalModel.js.map +1 -1
  92. package/dist/models/buildSchema.d.ts +2 -29
  93. package/dist/models/buildSchema.d.ts.map +1 -1
  94. package/dist/models/buildSchema.js +116 -23
  95. package/dist/models/buildSchema.js.map +1 -1
  96. package/{predefinedMigrations → dist/predefinedMigrations}/versions-v1-v2.js +3 -1
  97. package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -0
  98. package/dist/queries/buildAndOrConditions.d.ts +1 -2
  99. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  100. package/dist/queries/buildAndOrConditions.js +0 -2
  101. package/dist/queries/buildAndOrConditions.js.map +1 -1
  102. package/dist/queries/buildQuery.d.ts +3 -4
  103. package/dist/queries/buildQuery.d.ts.map +1 -1
  104. package/dist/queries/buildQuery.js +2 -3
  105. package/dist/queries/buildQuery.js.map +1 -1
  106. package/dist/queries/buildSearchParams.d.ts +1 -2
  107. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  108. package/dist/queries/buildSearchParams.js +34 -22
  109. package/dist/queries/buildSearchParams.js.map +1 -1
  110. package/dist/queries/buildSortParam.d.ts +3 -29
  111. package/dist/queries/buildSortParam.d.ts.map +1 -1
  112. package/dist/queries/buildSortParam.js +26 -17
  113. package/dist/queries/buildSortParam.js.map +1 -1
  114. package/dist/queries/getLocalizedSortProperty.d.ts +1 -2
  115. package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
  116. package/dist/queries/getLocalizedSortProperty.js +2 -2
  117. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  118. package/dist/queries/getLocalizedSortProperty.spec.js +44 -44
  119. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  120. package/dist/queries/mock.js.map +1 -1
  121. package/dist/queries/operatorMap.js.map +1 -1
  122. package/dist/queries/parseParams.d.ts +1 -3
  123. package/dist/queries/parseParams.d.ts.map +1 -1
  124. package/dist/queries/parseParams.js +8 -6
  125. package/dist/queries/parseParams.js.map +1 -1
  126. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  127. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  128. package/dist/queries/sanitizeQueryValue.js +145 -28
  129. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  130. package/dist/queryDrafts.d.ts +1 -1
  131. package/dist/queryDrafts.d.ts.map +1 -1
  132. package/dist/queryDrafts.js +37 -10
  133. package/dist/queryDrafts.js.map +1 -1
  134. package/dist/testCredentials.js.map +1 -1
  135. package/dist/transactions/beginTransaction.d.ts +1 -1
  136. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  137. package/dist/transactions/beginTransaction.js +3 -1
  138. package/dist/transactions/beginTransaction.js.map +1 -1
  139. package/dist/transactions/commitTransaction.d.ts +1 -1
  140. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  141. package/dist/transactions/commitTransaction.js +3 -0
  142. package/dist/transactions/commitTransaction.js.map +1 -1
  143. package/dist/transactions/rollbackTransaction.d.ts +1 -1
  144. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  145. package/dist/transactions/rollbackTransaction.js +13 -7
  146. package/dist/transactions/rollbackTransaction.js.map +1 -1
  147. package/dist/types.d.ts +7 -31
  148. package/dist/types.d.ts.map +1 -1
  149. package/dist/types.js.map +1 -1
  150. package/dist/updateGlobal.d.ts +1 -1
  151. package/dist/updateGlobal.d.ts.map +1 -1
  152. package/dist/updateGlobal.js +18 -5
  153. package/dist/updateGlobal.js.map +1 -1
  154. package/dist/updateGlobalVersion.d.ts +2 -3
  155. package/dist/updateGlobalVersion.d.ts.map +1 -1
  156. package/dist/updateGlobalVersion.js +19 -5
  157. package/dist/updateGlobalVersion.js.map +1 -1
  158. package/dist/updateOne.d.ts +1 -1
  159. package/dist/updateOne.d.ts.map +1 -1
  160. package/dist/updateOne.js +25 -7
  161. package/dist/updateOne.js.map +1 -1
  162. package/dist/updateVersion.d.ts +1 -1
  163. package/dist/updateVersion.d.ts.map +1 -1
  164. package/dist/updateVersion.js +18 -4
  165. package/dist/updateVersion.js.map +1 -1
  166. package/dist/upsert.d.ts +3 -0
  167. package/dist/upsert.d.ts.map +1 -0
  168. package/dist/upsert.js +15 -0
  169. package/dist/upsert.js.map +1 -0
  170. package/dist/utilities/buildJoinAggregation.d.ts +18 -0
  171. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
  172. package/dist/utilities/buildJoinAggregation.js +159 -0
  173. package/dist/utilities/buildJoinAggregation.js.map +1 -0
  174. package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
  175. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
  176. package/dist/utilities/buildProjectionFromSelect.js +171 -0
  177. package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
  178. package/dist/utilities/getDBName.d.ts +1 -1
  179. package/dist/utilities/getDBName.d.ts.map +1 -1
  180. package/dist/utilities/getDBName.js +3 -1
  181. package/dist/utilities/getDBName.js.map +1 -1
  182. package/dist/utilities/handleError.d.ts +6 -2
  183. package/dist/utilities/handleError.d.ts.map +1 -1
  184. package/dist/utilities/handleError.js +12 -9
  185. package/dist/utilities/handleError.js.map +1 -1
  186. package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
  187. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  188. package/dist/utilities/sanitizeInternalFields.js +1 -2
  189. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  190. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  191. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  192. package/dist/utilities/sanitizeRelationshipIDs.js +115 -0
  193. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  194. package/dist/withSession.d.ts +3 -27
  195. package/dist/withSession.d.ts.map +1 -1
  196. package/dist/withSession.js +10 -4
  197. package/dist/withSession.js.map +1 -1
  198. package/package.json +17 -17
@@ -0,0 +1,115 @@
1
+ import { Types } from 'mongoose';
2
+ import { APIError, 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
+ try {
11
+ return new Types.ObjectId(value);
12
+ } catch (error) {
13
+ throw new APIError(`Failed to create ObjectId from value: ${value}. Error: ${error.message}`, 400);
14
+ }
15
+ }
16
+ return value;
17
+ };
18
+ const sanitizeRelationship = ({ config, field, locale, ref, value })=>{
19
+ let relatedCollection;
20
+ let result = value;
21
+ const hasManyRelations = typeof field.relationTo !== 'string';
22
+ if (!hasManyRelations) {
23
+ relatedCollection = config.collections?.find(({ slug })=>slug === field.relationTo);
24
+ }
25
+ if (Array.isArray(value)) {
26
+ result = value.map((val)=>{
27
+ // Handle has many
28
+ if (relatedCollection && val && (typeof val === 'string' || typeof val === 'number')) {
29
+ return convertValue({
30
+ relatedCollection,
31
+ value: val
32
+ });
33
+ }
34
+ // Handle has many - polymorphic
35
+ if (isValidRelationObject(val)) {
36
+ const relatedCollectionForSingleValue = config.collections?.find(({ slug })=>slug === val.relationTo);
37
+ if (relatedCollectionForSingleValue) {
38
+ return {
39
+ relationTo: val.relationTo,
40
+ value: convertValue({
41
+ relatedCollection: relatedCollectionForSingleValue,
42
+ value: val.value
43
+ })
44
+ };
45
+ }
46
+ }
47
+ return val;
48
+ });
49
+ }
50
+ // Handle has one - polymorphic
51
+ if (isValidRelationObject(value)) {
52
+ relatedCollection = config.collections?.find(({ slug })=>slug === value.relationTo);
53
+ if (relatedCollection) {
54
+ result = {
55
+ relationTo: value.relationTo,
56
+ value: convertValue({
57
+ relatedCollection,
58
+ value: value.value
59
+ })
60
+ };
61
+ }
62
+ }
63
+ // Handle has one
64
+ if (relatedCollection && value && (typeof value === 'string' || typeof value === 'number')) {
65
+ result = convertValue({
66
+ relatedCollection,
67
+ value
68
+ });
69
+ }
70
+ if (locale) {
71
+ ref[locale] = result;
72
+ } else {
73
+ ref[field.name] = result;
74
+ }
75
+ };
76
+ export const sanitizeRelationshipIDs = ({ config, data, fields })=>{
77
+ const sanitize = ({ field, ref })=>{
78
+ if (field.type === 'relationship' || field.type === 'upload') {
79
+ // handle localized relationships
80
+ if (config.localization && field.localized) {
81
+ const locales = config.localization.locales;
82
+ const fieldRef = ref[field.name];
83
+ for (const { code } of locales){
84
+ if (ref[field.name]?.[code]) {
85
+ const value = ref[field.name][code];
86
+ sanitizeRelationship({
87
+ config,
88
+ field,
89
+ locale: code,
90
+ ref: fieldRef,
91
+ value
92
+ });
93
+ }
94
+ }
95
+ } else {
96
+ // handle non-localized relationships
97
+ sanitizeRelationship({
98
+ config,
99
+ field,
100
+ locale: undefined,
101
+ ref,
102
+ value: ref[field.name]
103
+ });
104
+ }
105
+ }
106
+ };
107
+ traverseFields({
108
+ callback: sanitize,
109
+ fields,
110
+ ref: data
111
+ });
112
+ return data;
113
+ };
114
+
115
+ //# 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 { Types } from 'mongoose'\nimport { APIError, 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}): number | string | Types.ObjectId => {\n const customIDField = relatedCollection.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n\n if (!customIDField) {\n try {\n return new Types.ObjectId(value)\n } catch (error) {\n throw new APIError(\n `Failed to create ObjectId from value: ${value}. Error: ${error.message}`,\n 400,\n )\n }\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":["Types","APIError","traverseFields","fieldAffectsData","isValidRelationObject","value","convertValue","relatedCollection","customIDField","fields","find","field","name","ObjectId","error","message","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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"}
@@ -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, transactionID?: number | string): {
8
+ export declare function withSession(db: MongooseAdapter, req: PayloadRequest): Promise<{
33
9
  session: ClientSession;
34
- } | object;
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":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;;GAGG;AACH,wBAAgB,WAAW,CACzB,EAAE,EAAE,eAAe,EACnB,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,GAC9B;IAAE,OAAO,EAAE,aAAa,CAAA;CAAE,GAAG,MAAM,CAErC"}
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"}
@@ -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, transactionID) {
5
- return db.sessions[transactionID] ? {
6
- session: db.sessions[transactionID]
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
@@ -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 transactionID?: number | string,\n): { session: ClientSession } | object {\n return db.sessions[transactionID] ? { session: db.sessions[transactionID] } : {}\n}\n"],"names":["withSession","db","transactionID","sessions","session"],"rangeMappings":";;;;;;;","mappings":"AAIA;;;CAGC,GACD,OAAO,SAASA,YACdC,EAAmB,EACnBC,aAA+B;IAE/B,OAAOD,GAAGE,QAAQ,CAACD,cAAc,GAAG;QAAEE,SAASH,GAAGE,QAAQ,CAACD,cAAc;IAAC,IAAI,CAAC;AACjF"}
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/db-mongodb",
3
- "version": "3.0.0-canary.6041f49",
3
+ "version": "3.0.0-canary.67aae47",
4
4
  "description": "The officially supported MongoDB database adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -14,8 +14,8 @@
14
14
  "exports": {
15
15
  ".": {
16
16
  "import": "./dist/index.js",
17
- "require": "./dist/index.js",
18
- "types": "./dist/index.d.ts"
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
19
  }
20
20
  },
21
21
  "main": "./dist/index.js",
@@ -26,29 +26,29 @@
26
26
  "predefinedMigrations"
27
27
  ],
28
28
  "dependencies": {
29
- "bson-objectid": "2.0.4",
30
- "deepmerge": "4.3.1",
31
- "get-port": "5.1.1",
32
29
  "http-status": "1.6.2",
33
- "mongoose": "6.12.3",
34
- "mongoose-paginate-v2": "1.7.22",
30
+ "mongoose": "8.8.1",
31
+ "mongoose-aggregate-paginate-v2": "1.1.2",
32
+ "mongoose-paginate-v2": "1.8.5",
35
33
  "prompts": "2.4.2",
36
- "uuid": "9.0.0"
34
+ "uuid": "10.0.0"
37
35
  },
38
36
  "devDependencies": {
39
- "@types/mongoose-aggregate-paginate-v2": "1.0.9",
40
- "mongodb": "4.17.1",
37
+ "@types/mongoose-aggregate-paginate-v2": "1.0.12",
38
+ "mongodb": "6.10.0",
41
39
  "mongodb-memory-server": "^9",
42
- "@payloadcms/eslint-config": "1.1.1",
43
- "payload": "3.0.0-canary.6041f49"
40
+ "@payloadcms/eslint-config": "3.0.0-beta.112",
41
+ "payload": "3.0.0-canary.67aae47"
44
42
  },
45
43
  "peerDependencies": {
46
- "payload": "3.0.0-canary.6041f49"
44
+ "payload": "3.0.0-canary.67aae47"
47
45
  },
48
46
  "scripts": {
49
- "build": "pnpm build:swc && pnpm build:types",
50
- "build:swc": "swc ./src -d ./dist --config-file .swcrc-build",
47
+ "build": "pnpm build:types && pnpm build:swc",
48
+ "build:swc": "swc ./src -d ./dist --config-file .swcrc-build --strip-leading-paths",
51
49
  "build:types": "tsc --emitDeclarationOnly --outDir dist",
52
- "clean": "rimraf {dist,*.tsbuildinfo}"
50
+ "clean": "rimraf {dist,*.tsbuildinfo}",
51
+ "lint": "eslint .",
52
+ "lint:fix": "eslint . --fix"
53
53
  }
54
54
  }