@payloadcms/db-mongodb 3.2.2-canary.d2399ed → 3.2.3-canary.2d2e7d5
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/count.d.ts.map +1 -1
- package/dist/count.js +21 -19
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts.map +1 -1
- package/dist/countGlobalVersions.js +21 -19
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +21 -19
- package/dist/countVersions.js.map +1 -1
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +22 -22
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +19 -21
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +30 -35
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +30 -35
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +6 -6
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +13 -17
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +6 -6
- package/dist/deleteVersions.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +74 -41
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +18 -19
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +62 -33
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +19 -32
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +62 -34
- package/dist/findVersions.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +16 -20
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js +2 -2
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -1
- package/dist/queries/buildAndOrConditions.d.ts +1 -3
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +1 -2
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +0 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +6 -2
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts +1 -3
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +10 -14
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +7 -1
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js +2 -2
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.js +2 -2
- package/dist/queries/getLocalizedSortProperty.js.map +1 -1
- package/dist/queries/parseParams.d.ts +1 -3
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +1 -2
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +0 -16
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +65 -41
- package/dist/queryDrafts.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +23 -25
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +27 -28
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +24 -28
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +26 -28
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.d.ts +4 -4
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +28 -7
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.js +1 -18
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
- package/dist/utilities/sanitizeInternalFields.d.ts +2 -0
- package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -0
- package/dist/utilities/sanitizeInternalFields.js +20 -0
- package/dist/utilities/sanitizeInternalFields.js.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.js +125 -0
- package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
- package/dist/utilities/{transform.spec.js → sanitizeRelationshipIDs.spec.js} +7 -23
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
- package/dist/{getSession.d.ts → withSession.d.ts} +4 -2
- package/dist/withSession.d.ts.map +1 -0
- package/dist/{getSession.js → withSession.js} +5 -3
- package/dist/withSession.js.map +1 -0
- package/package.json +3 -3
- package/dist/getSession.d.ts.map +0 -1
- package/dist/getSession.js.map +0 -1
- package/dist/utilities/findMany.d.ts +0 -20
- package/dist/utilities/findMany.d.ts.map +0 -1
- package/dist/utilities/findMany.js +0 -84
- package/dist/utilities/findMany.js.map +0 -1
- package/dist/utilities/getHasNearConstraint.d.ts +0 -3
- package/dist/utilities/getHasNearConstraint.d.ts.map +0 -1
- package/dist/utilities/getHasNearConstraint.js +0 -26
- package/dist/utilities/getHasNearConstraint.js.map +0 -1
- package/dist/utilities/transform.d.ts +0 -17
- package/dist/utilities/transform.d.ts.map +0 -1
- package/dist/utilities/transform.js +0 -250
- package/dist/utilities/transform.js.map +0 -1
- package/dist/utilities/transform.spec.js.map +0 -1
package/dist/createVersion.js
CHANGED
|
@@ -1,31 +1,27 @@
|
|
|
1
1
|
import { Types } from 'mongoose';
|
|
2
2
|
import { buildVersionCollectionFields } from 'payload';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
|
4
|
+
import { withSession } from './withSession.js';
|
|
5
5
|
export const createVersion = async function createVersion({ autosave, collectionSlug, createdAt, parent, publishedLocale, req = {}, snapshot, updatedAt, versionData }) {
|
|
6
6
|
const VersionModel = this.versions[collectionSlug];
|
|
7
|
-
const
|
|
8
|
-
const data = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
data,
|
|
22
|
-
fields,
|
|
23
|
-
operation: 'create'
|
|
24
|
-
});
|
|
25
|
-
const { insertedId } = await VersionModel.collection.insertOne(data, {
|
|
26
|
-
session
|
|
7
|
+
const options = await withSession(this, req);
|
|
8
|
+
const data = sanitizeRelationshipIDs({
|
|
9
|
+
config: this.payload.config,
|
|
10
|
+
data: {
|
|
11
|
+
autosave,
|
|
12
|
+
createdAt,
|
|
13
|
+
latest: true,
|
|
14
|
+
parent,
|
|
15
|
+
publishedLocale,
|
|
16
|
+
snapshot,
|
|
17
|
+
updatedAt,
|
|
18
|
+
version: versionData
|
|
19
|
+
},
|
|
20
|
+
fields: buildVersionCollectionFields(this.payload.config, this.payload.collections[collectionSlug].config)
|
|
27
21
|
});
|
|
28
|
-
|
|
22
|
+
const [doc] = await VersionModel.create([
|
|
23
|
+
data
|
|
24
|
+
], options, req);
|
|
29
25
|
const parentQuery = {
|
|
30
26
|
$or: [
|
|
31
27
|
{
|
|
@@ -42,11 +38,11 @@ export const createVersion = async function createVersion({ autosave, collection
|
|
|
42
38
|
}
|
|
43
39
|
});
|
|
44
40
|
}
|
|
45
|
-
await VersionModel.
|
|
41
|
+
await VersionModel.updateMany({
|
|
46
42
|
$and: [
|
|
47
43
|
{
|
|
48
44
|
_id: {
|
|
49
|
-
$ne:
|
|
45
|
+
$ne: doc._id
|
|
50
46
|
}
|
|
51
47
|
},
|
|
52
48
|
parentQuery,
|
|
@@ -60,16 +56,15 @@ export const createVersion = async function createVersion({ autosave, collection
|
|
|
60
56
|
$unset: {
|
|
61
57
|
latest: 1
|
|
62
58
|
}
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return data;
|
|
59
|
+
}, options);
|
|
60
|
+
const result = JSON.parse(JSON.stringify(doc));
|
|
61
|
+
const verificationToken = doc._verificationToken;
|
|
62
|
+
// custom id type reset
|
|
63
|
+
result.id = result._id;
|
|
64
|
+
if (verificationToken) {
|
|
65
|
+
result._verificationToken = verificationToken;
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
73
68
|
};
|
|
74
69
|
|
|
75
70
|
//# sourceMappingURL=createVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import { Types } from 'mongoose'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import { Types } from 'mongoose'\nimport {\n buildVersionCollectionFields,\n type CreateVersion,\n type Document,\n type PayloadRequest,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const createVersion: CreateVersion = async function createVersion(\n this: MongooseAdapter,\n {\n autosave,\n collectionSlug,\n createdAt,\n parent,\n publishedLocale,\n req = {} as PayloadRequest,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const VersionModel = this.versions[collectionSlug]\n const options = await withSession(this, req)\n\n const data = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: {\n autosave,\n createdAt,\n latest: true,\n parent,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n },\n fields: buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collectionSlug].config,\n ),\n })\n\n const [doc] = await VersionModel.create([data], options, req)\n\n const parentQuery = {\n $or: [\n {\n parent: {\n $eq: data.parent,\n },\n },\n ],\n }\n if (data.parent instanceof Types.ObjectId) {\n parentQuery.$or.push({\n parent: {\n $eq: data.parent.toString(),\n },\n })\n }\n\n await VersionModel.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n parentQuery,\n {\n latest: {\n $eq: true,\n },\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\n )\n\n const result: Document = JSON.parse(JSON.stringify(doc))\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["Types","buildVersionCollectionFields","sanitizeRelationshipIDs","withSession","createVersion","autosave","collectionSlug","createdAt","parent","publishedLocale","req","snapshot","updatedAt","versionData","VersionModel","versions","options","data","config","payload","latest","version","fields","collections","doc","create","parentQuery","$or","$eq","ObjectId","push","toString","updateMany","$and","_id","$ne","$unset","result","JSON","parse","stringify","verificationToken","_verificationToken","id"],"mappings":"AAAA,SAASA,KAAK,QAAQ,WAAU;AAChC,SACEC,4BAA4B,QAIvB,UAAS;AAIhB,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,gBAA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M,EAAE,GAAGN,OAAOH,GAAG;IACtB,IAAIO,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
|
package/dist/deleteMany.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,SAAS,CAAA;AAMzD,eAAO,MAAM,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,SAAS,CAAA;AAMzD,eAAO,MAAM,UAAU,EAAE,UAgBxB,CAAA"}
|
package/dist/deleteMany.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { withSession } from './withSession.js';
|
|
2
2
|
export const deleteMany = async function deleteMany({ collection, req = {}, where }) {
|
|
3
3
|
const Model = this.collections[collection];
|
|
4
|
-
const
|
|
4
|
+
const options = {
|
|
5
|
+
...await withSession(this, req),
|
|
6
|
+
lean: true
|
|
7
|
+
};
|
|
5
8
|
const query = await Model.buildQuery({
|
|
6
9
|
payload: this.payload,
|
|
7
|
-
session,
|
|
8
10
|
where
|
|
9
11
|
});
|
|
10
|
-
await Model.
|
|
11
|
-
session
|
|
12
|
-
});
|
|
12
|
+
await Model.deleteMany(query, options);
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
//# sourceMappingURL=deleteMany.js.map
|
package/dist/deleteMany.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: MongooseAdapter,\n { collection, req = {} as PayloadRequest, where },\n) {\n const Model = this.collections[collection]\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n }\n\n const query = await Model.buildQuery({\n payload: this.payload,\n where,\n })\n\n await Model.deleteMany(query, options)\n}\n"],"names":["withSession","deleteMany","collection","req","where","Model","collections","options","lean","query","buildQuery","payload"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEjD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAU;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEG,IAAI;QAChCK,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMC,MAAMJ,UAAU,CAACQ,OAAOF;AAChC,EAAC"}
|
package/dist/deleteOne.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAA4B,MAAM,SAAS,CAAA;AAQlE,eAAO,MAAM,SAAS,EAAE,SA4BvB,CAAA"}
|
package/dist/deleteOne.js
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
import { getSession } from './getSession.js';
|
|
2
1
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
|
-
import {
|
|
2
|
+
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
|
|
3
|
+
import { withSession } from './withSession.js';
|
|
4
4
|
export const deleteOne = async function deleteOne({ collection, req = {}, select, where }) {
|
|
5
5
|
const Model = this.collections[collection];
|
|
6
|
-
const
|
|
6
|
+
const options = await withSession(this, req);
|
|
7
7
|
const query = await Model.buildQuery({
|
|
8
8
|
payload: this.payload,
|
|
9
|
-
session,
|
|
10
9
|
where
|
|
11
10
|
});
|
|
12
|
-
const
|
|
13
|
-
|
|
11
|
+
const doc = await Model.findOneAndDelete(query, {
|
|
12
|
+
...options,
|
|
14
13
|
projection: buildProjectionFromSelect({
|
|
15
14
|
adapter: this,
|
|
16
|
-
fields,
|
|
15
|
+
fields: this.payload.collections[collection].config.flattenedFields,
|
|
17
16
|
select
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
operation: 'read'
|
|
26
|
-
});
|
|
27
|
-
return doc;
|
|
17
|
+
})
|
|
18
|
+
}).lean();
|
|
19
|
+
let result = JSON.parse(JSON.stringify(doc));
|
|
20
|
+
// custom id type reset
|
|
21
|
+
result.id = result._id;
|
|
22
|
+
result = sanitizeInternalFields(result);
|
|
23
|
+
return result;
|
|
28
24
|
};
|
|
29
25
|
|
|
30
26
|
//# sourceMappingURL=deleteOne.js.map
|
package/dist/deleteOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne, Document, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: MongooseAdapter,\n { collection, req = {} as PayloadRequest, select, where },\n) {\n const Model = this.collections[collection]\n const options = await withSession(this, req)\n\n const query = await Model.buildQuery({\n payload: this.payload,\n where,\n })\n\n const doc = await Model.findOneAndDelete(query, {\n ...options,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.collections[collection].config.flattenedFields,\n select,\n }),\n }).lean()\n\n let result: Document = JSON.parse(JSON.stringify(doc))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildProjectionFromSelect","sanitizeInternalFields","withSession","deleteOne","collection","req","select","where","Model","collections","options","query","buildQuery","payload","doc","findOneAndDelete","projection","adapter","fields","config","flattenedFields","lean","result","JSON","parse","stringify","id","_id"],"mappings":"AAIA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAEzD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACL,WAAW;IAC1C,MAAMM,UAAU,MAAMR,YAAY,IAAI,EAAEG;IAExC,MAAMM,QAAQ,MAAMH,MAAMI,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBN;IACF;IAEA,MAAMO,MAAM,MAAMN,MAAMO,gBAAgB,CAACJ,OAAO;QAC9C,GAAGD,OAAO;QACVM,YAAYhB,0BAA0B;YACpCiB,SAAS,IAAI;YACbC,QAAQ,IAAI,CAACL,OAAO,CAACJ,WAAW,CAACL,WAAW,CAACe,MAAM,CAACC,eAAe;YACnEd;QACF;IACF,GAAGe,IAAI;IAEP,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACX;IAEjD,uBAAuB;IACvBQ,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAASrB,uBAAuBqB;IAEhC,OAAOA;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,SAAS,CAAA;AAM7D,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,SAAS,CAAA;AAM7D,eAAO,MAAM,cAAc,EAAE,cAiB5B,CAAA"}
|
package/dist/deleteVersions.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { withSession } from './withSession.js';
|
|
2
2
|
export const deleteVersions = async function deleteVersions({ collection, locale, req = {}, where }) {
|
|
3
3
|
const VersionsModel = this.versions[collection];
|
|
4
|
-
const
|
|
4
|
+
const options = {
|
|
5
|
+
...await withSession(this, req),
|
|
6
|
+
lean: true
|
|
7
|
+
};
|
|
5
8
|
const query = await VersionsModel.buildQuery({
|
|
6
9
|
locale,
|
|
7
10
|
payload: this.payload,
|
|
8
|
-
session,
|
|
9
11
|
where
|
|
10
12
|
});
|
|
11
|
-
await VersionsModel.
|
|
12
|
-
session
|
|
13
|
-
});
|
|
13
|
+
await VersionsModel.deleteMany(query, options);
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
//# sourceMappingURL=deleteVersions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: MongooseAdapter,\n { collection, locale, req = {} as PayloadRequest, where },\n) {\n const VersionsModel = this.versions[collection]\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n }\n\n const query = await VersionsModel.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n await VersionsModel.deleteMany(query, options)\n}\n"],"names":["withSession","deleteVersions","collection","locale","req","where","VersionsModel","versions","options","lean","query","buildQuery","payload","deleteMany"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,iBAAiC,eAAeA,eAE3D,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEzD,MAAMC,gBAAgB,IAAI,CAACC,QAAQ,CAACL,WAAW;IAC/C,MAAMM,UAAU;QACd,GAAI,MAAMR,YAAY,IAAI,EAAEI,IAAI;QAChCK,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMJ,cAAcK,UAAU,CAAC;QAC3CR;QACAS,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMC,cAAcO,UAAU,CAACH,OAAOF;AACxC,EAAC"}
|
package/dist/find.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAkB,MAAM,SAAS,CAAA;AAYnD,eAAO,MAAM,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAkB,MAAM,SAAS,CAAA;AAYnD,eAAO,MAAM,IAAI,EAAE,IA6HlB,CAAA"}
|
package/dist/find.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { flattenWhereToOperators } from 'payload';
|
|
2
2
|
import { buildSortParam } from './queries/buildSortParam.js';
|
|
3
3
|
import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
|
|
4
4
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
export const find = async function find({ collection, joins = {}, limit = 0, locale, page, pagination, req = {}, select, sort: sortArg, where }) {
|
|
5
|
+
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
|
|
6
|
+
import { withSession } from './withSession.js';
|
|
7
|
+
export const find = async function find({ collection, joins = {}, limit = 0, locale, page, pagination, projection, req = {}, select, sort: sortArg, where }) {
|
|
9
8
|
const Model = this.collections[collection];
|
|
10
9
|
const collectionConfig = this.payload.collections[collection].config;
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const options = await withSession(this, req);
|
|
11
|
+
let hasNearConstraint = false;
|
|
12
|
+
if (where) {
|
|
13
|
+
const constraints = flattenWhereToOperators(where);
|
|
14
|
+
hasNearConstraint = constraints.some((prop)=>Object.keys(prop).some((key)=>key === 'near'));
|
|
15
|
+
}
|
|
14
16
|
let sort;
|
|
15
17
|
if (!hasNearConstraint) {
|
|
16
18
|
sort = buildSortParam({
|
|
17
19
|
config: this.payload.config,
|
|
18
|
-
fields,
|
|
20
|
+
fields: collectionConfig.flattenedFields,
|
|
19
21
|
locale,
|
|
20
22
|
sort: sortArg || collectionConfig.defaultSort,
|
|
21
23
|
timestamps: true
|
|
@@ -24,49 +26,80 @@ export const find = async function find({ collection, joins = {}, limit = 0, loc
|
|
|
24
26
|
const query = await Model.buildQuery({
|
|
25
27
|
locale,
|
|
26
28
|
payload: this.payload,
|
|
27
|
-
session,
|
|
28
29
|
where
|
|
29
30
|
});
|
|
30
31
|
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
|
|
31
32
|
const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
37
|
-
const collation = this.collation ? {
|
|
38
|
-
locale: locale && locale !== 'all' && locale !== '*' ? locale : 'en',
|
|
39
|
-
...this.collation
|
|
40
|
-
} : undefined;
|
|
41
|
-
const joinAgreggation = await buildJoinAggregation({
|
|
42
|
-
adapter: this,
|
|
43
|
-
collection,
|
|
44
|
-
collectionConfig,
|
|
45
|
-
joins,
|
|
46
|
-
locale,
|
|
47
|
-
session
|
|
48
|
-
});
|
|
49
|
-
const result = await findMany({
|
|
50
|
-
adapter: this,
|
|
51
|
-
collation,
|
|
52
|
-
collection: Model.collection,
|
|
53
|
-
joinAgreggation,
|
|
54
|
-
limit,
|
|
33
|
+
const paginationOptions = {
|
|
34
|
+
lean: true,
|
|
35
|
+
leanWithId: true,
|
|
36
|
+
options,
|
|
55
37
|
page,
|
|
56
38
|
pagination,
|
|
57
39
|
projection,
|
|
58
|
-
query,
|
|
59
|
-
session,
|
|
60
40
|
sort,
|
|
61
41
|
useEstimatedCount
|
|
62
|
-
}
|
|
63
|
-
|
|
42
|
+
};
|
|
43
|
+
if (select) {
|
|
44
|
+
paginationOptions.projection = buildProjectionFromSelect({
|
|
45
|
+
adapter: this,
|
|
46
|
+
fields: collectionConfig.flattenedFields,
|
|
47
|
+
select
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (this.collation) {
|
|
51
|
+
const defaultLocale = 'en';
|
|
52
|
+
paginationOptions.collation = {
|
|
53
|
+
locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
|
|
54
|
+
...this.collation
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
|
|
58
|
+
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
|
|
59
|
+
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
|
|
60
|
+
// which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses
|
|
61
|
+
// the correct indexed field
|
|
62
|
+
paginationOptions.useCustomCountFn = ()=>{
|
|
63
|
+
return Promise.resolve(Model.countDocuments(query, {
|
|
64
|
+
...options,
|
|
65
|
+
hint: {
|
|
66
|
+
_id: 1
|
|
67
|
+
}
|
|
68
|
+
}));
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (limit >= 0) {
|
|
72
|
+
paginationOptions.limit = limit;
|
|
73
|
+
// limit must also be set here, it's ignored when pagination is false
|
|
74
|
+
paginationOptions.options.limit = limit;
|
|
75
|
+
// Disable pagination if limit is 0
|
|
76
|
+
if (limit === 0) {
|
|
77
|
+
paginationOptions.pagination = false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
let result;
|
|
81
|
+
const aggregate = await buildJoinAggregation({
|
|
64
82
|
adapter: this,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
83
|
+
collection,
|
|
84
|
+
collectionConfig,
|
|
85
|
+
joins,
|
|
86
|
+
locale,
|
|
87
|
+
query
|
|
68
88
|
});
|
|
69
|
-
|
|
89
|
+
// build join aggregation
|
|
90
|
+
if (aggregate) {
|
|
91
|
+
result = await Model.aggregatePaginate(Model.aggregate(aggregate), paginationOptions);
|
|
92
|
+
} else {
|
|
93
|
+
result = await Model.paginate(query, paginationOptions);
|
|
94
|
+
}
|
|
95
|
+
const docs = JSON.parse(JSON.stringify(result.docs));
|
|
96
|
+
return {
|
|
97
|
+
...result,
|
|
98
|
+
docs: docs.map((doc)=>{
|
|
99
|
+
doc.id = doc._id;
|
|
100
|
+
return sanitizeInternalFields(doc);
|
|
101
|
+
})
|
|
102
|
+
};
|
|
70
103
|
};
|
|
71
104
|
|
|
72
105
|
//# sourceMappingURL=find.js.map
|
package/dist/find.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Find, PayloadRequest } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const find: Find = async function find(\n this: MongooseAdapter,\n {\n collection,\n joins = {},\n limit = 0,\n locale,\n page,\n pagination,\n projection,\n req = {} as PayloadRequest,\n select,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.collections[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = await withSession(this, req)\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 let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\n }\n\n if (select) {\n paginationOptions.projection = buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n })\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n locale,\n query,\n })\n // build join aggregation\n if (aggregate) {\n result = await Model.aggregatePaginate(Model.aggregate(aggregate), paginationOptions)\n } else {\n result = await Model.paginate(query, paginationOptions)\n }\n\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["flattenWhereToOperators","buildSortParam","buildJoinAggregation","buildProjectionFromSelect","sanitizeInternalFields","withSession","find","collection","joins","limit","locale","page","pagination","projection","req","select","sort","sortArg","where","Model","collections","collectionConfig","payload","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","flattenedFields","defaultSort","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","lean","leanWithId","adapter","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","aggregatePaginate","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,oBAAoB,QAA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AC,CAACC;YACdA,IAAIC,EAAE,GAAGD,IAAIV,GAAG;YAChB,OAAOhD,uBAAuB0D;QAChC;IACF;AACF,EAAC"}
|
package/dist/findGlobal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,SAAS,CAAA;AAUzD,eAAO,MAAM,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,SAAS,CAAA;AAUzD,eAAO,MAAM,UAAU,EAAE,UAoCxB,CAAA"}
|
package/dist/findGlobal.js
CHANGED
|
@@ -1,39 +1,38 @@
|
|
|
1
1
|
import { combineQueries } from 'payload';
|
|
2
|
-
import { getSession } from './getSession.js';
|
|
3
2
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
4
|
-
import {
|
|
3
|
+
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
|
|
4
|
+
import { withSession } from './withSession.js';
|
|
5
5
|
export const findGlobal = async function findGlobal({ slug, locale, req = {}, select, where }) {
|
|
6
6
|
const Model = this.globals;
|
|
7
|
-
const
|
|
7
|
+
const options = {
|
|
8
|
+
...await withSession(this, req),
|
|
9
|
+
lean: true,
|
|
10
|
+
select: buildProjectionFromSelect({
|
|
11
|
+
adapter: this,
|
|
12
|
+
fields: this.payload.globals.config.find((each)=>each.slug === slug).flattenedFields,
|
|
13
|
+
select
|
|
14
|
+
})
|
|
15
|
+
};
|
|
8
16
|
const query = await Model.buildQuery({
|
|
9
17
|
globalSlug: slug,
|
|
10
18
|
locale,
|
|
11
19
|
payload: this.payload,
|
|
12
|
-
session,
|
|
13
20
|
where: combineQueries({
|
|
14
21
|
globalType: {
|
|
15
22
|
equals: slug
|
|
16
23
|
}
|
|
17
24
|
}, where)
|
|
18
25
|
});
|
|
19
|
-
|
|
20
|
-
const doc = await Model.collection.findOne(query, {
|
|
21
|
-
projection: buildProjectionFromSelect({
|
|
22
|
-
adapter: this,
|
|
23
|
-
fields,
|
|
24
|
-
select
|
|
25
|
-
}),
|
|
26
|
-
session: await getSession(this, req)
|
|
27
|
-
});
|
|
26
|
+
let doc = await Model.findOne(query, {}, options);
|
|
28
27
|
if (!doc) {
|
|
29
28
|
return null;
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
if (doc._id) {
|
|
31
|
+
doc.id = doc._id;
|
|
32
|
+
delete doc._id;
|
|
33
|
+
}
|
|
34
|
+
doc = JSON.parse(JSON.stringify(doc));
|
|
35
|
+
doc = sanitizeInternalFields(doc);
|
|
37
36
|
return doc;
|
|
38
37
|
};
|
|
39
38
|
|
package/dist/findGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal, PayloadRequest } from 'payload'\n\nimport { combineQueries } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal, PayloadRequest } from 'payload'\n\nimport { combineQueries } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: MongooseAdapter,\n { slug, locale, req = {} as PayloadRequest, select, where },\n) {\n const Model = this.globals\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n select: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.globals.config.find((each) => each.slug === slug).flattenedFields,\n select,\n }),\n }\n\n const query = await Model.buildQuery({\n globalSlug: slug,\n locale,\n payload: this.payload,\n where: combineQueries({ globalType: { equals: slug } }, where),\n })\n\n let doc = (await Model.findOne(query, {}, options)) as any\n\n if (!doc) {\n return null\n }\n if (doc._id) {\n doc.id = doc._id\n delete doc._id\n }\n\n doc = JSON.parse(JSON.stringify(doc))\n doc = sanitizeInternalFields(doc)\n\n return doc\n}\n"],"names":["combineQueries","buildProjectionFromSelect","sanitizeInternalFields","withSession","findGlobal","slug","locale","req","select","where","Model","globals","options","lean","adapter","fields","payload","config","find","each","flattenedFields","query","buildQuery","globalSlug","globalType","equals","doc","findOne","_id","id","JSON","parse","stringify"],"mappings":"AAEA,SAASA,cAAc,QAAQ,UAAS;AAIxC,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAE3D,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAU;QACd,GAAI,MAAMT,YAAY,IAAI,EAAEI,IAAI;QAChCM,MAAM;QACNL,QAAQP,0BAA0B;YAChCa,SAAS,IAAI;YACbC,QAAQ,IAAI,CAACC,OAAO,CAACL,OAAO,CAACM,MAAM,CAACC,IAAI,CAAC,CAACC,OAASA,KAAKd,IAAI,KAAKA,MAAMe,eAAe;YACtFZ;QACF;IACF;IAEA,MAAMa,QAAQ,MAAMX,MAAMY,UAAU,CAAC;QACnCC,YAAYlB;QACZC;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBP,OAAOT,eAAe;YAAEwB,YAAY;gBAAEC,QAAQpB;YAAK;QAAE,GAAGI;IAC1D;IAEA,IAAIiB,MAAO,MAAMhB,MAAMiB,OAAO,CAACN,OAAO,CAAC,GAAGT;IAE1C,IAAI,CAACc,KAAK;QACR,OAAO;IACT;IACA,IAAIA,IAAIE,GAAG,EAAE;QACXF,IAAIG,EAAE,GAAGH,IAAIE,GAAG;QAChB,OAAOF,IAAIE,GAAG;IAChB;IAEAF,MAAMI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAChCA,MAAMxB,uBAAuBwB;IAE7B,OAAOA;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,SAAS,CAAA;AAWjE,eAAO,MAAM,kBAAkB,EAAE,kBA8GhC,CAAA"}
|