@payloadcms/db-mongodb 4.0.0-internal.8867dba → 4.0.0-internal.9726517
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/exports/migration-utils.d.ts +1 -0
- package/dist/exports/migration-utils.d.ts.map +1 -1
- package/dist/exports/migration-utils.js +1 -0
- package/dist/exports/migration-utils.js.map +1 -1
- package/dist/predefinedMigrations/jobs-processing-lease-v4.d.ts +5 -0
- package/dist/predefinedMigrations/jobs-processing-lease-v4.d.ts.map +1 -0
- package/dist/predefinedMigrations/jobs-processing-lease-v4.js +12 -0
- package/dist/predefinedMigrations/jobs-processing-lease-v4.js.map +1 -0
- package/dist/predefinedMigrations/migrateJobsProcessingLease.d.ts +6 -0
- package/dist/predefinedMigrations/migrateJobsProcessingLease.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateJobsProcessingLease.js +81 -0
- package/dist/predefinedMigrations/migrateJobsProcessingLease.js.map +1 -0
- package/dist/predefinedMigrations/migrateJobsProcessingLease.spec.js +130 -0
- package/dist/predefinedMigrations/migrateJobsProcessingLease.spec.js.map +1 -0
- package/package.json +3 -3
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { migrateJobsProcessingLease } from '../predefinedMigrations/migrateJobsProcessingLease.js';
|
|
1
2
|
export { localizeStatus, migrateLocalizeStatus, } from '../predefinedMigrations/migrateLocalizeStatus.js';
|
|
2
3
|
export { migrateRelationshipsV2_V3 } from '../predefinedMigrations/migrateRelationshipsV2_V3.js';
|
|
3
4
|
export { migrateVersionsV1_V2 } from '../predefinedMigrations/migrateVersionsV1_V2.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-utils.d.ts","sourceRoot":"","sources":["../../src/exports/migration-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,qBAAqB,GACtB,MAAM,kDAAkD,CAAA;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sDAAsD,CAAA;AAChG,OAAO,EAAE,oBAAoB,EAAE,MAAM,iDAAiD,CAAA"}
|
|
1
|
+
{"version":3,"file":"migration-utils.d.ts","sourceRoot":"","sources":["../../src/exports/migration-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,uDAAuD,CAAA;AAClG,OAAO,EACL,cAAc,EACd,qBAAqB,GACtB,MAAM,kDAAkD,CAAA;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sDAAsD,CAAA;AAChG,OAAO,EAAE,oBAAoB,EAAE,MAAM,iDAAiD,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { migrateJobsProcessingLease } from '../predefinedMigrations/migrateJobsProcessingLease.js';
|
|
1
2
|
export { localizeStatus, migrateLocalizeStatus } from '../predefinedMigrations/migrateLocalizeStatus.js';
|
|
2
3
|
export { migrateRelationshipsV2_V3 } from '../predefinedMigrations/migrateRelationshipsV2_V3.js';
|
|
3
4
|
export { migrateVersionsV1_V2 } from '../predefinedMigrations/migrateVersionsV1_V2.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/migration-utils.ts"],"sourcesContent":["export {\n localizeStatus,\n migrateLocalizeStatus,\n} from '../predefinedMigrations/migrateLocalizeStatus.js'\nexport { migrateRelationshipsV2_V3 } from '../predefinedMigrations/migrateRelationshipsV2_V3.js'\nexport { migrateVersionsV1_V2 } from '../predefinedMigrations/migrateVersionsV1_V2.js'\n"],"names":["localizeStatus","migrateLocalizeStatus","migrateRelationshipsV2_V3","migrateVersionsV1_V2"],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/exports/migration-utils.ts"],"sourcesContent":["export { migrateJobsProcessingLease } from '../predefinedMigrations/migrateJobsProcessingLease.js'\nexport {\n localizeStatus,\n migrateLocalizeStatus,\n} from '../predefinedMigrations/migrateLocalizeStatus.js'\nexport { migrateRelationshipsV2_V3 } from '../predefinedMigrations/migrateRelationshipsV2_V3.js'\nexport { migrateVersionsV1_V2 } from '../predefinedMigrations/migrateVersionsV1_V2.js'\n"],"names":["migrateJobsProcessingLease","localizeStatus","migrateLocalizeStatus","migrateRelationshipsV2_V3","migrateVersionsV1_V2"],"mappings":"AAAA,SAASA,0BAA0B,QAAQ,wDAAuD;AAClG,SACEC,cAAc,EACdC,qBAAqB,QAChB,mDAAkD;AACzD,SAASC,yBAAyB,QAAQ,uDAAsD;AAChG,SAASC,oBAAoB,QAAQ,kDAAiD"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare const imports = "import { migrateJobsProcessingLease } from '@payloadcms/db-mongodb/migration-utils'";
|
|
2
|
+
declare const upSQL = "await migrateJobsProcessingLease({\n direction: 'up',\n req,\n})";
|
|
3
|
+
declare const downSQL = "await migrateJobsProcessingLease({\n direction: 'down',\n req,\n})";
|
|
4
|
+
export { downSQL, imports, upSQL };
|
|
5
|
+
//# sourceMappingURL=jobs-processing-lease-v4.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jobs-processing-lease-v4.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/jobs-processing-lease-v4.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,wFAAwF,CAAA;AACrG,QAAA,MAAM,KAAK,uEAGR,CAAA;AACH,QAAA,MAAM,OAAO,yEAGV,CAAA;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const imports = `import { migrateJobsProcessingLease } from '@payloadcms/db-mongodb/migration-utils'`;
|
|
2
|
+
const upSQL = `await migrateJobsProcessingLease({
|
|
3
|
+
direction: 'up',
|
|
4
|
+
req,
|
|
5
|
+
})`;
|
|
6
|
+
const downSQL = `await migrateJobsProcessingLease({
|
|
7
|
+
direction: 'down',
|
|
8
|
+
req,
|
|
9
|
+
})`;
|
|
10
|
+
export { downSQL, imports, upSQL };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=jobs-processing-lease-v4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/predefinedMigrations/jobs-processing-lease-v4.ts"],"sourcesContent":["const imports = `import { migrateJobsProcessingLease } from '@payloadcms/db-mongodb/migration-utils'`\nconst upSQL = `await migrateJobsProcessingLease({\n direction: 'up',\n req,\n})`\nconst downSQL = `await migrateJobsProcessingLease({\n direction: 'down',\n req,\n})`\n\nexport { downSQL, imports, upSQL }\n"],"names":["imports","upSQL","downSQL"],"mappings":"AAAA,MAAMA,UAAU,CAAC,mFAAmF,CAAC;AACrG,MAAMC,QAAQ,CAAC;;;EAGb,CAAC;AACH,MAAMC,UAAU,CAAC;;;EAGf,CAAC;AAEH,SAASA,OAAO,EAAEF,OAAO,EAAEC,KAAK,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrateJobsProcessingLease.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/migrateJobsProcessingLease.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAO7C,wBAAsB,0BAA0B,CAAC,EAC/C,SAAS,EACT,GAAG,GACJ,EAAE;IACD,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,OAAO,CAAC,IAAI,CAAC,CAsChB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { getCollection } from '../utilities/getEntity.js';
|
|
2
|
+
import { getSession } from '../utilities/getSession.js';
|
|
3
|
+
export async function migrateJobsProcessingLease({ direction, req }) {
|
|
4
|
+
const adapter = req.payload.db;
|
|
5
|
+
const { Model } = getCollection({
|
|
6
|
+
adapter,
|
|
7
|
+
collectionSlug: 'payload-jobs'
|
|
8
|
+
});
|
|
9
|
+
const session = await getSession(adapter, req);
|
|
10
|
+
const indexes = await Model.collection.indexes({
|
|
11
|
+
session
|
|
12
|
+
});
|
|
13
|
+
if (direction === 'up') {
|
|
14
|
+
await Model.collection.updateMany({
|
|
15
|
+
processing: true
|
|
16
|
+
}, {
|
|
17
|
+
$set: {
|
|
18
|
+
processingUntil: new Date(0)
|
|
19
|
+
}
|
|
20
|
+
}, {
|
|
21
|
+
session
|
|
22
|
+
});
|
|
23
|
+
await Model.collection.updateMany({}, {
|
|
24
|
+
$unset: {
|
|
25
|
+
processing: ''
|
|
26
|
+
}
|
|
27
|
+
}, {
|
|
28
|
+
session
|
|
29
|
+
});
|
|
30
|
+
const processingIndex = indexes.find((index)=>index.key.processing === 1);
|
|
31
|
+
if (processingIndex?.name) {
|
|
32
|
+
await Model.collection.dropIndex(processingIndex.name, {
|
|
33
|
+
session
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
await Model.collection.createIndex({
|
|
37
|
+
processingUntil: 1
|
|
38
|
+
}, {
|
|
39
|
+
session
|
|
40
|
+
});
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
await Model.collection.updateMany({}, {
|
|
44
|
+
$set: {
|
|
45
|
+
processing: false
|
|
46
|
+
}
|
|
47
|
+
}, {
|
|
48
|
+
session
|
|
49
|
+
});
|
|
50
|
+
await Model.collection.updateMany({
|
|
51
|
+
processingUntil: {
|
|
52
|
+
$ne: null
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
$set: {
|
|
56
|
+
processing: true
|
|
57
|
+
}
|
|
58
|
+
}, {
|
|
59
|
+
session
|
|
60
|
+
});
|
|
61
|
+
await Model.collection.updateMany({}, {
|
|
62
|
+
$unset: {
|
|
63
|
+
processingUntil: ''
|
|
64
|
+
}
|
|
65
|
+
}, {
|
|
66
|
+
session
|
|
67
|
+
});
|
|
68
|
+
const processingUntilIndex = indexes.find((index)=>index.key.processingUntil === 1);
|
|
69
|
+
if (processingUntilIndex?.name) {
|
|
70
|
+
await Model.collection.dropIndex(processingUntilIndex.name, {
|
|
71
|
+
session
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
await Model.collection.createIndex({
|
|
75
|
+
processing: 1
|
|
76
|
+
}, {
|
|
77
|
+
session
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=migrateJobsProcessingLease.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/predefinedMigrations/migrateJobsProcessingLease.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { getCollection } from '../utilities/getEntity.js'\nimport { getSession } from '../utilities/getSession.js'\n\nexport async function migrateJobsProcessingLease({\n direction,\n req,\n}: {\n direction: 'down' | 'up'\n req: PayloadRequest\n}): Promise<void> {\n const adapter = req.payload.db as MongooseAdapter\n const { Model } = getCollection({ adapter, collectionSlug: 'payload-jobs' })\n const session = await getSession(adapter, req)\n const indexes = await Model.collection.indexes({ session })\n\n if (direction === 'up') {\n await Model.collection.updateMany(\n { processing: true },\n { $set: { processingUntil: new Date(0) } },\n { session },\n )\n await Model.collection.updateMany({}, { $unset: { processing: '' } }, { session })\n\n const processingIndex = indexes.find((index) => index.key.processing === 1)\n if (processingIndex?.name) {\n await Model.collection.dropIndex(processingIndex.name, { session })\n }\n\n await Model.collection.createIndex({ processingUntil: 1 }, { session })\n\n return\n }\n\n await Model.collection.updateMany({}, { $set: { processing: false } }, { session })\n await Model.collection.updateMany(\n { processingUntil: { $ne: null } },\n { $set: { processing: true } },\n { session },\n )\n await Model.collection.updateMany({}, { $unset: { processingUntil: '' } }, { session })\n\n const processingUntilIndex = indexes.find((index) => index.key.processingUntil === 1)\n if (processingUntilIndex?.name) {\n await Model.collection.dropIndex(processingUntilIndex.name, { session })\n }\n\n await Model.collection.createIndex({ processing: 1 }, { session })\n}\n"],"names":["getCollection","getSession","migrateJobsProcessingLease","direction","req","adapter","payload","db","Model","collectionSlug","session","indexes","collection","updateMany","processing","$set","processingUntil","Date","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AAM;YAAED,YAAY;QAAK;IAAE,GAC7B;QAAEJ;IAAQ;IAEZ,MAAMF,MAAMI,UAAU,CAACC,UAAU,CAAC,CAAC,GAAG;QAAEK,QAAQ;YAAEF,iBAAiB;QAAG;IAAE,GAAG;QAAEN;IAAQ;IAErF,MAAMiB,uBAAuBhB,QAAQS,IAAI,CAAC,CAACC,QAAUA,MAAMC,GAAG,CAACN,eAAe,KAAK;IACnF,IAAIW,sBAAsBJ,MAAM;QAC9B,MAAMf,MAAMI,UAAU,CAACY,SAAS,CAACG,qBAAqBJ,IAAI,EAAE;YAAEb;QAAQ;IACxE;IAEA,MAAMF,MAAMI,UAAU,CAACa,WAAW,CAAC;QAAEX,YAAY;IAAE,GAAG;QAAEJ;IAAQ;AAClE"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
const mocks = vi.hoisted(()=>({
|
|
3
|
+
collection: {
|
|
4
|
+
createIndex: vi.fn().mockResolvedValue(undefined),
|
|
5
|
+
dropIndex: vi.fn().mockResolvedValue(undefined),
|
|
6
|
+
indexes: vi.fn(),
|
|
7
|
+
updateMany: vi.fn().mockResolvedValue(undefined)
|
|
8
|
+
},
|
|
9
|
+
getSession: vi.fn().mockResolvedValue(undefined)
|
|
10
|
+
}));
|
|
11
|
+
vi.mock('../utilities/getEntity.js', ()=>({
|
|
12
|
+
getCollection: ()=>({
|
|
13
|
+
Model: {
|
|
14
|
+
collection: mocks.collection
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
}));
|
|
18
|
+
vi.mock('../utilities/getSession.js', ()=>({
|
|
19
|
+
getSession: mocks.getSession
|
|
20
|
+
}));
|
|
21
|
+
import { migrateJobsProcessingLease } from './migrateJobsProcessingLease.js';
|
|
22
|
+
describe('MongoDB jobs processing lease migration', ()=>{
|
|
23
|
+
const req = {
|
|
24
|
+
payload: {
|
|
25
|
+
db: {}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
afterEach(()=>{
|
|
29
|
+
vi.clearAllMocks();
|
|
30
|
+
});
|
|
31
|
+
it('should migrate active jobs to expired leases', async ()=>{
|
|
32
|
+
mocks.collection.indexes.mockResolvedValue([
|
|
33
|
+
{
|
|
34
|
+
key: {
|
|
35
|
+
_id: 1
|
|
36
|
+
},
|
|
37
|
+
name: '_id_'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
key: {
|
|
41
|
+
processing: 1
|
|
42
|
+
},
|
|
43
|
+
name: 'processing_1'
|
|
44
|
+
}
|
|
45
|
+
]);
|
|
46
|
+
await migrateJobsProcessingLease({
|
|
47
|
+
direction: 'up',
|
|
48
|
+
req
|
|
49
|
+
});
|
|
50
|
+
expect(mocks.collection.updateMany).toHaveBeenNthCalledWith(1, {
|
|
51
|
+
processing: true
|
|
52
|
+
}, {
|
|
53
|
+
$set: {
|
|
54
|
+
processingUntil: new Date(0)
|
|
55
|
+
}
|
|
56
|
+
}, {
|
|
57
|
+
session: undefined
|
|
58
|
+
});
|
|
59
|
+
expect(mocks.collection.updateMany).toHaveBeenNthCalledWith(2, {}, {
|
|
60
|
+
$unset: {
|
|
61
|
+
processing: ''
|
|
62
|
+
}
|
|
63
|
+
}, {
|
|
64
|
+
session: undefined
|
|
65
|
+
});
|
|
66
|
+
expect(mocks.collection.dropIndex).toHaveBeenCalledWith('processing_1', {
|
|
67
|
+
session: undefined
|
|
68
|
+
});
|
|
69
|
+
expect(mocks.collection.createIndex).toHaveBeenCalledWith({
|
|
70
|
+
processingUntil: 1
|
|
71
|
+
}, {
|
|
72
|
+
session: undefined
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
it('should restore the processing field when migrating down', async ()=>{
|
|
76
|
+
mocks.collection.indexes.mockResolvedValue([
|
|
77
|
+
{
|
|
78
|
+
key: {
|
|
79
|
+
_id: 1
|
|
80
|
+
},
|
|
81
|
+
name: '_id_'
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
key: {
|
|
85
|
+
processingUntil: 1
|
|
86
|
+
},
|
|
87
|
+
name: 'processingUntil_1'
|
|
88
|
+
}
|
|
89
|
+
]);
|
|
90
|
+
await migrateJobsProcessingLease({
|
|
91
|
+
direction: 'down',
|
|
92
|
+
req
|
|
93
|
+
});
|
|
94
|
+
expect(mocks.collection.updateMany).toHaveBeenNthCalledWith(1, {}, {
|
|
95
|
+
$set: {
|
|
96
|
+
processing: false
|
|
97
|
+
}
|
|
98
|
+
}, {
|
|
99
|
+
session: undefined
|
|
100
|
+
});
|
|
101
|
+
expect(mocks.collection.updateMany).toHaveBeenNthCalledWith(2, {
|
|
102
|
+
processingUntil: {
|
|
103
|
+
$ne: null
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
106
|
+
$set: {
|
|
107
|
+
processing: true
|
|
108
|
+
}
|
|
109
|
+
}, {
|
|
110
|
+
session: undefined
|
|
111
|
+
});
|
|
112
|
+
expect(mocks.collection.updateMany).toHaveBeenNthCalledWith(3, {}, {
|
|
113
|
+
$unset: {
|
|
114
|
+
processingUntil: ''
|
|
115
|
+
}
|
|
116
|
+
}, {
|
|
117
|
+
session: undefined
|
|
118
|
+
});
|
|
119
|
+
expect(mocks.collection.dropIndex).toHaveBeenCalledWith('processingUntil_1', {
|
|
120
|
+
session: undefined
|
|
121
|
+
});
|
|
122
|
+
expect(mocks.collection.createIndex).toHaveBeenCalledWith({
|
|
123
|
+
processing: 1
|
|
124
|
+
}, {
|
|
125
|
+
session: undefined
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
//# sourceMappingURL=migrateJobsProcessingLease.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/predefinedMigrations/migrateJobsProcessingLease.spec.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { afterEach, describe, expect, it, vi } from 'vitest'\n\nconst mocks = vi.hoisted(() => ({\n collection: {\n createIndex: vi.fn().mockResolvedValue(undefined),\n dropIndex: vi.fn().mockResolvedValue(undefined),\n indexes: vi.fn(),\n updateMany: vi.fn().mockResolvedValue(undefined),\n },\n getSession: vi.fn().mockResolvedValue(undefined),\n}))\n\nvi.mock('../utilities/getEntity.js', () => ({\n getCollection: () => ({ Model: { collection: mocks.collection } }),\n}))\n\nvi.mock('../utilities/getSession.js', () => ({\n getSession: mocks.getSession,\n}))\n\nimport { migrateJobsProcessingLease } from './migrateJobsProcessingLease.js'\n\ndescribe('MongoDB jobs processing lease migration', () => {\n const req = { payload: { db: {} } } as PayloadRequest\n\n afterEach(() => {\n vi.clearAllMocks()\n })\n\n it('should migrate active jobs to expired leases', async () => {\n mocks.collection.indexes.mockResolvedValue([\n { key: { _id: 1 }, name: '_id_' },\n { key: { processing: 1 }, name: 'processing_1' },\n ])\n\n await migrateJobsProcessingLease({ direction: 'up', req })\n\n expect(mocks.collection.updateMany).toHaveBeenNthCalledWith(\n 1,\n { processing: true },\n { $set: { processingUntil: new Date(0) } },\n { session: undefined },\n )\n expect(mocks.collection.updateMany).toHaveBeenNthCalledWith(\n 2,\n {},\n { $unset: { processing: '' } },\n { session: undefined },\n )\n expect(mocks.collection.dropIndex).toHaveBeenCalledWith('processing_1', {\n session: undefined,\n })\n expect(mocks.collection.createIndex).toHaveBeenCalledWith(\n { processingUntil: 1 },\n { session: undefined },\n )\n })\n\n it('should restore the processing field when migrating down', async () => {\n mocks.collection.indexes.mockResolvedValue([\n { key: { _id: 1 }, name: '_id_' },\n { key: { processingUntil: 1 }, name: 'processingUntil_1' },\n ])\n\n await migrateJobsProcessingLease({ direction: 'down', req })\n\n expect(mocks.collection.updateMany).toHaveBeenNthCalledWith(\n 1,\n {},\n { $set: { processing: false } },\n { session: undefined },\n )\n expect(mocks.collection.updateMany).toHaveBeenNthCalledWith(\n 2,\n { processingUntil: { $ne: null } },\n { $set: { processing: true } },\n { session: undefined },\n )\n expect(mocks.collection.updateMany).toHaveBeenNthCalledWith(\n 3,\n {},\n { $unset: { processingUntil: '' } },\n { session: undefined },\n )\n expect(mocks.collection.dropIndex).toHaveBeenCalledWith('processingUntil_1', {\n session: undefined,\n })\n expect(mocks.collection.createIndex).toHaveBeenCalledWith(\n { processing: 1 },\n { session: undefined },\n )\n })\n})\n"],"names":["afterEach","describe","expect","it","vi","mocks","hoisted","collection","createIndex","fn","mockResolvedValue","undefined","dropIndex","indexes","updateMany","getSession","mock","getCollection","Model","migrateJobsProcessingLease","req","payload","db","clearAllMocks","key","_id","name","processing","direction","toHaveBeenNthCalledWith","$set","processingUntil","Date","session","$unset","toHaveBeenCalledWith","$ne"],"mappings":"AAEA,SAASA,SAAS,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAE5D,MAAMC,QAAQD,GAAGE,OAAO,CAAC,IAAO,CAAA;QAC9BC,YAAY;YACVC,aAAaJ,GAAGK,EAAE,GAAGC,iBAAiB,CAACC;YACvCC,WAAWR,GAAGK,EAAE,GAAGC,iBAAiB,CAACC;YACrCE,SAAST,GAAGK,EAAE;YACdK,YAAYV,GAAGK,EAAE,GAAGC,iBAAiB,CAACC;QACxC;QACAI,YAAYX,GAAGK,EAAE,GAAGC,iBAAiB,CAACC;IACxC,CAAA;AAEAP,GAAGY,IAAI,CAAC,6BAA6B,IAAO,CAAA;QAC1CC,eAAe,IAAO,CAAA;gBAAEC,OAAO;oBAAEX,YAAYF,MAAME,UAAU;gBAAC;YAAE,CAAA;IAClE,CAAA;AAEAH,GAAGY,IAAI,CAAC,8BAA8B,IAAO,CAAA;QAC3CD,YAAYV,MAAMU,UAAU;IAC9B,CAAA;AAEA,SAASI,0BAA0B,QAAQ,kCAAiC;AAE5ElB,SAAS,2CAA2C;IAClD,MAAMmB,MAAM;QAAEC,SAAS;YAAEC,IAAI,CAAC;QAAE;IAAE;IAElCtB,UAAU;QACRI,GAAGmB,aAAa;IAClB;IAEApB,GAAG,gDAAgD;QACjDE,MAAME,UAAU,CAACM,OAAO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E,GACjC;YAAEN,MAAM;gBAAEH,YAAY;YAAK;QAAE,GAC7B;YAAEM,SAAStB;QAAU;QAEvBT,OAAOG,MAAME,UAAU,CAACO,UAAU,EAAEe,uBAAuB,CACzD,GACA,CAAC,GACD;YAAEK,QAAQ;gBAAEH,iBAAiB;YAAG;QAAE,GAClC;YAAEE,SAAStB;QAAU;QAEvBT,OAAOG,MAAME,UAAU,CAACK,SAAS,EAAEuB,oBAAoB,CAAC,qBAAqB;YAC3EF,SAAStB;QACX;QACAT,OAAOG,MAAME,UAAU,CAACC,WAAW,EAAE2B,oBAAoB,CACvD;YAAER,YAAY;QAAE,GAChB;YAAEM,SAAStB;QAAU;IAEzB;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/db-mongodb",
|
|
3
|
-
"version": "4.0.0-internal.
|
|
3
|
+
"version": "4.0.0-internal.9726517",
|
|
4
4
|
"description": "The officially supported MongoDB database adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
"mongodb": "6.20.0",
|
|
55
55
|
"mongodb-memory-server": "10.1.4",
|
|
56
56
|
"@payloadcms/eslint-config": "3.28.0",
|
|
57
|
-
"payload": "4.0.0-internal.
|
|
57
|
+
"payload": "4.0.0-internal.9726517"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"payload": "4.0.0-internal.
|
|
60
|
+
"payload": "4.0.0-internal.9726517"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "pnpm build:types && pnpm build:swc",
|