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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dan-haub/payload-dynamic-collections

v2.0.0

Published

A Payload Plugin that allows for dynamic schema regeneration at runtime

Downloads

2

Readme

Payload Dynamic Collections Plugin

License GitHub issues GitHub stars GitHub forks

Overview

Payload Dynamic Collections is a plugin for Payload CMS that enhances its capabilities by introducing dynamic collections, allowing you to manage your database collections at runtime. This system leverages PM2 and local database storage to ensure your Payload server is always up to date! This system is great for projects that constantly need new collections or updates to the schema of old ones, as you no longer have to completely rebuild and re-deploy your Payload server each time.

Features

  • Dynamic Collections: Create and edit collections directly from the admin console, no re-deploying necessary
  • Version Management: New collections aren't loaded until a new Version is created and selected. If something goes wrong, you can pick a new version at the click of a button!
  • Hooks and Access: You can supply your own hooks and access functions that can be selected when configuring new collections

Installation

  1. Install the plugin.

    yarn add @nebulaworks/payload-dynamic-collections
    or
    npm -i @nebulaworks/payload-dynamic-collections
  2. Configure your runtime environment to use PM2

    • According to the PM2 homepage: "PM2 is a daemon process manager that will help you manage and keep your application online 24/7"
    • This plugin requires that "always on" mentality to instantly restart your payload server once it realizes it is out of date.
    • How PM2 is configured will likely be different depending on the specifics of your project, but an example of a very simple configuration can be found in the dev folder with the docker compose file and its entrypoint script
    # entrypoint.sh
    yarn install
    cd dev
    yarn install
    yarn generate:types
    
    yarn global add pm2
    pm2 start yarn --interpreter sh -- dev
    pm2 logs --raw
  3. Configure the plugin in your Payload config.

  4. Start creating dynamic collections!

Usage

// payload.config.ts
import type { Config } from 'payload/config'
import { buildConfig } from 'payload/config'
import path from 'path'
import { mongooseAdapter } from '@payloadcms/db-mongodb'
import { webpackBundler } from '@payloadcms/bundler-webpack'
import { slateEditor } from '@payloadcms/richtext-slate'
import Users from './collections/Users'
import type { DynamicCollectionOptions } from '../../src/index' // TODO: Change to module path
import { dynamicCollectionsPlugin } from '../../src/index' // TODO: Change to module path
import { collectionAccess, fieldAccess } from './access'
import hidden from './hidden'
import { collectionHooks, fieldHooks } from './hooks'

const dynamicCollectionOptions: DynamicCollectionOptions = {
  enabled: true,
  access: {
    createVersion: collectionAccess.isAdmin,
    viewVersions: collectionAccess.isAdmin,
    editCollections: collectionAccess.isAdmin,
    viewCollections: collectionAccess.isAdmin,
  },

  collectionAccessFunctions: collectionAccess,
  fieldAccessFunctions: fieldAccess,
  hiddenFunctions: hidden,
  collectionHooks,
  fieldHooks,
}

const conf: Config = {
  admin: {
    user: Users.slug,
    bundler: webpackBundler(),
  },
  editor: slateEditor({}),
  collections: [Users],
  typescript: {
    outputFile: path.resolve(__dirname, 'payload-types.ts'),
  },
  graphQL: {
    schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'),
  },
  plugins: [dynamicCollectionsPlugin(dynamicCollectionOptions)],
  db: mongooseAdapter({
    url: process.env.DATABASE_URI,
  }),
}

export default buildConfig(conf)

Documentation

The Config

Creating New Collections

Editing Fields

Creating New Versions

Access Functions

Hidden Functions

Hooks and Hooks with Props

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For support or inquiries, please contact Dan Haub at [email protected].