Skip to content

Commit

Permalink
Merge branch 'main' into refactor/bulk-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsfletch committed Feb 21, 2025
2 parents 8c4abe8 + a8bec9a commit 53bd4c9
Show file tree
Hide file tree
Showing 42 changed files with 833 additions and 521 deletions.
110 changes: 75 additions & 35 deletions docs/configuration/overview.mdx

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions docs/rich-text/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ Here's an overview of all the included features:

| Feature Name | Included by default | Description |
| --- | --- | --- |
| **`BoldTextFeature`** | Yes | Handles the bold text format |
| **`ItalicTextFeature`** | Yes | Handles the italic text format |
| **`UnderlineTextFeature`** | Yes | Handles the underline text format |
| **`StrikethroughTextFeature`** | Yes | Handles the strikethrough text format |
| **`SubscriptTextFeature`** | Yes | Handles the subscript text format |
| **`SuperscriptTextFeature`** | Yes | Handles the superscript text format |
| **`InlineCodeTextFeature`** | Yes | Handles the inline-code text format |
| **`BoldFeature`** | Yes | Handles the bold text format |
| **`ItalicFeature`** | Yes | Handles the italic text format |
| **`UnderlineFeature`** | Yes | Handles the underline text format |
| **`StrikethroughFeature`** | Yes | Handles the strikethrough text format |
| **`SubscriptFeature`** | Yes | Handles the subscript text format |
| **`SuperscriptFeature`** | Yes | Handles the superscript text format |
| **`InlineCodeFeature`** | Yes | Handles the inline-code text format |
| **`ParagraphFeature`** | Yes | Handles paragraphs. Since they are already a key feature of lexical itself, this Feature mainly handles the Slash and Add-Block menu entries for paragraphs |
| **`HeadingFeature`** | Yes | Adds Heading Nodes (by default, H1 - H6, but that can be customized) |
| **`AlignFeature`** | Yes | Allows you to align text left, centered and right |
Expand Down
28 changes: 14 additions & 14 deletions packages/db-mongodb/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { MongooseAdapter } from './index.js'

import { getSession } from './utilities/getSession.js'
import { handleError } from './utilities/handleError.js'
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'
import { transform } from './utilities/transform.js'

