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

cool-data-manager

v1.0.22

Published

manage entities on graph.cool

Downloads

4

Readme

cool-data-manager

manage entities on graph.cool

npm i -S cool-data-manager

graph.cool schema

type YetAnotherThing {
  createdAt: DateTime!
  id: ID!
  stringData: String
  thing: Thing @relation(name: "MoreThingsOnThing")
  updatedAt: DateTime!
}

type OtherThing {
  createdAt: DateTime!
  id: ID!
  stringData: String
  thing: Thing @relation(name: "OtherThingOnThing")
  updatedAt: DateTime!
}

type Thing {
  booleanData: Boolean
  createdAt: DateTime!
  dateTimeData: DateTime
  enumData: THING_ENUM_DATA
  floatData: Float
  id: ID!
  intData: Int
  jsonData: Json
  otherThing: OtherThing @relation(name: "OtherThingOnThing")
  stringData: String
  stringRequired: String!
  updatedAt: DateTime!
  yetAnotherThings: [YetAnotherThing!]! @relation(name: "MoreThingsOnThing")
}

Lokka Client

const {Lokka}     = require('lokka')
const {Transport} = require('lokka-transport-http')

const client = new Lokka({
  transport: new Transport('https://api.graph.cool/simple/v1/[SIMPLE_API_KEY]')
})

module.exports = client

CoolDataManager - Thing, OtherThing and YetAnotherThing

const CoolDataManager = require('cool-data-manager').CoolDataManager;
const CoolRelation = require('cool-data-manager').CoolRelation;
const CoolCollection = require('cool-data-manager').CoolCollection;

const client = require('../client');

const OtherThing = require('../otherThing');
const YetAnotherThing = require('../yetAnotherThing');

const entityInfo = {
  entityName: 'Thing',
  entityNamePlural: 'Things',
  fields: {
    stringRequired: {
      type: 'string',
      required: true
    },
    stringData: {
      type: 'string'
    },
    intData: {
      type: 'int'
    },
    enumData: {
      type: 'enum',
      validValues: [ 'One', 'Two' ]
    },
    floatData: {
      type: 'float'
    },
    booleanData: {
      type: 'boolean'
    },
    dateTimeData: {
      type: 'dateTime'
    },
    otherThing: {
      type: new CoolRelation(OtherThing)
    },
    yetAnotherThings: {
      type: new CoolCollection(YetAnotherThing)
    }
  }
};

const entityManager = new CoolDataManager(entityInfo, client, { verbose: false });

module.exports = entityManager;

Test it out

'use strict';
const clog   = require('fbkt-clog');
const uuid = require('uuid');
const expect = require('chai').expect;
const moment = require('moment');
const entityManager = require('./index');

describe.only(__filename, function () {
  it('should create one thing and delete it', function (done) {
    this.timeout(10000);
    const testId     = uuid.v4();
    const testEntity = {
      stringRequired: testId,
      stringData: testId,
      intData: 1,
      enumData: 'One',
      floatData: 1.2345,
      booleanData: true,
      dateTimeData: moment.utc().format(),
      otherThing: {
        stringData: 'OTHER THING DATA'
      },
      yetAnotherThings: [
        {
          stringData: 'YET MORE'
        },
        {
          stringData: 'Still Yet MOre evEN'
        }
      ]
    };

    entityManager.createOne(testEntity, {
      verbose: true
    })
      .then(thing => {
        clog('THING', thing);
        expect(thing).to.be.an('object');
        expect(thing.stringData).to.equal(testEntity.stringData);
        expect(thing.intData).to.equal(testEntity.intData);
        expect(thing.enumData).to.equal(testEntity.enumData);
        expect(thing.floatData).to.equal(testEntity.floatData);
        expect(thing.booleanData).to.equal(testEntity.booleanData);
        expect(moment.utc(thing.dateTimeData).format()).to.equal(testEntity.dateTimeData);
        expect(thing.otherThing).to.be.an('object');
        expect(thing.otherThing.stringData).to.equal(testEntity.otherThing.stringData);
        expect(thing.yetAnotherThings).to.be.an('array');
        expect(thing.yetAnotherThings.length).to.equal(testEntity.yetAnotherThings.length);
        expect(thing.yetAnotherThings[0]).to.be.an('object');
        expect(thing.yetAnotherThings[0].stringData).to.equal(testEntity.yetAnotherThings[0].stringData);
        expect(thing.yetAnotherThings[1].stringData).to.equal(testEntity.yetAnotherThings[1].stringData);

        return entityManager.deleteOne(thing)
          .then(result => {
            expect(result).to.be.an('object');
            expect(result.id).to.equal(thing.id);
            // clog('DELETE ONE RESULT', result);
            done();
          })
      })
      .catch(error => {
        done(error);
      })
  });
});
~~~~~~~~~~~~ EXECUTING GRAPH COOL MUTATION ~~~~~~~~~~~~
{
  createThing(
    stringRequired: "737634ab-8f4d-4595-bf02-13a411f67a02",
    stringData: "737634ab-8f4d-4595-bf02-13a411f67a02",
    intData: 1,
    enumData: One,
    floatData: 1.2345,
    booleanData: true,
    dateTimeData: "2017-04-01T02:21:07Z",
    otherThing: {
    stringData: "OTHER THING DATA",
    },
      yetAnotherThings: [
        {

    stringData: "YET MORE",
        },{

    stringData: "Still Yet MOre evEN",
        }
      ],

  ) {
    id,
    createdAt,
    updatedAt,
       stringRequired,
         stringData,
         intData,
         enumData,
         floatData,
         booleanData,
         dateTimeData,
      otherThing {
                 stringData,

            },
            yetAnotherThings {
                 stringData,

            },

  },
}
____________ END EXECUTING GRAPH COOL MUTATION ____________


~~~~~~~~~~~~ THING ~~~~~~~~~~~~
{ updatedAt: '2017-04-01T02:21:08.000Z',
  enumData: 'One',
  booleanData: true,
  dateTimeData: '2017-04-01T02:21:07.000Z',
  yetAnotherThings:
   [ { stringData: 'YET MORE' },
     { stringData: 'Still Yet MOre evEN' } ],
  floatData: 1.2345,
  id: 'cj0ymsx4erc2l01853i8nd3xv',
  intData: 1,
  otherThing: { stringData: 'OTHER THING DATA' },
  createdAt: '2017-04-01T02:21:08.000Z',
  stringRequired: '737634ab-8f4d-4595-bf02-13a411f67a02',
  stringData: '737634ab-8f4d-4595-bf02-13a411f67a02' }
____________ END THING ____________

    ✓ should create one thing and delete it (1466ms)

... it can already do quite a bit more, with a few more features before it's done. check out the thing tests