@payloadcms/db-mongodb 4.0.0-internal.183b315 → 4.0.0-internal.1a2a79e
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/LICENSE.md +1 -1
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +9 -2
- package/dist/connect.js.map +1 -1
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +33 -4
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts.map +1 -1
- package/dist/countGlobalVersions.js +1 -0
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +36 -4
- package/dist/countVersions.js.map +1 -1
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +2 -1
- package/dist/create.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +23 -2
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +9 -2
- package/dist/createMigration.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +17 -4
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteBranchGlobal.d.ts +10 -0
- package/dist/deleteBranchGlobal.d.ts.map +1 -0
- package/dist/deleteBranchGlobal.js +22 -0
- package/dist/deleteBranchGlobal.js.map +1 -0
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +1 -0
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +20 -1
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +1 -0
- package/dist/deleteVersions.js.map +1 -1
- package/dist/exports/migration-utils.d.ts +3 -0
- package/dist/exports/migration-utils.d.ts.map +1 -1
- package/dist/exports/migration-utils.js +3 -0
- package/dist/exports/migration-utils.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +44 -8
- package/dist/find.js.map +1 -1
- package/dist/findDistinct.d.ts.map +1 -1
- package/dist/findDistinct.js +115 -12
- package/dist/findDistinct.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +34 -5
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +10 -2
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +43 -5
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +49 -5
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +89 -67
- package/dist/init.js.map +1 -1
- package/dist/migrateFresh.d.ts +4 -2
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +21 -6
- package/dist/migrateFresh.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +8 -2
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +4 -2
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts +5 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +34 -3
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +4 -0
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +115 -37
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/models/schemaBuildContext.d.ts +21 -0
- package/dist/models/schemaBuildContext.d.ts.map +1 -0
- package/dist/models/schemaBuildContext.js +29 -0
- package/dist/models/schemaBuildContext.js.map +1 -0
- package/dist/predefinedMigrations/branching.d.ts +4 -0
- package/dist/predefinedMigrations/branching.d.ts.map +1 -0
- package/dist/predefinedMigrations/branching.js +9 -0
- package/dist/predefinedMigrations/branching.js.map +1 -0
- package/dist/predefinedMigrations/localize-status.d.ts +4 -0
- package/dist/predefinedMigrations/localize-status.d.ts.map +1 -0
- package/dist/predefinedMigrations/localize-status.js +9 -0
- package/dist/predefinedMigrations/localize-status.js.map +1 -0
- package/dist/predefinedMigrations/migrateBranching.d.ts +15 -0
- package/dist/predefinedMigrations/migrateBranching.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateBranching.js +88 -0
- package/dist/predefinedMigrations/migrateBranching.js.map +1 -0
- package/dist/predefinedMigrations/migrateLocalizeStatus.d.ts +27 -0
- package/dist/predefinedMigrations/migrateLocalizeStatus.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateLocalizeStatus.js +324 -0
- package/dist/predefinedMigrations/migrateLocalizeStatus.js.map +1 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +4 -4
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/predefinedMigrations/migrateSizesToVariants.d.ts +13 -0
- package/dist/predefinedMigrations/migrateSizesToVariants.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateSizesToVariants.js +368 -0
- package/dist/predefinedMigrations/migrateSizesToVariants.js.map +1 -0
- package/dist/predefinedMigrations/sizes-to-variants.d.ts +5 -0
- package/dist/predefinedMigrations/sizes-to-variants.d.ts.map +1 -0
- package/dist/predefinedMigrations/sizes-to-variants.js +8 -0
- package/dist/predefinedMigrations/sizes-to-variants.js.map +1 -0
- package/dist/queries/buildAndOrConditions.d.ts +4 -2
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +3 -1
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildBranchVisibility.d.ts +11 -0
- package/dist/queries/buildBranchVisibility.d.ts.map +1 -0
- package/dist/queries/buildBranchVisibility.js +204 -0
- package/dist/queries/buildBranchVisibility.js.map +1 -0
- package/dist/queries/buildQuery.d.ts +4 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +3 -1
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts +4 -2
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +338 -24
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/getBuildQueryPlugin.d.ts +3 -1
- package/dist/queries/getBuildQueryPlugin.d.ts.map +1 -1
- package/dist/queries/getBuildQueryPlugin.js +3 -1
- package/dist/queries/getBuildQueryPlugin.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
- package/dist/queries/getLocalizedSortProperty.js +1 -1
- package/dist/queries/getLocalizedSortProperty.js.map +1 -1
- package/dist/queries/operatorMap.d.ts.map +1 -1
- package/dist/queries/parseParams.d.ts +4 -2
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +5 -1
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +2 -3
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +38 -7
- package/dist/queryDrafts.js.map +1 -1
- package/dist/testCredentials.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +0 -1
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +68 -7
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
- package/dist/transactions/rollbackTransaction.js +10 -9
- package/dist/transactions/rollbackTransaction.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +89 -9
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +3 -2
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateJobs.d.ts.map +1 -1
- package/dist/updateJobs.js +71 -14
- package/dist/updateJobs.js.map +1 -1
- package/dist/updateMany.d.ts.map +1 -1
- package/dist/updateMany.js +3 -2
- package/dist/updateMany.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +30 -4
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +3 -2
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsertBranchGlobalChange.d.ts +3 -0
- package/dist/upsertBranchGlobalChange.d.ts.map +1 -0
- package/dist/upsertBranchGlobalChange.js +28 -0
- package/dist/upsertBranchGlobalChange.js.map +1 -0
- package/dist/utilities/aggregatePaginate.d.ts +2 -1
- package/dist/utilities/aggregatePaginate.d.ts.map +1 -1
- package/dist/utilities/aggregatePaginate.js +21 -5
- package/dist/utilities/aggregatePaginate.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.d.ts +4 -2
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +124 -21
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.js +1 -1
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
- package/dist/utilities/getDBName.d.ts.map +1 -1
- package/dist/utilities/getEntity.d.ts +1 -1
- package/dist/utilities/getEntity.d.ts.map +1 -1
- package/dist/utilities/handleError.d.ts.map +1 -1
- package/dist/utilities/isObjectID.d.ts.map +1 -1
- package/dist/utilities/resolveJoins.d.ts +6 -2
- package/dist/utilities/resolveJoins.d.ts.map +1 -1
- package/dist/utilities/resolveJoins.js +114 -26
- package/dist/utilities/resolveJoins.js.map +1 -1
- package/dist/utilities/transform.d.ts.map +1 -1
- package/dist/utilities/transform.js +25 -34
- package/dist/utilities/transform.js.map +1 -1
- package/package.json +18 -21
- package/dist/queries/buildSortParam.spec.js +0 -123
- package/dist/queries/buildSortParam.spec.js.map +0 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +0 -215
- package/dist/queries/getLocalizedSortProperty.spec.js.map +0 -1
- package/dist/utilities/transform.spec.js +0 -479
- package/dist/utilities/transform.spec.js.map +0 -1
|
@@ -1,23 +1,84 @@
|
|
|
1
|
+
const unknownCommitRetryTimeoutMilliseconds = 120_000;
|
|
2
|
+
const unknownCommitRetryInitialDelayMilliseconds = 5;
|
|
3
|
+
const unknownCommitRetryMaximumDelayMilliseconds = 500;
|
|
4
|
+
const unknownCommitRetryGrowth = 1.5;
|
|
1
5
|
export const commitTransaction = async function commitTransaction(incomingID = '') {
|
|
2
6
|
const transactionID = incomingID instanceof Promise ? await incomingID : incomingID;
|
|
3
7
|
if (!this.sessions[transactionID]) {
|
|
4
8
|
return;
|
|
5
9
|
}
|
|
6
10
|
if (!this.sessions[transactionID]?.inTransaction()) {
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
await endRegisteredSession({
|
|
12
|
+
adapter: this,
|
|
13
|
+
session: this.sessions[transactionID],
|
|
14
|
+
transactionID
|
|
15
|
+
});
|
|
9
16
|
return;
|
|
10
17
|
}
|
|
11
18
|
const session = this.sessions[transactionID];
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
const retryDeadline = Date.now() + unknownCommitRetryTimeoutMilliseconds;
|
|
20
|
+
let retryIndex = 0;
|
|
21
|
+
while(true){
|
|
22
|
+
try {
|
|
23
|
+
const remainingMilliseconds = Math.max(retryDeadline - Date.now(), 1);
|
|
24
|
+
const timeoutMS = session.timeoutMS && session.timeoutMS > 0 ? Math.min(session.timeoutMS, remainingMilliseconds) : remainingMilliseconds;
|
|
25
|
+
await session.commitTransaction({
|
|
26
|
+
timeoutMS
|
|
27
|
+
});
|
|
28
|
+
await endRegisteredSession({
|
|
29
|
+
adapter: this,
|
|
30
|
+
session,
|
|
31
|
+
transactionID
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
if (!isUnknownTransactionCommitResult(error)) {
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
const retryDelayMilliseconds = Math.random() * Math.min(unknownCommitRetryInitialDelayMilliseconds * unknownCommitRetryGrowth ** retryIndex, unknownCommitRetryMaximumDelayMilliseconds);
|
|
39
|
+
if (isMaxTimeExpiredError(error) || Date.now() + retryDelayMilliseconds >= retryDeadline) {
|
|
40
|
+
await endRegisteredSession({
|
|
41
|
+
adapter: this,
|
|
42
|
+
session,
|
|
43
|
+
transactionID
|
|
44
|
+
});
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
await new Promise((resolve)=>setTimeout(resolve, retryDelayMilliseconds));
|
|
48
|
+
// The retry delay can resume late if the event loop is busy.
|
|
49
|
+
if (Date.now() >= retryDeadline) {
|
|
50
|
+
await endRegisteredSession({
|
|
51
|
+
adapter: this,
|
|
52
|
+
session,
|
|
53
|
+
transactionID
|
|
54
|
+
});
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
retryIndex += 1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const endRegisteredSession = async ({ adapter, session, transactionID })=>{
|
|
62
|
+
delete adapter.sessions[transactionID];
|
|
16
63
|
try {
|
|
17
64
|
await session.endSession();
|
|
18
65
|
} catch (_) {
|
|
19
|
-
//
|
|
66
|
+
// Ending the session is best effort after commit succeeds or its result remains unknown.
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const isMaxTimeExpiredError = (error)=>{
|
|
70
|
+
if (!error || typeof error !== 'object') {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
const mongoError = error;
|
|
74
|
+
return mongoError.code === 50 || mongoError.codeName === 'MaxTimeMSExpired';
|
|
75
|
+
};
|
|
76
|
+
const isUnknownTransactionCommitResult = (error)=>{
|
|
77
|
+
if (!error || typeof error !== 'object') {
|
|
78
|
+
return false;
|
|
20
79
|
}
|
|
80
|
+
const labeledError = error;
|
|
81
|
+
return labeledError.hasErrorLabel?.('UnknownTransactionCommitResult') === true || labeledError.errorLabels?.includes('UnknownTransactionCommitResult') === true;
|
|
21
82
|
};
|
|
22
83
|
|
|
23
84
|
//# sourceMappingURL=commitTransaction.js.map
|
|
@@ -1 +1 @@
|
|
|
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
|
|
1
|
+
{"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type { ClientSession } from 'mongodb'\nimport type { CommitTransaction } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nconst unknownCommitRetryTimeoutMilliseconds = 120_000\nconst unknownCommitRetryInitialDelayMilliseconds = 5\nconst unknownCommitRetryMaximumDelayMilliseconds = 500\nconst unknownCommitRetryGrowth = 1.5\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 await endRegisteredSession({\n adapter: this,\n session: this.sessions[transactionID],\n transactionID,\n })\n return\n }\n\n const session = this.sessions[transactionID]\n const retryDeadline = Date.now() + unknownCommitRetryTimeoutMilliseconds\n let retryIndex = 0\n\n while (true) {\n try {\n const remainingMilliseconds = Math.max(retryDeadline - Date.now(), 1)\n const timeoutMS =\n session.timeoutMS && session.timeoutMS > 0\n ? Math.min(session.timeoutMS, remainingMilliseconds)\n : remainingMilliseconds\n\n await session.commitTransaction({ timeoutMS })\n await endRegisteredSession({ adapter: this, session, transactionID })\n return\n } catch (error) {\n if (!isUnknownTransactionCommitResult(error)) {\n throw error\n }\n\n const retryDelayMilliseconds =\n Math.random() *\n Math.min(\n unknownCommitRetryInitialDelayMilliseconds * unknownCommitRetryGrowth ** retryIndex,\n unknownCommitRetryMaximumDelayMilliseconds,\n )\n\n if (isMaxTimeExpiredError(error) || Date.now() + retryDelayMilliseconds >= retryDeadline) {\n await endRegisteredSession({ adapter: this, session, transactionID })\n throw error\n }\n\n await new Promise((resolve) => setTimeout(resolve, retryDelayMilliseconds))\n\n // The retry delay can resume late if the event loop is busy.\n if (Date.now() >= retryDeadline) {\n await endRegisteredSession({ adapter: this, session, transactionID })\n throw error\n }\n\n retryIndex += 1\n }\n }\n}\n\nconst endRegisteredSession = async ({\n adapter,\n session,\n transactionID,\n}: {\n adapter: MongooseAdapter\n session: ClientSession\n transactionID: number | string\n}): Promise<void> => {\n delete adapter.sessions[transactionID]\n\n try {\n await session.endSession()\n } catch (_) {\n // Ending the session is best effort after commit succeeds or its result remains unknown.\n }\n}\n\nconst isMaxTimeExpiredError = (error: unknown): boolean => {\n if (!error || typeof error !== 'object') {\n return false\n }\n\n const mongoError = error as { code?: number; codeName?: string }\n\n return mongoError.code === 50 || mongoError.codeName === 'MaxTimeMSExpired'\n}\n\nconst isUnknownTransactionCommitResult = (error: unknown): boolean => {\n if (!error || typeof error !== 'object') {\n return false\n }\n\n const labeledError = error as {\n errorLabels?: string[]\n hasErrorLabel?: (label: string) => boolean\n }\n\n return (\n labeledError.hasErrorLabel?.('UnknownTransactionCommitResult') === true ||\n labeledError.errorLabels?.includes('UnknownTransactionCommitResult') === true\n )\n}\n"],"names":["unknownCommitRetryTimeoutMilliseconds","unknownCommitRetryInitialDelayMilliseconds","unknownCommitRetryMaximumDelayMilliseconds","unknownCommitRetryGrowth","commitTransaction","incomingID","transactionID","Promise","sessions","inTransaction","endRegisteredSession","adapter","session","retryDeadline","Date","now","retryIndex","remainingMilliseconds","Math","max","timeoutMS","min","error","isUnknownTransactionCommitResult","retryDelayMilliseconds","random","isMaxTimeExpiredError","resolve","setTimeout","endSession","_","mongoError","code","codeName","labeledError","hasErrorLabel","errorLabels","includes"],"mappings":"AAKA,MAAMA,wCAAwC;AAC9C,MAAMC,6CAA6C;AACnD,MAAMC,6CAA6C;AACnD,MAAMC,2BAA2B;AAEjC,OAAO,MAAMC,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,MAAMC,qBAAqB;YACzBC,SAAS,IAAI;YACbC,SAAS,IAAI,CAACJ,QAAQ,CAACF,cAAc;YACrCA;QACF;QACA;IACF;IAEA,MAAMM,UAAU,IAAI,CAACJ,QAAQ,CAACF,cAAc;IAC5C,MAAMO,gBAAgBC,KAAKC,GAAG,KAAKf;IACnC,IAAIgB,aAAa;IAEjB,MAAO,KAAM;QACX,IAAI;YACF,MAAMC,wBAAwBC,KAAKC,GAAG,CAACN,gBAAgBC,KAAKC,GAAG,IAAI;YACnE,MAAMK,YACJR,QAAQQ,SAAS,IAAIR,QAAQQ,SAAS,GAAG,IACrCF,KAAKG,GAAG,CAACT,QAAQQ,SAAS,EAAEH,yBAC5BA;YAEN,MAAML,QAAQR,iBAAiB,CAAC;gBAAEgB;YAAU;YAC5C,MAAMV,qBAAqB;gB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ackTransaction.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,mBAiCjC,CAAA"}
|
|
@@ -5,22 +5,23 @@ 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
|
-
}
|
|
14
8
|
const session = this.sessions[transactionID];
|
|
15
9
|
// Delete from registry FIRST to prevent race conditions
|
|
16
10
|
// This ensures other operations can't retrieve this session while we're aborting it
|
|
17
11
|
delete this.sessions[transactionID];
|
|
18
|
-
|
|
12
|
+
if (session.inTransaction()) {
|
|
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
|
+
}
|
|
19
21
|
try {
|
|
20
|
-
await session.abortTransaction();
|
|
21
22
|
await session.endSession();
|
|
22
23
|
} catch (_error) {
|
|
23
|
-
//
|
|
24
|
+
// ending a session is best effort after its transaction has failed or been aborted
|
|
24
25
|
}
|
|
25
26
|
};
|
|
26
27
|
|
|
@@ -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
|
|
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 if (session.inTransaction()) {\n try {\n await session.abortTransaction()\n } catch (_error) {\n // ignore the error as it is likely a race condition from multiple errors\n }\n } else {\n this.payload.logger.warn('rollbackTransaction called when no transaction exists')\n }\n\n try {\n await session.endSession()\n } catch (_error) {\n // ending a session is best effort after its transaction has failed or been aborted\n }\n}\n"],"names":["rollbackTransaction","incomingID","transactionID","Promise","sessions","session","inTransaction","abortTransaction","_error","payload","logger","warn","endSession"],"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,MAAMG,UAAU,IAAI,CAACD,QAAQ,CAACF,cAAc;IAE5C,wDAAwD;IACxD,oFAAoF;IACpF,OAAO,IAAI,CAACE,QAAQ,CAACF,cAAc;IAEnC,IAAIG,QAAQC,aAAa,IAAI;QAC3B,IAAI;YACF,MAAMD,QAAQE,gBAAgB;QAChC,EAAE,OAAOC,QAAQ;QACf,yEAAyE;QAC3E;IACF,OAAO;QACL,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B;IAEA,IAAI;QACF,MAAMN,QAAQO,UAAU;IAC1B,EAAE,OAAOJ,QAAQ;IACf,mFAAmF;IACrF;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,EAAoB,MAAM,SAAS,CAAA;AAe7D,eAAO,MAAM,YAAY,EAAE,YAgG1B,CAAA"}
|
package/dist/updateGlobal.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { resolveBranchGlobalWrite } from 'payload';
|
|
1
2
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
2
3
|
import { getGlobal } from './utilities/getEntity.js';
|
|
3
4
|
import { getSession } from './utilities/getSession.js';
|
|
4
5
|
import { transform } from './utilities/transform.js';
|
|
5
|
-
export const updateGlobal = async function updateGlobal(
|
|
6
|
+
export const updateGlobal = async function updateGlobal(args) {
|
|
7
|
+
const { slug: globalSlug, branch, branchConflictData, data, options: optionsArgs = {}, req, returning, select } = args;
|
|
6
8
|
const { globalConfig, Model } = getGlobal({
|
|
7
9
|
adapter: this,
|
|
8
10
|
globalSlug
|
|
@@ -15,6 +17,15 @@ export const updateGlobal = async function updateGlobal({ slug: globalSlug, data
|
|
|
15
17
|
globalSlug,
|
|
16
18
|
operation: 'write'
|
|
17
19
|
});
|
|
20
|
+
if (branchConflictData) {
|
|
21
|
+
transform({
|
|
22
|
+
adapter: this,
|
|
23
|
+
data: branchConflictData,
|
|
24
|
+
fields,
|
|
25
|
+
globalSlug,
|
|
26
|
+
operation: 'write'
|
|
27
|
+
});
|
|
28
|
+
}
|
|
18
29
|
const baseOptions = {
|
|
19
30
|
...optionsArgs,
|
|
20
31
|
session: await getSession(this, req),
|
|
@@ -24,22 +35,91 @@ export const updateGlobal = async function updateGlobal({ slug: globalSlug, data
|
|
|
24
35
|
const findOptions = {
|
|
25
36
|
...baseOptions,
|
|
26
37
|
lean: true,
|
|
27
|
-
new: true,
|
|
28
38
|
projection: buildProjectionFromSelect({
|
|
29
39
|
adapter: this,
|
|
30
40
|
fields: globalConfig.flattenedFields,
|
|
31
41
|
select
|
|
32
|
-
})
|
|
42
|
+
}),
|
|
43
|
+
returnDocument: 'after'
|
|
33
44
|
};
|
|
34
|
-
|
|
35
|
-
|
|
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
|
+
},
|
|
36
71
|
globalType: globalSlug
|
|
37
|
-
},
|
|
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
|
+
if (returning === false) {
|
|
119
|
+
await Model.updateOne(filter, writeData, baseOptions);
|
|
38
120
|
return null;
|
|
39
121
|
}
|
|
40
|
-
const result = await Model.findOneAndUpdate(
|
|
41
|
-
globalType: globalSlug
|
|
42
|
-
}, data, findOptions);
|
|
122
|
+
const result = await Model.findOneAndUpdate(filter, writeData, findOptions);
|
|
43
123
|
transform({
|
|
44
124
|
adapter: this,
|
|
45
125
|
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 } 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
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateGlobal, UpdateGlobalArgs } from 'payload'\n\nimport { resolveBranchGlobalWrite } 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\ntype BranchUpdateGlobalArgs<T extends Record<string, unknown>> = {\n branchConflictData?: Record<string, unknown>\n} & UpdateGlobalArgs<T>\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal<\n T extends Record<string, unknown>,\n>(this: MongooseAdapter, args: UpdateGlobalArgs<T>) {\n const {\n slug: globalSlug,\n branch,\n branchConflictData,\n data,\n options: optionsArgs = {},\n req,\n returning,\n select,\n } = args as BranchUpdateGlobalArgs<T>\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 if (branchConflictData) {\n transform({ adapter: this, data: branchConflictData, fields, globalSlug, operation: 'write' })\n }\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 const writeBranch = resolveBranchGlobalWrite({ branch, globalSlug, req })\n const isBranchableGlobal = this.payload.config.branching?.branchableGlobals.has(globalSlug)\n\n // On a branch the write targets that branch's own row, upserting it from\n // main's current content the first time the global is touched.\n const filter = writeBranch\n ? { _branch: { $eq: writeBranch }, globalType: globalSlug }\n : isBranchableGlobal\n ? { _branch: { $eq: 'main' }, globalType: globalSlug }\n : { globalType: globalSlug }\n\n if (writeBranch) {\n const mainDoc = await Model.findOne(\n { _branch: { $eq: 'main' }, globalType: globalSlug },\n {},\n baseOptions,\n ).lean()\n const { _id, __v, ...mainData } = (mainDoc ?? {}) as Record<string, unknown>\n const writeData = { ...((branchConflictData ?? data) as object), _branch: writeBranch }\n const insertData: Record<string, unknown> = { ...mainData, globalType: globalSlug }\n\n for (const key of Object.keys(writeData)) {\n delete insertData[key]\n }\n\n const upsertOptions = { ...findOptions, upsert: true }\n const update = { $set: writeData, $setOnInsert: insertData }\n\n if (returning === false) {\n await Model.findOneAndUpdate(filter, update, { ...baseOptions, upsert: true })\n return null as unknown as T\n }\n\n const result = (await Model.findOneAndUpdate(filter, update, upsertOptions)) as unknown as T\n\n transform({ adapter: this, data: result, fields, globalSlug, operation: 'read' })\n\n return result\n }\n\n // `_branch` is forced rather than taken from `data`. The incoming document is a\n // round-trip of a read, and `_branch` is stripped from reads — so the field's\n // `main` default silently refills it, and writing that back would flip the\n // branch's row onto main and leave two rows claiming to be production.\n const writeData = writeBranch ? { ...(data as object), _branch: writeBranch } : data\n\n if (returning === false) {\n await Model.updateOne(filter, writeData, baseOptions)\n return null as unknown as T\n }\n\n const result = (await Model.findOneAndUpdate(filter, writeData, findOptions)) as unknown as T\n\n transform({ adapter: this, data: result, fields, globalSlug, operation: 'read' })\n\n return result\n}\n"],"names":["resolveBranchGlobalWrite","buildProjectionFromSelect","getGlobal","getSession","transform","updateGlobal","args","slug","globalSlug","branch","branchConflictData","data","options","optionsArgs","req","returning","select","globalConfig","Model","adapter","fields","operation","baseOptions","session","timestamps","findOptions","lean","projection","flattenedFields","returnDocument","writeBranch","isBranchableGlobal","payload","config","branching","branchableGlobals","has","filter","_branch","$eq","globalType","mainDoc","findOne","_id","__v","mainData","writeData","insertData","key","Object","keys","upsertOptions","upsert","update","$set","$setOnInsert","findOneAndUpdate","result","updateOne"],"mappings":"AAGA,SAASA,wBAAwB,QAAQ,UAAS;AAIlD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAMpD,OAAO,MAAMC,eAA6B,eAAeA,aAEhCC,IAAyB;IAChD,MAAM,EACJC,MAAMC,UAAU,EAChBC,MAAM,EACNC,kBAAkB,EAClBC,IAAI,EACJC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACP,GAAGV;IACJ,MAAM,EAAEW,YAAY,EAAEC,KAAK,EAAE,GAAGhB,UAAU;QAAEiB,SAAS,IAAI;QAAEX;IAAW;IAEtE,MAAMY,SAASH,aAAaG,MAAM;IAElChB,UAAU;QAAEe,SAAS,IAAI;QAAER;QAAMS;QAAQZ;QAAYa,WAAW;IAAQ;IACxE,IAAIX,oBAAoB;QACtBN,UAAU;YAAEe,SAAS,IAAI;YAAER,MAAMD;YAAoBU;YAAQZ;YAAYa,WAAW;QAAQ;IAC9F;IAEA,MAAMC,cAAc;QAClB,GAAGT,WAAW;QACdU,SAAS,MAAMpB,WAAW,IAAI,EAAEW;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B,QAAQ;YAAK;YAC5E,OAAO;QACT;QAEA,MAAMK,SAAU,MAAMvC,MAAMsC,gBAAgB,CAACnB,QAAQgB,QAAQF;QAE7D/C,UAAU;YAAEe,SAAS,IAAI;YAAER,MAAM8C;YAAQrC;YAAQZ;YAAYa,WAAW;QAAO;QAE/E,OAAOoC;IACT;IAEA,gFAAgF;IAChF,8EAA8E;IAC9E,2EAA2E;IAC3E,uEAAuE;IACvE,MAAMX,YAAYhB,cAAc;QAAE,GAAInB,IAAI;QAAa2B,SAASR;IAAY,IAAInB;IAEhF,IAAII,cAAc,OAAO;QACvB,MAAMG,MAAMwC,SAAS,CAACrB,QAAQS,WAAWxB;QACzC,OAAO;IACT;IAEA,MAAMmC,SAAU,MAAMvC,MAAMsC,gBAAgB,CAACnB,QAAQS,WAAWrB;IAEhErB,UAAU;QAAEe,SAAS,IAAI;QAAER,MAAM8C;QAAQrC;QAAQZ;QAAYa,WAAW;IAAO;IAE/E,OAAOoC;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,gBAkD9B"}
|
|
@@ -21,6 +21,7 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, opti
|
|
|
21
21
|
adapter: this,
|
|
22
22
|
fields: flattenedFields,
|
|
23
23
|
locale,
|
|
24
|
+
req,
|
|
24
25
|
where: whereToUse
|
|
25
26
|
});
|
|
26
27
|
transform({
|
|
@@ -38,12 +39,12 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, opti
|
|
|
38
39
|
const findOptions = {
|
|
39
40
|
...baseOptions,
|
|
40
41
|
lean: true,
|
|
41
|
-
new: true,
|
|
42
42
|
projection: buildProjectionFromSelect({
|
|
43
43
|
adapter: this,
|
|
44
44
|
fields: flattenedFields,
|
|
45
45
|
select
|
|
46
|
-
})
|
|
46
|
+
}),
|
|
47
|
+
returnDocument: 'after'
|
|
47
48
|
};
|
|
48
49
|
if (returning === false) {
|
|
49
50
|
await Model.updateOne(query, versionData, baseOptions);
|
|
@@ -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 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
|
|
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 req,\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;QACAG;QACAI,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/updateJobs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateJobs.d.ts","sourceRoot":"","sources":["../src/updateJobs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAO,UAAU,EAAS,MAAM,SAAS,CAAA;AAWrD,eAAO,MAAM,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"updateJobs.d.ts","sourceRoot":"","sources":["../src/updateJobs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAO,UAAU,EAAS,MAAM,SAAS,CAAA;AAWrD,eAAO,MAAM,UAAU,EAAE,UAiLxB,CAAA"}
|
package/dist/updateJobs.js
CHANGED
|
@@ -24,7 +24,7 @@ export const updateJobs = async function updateMany({ id, data, limit, req, retu
|
|
|
24
24
|
sort: sortArg || collectionConfig.defaultSort,
|
|
25
25
|
timestamps: true
|
|
26
26
|
});
|
|
27
|
-
|
|
27
|
+
const query = await buildQuery({
|
|
28
28
|
adapter: this,
|
|
29
29
|
collectionSlug: collectionConfig.slug,
|
|
30
30
|
fields: collectionConfig.flattenedFields,
|
|
@@ -70,7 +70,7 @@ export const updateJobs = async function updateMany({ id, data, limit, req, retu
|
|
|
70
70
|
const findOptions = {
|
|
71
71
|
...baseOptions,
|
|
72
72
|
lean: true,
|
|
73
|
-
|
|
73
|
+
returnDocument: 'after'
|
|
74
74
|
};
|
|
75
75
|
let result = [];
|
|
76
76
|
try {
|
|
@@ -90,25 +90,82 @@ export const updateJobs = async function updateMany({ id, data, limit, req, retu
|
|
|
90
90
|
doc
|
|
91
91
|
] : [];
|
|
92
92
|
}
|
|
93
|
-
} else {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
} else if (limit === 1) {
|
|
94
|
+
/**
|
|
95
|
+
* Select, update, and return one job atomically in a single database call.
|
|
96
|
+
* We can only do this with limit === 1, which can be expressed as findOne.
|
|
97
|
+
*/ const doc = await Model.findOneAndUpdate(query, updateData, {
|
|
98
|
+
...findOptions,
|
|
99
|
+
projection: returning === false ? {
|
|
100
|
+
_id: 1
|
|
101
|
+
} : undefined,
|
|
102
|
+
sort
|
|
103
|
+
});
|
|
104
|
+
if (returning === false) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
result = doc ? [
|
|
108
|
+
doc
|
|
109
|
+
] : [];
|
|
110
|
+
} else if (typeof limit === 'number' && limit > 1) {
|
|
111
|
+
const candidates = await Model.find(query, {}, {
|
|
112
|
+
...findOptions,
|
|
113
|
+
limit,
|
|
114
|
+
projection: {
|
|
115
|
+
_id: 1
|
|
116
|
+
},
|
|
117
|
+
sort
|
|
118
|
+
});
|
|
119
|
+
if (candidates.length === 0) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
const candidateIDs = candidates.map((candidate)=>candidate._id);
|
|
123
|
+
if (typeof data.processingToken === 'string') {
|
|
124
|
+
/**
|
|
125
|
+
* `processingToken` identifies this claim update. `processing: true` cannot, because every
|
|
126
|
+
* worker writes the same value. The token lets us reliably find the jobs this update won.
|
|
127
|
+
*/ const claimQuery = {
|
|
128
|
+
$and: [
|
|
129
|
+
query,
|
|
130
|
+
{
|
|
131
|
+
_id: {
|
|
132
|
+
$in: candidateIDs
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
};
|
|
137
|
+
await Model.updateMany(claimQuery, updateData, baseOptions);
|
|
138
|
+
if (returning === false) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
const claimedJobsQuery = {
|
|
142
|
+
_id: {
|
|
143
|
+
$in: candidateIDs
|
|
100
144
|
},
|
|
145
|
+
processingToken: {
|
|
146
|
+
$eq: data.processingToken
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
result = await Model.find(claimedJobsQuery, {}, {
|
|
150
|
+
...findOptions,
|
|
101
151
|
sort
|
|
102
152
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
query = {
|
|
153
|
+
} else {
|
|
154
|
+
const limitedUpdateQuery = {
|
|
107
155
|
_id: {
|
|
108
|
-
$in:
|
|
156
|
+
$in: candidateIDs
|
|
109
157
|
}
|
|
110
158
|
};
|
|
159
|
+
await Model.updateMany(limitedUpdateQuery, updateData, baseOptions);
|
|
160
|
+
if (returning === false) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
result = await Model.find(limitedUpdateQuery, {}, {
|
|
164
|
+
...findOptions,
|
|
165
|
+
sort
|
|
166
|
+
});
|
|
111
167
|
}
|
|
168
|
+
} else {
|
|
112
169
|
await Model.updateMany(query, updateData, baseOptions);
|
|
113
170
|
if (returning === false) {
|
|
114
171
|
return null;
|
package/dist/updateJobs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateJobs.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\nimport type { Job, UpdateJobs, Where } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateJobs: UpdateJobs = async function updateMany(\n this: MongooseAdapter,\n { id, data, limit, req, returning, sort: sortArg, where: whereArg },\n) {\n if (\n !(data?.log as object[])?.length &&\n !(data.log && typeof data.log === 'object' && '$push' in data.log)\n ) {\n delete data.log\n }\n\n const where = id ? { id: { equals: id } } : (whereArg as Where)\n\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug: 'payload-jobs',\n })\n\n const sort: Record<string, unknown> | undefined = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n\n
|
|
1
|
+
{"version":3,"sources":["../src/updateJobs.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\nimport type { Job, UpdateJobs, Where } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateJobs: UpdateJobs = async function updateMany(\n this: MongooseAdapter,\n { id, data, limit, req, returning, sort: sortArg, where: whereArg },\n) {\n if (\n !(data?.log as object[])?.length &&\n !(data.log && typeof data.log === 'object' && '$push' in data.log)\n ) {\n delete data.log\n }\n\n const where = id ? { id: { equals: id } } : (whereArg as Where)\n\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug: 'payload-jobs',\n })\n\n const sort: Record<string, unknown> | undefined = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collectionConfig.slug,\n fields: collectionConfig.flattenedFields,\n where,\n })\n\n let updateData: UpdateQuery<any> = data\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields: collectionConfig.fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = updateData\n updateData = updateOps\n }\n\n const baseOptions = {\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 returnDocument: 'after',\n }\n\n let result: Job[] = []\n\n try {\n if (id) {\n if (returning === false) {\n await Model.updateOne(query, updateData, baseOptions)\n transform({ adapter: this, data, fields: collectionConfig.fields, operation: 'read' })\n\n return null\n } else {\n const doc = await Model.findOneAndUpdate(query, updateData, findOptions)\n result = doc ? [doc] : []\n }\n } else if (limit === 1) {\n /**\n * Select, update, and return one job atomically in a single database call.\n * We can only do this with limit === 1, which can be expressed as findOne.\n */\n const doc = await Model.findOneAndUpdate(query, updateData, {\n ...findOptions,\n projection: returning === false ? { _id: 1 } : undefined,\n sort,\n })\n\n if (returning === false) {\n return null\n }\n\n result = doc ? [doc] : []\n } else if (typeof limit === 'number' && limit > 1) {\n const candidates = await Model.find(\n query,\n {},\n { ...findOptions, limit, projection: { _id: 1 }, sort },\n )\n\n if (candidates.length === 0) {\n return null\n }\n\n const candidateIDs = candidates.map((candidate) => candidate._id)\n\n if (typeof data.processingToken === 'string') {\n /**\n * `processingToken` identifies this claim update. `processing: true` cannot, because every\n * worker writes the same value. The token lets us reliably find the jobs this update won.\n */\n const claimQuery = {\n $and: [query, { _id: { $in: candidateIDs } }],\n }\n\n await Model.updateMany(claimQuery, updateData, baseOptions)\n\n if (returning === false) {\n return null\n }\n\n const claimedJobsQuery = {\n _id: { $in: candidateIDs },\n processingToken: { $eq: data.processingToken },\n }\n\n result = await Model.find(claimedJobsQuery, {}, { ...findOptions, sort })\n } else {\n const limitedUpdateQuery = { _id: { $in: candidateIDs } }\n\n await Model.updateMany(limitedUpdateQuery, updateData, baseOptions)\n\n if (returning === false) {\n return null\n }\n\n result = await Model.find(limitedUpdateQuery, {}, { ...findOptions, sort })\n }\n } else {\n await Model.updateMany(query, updateData, baseOptions)\n\n if (returning === false) {\n return null\n }\n\n result = await Model.find(query, {}, { ...findOptions, sort })\n }\n } catch (error) {\n handleError({ collection: collectionConfig.slug, error, req })\n }\n\n transform({\n adapter: this,\n data: result,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["buildQuery","buildSortParam","getCollection","getSession","handleError","transform","updateJobs","updateMany","id","data","limit","req","returning","sort","sortArg","where","whereArg","log","length","equals","collectionConfig","Model","adapter","collectionSlug","config","payload","fields","flattenedFields","defaultSort","timestamps","query","slug","updateData","$inc","$push","$addToSet","$pull","operation","updateOps","Object","keys","$set","baseOptions","session","findOptions","lean","returnDocument","result","updateOne","doc","findOneAndUpdate","projection","_id","undefined","candidates","find","candidateIDs","map","candidate","processingToken","claimQuery","$and","$in","claimedJobsQuery","$eq","limitedUpdateQuery","error","collection"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,aAAyB,eAAeC,WAEnD,EAAEC,EAAE,EAAEC,IAAI,EAAEC,KAAK,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAMC,OAAO,EAAEC,OAAOC,QAAQ,EAAE;IAEnE,IACE,CAAEP,MAAMQ,KAAkBC,UAC1B,CAAET,CAAAA,KAAKQ,GAAG,IAAI,OAAOR,KAAKQ,GAAG,KAAK,YAAY,WAAWR,KAAKQ,GAAG,AAAD,GAChE;QACA,OAAOR,KAAKQ,GAAG;IACjB;IAEA,MAAMF,QAAQP,KAAK;QAAEA,IAAI;YAAEW,QAAQX;QAAG;IAAE,IAAKQ;IAE7C,MAAM,EAAEI,gBAAgB,EAAEC,KAAK,EAAE,GAAGnB,cAAc;QAChDoB,SAAS,IAAI;QACbC,gBAAgB;IAClB;IAEA,MAAMV,OAA4CZ,eAAe;QAC/DqB,SAAS,IAAI;QACbE,QAAQ,IAAI,CAACC,OAAO,CAACD,MAAM;QAC3BE,QAAQN,iBAAiBO,eAAe;QACxCd,MAAMC,WAAWM,iBAAiBQ,WAAW;QAC7CC,YAAY;IACd;IAEA,MAAMC,QAAQ,MAAM9B,WAAW;QAC7BsB,SAAS,IAAI;QACbC,gBAAgBH,iBAAiBW,IAAI;QACrCL,QAAQN,iBAAiBO,eAAe;QACxCZ;IACF;IAEA,IAAIiB,aAA+BvB;IAEnC,MAAMwB,OAA+B,CAAC;IACtC,MAAMC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C,YAAYU;gBAEvD,IAAI9B,cAAc,OAAO;oBACvB,OAAO;gBACT;gBAEAmC,SAAS,MAAM1B,MAAMkC,IAAI,CAACU,oBAAoB,CAAC,GAAG;oBAAE,GAAGrB,WAAW;oBAAE/B;gBAAK;YAC3E;QACF,OAAO;YACL,MAAMQ,MAAMd,UAAU,CAACuB,OAAOE,YAAYU;YAE1C,IAAI9B,cAAc,OAAO;gBACvB,OAAO;YACT;YAEAmC,SAAS,MAAM1B,MAAMkC,IAAI,CAACzB,OAAO,CAAC,GAAG;gBAAE,GAAGc,WAAW;gBAAE/B;YAAK;QAC9D;IACF,EAAE,OAAOqD,OAAO;QACd9D,YAAY;YAAE+D,YAAY/C,iBAAiBW,IAAI;YAAEmC;YAAOvD;QAAI;IAC9D;IAEAN,UAAU;QACRiB,SAAS,IAAI;QACbb,MAAMsC;QACNrB,QAAQN,iBAAiBM,MAAM;QAC/BW,WAAW;IACb;IAEA,OAAOU;AACT,EAAC"}
|
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,UA0IxB,CAAA"}
|
package/dist/updateMany.js
CHANGED
|
@@ -32,6 +32,7 @@ export const updateMany = async function updateMany({ collection: collectionSlug
|
|
|
32
32
|
collectionSlug,
|
|
33
33
|
fields: collectionConfig.flattenedFields,
|
|
34
34
|
locale,
|
|
35
|
+
req,
|
|
35
36
|
where
|
|
36
37
|
});
|
|
37
38
|
const $inc = {};
|
|
@@ -74,12 +75,12 @@ export const updateMany = async function updateMany({ collection: collectionSlug
|
|
|
74
75
|
const findOptions = {
|
|
75
76
|
...baseOptions,
|
|
76
77
|
lean: true,
|
|
77
|
-
new: true,
|
|
78
78
|
projection: buildProjectionFromSelect({
|
|
79
79
|
adapter: this,
|
|
80
80
|
fields: collectionConfig.flattenedFields,
|
|
81
81
|
select
|
|
82
|
-
})
|
|
82
|
+
}),
|
|
83
|
+
returnDocument: 'after'
|
|
83
84
|
};
|
|
84
85
|
try {
|
|
85
86
|
if (typeof limit === 'number' && limit > 0) {
|
package/dist/updateMany.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\n\nimport { flattenWhereToOperators, type UpdateMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateMany: UpdateMany = async function updateMany(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n data,\n limit,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n sort: sortArg,\n where,\n },\n) {\n let hasNearConstraint = false\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 { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n let sort: Record<string, unknown> | undefined\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n let query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields: collectionConfig.fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = data\n data = updateOps\n }\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
|
|
1
|
+
{"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\n\nimport { flattenWhereToOperators, type UpdateMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateMany: UpdateMany = async function updateMany(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n data,\n limit,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n sort: sortArg,\n where,\n },\n) {\n let hasNearConstraint = false\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 { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n let sort: Record<string, unknown> | undefined\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n let query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n req,\n where,\n })\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields: collectionConfig.fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = data\n data = updateOps\n }\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: collectionConfig.flattenedFields,\n select,\n }),\n returnDocument: 'after',\n }\n\n try {\n if (typeof limit === 'number' && limit > 0) {\n const documentsToUpdate = await Model.find(\n query,\n {},\n { ...findOptions, limit, projection: { _id: 1 }, sort },\n )\n if (documentsToUpdate.length === 0) {\n return null\n }\n\n query = { _id: { $in: documentsToUpdate.map((doc) => doc._id) } }\n }\n\n await Model.updateMany(query, data, baseOptions)\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n\n if (returning === false) {\n return null\n }\n\n const result = await Model.find(\n query,\n {},\n {\n ...findOptions,\n sort,\n },\n )\n\n transform({\n adapter: this,\n data: result,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["flattenWhereToOperators","buildQuery","buildSortParam","buildProjectionFromSelect","getCollection","getSession","handleError","transform","updateMany","collection","collectionSlug","data","limit","locale","options","optionsArgs","req","returning","select","sort","sortArg","where","hasNearConstraint","constraints","some","prop","Object","keys","key","collectionConfig","Model","adapter","config","payload","fields","flattenedFields","defaultSort","timestamps","query","$inc","$push","$addToSet","$pull","operation","updateOps","length","$set","baseOptions","session","findOptions","lean","projection","returnDocument","documentsToUpdate","find","_id","$in","map","doc","error","result"],"mappings":"AAEA,SAASA,uBAAuB,QAAyB,UAAS;AAIlE,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EACEC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,IAAIC,oBAAoB;IAExB,IAAID,OAAO;QACT,MAAME,cAAcvB,wBAAwBqB;QAC5CC,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAG1B,cAAc;QAAE2B,SAAS,IAAI;QAAErB;IAAe;IAElF,IAAIS;IACJ,IAAI,CAACG,mBAAmB;QACtBH,OAAOjB,eAAe;YACpB6B,SAAS,IAAI;Y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