Compare commits

..

57 Commits

Author SHA1 Message Date
Elliot DeNolf
4151a902f2 chore(release): v3.53.0 [skip ci] 2025-08-21 14:27:59 -04:00
Jarrod Flesch
b65ca6832d fix(ui): thread id through instead of from routeParams (#13539)
Adjustment to https://github.com/payloadcms/payload/pull/13526

Prefer to thread ID through arguments instead of relying on routeParams
which would mean that ID is always a string - would not work for PG dbs
or non-text based ID's.
2025-08-21 18:14:58 +00:00
Jarrod Flesch
76741eb722 chore(plugin-multi-tenant): missing collections warning (#13538)
Fixes https://github.com/payloadcms/payload/issues/13517

⚠️ **Need to merge https://github.com/payloadcms/payload/pull/13379
first**

Adds warning if collections are enabled but not found. This can happen
if you add the multi-tenant before other plugins that add the
collections you are attempting to add multi-tenancy to.
2025-08-21 18:01:19 +00:00
Jónas G. Sigurðsson
2bdd669fde feat: add icelandic translations (#13423)
### What?

Add Icelandic translations

### Why?

It hadn't been implemented yet

### How?

I added files, mimicking the existing pattern for translations and
translated all messages in the list
2025-08-21 13:24:20 -04:00
Patrik
96074530b1 fix: server edit view components don't receive document id prop (#13526)
### What?

Make the document `id` available to server-rendered admin components
that expect it—specifically `EditMenuItems` and
`BeforeDocumentControls`—so `props.id` matches the official docs.

### Why?

The docs show examples using `props.id`, but the runtime `serverProps`
and TS types didn’t include it. This led to `undefined` at render time.

### How?

- Add id to ServerProps and set it in renderDocumentSlots from
req.routeParams.id.

Fixes #13420
2025-08-21 13:23:51 -04:00
Jarrod Flesch
5cf215d9cb feat(plugin-multi-tenant): visible tenant field on documents (#13379)
The goal of this PR is to show the selected tenant on the document level
instead of using the global selector to sync the state to the document.


Should merge https://github.com/payloadcms/payload/pull/13316 before
this one.

### Video of what this PR implements

**Would love feedback!**


https://github.com/user-attachments/assets/93ca3d2c-d479-4555-ab38-b77a5a9955e8
2025-08-21 13:15:24 -04:00
Alessio Gravili
393b4a0929 fix(next): no client field found error when accessing version view in some configurations (#13339)
This PR fixes some incorrect field paths handling (=> should not pass
path and schema paths that contain index paths down to sub-fields
outside of the indexPath property) when building the version fields.

Fixes https://github.com/payloadcms/payload/issues/12376

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1210932060696925
2025-08-21 10:04:55 -04:00
Dan Ribbens
a94cd95b90 fix: uploads update unnecessarily resizing with sharp (#13528)
fixes https://github.com/payloadcms/payload/issues/13499
2025-08-21 09:24:21 -04:00
Patrik
a04bc9a3e7 fix(translations): stale version.versionCreatedOn key in translation (#13530)
### What?

Remove `versionCreatedOn` from translations.

### Why?

The key is no longer referenced anywhere in the admin/UI code.

Fixes #13188 


---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1211105332940662
2025-08-20 15:20:40 -04:00
Anders Semb Hermansen
36fd6e905a perf(storage-s3): stream files and abort s3 request from static handler (#13430)
### What?

Stream S3 object directly to response instead of creating a Buffer in
memory and wire up an abort controller to stop streaming if user aborts
download

### Why?

To avoid excessive memory usage and to abort s3 download if user has
aborted the request anyway.

### How?

In node environment the AWS S3 always returns a Readable. The
streamToBuffer method always required this, but the any type hided that
this was actually needed. Now there is an explicit type check, but this
should never trigger in a node server environment.

Wire up and abort controller to the request so that we tell the S3
object to also stop streaming further if the user aborts.

Fixes #10286
Maybe also helps on other issues with s3 and resource usage
2025-08-20 14:53:21 -04:00
Jacob Fletcher
c67ceca8e2 perf(ui): do not fetch doc permissions on autosave (#13477)
No need to re-fetch doc permissions during autosave. This will save us
from making two additional client-side requests on every autosave
interval, on top of the two existing requests needed to autosave and
refresh form state.

This _does_ mean that the UI will not fully reflect permissions again
until you fully save, or until you navigating back, but that has always
been the behavior anyway (until #13416). Maybe we can find another
solution for this in the future, or otherwise consider this to be
expected behavior.

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1211094073049052
2025-08-20 13:39:35 -04:00
Jacob Fletcher
f382c39dae fix: accept computed array and block rows from server form state (#13501)
If you have a beforeChange hook that manipulates arrays or blocks by
_adding rows_, the result of that hook will not be reflected in the UI
after save or autosave as you might expect.

For example, this hook that ensures at least one array row is populated:

```ts
{
  type: 'array',
  hooks: {
    beforeChange: [
      ({ value }) =>
        !value?.length
          ? [
              // this is an added/computed row if attempt to save with no rows
            ]
          : value,
    ],
  },
  // ...
}
```

When you save without any rows, this hook will have automatically
computed a row for you and saved it to the database. Form state will not
reflect this fact, however, until you refresh or navigate back.

This is for two reasons:
1. When merging server form state, we receive the new fields, but do not
receive the new rows. This is because the `acceptValues` flag only
applies to the `value` property of fields, but should also apply to the
`rows` property on `array` and `blocks` fields too.
2. When creating new form state on the server, the newly added rows are
not being flagged with `addedByServer`, and so never make it into form
state when it is merged in on the client. To do this we need to send the
previous form state to the server and set `renderAllFields` to false in
order receive this property as expected. Fixed by #13524.

Before:


https://github.com/user-attachments/assets/3ab07ef5-3afd-456f-a9a8-737909b75016

After:


https://github.com/user-attachments/assets/27ad1d83-9313-45a9-b44a-db1e64452a99

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1211094073049042
2025-08-20 13:39:25 -04:00
Said Akhrarov
fea6742ceb fix(plugin-form-builder): export radio field type (#11908)
<!--

Thank you for the PR! Please go through the checklist below and make
sure you've completed all the steps.

Please review the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository if you haven't already.

The following items will ensure that your PR is handled as smoothly as
possible:

- PR Title must follow conventional commits format. For example, `feat:
my new feature`, `fix(plugin-seo): my fix`.
- Minimal description explained as if explained to someone not
immediately familiar with the code.
- Provide before/after screenshots or code diffs if applicable.
- Link any related issues/discussions from GitHub or Discord.
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Fixes #

-->
### What?
[#11716](https://github.com/payloadcms/payload/pull/11716) introduced
the `RadioField` component. This PR exports the type for use by
end-users.

### Why?
To allow end-users to utilize the type as expected with
`plugin-form-builder`.

### How?
Adds the `RadioField` interface to the list of exported plugin types.

Fixes #11806
2025-08-20 18:27:59 +01:00
Sasha
aa90271a59 fix(db-postgres): camelCase point fields (#13519)
Fixes https://github.com/payloadcms/payload/issues/13394
2025-08-20 20:18:14 +03:00
Jacob Fletcher
5e433aa9c3 perf(ui): reduce number of field renders on submit (#13524)
Needed for #13501.

No need to re-render all fields during save, and especially autosave.
Fields are already rendered. We only need to render new fields that may
have been created by hooks, etc.

We can achieve this by sending previous form state and new data through
the request with `renderAllFields: false`. That way form state can be
built up from previous form state, while still accepting new data.

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1211094406108904
2025-08-20 12:39:48 -04:00
Gregor Billing
c7b9f0f563 fix(db-mongodb): disable join aggregations in DocumentDB compatibility mode (#13270)
### What?

The PR #12763 added significant improvements for third-party databases
that are compatible with the MongoDB API. While the original PR was
focused on Firestore, other databases like DocumentDB also benefit from
these compatibility features.

In particular, the aggregate JOIN strategy does not work on AWS
DocumentDB and thus needs to be disabled. The current PR aims to provide
this as a sensible default in the `compatibilityOptions` that are
provided by Payload out-of-the-box.

As a bonus, it also fixes a small typo from `compat(a)bility` to
`compat(i)bility`.

### Why?

Because our Payload instance, which is backed by AWS DocumentDB, crashes
upon trying to access any `join` field.

### How?

By adding the existing `useJoinAggregations` with value `false` to the
compatiblity layer. Individual developers can still choose to override
it in their own local config as needed.
2025-08-20 16:31:19 +00:00
Patrik
b3e48f8efa fix(ui): logout type error when user is null during locale switch (#13514)
### What?

Prevent a `TypeError: Cannot read properties of null (reading
'collection')` in the admin UI when switching locales by hardening
`AuthProvider.logOut`.

### Why?

During locale transitions, user can briefly be null. The existing code
used `user.collection` unguarded

### How?

- Use `userSlug` over `user.collection`.
- Always clear local auth in a `finally` block (`setNewUser(null)`,
`revokeTokenAndExpire()`), regardless of request outcome.

Fixes #13313 


---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1211093549155962
2025-08-20 11:02:09 -04:00
Bob Bass
f44e27691e fix: 'front-end' spelling typo in JSDocs for overrideAccess (#13515)
### What?

Repeated typo in jsdoc documentation has been fixed

### Why?
'front-end' was reading as 'fron-end' in several jsdoc comments
2025-08-20 07:25:40 -07:00
Boyan Bratvanov
a840fc944b docs: fix typo in custom views (#13522)
A very small fix.
2025-08-20 13:40:57 +01:00
German Jablonski
cf427e5519 fix: imports (part 2/2) (#13520)
Completes https://github.com/payloadcms/payload/pull/13513

That PR fixed it for the `admin` suite, but I had also encountered the
same issue in `live-preview`.

When searching for instances, I found others with the same pattern
within packages, which I took the opportunity to fix in case the same
error occurs in the future.
2025-08-20 08:08:55 -04:00
Jacob Fletcher
adb83b1e06 test: add array field helpers (#13493)
Adds various helpers to make it easier and more standard to manage array
fields within e2e tests. Retrofits existing tests to ensure consistent
interactions across the board, and also organizes existing blocks and
relationship field helpers in the same way.

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1211094073049046
2025-08-19 19:44:59 +00:00
Sasha
368cd901f8 fix(ui): replace deprecated document.execCommand('copy') API with navigator (#13431)
Replaces the deprecated API which might cause issues with the copy
button.

Also adds an E2E test for the copy button
2025-08-19 15:39:31 -04:00
Jarrod Flesch
406a09f4bf fix(ui): local image src changing when title changes (#13442)
When changing the title of a newly uploaded image, the image would
flicker because the `createObjectURL` was running and creating a new
local file url. This change allows `handleFileChange` to run and not
affect the url if the file being added is not a new file.

### Before


https://github.com/user-attachments/assets/9e21101e-c4cc-4fc3-b510-18f1a0d9fb3a



### After


https://github.com/user-attachments/assets/9f310e10-d29c-49a9-bd28-cb6da6c5651a
2025-08-19 15:39:03 -04:00
Patrik
4f6d0d8ed2 fix: select field component value prop type does not support array values (#13510)
### What?

Update `SelectFieldBaseClientProps` type so `value` accepts `string[]`
for `hasMany` selects

### Why?

Multi-selects currently error with “Type 'string[]' is not assignable to
type 'string'”.

### How?

- Change `value?: string` to `value?: string | string[]`
- Also adds additional multi select custom component to `admin` test
suite for testing

---------

Co-authored-by: Jarrod Flesch <jarrodmflesch@gmail.com>
2025-08-19 11:54:52 -07:00
Jarrod Flesch
9e7bb24ffb test: fix link imports (#13513)
Fixes issue in test suites that import the Link component from
next/link.
2025-08-19 14:51:11 -04:00
Jarrod Flesch
73ba4d1bb9 fix: unable to query versions on latest key (#13512)
Fixes https://github.com/payloadcms/payload/issues/13455

https://github.com/payloadcms/payload/pull/13297 Fixed a scoping issue,
but exposed a new issue where querying versioned documents by the
`latest` key would fail. This PR fixes the newly discoverable issue.
2025-08-19 11:42:02 -07:00
Patrik
332b2a9d3c fix(ui): double ? in gravatar url (#13511)
### What?

Ensure the Gravatar URL appends the query string only once.

### Why?

Previously `src` used `...?${query}` while `query` already began with
`?`, producing `??` and causing the avatar URL to be invalid in some
cases.

### How?

- Keep `query` as `?${params}` (from `URLSearchParams`).
- Change `src` from `https://www.gravatar.com/avatar/${hash}?${query}`
to `https://www.gravatar.com/avatar/${hash}${query}` so only one `?` is
present.

Fixes #13325
2025-08-19 11:03:53 -07:00
Sasha
92d459ec99 fix: avoid re-uploading the file unless changed (#13500)
Fixes https://github.com/payloadcms/payload/issues/13182

Before, the condition in
b714e6b151/packages/payload/src/uploads/generateFileData.ts#
was always passing. Now, with `shouldReupload` we properly check the
difference (whether the image was cropped or the focal point was
changed)
2025-08-19 17:50:50 +03:00
Jan Huenges
7699d02d7f fix(richtext-lexical): use thumbnail component for uploads (#12540)
### What?

Fix the broken thumbnail for non-images for uploads in the
richtext-lexical editor.

**Before:**

![before](https://github.com/user-attachments/assets/dbe5ffb7-9032-435b-8684-3c8bf53ae5bd)

**After:**

![after](https://github.com/user-attachments/assets/1c4af50e-2216-4ada-aff0-7a5e5559ac64)


### Why?

As described in #6867, the thumbnail in the richtext-lexical editor is
always trying to render an thumbnail image. This leads to a broken image
as soon as a non-image is added.

### How?

The fix was done by using the `<Thumbnail />` component from
`@payloadcms/ui`

Fixes #6867

---------

Co-authored-by: German Jablonski <43938777+GermanJablo@users.noreply.github.com>
2025-08-19 14:14:51 +00:00
Паламар Роман
b714e6b151 fix(templates): plugin template correct paths for exports (#13427)
When using plugin template , initial package.json settings is wrong.
They point to non-existing files in exports folder ( index.ts ,
index.js, index.d.ts ) , which results in broken package if published
(can't import your plugin from package)

Fixes #13426
2025-08-19 14:10:18 +01:00
chenxi-debugger
379ef87d84 docs(db-mongodb): note on indexing localized fields & per-locale growth (#13469)
Closes #13464

Adds a note to the Indexes docs for localized fields:
- Indexing a `localized: true` field creates one index per locale path
(e.g. `slug.en`, `slug.da-dk`), which can grow index count on MongoDB.
- Recommends defining explicit indexes via collection-level `indexes`
for only the locale paths you actually query.
- Includes a concrete example (index `slug.en` only).

Docs-only change.

---------

Co-authored-by: German Jablonski <43938777+GermanJablo@users.noreply.github.com>
2025-08-19 12:45:38 +00:00
Patrik
9f7d8c65d5 fix(ui): nested fields with admin.disableListColumn still appear as columns in list view (#13504)
### What?

This PR makes `filterFields` recurse into **fields with subfields**
(e.g., tabs, row, group, collapsible, array) so nested fields with
`admin.disableListColumn: true` (or hidden/disabled fields) are properly
excluded.

### Why?

Nested fields with `admin.disableListColumn: true` were still appearing
in the list view.

Example: a text field inside a `row` or `group` continued to show as a
column despite being marked `disableListColumn`.

### How?

- Call `filterFields` recursively for `tab.fields` and for any field
exposing a `fields` array.

Fixes #13496
2025-08-18 11:50:08 -07:00
Patrik
30ea8e1bac fix(ui): blocks field not respecting width styles in row layouts (#13502)
### What?

This PR applies `mergeFieldStyles` to the `BlocksField` component,
ensuring that custom admin styles such as `width` are correctly
respected when Blocks fields are placed inside row layouts.

### Why?

Previously, Blocks fields did not inherit or apply their `admin.width`
(or other merged field styles). For example, when placing two Blocks
fields side by side inside a row with `width: '50%'`, the widths were
ignored, causing layout issues.

### How?

- Imported and used `mergeFieldStyles` within `BlocksField`.
- Applied the merged styles to the root `<div>` via the `style` prop,
consistent with how other field components (like `TextField`) handle
styles.

Fixes #13498
2025-08-18 09:15:40 -07:00
German Jablonski
f9bbca8bfe docs: clarify pagination and improve cross-referencing (#13503)
Fixes #13417

Builds on #13471

---------

Co-authored-by: chenxi-debugger <chenxi.debugger@gmail.com>
2025-08-18 16:55:52 +01:00
id3er0
9d08f503ae fix(storage-s3): validate Content-Length before appending header (#13472)
## Description
Fixes "Parse Error: Invalid character in Content-Length" errors that
occur when S3-compatible storage providers (like MinIO) return undefined
or invalid ContentLength values.

## Changes
- Added validation before appending Content-Length header in
`staticHandler.ts`
- Only appends Content-Length when value is present and numeric
- Prevents HTTP specification violations from undefined/invalid values

## Code Changes
```typescript
const contentLength = String(object.ContentLength);
if (contentLength && !isNaN(Number(contentLength))) {
  headers.append('Content-Length', contentLength);
}
```

## Issue
- Resolves MinIO compatibility issues where undefined ContentLength
causes client parse errors
- Maintains backward compatibility when ContentLength is valid

## Testing
- [x] Tested with MinIO provider returning undefined ContentLength
- [x] Verified valid Content-Length values are still properly set
- [x] Confirmed no regression in existing S3 functionality

### Type of Change
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)

### Checklist
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] My changes generate no new warnings
- [x] Any dependent changes have been merged and published
```
2025-08-15 19:50:27 +00:00
Patrik
a7ed88b5fa feat(plugin-import-export): use groupBy as SortBy when present and sort is unset (#13491)
### What?

When exporting, if no `sort` parameter is set but a `groupBy` parameter
is present in the list-view query, the export will treat `groupBy` as
the SortBy field and default to ascending order.
Additionally, the SortOrder field in the export UI is now hidden when no
sort is present, reducing visual noise and preventing irrelevant order
selection.

### Why?

Previously, exports ignored `groupBy` entirely when no sort was set,
leading to unsorted output even if the list view was grouped. Also,
SortOrder was always shown, even when no sort field was selected, which
could be confusing. These changes ensure exports reflect the list view’s
grouping and keep the UI focused.

### How?

- Check for `groupBy` in the query only when `sort` is unset.
- If found, set SortBy to `groupBy` and SortOrder to ascending.
- Hide the SortOrder field when `sort` is not set.
- Leave sorting unset if neither `sort` nor `groupBy` are present.
2025-08-15 11:56:58 -07:00
Sasha
ec5b673aca fix: copy to locale with localized fields inside tabs (#13456)
Fixes https://github.com/payloadcms/payload/issues/13374
2025-08-15 14:55:12 -04:00
Sasha
3dd142c637 fix(ui): cannot replace the file if the user does not have delete access (#13484)
Currently, if you don't have delete access to the document, the UI
doesn't allow you to replace the file, which isn't expected. This is
also a UI only restriction, and the API allows you do this fine.

This PR makes so the "remove file" button renders even if you don't have
delete access, while still ensures you have update access.

---------

Co-authored-by: Paul Popus <paul@payloadcms.com>
2025-08-15 14:52:45 -04:00
Jarrod Flesch
1909063e42 fix: omit trashed documents from appearing in folder results (#13492)
### Issue

The folders join field query was returning trashed documents. 

### Fix
Adds a constraint to trash enabled collections, which prevents trashed
documents from being surfaced in folder views.
2025-08-15 14:45:36 -04:00
Anatoly Kopyl
64f4b0aff3 fix: update docker base image in templates (#13020)
<!--

Thank you for the PR! Please go through the checklist below and make
sure you've completed all the steps.

Please review the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository if you haven't already.

The following items will ensure that your PR is handled as smoothly as
possible:

- PR Title must follow conventional commits format. For example, `feat:
my new feature`, `fix(plugin-seo): my fix`.
- Minimal description explained as if explained to someone not
immediately familiar with the code.
- Provide before/after screenshots or code diffs if applicable.
- Link any related issues/discussions from GitHub or Discord.
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Fixes #

-->

Went ahead and bumped the base from `node:22.12.0-alpine` to
`node:22.17.0-alpine` across all templates to fix #13019.
2025-08-15 18:49:02 +01:00
Said Akhrarov
c8ef92449b fix(next): add missing translations to version view
<!--

Thank you for the PR! Please go through the checklist below and make
sure you've completed all the steps.

Please review the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository if you haven't already.

The following items will ensure that your PR is handled as smoothly as
possible:

- PR Title must follow conventional commits format. For example, `feat:
my new feature`, `fix(plugin-seo): my fix`.
- Minimal description explained as if explained to someone not
immediately familiar with the code.
- Provide before/after screenshots or code diffs if applicable.
- Link any related issues/discussions from GitHub or Discord.
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Fixes #

-->
### What?
This PR translates the block and item label in the version view, as well
as the version label in the step nav.

### Why?
To appropriately translate labels in the version views.

### How?
By using the TFunction from useTranslation as well as existing
translation keys.

Fixes #13193
Fixes #13194
2025-08-15 18:43:01 +01:00
Patrik
b7243b1413 fix(ui): bulk upload action bar buttons wrapping (#13486)
### What?

Added `white-space: nowrap` to the `.bulk-upload--actions-bar__buttons`
class to ensure button labels remain on a single line.

### Why?

In the bulk upload action bar, buttons containing multi-word labels were
wrapping to two lines, causing them to expand vertically and misalign
with other controls.

### How?

Applied `white-space: nowrap` to `.bulk-upload--actions-bar__buttons` so
all button labels stay on one line, maintaining consistent height and
alignment.

#### Before
<img width="1469" height="525" alt="Screenshot 2025-08-15 at 9 20 07 AM"
src="https://github.com/user-attachments/assets/aecc65ae-7b2f-43ba-96c8-1143fcee7f88"
/>

#### After
<img width="1474" height="513" alt="Screenshot 2025-08-15 at 9 19 55 AM"
src="https://github.com/user-attachments/assets/438c6ee1-b966-4966-8686-37ba4619a25c"
/>
2025-08-15 11:49:08 -04:00
Elliot DeNolf
f5d77662b0 templates: bump for v3.52.0 (#13488)
🤖 Automated bump of templates for v3.52.0

Triggered by user: @denolfe

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-08-15 11:28:20 -04:00
Patrik
efdf00200a feat(plugin-import-export): adds sort order control and sync with sort-by field (#13478)
### What?

This PR adds a dedicated `sortOrder` select field (Ascending /
Descending) to the import-export plugin, alongside updates to the
existing `SortBy` component. The new field and component logic keep the
sort field (`sort`) in sync with the selected sort direction.

### Why?

Previously, descending sorting did not work. While the `SortBy` field
could read the list view’s `query.sort` param, if the value contained a
leading dash (e.g. `-title`), it would not be handled correctly. Only
ascending sorts such as `sort=title` worked, and the preview table would
not reflect a descending order.

### How?

- Added a new `sortOrder` select field to the export options schema.
- Implemented a `SortOrder` custom component using ReactSelect:
- On new exports, reads `query.sort` from the list view and sets both
`sortOrder` and `sort` (combined value with or without a leading dash).
  - Handles external changes to `sort` that include a leading dash.
- Updated `SortBy`:
- No longer writes to `sort` during initial hydration—`SortOrder` owns
initial value setting.
- On user field changes, writes the combined value using the current
`sortOrder`.
2025-08-15 11:27:54 -04:00
Elliot DeNolf
217606ac20 chore(release): v3.52.0 [skip ci] 2025-08-15 10:42:32 -04:00
jacobsfletch
0b60bf2eff fix(ui): significantly more predictable autosave form state (#13460) 2025-08-14 19:36:02 -04:00
Sasha
46699ec314 test: skip cookies filter for internal URLs in getExternalFile (#13476)
Test for https://github.com/payloadcms/payload/pull/13475
2025-08-14 13:17:17 -04:00
Sean Zubrickas
cdd90f91c8 docs: updates image paths to new screenshots (#13461)
Updates images paths for the following screenshots:

- auth-overview.jpg
- autosave-drafts.jpg
- autosave-v3.jpg
- uploads-overview.jpg
- versions-v3.jpg
2025-08-14 13:15:35 -04:00
Sasha
8d4e7f5f30 fix: filter payload- cookies in getExternalFile only if the URL is external (#13475)
Fixes a regression from
https://github.com/payloadcms/payload/pull/13215. Fixes the issue when
`skipSafeFetch: true` is set
https://github.com/payloadcms/payload/issues/13146#issuecomment-3066858749

This PR makes it so we still send the cookies if we do `fetch` to our
server, but filter them when we `fetch` to an external server (usually a
third party storage, for which we don't want to expose those cookies)
2025-08-14 14:51:24 +00:00
jacobsfletch
b426052cab test: fix import-export plugin int (#13474)
CI is blocked because of failing int tests within the import/export
plugin suite after #13380.
2025-08-14 08:54:13 -04:00
Sasha
047519f47f fix(db-postgres): ensure index names are not too long (#13428)
Fixes https://github.com/payloadcms/payload/issues/13196
2025-08-14 02:44:56 +03:00
Dan Ribbens
c1c68fbb55 feat(plugin-import-export): adds limit and page fields to export options (#13380)
### What:
This PR adds `limit` and `page` fields to the export options, allowing
users to control the number of documents exported and the page from
which to start the export. It also enforces that limit must be a
positive multiple of 100.

### Why:
This feature is needed to provide pagination support for large exports,
enabling users to export manageable chunks of data rather than the
entire dataset at once. Enforcing multiples-of-100 for `limit` ensures
consistent chunking behavior and prevents unexpected export issues.

### How:
- The `limit` field determines the maximum number of documents to export
and **must be a positive multiple of 100**.
- The `page` field defines the starting page of the export and is
displayed only when a `limit` is specified.
- If `limit` is cleared, the `page` resets to 1 to maintain consistency.
- Export logic was adjusted to respect the `limit` and `page` values
when fetching documents.

---------

Co-authored-by: Patrik Kozak <35232443+PatrikKozak@users.noreply.github.com>
2025-08-13 14:01:45 -07:00
Patrik
3e65111bc1 fix(plugin-import-export): csv export & preview showing full documents for hasMany monomorphic relationships instead of just ID (#13465)
### What?

Fixes an issue where CSV exports and the preview table displayed all
fields of documents in hasMany monomorphic relationships instead of only
their IDs.

### Why?

This caused cluttered output and inconsistent CSV formats, since only
IDs should be exported for hasMany monomorphic relationships.

### How?

Added explicit `toCSV` handling for all relationship types in
`getCustomFieldFunctions`, updated `flattenObject` to delegate to these
handlers, and adjusted `getFlattenedFieldKeys` to generate the correct
headers.
2025-08-13 13:54:32 -07:00
Elliot DeNolf
0e8a6c0162 templates: bump for v3.51.0 (#13457)
🤖 Automated bump of templates for v3.51.0

Triggered by user: @denolfe

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-08-13 09:47:04 -04:00
Elliot DeNolf
0688050eb6 chore(release): v3.51.0 [skip ci] 2025-08-13 09:20:13 -04:00
Jessica Rynkar
5a99d8c5f4 fix: upload with no filename gives vague error (#13414)
### What?
Adds validation to the file upload field to ensure a filename is
provided. If the filename is missing, a clear error message is shown to
the user instead of a general error.

### Why?
Currently, attempting to upload a file without a filename results in a
generic error message: `Something went wrong.` This makes it unclear for
users to understand what the issue is.

### How?
The upload field validation has been updated to explicitly check for a
missing filename. If the filename is undefined or null, the error
message `A filename is required` is now shown.

Fixes #13410
2025-08-13 12:26:59 +01:00
Jessica Rynkar
35ca98e70e fix: version view breaks when tab field has function for label (#13415)
### What?

Fixes an issue where using a function as the `label` for a `tabs` field
causes the versions UI to break.

### Why?

The versions UI was not properly resolving function labels on `tab`
fields, leading to a crash when trying to render them.

### How?

Tweaked the logic so that if the label is a function, it gets called
before rendering.

Fixes #13375
2025-08-13 09:02:43 +01:00
385 changed files with 4527 additions and 1607 deletions

2
.gitignore vendored
View File

@@ -331,5 +331,7 @@ test/databaseAdapter.js
test/.localstack
test/google-cloud-storage
test/azurestoragedata/
/media-without-delete-access
licenses.csv

View File

@@ -33,7 +33,7 @@ export const Users: CollectionConfig = {
}
```
![Authentication Admin Panel functionality](https://payloadcms.com/images/docs/auth-admin.jpg)
![Authentication Admin Panel functionality](https://payloadcms.com/images/docs/auth-overview.jpg)
_Admin Panel screenshot depicting an Admins Collection with Auth enabled_
## Config Options

View File

@@ -141,7 +141,7 @@ The following options are available:
| `livePreview` | Enable real-time editing for instant visual feedback of your front-end application. [More details](../live-preview/overview). |
| `components` | Swap in your own React components to be used within this Collection. [More details](#custom-components). |
| `listSearchableFields` | Specify which fields should be searched in the List search view. [More details](#list-searchable-fields). |
| `pagination` | Set pagination-specific options for this Collection. [More details](#pagination). |
| `pagination` | Set pagination-specific options for this Collection in the List View. [More details](#pagination). |
| `baseFilter` | Defines a default base filter which will be applied to the List View (along with any other filters applied by the user) and internal links in Lexical Editor, |
<Banner type="warning">

View File

@@ -158,7 +158,7 @@ export function MyCustomView(props: AdminViewServerProps) {
<Banner type="success">
**Tip:** For consistent layout and navigation, you may want to wrap your
Custom View with one of the built-in [Template](./overview#templates).
Custom View with one of the built-in [Templates](./overview#templates).
</Banner>
### View Templates

View File

@@ -293,7 +293,6 @@ Here's an example of a custom `editMenuItems` component:
```tsx
import React from 'react'
import { PopupList } from '@payloadcms/ui'
import type { EditMenuItemsServerProps } from 'payload'
@@ -301,12 +300,12 @@ export const EditMenuItems = async (props: EditMenuItemsServerProps) => {
const href = `/custom-action?id=${props.id}`
return (
<PopupList.ButtonGroup>
<PopupList.Button href={href}>Custom Edit Menu Item</PopupList.Button>
<PopupList.Button href={href}>
<>
<a href={href}>Custom Edit Menu Item</a>
<a href={href}>
Another Custom Edit Menu Item - add as many as you need!
</PopupList.Button>
</PopupList.ButtonGroup>
</a>
</>
)
}
```

View File

@@ -63,3 +63,22 @@ export const MyCollection: CollectionConfig = {
],
}
```
## Localized fields and MongoDB indexes
When you set `index: true` or `unique: true` on a localized field, MongoDB creates one index **per locale path** (e.g., `slug.en`, `slug.da-dk`, etc.). With many locales and indexed fields, this can quickly approach MongoDB's per-collection index limit.
If you know you'll query specifically by a locale, index only those locale paths using the collection-level `indexes` option instead of setting `index: true` on the localized field. This approach gives you more control and helps avoid unnecessary indexes.
```ts
import type { CollectionConfig } from 'payload'
export const Pages: CollectionConfig = {
fields: [{ name: 'slug', type: 'text', localized: true }],
indexes: [
// Index English slug only (rather than all locales)
{ fields: ['slug.en'] },
// You could also make it unique:
// { fields: ['slug.en'], unique: true },
],
}
```

View File

@@ -60,21 +60,21 @@ You can access Mongoose models as follows:
## Using other MongoDB implementations
You can import the `compatabilityOptions` object to get the recommended settings for other MongoDB implementations. Since these databases aren't officially supported by payload, you may still encounter issues even with these settings (please create an issue or PR if you believe these options should be updated):
You can import the `compatibilityOptions` object to get the recommended settings for other MongoDB implementations. Since these databases aren't officially supported by payload, you may still encounter issues even with these settings (please create an issue or PR if you believe these options should be updated):
```ts
import { mongooseAdapter, compatabilityOptions } from '@payloadcms/db-mongodb'
import { mongooseAdapter, compatibilityOptions } from '@payloadcms/db-mongodb'
export default buildConfig({
db: mongooseAdapter({
url: process.env.DATABASE_URI,
// For example, if you're using firestore:
...compatabilityOptions.firestore,
...compatibilityOptions.firestore,
}),
})
```
We export compatability options for [DocumentDB](https://aws.amazon.com/documentdb/), [Azure Cosmos DB](https://azure.microsoft.com/en-us/products/cosmos-db) and [Firestore](https://cloud.google.com/firestore/mongodb-compatibility/docs/overview). Known limitations:
We export compatibility options for [DocumentDB](https://aws.amazon.com/documentdb/), [Azure Cosmos DB](https://azure.microsoft.com/en-us/products/cosmos-db) and [Firestore](https://cloud.google.com/firestore/mongodb-compatibility/docs/overview). Known limitations:
- Azure Cosmos DB does not support transactions that update two or more documents in different collections, which is a common case when using Payload (via hooks).
- Azure Cosmos DB the root config property `indexSortableFields` must be set to `true`.

View File

@@ -162,6 +162,11 @@ const result = await payload.find({
})
```
<Banner type="info">
`pagination`, `page`, and `limit` are three related properties [documented
here](/docs/queries/pagination).
</Banner>
### Find by ID#collection-find-by-id
```js

View File

@@ -207,7 +207,7 @@ Everything mentioned above applies to local development as well, but there are a
### Enable Turbopack
<Banner type="warning">
**Note:** In the future this will be the default. Use as your own risk.
**Note:** In the future this will be the default. Use at your own risk.
</Banner>
Add `--turbo` to your dev script to significantly speed up your local development server start time.

View File

@@ -85,8 +85,8 @@ type MultiTenantPluginConfig<ConfigTypes = unknown> = {
*/
tenantFieldOverrides?: CollectionTenantFieldConfigOverrides
/**
* Set to `false` if you want to manually apply the baseListFilter
* Set to `false` if you want to manually apply the baseFilter
* Set to `false` if you want to manually apply
* the baseFilter
*
* @default true
*/

View File

@@ -13,8 +13,8 @@ keywords: uploads, images, media, overview, documentation, Content Management Sy
</Banner>
<LightDarkImage
srcLight="https://payloadcms.com/images/docs/upload-admin.jpg"
srcDark="https://payloadcms.com/images/docs/upload-admin.jpg"
srcLight="https://payloadcms.com/images/docs/uploads-overview.jpg"
srcDark="https://payloadcms.com/images/docs/uploads-overview.jpg"
alt="Shows an Upload enabled collection in the Payload Admin Panel"
caption="Admin Panel screenshot depicting a Media Collection with Upload enabled"
/>

View File

@@ -12,7 +12,7 @@ Extending on Payload's [Draft](/docs/versions/drafts) functionality, you can con
Autosave relies on Versions and Drafts being enabled in order to function.
</Banner>
![Autosave Enabled](/images/docs/autosave-enabled.png)
![Autosave Enabled](/images/docs/autosave-v3.jpg)
_If Autosave is enabled, drafts will be created automatically as the document is modified and the Admin UI adds an indicator describing when the document was last saved to the top right of the sidebar._
## Options

View File

@@ -14,7 +14,7 @@ Payload's Draft functionality builds on top of the Versions functionality to all
By enabling Versions with Drafts, your collections and globals can maintain _newer_, and _unpublished_ versions of your documents. It's perfect for cases where you might want to work on a document, update it and save your progress, but not necessarily make it publicly published right away. Drafts are extremely helpful when building preview implementations.
![Drafts Enabled](/images/docs/drafts-enabled.png)
![Drafts Enabled](/images/docs/autosave-drafts.jpg)
_If Drafts are enabled, the typical Save button is replaced with new actions which allow you to either save a draft, or publish your changes._
## Options

View File

@@ -13,7 +13,7 @@ keywords: version history, revisions, audit log, draft, publish, restore, autosa
When enabled, Payload will automatically scaffold a new Collection in your database to store versions of your document(s) over time, and the Admin UI will be extended with additional views that allow you to browse document versions, view diffs in order to see exactly what has changed in your documents (and when they changed), and restore documents back to prior versions easily.
![Versions](/images/docs/versions.png)
![Versions](/images/docs/versions-v3.jpg)
_Comparing an old version to a newer version of a document_
**With Versions, you can:**

View File

@@ -1,6 +1,6 @@
{
"name": "payload-monorepo",
"version": "3.50.0",
"version": "3.53.0",
"private": true,
"type": "module",
"workspaces": [

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/admin-bar",
"version": "3.50.0",
"version": "3.53.0",
"description": "An admin bar for React apps using Payload",
"homepage": "https://payloadcms.com",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "create-payload-app",
"version": "3.50.0",
"version": "3.53.0",
"homepage": "https://payloadcms.com",
"repository": {
"type": "git",

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/db-mongodb",
"version": "3.50.0",
"version": "3.53.0",
"description": "The officially supported MongoDB database adapter for Payload",
"homepage": "https://payloadcms.com",
"repository": {

View File

@@ -331,7 +331,7 @@ export function mongooseAdapter({
}
}
export { compatabilityOptions } from './utilities/compatabilityOptions.js'
export { compatibilityOptions } from './utilities/compatibilityOptions.js'
/**
* Attempt to find migrations directory.

View File

@@ -50,18 +50,12 @@ export const updateOne: UpdateOne = async function updateOne(
let result
let updateData: UpdateQuery<any> = data
const $inc: Record<string, number> = {}
const $push: Record<string, { $each: any[] } | any> = {}
transform({ $inc, $push, adapter: this, data, fields, operation: 'write' })
let updateData: UpdateQuery<any> = data
transform({ $inc, adapter: this, data, fields, operation: 'write' })
if (Object.keys($inc).length) {
updateData = { $inc, $set: updateData }
}
if (Object.keys($push).length) {
updateData = { $push, $set: updateData }
}
try {
if (returning === false) {

View File

@@ -2,9 +2,9 @@ import type { Args } from '../index.js'
/**
* Each key is a mongo-compatible database and the value
* is the recommended `mongooseAdapter` settings for compatability.
* is the recommended `mongooseAdapter` settings for compatibility.
*/
export const compatabilityOptions = {
export const compatibilityOptions = {
cosmosdb: {
transactionOptions: false,
useJoinAggregations: false,
@@ -12,6 +12,7 @@ export const compatabilityOptions = {
},
documentdb: {
disableIndexHints: true,
useJoinAggregations: false,
},
firestore: {
disableIndexHints: true,

View File

@@ -209,7 +209,6 @@ const sanitizeDate = ({
type Args = {
$inc?: Record<string, number>
$push?: Record<string, { $each: any[] } | any>
/** instance of the adapter */
adapter: MongooseAdapter
/** data to transform, can be an array of documents or a single document */
@@ -399,7 +398,6 @@ const stripFields = ({
export const transform = ({
$inc,
$push,
adapter,
data,
fields,
@@ -414,16 +412,7 @@ export const transform = ({
if (Array.isArray(data)) {
for (const item of data) {
transform({
$inc,
$push,
adapter,
data: item,
fields,
globalSlug,
operation,
validateRelationships,
})
transform({ $inc, adapter, data: item, fields, globalSlug, operation, validateRelationships })
}
return
}
@@ -481,26 +470,6 @@ export const transform = ({
}
}
if (
$push &&
field.type === 'array' &&
operation === 'write' &&
field.name in ref &&
ref[field.name]
) {
const value = ref[field.name]
if (value && typeof value === 'object' && '$push' in value) {
const push = value.$push
if (Array.isArray(push)) {
$push[`${parentPath}${field.name}`] = { $each: push }
} else if (typeof push === 'object') {
$push[`${parentPath}${field.name}`] = push
}
delete ref[field.name]
}
}
if (field.type === 'date' && operation === 'read' && field.name in ref && ref[field.name]) {
if (config.localization && fieldShouldBeLocalized({ field, parentIsLocalized })) {
const fieldRef = ref[field.name] as Record<string, unknown>

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/db-postgres",
"version": "3.50.0",
"version": "3.53.0",
"description": "The officially supported Postgres database adapter for Payload",
"homepage": "https://payloadcms.com",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/db-sqlite",
"version": "3.50.0",
"version": "3.53.0",
"description": "The officially supported SQLite database adapter for Payload",
"homepage": "https://payloadcms.com",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/db-vercel-postgres",
"version": "3.50.0",
"version": "3.53.0",
"description": "Vercel Postgres adapter for Payload",
"homepage": "https://payloadcms.com",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/drizzle",
"version": "3.50.0",
"version": "3.53.0",
"description": "A library of shared functions used by different payload database adapters",
"homepage": "https://payloadcms.com",
"repository": {

View File

@@ -791,9 +791,14 @@ export const traverseFields = ({
} else {
shouldSelect = true
}
const tableName = fieldShouldBeLocalized({ field, parentIsLocalized })
? `${currentTableName}${adapter.localesSuffix}`
: currentTableName
if (shouldSelect) {
args.extras[name] = sql.raw(`ST_AsGeoJSON(${toSnakeCase(name)})::jsonb`).as(name)
args.extras[name] = sql
.raw(`ST_AsGeoJSON("${adapter.tables[tableName][name].name}")::jsonb`)
.as(name)
}
break
}

View File

@@ -71,7 +71,6 @@ export const transformArray = ({
data.forEach((arrayRow, i) => {
const newRow: ArrayRowToInsert = {
arrays: {},
arraysToPush: {},
locales: {},
row: {
_order: i + 1,
@@ -105,7 +104,6 @@ export const transformArray = ({
traverseFields({
adapter,
arrays: newRow.arrays,
arraysToPush: newRow.arraysToPush,
baseTableName,
blocks,
blocksToDelete,

View File

@@ -78,7 +78,6 @@ export const transformBlocks = ({
const newRow: BlockRowToInsert = {
arrays: {},
arraysToPush: {},
locales: {},
row: {
_order: i + 1,
@@ -117,7 +116,6 @@ export const transformBlocks = ({
traverseFields({
adapter,
arrays: newRow.arrays,
arraysToPush: newRow.arraysToPush,
baseTableName,
blocks,
blocksToDelete,

View File

@@ -27,7 +27,6 @@ export const transformForWrite = ({
// Split out the incoming data into rows to insert / delete
const rowToInsert: RowToInsert = {
arrays: {},
arraysToPush: {},
blocks: {},
blocksToDelete: new Set(),
locales: {},
@@ -46,7 +45,6 @@ export const transformForWrite = ({
traverseFields({
adapter,
arrays: rowToInsert.arrays,
arraysToPush: rowToInsert.arraysToPush,
baseTableName: tableName,
blocks: rowToInsert.blocks,
blocksToDelete: rowToInsert.blocksToDelete,

View File

@@ -4,7 +4,13 @@ import { fieldIsVirtual, fieldShouldBeLocalized } from 'payload/shared'
import toSnakeCase from 'to-snake-case'
import type { DrizzleAdapter } from '../../types.js'
import type { NumberToDelete, RelationshipToDelete, RowToInsert, TextToDelete } from './types.js'
import type {
ArrayRowToInsert,
BlockRowToInsert,
NumberToDelete,
RelationshipToDelete,
TextToDelete,
} from './types.js'
import { isArrayOfRows } from '../../utilities/isArrayOfRows.js'
import { resolveBlockTableName } from '../../utilities/validateExistingBlockIsIdentical.js'
@@ -17,20 +23,16 @@ import { transformTexts } from './texts.js'
type Args = {
adapter: DrizzleAdapter
/**
* This will delete the array table and then re-insert all the new array rows.
*/
arrays: RowToInsert['arrays']
/**
* Array rows to push to the existing array. This will simply create
* a new row in the array table.
*/
arraysToPush: RowToInsert['arraysToPush']
arrays: {
[tableName: string]: ArrayRowToInsert[]
}
/**
* This is the name of the base table
*/
baseTableName: string
blocks: RowToInsert['blocks']
blocks: {
[blockType: string]: BlockRowToInsert[]
}
blocksToDelete: Set<string>
/**
* A snake-case field prefix, representing prior fields
@@ -80,7 +82,6 @@ type Args = {
export const traverseFields = ({
adapter,
arrays,
arraysToPush,
baseTableName,
blocks,
blocksToDelete,
@@ -128,6 +129,10 @@ export const traverseFields = ({
if (field.type === 'array') {
const arrayTableName = adapter.tableNameMap.get(`${parentTableName}_${columnName}`)
if (!arrays[arrayTableName]) {
arrays[arrayTableName] = []
}
if (isLocalized) {
if (typeof data[field.name] === 'object' && data[field.name] !== null) {
Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {
@@ -152,33 +157,19 @@ export const traverseFields = ({
textsToDelete,
withinArrayOrBlockLocale: localeKey,
})
if (!arrays[arrayTableName]) {
arrays[arrayTableName] = []
}
arrays[arrayTableName] = arrays[arrayTableName].concat(newRows)
}
})
}
} else {
let value = data[field.name]
let push = false
if (
// TODO do this for localized as well in DRY way
typeof value === 'object' &&
'$push' in value
) {
value = Array.isArray(value.$push) ? value.$push : [value.$push]
push = true
}
const newRows = transformArray({
adapter,
arrayTableName,
baseTableName,
blocks,
blocksToDelete,
data: value,
data: data[field.name],
field,
numbers,
numbersToDelete,
@@ -192,17 +183,7 @@ export const traverseFields = ({
withinArrayOrBlockLocale,
})
if (push) {
if (!arraysToPush[arrayTableName]) {
arraysToPush[arrayTableName] = []
}
arraysToPush[arrayTableName] = arraysToPush[arrayTableName].concat(newRows)
} else {
if (!arrays[arrayTableName]) {
arrays[arrayTableName] = []
}
arrays[arrayTableName] = arrays[arrayTableName].concat(newRows)
}
arrays[arrayTableName] = arrays[arrayTableName].concat(newRows)
}
return
@@ -283,7 +264,6 @@ export const traverseFields = ({
traverseFields({
adapter,
arrays,
arraysToPush,
baseTableName,
blocks,
blocksToDelete,
@@ -318,7 +298,6 @@ export const traverseFields = ({
traverseFields({
adapter,
arrays,
arraysToPush,
baseTableName,
blocks,
blocksToDelete,

View File

@@ -2,9 +2,6 @@ export type ArrayRowToInsert = {
arrays: {
[tableName: string]: ArrayRowToInsert[]
}
arraysToPush: {
[tableName: string]: ArrayRowToInsert[]
}
locales: {
[locale: string]: Record<string, unknown>
}
@@ -15,9 +12,6 @@ export type BlockRowToInsert = {
arrays: {
[tableName: string]: ArrayRowToInsert[]
}
arraysToPush: {
[tableName: string]: ArrayRowToInsert[]
}
locales: {
[locale: string]: Record<string, unknown>
}
@@ -43,9 +37,6 @@ export type RowToInsert = {
arrays: {
[tableName: string]: ArrayRowToInsert[]
}
arraysToPush: {
[tableName: string]: ArrayRowToInsert[]
}
blocks: {
[tableName: string]: BlockRowToInsert[]
}

View File

@@ -13,13 +13,9 @@ export const updateJobs: UpdateJobs = async function updateMany(
this: DrizzleAdapter,
{ id, data, limit: limitArg, req, returning, sort: sortArg, where: whereArg },
) {
if (
!(data?.log as object[])?.length &&
!(data.log && typeof data.log === 'object' && '$push' in data.log)
) {
if (!(data?.log as object[])?.length) {
delete data.log
}
const whereToUse: Where = id ? { id: { equals: id } } : whereArg
const limit = id ? 1 : limitArg

View File

@@ -44,7 +44,7 @@ export const upsertRow = async <T extends Record<string, unknown> | TypeWithID>(
}: Args): Promise<T> => {
let insertedRow: Record<string, unknown> = { id }
if (id && shouldUseOptimizedUpsertRow({ data, fields })) {
const { arraysToPush, row } = transformForWrite({
const { row } = transformForWrite({
adapter,
data,
enableAtomicWrites: true,
@@ -54,27 +54,11 @@ export const upsertRow = async <T extends Record<string, unknown> | TypeWithID>(
const drizzle = db as LibSQLDatabase
// First, handle $push arrays
if (arraysToPush && Object.keys(arraysToPush)?.length) {
await insertArrays({
adapter,
arrays: [arraysToPush],
db,
parentRows: [insertedRow],
uuidMap: {},
})
}
// Then, handle regular row update
if (ignoreResult) {
if (row && Object.keys(row).length) {
await drizzle
.update(adapter.tables[tableName])
.set(row)
.where(eq(adapter.tables[tableName].id, id))
}
await drizzle
.update(adapter.tables[tableName])
.set(row)
.where(eq(adapter.tables[tableName].id, id))
return ignoreResult === 'idOnly' ? ({ id } as T) : null
}
@@ -90,22 +74,6 @@ export const upsertRow = async <T extends Record<string, unknown> | TypeWithID>(
const findManyKeysLength = Object.keys(findManyArgs).length
const hasOnlyColumns = Object.keys(findManyArgs.columns || {}).length > 0
if (!row || !Object.keys(row).length) {
// Nothing to update => just fetch current row and return
findManyArgs.where = eq(adapter.tables[tableName].id, insertedRow.id)
const doc = await db.query[tableName].findFirst(findManyArgs)
return transform<T>({
adapter,
config: adapter.payload.config,
data: doc,
fields,
joinQuery: false,
tableName,
})
}
if (findManyKeysLength === 0 || hasOnlyColumns) {
// Optimization - No need for joins => can simply use returning(). This is optimal for very simple collections
// without complex fields that live in separate tables like blocks, arrays, relationships, etc.
@@ -461,9 +429,9 @@ export const upsertRow = async <T extends Record<string, unknown> | TypeWithID>(
await insertArrays({
adapter,
arrays: [rowToInsert.arrays, rowToInsert.arraysToPush],
arrays: [rowToInsert.arrays],
db,
parentRows: [insertedRow, insertedRow],
parentRows: [insertedRow],
uuidMap: arraysBlocksUUIDMap,
})

View File

@@ -32,9 +32,6 @@ export const insertArrays = async ({
const rowsByTable: RowsByTable = {}
arrays.forEach((arraysByTable, parentRowIndex) => {
if (!arraysByTable || Object.keys(arraysByTable).length === 0) {
return
}
Object.entries(arraysByTable).forEach(([tableName, arrayRows]) => {
// If the table doesn't exist in map, initialize it
if (!rowsByTable[tableName]) {

View File

@@ -20,6 +20,7 @@ export const shouldUseOptimizedUpsertRow = ({
}
if (
field.type === 'array' ||
field.type === 'blocks' ||
((field.type === 'text' ||
field.type === 'relationship' ||
@@ -34,17 +35,6 @@ export const shouldUseOptimizedUpsertRow = ({
return false
}
if (field.type === 'array') {
if (typeof value === 'object' && '$push' in value && value.$push) {
return shouldUseOptimizedUpsertRow({
// Only check first row - this function cares about field definitions. Each array row will have the same field definitions.
data: Array.isArray(value.$push) ? value.$push?.[0] : value.$push,
fields: field.flattenedFields,
})
}
return false
}
if (
(field.type === 'group' || field.type === 'tab') &&
value &&

View File

@@ -9,7 +9,12 @@ export const buildIndexName = ({
name: string
number?: number
}): string => {
const indexName = `${name}${number ? `_${number}` : ''}_idx`
let indexName = `${name}${number ? `_${number}` : ''}_idx`
if (indexName.length > 60) {
const suffix = `${number ? `_${number}` : ''}_idx`
indexName = `${name.slice(0, 60 - suffix.length)}${suffix}`
}
if (!adapter.indexes.has(indexName)) {
adapter.indexes.add(indexName)

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/email-nodemailer",
"version": "3.50.0",
"version": "3.53.0",
"description": "Payload Nodemailer Email Adapter",
"homepage": "https://payloadcms.com",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/email-resend",
"version": "3.50.0",
"version": "3.53.0",
"description": "Payload Resend Email Adapter",
"homepage": "https://payloadcms.com",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/graphql",
"version": "3.50.0",
"version": "3.53.0",
"homepage": "https://payloadcms.com",
"repository": {
"type": "git",

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/live-preview-react",
"version": "3.50.0",
"version": "3.53.0",
"description": "The official React SDK for Payload Live Preview",
"homepage": "https://payloadcms.com",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/live-preview-vue",
"version": "3.50.0",
"version": "3.53.0",
"description": "The official Vue SDK for Payload Live Preview",
"homepage": "https://payloadcms.com",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/live-preview",
"version": "3.50.0",
"version": "3.53.0",
"description": "The official live preview JavaScript SDK for Payload",
"homepage": "https://payloadcms.com",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/next",
"version": "3.50.0",
"version": "3.53.0",
"homepage": "https://payloadcms.com",
"repository": {
"type": "git",

View File

@@ -333,6 +333,7 @@ export const renderDocument = async ({
}
const documentSlots = renderDocumentSlots({
id,
collectionConfig,
globalConfig,
hasSavePermission,

View File

@@ -1,6 +1,5 @@
import type {
BeforeDocumentControlsServerPropsOnly,
DefaultServerFunctionArgs,
DocumentSlots,
EditMenuItemsServerPropsOnly,
PayloadRequest,
@@ -27,10 +26,11 @@ export const renderDocumentSlots: (args: {
collectionConfig?: SanitizedCollectionConfig
globalConfig?: SanitizedGlobalConfig
hasSavePermission: boolean
id?: number | string
permissions: SanitizedDocumentPermissions
req: PayloadRequest
}) => DocumentSlots = (args) => {
const { collectionConfig, globalConfig, hasSavePermission, req } = args
const { id, collectionConfig, globalConfig, hasSavePermission, req } = args
const components: DocumentSlots = {} as DocumentSlots
@@ -39,6 +39,7 @@ export const renderDocumentSlots: (args: {
const isPreviewEnabled = collectionConfig?.admin?.preview || globalConfig?.admin?.preview
const serverProps: ServerProps = {
id,
i18n: req.i18n,
payload: req.payload,
user: req.user,
@@ -169,10 +170,11 @@ export const renderDocumentSlots: (args: {
return components
}
export const renderDocumentSlotsHandler: ServerFunction<{ collectionSlug: string }> = async (
args,
) => {
const { collectionSlug, req } = args
export const renderDocumentSlotsHandler: ServerFunction<{
collectionSlug: string
id?: number | string
}> = async (args) => {
const { id, collectionSlug, req } = args
const collectionConfig = req.payload.collections[collectionSlug]?.config
@@ -187,6 +189,7 @@ export const renderDocumentSlotsHandler: ServerFunction<{ collectionSlug: string
})
return renderDocumentSlots({
id,
collectionConfig,
hasSavePermission,
permissions: docPermissions,

View File

@@ -26,9 +26,11 @@ export const LogoutClient: React.FC<{
const { startRouteTransition } = useRouteTransition()
const [isLoggedOut, setIsLoggedOut] = React.useState<boolean>(!user)
const isLoggedIn = React.useMemo(() => {
return Boolean(user?.id)
}, [user?.id])
const logOutSuccessRef = React.useRef(false)
const navigatingToLoginRef = React.useRef(false)
const [loginRoute] = React.useState(() =>
formatAdminURL({
@@ -45,26 +47,26 @@ export const LogoutClient: React.FC<{
const router = useRouter()
const handleLogOut = React.useCallback(async () => {
const loggedOut = await logOut()
setIsLoggedOut(loggedOut)
await logOut()
if (!inactivity && loggedOut && !logOutSuccessRef.current) {
if (!inactivity && !navigatingToLoginRef.current) {
toast.success(t('authentication:loggedOutSuccessfully'))
logOutSuccessRef.current = true
navigatingToLoginRef.current = true
startRouteTransition(() => router.push(loginRoute))
return
}
}, [inactivity, logOut, loginRoute, router, startRouteTransition, t])
useEffect(() => {
if (!isLoggedOut) {
if (isLoggedIn) {
void handleLogOut()
} else {
} else if (!navigatingToLoginRef.current) {
navigatingToLoginRef.current = true
startRouteTransition(() => router.push(loginRoute))
}
}, [handleLogOut, isLoggedOut, loginRoute, router, startRouteTransition])
}, [handleLogOut, isLoggedIn, loginRoute, router, startRouteTransition])
if (isLoggedOut && inactivity) {
if (!isLoggedIn && inactivity) {
return (
<div className={`${baseClass}__wrap`}>
<h2>{t('authentication:loggedOutInactivity')}</h2>

View File

@@ -90,7 +90,7 @@ export const SetStepNav: React.FC<{
}),
},
{
label: 'Versions',
label: t('version:versions'),
url: formatAdminURL({
adminRoute,
path: `${docBasePath}/versions`,
@@ -118,7 +118,7 @@ export const SetStepNav: React.FC<{
}),
},
{
label: 'Versions',
label: t('version:versions'),
url: formatAdminURL({
adminRoute,
path: `/globals/${globalSlug}/versions`,

View File

@@ -20,13 +20,13 @@ import {
import {
fieldIsID,
fieldShouldBeLocalized,
getFieldPaths,
getFieldPermissions,
getUniqueListBy,
tabHasName,
} from 'payload/shared'
import { diffComponents } from './fields/index.js'
import { getFieldPathsModified } from './utilities/getFieldPathsModified.js'
export type BuildVersionFieldsArgs = {
clientSchemaMap: ClientFieldSchemaMap
@@ -90,7 +90,7 @@ export const buildVersionFields = ({
continue
}
const { indexPath, path, schemaPath } = getFieldPathsModified({
const { indexPath, path, schemaPath } = getFieldPaths({
field,
index: fieldIndex,
parentIndexPath,
@@ -286,7 +286,7 @@ const buildVersionField = ({
indexPath: tabIndexPath,
path: tabPath,
schemaPath: tabSchemaPath,
} = getFieldPathsModified({
} = getFieldPaths({
field: tabAsField,
index: tabIndex,
parentIndexPath: indexPath,
@@ -322,14 +322,18 @@ const buildVersionField = ({
nestingLevel: nestingLevel + 1,
parentIndexPath: isNamedTab ? '' : tabIndexPath,
parentIsLocalized: parentIsLocalized || tab.localized,
parentPath: isNamedTab ? tabPath : path,
parentSchemaPath: isNamedTab ? tabSchemaPath : parentSchemaPath,
parentPath: isNamedTab ? tabPath : 'name' in field ? path : parentPath,
parentSchemaPath: isNamedTab
? tabSchemaPath
: 'name' in field
? schemaPath
: parentSchemaPath,
req,
selectedLocales,
versionFromSiblingData: 'name' in tab ? valueFrom?.[tab.name] : valueFrom,
versionToSiblingData: 'name' in tab ? valueTo?.[tab.name] : valueTo,
}).versionFields,
label: tab.label,
label: typeof tab.label === 'function' ? tab.label({ i18n, t: i18n.t }) : tab.label,
}
if (tabVersion?.fields?.length) {
baseVersionField.tabs.push(tabVersion)
@@ -370,8 +374,8 @@ const buildVersionField = ({
nestingLevel: nestingLevel + 1,
parentIndexPath: 'name' in field ? '' : indexPath,
parentIsLocalized: parentIsLocalized || field.localized,
parentPath: path + '.' + i,
parentSchemaPath: schemaPath,
parentPath: ('name' in field ? path : parentPath) + '.' + i,
parentSchemaPath: 'name' in field ? schemaPath : parentSchemaPath,
req,
selectedLocales,
versionFromSiblingData: fromRow,
@@ -469,8 +473,8 @@ const buildVersionField = ({
nestingLevel: nestingLevel + 1,
parentIndexPath: 'name' in field ? '' : indexPath,
parentIsLocalized: parentIsLocalized || ('localized' in field && field.localized),
parentPath: path + '.' + i,
parentSchemaPath: schemaPath + '.' + toBlock.slug,
parentPath: ('name' in field ? path : parentPath) + '.' + i,
parentSchemaPath: ('name' in field ? schemaPath : parentSchemaPath) + '.' + toBlock.slug,
req,
selectedLocales,
versionFromSiblingData: fromRow,

View File

@@ -25,7 +25,7 @@ export const Iterable: React.FC<FieldDiffClientProps> = ({
parentIsLocalized,
versionValue: valueTo,
}) => {
const { i18n } = useTranslation()
const { i18n, t } = useTranslation()
const { selectedLocales } = useSelectedLocales()
const { config } = useConfig()
@@ -73,7 +73,9 @@ export const Iterable: React.FC<FieldDiffClientProps> = ({
})
const rowNumber = String(i + 1).padStart(2, '0')
const rowLabel = fieldIsArrayType(field) ? `Item ${rowNumber}` : `Block ${rowNumber}`
const rowLabel = fieldIsArrayType(field)
? `${t('general:item')} ${rowNumber}`
: `${t('fields:block')} ${rowNumber}`
return (
<div className={`${baseClass}__row`} key={i}>

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/payload-cloud",
"version": "3.50.0",
"version": "3.53.0",
"description": "The official Payload Cloud plugin",
"homepage": "https://payloadcms.com",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "payload",
"version": "3.50.0",
"version": "3.53.0",
"description": "Node, React, Headless CMS and Application Framework built on Next.js",
"keywords": [
"admin panel",

View File

@@ -25,7 +25,7 @@ type SelectFieldBaseClientProps = {
readonly onChange?: (e: string | string[]) => void
readonly path: string
readonly validate?: SelectFieldValidation
readonly value?: string
readonly value?: string | string[]
}
type SelectFieldBaseServerProps = Pick<FieldPaths, 'path'>

View File

@@ -56,6 +56,12 @@ export type FieldState = {
fieldSchema?: Field
filterOptions?: FilterOptionsResult
initialValue?: unknown
/**
* @experimental - Note: this property is experimental and may change in the future. Use at your own discretion.
* Every time a field is changed locally, this flag is set to true. Prevents form state from server from overwriting local changes.
* After merging server form state, this flag is reset.
*/
isModified?: boolean
/**
* The path of the field when its custom components were last rendered.
* This is used to denote if a field has been rendered, and if so,
@@ -114,9 +120,11 @@ export type BuildFormStateArgs = {
mockRSCs?: boolean
operation?: 'create' | 'update'
readOnly?: boolean
/*
If true, will render field components within their state object
*/
/**
* If true, will render field components within their state object.
* Performance optimization: Setting to `false` ensures that only fields that have changed paths will re-render, e.g. new array rows, etc.
* For example, you only need to render ALL fields on initial render, not on every onChange.
*/
renderAllFields?: boolean
req: PayloadRequest
returnLockStatus?: boolean

View File

@@ -32,7 +32,7 @@ export type Options<TSlug extends CollectionSlug> = {
locale?: TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -32,7 +32,7 @@ export type Options<TSlug extends CollectionSlug> = {
locale?: TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -81,7 +81,7 @@ export type Options<TSlug extends CollectionSlug, TSelect extends SelectType> =
locale?: TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -46,7 +46,7 @@ export type BaseOptions<TSlug extends CollectionSlug, TSelect extends SelectType
locale?: TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -62,7 +62,7 @@ export type Options<TSlug extends CollectionSlug, TSelect extends SelectType> =
locale?: TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -76,7 +76,7 @@ export type Options<TSlug extends CollectionSlug, TSelect extends SelectType> =
locale?: 'all' | TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -77,7 +77,7 @@ export type Options<
locale?: 'all' | TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -54,7 +54,7 @@ export type Options<
locale?: 'all' | TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -1,4 +1,3 @@
/* eslint-disable no-restricted-exports */
import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'
import type { Document, PayloadRequest, PopulateType, SelectType } from '../../../types/index.js'
import type { CreateLocalReqOptions } from '../../../utilities/createLocalReq.js'
@@ -48,7 +47,7 @@ export type Options<TSlug extends CollectionSlug> = {
locale?: 'all' | TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -1,4 +1,3 @@
/* eslint-disable no-restricted-exports */
import type { PaginatedDocs } from '../../../database/types.js'
import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'
import type {
@@ -53,7 +52,7 @@ export type Options<TSlug extends CollectionSlug> = {
locale?: 'all' | TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -41,7 +41,7 @@ export type Options<TSlug extends CollectionSlug> = {
locale?: TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -76,7 +76,7 @@ export type BaseOptions<TSlug extends CollectionSlug, TSelect extends SelectType
locale?: TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -402,6 +402,7 @@ export type Params = { [key: string]: string | string[] | undefined }
export type ServerProps = {
readonly documentSubViewType?: DocumentSubViewTypes
readonly i18n: I18nClient
readonly id?: number | string
readonly locale?: Locale
readonly params?: Params
readonly payload: Payload

View File

@@ -162,7 +162,12 @@ export async function validateSearchParam({
if (versionFields) {
fieldAccess = policies[entityType]![entitySlug]!.fields
if (segments[0] === 'parent' || segments[0] === 'version' || segments[0] === 'snapshot') {
if (
segments[0] === 'parent' ||
segments[0] === 'version' ||
segments[0] === 'snapshot' ||
segments[0] === 'latest'
) {
segments.shift()
}
} else {

View File

@@ -0,0 +1 @@
export { is } from '@payloadcms/translations/languages/is'

View File

@@ -2,8 +2,7 @@ import ObjectIdImport from 'bson-objectid'
import type { TextField } from '../config/types.js'
const ObjectId = (ObjectIdImport.default ||
ObjectIdImport) as unknown as typeof ObjectIdImport.default
const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport
export const baseIDField: TextField = {
name: 'id',

View File

@@ -49,6 +49,9 @@ export function getFieldPaths({
}
}
/**
* @deprecated - will be removed in 4.0. Use `getFieldPaths` instead.
*/
export function getFieldPathsModified({
field,
index,

View File

@@ -1,8 +1,7 @@
import Ajv from 'ajv'
import ObjectIdImport from 'bson-objectid'
const ObjectId = (ObjectIdImport.default ||
ObjectIdImport) as unknown as typeof ObjectIdImport.default
const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport
import type { TFunction } from '@payloadcms/translations'
import type { JSONSchema4 } from 'json-schema'

View File

@@ -51,6 +51,15 @@ export async function buildFolderWhereConstraints({
equals: collectionConfig.slug,
},
})
// join queries need to omit trashed documents
if (collectionConfig.trash) {
constraints.push({
deletedAt: {
exists: false,
},
})
}
}
const filteredConstraints = constraints.filter(Boolean)

View File

@@ -32,7 +32,7 @@ export type CountGlobalVersionsOptions<TSlug extends GlobalSlug> = {
locale?: TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -43,7 +43,7 @@ export type Options<TSlug extends GlobalSlug, TSelect extends SelectType> = {
locale?: 'all' | TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -39,7 +39,7 @@ export type Options<TSlug extends GlobalSlug> = {
locale?: 'all' | TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -44,7 +44,7 @@ export type Options<TSlug extends GlobalSlug> = {
locale?: 'all' | TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -33,7 +33,7 @@ export type Options<TSlug extends GlobalSlug> = {
locale?: TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -51,7 +51,7 @@ export type Options<TSlug extends GlobalSlug, TSelect extends SelectType> = {
locale?: 'all' | TypedLocale
/**
* Skip access control.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
* Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.
* @default true
*/
overrideAccess?: boolean

View File

@@ -1,6 +1,6 @@
import ObjectIdImport from 'bson-objectid'
import type { JobLog, PayloadRequest } from '../../index.js'
import type { PayloadRequest } from '../../index.js'
import type { RunJobsSilent } from '../localAPI.js'
import type { UpdateJobFunction } from '../operations/runJobs/runJob/getUpdateJobFunction.js'
import type { TaskError } from './index.js'
@@ -9,8 +9,7 @@ import { getCurrentDate } from '../utilities/getCurrentDate.js'
import { calculateBackoffWaitUntil } from './calculateBackoffWaitUntil.js'
import { getWorkflowRetryBehavior } from './getWorkflowRetryBehavior.js'
const ObjectId = (ObjectIdImport.default ||
ObjectIdImport) as unknown as typeof ObjectIdImport.default
const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport
export async function handleTaskError({
error,
@@ -60,6 +59,19 @@ export async function handleTaskError({
const currentDate = getCurrentDate()
;(job.log ??= []).push({
id: new ObjectId().toHexString(),
completedAt: currentDate.toISOString(),
error: errorJSON,
executedAt: executedAt.toISOString(),
input,
output: output ?? {},
parent: req.payload.config.jobs.addParentToTaskLog ? parent : undefined,
state: 'failed',
taskID,
taskSlug,
})
if (job.waitUntil) {
// Check if waitUntil is in the past
const waitUntil = new Date(job.waitUntil)
@@ -87,19 +99,6 @@ export async function handleTaskError({
maxRetries = retriesConfig.attempts
}
const taskLogToPush: JobLog = {
id: new ObjectId().toHexString(),
completedAt: currentDate.toISOString(),
error: errorJSON,
executedAt: executedAt.toISOString(),
input,
output: output ?? {},
parent: req.payload.config.jobs.addParentToTaskLog ? parent : undefined,
state: 'failed',
taskID,
taskSlug,
}
if (!taskStatus?.complete && (taskStatus?.totalTried ?? 0) >= maxRetries) {
/**
* Task reached max retries => workflow will not retry
@@ -108,9 +107,7 @@ export async function handleTaskError({
await updateJob({
error: errorJSON,
hasError: true,
log: {
$push: taskLogToPush,
} as any,
log: job.log,
processing: false,
totalTried: (job.totalTried ?? 0) + 1,
waitUntil: job.waitUntil,
@@ -170,9 +167,7 @@ export async function handleTaskError({
await updateJob({
error: hasFinalError ? errorJSON : undefined,
hasError: hasFinalError, // If reached max retries => final error. If hasError is true this job will not be retried
log: {
$push: taskLogToPush,
} as any,
log: job.log,
processing: false,
totalTried: (job.totalTried ?? 0) + 1,
waitUntil: job.waitUntil,

View File

@@ -79,6 +79,7 @@ export async function handleWorkflowError({
await updateJob({
error: errorJSON,
hasError: hasFinalError, // If reached max retries => final error. If hasError is true this job will not be retried
log: job.log,
processing: false,
totalTried: (job.totalTried ?? 0) + 1,
waitUntil: job.waitUntil,

View File

@@ -13,7 +13,6 @@ import type {
TaskType,
} from '../../../config/types/taskTypes.js'
import type {
JobLog,
SingleTaskStatus,
WorkflowConfig,
WorkflowTypes,
@@ -24,8 +23,7 @@ import { TaskError } from '../../../errors/index.js'
import { getCurrentDate } from '../../../utilities/getCurrentDate.js'
import { getTaskHandlerFromConfig } from './importHandlerPath.js'
const ObjectId = (ObjectIdImport.default ||
ObjectIdImport) as unknown as typeof ObjectIdImport.default
const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport
export type TaskParent = {
taskID: string
@@ -186,7 +184,7 @@ export const getRunTaskFunction = <TIsInline extends boolean>(
await taskConfig.onSuccess()
}
const newLogItem: JobLog = {
;(job.log ??= []).push({
id: new ObjectId().toHexString(),
completedAt: getCurrentDate().toISOString(),
executedAt: executedAt.toISOString(),
@@ -196,12 +194,10 @@ export const getRunTaskFunction = <TIsInline extends boolean>(
state: 'succeeded',
taskID,
taskSlug,
}
})
await updateJob({
log: {
$push: newLogItem,
} as any,
log: job.log,
})
return output

View File

@@ -37,6 +37,33 @@ type Result<T> = Promise<{
files: FileToSave[]
}>
const shouldReupload = (
uploadEdits: UploadEdits,
fileData: Record<string, unknown> | undefined,
) => {
if (!fileData) {
return false
}
if (uploadEdits.crop || uploadEdits.heightInPixels || uploadEdits.widthInPixels) {
return true
}
// Since uploadEdits always has focalPoint, compare to the value in the data if it was changed
if (uploadEdits.focalPoint) {
const incomingFocalX = uploadEdits.focalPoint.x
const incomingFocalY = uploadEdits.focalPoint.y
const currentFocalX = 'focalX' in fileData && fileData.focalX
const currentFocalY = 'focalY' in fileData && fileData.focalY
const isEqual = incomingFocalX === currentFocalX && incomingFocalY === currentFocalY
return !isEqual
}
return false
}
export const generateFileData = async <T>({
collection: { config: collectionConfig },
data,
@@ -67,7 +94,7 @@ export const generateFileData = async <T>({
})
const {
constructorOptions = {},
constructorOptions,
disableLocalStorage,
focalPoint: focalPointEnabled = true,
formatOptions,
@@ -82,7 +109,10 @@ export const generateFileData = async <T>({
const incomingFileData = isDuplicating ? originalDoc : data
if (!file && uploadEdits && incomingFileData) {
if (
!file &&
(isDuplicating || shouldReupload(uploadEdits, incomingFileData as Record<string, unknown>))
) {
const { filename, url } = incomingFileData as unknown as FileData
if (filename && (filename.includes('../') || filename.includes('..\\'))) {

View File

@@ -13,22 +13,28 @@ type Args = {
export const getExternalFile = async ({ data, req, uploadConfig }: Args): Promise<File> => {
const { filename, url } = data
let trimAuthCookies = true
if (typeof url === 'string') {
let fileURL = url
if (!url.startsWith('http')) {
// URL points to the same server - we can send any cookies safely to our server.
trimAuthCookies = false
const baseUrl = req.headers.get('origin') || `${req.protocol}://${req.headers.get('host')}`
fileURL = `${baseUrl}${url}`
}
let cookies = (req.headers.get('cookie') ?? '').split(';')
if (trimAuthCookies) {
cookies = cookies.filter(
(cookie) => !cookie.trim().startsWith(req.payload.config.cookiePrefix),
)
}
const headers = uploadConfig.externalFileHeaderFilter
? uploadConfig.externalFileHeaderFilter(Object.fromEntries(new Headers(req.headers)))
: {
cookie:
req.headers
.get('cookie')
?.split(';')
.filter((cookie) => !cookie.trim().startsWith(req.payload.config.cookiePrefix))
.join(';') || '',
cookie: cookies.join(';'),
}
// Check if URL is allowed because of skipSafeFetch allowList

View File

@@ -1,7 +1,6 @@
import ObjectIdImport from 'bson-objectid'
const ObjectId = (ObjectIdImport.default ||
ObjectIdImport) as unknown as typeof ObjectIdImport.default
const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport
export const isValidID = (
value: number | string,

View File

@@ -416,20 +416,11 @@ export const traverseFields = ({
})
) {
if (Array.isArray(currentRef)) {
return
}
for (const key in currentRef as Record<string, unknown>) {
const localeData = currentRef[key as keyof typeof currentRef]
if (!Array.isArray(localeData)) {
continue
}
traverseArrayOrBlocksField({
callback,
callbackStack,
config,
data: localeData,
data: currentRef,
field,
fillEmpty,
leavesFirst,
@@ -437,6 +428,26 @@ export const traverseFields = ({
parentPath,
parentRef: currentParentRef,
})
} else {
for (const key in currentRef as Record<string, unknown>) {
const localeData = currentRef[key as keyof typeof currentRef]
if (!Array.isArray(localeData)) {
continue
}
traverseArrayOrBlocksField({
callback,
callbackStack,
config,
data: localeData,
field,
fillEmpty,
leavesFirst,
parentIsLocalized: true,
parentPath,
parentRef: currentParentRef,
})
}
}
} else if (Array.isArray(currentRef)) {
traverseArrayOrBlocksField({

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/plugin-cloud-storage",
"version": "3.50.0",
"version": "3.53.0",
"description": "The official cloud storage plugin for Payload CMS",
"homepage": "https://payloadcms.com",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/plugin-form-builder",
"version": "3.50.0",
"version": "3.53.0",
"description": "Form builder plugin for Payload CMS",
"keywords": [
"payload",

View File

@@ -20,6 +20,7 @@ export type {
PaymentField,
PaymentFieldConfig,
PriceCondition,
RadioField,
Redirect,
SelectField,
SelectFieldOption,

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/plugin-import-export",
"version": "3.50.0",
"version": "3.53.0",
"description": "Import-Export plugin for Payload",
"keywords": [
"payload",

View File

@@ -73,7 +73,17 @@ export const ExportSaveButton: React.FC = () => {
}
if (!response.ok) {
throw new Error('Failed to download file')
// Try to parse the error message from the JSON response
let errorMsg = 'Failed to download file'
try {
const errorJson = await response.json()
if (errorJson?.errors?.[0]?.message) {
errorMsg = errorJson.errors[0].message
}
} catch {
// Ignore JSON parse errors, fallback to generic message
}
throw new Error(errorMsg)
}
const fileStream = response.body
@@ -98,9 +108,8 @@ export const ExportSaveButton: React.FC = () => {
a.click()
document.body.removeChild(a)
URL.revokeObjectURL(url)
} catch (error) {
console.error('Error downloading file:', error)
toast.error('Error downloading file')
} catch (error: any) {
toast.error(error.message || 'Error downloading file')
}
}

View File

@@ -0,0 +1,3 @@
.page-field {
--field-width: 33.3333%;
}

View File

@@ -0,0 +1,41 @@
'use client'
import type { NumberFieldClientComponent } from 'payload'
import { NumberField, useField } from '@payloadcms/ui'
import React, { useEffect } from 'react'
import './index.scss'
const baseClass = 'page-field'
export const Page: NumberFieldClientComponent = (props) => {
const { setValue } = useField<number>()
const { value: limitValue } = useField<number>({ path: 'limit' })
// Effect to reset page to 1 if limit is removed
useEffect(() => {
if (!limitValue) {
setValue(1) // Reset page to 1
}
}, [limitValue, setValue])
return (
<div className={baseClass}>
<NumberField
field={{
name: props.field.name,
admin: {
autoComplete: undefined,
placeholder: undefined,
step: 1,
},
label: props.field.label,
min: 1,
}}
onChange={(value) => setValue(value ?? 1)} // Update the page value on change
path={props.path}
/>
</div>
)
}

View File

@@ -28,6 +28,7 @@ export const Preview = () => {
const { collection } = useImportExport()
const { config } = useConfig()
const { value: where } = useField({ path: 'where' })
const { value: page } = useField({ path: 'page' })
const { value: limit } = useField<number>({ path: 'limit' })
const { value: fields } = useField<string[]>({ path: 'fields' })
const { value: sort } = useField({ path: 'sort' })
@@ -71,6 +72,7 @@ export const Preview = () => {
format,
limit,
locale,
page,
sort,
where,
}),
@@ -168,6 +170,7 @@ export const Preview = () => {
i18n,
limit,
locale,
page,
sort,
where,
])

View File

@@ -1,4 +1,3 @@
.sort-by-fields {
display: block;
width: 33%;
--field-width: 25%;
}

View File

@@ -11,21 +11,32 @@ import {
useField,
useListQuery,
} from '@payloadcms/ui'
import React, { useEffect, useState } from 'react'
import React, { useEffect, useMemo, useRef, useState } from 'react'
import { applySortOrder, normalizeQueryParam, stripSortDash } from '../../utilities/sortHelpers.js'
import { reduceFields } from '../FieldsToExport/reduceFields.js'
import { useImportExport } from '../ImportExportProvider/index.js'
import './index.scss'
const baseClass = 'sort-by-fields'
export const SortBy: SelectFieldClientComponent = (props) => {
const { id } = useDocumentInfo()
const { setValue, value } = useField<string>()
// The "sort" text field that stores 'title' or '-title'
const { setValue: setSort, value: sortRaw } = useField<string>()
// Sibling order field ('asc' | 'desc') used when writing sort on change
const { value: sortOrder = 'asc' } = useField<string>({ path: 'sortOrder' })
// Needed so we can initialize sortOrder when SortOrder component is hidden
const { setValue: setSortOrder } = useField<'asc' | 'desc'>({ path: 'sortOrder' })
const { value: collectionSlug } = useField<string>({ path: 'collectionSlug' })
const { query } = useListQuery()
const { getEntityConfig } = useConfig()
const { collection } = useImportExport()
// ReactSelect's displayed option
const [displayedValue, setDisplayedValue] = useState<{
id: string
label: ReactNode
@@ -33,45 +44,83 @@ export const SortBy: SelectFieldClientComponent = (props) => {
} | null>(null)
const collectionConfig = getEntityConfig({ collectionSlug: collectionSlug ?? collection })
const fieldOptions = reduceFields({ fields: collectionConfig?.fields })
const fieldOptions = useMemo(
() => reduceFields({ fields: collectionConfig?.fields }),
[collectionConfig?.fields],
)
// Sync displayedValue with value from useField
// Normalize the stored value for display (strip the '-') and pick the option
useEffect(() => {
if (!value) {
const clean = stripSortDash(sortRaw)
if (!clean) {
setDisplayedValue(null)
return
}
const option = fieldOptions.find((field) => field.value === value)
if (option && (!displayedValue || displayedValue.value !== value)) {
const option = fieldOptions.find((f) => f.value === clean)
if (option && (!displayedValue || displayedValue.value !== clean)) {
setDisplayedValue(option)
}
}, [displayedValue, fieldOptions, value])
}, [sortRaw, fieldOptions, displayedValue])
// One-time init guard so clearing `sort` doesn't rehydrate from query again
const didInitRef = useRef(false)
// Sync the visible select from list-view query sort (preferred) or groupBy (fallback)
// and initialize both `sort` and `sortOrder` here as SortOrder may be hidden by admin.condition.
useEffect(() => {
if (id || !query?.sort || value) {
if (didInitRef.current) {
return
}
if (id) {
didInitRef.current = true
return
}
if (typeof sortRaw === 'string' && sortRaw.length > 0) {
// Already initialized elsewhere
didInitRef.current = true
return
}
const option = fieldOptions.find((field) => field.value === query.sort)
const qsSort = normalizeQueryParam(query?.sort)
const qsGroupBy = normalizeQueryParam(query?.groupBy)
const source = qsSort ?? qsGroupBy
if (!source) {
didInitRef.current = true
return
}
const isDesc = !!qsSort && qsSort.startsWith('-')
const base = stripSortDash(source)
const order: 'asc' | 'desc' = isDesc ? 'desc' : 'asc'
// Write BOTH fields so preview/export have the right values even if SortOrder is hidden
setSort(applySortOrder(base, order))
setSortOrder(order)
const option = fieldOptions.find((f) => f.value === base)
if (option) {
setValue(option.value)
setDisplayedValue(option)
}
}, [fieldOptions, id, query?.sort, value, setValue])
didInitRef.current = true
}, [id, query?.groupBy, query?.sort, sortRaw, fieldOptions, setSort, setSortOrder])
// When user selects a different field, store it with the current order applied
const onChange = (option: { id: string; label: ReactNode; value: string } | null) => {
if (!option) {
setValue('')
setSort('')
setDisplayedValue(null)
} else {
setValue(option.value)
setDisplayedValue(option)
const next = applySortOrder(option.value, String(sortOrder) as 'asc' | 'desc')
setSort(next)
}
}
return (
<div className={baseClass} style={{ '--field-width': '33%' } as React.CSSProperties}>
<div className={baseClass}>
<FieldLabel label={props.field.label} path={props.path} />
<ReactSelect
className={baseClass}

View File

@@ -0,0 +1,3 @@
.sort-order-field {
--field-width: 25%;
}

View File

@@ -0,0 +1,126 @@
'use client'
import type { SelectFieldClientComponent } from 'payload'
import { FieldLabel, ReactSelect, useDocumentInfo, useField, useListQuery } from '@payloadcms/ui'
import React, { useEffect, useMemo, useRef, useState } from 'react'
import { applySortOrder, normalizeQueryParam, stripSortDash } from '../../utilities/sortHelpers.js'
import './index.scss'
const baseClass = 'sort-order-field'
type Order = 'asc' | 'desc'
type OrderOption = { label: string; value: Order }
const options = [
{ label: 'Ascending', value: 'asc' as const },
{ label: 'Descending', value: 'desc' as const },
] as const
const defaultOption: OrderOption = options[0]
export const SortOrder: SelectFieldClientComponent = (props) => {
const { id } = useDocumentInfo()
const { query } = useListQuery()
// 'sortOrder' select field: 'asc' | 'desc'
const { setValue: setOrder, value: orderValueRaw } = useField<Order>()
// 'sort' text field: 'title' | '-title'
const { setValue: setSort, value: sortRaw } = useField<string>({ path: 'sort' })
// The current order value, defaulting to 'asc' for UI
const orderValue: Order = orderValueRaw || 'asc'
// Map 'asc' | 'desc' to the option object for ReactSelect
const currentOption = useMemo<OrderOption>(
() => options.find((o) => o.value === orderValue) ?? defaultOption,
[orderValue],
)
const [displayed, setDisplayed] = useState<null | OrderOption>(currentOption)
// One-time init guard so clearing `sort` doesn't rehydrate from query again
const didInitRef = useRef(false)
// Derive from list-view query.sort if present; otherwise fall back to groupBy
useEffect(() => {
if (didInitRef.current) {
return
}
// Existing export -> don't initialize here
if (id) {
didInitRef.current = true
return
}
// If sort already has a value, treat as initialized
if (typeof sortRaw === 'string' && sortRaw.length > 0) {
didInitRef.current = true
return
}
const qsSort = normalizeQueryParam(query?.sort)
const qsGroupBy = normalizeQueryParam(query?.groupBy)
if (qsSort) {
const isDesc = qsSort.startsWith('-')
const base = stripSortDash(qsSort)
const order: Order = isDesc ? 'desc' : 'asc'
setOrder(order)
setSort(applySortOrder(base, order)) // combined: 'title' or '-title'
didInitRef.current = true
return
}
// Fallback: groupBy (always ascending)
if (qsGroupBy) {
setOrder('asc')
setSort(applySortOrder(qsGroupBy, 'asc')) // write 'groupByField' (no dash)
didInitRef.current = true
return
}
// Nothing to initialize
didInitRef.current = true
}, [id, query?.sort, query?.groupBy, sortRaw, setOrder, setSort])
// Keep the select's displayed option in sync with the stored order
useEffect(() => {
setDisplayed(currentOption ?? defaultOption)
}, [currentOption])
// Handle manual order changes via ReactSelect:
// - update the order field
// - rewrite the combined "sort" string to add/remove the leading '-'
const onChange = (option: null | OrderOption) => {
const next = option?.value ?? 'asc'
setOrder(next)
const base = stripSortDash(sortRaw)
if (base) {
setSort(applySortOrder(base, next))
}
setDisplayed(option ?? defaultOption)
}
return (
<div className={baseClass}>
<FieldLabel label={props.field.label} path={props.path} />
<ReactSelect
className={baseClass}
disabled={props.readOnly}
inputId={`field-${props.path.replace(/\./g, '__')}`}
isClearable={false}
isSearchable={false}
// @ts-expect-error react-select option typing differs from our local type
onChange={onChange}
options={options as unknown as OrderOption[]}
// @ts-expect-error react-select option typing differs from our local type
value={displayed}
/>
</div>
)
}

View File

@@ -6,6 +6,7 @@ import { APIError } from 'payload'
import { Readable } from 'stream'
import { buildDisabledFieldRegex } from '../utilities/buildDisabledFieldRegex.js'
import { validateLimitValue } from '../utilities/validateLimitValue.js'
import { flattenObject } from './flattenObject.js'
import { getCustomFieldFunctions } from './getCustomFieldFunctions.js'
import { getFilename } from './getFilename.js'
@@ -23,8 +24,10 @@ export type Export = {
format: 'csv' | 'json'
globals?: string[]
id: number | string
limit?: number
locale?: string
name: string
page?: number
slug: string
sort: Sort
user: string
@@ -57,6 +60,8 @@ export const createExport = async (args: CreateExportArgs) => {
locale: localeInput,
sort,
user,
page,
limit: incomingLimit,
where,
},
req: { locale: localeArg, payload },
@@ -87,14 +92,30 @@ export const createExport = async (args: CreateExportArgs) => {
req.payload.logger.debug({ message: 'Export configuration:', name, isCSV, locale })
}
const batchSize = 100 // fixed per request
const hardLimit =
typeof incomingLimit === 'number' && incomingLimit > 0 ? incomingLimit : undefined
const { totalDocs } = await payload.count({
collection: collectionSlug,
user,
locale,
overrideAccess: false,
})
const totalPages = Math.max(1, Math.ceil(totalDocs / batchSize))
const requestedPage = page || 1
const adjustedPage = requestedPage > totalPages ? 1 : requestedPage
const findArgs = {
collection: collectionSlug,
depth: 1,
draft: drafts === 'yes',
limit: 100,
limit: batchSize,
locale,
overrideAccess: false,
page: 0,
page: 0, // The page will be incremented manually in the loop
select,
sort,
user,
@@ -156,15 +177,37 @@ export const createExport = async (args: CreateExportArgs) => {
req.payload.logger.debug('Pre-scanning all columns before streaming')
}
const limitErrorMsg = validateLimitValue(
incomingLimit,
req.t,
batchSize, // step i.e. 100
)
if (limitErrorMsg) {
throw new APIError(limitErrorMsg)
}
const allColumns: string[] = []
if (isCSV) {
const allColumnsSet = new Set<string>()
let scanPage = 1
// Use the incoming page value here, defaulting to 1 if undefined
let scanPage = adjustedPage
let hasMore = true
let fetched = 0
const maxDocs = typeof hardLimit === 'number' ? hardLimit : Number.POSITIVE_INFINITY
while (hasMore) {
const result = await payload.find({ ...findArgs, page: scanPage })
const remaining = Math.max(0, maxDocs - fetched)
if (remaining === 0) {
break
}
const result = await payload.find({
...findArgs,
page: scanPage,
limit: Math.min(batchSize, remaining),
})
result.docs.forEach((doc) => {
const flat = filterDisabledCSV(flattenObject({ doc, fields, toCSVFunctions }))
@@ -176,8 +219,9 @@ export const createExport = async (args: CreateExportArgs) => {
})
})
hasMore = result.hasNextPage
scanPage += 1
fetched += result.docs.length
scanPage += 1 // Increment page for next batch
hasMore = result.hasNextPage && fetched < maxDocs
}
if (debug) {
@@ -187,11 +231,27 @@ export const createExport = async (args: CreateExportArgs) => {
const encoder = new TextEncoder()
let isFirstBatch = true
let streamPage = 1
let streamPage = adjustedPage
let fetched = 0
const maxDocs = typeof hardLimit === 'number' ? hardLimit : Number.POSITIVE_INFINITY
const stream = new Readable({
async read() {
const result = await payload.find({ ...findArgs, page: streamPage })
const remaining = Math.max(0, maxDocs - fetched)
if (remaining === 0) {
if (!isCSV) {
this.push(encoder.encode(']'))
}
this.push(null)
return
}
const result = await payload.find({
...findArgs,
page: streamPage,
limit: Math.min(batchSize, remaining),
})
if (debug) {
req.payload.logger.debug(`Streaming batch ${streamPage} with ${result.docs.length} docs`)
@@ -240,10 +300,11 @@ export const createExport = async (args: CreateExportArgs) => {
}
}
fetched += result.docs.length
isFirstBatch = false
streamPage += 1
streamPage += 1 // Increment stream page for the next batch
if (!result.hasNextPage) {
if (!result.hasNextPage || fetched >= maxDocs) {
if (debug) {
req.payload.logger.debug('Stream complete - no more pages')
}
@@ -272,18 +333,29 @@ export const createExport = async (args: CreateExportArgs) => {
const rows: Record<string, unknown>[] = []
const columnsSet = new Set<string>()
const columns: string[] = []
let page = 1
// Start from the incoming page value, defaulting to 1 if undefined
let currentPage = adjustedPage
let fetched = 0
let hasNextPage = true
const maxDocs = typeof hardLimit === 'number' ? hardLimit : Number.POSITIVE_INFINITY
while (hasNextPage) {
const remaining = Math.max(0, maxDocs - fetched)
if (remaining === 0) {
break
}
const result = await payload.find({
...findArgs,
page,
page: currentPage,
limit: Math.min(batchSize, remaining),
})
if (debug) {
req.payload.logger.debug(
`Processing batch ${findArgs.page} with ${result.docs.length} documents`,
`Processing batch ${currentPage} with ${result.docs.length} documents`,
)
}
@@ -308,10 +380,12 @@ export const createExport = async (args: CreateExportArgs) => {
outputData.push(batchRows.map((doc) => JSON.stringify(doc)).join(',\n'))
}
hasNextPage = result.hasNextPage
page += 1
fetched += result.docs.length
hasNextPage = result.hasNextPage && fetched < maxDocs
currentPage += 1 // Increment page for next batch
}
// Prepare final output
if (isCSV) {
const paddedRows = rows.map((row) => {
const fullRow: Record<string, unknown> = {}

View File

@@ -5,22 +5,33 @@ import { APIError } from 'payload'
import { createExport } from './createExport.js'
export const download = async (req: PayloadRequest, debug = false) => {
let body
if (typeof req?.json === 'function') {
body = await req.json()
try {
let body
if (typeof req?.json === 'function') {
body = await req.json()
}
if (!body || !body.data) {
throw new APIError('Request data is required.')
}
const { collectionSlug } = body.data || {}
req.payload.logger.info(`Download request received ${collectionSlug}`)
body.data.user = req.user
const res = await createExport({
download: true,
input: { ...body.data, debug },
req,
})
return res as Response
} catch (err) {
// Return JSON for front-end toast
return new Response(
JSON.stringify({ errors: [{ message: (err as Error).message || 'Something went wrong' }] }),
{ headers: { 'Content-Type': 'application/json' }, status: 400 },
)
}
if (!body || !body.data) {
throw new APIError('Request data is required.')
}
req.payload.logger.info(`Download request received ${body.data.collectionSlug}`)
body.data.user = req.user
return createExport({
download: true,
input: { ...body.data, debug },
req,
}) as Promise<Response>
}

Some files were not shown because too many files have changed in this diff Show More