@payloadcms/db-mongodb 4.0.0-internal.ea6e8f8 → 4.0.0-internal.ee5d8bd
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/connect.d.ts.map +1 -1
- package/dist/connect.js +0 -1
- package/dist/connect.js.map +1 -1
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +4 -33
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts.map +1 -1
- package/dist/countGlobalVersions.js +0 -1
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +4 -36
- package/dist/countVersions.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +0 -22
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +3 -16
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +0 -1
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +1 -20
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +0 -1
- package/dist/deleteVersions.js.map +1 -1
- package/dist/exports/migration-utils.d.ts +0 -1
- package/dist/exports/migration-utils.d.ts.map +1 -1
- package/dist/exports/migration-utils.js +0 -1
- package/dist/exports/migration-utils.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +8 -44
- package/dist/find.js.map +1 -1
- package/dist/findDistinct.d.ts.map +1 -1
- package/dist/findDistinct.js +11 -70
- package/dist/findDistinct.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +5 -34
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +2 -10
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +5 -43
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +5 -49
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +1 -30
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +10 -30
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/migrateSizesToVariants.js.map +1 -1
- package/dist/queries/buildAndOrConditions.d.ts +2 -4
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +1 -3
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +2 -4
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +1 -3
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts +2 -4
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +44 -175
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/getBuildQueryPlugin.d.ts +1 -3
- package/dist/queries/getBuildQueryPlugin.d.ts.map +1 -1
- package/dist/queries/getBuildQueryPlugin.js +1 -3
- package/dist/queries/getBuildQueryPlugin.js.map +1 -1
- package/dist/queries/parseParams.d.ts +2 -4
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +1 -5
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +7 -38
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +7 -55
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
- package/dist/transactions/rollbackTransaction.js +9 -10
- package/dist/transactions/rollbackTransaction.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +7 -87
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +0 -1
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateMany.d.ts.map +1 -1
- package/dist/updateMany.js +1 -3
- package/dist/updateMany.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +2 -28
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +0 -1
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/aggregatePaginate.d.ts +1 -2
- package/dist/utilities/aggregatePaginate.d.ts.map +1 -1
- package/dist/utilities/aggregatePaginate.js +4 -18
- package/dist/utilities/aggregatePaginate.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.d.ts +2 -4
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +23 -118
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/resolveJoins.d.ts +2 -6
- package/dist/utilities/resolveJoins.d.ts.map +1 -1
- package/dist/utilities/resolveJoins.js +26 -114
- package/dist/utilities/resolveJoins.js.map +1 -1
- package/package.json +16 -19
- package/dist/deleteBranchGlobal.d.ts +0 -10
- package/dist/deleteBranchGlobal.d.ts.map +0 -1
- package/dist/deleteBranchGlobal.js +0 -22
- package/dist/deleteBranchGlobal.js.map +0 -1
- package/dist/predefinedMigrations/branching.d.ts +0 -4
- package/dist/predefinedMigrations/branching.d.ts.map +0 -1
- package/dist/predefinedMigrations/branching.js +0 -9
- package/dist/predefinedMigrations/branching.js.map +0 -1
- package/dist/predefinedMigrations/migrateBranching.d.ts +0 -15
- package/dist/predefinedMigrations/migrateBranching.d.ts.map +0 -1
- package/dist/predefinedMigrations/migrateBranching.js +0 -88
- package/dist/predefinedMigrations/migrateBranching.js.map +0 -1
- package/dist/queries/buildBranchVisibility.d.ts +0 -11
- package/dist/queries/buildBranchVisibility.d.ts.map +0 -1
- package/dist/queries/buildBranchVisibility.js +0 -204
- package/dist/queries/buildBranchVisibility.js.map +0 -1
- package/dist/upsertBranchGlobalChange.d.ts +0 -3
- package/dist/upsertBranchGlobalChange.d.ts.map +0 -1
- package/dist/upsertBranchGlobalChange.js +0 -28
- package/dist/upsertBranchGlobalChange.js.map +0 -1
|
@@ -2,7 +2,7 @@ import { deepMergeWithCombinedArrays } from 'payload';
|
|
|
2
2
|
import { validOperatorSet } from 'payload/shared';
|
|
3
3
|
import { buildAndOrConditions } from './buildAndOrConditions.js';
|
|
4
4
|
import { buildSearchParam } from './buildSearchParams.js';
|
|
5
|
-
export async function parseParams({
|
|
5
|
+
export async function parseParams({ collectionSlug, fields, globalSlug, locale, parentIsLocalized, payload, where }) {
|
|
6
6
|
let result = {};
|
|
7
7
|
if (typeof where === 'object') {
|
|
8
8
|
// We need to determine if the whereKey is an AND, OR, or a schema path
|
|
@@ -16,14 +16,12 @@ export async function parseParams({ branch, collectionSlug, fields, globalSlug,
|
|
|
16
16
|
}
|
|
17
17
|
if (Array.isArray(condition)) {
|
|
18
18
|
const builtConditions = await buildAndOrConditions({
|
|
19
|
-
branch,
|
|
20
19
|
collectionSlug,
|
|
21
20
|
fields,
|
|
22
21
|
globalSlug,
|
|
23
22
|
locale,
|
|
24
23
|
parentIsLocalized,
|
|
25
24
|
payload,
|
|
26
|
-
req,
|
|
27
25
|
where: condition
|
|
28
26
|
});
|
|
29
27
|
if (builtConditions.length > 0 && conditionOperator !== null) {
|
|
@@ -38,7 +36,6 @@ export async function parseParams({ branch, collectionSlug, fields, globalSlug,
|
|
|
38
36
|
const validOperators = Object.keys(pathOperators).filter((operator)=>validOperatorSet.has(operator));
|
|
39
37
|
for (const operator of validOperators){
|
|
40
38
|
const searchParam = await buildSearchParam({
|
|
41
|
-
branch,
|
|
42
39
|
collectionSlug,
|
|
43
40
|
fields,
|
|
44
41
|
globalSlug,
|
|
@@ -47,7 +44,6 @@ export async function parseParams({ branch, collectionSlug, fields, globalSlug,
|
|
|
47
44
|
operator,
|
|
48
45
|
parentIsLocalized,
|
|
49
46
|
payload,
|
|
50
|
-
req,
|
|
51
47
|
val: pathOperators[operator]
|
|
52
48
|
});
|
|
53
49
|
if (searchParam?.value && searchParam?.path) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["import type { QueryFilter } from 'mongoose'\nimport type { FlattenedField, Operator, Payload,
|
|
1
|
+
{"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["import type { QueryFilter } from 'mongoose'\nimport type { FlattenedField, Operator, Payload, Where } from 'payload'\n\nimport { deepMergeWithCombinedArrays } from 'payload'\nimport { validOperatorSet } from 'payload/shared'\n\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { buildSearchParam } from './buildSearchParams.js'\n\nexport async function parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n parentIsLocalized,\n payload,\n where,\n}: {\n collectionSlug?: string\n fields: FlattenedField[]\n globalSlug?: string\n locale?: string\n parentIsLocalized: boolean\n payload: Payload\n where: Where\n}): Promise<Record<string, unknown>> {\n let result = {} as QueryFilter<any>\n\n if (typeof where === 'object') {\n // We need to determine if the whereKey is an AND, OR, or a schema path\n for (const relationOrPath of Object.keys(where)) {\n const condition = where[relationOrPath]\n let conditionOperator: '$and' | '$or' | null = null\n if (relationOrPath.toLowerCase() === 'and') {\n conditionOperator = '$and'\n } else if (relationOrPath.toLowerCase() === 'or') {\n conditionOperator = '$or'\n }\n if (Array.isArray(condition)) {\n const builtConditions = await buildAndOrConditions({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n parentIsLocalized,\n payload,\n where: condition,\n })\n if (builtConditions.length > 0 && conditionOperator !== null) {\n result[conditionOperator] = builtConditions\n }\n } else {\n // It's a path - and there can be multiple comparisons on a single path.\n // For example - title like 'test' and title not equal to 'tester'\n // So we need to loop on keys again here to handle each operator independently\n const pathOperators = where[relationOrPath]\n if (typeof pathOperators === 'object') {\n const validOperators: Operator[] = Object.keys(pathOperators).filter((operator) =>\n validOperatorSet.has(operator as Operator),\n ) as Operator[]\n\n for (const operator of validOperators) {\n const searchParam = await buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: relationOrPath,\n locale,\n operator,\n parentIsLocalized,\n payload,\n val: (pathOperators as Record<string, Where>)[operator],\n })\n\n if (searchParam?.value && searchParam?.path) {\n if (validOperators.length > 1) {\n if (!result.$and) {\n result.$and = []\n }\n result.$and.push({\n [searchParam.path]: searchParam.value,\n })\n } else {\n if (result[searchParam.path]) {\n if (!result.$and) {\n result.$and = []\n }\n\n result.$and.push({ [searchParam.path]: result[searchParam.path] })\n result.$and.push({\n [searchParam.path]: searchParam.value,\n })\n delete result[searchParam.path]\n } else {\n result[searchParam.path] = searchParam.value\n }\n }\n } else if (typeof searchParam?.value === 'object') {\n result = deepMergeWithCombinedArrays(result, searchParam.value ?? {}, {\n // dont clone Types.ObjectIDs\n clone: false,\n })\n }\n }\n }\n }\n }\n }\n\n return result\n}\n"],"names":["deepMergeWithCombinedArrays","validOperatorSet","buildAndOrConditions","buildSearchParam","parseParams","collectionSlug","fields","globalSlug","locale","parentIsLocalized","payload","where","result","relationOrPath","Object","keys","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","length","pathOperators","validOperators","filter","operator","has","searchParam","incomingPath","val","value","path","$and","push","clone"],"mappings":"AAGA,SAASA,2BAA2B,QAAQ,UAAS;AACrD,SAASC,gBAAgB,QAAQ,iBAAgB;AAEjD,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,gBAAgB,QAAQ,yBAAwB;AAEzD,OAAO,eA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,IAAI,GAAG,EAAE;gCAClB;gCACArB,OAAOqB,IAAI,CAACC,IAAI,CAAC;oCACf,CAACN,YAAYI,IAAI,CAAC,EAAEJ,YAAYG,KAAK;gCACvC;4BACF,OAAO;gCACL,IAAInB,MAAM,CAACgB,YAAYI,IAAI,CAAC,EAAE;oCAC5B,IAAI,CAACpB,OAAOqB,IAAI,EAAE;wCAChBrB,OAAOqB,IAAI,GAAG,EAAE;oCAClB;oCAEArB,OAAOqB,IAAI,CAACC,IAAI,CAAC;wCAAE,CAACN,YAAYI,IAAI,CAAC,EAAEpB,MAAM,CAACgB,YAAYI,IAAI,CAAC;oCAAC;oCAChEpB,OAAOqB,IAAI,CAACC,IAAI,CAAC;wCACf,CAACN,YAAYI,IAAI,CAAC,EAAEJ,YAAYG,KAAK;oCACvC;oCACA,OAAOnB,MAAM,CAACgB,YAAYI,IAAI,CAAC;gCACjC,OAAO;oCACLpB,MAAM,CAACgB,YAAYI,IAAI,CAAC,GAAGJ,YAAYG,KAAK;gCAC9C;4BACF;wBACF,OAAO,IAAI,OAAOH,aAAaG,UAAU,UAAU;4BACjDnB,SAASZ,4BAA4BY,QAAQgB,YAAYG,KAAK,IAAI,CAAC,GAAG;gCACpE,6BAA6B;gCAC7BI,OAAO;4BACT;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAOvB;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAgB1C,eAAO,MAAM,WAAW,EAAE,WA+KzB,CAAA"}
|
package/dist/queryDrafts.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { buildVersionCollectionFields, combineQueries, flattenWhereToOperators
|
|
2
|
-
import { buildBranchVisibilityStages } from './queries/buildBranchVisibility.js';
|
|
1
|
+
import { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload';
|
|
3
2
|
import { buildQuery } from './queries/buildQuery.js';
|
|
4
3
|
import { buildSortParam } from './queries/buildSortParam.js';
|
|
5
4
|
import { aggregatePaginate } from './utilities/aggregatePaginate.js';
|
|
@@ -9,17 +8,12 @@ import { getCollection } from './utilities/getEntity.js';
|
|
|
9
8
|
import { getSession } from './utilities/getSession.js';
|
|
10
9
|
import { resolveJoins } from './utilities/resolveJoins.js';
|
|
11
10
|
import { transform } from './utilities/transform.js';
|
|
12
|
-
export const queryDrafts = async function queryDrafts({
|
|
11
|
+
export const queryDrafts = async function queryDrafts({ collection: collectionSlug, joins, limit, locale, page, pagination, req, select, sort: sortArg, where = {} }) {
|
|
13
12
|
const { collectionConfig, Model } = getCollection({
|
|
14
13
|
adapter: this,
|
|
15
14
|
collectionSlug,
|
|
16
15
|
versions: true
|
|
17
16
|
});
|
|
18
|
-
const branchReadState = resolveBranchReadState({
|
|
19
|
-
branch,
|
|
20
|
-
collectionSlug,
|
|
21
|
-
req
|
|
22
|
-
});
|
|
23
17
|
let hasNearConstraint;
|
|
24
18
|
let sort;
|
|
25
19
|
if (where) {
|
|
@@ -40,46 +34,28 @@ export const queryDrafts = async function queryDrafts({ branch, collection: coll
|
|
|
40
34
|
versions: true
|
|
41
35
|
});
|
|
42
36
|
}
|
|
43
|
-
const branchedWhere = branchReadState.useBranching ? rewriteBranchVersionParents(where) : await resolveBranchVersionQuery({
|
|
44
|
-
branch,
|
|
45
|
-
collectionSlug,
|
|
46
|
-
req,
|
|
47
|
-
where
|
|
48
|
-
});
|
|
49
|
-
const branchVisibility = branchReadState.useBranching ? buildBranchVisibilityStages({
|
|
50
|
-
adapter: this,
|
|
51
|
-
branch: branchReadState.branch,
|
|
52
|
-
collectionSlug,
|
|
53
|
-
mode: 'drafts'
|
|
54
|
-
}) : [];
|
|
55
37
|
const combinedWhere = combineQueries({
|
|
56
38
|
latest: {
|
|
57
39
|
equals: true
|
|
58
40
|
}
|
|
59
|
-
},
|
|
41
|
+
}, where);
|
|
60
42
|
const versionQuery = await buildQuery({
|
|
61
43
|
adapter: this,
|
|
62
|
-
branch,
|
|
63
44
|
fields,
|
|
64
45
|
locale,
|
|
65
|
-
req,
|
|
66
46
|
where: combinedWhere
|
|
67
47
|
});
|
|
68
48
|
const projection = buildProjectionFromSelect({
|
|
69
49
|
adapter: this,
|
|
70
50
|
fields,
|
|
71
|
-
select
|
|
72
|
-
collectionSlug,
|
|
73
|
-
req,
|
|
74
|
-
select
|
|
75
|
-
})
|
|
51
|
+
select
|
|
76
52
|
});
|
|
77
53
|
const session = await getSession(this, req);
|
|
78
54
|
const options = {
|
|
79
55
|
session
|
|
80
56
|
};
|
|
81
57
|
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
|
|
82
|
-
const useEstimatedCount =
|
|
58
|
+
const useEstimatedCount = hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0;
|
|
83
59
|
const paginationOptions = {
|
|
84
60
|
lean: true,
|
|
85
61
|
leanWithId: true,
|
|
@@ -121,20 +97,17 @@ export const queryDrafts = async function queryDrafts({ branch, collection: coll
|
|
|
121
97
|
let result;
|
|
122
98
|
const aggregate = await buildJoinAggregation({
|
|
123
99
|
adapter: this,
|
|
124
|
-
branch,
|
|
125
100
|
collection: collectionSlug,
|
|
126
101
|
collectionConfig,
|
|
127
102
|
joins,
|
|
128
103
|
locale,
|
|
129
104
|
projection,
|
|
130
105
|
query: versionQuery,
|
|
131
|
-
req,
|
|
132
106
|
versions: true
|
|
133
107
|
});
|
|
134
|
-
if (aggregate.length > 0 ||
|
|
108
|
+
if (aggregate.length > 0 || sortAggregation.length > 0) {
|
|
135
109
|
result = await aggregatePaginate({
|
|
136
110
|
adapter: this,
|
|
137
|
-
branchVisibility,
|
|
138
111
|
collation: paginationOptions.collation,
|
|
139
112
|
joinAggregation: aggregate,
|
|
140
113
|
limit: paginationOptions.limit,
|
|
@@ -154,12 +127,10 @@ export const queryDrafts = async function queryDrafts({ branch, collection: coll
|
|
|
154
127
|
if (!this.useJoinAggregations) {
|
|
155
128
|
await resolveJoins({
|
|
156
129
|
adapter: this,
|
|
157
|
-
branch,
|
|
158
130
|
collectionSlug,
|
|
159
131
|
docs: result.docs,
|
|
160
132
|
joins,
|
|
161
133
|
locale,
|
|
162
|
-
req,
|
|
163
134
|
versions: true
|
|
164
135
|
});
|
|
165
136
|
}
|
|
@@ -170,9 +141,7 @@ export const queryDrafts = async function queryDrafts({ branch, collection: coll
|
|
|
170
141
|
operation: 'read'
|
|
171
142
|
});
|
|
172
143
|
for(let i = 0; i < result.docs.length; i++){
|
|
173
|
-
|
|
174
|
-
// canonical document ID comes from `_branchParent` when present.
|
|
175
|
-
const id = projectBranchVersionParent(result.docs[i]);
|
|
144
|
+
const id = result.docs[i].parent;
|
|
176
145
|
result.docs[i] = result.docs[i].version ?? {};
|
|
177
146
|
result.docs[i].id = id;
|
|
178
147
|
}
|
package/dist/queryDrafts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions, PipelineStage, QueryOptions } from 'mongoose'\nimport type { QueryDrafts } from 'payload'\n\nimport {\n buildVersionCollectionFields,\n combineQueries,\n flattenWhereToOperators,\n projectBranchVersionParent,\n resolveBranchReadState,\n resolveBranchVersionQuery,\n rewriteBranchVersionParents,\n withBranchVersionSelect,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildBranchVisibilityStages } from './queries/buildBranchVisibility.js'\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { aggregatePaginate } from './utilities/aggregatePaginate.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { resolveJoins } from './utilities/resolveJoins.js'\nimport { transform } from './utilities/transform.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n {\n branch,\n collection: collectionSlug,\n joins,\n limit,\n locale,\n page,\n pagination,\n req,\n select,\n sort: sortArg,\n where = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n const branchReadState = resolveBranchReadState({ branch, collectionSlug, req })\n\n let hasNearConstraint\n let sort\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n\n const sortAggregation: PipelineStage[] = []\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n sortAggregation,\n timestamps: true,\n versions: true,\n })\n }\n\n const branchedWhere = branchReadState.useBranching\n ? rewriteBranchVersionParents(where)\n : await resolveBranchVersionQuery({\n branch,\n collectionSlug,\n req,\n where,\n })\n const branchVisibility = branchReadState.useBranching\n ? buildBranchVisibilityStages({\n adapter: this,\n branch: branchReadState.branch,\n collectionSlug,\n mode: 'drafts',\n })\n : []\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, branchedWhere ?? {})\n\n const versionQuery = await buildQuery({\n adapter: this,\n branch,\n fields,\n locale,\n req,\n where: combinedWhere,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields,\n select: withBranchVersionSelect({ collectionSlug, req, select }),\n })\n\n const session = await getSession(this, req)\n const options: QueryOptions = {\n session,\n }\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount =\n !branchVisibility.length &&\n (hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0)\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(versionQuery, {\n collation: paginationOptions.collation,\n hint: { _id: 1 },\n session,\n }),\n )\n }\n }\n\n if (limit && limit > 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n\n paginationOptions.options!.limit = limit\n }\n\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n branch,\n collection: collectionSlug,\n collectionConfig,\n joins,\n locale,\n projection,\n query: versionQuery,\n req,\n versions: true,\n })\n\n if (aggregate.length > 0 || branchVisibility.length > 0 || sortAggregation.length > 0) {\n result = await aggregatePaginate({\n adapter: this,\n branchVisibility,\n collation: paginationOptions.collation,\n joinAggregation: aggregate,\n limit: paginationOptions.limit,\n Model,\n page: paginationOptions.page,\n pagination: paginationOptions.pagination,\n projection: paginationOptions.projection,\n query: versionQuery,\n session: paginationOptions.options?.session ?? undefined,\n sort: paginationOptions.sort as object,\n sortAggregation,\n useEstimatedCount: paginationOptions.useEstimatedCount,\n })\n } else {\n result = await Model.paginate(versionQuery, paginationOptions)\n }\n\n if (!this.useJoinAggregations) {\n await resolveJoins({\n adapter: this,\n branch,\n collectionSlug,\n docs: result.docs as Record<string, unknown>[],\n joins,\n locale,\n req,\n versions: true,\n })\n }\n\n transform({\n adapter: this,\n data: result.docs,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig),\n operation: 'read',\n })\n\n for (let i = 0; i < result.docs.length; i++) {\n // A branch version's `parent` is the shadow row's primary key, so the\n // canonical document ID comes from `_branchParent` when present.\n const id = projectBranchVersionParent(result.docs[i] as Record<string, unknown>)\n result.docs[i] = result.docs[i].version ?? {}\n result.docs[i].id = id\n }\n\n return result\n}\n"],"names":["buildVersionCollectionFields","combineQueries","flattenWhereToOperators","projectBranchVersionParent","resolveBranchReadState","resolveBranchVersionQuery","rewriteBranchVersionParents","withBranchVersionSelect","buildBranchVisibilityStages","buildQuery","buildSortParam","aggregatePaginate","buildJoinAggregation","buildProjectionFromSelect","getCollection","getSession","resolveJoins","transform","queryDrafts","branch","collection","collectionSlug","joins","limit","locale","page","pagination","req","select","sort","sortArg","where","collectionConfig","Model","adapter","versions","branchReadState","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","payload","config","sortAggregation","defaultSort","timestamps","branchedWhere","useBranching","branchVisibility","mode","combinedWhere","latest","equals","versionQuery","projection","session","options","useEstimatedCount","length","paginationOptions","lean","leanWithId","collation","localizationConfig","localization","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","query","joinAggregation","undefined","paginate","useJoinAggregations","docs","data","operation","i","id","version"],"mappings":"AAGA,SACEA,4BAA4B,EAC5BC,cAAc,EACdC,uBAAuB,EACvBC,0BAA0B,EAC1BC,sBAAsB,EACtBC,yBAAyB,EACzBC,2BAA2B,EAC3BC,uBAAuB,QAClB,UAAS;AAIhB,SAASC,2BAA2B,QAAQ,qCAAoC;AAChF,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,iBAAiB,QAAQ,mCAAkC;AACpE,SAASC,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IAAI;QACjBxC,QAAQ5C,6BAA6B,IAAI,CAAC6C,OAAO,CAACC,MAAM,EAAEd;QAC1DsD,WAAW;IACb;IAEA,IAAK,IAAIC,IAAI,GAAGA,IAAIV,OAAOO,IAAI,CAACtB,MAAM,EAAEyB,IAAK;QAC3C,sEAAsE;QACtE,iEAAiE;QACjE,MAAMC,KAAKrF,2BAA2B0E,OAAOO,IAAI,CAACG,EAAE;QACpDV,OAAOO,IAAI,CAACG,EAAE,GAAGV,OAAOO,IAAI,CAACG,EAAE,CAACE,OAAO,IAAI,CAAC;QAC5CZ,OAAOO,IAAI,CAACG,EAAE,CAACC,EAAE,GAAGA;IACtB;IAEA,OAAOX;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions, PipelineStage, QueryOptions } from 'mongoose'\nimport type { QueryDrafts } from 'payload'\n\nimport { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { aggregatePaginate } from './utilities/aggregatePaginate.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { resolveJoins } from './utilities/resolveJoins.js'\nimport { transform } from './utilities/transform.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n joins,\n limit,\n locale,\n page,\n pagination,\n req,\n select,\n sort: sortArg,\n where = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n let hasNearConstraint\n let sort\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n\n const sortAggregation: PipelineStage[] = []\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n sortAggregation,\n timestamps: true,\n versions: true,\n })\n }\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const versionQuery = await buildQuery({\n adapter: this,\n fields,\n locale,\n where: combinedWhere,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields,\n select,\n })\n\n const session = await getSession(this, req)\n const options: QueryOptions = {\n session,\n }\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(versionQuery, {\n collation: paginationOptions.collation,\n hint: { _id: 1 },\n session,\n }),\n )\n }\n }\n\n if (limit && limit > 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n\n paginationOptions.options!.limit = limit\n }\n\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection: collectionSlug,\n collectionConfig,\n joins,\n locale,\n projection,\n query: versionQuery,\n versions: true,\n })\n\n if (aggregate.length > 0 || sortAggregation.length > 0) {\n result = await aggregatePaginate({\n adapter: this,\n collation: paginationOptions.collation,\n joinAggregation: aggregate,\n limit: paginationOptions.limit,\n Model,\n page: paginationOptions.page,\n pagination: paginationOptions.pagination,\n projection: paginationOptions.projection,\n query: versionQuery,\n session: paginationOptions.options?.session ?? undefined,\n sort: paginationOptions.sort as object,\n sortAggregation,\n useEstimatedCount: paginationOptions.useEstimatedCount,\n })\n } else {\n result = await Model.paginate(versionQuery, paginationOptions)\n }\n\n if (!this.useJoinAggregations) {\n await resolveJoins({\n adapter: this,\n collectionSlug,\n docs: result.docs as Record<string, unknown>[],\n joins,\n locale,\n versions: true,\n })\n }\n\n transform({\n adapter: this,\n data: result.docs,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig),\n operation: 'read',\n })\n\n for (let i = 0; i < result.docs.length; i++) {\n const id = result.docs[i].parent\n result.docs[i] = result.docs[i].version ?? {}\n result.docs[i].id = id\n }\n\n return result\n}\n"],"names":["buildVersionCollectionFields","combineQueries","flattenWhereToOperators","buildQuery","buildSortParam","aggregatePaginate","buildJoinAggregation","buildProjectionFromSelect","getCollection","getSession","resolveJoins","transform","queryDrafts","collection","collectionSlug","joins","limit","locale","page","pagination","req","select","sort","sortArg","where","collectionConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","payload","config","sortAggregation","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","projection","session","options","useEstimatedCount","length","paginationOptions","lean","leanWithId","collation","localizationConfig","localization","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","query","joinAggregation","undefined","paginate","useJoinAggregations","docs","data","operation","i","id","parent","version"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAI/F,SAASC,UAAU,QAAQ,0BAAyB;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
1
|
-
{"version":3,"file":"commitTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/commitTransaction.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"commitTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/commitTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAIhD,eAAO,MAAM,iBAAiB,EAAE,iBA4B/B,CAAA"}
|
|
@@ -1,71 +1,23 @@
|
|
|
1
|
-
const unknownCommitRetryTimeoutMilliseconds = 120_000;
|
|
2
|
-
const unknownCommitRetryInitialDelayMilliseconds = 5;
|
|
3
|
-
const unknownCommitRetryMaximumDelayMilliseconds = 500;
|
|
4
|
-
const unknownCommitRetryGrowth = 1.5;
|
|
5
1
|
export const commitTransaction = async function commitTransaction(incomingID = '') {
|
|
6
2
|
const transactionID = incomingID instanceof Promise ? await incomingID : incomingID;
|
|
7
3
|
if (!this.sessions[transactionID]) {
|
|
8
4
|
return;
|
|
9
5
|
}
|
|
10
6
|
if (!this.sessions[transactionID]?.inTransaction()) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
session: this.sessions[transactionID],
|
|
14
|
-
transactionID
|
|
15
|
-
});
|
|
7
|
+
// Clean up the orphaned session reference
|
|
8
|
+
delete this.sessions[transactionID];
|
|
16
9
|
return;
|
|
17
10
|
}
|
|
18
11
|
const session = this.sessions[transactionID];
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
await session.commitTransaction();
|
|
24
|
-
await endRegisteredSession({
|
|
25
|
-
adapter: this,
|
|
26
|
-
session,
|
|
27
|
-
transactionID
|
|
28
|
-
});
|
|
29
|
-
return;
|
|
30
|
-
} catch (error) {
|
|
31
|
-
if (!isUnknownTransactionCommitResult(error)) {
|
|
32
|
-
throw error;
|
|
33
|
-
}
|
|
34
|
-
const retryDelayMilliseconds = Math.random() * Math.min(unknownCommitRetryInitialDelayMilliseconds * unknownCommitRetryGrowth ** retryIndex, unknownCommitRetryMaximumDelayMilliseconds);
|
|
35
|
-
if (isMaxTimeExpiredError(error) || Date.now() + retryDelayMilliseconds >= retryDeadline) {
|
|
36
|
-
await endRegisteredSession({
|
|
37
|
-
adapter: this,
|
|
38
|
-
session,
|
|
39
|
-
transactionID
|
|
40
|
-
});
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
await new Promise((resolve)=>setTimeout(resolve, retryDelayMilliseconds));
|
|
44
|
-
retryIndex += 1;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const endRegisteredSession = async ({ adapter, session, transactionID })=>{
|
|
49
|
-
delete adapter.sessions[transactionID];
|
|
12
|
+
// Delete from registry FIRST to prevent race conditions
|
|
13
|
+
// This ensures other operations can't retrieve this session while we're ending it
|
|
14
|
+
delete this.sessions[transactionID];
|
|
15
|
+
await session.commitTransaction();
|
|
50
16
|
try {
|
|
51
17
|
await session.endSession();
|
|
52
18
|
} catch (_) {
|
|
53
|
-
//
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
const isMaxTimeExpiredError = (error)=>{
|
|
57
|
-
if (!error || typeof error !== 'object') {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
const mongoError = error;
|
|
61
|
-
return mongoError.code === 50 || mongoError.codeName === 'MaxTimeMSExpired';
|
|
62
|
-
};
|
|
63
|
-
const isUnknownTransactionCommitResult = (error)=>{
|
|
64
|
-
if (!error || typeof error !== 'object') {
|
|
65
|
-
return false;
|
|
19
|
+
// ending sessions is only best effort and won't impact anything if it fails since the transaction was committed
|
|
66
20
|
}
|
|
67
|
-
const labeledError = error;
|
|
68
|
-
return labeledError.hasErrorLabel?.('UnknownTransactionCommitResult') === true || labeledError.errorLabels?.includes('UnknownTransactionCommitResult') === true;
|
|
69
21
|
};
|
|
70
22
|
|
|
71
23
|
//# sourceMappingURL=commitTransaction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type { CommitTransaction } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const commitTransaction: CommitTransaction = async function commitTransaction(\n this: MongooseAdapter,\n incomingID = '',\n) {\n const transactionID = incomingID instanceof Promise ? await incomingID : incomingID\n\n if (!this.sessions[transactionID]) {\n return\n }\n\n if (!this.sessions[transactionID]?.inTransaction()) {\n // Clean up the orphaned session reference\n delete this.sessions[transactionID]\n return\n }\n\n const session = this.sessions[transactionID]\n\n // Delete from registry FIRST to prevent race conditions\n // This ensures other operations can't retrieve this session while we're ending it\n delete this.sessions[transactionID]\n\n await session.commitTransaction()\n try {\n await session.endSession()\n } catch (_) {\n // ending sessions is only best effort and won't impact anything if it fails since the transaction was committed\n }\n}\n"],"names":["commitTransaction","incomingID","transactionID","Promise","sessions","inTransaction","session","endSession","_"],"mappings":"AAIA,OAAO,MAAMA,oBAAuC,eAAeA,kBAEjEC,aAAa,EAAE;IAEf,MAAMC,gBAAgBD,sBAAsBE,UAAU,MAAMF,aAAaA;IAEzE,IAAI,CAAC,IAAI,CAACG,QAAQ,CAACF,cAAc,EAAE;QACjC;IACF;IAEA,IAAI,CAAC,IAAI,CAACE,QAAQ,CAACF,cAAc,EAAEG,iBAAiB;QAClD,0CAA0C;QAC1C,OAAO,IAAI,CAACD,QAAQ,CAACF,cAAc;QACnC;IACF;IAEA,MAAMI,UAAU,IAAI,CAACF,QAAQ,CAACF,cAAc;IAE5C,wDAAwD;IACxD,kFAAkF;IAClF,OAAO,IAAI,CAACE,QAAQ,CAACF,cAAc;IAEnC,MAAMI,QAAQN,iBAAiB;IAC/B,IAAI;QACF,MAAMM,QAAQC,UAAU;IAC1B,EAAE,OAAOC,GAAG;IACV,gHAAgH;IAClH;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollbackTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/rollbackTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAIlD,eAAO,MAAM,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"rollbackTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/rollbackTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAIlD,eAAO,MAAM,mBAAmB,EAAE,mBAgCjC,CAAA"}
|
|
@@ -5,23 +5,22 @@ export const rollbackTransaction = async function rollbackTransaction(incomingID
|
|
|
5
5
|
if (!this.sessions[transactionID]) {
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
|
+
// when session exists but is not inTransaction something unexpected is happening to the session
|
|
9
|
+
if (!this.sessions[transactionID]?.inTransaction()) {
|
|
10
|
+
this.payload.logger.warn('rollbackTransaction called when no transaction exists');
|
|
11
|
+
delete this.sessions[transactionID];
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
8
14
|
const session = this.sessions[transactionID];
|
|
9
15
|
// Delete from registry FIRST to prevent race conditions
|
|
10
16
|
// This ensures other operations can't retrieve this session while we're aborting it
|
|
11
17
|
delete this.sessions[transactionID];
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
await session.abortTransaction();
|
|
15
|
-
} catch (_error) {
|
|
16
|
-
// ignore the error as it is likely a race condition from multiple errors
|
|
17
|
-
}
|
|
18
|
-
} else {
|
|
19
|
-
this.payload.logger.warn('rollbackTransaction called when no transaction exists');
|
|
20
|
-
}
|
|
18
|
+
// the first call for rollback should be aborted and deleted causing any other operations with the same transaction to fail
|
|
21
19
|
try {
|
|
20
|
+
await session.abortTransaction();
|
|
22
21
|
await session.endSession();
|
|
23
22
|
} catch (_error) {
|
|
24
|
-
//
|
|
23
|
+
// ignore the error as it is likely a race condition from multiple errors
|
|
25
24
|
}
|
|
26
25
|
};
|
|
27
26
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/transactions/rollbackTransaction.ts"],"sourcesContent":["import type { RollbackTransaction } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const rollbackTransaction: RollbackTransaction = async function rollbackTransaction(\n this: MongooseAdapter,\n incomingID = '',\n) {\n const transactionID = incomingID instanceof Promise ? await incomingID : incomingID\n\n // if multiple operations are using the same transaction, the first will flow through and delete the session.\n // subsequent calls should be ignored.\n if (!this.sessions[transactionID]) {\n return\n }\n\n const session = this.sessions[transactionID]\n\n // Delete from registry FIRST to prevent race conditions\n // This ensures other operations can't retrieve this session while we're aborting it\n delete this.sessions[transactionID]\n\n
|
|
1
|
+
{"version":3,"sources":["../../src/transactions/rollbackTransaction.ts"],"sourcesContent":["import type { RollbackTransaction } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const rollbackTransaction: RollbackTransaction = async function rollbackTransaction(\n this: MongooseAdapter,\n incomingID = '',\n) {\n const transactionID = incomingID instanceof Promise ? await incomingID : incomingID\n\n // if multiple operations are using the same transaction, the first will flow through and delete the session.\n // subsequent calls should be ignored.\n if (!this.sessions[transactionID]) {\n return\n }\n\n // when session exists but is not inTransaction something unexpected is happening to the session\n if (!this.sessions[transactionID]?.inTransaction()) {\n this.payload.logger.warn('rollbackTransaction called when no transaction exists')\n delete this.sessions[transactionID]\n return\n }\n\n const session = this.sessions[transactionID]\n\n // Delete from registry FIRST to prevent race conditions\n // This ensures other operations can't retrieve this session while we're aborting it\n delete this.sessions[transactionID]\n\n // the first call for rollback should be aborted and deleted causing any other operations with the same transaction to fail\n try {\n await session.abortTransaction()\n await session.endSession()\n } catch (_error) {\n // ignore the error as it is likely a race condition from multiple errors\n }\n}\n"],"names":["rollbackTransaction","incomingID","transactionID","Promise","sessions","inTransaction","payload","logger","warn","session","abortTransaction","endSession","_error"],"mappings":"AAIA,OAAO,MAAMA,sBAA2C,eAAeA,oBAErEC,aAAa,EAAE;IAEf,MAAMC,gBAAgBD,sBAAsBE,UAAU,MAAMF,aAAaA;IAEzE,6GAA6G;IAC7G,sCAAsC;IACtC,IAAI,CAAC,IAAI,CAACG,QAAQ,CAACF,cAAc,EAAE;QACjC;IACF;IAEA,gGAAgG;IAChG,IAAI,CAAC,IAAI,CAACE,QAAQ,CAACF,cAAc,EAAEG,iBAAiB;QAClD,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;QACzB,OAAO,IAAI,CAACJ,QAAQ,CAACF,cAAc;QACnC;IACF;IAEA,MAAMO,UAAU,IAAI,CAACL,QAAQ,CAACF,cAAc;IAE5C,wDAAwD;IACxD,oFAAoF;IACpF,OAAO,IAAI,CAACE,QAAQ,CAACF,cAAc;IAEnC,2HAA2H;IAC3H,IAAI;QACF,MAAMO,QAAQC,gBAAgB;QAC9B,MAAMD,QAAQE,UAAU;IAC1B,EAAE,OAAOC,QAAQ;IACf,yEAAyE;IAC3E;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAS3C,eAAO,MAAM,YAAY,EAAE,YAsC1B,CAAA"}
|
package/dist/updateGlobal.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { resolveBranchGlobalWrite } from 'payload';
|
|
2
1
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
2
|
import { getGlobal } from './utilities/getEntity.js';
|
|
4
3
|
import { getSession } from './utilities/getSession.js';
|
|
5
4
|
import { transform } from './utilities/transform.js';
|
|
6
|
-
export const updateGlobal = async function updateGlobal(
|
|
7
|
-
const { slug: globalSlug, branch, branchConflictData, data, options: optionsArgs = {}, req, returning, select } = args;
|
|
5
|
+
export const updateGlobal = async function updateGlobal({ slug: globalSlug, data, options: optionsArgs = {}, req, returning, select }) {
|
|
8
6
|
const { globalConfig, Model } = getGlobal({
|
|
9
7
|
adapter: this,
|
|
10
8
|
globalSlug
|
|
@@ -17,15 +15,6 @@ export const updateGlobal = async function updateGlobal(args) {
|
|
|
17
15
|
globalSlug,
|
|
18
16
|
operation: 'write'
|
|
19
17
|
});
|
|
20
|
-
if (branchConflictData) {
|
|
21
|
-
transform({
|
|
22
|
-
adapter: this,
|
|
23
|
-
data: branchConflictData,
|
|
24
|
-
fields,
|
|
25
|
-
globalSlug,
|
|
26
|
-
operation: 'write'
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
18
|
const baseOptions = {
|
|
30
19
|
...optionsArgs,
|
|
31
20
|
session: await getSession(this, req),
|
|
@@ -42,84 +31,15 @@ export const updateGlobal = async function updateGlobal(args) {
|
|
|
42
31
|
}),
|
|
43
32
|
returnDocument: 'after'
|
|
44
33
|
};
|
|
45
|
-
const writeBranch = resolveBranchGlobalWrite({
|
|
46
|
-
branch,
|
|
47
|
-
globalSlug,
|
|
48
|
-
req
|
|
49
|
-
});
|
|
50
|
-
const isBranchableGlobal = this.payload.config.branching?.branchableGlobals.has(globalSlug);
|
|
51
|
-
// On a branch the write targets that branch's own row, upserting it from
|
|
52
|
-
// main's current content the first time the global is touched.
|
|
53
|
-
const filter = writeBranch ? {
|
|
54
|
-
_branch: {
|
|
55
|
-
$eq: writeBranch
|
|
56
|
-
},
|
|
57
|
-
globalType: globalSlug
|
|
58
|
-
} : isBranchableGlobal ? {
|
|
59
|
-
_branch: {
|
|
60
|
-
$eq: 'main'
|
|
61
|
-
},
|
|
62
|
-
globalType: globalSlug
|
|
63
|
-
} : {
|
|
64
|
-
globalType: globalSlug
|
|
65
|
-
};
|
|
66
|
-
if (writeBranch) {
|
|
67
|
-
const mainDoc = await Model.findOne({
|
|
68
|
-
_branch: {
|
|
69
|
-
$eq: 'main'
|
|
70
|
-
},
|
|
71
|
-
globalType: globalSlug
|
|
72
|
-
}, {}, baseOptions).lean();
|
|
73
|
-
const { _id, __v, ...mainData } = mainDoc ?? {};
|
|
74
|
-
const writeData = {
|
|
75
|
-
...branchConflictData ?? data,
|
|
76
|
-
_branch: writeBranch
|
|
77
|
-
};
|
|
78
|
-
const insertData = {
|
|
79
|
-
...mainData,
|
|
80
|
-
globalType: globalSlug
|
|
81
|
-
};
|
|
82
|
-
for (const key of Object.keys(writeData)){
|
|
83
|
-
delete insertData[key];
|
|
84
|
-
}
|
|
85
|
-
const upsertOptions = {
|
|
86
|
-
...findOptions,
|
|
87
|
-
upsert: true
|
|
88
|
-
};
|
|
89
|
-
const update = {
|
|
90
|
-
$set: writeData,
|
|
91
|
-
$setOnInsert: insertData
|
|
92
|
-
};
|
|
93
|
-
if (returning === false) {
|
|
94
|
-
await Model.findOneAndUpdate(filter, update, {
|
|
95
|
-
...baseOptions,
|
|
96
|
-
upsert: true
|
|
97
|
-
});
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
const result = await Model.findOneAndUpdate(filter, update, upsertOptions);
|
|
101
|
-
transform({
|
|
102
|
-
adapter: this,
|
|
103
|
-
data: result,
|
|
104
|
-
fields,
|
|
105
|
-
globalSlug,
|
|
106
|
-
operation: 'read'
|
|
107
|
-
});
|
|
108
|
-
return result;
|
|
109
|
-
}
|
|
110
|
-
// `_branch` is forced rather than taken from `data`. The incoming document is a
|
|
111
|
-
// round-trip of a read, and `_branch` is stripped from reads — so the field's
|
|
112
|
-
// `main` default silently refills it, and writing that back would flip the
|
|
113
|
-
// branch's row onto main and leave two rows claiming to be production.
|
|
114
|
-
const writeData = writeBranch ? {
|
|
115
|
-
...data,
|
|
116
|
-
_branch: writeBranch
|
|
117
|
-
} : data;
|
|
118
34
|
if (returning === false) {
|
|
119
|
-
await Model.updateOne(
|
|
35
|
+
await Model.updateOne({
|
|
36
|
+
globalType: globalSlug
|
|
37
|
+
}, data, baseOptions);
|
|
120
38
|
return null;
|
|
121
39
|
}
|
|
122
|
-
const result = await Model.findOneAndUpdate(
|
|
40
|
+
const result = await Model.findOneAndUpdate({
|
|
41
|
+
globalType: globalSlug
|
|
42
|
+
}, data, findOptions);
|
|
123
43
|
transform({
|
|
124
44
|
adapter: this,
|
|
125
45
|
data: result,
|
package/dist/updateGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateGlobal
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug: globalSlug, data, options: optionsArgs = {}, req, returning, select },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug })\n\n const fields = globalConfig.fields\n\n transform({ adapter: this, data, fields, globalSlug, operation: 'write' })\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: globalConfig.flattenedFields,\n select,\n }),\n returnDocument: 'after',\n }\n\n if (returning === false) {\n await Model.updateOne({ globalType: globalSlug }, data, baseOptions)\n return null\n }\n\n const result: any = await Model.findOneAndUpdate({ globalType: globalSlug }, data, findOptions)\n\n transform({ adapter: this, data: result, fields, globalSlug, operation: 'read' })\n\n return result\n}\n"],"names":["buildProjectionFromSelect","getGlobal","getSession","transform","updateGlobal","slug","globalSlug","data","options","optionsArgs","req","returning","select","globalConfig","Model","adapter","fields","operation","baseOptions","session","timestamps","findOptions","lean","projection","flattenedFields","returnDocument","updateOne","globalType","result","findOneAndUpdate"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,MAAMC,UAAU,EAAEC,IAAI,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAE;IAE7E,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGb,UAAU;QAAEc,SAAS,IAAI;QAAET;IAAW;IAEtE,MAAMU,SAASH,aAAaG,MAAM;IAElCb,UAAU;QAAEY,SAAS,IAAI;QAAER;QAAMS;QAAQV;QAAYW,WAAW;IAAQ;IAExE,MAAMC,cAAc;QAClB,GAAGT,WAAW;QACdU,SAAS,MAAMjB,WAAW,IAAI,EAAEQ;QAChC,uDAAuD;QACvDU,YAAY;IACd;IAEA,MAAMC,cAA4B;QAChC,GAAGH,WAAW;QACdI,MAAM;QACNC,YAAYvB,0BAA0B;YACpCe,SAAS,IAAI;YACbC,QAAQH,aAAaW,eAAe;YACpCZ;QACF;QACAa,gBAAgB;IAClB;IAEA,IAAId,cAAc,OAAO;QACvB,MAAMG,MAAMY,SAAS,CAAC;YAAEC,YAAYrB;QAAW,GAAGC,MAAMW;QACxD,OAAO;IACT;IAEA,MAAMU,SAAc,MAAMd,MAAMe,gBAAgB,CAAC;QAAEF,YAAYrB;IAAW,GAAGC,MAAMc;IAEnFlB,UAAU;QAAEY,SAAS,IAAI;QAAER,MAAMqB;QAAQZ;QAAQV;QAAYW,WAAW;IAAO;IAE/E,OAAOW;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAIlE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAQjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EACzE,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,OAAO,EAAE,WAAgB,EACzB,GAAG,EACH,SAAS,EACT,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAIlE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAQjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EACzE,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,OAAO,EAAE,WAAgB,EACzB,GAAG,EACH,SAAS,EACT,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBAiD9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { JsonObject, UpdateGlobalVersionArgs } from 'payload'\n\nimport { buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport async function updateGlobalVersion<T extends JsonObject = JsonObject>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n const whereToUse = where || { id: { equals: id } }\n\n const fields = buildVersionGlobalFields(this.payload.config, globalConfig)\n const flattenedFields = buildVersionGlobalFields(this.payload.config, globalConfig, true)\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { JsonObject, UpdateGlobalVersionArgs } from 'payload'\n\nimport { buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport async function updateGlobalVersion<T extends JsonObject = JsonObject>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n const whereToUse = where || { id: { equals: id } }\n\n const fields = buildVersionGlobalFields(this.payload.config, globalConfig)\n const flattenedFields = buildVersionGlobalFields(this.payload.config, globalConfig, true)\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 const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n returnDocument: 'after',\n }\n\n if (returning === false) {\n await Model.updateOne(query, versionData, baseOptions)\n return null\n }\n\n const doc = await Model.findOneAndUpdate(query, versionData, findOptions)\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":["buildVersionGlobalFields","buildQuery","buildProjectionFromSelect","getGlobal","getSession","transform","updateGlobalVersion","id","global","globalSlug","locale","options","optionsArgs","req","returning","select","versionData","where","globalConfig","Model","adapter","versions","whereToUse","equals","fields","payload","config","flattenedFields","query","data","operation","baseOptions","session","timestamps","findOptions","lean","projection","returnDocument","updateOne","doc","findOneAndUpdate"],"mappings":"AAGA,SAASA,wBAAwB,QAAQ,UAAS;AAIlD,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,QAAQC,UAAU,EAClBC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGhB,UAAU;QAAEiB,SAAS,IAAI;QAAEX;QAAYY,UAAU;IAAK;IACtF,MAAMC,aAAaL,SAAS;QAAEV,IAAI;YAAEgB,QAAQhB;QAAG;IAAE;IAEjD,MAAMiB,SAASxB,yBAAyB,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAER;IAC7D,MAAMS,kBAAkB3B,yBAAyB,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAER,cAAc;IAEpF,MAAMU,QAAQ,MAAM3B,WAAW;QAC7BmB,SAAS,IAAI;QACbI,QAAQG;QACRjB;QACAO,OAAOK;IACT;IAEAjB,UAAU;QAAEe,SAAS,IAAI;QAAES,MAAMb;QAAaQ;QAAQM,WAAW;IAAQ;IAEzE,MAAMC,cAAc;QAClB,GAAGnB,WAAW;QACdoB,SAAS,MAAM5B,WAAW,IAAI,EAAES;QAChC,uDAAuD;QACvDoB,YAAY;IACd;IAEA,MAAMC,cAA4B;QAChC,GAAGH,WAAW;QACdI,MAAM;QACNC,YAAYlC,0BAA0B;YACpCkB,SAAS,IAAI;YACbI,QAAQG;YACRZ;QACF;QACAsB,gBAAgB;IAClB;IAEA,IAAIvB,cAAc,OAAO;QACvB,MAAMK,MAAMmB,SAAS,CAACV,OAAOZ,aAAae;QAC1C,OAAO;IACT;IAEA,MAAMQ,MAAM,MAAMpB,MAAMqB,gBAAgB,CAACZ,OAAOZ,aAAakB;IAE7D,IAAI,CAACK,KAAK;QACR,OAAO;IACT;IAEAlC,UAAU;QAAEe,SAAS,IAAI;QAAES,MAAMU;QAAKf;QAAQM,WAAW;IAAO;IAEhE,OAAOS;AACT"}
|
package/dist/updateMany.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateMany.d.ts","sourceRoot":"","sources":["../src/updateMany.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,UAAU,EAAE,MAAM,SAAS,CAAA;AAYlE,eAAO,MAAM,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"updateMany.d.ts","sourceRoot":"","sources":["../src/updateMany.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,UAAU,EAAE,MAAM,SAAS,CAAA;AAYlE,eAAO,MAAM,UAAU,EAAE,UAwIxB,CAAA"}
|