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

payload-relationship-enhancer

v0.0.10

Published

This is a very early release of a plugin designed to enhance the relationships within payload to do two things:

Downloads

987

Readme

payload-relationship-enhancer

This is a very early release of a plugin designed to enhance the relationships within payload to do two things:

  1. Provide referential integrity through deletes - i.e. if A references B and then B is deleted, A should no longer reference A
  2. Provide bi-directional relationships - i.e. if A references B, allow B to reference A and keep them in sync.

Motivation: if you have used keystonejs you know why, but more importantly, this stops gymnastics at query time to try and reverse lookup a relationship and instead builds it into the GraphQL / REST schema

A word of warning

This was written by someone who is bad at coding, and until a week ago had never used Mongo or Payload. Performance is probably bad and it might delete all your relationships.

I am almost certain this will not work properly for everyone and in every case, please leave an issue with details about how your relationships were setup!

Payload would appear to be considering bi-directional relationships as a core feature (although it is not on roadmap) in the future, so this should be seen as a stop-gap for applications prior to its official implementation.

Getting started

  1. bun add payload-relationship-enhancer

  2. update your payload config like this:

import RelationshipEnhancerPlugin from "payload-relationship-enhancer";

plugins: [payloadCloud(), RelationshipEnhancerPlugin],
  1. configure it like this:
    {
      type: "relationship",
      relationTo: "c",
      hasMany: true,
      name: "amixedblocks",
      custom: {
        relationshipEnhancer: {
          relationshipIntegrity: true,
          biDirectional: [
            {
              relationTo: "c", // must match one or more of the things in relationTo
              path: "cmixedblocks", // this is the path of the field on c that is ALSO a relationship field AND has a biDirectional config pointing back here
            },
            ...
          ],
        },
      },
    },

Config type is

        {
          relationshipIntegrity?: boolean,
          biDirectional?: [
            {
              relationTo: string;
              path: string;
            },
            ...
          ],
        }

Limitations / TODO

  • Currently any relationship field nested under an array will be ignored by this plugin, groups and tabs and blocks should be fine.
  • Only Mongo is supported as a database, it is very possible to add Postgres.
  • Support for localised relationship fields is not yet there
  • The changes made by this plugin do NOT trigger lifecycle hooks - i.e. if you have a bi-directional relationship between A and B, and set the value in A to some B document, the plugin will update a B document but no update hook will run - this is because we use the mongoose adapter directly and I am not sure exactly how to manually trigger updates.
  • This really needs some tests
  • I don't think the structure of this plugin follows best practice
  • Should add some plugin init config params for profiling performance
  • Better docs
  • The config will let you point two fields on 1 collection to 1 field on another - this breaks stuff. need to sanitise out in config check step
  • Some janky stuff with 'required' relationship fields that needs to be tested out

Contributing

Please do.

Dev mode

  • bun install
  • bun run dev

Mongo & payload will start - localhost:3000. Payload user is [email protected] with password test