@payloadcms/db-mongodb 3.0.0-alpha.62 → 3.0.0-alpha.64

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