@payloadcms/db-mongodb 3.0.0-canary.ff8c8fd → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +12 -3
- package/dist/connect.js.map +1 -1
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +8 -1
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts +3 -0
- package/dist/countGlobalVersions.d.ts.map +1 -0
- package/dist/countGlobalVersions.js +40 -0
- package/dist/countGlobalVersions.js.map +1 -0
- package/dist/countVersions.d.ts +3 -0
- package/dist/countVersions.d.ts.map +1 -0
- package/dist/countVersions.js +40 -0
- package/dist/countVersions.js.map +1 -0
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +10 -1
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +10 -5
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +13 -4
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +8 -6
- package/dist/createMigration.js.map +1 -1
- package/dist/createVersion.d.ts +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +31 -9
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +11 -3
- package/dist/deleteOne.js.map +1 -1
- package/dist/exports/migration-utils.d.ts +3 -0
- package/dist/exports/migration-utils.d.ts.map +1 -0
- package/dist/exports/migration-utils.js +4 -0
- package/dist/exports/migration-utils.js.map +1 -0
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +27 -4
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +9 -3
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +9 -4
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +27 -3
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +9 -4
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +23 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -7
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +20 -18
- package/dist/init.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +2 -3
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +10 -7
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts +2 -2
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +6 -6
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +2 -3
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +108 -66
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts +6 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +141 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts +5 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js +107 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -0
- package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
- package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
- package/dist/predefinedMigrations/relationships-v2-v3.js +9 -0
- package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
- package/dist/predefinedMigrations/versions-v1-v2.d.ts +4 -0
- package/dist/predefinedMigrations/versions-v1-v2.d.ts.map +1 -0
- package/dist/predefinedMigrations/versions-v1-v2.js +5 -95
- package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +2 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +1 -2
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +29 -18
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +2 -2
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js +26 -17
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +7 -2
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +3 -2
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +263 -37
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +29 -8
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +2 -0
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +3 -1
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/types.d.ts +7 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +18 -4
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts +2 -2
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +19 -4
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +18 -4
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +18 -3
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsert.d.ts +3 -0
- package/dist/upsert.d.ts.map +1 -0
- package/dist/upsert.js +15 -0
- package/dist/upsert.js.map +1 -0
- package/dist/utilities/buildJoinAggregation.d.ts +18 -0
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
- package/dist/utilities/buildJoinAggregation.js +159 -0
- package/dist/utilities/buildJoinAggregation.js.map +1 -0
- package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
- package/dist/utilities/buildProjectionFromSelect.js +171 -0
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
- package/dist/utilities/getDBName.d.ts.map +1 -1
- package/dist/utilities/getDBName.js +3 -1
- package/dist/utilities/getDBName.js.map +1 -1
- package/dist/utilities/handleError.js +2 -2
- package/dist/utilities/handleError.js.map +1 -1
- package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
- package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
- package/dist/utilities/sanitizeInternalFields.js +1 -2
- package/dist/utilities/sanitizeInternalFields.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.js +125 -0
- package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.spec.js +408 -0
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
- package/dist/withSession.d.ts +1 -1
- package/dist/withSession.d.ts.map +1 -1
- package/dist/withSession.js +5 -3
- package/dist/withSession.js.map +1 -1
- package/license.md +22 -0
- package/package.json +24 -11
- package/dist/queries/mock.js +0 -2
- package/dist/queries/mock.js.map +0 -1
package/dist/init.js
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
import mongoose from 'mongoose';
|
2
|
+
import mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';
|
2
3
|
import paginate from 'mongoose-paginate-v2';
|
3
4
|
import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
|
4
|
-
import buildCollectionSchema from './models/buildCollectionSchema.js';
|
5
|
+
import { buildCollectionSchema } from './models/buildCollectionSchema.js';
|
5
6
|
import { buildGlobalModel } from './models/buildGlobalModel.js';
|
6
|
-
import buildSchema from './models/buildSchema.js';
|
7
|
-
import getBuildQueryPlugin from './queries/buildQuery.js';
|
7
|
+
import { buildSchema } from './models/buildSchema.js';
|
8
|
+
import { getBuildQueryPlugin } from './queries/buildQuery.js';
|
8
9
|
import { getDBName } from './utilities/getDBName.js';
|
9
10
|
export const init = function init() {
|
10
11
|
this.payload.config.collections.forEach((collection)=>{
|
11
|
-
const schema = buildCollectionSchema(collection, this.payload
|
12
|
+
const schema = buildCollectionSchema(collection, this.payload);
|
12
13
|
if (collection.versions) {
|
13
14
|
const versionModelName = getDBName({
|
14
15
|
config: collection,
|
15
16
|
versions: true
|
16
17
|
});
|
17
|
-
const versionCollectionFields = buildVersionCollectionFields(collection);
|
18
|
-
const versionSchema = buildSchema(this.payload
|
18
|
+
const versionCollectionFields = buildVersionCollectionFields(this.payload.config, collection);
|
19
|
+
const versionSchema = buildSchema(this.payload, versionCollectionFields, {
|
19
20
|
disableUnique: true,
|
20
21
|
draftsEnabled: true,
|
21
22
|
indexSortableFields: this.payload.config.indexSortableFields,
|
@@ -30,25 +31,27 @@ export const init = function init() {
|
|
30
31
|
collectionSlug: collection.slug,
|
31
32
|
versionsFields: versionCollectionFields
|
32
33
|
}));
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
if (Object.keys(collection.joins).length > 0) {
|
35
|
+
versionSchema.plugin(mongooseAggregatePaginate);
|
36
|
+
}
|
37
|
+
const versionCollectionName = this.autoPluralization === true && !collection.dbName ? undefined : versionModelName;
|
38
|
+
this.versions[collection.slug] = mongoose.model(versionModelName, versionSchema, versionCollectionName);
|
36
39
|
}
|
37
|
-
const
|
40
|
+
const modelName = getDBName({
|
38
41
|
config: collection
|
39
|
-
})
|
40
|
-
this.
|
42
|
+
});
|
43
|
+
const collectionName = this.autoPluralization === true && !collection.dbName ? undefined : modelName;
|
44
|
+
this.collections[collection.slug] = mongoose.model(modelName, schema, collectionName);
|
41
45
|
});
|
42
|
-
|
43
|
-
this.globals = model;
|
46
|
+
this.globals = buildGlobalModel(this.payload);
|
44
47
|
this.payload.config.globals.forEach((global)=>{
|
45
48
|
if (global.versions) {
|
46
49
|
const versionModelName = getDBName({
|
47
50
|
config: global,
|
48
51
|
versions: true
|
49
52
|
});
|
50
|
-
const versionGlobalFields = buildVersionGlobalFields(global);
|
51
|
-
const versionSchema = buildSchema(this.payload
|
53
|
+
const versionGlobalFields = buildVersionGlobalFields(this.payload.config, global);
|
54
|
+
const versionSchema = buildSchema(this.payload, versionGlobalFields, {
|
52
55
|
disableUnique: true,
|
53
56
|
draftsEnabled: true,
|
54
57
|
indexSortableFields: this.payload.config.indexSortableFields,
|
@@ -62,8 +65,7 @@ export const init = function init() {
|
|
62
65
|
}).plugin(getBuildQueryPlugin({
|
63
66
|
versionsFields: versionGlobalFields
|
64
67
|
}));
|
65
|
-
|
66
|
-
this.versions[global.slug] = versionsModel;
|
68
|
+
this.versions[global.slug] = mongoose.model(versionModelName, versionSchema, versionModelName);
|
67
69
|
}
|
68
70
|
});
|
69
71
|
};
|
package/dist/init.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/init.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Init, SanitizedCollectionConfig } from 'payload'\n\nimport mongoose from 'mongoose'\nimport paginate from 'mongoose-paginate-v2'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\nimport type { CollectionModel } from './types.js'\n\nimport buildCollectionSchema from './models/buildCollectionSchema.js'\nimport { buildGlobalModel } from './models/buildGlobalModel.js'\nimport buildSchema from './models/buildSchema.js'\nimport getBuildQueryPlugin from './queries/buildQuery.js'\nimport { getDBName } from './utilities/getDBName.js'\n\nexport const init: Init = function init(this: MongooseAdapter) {\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n const schema = buildCollectionSchema(collection, this.payload
|
1
|
+
{"version":3,"sources":["../src/init.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Init, SanitizedCollectionConfig } from 'payload'\n\nimport mongoose from 'mongoose'\nimport mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2'\nimport paginate from 'mongoose-paginate-v2'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\nimport type { CollectionModel } from './types.js'\n\nimport { buildCollectionSchema } from './models/buildCollectionSchema.js'\nimport { buildGlobalModel } from './models/buildGlobalModel.js'\nimport { buildSchema } from './models/buildSchema.js'\nimport { getBuildQueryPlugin } from './queries/buildQuery.js'\nimport { getDBName } from './utilities/getDBName.js'\n\nexport const init: Init = function init(this: MongooseAdapter) {\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n const schema = buildCollectionSchema(collection, this.payload)\n\n if (collection.versions) {\n const versionModelName = getDBName({ config: collection, versions: true })\n\n const versionCollectionFields = buildVersionCollectionFields(this.payload.config, collection)\n\n const versionSchema = buildSchema(this.payload, versionCollectionFields, {\n disableUnique: true,\n draftsEnabled: true,\n indexSortableFields: this.payload.config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: false,\n },\n })\n\n versionSchema.plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true }).plugin(\n getBuildQueryPlugin({\n collectionSlug: collection.slug,\n versionsFields: versionCollectionFields,\n }),\n )\n\n if (Object.keys(collection.joins).length > 0) {\n versionSchema.plugin(mongooseAggregatePaginate)\n }\n\n const versionCollectionName =\n this.autoPluralization === true && !collection.dbName ? undefined : versionModelName\n\n this.versions[collection.slug] = mongoose.model(\n versionModelName,\n versionSchema,\n versionCollectionName,\n ) as CollectionModel\n }\n\n const modelName = getDBName({ config: collection })\n const collectionName =\n this.autoPluralization === true && !collection.dbName ? undefined : modelName\n\n this.collections[collection.slug] = mongoose.model(\n modelName,\n schema,\n collectionName,\n ) as CollectionModel\n })\n\n this.globals = buildGlobalModel(this.payload)\n\n this.payload.config.globals.forEach((global) => {\n if (global.versions) {\n const versionModelName = getDBName({ config: global, versions: true })\n\n const versionGlobalFields = buildVersionGlobalFields(this.payload.config, global)\n\n const versionSchema = buildSchema(this.payload, versionGlobalFields, {\n disableUnique: true,\n draftsEnabled: true,\n indexSortableFields: this.payload.config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: false,\n },\n })\n\n versionSchema\n .plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true })\n .plugin(getBuildQueryPlugin({ versionsFields: versionGlobalFields }))\n\n this.versions[global.slug] = mongoose.model(\n versionModelName,\n versionSchema,\n versionModelName,\n ) as CollectionModel\n }\n })\n}\n"],"names":["mongoose","mongooseAggregatePaginate","paginate","buildVersionCollectionFields","buildVersionGlobalFields","buildCollectionSchema","buildGlobalModel","buildSchema","getBuildQueryPlugin","getDBName","init","payload","config","collections","forEach","collection","schema","versions","versionModelName","versionCollectionFields","versionSchema","disableUnique","draftsEnabled","indexSortableFields","options","minimize","timestamps","plugin","useEstimatedCount","collectionSlug","slug","versionsFields","Object","keys","joins","length","versionCollectionName","autoPluralization","dbName","undefined","model","modelName","collectionName","globals","global","versionGlobalFields"],"mappings":"AAGA,OAAOA,cAAc,WAAU;AAC/B,OAAOC,+BAA+B,iCAAgC;AACtE,OAAOC,cAAc,uBAAsB;AAC3C,SAASC,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAKhF,SAASC,qBAAqB,QAAQ,oCAAmC;AACzE,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,SAASC,WAAW,QAAQ,0BAAyB;AACrD,SAASC,mBAAmB,QAAQ,0BAAyB;AAC7D,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,OAAa,SAASA;IACjC,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,WAAW,CAACC,OAAO,CAAC,CAACC;QACvC,MAAMC,SAASX,sBAAsBU,YAAY,IAAI,CAACJ,OAAO;QAE7D,IAAII,WAAWE,QAAQ,EAAE;YACvB,MAAMC,mBAAmBT,UAAU;gBAAEG,QAAQG;gBAAYE,UAAU;YAAK;YAExE,MAAME,0BAA0BhB,6BAA6B,IAAI,CAACQ,OAAO,CAACC,MAAM,EAAEG;YAElF,MAAMK,gBAAgBb,YAAY,IAAI,CAACI,OAAO,EAAEQ,yBAAyB;gBACvEE,eAAe;gBACfC,eAAe;gBACfC,qBAAqB,IAAI,CAACZ,OAAO,CAACC,MAAM,CAACW,mBAAmB;gBAC5DC,SAAS;oBACPC,UAAU;oBACVC,YAAY;gBACd;YACF;YAEAN,cAAcO,MAAM,CAAuBzB,UAAU;gBAAE0B,mBAAmB;YAAK,GAAGD,MAAM,CACtFnB,oBAAoB;gBAClBqB,gBAAgBd,WAAWe,IAAI;gBAC/BC,gBAAgBZ;YAClB;YAGF,IAAIa,OAAOC,IAAI,CAAClB,WAAWmB,KAAK,EAAEC,MAAM,GAAG,GAAG;gBAC5Cf,cAAcO,MAAM,CAAC1B;YACvB;YAEA,MAAMmC,wBACJ,IAAI,CAACC,iBAAiB,KAAK,QAAQ,CAACtB,WAAWuB,MAAM,GAAGC,YAAYrB;YAEtE,IAAI,CAACD,QAAQ,CAACF,WAAWe,IAAI,CAAC,GAAG9B,SAASwC,KAAK,CAC7CtB,kBACAE,eACAgB;QAEJ;QAEA,MAAMK,YAAYhC,UAAU;YAAEG,QAAQG;QAAW;QACjD,MAAM2B,iBACJ,IAAI,CAACL,iBAAiB,KAAK,QAAQ,CAACtB,WAAWuB,MAAM,GAAGC,YAAYE;QAEtE,IAAI,CAAC5B,WAAW,CAACE,WAAWe,IAAI,CAAC,GAAG9B,SAASwC,KAAK,CAChDC,WACAzB,QACA0B;IAEJ;IAEA,IAAI,CAACC,OAAO,GAAGrC,iBAAiB,IAAI,CAACK,OAAO;IAE5C,IAAI,CAACA,OAAO,CAACC,MAAM,CAAC+B,OAAO,CAAC7B,OAAO,CAAC,CAAC8B;QACnC,IAAIA,OAAO3B,QAAQ,EAAE;YACnB,MAAMC,mBAAmBT,UAAU;gBAAEG,QAAQgC;gBAAQ3B,UAAU;YAAK;YAEpE,MAAM4B,sBAAsBzC,yBAAyB,IAAI,CAACO,OAAO,CAACC,MAAM,EAAEgC;YAE1E,MAAMxB,gBAAgBb,YAAY,IAAI,CAACI,OAAO,EAAEkC,qBAAqB;gBACnExB,eAAe;gBACfC,eAAe;gBACfC,qBAAqB,IAAI,CAACZ,OAAO,CAACC,MAAM,CAACW,mBAAmB;gBAC5DC,SAAS;oBACPC,UAAU;oBACVC,YAAY;gBACd;YACF;YAEAN,cACGO,MAAM,CAAuBzB,UAAU;gBAAE0B,mBAAmB;YAAK,GACjED,MAAM,CAACnB,oBAAoB;gBAAEuB,gBAAgBc;YAAoB;YAEpE,IAAI,CAAC5B,QAAQ,CAAC2B,OAAOd,IAAI,CAAC,GAAG9B,SAASwC,KAAK,CACzCtB,kBACAE,eACAF;QAEJ;IACF;AACF,EAAC"}
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import type { Schema } from 'mongoose';
|
2
|
-
import type {
|
3
|
-
declare const buildCollectionSchema: (collection: SanitizedCollectionConfig,
|
4
|
-
export default buildCollectionSchema;
|
2
|
+
import type { Payload, SanitizedCollectionConfig } from 'payload';
|
3
|
+
export declare const buildCollectionSchema: (collection: SanitizedCollectionConfig, payload: Payload, schemaOptions?: {}) => Schema;
|
5
4
|
//# sourceMappingURL=buildCollectionSchema.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildCollectionSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildCollectionSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,KAAK,EAAE,
|
1
|
+
{"version":3,"file":"buildCollectionSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildCollectionSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAQjE,eAAO,MAAM,qBAAqB,eACpB,yBAAyB,WAC5B,OAAO,yBAEf,MAqCF,CAAA"}
|
@@ -1,10 +1,11 @@
|
|
1
|
+
import mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';
|
1
2
|
import paginate from 'mongoose-paginate-v2';
|
2
|
-
import getBuildQueryPlugin from '../queries/buildQuery.js';
|
3
|
-
import buildSchema from './buildSchema.js';
|
4
|
-
const buildCollectionSchema = (collection,
|
5
|
-
const schema = buildSchema(
|
3
|
+
import { getBuildQueryPlugin } from '../queries/buildQuery.js';
|
4
|
+
import { buildSchema } from './buildSchema.js';
|
5
|
+
export const buildCollectionSchema = (collection, payload, schemaOptions = {})=>{
|
6
|
+
const schema = buildSchema(payload, collection.fields, {
|
6
7
|
draftsEnabled: Boolean(typeof collection?.versions === 'object' && collection.versions.drafts),
|
7
|
-
indexSortableFields: config.indexSortableFields,
|
8
|
+
indexSortableFields: payload.config.indexSortableFields,
|
8
9
|
options: {
|
9
10
|
minimize: false,
|
10
11
|
timestamps: collection.timestamps !== false,
|
@@ -20,7 +21,7 @@ const buildCollectionSchema = (collection, config, schemaOptions = {})=>{
|
|
20
21
|
unique: true
|
21
22
|
});
|
22
23
|
}
|
23
|
-
if (config.indexSortableFields && collection.timestamps !== false) {
|
24
|
+
if (payload.config.indexSortableFields && collection.timestamps !== false) {
|
24
25
|
schema.index({
|
25
26
|
updatedAt: 1
|
26
27
|
});
|
@@ -33,8 +34,10 @@ const buildCollectionSchema = (collection, config, schemaOptions = {})=>{
|
|
33
34
|
}).plugin(getBuildQueryPlugin({
|
34
35
|
collectionSlug: collection.slug
|
35
36
|
}));
|
37
|
+
if (Object.keys(collection.joins).length > 0) {
|
38
|
+
schema.plugin(mongooseAggregatePaginate);
|
39
|
+
}
|
36
40
|
return schema;
|
37
41
|
};
|
38
|
-
export default buildCollectionSchema;
|
39
42
|
|
40
43
|
//# sourceMappingURL=buildCollectionSchema.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/models/buildCollectionSchema.ts"],"sourcesContent":["import type { PaginateOptions, Schema } from 'mongoose'\nimport type {
|
1
|
+
{"version":3,"sources":["../../src/models/buildCollectionSchema.ts"],"sourcesContent":["import type { PaginateOptions, Schema } from 'mongoose'\nimport type { Payload, SanitizedCollectionConfig } from 'payload'\n\nimport mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2'\nimport paginate from 'mongoose-paginate-v2'\n\nimport { getBuildQueryPlugin } from '../queries/buildQuery.js'\nimport { buildSchema } from './buildSchema.js'\n\nexport const buildCollectionSchema = (\n collection: SanitizedCollectionConfig,\n payload: Payload,\n schemaOptions = {},\n): Schema => {\n const schema = buildSchema(payload, collection.fields, {\n draftsEnabled: Boolean(typeof collection?.versions === 'object' && collection.versions.drafts),\n indexSortableFields: payload.config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: collection.timestamps !== false,\n ...schemaOptions,\n },\n })\n\n if (Array.isArray(collection.upload.filenameCompoundIndex)) {\n const indexDefinition: Record<string, 1> = collection.upload.filenameCompoundIndex.reduce(\n (acc, index) => {\n acc[index] = 1\n return acc\n },\n {},\n )\n\n schema.index(indexDefinition, { unique: true })\n }\n\n if (payload.config.indexSortableFields && collection.timestamps !== false) {\n schema.index({ updatedAt: 1 })\n schema.index({ createdAt: 1 })\n }\n\n schema\n .plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true })\n .plugin(getBuildQueryPlugin({ collectionSlug: collection.slug }))\n\n if (Object.keys(collection.joins).length > 0) {\n schema.plugin(mongooseAggregatePaginate)\n }\n\n return schema\n}\n"],"names":["mongooseAggregatePaginate","paginate","getBuildQueryPlugin","buildSchema","buildCollectionSchema","collection","payload","schemaOptions","schema","fields","draftsEnabled","Boolean","versions","drafts","indexSortableFields","config","options","minimize","timestamps","Array","isArray","upload","filenameCompoundIndex","indexDefinition","reduce","acc","index","unique","updatedAt","createdAt","plugin","useEstimatedCount","collectionSlug","slug","Object","keys","joins","length"],"mappings":"AAGA,OAAOA,+BAA+B,iCAAgC;AACtE,OAAOC,cAAc,uBAAsB;AAE3C,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,wBAAwB,CACnCC,YACAC,SACAC,gBAAgB,CAAC,CAAC;IAElB,MAAMC,SAASL,YAAYG,SAASD,WAAWI,MAAM,EAAE;QACrDC,eAAeC,QAAQ,OAAON,YAAYO,aAAa,YAAYP,WAAWO,QAAQ,CAACC,MAAM;QAC7FC,qBAAqBR,QAAQS,MAAM,CAACD,mBAAmB;QACvDE,SAAS;YACPC,UAAU;YACVC,YAAYb,WAAWa,UAAU,KAAK;YACtC,GAAGX,aAAa;QAClB;IACF;IAEA,IAAIY,MAAMC,OAAO,CAACf,WAAWgB,MAAM,CAACC,qBAAqB,GAAG;QAC1D,MAAMC,kBAAqClB,WAAWgB,MAAM,CAACC,qBAAqB,CAACE,MAAM,CACvF,CAACC,KAAKC;YACJD,GAAG,CAACC,MAAM,GAAG;YACb,OAAOD;QACT,GACA,CAAC;QAGHjB,OAAOkB,KAAK,CAACH,iBAAiB;YAAEI,QAAQ;QAAK;IAC/C;IAEA,IAAIrB,QAAQS,MAAM,CAACD,mBAAmB,IAAIT,WAAWa,UAAU,KAAK,OAAO;QACzEV,OAAOkB,KAAK,CAAC;YAAEE,WAAW;QAAE;QAC5BpB,OAAOkB,KAAK,CAAC;YAAEG,WAAW;QAAE;IAC9B;IAEArB,OACGsB,MAAM,CAAuB7B,UAAU;QAAE8B,mBAAmB;IAAK,GACjED,MAAM,CAAC5B,oBAAoB;QAAE8B,gBAAgB3B,WAAW4B,IAAI;IAAC;IAEhE,IAAIC,OAAOC,IAAI,CAAC9B,WAAW+B,KAAK,EAAEC,MAAM,GAAG,GAAG;QAC5C7B,OAAOsB,MAAM,CAAC9B;IAChB;IAEA,OAAOQ;AACT,EAAC"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type {
|
1
|
+
import type { Payload } from 'payload';
|
2
2
|
import type { GlobalModel } from '../types.js';
|
3
|
-
export declare const buildGlobalModel: (
|
3
|
+
export declare const buildGlobalModel: (payload: Payload) => GlobalModel | null;
|
4
4
|
//# sourceMappingURL=buildGlobalModel.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildGlobalModel.d.ts","sourceRoot":"","sources":["../../src/models/buildGlobalModel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
1
|
+
{"version":3,"file":"buildGlobalModel.d.ts","sourceRoot":"","sources":["../../src/models/buildGlobalModel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAItC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAK9C,eAAO,MAAM,gBAAgB,YAAa,OAAO,KAAG,WAAW,GAAG,IAwBjE,CAAA"}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import mongoose from 'mongoose';
|
2
|
-
import getBuildQueryPlugin from '../queries/buildQuery.js';
|
3
|
-
import buildSchema from './buildSchema.js';
|
4
|
-
export const buildGlobalModel = (
|
5
|
-
if (config.globals && config.globals.length > 0) {
|
2
|
+
import { getBuildQueryPlugin } from '../queries/buildQuery.js';
|
3
|
+
import { buildSchema } from './buildSchema.js';
|
4
|
+
export const buildGlobalModel = (payload)=>{
|
5
|
+
if (payload.config.globals && payload.config.globals.length > 0) {
|
6
6
|
const globalsSchema = new mongoose.Schema({}, {
|
7
7
|
discriminatorKey: 'globalType',
|
8
8
|
minimize: false,
|
@@ -10,8 +10,8 @@ export const buildGlobalModel = (config)=>{
|
|
10
10
|
});
|
11
11
|
globalsSchema.plugin(getBuildQueryPlugin());
|
12
12
|
const Globals = mongoose.model('globals', globalsSchema, 'globals');
|
13
|
-
Object.values(config.globals).forEach((globalConfig)=>{
|
14
|
-
const globalSchema = buildSchema(
|
13
|
+
Object.values(payload.config.globals).forEach((globalConfig)=>{
|
14
|
+
const globalSchema = buildSchema(payload, globalConfig.fields, {
|
15
15
|
options: {
|
16
16
|
minimize: false
|
17
17
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/models/buildGlobalModel.ts"],"sourcesContent":["import type {
|
1
|
+
{"version":3,"sources":["../../src/models/buildGlobalModel.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\nimport mongoose from 'mongoose'\n\nimport type { GlobalModel } from '../types.js'\n\nimport { getBuildQueryPlugin } from '../queries/buildQuery.js'\nimport { buildSchema } from './buildSchema.js'\n\nexport const buildGlobalModel = (payload: Payload): GlobalModel | null => {\n if (payload.config.globals && payload.config.globals.length > 0) {\n const globalsSchema = new mongoose.Schema(\n {},\n { discriminatorKey: 'globalType', minimize: false, timestamps: true },\n )\n\n globalsSchema.plugin(getBuildQueryPlugin())\n\n const Globals = mongoose.model('globals', globalsSchema, 'globals') as unknown as GlobalModel\n\n Object.values(payload.config.globals).forEach((globalConfig) => {\n const globalSchema = buildSchema(payload, globalConfig.fields, {\n options: {\n minimize: false,\n },\n })\n Globals.discriminator(globalConfig.slug, globalSchema)\n })\n\n return Globals\n }\n\n return null\n}\n"],"names":["mongoose","getBuildQueryPlugin","buildSchema","buildGlobalModel","payload","config","globals","length","globalsSchema","Schema","discriminatorKey","minimize","timestamps","plugin","Globals","model","Object","values","forEach","globalConfig","globalSchema","fields","options","discriminator","slug"],"mappings":"AAEA,OAAOA,cAAc,WAAU;AAI/B,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,mBAAmB,CAACC;IAC/B,IAAIA,QAAQC,MAAM,CAACC,OAAO,IAAIF,QAAQC,MAAM,CAACC,OAAO,CAACC,MAAM,GAAG,GAAG;QAC/D,MAAMC,gBAAgB,IAAIR,SAASS,MAAM,CACvC,CAAC,GACD;YAAEC,kBAAkB;YAAcC,UAAU;YAAOC,YAAY;QAAK;QAGtEJ,cAAcK,MAAM,CAACZ;QAErB,MAAMa,UAAUd,SAASe,KAAK,CAAC,WAAWP,eAAe;QAEzDQ,OAAOC,MAAM,CAACb,QAAQC,MAAM,CAACC,OAAO,EAAEY,OAAO,CAAC,CAACC;YAC7C,MAAMC,eAAelB,YAAYE,SAASe,aAAaE,MAAM,EAAE;gBAC7DC,SAAS;oBACPX,UAAU;gBACZ;YACF;YACAG,QAAQS,aAAa,CAACJ,aAAaK,IAAI,EAAEJ;QAC3C;QAEA,OAAON;IACT;IAEA,OAAO;AACT,EAAC"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { Schema, SchemaOptions } from 'mongoose';
|
2
|
-
import type
|
2
|
+
import { type Field, type Payload } from 'payload';
|
3
3
|
export type BuildSchemaOptions = {
|
4
4
|
allowIDField?: boolean;
|
5
5
|
disableUnique?: boolean;
|
@@ -7,6 +7,5 @@ export type BuildSchemaOptions = {
|
|
7
7
|
indexSortableFields?: boolean;
|
8
8
|
options?: SchemaOptions;
|
9
9
|
};
|
10
|
-
declare const buildSchema: (
|
11
|
-
export default buildSchema;
|
10
|
+
export declare const buildSchema: (payload: Payload, configFields: Field[], buildSchemaOptions?: BuildSchemaOptions) => Schema;
|
12
11
|
//# sourceMappingURL=buildSchema.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,MAAM,EAAE,aAAa,EAAqB,MAAM,UAAU,CAAA;
|
1
|
+
{"version":3,"file":"buildSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,MAAM,EAAE,aAAa,EAAqB,MAAM,UAAU,CAAA;AAGtF,OAAO,EASL,KAAK,KAAK,EAMV,KAAK,OAAO,EAab,MAAM,SAAS,CAAA;AAShB,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,OAAO,CAAC,EAAE,aAAa,CAAA;CACxB,CAAA;AAoED,eAAO,MAAM,WAAW,YACb,OAAO,gBACF,KAAK,EAAE,uBACD,kBAAkB,KACrC,MAmCF,CAAA"}
|