npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

payload-repository

v1.1.1

Published

Opinionated repository and operations object wrapper around Payload's Local API.

Readme

Payload Repository and Operations

Opinionated repository and operations object wrapper around Payload's Local API.

Installation

npm install payload-repository

Usage

Pass your generated Payload Config type as the first type argument to get full type safety on fields, select, and return types.

CollectionOperations

Extend CollectionOperations to encapsulate domain-specific operations logic for a collection:

import type {BasePayload} from 'payload';
import type {Config} from '@/payload-types';
import {CollectionOperations} from 'payload-repository';

class PostsOperations extends CollectionOperations<Config, 'posts'> {
    constructor(payload: BasePayload) {
        super(payload, 'posts');
    }

    create(title: string) {
        return this.repository.create({title});
    }

    findAll() {
        return this.repository.find({});
    }

    findById(id: number) {
        return this.repository.findById(id);
    }

    findPublished() {
        return this.repository.find({status: {equals: 'published'}});
    }

    publish(id: number) {
        return this.repository.updateById(id, {status: 'published'});
    }

    deleteById(id: number) {
        return this.repository.deleteById(id);
    }
}

// Usage
const postsOperations = new PostsOperations(payload);

const post = await postsOperations.create('Hello World');
const published = await postsOperations.findPublished();
await postsOperations.publish(post.id);

GlobalOperations

Extend GlobalOperations to encapsulate domain-specific operations logic for a global:

import type {BasePayload} from 'payload';
import type {Config} from '@/payload-types';
import {GlobalOperations} from 'payload-repository';

class SettingsOperations extends GlobalOperations<Config, 'settings'> {
    constructor(payload: BasePayload) {
        super(payload, 'settings');
    }

    get() {
        return this.repository.find();
    }

    setSiteTitle(title: string) {
        return this.repository.update({siteTitle: title});
    }
}

// Usage
const settingsOperations = new SettingsOperations(payload);

const settings = await settingsOperations.get();
await settingsOperations.setSiteTitle('My Site');

Transformers

Transformers are optional middleware functions that intercept and modify arguments before they reach the Payload API. They can transform data, where clauses, and options on a per-operation basis.

Pass transformers as the third argument to CollectionOperations or GlobalOperations:

import type {BasePayload} from 'payload';
import type {Config} from '@/payload-types';
import {CollectionOperations} from 'payload-repository';
import type {CollectionTransformers} from 'payload-repository/internal/types';

const tenantTransformers = (tenantId: number): CollectionTransformers<Config, 'posts'> => ({
    create: {
        data: data => ({...data, tenant: tenantId}),
    },
    find: {
        where: where => ({...where, tenant: {equals: tenantId}}),
    },
    update: {
        data: data => ({...data, tenant: tenantId}),
        where: where => ({...where, tenant: {equals: tenantId}}),
    },
    delete: {
        where: where => ({...where, tenant: {equals: tenantId}}),
    },
});

class PostsOperations extends CollectionOperations<Config, 'posts'> {
    constructor(payload: BasePayload, tenantId: number) {
        super(payload, 'posts', tenantTransformers(tenantId));
    }

    create(title: string) {
        return this.repository.create({title});
    }

    findAll() {
        return this.repository.find({});
    }
}

// Usage
const tenantPosts = new PostsOperations(payload, 42);

// tenant is automatically injected into the data
await tenantPosts.create('Hello World');

// tenant where clause is automatically applied
const posts = await tenantPosts.findAll();

Transformers support async functions and are available for all repository operations.

Merging Transformers

When building layered repositories where each layer contributes its own transformers, use mergeTransformers to combine them. Overlapping transformers on the same operation and argument are chained sequentially:

import type {BasePayload} from 'payload';
import type {Config} from '@/payload-types';
import {CollectionOperations, mergeTransformers} from 'payload-repository';
import type {CollectionTransformers} from 'payload-repository/internal/types';

const tenantTransformers = (tenantId: number): CollectionTransformers<Config, 'posts'> => ({
    find: {
        where: where => ({...where, tenant: {equals: tenantId}}),
    },
});

const localeTransformers = (locale: string): CollectionTransformers<Config, 'posts'> => ({
    find: {
        options: options => ({...options, locale}),
    },
});

class PostsOperations extends CollectionOperations<Config, 'posts'> {
    constructor(payload: BasePayload, tenantId: number, locale: string) {
        super(payload, 'posts', mergeTransformers(
            tenantTransformers(tenantId),
            localeTransformers(locale),
        ));
    }

    findAll() {
        return this.repository.find({});
    }
}

mergeTransformers works with both CollectionTransformers and GlobalTransformers. When multiple transformer objects define the same leaf (e.g. both define find.where), they are chained in order — the second transformer receives the output of the first.

License

MIT

Todo

  • [ ] Github Actions