@payloadcms/db-mongodb 3.0.0-beta.9 → 3.0.0-canary.2077da8
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/count.d.ts +3 -0
- package/dist/count.d.ts.map +1 -0
- package/dist/count.js +33 -0
- package/dist/count.js.map +1 -0
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +13 -27
- package/dist/createMigration.js.map +1 -1
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +1 -0
- package/dist/init.js.map +1 -1
- package/dist/migrateFresh.js.map +1 -1
- package/{predefinedMigrations → dist/predefinedMigrations}/versions-v1-v2.js +3 -1
- package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -0
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +7 -5
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +14 -11
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +1 -1
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +5 -1
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.js.map +1 -1
- package/package.json +18 -23
- package/src/index.ts +0 -198
package/src/index.ts
DELETED
@@ -1,198 +0,0 @@
|
|
1
|
-
import type { TransactionOptions } from 'mongodb'
|
2
|
-
import type { MongoMemoryReplSet } from 'mongodb-memory-server'
|
3
|
-
import type { ClientSession, ConnectOptions, Connection } from 'mongoose'
|
4
|
-
import type { Payload } from 'payload'
|
5
|
-
import type { BaseDatabaseAdapter, DatabaseAdapterObj } from 'payload/database'
|
6
|
-
|
7
|
-
import fs from 'fs'
|
8
|
-
import mongoose from 'mongoose'
|
9
|
-
import path from 'path'
|
10
|
-
import { createDatabaseAdapter } from 'payload/database'
|
11
|
-
|
12
|
-
import type { CollectionModel, GlobalModel } from './types.js'
|
13
|
-
|
14
|
-
import { connect } from './connect.js'
|
15
|
-
import { create } from './create.js'
|
16
|
-
import { createGlobal } from './createGlobal.js'
|
17
|
-
import { createGlobalVersion } from './createGlobalVersion.js'
|
18
|
-
import { createMigration } from './createMigration.js'
|
19
|
-
import { createVersion } from './createVersion.js'
|
20
|
-
import { deleteMany } from './deleteMany.js'
|
21
|
-
import { deleteOne } from './deleteOne.js'
|
22
|
-
import { deleteVersions } from './deleteVersions.js'
|
23
|
-
import { destroy } from './destroy.js'
|
24
|
-
import { find } from './find.js'
|
25
|
-
import { findGlobal } from './findGlobal.js'
|
26
|
-
import { findGlobalVersions } from './findGlobalVersions.js'
|
27
|
-
import { findOne } from './findOne.js'
|
28
|
-
import { findVersions } from './findVersions.js'
|
29
|
-
import { init } from './init.js'
|
30
|
-
import { migrateFresh } from './migrateFresh.js'
|
31
|
-
import { queryDrafts } from './queryDrafts.js'
|
32
|
-
import { beginTransaction } from './transactions/beginTransaction.js'
|
33
|
-
import { commitTransaction } from './transactions/commitTransaction.js'
|
34
|
-
import { rollbackTransaction } from './transactions/rollbackTransaction.js'
|
35
|
-
import { updateGlobal } from './updateGlobal.js'
|
36
|
-
import { updateGlobalVersion } from './updateGlobalVersion.js'
|
37
|
-
import { updateOne } from './updateOne.js'
|
38
|
-
import { updateVersion } from './updateVersion.js'
|
39
|
-
|
40
|
-
export type { MigrateDownArgs, MigrateUpArgs } from './types.js'
|
41
|
-
|
42
|
-
export interface Args {
|
43
|
-
/** Set to false to disable auto-pluralization of collection names, Defaults to true */
|
44
|
-
autoPluralization?: boolean
|
45
|
-
/** Extra configuration options */
|
46
|
-
connectOptions?: ConnectOptions & {
|
47
|
-
/** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */
|
48
|
-
useFacet?: boolean
|
49
|
-
}
|
50
|
-
/** 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 */
|
51
|
-
disableIndexHints?: boolean
|
52
|
-
migrationDir?: string
|
53
|
-
/**
|
54
|
-
* typed as any to avoid dependency
|
55
|
-
*/
|
56
|
-
mongoMemoryServer?: MongoMemoryReplSet
|
57
|
-
transactionOptions?: TransactionOptions | false
|
58
|
-
/** The URL to connect to MongoDB or false to start payload and prevent connecting */
|
59
|
-
url: false | string
|
60
|
-
}
|
61
|
-
|
62
|
-
export type MongooseAdapter = BaseDatabaseAdapter &
|
63
|
-
Args & {
|
64
|
-
collections: {
|
65
|
-
[slug: string]: CollectionModel
|
66
|
-
}
|
67
|
-
connection: Connection
|
68
|
-
globals: GlobalModel
|
69
|
-
mongoMemoryServer: MongoMemoryReplSet
|
70
|
-
sessions: Record<number | string, ClientSession>
|
71
|
-
versions: {
|
72
|
-
[slug: string]: CollectionModel
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
declare module 'payload' {
|
77
|
-
export interface DatabaseAdapter
|
78
|
-
extends Omit<BaseDatabaseAdapter, 'sessions'>,
|
79
|
-
Omit<Args, 'migrationDir'> {
|
80
|
-
collections: {
|
81
|
-
[slug: string]: CollectionModel
|
82
|
-
}
|
83
|
-
connection: Connection
|
84
|
-
globals: GlobalModel
|
85
|
-
mongoMemoryServer: MongoMemoryReplSet
|
86
|
-
sessions: Record<number | string, ClientSession>
|
87
|
-
transactionOptions: TransactionOptions
|
88
|
-
versions: {
|
89
|
-
[slug: string]: CollectionModel
|
90
|
-
}
|
91
|
-
}
|
92
|
-
}
|
93
|
-
|
94
|
-
export function mongooseAdapter({
|
95
|
-
autoPluralization = true,
|
96
|
-
connectOptions,
|
97
|
-
disableIndexHints = false,
|
98
|
-
migrationDir: migrationDirArg,
|
99
|
-
mongoMemoryServer,
|
100
|
-
transactionOptions = {},
|
101
|
-
url,
|
102
|
-
}: Args): DatabaseAdapterObj {
|
103
|
-
function adapter({ payload }: { payload: Payload }) {
|
104
|
-
const migrationDir = findMigrationDir(migrationDirArg)
|
105
|
-
mongoose.set('strictQuery', false)
|
106
|
-
|
107
|
-
return createDatabaseAdapter<MongooseAdapter>({
|
108
|
-
name: 'mongoose',
|
109
|
-
|
110
|
-
// Mongoose-specific
|
111
|
-
autoPluralization,
|
112
|
-
collections: {},
|
113
|
-
connectOptions: connectOptions || {},
|
114
|
-
connection: undefined,
|
115
|
-
disableIndexHints,
|
116
|
-
globals: undefined,
|
117
|
-
mongoMemoryServer,
|
118
|
-
sessions: {},
|
119
|
-
transactionOptions: transactionOptions === false ? undefined : transactionOptions,
|
120
|
-
url,
|
121
|
-
versions: {},
|
122
|
-
|
123
|
-
// DatabaseAdapter
|
124
|
-
beginTransaction: transactionOptions ? beginTransaction : undefined,
|
125
|
-
commitTransaction,
|
126
|
-
connect,
|
127
|
-
create,
|
128
|
-
createGlobal,
|
129
|
-
createGlobalVersion,
|
130
|
-
createMigration,
|
131
|
-
createVersion,
|
132
|
-
defaultIDType: 'text',
|
133
|
-
deleteMany,
|
134
|
-
deleteOne,
|
135
|
-
deleteVersions,
|
136
|
-
destroy,
|
137
|
-
find,
|
138
|
-
findGlobal,
|
139
|
-
findGlobalVersions,
|
140
|
-
findOne,
|
141
|
-
findVersions,
|
142
|
-
init,
|
143
|
-
migrateFresh,
|
144
|
-
migrationDir,
|
145
|
-
payload,
|
146
|
-
queryDrafts,
|
147
|
-
rollbackTransaction,
|
148
|
-
updateGlobal,
|
149
|
-
updateGlobalVersion,
|
150
|
-
updateOne,
|
151
|
-
updateVersion,
|
152
|
-
})
|
153
|
-
}
|
154
|
-
|
155
|
-
return {
|
156
|
-
defaultIDType: 'text',
|
157
|
-
init: adapter,
|
158
|
-
}
|
159
|
-
}
|
160
|
-
|
161
|
-
/**
|
162
|
-
* Attempt to find migrations directory.
|
163
|
-
*
|
164
|
-
* Checks for the following directories in order:
|
165
|
-
* - `migrationDir` argument from Payload config
|
166
|
-
* - `src/migrations`
|
167
|
-
* - `dist/migrations`
|
168
|
-
* - `migrations`
|
169
|
-
*
|
170
|
-
* Defaults to `src/migrations`
|
171
|
-
*
|
172
|
-
* @param migrationDir
|
173
|
-
* @returns
|
174
|
-
*/
|
175
|
-
function findMigrationDir(migrationDir?: string): string {
|
176
|
-
const cwd = process.cwd()
|
177
|
-
const srcDir = path.resolve(cwd, 'src/migrations')
|
178
|
-
const distDir = path.resolve(cwd, 'dist/migrations')
|
179
|
-
const relativeMigrations = path.resolve(cwd, 'migrations')
|
180
|
-
|
181
|
-
// Use arg if provided
|
182
|
-
if (migrationDir) return migrationDir
|
183
|
-
|
184
|
-
// Check other common locations
|
185
|
-
if (fs.existsSync(srcDir)) {
|
186
|
-
return srcDir
|
187
|
-
}
|
188
|
-
|
189
|
-
if (fs.existsSync(distDir)) {
|
190
|
-
return distDir
|
191
|
-
}
|
192
|
-
|
193
|
-
if (fs.existsSync(relativeMigrations)) {
|
194
|
-
return relativeMigrations
|
195
|
-
}
|
196
|
-
|
197
|
-
return srcDir
|
198
|
-
}
|