Compare commits
121 Commits
v3.0.0-alp
...
v3.0.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40696ddea7 | ||
|
|
38d2dc8c8e | ||
|
|
69346c5b3e | ||
|
|
a2aa527f50 | ||
|
|
b2ae40c8c8 | ||
|
|
11498dcc7f | ||
|
|
140d5242cf | ||
|
|
e3dff56479 | ||
|
|
0fb7666b97 | ||
|
|
5c06de6abc | ||
|
|
582a609d27 | ||
|
|
ec3d25e64e | ||
|
|
740c7510ea | ||
|
|
c9f6c707ac | ||
|
|
667eee07b1 | ||
|
|
deba38ab60 | ||
|
|
25e44e54fb | ||
|
|
62a2341ab4 | ||
|
|
53b465b7bb | ||
|
|
fc6a3282ad | ||
|
|
cecd1ccc96 | ||
|
|
439987c149 | ||
|
|
61279ac119 | ||
|
|
ca2fbf5cdf | ||
|
|
d3129224bd | ||
|
|
57625b26c9 | ||
|
|
e345009e0a | ||
|
|
41f5071d7f | ||
|
|
623969be82 | ||
|
|
d106037f42 | ||
|
|
a9f1b3eea9 | ||
|
|
a1f1067063 | ||
|
|
f57dda5d09 | ||
|
|
93acb8b163 | ||
|
|
4f32ab4421 | ||
|
|
c52736372a | ||
|
|
eca11bc064 | ||
|
|
093fd2d638 | ||
|
|
194fb44fb5 | ||
|
|
0c032d69ee | ||
|
|
b2219d879f | ||
|
|
304cf9d797 | ||
|
|
29963a04fc | ||
|
|
dff80d8276 | ||
|
|
f33bb0d73f | ||
|
|
be09dd41fa | ||
|
|
36b12b645b | ||
|
|
bea15771b9 | ||
|
|
8c2cbce4a4 | ||
|
|
9674f4e739 | ||
|
|
137952af73 | ||
|
|
66dcb1020a | ||
|
|
829d19dfc2 | ||
|
|
c73159d2d0 | ||
|
|
4159fae8c9 | ||
|
|
bff045fff2 | ||
|
|
3090e7c163 | ||
|
|
38798aec73 | ||
|
|
bc7a69044b | ||
|
|
ee6512567e | ||
|
|
1b7ded4560 | ||
|
|
e9abe63b47 | ||
|
|
b70bf81d6c | ||
|
|
410fddbf7f | ||
|
|
c0c9026da6 | ||
|
|
f76e534b64 | ||
|
|
468148ceb2 | ||
|
|
cc69cac29e | ||
|
|
19d2a4d1cd | ||
|
|
a7dcdc8df2 | ||
|
|
7815d5ac5d | ||
|
|
23051db54a | ||
|
|
f51434880f | ||
|
|
87d5b4d3af | ||
|
|
dd335ac75b | ||
|
|
16d5e5f906 | ||
|
|
42114a3680 | ||
|
|
e7adaecb0f | ||
|
|
9818f3df46 | ||
|
|
ca832a01cb | ||
|
|
aaa2b204ba | ||
|
|
78bf9e5993 | ||
|
|
8be0296fc1 | ||
|
|
26cd741c04 | ||
|
|
bf655b3327 | ||
|
|
1793b37adc | ||
|
|
d0ffe85abb | ||
|
|
f9f7dcfc58 | ||
|
|
f06257e7ff | ||
|
|
e490f0bce6 | ||
|
|
770c7173ec | ||
|
|
661ab4867b | ||
|
|
9ee3b5aae6 | ||
|
|
d202256c30 | ||
|
|
b8856d4ef7 | ||
|
|
e1294ac210 | ||
|
|
b0edd2d137 | ||
|
|
0d0e9bc953 | ||
|
|
2576291d9f | ||
|
|
d2aab87faa | ||
|
|
c2509b462c | ||
|
|
0e378be769 | ||
|
|
2785eaab21 | ||
|
|
8a10fd1547 | ||
|
|
8f8ed817fb | ||
|
|
7a150254fe | ||
|
|
9612a4a781 | ||
|
|
249b233dc2 | ||
|
|
c4d4a9b47b | ||
|
|
a55e991bfa | ||
|
|
610276f66b | ||
|
|
de99aabf7f | ||
|
|
40a0a0083f | ||
|
|
56ecd2ac14 | ||
|
|
4617d58b6a | ||
|
|
98aeff2f3e | ||
|
|
f2239decca | ||
|
|
36bd25a9cc | ||
|
|
933ae663f0 | ||
|
|
a08674f708 | ||
|
|
7fe0855932 |
@@ -9,3 +9,4 @@
|
||||
**/node_modules
|
||||
**/temp
|
||||
**/docs/**
|
||||
tsconfig.json
|
||||
|
||||
8
.vscode/launch.json
vendored
8
.vscode/launch.json
vendored
@@ -3,13 +3,7 @@
|
||||
// Hover to view descriptions of existing attributes.
|
||||
"configurations": [
|
||||
{
|
||||
"command": "pnpm dev",
|
||||
"name": "Run Dev 3.0",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
},
|
||||
{
|
||||
"command": "pnpm run dev _community",
|
||||
"command": "pnpm run dev _community -- --no-turbo",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"name": "Run Dev Community",
|
||||
"request": "launch",
|
||||
|
||||
17
app/(payload)/admin/[[...segments]]/not-found.tsx
Normal file
17
app/(payload)/admin/[[...segments]]/not-found.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
||||
import config from '@payload-config'
|
||||
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
|
||||
import { NotFoundView } from '@payloadcms/next/views/NotFound/index.js'
|
||||
|
||||
type Args = {
|
||||
params: {
|
||||
segments: string[]
|
||||
}
|
||||
searchParams: {
|
||||
[key: string]: string | string[]
|
||||
}
|
||||
}
|
||||
|
||||
const NotFound = ({ params, searchParams }: Args) => NotFoundView({ config, params, searchParams })
|
||||
|
||||
export default NotFound
|
||||
@@ -1,7 +1,7 @@
|
||||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
||||
import config from '@payload-config'
|
||||
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
|
||||
import { RootPage, generatePageMetadata } from '@payloadcms/next/views/Root/index'
|
||||
import { RootPage, generatePageMetadata } from '@payloadcms/next/views/Root/index.js'
|
||||
|
||||
type Args = {
|
||||
params: {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
||||
/* DO NOT MODIFY it because it could be re-written at any time. */
|
||||
import config from '@payload-config'
|
||||
import { REST_DELETE, REST_GET, REST_PATCH, REST_POST } from '@payloadcms/next/routes'
|
||||
import { REST_DELETE, REST_GET, REST_PATCH, REST_POST } from '@payloadcms/next/routes/index.js'
|
||||
|
||||
export const GET = REST_GET(config)
|
||||
export const POST = REST_POST(config)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
||||
/* DO NOT MODIFY it because it could be re-written at any time. */
|
||||
import config from '@payload-config'
|
||||
import { GET_STATIC_FILE } from '@payloadcms/next/routes'
|
||||
import { GET_STATIC_FILE } from '@payloadcms/next/routes/index.js'
|
||||
|
||||
export const GET = GET_STATIC_FILE(config)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
||||
/* DO NOT MODIFY it because it could be re-written at any time. */
|
||||
import config from '@payload-config'
|
||||
import { GRAPHQL_PLAYGROUND_GET } from '@payloadcms/next/routes'
|
||||
import { GRAPHQL_PLAYGROUND_GET } from '@payloadcms/next/routes/index.js'
|
||||
|
||||
export const GET = GRAPHQL_PLAYGROUND_GET(config)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
||||
/* DO NOT MODIFY it because it could be re-written at any time. */
|
||||
import config from '@payload-config'
|
||||
import { GRAPHQL_POST } from '@payloadcms/next/routes'
|
||||
import { GRAPHQL_POST } from '@payloadcms/next/routes/index.js'
|
||||
|
||||
export const POST = GRAPHQL_POST(config)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
||||
import configPromise from '@payload-config'
|
||||
import { RootLayout } from '@payloadcms/next/layouts/Root/index'
|
||||
import { RootLayout } from '@payloadcms/next/layouts/Root/index.js'
|
||||
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
|
||||
import React from 'react'
|
||||
|
||||
|
||||
@@ -22,4 +22,4 @@ const customJestConfig = {
|
||||
}
|
||||
|
||||
// module.exports = createJestConfig(customJestConfig)
|
||||
module.exports = customJestConfig
|
||||
export default customJestConfig
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
const { withPayload } = require('./packages/next/src/withPayload')
|
||||
const withBundleAnalyzer = require('@next/bundle-analyzer')({
|
||||
enabled: process.env.ANALYZE === 'true',
|
||||
})
|
||||
|
||||
module.exports = withBundleAnalyzer(
|
||||
withPayload({
|
||||
reactStrictMode: false,
|
||||
async redirects() {
|
||||
return [
|
||||
{
|
||||
destination: '/admin',
|
||||
permanent: true,
|
||||
source: '/',
|
||||
},
|
||||
]
|
||||
},
|
||||
}),
|
||||
)
|
||||
29
next.config.mjs
Normal file
29
next.config.mjs
Normal file
@@ -0,0 +1,29 @@
|
||||
import withPayload from './packages/next/src/withPayload.js'
|
||||
import bundleAnalyzer from '@next/bundle-analyzer'
|
||||
|
||||
const withBundleAnalyzer = bundleAnalyzer({
|
||||
enabled: process.env.ANALYZE === 'true',
|
||||
})
|
||||
|
||||
export default withBundleAnalyzer(
|
||||
withPayload({
|
||||
reactStrictMode: false,
|
||||
webpack: (webpackConfig) => {
|
||||
webpackConfig.resolve.extensionAlias = {
|
||||
'.js': ['.ts', '.tsx', '.js', '.jsx'],
|
||||
'.mjs': ['.mts', '.mjs'],
|
||||
'.cjs': ['.cts', '.cjs'],
|
||||
}
|
||||
return webpackConfig
|
||||
},
|
||||
async redirects() {
|
||||
return [
|
||||
{
|
||||
destination: '/admin',
|
||||
permanent: true,
|
||||
source: '/',
|
||||
},
|
||||
]
|
||||
},
|
||||
}),
|
||||
)
|
||||
10
package.json
10
package.json
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"name": "payload-monorepo",
|
||||
"version": "3.0.0-alpha.12",
|
||||
"version": "3.0.0-alpha.29",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"workspaces:": [
|
||||
"packages/*"
|
||||
],
|
||||
@@ -9,7 +10,7 @@
|
||||
"build": "pnpm run build:core",
|
||||
"build:all": "turbo build",
|
||||
"build:core": "turbo build --filter \"!@payloadcms/plugin-*\"",
|
||||
"build:plugins": "turbo build --filter \"@payloadcms/plugin-*\"",
|
||||
"build:plugins": "turbo build --filter \"@payloadcms/plugin-*\" --filter \"!@payloadcms/plugin-search\" --filter \"!@payloadcms/plugin-redirects\" --filter \"!@payloadcms/plugin-nested-docs\"",
|
||||
"build:app": "next build",
|
||||
"build:create-payload-app": "turbo build --filter create-payload-app",
|
||||
"build:db-mongodb": "turbo build --filter db-mongodb",
|
||||
@@ -89,6 +90,7 @@
|
||||
"@types/testing-library__jest-dom": "5.14.8",
|
||||
"add-stream": "^1.0.0",
|
||||
"chalk": "^4.1.2",
|
||||
"comment-json": "^4.2.3",
|
||||
"concat-stream": "^2.0.0",
|
||||
"conventional-changelog": "^5.1.0",
|
||||
"conventional-changelog-conventionalcommits": "^7.0.2",
|
||||
@@ -115,7 +117,7 @@
|
||||
"lint-staged": "^14.0.1",
|
||||
"minimist": "1.2.8",
|
||||
"mongodb-memory-server": "^9",
|
||||
"next": "14.1.1-canary.26",
|
||||
"next": "14.1.2",
|
||||
"node-mocks-http": "^1.14.1",
|
||||
"nodemon": "3.0.3",
|
||||
"pino": "8.15.0",
|
||||
@@ -128,7 +130,7 @@
|
||||
"read-stream": "^2.1.1",
|
||||
"rimraf": "3.0.2",
|
||||
"semver": "^7.5.4",
|
||||
"sharp": "0.33.2",
|
||||
"sharp": "0.32.6",
|
||||
"shelljs": "0.8.5",
|
||||
"simple-git": "^3.20.0",
|
||||
"slash": "3.0.0",
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "pnpm copyfiles && pnpm build:swc",
|
||||
"copyfiles": "copyfiles -u 4 \"../next/src/app/(payload)/**\" \"dist/app\"",
|
||||
"copyfiles": "copyfiles -u 2 \"../../app/(payload)/**\" \"dist\"",
|
||||
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
||||
"clean": "rimraf {dist,*.tsbuildinfo}",
|
||||
"test": "jest",
|
||||
@@ -23,7 +23,9 @@
|
||||
"arg": "^5.0.0",
|
||||
"chalk": "^4.1.0",
|
||||
"command-exists": "^1.2.9",
|
||||
"comment-json": "^4.2.3",
|
||||
"degit": "^2.8.4",
|
||||
"detect-package-manager": "^3.0.1",
|
||||
"execa": "^5.0.0",
|
||||
"figures": "^3.2.0",
|
||||
"fs-extra": "^9.0.1",
|
||||
|
||||
@@ -1,16 +1,88 @@
|
||||
import type { CompilerOptions } from 'typescript'
|
||||
|
||||
import chalk from 'chalk'
|
||||
import * as CommentJson from 'comment-json'
|
||||
import { detect } from 'detect-package-manager'
|
||||
import execa from 'execa'
|
||||
import fs from 'fs'
|
||||
import fse from 'fs-extra'
|
||||
import globby from 'globby'
|
||||
import path from 'path'
|
||||
|
||||
import type { CliArgs } from '../types'
|
||||
|
||||
import { copyRecursiveSync } from '../utils/copy-recursive-sync'
|
||||
import { error, info, debug as origDebug, success } from '../utils/log'
|
||||
import { error, info, debug as origDebug, success, warning } from '../utils/log'
|
||||
|
||||
export async function initNext(
|
||||
args: Pick<CliArgs, '--debug'> & { nextDir?: string; useDistFiles?: boolean },
|
||||
): Promise<{ success: boolean }> {
|
||||
const { '--debug': debug, nextDir, useDistFiles } = args
|
||||
type InitNextArgs = Pick<CliArgs, '--debug'> & {
|
||||
projectDir?: string
|
||||
useDistFiles?: boolean
|
||||
}
|
||||
type InitNextResult = { reason?: string; success: boolean; userAppDir?: string }
|
||||
|
||||
export async function initNext(args: InitNextArgs): Promise<InitNextResult> {
|
||||
args.projectDir = args.projectDir || process.cwd()
|
||||
const { projectDir } = args
|
||||
const templateResult = await applyPayloadTemplateFiles(args)
|
||||
if (!templateResult.success) return templateResult
|
||||
|
||||
const { success: installSuccess } = await installDeps(projectDir)
|
||||
if (!installSuccess) {
|
||||
return { ...templateResult, reason: 'Failed to install dependencies', success: false }
|
||||
}
|
||||
|
||||
// Create or find payload.config.ts
|
||||
const createConfigResult = findOrCreatePayloadConfig(projectDir)
|
||||
if (!createConfigResult.success) {
|
||||
return { ...templateResult, ...createConfigResult }
|
||||
}
|
||||
|
||||
// Add `@payload-config` to tsconfig.json `paths`
|
||||
await addPayloadConfigToTsConfig(projectDir)
|
||||
|
||||
// Output directions for user to update next.config.js
|
||||
const withPayloadMessage = `
|
||||
|
||||
${chalk.bold(`Wrap your existing next.config.js with the withPayload function. Here is an example:`)}
|
||||
|
||||
const { withPayload } = require("@payloadcms/next");
|
||||
|
||||
const nextConfig = {
|
||||
// Your Next.js config
|
||||
};
|
||||
|
||||
module.exports = withPayload(nextConfig);
|
||||
|
||||
`
|
||||
|
||||
console.log(withPayloadMessage)
|
||||
|
||||
return templateResult
|
||||
}
|
||||
|
||||
async function addPayloadConfigToTsConfig(projectDir: string) {
|
||||
const tsConfigPath = path.resolve(projectDir, 'tsconfig.json')
|
||||
const userTsConfigContent = await fse.readFile(tsConfigPath, {
|
||||
encoding: 'utf8',
|
||||
})
|
||||
const userTsConfig = CommentJson.parse(userTsConfigContent) as {
|
||||
compilerOptions?: CompilerOptions
|
||||
}
|
||||
if (!userTsConfig.compilerOptions && !('extends' in userTsConfig)) {
|
||||
userTsConfig.compilerOptions = {}
|
||||
}
|
||||
|
||||
if (!userTsConfig.compilerOptions.paths?.['@payload-config']) {
|
||||
userTsConfig.compilerOptions.paths = {
|
||||
...(userTsConfig.compilerOptions.paths || {}),
|
||||
'@payload-config': ['./payload.config.ts'],
|
||||
}
|
||||
await fse.writeFile(tsConfigPath, CommentJson.stringify(userTsConfig, null, 2))
|
||||
}
|
||||
}
|
||||
|
||||
async function applyPayloadTemplateFiles(args: InitNextArgs): Promise<InitNextResult> {
|
||||
const { '--debug': debug, projectDir, useDistFiles } = args
|
||||
|
||||
info('Initializing Payload app in Next.js project', 1)
|
||||
|
||||
@@ -18,24 +90,18 @@ export async function initNext(
|
||||
if (debug) origDebug(message)
|
||||
}
|
||||
|
||||
let projectDir = process.cwd()
|
||||
if (nextDir) {
|
||||
projectDir = path.resolve(projectDir, nextDir)
|
||||
if (debug) logDebug(`Overriding project directory to ${projectDir}`)
|
||||
}
|
||||
|
||||
if (!fs.existsSync(projectDir)) {
|
||||
error(`Could not find specified project directory at ${projectDir}`)
|
||||
return { success: false }
|
||||
return { reason: `Could not find specified project directory at ${projectDir}`, success: false }
|
||||
}
|
||||
|
||||
// Next.js configs can be next.config.js, next.config.mjs, etc.
|
||||
const foundConfig = (await globby('next.config.*js', { cwd: projectDir }))?.[0]
|
||||
const nextConfigPath = path.resolve(projectDir, foundConfig)
|
||||
if (!fs.existsSync(nextConfigPath)) {
|
||||
error(
|
||||
`No next.config.js found at ${nextConfigPath}. Ensure you are in a Next.js project directory.`,
|
||||
)
|
||||
return { success: false }
|
||||
return {
|
||||
reason: `No next.config.js found at ${nextConfigPath}. Ensure you are in a Next.js project directory.`,
|
||||
success: false,
|
||||
}
|
||||
} else {
|
||||
if (debug) logDebug(`Found Next config at ${nextConfigPath}`)
|
||||
}
|
||||
@@ -43,21 +109,27 @@ export async function initNext(
|
||||
const templateFilesPath =
|
||||
__dirname.endsWith('dist') || useDistFiles
|
||||
? path.resolve(__dirname, '../..', 'dist/app')
|
||||
: path.resolve(__dirname, '../../../next/src/app')
|
||||
: path.resolve(__dirname, '../../../../app')
|
||||
|
||||
if (debug) logDebug(`Using template files from: ${templateFilesPath}`)
|
||||
|
||||
if (!fs.existsSync(templateFilesPath)) {
|
||||
error(`Could not find template source files from ${templateFilesPath}`)
|
||||
return { success: false }
|
||||
return {
|
||||
reason: `Could not find template source files from ${templateFilesPath}`,
|
||||
success: false,
|
||||
}
|
||||
} else {
|
||||
if (debug) logDebug('Found template source files')
|
||||
}
|
||||
|
||||
const userAppDir = path.resolve(projectDir, 'src/app')
|
||||
// src/app or app
|
||||
const userAppDirGlob = await globby(['**/app'], {
|
||||
cwd: projectDir,
|
||||
onlyDirectories: true,
|
||||
})
|
||||
const userAppDir = path.resolve(projectDir, userAppDirGlob?.[0])
|
||||
if (!fs.existsSync(userAppDir)) {
|
||||
error(`Could not find user app directory at ${userAppDir}`)
|
||||
return { success: false }
|
||||
return { reason: `Could not find user app directory inside ${projectDir}`, success: false }
|
||||
} else {
|
||||
logDebug(`Found user app directory: ${userAppDir}`)
|
||||
}
|
||||
@@ -65,5 +137,83 @@ export async function initNext(
|
||||
logDebug(`Copying template files from ${templateFilesPath} to ${userAppDir}`)
|
||||
copyRecursiveSync(templateFilesPath, userAppDir, debug)
|
||||
success('Successfully initialized.')
|
||||
return { success: true }
|
||||
return { success: true, userAppDir }
|
||||
}
|
||||
|
||||
async function installDeps(projectDir: string) {
|
||||
const packageManager = await detect({ cwd: projectDir })
|
||||
if (!packageManager) {
|
||||
throw new Error('Could not detect package manager')
|
||||
}
|
||||
|
||||
info(`Installing dependencies with ${packageManager}`, 1)
|
||||
const packagesToInstall = [
|
||||
'payload',
|
||||
'@payloadcms/db-mongodb',
|
||||
'@payloadcms/next',
|
||||
'@payloadcms/richtext-slate',
|
||||
'@payloadcms/ui',
|
||||
].map((pkg) => `${pkg}@alpha`)
|
||||
|
||||
let exitCode = 0
|
||||
switch (packageManager) {
|
||||
case 'npm': {
|
||||
;({ exitCode } = await execa('npm', ['install', '--save', ...packagesToInstall], {
|
||||
cwd: projectDir,
|
||||
}))
|
||||
break
|
||||
}
|
||||
case 'yarn':
|
||||
case 'pnpm': {
|
||||
;({ exitCode } = await execa(packageManager, ['add', ...packagesToInstall], {
|
||||
cwd: projectDir,
|
||||
}))
|
||||
break
|
||||
}
|
||||
case 'bun': {
|
||||
warning('Bun support is untested.')
|
||||
;({ exitCode } = await execa('bun', ['add', ...packagesToInstall], { cwd: projectDir }))
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (exitCode !== 0) {
|
||||
error(`Failed to install dependencies with ${packageManager}`)
|
||||
} else {
|
||||
success(`Successfully installed dependencies`)
|
||||
}
|
||||
return { success: exitCode === 0 }
|
||||
}
|
||||
function findOrCreatePayloadConfig(projectDir: string) {
|
||||
const configPath = path.resolve(projectDir, 'payload.config.ts')
|
||||
if (fs.existsSync(configPath)) {
|
||||
return { message: 'Found existing payload.config.ts', success: true }
|
||||
} else {
|
||||
// Create default config
|
||||
// TODO: Pull this from templates
|
||||
const defaultConfig = `import path from "path";
|
||||
|
||||
import { mongooseAdapter } from "@payloadcms/db-mongodb"; // database-adapter-import
|
||||
import { slateEditor } from "@payloadcms/richtext-slate"; // editor-import
|
||||
import { buildConfig } from "payload/config";
|
||||
|
||||
export default buildConfig({
|
||||
editor: slateEditor({}), // editor-config
|
||||
collections: [],
|
||||
secret: "asdfasdf",
|
||||
typescript: {
|
||||
outputFile: path.resolve(__dirname, "payload-types.ts"),
|
||||
},
|
||||
graphQL: {
|
||||
schemaOutputFile: path.resolve(__dirname, "generated-schema.graphql"),
|
||||
},
|
||||
db: mongooseAdapter({
|
||||
url: "mongodb://localhost:27017/next-payload-3",
|
||||
}),
|
||||
});
|
||||
`
|
||||
|
||||
fse.writeFileSync(configPath, defaultConfig)
|
||||
return { message: 'Created default payload.config.ts', success: true }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import { parseTemplate } from './lib/parse-template'
|
||||
import { selectDb } from './lib/select-db'
|
||||
import { getValidTemplates, validateTemplate } from './lib/templates'
|
||||
import { writeEnvFile } from './lib/write-env-file'
|
||||
import { success } from './utils/log'
|
||||
import { error, success } from './utils/log'
|
||||
import { helpMessage, successMessage, welcomeMessage } from './utils/messages'
|
||||
|
||||
export class Main {
|
||||
@@ -61,6 +61,11 @@ export class Main {
|
||||
|
||||
if (this.args['--init-next']) {
|
||||
const result = await initNext(this.args)
|
||||
if (!result.success) {
|
||||
error(result.reason || 'Failed to initialize Payload app in Next.js project')
|
||||
} else {
|
||||
success('Payload app successfully initialized in Next.js project')
|
||||
}
|
||||
process.exit(result.success ? 0 : 1)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "commonjs"
|
||||
"type": "es6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
{
|
||||
"name": "@payloadcms/db-mongodb",
|
||||
"version": "3.0.0-alpha.12",
|
||||
"version": "3.0.0-alpha.29",
|
||||
"description": "The officially supported MongoDB database adapter for Payload - Update 2",
|
||||
"repository": "https://github.com/payloadcms/payload",
|
||||
"license": "MIT",
|
||||
"homepage": "https://payloadcms.com",
|
||||
"type": "module",
|
||||
"author": {
|
||||
"email": "info@payloadcms.com",
|
||||
"name": "Payload",
|
||||
|
||||
@@ -4,9 +4,16 @@ import type { Connect } from 'payload/database'
|
||||
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
export const connect: Connect = async function connect(
|
||||
this: MongooseAdapter,
|
||||
options = {
|
||||
hotReload: false,
|
||||
},
|
||||
) {
|
||||
const { hotReload } = options
|
||||
|
||||
export const connect: Connect = async function connect(this: MongooseAdapter) {
|
||||
if (this.url === false) {
|
||||
return
|
||||
}
|
||||
@@ -24,6 +31,8 @@ export const connect: Connect = async function connect(this: MongooseAdapter) {
|
||||
useFacet: undefined,
|
||||
}
|
||||
|
||||
if (hotReload) connectionOptions.autoIndex = false
|
||||
|
||||
try {
|
||||
this.connection = (await mongoose.connect(urlToConnect, connectionOptions)).connection
|
||||
|
||||
@@ -34,12 +43,15 @@ export const connect: Connect = async function connect(this: MongooseAdapter) {
|
||||
this.beginTransaction = undefined
|
||||
}
|
||||
|
||||
if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
|
||||
this.payload.logger.info('---- DROPPING DATABASE ----')
|
||||
await mongoose.connection.dropDatabase()
|
||||
this.payload.logger.info('---- DROPPED DATABASE ----')
|
||||
if (!hotReload) {
|
||||
if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
|
||||
this.payload.logger.info('---- DROPPING DATABASE ----')
|
||||
await mongoose.connection.dropDatabase()
|
||||
this.payload.logger.info('---- DROPPED DATABASE ----')
|
||||
}
|
||||
|
||||
this.payload.logger.info(successfulConnectionMessage)
|
||||
}
|
||||
this.payload.logger.info(successfulConnectionMessage)
|
||||
} catch (err) {
|
||||
this.payload.logger.error(`Error: cannot connect to MongoDB. Details: ${err.message}`, err)
|
||||
process.exit(1)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { Create } from 'payload/database'
|
||||
import type { Document, PayloadRequest } from 'payload/types'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
import handleError from './utilities/handleError'
|
||||
import { withSession } from './withSession'
|
||||
import handleError from './utilities/handleError.js'
|
||||
import { withSession } from './withSession.js'
|
||||
|
||||
export const create: Create = async function create(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { CreateGlobal } from 'payload/database'
|
||||
import type { PayloadRequest } from 'payload/types'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields'
|
||||
import { withSession } from './withSession'
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js'
|
||||
import { withSession } from './withSession.js'
|
||||
|
||||
export const createGlobal: CreateGlobal = async function createGlobal(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -2,9 +2,9 @@ import type { CreateGlobalVersion } from 'payload/database'
|
||||
import type { PayloadRequest } from 'payload/types'
|
||||
import type { Document } from 'payload/types'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
import { withSession } from './withSession'
|
||||
import { withSession } from './withSession.js'
|
||||
|
||||
export const createGlobalVersion: CreateGlobalVersion = async function createGlobalVersion(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -2,9 +2,9 @@ import type { CreateVersion } from 'payload/database'
|
||||
import type { PayloadRequest } from 'payload/types'
|
||||
import type { Document } from 'payload/types'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
import { withSession } from './withSession'
|
||||
import { withSession } from './withSession.js'
|
||||
|
||||
export const createVersion: CreateVersion = async function createVersion(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { DeleteMany } from 'payload/database'
|
||||
import type { PayloadRequest } from 'payload/types'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
import { withSession } from './withSession'
|
||||
import { withSession } from './withSession.js'
|
||||
|
||||
export const deleteMany: DeleteMany = async function deleteMany(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -2,10 +2,10 @@ import type { DeleteOne } from 'payload/database'
|
||||
import type { PayloadRequest } from 'payload/types'
|
||||
import type { Document } from 'payload/types'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields'
|
||||
import { withSession } from './withSession'
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js'
|
||||
import { withSession } from './withSession.js'
|
||||
|
||||
export const deleteOne: DeleteOne = async function deleteOne(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { DeleteVersions } from 'payload/database'
|
||||
import type { PayloadRequest } from 'payload/types'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
import { withSession } from './withSession'
|
||||
import { withSession } from './withSession.js'
|
||||
|
||||
export const deleteVersions: DeleteVersions = async function deleteVersions(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { Destroy } from 'payload/database'
|
||||
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
import type { MongooseAdapter } from './index'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
export const destroy: Destroy = async function destroy(this: MongooseAdapter) {
|
||||
if (this.mongoMemoryServer) {
|
||||
@@ -10,6 +10,7 @@ export const destroy: Destroy = async function destroy(this: MongooseAdapter) {
|
||||
await mongoose.connection.close()
|
||||
await this.mongoMemoryServer.stop()
|
||||
} else {
|
||||
await mongoose.connection.close()
|
||||
await mongoose.disconnect()
|
||||
}
|
||||
Object.keys(mongoose.models).map((model) => mongoose.deleteModel(model))
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ import type { PayloadRequest } from 'payload/types'
|
||||
|
||||
import { flattenWhereToOperators } from 'payload/database'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
import { buildSortParam } from './queries/buildSortParam'
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields'
|
||||
import { withSession } from './withSession'
|
||||
import { buildSortParam } from './queries/buildSortParam.js'
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js'
|
||||
import { withSession } from './withSession.js'
|
||||
|
||||
export const find: Find = async function find(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -3,10 +3,10 @@ import type { PayloadRequest } from 'payload/types'
|
||||
|
||||
import { combineQueries } from 'payload/database'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields'
|
||||
import { withSession } from './withSession'
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js'
|
||||
import { withSession } from './withSession.js'
|
||||
|
||||
export const findGlobal: FindGlobal = async function findGlobal(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -5,11 +5,11 @@ import type { PayloadRequest } from 'payload/types'
|
||||
import { flattenWhereToOperators } from 'payload/database'
|
||||
import { buildVersionGlobalFields } from 'payload/versions'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
import { buildSortParam } from './queries/buildSortParam'
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields'
|
||||
import { withSession } from './withSession'
|
||||
import { buildSortParam } from './queries/buildSortParam.js'
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js'
|
||||
import { withSession } from './withSession.js'
|
||||
|
||||
export const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -3,10 +3,10 @@ import type { FindOne } from 'payload/database'
|
||||
import type { PayloadRequest } from 'payload/types'
|
||||
import type { Document } from 'payload/types'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields'
|
||||
import { withSession } from './withSession'
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js'
|
||||
import { withSession } from './withSession.js'
|
||||
|
||||
export const findOne: FindOne = async function findOne(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -4,11 +4,11 @@ import type { PayloadRequest } from 'payload/types'
|
||||
|
||||
import { flattenWhereToOperators } from 'payload/database'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
import { buildSortParam } from './queries/buildSortParam'
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields'
|
||||
import { withSession } from './withSession'
|
||||
import { buildSortParam } from './queries/buildSortParam.js'
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js'
|
||||
import { withSession } from './withSession.js'
|
||||
|
||||
export const findVersions: FindVersions = async function findVersions(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -8,35 +8,35 @@ import mongoose from 'mongoose'
|
||||
import path from 'path'
|
||||
import { createDatabaseAdapter } from 'payload/database'
|
||||
|
||||
import type { CollectionModel, GlobalModel } from './types'
|
||||
import type { CollectionModel, GlobalModel } from './types.d.ts'
|
||||
|
||||
import { connect } from './connect'
|
||||
import { create } from './create'
|
||||
import { createGlobal } from './createGlobal'
|
||||
import { createGlobalVersion } from './createGlobalVersion'
|
||||
import { createMigration } from './createMigration'
|
||||
import { createVersion } from './createVersion'
|
||||
import { deleteMany } from './deleteMany'
|
||||
import { deleteOne } from './deleteOne'
|
||||
import { deleteVersions } from './deleteVersions'
|
||||
import { destroy } from './destroy'
|
||||
import { find } from './find'
|
||||
import { findGlobal } from './findGlobal'
|
||||
import { findGlobalVersions } from './findGlobalVersions'
|
||||
import { findOne } from './findOne'
|
||||
import { findVersions } from './findVersions'
|
||||
import { init } from './init'
|
||||
import { migrateFresh } from './migrateFresh'
|
||||
import { queryDrafts } from './queryDrafts'
|
||||
import { beginTransaction } from './transactions/beginTransaction'
|
||||
import { commitTransaction } from './transactions/commitTransaction'
|
||||
import { rollbackTransaction } from './transactions/rollbackTransaction'
|
||||
import { updateGlobal } from './updateGlobal'
|
||||
import { updateGlobalVersion } from './updateGlobalVersion'
|
||||
import { updateOne } from './updateOne'
|
||||
import { updateVersion } from './updateVersion'
|
||||
import { connect } from './connect.js'
|
||||
import { create } from './create.js'
|
||||
import { createGlobal } from './createGlobal.js'
|
||||
import { createGlobalVersion } from './createGlobalVersion.js'
|
||||
import { createMigration } from './createMigration.js'
|
||||
import { createVersion } from './createVersion.js'
|
||||
import { deleteMany } from './deleteMany.js'
|
||||
import { deleteOne } from './deleteOne.js'
|
||||
import { deleteVersions } from './deleteVersions.js'
|
||||
import { destroy } from './destroy.js'
|
||||
import { find } from './find.js'
|
||||
import { findGlobal } from './findGlobal.js'
|
||||
import { findGlobalVersions } from './findGlobalVersions.js'
|
||||
import { findOne } from './findOne.js'
|
||||
import { findVersions } from './findVersions.js'
|
||||
import { init } from './init.js'
|
||||
import { migrateFresh } from './migrateFresh.js'
|
||||
import { queryDrafts } from './queryDrafts.js'
|
||||
import { beginTransaction } from './transactions/beginTransaction.js'
|
||||
import { commitTransaction } from './transactions/commitTransaction.js'
|
||||
import { rollbackTransaction } from './transactions/rollbackTransaction.js'
|
||||
import { updateGlobal } from './updateGlobal.js'
|
||||
import { updateGlobalVersion } from './updateGlobalVersion.js'
|
||||
import { updateOne } from './updateOne.js'
|
||||
import { updateVersion } from './updateVersion.js'
|
||||
|
||||
export type { MigrateDownArgs, MigrateUpArgs } from './types'
|
||||
export type { MigrateDownArgs, MigrateUpArgs } from './types.d.ts'
|
||||
import type { DatabaseAdapterObj } from 'payload/database'
|
||||
|
||||
export interface Args {
|
||||
|
||||
@@ -11,15 +11,15 @@ import {
|
||||
getVersionsModelName,
|
||||
} from 'payload/versions'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { CollectionModel } from './types'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
import type { CollectionModel } from './types.d.ts'
|
||||
|
||||
import buildCollectionSchema from './models/buildCollectionSchema'
|
||||
import { buildGlobalModel } from './models/buildGlobalModel'
|
||||
import buildSchema from './models/buildSchema'
|
||||
import getBuildQueryPlugin from './queries/buildQuery'
|
||||
import buildCollectionSchema from './models/buildCollectionSchema.js'
|
||||
import { buildGlobalModel } from './models/buildGlobalModel.js'
|
||||
import buildSchema from './models/buildSchema.js'
|
||||
import getBuildQueryPlugin from './queries/buildQuery.js'
|
||||
|
||||
export const init: Init = async function init(this: MongooseAdapter) {
|
||||
export const init: Init = function init(this: MongooseAdapter) {
|
||||
this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {
|
||||
const schema = buildCollectionSchema(collection, this.payload.config)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from 'payload/database'
|
||||
import prompts from 'prompts'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
/**
|
||||
* Drop the current database and run all migrate up functions
|
||||
|
||||
@@ -4,8 +4,8 @@ import type { SanitizedCollectionConfig } from 'payload/types'
|
||||
|
||||
import paginate from 'mongoose-paginate-v2'
|
||||
|
||||
import getBuildQueryPlugin from '../queries/buildQuery'
|
||||
import buildSchema from './buildSchema'
|
||||
import getBuildQueryPlugin from '../queries/buildQuery.js'
|
||||
import buildSchema from './buildSchema.js'
|
||||
|
||||
const buildCollectionSchema = (
|
||||
collection: SanitizedCollectionConfig,
|
||||
|
||||
@@ -2,10 +2,10 @@ import type { SanitizedConfig } from 'payload/config'
|
||||
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
import type { GlobalModel } from '../types'
|
||||
import type { GlobalModel } from '../types.d.ts'
|
||||
|
||||
import getBuildQueryPlugin from '../queries/buildQuery'
|
||||
import buildSchema from './buildSchema'
|
||||
import getBuildQueryPlugin from '../queries/buildQuery.js'
|
||||
import buildSchema from './buildSchema.js'
|
||||
|
||||
export const buildGlobalModel = (config: SanitizedConfig): GlobalModel | null => {
|
||||
if (config.globals && config.globals.length > 0) {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
/* eslint-disable class-methods-use-this */
|
||||
/* eslint-disable @typescript-eslint/no-use-before-define */
|
||||
/* eslint-disable no-use-before-define */
|
||||
import type { IndexOptions, SchemaOptions, SchemaTypeOptions } from 'mongoose'
|
||||
import type { IndexOptions, Schema, SchemaOptions, SchemaTypeOptions } from 'mongoose'
|
||||
import type { SanitizedConfig, SanitizedLocalizationConfig } from 'payload/config'
|
||||
import type {
|
||||
ArrayField,
|
||||
@@ -32,7 +31,7 @@ import type {
|
||||
UploadField,
|
||||
} from 'payload/types'
|
||||
|
||||
import { Schema } from 'mongoose'
|
||||
import mongoose from 'mongoose'
|
||||
import {
|
||||
fieldAffectsData,
|
||||
fieldIsLocalized,
|
||||
@@ -126,7 +125,7 @@ const buildSchema = (
|
||||
}
|
||||
}
|
||||
|
||||
const schema = new Schema(fields, options)
|
||||
const schema = new mongoose.Schema(fields, options)
|
||||
|
||||
schemaFields.forEach((field) => {
|
||||
if (!fieldIsPresentationalOnly(field)) {
|
||||
@@ -176,7 +175,7 @@ const fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {
|
||||
buildSchemaOptions: BuildSchemaOptions,
|
||||
): void => {
|
||||
const fieldSchema = {
|
||||
type: [new Schema({}, { _id: false, discriminatorKey: 'blockType' })],
|
||||
type: [new mongoose.Schema({}, { _id: false, discriminatorKey: 'blockType' })],
|
||||
default: undefined,
|
||||
}
|
||||
|
||||
@@ -185,7 +184,7 @@ const fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {
|
||||
})
|
||||
|
||||
field.blocks.forEach((blockItem: Block) => {
|
||||
const blockSchema = new Schema({}, { _id: false, id: false })
|
||||
const blockSchema = new mongoose.Schema({}, { _id: false, id: false })
|
||||
|
||||
blockItem.fields.forEach((blockField) => {
|
||||
const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[blockField.type]
|
||||
@@ -307,7 +306,10 @@ const fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {
|
||||
config: SanitizedConfig,
|
||||
buildSchemaOptions: BuildSchemaOptions,
|
||||
): void => {
|
||||
const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Schema.Types.Mixed }
|
||||
const baseSchema = {
|
||||
...formatBaseSchema(field, buildSchemaOptions),
|
||||
type: mongoose.Schema.Types.Mixed,
|
||||
}
|
||||
|
||||
schema.add({
|
||||
[field.name]: localizeSchema(field, baseSchema, config.localization),
|
||||
@@ -405,17 +407,17 @@ const fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {
|
||||
localeSchema = {
|
||||
...formatBaseSchema(field, buildSchemaOptions),
|
||||
_id: false,
|
||||
type: Schema.Types.Mixed,
|
||||
type: mongoose.Schema.Types.Mixed,
|
||||
relationTo: { type: String, enum: field.relationTo },
|
||||
value: {
|
||||
type: Schema.Types.Mixed,
|
||||
type: mongoose.Schema.Types.Mixed,
|
||||
refPath: `${field.name}.${locale}.relationTo`,
|
||||
},
|
||||
}
|
||||
} else {
|
||||
localeSchema = {
|
||||
...formatBaseSchema(field, buildSchemaOptions),
|
||||
type: Schema.Types.Mixed,
|
||||
type: mongoose.Schema.Types.Mixed,
|
||||
ref: field.relationTo,
|
||||
}
|
||||
}
|
||||
@@ -431,10 +433,10 @@ const fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {
|
||||
schemaToReturn = {
|
||||
...formatBaseSchema(field, buildSchemaOptions),
|
||||
_id: false,
|
||||
type: Schema.Types.Mixed,
|
||||
type: mongoose.Schema.Types.Mixed,
|
||||
relationTo: { type: String, enum: field.relationTo },
|
||||
value: {
|
||||
type: Schema.Types.Mixed,
|
||||
type: mongoose.Schema.Types.Mixed,
|
||||
refPath: `${field.name}.relationTo`,
|
||||
},
|
||||
}
|
||||
@@ -448,7 +450,7 @@ const fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {
|
||||
} else {
|
||||
schemaToReturn = {
|
||||
...formatBaseSchema(field, buildSchemaOptions),
|
||||
type: Schema.Types.Mixed,
|
||||
type: mongoose.Schema.Types.Mixed,
|
||||
ref: field.relationTo,
|
||||
}
|
||||
|
||||
@@ -470,7 +472,10 @@ const fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {
|
||||
config: SanitizedConfig,
|
||||
buildSchemaOptions: BuildSchemaOptions,
|
||||
): void => {
|
||||
const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Schema.Types.Mixed }
|
||||
const baseSchema = {
|
||||
...formatBaseSchema(field, buildSchemaOptions),
|
||||
type: mongoose.Schema.Types.Mixed,
|
||||
}
|
||||
|
||||
schema.add({
|
||||
[field.name]: localizeSchema(field, baseSchema, config.localization),
|
||||
@@ -586,7 +591,7 @@ const fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {
|
||||
): void => {
|
||||
const baseSchema = {
|
||||
...formatBaseSchema(field, buildSchemaOptions),
|
||||
type: Schema.Types.Mixed,
|
||||
type: mongoose.Schema.Types.Mixed,
|
||||
ref: field.relationTo,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Payload } from 'payload'
|
||||
import type { Field, Where } from 'payload/types'
|
||||
|
||||
import { parseParams } from './parseParams'
|
||||
import { parseParams } from './parseParams.js'
|
||||
|
||||
export async function buildAndOrConditions({
|
||||
collectionSlug,
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { Field, Where } from 'payload/types'
|
||||
|
||||
import { QueryError } from 'payload/errors'
|
||||
|
||||
import { parseParams } from './parseParams'
|
||||
import { parseParams } from './parseParams.js'
|
||||
|
||||
type GetBuildQueryPluginArgs = {
|
||||
collectionSlug?: string
|
||||
|
||||
@@ -9,10 +9,10 @@ import { getLocalizedPaths } from 'payload/database'
|
||||
import { fieldAffectsData } from 'payload/types'
|
||||
import { validOperators } from 'payload/types'
|
||||
|
||||
import type { MongooseAdapter } from '..'
|
||||
import type { MongooseAdapter } from '../index.d.ts'
|
||||
|
||||
import { operatorMap } from './operatorMap'
|
||||
import { sanitizeQueryValue } from './sanitizeQueryValue'
|
||||
import { operatorMap } from './operatorMap.js'
|
||||
import { sanitizeQueryValue } from './sanitizeQueryValue.js'
|
||||
|
||||
type SearchParam = {
|
||||
path?: string
|
||||
@@ -204,7 +204,9 @@ export async function buildSearchParam({
|
||||
|
||||
if (typeof formattedValue === 'string') {
|
||||
if (mongoose.Types.ObjectId.isValid(formattedValue)) {
|
||||
result.value.$or.push({ [path]: { [operatorKey]: new ObjectId(formattedValue) } })
|
||||
result.value.$or.push({
|
||||
[path]: { [operatorKey]: new ObjectId.default(formattedValue) },
|
||||
})
|
||||
} else {
|
||||
;(Array.isArray(field.relationTo) ? field.relationTo : [field.relationTo]).forEach(
|
||||
(relationTo) => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { PaginateOptions } from 'mongoose'
|
||||
import type { SanitizedConfig } from 'payload/config'
|
||||
import type { Field } from 'payload/types'
|
||||
|
||||
import { getLocalizedSortProperty } from './getLocalizedSortProperty'
|
||||
import { getLocalizedSortProperty } from './getLocalizedSortProperty.js'
|
||||
|
||||
type Args = {
|
||||
config: SanitizedConfig
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { sanitizeConfig } from 'payload/config'
|
||||
import { Config } from 'payload/config'
|
||||
import { getLocalizedSortProperty } from './getLocalizedSortProperty'
|
||||
import { getLocalizedSortProperty } from './getLocalizedSortProperty.js'
|
||||
|
||||
const config = {
|
||||
localization: {
|
||||
|
||||
@@ -9,8 +9,8 @@ import deepmerge from 'deepmerge'
|
||||
import { validOperators } from 'payload/types'
|
||||
import { combineMerge } from 'payload/utilities'
|
||||
|
||||
import { buildAndOrConditions } from './buildAndOrConditions'
|
||||
import { buildSearchParam } from './buildSearchParams'
|
||||
import { buildAndOrConditions } from './buildAndOrConditions.js'
|
||||
import { buildSearchParam } from './buildSearchParams.js'
|
||||
|
||||
export async function parseParams({
|
||||
collectionSlug,
|
||||
|
||||
@@ -4,11 +4,11 @@ import type { PayloadRequest } from 'payload/types'
|
||||
|
||||
import { combineQueries, flattenWhereToOperators } from 'payload/database'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
import { buildSortParam } from './queries/buildSortParam'
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields'
|
||||
import { withSession } from './withSession'
|
||||
import { buildSortParam } from './queries/buildSortParam.js'
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js'
|
||||
import { withSession } from './withSession.js'
|
||||
|
||||
export const queryDrafts: QueryDrafts = async function queryDrafts(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { BeginTransaction } from 'payload/database'
|
||||
import { APIError } from 'payload/errors'
|
||||
import { v4 as uuid } from 'uuid'
|
||||
|
||||
import type { MongooseAdapter } from '../index'
|
||||
import type { MongooseAdapter } from '../index.d.ts'
|
||||
|
||||
export const beginTransaction: BeginTransaction = async function beginTransaction(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -25,7 +25,7 @@ import type {
|
||||
UploadField,
|
||||
} from 'payload/types'
|
||||
|
||||
import type { BuildQueryArgs } from './queries/buildQuery'
|
||||
import type { BuildQueryArgs } from './queries/buildQuery.d.ts'
|
||||
|
||||
export interface CollectionModel extends Model<any>, PaginateModel<any> {
|
||||
/** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { UpdateGlobal } from 'payload/database'
|
||||
import type { PayloadRequest } from 'payload/types'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields'
|
||||
import { withSession } from './withSession'
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js'
|
||||
import { withSession } from './withSession.js'
|
||||
|
||||
export const updateGlobal: UpdateGlobal = async function updateGlobal(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { UpdateGlobalVersionArgs } from 'payload/database'
|
||||
import type { PayloadRequest, TypeWithID } from 'payload/types'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
import { withSession } from './withSession'
|
||||
import { withSession } from './withSession.js'
|
||||
|
||||
export async function updateGlobalVersion<T extends TypeWithID>(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { UpdateOne } from 'payload/database'
|
||||
import type { PayloadRequest } from 'payload/types'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
import handleError from './utilities/handleError'
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields'
|
||||
import { withSession } from './withSession'
|
||||
import handleError from './utilities/handleError.js'
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js'
|
||||
import { withSession } from './withSession.js'
|
||||
|
||||
export const updateOne: UpdateOne = async function updateOne(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { UpdateVersion } from 'payload/database'
|
||||
import type { PayloadRequest } from 'payload/types'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
import { withSession } from './withSession'
|
||||
import { withSession } from './withSession.js'
|
||||
|
||||
export const updateVersion: UpdateVersion = async function updateVersion(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ClientSession } from 'mongoose'
|
||||
|
||||
import type { MongooseAdapter } from './index'
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
/**
|
||||
* returns the session belonging to the transaction of the req.session if exists
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "commonjs"
|
||||
"type": "es6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
{
|
||||
"name": "@payloadcms/db-postgres",
|
||||
"version": "0.7.0",
|
||||
"version": "3.0.0-alpha.29",
|
||||
"description": "The officially supported Postgres database adapter for Payload",
|
||||
"repository": "https://github.com/payloadcms/payload",
|
||||
"license": "MIT",
|
||||
"homepage": "https://payloadcms.com",
|
||||
"type": "module",
|
||||
"author": {
|
||||
"email": "info@payloadcms.com",
|
||||
"name": "Payload",
|
||||
|
||||
@@ -7,7 +7,7 @@ import { numeric, timestamp, varchar } from 'drizzle-orm/pg-core'
|
||||
import { Pool } from 'pg'
|
||||
import prompts from 'prompts'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
const connectWithReconnect = async function ({
|
||||
adapter,
|
||||
@@ -46,7 +46,14 @@ const connectWithReconnect = async function ({
|
||||
})
|
||||
}
|
||||
|
||||
export const connect: Connect = async function connect(this: PostgresAdapter, payload) {
|
||||
export const connect: Connect = async function connect(
|
||||
this: PostgresAdapter,
|
||||
options = {
|
||||
hotReload: false,
|
||||
},
|
||||
) {
|
||||
const { hotReload } = options
|
||||
|
||||
this.schema = {
|
||||
...this.tables,
|
||||
...this.relations,
|
||||
@@ -55,23 +62,26 @@ export const connect: Connect = async function connect(this: PostgresAdapter, pa
|
||||
|
||||
try {
|
||||
this.pool = new Pool(this.poolOptions)
|
||||
await connectWithReconnect({ adapter: this, payload })
|
||||
await connectWithReconnect({ adapter: this, payload: this.payload })
|
||||
|
||||
const logger = this.logger || false
|
||||
|
||||
this.drizzle = drizzle(this.pool, { logger, schema: this.schema })
|
||||
if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
|
||||
this.payload.logger.info(`---- DROPPING TABLES SCHEMA(${this.schemaName || 'public'}) ----`)
|
||||
await this.drizzle.execute(
|
||||
sql.raw(`
|
||||
drop schema if exists ${this.schemaName || 'public'} cascade;
|
||||
create schema ${this.schemaName || 'public'};
|
||||
`),
|
||||
)
|
||||
this.payload.logger.info('---- DROPPED TABLES ----')
|
||||
|
||||
if (!hotReload) {
|
||||
if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
|
||||
this.payload.logger.info(`---- DROPPING TABLES SCHEMA(${this.schemaName || 'public'}) ----`)
|
||||
await this.drizzle.execute(
|
||||
sql.raw(`
|
||||
drop schema if exists ${this.schemaName || 'public'} cascade;
|
||||
create schema ${this.schemaName || 'public'};
|
||||
`),
|
||||
)
|
||||
this.payload.logger.info('---- DROPPED TABLES ----')
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
payload.logger.error(`Error: cannot connect to Postgres. Details: ${err.message}`, err)
|
||||
this.payload.logger.error(`Error: cannot connect to Postgres. Details: ${err.message}`, err)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ import type { Create } from 'payload/database'
|
||||
|
||||
import toSnakeCase from 'to-snake-case'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
import { upsertRow } from './upsertRow'
|
||||
import { upsertRow } from './upsertRow/index.js'
|
||||
|
||||
export const create: Create = async function create(
|
||||
this: PostgresAdapter,
|
||||
|
||||
@@ -3,9 +3,9 @@ import type { PayloadRequest, TypeWithID } from 'payload/types'
|
||||
|
||||
import toSnakeCase from 'to-snake-case'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
import { upsertRow } from './upsertRow'
|
||||
import { upsertRow } from './upsertRow/index.js'
|
||||
|
||||
export async function createGlobal<T extends TypeWithID>(
|
||||
this: PostgresAdapter,
|
||||
|
||||
@@ -6,9 +6,9 @@ import { sql } from 'drizzle-orm'
|
||||
import { buildVersionGlobalFields } from 'payload/versions'
|
||||
import toSnakeCase from 'to-snake-case'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
import { upsertRow } from './upsertRow'
|
||||
import { upsertRow } from './upsertRow/index.js'
|
||||
|
||||
export async function createGlobalVersion<T extends TypeWithID>(
|
||||
this: PostgresAdapter,
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { CreateMigration } from 'payload/database'
|
||||
import fs from 'fs'
|
||||
import prompts from 'prompts'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
const migrationTemplate = (
|
||||
upSQL?: string,
|
||||
|
||||
@@ -5,9 +5,9 @@ import { sql } from 'drizzle-orm'
|
||||
import { buildVersionCollectionFields } from 'payload/versions'
|
||||
import toSnakeCase from 'to-snake-case'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
import { upsertRow } from './upsertRow'
|
||||
import { upsertRow } from './upsertRow/index.js'
|
||||
|
||||
export async function createVersion<T extends TypeWithID>(
|
||||
this: PostgresAdapter,
|
||||
|
||||
@@ -4,9 +4,9 @@ import type { PayloadRequest } from 'payload/types'
|
||||
import { inArray } from 'drizzle-orm'
|
||||
import toSnakeCase from 'to-snake-case'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
import { findMany } from './find/findMany'
|
||||
import { findMany } from './find/findMany.js'
|
||||
|
||||
export const deleteMany: DeleteMany = async function deleteMany(
|
||||
this: PostgresAdapter,
|
||||
|
||||
@@ -3,11 +3,11 @@ import type { PayloadRequest } from 'payload/types'
|
||||
|
||||
import toSnakeCase from 'to-snake-case'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
import { buildFindManyArgs } from './find/buildFindManyArgs'
|
||||
import buildQuery from './queries/buildQuery'
|
||||
import { transform } from './transform/read'
|
||||
import { buildFindManyArgs } from './find/buildFindManyArgs.js'
|
||||
import buildQuery from './queries/buildQuery.js'
|
||||
import { transform } from './transform/read/index.js'
|
||||
|
||||
export const deleteOne: DeleteOne = async function deleteOne(
|
||||
this: PostgresAdapter,
|
||||
|
||||
@@ -5,9 +5,9 @@ import { inArray } from 'drizzle-orm'
|
||||
import { buildVersionCollectionFields } from 'payload/versions'
|
||||
import toSnakeCase from 'to-snake-case'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
import { findMany } from './find/findMany'
|
||||
import { findMany } from './find/findMany.js'
|
||||
|
||||
export const deleteVersions: DeleteVersions = async function deleteVersion(
|
||||
this: PostgresAdapter,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Destroy } from 'payload/database'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
export const destroy: Destroy = async function destroy(this: PostgresAdapter) {
|
||||
// TODO: this hangs test suite for some reason
|
||||
|
||||
@@ -3,9 +3,9 @@ import type { PayloadRequest, SanitizedCollectionConfig } from 'payload/types'
|
||||
|
||||
import toSnakeCase from 'to-snake-case'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
import { findMany } from './find/findMany'
|
||||
import { findMany } from './find/findMany.js'
|
||||
|
||||
export const find: Find = async function find(
|
||||
this: PostgresAdapter,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { DBQueryConfig } from 'drizzle-orm'
|
||||
import type { Field } from 'payload/types'
|
||||
|
||||
import type { PostgresAdapter } from '../types'
|
||||
import type { PostgresAdapter } from '../types.d.ts'
|
||||
|
||||
import { traverseFields } from './traverseFields'
|
||||
import { traverseFields } from './traverseFields.js'
|
||||
|
||||
type BuildFindQueryArgs = {
|
||||
adapter: PostgresAdapter
|
||||
|
||||
@@ -3,13 +3,13 @@ import type { Field, PayloadRequest, TypeWithID } from 'payload/types'
|
||||
|
||||
import { inArray, sql } from 'drizzle-orm'
|
||||
|
||||
import type { PostgresAdapter } from '../types'
|
||||
import type { ChainedMethods } from './chainMethods'
|
||||
import type { PostgresAdapter } from '../types.d.ts'
|
||||
import type { ChainedMethods } from './chainMethods.d.ts'
|
||||
|
||||
import buildQuery from '../queries/buildQuery'
|
||||
import { transform } from '../transform/read'
|
||||
import { buildFindManyArgs } from './buildFindManyArgs'
|
||||
import { chainMethods } from './chainMethods'
|
||||
import buildQuery from '../queries/buildQuery.js'
|
||||
import { transform } from '../transform/read/index.js'
|
||||
import { buildFindManyArgs } from './buildFindManyArgs.js'
|
||||
import { chainMethods } from './chainMethods.js'
|
||||
|
||||
type Args = Omit<FindArgs, 'collection'> & {
|
||||
adapter: PostgresAdapter
|
||||
|
||||
@@ -4,8 +4,8 @@ import type { Field } from 'payload/types'
|
||||
import { fieldAffectsData, tabHasName } from 'payload/types'
|
||||
import toSnakeCase from 'to-snake-case'
|
||||
|
||||
import type { PostgresAdapter } from '../types'
|
||||
import type { Result } from './buildFindManyArgs'
|
||||
import type { PostgresAdapter } from '../types.d.ts'
|
||||
import type { Result } from './buildFindManyArgs.d.ts'
|
||||
|
||||
type TraverseFieldArgs = {
|
||||
_locales: Record<string, unknown>
|
||||
|
||||
@@ -2,9 +2,9 @@ import type { FindGlobal } from 'payload/database'
|
||||
|
||||
import toSnakeCase from 'to-snake-case'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
import { findMany } from './find/findMany'
|
||||
import { findMany } from './find/findMany.js'
|
||||
|
||||
export const findGlobal: FindGlobal = async function findGlobal(
|
||||
this: PostgresAdapter,
|
||||
|
||||
@@ -4,9 +4,9 @@ import type { PayloadRequest, SanitizedGlobalConfig } from 'payload/types'
|
||||
import { buildVersionGlobalFields } from 'payload/versions'
|
||||
import toSnakeCase from 'to-snake-case'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
import { findMany } from './find/findMany'
|
||||
import { findMany } from './find/findMany.js'
|
||||
|
||||
export const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(
|
||||
this: PostgresAdapter,
|
||||
|
||||
@@ -3,9 +3,9 @@ import type { PayloadRequest, SanitizedCollectionConfig, TypeWithID } from 'payl
|
||||
|
||||
import toSnakeCase from 'to-snake-case'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
import { findMany } from './find/findMany'
|
||||
import { findMany } from './find/findMany.js'
|
||||
|
||||
export async function findOne<T extends TypeWithID>(
|
||||
this: PostgresAdapter,
|
||||
|
||||
@@ -4,9 +4,9 @@ import type { PayloadRequest, SanitizedCollectionConfig } from 'payload/types'
|
||||
import { buildVersionCollectionFields } from 'payload/versions'
|
||||
import toSnakeCase from 'to-snake-case'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
import { findMany } from './find/findMany'
|
||||
import { findMany } from './find/findMany.js'
|
||||
|
||||
export const findVersions: FindVersions = async function findVersions(
|
||||
this: PostgresAdapter,
|
||||
|
||||
@@ -5,40 +5,40 @@ import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { createDatabaseAdapter } from 'payload/database'
|
||||
|
||||
import type { Args, PostgresAdapter } from './types'
|
||||
import type { Args, PostgresAdapter } from './types.d.ts'
|
||||
|
||||
import { connect } from './connect'
|
||||
import { create } from './create'
|
||||
import { createGlobal } from './createGlobal'
|
||||
import { createGlobalVersion } from './createGlobalVersion'
|
||||
import { createMigration } from './createMigration'
|
||||
import { createVersion } from './createVersion'
|
||||
import { deleteMany } from './deleteMany'
|
||||
import { deleteOne } from './deleteOne'
|
||||
import { deleteVersions } from './deleteVersions'
|
||||
import { destroy } from './destroy'
|
||||
import { find } from './find'
|
||||
import { findGlobal } from './findGlobal'
|
||||
import { findGlobalVersions } from './findGlobalVersions'
|
||||
import { findOne } from './findOne'
|
||||
import { findVersions } from './findVersions'
|
||||
import { init } from './init'
|
||||
import { migrate } from './migrate'
|
||||
import { migrateDown } from './migrateDown'
|
||||
import { migrateFresh } from './migrateFresh'
|
||||
import { migrateRefresh } from './migrateRefresh'
|
||||
import { migrateReset } from './migrateReset'
|
||||
import { migrateStatus } from './migrateStatus'
|
||||
import { queryDrafts } from './queryDrafts'
|
||||
import { beginTransaction } from './transactions/beginTransaction'
|
||||
import { commitTransaction } from './transactions/commitTransaction'
|
||||
import { rollbackTransaction } from './transactions/rollbackTransaction'
|
||||
import { updateOne } from './update'
|
||||
import { updateGlobal } from './updateGlobal'
|
||||
import { updateGlobalVersion } from './updateGlobalVersion'
|
||||
import { updateVersion } from './updateVersion'
|
||||
import { connect } from './connect.js'
|
||||
import { create } from './create.js'
|
||||
import { createGlobal } from './createGlobal.js'
|
||||
import { createGlobalVersion } from './createGlobalVersion.js'
|
||||
import { createMigration } from './createMigration.js'
|
||||
import { createVersion } from './createVersion.js'
|
||||
import { deleteMany } from './deleteMany.js'
|
||||
import { deleteOne } from './deleteOne.js'
|
||||
import { deleteVersions } from './deleteVersions.js'
|
||||
import { destroy } from './destroy.js'
|
||||
import { find } from './find.js'
|
||||
import { findGlobal } from './findGlobal.js'
|
||||
import { findGlobalVersions } from './findGlobalVersions.js'
|
||||
import { findOne } from './findOne.js'
|
||||
import { findVersions } from './findVersions.js'
|
||||
import { init } from './init.js'
|
||||
import { migrate } from './migrate.js'
|
||||
import { migrateDown } from './migrateDown.js'
|
||||
import { migrateFresh } from './migrateFresh.js'
|
||||
import { migrateRefresh } from './migrateRefresh.js'
|
||||
import { migrateReset } from './migrateReset.js'
|
||||
import { migrateStatus } from './migrateStatus.js'
|
||||
import { queryDrafts } from './queryDrafts.js'
|
||||
import { beginTransaction } from './transactions/beginTransaction.js'
|
||||
import { commitTransaction } from './transactions/commitTransaction.js'
|
||||
import { rollbackTransaction } from './transactions/rollbackTransaction.js'
|
||||
import { updateOne } from './update.js'
|
||||
import { updateGlobal } from './updateGlobal.js'
|
||||
import { updateGlobalVersion } from './updateGlobalVersion.js'
|
||||
import { updateVersion } from './updateVersion.js'
|
||||
|
||||
export type { MigrateDownArgs, MigrateUpArgs } from './types'
|
||||
export type { MigrateDownArgs, MigrateUpArgs } from './types.d.ts'
|
||||
|
||||
export function postgresAdapter(args: Args): DatabaseAdapterObj<PostgresAdapter> {
|
||||
function adapter({ payload }: { payload: Payload }) {
|
||||
|
||||
@@ -6,9 +6,9 @@ import { pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core'
|
||||
import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload/versions'
|
||||
import toSnakeCase from 'to-snake-case'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
import { buildTable } from './schema/build'
|
||||
import { buildTable } from './schema/build.js'
|
||||
|
||||
export const init: Init = async function init(this: PostgresAdapter) {
|
||||
if (this.schemaName) {
|
||||
|
||||
@@ -11,11 +11,11 @@ import {
|
||||
} from 'payload/database'
|
||||
import prompts from 'prompts'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
import { createMigrationTable } from './utilities/createMigrationTable'
|
||||
import { migrationTableExists } from './utilities/migrationTableExists'
|
||||
import { parseError } from './utilities/parseError'
|
||||
import { createMigrationTable } from './utilities/createMigrationTable.js'
|
||||
import { migrationTableExists } from './utilities/migrationTableExists.js'
|
||||
import { parseError } from './utilities/parseError.js'
|
||||
|
||||
export async function migrate(this: PostgresAdapter): Promise<void> {
|
||||
const { payload } = this
|
||||
|
||||
@@ -9,10 +9,10 @@ import {
|
||||
readMigrationFiles,
|
||||
} from 'payload/database'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
import { migrationTableExists } from './utilities/migrationTableExists'
|
||||
import { parseError } from './utilities/parseError'
|
||||
import { migrationTableExists } from './utilities/migrationTableExists.js'
|
||||
import { parseError } from './utilities/parseError.js'
|
||||
|
||||
export async function migrateDown(this: PostgresAdapter): Promise<void> {
|
||||
const { payload } = this
|
||||
|
||||
@@ -9,9 +9,9 @@ import {
|
||||
} from 'payload/database'
|
||||
import prompts from 'prompts'
|
||||
|
||||
import type { PostgresAdapter } from './types'
|
||||
import type { PostgresAdapter } from './types.d.ts'
|
||||
|
||||
import { parseError } from './utilities/parseError'
|
||||
import { parseError } from './utilities/parseError.js'
|
||||
|
||||
/**
|
||||
* Drop the current database and run all migrate up functions
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user