
Research
/Security News
11 Malicious Go Packages Distribute Obfuscated Remote Payloads
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
payloadcms-typing-supercharge
Advanced tools
This package provides strongly typed PayloadCMS types, enhancing the type safety and validation of your PayloadCMS queries and operations. It allows you to perform type-safe selections, where clauses, sort operations, and CRUD operations with strong type
Project starts on 18-05-2025
This package provides strongly typed PayloadCMS types, enhancing the type safety and validation of your PayloadCMS queries and operations. It allows you to perform type-safe selections, where clauses, sort operations, and CRUD operations with strong type inference.
Give me a ⭐ if you like it.
PayloadCMS is a great headless CMS, but its default types can be enhanced to provide better type safety and validation. This package supercharges PayloadCMS with:
IMHO, Payload claims to be type-safe, but not strong as I expected (ton of any
...) Give me a ⭐ if you agree :p
string | {collection-object}
at the same time.find
findByID
create
update
(byID and Bulk)delete
(byID and Bulk)AccessResult
Access
FilterOptionsFunc
FilterOptions
Sort
Where
[!CAUTION]
ALL operations underTypedPayload
are rootless by default, meaningoverrideAccess = false
.
[!NOTE]
If you wanna to use root access by default, you can setoverrideAccess = true
in the constructor ofTypedPayload
class. eg.const typedPayload = new TypedPayload(payload, { overrideAccess: true });
Install the package using npm:
npm install payloadcms-typing-supercharge
[!TIP]
Read troubleshooting before doing the dependency installation. You may find a better way to use the package.
First, import the TypedPayload
class:
import { TypedPayload } from 'payloadcms-typing-supercharge';
Create a type-safe PayloadCMS instance:
const typedPayload = TypedPayload.createTypedPayload(payload);
Enjoy type-safe operations! Here are some examples:
interface Profile { // Sample Collection Type
id: string;
name: string;
subProfile: Profile;
}
interface User { // Sample Collection Type
id: string;
name: string;
profile: Profile;
}
const result = await typedPayload.find({
collection: 'users',
depth: 2,
});
result.profile // ✅ Type: Profile, current depth 0
result.profile.subProfile // ✅ Type: Profile, current depth 1
result.profile.subProfile.subProfile // ✅ Type: string (ID), current depth 2
result.profile.subProfile.subProfile.subProfile // ❌ Invalid, depth exceeded, current depth 3
interface Profile { // Sample Collection Type
id: string;
name: string;
subProfile: Profile;
}
interface User { // Sample Collection Type
id: string;
name: string;
profile: Profile;
}
await typedPayload.find({
collection: 'users',
where: {
"profile.subProfile.name": { // ✅ Valid selection
equals: 'John Doe'
}
},
});
await typedPayload.find({
collection: 'users',
where: {
"profile.subProfile.firstName": { // ❌ Invalid selection, `firstName` does not exist
equals: 'John Doe'
}
},
});
interface Profile { // Sample Collection Type
id: string;
name: string;
subProfile: Profile;
}
interface User { // Sample Collection Type
id: string;
name: string;
profile: Profile;
}
await typedPayload.find({
collection: 'users',
sort: ['name', '-profile.subProfile.name'], // ✅ Valid sort
});
await typedPayload.find({
collection: 'users',
sort: [
'+name', // ❌ Invalid sortting operator, `+` is not allowed
'-profile.subProfile.firstName' // ❌ Invalid sort, `firstName` does not exist
],
});
import { createTypedCollectionConfig } from 'payloadcms-typing-supercharge';
export const Users = createTypedCollectionConfig({
slug: 'users',
fields: [
{
name: 'name',
type: 'text',
},
{
name: 'profile',
type: 'relationship',
relationTo: 'profiles',
},
],
access: { // ✅ Typed
//...
},
});
[!NOTE]
Not all values in thecreateTypedCollectionConfig
are type-safe right now.
If you encounter an error like the following during payload type generation:
Error: ENOENT: no such file or directory, open '[path]/payloadcms-typing-supercharge/dist/types/index.js?namespace=xxxxxxxxx'
You can resolve this by using the copy-payloadcms-typing-supercharge
command to copy the type definitions to your local directory:
copy-payloadcms-typing-supercharge ./payloadcms-typing-supercharge
This command will ensure the type definitions are properly available in your project.
[!NOTE]
Although you can customise the path to copy the type definitions to your local directory, it is recommended to use the same path as the package name to avoid changing the name of imports.
You can add the following command to your package.json
scripts section:
{
// ...
"scripts": {
"generate:types": "copy-payloadcms-typing-supercharge ./payloadcms-typing-supercharge && payload generate:types",
},
// ...
}
[!TIP]
You can also put the copiedpayloadcms-typing-supercharge
into .gitignore to avoid pushing it to the repository.
Don't install the package as a dependency, but do the following.
[!TIP]
Recommended to remove the package before doing this approach if you have installed it as a dependency.
Add the following to your package.json
scripts section:
{
// ...
"scripts": {
"payloadTyping@upgrade": "npx payloadcms-typing-supercharge packages/payloadcms-typing-supercharge",
},
// ...
}
Add the following to your tsconfig.json
scripts section:
{
"compilerOptions": {
"paths": {
// ...
"payloadcms-typing-supercharge": [
"./packages/payloadcms-typing-supercharge/index.ts"
],
"payloadcms-typing-supercharge/*": [
"./packages/payloadcms-typing-supercharge/*"
],
// ...
},
},
}
Run npm run payloadTyping@upgrade
to copy the files to your local directory.
GOOD to go!
Where
performanceCollectionConfig
Contributions are welcome! If you find a bug or have a feature request, please open an issue. If you want to contribute code, please fork the repository and submit a pull request.
[!NOTE]
Due to the typing loss in theTypedPayload
class after build process, the package will serve as the orginal typescript source code.
[!NOTE]
TypeScript aliases are not allowed in this project to prevent aliases mapping problem after file copy. So make sure to use the relative path for file imports.
This project is licensed under the MIT License - see the LICENSE file for details
Love it? Consider a donation to support my work.
FAQs
This package provides strongly typed PayloadCMS types, enhancing the type safety and validation of your PayloadCMS queries and operations. It allows you to perform type-safe selections, where clauses, sort operations, and CRUD operations with strong type
The npm package payloadcms-typing-supercharge receives a total of 4 weekly downloads. As such, payloadcms-typing-supercharge popularity was classified as not popular.
We found that payloadcms-typing-supercharge demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).