@payloadcms/db-mongodb 3.0.0-canary.f83d96a → 3.0.0-canary.fb04843
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +18 -4
- package/dist/connect.js.map +1 -1
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +9 -2
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts +3 -0
- package/dist/countGlobalVersions.d.ts.map +1 -0
- package/dist/countGlobalVersions.js +40 -0
- package/dist/countGlobalVersions.js.map +1 -0
- package/dist/countVersions.d.ts +3 -0
- package/dist/countVersions.d.ts.map +1 -0
- package/dist/countVersions.js +40 -0
- package/dist/countVersions.js.map +1 -0
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +11 -2
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +11 -6
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +14 -5
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +9 -7
- package/dist/createMigration.js.map +1 -1
- package/dist/createVersion.d.ts +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +32 -10
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +1 -1
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +12 -4
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +1 -1
- package/dist/deleteVersions.js.map +1 -1
- package/dist/exports/migration-utils.d.ts +3 -0
- package/dist/exports/migration-utils.d.ts.map +1 -0
- package/dist/exports/migration-utils.js +4 -0
- package/dist/exports/migration-utils.js.map +1 -0
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +35 -6
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +10 -4
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +18 -7
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +28 -4
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +17 -6
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +59 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -7
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +18 -16
- package/dist/init.js.map +1 -1
- package/dist/migrateFresh.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +1 -2
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +16 -4
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.js +2 -2
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +1 -2
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +116 -23
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts +6 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +141 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts +5 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js +107 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -0
- package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
- package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
- package/dist/predefinedMigrations/relationships-v2-v3.js +9 -0
- package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
- package/dist/predefinedMigrations/versions-v1-v2.d.ts +4 -0
- package/dist/predefinedMigrations/versions-v1-v2.d.ts.map +1 -0
- package/dist/predefinedMigrations/versions-v1-v2.js +5 -95
- package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +0 -2
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +2 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +1 -2
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +28 -18
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +2 -2
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js +26 -17
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +43 -43
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +7 -5
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +144 -27
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +37 -10
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +2 -0
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +3 -0
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
- package/dist/transactions/rollbackTransaction.js +13 -7
- package/dist/transactions/rollbackTransaction.js.map +1 -1
- package/dist/types.d.ts +7 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +18 -5
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts +2 -2
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +19 -5
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +19 -5
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +18 -4
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsert.d.ts +3 -0
- package/dist/upsert.d.ts.map +1 -0
- package/dist/upsert.js +15 -0
- package/dist/upsert.js.map +1 -0
- package/dist/utilities/buildJoinAggregation.d.ts +18 -0
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
- package/dist/utilities/buildJoinAggregation.js +159 -0
- package/dist/utilities/buildJoinAggregation.js.map +1 -0
- package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
- package/dist/utilities/buildProjectionFromSelect.js +171 -0
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
- package/dist/utilities/getDBName.d.ts.map +1 -1
- package/dist/utilities/getDBName.js +3 -1
- package/dist/utilities/getDBName.js.map +1 -1
- package/dist/utilities/handleError.js +2 -2
- package/dist/utilities/handleError.js.map +1 -1
- package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
- package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
- package/dist/utilities/sanitizeInternalFields.js +1 -2
- package/dist/utilities/sanitizeInternalFields.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.js +115 -0
- package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.spec.js +383 -0
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
- package/dist/withSession.d.ts +3 -2
- package/dist/withSession.d.ts.map +1 -1
- package/dist/withSession.js +10 -4
- package/dist/withSession.js.map +1 -1
- package/license.md +22 -0
- package/package.json +24 -11
@@ -0,0 +1,107 @@
|
|
1
|
+
import { withSession } from '../withSession.js';
|
2
|
+
export async function migrateVersionsV1_V2({ req }) {
|
3
|
+
const { payload } = req;
|
4
|
+
const { session } = await withSession(payload.db, req);
|
5
|
+
// For each collection
|
6
|
+
for (const { slug, versions } of payload.config.collections){
|
7
|
+
if (versions?.drafts) {
|
8
|
+
await migrateCollectionDocs({
|
9
|
+
slug,
|
10
|
+
payload,
|
11
|
+
session
|
12
|
+
});
|
13
|
+
payload.logger.info(`Migrated the "${slug}" collection.`);
|
14
|
+
}
|
15
|
+
}
|
16
|
+
// For each global
|
17
|
+
for (const { slug, versions } of payload.config.globals){
|
18
|
+
if (versions) {
|
19
|
+
const VersionsModel = payload.db.versions[slug];
|
20
|
+
await VersionsModel.findOneAndUpdate({}, {
|
21
|
+
latest: true
|
22
|
+
}, {
|
23
|
+
session,
|
24
|
+
sort: {
|
25
|
+
updatedAt: -1
|
26
|
+
}
|
27
|
+
}).exec();
|
28
|
+
payload.logger.info(`Migrated the "${slug}" global.`);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
async function migrateCollectionDocs({ slug, docsAtATime = 100, payload, session }) {
|
33
|
+
const VersionsModel = payload.db.versions[slug];
|
34
|
+
const remainingDocs = await VersionsModel.aggregate([
|
35
|
+
// Sort so that newest are first
|
36
|
+
{
|
37
|
+
$sort: {
|
38
|
+
updatedAt: -1
|
39
|
+
}
|
40
|
+
},
|
41
|
+
// Group by parent ID
|
42
|
+
// take the $first of each
|
43
|
+
{
|
44
|
+
$group: {
|
45
|
+
_id: '$parent',
|
46
|
+
_versionID: {
|
47
|
+
$first: '$_id'
|
48
|
+
},
|
49
|
+
createdAt: {
|
50
|
+
$first: '$createdAt'
|
51
|
+
},
|
52
|
+
latest: {
|
53
|
+
$first: '$latest'
|
54
|
+
},
|
55
|
+
updatedAt: {
|
56
|
+
$first: '$updatedAt'
|
57
|
+
},
|
58
|
+
version: {
|
59
|
+
$first: '$version'
|
60
|
+
}
|
61
|
+
}
|
62
|
+
},
|
63
|
+
{
|
64
|
+
$match: {
|
65
|
+
latest: {
|
66
|
+
$eq: null
|
67
|
+
}
|
68
|
+
}
|
69
|
+
},
|
70
|
+
{
|
71
|
+
$limit: docsAtATime
|
72
|
+
}
|
73
|
+
], {
|
74
|
+
allowDiskUse: true,
|
75
|
+
session
|
76
|
+
}).exec();
|
77
|
+
if (!remainingDocs || remainingDocs.length === 0) {
|
78
|
+
const newVersions = await VersionsModel.find({
|
79
|
+
latest: {
|
80
|
+
$eq: true
|
81
|
+
}
|
82
|
+
}, undefined, {
|
83
|
+
session
|
84
|
+
});
|
85
|
+
if (newVersions?.length) {
|
86
|
+
payload.logger.info(`Migrated ${newVersions.length} documents in the "${slug}" versions collection.`);
|
87
|
+
}
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
const remainingDocIds = remainingDocs.map((doc)=>doc._versionID);
|
91
|
+
await VersionsModel.updateMany({
|
92
|
+
_id: {
|
93
|
+
$in: remainingDocIds
|
94
|
+
}
|
95
|
+
}, {
|
96
|
+
latest: true
|
97
|
+
}, {
|
98
|
+
session
|
99
|
+
});
|
100
|
+
await migrateCollectionDocs({
|
101
|
+
slug,
|
102
|
+
payload,
|
103
|
+
session
|
104
|
+
});
|
105
|
+
}
|
106
|
+
|
107
|
+
//# sourceMappingURL=migrateVersionsV1_V2.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/predefinedMigrations/migrateVersionsV1_V2.ts"],"sourcesContent":["import type { ClientSession } from 'mongoose'\nimport type { Payload, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { withSession } from '../withSession.js'\n\nexport async function migrateVersionsV1_V2({ req }: { req: PayloadRequest }) {\n const { payload } = req\n\n const { session } = await withSession(payload.db as MongooseAdapter, req)\n\n // For each collection\n\n for (const { slug, versions } of payload.config.collections) {\n if (versions?.drafts) {\n await migrateCollectionDocs({ slug, payload, session })\n\n payload.logger.info(`Migrated the \"${slug}\" collection.`)\n }\n }\n\n // For each global\n for (const { slug, versions } of payload.config.globals) {\n if (versions) {\n const VersionsModel = payload.db.versions[slug]\n\n await VersionsModel.findOneAndUpdate(\n {},\n { latest: true },\n {\n session,\n sort: { updatedAt: -1 },\n },\n ).exec()\n\n payload.logger.info(`Migrated the \"${slug}\" global.`)\n }\n }\n}\n\nasync function migrateCollectionDocs({\n slug,\n docsAtATime = 100,\n payload,\n session,\n}: {\n docsAtATime?: number\n payload: Payload\n session: ClientSession\n slug: string\n}) {\n const VersionsModel = payload.db.versions[slug]\n const remainingDocs = await VersionsModel.aggregate(\n [\n // Sort so that newest are first\n {\n $sort: {\n updatedAt: -1,\n },\n },\n // Group by parent ID\n // take the $first of each\n {\n $group: {\n _id: '$parent',\n _versionID: { $first: '$_id' },\n createdAt: { $first: '$createdAt' },\n latest: { $first: '$latest' },\n updatedAt: { $first: '$updatedAt' },\n version: { $first: '$version' },\n },\n },\n {\n $match: {\n latest: { $eq: null },\n },\n },\n {\n $limit: docsAtATime,\n },\n ],\n {\n allowDiskUse: true,\n session,\n },\n ).exec()\n\n if (!remainingDocs || remainingDocs.length === 0) {\n const newVersions = await VersionsModel.find(\n {\n latest: {\n $eq: true,\n },\n },\n undefined,\n { session },\n )\n\n if (newVersions?.length) {\n payload.logger.info(\n `Migrated ${newVersions.length} documents in the \"${slug}\" versions collection.`,\n )\n }\n\n return\n }\n\n const remainingDocIds = remainingDocs.map((doc) => doc._versionID)\n\n await VersionsModel.updateMany(\n {\n _id: {\n $in: remainingDocIds,\n },\n },\n {\n latest: true,\n },\n {\n session,\n },\n )\n\n await migrateCollectionDocs({ slug, payload, session })\n}\n"],"names":["withSession","migrateVersionsV1_V2","req","payload","session","db","slug","versions","config","collections","drafts","migrateCollectionDocs","logger","info","globals","VersionsModel","findOneAndUpdate","latest","sort","updatedAt","exec","docsAtATime","remainingDocs","aggregate","$sort","$group","_id","_versionID","$first","createdAt","version","$match","$eq","$limit","allowDiskUse","length","newVersions","find","undefined","remainingDocIds","map","doc","updateMany","$in"],"mappings":"AAKA,SAASA,WAAW,QAAQ,oBAAmB;AAE/C,OAAO,eAAeC,qBAAqB,EAAEC,GAAG,EAA2B;IACzE,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,MAAM,EAAEE,OAAO,EAAE,GAAG,MAAMJ,YAAYG,QAAQE,EAAE,EAAqBH;IAErE,sBAAsB;IAEtB,KAAK,MAAM,EAAEI,IAAI,EAAEC,QAAQ,EAAE,IAAIJ,QAAQK,MAAM,CAACC,WAAW,CAAE;QAC3D,IAAIF,UAAUG,QAAQ;YACpB,MAAMC,sBAAsB;gBAAEL;gBAAMH;gBAASC;YAAQ;YAErDD,QAAQS,MAAM,CAACC,IAAI,CAAC,CAAC,cAAc,EAAEP,KAAK,aAAa,CAAC;QAC1D;IACF;IAEA,kBAAkB;IAClB,KAAK,MAAM,EAAEA,IAAI,EAAEC,QAAQ,EAAE,IAAIJ,QAAQK,MAAM,CAACM,OAAO,CAAE;QACvD,IAAIP,UAAU;YACZ,MAAMQ,gBAAgBZ,QAAQE,EAAE,CAACE,QAAQ,CAACD,KAAK;YAE/C,MAAMS,cAAcC,gBAAgB,CAClC,CAAC,GACD;gBAAEC,QAAQ;YAAK,GACf;gBACEb;gBACAc,MAAM;oBAAEC,WAAW,CAAC;gBAAE;YACxB,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ACA;QACEtB,QAAQ;IACV,GACA;QACEb;IACF;IAGF,MAAMO,sBAAsB;QAAEL;QAAMH;QAASC;IAAQ;AACvD"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
declare const imports = "import { migrateRelationshipsV2_V3 } from '@payloadcms/db-mongodb/migration-utils'";
|
2
|
+
declare const upSQL = " await migrateRelationshipsV2_V3({\n batchSize: 100,\n req,\n })\n";
|
3
|
+
export { imports, upSQL };
|
4
|
+
//# sourceMappingURL=relationships-v2-v3.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"relationships-v2-v3.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/relationships-v2-v3.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,uFAAuF,CAAA;AACpG,QAAA,MAAM,KAAK,8FAIV,CAAA;AACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
const imports = `import { migrateRelationshipsV2_V3 } from '@payloadcms/db-mongodb/migration-utils'`;
|
2
|
+
const upSQL = ` await migrateRelationshipsV2_V3({
|
3
|
+
batchSize: 100,
|
4
|
+
req,
|
5
|
+
})
|
6
|
+
`;
|
7
|
+
export { imports, upSQL };
|
8
|
+
|
9
|
+
//# sourceMappingURL=relationships-v2-v3.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/predefinedMigrations/relationships-v2-v3.ts"],"sourcesContent":["const imports = `import { migrateRelationshipsV2_V3 } from '@payloadcms/db-mongodb/migration-utils'`\nconst upSQL = ` await migrateRelationshipsV2_V3({\n batchSize: 100,\n req,\n })\n`\nexport { imports, upSQL }\n"],"names":["imports","upSQL"],"mappings":"AAAA,MAAMA,UAAU,CAAC,kFAAkF,CAAC;AACpG,MAAMC,QAAQ,CAAC;;;;AAIf,CAAC;AACD,SAASD,OAAO,EAAEC,KAAK,GAAE"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"versions-v1-v2.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/versions-v1-v2.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,kFAAkF,CAAA;AAC/F,QAAA,MAAM,KAAK,gEAGV,CAAA;AACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA"}
|
@@ -1,98 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
// Sort so that newest are first
|
6
|
-
{
|
7
|
-
$sort: {
|
8
|
-
updatedAt: -1,
|
9
|
-
},
|
10
|
-
},
|
11
|
-
// Group by parent ID
|
12
|
-
// take the $first of each
|
13
|
-
{
|
14
|
-
$group: {
|
15
|
-
_id: '$parent',
|
16
|
-
_versionID: { $first: '$_id' },
|
17
|
-
createdAt: { $first: '$createdAt' },
|
18
|
-
latest: { $first: '$latest' },
|
19
|
-
updatedAt: { $first: '$updatedAt' },
|
20
|
-
version: { $first: '$version' },
|
21
|
-
},
|
22
|
-
},
|
23
|
-
{
|
24
|
-
$match: {
|
25
|
-
latest: { $eq: null },
|
26
|
-
},
|
27
|
-
},
|
28
|
-
{
|
29
|
-
$limit: docsAtATime,
|
30
|
-
},
|
31
|
-
],
|
32
|
-
{
|
33
|
-
allowDiskUse: true,
|
34
|
-
},
|
35
|
-
).exec()
|
36
|
-
|
37
|
-
if (!remainingDocs || remainingDocs.length === 0) {
|
38
|
-
const newVersions = await VersionsModel.find({
|
39
|
-
latest: {
|
40
|
-
$eq: true,
|
41
|
-
},
|
42
|
-
})
|
43
|
-
|
44
|
-
if (newVersions?.length) {
|
45
|
-
payload.logger.info(
|
46
|
-
\`Migrated \${newVersions.length} documents in the "\${slug}" versions collection.\`,
|
47
|
-
)
|
48
|
-
}
|
49
|
-
|
50
|
-
return
|
51
|
-
}
|
52
|
-
|
53
|
-
const remainingDocIds = remainingDocs.map((doc) => doc._versionID)
|
54
|
-
|
55
|
-
await VersionsModel.updateMany(
|
56
|
-
{
|
57
|
-
_id: {
|
58
|
-
$in: remainingDocIds,
|
59
|
-
},
|
60
|
-
},
|
61
|
-
{
|
62
|
-
latest: true,
|
63
|
-
},
|
64
|
-
)
|
65
|
-
|
66
|
-
await migrateCollectionDocs(slug)
|
67
|
-
}
|
68
|
-
|
69
|
-
// For each collection
|
70
|
-
await Promise.all(
|
71
|
-
payload.config.collections.map(async ({ slug, versions }) => {
|
72
|
-
if (versions?.drafts) {
|
73
|
-
return migrateCollectionDocs(slug)
|
74
|
-
}
|
75
|
-
}),
|
76
|
-
)
|
77
|
-
|
78
|
-
// For each global
|
79
|
-
await Promise.all(
|
80
|
-
payload.config.globals.map(async ({ slug, versions }) => {
|
81
|
-
if (versions) {
|
82
|
-
const VersionsModel = payload.db.versions[slug]
|
83
|
-
|
84
|
-
await VersionsModel.findOneAndUpdate(
|
85
|
-
{},
|
86
|
-
{ latest: true },
|
87
|
-
{
|
88
|
-
sort: { updatedAt: -1 },
|
89
|
-
},
|
90
|
-
).exec()
|
91
|
-
|
92
|
-
payload.logger.info(\`Migrated the "\${slug}" global.\`)
|
93
|
-
}
|
94
|
-
}),
|
95
|
-
)
|
1
|
+
const imports = `import { migrateVersionsV1_V2 } from '@payloadcms/db-mongodb/migration-utils'`;
|
2
|
+
const upSQL = ` await migrateVersionsV1_V2({
|
3
|
+
req,
|
4
|
+
})
|
96
5
|
`;
|
6
|
+
export { imports, upSQL };
|
97
7
|
|
98
8
|
//# sourceMappingURL=versions-v1-v2.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/predefinedMigrations/versions-v1-v2.
|
1
|
+
{"version":3,"sources":["../../src/predefinedMigrations/versions-v1-v2.ts"],"sourcesContent":["const imports = `import { migrateVersionsV1_V2 } from '@payloadcms/db-mongodb/migration-utils'`\nconst upSQL = ` await migrateVersionsV1_V2({\n req,\n })\n`\nexport { imports, upSQL }\n"],"names":["imports","upSQL"],"mappings":"AAAA,MAAMA,UAAU,CAAC,6EAA6E,CAAC;AAC/F,MAAMC,QAAQ,CAAC;;;AAGf,CAAC;AACD,SAASD,OAAO,EAAEC,KAAK,GAAE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildAndOrConditions.d.ts","sourceRoot":"","sources":["../../src/queries/buildAndOrConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpD,wBAAsB,oBAAoB,CAAC,EACzC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,GACN,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,EAAE,CAAA;CACf,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,
|
1
|
+
{"version":3,"file":"buildAndOrConditions.d.ts","sourceRoot":"","sources":["../../src/queries/buildAndOrConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpD,wBAAsB,oBAAoB,CAAC,EACzC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,GACN,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,EAAE,CAAA;CACf,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAsBrC"}
|
@@ -3,11 +3,9 @@ export async function buildAndOrConditions({ collectionSlug, fields, globalSlug,
|
|
3
3
|
const completedConditions = [];
|
4
4
|
// Loop over all AND / OR operations and add them to the AND / OR query param
|
5
5
|
// Operations should come through as an array
|
6
|
-
// eslint-disable-next-line no-restricted-syntax
|
7
6
|
for (const condition of where){
|
8
7
|
// If the operation is properly formatted as an object
|
9
8
|
if (typeof condition === 'object') {
|
10
|
-
// eslint-disable-next-line no-await-in-loop
|
11
9
|
const result = await parseParams({
|
12
10
|
collectionSlug,
|
13
11
|
fields,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { Field, Payload, Where } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\nexport async function buildAndOrConditions({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n}: {\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n locale?: string\n payload: Payload\n where: Where[]\n}): Promise<Record<string, unknown>[]> {\n const completedConditions = []\n // Loop over all AND / OR operations and add them to the AND / OR query param\n // Operations should come through as an array\n
|
1
|
+
{"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { Field, Payload, Where } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\nexport async function buildAndOrConditions({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n}: {\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n locale?: string\n payload: Payload\n where: Where[]\n}): Promise<Record<string, unknown>[]> {\n const completedConditions = []\n // Loop over all AND / OR operations and add them to the AND / OR query param\n // Operations should come through as an array\n\n for (const condition of where) {\n // If the operation is properly formatted as an object\n if (typeof condition === 'object') {\n const result = await parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where: condition,\n })\n if (Object.keys(result).length > 0) {\n completedConditions.push(result)\n }\n }\n }\n return completedConditions\n}\n"],"names":["parseParams","buildAndOrConditions","collectionSlug","fields","globalSlug","locale","payload","where","completedConditions","condition","result","Object","keys","length","push"],"mappings":"AAEA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,qBAAqB,EACzCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EAQN;IACC,MAAMC,sBAAsB,EAAE;IAC9B,6EAA6E;IAC7E,6CAA6C;IAE7C,KAAK,MAAMC,aAAaF,MAAO;QAC7B,sDAAsD;QACtD,IAAI,OAAOE,cAAc,UAAU;YACjC,MAAMC,SAAS,MAAMV,YAAY;gBAC/BE;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,OAAOE;YACT;YACA,IAAIE,OAAOC,IAAI,CAACF,QAAQG,MAAM,GAAG,GAAG;gBAClCL,oBAAoBM,IAAI,CAACJ;YAC3B;QACF;IACF;IACA,OAAOF;AACT"}
|
@@ -9,6 +9,6 @@ export type BuildQueryArgs = {
|
|
9
9
|
payload: Payload;
|
10
10
|
where: Where;
|
11
11
|
};
|
12
|
-
declare const getBuildQueryPlugin: ({ collectionSlug, versionsFields }?: GetBuildQueryPluginArgs) => (schema: any) => void;
|
13
|
-
export
|
12
|
+
export declare const getBuildQueryPlugin: ({ collectionSlug, versionsFields, }?: GetBuildQueryPluginArgs) => (schema: any) => void;
|
13
|
+
export {};
|
14
14
|
//# sourceMappingURL=buildQuery.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAMpD,KAAK,uBAAuB,GAAG;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,KAAK,EAAE,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAID,
|
1
|
+
{"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAMpD,KAAK,uBAAuB,GAAG;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,KAAK,EAAE,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAID,eAAO,MAAM,mBAAmB,yCAG7B,uBAAuB,0BAsCzB,CAAA"}
|
@@ -2,7 +2,7 @@ import { QueryError } from 'payload';
|
|
2
2
|
import { parseParams } from './parseParams.js';
|
3
3
|
// This plugin asynchronously builds a list of Mongoose query constraints
|
4
4
|
// which can then be used in subsequent Mongoose queries.
|
5
|
-
const getBuildQueryPlugin = ({ collectionSlug, versionsFields } = {})=>{
|
5
|
+
export const getBuildQueryPlugin = ({ collectionSlug, versionsFields } = {})=>{
|
6
6
|
return function buildQueryPlugin(schema) {
|
7
7
|
const modifiedSchema = schema;
|
8
8
|
async function buildQuery({ globalSlug, locale, payload, where }) {
|
@@ -34,6 +34,5 @@ const getBuildQueryPlugin = ({ collectionSlug, versionsFields } = {})=>{
|
|
34
34
|
modifiedSchema.statics.buildQuery = buildQuery;
|
35
35
|
};
|
36
36
|
};
|
37
|
-
export default getBuildQueryPlugin;
|
38
37
|
|
39
38
|
//# sourceMappingURL=buildQuery.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { Field, Payload, Where } from 'payload'\n\nimport { QueryError } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\ntype GetBuildQueryPluginArgs = {\n collectionSlug?: string\n versionsFields?: Field[]\n}\n\nexport type BuildQueryArgs = {\n globalSlug?: string\n locale?: string\n payload: Payload\n where: Where\n}\n\n// This plugin asynchronously builds a list of Mongoose query constraints\n// which can then be used in subsequent Mongoose queries.\
|
1
|
+
{"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { Field, Payload, Where } from 'payload'\n\nimport { QueryError } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\ntype GetBuildQueryPluginArgs = {\n collectionSlug?: string\n versionsFields?: Field[]\n}\n\nexport type BuildQueryArgs = {\n globalSlug?: string\n locale?: string\n payload: Payload\n where: Where\n}\n\n// This plugin asynchronously builds a list of Mongoose query constraints\n// which can then be used in subsequent Mongoose queries.\nexport const getBuildQueryPlugin = ({\n collectionSlug,\n versionsFields,\n}: GetBuildQueryPluginArgs = {}) => {\n return function buildQueryPlugin(schema) {\n const modifiedSchema = schema\n async function buildQuery({\n globalSlug,\n locale,\n payload,\n where,\n }: BuildQueryArgs): Promise<Record<string, unknown>> {\n let fields = versionsFields\n if (!fields) {\n if (globalSlug) {\n const globalConfig = payload.globals.config.find(({ slug }) => slug === globalSlug)\n fields = globalConfig.fields\n }\n if (collectionSlug) {\n const collectionConfig = payload.collections[collectionSlug].config\n fields = collectionConfig.fields\n }\n }\n const errors = []\n const result = await parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n })\n\n if (errors.length > 0) {\n throw new QueryError(errors)\n }\n\n return result\n }\n modifiedSchema.statics.buildQuery = buildQuery\n }\n}\n"],"names":["QueryError","parseParams","getBuildQueryPlugin","collectionSlug","versionsFields","buildQueryPlugin","schema","modifiedSchema","buildQuery","globalSlug","locale","payload","where","fields","globalConfig","globals","config","find","slug","collectionConfig","collections","errors","result","length","statics"],"mappings":"AAEA,SAASA,UAAU,QAAQ,UAAS;AAEpC,SAASC,WAAW,QAAQ,mBAAkB;AAc9C,yEAAyE;AACzE,yDAAyD;AACzD,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,cAAc,EACdC,cAAc,EACU,GAAG,CAAC,CAAC;IAC7B,OAAO,SAASC,iBAAiBC,MAAM;QACrC,MAAMC,iBAAiBD;QACvB,eAAeE,WAAW,EACxBC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EACU;YACf,IAAIC,SAAST;YACb,IAAI,CAACS,QAAQ;gBACX,IAAIJ,YAAY;oBACd,MAAMK,eAAeH,QAAQI,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAAST;oBACxEI,SAASC,aAAaD,MAAM;gBAC9B;gBACA,IAAIV,gBAAgB;oBAClB,MAAMgB,mBAAmBR,QAAQS,WAAW,CAACjB,eAAe,CAACa,MAAM;oBACnEH,SAASM,iBAAiBN,MAAM;gBAClC;YACF;YACA,MAAMQ,SAAS,EAAE;YACjB,MAAMC,SAAS,MAAMrB,YAAY;gBAC/BE;gBACAU;gBACAJ;gBACAC;gBACAC;gBACAC;YACF;YAEA,IAAIS,OAAOE,MAAM,GAAG,GAAG;gBACrB,MAAM,IAAIvB,WAAWqB;YACvB;YAEA,OAAOC;QACT;QACAf,eAAeiB,OAAO,CAAChB,UAAU,GAAGA;IACtC;AACF,EAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildSearchParams.d.ts","sourceRoot":"","sources":["../../src/queries/buildSearchParams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAyB,OAAO,EAAE,MAAM,SAAS,CAAA;
|
1
|
+
{"version":3,"file":"buildSearchParams.d.ts","sourceRoot":"","sources":["../../src/queries/buildSearchParams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAyB,OAAO,EAAE,MAAM,SAAS,CAAA;AAWpE,KAAK,WAAW,GAAG;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAOD;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,cAAc,EACd,MAAM,EACN,UAAU,EACV,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,OAAO,EACP,GAAG,GACJ,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,OAAO,CAAA;CACb,GAAG,OAAO,CAAC,WAAW,CAAC,CAgOvB"}
|
@@ -1,10 +1,8 @@
|
|
1
|
-
import
|
2
|
-
import mongoose from 'mongoose';
|
1
|
+
import { Types } from 'mongoose';
|
3
2
|
import { getLocalizedPaths } from 'payload';
|
4
3
|
import { validOperators } from 'payload/shared';
|
5
4
|
import { operatorMap } from './operatorMap.js';
|
6
5
|
import { sanitizeQueryValue } from './sanitizeQueryValue.js';
|
7
|
-
const ObjectId = ObjectIdImport.default || ObjectIdImport;
|
8
6
|
const subQueryOptions = {
|
9
7
|
lean: true,
|
10
8
|
limit: 50
|
@@ -14,7 +12,9 @@ const subQueryOptions = {
|
|
14
12
|
*/ export async function buildSearchParam({ collectionSlug, fields, globalSlug, incomingPath, locale, operator, payload, val }) {
|
15
13
|
// Replace GraphQL nested field double underscore formatting
|
16
14
|
let sanitizedPath = incomingPath.replace(/__/g, '.');
|
17
|
-
if (sanitizedPath === 'id')
|
15
|
+
if (sanitizedPath === 'id') {
|
16
|
+
sanitizedPath = '_id';
|
17
|
+
}
|
18
18
|
let paths = [];
|
19
19
|
let hasCustomID = false;
|
20
20
|
if (sanitizedPath === '_id') {
|
@@ -45,16 +45,22 @@ const subQueryOptions = {
|
|
45
45
|
}
|
46
46
|
const [{ field, path }] = paths;
|
47
47
|
if (path) {
|
48
|
-
const
|
48
|
+
const sanitizedQueryValue = sanitizeQueryValue({
|
49
49
|
field,
|
50
50
|
hasCustomID,
|
51
51
|
operator,
|
52
52
|
path,
|
53
53
|
val
|
54
54
|
});
|
55
|
-
if (
|
56
|
-
|
57
|
-
}
|
55
|
+
if (!sanitizedQueryValue) {
|
56
|
+
return undefined;
|
57
|
+
}
|
58
|
+
const { operator: formattedOperator, rawQuery, val: formattedValue } = sanitizedQueryValue;
|
59
|
+
if (rawQuery) {
|
60
|
+
return {
|
61
|
+
value: rawQuery
|
62
|
+
};
|
63
|
+
}
|
58
64
|
// If there are multiple collections to search through,
|
59
65
|
// Recursively build up a list of query constraints
|
60
66
|
if (paths.length > 1) {
|
@@ -84,7 +90,7 @@ const subQueryOptions = {
|
|
84
90
|
result.forEach((doc)=>{
|
85
91
|
const stringID = doc._id.toString();
|
86
92
|
$in.push(stringID);
|
87
|
-
if (
|
93
|
+
if (Types.ObjectId.isValid(stringID)) {
|
88
94
|
$in.push(doc._id);
|
89
95
|
}
|
90
96
|
});
|
@@ -107,7 +113,7 @@ const subQueryOptions = {
|
|
107
113
|
}
|
108
114
|
const subQuery = priorQueryResult.value;
|
109
115
|
const result = await SubModel.find(subQuery, subQueryOptions);
|
110
|
-
const $in = result.map((doc)=>doc._id
|
116
|
+
const $in = result.map((doc)=>doc._id);
|
111
117
|
// If it is the last recursion
|
112
118
|
// then pass through the search param
|
113
119
|
if (i + 1 === pathsToQuery.length) {
|
@@ -133,7 +139,9 @@ const subQueryOptions = {
|
|
133
139
|
if (field.type === 'relationship' || field.type === 'upload') {
|
134
140
|
let hasNumberIDRelation;
|
135
141
|
let multiIDCondition = '$or';
|
136
|
-
if (operatorKey === '$ne')
|
142
|
+
if (operatorKey === '$ne') {
|
143
|
+
multiIDCondition = '$and';
|
144
|
+
}
|
137
145
|
const result = {
|
138
146
|
value: {
|
139
147
|
[multiIDCondition]: [
|
@@ -146,10 +154,10 @@ const subQueryOptions = {
|
|
146
154
|
}
|
147
155
|
};
|
148
156
|
if (typeof formattedValue === 'string') {
|
149
|
-
if (
|
157
|
+
if (Types.ObjectId.isValid(formattedValue)) {
|
150
158
|
result.value[multiIDCondition].push({
|
151
159
|
[path]: {
|
152
|
-
[operatorKey]: ObjectId(formattedValue)
|
160
|
+
[operatorKey]: new Types.ObjectId(formattedValue)
|
153
161
|
}
|
154
162
|
});
|
155
163
|
} else {
|
@@ -161,11 +169,13 @@ const subQueryOptions = {
|
|
161
169
|
hasNumberIDRelation = true;
|
162
170
|
}
|
163
171
|
});
|
164
|
-
if (hasNumberIDRelation)
|
165
|
-
[
|
166
|
-
[
|
167
|
-
|
168
|
-
|
172
|
+
if (hasNumberIDRelation) {
|
173
|
+
result.value[multiIDCondition].push({
|
174
|
+
[path]: {
|
175
|
+
[operatorKey]: parseFloat(formattedValue)
|
176
|
+
}
|
177
|
+
});
|
178
|
+
}
|
169
179
|
}
|
170
180
|
}
|
171
181
|
if (result.value[multiIDCondition].length > 1) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/queries/buildSearchParams.ts"],"sourcesContent":["import type { Field, Operator, PathToQuery, Payload } from 'payload'\n\nimport ObjectIdImport from 'bson-objectid'\nimport mongoose from 'mongoose'\nimport { getLocalizedPaths } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { operatorMap } from './operatorMap.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\nconst ObjectId = (ObjectIdImport.default ||\n ObjectIdImport) as unknown as typeof ObjectIdImport.default\n\ntype SearchParam = {\n path?: string\n rawQuery?: unknown\n value?: unknown\n}\n\nconst subQueryOptions = {\n lean: true,\n limit: 50,\n}\n\n/**\n * Convert the Payload key / value / operator into a MongoDB query\n */\nexport async function buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath,\n locale,\n operator,\n payload,\n val,\n}: {\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n incomingPath: string\n locale?: string\n operator: string\n payload: Payload\n val: unknown\n}): Promise<SearchParam> {\n // Replace GraphQL nested field double underscore formatting\n let sanitizedPath = incomingPath.replace(/__/g, '.')\n if (sanitizedPath === 'id') sanitizedPath = '_id'\n\n let paths: PathToQuery[] = []\n\n let hasCustomID = false\n\n if (sanitizedPath === '_id') {\n const customIDFieldType = payload.collections[collectionSlug]?.customIDType\n\n let idFieldType: 'number' | 'text' = 'text'\n\n if (customIDFieldType) {\n idFieldType = customIDFieldType\n hasCustomID = true\n }\n\n paths.push({\n collectionSlug,\n complete: true,\n field: {\n name: 'id',\n type: idFieldType,\n } as Field,\n path: '_id',\n })\n } else {\n paths = await getLocalizedPaths({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: sanitizedPath,\n locale,\n payload,\n })\n }\n\n const [{ field, path }] = paths\n\n if (path) {\n const {\n operator: formattedOperator,\n rawQuery,\n val: formattedValue,\n } = sanitizeQueryValue({\n field,\n hasCustomID,\n operator,\n path,\n val,\n })\n\n if (rawQuery) return { value: rawQuery }\n\n // If there are multiple collections to search through,\n // Recursively build up a list of query constraints\n if (paths.length > 1) {\n // Remove top collection and reverse array\n // to work backwards from top\n const pathsToQuery = paths.slice(1).reverse()\n\n const initialRelationshipQuery = {\n value: {},\n } as SearchParam\n\n const relationshipQuery = await pathsToQuery.reduce(\n async (priorQuery, { collectionSlug: slug, path: subPath }, i) => {\n const priorQueryResult = await priorQuery\n\n const SubModel = (payload.db as MongooseAdapter).collections[slug]\n\n // On the \"deepest\" collection,\n // Search on the value passed through the query\n if (i === 0) {\n const subQuery = await SubModel.buildQuery({\n locale,\n payload,\n where: {\n [subPath]: {\n [formattedOperator]: val,\n },\n },\n })\n\n const result = await SubModel.find(subQuery, subQueryOptions)\n\n const $in: unknown[] = []\n\n result.forEach((doc) => {\n const stringID = doc._id.toString()\n $in.push(stringID)\n\n if (mongoose.Types.ObjectId.isValid(stringID)) {\n $in.push(doc._id)\n }\n })\n\n if (pathsToQuery.length === 1) {\n return {\n path,\n value: { $in },\n }\n }\n\n const nextSubPath = pathsToQuery[i + 1].path\n\n return {\n value: { [nextSubPath]: { $in } },\n }\n }\n\n const subQuery = priorQueryResult.value\n const result = await SubModel.find(subQuery, subQueryOptions)\n\n const $in = result.map((doc) => doc._id.toString())\n\n // If it is the last recursion\n // then pass through the search param\n if (i + 1 === pathsToQuery.length) {\n return {\n path,\n value: { $in },\n }\n }\n\n return {\n value: {\n _id: { $in },\n },\n }\n },\n Promise.resolve(initialRelationshipQuery),\n )\n\n return relationshipQuery\n }\n\n if (formattedOperator && validOperators.includes(formattedOperator as Operator)) {\n const operatorKey = operatorMap[formattedOperator]\n\n if (field.type === 'relationship' || field.type === 'upload') {\n let hasNumberIDRelation\n let multiIDCondition = '$or'\n if (operatorKey === '$ne') multiIDCondition = '$and'\n\n const result = {\n value: {\n [multiIDCondition]: [{ [path]: { [operatorKey]: formattedValue } }],\n },\n }\n\n if (typeof formattedValue === 'string') {\n if (mongoose.Types.ObjectId.isValid(formattedValue)) {\n result.value[multiIDCondition].push({\n [path]: { [operatorKey]: ObjectId(formattedValue) },\n })\n } else {\n ;(Array.isArray(field.relationTo) ? field.relationTo : [field.relationTo]).forEach(\n (relationTo) => {\n const isRelatedToCustomNumberID =\n payload.collections[relationTo]?.customIDType === 'number'\n\n if (isRelatedToCustomNumberID) {\n hasNumberIDRelation = true\n }\n },\n )\n\n if (hasNumberIDRelation)\n result.value[multiIDCondition].push({\n [path]: { [operatorKey]: parseFloat(formattedValue) },\n })\n }\n }\n\n if (result.value[multiIDCondition].length > 1) {\n return result\n }\n }\n\n if (formattedOperator === 'like' && typeof formattedValue === 'string') {\n const words = formattedValue.split(' ')\n\n const result = {\n value: {\n $and: words.map((word) => ({\n [path]: {\n $options: 'i',\n $regex: word.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n },\n })),\n },\n }\n\n return result\n }\n\n // Some operators like 'near' need to define a full query\n // so if there is no operator key, just return the value\n if (!operatorKey) {\n return {\n path,\n value: formattedValue,\n }\n }\n\n return {\n path,\n value: { [operatorKey]: formattedValue },\n }\n }\n }\n return undefined\n}\n"],"names":["ObjectIdImport","mongoose","getLocalizedPaths","validOperators","operatorMap","sanitizeQueryValue","ObjectId","default","subQueryOptions","lean","limit","buildSearchParam","collectionSlug","fields","globalSlug","incomingPath","locale","operator","payload","val","sanitizedPath","replace","paths","hasCustomID","customIDFieldType","collections","customIDType","idFieldType","push","complete","field","name","type","path","formattedOperator","rawQuery","formattedValue","value","length","pathsToQuery","slice","reverse","initialRelationshipQuery","relationshipQuery","reduce","priorQuery","slug","subPath","i","priorQueryResult","SubModel","db","subQuery","buildQuery","where","result","find","$in","forEach","doc","stringID","_id","toString","Types","isValid","nextSubPath","map","Promise","resolve","includes","operatorKey","hasNumberIDRelation","multiIDCondition","Array","isArray","relationTo","isRelatedToCustomNumberID","parseFloat","words","split","$and","word","$options","$regex","undefined"],"mappings":"AAEA,OAAOA,oBAAoB,gBAAe;AAC1C,OAAOC,cAAc,WAAU;AAC/B,SAASC,iBAAiB,QAAQ,UAAS;AAC3C,SAASC,cAAc,QAAQ,iBAAgB;AAI/C,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,MAAMC,WAAYN,eAAeO,OAAO,IACtCP;AAQF,MAAMQ,kBAAkB;IACtBC,MAAM;IACNC,OAAO;AACT;AAEA;;CAEC,GACD,OAAO,eAAeC,iBAAiB,EACrCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,YAAY,EACZC,MAAM,EACNC,QAAQ,EACRC,OAAO,EACPC,GAAG,EAUJ;IACC,4DAA4D;IAC5D,IAAIC,gBAAgBL,aAAaM,OAAO,CAAC,OAAO;IAChD,IAAID,kBAAkB,MAAMA,gB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,CAAC,CAACe,OAAU,CAAA;gCACzB,CAAChD,KAAK,EAAE;oCACNiD,UAAU;oCACVC,QAAQF,KAAK5D,OAAO,CAAC,uBAAuB;gCAC9C;4BACF,CAAA;oBACF;gBACF;gBAEA,OAAOkC;YACT;YAEA,yDAAyD;YACzD,wDAAwD;YACxD,IAAI,CAACe,aAAa;gBAChB,OAAO;oBACLrC;oBACAI,OAAOD;gBACT;YACF;YAEA,OAAO;gBACLH;gBACAI,OAAO;oBAAE,CAACiC,YAAY,EAAElC;gBAAe;YACzC;QACF;IACF;IACA,OAAOgD;AACT"}
|
1
|
+
{"version":3,"sources":["../../src/queries/buildSearchParams.ts"],"sourcesContent":["import type { Field, Operator, PathToQuery, Payload } from 'payload'\n\nimport { Types } from 'mongoose'\nimport { getLocalizedPaths } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { operatorMap } from './operatorMap.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\ntype SearchParam = {\n path?: string\n rawQuery?: unknown\n value?: unknown\n}\n\nconst subQueryOptions = {\n lean: true,\n limit: 50,\n}\n\n/**\n * Convert the Payload key / value / operator into a MongoDB query\n */\nexport async function buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath,\n locale,\n operator,\n payload,\n val,\n}: {\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n incomingPath: string\n locale?: string\n operator: string\n payload: Payload\n val: unknown\n}): Promise<SearchParam> {\n // Replace GraphQL nested field double underscore formatting\n let sanitizedPath = incomingPath.replace(/__/g, '.')\n if (sanitizedPath === 'id') {\n sanitizedPath = '_id'\n }\n\n let paths: PathToQuery[] = []\n\n let hasCustomID = false\n\n if (sanitizedPath === '_id') {\n const customIDFieldType = payload.collections[collectionSlug]?.customIDType\n\n let idFieldType: 'number' | 'text' = 'text'\n\n if (customIDFieldType) {\n idFieldType = customIDFieldType\n hasCustomID = true\n }\n\n paths.push({\n collectionSlug,\n complete: true,\n field: {\n name: 'id',\n type: idFieldType,\n } as Field,\n path: '_id',\n })\n } else {\n paths = await getLocalizedPaths({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: sanitizedPath,\n locale,\n payload,\n })\n }\n\n const [{ field, path }] = paths\n\n if (path) {\n const sanitizedQueryValue = sanitizeQueryValue({\n field,\n hasCustomID,\n operator,\n path,\n val,\n })\n\n if (!sanitizedQueryValue) {\n return undefined\n }\n\n const { operator: formattedOperator, rawQuery, val: formattedValue } = sanitizedQueryValue\n\n if (rawQuery) {\n return { value: rawQuery }\n }\n\n // If there are multiple collections to search through,\n // Recursively build up a list of query constraints\n if (paths.length > 1) {\n // Remove top collection and reverse array\n // to work backwards from top\n const pathsToQuery = paths.slice(1).reverse()\n\n const initialRelationshipQuery = {\n value: {},\n } as SearchParam\n\n const relationshipQuery = await pathsToQuery.reduce(\n async (priorQuery, { collectionSlug: slug, path: subPath }, i) => {\n const priorQueryResult = await priorQuery\n\n const SubModel = (payload.db as MongooseAdapter).collections[slug]\n\n // On the \"deepest\" collection,\n // Search on the value passed through the query\n if (i === 0) {\n const subQuery = await SubModel.buildQuery({\n locale,\n payload,\n where: {\n [subPath]: {\n [formattedOperator]: val,\n },\n },\n })\n\n const result = await SubModel.find(subQuery, subQueryOptions)\n\n const $in: unknown[] = []\n\n result.forEach((doc) => {\n const stringID = doc._id.toString()\n $in.push(stringID)\n\n if (Types.ObjectId.isValid(stringID)) {\n $in.push(doc._id)\n }\n })\n\n if (pathsToQuery.length === 1) {\n return {\n path,\n value: { $in },\n }\n }\n\n const nextSubPath = pathsToQuery[i + 1].path\n\n return {\n value: { [nextSubPath]: { $in } },\n }\n }\n\n const subQuery = priorQueryResult.value\n const result = await SubModel.find(subQuery, subQueryOptions)\n\n const $in = result.map((doc) => doc._id)\n\n // If it is the last recursion\n // then pass through the search param\n if (i + 1 === pathsToQuery.length) {\n return {\n path,\n value: { $in },\n }\n }\n\n return {\n value: {\n _id: { $in },\n },\n }\n },\n Promise.resolve(initialRelationshipQuery),\n )\n\n return relationshipQuery\n }\n\n if (formattedOperator && validOperators.includes(formattedOperator as Operator)) {\n const operatorKey = operatorMap[formattedOperator]\n\n if (field.type === 'relationship' || field.type === 'upload') {\n let hasNumberIDRelation\n let multiIDCondition = '$or'\n if (operatorKey === '$ne') {\n multiIDCondition = '$and'\n }\n\n const result = {\n value: {\n [multiIDCondition]: [{ [path]: { [operatorKey]: formattedValue } }],\n },\n }\n\n if (typeof formattedValue === 'string') {\n if (Types.ObjectId.isValid(formattedValue)) {\n result.value[multiIDCondition].push({\n [path]: { [operatorKey]: new Types.ObjectId(formattedValue) },\n })\n } else {\n ;(Array.isArray(field.relationTo) ? field.relationTo : [field.relationTo]).forEach(\n (relationTo) => {\n const isRelatedToCustomNumberID =\n payload.collections[relationTo]?.customIDType === 'number'\n\n if (isRelatedToCustomNumberID) {\n hasNumberIDRelation = true\n }\n },\n )\n\n if (hasNumberIDRelation) {\n result.value[multiIDCondition].push({\n [path]: { [operatorKey]: parseFloat(formattedValue) },\n })\n }\n }\n }\n\n if (result.value[multiIDCondition].length > 1) {\n return result\n }\n }\n\n if (formattedOperator === 'like' && typeof formattedValue === 'string') {\n const words = formattedValue.split(' ')\n\n const result = {\n value: {\n $and: words.map((word) => ({\n [path]: {\n $options: 'i',\n $regex: word.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n },\n })),\n },\n }\n\n return result\n }\n\n // Some operators like 'near' need to define a full query\n // so if there is no operator key, just return the value\n if (!operatorKey) {\n return {\n path,\n value: formattedValue,\n }\n }\n\n return {\n path,\n value: { [operatorKey]: formattedValue },\n }\n }\n }\n return undefined\n}\n"],"names":["Types","getLocalizedPaths","validOperators","operatorMap","sanitizeQueryValue","subQueryOptions","lean","limit","buildSearchParam","collectionSlug","fields","globalSlug","incomingPath","locale","operator","payload","val","sanitizedPath","replace","paths","hasCustomID","customIDFieldType","collections","customIDType","idFieldType","push","complete","field","name","type","path","sanitizedQueryValue","undefined","formattedOperator","rawQuery","formattedValue","value","length","pathsToQuery","slice","reverse","initialRelationshipQuery","relationshipQuery","reduce","priorQuery","slug","subPath","i","priorQueryResult","SubModel","db","subQuery","buildQuery","where","result","find","$in","forEach","doc","stringID","_id","toString","ObjectId","isValid","nextSubPath","map","Promise","resolve","includes","operatorKey","hasNumberIDRelation","multiIDCondition","Array","isArray","relationTo","isRelatedToCustomNumberID","parseFloat","words","split","$and","word","$options","$regex"],"mappings":"AAEA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,iBAAiB,QAAQ,UAAS;AAC3C,SAASC,cAAc,QAAQ,iBAAgB;AAI/C,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAQ5D,MAAMC,kBAAkB;IACtBC,MAAM;IACNC,OAAO;AACT;AAEA;;CAEC,GACD,OAAO,eAAeC,iBAAiB,EACrCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,YAAY,EACZC,MAAM,EACNC,QAAQ,EACRC,OAAO,EACPC,GAAG,EAUJ;IACC,4DAA4D;IAC5D,IAAIC,gBAAgBL,aAAaM,OAAO,CAAC,OAAO;IAChD,IAAID,kBAAkB,MAAM;QAC1BA,gBAAgB;IAClB;IAEA,IAAIE,QAAuB,EAAE;IAE7B,IAAIC,cAAc;IAElB,IAAIH,kBAAkB,OAAO;QAC3B,MAAMI,oBAAoBN,QAAQO,WAAW,CAACb,eAAe,EAAEc;QAE/D,IAAIC,cAAiC;QAErC,IAAIH,mBAAmB;YACrBG,cAAcH;YACdD,cAAc;QAChB;QAEAD,MAAMM,IAAI,CAAC;YACThB;YACAiB,UAAU;YACVC,OAAO;gBACLC,MAAM;gBACNC,MAAML;YACR;YACAM,MAAM;QACR;IACF,OAAO;QACLX,QAAQ,MAAMlB,kBAAkB;YAC9BQ;YACAC;YACAC;YACAC,cAAcK;YACdJ;YACAE;QACF;IACF;IAEA,MAAM,CAAC,EAAEY,KAAK,EAAEG,IAAI,EAAE,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+1,10 @@
|
|
1
1
|
import type { PaginateOptions } from 'mongoose';
|
2
|
-
import type { Field, SanitizedConfig } from 'payload';
|
2
|
+
import type { Field, SanitizedConfig, Sort } from 'payload';
|
3
3
|
type Args = {
|
4
4
|
config: SanitizedConfig;
|
5
5
|
fields: Field[];
|
6
6
|
locale: string;
|
7
|
-
sort:
|
7
|
+
sort: Sort;
|
8
8
|
timestamps: boolean;
|
9
9
|
};
|
10
10
|
export type SortArgs = {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildSortParam.d.ts","sourceRoot":"","sources":["../../src/queries/buildSortParam.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;
|
1
|
+
{"version":3,"file":"buildSortParam.d.ts","sourceRoot":"","sources":["../../src/queries/buildSortParam.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAI3D,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,IAAI,CAAA;IACV,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,SAAS,EAAE,aAAa,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;CACjB,EAAE,CAAA;AAEH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAA;AAE1C,eAAO,MAAM,cAAc,kDAMxB,IAAI,KAAG,eAAe,CAAC,MAAM,CAsC/B,CAAA"}
|
@@ -1,32 +1,41 @@
|
|
1
1
|
import { getLocalizedSortProperty } from './getLocalizedSortProperty.js';
|
2
2
|
export const buildSortParam = ({ config, fields, locale, sort, timestamps })=>{
|
3
|
-
let sortProperty;
|
4
|
-
let sortDirection = 'desc';
|
5
3
|
if (!sort) {
|
6
4
|
if (timestamps) {
|
7
|
-
|
5
|
+
sort = '-createdAt';
|
8
6
|
} else {
|
9
|
-
|
7
|
+
sort = '-id';
|
10
8
|
}
|
11
|
-
} else if (sort.indexOf('-') === 0) {
|
12
|
-
sortProperty = sort.substring(1);
|
13
|
-
} else {
|
14
|
-
sortProperty = sort;
|
15
|
-
sortDirection = 'asc';
|
16
9
|
}
|
17
|
-
if (
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
if (typeof sort === 'string') {
|
11
|
+
sort = [
|
12
|
+
sort
|
13
|
+
];
|
14
|
+
}
|
15
|
+
const sorting = sort.reduce((acc, item)=>{
|
16
|
+
let sortProperty;
|
17
|
+
let sortDirection;
|
18
|
+
if (item.indexOf('-') === 0) {
|
19
|
+
sortProperty = item.substring(1);
|
20
|
+
sortDirection = 'desc';
|
21
|
+
} else {
|
22
|
+
sortProperty = item;
|
23
|
+
sortDirection = 'asc';
|
24
|
+
}
|
25
|
+
if (sortProperty === 'id') {
|
26
|
+
acc['_id'] = sortDirection;
|
27
|
+
return acc;
|
28
|
+
}
|
29
|
+
const localizedProperty = getLocalizedSortProperty({
|
21
30
|
config,
|
22
31
|
fields,
|
23
32
|
locale,
|
24
33
|
segments: sortProperty.split('.')
|
25
34
|
});
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
35
|
+
acc[localizedProperty] = sortDirection;
|
36
|
+
return acc;
|
37
|
+
}, {});
|
38
|
+
return sorting;
|
30
39
|
};
|
31
40
|
|
32
41
|
//# sourceMappingURL=buildSortParam.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/queries/buildSortParam.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Field, SanitizedConfig } from 'payload'\n\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\ntype Args = {\n config: SanitizedConfig\n fields: Field[]\n locale: string\n sort:
|
1
|
+
{"version":3,"sources":["../../src/queries/buildSortParam.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Field, SanitizedConfig, Sort } from 'payload'\n\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\ntype Args = {\n config: SanitizedConfig\n fields: Field[]\n locale: string\n sort: Sort\n timestamps: boolean\n}\n\nexport type SortArgs = {\n direction: SortDirection\n property: string\n}[]\n\nexport type SortDirection = 'asc' | 'desc'\n\nexport const buildSortParam = ({\n config,\n fields,\n locale,\n sort,\n timestamps,\n}: Args): PaginateOptions['sort'] => {\n if (!sort) {\n if (timestamps) {\n sort = '-createdAt'\n } else {\n sort = '-id'\n }\n }\n\n if (typeof sort === 'string') {\n sort = [sort]\n }\n\n const sorting = sort.reduce<PaginateOptions['sort']>((acc, item) => {\n let sortProperty: string\n let sortDirection: SortDirection\n if (item.indexOf('-') === 0) {\n sortProperty = item.substring(1)\n sortDirection = 'desc'\n } else {\n sortProperty = item\n sortDirection = 'asc'\n }\n if (sortProperty === 'id') {\n acc['_id'] = sortDirection\n return acc\n }\n const localizedProperty = getLocalizedSortProperty({\n config,\n fields,\n locale,\n segments: sortProperty.split('.'),\n })\n acc[localizedProperty] = sortDirection\n return acc\n }, {})\n\n return sorting\n}\n"],"names":["getLocalizedSortProperty","buildSortParam","config","fields","locale","sort","timestamps","sorting","reduce","acc","item","sortProperty","sortDirection","indexOf","substring","localizedProperty","segments","split"],"mappings":"AAGA,SAASA,wBAAwB,QAAQ,gCAA+B;AAiBxE,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,UAAU,EACL;IACL,IAAI,CAACD,MAAM;QACT,IAAIC,YAAY;YACdD,OAAO;QACT,OAAO;YACLA,OAAO;QACT;IACF;IAEA,IAAI,OAAOA,SAAS,UAAU;QAC5BA,OAAO;YAACA;SAAK;IACf;IAEA,MAAME,UAAUF,KAAKG,MAAM,CAA0B,CAACC,KAAKC;QACzD,IAAIC;QACJ,IAAIC;QACJ,IAAIF,KAAKG,OAAO,CAAC,SAAS,GAAG;YAC3BF,eAAeD,KAAKI,SAAS,CAAC;YAC9BF,gBAAgB;QAClB,OAAO;YACLD,eAAeD;YACfE,gBAAgB;QAClB;QACA,IAAID,iBAAiB,MAAM;YACzBF,GAAG,CAAC,MAAM,GAAGG;YACb,OAAOH;QACT;QACA,MAAMM,oBAAoBf,yBAAyB;YACjDE;YACAC;YACAC;YACAY,UAAUL,aAAaM,KAAK,CAAC;QAC/B;QACAR,GAAG,CAACM,kBAAkB,GAAGH;QACzB,OAAOH;IACT,GAAG,CAAC;IAEJ,OAAOF;AACT,EAAC"}
|