export const create: Create = async function create(
this: MongooseAdapter,
Expand All @@ -18,31 +18,31 @@ export const create: Create = async function create(

let doc

const sanitizedData = sanitizeRelationshipIDs({
config: this.payload.config,
transform({
adapter: this,
data,
fields: this.payload.collections[collection].config.fields,
operation: 'write',
})

if (this.payload.collections[collection].customIDType) {
sanitizedData._id = sanitizedData.id
data._id = data.id
}

try {
;[doc] = await Model.create([sanitizedData], options)
;[doc] = await Model.create([data], options)
} catch (error) {
handleError({ collection, error, req })
}

// doc.toJSON does not do stuff like converting ObjectIds to string, or date strings to date objects. That's why we use JSON.parse/stringify here
const result: Document = JSON.parse(JSON.stringify(doc))
const verificationToken = doc._verificationToken
doc = doc.toObject()

// custom id type reset
result.id = result._id
if (verificationToken) {
result._verificationToken = verificationToken
}
transform({
adapter: this,
data: doc,
fields: this.payload.collections[collection].config.fields,
operation: 'read',
})

return result
return doc
}
27 changes: 14 additions & 13 deletions packages/db-mongodb/src/createGlobal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,36 @@ import type { CreateGlobal } from 'payload'
import type { MongooseAdapter } from './index.js'

import { getSession } from './utilities/getSession.js'
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'
import { transform } from './utilities/transform.js'

export const createGlobal: CreateGlobal = async function createGlobal(
this: MongooseAdapter,
{ slug, data, req },
) {
const Model = this.globals

const global = sanitizeRelationshipIDs({
config: this.payload.config,
data: {
globalType: slug,
...data,
},
transform({
adapter: this,
data,
fields: this.payload.config.globals.find((globalConfig) => globalConfig.slug === slug).fields,
globalSlug: slug,
operation: 'write',
})

const options: CreateOptions = {
session: await getSession(this, req),
}

let [result] = (await Model.create([global], options)) as any
let [result] = (await Model.create([data], options)) as any

result = JSON.parse(JSON.stringify(result))
result = result.toObject()

// custom id type reset
result.id = result._id
result = sanitizeInternalFields(result)
transform({
adapter: this,
data: result,
fields: this.payload.config.globals.find((globalConfig) => globalConfig.slug === slug).fields,
operation: 'read',
})

return result
}
60 changes: 33 additions & 27 deletions packages/db-mongodb/src/createGlobalVersion.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { CreateOptions } from 'mongoose'

import { buildVersionGlobalFields, type CreateGlobalVersion, type Document } from 'payload'
import { buildVersionGlobalFields, type CreateGlobalVersion } from 'payload'

import type { MongooseAdapter } from './index.js'

import { getSession } from './utilities/getSession.js'
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'
import { transform } from './utilities/transform.js'

export const createGlobalVersion: CreateGlobalVersion = async function createGlobalVersion(
this: MongooseAdapter,
Expand All @@ -26,25 +26,30 @@ export const createGlobalVersion: CreateGlobalVersion = async function createGlo
session: await getSession(this, req),
}

const data = sanitizeRelationshipIDs({
config: this.payload.config,
data: {
autosave,
createdAt,
latest: true,
parent,
publishedLocale,
snapshot,
updatedAt,
version: versionData,
},
fields: buildVersionGlobalFields(
this.payload.config,
this.payload.config.globals.find((global) => global.slug === globalSlug),
),
const data = {
autosave,
createdAt,
latest: true,
parent,
publishedLocale,
snapshot,
updatedAt,
version: versionData,
}

const fields = buildVersionGlobalFields(
this.payload.config,
this.payload.config.globals.find((global) => global.slug === globalSlug),
)

transform({
adapter: this,
data,
fields,
operation: 'write',
})

const [doc] = await VersionModel.create([data], options, req)
let [doc] = await VersionModel.create([data], options, req)

await VersionModel.updateMany(
{
Expand All @@ -70,13 +75,14 @@ export const createGlobalVersion: CreateGlobalVersion = async function createGlo
options,
)

const result: Document = JSON.parse(JSON.stringify(doc))
const verificationToken = doc._verificationToken
doc = doc.toObject()

// custom id type reset
result.id = result._id
if (verificationToken) {
result._verificationToken = verificationToken
}
return result
transform({
adapter: this,
data: doc,
fields,
operation: 'read',
})

return doc
}
68 changes: 33 additions & 35 deletions packages/db-mongodb/src/createVersion.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { CreateOptions } from 'mongoose'

import { Types } from 'mongoose'
import { buildVersionCollectionFields, type CreateVersion, type Document } from 'payload'
import { buildVersionCollectionFields, type CreateVersion } from 'payload'

import type { MongooseAdapter } from './index.js'

import { getSession } from './utilities/getSession.js'
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'
import { transform } from './utilities/transform.js'

export const createVersion: CreateVersion = async function createVersion(
this: MongooseAdapter,
Expand All @@ -27,25 +26,30 @@ export const createVersion: CreateVersion = async function createVersion(
session: await getSession(this, req),
}

const data = sanitizeRelationshipIDs({
config: this.payload.config,
data: {
autosave,
createdAt,
latest: true,
parent,
publishedLocale,
snapshot,
updatedAt,
version: versionData,
},
fields: buildVersionCollectionFields(
this.payload.config,
this.payload.collections[collectionSlug].config,
),
const data = {
autosave,
createdAt,
latest: true,
parent,
publishedLocale,
snapshot,
updatedAt,
version: versionData,
}

const fields = buildVersionCollectionFields(
this.payload.config,
this.payload.collections[collectionSlug].config,
)

transform({
adapter: this,
data,
fields,
operation: 'write',
})

const [doc] = await VersionModel.create([data], options, req)
let [doc] = await VersionModel.create([data], options, req)

const parentQuery = {
$or: [
Expand All @@ -56,13 +60,6 @@ export const createVersion: CreateVersion = async function createVersion(
},
],
}
if (data.parent instanceof Types.ObjectId) {
parentQuery.$or.push({
parent: {
$eq: data.parent.toString(),
},
})
}

await VersionModel.updateMany(
{
Expand All @@ -89,13 +86,14 @@ export const createVersion: CreateVersion = async function createVersion(
options,
)

const result: Document = JSON.parse(JSON.stringify(doc))
const verificationToken = doc._verificationToken
doc = doc.toObject()

// custom id type reset
result.id = result._id
if (verificationToken) {
result._verificationToken = verificationToken
}
return result
transform({
adapter: this,
data: doc,
fields,
operation: 'read',
})

return doc
}
17 changes: 9 additions & 8 deletions packages/db-mongodb/src/deleteOne.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { QueryOptions } from 'mongoose'
import type { DeleteOne, Document } from 'payload'
import type { DeleteOne } from 'payload'

import type { MongooseAdapter } from './index.js'

import { buildQuery } from './queries/buildQuery.js'
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'
import { getSession } from './utilities/getSession.js'
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'
import { transform } from './utilities/transform.js'

export const deleteOne: DeleteOne = async function deleteOne(
this: MongooseAdapter,
Expand Down Expand Up @@ -35,11 +35,12 @@ export const deleteOne: DeleteOne = async function deleteOne(
return null
}

let result: Document = JSON.parse(JSON.stringify(doc))

// custom id type reset
result.id = result._id
result = sanitizeInternalFields(result)
transform({
adapter: this,
data: doc,
fields: this.payload.collections[collection].config.fields,
operation: 'read',
})

return result
return doc
}
17 changes: 8 additions & 9 deletions packages/db-mongodb/src/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { buildSortParam } from './queries/buildSortParam.js'
import { buildJoinAggregation } from './utilities/buildJoinAggregation.js'
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'
import { getSession } from './utilities/getSession.js'
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'
import { transform } from './utilities/transform.js'

export const find: Find = async function find(
this: MongooseAdapter,
Expand Down Expand Up @@ -133,13 +133,12 @@ export const find: Find = async function find(
result = await Model.paginate(query, paginationOptions)
}

const docs = JSON.parse(JSON.stringify(result.docs))
transform({
adapter: this,
data: result.docs,
fields: this.payload.collections[collection].config.fields,
operation: 'read',
})

return {
...result,
docs: docs.map((doc) => {
doc.id = doc._id
return sanitizeInternalFields(doc)
}),
}
return result
}
Loading

0 comments on commit 53bd4c9

Please sign in to comment.