chore: improves types for payloadRequest (#6012)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import type { QueryOptions } from 'mongoose'
|
import type { QueryOptions } from 'mongoose'
|
||||||
import type { Count } from 'payload/database'
|
import type { Count } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import { flattenWhereToOperators } from 'payload/database'
|
import { flattenWhereToOperators } from 'payload/database'
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ import { withSession } from './withSession.js'
|
|||||||
|
|
||||||
export const count: Count = async function count(
|
export const count: Count = async function count(
|
||||||
this: MongooseAdapter,
|
this: MongooseAdapter,
|
||||||
{ collection, locale, req = {} as PayloadRequest, where },
|
{ collection, locale, req = {} as PayloadRequestWithData, where },
|
||||||
) {
|
) {
|
||||||
const Model = this.collections[collection]
|
const Model = this.collections[collection]
|
||||||
const options: QueryOptions = withSession(this, req.transactionID)
|
const options: QueryOptions = withSession(this, req.transactionID)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { Create } from 'payload/database'
|
import type { Create } from 'payload/database'
|
||||||
import type { Document, PayloadRequest } from 'payload/types'
|
import type { Document, PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import type { MongooseAdapter } from './index.js'
|
import type { MongooseAdapter } from './index.js'
|
||||||
|
|
||||||
@@ -8,7 +8,7 @@ import { withSession } from './withSession.js'
|
|||||||
|
|
||||||
export const create: Create = async function create(
|
export const create: Create = async function create(
|
||||||
this: MongooseAdapter,
|
this: MongooseAdapter,
|
||||||
{ collection, data, req = {} as PayloadRequest },
|
{ collection, data, req = {} as PayloadRequestWithData },
|
||||||
) {
|
) {
|
||||||
const Model = this.collections[collection]
|
const Model = this.collections[collection]
|
||||||
const options = withSession(this, req.transactionID)
|
const options = withSession(this, req.transactionID)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { CreateGlobal } from 'payload/database'
|
import type { CreateGlobal } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import type { MongooseAdapter } from './index.js'
|
import type { MongooseAdapter } from './index.js'
|
||||||
|
|
||||||
@@ -8,7 +8,7 @@ import { withSession } from './withSession.js'
|
|||||||
|
|
||||||
export const createGlobal: CreateGlobal = async function createGlobal(
|
export const createGlobal: CreateGlobal = async function createGlobal(
|
||||||
this: MongooseAdapter,
|
this: MongooseAdapter,
|
||||||
{ slug, data, req = {} as PayloadRequest },
|
{ slug, data, req = {} as PayloadRequestWithData },
|
||||||
) {
|
) {
|
||||||
const Model = this.globals
|
const Model = this.globals
|
||||||
const global = {
|
const global = {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { CreateGlobalVersion } from 'payload/database'
|
import type { CreateGlobalVersion } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
import type { Document } from 'payload/types'
|
import type { Document } from 'payload/types'
|
||||||
|
|
||||||
import type { MongooseAdapter } from './index.js'
|
import type { MongooseAdapter } from './index.js'
|
||||||
@@ -8,7 +8,15 @@ import { withSession } from './withSession.js'
|
|||||||
|
|
||||||
export const createGlobalVersion: CreateGlobalVersion = async function createGlobalVersion(
|
export const createGlobalVersion: CreateGlobalVersion = async function createGlobalVersion(
|
||||||
this: MongooseAdapter,
|
this: MongooseAdapter,
|
||||||
{ autosave, createdAt, globalSlug, parent, req = {} as PayloadRequest, updatedAt, versionData },
|
{
|
||||||
|
autosave,
|
||||||
|
createdAt,
|
||||||
|
globalSlug,
|
||||||
|
parent,
|
||||||
|
req = {} as PayloadRequestWithData,
|
||||||
|
updatedAt,
|
||||||
|
versionData,
|
||||||
|
},
|
||||||
) {
|
) {
|
||||||
const VersionModel = this.versions[globalSlug]
|
const VersionModel = this.versions[globalSlug]
|
||||||
const options = withSession(this, req.transactionID)
|
const options = withSession(this, req.transactionID)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { CreateVersion } from 'payload/database'
|
import type { CreateVersion } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
import type { Document } from 'payload/types'
|
import type { Document } from 'payload/types'
|
||||||
|
|
||||||
import type { MongooseAdapter } from './index.js'
|
import type { MongooseAdapter } from './index.js'
|
||||||
@@ -13,7 +13,7 @@ export const createVersion: CreateVersion = async function createVersion(
|
|||||||
collectionSlug,
|
collectionSlug,
|
||||||
createdAt,
|
createdAt,
|
||||||
parent,
|
parent,
|
||||||
req = {} as PayloadRequest,
|
req = {} as PayloadRequestWithData,
|
||||||
updatedAt,
|
updatedAt,
|
||||||
versionData,
|
versionData,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { DeleteMany } from 'payload/database'
|
import type { DeleteMany } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import type { MongooseAdapter } from './index.js'
|
import type { MongooseAdapter } from './index.js'
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ import { withSession } from './withSession.js'
|
|||||||
|
|
||||||
export const deleteMany: DeleteMany = async function deleteMany(
|
export const deleteMany: DeleteMany = async function deleteMany(
|
||||||
this: MongooseAdapter,
|
this: MongooseAdapter,
|
||||||
{ collection, req = {} as PayloadRequest, where },
|
{ collection, req = {} as PayloadRequestWithData, where },
|
||||||
) {
|
) {
|
||||||
const Model = this.collections[collection]
|
const Model = this.collections[collection]
|
||||||
const options = {
|
const options = {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { DeleteOne } from 'payload/database'
|
import type { DeleteOne } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
import type { Document } from 'payload/types'
|
import type { Document } from 'payload/types'
|
||||||
|
|
||||||
import type { MongooseAdapter } from './index.js'
|
import type { MongooseAdapter } from './index.js'
|
||||||
@@ -9,7 +9,7 @@ import { withSession } from './withSession.js'
|
|||||||
|
|
||||||
export const deleteOne: DeleteOne = async function deleteOne(
|
export const deleteOne: DeleteOne = async function deleteOne(
|
||||||
this: MongooseAdapter,
|
this: MongooseAdapter,
|
||||||
{ collection, req = {} as PayloadRequest, where },
|
{ collection, req = {} as PayloadRequestWithData, where },
|
||||||
) {
|
) {
|
||||||
const Model = this.collections[collection]
|
const Model = this.collections[collection]
|
||||||
const options = withSession(this, req.transactionID)
|
const options = withSession(this, req.transactionID)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { DeleteVersions } from 'payload/database'
|
import type { DeleteVersions } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import type { MongooseAdapter } from './index.js'
|
import type { MongooseAdapter } from './index.js'
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ import { withSession } from './withSession.js'
|
|||||||
|
|
||||||
export const deleteVersions: DeleteVersions = async function deleteVersions(
|
export const deleteVersions: DeleteVersions = async function deleteVersions(
|
||||||
this: MongooseAdapter,
|
this: MongooseAdapter,
|
||||||
{ collection, locale, req = {} as PayloadRequest, where },
|
{ collection, locale, req = {} as PayloadRequestWithData, where },
|
||||||
) {
|
) {
|
||||||
const VersionsModel = this.versions[collection]
|
const VersionsModel = this.versions[collection]
|
||||||
const options = {
|
const options = {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { PaginateOptions } from 'mongoose'
|
import type { PaginateOptions } from 'mongoose'
|
||||||
import type { Find } from 'payload/database'
|
import type { Find } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import { flattenWhereToOperators } from 'payload/database'
|
import { flattenWhereToOperators } from 'payload/database'
|
||||||
|
|
||||||
@@ -12,7 +12,16 @@ import { withSession } from './withSession.js'
|
|||||||
|
|
||||||
export const find: Find = async function find(
|
export const find: Find = async function find(
|
||||||
this: MongooseAdapter,
|
this: MongooseAdapter,
|
||||||
{ collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },
|
{
|
||||||
|
collection,
|
||||||
|
limit,
|
||||||
|
locale,
|
||||||
|
page,
|
||||||
|
pagination,
|
||||||
|
req = {} as PayloadRequestWithData,
|
||||||
|
sort: sortArg,
|
||||||
|
where,
|
||||||
|
},
|
||||||
) {
|
) {
|
||||||
const Model = this.collections[collection]
|
const Model = this.collections[collection]
|
||||||
const collectionConfig = this.payload.collections[collection].config
|
const collectionConfig = this.payload.collections[collection].config
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { FindGlobal } from 'payload/database'
|
import type { FindGlobal } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import { combineQueries } from 'payload/database'
|
import { combineQueries } from 'payload/database'
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ import { withSession } from './withSession.js'
|
|||||||
|
|
||||||
export const findGlobal: FindGlobal = async function findGlobal(
|
export const findGlobal: FindGlobal = async function findGlobal(
|
||||||
this: MongooseAdapter,
|
this: MongooseAdapter,
|
||||||
{ slug, locale, req = {} as PayloadRequest, where },
|
{ slug, locale, req = {} as PayloadRequestWithData, where },
|
||||||
) {
|
) {
|
||||||
const Model = this.globals
|
const Model = this.globals
|
||||||
const options = {
|
const options = {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { PaginateOptions } from 'mongoose'
|
import type { PaginateOptions } from 'mongoose'
|
||||||
import type { FindGlobalVersions } from 'payload/database'
|
import type { FindGlobalVersions } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import { flattenWhereToOperators } from 'payload/database'
|
import { flattenWhereToOperators } from 'payload/database'
|
||||||
import { buildVersionGlobalFields } from 'payload/versions'
|
import { buildVersionGlobalFields } from 'payload/versions'
|
||||||
@@ -19,7 +19,7 @@ export const findGlobalVersions: FindGlobalVersions = async function findGlobalV
|
|||||||
locale,
|
locale,
|
||||||
page,
|
page,
|
||||||
pagination,
|
pagination,
|
||||||
req = {} as PayloadRequest,
|
req = {} as PayloadRequestWithData,
|
||||||
skip,
|
skip,
|
||||||
sort: sortArg,
|
sort: sortArg,
|
||||||
where,
|
where,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { MongooseQueryOptions } from 'mongoose'
|
import type { MongooseQueryOptions } from 'mongoose'
|
||||||
import type { FindOne } from 'payload/database'
|
import type { FindOne } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
import type { Document } from 'payload/types'
|
import type { Document } from 'payload/types'
|
||||||
|
|
||||||
import type { MongooseAdapter } from './index.js'
|
import type { MongooseAdapter } from './index.js'
|
||||||
@@ -10,7 +10,7 @@ import { withSession } from './withSession.js'
|
|||||||
|
|
||||||
export const findOne: FindOne = async function findOne(
|
export const findOne: FindOne = async function findOne(
|
||||||
this: MongooseAdapter,
|
this: MongooseAdapter,
|
||||||
{ collection, locale, req = {} as PayloadRequest, where },
|
{ collection, locale, req = {} as PayloadRequestWithData, where },
|
||||||
) {
|
) {
|
||||||
const Model = this.collections[collection]
|
const Model = this.collections[collection]
|
||||||
const options: MongooseQueryOptions = {
|
const options: MongooseQueryOptions = {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { PaginateOptions } from 'mongoose'
|
import type { PaginateOptions } from 'mongoose'
|
||||||
import type { FindVersions } from 'payload/database'
|
import type { FindVersions } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import { flattenWhereToOperators } from 'payload/database'
|
import { flattenWhereToOperators } from 'payload/database'
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ export const findVersions: FindVersions = async function findVersions(
|
|||||||
locale,
|
locale,
|
||||||
page,
|
page,
|
||||||
pagination,
|
pagination,
|
||||||
req = {} as PayloadRequest,
|
req = {} as PayloadRequestWithData,
|
||||||
skip,
|
skip,
|
||||||
sort: sortArg,
|
sort: sortArg,
|
||||||
where,
|
where,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
commitTransaction,
|
commitTransaction,
|
||||||
@@ -50,7 +50,7 @@ export async function migrateFresh(
|
|||||||
msg: `Found ${migrationFiles.length} migration files.`,
|
msg: `Found ${migrationFiles.length} migration files.`,
|
||||||
})
|
})
|
||||||
|
|
||||||
const req = { payload } as PayloadRequest
|
const req = { payload } as PayloadRequestWithData
|
||||||
|
|
||||||
// Run all migrate up
|
// Run all migrate up
|
||||||
for (const migration of migrationFiles) {
|
for (const migration of migrationFiles) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { PaginateOptions } from 'mongoose'
|
import type { PaginateOptions } from 'mongoose'
|
||||||
import type { QueryDrafts } from 'payload/database'
|
import type { QueryDrafts } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import { combineQueries, flattenWhereToOperators } from 'payload/database'
|
import { combineQueries, flattenWhereToOperators } from 'payload/database'
|
||||||
|
|
||||||
@@ -12,7 +12,16 @@ import { withSession } from './withSession.js'
|
|||||||
|
|
||||||
export const queryDrafts: QueryDrafts = async function queryDrafts(
|
export const queryDrafts: QueryDrafts = async function queryDrafts(
|
||||||
this: MongooseAdapter,
|
this: MongooseAdapter,
|
||||||
{ collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },
|
{
|
||||||
|
collection,
|
||||||
|
limit,
|
||||||
|
locale,
|
||||||
|
page,
|
||||||
|
pagination,
|
||||||
|
req = {} as PayloadRequestWithData,
|
||||||
|
sort: sortArg,
|
||||||
|
where,
|
||||||
|
},
|
||||||
) {
|
) {
|
||||||
const VersionModel = this.versions[collection]
|
const VersionModel = this.versions[collection]
|
||||||
const collectionConfig = this.payload.collections[collection].config
|
const collectionConfig = this.payload.collections[collection].config
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { UpdateGlobal } from 'payload/database'
|
import type { UpdateGlobal } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import type { MongooseAdapter } from './index.js'
|
import type { MongooseAdapter } from './index.js'
|
||||||
|
|
||||||
@@ -8,7 +8,7 @@ import { withSession } from './withSession.js'
|
|||||||
|
|
||||||
export const updateGlobal: UpdateGlobal = async function updateGlobal(
|
export const updateGlobal: UpdateGlobal = async function updateGlobal(
|
||||||
this: MongooseAdapter,
|
this: MongooseAdapter,
|
||||||
{ slug, data, req = {} as PayloadRequest },
|
{ slug, data, req = {} as PayloadRequestWithData },
|
||||||
) {
|
) {
|
||||||
const Model = this.globals
|
const Model = this.globals
|
||||||
const options = {
|
const options = {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { UpdateGlobalVersionArgs } from 'payload/database'
|
import type { UpdateGlobalVersionArgs } from 'payload/database'
|
||||||
import type { PayloadRequest, TypeWithID } from 'payload/types'
|
import type { PayloadRequestWithData, TypeWithID } from 'payload/types'
|
||||||
|
|
||||||
import type { MongooseAdapter } from './index.js'
|
import type { MongooseAdapter } from './index.js'
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ export async function updateGlobalVersion<T extends TypeWithID>(
|
|||||||
id,
|
id,
|
||||||
global,
|
global,
|
||||||
locale,
|
locale,
|
||||||
req = {} as PayloadRequest,
|
req = {} as PayloadRequestWithData,
|
||||||
versionData,
|
versionData,
|
||||||
where,
|
where,
|
||||||
}: UpdateGlobalVersionArgs<T>,
|
}: UpdateGlobalVersionArgs<T>,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { UpdateOne } from 'payload/database'
|
import type { UpdateOne } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import type { MongooseAdapter } from './index.js'
|
import type { MongooseAdapter } from './index.js'
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ import { withSession } from './withSession.js'
|
|||||||
|
|
||||||
export const updateOne: UpdateOne = async function updateOne(
|
export const updateOne: UpdateOne = async function updateOne(
|
||||||
this: MongooseAdapter,
|
this: MongooseAdapter,
|
||||||
{ id, collection, data, locale, req = {} as PayloadRequest, where: whereArg },
|
{ id, collection, data, locale, req = {} as PayloadRequestWithData, where: whereArg },
|
||||||
) {
|
) {
|
||||||
const where = id ? { id: { equals: id } } : whereArg
|
const where = id ? { id: { equals: id } } : whereArg
|
||||||
const Model = this.collections[collection]
|
const Model = this.collections[collection]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { UpdateVersion } from 'payload/database'
|
import type { UpdateVersion } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import type { MongooseAdapter } from './index.js'
|
import type { MongooseAdapter } from './index.js'
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ import { withSession } from './withSession.js'
|
|||||||
|
|
||||||
export const updateVersion: UpdateVersion = async function updateVersion(
|
export const updateVersion: UpdateVersion = async function updateVersion(
|
||||||
this: MongooseAdapter,
|
this: MongooseAdapter,
|
||||||
{ id, collection, locale, req = {} as PayloadRequest, versionData, where },
|
{ id, collection, locale, req = {} as PayloadRequestWithData, versionData, where },
|
||||||
) {
|
) {
|
||||||
const VersionModel = this.versions[collection]
|
const VersionModel = this.versions[collection]
|
||||||
const whereToUse = where || { id: { equals: id } }
|
const whereToUse = where || { id: { equals: id } }
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { CreateGlobalArgs } from 'payload/database'
|
import type { CreateGlobalArgs } from 'payload/database'
|
||||||
import type { PayloadRequest, TypeWithID } from 'payload/types'
|
import type { PayloadRequestWithData, TypeWithID } from 'payload/types'
|
||||||
|
|
||||||
import toSnakeCase from 'to-snake-case'
|
import toSnakeCase from 'to-snake-case'
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ import { upsertRow } from './upsertRow/index.js'
|
|||||||
|
|
||||||
export async function createGlobal<T extends TypeWithID>(
|
export async function createGlobal<T extends TypeWithID>(
|
||||||
this: PostgresAdapter,
|
this: PostgresAdapter,
|
||||||
{ slug, data, req = {} as PayloadRequest }: CreateGlobalArgs,
|
{ slug, data, req = {} as PayloadRequestWithData }: CreateGlobalArgs,
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
const db = this.sessions[req.transactionID]?.db || this.drizzle
|
const db = this.sessions[req.transactionID]?.db || this.drizzle
|
||||||
const globalConfig = this.payload.globals.config.find((config) => config.slug === slug)
|
const globalConfig = this.payload.globals.config.find((config) => config.slug === slug)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { TypeWithVersion } from 'payload/database'
|
import type { TypeWithVersion } from 'payload/database'
|
||||||
import type { PayloadRequest, TypeWithID } from 'payload/types'
|
import type { PayloadRequestWithData, TypeWithID } from 'payload/types'
|
||||||
|
|
||||||
import { sql } from 'drizzle-orm'
|
import { sql } from 'drizzle-orm'
|
||||||
import { type CreateGlobalVersionArgs } from 'payload/database'
|
import { type CreateGlobalVersionArgs } from 'payload/database'
|
||||||
@@ -12,7 +12,12 @@ import { upsertRow } from './upsertRow/index.js'
|
|||||||
|
|
||||||
export async function createGlobalVersion<T extends TypeWithID>(
|
export async function createGlobalVersion<T extends TypeWithID>(
|
||||||
this: PostgresAdapter,
|
this: PostgresAdapter,
|
||||||
{ autosave, globalSlug, req = {} as PayloadRequest, versionData }: CreateGlobalVersionArgs,
|
{
|
||||||
|
autosave,
|
||||||
|
globalSlug,
|
||||||
|
req = {} as PayloadRequestWithData,
|
||||||
|
versionData,
|
||||||
|
}: CreateGlobalVersionArgs,
|
||||||
) {
|
) {
|
||||||
const db = this.sessions[req.transactionID]?.db || this.drizzle
|
const db = this.sessions[req.transactionID]?.db || this.drizzle
|
||||||
const global = this.payload.globals.config.find(({ slug }) => slug === globalSlug)
|
const global = this.payload.globals.config.find(({ slug }) => slug === globalSlug)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { CreateVersionArgs, TypeWithVersion } from 'payload/database'
|
import type { CreateVersionArgs, TypeWithVersion } from 'payload/database'
|
||||||
import type { PayloadRequest, TypeWithID } from 'payload/types'
|
import type { PayloadRequestWithData, TypeWithID } from 'payload/types'
|
||||||
|
|
||||||
import { sql } from 'drizzle-orm'
|
import { sql } from 'drizzle-orm'
|
||||||
import { buildVersionCollectionFields } from 'payload/versions'
|
import { buildVersionCollectionFields } from 'payload/versions'
|
||||||
@@ -15,7 +15,7 @@ export async function createVersion<T extends TypeWithID>(
|
|||||||
autosave,
|
autosave,
|
||||||
collectionSlug,
|
collectionSlug,
|
||||||
parent,
|
parent,
|
||||||
req = {} as PayloadRequest,
|
req = {} as PayloadRequestWithData,
|
||||||
versionData,
|
versionData,
|
||||||
}: CreateVersionArgs<T>,
|
}: CreateVersionArgs<T>,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { DeleteMany } from 'payload/database'
|
import type { DeleteMany } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import { inArray } from 'drizzle-orm'
|
import { inArray } from 'drizzle-orm'
|
||||||
import toSnakeCase from 'to-snake-case'
|
import toSnakeCase from 'to-snake-case'
|
||||||
@@ -10,7 +10,7 @@ import { findMany } from './find/findMany.js'
|
|||||||
|
|
||||||
export const deleteMany: DeleteMany = async function deleteMany(
|
export const deleteMany: DeleteMany = async function deleteMany(
|
||||||
this: PostgresAdapter,
|
this: PostgresAdapter,
|
||||||
{ collection, req = {} as PayloadRequest, where },
|
{ collection, req = {} as PayloadRequestWithData, where },
|
||||||
) {
|
) {
|
||||||
const db = this.sessions[req.transactionID]?.db || this.drizzle
|
const db = this.sessions[req.transactionID]?.db || this.drizzle
|
||||||
const collectionConfig = this.payload.collections[collection].config
|
const collectionConfig = this.payload.collections[collection].config
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { DeleteOne } from 'payload/database'
|
import type { DeleteOne } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import { eq } from 'drizzle-orm'
|
import { eq } from 'drizzle-orm'
|
||||||
import toSnakeCase from 'to-snake-case'
|
import toSnakeCase from 'to-snake-case'
|
||||||
@@ -13,7 +13,7 @@ import { transform } from './transform/read/index.js'
|
|||||||
|
|
||||||
export const deleteOne: DeleteOne = async function deleteOne(
|
export const deleteOne: DeleteOne = async function deleteOne(
|
||||||
this: PostgresAdapter,
|
this: PostgresAdapter,
|
||||||
{ collection: collectionSlug, req = {} as PayloadRequest, where: whereArg },
|
{ collection: collectionSlug, req = {} as PayloadRequestWithData, where: whereArg },
|
||||||
) {
|
) {
|
||||||
const db = this.sessions[req.transactionID]?.db || this.drizzle
|
const db = this.sessions[req.transactionID]?.db || this.drizzle
|
||||||
const collection = this.payload.collections[collectionSlug].config
|
const collection = this.payload.collections[collectionSlug].config
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { DeleteVersions } from 'payload/database'
|
import type { DeleteVersions } from 'payload/database'
|
||||||
import type { PayloadRequest, SanitizedCollectionConfig } from 'payload/types'
|
import type { PayloadRequestWithData, SanitizedCollectionConfig } from 'payload/types'
|
||||||
|
|
||||||
import { inArray } from 'drizzle-orm'
|
import { inArray } from 'drizzle-orm'
|
||||||
import { buildVersionCollectionFields } from 'payload/versions'
|
import { buildVersionCollectionFields } from 'payload/versions'
|
||||||
@@ -11,7 +11,7 @@ import { findMany } from './find/findMany.js'
|
|||||||
|
|
||||||
export const deleteVersions: DeleteVersions = async function deleteVersion(
|
export const deleteVersions: DeleteVersions = async function deleteVersion(
|
||||||
this: PostgresAdapter,
|
this: PostgresAdapter,
|
||||||
{ collection, locale, req = {} as PayloadRequest, where: where },
|
{ collection, locale, req = {} as PayloadRequestWithData, where: where },
|
||||||
) {
|
) {
|
||||||
const db = this.sessions[req.transactionID]?.db || this.drizzle
|
const db = this.sessions[req.transactionID]?.db || this.drizzle
|
||||||
const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config
|
const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { Find } from 'payload/database'
|
import type { Find } from 'payload/database'
|
||||||
import type { PayloadRequest, SanitizedCollectionConfig } from 'payload/types'
|
import type { PayloadRequestWithData, SanitizedCollectionConfig } from 'payload/types'
|
||||||
|
|
||||||
import toSnakeCase from 'to-snake-case'
|
import toSnakeCase from 'to-snake-case'
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ export const find: Find = async function find(
|
|||||||
locale,
|
locale,
|
||||||
page = 1,
|
page = 1,
|
||||||
pagination,
|
pagination,
|
||||||
req = {} as PayloadRequest,
|
req = {} as PayloadRequestWithData,
|
||||||
sort: sortArg,
|
sort: sortArg,
|
||||||
where,
|
where,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { FindArgs } from 'payload/database'
|
import type { FindArgs } from 'payload/database'
|
||||||
import type { Field, PayloadRequest, TypeWithID } from 'payload/types'
|
import type { Field, PayloadRequestWithData, TypeWithID } from 'payload/types'
|
||||||
|
|
||||||
import { inArray, sql } from 'drizzle-orm'
|
import { inArray, sql } from 'drizzle-orm'
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ export const findMany = async function find({
|
|||||||
locale,
|
locale,
|
||||||
page = 1,
|
page = 1,
|
||||||
pagination,
|
pagination,
|
||||||
req = {} as PayloadRequest,
|
req = {} as PayloadRequestWithData,
|
||||||
skip,
|
skip,
|
||||||
sort,
|
sort,
|
||||||
tableName,
|
tableName,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { FindGlobalVersions } from 'payload/database'
|
import type { FindGlobalVersions } from 'payload/database'
|
||||||
import type { PayloadRequest, SanitizedGlobalConfig } from 'payload/types'
|
import type { PayloadRequestWithData, SanitizedGlobalConfig } from 'payload/types'
|
||||||
|
|
||||||
import { buildVersionGlobalFields } from 'payload/versions'
|
import { buildVersionGlobalFields } from 'payload/versions'
|
||||||
import toSnakeCase from 'to-snake-case'
|
import toSnakeCase from 'to-snake-case'
|
||||||
@@ -16,7 +16,7 @@ export const findGlobalVersions: FindGlobalVersions = async function findGlobalV
|
|||||||
locale,
|
locale,
|
||||||
page,
|
page,
|
||||||
pagination,
|
pagination,
|
||||||
req = {} as PayloadRequest,
|
req = {} as PayloadRequestWithData,
|
||||||
skip,
|
skip,
|
||||||
sort: sortArg,
|
sort: sortArg,
|
||||||
where,
|
where,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { FindOneArgs } from 'payload/database'
|
import type { FindOneArgs } from 'payload/database'
|
||||||
import type { PayloadRequest, SanitizedCollectionConfig, TypeWithID } from 'payload/types'
|
import type { PayloadRequestWithData, SanitizedCollectionConfig, TypeWithID } from 'payload/types'
|
||||||
|
|
||||||
import toSnakeCase from 'to-snake-case'
|
import toSnakeCase from 'to-snake-case'
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ import { findMany } from './find/findMany.js'
|
|||||||
|
|
||||||
export async function findOne<T extends TypeWithID>(
|
export async function findOne<T extends TypeWithID>(
|
||||||
this: PostgresAdapter,
|
this: PostgresAdapter,
|
||||||
{ collection, locale, req = {} as PayloadRequest, where }: FindOneArgs,
|
{ collection, locale, req = {} as PayloadRequestWithData, where }: FindOneArgs,
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config
|
const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { FindVersions } from 'payload/database'
|
import type { FindVersions } from 'payload/database'
|
||||||
import type { PayloadRequest, SanitizedCollectionConfig } from 'payload/types'
|
import type { PayloadRequestWithData, SanitizedCollectionConfig } from 'payload/types'
|
||||||
|
|
||||||
import { buildVersionCollectionFields } from 'payload/versions'
|
import { buildVersionCollectionFields } from 'payload/versions'
|
||||||
import toSnakeCase from 'to-snake-case'
|
import toSnakeCase from 'to-snake-case'
|
||||||
@@ -16,7 +16,7 @@ export const findVersions: FindVersions = async function findVersions(
|
|||||||
locale,
|
locale,
|
||||||
page,
|
page,
|
||||||
pagination,
|
pagination,
|
||||||
req = {} as PayloadRequest,
|
req = {} as PayloadRequestWithData,
|
||||||
skip,
|
skip,
|
||||||
sort: sortArg,
|
sort: sortArg,
|
||||||
where,
|
where,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable no-restricted-syntax, no-await-in-loop */
|
/* eslint-disable no-restricted-syntax, no-await-in-loop */
|
||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
import type { Migration } from 'payload/database'
|
import type { Migration } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import { createRequire } from 'module'
|
import { createRequire } from 'module'
|
||||||
import {
|
import {
|
||||||
@@ -88,7 +88,7 @@ async function runMigrationFile(payload: Payload, migration: Migration, batch: n
|
|||||||
const { generateDrizzleJson } = require('drizzle-kit/payload')
|
const { generateDrizzleJson } = require('drizzle-kit/payload')
|
||||||
|
|
||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
const req = { payload } as PayloadRequest
|
const req = { payload } as PayloadRequestWithData
|
||||||
|
|
||||||
payload.logger.info({ msg: `Migrating: ${migration.name}` })
|
payload.logger.info({ msg: `Migrating: ${migration.name}` })
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable no-restricted-syntax, no-await-in-loop */
|
/* eslint-disable no-restricted-syntax, no-await-in-loop */
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
commitTransaction,
|
commitTransaction,
|
||||||
@@ -40,7 +40,7 @@ export async function migrateDown(this: PostgresAdapter): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
const req = { payload } as PayloadRequest
|
const req = { payload } as PayloadRequestWithData
|
||||||
|
|
||||||
try {
|
try {
|
||||||
payload.logger.info({ msg: `Migrating down: ${migrationFile.name}` })
|
payload.logger.info({ msg: `Migrating down: ${migrationFile.name}` })
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import { sql } from 'drizzle-orm'
|
import { sql } from 'drizzle-orm'
|
||||||
import {
|
import {
|
||||||
@@ -56,7 +56,7 @@ export async function migrateFresh(
|
|||||||
msg: `Found ${migrationFiles.length} migration files.`,
|
msg: `Found ${migrationFiles.length} migration files.`,
|
||||||
})
|
})
|
||||||
|
|
||||||
const req = { payload } as PayloadRequest
|
const req = { payload } as PayloadRequestWithData
|
||||||
// Run all migrate up
|
// Run all migrate up
|
||||||
for (const migration of migrationFiles) {
|
for (const migration of migrationFiles) {
|
||||||
payload.logger.info({ msg: `Migrating: ${migration.name}` })
|
payload.logger.info({ msg: `Migrating: ${migration.name}` })
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable no-restricted-syntax, no-await-in-loop */
|
/* eslint-disable no-restricted-syntax, no-await-in-loop */
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
commitTransaction,
|
commitTransaction,
|
||||||
@@ -34,7 +34,7 @@ export async function migrateRefresh(this: PostgresAdapter) {
|
|||||||
msg: `Rolling back batch ${latestBatch} consisting of ${existingMigrations.length} migration(s).`,
|
msg: `Rolling back batch ${latestBatch} consisting of ${existingMigrations.length} migration(s).`,
|
||||||
})
|
})
|
||||||
|
|
||||||
const req = { payload } as PayloadRequest
|
const req = { payload } as PayloadRequestWithData
|
||||||
|
|
||||||
// Reverse order of migrations to rollback
|
// Reverse order of migrations to rollback
|
||||||
existingMigrations.reverse()
|
existingMigrations.reverse()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable no-restricted-syntax, no-await-in-loop */
|
/* eslint-disable no-restricted-syntax, no-await-in-loop */
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
commitTransaction,
|
commitTransaction,
|
||||||
@@ -27,7 +27,7 @@ export async function migrateReset(this: PostgresAdapter): Promise<void> {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const req = { payload } as PayloadRequest
|
const req = { payload } as PayloadRequestWithData
|
||||||
|
|
||||||
// Rollback all migrations in order
|
// Rollback all migrations in order
|
||||||
for (const migration of existingMigrations) {
|
for (const migration of existingMigrations) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { PayloadRequest, SanitizedCollectionConfig } from 'payload/types'
|
import type { PayloadRequestWithData, SanitizedCollectionConfig } from 'payload/types'
|
||||||
|
|
||||||
import { type QueryDrafts, combineQueries } from 'payload/database'
|
import { type QueryDrafts, combineQueries } from 'payload/database'
|
||||||
import { buildVersionCollectionFields } from 'payload/versions'
|
import { buildVersionCollectionFields } from 'payload/versions'
|
||||||
@@ -10,7 +10,16 @@ import { findMany } from './find/findMany.js'
|
|||||||
|
|
||||||
export const queryDrafts: QueryDrafts = async function queryDrafts(
|
export const queryDrafts: QueryDrafts = async function queryDrafts(
|
||||||
this: PostgresAdapter,
|
this: PostgresAdapter,
|
||||||
{ collection, limit, locale, page = 1, pagination, req = {} as PayloadRequest, sort, where },
|
{
|
||||||
|
collection,
|
||||||
|
limit,
|
||||||
|
locale,
|
||||||
|
page = 1,
|
||||||
|
pagination,
|
||||||
|
req = {} as PayloadRequestWithData,
|
||||||
|
sort,
|
||||||
|
where,
|
||||||
|
},
|
||||||
) {
|
) {
|
||||||
const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config
|
const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config
|
||||||
const tableName = this.tableNameMap.get(
|
const tableName = this.tableNameMap.get(
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import type {
|
|||||||
import type { PgTableFn } from 'drizzle-orm/pg-core/table'
|
import type { PgTableFn } from 'drizzle-orm/pg-core/table'
|
||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
import type { BaseDatabaseAdapter } from 'payload/database'
|
import type { BaseDatabaseAdapter } from 'payload/database'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
import type { Pool, PoolConfig } from 'pg'
|
import type { Pool, PoolConfig } from 'pg'
|
||||||
|
|
||||||
export type DrizzleDB = NodePgDatabase<Record<string, unknown>>
|
export type DrizzleDB = NodePgDatabase<Record<string, unknown>>
|
||||||
@@ -95,8 +95,8 @@ export type IDType = 'integer' | 'numeric' | 'uuid' | 'varchar'
|
|||||||
|
|
||||||
export type PostgresAdapterResult = (args: { payload: Payload }) => PostgresAdapter
|
export type PostgresAdapterResult = (args: { payload: Payload }) => PostgresAdapter
|
||||||
|
|
||||||
export type MigrateUpArgs = { payload: Payload; req?: Partial<PayloadRequest> }
|
export type MigrateUpArgs = { payload: Payload; req?: Partial<PayloadRequestWithData> }
|
||||||
export type MigrateDownArgs = { payload: Payload; req?: Partial<PayloadRequest> }
|
export type MigrateDownArgs = { payload: Payload; req?: Partial<PayloadRequestWithData> }
|
||||||
|
|
||||||
declare module 'payload' {
|
declare module 'payload' {
|
||||||
export interface DatabaseAdapter
|
export interface DatabaseAdapter
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { UpdateGlobalArgs } from 'payload/database'
|
import type { UpdateGlobalArgs } from 'payload/database'
|
||||||
import type { PayloadRequest, TypeWithID } from 'payload/types'
|
import type { PayloadRequestWithData, TypeWithID } from 'payload/types'
|
||||||
|
|
||||||
import toSnakeCase from 'to-snake-case'
|
import toSnakeCase from 'to-snake-case'
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ import { upsertRow } from './upsertRow/index.js'
|
|||||||
|
|
||||||
export async function updateGlobal<T extends TypeWithID>(
|
export async function updateGlobal<T extends TypeWithID>(
|
||||||
this: PostgresAdapter,
|
this: PostgresAdapter,
|
||||||
{ slug, data, req = {} as PayloadRequest }: UpdateGlobalArgs,
|
{ slug, data, req = {} as PayloadRequestWithData }: UpdateGlobalArgs,
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
const db = this.sessions[req.transactionID]?.db || this.drizzle
|
const db = this.sessions[req.transactionID]?.db || this.drizzle
|
||||||
const globalConfig = this.payload.globals.config.find((config) => config.slug === slug)
|
const globalConfig = this.payload.globals.config.find((config) => config.slug === slug)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { TypeWithVersion, UpdateGlobalVersionArgs } from 'payload/database'
|
import type { TypeWithVersion, UpdateGlobalVersionArgs } from 'payload/database'
|
||||||
import type { PayloadRequest, SanitizedGlobalConfig, TypeWithID } from 'payload/types'
|
import type { PayloadRequestWithData, SanitizedGlobalConfig, TypeWithID } from 'payload/types'
|
||||||
|
|
||||||
import { buildVersionGlobalFields } from 'payload/versions'
|
import { buildVersionGlobalFields } from 'payload/versions'
|
||||||
import toSnakeCase from 'to-snake-case'
|
import toSnakeCase from 'to-snake-case'
|
||||||
@@ -15,7 +15,7 @@ export async function updateGlobalVersion<T extends TypeWithID>(
|
|||||||
id,
|
id,
|
||||||
global,
|
global,
|
||||||
locale,
|
locale,
|
||||||
req = {} as PayloadRequest,
|
req = {} as PayloadRequestWithData,
|
||||||
versionData,
|
versionData,
|
||||||
where: whereArg,
|
where: whereArg,
|
||||||
}: UpdateGlobalVersionArgs<T>,
|
}: UpdateGlobalVersionArgs<T>,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { TypeWithVersion, UpdateVersionArgs } from 'payload/database'
|
import type { TypeWithVersion, UpdateVersionArgs } from 'payload/database'
|
||||||
import type { PayloadRequest, SanitizedCollectionConfig, TypeWithID } from 'payload/types'
|
import type { PayloadRequestWithData, SanitizedCollectionConfig, TypeWithID } from 'payload/types'
|
||||||
|
|
||||||
import { buildVersionCollectionFields } from 'payload/versions'
|
import { buildVersionCollectionFields } from 'payload/versions'
|
||||||
import toSnakeCase from 'to-snake-case'
|
import toSnakeCase from 'to-snake-case'
|
||||||
@@ -15,7 +15,7 @@ export async function updateVersion<T extends TypeWithID>(
|
|||||||
id,
|
id,
|
||||||
collection,
|
collection,
|
||||||
locale,
|
locale,
|
||||||
req = {} as PayloadRequest,
|
req = {} as PayloadRequestWithData,
|
||||||
versionData,
|
versionData,
|
||||||
where: whereArg,
|
where: whereArg,
|
||||||
}: UpdateVersionArgs<T>,
|
}: UpdateVersionArgs<T>,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { SQL } from 'drizzle-orm'
|
import type { SQL } from 'drizzle-orm'
|
||||||
import type { Field, PayloadRequest } from 'payload/types'
|
import type { Field, PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import type { DrizzleDB, GenericColumn, PostgresAdapter } from '../types.js'
|
import type { DrizzleDB, GenericColumn, PostgresAdapter } from '../types.js'
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ type BaseArgs = {
|
|||||||
db: DrizzleDB
|
db: DrizzleDB
|
||||||
fields: Field[]
|
fields: Field[]
|
||||||
path?: string
|
path?: string
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
tableName: string
|
tableName: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { PayloadRequest, Where } from 'payload/types'
|
import type { PayloadRequestWithData, Where } from 'payload/types'
|
||||||
import type { Collection } from 'payload/types'
|
import type { Collection } from 'payload/types'
|
||||||
|
|
||||||
import { countOperation } from 'payload/operations'
|
import { countOperation } from 'payload/operations'
|
||||||
@@ -14,7 +14,7 @@ export type Resolver = (
|
|||||||
where?: Where
|
where?: Where
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
},
|
},
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
) => Promise<{ totalDocs: number }>
|
) => Promise<{ totalDocs: number }>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { GeneratedTypes } from 'payload'
|
import type { GeneratedTypes } from 'payload'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
import type { Collection } from 'payload/types'
|
import type { Collection } from 'payload/types'
|
||||||
import type { MarkOptional } from 'ts-essentials'
|
import type { MarkOptional } from 'ts-essentials'
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ export type Resolver<TSlug extends keyof GeneratedTypes['collections']> = (
|
|||||||
locale?: string
|
locale?: string
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
},
|
},
|
||||||
) => Promise<GeneratedTypes['collections'][TSlug]>
|
) => Promise<GeneratedTypes['collections'][TSlug]>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { GeneratedTypes } from 'payload'
|
import type { GeneratedTypes } from 'payload'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
import type { Collection } from 'payload/types'
|
import type { Collection } from 'payload/types'
|
||||||
|
|
||||||
import { deleteByIDOperation } from 'payload/operations'
|
import { deleteByIDOperation } from 'payload/operations'
|
||||||
@@ -14,7 +14,7 @@ export type Resolver<TSlug extends keyof GeneratedTypes['collections']> = (
|
|||||||
locale?: string
|
locale?: string
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
},
|
},
|
||||||
) => Promise<GeneratedTypes['collections'][TSlug]>
|
) => Promise<GeneratedTypes['collections'][TSlug]>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { CollectionPermission, GlobalPermission } from 'payload/auth'
|
import type { CollectionPermission, GlobalPermission } from 'payload/auth'
|
||||||
import type { Collection, PayloadRequest } from 'payload/types'
|
import type { Collection, PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import { docAccessOperation } from 'payload/operations'
|
import { docAccessOperation } from 'payload/operations'
|
||||||
import { isolateObjectProperty } from 'payload/utilities'
|
import { isolateObjectProperty } from 'payload/utilities'
|
||||||
@@ -12,7 +12,7 @@ export type Resolver = (
|
|||||||
id: number | string
|
id: number | string
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
},
|
},
|
||||||
) => Promise<CollectionPermission | GlobalPermission>
|
) => Promise<CollectionPermission | GlobalPermission>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { GeneratedTypes } from 'payload'
|
import type { GeneratedTypes } from 'payload'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
import type { Collection } from 'payload/types'
|
import type { Collection } from 'payload/types'
|
||||||
|
|
||||||
import { duplicateOperation } from 'payload/operations'
|
import { duplicateOperation } from 'payload/operations'
|
||||||
@@ -16,7 +16,7 @@ export type Resolver<T> = (
|
|||||||
locale?: string
|
locale?: string
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
},
|
},
|
||||||
) => Promise<T>
|
) => Promise<T>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { PaginatedDocs } from 'payload/database'
|
import type { PaginatedDocs } from 'payload/database'
|
||||||
import type { PayloadRequest, Where } from 'payload/types'
|
import type { PayloadRequestWithData, Where } from 'payload/types'
|
||||||
import type { Collection } from 'payload/types'
|
import type { Collection } from 'payload/types'
|
||||||
|
|
||||||
import { findOperation } from 'payload/operations'
|
import { findOperation } from 'payload/operations'
|
||||||
@@ -20,7 +20,7 @@ export type Resolver = (
|
|||||||
where?: Where
|
where?: Where
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
},
|
},
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
) => Promise<PaginatedDocs<any>>
|
) => Promise<PaginatedDocs<any>>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { GeneratedTypes } from 'payload'
|
import type { GeneratedTypes } from 'payload'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
import type { Collection } from 'payload/types'
|
import type { Collection } from 'payload/types'
|
||||||
|
|
||||||
import { findByIDOperation } from 'payload/operations'
|
import { findByIDOperation } from 'payload/operations'
|
||||||
@@ -16,7 +16,7 @@ export type Resolver<T> = (
|
|||||||
locale?: string
|
locale?: string
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
},
|
},
|
||||||
) => Promise<T>
|
) => Promise<T>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
import type { Collection, TypeWithID } from 'payload/types'
|
import type { Collection, TypeWithID } from 'payload/types'
|
||||||
import type { TypeWithVersion } from 'payload/versions'
|
import type { TypeWithVersion } from 'payload/versions'
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ export type Resolver<T extends TypeWithID = any> = (
|
|||||||
locale?: string
|
locale?: string
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
},
|
},
|
||||||
) => Promise<TypeWithVersion<T>>
|
) => Promise<TypeWithVersion<T>>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { PaginatedDocs } from 'payload/database'
|
import type { PaginatedDocs } from 'payload/database'
|
||||||
import type { PayloadRequest, Where } from 'payload/types'
|
import type { PayloadRequestWithData, Where } from 'payload/types'
|
||||||
import type { Collection } from 'payload/types'
|
import type { Collection } from 'payload/types'
|
||||||
|
|
||||||
import { findVersionsOperation } from 'payload/operations'
|
import { findVersionsOperation } from 'payload/operations'
|
||||||
@@ -18,7 +18,7 @@ export type Resolver = (
|
|||||||
where: Where
|
where: Where
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
},
|
},
|
||||||
) => Promise<PaginatedDocs<any>>
|
) => Promise<PaginatedDocs<any>>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
import type { Collection } from 'payload/types'
|
import type { Collection } from 'payload/types'
|
||||||
|
|
||||||
import { restoreVersionOperation } from 'payload/operations'
|
import { restoreVersionOperation } from 'payload/operations'
|
||||||
@@ -12,7 +12,7 @@ export type Resolver = (
|
|||||||
id: number | string
|
id: number | string
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
},
|
},
|
||||||
) => Promise<Document>
|
) => Promise<Document>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { GeneratedTypes } from 'payload'
|
import type { GeneratedTypes } from 'payload'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
import type { Collection } from 'payload/types'
|
import type { Collection } from 'payload/types'
|
||||||
|
|
||||||
import { updateByIDOperation } from 'payload/operations'
|
import { updateByIDOperation } from 'payload/operations'
|
||||||
@@ -17,7 +17,7 @@ export type Resolver<TSlug extends keyof GeneratedTypes['collections']> = (
|
|||||||
locale?: string
|
locale?: string
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
},
|
},
|
||||||
) => Promise<GeneratedTypes['collections'][TSlug]>
|
) => Promise<GeneratedTypes['collections'][TSlug]>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { CollectionPermission, GlobalPermission } from 'payload/auth'
|
import type { CollectionPermission, GlobalPermission } from 'payload/auth'
|
||||||
import type { PayloadRequest, SanitizedGlobalConfig } from 'payload/types'
|
import type { PayloadRequestWithData, SanitizedGlobalConfig } from 'payload/types'
|
||||||
|
|
||||||
import { docAccessOperationGlobal } from 'payload/operations'
|
import { docAccessOperationGlobal } from 'payload/operations'
|
||||||
import { isolateObjectProperty } from 'payload/utilities'
|
import { isolateObjectProperty } from 'payload/utilities'
|
||||||
@@ -9,7 +9,7 @@ import type { Context } from '../types.js'
|
|||||||
export type Resolver = (
|
export type Resolver = (
|
||||||
_: unknown,
|
_: unknown,
|
||||||
context: {
|
context: {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
},
|
},
|
||||||
) => Promise<CollectionPermission | GlobalPermission>
|
) => Promise<CollectionPermission | GlobalPermission>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Document, PayloadRequest, SanitizedGlobalConfig } from 'payload/types'
|
import type { Document, PayloadRequestWithData, SanitizedGlobalConfig } from 'payload/types'
|
||||||
|
|
||||||
import { findVersionByIDOperationGlobal } from 'payload/operations'
|
import { findVersionByIDOperationGlobal } from 'payload/operations'
|
||||||
import { isolateObjectProperty } from 'payload/utilities'
|
import { isolateObjectProperty } from 'payload/utilities'
|
||||||
@@ -14,7 +14,7 @@ export type Resolver = (
|
|||||||
locale?: string
|
locale?: string
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
},
|
},
|
||||||
) => Promise<Document>
|
) => Promise<Document>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Document, PayloadRequest, SanitizedGlobalConfig, Where } from 'payload/types'
|
import type { Document, PayloadRequestWithData, SanitizedGlobalConfig, Where } from 'payload/types'
|
||||||
|
|
||||||
import { findVersionsOperationGlobal } from 'payload/operations'
|
import { findVersionsOperationGlobal } from 'payload/operations'
|
||||||
import { isolateObjectProperty } from 'payload/utilities'
|
import { isolateObjectProperty } from 'payload/utilities'
|
||||||
@@ -16,7 +16,7 @@ export type Resolver = (
|
|||||||
where: Where
|
where: Where
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
},
|
},
|
||||||
) => Promise<Document>
|
) => Promise<Document>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Document, PayloadRequest, SanitizedGlobalConfig } from 'payload/types'
|
import type { Document, PayloadRequestWithData, SanitizedGlobalConfig } from 'payload/types'
|
||||||
|
|
||||||
import { restoreVersionOperationGlobal } from 'payload/operations'
|
import { restoreVersionOperationGlobal } from 'payload/operations'
|
||||||
import { isolateObjectProperty } from 'payload/utilities'
|
import { isolateObjectProperty } from 'payload/utilities'
|
||||||
@@ -11,7 +11,7 @@ type Resolver = (
|
|||||||
id: number | string
|
id: number | string
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
},
|
},
|
||||||
) => Promise<Document>
|
) => Promise<Document>
|
||||||
export default function restoreVersionResolver(globalConfig: SanitizedGlobalConfig): Resolver {
|
export default function restoreVersionResolver(globalConfig: SanitizedGlobalConfig): Resolver {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { GeneratedTypes } from 'payload'
|
import type { GeneratedTypes } from 'payload'
|
||||||
import type { PayloadRequest, SanitizedGlobalConfig } from 'payload/types'
|
import type { PayloadRequestWithData, SanitizedGlobalConfig } from 'payload/types'
|
||||||
import type { DeepPartial } from 'ts-essentials'
|
import type { DeepPartial } from 'ts-essentials'
|
||||||
|
|
||||||
import { updateOperationGlobal } from 'payload/operations'
|
import { updateOperationGlobal } from 'payload/operations'
|
||||||
@@ -16,7 +16,7 @@ type Resolver<TSlug extends keyof GeneratedTypes['globals']> = (
|
|||||||
locale?: string
|
locale?: string
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
},
|
},
|
||||||
) => Promise<GeneratedTypes['globals'][TSlug]>
|
) => Promise<GeneratedTypes['globals'][TSlug]>
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
export type Context = {
|
export type Context = {
|
||||||
headers: {
|
headers: {
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
}
|
}
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import type { ObjMap } from 'graphql/jsutils/ObjMap.js'
|
import type { ObjMap } from 'graphql/jsutils/ObjMap.js'
|
||||||
import type { GraphQLFieldConfig, GraphQLFieldResolver } from 'graphql/type/definition.js'
|
import type { GraphQLFieldConfig, GraphQLFieldResolver } from 'graphql/type/definition.js'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import { isolateObjectProperty } from 'payload/utilities'
|
import { isolateObjectProperty } from 'payload/utilities'
|
||||||
|
|
||||||
type PayloadContext = { req: PayloadRequest }
|
type PayloadContext = { req: PayloadRequestWithData }
|
||||||
|
|
||||||
function wrapCustomResolver<TSource, TArgs, TResult>(
|
function wrapCustomResolver<TSource, TArgs, TResult>(
|
||||||
resolver: GraphQLFieldResolver<TSource, PayloadContext, TArgs, TResult>,
|
resolver: GraphQLFieldResolver<TSource, PayloadContext, TArgs, TResult>,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export { addDataAndFileToRequest } from '../utilities/addDataAndFileToRequest.js'
|
export { addDataAndFileToRequest } from '../utilities/addDataAndFileToRequest.js'
|
||||||
export { addLocalesToRequest } from '../utilities/addLocalesToRequest.js'
|
export { addLocalesToRequestFromData, sanitizeLocales } from '../utilities/addLocalesToRequest.js'
|
||||||
export { traverseFields } from '../utilities/buildFieldSchemaMap/traverseFields.js'
|
export { traverseFields } from '../utilities/buildFieldSchemaMap/traverseFields.js'
|
||||||
export { createPayloadRequest } from '../utilities/createPayloadRequest.js'
|
export { createPayloadRequest as createBasePayloadRequest } from '../utilities/createPayloadRequest.js'
|
||||||
export { getNextRequestI18n } from '../utilities/getNextRequestI18n.js'
|
export { getNextRequestI18n } from '../utilities/getNextRequestI18n.js'
|
||||||
export { getPayloadHMR, reload } from '../utilities/getPayloadHMR.js'
|
export { getPayloadHMR, reload } from '../utilities/getPayloadHMR.js'
|
||||||
export { headersWithCors } from '../utilities/headersWithCors.js'
|
export { headersWithCors } from '../utilities/headersWithCors.js'
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import { configToSchema } from '@payloadcms/graphql'
|
|||||||
import { createHandler } from 'graphql-http/lib/use/fetch'
|
import { createHandler } from 'graphql-http/lib/use/fetch'
|
||||||
import httpStatus from 'http-status'
|
import httpStatus from 'http-status'
|
||||||
|
|
||||||
import { addLocalesToRequest } from '../../utilities/addLocalesToRequest.js'
|
import { addDataAndFileToRequest } from '../../utilities/addDataAndFileToRequest.js'
|
||||||
|
import { addLocalesToRequestFromData } from '../../utilities/addLocalesToRequest.js'
|
||||||
import { createPayloadRequest } from '../../utilities/createPayloadRequest.js'
|
import { createPayloadRequest } from '../../utilities/createPayloadRequest.js'
|
||||||
import { headersWithCors } from '../../utilities/headersWithCors.js'
|
import { headersWithCors } from '../../utilities/headersWithCors.js'
|
||||||
|
|
||||||
@@ -83,23 +84,24 @@ export const getGraphql = async (config: Promise<SanitizedConfig> | SanitizedCon
|
|||||||
export const POST =
|
export const POST =
|
||||||
(config: Promise<SanitizedConfig> | SanitizedConfig) => async (request: Request) => {
|
(config: Promise<SanitizedConfig> | SanitizedConfig) => async (request: Request) => {
|
||||||
const originalRequest = request.clone()
|
const originalRequest = request.clone()
|
||||||
const req = await createPayloadRequest({
|
const basePayloadRequest = await createPayloadRequest({
|
||||||
config,
|
config,
|
||||||
request,
|
request,
|
||||||
})
|
})
|
||||||
|
|
||||||
addLocalesToRequest({ request: req })
|
const reqWithData = await addDataAndFileToRequest({ request: basePayloadRequest })
|
||||||
|
const payloadRequest = addLocalesToRequestFromData({ request: reqWithData })
|
||||||
|
|
||||||
const { schema, validationRules } = await getGraphql(config)
|
const { schema, validationRules } = await getGraphql(config)
|
||||||
|
|
||||||
const { payload } = req
|
const { payload } = payloadRequest
|
||||||
|
|
||||||
const afterErrorHook =
|
const afterErrorHook =
|
||||||
typeof payload.config.hooks.afterError === 'function' ? payload.config.hooks.afterError : null
|
typeof payload.config.hooks.afterError === 'function' ? payload.config.hooks.afterError : null
|
||||||
|
|
||||||
const headers = {}
|
const headers = {}
|
||||||
const apiResponse = await createHandler({
|
const apiResponse = await createHandler({
|
||||||
context: { headers, req },
|
context: { headers, req: payloadRequest },
|
||||||
onOperation: async (request, args, result) => {
|
onOperation: async (request, args, result) => {
|
||||||
const response =
|
const response =
|
||||||
typeof payload.extensions === 'function'
|
typeof payload.extensions === 'function'
|
||||||
@@ -126,7 +128,7 @@ export const POST =
|
|||||||
|
|
||||||
const resHeaders = headersWithCors({
|
const resHeaders = headersWithCors({
|
||||||
headers: new Headers(apiResponse.headers),
|
headers: new Headers(apiResponse.headers),
|
||||||
req,
|
req: payloadRequest,
|
||||||
})
|
})
|
||||||
|
|
||||||
for (const key in headers) {
|
for (const key in headers) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import type { SanitizedConfig } from 'payload/types'
|
|||||||
|
|
||||||
import { renderPlaygroundPage } from 'graphql-playground-html'
|
import { renderPlaygroundPage } from 'graphql-playground-html'
|
||||||
|
|
||||||
import { addLocalesToRequest } from '../../utilities/addLocalesToRequest.js'
|
|
||||||
import { createPayloadRequest } from '../../utilities/createPayloadRequest.js'
|
import { createPayloadRequest } from '../../utilities/createPayloadRequest.js'
|
||||||
|
|
||||||
export const GET = (config: Promise<SanitizedConfig>) => async (request: Request) => {
|
export const GET = (config: Promise<SanitizedConfig>) => async (request: Request) => {
|
||||||
@@ -11,8 +10,6 @@ export const GET = (config: Promise<SanitizedConfig>) => async (request: Request
|
|||||||
request,
|
request,
|
||||||
})
|
})
|
||||||
|
|
||||||
addLocalesToRequest({ request: req })
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(!req.payload.config.graphQL.disable &&
|
(!req.payload.config.graphQL.disable &&
|
||||||
!req.payload.config.graphQL.disablePlaygroundInProduction &&
|
!req.payload.config.graphQL.disablePlaygroundInProduction &&
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { BuildFormStateArgs } from '@payloadcms/ui/forms/buildStateFromSchema'
|
import type { BuildFormStateArgs } from '@payloadcms/ui/forms/buildStateFromSchema'
|
||||||
import type { DocumentPreferences, Field, PayloadRequest, TypeWithID } from 'payload/types'
|
import type { DocumentPreferences, Field, PayloadRequestWithData, TypeWithID } from 'payload/types'
|
||||||
|
|
||||||
import { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'
|
import { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'
|
||||||
import { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues'
|
import { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues'
|
||||||
@@ -17,7 +17,7 @@ if (!cached) {
|
|||||||
cached = global._payload_fieldSchemaMap = null
|
cached = global._payload_fieldSchemaMap = null
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getFieldSchemaMap = (req: PayloadRequest): FieldSchemaMap => {
|
export const getFieldSchemaMap = (req: PayloadRequestWithData): FieldSchemaMap => {
|
||||||
if (cached && process.env.NODE_ENV !== 'development') {
|
if (cached && process.env.NODE_ENV !== 'development') {
|
||||||
return cached
|
return cached
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ export const getFieldSchemaMap = (req: PayloadRequest): FieldSchemaMap => {
|
|||||||
return cached
|
return cached
|
||||||
}
|
}
|
||||||
|
|
||||||
export const buildFormState = async ({ req }: { req: PayloadRequest }) => {
|
export const buildFormState = async ({ req }: { req: PayloadRequestWithData }) => {
|
||||||
const headers = headersWithCors({
|
const headers = headersWithCors({
|
||||||
headers: new Headers(),
|
headers: new Headers(),
|
||||||
req,
|
req,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Collection, PayloadRequest, Where } from 'payload/types'
|
import type { Collection, PayloadRequestWithData, Where } from 'payload/types'
|
||||||
|
|
||||||
import { executeAccess } from 'payload/auth'
|
import { executeAccess } from 'payload/auth'
|
||||||
import { Forbidden } from 'payload/errors'
|
import { Forbidden } from 'payload/errors'
|
||||||
@@ -12,7 +12,7 @@ export async function checkFileAccess({
|
|||||||
}: {
|
}: {
|
||||||
collection: Collection
|
collection: Collection
|
||||||
filename: string
|
filename: string
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
}) {
|
}) {
|
||||||
const { config } = collection
|
const { config } = collection
|
||||||
const disableEndpoints = endpointsAreDisabled({ endpoints: config.endpoints, request: req })
|
const disableEndpoints = endpointsAreDisabled({ endpoints: config.endpoints, request: req })
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Collection, PayloadRequest } from 'payload/types'
|
import type { Collection, PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import getFileType from 'file-type'
|
import getFileType from 'file-type'
|
||||||
import fsPromises from 'fs/promises'
|
import fsPromises from 'fs/promises'
|
||||||
@@ -16,7 +16,7 @@ import { getFileTypeFallback } from './getFileTypeFallback.js'
|
|||||||
type Args = {
|
type Args = {
|
||||||
collection: Collection
|
collection: Collection
|
||||||
filename: string
|
filename: string
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
}
|
}
|
||||||
export const getFile = async ({ collection, filename, req }: Args): Promise<Response> => {
|
export const getFile = async ({ collection, filename, req }: Args): Promise<Response> => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
import type { Endpoint } from 'payload/config'
|
import type { Endpoint } from 'payload/config'
|
||||||
import type { Collection, GlobalConfig, PayloadRequest, SanitizedConfig } from 'payload/types'
|
import type {
|
||||||
|
Collection,
|
||||||
|
GlobalConfig,
|
||||||
|
PayloadRequest,
|
||||||
|
PayloadRequestData,
|
||||||
|
SanitizedConfig,
|
||||||
|
} from 'payload/types'
|
||||||
|
|
||||||
import httpStatus from 'http-status'
|
import httpStatus from 'http-status'
|
||||||
import { match } from 'path-to-regexp'
|
import { match } from 'path-to-regexp'
|
||||||
@@ -12,7 +18,7 @@ import type {
|
|||||||
} from './types.js'
|
} from './types.js'
|
||||||
|
|
||||||
import { addDataAndFileToRequest } from '../../utilities/addDataAndFileToRequest.js'
|
import { addDataAndFileToRequest } from '../../utilities/addDataAndFileToRequest.js'
|
||||||
import { addLocalesToRequest } from '../../utilities/addLocalesToRequest.js'
|
import { addLocalesToRequestFromData } from '../../utilities/addLocalesToRequest.js'
|
||||||
import { createPayloadRequest } from '../../utilities/createPayloadRequest.js'
|
import { createPayloadRequest } from '../../utilities/createPayloadRequest.js'
|
||||||
import { headersWithCors } from '../../utilities/headersWithCors.js'
|
import { headersWithCors } from '../../utilities/headersWithCors.js'
|
||||||
import { access } from './auth/access.js'
|
import { access } from './auth/access.js'
|
||||||
@@ -198,7 +204,7 @@ export const GET =
|
|||||||
(config: Promise<SanitizedConfig> | SanitizedConfig) =>
|
(config: Promise<SanitizedConfig> | SanitizedConfig) =>
|
||||||
async (request: Request, { params: { slug } }: { params: { slug: string[] } }) => {
|
async (request: Request, { params: { slug } }: { params: { slug: string[] } }) => {
|
||||||
const [slug1, slug2, slug3, slug4] = slug
|
const [slug1, slug2, slug3, slug4] = slug
|
||||||
let req: PayloadRequest
|
let req: PayloadRequest | (PayloadRequest & PayloadRequestData)
|
||||||
let res: Response
|
let res: Response
|
||||||
let collection: Collection
|
let collection: Collection
|
||||||
|
|
||||||
@@ -235,14 +241,13 @@ export const GET =
|
|||||||
if (customEndpointResponse) {
|
if (customEndpointResponse) {
|
||||||
return customEndpointResponse
|
return customEndpointResponse
|
||||||
} else {
|
} else {
|
||||||
await addDataAndFileToRequest({ request: req })
|
const reqWithData = await addDataAndFileToRequest({ request: req })
|
||||||
addLocalesToRequest({ request: req })
|
const payloadRequest = addLocalesToRequestFromData({ request: reqWithData })
|
||||||
}
|
|
||||||
|
|
||||||
switch (slug.length) {
|
switch (slug.length) {
|
||||||
case 1:
|
case 1:
|
||||||
// /:collection
|
// /:collection
|
||||||
res = await endpoints.collection.GET.find({ collection, req })
|
res = await endpoints.collection.GET.find({ collection, req: payloadRequest })
|
||||||
break
|
break
|
||||||
case 2:
|
case 2:
|
||||||
if (slug2 in endpoints.collection.GET) {
|
if (slug2 in endpoints.collection.GET) {
|
||||||
@@ -252,33 +257,42 @@ export const GET =
|
|||||||
// /:collection/count
|
// /:collection/count
|
||||||
res = await (endpoints.collection.GET[slug2] as CollectionRouteHandler)({
|
res = await (endpoints.collection.GET[slug2] as CollectionRouteHandler)({
|
||||||
collection,
|
collection,
|
||||||
req,
|
req: payloadRequest,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// /:collection/:id
|
// /:collection/:id
|
||||||
res = await endpoints.collection.GET.findByID({ id: slug2, collection, req })
|
res = await endpoints.collection.GET.findByID({
|
||||||
|
id: slug2,
|
||||||
|
collection,
|
||||||
|
req: payloadRequest,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 3:
|
case 3:
|
||||||
if (slug2 === 'file') {
|
if (slug2 === 'file') {
|
||||||
// /:collection/file/:filename
|
// /:collection/file/:filename
|
||||||
res = await endpoints.collection.GET.getFile({ collection, filename: slug3, req })
|
res = await endpoints.collection.GET.getFile({
|
||||||
|
collection,
|
||||||
|
filename: slug3,
|
||||||
|
req: payloadRequest,
|
||||||
|
})
|
||||||
} else if (slug3 in endpoints.collection.GET) {
|
} else if (slug3 in endpoints.collection.GET) {
|
||||||
// /:collection/:id/preview
|
// /:collection/:id/preview
|
||||||
res = await (endpoints.collection.GET[slug3] as CollectionRouteHandlerWithID)({
|
res = await (endpoints.collection.GET[slug3] as CollectionRouteHandlerWithID)({
|
||||||
id: slug2,
|
id: slug2,
|
||||||
collection,
|
collection,
|
||||||
req,
|
req: payloadRequest,
|
||||||
})
|
})
|
||||||
} else if (`doc-${slug2}-by-id` in endpoints.collection.GET) {
|
} else if (`doc-${slug2}-by-id` in endpoints.collection.GET) {
|
||||||
// /:collection/access/:id
|
// /:collection/access/:id
|
||||||
// /:collection/versions/:id
|
// /:collection/versions/:id
|
||||||
res = await (
|
res = await (
|
||||||
endpoints.collection.GET[`doc-${slug2}-by-id`] as CollectionRouteHandlerWithID
|
endpoints.collection.GET[`doc-${slug2}-by-id`] as CollectionRouteHandlerWithID
|
||||||
)({ id: slug3, collection, req })
|
)({ id: slug3, collection, req: payloadRequest })
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (slug1 === 'globals') {
|
} else if (slug1 === 'globals') {
|
||||||
const globalConfig = req.payload.config.globals.find((global) => global.slug === slug2)
|
const globalConfig = req.payload.config.globals.find((global) => global.slug === slug2)
|
||||||
|
|
||||||
@@ -298,21 +312,20 @@ export const GET =
|
|||||||
if (customEndpointResponse) {
|
if (customEndpointResponse) {
|
||||||
return customEndpointResponse
|
return customEndpointResponse
|
||||||
} else {
|
} else {
|
||||||
await addDataAndFileToRequest({ request: req })
|
const reqWithData = await addDataAndFileToRequest({ request: req })
|
||||||
addLocalesToRequest({ request: req })
|
const payloadRequest = addLocalesToRequestFromData({ request: reqWithData })
|
||||||
}
|
|
||||||
|
|
||||||
switch (slug.length) {
|
switch (slug.length) {
|
||||||
case 2:
|
case 2:
|
||||||
// /globals/:slug
|
// /globals/:slug
|
||||||
res = await endpoints.global.GET.findOne({ globalConfig, req })
|
res = await endpoints.global.GET.findOne({ globalConfig, req: payloadRequest })
|
||||||
break
|
break
|
||||||
case 3:
|
case 3:
|
||||||
if (slug3 in endpoints.global.GET) {
|
if (slug3 in endpoints.global.GET) {
|
||||||
// /globals/:slug/preview
|
// /globals/:slug/preview
|
||||||
res = await (endpoints.global.GET[slug3] as GlobalRouteHandler)({
|
res = await (endpoints.global.GET[slug3] as GlobalRouteHandler)({
|
||||||
globalConfig,
|
globalConfig,
|
||||||
req,
|
req: payloadRequest,
|
||||||
})
|
})
|
||||||
} else if (`doc-${slug3}` in endpoints.global.GET) {
|
} else if (`doc-${slug3}` in endpoints.global.GET) {
|
||||||
// /globals/:slug/access
|
// /globals/:slug/access
|
||||||
@@ -320,7 +333,7 @@ export const GET =
|
|||||||
// /globals/:slug/preview
|
// /globals/:slug/preview
|
||||||
res = await (endpoints.global.GET?.[`doc-${slug3}`] as GlobalRouteHandler)({
|
res = await (endpoints.global.GET?.[`doc-${slug3}`] as GlobalRouteHandler)({
|
||||||
globalConfig,
|
globalConfig,
|
||||||
req,
|
req: payloadRequest,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -332,15 +345,16 @@ export const GET =
|
|||||||
)({
|
)({
|
||||||
id: slug4,
|
id: slug4,
|
||||||
globalConfig,
|
globalConfig,
|
||||||
req,
|
req: payloadRequest,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (slug.length === 1 && slug1 in endpoints.root.GET) {
|
} else if (slug.length === 1 && slug1 in endpoints.root.GET) {
|
||||||
await addDataAndFileToRequest({ request: req })
|
const reqWithData = await addDataAndFileToRequest({ request: req })
|
||||||
addLocalesToRequest({ request: req })
|
const payloadRequest = addLocalesToRequestFromData({ request: reqWithData })
|
||||||
res = await endpoints.root.GET[slug1]({ req })
|
res = await endpoints.root.GET[slug1]({ req: payloadRequest })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res instanceof Response) return res
|
if (res instanceof Response) return res
|
||||||
@@ -406,14 +420,13 @@ export const POST =
|
|||||||
if (customEndpointResponse) {
|
if (customEndpointResponse) {
|
||||||
return customEndpointResponse
|
return customEndpointResponse
|
||||||
} else {
|
} else {
|
||||||
await addDataAndFileToRequest({ request: req })
|
const reqWithData = await addDataAndFileToRequest({ request: req })
|
||||||
addLocalesToRequest({ request: req })
|
const payloadRequest = addLocalesToRequestFromData({ request: reqWithData })
|
||||||
}
|
|
||||||
|
|
||||||
switch (slug.length) {
|
switch (slug.length) {
|
||||||
case 1:
|
case 1:
|
||||||
// /:collection
|
// /:collection
|
||||||
res = await endpoints.collection.POST.create({ collection, req })
|
res = await endpoints.collection.POST.create({ collection, req: payloadRequest })
|
||||||
break
|
break
|
||||||
case 2:
|
case 2:
|
||||||
if (slug2 in endpoints.collection.POST) {
|
if (slug2 in endpoints.collection.POST) {
|
||||||
@@ -428,7 +441,7 @@ export const POST =
|
|||||||
|
|
||||||
res = await (endpoints.collection.POST?.[slug2] as CollectionRouteHandler)({
|
res = await (endpoints.collection.POST?.[slug2] as CollectionRouteHandler)({
|
||||||
collection,
|
collection,
|
||||||
req,
|
req: payloadRequest,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -439,13 +452,18 @@ export const POST =
|
|||||||
// /:collection/verify/:token ("doc-verify-by-id" uses id as token internally)
|
// /:collection/verify/:token ("doc-verify-by-id" uses id as token internally)
|
||||||
res = await (
|
res = await (
|
||||||
endpoints.collection.POST[`doc-${slug2}-by-id`] as CollectionRouteHandlerWithID
|
endpoints.collection.POST[`doc-${slug2}-by-id`] as CollectionRouteHandlerWithID
|
||||||
)({ id: slug3, collection, req })
|
)({ id: slug3, collection, req: payloadRequest })
|
||||||
} else if (slug3 === 'duplicate' && collection.config.disableDuplicate !== true) {
|
} else if (slug3 === 'duplicate' && collection.config.disableDuplicate !== true) {
|
||||||
// /:collection/:id/duplicate
|
// /:collection/:id/duplicate
|
||||||
res = await endpoints.collection.POST.duplicate({ id: slug2, collection, req })
|
res = await endpoints.collection.POST.duplicate({
|
||||||
|
id: slug2,
|
||||||
|
collection,
|
||||||
|
req: payloadRequest,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (slug1 === 'globals' && slug2) {
|
} else if (slug1 === 'globals' && slug2) {
|
||||||
const globalConfig = req.payload.config.globals.find((global) => global.slug === slug2)
|
const globalConfig = req.payload.config.globals.find((global) => global.slug === slug2)
|
||||||
const disableEndpoints = endpointsAreDisabled({
|
const disableEndpoints = endpointsAreDisabled({
|
||||||
@@ -463,21 +481,19 @@ export const POST =
|
|||||||
if (customEndpointResponse) {
|
if (customEndpointResponse) {
|
||||||
return customEndpointResponse
|
return customEndpointResponse
|
||||||
} else {
|
} else {
|
||||||
await addDataAndFileToRequest({ request: req })
|
const reqWithData = await addDataAndFileToRequest({ request: req })
|
||||||
addLocalesToRequest({ request: req })
|
const payloadRequest = addLocalesToRequestFromData({ request: reqWithData })
|
||||||
}
|
|
||||||
|
|
||||||
switch (slug.length) {
|
switch (slug.length) {
|
||||||
case 2:
|
case 2:
|
||||||
// /globals/:slug
|
// /globals/:slug
|
||||||
res = await endpoints.global.POST.update({ globalConfig, req })
|
res = await endpoints.global.POST.update({ globalConfig, req: payloadRequest })
|
||||||
break
|
break
|
||||||
case 3:
|
case 3:
|
||||||
if (`doc-${slug3}` in endpoints.global.POST) {
|
if (`doc-${slug3}` in endpoints.global.POST) {
|
||||||
// /globals/:slug/access
|
// /globals/:slug/access
|
||||||
res = await (endpoints.global.POST?.[`doc-${slug3}`] as GlobalRouteHandler)({
|
res = await (endpoints.global.POST?.[`doc-${slug3}`] as GlobalRouteHandler)({
|
||||||
globalConfig,
|
globalConfig,
|
||||||
req,
|
req: payloadRequest,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -489,17 +505,18 @@ export const POST =
|
|||||||
)({
|
)({
|
||||||
id: slug4,
|
id: slug4,
|
||||||
globalConfig,
|
globalConfig,
|
||||||
req,
|
req: payloadRequest,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
res = new Response('Route Not Found', { status: 404 })
|
res = new Response('Route Not Found', { status: 404 })
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (slug.length === 1 && slug1 in endpoints.root.POST) {
|
} else if (slug.length === 1 && slug1 in endpoints.root.POST) {
|
||||||
await addDataAndFileToRequest({ request: req })
|
const reqWithData = await addDataAndFileToRequest({ request: req })
|
||||||
addLocalesToRequest({ request: req })
|
const payloadRequest = addLocalesToRequestFromData({ request: reqWithData })
|
||||||
res = await endpoints.root.POST[slug1]({ req })
|
res = await endpoints.root.POST[slug1]({ req: payloadRequest })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res instanceof Response) return res
|
if (res instanceof Response) return res
|
||||||
@@ -564,21 +581,25 @@ export const DELETE =
|
|||||||
if (customEndpointResponse) {
|
if (customEndpointResponse) {
|
||||||
return customEndpointResponse
|
return customEndpointResponse
|
||||||
} else {
|
} else {
|
||||||
await addDataAndFileToRequest({ request: req })
|
const reqWithData = await addDataAndFileToRequest({ request: req })
|
||||||
addLocalesToRequest({ request: req })
|
const payloadRequest = addLocalesToRequestFromData({ request: reqWithData })
|
||||||
}
|
|
||||||
|
|
||||||
switch (slug.length) {
|
switch (slug.length) {
|
||||||
case 1:
|
case 1:
|
||||||
// /:collection
|
// /:collection
|
||||||
res = await endpoints.collection.DELETE.delete({ collection, req })
|
res = await endpoints.collection.DELETE.delete({ collection, req: payloadRequest })
|
||||||
break
|
break
|
||||||
case 2:
|
case 2:
|
||||||
// /:collection/:id
|
// /:collection/:id
|
||||||
res = await endpoints.collection.DELETE.deleteByID({ id: slug2, collection, req })
|
res = await endpoints.collection.DELETE.deleteByID({
|
||||||
|
id: slug2,
|
||||||
|
collection,
|
||||||
|
req: payloadRequest,
|
||||||
|
})
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (res instanceof Response) return res
|
if (res instanceof Response) return res
|
||||||
|
|
||||||
@@ -643,21 +664,25 @@ export const PATCH =
|
|||||||
if (customEndpointResponse) {
|
if (customEndpointResponse) {
|
||||||
return customEndpointResponse
|
return customEndpointResponse
|
||||||
} else {
|
} else {
|
||||||
await addDataAndFileToRequest({ request: req })
|
const reqWithData = await addDataAndFileToRequest({ request: req })
|
||||||
addLocalesToRequest({ request: req })
|
const payloadRequest = addLocalesToRequestFromData({ request: reqWithData })
|
||||||
}
|
|
||||||
|
|
||||||
switch (slug.length) {
|
switch (slug.length) {
|
||||||
case 1:
|
case 1:
|
||||||
// /:collection
|
// /:collection
|
||||||
res = await endpoints.collection.PATCH.update({ collection, req })
|
res = await endpoints.collection.PATCH.update({ collection, req: payloadRequest })
|
||||||
break
|
break
|
||||||
case 2:
|
case 2:
|
||||||
// /:collection/:id
|
// /:collection/:id
|
||||||
res = await endpoints.collection.PATCH.updateByID({ id: slug2, collection, req })
|
res = await endpoints.collection.PATCH.updateByID({
|
||||||
|
id: slug2,
|
||||||
|
collection,
|
||||||
|
req: payloadRequest,
|
||||||
|
})
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (res instanceof Response) return res
|
if (res instanceof Response) return res
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Collection, PayloadRequest, SanitizedConfig } from 'payload/types'
|
import type { Collection, PayloadRequestWithData, SanitizedConfig } from 'payload/types'
|
||||||
|
|
||||||
import httpStatus from 'http-status'
|
import httpStatus from 'http-status'
|
||||||
import { APIError } from 'payload/errors'
|
import { APIError } from 'payload/errors'
|
||||||
@@ -78,7 +78,7 @@ export const routeError = async ({
|
|||||||
collection?: Collection
|
collection?: Collection
|
||||||
config: Promise<SanitizedConfig> | SanitizedConfig
|
config: Promise<SanitizedConfig> | SanitizedConfig
|
||||||
err: APIError
|
err: APIError
|
||||||
req: Partial<PayloadRequest>
|
req: Partial<PayloadRequestWithData>
|
||||||
}) => {
|
}) => {
|
||||||
let payload = req?.payload
|
let payload = req?.payload
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
import type { Collection, PayloadRequest, SanitizedGlobalConfig } from 'payload/types'
|
import type { Collection, PayloadRequestWithData, SanitizedGlobalConfig } from 'payload/types'
|
||||||
|
|
||||||
export type BaseRouteHandler = ({ req }: { req: PayloadRequest }) => Promise<Response> | Response
|
export type BaseRouteHandler = ({
|
||||||
|
req,
|
||||||
|
}: {
|
||||||
|
req: PayloadRequestWithData
|
||||||
|
}) => Promise<Response> | Response
|
||||||
|
|
||||||
export type CollectionRouteHandler = ({
|
export type CollectionRouteHandler = ({
|
||||||
collection,
|
collection,
|
||||||
req,
|
req,
|
||||||
}: {
|
}: {
|
||||||
collection: Collection
|
collection: Collection
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
}) => Promise<Response> | Response
|
}) => Promise<Response> | Response
|
||||||
|
|
||||||
export type CollectionRouteHandlerWithID = ({
|
export type CollectionRouteHandlerWithID = ({
|
||||||
@@ -17,7 +21,7 @@ export type CollectionRouteHandlerWithID = ({
|
|||||||
}: {
|
}: {
|
||||||
collection: Collection
|
collection: Collection
|
||||||
id: string
|
id: string
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
}) => Promise<Response> | Response
|
}) => Promise<Response> | Response
|
||||||
|
|
||||||
export type GlobalRouteHandler = ({
|
export type GlobalRouteHandler = ({
|
||||||
@@ -25,7 +29,7 @@ export type GlobalRouteHandler = ({
|
|||||||
req,
|
req,
|
||||||
}: {
|
}: {
|
||||||
globalConfig: SanitizedGlobalConfig
|
globalConfig: SanitizedGlobalConfig
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
}) => Promise<Response> | Response
|
}) => Promise<Response> | Response
|
||||||
|
|
||||||
export type GlobalRouteHandlerWithID = ({
|
export type GlobalRouteHandlerWithID = ({
|
||||||
@@ -35,5 +39,5 @@ export type GlobalRouteHandlerWithID = ({
|
|||||||
}: {
|
}: {
|
||||||
globalConfig: SanitizedGlobalConfig
|
globalConfig: SanitizedGlobalConfig
|
||||||
id: string
|
id: string
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
}) => Promise<Response> | Response
|
}) => Promise<Response> | Response
|
||||||
|
|||||||
@@ -1,28 +1,25 @@
|
|||||||
import type { CustomPayloadRequest, PayloadRequest } from 'payload/types'
|
import type { PayloadRequest, PayloadRequestData } from 'payload/types'
|
||||||
|
|
||||||
import type { NextFileUploadOptions } from '../next-fileupload/index.js'
|
import type { NextFileUploadOptions } from '../next-fileupload/index.js'
|
||||||
|
|
||||||
import { nextFileUpload } from '../next-fileupload/index.js'
|
import { nextFileUpload } from '../next-fileupload/index.js'
|
||||||
|
|
||||||
type AddDataAndFileToRequest = (args: { request: PayloadRequest }) => Promise<void>
|
type ReturnType = PayloadRequest & PayloadRequestData
|
||||||
|
type AddDataAndFileToRequest = (args: { request: PayloadRequest }) => Promise<ReturnType>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mutates the Request to contain 'data' and 'file' if present
|
* Mutates the Request to contain 'data' and 'file' if present
|
||||||
*/
|
*/
|
||||||
export const addDataAndFileToRequest: AddDataAndFileToRequest = async ({
|
export const addDataAndFileToRequest: AddDataAndFileToRequest = async ({ request }) => {
|
||||||
request: incomingRequest,
|
const config = request.payload.config
|
||||||
}) => {
|
|
||||||
const config = incomingRequest.payload.config
|
|
||||||
let data: Record<string, any> | undefined = undefined
|
let data: Record<string, any> | undefined = undefined
|
||||||
let file: CustomPayloadRequest['file'] = undefined
|
let file: PayloadRequestData['file'] = undefined
|
||||||
|
|
||||||
if (
|
if (
|
||||||
incomingRequest.method &&
|
request.method &&
|
||||||
['PATCH', 'POST', 'PUT'].includes(incomingRequest.method.toUpperCase()) &&
|
['PATCH', 'POST', 'PUT'].includes(request.method.toUpperCase()) &&
|
||||||
incomingRequest.body
|
request.body
|
||||||
) {
|
) {
|
||||||
// @ts-expect-error todo: fix type
|
|
||||||
const request = new Request(incomingRequest)
|
|
||||||
const [contentType] = (request.headers.get('Content-Type') || '').split(';')
|
const [contentType] = (request.headers.get('Content-Type') || '').split(';')
|
||||||
|
|
||||||
if (contentType === 'application/json') {
|
if (contentType === 'application/json') {
|
||||||
@@ -44,7 +41,7 @@ export const addDataAndFileToRequest: AddDataAndFileToRequest = async ({
|
|||||||
if (request.headers.has('Content-Length') && request.headers.get('Content-Length') !== '0') {
|
if (request.headers.has('Content-Length') && request.headers.get('Content-Length') !== '0') {
|
||||||
const { error, fields, files } = await nextFileUpload({
|
const { error, fields, files } = await nextFileUpload({
|
||||||
options: config.upload as NextFileUploadOptions,
|
options: config.upload as NextFileUploadOptions,
|
||||||
request,
|
request: request as Request,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -62,9 +59,12 @@ export const addDataAndFileToRequest: AddDataAndFileToRequest = async ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mutableRequest = request as ReturnType
|
||||||
if (data) {
|
if (data) {
|
||||||
incomingRequest.data = data
|
mutableRequest.data = data
|
||||||
incomingRequest.json = () => Promise.resolve(data)
|
mutableRequest.json = () => Promise.resolve(data)
|
||||||
}
|
}
|
||||||
if (file) incomingRequest.file = file
|
if (file) mutableRequest.file = file
|
||||||
|
|
||||||
|
return mutableRequest
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +1,67 @@
|
|||||||
import type { PayloadRequest } from 'payload/types'
|
import type {
|
||||||
|
PayloadRequest,
|
||||||
type AddLocalesToRequestArgs = {
|
PayloadRequestData,
|
||||||
request: PayloadRequest
|
PayloadRequestWithData,
|
||||||
}
|
SanitizedConfig,
|
||||||
|
} from 'payload/types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mutates the Request to contain 'locale' and 'fallbackLocale' based on data or searchParams
|
* Mutates the Request to contain 'locale' and 'fallbackLocale' based on data or searchParams
|
||||||
*/
|
*/
|
||||||
export function addLocalesToRequest({ request }: AddLocalesToRequestArgs): void {
|
type Args = {
|
||||||
|
request: PayloadRequest & PayloadRequestData
|
||||||
|
}
|
||||||
|
export function addLocalesToRequestFromData({ request }: Args): PayloadRequestWithData {
|
||||||
const {
|
const {
|
||||||
data,
|
data,
|
||||||
payload: { config },
|
payload: { config },
|
||||||
} = request
|
} = request
|
||||||
const { localization } = config
|
|
||||||
const urlProperties = new URL(request.url)
|
|
||||||
const { searchParams } = urlProperties
|
|
||||||
|
|
||||||
let locale = searchParams.get('locale')
|
|
||||||
let fallbackLocale = searchParams.get('fallback-locale')
|
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
if (data?.locale && typeof data.locale === 'string') {
|
let localeOnReq = request.locale
|
||||||
locale = data.locale
|
let fallbackLocaleOnReq = request.fallbackLocale
|
||||||
}
|
|
||||||
if (data?.['fallback-locale'] && typeof data?.['fallback-locale'] === 'string') {
|
if (!localeOnReq && data?.locale && typeof data.locale === 'string') {
|
||||||
fallbackLocale = data['fallback-locale']
|
localeOnReq = data.locale
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!fallbackLocaleOnReq &&
|
||||||
|
data?.['fallback-locale'] &&
|
||||||
|
typeof data?.['fallback-locale'] === 'string'
|
||||||
|
) {
|
||||||
|
fallbackLocaleOnReq = data['fallback-locale']
|
||||||
|
}
|
||||||
|
|
||||||
|
const { fallbackLocale, locale } = sanitizeLocales({
|
||||||
|
fallbackLocale: fallbackLocaleOnReq,
|
||||||
|
locale: localeOnReq,
|
||||||
|
localization: config.localization,
|
||||||
|
})
|
||||||
|
|
||||||
|
const mutableRequest = request
|
||||||
|
if (locale) mutableRequest.locale = locale
|
||||||
|
if (fallbackLocale) mutableRequest.fallbackLocale = fallbackLocale
|
||||||
|
return mutableRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
return request
|
||||||
|
}
|
||||||
|
|
||||||
|
type SanitizeLocalesArgs = {
|
||||||
|
fallbackLocale: string
|
||||||
|
locale: string
|
||||||
|
localization: SanitizedConfig['localization']
|
||||||
|
}
|
||||||
|
type SanitizeLocalesReturn = {
|
||||||
|
fallbackLocale?: string
|
||||||
|
locale?: string
|
||||||
|
}
|
||||||
|
export const sanitizeLocales = ({
|
||||||
|
fallbackLocale,
|
||||||
|
locale,
|
||||||
|
localization,
|
||||||
|
}: SanitizeLocalesArgs): SanitizeLocalesReturn => {
|
||||||
if (fallbackLocale === 'none') {
|
if (fallbackLocale === 'none') {
|
||||||
fallbackLocale = 'null'
|
fallbackLocale = 'null'
|
||||||
} else if (localization && !localization.localeCodes.includes(fallbackLocale)) {
|
} else if (localization && !localization.localeCodes.includes(fallbackLocale)) {
|
||||||
@@ -40,6 +74,8 @@ export function addLocalesToRequest({ request }: AddLocalesToRequestArgs): void
|
|||||||
locale = localization.defaultLocale
|
locale = localization.defaultLocale
|
||||||
}
|
}
|
||||||
|
|
||||||
if (locale) request.locale = locale
|
return {
|
||||||
if (fallbackLocale) request.fallbackLocale = fallbackLocale
|
fallbackLocale,
|
||||||
|
locale,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import type { FieldSchemaMap } from './types.js'
|
import type { FieldSchemaMap } from './types.js'
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ import { traverseFields } from './traverseFields.js'
|
|||||||
export const buildFieldSchemaMap = ({
|
export const buildFieldSchemaMap = ({
|
||||||
i18n,
|
i18n,
|
||||||
payload: { config },
|
payload: { config },
|
||||||
}: PayloadRequest): FieldSchemaMap => {
|
}: PayloadRequestWithData): FieldSchemaMap => {
|
||||||
const result: FieldSchemaMap = new Map()
|
const result: FieldSchemaMap = new Map()
|
||||||
|
|
||||||
const validRelationships = config.collections.map((c) => c.slug) || []
|
const validRelationships = config.collections.map((c) => c.slug) || []
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
import type {
|
import type { CustomPayloadRequestProperties, PayloadRequest, SanitizedConfig } from 'payload/types'
|
||||||
Collection,
|
|
||||||
CustomPayloadRequest,
|
|
||||||
PayloadRequest,
|
|
||||||
SanitizedConfig,
|
|
||||||
} from 'payload/types'
|
|
||||||
|
|
||||||
import { initI18n } from '@payloadcms/translations'
|
import { initI18n } from '@payloadcms/translations'
|
||||||
import { executeAuthStrategies } from 'payload/auth'
|
import { executeAuthStrategies } from 'payload/auth'
|
||||||
@@ -12,6 +7,7 @@ import { getDataLoader } from 'payload/utilities'
|
|||||||
import qs from 'qs'
|
import qs from 'qs'
|
||||||
import { URL } from 'url'
|
import { URL } from 'url'
|
||||||
|
|
||||||
|
import { sanitizeLocales } from './addLocalesToRequest.js'
|
||||||
import { getPayloadHMR } from './getPayloadHMR.js'
|
import { getPayloadHMR } from './getPayloadHMR.js'
|
||||||
import { getRequestLanguage } from './getRequestLanguage.js'
|
import { getRequestLanguage } from './getRequestLanguage.js'
|
||||||
|
|
||||||
@@ -31,15 +27,10 @@ export const createPayloadRequest = async ({
|
|||||||
const cookies = parseCookies(request.headers)
|
const cookies = parseCookies(request.headers)
|
||||||
const payload = await getPayloadHMR({ config: configPromise })
|
const payload = await getPayloadHMR({ config: configPromise })
|
||||||
|
|
||||||
const { collections, config } = payload
|
const { config } = payload
|
||||||
|
|
||||||
let collection: Collection = undefined
|
|
||||||
if (params?.collection && collections?.[params.collection]) {
|
|
||||||
collection = collections[params.collection]
|
|
||||||
}
|
|
||||||
|
|
||||||
const urlProperties = new URL(request.url)
|
const urlProperties = new URL(request.url)
|
||||||
const { pathname } = urlProperties
|
const { pathname, searchParams } = urlProperties
|
||||||
|
|
||||||
const isGraphQL =
|
const isGraphQL =
|
||||||
!config.graphQL.disable && pathname === `${config.routes.api}${config.routes.graphQL}`
|
!config.graphQL.disable && pathname === `${config.routes.api}${config.routes.graphQL}`
|
||||||
@@ -56,12 +47,26 @@ export const createPayloadRequest = async ({
|
|||||||
language,
|
language,
|
||||||
})
|
})
|
||||||
|
|
||||||
const customRequest: CustomPayloadRequest = {
|
let locale
|
||||||
|
let fallbackLocale
|
||||||
|
if (config.localization) {
|
||||||
|
const locales = sanitizeLocales({
|
||||||
|
fallbackLocale: searchParams.get('fallback-locale'),
|
||||||
|
locale: searchParams.get('locale'),
|
||||||
|
localization: payload.config.localization,
|
||||||
|
})
|
||||||
|
locale = locales.locale
|
||||||
|
fallbackLocale = locales.fallbackLocale
|
||||||
|
}
|
||||||
|
|
||||||
|
const customRequest: CustomPayloadRequestProperties = {
|
||||||
context: {},
|
context: {},
|
||||||
|
fallbackLocale,
|
||||||
hash: urlProperties.hash,
|
hash: urlProperties.hash,
|
||||||
host: urlProperties.host,
|
host: urlProperties.host,
|
||||||
href: urlProperties.href,
|
href: urlProperties.href,
|
||||||
i18n,
|
i18n,
|
||||||
|
locale,
|
||||||
origin: urlProperties.origin,
|
origin: urlProperties.origin,
|
||||||
pathname: urlProperties.pathname,
|
pathname: urlProperties.pathname,
|
||||||
payload,
|
payload,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Collection, CustomPayloadRequest, SanitizedConfig } from 'payload/types'
|
import type { Collection, PayloadRequestWithData, SanitizedConfig } from 'payload/types'
|
||||||
|
|
||||||
import type { NextFileUploadOptions } from '../next-fileupload/index.js'
|
import type { NextFileUploadOptions } from '../next-fileupload/index.js'
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ type GetDataAndFile = (args: {
|
|||||||
request: Request
|
request: Request
|
||||||
}) => Promise<{
|
}) => Promise<{
|
||||||
data: Record<string, any>
|
data: Record<string, any>
|
||||||
file: CustomPayloadRequest['file']
|
file: PayloadRequestWithData['file']
|
||||||
}>
|
}>
|
||||||
export const getDataAndFile: GetDataAndFile = async ({
|
export const getDataAndFile: GetDataAndFile = async ({
|
||||||
collection,
|
collection,
|
||||||
@@ -18,7 +18,7 @@ export const getDataAndFile: GetDataAndFile = async ({
|
|||||||
request: incomingRequest,
|
request: incomingRequest,
|
||||||
}) => {
|
}) => {
|
||||||
let data: Record<string, any> = undefined
|
let data: Record<string, any> = undefined
|
||||||
let file: CustomPayloadRequest['file'] = undefined
|
let file: PayloadRequestWithData['file'] = undefined
|
||||||
|
|
||||||
if (
|
if (
|
||||||
['PATCH', 'POST', 'PUT'].includes(incomingRequest.method.toUpperCase()) &&
|
['PATCH', 'POST', 'PUT'].includes(incomingRequest.method.toUpperCase()) &&
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
type CorsArgs = {
|
type CorsArgs = {
|
||||||
headers: Headers
|
headers: Headers
|
||||||
req: Partial<PayloadRequest>
|
req: Partial<PayloadRequestWithData>
|
||||||
}
|
}
|
||||||
export const headersWithCors = ({ headers, req }: CorsArgs): Headers => {
|
export const headersWithCors = ({ headers, req }: CorsArgs): Headers => {
|
||||||
const cors = req?.payload.config.cors
|
const cors = req?.payload.config.cors
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type {
|
import type {
|
||||||
InitPageResult,
|
InitPageResult,
|
||||||
PayloadRequest,
|
PayloadRequestWithData,
|
||||||
SanitizedCollectionConfig,
|
SanitizedCollectionConfig,
|
||||||
SanitizedConfig,
|
SanitizedConfig,
|
||||||
SanitizedGlobalConfig,
|
SanitizedGlobalConfig,
|
||||||
@@ -63,7 +63,7 @@ export const initPage = async ({
|
|||||||
ignoreQueryPrefix: true,
|
ignoreQueryPrefix: true,
|
||||||
}),
|
}),
|
||||||
url: `${payload.config.serverURL}${route}${searchParams ? queryString : ''}`,
|
url: `${payload.config.serverURL}${route}${searchParams ? queryString : ''}`,
|
||||||
} as PayloadRequest,
|
} as PayloadRequestWithData,
|
||||||
},
|
},
|
||||||
payload,
|
payload,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import type { PayloadRequest } from 'payload/types'
|
import type { PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import { CopyToClipboard } from '@payloadcms/ui/elements/CopyToClipboard'
|
import { CopyToClipboard } from '@payloadcms/ui/elements/CopyToClipboard'
|
||||||
import { GenerateConfirmation } from '@payloadcms/ui/elements/GenerateConfirmation'
|
import { GenerateConfirmation } from '@payloadcms/ui/elements/GenerateConfirmation'
|
||||||
@@ -40,7 +40,7 @@ export const APIKey: React.FC<{ enabled: boolean; readOnly?: boolean }> = ({
|
|||||||
config,
|
config,
|
||||||
},
|
},
|
||||||
t,
|
t,
|
||||||
} as PayloadRequest,
|
} as PayloadRequestWithData,
|
||||||
siblingData: {},
|
siblingData: {},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import type { FormState, PayloadRequest } from 'payload/types'
|
import type { FormState, PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import { Email } from '@payloadcms/ui/fields/Email'
|
import { Email } from '@payloadcms/ui/fields/Email'
|
||||||
import { Form } from '@payloadcms/ui/forms/Form'
|
import { Form } from '@payloadcms/ui/forms/Form'
|
||||||
@@ -70,7 +70,7 @@ export const ForgotPasswordForm: React.FC = () => {
|
|||||||
type: 'email',
|
type: 'email',
|
||||||
data: {},
|
data: {},
|
||||||
preferences: { fields: {} },
|
preferences: { fields: {} },
|
||||||
req: { t } as PayloadRequest,
|
req: { t } as PayloadRequestWithData,
|
||||||
required: true,
|
required: true,
|
||||||
siblingData: {},
|
siblingData: {},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import React from 'react'
|
|||||||
const baseClass = 'login__form'
|
const baseClass = 'login__form'
|
||||||
const Link = (LinkImport.default || LinkImport) as unknown as typeof LinkImport.default
|
const Link = (LinkImport.default || LinkImport) as unknown as typeof LinkImport.default
|
||||||
|
|
||||||
import type { FormState, PayloadRequest } from 'payload/types'
|
import type { FormState, PayloadRequestWithData } from 'payload/types'
|
||||||
|
|
||||||
import { FormLoadingOverlayToggle } from '@payloadcms/ui/elements/Loading'
|
import { FormLoadingOverlayToggle } from '@payloadcms/ui/elements/Loading'
|
||||||
import { Email } from '@payloadcms/ui/fields/Email'
|
import { Email } from '@payloadcms/ui/fields/Email'
|
||||||
@@ -69,7 +69,7 @@ export const LoginForm: React.FC<{
|
|||||||
type: 'email',
|
type: 'email',
|
||||||
data: {},
|
data: {},
|
||||||
preferences: { fields: {} },
|
preferences: { fields: {} },
|
||||||
req: { t } as PayloadRequest,
|
req: { t } as PayloadRequestWithData,
|
||||||
required: true,
|
required: true,
|
||||||
siblingData: {},
|
siblingData: {},
|
||||||
})
|
})
|
||||||
@@ -91,7 +91,7 @@ export const LoginForm: React.FC<{
|
|||||||
config,
|
config,
|
||||||
},
|
},
|
||||||
t,
|
t,
|
||||||
} as PayloadRequest,
|
} as PayloadRequestWithData,
|
||||||
required: true,
|
required: true,
|
||||||
siblingData: {},
|
siblingData: {},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import type { JSONSchema4 } from 'json-schema'
|
|||||||
|
|
||||||
import type { SanitizedConfig } from '../config/types.js'
|
import type { SanitizedConfig } from '../config/types.js'
|
||||||
import type { Field, FieldBase, RichTextField, Validate } from '../fields/config/types.js'
|
import type { Field, FieldBase, RichTextField, Validate } from '../fields/config/types.js'
|
||||||
import type { PayloadRequest, RequestContext } from '../types/index.js'
|
import type { PayloadRequestWithData, RequestContext } from '../types/index.js'
|
||||||
import type { WithServerSideProps } from './elements/WithServerSideProps.js'
|
import type { WithServerSideProps } from './elements/WithServerSideProps.js'
|
||||||
|
|
||||||
export type RichTextFieldProps<
|
export type RichTextFieldProps<
|
||||||
@@ -64,7 +64,7 @@ type RichTextAdapterBase<
|
|||||||
flattenLocales: boolean
|
flattenLocales: boolean
|
||||||
overrideAccess?: boolean
|
overrideAccess?: boolean
|
||||||
populationPromises: Promise<void>[]
|
populationPromises: Promise<void>[]
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
showHiddenFields: boolean
|
showHiddenFields: boolean
|
||||||
siblingDoc: Record<string, unknown>
|
siblingDoc: Record<string, unknown>
|
||||||
}) => void
|
}) => void
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import type { Permissions } from '../../auth/index.js'
|
|||||||
import type { SanitizedCollectionConfig } from '../../collections/config/types.js'
|
import type { SanitizedCollectionConfig } from '../../collections/config/types.js'
|
||||||
import type { Locale } from '../../config/types.js'
|
import type { Locale } from '../../config/types.js'
|
||||||
import type { SanitizedGlobalConfig } from '../../globals/config/types.js'
|
import type { SanitizedGlobalConfig } from '../../globals/config/types.js'
|
||||||
import type { PayloadRequest } from '../../types/index.js'
|
import type { PayloadRequestWithData } from '../../types/index.js'
|
||||||
|
|
||||||
export type AdminViewConfig = {
|
export type AdminViewConfig = {
|
||||||
Component: AdminViewComponent
|
Component: AdminViewComponent
|
||||||
@@ -42,7 +42,7 @@ export type InitPageResult = {
|
|||||||
globalConfig?: SanitizedGlobalConfig
|
globalConfig?: SanitizedGlobalConfig
|
||||||
locale: Locale
|
locale: Locale
|
||||||
permissions: Permissions
|
permissions: Permissions
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
translations: SupportedLanguages
|
translations: SupportedLanguages
|
||||||
visibleEntities: VisibleEntities
|
visibleEntities: VisibleEntities
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
import type { PayloadRequest } from '../types/index.js'
|
import type { PayloadRequestWithData } from '../types/index.js'
|
||||||
|
|
||||||
export default ({ req: { user } }: { req: PayloadRequest }): boolean => Boolean(user)
|
export default ({ req: { user } }: { req: PayloadRequestWithData }): boolean => Boolean(user)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { Access, AccessResult } from '../config/types.js'
|
import type { Access, AccessResult } from '../config/types.js'
|
||||||
import type { PayloadRequest } from '../types/index.js'
|
import type { PayloadRequestWithData } from '../types/index.js'
|
||||||
|
|
||||||
import { Forbidden } from '../errors/index.js'
|
import { Forbidden } from '../errors/index.js'
|
||||||
|
|
||||||
@@ -8,7 +8,7 @@ type OperationArgs = {
|
|||||||
disableErrors?: boolean
|
disableErrors?: boolean
|
||||||
id?: number | string
|
id?: number | string
|
||||||
isReadingStaticFile?: boolean
|
isReadingStaticFile?: boolean
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
}
|
}
|
||||||
const executeAccess = async (
|
const executeAccess = async (
|
||||||
{ id, data, disableErrors, isReadingStaticFile = false, req }: OperationArgs,
|
{ id, data, disableErrors, isReadingStaticFile = false, req }: OperationArgs,
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import type { AllOperations, PayloadRequest } from '../types/index.js'
|
import type { AllOperations, PayloadRequestWithData } from '../types/index.js'
|
||||||
import type { Permissions } from './types.js'
|
import type { Permissions } from './types.js'
|
||||||
|
|
||||||
import { getEntityPolicies } from '../utilities/getEntityPolicies.js'
|
import { getEntityPolicies } from '../utilities/getEntityPolicies.js'
|
||||||
import isolateObjectProperty from '../utilities/isolateObjectProperty.js'
|
import isolateObjectProperty from '../utilities/isolateObjectProperty.js'
|
||||||
|
|
||||||
type GetAccessResultsArgs = {
|
type GetAccessResultsArgs = {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
}
|
}
|
||||||
export async function getAccessResults({ req }: GetAccessResultsArgs): Promise<Permissions> {
|
export async function getAccessResults({ req }: GetAccessResultsArgs): Promise<Permissions> {
|
||||||
const results = {} as Permissions
|
const results = {} as Permissions
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable no-param-reassign */
|
/* eslint-disable no-param-reassign */
|
||||||
import type { CollectionConfig } from '../collections/config/types.js'
|
import type { CollectionConfig } from '../collections/config/types.js'
|
||||||
import type { Field, TabAsField } from '../fields/config/types.js'
|
import type { Field, TabAsField } from '../fields/config/types.js'
|
||||||
import type { PayloadRequest } from '../types/index.js'
|
import type { PayloadRequestWithData } from '../types/index.js'
|
||||||
|
|
||||||
import { fieldAffectsData, tabHasName } from '../fields/config/types.js'
|
import { fieldAffectsData, tabHasName } from '../fields/config/types.js'
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ const traverseFields = ({
|
|||||||
export const getFieldsToSign = (args: {
|
export const getFieldsToSign = (args: {
|
||||||
collectionConfig: CollectionConfig
|
collectionConfig: CollectionConfig
|
||||||
email: string
|
email: string
|
||||||
user: PayloadRequest['user']
|
user: PayloadRequestWithData['user']
|
||||||
}): Record<string, unknown> => {
|
}): Record<string, unknown> => {
|
||||||
const { collectionConfig, email, user } = args
|
const { collectionConfig, email, user } = args
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { PayloadRequest } from '../../types/index.js'
|
import type { PayloadRequestWithData } from '../../types/index.js'
|
||||||
import type { Permissions } from '../types.js'
|
import type { Permissions } from '../types.js'
|
||||||
|
|
||||||
import { commitTransaction } from '../../utilities/commitTransaction.js'
|
import { commitTransaction } from '../../utilities/commitTransaction.js'
|
||||||
@@ -8,7 +8,7 @@ import { adminInit as adminInitTelemetry } from '../../utilities/telemetry/event
|
|||||||
import { getAccessResults } from '../getAccessResults.js'
|
import { getAccessResults } from '../getAccessResults.js'
|
||||||
|
|
||||||
type Arguments = {
|
type Arguments = {
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
}
|
}
|
||||||
|
|
||||||
export const accessOperation = async (args: Arguments): Promise<Permissions> => {
|
export const accessOperation = async (args: Arguments): Promise<Permissions> => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { GeneratedTypes } from '../../index.js'
|
import type { GeneratedTypes } from '../../index.js'
|
||||||
import type { PayloadRequest } from '../../types/index.js'
|
import type { PayloadRequestWithData } from '../../types/index.js'
|
||||||
import type { Permissions, User } from '../types.js'
|
import type { Permissions, User } from '../types.js'
|
||||||
|
|
||||||
import { commitTransaction } from '../../utilities/commitTransaction.js'
|
import { commitTransaction } from '../../utilities/commitTransaction.js'
|
||||||
@@ -11,7 +11,7 @@ import { getAccessResults } from '../getAccessResults.js'
|
|||||||
|
|
||||||
export type AuthArgs = {
|
export type AuthArgs = {
|
||||||
headers: Request['headers']
|
headers: Request['headers']
|
||||||
req?: Omit<PayloadRequest, 'user'>
|
req?: Omit<PayloadRequestWithData, 'user'>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AuthResult = {
|
export type AuthResult = {
|
||||||
@@ -22,7 +22,7 @@ export type AuthResult = {
|
|||||||
|
|
||||||
export const auth = async (args: Required<AuthArgs>): Promise<AuthResult> => {
|
export const auth = async (args: Required<AuthArgs>): Promise<AuthResult> => {
|
||||||
const { headers } = args
|
const { headers } = args
|
||||||
const req = args.req as PayloadRequest
|
const req = args.req as PayloadRequestWithData
|
||||||
const { payload } = req
|
const { payload } = req
|
||||||
|
|
||||||
const cookies = parseCookies(headers)
|
const cookies = parseCookies(headers)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import httpStatus from 'http-status'
|
|||||||
import { URL } from 'url'
|
import { URL } from 'url'
|
||||||
|
|
||||||
import type { Collection } from '../../collections/config/types.js'
|
import type { Collection } from '../../collections/config/types.js'
|
||||||
import type { PayloadRequest } from '../../types/index.js'
|
import type { PayloadRequestWithData } from '../../types/index.js'
|
||||||
|
|
||||||
import { buildAfterOperation } from '../../collections/operations/utils.js'
|
import { buildAfterOperation } from '../../collections/operations/utils.js'
|
||||||
import { APIError } from '../../errors/index.js'
|
import { APIError } from '../../errors/index.js'
|
||||||
@@ -19,7 +19,7 @@ export type Arguments = {
|
|||||||
}
|
}
|
||||||
disableEmail?: boolean
|
disableEmail?: boolean
|
||||||
expiration?: number
|
expiration?: number
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Result = string
|
export type Result = string
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { PayloadRequest } from '../../types/index.js'
|
import type { PayloadRequestWithData } from '../../types/index.js'
|
||||||
|
|
||||||
export const initOperation = async (args: {
|
export const initOperation = async (args: {
|
||||||
collection: string
|
collection: string
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
}): Promise<boolean> => {
|
}): Promise<boolean> => {
|
||||||
const { collection: slug, req } = args
|
const { collection: slug, req } = args
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { Payload } from '../../../index.js'
|
import type { Payload } from '../../../index.js'
|
||||||
import type { PayloadRequest } from '../../../types/index.js'
|
import type { PayloadRequestWithData } from '../../../types/index.js'
|
||||||
import type { AuthArgs, AuthResult } from '../auth.js'
|
import type { AuthArgs, AuthResult } from '../auth.js'
|
||||||
|
|
||||||
import { createLocalReq } from '../../../utilities/createLocalReq.js'
|
import { createLocalReq } from '../../../utilities/createLocalReq.js'
|
||||||
@@ -10,6 +10,6 @@ export const auth = async (payload: Payload, options: AuthArgs): Promise<AuthRes
|
|||||||
|
|
||||||
return await authOperation({
|
return await authOperation({
|
||||||
headers,
|
headers,
|
||||||
req: await createLocalReq({ req: options.req as PayloadRequest }, payload),
|
req: await createLocalReq({ req: options.req as PayloadRequestWithData }, payload),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { GeneratedTypes, Payload, RequestContext } from '../../../index.js'
|
import type { GeneratedTypes, Payload, RequestContext } from '../../../index.js'
|
||||||
import type { PayloadRequest } from '../../../types/index.js'
|
import type { PayloadRequestWithData } from '../../../types/index.js'
|
||||||
import type { Result } from '../forgotPassword.js'
|
import type { Result } from '../forgotPassword.js'
|
||||||
|
|
||||||
import { APIError } from '../../../errors/index.js'
|
import { APIError } from '../../../errors/index.js'
|
||||||
@@ -14,7 +14,7 @@ export type Options<T extends keyof GeneratedTypes['collections']> = {
|
|||||||
}
|
}
|
||||||
disableEmail?: boolean
|
disableEmail?: boolean
|
||||||
expiration?: number
|
expiration?: number
|
||||||
req?: PayloadRequest
|
req?: PayloadRequestWithData
|
||||||
}
|
}
|
||||||
|
|
||||||
async function localForgotPassword<T extends keyof GeneratedTypes['collections']>(
|
async function localForgotPassword<T extends keyof GeneratedTypes['collections']>(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Payload, RequestContext } from '../../../index.js'
|
import type { Payload, RequestContext } from '../../../index.js'
|
||||||
import type { GeneratedTypes } from '../../../index.js'
|
import type { GeneratedTypes } from '../../../index.js'
|
||||||
import type { PayloadRequest } from '../../../types/index.js'
|
import type { PayloadRequestWithData } from '../../../types/index.js'
|
||||||
import type { Result } from '../login.js'
|
import type { Result } from '../login.js'
|
||||||
|
|
||||||
import { APIError } from '../../../errors/index.js'
|
import { APIError } from '../../../errors/index.js'
|
||||||
@@ -18,7 +18,7 @@ export type Options<TSlug extends keyof GeneratedTypes['collections']> = {
|
|||||||
fallbackLocale?: string
|
fallbackLocale?: string
|
||||||
locale?: string
|
locale?: string
|
||||||
overrideAccess?: boolean
|
overrideAccess?: boolean
|
||||||
req?: PayloadRequest
|
req?: PayloadRequestWithData
|
||||||
showHiddenFields?: boolean
|
showHiddenFields?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Payload, RequestContext } from '../../../index.js'
|
import type { Payload, RequestContext } from '../../../index.js'
|
||||||
import type { GeneratedTypes } from '../../../index.js'
|
import type { GeneratedTypes } from '../../../index.js'
|
||||||
import type { PayloadRequest } from '../../../types/index.js'
|
import type { PayloadRequestWithData } from '../../../types/index.js'
|
||||||
import type { Result } from '../resetPassword.js'
|
import type { Result } from '../resetPassword.js'
|
||||||
|
|
||||||
import { APIError } from '../../../errors/index.js'
|
import { APIError } from '../../../errors/index.js'
|
||||||
@@ -15,7 +15,7 @@ export type Options<T extends keyof GeneratedTypes['collections']> = {
|
|||||||
token: string
|
token: string
|
||||||
}
|
}
|
||||||
overrideAccess: boolean
|
overrideAccess: boolean
|
||||||
req?: PayloadRequest
|
req?: PayloadRequestWithData
|
||||||
}
|
}
|
||||||
|
|
||||||
async function localResetPassword<T extends keyof GeneratedTypes['collections']>(
|
async function localResetPassword<T extends keyof GeneratedTypes['collections']>(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Payload, RequestContext } from '../../../index.js'
|
import type { Payload, RequestContext } from '../../../index.js'
|
||||||
import type { GeneratedTypes } from '../../../index.js'
|
import type { GeneratedTypes } from '../../../index.js'
|
||||||
import type { PayloadRequest } from '../../../types/index.js'
|
import type { PayloadRequestWithData } from '../../../types/index.js'
|
||||||
|
|
||||||
import { APIError } from '../../../errors/index.js'
|
import { APIError } from '../../../errors/index.js'
|
||||||
import { createLocalReq } from '../../../utilities/createLocalReq.js'
|
import { createLocalReq } from '../../../utilities/createLocalReq.js'
|
||||||
@@ -13,7 +13,7 @@ export type Options<T extends keyof GeneratedTypes['collections']> = {
|
|||||||
email
|
email
|
||||||
}
|
}
|
||||||
overrideAccess: boolean
|
overrideAccess: boolean
|
||||||
req?: PayloadRequest
|
req?: PayloadRequestWithData
|
||||||
}
|
}
|
||||||
|
|
||||||
async function localUnlock<T extends keyof GeneratedTypes['collections']>(
|
async function localUnlock<T extends keyof GeneratedTypes['collections']>(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Payload, RequestContext } from '../../../index.js'
|
import type { Payload, RequestContext } from '../../../index.js'
|
||||||
import type { GeneratedTypes } from '../../../index.js'
|
import type { GeneratedTypes } from '../../../index.js'
|
||||||
import type { PayloadRequest } from '../../../types/index.js'
|
import type { PayloadRequestWithData } from '../../../types/index.js'
|
||||||
|
|
||||||
import { APIError } from '../../../errors/index.js'
|
import { APIError } from '../../../errors/index.js'
|
||||||
import { createLocalReq } from '../../../utilities/createLocalReq.js'
|
import { createLocalReq } from '../../../utilities/createLocalReq.js'
|
||||||
@@ -9,7 +9,7 @@ import { verifyEmailOperation } from '../verifyEmail.js'
|
|||||||
export type Options<T extends keyof GeneratedTypes['collections']> = {
|
export type Options<T extends keyof GeneratedTypes['collections']> = {
|
||||||
collection: T
|
collection: T
|
||||||
context?: RequestContext
|
context?: RequestContext
|
||||||
req?: PayloadRequest
|
req?: PayloadRequestWithData
|
||||||
token: string
|
token: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import jwt from 'jsonwebtoken'
|
|||||||
|
|
||||||
import type { Collection } from '../../collections/config/types.js'
|
import type { Collection } from '../../collections/config/types.js'
|
||||||
import type { GeneratedTypes } from '../../index.js'
|
import type { GeneratedTypes } from '../../index.js'
|
||||||
import type { PayloadRequest } from '../../types/index.js'
|
import type { PayloadRequestWithData } from '../../types/index.js'
|
||||||
import type { User } from '../types.js'
|
import type { User } from '../types.js'
|
||||||
|
|
||||||
import { buildAfterOperation } from '../../collections/operations/utils.js'
|
import { buildAfterOperation } from '../../collections/operations/utils.js'
|
||||||
@@ -32,7 +32,7 @@ export type Arguments = {
|
|||||||
}
|
}
|
||||||
depth?: number
|
depth?: number
|
||||||
overrideAccess?: boolean
|
overrideAccess?: boolean
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
showHiddenFields?: boolean
|
showHiddenFields?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import httpStatus from 'http-status'
|
import httpStatus from 'http-status'
|
||||||
|
|
||||||
import type { Collection } from '../../collections/config/types.js'
|
import type { Collection } from '../../collections/config/types.js'
|
||||||
import type { PayloadRequest } from '../../types/index.js'
|
import type { PayloadRequestWithData } from '../../types/index.js'
|
||||||
|
|
||||||
import { APIError } from '../../errors/index.js'
|
import { APIError } from '../../errors/index.js'
|
||||||
|
|
||||||
export type Arguments = {
|
export type Arguments = {
|
||||||
collection: Collection
|
collection: Collection
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
}
|
}
|
||||||
|
|
||||||
export const logoutOperation = async (incomingArgs: Arguments): Promise<boolean> => {
|
export const logoutOperation = async (incomingArgs: Arguments): Promise<boolean> => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import jwt from 'jsonwebtoken'
|
import jwt from 'jsonwebtoken'
|
||||||
|
|
||||||
import type { Collection } from '../../collections/config/types.js'
|
import type { Collection } from '../../collections/config/types.js'
|
||||||
import type { PayloadRequest } from '../../types/index.js'
|
import type { PayloadRequestWithData } from '../../types/index.js'
|
||||||
import type { ClientUser, User } from '../types.js'
|
import type { ClientUser, User } from '../types.js'
|
||||||
|
|
||||||
export type MeOperationResult = {
|
export type MeOperationResult = {
|
||||||
@@ -14,7 +14,7 @@ export type MeOperationResult = {
|
|||||||
export type Arguments = {
|
export type Arguments = {
|
||||||
collection: Collection
|
collection: Collection
|
||||||
currentToken?: string
|
currentToken?: string
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
}
|
}
|
||||||
|
|
||||||
export const meOperation = async ({
|
export const meOperation = async ({
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import jwt from 'jsonwebtoken'
|
|||||||
import url from 'url'
|
import url from 'url'
|
||||||
|
|
||||||
import type { BeforeOperationHook, Collection } from '../../collections/config/types.js'
|
import type { BeforeOperationHook, Collection } from '../../collections/config/types.js'
|
||||||
import type { PayloadRequest } from '../../types/index.js'
|
import type { PayloadRequestWithData } from '../../types/index.js'
|
||||||
import type { Document } from '../../types/index.js'
|
import type { Document } from '../../types/index.js'
|
||||||
|
|
||||||
import { buildAfterOperation } from '../../collections/operations/utils.js'
|
import { buildAfterOperation } from '../../collections/operations/utils.js'
|
||||||
@@ -20,7 +20,7 @@ export type Result = {
|
|||||||
|
|
||||||
export type Arguments = {
|
export type Arguments = {
|
||||||
collection: Collection
|
collection: Collection
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
token: string
|
token: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { MarkOptional } from 'ts-essentials'
|
|||||||
|
|
||||||
import type { Collection } from '../../collections/config/types.js'
|
import type { Collection } from '../../collections/config/types.js'
|
||||||
import type { GeneratedTypes } from '../../index.js'
|
import type { GeneratedTypes } from '../../index.js'
|
||||||
import type { PayloadRequest } from '../../types/index.js'
|
import type { PayloadRequestWithData } from '../../types/index.js'
|
||||||
|
|
||||||
import { Forbidden } from '../../errors/index.js'
|
import { Forbidden } from '../../errors/index.js'
|
||||||
import { commitTransaction } from '../../utilities/commitTransaction.js'
|
import { commitTransaction } from '../../utilities/commitTransaction.js'
|
||||||
@@ -15,7 +15,7 @@ export type Arguments<T extends { [field: number | string | symbol]: unknown }>
|
|||||||
email: string
|
email: string
|
||||||
password: string
|
password: string
|
||||||
}
|
}
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Result<T> = {
|
export type Result<T> = {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import httpStatus from 'http-status'
|
|||||||
import jwt from 'jsonwebtoken'
|
import jwt from 'jsonwebtoken'
|
||||||
|
|
||||||
import type { Collection } from '../../collections/config/types.js'
|
import type { Collection } from '../../collections/config/types.js'
|
||||||
import type { PayloadRequest } from '../../types/index.js'
|
import type { PayloadRequestWithData } from '../../types/index.js'
|
||||||
|
|
||||||
import { APIError } from '../../errors/index.js'
|
import { APIError } from '../../errors/index.js'
|
||||||
import { commitTransaction } from '../../utilities/commitTransaction.js'
|
import { commitTransaction } from '../../utilities/commitTransaction.js'
|
||||||
@@ -25,7 +25,7 @@ export type Arguments = {
|
|||||||
}
|
}
|
||||||
depth?: number
|
depth?: number
|
||||||
overrideAccess?: boolean
|
overrideAccess?: boolean
|
||||||
req: PayloadRequest
|
req: PayloadRequestWithData
|
||||||
}
|
}
|
||||||
|
|
||||||
export const resetPasswordOperation = async (args: Arguments): Promise<Result> => {
|
export const resetPasswordOperation = async (args: Arguments): Promise<Result> => {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user