@payloadcms/db-mongodb 1.0.0-beta.0 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -15
- package/src/index.ts +117 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/db-mongodb",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
4
|
"description": "The officially supported MongoDB database adapter for Payload",
|
|
5
5
|
"repository": "https://github.com/payloadcms/payload",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,13 +10,8 @@
|
|
|
10
10
|
"name": "Payload",
|
|
11
11
|
"url": "https://payloadcms.com"
|
|
12
12
|
},
|
|
13
|
-
"main": "./
|
|
14
|
-
"types": "./
|
|
15
|
-
"scripts": {
|
|
16
|
-
"build": "pnpm build:swc && pnpm build:types",
|
|
17
|
-
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
|
18
|
-
"build:types": "tsc --emitDeclarationOnly --outDir dist"
|
|
19
|
-
},
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
20
15
|
"dependencies": {
|
|
21
16
|
"bson-objectid": "2.0.4",
|
|
22
17
|
"deepmerge": "4.3.1",
|
|
@@ -27,17 +22,20 @@
|
|
|
27
22
|
"uuid": "9.0.0"
|
|
28
23
|
},
|
|
29
24
|
"devDependencies": {
|
|
30
|
-
"@payloadcms/eslint-config": "workspace:*",
|
|
31
25
|
"@types/mongoose-aggregate-paginate-v2": "1.0.9",
|
|
32
26
|
"mongodb-memory-server": "8.13.0",
|
|
33
|
-
"payload": "
|
|
27
|
+
"payload": "2.0.0-beta.1",
|
|
28
|
+
"@payloadcms/eslint-config": "0.0.1"
|
|
34
29
|
},
|
|
35
30
|
"publishConfig": {
|
|
36
|
-
"
|
|
37
|
-
"registry": "https://registry.npmjs.org/",
|
|
38
|
-
"types": "./dist/index.d.ts"
|
|
31
|
+
"registry": "https://registry.npmjs.org/"
|
|
39
32
|
},
|
|
40
33
|
"files": [
|
|
41
34
|
"dist"
|
|
42
|
-
]
|
|
43
|
-
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "pnpm build:swc && pnpm build:types",
|
|
38
|
+
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
|
39
|
+
"build:types": "tsc --emitDeclarationOnly --outDir dist"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { ClientSession, ConnectOptions, Connection } from 'mongoose'
|
|
2
|
+
import type { Payload } from 'payload'
|
|
3
|
+
import type { DatabaseAdapter } from 'payload/database'
|
|
4
|
+
|
|
5
|
+
import mongoose from 'mongoose'
|
|
6
|
+
import { createDatabaseAdapter } from 'payload/database'
|
|
7
|
+
import { createMigration } from 'payload/database'
|
|
8
|
+
|
|
9
|
+
import type { CollectionModel, GlobalModel } from './types'
|
|
10
|
+
|
|
11
|
+
import { connect } from './connect'
|
|
12
|
+
import { create } from './create'
|
|
13
|
+
import { createGlobal } from './createGlobal'
|
|
14
|
+
import { createGlobalVersion } from './createGlobalVersion'
|
|
15
|
+
import { createVersion } from './createVersion'
|
|
16
|
+
import { deleteMany } from './deleteMany'
|
|
17
|
+
import { deleteOne } from './deleteOne'
|
|
18
|
+
import { deleteVersions } from './deleteVersions'
|
|
19
|
+
import { destroy } from './destroy'
|
|
20
|
+
import { find } from './find'
|
|
21
|
+
import { findGlobal } from './findGlobal'
|
|
22
|
+
import { findGlobalVersions } from './findGlobalVersions'
|
|
23
|
+
import { findOne } from './findOne'
|
|
24
|
+
import { findVersions } from './findVersions'
|
|
25
|
+
import { init } from './init'
|
|
26
|
+
import { queryDrafts } from './queryDrafts'
|
|
27
|
+
import { beginTransaction } from './transactions/beginTransaction'
|
|
28
|
+
import { commitTransaction } from './transactions/commitTransaction'
|
|
29
|
+
import { rollbackTransaction } from './transactions/rollbackTransaction'
|
|
30
|
+
import { updateGlobal } from './updateGlobal'
|
|
31
|
+
import { updateGlobalVersion } from './updateGlobalVersion'
|
|
32
|
+
import { updateOne } from './updateOne'
|
|
33
|
+
import { updateVersion } from './updateVersion'
|
|
34
|
+
import { webpack } from './webpack'
|
|
35
|
+
|
|
36
|
+
export interface Args {
|
|
37
|
+
/** Set to false to disable auto-pluralization of collection names, Defaults to true */
|
|
38
|
+
autoPluralization?: boolean
|
|
39
|
+
/** Extra configuration options */
|
|
40
|
+
connectOptions?: ConnectOptions & {
|
|
41
|
+
/** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */
|
|
42
|
+
useFacet?: boolean
|
|
43
|
+
}
|
|
44
|
+
migrationDir?: string
|
|
45
|
+
/** The URL to connect to MongoDB or false to start payload and prevent connecting */
|
|
46
|
+
url: false | string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type MongooseAdapter = DatabaseAdapter &
|
|
50
|
+
Args & {
|
|
51
|
+
collections: {
|
|
52
|
+
[slug: string]: CollectionModel
|
|
53
|
+
}
|
|
54
|
+
connection: Connection
|
|
55
|
+
globals: GlobalModel
|
|
56
|
+
mongoMemoryServer: any
|
|
57
|
+
sessions: Record<number | string, ClientSession>
|
|
58
|
+
versions: {
|
|
59
|
+
[slug: string]: CollectionModel
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
type MongooseAdapterResult = (args: { payload: Payload }) => MongooseAdapter
|
|
64
|
+
|
|
65
|
+
export function mongooseAdapter({
|
|
66
|
+
autoPluralization = true,
|
|
67
|
+
connectOptions,
|
|
68
|
+
migrationDir,
|
|
69
|
+
url,
|
|
70
|
+
}: Args): MongooseAdapterResult {
|
|
71
|
+
function adapter({ payload }: { payload: Payload }) {
|
|
72
|
+
mongoose.set('strictQuery', false)
|
|
73
|
+
|
|
74
|
+
return createDatabaseAdapter<MongooseAdapter>({
|
|
75
|
+
autoPluralization,
|
|
76
|
+
beginTransaction,
|
|
77
|
+
collections: {},
|
|
78
|
+
commitTransaction,
|
|
79
|
+
connect,
|
|
80
|
+
connectOptions: connectOptions || {},
|
|
81
|
+
connection: undefined,
|
|
82
|
+
create,
|
|
83
|
+
createGlobal,
|
|
84
|
+
createGlobalVersion,
|
|
85
|
+
createMigration,
|
|
86
|
+
createVersion,
|
|
87
|
+
defaultIDType: 'text',
|
|
88
|
+
deleteMany,
|
|
89
|
+
deleteOne,
|
|
90
|
+
deleteVersions,
|
|
91
|
+
destroy,
|
|
92
|
+
find,
|
|
93
|
+
findGlobal,
|
|
94
|
+
findGlobalVersions,
|
|
95
|
+
findOne,
|
|
96
|
+
findVersions,
|
|
97
|
+
globals: undefined,
|
|
98
|
+
init,
|
|
99
|
+
...(migrationDir && { migrationDir }),
|
|
100
|
+
name: 'mongoose',
|
|
101
|
+
mongoMemoryServer: undefined,
|
|
102
|
+
payload,
|
|
103
|
+
queryDrafts,
|
|
104
|
+
rollbackTransaction,
|
|
105
|
+
sessions: {},
|
|
106
|
+
updateGlobal,
|
|
107
|
+
updateGlobalVersion,
|
|
108
|
+
updateOne,
|
|
109
|
+
updateVersion,
|
|
110
|
+
url,
|
|
111
|
+
versions: {},
|
|
112
|
+
webpack,
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return adapter
|
|
117
|
+
}
|