@payloadcms/db-mongodb 4.0.0-internal.ea6e8f8 → 4.0.0-internal.ee5d8bd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +0 -1
- package/dist/connect.js.map +1 -1
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +4 -33
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts.map +1 -1
- package/dist/countGlobalVersions.js +0 -1
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +4 -36
- package/dist/countVersions.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +0 -22
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +3 -16
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +0 -1
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +1 -20
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +0 -1
- package/dist/deleteVersions.js.map +1 -1
- package/dist/exports/migration-utils.d.ts +0 -1
- package/dist/exports/migration-utils.d.ts.map +1 -1
- package/dist/exports/migration-utils.js +0 -1
- package/dist/exports/migration-utils.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +8 -44
- package/dist/find.js.map +1 -1
- package/dist/findDistinct.d.ts.map +1 -1
- package/dist/findDistinct.js +11 -70
- package/dist/findDistinct.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +5 -34
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +2 -10
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +5 -43
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +5 -49
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +1 -30
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +10 -30
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/migrateSizesToVariants.js.map +1 -1
- package/dist/queries/buildAndOrConditions.d.ts +2 -4
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +1 -3
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +2 -4
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +1 -3
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts +2 -4
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +44 -175
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/getBuildQueryPlugin.d.ts +1 -3
- package/dist/queries/getBuildQueryPlugin.d.ts.map +1 -1
- package/dist/queries/getBuildQueryPlugin.js +1 -3
- package/dist/queries/getBuildQueryPlugin.js.map +1 -1
- package/dist/queries/parseParams.d.ts +2 -4
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +1 -5
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +7 -38
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +7 -55
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
- package/dist/transactions/rollbackTransaction.js +9 -10
- package/dist/transactions/rollbackTransaction.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +7 -87
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +0 -1
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateMany.d.ts.map +1 -1
- package/dist/updateMany.js +1 -3
- package/dist/updateMany.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +2 -28
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +0 -1
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/aggregatePaginate.d.ts +1 -2
- package/dist/utilities/aggregatePaginate.d.ts.map +1 -1
- package/dist/utilities/aggregatePaginate.js +4 -18
- package/dist/utilities/aggregatePaginate.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.d.ts +2 -4
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +23 -118
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/resolveJoins.d.ts +2 -6
- package/dist/utilities/resolveJoins.d.ts.map +1 -1
- package/dist/utilities/resolveJoins.js +26 -114
- package/dist/utilities/resolveJoins.js.map +1 -1
- package/package.json +16 -19
- package/dist/deleteBranchGlobal.d.ts +0 -10
- package/dist/deleteBranchGlobal.d.ts.map +0 -1
- package/dist/deleteBranchGlobal.js +0 -22
- package/dist/deleteBranchGlobal.js.map +0 -1
- package/dist/predefinedMigrations/branching.d.ts +0 -4
- package/dist/predefinedMigrations/branching.d.ts.map +0 -1
- package/dist/predefinedMigrations/branching.js +0 -9
- package/dist/predefinedMigrations/branching.js.map +0 -1
- package/dist/predefinedMigrations/migrateBranching.d.ts +0 -15
- package/dist/predefinedMigrations/migrateBranching.d.ts.map +0 -1
- package/dist/predefinedMigrations/migrateBranching.js +0 -88
- package/dist/predefinedMigrations/migrateBranching.js.map +0 -1
- package/dist/queries/buildBranchVisibility.d.ts +0 -11
- package/dist/queries/buildBranchVisibility.d.ts.map +0 -1
- package/dist/queries/buildBranchVisibility.js +0 -204
- package/dist/queries/buildBranchVisibility.js.map +0 -1
- package/dist/upsertBranchGlobalChange.d.ts +0 -3
- package/dist/upsertBranchGlobalChange.d.ts.map +0 -1
- package/dist/upsertBranchGlobalChange.js +0 -28
- package/dist/upsertBranchGlobalChange.js.map +0 -1
package/dist/connect.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAa,MAAM,SAAS,CAAA;AAOjD,eAAO,MAAM,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAa,MAAM,SAAS,CAAA;AAOjD,eAAO,MAAM,OAAO,EAAE,OAkHrB,CAAA"}
|
package/dist/connect.js
CHANGED
|
@@ -69,7 +69,6 @@ export const connect = async function connect(options = {
|
|
|
69
69
|
this.collections[collection.slug],
|
|
70
70
|
this.versions[collection.slug]
|
|
71
71
|
]),
|
|
72
|
-
this.globals,
|
|
73
72
|
...this.payload.config.globals.map((global)=>this.versions[global.slug])
|
|
74
73
|
].map(async (model)=>{
|
|
75
74
|
await model?.ensureIndexes();
|
package/dist/connect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { ConnectOptions } from 'mongoose'\nimport type { Connect, Migration } from 'payload'\n\nimport mongoose from 'mongoose'\nimport { defaultBeginTransaction } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const connect: Connect = async function connect(\n this: MongooseAdapter,\n options = {\n hotReload: false,\n },\n) {\n const { hotReload } = options\n\n if (this.url === false) {\n return\n }\n\n if (typeof this.url !== 'string') {\n throw new Error('Error: missing MongoDB connection URL.')\n }\n\n const urlToConnect = this.url\n\n const connectionOptions: ConnectOptions = {\n autoIndex: true,\n ...this.connectOptions,\n }\n\n if (hotReload) {\n connectionOptions.autoIndex = false\n }\n\n try {\n if (!this.connection) {\n this.connection = await mongoose.createConnection(urlToConnect, connectionOptions).asPromise()\n if (this.afterCreateConnection) {\n await this.afterCreateConnection(this)\n }\n }\n\n await this.connection.openUri(urlToConnect, connectionOptions)\n\n if (this.afterOpenConnection) {\n await this.afterOpenConnection(this)\n }\n\n if (this.useAlternativeDropDatabase) {\n if (this.connection.db) {\n // Firestore doesn't support dropDatabase, so we monkey patch\n // dropDatabase to delete all documents from all collections instead\n this.connection.db.dropDatabase = async function (): Promise<boolean> {\n const existingCollections = await this.listCollections().toArray()\n await Promise.all(\n existingCollections.map(async (collectionInfo) => {\n const collection = this.collection(collectionInfo.name)\n await collection.deleteMany({})\n }),\n )\n return true\n }\n this.connection.dropDatabase = async function () {\n await this.db?.dropDatabase()\n }\n }\n }\n\n // If we are running a replica set with MongoDB Memory Server,\n // wait until the replica set elects a primary before proceeding\n if (this.mongoMemoryServer) {\n this.payload.logger.info(\n 'Waiting for MongoDB Memory Server replica set to elect a primary...',\n )\n await new Promise((resolve) => setTimeout(resolve, 2000))\n }\n\n if (!this.connection.getClient().options.replicaSet) {\n this.transactionOptions = false\n this.beginTransaction = defaultBeginTransaction()\n }\n\n if (!hotReload) {\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info('---- DROPPING DATABASE ----')\n await this.connection.dropDatabase()\n\n this.payload.logger.info('---- DROPPED DATABASE ----')\n }\n }\n\n if (this.ensureIndexes) {\n await Promise.all(\n [\n ...this.payload.config.collections.flatMap((collection) => [\n this.collections[collection.slug],\n this.versions[collection.slug],\n ]),\n
|
|
1
|
+
{"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { ConnectOptions } from 'mongoose'\nimport type { Connect, Migration } from 'payload'\n\nimport mongoose from 'mongoose'\nimport { defaultBeginTransaction } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const connect: Connect = async function connect(\n this: MongooseAdapter,\n options = {\n hotReload: false,\n },\n) {\n const { hotReload } = options\n\n if (this.url === false) {\n return\n }\n\n if (typeof this.url !== 'string') {\n throw new Error('Error: missing MongoDB connection URL.')\n }\n\n const urlToConnect = this.url\n\n const connectionOptions: ConnectOptions = {\n autoIndex: true,\n ...this.connectOptions,\n }\n\n if (hotReload) {\n connectionOptions.autoIndex = false\n }\n\n try {\n if (!this.connection) {\n this.connection = await mongoose.createConnection(urlToConnect, connectionOptions).asPromise()\n if (this.afterCreateConnection) {\n await this.afterCreateConnection(this)\n }\n }\n\n await this.connection.openUri(urlToConnect, connectionOptions)\n\n if (this.afterOpenConnection) {\n await this.afterOpenConnection(this)\n }\n\n if (this.useAlternativeDropDatabase) {\n if (this.connection.db) {\n // Firestore doesn't support dropDatabase, so we monkey patch\n // dropDatabase to delete all documents from all collections instead\n this.connection.db.dropDatabase = async function (): Promise<boolean> {\n const existingCollections = await this.listCollections().toArray()\n await Promise.all(\n existingCollections.map(async (collectionInfo) => {\n const collection = this.collection(collectionInfo.name)\n await collection.deleteMany({})\n }),\n )\n return true\n }\n this.connection.dropDatabase = async function () {\n await this.db?.dropDatabase()\n }\n }\n }\n\n // If we are running a replica set with MongoDB Memory Server,\n // wait until the replica set elects a primary before proceeding\n if (this.mongoMemoryServer) {\n this.payload.logger.info(\n 'Waiting for MongoDB Memory Server replica set to elect a primary...',\n )\n await new Promise((resolve) => setTimeout(resolve, 2000))\n }\n\n if (!this.connection.getClient().options.replicaSet) {\n this.transactionOptions = false\n this.beginTransaction = defaultBeginTransaction()\n }\n\n if (!hotReload) {\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info('---- DROPPING DATABASE ----')\n await this.connection.dropDatabase()\n\n this.payload.logger.info('---- DROPPED DATABASE ----')\n }\n }\n\n if (this.ensureIndexes) {\n await Promise.all(\n [\n ...this.payload.config.collections.flatMap((collection) => [\n this.collections[collection.slug],\n this.versions[collection.slug],\n ]),\n ...this.payload.config.globals.map((global) => this.versions[global.slug]),\n ].map(async (model) => {\n await model?.ensureIndexes()\n }),\n )\n }\n\n if (process.env.NODE_ENV === 'production' && this.prodMigrations) {\n await this.migrate({ migrations: this.prodMigrations as unknown as Migration[] })\n }\n } catch (err) {\n let msg = `Error: cannot connect to MongoDB.`\n\n if (typeof err === 'object' && err && 'message' in err && typeof err.message === 'string') {\n msg = `${msg} Details: ${err.message}`\n }\n\n this.payload.logger.error({\n err,\n msg,\n })\n throw new Error(`Error: cannot connect to MongoDB: ${msg}`)\n }\n}\n"],"names":["mongoose","defaultBeginTransaction","connect","options","hotReload","url","Error","urlToConnect","connectionOptions","autoIndex","connectOptions","connection","createConnection","asPromise","afterCreateConnection","openUri","afterOpenConnection","useAlternativeDropDatabase","db","dropDatabase","existingCollections","listCollections","toArray","Promise","all","map","collectionInfo","collection","name","deleteMany","mongoMemoryServer","payload","logger","info","resolve","setTimeout","getClient","replicaSet","transactionOptions","beginTransaction","process","env","PAYLOAD_DROP_DATABASE","ensureIndexes","config","collections","flatMap","slug","versions","globals","global","model","NODE_ENV","prodMigrations","migrate","migrations","err","msg","message","error"],"mappings":"AAGA,OAAOA,cAAc,WAAU;AAC/B,SAASC,uBAAuB,QAAQ,UAAS;AAIjD,OAAO,MAAMC,UAAmB,eAAeA,QAE7CC,UAAU;IACRC,WAAW;AACb,CAAC;IAED,MAAM,EAAEA,SAAS,EAAE,GAAGD;IAEtB,IAAI,IAAI,CAACE,GAAG,KAAK,OAAO;QACtB;IACF;IAEA,IAAI,OAAO,IAAI,CAACA,GAAG,KAAK,UAAU;QAChC,MAAM,IAAIC,MAAM;IAClB;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AAIE,OAAO,EAAE;QACxC;QAEA,IAAI,CAAC3B,OAAO,CAACC,MAAM,CAAC2B,KAAK,CAAC;YACxBH;YACAC;QACF;QACA,MAAM,IAAInD,MAAM,CAAC,kCAAkC,EAAEmD,KAAK;IAC5D;AACF,EAAC"}
|
package/dist/count.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAUpC,eAAO,MAAM,KAAK,EAAE,KA2DnB,CAAA"}
|
package/dist/count.js
CHANGED
|
@@ -1,29 +1,12 @@
|
|
|
1
|
-
import { flattenWhereToOperators
|
|
2
|
-
import { buildBranchVisibilityStages } from './queries/buildBranchVisibility.js';
|
|
1
|
+
import { flattenWhereToOperators } from 'payload';
|
|
3
2
|
import { buildQuery } from './queries/buildQuery.js';
|
|
4
3
|
import { getCollection } from './utilities/getEntity.js';
|
|
5
4
|
import { getSession } from './utilities/getSession.js';
|
|
6
|
-
export const count = async function count({
|
|
5
|
+
export const count = async function count({ collection: collectionSlug, locale, req, where = {} }) {
|
|
7
6
|
const { collectionConfig, Model } = getCollection({
|
|
8
7
|
adapter: this,
|
|
9
8
|
collectionSlug
|
|
10
9
|
});
|
|
11
|
-
const branchReadState = resolveBranchReadState({
|
|
12
|
-
branch,
|
|
13
|
-
collectionSlug,
|
|
14
|
-
req
|
|
15
|
-
});
|
|
16
|
-
where = branchReadState.useBranching ? rewriteBranchIDs(where) ?? {} : await resolveBranchQuery({
|
|
17
|
-
branch,
|
|
18
|
-
collectionSlug,
|
|
19
|
-
req,
|
|
20
|
-
where
|
|
21
|
-
}) ?? {};
|
|
22
|
-
const branchVisibility = branchReadState.useBranching ? buildBranchVisibilityStages({
|
|
23
|
-
adapter: this,
|
|
24
|
-
branch: branchReadState.branch,
|
|
25
|
-
collectionSlug
|
|
26
|
-
}) : [];
|
|
27
10
|
let hasNearConstraint = false;
|
|
28
11
|
if (where) {
|
|
29
12
|
const constraints = flattenWhereToOperators(where);
|
|
@@ -31,15 +14,13 @@ export const count = async function count({ branch, collection: collectionSlug,
|
|
|
31
14
|
}
|
|
32
15
|
const query = await buildQuery({
|
|
33
16
|
adapter: this,
|
|
34
|
-
branch,
|
|
35
17
|
collectionSlug,
|
|
36
18
|
fields: collectionConfig.flattenedFields,
|
|
37
19
|
locale,
|
|
38
|
-
req,
|
|
39
20
|
where
|
|
40
21
|
});
|
|
41
22
|
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
|
|
42
|
-
const useEstimatedCount =
|
|
23
|
+
const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
|
|
43
24
|
const options = {
|
|
44
25
|
session: await getSession(this, req)
|
|
45
26
|
};
|
|
@@ -61,17 +42,7 @@ export const count = async function count({ branch, collection: collectionSlug,
|
|
|
61
42
|
};
|
|
62
43
|
}
|
|
63
44
|
let result;
|
|
64
|
-
if (
|
|
65
|
-
result = await Model.aggregate([
|
|
66
|
-
{
|
|
67
|
-
$match: query
|
|
68
|
-
},
|
|
69
|
-
...branchVisibility,
|
|
70
|
-
{
|
|
71
|
-
$count: 'count'
|
|
72
|
-
}
|
|
73
|
-
], options).then((rows)=>rows[0]?.count ?? 0);
|
|
74
|
-
} else if (useEstimatedCount) {
|
|
45
|
+
if (useEstimatedCount) {
|
|
75
46
|
result = await Model.estimatedDocumentCount({
|
|
76
47
|
session: options.session
|
|
77
48
|
});
|
package/dist/count.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/count.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { Count } from 'payload'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/count.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { Count } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const count: Count = async function count(\n this: MongooseAdapter,\n { collection: collectionSlug, locale, req, where = {} },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\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\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n options.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 options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["flattenWhereToOperators","buildQuery","getCollection","getSession","count","collection","collectionSlug","locale","req","where","collectionConfig","Model","adapter","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","flattenedFields","useEstimatedCount","length","options","session","collation","localizationConfig","payload","config","localization","defaultLocale","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,QAAe,eAAeA,MAEzC,EAAEC,YAAYC,cAAc,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAEvD,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGT,cAAc;QAAEU,SAAS,IAAI;QAAEN;IAAe;IAElF,IAAIO,oBAAoB;IAExB,IAAIJ,OAAO;QACT,MAAMK,cAAcd,wBAAwBS;QAC5CI,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMnB,WAAW;QAC7BW,SAAS,IAAI;QACbN;QACAe,QAAQX,iBAAiBY,eAAe;QACxCf;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMc,oBAAoBV,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK;IAEvF,MAAMC,UAAwB;QAC5BC,SAAS,MAAMvB,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAI,IAAI,CAACmB,SAAS,EAAE;QAClB,MAAMC,qBAAqB,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,YAAY;QAC3D,MAAMC,gBACJ,AAAC,OAAOJ,uBAAuB,YAAYA,oBAAoBI,iBAAkB;QAEnFP,QAAQE,SAAS,GAAG;YAClBpB,QAAQA,UAAUA,WAAW,SAASA,WAAW,MAAMA,SAASyB;YAChE,GAAG,IAAI,CAACL,SAAS;QACnB;IACF;IAEA,IAAI,CAACJ,qBAAqBN,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACS,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BR,QAAQS,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIb,mBAAmB;QACrBa,SAAS,MAAMzB,MAAM0B,sBAAsB,CAAC;YAAEX,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLU,SAAS,MAAMzB,MAAM2B,cAAc,CAAClB,OAAOK;IAC7C;IAEA,OAAO;QACLc,WAAWH;IACb;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"countGlobalVersions.d.ts","sourceRoot":"","sources":["../src/countGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAUlD,eAAO,MAAM,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"countGlobalVersions.d.ts","sourceRoot":"","sources":["../src/countGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAUlD,eAAO,MAAM,mBAAmB,EAAE,mBA0DjC,CAAA"}
|
|
@@ -17,7 +17,6 @@ export const countGlobalVersions = async function countGlobalVersions({ global:
|
|
|
17
17
|
adapter: this,
|
|
18
18
|
fields: buildVersionGlobalFields(this.payload.config, globalConfig, true),
|
|
19
19
|
locale,
|
|
20
|
-
req,
|
|
21
20
|
where
|
|
22
21
|
});
|
|
23
22
|
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/countGlobalVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountGlobalVersions } from 'payload'\n\nimport { buildVersionGlobalFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const countGlobalVersions: CountGlobalVersions = async function countGlobalVersions(\n this: MongooseAdapter,\n { global: globalSlug, locale, req, where = {} },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: buildVersionGlobalFields(this.payload.config, globalConfig, true),\n locale,\n
|
|
1
|
+
{"version":3,"sources":["../src/countGlobalVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountGlobalVersions } from 'payload'\n\nimport { buildVersionGlobalFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const countGlobalVersions: CountGlobalVersions = async function countGlobalVersions(\n this: MongooseAdapter,\n { global: globalSlug, locale, req, where = {} },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: buildVersionGlobalFields(this.payload.config, globalConfig, true),\n locale,\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\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n options.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 options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["buildVersionGlobalFields","flattenWhereToOperators","buildQuery","getGlobal","getSession","countGlobalVersions","global","globalSlug","locale","req","where","globalConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","payload","config","useEstimatedCount","length","options","session","collation","localizationConfig","localization","defaultLocale","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,wBAAwB,EAAEC,uBAAuB,QAAQ,UAAS;AAI3E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EAAEC,QAAQC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAE/C,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGT,UAAU;QAAEU,SAAS,IAAI;QAAEN;QAAYO,UAAU;IAAK;IAEtF,IAAIC,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcf,wBAAwBS;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MA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CAAA;
|
|
1
|
+
{"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../src/countVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAU5C,eAAO,MAAM,aAAa,EAAE,aA8D3B,CAAA"}
|
package/dist/countVersions.js
CHANGED
|
@@ -1,33 +1,13 @@
|
|
|
1
|
-
import { buildVersionCollectionFields, flattenWhereToOperators
|
|
2
|
-
import { buildBranchVisibilityStages } from './queries/buildBranchVisibility.js';
|
|
1
|
+
import { buildVersionCollectionFields, flattenWhereToOperators } from 'payload';
|
|
3
2
|
import { buildQuery } from './queries/buildQuery.js';
|
|
4
3
|
import { getCollection } from './utilities/getEntity.js';
|
|
5
4
|
import { getSession } from './utilities/getSession.js';
|
|
6
|
-
export const countVersions = async function countVersions({
|
|
5
|
+
export const countVersions = async function countVersions({ collection: collectionSlug, locale, req, where = {} }) {
|
|
7
6
|
const { collectionConfig, Model } = getCollection({
|
|
8
7
|
adapter: this,
|
|
9
8
|
collectionSlug,
|
|
10
9
|
versions: true
|
|
11
10
|
});
|
|
12
|
-
const branchReadState = resolveBranchReadState({
|
|
13
|
-
branch,
|
|
14
|
-
collectionSlug,
|
|
15
|
-
req
|
|
16
|
-
});
|
|
17
|
-
// Shares the list's predicate so the count in the Versions tab can never
|
|
18
|
-
// disagree with the rows the Versions view actually renders.
|
|
19
|
-
where = branchReadState.useBranching ? rewriteBranchVersionParents(where) ?? {} : await resolveBranchVersionHistoryQuery({
|
|
20
|
-
branch,
|
|
21
|
-
collectionSlug,
|
|
22
|
-
req,
|
|
23
|
-
where
|
|
24
|
-
}) ?? {};
|
|
25
|
-
const branchVisibility = branchReadState.useBranching ? buildBranchVisibilityStages({
|
|
26
|
-
adapter: this,
|
|
27
|
-
branch: branchReadState.branch,
|
|
28
|
-
collectionSlug,
|
|
29
|
-
mode: 'history'
|
|
30
|
-
}) : [];
|
|
31
11
|
let hasNearConstraint = false;
|
|
32
12
|
if (where) {
|
|
33
13
|
const constraints = flattenWhereToOperators(where);
|
|
@@ -35,14 +15,12 @@ export const countVersions = async function countVersions({ branch, collection:
|
|
|
35
15
|
}
|
|
36
16
|
const query = await buildQuery({
|
|
37
17
|
adapter: this,
|
|
38
|
-
branch,
|
|
39
18
|
fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),
|
|
40
19
|
locale,
|
|
41
|
-
req,
|
|
42
20
|
where
|
|
43
21
|
});
|
|
44
22
|
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
|
|
45
|
-
const useEstimatedCount =
|
|
23
|
+
const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
|
|
46
24
|
const options = {
|
|
47
25
|
session: await getSession(this, req)
|
|
48
26
|
};
|
|
@@ -64,17 +42,7 @@ export const countVersions = async function countVersions({ branch, collection:
|
|
|
64
42
|
};
|
|
65
43
|
}
|
|
66
44
|
let result;
|
|
67
|
-
if (
|
|
68
|
-
result = await Model.aggregate([
|
|
69
|
-
{
|
|
70
|
-
$match: query
|
|
71
|
-
},
|
|
72
|
-
...branchVisibility,
|
|
73
|
-
{
|
|
74
|
-
$count: 'count'
|
|
75
|
-
}
|
|
76
|
-
], options).then((rows)=>rows[0]?.count ?? 0);
|
|
77
|
-
} else if (useEstimatedCount) {
|
|
45
|
+
if (useEstimatedCount) {
|
|
78
46
|
result = await Model.estimatedDocumentCount({
|
|
79
47
|
session: options.session
|
|
80
48
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/countVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountVersions } from 'payload'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/countVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountVersions } from 'payload'\n\nimport { buildVersionCollectionFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const countVersions: CountVersions = async function countVersions(\n this: MongooseAdapter,\n { collection: collectionSlug, locale, req, where = {} },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),\n locale,\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\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n options.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 options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["buildVersionCollectionFields","flattenWhereToOperators","buildQuery","getCollection","getSession","countVersions","collection","collectionSlug","locale","req","where","collectionConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","payload","config","useEstimatedCount","length","options","session","collation","localizationConfig","localization","defaultLocale","disableIndexHints","hint","_id","result","est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,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK,KAAK,IAAI,CAACO,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BN,QAAQO,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIX,mBAAmB;QACrBW,SAAS,MAAMzB,MAAM0B,sBAAsB,CAAC;YAAET,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLQ,SAAS,MAAMzB,MAAM2B,cAAc,CAACjB,OAAOM;IAC7C;IAEA,OAAO;QACLY,WAAWH;IACb;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAQ5E,eAAO,MAAM,mBAAmB,EAAE,mBA+EjC,CAAA"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { MAIN_BRANCH, resolveBranch } from 'payload';
|
|
2
1
|
import { buildVersionGlobalFields } from 'payload';
|
|
3
2
|
import { getGlobal } from './utilities/getEntity.js';
|
|
4
3
|
import { getSession } from './utilities/getSession.js';
|
|
@@ -9,9 +8,7 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
|
|
|
9
8
|
globalSlug,
|
|
10
9
|
versions: true
|
|
11
10
|
});
|
|
12
|
-
const versionBranch = req?.payload?.config?.branching?.branchableGlobals?.has(globalSlug) ? resolveBranch(req) : MAIN_BRANCH;
|
|
13
11
|
const data = {
|
|
14
|
-
_branch: versionBranch,
|
|
15
12
|
autosave,
|
|
16
13
|
createdAt,
|
|
17
14
|
latest: true,
|
|
@@ -38,9 +35,6 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
|
|
|
38
35
|
let [doc] = await Model.create([
|
|
39
36
|
data
|
|
40
37
|
], options);
|
|
41
|
-
// Scoped by `_branch`. Unlike collection versions, global versions have no
|
|
42
|
-
// `parent` to separate streams by — every version of a global shares one — so
|
|
43
|
-
// without this an unscoped clear would wipe main's latest flag from a branch.
|
|
44
38
|
await Model.updateMany({
|
|
45
39
|
$and: [
|
|
46
40
|
{
|
|
@@ -52,22 +46,6 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
|
|
|
52
46
|
latest: {
|
|
53
47
|
$eq: true
|
|
54
48
|
}
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
$or: [
|
|
58
|
-
{
|
|
59
|
-
_branch: {
|
|
60
|
-
$eq: versionBranch
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
...versionBranch === MAIN_BRANCH ? [
|
|
64
|
-
{
|
|
65
|
-
_branch: {
|
|
66
|
-
$exists: false
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
] : []
|
|
70
|
-
]
|
|
71
49
|
}
|
|
72
50
|
]
|
|
73
51
|
}, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import { buildVersionGlobalFields, type CreateGlobalVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const createGlobalVersion: CreateGlobalVersion = async function createGlobalVersion(\n this: MongooseAdapter,\n {\n autosave,\n createdAt,\n globalSlug,\n publishedLocale,\n req,\n returning,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n\n const data = {\n autosave,\n createdAt,\n latest: true,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n }\n if (!data.createdAt) {\n data.createdAt = new Date().toISOString()\n }\n\n const fields = buildVersionGlobalFields(this.payload.config, globalConfig)\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const options = {\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n let [doc] = await Model.create([data], options)\n\n await Model.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n {\n latest: {\n $eq: true,\n },\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\n )\n\n if (returning === false) {\n return null\n }\n\n doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["buildVersionGlobalFields","getGlobal","getSession","transform","createGlobalVersion","autosave","createdAt","globalSlug","publishedLocale","req","returning","snapshot","updatedAt","versionData","globalConfig","Model","adapter","versions","data","latest","version","Date","toISOString","fields","payload","config","operation","options","session","timestamps","doc","create","updateMany","$and","_id","$ne","$eq","$unset","toObject"],"mappings":"AAAA,SAASA,wBAAwB,QAAkC,UAAS;AAI5E,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EACEC,QAAQ,EACRC,SAAS,EACTC,UAAU,EACVC,eAAe,EACfC,GAAG,EACHC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACZ;IAED,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGd,UAAU;QAAEe,SAAS,IAAI;QAAET;QAAYU,UAAU;IAAK;IAEtF,MAAMC,OAAO;QACXb;QACAC;QACAa,QAAQ;QACRX;QACAG;QACAC;QACAQ,SAASP;IACX;IACA,IAAI,CAACK,KAAKZ,SAAS,EAAE;QACnBY,KAAKZ,SAAS,GAAG,IAAIe,OAAOC,WAAW;IACzC;IAEA,MAAMC,SAASvB,yBAAyB,IAAI,CAACwB,OAAO,CAACC,MAAM,EAAEX;IAE7DX,UAAU;QACRa,SAAS,IAAI;QACbE;QACAK;QACAG,WAAW;IACb;IAEA,MAAMC,UAAU;QACdC,SAAS,MAAM1B,WAAW,IAAI,EAAEO;QAChC,uDAAuD;QACvDoB,YAAY;IACd;IAEA,IAAI,CAACC,IAAI,GAAG,MAAMf,MAAMgB,MAAM,CAAC;QAACb;KAAK,EAAES;IAEvC,MAAMZ,MAAMiB,UAAU,CACpB;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKL,IAAII,GAAG;gBACd;YACF;YACA;gBACEf,QAAQ;oBACNiB,KAAK;gBACP;YACF;SACD;IACH,GACA;QAAEC,QAAQ;YAAElB,QAAQ;QAAE;IAAE,GACxBQ;IAGF,IAAIjB,cAAc,OAAO;QACvB,OAAO;IACT;IAEAoB,MAAMA,IAAIQ,QAAQ;IAElBnC,UAAU;QACRa,SAAS,IAAI;QACbE,MAAMY;QACNP;QACAG,WAAW;IACb;IAEA,OAAOI;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createVersion.d.ts","sourceRoot":"","sources":["../src/createVersion.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"createVersion.d.ts","sourceRoot":"","sources":["../src/createVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAQ1E,eAAO,MAAM,aAAa,EAAE,aAqG3B,CAAA"}
|
package/dist/createVersion.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildVersionCollectionFields
|
|
1
|
+
import { buildVersionCollectionFields } from 'payload';
|
|
2
2
|
import { getCollection } from './utilities/getEntity.js';
|
|
3
3
|
import { getSession } from './utilities/getSession.js';
|
|
4
4
|
import { transform } from './utilities/transform.js';
|
|
@@ -8,25 +8,15 @@ export const createVersion = async function createVersion({ autosave, collection
|
|
|
8
8
|
collectionSlug,
|
|
9
9
|
versions: true
|
|
10
10
|
});
|
|
11
|
-
const branched = await resolveBranchVersionParent({
|
|
12
|
-
collectionSlug,
|
|
13
|
-
parent,
|
|
14
|
-
req,
|
|
15
|
-
versionData: versionData
|
|
16
|
-
});
|
|
17
11
|
const data = {
|
|
18
12
|
autosave,
|
|
19
13
|
createdAt,
|
|
20
14
|
latest: true,
|
|
21
|
-
parent
|
|
15
|
+
parent,
|
|
22
16
|
publishedLocale,
|
|
23
17
|
snapshot,
|
|
24
18
|
updatedAt,
|
|
25
|
-
version: versionData
|
|
26
|
-
...branched.versionData._branch ? {
|
|
27
|
-
_branch: branched.versionData._branch,
|
|
28
|
-
_branchParent: branched.versionData._branchParent
|
|
29
|
-
} : {}
|
|
19
|
+
version: versionData
|
|
30
20
|
};
|
|
31
21
|
if (!data.createdAt) {
|
|
32
22
|
data.createdAt = new Date().toISOString();
|
|
@@ -46,9 +36,6 @@ export const createVersion = async function createVersion({ autosave, collection
|
|
|
46
36
|
let [doc] = await Model.create([
|
|
47
37
|
data
|
|
48
38
|
], options);
|
|
49
|
-
// No branch scoping needed here: a branch version's `parent` is the shadow
|
|
50
|
-
// row's own primary key, so main's chain and the branch's chain are already
|
|
51
|
-
// disjoint and `latest` clearing cannot cross between them.
|
|
52
39
|
const parentQuery = {
|
|
53
40
|
$or: [
|
|
54
41
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import { buildVersionCollectionFields, type CreateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.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,\n returning,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n const data = {\n autosave,\n createdAt,\n latest: true,\n parent,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n }\n if (!data.createdAt) {\n data.createdAt = new Date().toISOString()\n }\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const options = {\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n let [doc] = await Model.create([data], options)\n\n const parentQuery = {\n $or: [\n {\n parent: {\n $eq: data.parent,\n },\n },\n ],\n }\n\n await Model.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 updatedAt: {\n $lt: new Date(doc.updatedAt),\n },\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\n )\n\n if (returning === false) {\n return null\n }\n\n doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["buildVersionCollectionFields","getCollection","getSession","transform","createVersion","autosave","collectionSlug","createdAt","parent","publishedLocale","req","returning","snapshot","updatedAt","versionData","collectionConfig","Model","adapter","versions","data","latest","version","Date","toISOString","fields","payload","config","operation","options","session","timestamps","doc","create","parentQuery","$or","$eq","updateMany","$and","_id","$ne","$lt","$unset","toObject"],"mappings":"AAAA,SAASA,4BAA4B,QAA4B,UAAS;AAI1E,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,QAAQ,EACRC,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,eAAe,EACfC,GAAG,EACHC,SAAS,EACTC,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1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAA;AAQzC,eAAO,MAAM,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAA;AAQzC,eAAO,MAAM,UAAU,EAAE,UAkBxB,CAAA"}
|
package/dist/deleteMany.js
CHANGED
package/dist/deleteMany.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteOptions } from 'mongodb'\n\nimport { type DeleteMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: MongooseAdapter,\n { collection: collectionSlug, req, where },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n
|
|
1
|
+
{"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteOptions } from 'mongodb'\n\nimport { type DeleteMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: MongooseAdapter,\n { collection: collectionSlug, req, where },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n where,\n })\n\n const options: DeleteOptions = {\n session: await getSession(this, req),\n }\n\n await Model.deleteMany(query, options)\n}\n"],"names":["buildQuery","getCollection","getSession","deleteMany","collection","collectionSlug","req","where","collectionConfig","Model","adapter","query","fields","flattenedFields","options","session"],"mappings":"AAMA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,YAAYC,cAAc,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAE1C,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGR,cAAc;QAAES,SAAS,IAAI;QAAEL;IAAe;IAElF,MAAMM,QAAQ,MAAMX,WAAW;QAC7BU,SAAS,IAAI;QACbL;QACAO,QAAQJ,iBAAiBK,eAAe;QACxCN;IACF;IAEA,MAAMO,UAAyB;QAC7BC,SAAS,MAAMb,WAAW,IAAI,EAAEI;IAClC;IAEA,MAAMG,MAAMN,UAAU,CAACQ,OAAOG;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":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAUxC,eAAO,MAAM,SAAS,EAAE,SAyCvB,CAAA"}
|
package/dist/deleteOne.js
CHANGED
|
@@ -1,36 +1,17 @@
|
|
|
1
|
-
import { resolveBranchDelete } from 'payload';
|
|
2
1
|
import { buildQuery } from './queries/buildQuery.js';
|
|
3
2
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
4
3
|
import { getCollection } from './utilities/getEntity.js';
|
|
5
4
|
import { getSession } from './utilities/getSession.js';
|
|
6
5
|
import { transform } from './utilities/transform.js';
|
|
7
|
-
export const deleteOne = async function deleteOne({
|
|
6
|
+
export const deleteOne = async function deleteOne({ collection: collectionSlug, req, returning, select, where }) {
|
|
8
7
|
const { collectionConfig, Model } = getCollection({
|
|
9
8
|
adapter: this,
|
|
10
9
|
collectionSlug
|
|
11
10
|
});
|
|
12
|
-
const branchDelete = await resolveBranchDelete({
|
|
13
|
-
branch,
|
|
14
|
-
collectionSlug,
|
|
15
|
-
req,
|
|
16
|
-
where
|
|
17
|
-
});
|
|
18
|
-
if (branchDelete.tombstoned) {
|
|
19
|
-
return returning === false ? null : branchDelete.doc;
|
|
20
|
-
}
|
|
21
|
-
if (branchDelete.deleteRowID !== undefined) {
|
|
22
|
-
where = {
|
|
23
|
-
id: {
|
|
24
|
-
equals: branchDelete.deleteRowID
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
11
|
const query = await buildQuery({
|
|
29
12
|
adapter: this,
|
|
30
|
-
branch,
|
|
31
13
|
collectionSlug,
|
|
32
14
|
fields: collectionConfig.flattenedFields,
|
|
33
|
-
req,
|
|
34
15
|
where
|
|
35
16
|
});
|
|
36
17
|
const options = {
|
package/dist/deleteOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { DeleteOne } from 'payload'\n\nimport
|
|
1
|
+
{"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { DeleteOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: MongooseAdapter,\n { collection: collectionSlug, req, returning, select, where },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n where,\n })\n\n const options = {\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n } satisfies QueryOptions\n\n if (returning === false) {\n await Model.deleteOne(query, options)?.lean()\n return null\n }\n\n const doc = await Model.findOneAndDelete(query, options)?.lean()\n\n if (!doc) {\n return null\n }\n\n transform({\n adapter: this,\n data: doc,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["buildQuery","buildProjectionFromSelect","getCollection","getSession","transform","deleteOne","collection","collectionSlug","req","returning","select","where","collectionConfig","Model","adapter","query","fields","flattenedFields","options","projection","session","lean","doc","findOneAndDelete","data","operation"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,YAAYC,cAAc,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAE7D,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGX,cAAc;QAAEY,SAAS,IAAI;QAAEP;IAAe;IAElF,MAAMQ,QAAQ,MAAMf,WAAW;QAC7Bc,SAAS,IAAI;QACbP;QACAS,QAAQJ,iBAAiBK,eAAe;QACxCN;IACF;IAEA,MAAMO,UAAU;QACdC,YAAYlB,0BAA0B;YACpCa,SAAS,IAAI;YACbE,QAAQJ,iBAAiBK,eAAe;YACxCP;QACF;QACAU,SAAS,MAAMjB,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAIC,cAAc,OAAO;QACvB,MAAMI,MAAMR,SAAS,CAACU,OAAOG,UAAUG;QACvC,OAAO;IACT;IAEA,MAAMC,MAAM,MAAMT,MAAMU,gBAAgB,CAACR,OAAOG,UAAUG;IAE1D,IAAI,CAACC,KAAK;QACR,OAAO;IACT;IAEAlB,UAAU;QACRU,SAAS,IAAI;QACbU,MAAMF;QACNN,QAAQJ,iBAAiBI,MAAM;QAC/BS,WAAW;IACb;IAEA,OAAOH;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;AAW7D,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;AAW7D,eAAO,MAAM,cAAc,EAAE,cAqC5B,CAAA"}
|
package/dist/deleteVersions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions, FlattenedField } from 'payload'\n\nimport { APIError, buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\nimport type { CollectionModel } from './types.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection, getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: MongooseAdapter,\n { collection: collectionSlug, globalSlug, locale, req, where },\n) {\n let fields: FlattenedField[]\n let VersionsModel: CollectionModel\n\n if (globalSlug) {\n const { globalConfig, Model } = getGlobal({\n adapter: this,\n globalSlug,\n versions: true,\n })\n fields = buildVersionGlobalFields(this.payload.config, globalConfig, true)\n VersionsModel = Model\n } else if (collectionSlug) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n VersionsModel = Model\n } else {\n throw new APIError('Either collection or globalSlug must be passed.')\n }\n\n const query = await buildQuery({\n adapter: this,\n fields,\n locale,\n
|
|
1
|
+
{"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions, FlattenedField } from 'payload'\n\nimport { APIError, buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\nimport type { CollectionModel } from './types.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection, getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: MongooseAdapter,\n { collection: collectionSlug, globalSlug, locale, req, where },\n) {\n let fields: FlattenedField[]\n let VersionsModel: CollectionModel\n\n if (globalSlug) {\n const { globalConfig, Model } = getGlobal({\n adapter: this,\n globalSlug,\n versions: true,\n })\n fields = buildVersionGlobalFields(this.payload.config, globalConfig, true)\n VersionsModel = Model\n } else if (collectionSlug) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n VersionsModel = Model\n } else {\n throw new APIError('Either collection or globalSlug must be passed.')\n }\n\n const query = await buildQuery({\n adapter: this,\n fields,\n locale,\n where,\n })\n\n const session = await getSession(this, req)\n\n await VersionsModel.deleteMany(query, { session })\n}\n"],"names":["APIError","buildVersionCollectionFields","buildVersionGlobalFields","buildQuery","getCollection","getGlobal","getSession","deleteVersions","collection","collectionSlug","globalSlug","locale","req","where","fields","VersionsModel","globalConfig","Model","adapter","versions","payload","config","collectionConfig","query","session","deleteMany"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAK1F,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,EAAEC,SAAS,QAAQ,2BAA0B;AACnE,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,iBAAiC,eAAeA,eAE3D,EAAEC,YAAYC,cAAc,EAAEC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAE9D,IAAIC;IACJ,IAAIC;IAEJ,IAAIL,YAAY;QACd,MAAM,EAAEM,YAAY,EAAEC,KAAK,EAAE,GAAGZ,UAAU;YACxCa,SAAS,IAAI;YACbR;YACAS,UAAU;QACZ;QACAL,SAASZ,yBAAyB,IAAI,CAACkB,OAAO,CAACC,MAAM,EAAEL,cAAc;QACrED,gBAAgBE;IAClB,OAAO,IAAIR,gBAAgB;QACzB,MAAM,EAAEa,gBAAgB,EAAEL,KAAK,EAAE,GAAGb,cAAc;YAChDc,SAAS,IAAI;YACbT;YACAU,UAAU;QACZ;QACAL,SAASb,6BAA6B,IAAI,CAACmB,OAAO,CAACC,MAAM,EAAEC,kBAAkB;QAC7EP,gBAAgBE;IAClB,OAAO;QACL,MAAM,IAAIjB,SAAS;IACrB;IAEA,MAAMuB,QAAQ,MAAMpB,WAAW;QAC7Be,SAAS,IAAI;QACbJ;QACAH;QACAE;IACF;IAEA,MAAMW,UAAU,MAAMlB,WAAW,IAAI,EAAEM;IAEvC,MAAMG,cAAcU,UAAU,CAACF,OAAO;QAAEC;IAAQ;AAClD,EAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { migrateBranching } from '../predefinedMigrations/migrateBranching.js';
|
|
2
1
|
export { localizeStatus, migrateLocalizeStatus, } from '../predefinedMigrations/migrateLocalizeStatus.js';
|
|
3
2
|
export { migrateRelationshipsV2_V3 } from '../predefinedMigrations/migrateRelationshipsV2_V3.js';
|
|
4
3
|
export { migrateSizesToVariants } from '../predefinedMigrations/migrateSizesToVariants.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-utils.d.ts","sourceRoot":"","sources":["../../src/exports/migration-utils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"migration-utils.d.ts","sourceRoot":"","sources":["../../src/exports/migration-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,qBAAqB,GACtB,MAAM,kDAAkD,CAAA;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sDAAsD,CAAA;AAChG,OAAO,EAAE,sBAAsB,EAAE,MAAM,mDAAmD,CAAA;AAC1F,OAAO,EAAE,oBAAoB,EAAE,MAAM,iDAAiD,CAAA"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { migrateBranching } from '../predefinedMigrations/migrateBranching.js';
|
|
2
1
|
export { localizeStatus, migrateLocalizeStatus } from '../predefinedMigrations/migrateLocalizeStatus.js';
|
|
3
2
|
export { migrateRelationshipsV2_V3 } from '../predefinedMigrations/migrateRelationshipsV2_V3.js';
|
|
4
3
|
export { migrateSizesToVariants } from '../predefinedMigrations/migrateSizesToVariants.js';
|