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

dgraph-js-extras

v0.8.1

Published

Functions to use with dgraph

Downloads

54

Readme

DGraph JS Extras

A library of helper functions to accompany the dgraph-js library.

  • 0 dependencies just dgraph-js and grpc are needed as peer dependencies.
  • 100% test coverage.
  • Written in Typescript just like the DGraph library so you get IntelliSense.
  • Write one line statements to persist data that would take multiple lines with the base library.

Functions including "commit" indicate they will be set to "commitNow" Functions including "txn" indicate they create their own transactions and can be directly awaited.

This library is pre 1.0 and there might be some small API changes, that said everything is a small function so you could always ctrl-c ctrl-v it out of the repo if things change.

Example: persist two new nodes, return the node ids

 const users = [
    { username: 'foo' }
    { username: 'bar' }
 ]
 
 const id1 = await xExtractUids(xSetJSONCommitTxn(users, dgraphClient));

Example: upsert helper function

const updateJunior = {
    skill: 'Javascript',
    level: 10,
    x: 'y',
    y: 'y',
    z: 'y'
};

// If you already had a node in the db that looks like:
const existingNode = {
    skill: 'Javascript',
    level: 10,
    x: 'foo',
    y: 'foo',
    z: 'foo'
};

// You can pass an array of values to update, or just an object.
const updates = [updateJunior];

// The basicEqualityUpsertFn below will find any nodes that has both skill and level predicates.
const upsertFn = basicEqualityUpsertFn(['skill', 'level']);

// x, y and z will be updated from 'foo' to 'y', because both skill and level match.

// If no node matched both skill 'Javascript' and level '10' a new node would be created.
// We can await this direclty as it includes commit and txn postfix. 
const [uid] = await xUpsertCommitTxn(upsertFn, updates, dgraphClient);

// It returns the uids of the found or created nodes.
// If you want it as part of a bigger transaction there is also a xUpsertObject function you could use. 

Checkout all the functions in API documentation

Contribute?

Please do feel free to submit a PR.

Testing

Install docker then run yarn run dgraph-test-db-up Now just call yarn run test

You can also setup Wallaby JS as a test runner. I am a fan.

Deploy workflow

  1. Make changes
  2. Commit those changes yarn run commit
  3. Test yarn run test
  4. Bump version in package.json
  5. Generate changelog yarn run generate-changelog
  6. Publish yarn publish
  7. Commit package.json, CHANGELOG.md and lib files
  8. Git tag - needed by changelog to know what version to attribute the commits to
  9. Push