A utility library for Payload 3 developers. It provides a JSON schema function that removes unresolved ID variants from relationship types, plus helpers that walk a document against its collection schema, flatten it into rows, or return a transformed clone. Bundled field resolvers handle relationships, Lexical rich text and uploads. Requires Payload 3.29 or later.
A collection of utilities for Payload 3.0
Installation
npm i @whatworks/payload-utilities16
Stars
1
Forks
2
Open Issues
3 days ago
Last Updated
48
Weekly Downloads
v3.0.1
npm Version
83.4 KB
Unpacked Size
0
Dependencies
16+1 since Sep 7
| Date | Stars |
|---|---|
| Dec 6, 2026 | 16 |
| Dec 5, 2026 | 16 |
| Dec 4, 2026 | 16 |
| Dec 3, 2026 | 16 |
| Dec 2, 2026 | 16 |
| Dec 1, 2026 | 16 |
| Nov 30, 2026 | 16 |
| Nov 29, 2026 | 16 |
| Nov 28, 2026 | 16 |
| Nov 27, 2026 | 16 |
| Nov 26, 2026 | 16 |
| Nov 25, 2026 | 16 |
| Nov 24, 2026 | 16 |
| Nov 23, 2026 | 16 |
| Nov 22, 2026 | 16 |
| Nov 21, 2026 | 16 |
| Nov 20, 2026 | 16 |
| Nov 19, 2026 | 16 |
| Nov 18, 2026 | 16 |
| Nov 17, 2026 | 15 |
| Nov 16, 2026 | 15 |
| Nov 15, 2026 | 15 |
| Nov 14, 2026 | 15 |
| Nov 13, 2026 | 15 |
| Nov 12, 2026 | 15 |
| Nov 11, 2026 | 15 |
| Nov 10, 2026 | 15 |
| Nov 9, 2026 | 15 |
| Nov 8, 2026 | 15 |
| Nov 7, 2026 | 15 |
| Nov 6, 2026 | 15 |
| Nov 5, 2026 | 15 |
| Nov 4, 2026 | 15 |
| Nov 3, 2026 | 15 |
| Nov 2, 2026 | 15 |
| Nov 1, 2026 | 15 |
| Oct 31, 2026 | 15 |
| Oct 30, 2026 | 15 |
| Oct 29, 2026 | 15 |
| Oct 28, 2026 | 15 |
| Oct 27, 2026 | 15 |
| Oct 26, 2026 | 15 |
| Oct 25, 2026 | 15 |
| Oct 24, 2026 | 15 |
| Oct 23, 2026 | 15 |
| Oct 22, 2026 | 15 |
| Oct 21, 2026 | 15 |
| Oct 20, 2026 | 15 |
| Oct 19, 2026 | 15 |
| Oct 18, 2026 | 15 |
| Oct 17, 2026 | 15 |
| Oct 16, 2026 | 15 |
| Oct 15, 2026 | 15 |
| Oct 14, 2026 | 15 |
| Oct 13, 2026 | 15 |
| Oct 12, 2026 | 15 |
| Oct 11, 2026 | 15 |
| Oct 10, 2026 | 15 |
| Oct 9, 2026 | 15 |
| Oct 8, 2026 | 15 |
| Oct 7, 2026 | 15 |
| Oct 6, 2026 | 15 |
| Oct 5, 2026 | 15 |
| Oct 4, 2026 | 15 |
| Oct 3, 2026 | 15 |
| Oct 2, 2026 | 15 |
| Oct 1, 2026 | 15 |
| Sep 30, 2026 | 15 |
| Sep 29, 2026 | 15 |
| Sep 28, 2026 | 15 |
| Sep 27, 2026 | 15 |
| Sep 26, 2026 | 15 |
| Sep 25, 2026 | 15 |
| Sep 24, 2026 | 15 |
| Sep 23, 2026 | 15 |
| Sep 22, 2026 | 15 |
| Sep 21, 2026 | 15 |
| Sep 20, 2026 | 15 |
| Sep 19, 2026 | 15 |
| Sep 18, 2026 | 15 |
| Sep 17, 2026 | 15 |
| Sep 16, 2026 | 15 |
| Sep 15, 2026 | 15 |
| Sep 14, 2026 | 15 |
| Sep 13, 2026 | 15 |
| Sep 12, 2026 | 15 |
| Sep 11, 2026 | 15 |
| Sep 10, 2026 | 15 |
| Sep 9, 2026 | 15 |
| Sep 8, 2026 | 15 |
| Sep 7, 2026 | 15 |
Shared by 12 plugins in what-works-global/payload-packages.
48+39 since Sep 7
| Date | Weekly downloads |
|---|---|
| Dec 6, 2026 | 48 |
| Dec 5, 2026 | 87 |
| Dec 4, 2026 | 90 |
| Dec 3, 2026 | 112 |
| Dec 2, 2026 | 141 |
| Dec 1, 2026 | 172 |
| Nov 30, 2026 | 173 |
| Nov 29, 2026 | 156 |
| Nov 28, 2026 | 115 |
| Nov 27, 2026 | 107 |
| Nov 26, 2026 | 145 |
| Nov 25, 2026 | 154 |
| Nov 24, 2026 | 166 |
| Nov 23, 2026 | 165 |
| Nov 22, 2026 | 190 |
| Nov 21, 2026 | 190 |
| Nov 20, 2026 | 277 |
| Nov 19, 2026 | 245 |
| Nov 18, 2026 | 320 |
| Nov 17, 2026 | 281 |
| Nov 16, 2026 | 290 |
| Nov 15, 2026 | 288 |
| Nov 14, 2026 | 296 |
| Nov 13, 2026 | 241 |
| Nov 12, 2026 | 219 |
| Nov 11, 2026 | 138 |
| Nov 10, 2026 | 139 |
| Nov 9, 2026 | 131 |
| Nov 8, 2026 | 105 |
| Nov 7, 2026 | 93 |
| Nov 6, 2026 | 58 |
| Nov 5, 2026 | 62 |
| Nov 4, 2026 | 44 |
| Nov 3, 2026 | 38 |
| Nov 2, 2026 | 40 |
| Nov 1, 2026 | 44 |
| Oct 31, 2026 | 38 |
| Oct 30, 2026 | 47 |
| Oct 29, 2026 | 37 |
| Oct 28, 2026 | 17 |
| Oct 27, 2026 | 29 |
| Oct 26, 2026 | 27 |
| Oct 25, 2026 | 28 |
| Oct 24, 2026 | 27 |
| Oct 23, 2026 | 18 |
| Oct 22, 2026 | 21 |
| Oct 21, 2026 | 27 |
| Oct 20, 2026 | 17 |
| Oct 19, 2026 | 18 |
| Oct 18, 2026 | 15 |
| Oct 17, 2026 | 17 |
| Oct 16, 2026 | 20 |
| Oct 15, 2026 | 22 |
| Oct 14, 2026 | 28 |
| Oct 13, 2026 | 28 |
| Oct 12, 2026 | 31 |
| Oct 11, 2026 | 34 |
| Oct 10, 2026 | 44 |
| Oct 9, 2026 | 218 |
| Oct 8, 2026 | 213 |
| Oct 7, 2026 | 201 |
| Oct 6, 2026 | 199 |
| Oct 5, 2026 | 194 |
| Oct 4, 2026 | 189 |
| Oct 3, 2026 | 183 |
| Oct 2, 2026 | 6 |
| Oct 1, 2026 | 18 |
| Sep 30, 2026 | 21 |
| Sep 29, 2026 | 21 |
| Sep 28, 2026 | 21 |
| Sep 27, 2026 | 24 |
| Sep 26, 2026 | 21 |
| Sep 25, 2026 | 21 |
| Sep 24, 2026 | 10 |
| Sep 23, 2026 | 15 |
| Sep 22, 2026 | 16 |
| Sep 21, 2026 | 21 |
| Sep 20, 2026 | 21 |
| Sep 19, 2026 | 24 |
| Sep 18, 2026 | 26 |
| Sep 17, 2026 | 26 |
| Sep 16, 2026 | 20 |
| Sep 15, 2026 | 19 |
| Sep 14, 2026 | 14 |
| Sep 13, 2026 | 11 |
| Sep 12, 2026 | 6 |
| Sep 11, 2026 | 5 |
| Sep 10, 2026 | 8 |
| Sep 9, 2026 | 7 |
| Sep 8, 2026 | 8 |
| Sep 7, 2026 | 9 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1064440892-payload-utilities)<a href="https://payloaddirectory.dev/plugins/1064440892-payload-utilities"><img src="https://payloaddirectory.dev/badge/1064440892-payload-utilities.svg" alt="Payload Directory"></a>README
A collection of utilities for Payload 3.0.
resolveJsonSchemaRelationshipstraverseDocumentflattenDocumenttransformDocumentpnpm add @whatworks/payload-utilities
| Entry | Path |
|---|---|
| Root | @whatworks/payload-utilities |
| Document traversal | @whatworks/payload-utilities/traverseDocument |
resolveJsonSchemaRelationshipsA JsonSchemaFunction for config.typescript.schema that rewrites generated types under the assumption that documents are always fetched with full depth. Strips the unresolved string (ID) variant from relationship unions so string | Page becomes Page and (string | Page)[] becomes Page[]. Null is preserved.
import { buildConfig } from 'payload'
import { resolveJsonSchemaRelationships } from '@whatworks/payload-utilities'
export default buildConfig({
typescript: {
schema: [resolveJsonSchemaRelationships],
},
})
traverseDocumentWalks a document against its sanitized collection schema, invoking a callback for each field/value pair. Recurses into array and group fields. Returning a truthy value from the callback short-circuits traversal. Sync callbacks return void; async callbacks return Promise<void>.
import { traverseDocument } from '@whatworks/payload-utilities/traverseDocument'
await traverseDocument({
collection,
doc,
req,
callback: ({ field, schemaPathSegments, value }) => {
console.log(schemaPathSegments.map((s) => s.name).join('.'), field.type, value)
},
})
Callback args:
field — the matched Field from the schema map.schemaPathSegments — { name, label }[] describing the path through the schema.indexPathSegments — same as schemaPathSegments but includes array indices.siblingData — the parent object the value lives on.schemaMap — the resolved Payload field schema map.value — the field's current value.flattenDocumentReturns a flat, schema-ordered array of { field, schemaPathSegments, indexPathSegments, value } for every visited field. Optionally applies fieldResolvers to transform the stored value. Useful for serializing documents (e.g. exporting, indexing, generating previews).
import {
flattenDocument,
relationshipTitleResolver,
richTextPlaintextResolver,
} from '@whatworks/payload-utilities/traverseDocument'
const rows = await flattenDocument({
collection,
doc,
req,
excludedFields: ['internalNotes'],
fieldResolvers: {
relationship: relationshipTitleResolver,
richText: richTextPlaintextResolver(),
},
})
transformDocumentReturns a deep-cloned copy of the document with any fieldResolvers applied in place. Resolvers returning undefined leave the value untouched; child paths win over parent paths when both resolve.
import {
transformDocument,
uploadMetadataResolver,
} from '@whatworks/payload-utilities/traverseDocument'
const transformed = await transformDocument({
collection,
doc,
req,
fieldResolvers: {
upload: uploadMetadataResolver,
},
})
A FieldResolver<T> receives the field, its value, sibling data, and the current request, and returns a replacement value (or undefined to keep the original). Three are bundled:
| Resolver | Field type | Behavior |
|---|---|---|
relationshipTitleResolver | relationship | Resolves to the referenced document's admin.useAsTitle value. Falls back to the populated value on the doc, then the ID, then the original value. Handles polymorphic and hasMany relationships. |
richTextPlaintextResolver({ converters? }) | richText | Converts a Lexical value to plain text via @payloadcms/richtext-lexical/plaintext. Accepts optional custom PlaintextConverters. |
uploadMetadataResolver | upload | Resolves to { id, filename, filesize, mimeType, url } from the referenced upload document. Uses inline metadata when complete, otherwise fetches it. |
Define your own by typing the field key:
import type { FieldResolver } from '@whatworks/payload-utilities/traverseDocument'
const numberResolver: FieldResolver<'number'> = ({ value }) =>
typeof value === 'number' ? value.toFixed(2) : undefined
payload utilities
Helper functions for composing field validators, extracting IDs and resolving documents in Payload
77251/wk0v3
payload schema
Define Payload field validation once and compile it to Payload fields and Zod 4 schemas
7139/wk3v3
payload field factories
Typed factory functions that build Payload field configs with concise, composable overrides
77255/wk1v3
link field
Link field and Lexical link feature supporting internal document and custom URL links
6346/wk0v4
payload plugin tooling
Shared lint, format, TypeScript, build, test and CI config for developing Payload plugins
6039/wk0v4
payload cli
Command-line access to Payload collections and globals through the Local API, built for AI agents and humans
588/wk13v3