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

@royalzsoftware/royal-data-ts

v0.4.3

Published

🌟 Define your models and this package handle will handle the persistence

Downloads

3

Readme

Royal Data TS

πŸš€ Define your models and this package will handle the persistence

This package is a simple library using the power of repositories to unify data access to several different sources.

Run the example in 4.738 seconds from now

$ cd /tmp && git clone https://github.com/royalzsoftware/royal-data-ts && cd royal-data-ts && npm install && npm run example

Installation

npm

$ npm i @royalzsoftware/royal-data-ts

yarn

$ yarn add @royalzsoftware/royal-data-ts

Example

import { firstValueFrom } from "rxjs";
import { CrudRepository } from "./crud-repository";
import { CrudRepositoryBuilder } from "./crud-repository-builder";

// 0. create the user domain object
class User {
    private readonly permissions: string[] = [];

    constructor(public username: string, public password: string) { }

    addPermission(permission: string) {
        this.permissions.push(permission);
    }

    isAdminUser() {
        return this.permissions.includes('admin');
    }
}

// 1. inject the userRepository
async function test(userRepository: CrudRepository<User>) {
    // 2. create the user
    const user = new User("Alexander", "Panov");

    // 3. store the current user and retrieve newly created id
    const {id: userId} = await firstValueFrom(userRepository.create(user));

    // 4. add permission to the user
    user.addPermission('admin');

    // 5. update the user with the previously retrieved id and the user data
    const {model: updatedUser} = await firstValueFrom(userRepository.update(userId, user));

    // 6. print out if the admin is an admin user
    console.log(updatedUser.isAdminUser());
}

const repoBuilder = new CrudRepositoryBuilder<User>();

// 7. instantiate in memory repository
const userRepository = repoBuilder.inMemory();

// 8. or inject the http repository, by providing a http client.
const httpClient = undefined as any // YOUR JOB

const httpUserRepository = repoBuilder.http(httpClient, (userData: any) => {
    return new User(userData.username, userData.password);
}).withDefaultRouteDefinitions('/users');

// 9. run this shit
test(userRepository);

🌟 Highlights

  • RxJs first
  • EventRepository that holds the changes inMemory until you want to persist it by applying the events to a persisted CRUD Repository
  • Zero dependencies besides Typescript
  • Small modules that can be extended easily
  • Shipped with LocalStorage adapter, for UI development without external depedencies
  • Clear defined interfaces with low risk of wrong usage
  • Ships with highly extensible HTTP Repository

Releasing a new version

Prerequisites

  • Please do not have neither staged, nor unstaged changes, these will break the flow.
  • You need to have make installed.

Doing

  • Rename the UNRELEASED section in the CHANGELOG.md file to following DATE - SEMANTICVERSION for example 2023-11-12 - 0.1.3
  • Then run make