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

rystem.repository.client

v0.1.2

Published

It can simplify the integration with rystem repository server.

Downloads

19

Readme

What is Rystem?

Client for Repository Framework

Services setup

You need to install through the RepositoryServices class all the repository clients, with settings.

.Create() => set a default uri for all clients. In settings you have:

  • name: a value to retrieve the installed client.
  • path: a path which concatened with default uri create the final url for your client.
  • uri: override the default uri and the path
import { RepositoryServices } from "rystem.repository.client";

RepositoryServices
    .Create("https://localhost:7058/api/")
    .addRepository<IperUser, string>(x => {
        x.name = "test";
        x.path = "SuperUser";
    })
    .addRepository<SuperUser, string>(x => {
        x.name = "test2"
        x.uri = "https://localhost:9090/api/SuperUser/inmemory/"
    });

You can also add Command or Query for your CQRS pattern with

RepositoryServices
    .Create("https://localhost:7058/api/")
    .addCommand<IperUser, string>(x => {
        x.name = "test";
        x.path = "SuperUser";
    })
    .addQuery<SuperUser, string>(x => {
        x.name = "test2"
        x.uri = "https://localhost:9090/api/SuperUser/inmemory/"
    });

Add Custom Headers to each request

For instance when you need to add a token from your authentication flow you can use this implementation.

RepositoryServices
        .Create("http://localhost:5000/api/")
        .addRepository<IperUser, string>(x => {
            x.name = "test";
            x.path = "SuperUser";
            x.addHeadersEnricher((...args) => {
                return {
                    "Authorization-UI": "Bearer dsjadjalsdjalsdjalsda"
                }
            });
            x.addHeadersEnricher((endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit, body: any) => {
                return {
                    "Authorization-UI2": "Bearer dsjadjalsdjalsdjalsda"
                }
            })
        })

Add Custom Error Handlers

For instance when you need to capture a not authorized error to request a new authentication flow before a new request. Returning true you can retry automatically the request, with false the request chain will be stopped.

RepositoryServices
        .Create("http://localhost:5000/api/")
        .addRepository<IperUser, string>(x => {
            x.name = "test";
            x.path = "SuperUser";
            x.addErrorHandler((endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit, body: any, err: any) => {
                return (err as string).startsWith("big error");
            });
        })

Usage

Always with RepositoryServices class you can retrieve with the correct name the integration you setup during your startup.

const repository = RepositoryServices
    .Repository<IperUser, string>("test");

You can also retrieve CQRS interfaces.

const command = RepositoryServices
    .Command<IperUser, string>("test");
const query = RepositoryServices
    .Query<IperUser, string>("test2");

Methods

Insert

let response: State<IperUser, string> =
    await repository.insert(id, iperUser);

Update

let response: State<IperUser, string> =
    await repository.update(id, iperUser);

Exist

let response: State<IperUser, string> =
    await repository.exist(id);

Delete

let response: State<IperUser, string> =
    await repository.delete(id);

Batch operations

const batcher = repository.batch();
batcher
    .addInsert(id1, iperUser1)
    .addUpdate(id2, iperUser2)
    .addDelete(id3);
    const batchResults: BatchResults<IperUser, string> =
        await batcher.execute();

Query operations

  • get all elements
let queryResults = await repository.query().execute();
  • filter as string
let id = "someId";
let queryResults = await repository
    .query()
    .filter(`x => x.id == "${id}"`)
    .execute();
  • build a filter (similar to the previous example with addiction of ordering by ascending all retrieved elements)
let queryResults = await repository
    .query()
    .where()
    .select(x => x.id)
    .equal(id)
    .build()
    .orderBy(x => x.name)
    .execute();
  • build a filter and count all elements
const count = await repository
    .query()
    .where()
    .select(x => x.id)
    .equal(id)
    .count();
  • build a filter and sum a column of all elements
const sum = await repository
    .query()
    .where()
    .select(x => x.id)
    .equal(id)
    .sum(x => x.port);
  • build a filter with greaterThanOrEqual for instance
const portGreaterThanZero = await repository
    .query()
    .where()
    .openRoundBracket()
    .select(x => x.port)
    .greaterThanOrEqual(0)
    .count();
  • same of previous but ordered by a column
const portGreaterThanZeroOrderedByName = await repository
    .query()
    .where()
    .select(x => x.port)
    .greaterThanOrEqual(0)
    .build()
    .orderBy(x => x.name)
    .execute();