@payloadcms/db-mongodb 3.0.0-canary.f83d96a → 3.0.0-canary.fb04843
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +18 -4
- package/dist/connect.js.map +1 -1
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +9 -2
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts +3 -0
- package/dist/countGlobalVersions.d.ts.map +1 -0
- package/dist/countGlobalVersions.js +40 -0
- package/dist/countGlobalVersions.js.map +1 -0
- package/dist/countVersions.d.ts +3 -0
- package/dist/countVersions.d.ts.map +1 -0
- package/dist/countVersions.js +40 -0
- package/dist/countVersions.js.map +1 -0
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +11 -2
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +11 -6
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +14 -5
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +9 -7
- package/dist/createMigration.js.map +1 -1
- package/dist/createVersion.d.ts +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +32 -10
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +1 -1
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +12 -4
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +1 -1
- package/dist/deleteVersions.js.map +1 -1
- package/dist/exports/migration-utils.d.ts +3 -0
- package/dist/exports/migration-utils.d.ts.map +1 -0
- package/dist/exports/migration-utils.js +4 -0
- package/dist/exports/migration-utils.js.map +1 -0
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +35 -6
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +10 -4
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +18 -7
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +28 -4
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +17 -6
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +59 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -7
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +18 -16
- package/dist/init.js.map +1 -1
- package/dist/migrateFresh.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +1 -2
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +16 -4
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.js +2 -2
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +1 -2
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +116 -23
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts +6 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +141 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts +5 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js +107 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -0
- package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
- package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
- package/dist/predefinedMigrations/relationships-v2-v3.js +9 -0
- package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
- package/dist/predefinedMigrations/versions-v1-v2.d.ts +4 -0
- package/dist/predefinedMigrations/versions-v1-v2.d.ts.map +1 -0
- package/dist/predefinedMigrations/versions-v1-v2.js +5 -95
- package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +0 -2
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +2 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +1 -2
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +28 -18
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +2 -2
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js +26 -17
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +43 -43
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +7 -5
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +144 -27
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +37 -10
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +2 -0
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +3 -0
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
- package/dist/transactions/rollbackTransaction.js +13 -7
- package/dist/transactions/rollbackTransaction.js.map +1 -1
- package/dist/types.d.ts +7 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +18 -5
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts +2 -2
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +19 -5
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +19 -5
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +18 -4
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsert.d.ts +3 -0
- package/dist/upsert.d.ts.map +1 -0
- package/dist/upsert.js +15 -0
- package/dist/upsert.js.map +1 -0
- package/dist/utilities/buildJoinAggregation.d.ts +18 -0
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
- package/dist/utilities/buildJoinAggregation.js +159 -0
- package/dist/utilities/buildJoinAggregation.js.map +1 -0
- package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
- package/dist/utilities/buildProjectionFromSelect.js +171 -0
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
- package/dist/utilities/getDBName.d.ts.map +1 -1
- package/dist/utilities/getDBName.js +3 -1
- package/dist/utilities/getDBName.js.map +1 -1
- package/dist/utilities/handleError.js +2 -2
- package/dist/utilities/handleError.js.map +1 -1
- package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
- package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
- package/dist/utilities/sanitizeInternalFields.js +1 -2
- package/dist/utilities/sanitizeInternalFields.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.js +115 -0
- package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.spec.js +383 -0
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
- package/dist/withSession.d.ts +3 -2
- package/dist/withSession.d.ts.map +1 -1
- package/dist/withSession.js +10 -4
- package/dist/withSession.js.map +1 -1
- package/license.md +22 -0
- package/package.json +24 -11
package/dist/index.d.ts
CHANGED
@@ -1,54 +1,103 @@
|
|
1
|
-
import type { TransactionOptions } from 'mongodb';
|
1
|
+
import type { CollationOptions, TransactionOptions } from 'mongodb';
|
2
2
|
import type { MongoMemoryReplSet } from 'mongodb-memory-server';
|
3
|
-
import type { ClientSession, ConnectOptions,
|
4
|
-
import type { BaseDatabaseAdapter, DatabaseAdapterObj } from 'payload';
|
5
|
-
import type { CollectionModel, GlobalModel } from './types.js';
|
3
|
+
import type { ClientSession, Connection, ConnectOptions, QueryOptions } from 'mongoose';
|
4
|
+
import type { BaseDatabaseAdapter, DatabaseAdapterObj, UpdateOneArgs } from 'payload';
|
5
|
+
import type { CollectionModel, GlobalModel, MigrateDownArgs, MigrateUpArgs } from './types.js';
|
6
6
|
export type { MigrateDownArgs, MigrateUpArgs } from './types.js';
|
7
7
|
export interface Args {
|
8
8
|
/** Set to false to disable auto-pluralization of collection names, Defaults to true */
|
9
9
|
autoPluralization?: boolean;
|
10
|
+
/**
|
11
|
+
* If enabled, collation allows for language-specific rules for string comparison.
|
12
|
+
* This configuration can include the following options:
|
13
|
+
*
|
14
|
+
* - `strength` (number): Comparison level (1: Primary, 2: Secondary, 3: Tertiary (default), 4: Quaternary, 5: Identical)
|
15
|
+
* - `caseLevel` (boolean): Include case comparison at strength level 1 or 2.
|
16
|
+
* - `caseFirst` (string): Sort order of case differences during tertiary level comparisons ("upper", "lower", "off").
|
17
|
+
* - `numericOrdering` (boolean): Compare numeric strings as numbers.
|
18
|
+
* - `alternate` (string): Consider whitespace and punctuation as base characters ("non-ignorable", "shifted").
|
19
|
+
* - `maxVariable` (string): Characters considered ignorable when `alternate` is "shifted" ("punct", "space").
|
20
|
+
* - `backwards` (boolean): Sort strings with diacritics from back of the string.
|
21
|
+
* - `normalization` (boolean): Check if text requires normalization and perform normalization.
|
22
|
+
*
|
23
|
+
* Available on MongoDB version 3.4 and up.
|
24
|
+
* The locale that gets passed is your current project's locale but defaults to "en".
|
25
|
+
*
|
26
|
+
* Example:
|
27
|
+
* {
|
28
|
+
* strength: 3
|
29
|
+
* }
|
30
|
+
*
|
31
|
+
* Defaults to disabled.
|
32
|
+
*/
|
33
|
+
collation?: Omit<CollationOptions, 'locale'>;
|
10
34
|
/** Extra configuration options */
|
11
|
-
connectOptions?:
|
35
|
+
connectOptions?: {
|
12
36
|
/** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */
|
13
37
|
useFacet?: boolean;
|
14
|
-
};
|
38
|
+
} & ConnectOptions;
|
15
39
|
/** Set to true to disable hinting to MongoDB to use 'id' as index. This is currently done when counting documents for pagination. Disabling this optimization might fix some problems with AWS DocumentDB. Defaults to false */
|
16
40
|
disableIndexHints?: boolean;
|
41
|
+
/**
|
42
|
+
* Set to `true` to ensure that indexes are ready before completing connection.
|
43
|
+
* NOTE: not recommended for production. This can slow down the initialization of Payload.
|
44
|
+
*/
|
45
|
+
ensureIndexes?: boolean;
|
17
46
|
migrationDir?: string;
|
18
47
|
/**
|
19
48
|
* typed as any to avoid dependency
|
20
49
|
*/
|
21
50
|
mongoMemoryServer?: MongoMemoryReplSet;
|
22
|
-
|
51
|
+
prodMigrations?: {
|
52
|
+
down: (args: MigrateDownArgs) => Promise<void>;
|
53
|
+
name: string;
|
54
|
+
up: (args: MigrateUpArgs) => Promise<void>;
|
55
|
+
}[];
|
56
|
+
transactionOptions?: false | TransactionOptions;
|
23
57
|
/** The URL to connect to MongoDB or false to start payload and prevent connecting */
|
24
58
|
url: false | string;
|
25
59
|
}
|
26
|
-
export type MongooseAdapter =
|
60
|
+
export type MongooseAdapter = {
|
27
61
|
collections: {
|
28
62
|
[slug: string]: CollectionModel;
|
29
63
|
};
|
30
64
|
connection: Connection;
|
65
|
+
ensureIndexes: boolean;
|
31
66
|
globals: GlobalModel;
|
32
67
|
mongoMemoryServer: MongoMemoryReplSet;
|
68
|
+
prodMigrations?: {
|
69
|
+
down: (args: MigrateDownArgs) => Promise<void>;
|
70
|
+
name: string;
|
71
|
+
up: (args: MigrateUpArgs) => Promise<void>;
|
72
|
+
}[];
|
33
73
|
sessions: Record<number | string, ClientSession>;
|
34
74
|
versions: {
|
35
75
|
[slug: string]: CollectionModel;
|
36
76
|
};
|
37
|
-
};
|
77
|
+
} & Args & BaseDatabaseAdapter;
|
38
78
|
declare module 'payload' {
|
39
79
|
interface DatabaseAdapter extends Omit<BaseDatabaseAdapter, 'sessions'>, Omit<Args, 'migrationDir'> {
|
40
80
|
collections: {
|
41
81
|
[slug: string]: CollectionModel;
|
42
82
|
};
|
43
83
|
connection: Connection;
|
84
|
+
ensureIndexes: boolean;
|
44
85
|
globals: GlobalModel;
|
45
86
|
mongoMemoryServer: MongoMemoryReplSet;
|
87
|
+
prodMigrations?: {
|
88
|
+
down: (args: MigrateDownArgs) => Promise<void>;
|
89
|
+
name: string;
|
90
|
+
up: (args: MigrateUpArgs) => Promise<void>;
|
91
|
+
}[];
|
46
92
|
sessions: Record<number | string, ClientSession>;
|
47
93
|
transactionOptions: TransactionOptions;
|
94
|
+
updateOne: (args: {
|
95
|
+
options?: QueryOptions;
|
96
|
+
} & UpdateOneArgs) => Promise<Document>;
|
48
97
|
versions: {
|
49
98
|
[slug: string]: CollectionModel;
|
50
99
|
};
|
51
100
|
}
|
52
101
|
}
|
53
|
-
export declare function mongooseAdapter({ autoPluralization, connectOptions, disableIndexHints, migrationDir: migrationDirArg, mongoMemoryServer, transactionOptions, url, }: Args): DatabaseAdapterObj;
|
102
|
+
export declare function mongooseAdapter({ autoPluralization, connectOptions, disableIndexHints, ensureIndexes, migrationDir: migrationDirArg, mongoMemoryServer, prodMigrations, transactionOptions, url, }: Args): DatabaseAdapterObj;
|
54
103
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvF,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAW,aAAa,EAAE,MAAM,SAAS,CAAA;AAO9F,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAgC9F,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEhE,MAAM,WAAW,IAAI;IACnB,uFAAuF;IACvF,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAA;IAC5C,kCAAkC;IAClC,cAAc,CAAC,EAAE;QACf,4FAA4F;QAC5F,QAAQ,CAAC,EAAE,OAAO,CAAA;KACnB,GAAG,cAAc,CAAA;IAElB,gOAAgO;IACh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AC,mBAAmB,EAAE,UAAU,CAAC,EAC3C,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC;QAC5B,WAAW,EAAE;YACX,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;SAChC,CAAA;QACD,UAAU,EAAE,UAAU,CAAA;QACtB,aAAa,EAAE,OAAO,CAAA;QACtB,OAAO,EAAE,WAAW,CAAA;QACpB,iBAAiB,EAAE,kBAAkB,CAAA;QACrC,cAAc,CAAC,EAAE;YACf,IAAI,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;YAC9C,IAAI,EAAE,MAAM,CAAA;YACZ,EAAE,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;SAC3C,EAAE,CAAA;QACH,QAAQ,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,aAAa,CAAC,CAAA;QAChD,kBAAkB,EAAE,kBAAkB,CAAA;QACtC,SAAS,EAAE,CAAC,IAAI,EAAE;YAAE,OAAO,CAAC,EAAE,YAAY,CAAA;SAAE,GAAG,aAAa,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;QAClF,QAAQ,EAAE;YACR,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;SAChC,CAAA;KACF;CACF;AAED,wBAAgB,eAAe,CAAC,EAC9B,iBAAwB,EACxB,cAAc,EACd,iBAAyB,EACzB,aAAa,EACb,YAAY,EAAE,eAAe,EAC7B,iBAAiB,EACjB,cAAc,EACd,kBAAuB,EACvB,GAAG,GACJ,EAAE,IAAI,GAAG,kBAAkB,CA+D3B"}
|
package/dist/index.js
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
import fs from 'fs';
|
2
2
|
import mongoose from 'mongoose';
|
3
3
|
import path from 'path';
|
4
|
-
import { createDatabaseAdapter } from 'payload';
|
4
|
+
import { createDatabaseAdapter, defaultBeginTransaction } from 'payload';
|
5
5
|
import { connect } from './connect.js';
|
6
6
|
import { count } from './count.js';
|
7
|
+
import { countGlobalVersions } from './countGlobalVersions.js';
|
8
|
+
import { countVersions } from './countVersions.js';
|
7
9
|
import { create } from './create.js';
|
8
10
|
import { createGlobal } from './createGlobal.js';
|
9
11
|
import { createGlobalVersion } from './createGlobalVersion.js';
|
@@ -28,7 +30,8 @@ import { updateGlobal } from './updateGlobal.js';
|
|
28
30
|
import { updateGlobalVersion } from './updateGlobalVersion.js';
|
29
31
|
import { updateOne } from './updateOne.js';
|
30
32
|
import { updateVersion } from './updateVersion.js';
|
31
|
-
|
33
|
+
import { upsert } from './upsert.js';
|
34
|
+
export function mongooseAdapter({ autoPluralization = true, connectOptions, disableIndexHints = false, ensureIndexes, migrationDir: migrationDirArg, mongoMemoryServer, prodMigrations, transactionOptions = {}, url }) {
|
32
35
|
function adapter({ payload }) {
|
33
36
|
const migrationDir = findMigrationDir(migrationDirArg);
|
34
37
|
mongoose.set('strictQuery', false);
|
@@ -37,10 +40,10 @@ export function mongooseAdapter({ autoPluralization = true, connectOptions, disa
|
|
37
40
|
// Mongoose-specific
|
38
41
|
autoPluralization,
|
39
42
|
collections: {},
|
40
|
-
connectOptions: connectOptions || {},
|
41
43
|
connection: undefined,
|
42
|
-
|
44
|
+
connectOptions: connectOptions || {},
|
43
45
|
disableIndexHints,
|
46
|
+
ensureIndexes,
|
44
47
|
globals: undefined,
|
45
48
|
mongoMemoryServer,
|
46
49
|
sessions: {},
|
@@ -48,9 +51,12 @@ export function mongooseAdapter({ autoPluralization = true, connectOptions, disa
|
|
48
51
|
url,
|
49
52
|
versions: {},
|
50
53
|
// DatabaseAdapter
|
51
|
-
beginTransaction: transactionOptions ?
|
54
|
+
beginTransaction: transactionOptions === false ? defaultBeginTransaction() : beginTransaction,
|
52
55
|
commitTransaction,
|
53
56
|
connect,
|
57
|
+
count,
|
58
|
+
countGlobalVersions,
|
59
|
+
countVersions,
|
54
60
|
create,
|
55
61
|
createGlobal,
|
56
62
|
createGlobalVersion,
|
@@ -69,13 +75,16 @@ export function mongooseAdapter({ autoPluralization = true, connectOptions, disa
|
|
69
75
|
init,
|
70
76
|
migrateFresh,
|
71
77
|
migrationDir,
|
78
|
+
packageName: '@payloadcms/db-mongodb',
|
72
79
|
payload,
|
80
|
+
prodMigrations,
|
73
81
|
queryDrafts,
|
74
82
|
rollbackTransaction,
|
75
83
|
updateGlobal,
|
76
84
|
updateGlobalVersion,
|
77
85
|
updateOne,
|
78
|
-
updateVersion
|
86
|
+
updateVersion,
|
87
|
+
upsert
|
79
88
|
});
|
80
89
|
}
|
81
90
|
return {
|
@@ -102,7 +111,9 @@ export function mongooseAdapter({ autoPluralization = true, connectOptions, disa
|
|
102
111
|
const distDir = path.resolve(cwd, 'dist/migrations');
|
103
112
|
const relativeMigrations = path.resolve(cwd, 'migrations');
|
104
113
|
// Use arg if provided
|
105
|
-
if (migrationDir)
|
114
|
+
if (migrationDir) {
|
115
|
+
return migrationDir;
|
116
|
+
}
|
106
117
|
// Check other common locations
|
107
118
|
if (fs.existsSync(srcDir)) {
|
108
119
|
return srcDir;
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { TransactionOptions } from 'mongodb'\nimport type { MongoMemoryReplSet } from 'mongodb-memory-server'\nimport type { ClientSession, ConnectOptions, Connection } from 'mongoose'\nimport type { BaseDatabaseAdapter, DatabaseAdapterObj, Payload } from 'payload'\n\nimport fs from 'fs'\nimport mongoose from 'mongoose'\nimport path from 'path'\nimport { createDatabaseAdapter } from 'payload'\n\nimport type { CollectionModel, GlobalModel } from './types.js'\n\nimport { connect } from './connect.js'\nimport { count } from './count.js'\nimport { create } from './create.js'\nimport { createGlobal } from './createGlobal.js'\nimport { createGlobalVersion } from './createGlobalVersion.js'\nimport { createMigration } from './createMigration.js'\nimport { createVersion } from './createVersion.js'\nimport { deleteMany } from './deleteMany.js'\nimport { deleteOne } from './deleteOne.js'\nimport { deleteVersions } from './deleteVersions.js'\nimport { destroy } from './destroy.js'\nimport { find } from './find.js'\nimport { findGlobal } from './findGlobal.js'\nimport { findGlobalVersions } from './findGlobalVersions.js'\nimport { findOne } from './findOne.js'\nimport { findVersions } from './findVersions.js'\nimport { init } from './init.js'\nimport { migrateFresh } from './migrateFresh.js'\nimport { queryDrafts } from './queryDrafts.js'\nimport { beginTransaction } from './transactions/beginTransaction.js'\nimport { commitTransaction } from './transactions/commitTransaction.js'\nimport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nimport { updateGlobal } from './updateGlobal.js'\nimport { updateGlobalVersion } from './updateGlobalVersion.js'\nimport { updateOne } from './updateOne.js'\nimport { updateVersion } from './updateVersion.js'\n\nexport type { MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nexport interface Args {\n /** Set to false to disable auto-pluralization of collection names, Defaults to true */\n autoPluralization?: boolean\n /** Extra configuration options */\n connectOptions?: ConnectOptions & {\n /** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */\n useFacet?: boolean\n }\n /** Set to true to disable hinting to MongoDB to use 'id' as index. This is currently done when counting documents for pagination. Disabling this optimization might fix some problems with AWS DocumentDB. Defaults to false */\n disableIndexHints?: boolean\n migrationDir?: string\n /**\n * typed as any to avoid dependency\n */\n mongoMemoryServer?: MongoMemoryReplSet\n transactionOptions?: TransactionOptions | false\n /** The URL to connect to MongoDB or false to start payload and prevent connecting */\n url: false | string\n}\n\nexport type MongooseAdapter = BaseDatabaseAdapter &\n Args & {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n sessions: Record<number | string, ClientSession>\n versions: {\n [slug: string]: CollectionModel\n }\n }\n\ndeclare module 'payload' {\n export interface DatabaseAdapter\n extends Omit<BaseDatabaseAdapter, 'sessions'>,\n Omit<Args, 'migrationDir'> {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n sessions: Record<number | string, ClientSession>\n transactionOptions: TransactionOptions\n versions: {\n [slug: string]: CollectionModel\n }\n }\n}\n\nexport function mongooseAdapter({\n autoPluralization = true,\n connectOptions,\n disableIndexHints = false,\n migrationDir: migrationDirArg,\n mongoMemoryServer,\n transactionOptions = {},\n url,\n}: Args): DatabaseAdapterObj {\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(migrationDirArg)\n mongoose.set('strictQuery', false)\n\n return createDatabaseAdapter<MongooseAdapter>({\n name: 'mongoose',\n\n // Mongoose-specific\n autoPluralization,\n collections: {},\n connectOptions: connectOptions || {},\n connection: undefined,\n count,\n disableIndexHints,\n globals: undefined,\n mongoMemoryServer,\n sessions: {},\n transactionOptions: transactionOptions === false ? undefined : transactionOptions,\n url,\n versions: {},\n // DatabaseAdapter\n beginTransaction: transactionOptions ? beginTransaction : undefined,\n commitTransaction,\n connect,\n create,\n createGlobal,\n createGlobalVersion,\n createMigration,\n createVersion,\n defaultIDType: 'text',\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n init,\n migrateFresh,\n migrationDir,\n payload,\n queryDrafts,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n })\n }\n\n return {\n defaultIDType: 'text',\n init: adapter,\n }\n}\n\n/**\n * Attempt to find migrations directory.\n *\n * Checks for the following directories in order:\n * - `migrationDir` argument from Payload config\n * - `src/migrations`\n * - `dist/migrations`\n * - `migrations`\n *\n * Defaults to `src/migrations`\n *\n * @param migrationDir\n * @returns\n */\nfunction findMigrationDir(migrationDir?: string): string {\n const cwd = process.cwd()\n const srcDir = path.resolve(cwd, 'src/migrations')\n const distDir = path.resolve(cwd, 'dist/migrations')\n const relativeMigrations = path.resolve(cwd, 'migrations')\n\n // Use arg if provided\n if (migrationDir) return migrationDir\n\n // Check other common locations\n if (fs.existsSync(srcDir)) {\n return srcDir\n }\n\n if (fs.existsSync(distDir)) {\n return distDir\n }\n\n if (fs.existsSync(relativeMigrations)) {\n return relativeMigrations\n }\n\n return srcDir\n}\n"],"names":["fs","mongoose","path","createDatabaseAdapter","connect","count","create","createGlobal","createGlobalVersion","createMigration","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findOne","findVersions","init","migrateFresh","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateGlobal","updateGlobalVersion","updateOne","updateVersion","mongooseAdapter","autoPluralization","connectOptions","disableIndexHints","migrationDir","migrationDirArg","mongoMemoryServer","transactionOptions","url","adapter","payload","findMigrationDir","set","name","collections","connection","undefined","globals","sessions","versions","defaultIDType","cwd","process","srcDir","resolve","distDir","relativeMigrations","existsSync"],"mappings":"AAKA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,cAAc,WAAU;AAC/B,OAAOC,UAAU,OAAM;AACvB,SAASC,qBAAqB,QAAQ,UAAS;AAI/C,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,KAAK,QAAQ,aAAY;AAClC,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,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,qBAAqBtD,KAAKoD,OAAO,CAACH,KAAK;IAE7C,sBAAsB;IACtB,IAAIjB,cAAc,OAAOA;IAEzB,+BAA+B;IAC/B,IAAIlC,GAAGyD,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAIrD,GAAGyD,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAIvD,GAAGyD,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollationOptions, TransactionOptions } from 'mongodb'\nimport type { MongoMemoryReplSet } from 'mongodb-memory-server'\nimport type { ClientSession, Connection, ConnectOptions, QueryOptions } from 'mongoose'\nimport type { BaseDatabaseAdapter, DatabaseAdapterObj, Payload, UpdateOneArgs } from 'payload'\n\nimport fs from 'fs'\nimport mongoose from 'mongoose'\nimport path from 'path'\nimport { createDatabaseAdapter, defaultBeginTransaction } from 'payload'\n\nimport type { CollectionModel, GlobalModel, MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nimport { connect } from './connect.js'\nimport { count } from './count.js'\nimport { countGlobalVersions } from './countGlobalVersions.js'\nimport { countVersions } from './countVersions.js'\nimport { create } from './create.js'\nimport { createGlobal } from './createGlobal.js'\nimport { createGlobalVersion } from './createGlobalVersion.js'\nimport { createMigration } from './createMigration.js'\nimport { createVersion } from './createVersion.js'\nimport { deleteMany } from './deleteMany.js'\nimport { deleteOne } from './deleteOne.js'\nimport { deleteVersions } from './deleteVersions.js'\nimport { destroy } from './destroy.js'\nimport { find } from './find.js'\nimport { findGlobal } from './findGlobal.js'\nimport { findGlobalVersions } from './findGlobalVersions.js'\nimport { findOne } from './findOne.js'\nimport { findVersions } from './findVersions.js'\nimport { init } from './init.js'\nimport { migrateFresh } from './migrateFresh.js'\nimport { queryDrafts } from './queryDrafts.js'\nimport { beginTransaction } from './transactions/beginTransaction.js'\nimport { commitTransaction } from './transactions/commitTransaction.js'\nimport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nimport { updateGlobal } from './updateGlobal.js'\nimport { updateGlobalVersion } from './updateGlobalVersion.js'\nimport { updateOne } from './updateOne.js'\nimport { updateVersion } from './updateVersion.js'\nimport { upsert } from './upsert.js'\n\nexport type { MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nexport interface Args {\n /** Set to false to disable auto-pluralization of collection names, Defaults to true */\n autoPluralization?: boolean\n /**\n * If enabled, collation allows for language-specific rules for string comparison.\n * This configuration can include the following options:\n *\n * - `strength` (number): Comparison level (1: Primary, 2: Secondary, 3: Tertiary (default), 4: Quaternary, 5: Identical)\n * - `caseLevel` (boolean): Include case comparison at strength level 1 or 2.\n * - `caseFirst` (string): Sort order of case differences during tertiary level comparisons (\"upper\", \"lower\", \"off\").\n * - `numericOrdering` (boolean): Compare numeric strings as numbers.\n * - `alternate` (string): Consider whitespace and punctuation as base characters (\"non-ignorable\", \"shifted\").\n * - `maxVariable` (string): Characters considered ignorable when `alternate` is \"shifted\" (\"punct\", \"space\").\n * - `backwards` (boolean): Sort strings with diacritics from back of the string.\n * - `normalization` (boolean): Check if text requires normalization and perform normalization.\n *\n * Available on MongoDB version 3.4 and up.\n * The locale that gets passed is your current project's locale but defaults to \"en\".\n *\n * Example:\n * {\n * strength: 3\n * }\n *\n * Defaults to disabled.\n */\n collation?: Omit<CollationOptions, 'locale'>\n /** Extra configuration options */\n connectOptions?: {\n /** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */\n useFacet?: boolean\n } & ConnectOptions\n\n /** Set to true to disable hinting to MongoDB to use 'id' as index. This is currently done when counting documents for pagination. Disabling this optimization might fix some problems with AWS DocumentDB. Defaults to false */\n disableIndexHints?: boolean\n /**\n * Set to `true` to ensure that indexes are ready before completing connection.\n * NOTE: not recommended for production. This can slow down the initialization of Payload.\n */\n ensureIndexes?: boolean\n migrationDir?: string\n /**\n * typed as any to avoid dependency\n */\n mongoMemoryServer?: MongoMemoryReplSet\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n transactionOptions?: false | TransactionOptions\n /** The URL to connect to MongoDB or false to start payload and prevent connecting */\n url: false | string\n}\n\nexport type MongooseAdapter = {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n ensureIndexes: boolean\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n sessions: Record<number | string, ClientSession>\n versions: {\n [slug: string]: CollectionModel\n }\n} & Args &\n BaseDatabaseAdapter\n\ndeclare module 'payload' {\n export interface DatabaseAdapter\n extends Omit<BaseDatabaseAdapter, 'sessions'>,\n Omit<Args, 'migrationDir'> {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n ensureIndexes: boolean\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n sessions: Record<number | string, ClientSession>\n transactionOptions: TransactionOptions\n updateOne: (args: { options?: QueryOptions } & UpdateOneArgs) => Promise<Document>\n versions: {\n [slug: string]: CollectionModel\n }\n }\n}\n\nexport function mongooseAdapter({\n autoPluralization = true,\n connectOptions,\n disableIndexHints = false,\n ensureIndexes,\n migrationDir: migrationDirArg,\n mongoMemoryServer,\n prodMigrations,\n transactionOptions = {},\n url,\n}: Args): DatabaseAdapterObj {\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(migrationDirArg)\n mongoose.set('strictQuery', false)\n\n return createDatabaseAdapter<MongooseAdapter>({\n name: 'mongoose',\n\n // Mongoose-specific\n autoPluralization,\n collections: {},\n connection: undefined,\n connectOptions: connectOptions || {},\n disableIndexHints,\n ensureIndexes,\n globals: undefined,\n mongoMemoryServer,\n sessions: {},\n transactionOptions: transactionOptions === false ? undefined : transactionOptions,\n url,\n versions: {},\n // DatabaseAdapter\n beginTransaction: transactionOptions === false ? defaultBeginTransaction() : beginTransaction,\n commitTransaction,\n connect,\n count,\n countGlobalVersions,\n countVersions,\n create,\n createGlobal,\n createGlobalVersion,\n createMigration,\n createVersion,\n defaultIDType: 'text',\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n init,\n migrateFresh,\n migrationDir,\n packageName: '@payloadcms/db-mongodb',\n payload,\n prodMigrations,\n queryDrafts,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n upsert,\n })\n }\n\n return {\n defaultIDType: 'text',\n init: adapter,\n }\n}\n\n/**\n * Attempt to find migrations directory.\n *\n * Checks for the following directories in order:\n * - `migrationDir` argument from Payload config\n * - `src/migrations`\n * - `dist/migrations`\n * - `migrations`\n *\n * Defaults to `src/migrations`\n *\n * @param migrationDir\n * @returns\n */\nfunction findMigrationDir(migrationDir?: string): string {\n const cwd = process.cwd()\n const srcDir = path.resolve(cwd, 'src/migrations')\n const distDir = path.resolve(cwd, 'dist/migrations')\n const relativeMigrations = path.resolve(cwd, 'migrations')\n\n // Use arg if provided\n if (migrationDir) {\n return migrationDir\n }\n\n // Check other common locations\n if (fs.existsSync(srcDir)) {\n return srcDir\n }\n\n if (fs.existsSync(distDir)) {\n return distDir\n }\n\n if (fs.existsSync(relativeMigrations)) {\n return relativeMigrations\n }\n\n return srcDir\n}\n"],"names":["fs","mongoose","path","createDatabaseAdapter","defaultBeginTransaction","connect","count","countGlobalVersions","countVersions","create","createGlobal","createGlobalVersion","createMigration","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findOne","findVersions","init","migrateFresh","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateGlobal","updateGlobalVersion","updateOne","updateVersion","upsert","mongooseAdapter","autoPluralization","connectOptions","disableIndexHints","ensureIndexes","migrationDir","migrationDirArg","mongoMemoryServer","prodMigrations","transactionOptions","url","adapter","payload","findMigrationDir","set","name","collections","connection","undefined","globals","sessions","versions","defaultIDType","packageName","cwd","process","srcDir","resolve","distDir","relativeMigrations","existsSync"],"mappings":"AAKA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,cAAc,WAAU;AAC/B,OAAOC,UAAU,OAAM;AACvB,SAASC,qBAAqB,EAAEC,uBAAuB,QAAQ,UAAS;AAIxE,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,KAAK,QAAQ,aAAY;AAClC,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,mBAAmB,QAAQ,wCAAuC;AAC3E,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,aAAa,QAAQ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vC,GAAGgE,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAI5D,GAAGgE,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAI9D,GAAGgE,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
|
package/dist/init.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAA;AAgB9D,eAAO,MAAM,IAAI,EAAE,IAgFlB,CAAA"}
|
package/dist/init.js
CHANGED
@@ -1,10 +1,11 @@
|
|
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)=>{
|
@@ -14,7 +15,7 @@ export const init = function init() {
|
|
14
15
|
config: collection,
|
15
16
|
versions: true
|
16
17
|
});
|
17
|
-
const versionCollectionFields = buildVersionCollectionFields(collection);
|
18
|
+
const versionCollectionFields = buildVersionCollectionFields(this.payload.config, collection);
|
18
19
|
const versionSchema = buildSchema(this.payload.config, versionCollectionFields, {
|
19
20
|
disableUnique: true,
|
20
21
|
draftsEnabled: true,
|
@@ -30,24 +31,26 @@ 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.config);
|
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);
|
53
|
+
const versionGlobalFields = buildVersionGlobalFields(this.payload.config, global);
|
51
54
|
const versionSchema = buildSchema(this.payload.config, versionGlobalFields, {
|
52
55
|
disableUnique: true,
|
53
56
|
draftsEnabled: true,
|
@@ -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":["
|
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.config)\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.config, 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.config)\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.config, 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,C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AAI,CAACK,OAAO,CAACC,MAAM;IAEnD,IAAI,CAACD,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,CAACC,MAAM,EAAEiC,qBAAqB;gBAC1ExB,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"}
|
package/dist/migrateFresh.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import type {
|
1
|
+
{"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload'\nimport prompts from 'prompts'\n\nimport type { MongooseAdapter } from './index.js'\n\n/**\n * Drop the current database and run all migrate up functions\n */\nexport async function migrateFresh(\n this: MongooseAdapter,\n { forceAcceptWarning = false }: { forceAcceptWarning?: boolean },\n): Promise<void> {\n const { payload } = this\n\n if (!forceAcceptWarning) {\n const { confirm: acceptWarning } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: `WARNING: This will drop your database and run all migrations. Are you sure you want to proceed?`,\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!acceptWarning) {\n process.exit(0)\n }\n }\n\n payload.logger.info({\n msg: `Dropping database.`,\n })\n\n await this.connection.dropDatabase()\n\n const migrationFiles = await readMigrationFiles({ payload })\n payload.logger.debug({\n msg: `Found ${migrationFiles.length} migration files.`,\n })\n\n const req = { payload } as PayloadRequest\n\n // Run all migrate up\n for (const migration of migrationFiles) {\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n try {\n const start = Date.now()\n await initTransaction(req)\n await migration.up({ payload, req })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n batch: 1,\n },\n req,\n })\n\n await commitTransaction(req)\n\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({\n err,\n msg: `Error running migration ${migration.name}. Rolling back.`,\n })\n throw err\n }\n }\n}\n"],"names":["commitTransaction","initTransaction","killTransaction","readMigrationFiles","prompts","migrateFresh","forceAcceptWarning","payload","confirm","acceptWarning","name","type","initial","message","onCancel","process","exit","logger","info","msg","connection","dropDatabase","migrationFiles","debug","length","req","migration","start","Date","now","up","create","collection","data","batch","err","error"],"mappings":"AAEA,SAASA,iBAAiB,EAAEC,eAAe,EAAEC,eAAe,EAAEC,kBAAkB,QAAQ,UAAS;AACjG,OAAOC,aAAa,UAAS;AAI7B;;CAEC,GACD,OAAO,eAAeC,aAEpB,EAAEC,qBAAqB,KAAK,EAAoC;IAEhE,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IAExB,IAAI,CAACD,oBAAoB;QACvB,MAAM,EAAEE,SAASC,aAAa,EAAE,GAAG,MAAML,QACvC;YACEM,MAAM;YACNC,MAAM;YACNC,SAAS;YACTC,SAAS,CAAC,+FAA+F,CAAC;QAC5G,GACA;YACEC,UAAU;gBACRC,QAAQC,IAAI,CAAC;YACf;QACF;QAGF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
import type { SanitizedCollectionConfig, SanitizedConfig } from 'payload';
|
3
|
-
declare const buildCollectionSchema: (collection: SanitizedCollectionConfig, config: SanitizedConfig, schemaOptions?: {}) => Schema;
|
4
|
-
export default buildCollectionSchema;
|
3
|
+
export declare const buildCollectionSchema: (collection: SanitizedCollectionConfig, config: SanitizedConfig, 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,yBAAyB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;
|
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,yBAAyB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAQzE,eAAO,MAAM,qBAAqB,eACpB,yBAAyB,UAC7B,eAAe,yBAEtB,MAqCF,CAAA"}
|
@@ -1,7 +1,8 @@
|
|
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, config, schemaOptions = {})=>{
|
3
|
+
import { getBuildQueryPlugin } from '../queries/buildQuery.js';
|
4
|
+
import { buildSchema } from './buildSchema.js';
|
5
|
+
export const buildCollectionSchema = (collection, config, schemaOptions = {})=>{
|
5
6
|
const schema = buildSchema(config, collection.fields, {
|
6
7
|
draftsEnabled: Boolean(typeof collection?.versions === 'object' && collection.versions.drafts),
|
7
8
|
indexSortableFields: config.indexSortableFields,
|
@@ -11,6 +12,15 @@ const buildCollectionSchema = (collection, config, schemaOptions = {})=>{
|
|
11
12
|
...schemaOptions
|
12
13
|
}
|
13
14
|
});
|
15
|
+
if (Array.isArray(collection.upload.filenameCompoundIndex)) {
|
16
|
+
const indexDefinition = collection.upload.filenameCompoundIndex.reduce((acc, index)=>{
|
17
|
+
acc[index] = 1;
|
18
|
+
return acc;
|
19
|
+
}, {});
|
20
|
+
schema.index(indexDefinition, {
|
21
|
+
unique: true
|
22
|
+
});
|
23
|
+
}
|
14
24
|
if (config.indexSortableFields && collection.timestamps !== false) {
|
15
25
|
schema.index({
|
16
26
|
updatedAt: 1
|
@@ -24,8 +34,10 @@ const buildCollectionSchema = (collection, config, schemaOptions = {})=>{
|
|
24
34
|
}).plugin(getBuildQueryPlugin({
|
25
35
|
collectionSlug: collection.slug
|
26
36
|
}));
|
37
|
+
if (Object.keys(collection.joins).length > 0) {
|
38
|
+
schema.plugin(mongooseAggregatePaginate);
|
39
|
+
}
|
27
40
|
return schema;
|
28
41
|
};
|
29
|
-
export default buildCollectionSchema;
|
30
42
|
|
31
43
|
//# sourceMappingURL=buildCollectionSchema.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/models/buildCollectionSchema.ts"],"sourcesContent":["import type { PaginateOptions, Schema } from 'mongoose'\nimport type { SanitizedCollectionConfig, SanitizedConfig } from 'payload'\n\nimport paginate from 'mongoose-paginate-v2'\n\nimport getBuildQueryPlugin from '../queries/buildQuery.js'\nimport buildSchema from './buildSchema.js'\n\
|
1
|
+
{"version":3,"sources":["../../src/models/buildCollectionSchema.ts"],"sourcesContent":["import type { PaginateOptions, Schema } from 'mongoose'\nimport type { SanitizedCollectionConfig, SanitizedConfig } 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 config: SanitizedConfig,\n schemaOptions = {},\n): Schema => {\n const schema = buildSchema(config, collection.fields, {\n draftsEnabled: Boolean(typeof collection?.versions === 'object' && collection.versions.drafts),\n indexSortableFields: 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 (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","config","schemaOptions","schema","fields","draftsEnabled","Boolean","versions","drafts","indexSortableFields","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,QACAC,gBAAgB,CAAC,CAAC;IAElB,MAAMC,SAASL,YAAYG,QAAQD,WAAWI,MAAM,EAAE;QACpDC,eAAeC,QAAQ,OAAON,YAAYO,aAAa,YAAYP,WAAWO,QAAQ,CAACC,MAAM;QAC7FC,qBAAqBR,OAAOQ,mBAAmB;QAC/CC,SAAS;YACPC,UAAU;YACVC,YAAYZ,WAAWY,UAAU,KAAK;YACtC,GAAGV,aAAa;QAClB;IACF;IAEA,IAAIW,MAAMC,OAAO,CAACd,WAAWe,MAAM,CAACC,qBAAqB,GAAG;QAC1D,MAAMC,kBAAqCjB,WAAWe,MAAM,CAACC,qBAAqB,CAACE,MAAM,CACvF,CAACC,KAAKC;YACJD,GAAG,CAACC,MAAM,GAAG;YACb,OAAOD;QACT,GACA,CAAC;QAGHhB,OAAOiB,KAAK,CAACH,iBAAiB;YAAEI,QAAQ;QAAK;IAC/C;IAEA,IAAIpB,OAAOQ,mBAAmB,IAAIT,WAAWY,UAAU,KAAK,OAAO;QACjET,OAAOiB,KAAK,CAAC;YAAEE,WAAW;QAAE;QAC5BnB,OAAOiB,KAAK,CAAC;YAAEG,WAAW;QAAE;IAC9B;IAEApB,OACGqB,MAAM,CAAuB5B,UAAU;QAAE6B,mBAAmB;IAAK,GACjED,MAAM,CAAC3B,oBAAoB;QAAE6B,gBAAgB1B,WAAW2B,IAAI;IAAC;IAEhE,IAAIC,OAAOC,IAAI,CAAC7B,WAAW8B,KAAK,EAAEC,MAAM,GAAG,GAAG;QAC5C5B,OAAOqB,MAAM,CAAC7B;IAChB;IAEA,OAAOQ;AACT,EAAC"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import mongoose from 'mongoose';
|
2
|
-
import getBuildQueryPlugin from '../queries/buildQuery.js';
|
3
|
-
import buildSchema from './buildSchema.js';
|
2
|
+
import { getBuildQueryPlugin } from '../queries/buildQuery.js';
|
3
|
+
import { buildSchema } from './buildSchema.js';
|
4
4
|
export const buildGlobalModel = (config)=>{
|
5
5
|
if (config.globals && config.globals.length > 0) {
|
6
6
|
const globalsSchema = new mongoose.Schema({}, {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/models/buildGlobalModel.ts"],"sourcesContent":["import type { SanitizedConfig } 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 = (config: SanitizedConfig): GlobalModel | null => {\n if (config.globals && 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(config.globals).forEach((globalConfig) => {\n const globalSchema = buildSchema(config, 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","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,
|
1
|
+
{"version":3,"sources":["../../src/models/buildGlobalModel.ts"],"sourcesContent":["import type { SanitizedConfig } 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 = (config: SanitizedConfig): GlobalModel | null => {\n if (config.globals && 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(config.globals).forEach((globalConfig) => {\n const globalSchema = buildSchema(config, 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","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,OAAOC,OAAO,IAAID,OAAOC,OAAO,CAACC,MAAM,GAAG,GAAG;QAC/C,MAAMC,gBAAgB,IAAIP,SAASQ,MAAM,CACvC,CAAC,GACD;YAAEC,kBAAkB;YAAcC,UAAU;YAAOC,YAAY;QAAK;QAGtEJ,cAAcK,MAAM,CAACX;QAErB,MAAMY,UAAUb,SAASc,KAAK,CAAC,WAAWP,eAAe;QAEzDQ,OAAOC,MAAM,CAACZ,OAAOC,OAAO,EAAEY,OAAO,CAAC,CAACC;YACrC,MAAMC,eAAejB,YAAYE,QAAQc,aAAaE,MAAM,EAAE;gBAC5DC,SAAS;oBACPX,UAAU;gBACZ;YACF;YACAG,QAAQS,aAAa,CAACJ,aAAaK,IAAI,EAAEJ;QAC3C;QAEA,OAAON;IACT;IAEA,OAAO;AACT,EAAC"}
|
@@ -7,6 +7,5 @@ export type BuildSchemaOptions = {
|
|
7
7
|
indexSortableFields?: boolean;
|
8
8
|
options?: SchemaOptions;
|
9
9
|
};
|
10
|
-
declare const buildSchema: (config: SanitizedConfig, configFields: Field[], buildSchemaOptions?: BuildSchemaOptions) => Schema;
|
11
|
-
export default buildSchema;
|
10
|
+
export declare const buildSchema: (config: SanitizedConfig, 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":"
|
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;AACtF,OAAO,KAAK,EASV,KAAK,EAWL,eAAe,EAQhB,MAAM,SAAS,CAAA;AAWhB,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,WACd,eAAe,gBACT,KAAK,EAAE,uBACD,kBAAkB,KACrC,MAmCF,CAAA"}
|