diff --git a/packages/dev/next.config.js b/packages/dev/next.config.js index 17ce6449f0..dd44a7b72c 100644 --- a/packages/dev/next.config.js +++ b/packages/dev/next.config.js @@ -1,9 +1,9 @@ /** @type {import('next').NextConfig} */ const nextConfig = { - // experimental: { - // serverComponentsExternalPackages: ['@payloadcms/db-mongodb'], - // }, - // transpilePackages: ['@payloadcms/db-mongodb'], + experimental: { + serverComponentsExternalPackages: ['@payloadcms/db-mongodb', 'mongoose'], + }, + transpilePackages: ['@payloadcms/db-mongodb', 'mongoose'], webpack: (config) => { return { ...config, diff --git a/packages/dev/package.json b/packages/dev/package.json index 2b9b2a048c..b7daebaab1 100644 --- a/packages/dev/package.json +++ b/packages/dev/package.json @@ -9,12 +9,13 @@ "lint": "next lint" }, "dependencies": { - "next": "14.0.2-canary.18", + "next": "14.0.2", "react": "^18", "react-dom": "^18" }, "devDependencies": { "@payloadcms/db-mongodb": "workspace:*", + "@payloadcms/next": "workspace:*", "@payloadcms/richtext-lexical": "workspace:*", "@types/node": "^20", "@types/react": "^18", diff --git a/packages/dev/src/app/(payload)/api/[collection]/init/route.ts b/packages/dev/src/app/(payload)/api/[collection]/init/route.ts index b9653f3ae7..650e8fce11 100644 --- a/packages/dev/src/app/(payload)/api/[collection]/init/route.ts +++ b/packages/dev/src/app/(payload)/api/[collection]/init/route.ts @@ -1,4 +1,6 @@ -import { initHandler } from 'payload/handlers' +/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */ +/* DO NOT MODIFY it because it could be re-written at any time. */ +import { init } from '@payloadcms/next/handlers' import config from 'payload-config' -export const GET = initHandler({ config }) +export const GET = init({ config }) diff --git a/packages/dev/tsconfig.json b/packages/dev/tsconfig.json index e542b7e0e5..a7c8450adc 100644 --- a/packages/dev/tsconfig.json +++ b/packages/dev/tsconfig.json @@ -12,16 +12,19 @@ "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", + "composite": true, // Make sure typescript knows that this module depends on their references "plugins": [ { "name": "next" } ], "paths": { - "payload-config": ["./src/payload.config.ts"] + "payload-config": ["./src/payload.config.ts"], + "@payloadcms/next/*": ["../next/src/exports/*.ts"] } }, "include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"], "exclude": ["node_modules"], - "references": [{ "path": "../payload" }] + "composite": true, // Make sure typescript knows that this module depends on their references + "references": [{ "path": "../payload" }, { "path": "../next" }] } diff --git a/packages/next/package.json b/packages/next/package.json new file mode 100644 index 0000000000..1096600a8c --- /dev/null +++ b/packages/next/package.json @@ -0,0 +1,41 @@ +{ + "name": "@payloadcms/next", + "version": "0.0.1", + "private": true, + "scripts": { + "build": "pnpm copyfiles && pnpm build:swc && pnpm build:types", + "build:swc": "swc ./src -d ./dist --config-file .swcrc", + "build:types": "tsc --emitDeclarationOnly --outDir dist", + "clean": "rimraf {dist,*.tsbuildinfo}", + "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/", + "prepublishOnly": "pnpm clean && pnpm build" + }, + "exports": { + "./*": { + "import": "./src/exports/*.ts", + "require": "./src/exports/*.ts", + "types": "./src/exports/*.ts" + } + }, + "devDependencies": { + "@payloadcms/eslint-config": "workspace:*", + "payload": "workspace:*" + }, + "peerDependencies": { + "payload": "^2.0.0" + }, + "publishConfig": { + "exports": { + "./*": { + "import": "./dist/exports/*.ts", + "require": "./dist/exports/*.ts", + "types": "./dist/exports/*.d.ts" + } + }, + "registry": "https://registry.npmjs.org/", + "types": "./dist/index.d.ts" + }, + "files": [ + "dist" + ] +} diff --git a/packages/next/src/app/api/[collection]/init/route.ts b/packages/next/src/app/api/[collection]/init/route.ts new file mode 100644 index 0000000000..650e8fce11 --- /dev/null +++ b/packages/next/src/app/api/[collection]/init/route.ts @@ -0,0 +1,6 @@ +/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */ +/* DO NOT MODIFY it because it could be re-written at any time. */ +import { init } from '@payloadcms/next/handlers' +import config from 'payload-config' + +export const GET = init({ config }) diff --git a/packages/next/src/config.ts b/packages/next/src/config.ts new file mode 100644 index 0000000000..eed110af03 --- /dev/null +++ b/packages/next/src/config.ts @@ -0,0 +1,3 @@ +import { SanitizedConfig } from 'payload/config' + +export default {} as Promise diff --git a/packages/next/src/createPayloadRequest.ts b/packages/next/src/createPayloadRequest.ts new file mode 100644 index 0000000000..dbed8f5360 --- /dev/null +++ b/packages/next/src/createPayloadRequest.ts @@ -0,0 +1,17 @@ +import type { SanitizedConfig, PayloadRequest } from 'payload/types' +import { getPayload } from 'payload' + +type Args = { + request: Request + config: Promise +} + +export const createPayloadRequest = async ({ request, config }: Args): Promise => { + const payload = await getPayload({ config }) + + const req: PayloadRequest = Object.assign(request, { + payload, + }) + + return req +} diff --git a/packages/next/src/exports/handlers.ts b/packages/next/src/exports/handlers.ts new file mode 100644 index 0000000000..34a8674d21 --- /dev/null +++ b/packages/next/src/exports/handlers.ts @@ -0,0 +1 @@ +export { init } from '../handlers/init' diff --git a/packages/next/src/handlers/init.ts b/packages/next/src/handlers/init.ts new file mode 100644 index 0000000000..1bb75fa418 --- /dev/null +++ b/packages/next/src/handlers/init.ts @@ -0,0 +1,15 @@ +import type { SanitizedConfig } from 'payload/types' +import { init as initOperation } from 'payload/operations' +import { createPayloadRequest } from '../createPayloadRequest' + +export const init = ({ config }: { config: Promise }) => + async function (request: Request, { params }: { params: { collection: string } }) { + const req = await createPayloadRequest({ request, config }) + + const initialized = await initOperation({ + collection: params.collection, + req, + }) + + return Response.json({ initialized }) + } diff --git a/packages/next/src/types.ts b/packages/next/src/types.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/next/tsconfig.json b/packages/next/tsconfig.json new file mode 100644 index 0000000000..de87db9a9f --- /dev/null +++ b/packages/next/tsconfig.json @@ -0,0 +1,27 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "composite": true, // Make sure typescript knows that this module depends on their references + "noEmit": false /* Do not emit outputs. */, + "emitDeclarationOnly": true, + "outDir": "./dist" /* Specify an output folder for all emitted files. */, + "rootDir": "./src" /* Specify the root folder within your source files. */, + "paths": { + "payload-config": ["./src/config.ts"] + } + }, + "exclude": [ + "dist", + "build", + "tests", + "test", + "node_modules", + ".eslintrc.js", + "src/**/*.spec.js", + "src/**/*.spec.jsx", + "src/**/*.spec.ts", + "src/**/*.spec.tsx" + ], + "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts", "src/**/*.json"], + "references": [{ "path": "../payload" }] +} diff --git a/packages/payload/src/auth/operations/init.ts b/packages/payload/src/auth/operations/init.ts index 118e85c2d9..4e7f664375 100644 --- a/packages/payload/src/auth/operations/init.ts +++ b/packages/payload/src/auth/operations/init.ts @@ -1,4 +1,4 @@ -import type { PayloadRequest } from '../../express/types' +import type { PayloadRequest } from '../../types' async function init(args: { collection: string; req: PayloadRequest }): Promise { const { collection: slug, req } = args diff --git a/packages/payload/src/exports/operations.ts b/packages/payload/src/exports/operations.ts new file mode 100644 index 0000000000..3cb1eb3587 --- /dev/null +++ b/packages/payload/src/exports/operations.ts @@ -0,0 +1 @@ +export { default as init } from '../auth/operations/init' diff --git a/packages/payload/src/exports/types.ts b/packages/payload/src/exports/types.ts index 8133ba2bfd..8390ce8955 100644 --- a/packages/payload/src/exports/types.ts +++ b/packages/payload/src/exports/types.ts @@ -45,7 +45,7 @@ export type { TypeWithID, } from './../collections/config/types' -export type { Access, AccessArgs } from './../config/types' +export type { Access, AccessArgs, SanitizedConfig } from './../config/types' export type { ArrayField, diff --git a/packages/payload/src/types/index.ts b/packages/payload/src/types/index.ts index 34d40147cb..2cdeadbbb1 100644 --- a/packages/payload/src/types/index.ts +++ b/packages/payload/src/types/index.ts @@ -1,7 +1,10 @@ +import type payload from '../' import type { TypeWithTimestamps } from '../collections/config/types' import type { validOperators } from './constants' -export type { PayloadRequest } from '../express/types' +export type PayloadRequest = Request & { + payload: typeof payload +} export type Operator = (typeof validOperators)[number] diff --git a/packages/ui/package.json b/packages/ui/package.json new file mode 100644 index 0000000000..518b69661a --- /dev/null +++ b/packages/ui/package.json @@ -0,0 +1,29 @@ +{ + "name": "@payloadcms/ui", + "version": "0.0.1", + "private": true, + "scripts": { + "build": "pnpm copyfiles && pnpm build:swc && pnpm build:types", + "build:swc": "swc ./src -d ./dist --config-file .swcrc", + "build:types": "tsc --emitDeclarationOnly --outDir dist", + "clean": "rimraf {dist,*.tsbuildinfo}", + "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/", + "prepublishOnly": "pnpm clean && pnpm build" + }, + "devDependencies": { + "@payloadcms/eslint-config": "workspace:*", + "payload": "workspace:*" + }, + "peerDependencies": { + "payload": "^2.0.0" + }, + "publishConfig": { + "exports": null, + "main": "./dist/index.js", + "registry": "https://registry.npmjs.org/", + "types": "./dist/index.d.ts" + }, + "files": [ + "dist" + ] +} diff --git a/packages/ui/tsconfig.json b/packages/ui/tsconfig.json new file mode 100644 index 0000000000..8aa2b21021 --- /dev/null +++ b/packages/ui/tsconfig.json @@ -0,0 +1,24 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "composite": true, // Make sure typescript knows that this module depends on their references + "noEmit": false /* Do not emit outputs. */, + "emitDeclarationOnly": true, + "outDir": "./dist" /* Specify an output folder for all emitted files. */, + "rootDir": "./src" /* Specify the root folder within your source files. */ + }, + "exclude": [ + "dist", + "build", + "tests", + "test", + "node_modules", + ".eslintrc.js", + "src/**/*.spec.js", + "src/**/*.spec.jsx", + "src/**/*.spec.ts", + "src/**/*.spec.tsx" + ], + "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts", "src/**/*.json"], + "references": [{ "path": "../payload" }] // db-postgres depends on payload +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 57c91b94d8..8d92b55111 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -498,8 +498,8 @@ importers: packages/dev: dependencies: next: - specifier: 14.0.2-canary.18 - version: 14.0.2-canary.18(@babel/core@7.22.20)(react-dom@18.2.0)(react@18.2.0) + specifier: 14.0.2 + version: 14.0.2(@babel/core@7.22.20)(react-dom@18.2.0)(react@18.2.0) react: specifier: ^18 version: 18.2.0 @@ -510,6 +510,9 @@ importers: '@payloadcms/db-mongodb': specifier: workspace:* version: link:../db-mongodb + '@payloadcms/next': + specifier: workspace:* + version: link:../next '@payloadcms/richtext-lexical': specifier: workspace:* version: link:../richtext-lexical @@ -605,6 +608,15 @@ importers: specifier: workspace:* version: link:../payload + packages/next: + devDependencies: + '@payloadcms/eslint-config': + specifier: workspace:* + version: link:../eslint-config-payload + payload: + specifier: workspace:* + version: link:../payload + packages/payload: dependencies: '@date-io/date-fns': @@ -1309,6 +1321,15 @@ importers: specifier: workspace:* version: link:../payload + packages/ui: + devDependencies: + '@payloadcms/eslint-config': + specifier: workspace:* + version: link:../eslint-config-payload + payload: + specifier: workspace:* + version: link:../payload + packages: /@aashutoshrathi/word-wrap@1.2.6: @@ -4180,12 +4201,12 @@ packages: sparse-bitfield: 3.0.3 optional: true - /@next/env@14.0.2-canary.18: - resolution: {integrity: sha512-P0TbiW5a1H2EjHuVsx1hcYRokZRNd8BxPIqw8GG9ZDbMLRQMZQt9MBhyQDavPjPaKvHenTsw2cztPjDxGkKBig==} + /@next/env@14.0.2: + resolution: {integrity: sha512-HAW1sljizEaduEOes/m84oUqeIDAUYBR1CDwu2tobNlNDFP3cSm9d6QsOsGeNlIppU1p/p1+bWbYCbvwjFiceA==} dev: false - /@next/swc-darwin-arm64@14.0.2-canary.18: - resolution: {integrity: sha512-7zEjO7sTC5vfYpIln8CFYO/Nm5mMZkdfMU/bpRA3SMyM2WWg5k9M+TEoJ71rQ3GpMvC9N5VzUJ8B2tRC8H/1Tw==} + /@next/swc-darwin-arm64@14.0.2: + resolution: {integrity: sha512-i+jQY0fOb8L5gvGvojWyZMfQoQtDVB2kYe7fufOEiST6sicvzI2W5/EXo4lX5bLUjapHKe+nFxuVv7BA+Pd7LQ==} engines: {node: '>= 10'} cpu: [arm64] os: [darwin] @@ -4193,8 +4214,8 @@ packages: dev: false optional: true - /@next/swc-darwin-x64@14.0.2-canary.18: - resolution: {integrity: sha512-2Jtr2HeR5YNFyyVV4nmwIVrpz97+fu+eqIsZC8JbwDcWtd4+Bbd/MnN7XCdyUHFrrhGBuRbX52LxMTMl9tnY6Q==} + /@next/swc-darwin-x64@14.0.2: + resolution: {integrity: sha512-zRCAO0d2hW6gBEa4wJaLn+gY8qtIqD3gYd9NjruuN98OCI6YyelmhWVVLlREjS7RYrm9OUQIp/iVJFeB6kP1hg==} engines: {node: '>= 10'} cpu: [x64] os: [darwin] @@ -4202,8 +4223,8 @@ packages: dev: false optional: true - /@next/swc-linux-arm64-gnu@14.0.2-canary.18: - resolution: {integrity: sha512-+p5xZod0o9HBffPH6s0/m8XXKK5/mmZK7jORyHBqGihOVZEuJFl0hGNNBqnIE7brUuRdGLlS4EYQvEHqtC9z3A==} + /@next/swc-linux-arm64-gnu@14.0.2: + resolution: {integrity: sha512-tSJmiaon8YaKsVhi7GgRizZoV0N1Sx5+i+hFTrCKKQN7s3tuqW0Rov+RYdPhAv/pJl4qiG+XfSX4eJXqpNg3dA==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] @@ -4211,8 +4232,8 @@ packages: dev: false optional: true - /@next/swc-linux-arm64-musl@14.0.2-canary.18: - resolution: {integrity: sha512-T7aXq6S6PlobMDEyxEb7B9hB3cMu6A9gWjD3gx6FrQEWp/V3+TrbBN/mXSpsT7QtvS1WA+vuK7jnS2IvpcJtXw==} + /@next/swc-linux-arm64-musl@14.0.2: + resolution: {integrity: sha512-dXJLMSEOwqJKcag1BeX1C+ekdPPJ9yXbWIt3nAadhbLx5CjACoB2NQj9Xcqu2tmdr5L6m34fR+fjGPs+ZVPLzA==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] @@ -4220,8 +4241,8 @@ packages: dev: false optional: true - /@next/swc-linux-x64-gnu@14.0.2-canary.18: - resolution: {integrity: sha512-aIKt/fUlSmpiBmprMXpcNSryAVaoW2/GbEsL1qvu5u6/oG85tKf7wtAkudF0UqVji8RM59YTqpn9iGeAdSpCfA==} + /@next/swc-linux-x64-gnu@14.0.2: + resolution: {integrity: sha512-WC9KAPSowj6as76P3vf1J3mf2QTm3Wv3FBzQi7UJ+dxWjK3MhHVWsWUo24AnmHx9qDcEtHM58okgZkXVqeLB+Q==} engines: {node: '>= 10'} cpu: [x64] os: [linux] @@ -4229,8 +4250,8 @@ packages: dev: false optional: true - /@next/swc-linux-x64-musl@14.0.2-canary.18: - resolution: {integrity: sha512-0eeuzkyVpfEodkSH3NNOAPq3/Zgb5l8nrpsWA7+bw7wztPuY41g+roD2BcslpZ1LaCgD38d4g7NPmXpKcGGVIA==} + /@next/swc-linux-x64-musl@14.0.2: + resolution: {integrity: sha512-KSSAwvUcjtdZY4zJFa2f5VNJIwuEVnOSlqYqbQIawREJA+gUI6egeiRu290pXioQXnQHYYdXmnVNZ4M+VMB7KQ==} engines: {node: '>= 10'} cpu: [x64] os: [linux] @@ -4238,8 +4259,8 @@ packages: dev: false optional: true - /@next/swc-win32-arm64-msvc@14.0.2-canary.18: - resolution: {integrity: sha512-wqA/P/tkb8VN22xLvekO5Ze+p3xuNPzzeIx+MFgxMZownxsMaRr9mjMZs7JgS3SXn3XYEIO98FVZoXCXPmC1Tg==} + /@next/swc-win32-arm64-msvc@14.0.2: + resolution: {integrity: sha512-2/O0F1SqJ0bD3zqNuYge0ok7OEWCQwk55RPheDYD0va5ij7kYwrFkq5ycCRN0TLjLfxSF6xI5NM6nC5ux7svEQ==} engines: {node: '>= 10'} cpu: [arm64] os: [win32] @@ -4247,8 +4268,8 @@ packages: dev: false optional: true - /@next/swc-win32-ia32-msvc@14.0.2-canary.18: - resolution: {integrity: sha512-5p6vXquoHiJ16agnghlCtCLj8zzAH54AEZr8Y8wsvHwH2afxqQgd/8WdnkSdpoqlKEkzD/GQyHkpJ0mwkiyvAw==} + /@next/swc-win32-ia32-msvc@14.0.2: + resolution: {integrity: sha512-vJI/x70Id0oN4Bq/R6byBqV1/NS5Dl31zC+lowO8SDu1fHmUxoAdILZR5X/sKbiJpuvKcCrwbYgJU8FF/Gh50Q==} engines: {node: '>= 10'} cpu: [ia32] os: [win32] @@ -4256,8 +4277,8 @@ packages: dev: false optional: true - /@next/swc-win32-x64-msvc@14.0.2-canary.18: - resolution: {integrity: sha512-JCrMBHM8KXZONoLVwbBghLVZxXkshpkZpl1mRlAEHLnYVSp6nXhV40pNDSHUP4lpd9hYTRXZF34BjzdLa8LB1Q==} + /@next/swc-win32-x64-msvc@14.0.2: + resolution: {integrity: sha512-Ut4LXIUvC5m8pHTe2j0vq/YDnTEyq6RSR9vHYPqnELrDapPhLNz9Od/L5Ow3J8RNDWpEnfCiQXuVdfjlNEJ7ug==} engines: {node: '>= 10'} cpu: [x64] os: [win32] @@ -13246,8 +13267,8 @@ packages: /next-tick@1.1.0: resolution: {integrity: sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==} - /next@14.0.2-canary.18(@babel/core@7.22.20)(react-dom@18.2.0)(react@18.2.0): - resolution: {integrity: sha512-ulPinl+SEPCn6BGYznkHQZE9YBW9TA1dJJyD8NUeJIriHN0ag28S5kzfgAYVKSQGyxViNETfroiyNDbZDV0gMQ==} + /next@14.0.2(@babel/core@7.22.20)(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-jsAU2CkYS40GaQYOiLl9m93RTv2DA/tTJ0NRlmZIBIL87YwQ/xR8k796z7IqgM3jydI8G25dXvyYMC9VDIevIg==} engines: {node: '>=18.17.0'} hasBin: true peerDependencies: @@ -13261,7 +13282,7 @@ packages: sass: optional: true dependencies: - '@next/env': 14.0.2-canary.18 + '@next/env': 14.0.2 '@swc/helpers': 0.5.2 busboy: 1.6.0 caniuse-lite: 1.0.30001535 @@ -13271,15 +13292,15 @@ packages: styled-jsx: 5.1.1(@babel/core@7.22.20)(react@18.2.0) watchpack: 2.4.0 optionalDependencies: - '@next/swc-darwin-arm64': 14.0.2-canary.18 - '@next/swc-darwin-x64': 14.0.2-canary.18 - '@next/swc-linux-arm64-gnu': 14.0.2-canary.18 - '@next/swc-linux-arm64-musl': 14.0.2-canary.18 - '@next/swc-linux-x64-gnu': 14.0.2-canary.18 - '@next/swc-linux-x64-musl': 14.0.2-canary.18 - '@next/swc-win32-arm64-msvc': 14.0.2-canary.18 - '@next/swc-win32-ia32-msvc': 14.0.2-canary.18 - '@next/swc-win32-x64-msvc': 14.0.2-canary.18 + '@next/swc-darwin-arm64': 14.0.2 + '@next/swc-darwin-x64': 14.0.2 + '@next/swc-linux-arm64-gnu': 14.0.2 + '@next/swc-linux-arm64-musl': 14.0.2 + '@next/swc-linux-x64-gnu': 14.0.2 + '@next/swc-linux-x64-musl': 14.0.2 + '@next/swc-win32-arm64-msvc': 14.0.2 + '@next/swc-win32-ia32-msvc': 14.0.2 + '@next/swc-win32-x64-msvc': 14.0.2 transitivePeerDependencies: - '@babel/core' - babel-plugin-macros diff --git a/tsconfig.json b/tsconfig.json index 1f6831d328..1798b887ae 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -39,6 +39,8 @@ { "path": "./packages/payload" }, { "path": "./packages/plugin-nested-docs" }, { "path": "./packages/live-preview" }, - { "path": "./packages/live-preview-react" } + { "path": "./packages/live-preview-react" }, + { "path": "./packages/next" }, + { "path": "./packages/ui" } ] }