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

@rlay/rlay-client-lib

v0.2.4

Published

Provides a high-level interface (ORM) for your application, based on your schema.

Downloads

20

Readme

Rlay Client Library

Provides a high-level interface (ORM) for your application, based on your schema.

This library exposes Rlay native Entities such as Rlay_Class, Rlay_ClassAssertion, Rlay_Individual, etc. through the client. When the client is generated and constructed with rlay-generated, the client will also expose the application specific Entities e.g. HTTPRequestClass, etc. These application specific Entities can

Requirements

npm install -g @rlay/utils

Usage

rlay-generate

The default behavior for using the Rlay Client Library is, by using rlay-generate, which creates generated/rlay-client/index.js in the root of the project. generated/rlay-client/index.js exposes the initialized Client instance, ready for usage.

const client = require('./generated/rlay-client');

// Create a new Individual
client.Individual.create();

// Find an Entity by its CID
client.Individual.find('123...789');
// this also works
client.Entity.find('123...789');

Instantiate a new Entity

Assume payload is valid and of type DataProperty

const client = require('./generated/rlay-client');

const entity = new client.Rlay_DataProperty(client, payload);

or

const client = require('./generated/rlay-client');

const entity = new client.Rlay_DataProperty.from(payload);

or (recommended)

const client = require('./generated/rlay-client');

const entity = new client.getEntityFromPayload(payload);

assert(entity instanceof client.Rlay_DataProperty);

Create a new Entity

Assume payload is valid and of type DataProperty

const client = require('./generated/rlay-client');

const entity = new client.Rlay_DataProperty(client, payload);
await entity.create();

or

const client = require('./generated/rlay-client');

const entity = await client.Rlay_DataProperty.create(payload);

or (recommended)

const client = require('./generated/rlay-client');

const entity = await client.createEntityFromPayload(payload);

assert(entity instanceof client.Rlay_DataProperty);
assert.equal(entity.remoteCid, entity.cid);

Create an Individual with inherent properties aka. properties

The properties of an individual can only be specified at the creation-time of the Individual and are like any other operations immutable.

const client = require('./generated/rlay-client');

// Create a new Individual with inherent properties
await client.Individual.create({
  nameOfApplicationSpecificEntity: true,
  anotherApplicationSpecificEntity: 45,
});

Create non-inherent properties aka. assertions about an Individual

Once the individual is created (with or without properties) assertions about it can be made.

const client = require('./generated/rlay-client');

const properties = {
  nameOfApplicationSpecificEntity: true,
  anotherApplicationSpecificEntity: 45,
};

const assertions = {
  nameOfApplicationSpecificEntity: 'test',
  anotherApplicationSpecificEntity: 42,
};

// Create a new Individual
const indi = client.Individual.create(properties);
// Create assertions about that individual
indi.assert(assertions);

Find an entity by its CID

Once an entity is created it can be found by its CID.

const client = require('./generated/rlay-client');

// Find an entity
const result1 = client.Entity.find('individual_CID');
const result2 = client.Entity.find('class_CID');

console.log(result1 instanceof client.Rlay_Individual); // true
console.log(result2 instanceof client.Rlay_Class); // true
// .find() calls .fetch() on the Entity instance
console.log(result1.properties instanceof Object); // true
console.log(result1.nameOfApplicationSpecificEntity !== undefined); // true

Architecture

Rlay Entities

  • [x] Entity
    • [x] documentation
    • [x] tests
  • [x] Entity Factory Interface
    • [x] documentation
    • [x] tests
  • [x] Entity Interface
    • [x] documentation
    • [x] tests
  • [x] Individual
    • [ ] documentation
    • [ ] tests
  • [ ] Integration tests

Testing

All tests are unit tests and do not require a running rlay-client server. All tests are importing the Rlay MockClient.

Rlay MockClient

Located at [./test/mocks/client.js](./tests/mocks/client.js) it mocks all functions that usually would call out to the rlay-client server.