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

tspa

v1.0.4

Published

TypeScript Persistence API

Downloads

7

Readme

TypeScript Persistence API (TSPA)

Install

yarn install tspa

MongoCrudRepository

MongoCrudRepository is an implementation of the TransactionalCrudRepository interface tailored for MongoDB. It offers seamless integration with MongoDB databases, allowing you to perform CRUD operations on your MongoDB collections effortlessly, as well as run transactional operations.

Features

  • CRUD Operations: Perform Create, Read, Update, and Delete operations on MongoDB collections.
  • Query Options: Customize your queries with query options to control aspects like sorting, limiting, and skipping results.
  • Transactional Support: Integrates with TransactionalCrudRepository, allowing transactional operations for MongoDB transactions.

Usage

# .env

TSPA_APP_NAME=your-app-name
TSPA_MONGO_URI=your-mongo-uri #mongodb://localhost:27017/<your app name>?authSource=admin&replicaSet=<your app replica set name>
TSPA_LOG_LEVEL=info #none, error, warn, info, trace, debug
TSPA_INTERNAL_LOG_LEVEL=none #none, error, warn, info, trace, debug
import { Entity, MongoCrudRepository, TransactionalCrudRepository } from 'tspa';

interface User extends Entity {
  name: string;
  email: string;
}

// Below is the user object to tell mongoDB how to store the data. This object is not actually stored, rather a schema is created based on the object fields.
const user: User = {
  id: '1',
  name: 'John Doe',
  email: '[email protected]'
}

const userRepository: TransactionalCrudRepository<User> = MongoCrudRepository.initFor<User>('users', {
  entities: [{ user }],
  uri: TSPA_MONGO_URI,
  appName: TSPA_APP_NAME
});

//OR

MongoCrudRepository.init<User>({ entities: [{ user }], uri: TSPA_MONGO_URI, appName: TSPA_APP_NAME });
const userRepository: TransactionalCrudRepository<User> = MongoCrudRepository.for<User>('users');

const createdUser: User = userRepository.create(user);

FirestoreCrudRepository

FirestoreCrudRepository is an implementation of the CrudRepository interface tailored for Firestore. It offers seamless integration with Firestore storage.

Features

  • CRUD Operations: Perform Create, Read, Update, and Delete operations on Firestore collections.
  • Query Options: Customize your queries with query options to control aspects like sorting, limiting, and skipping results.
  • Real-time Updates: Leverage Firestore's real-time updates for live data synchronization.

Usage

# .env

TSPA_APP_NAME=your-app-name
TSPA_FIREBASE_API_KEY=your-api-key
TSPA_FIREBASE_AUTH_DOMAIN=your-auth-domain
TSPA_FIREBASE_PROJECT_ID=your-project-id
TSPA_LOG_LEVEL=info #none, error, warn, info, trace, debug
TSPA_INTERNAL_LOG_LEVEL=none #none, error, warn, info, trace, debug
import { Entity, FirestoreCrudRepository, CrudRepository } from 'tspa';

interface User extends Entity {
  name: string;
  email: string;
}

const user: User = {
  id: '1',
  name: 'John Doe',
  email: '[email protected]'
}

const userRepository: CrudRepository<User> = FirestoreCrudRepository.initFor<User>('users', {
  apiKey: 'apiKey',
  authDomain: 'authDomain',
  projectId: 'your-project-id',
  appName: 'your-app-name'
});

//OR

FirestoreCrudRepository.init<User>({
  apiKey: 'apiKey',
  authDomain: 'authDomain',
  projectId: 'your-project-id',
  appName: 'your-app-name'
});
const userRepository: CrudRepository<User> = FirestoreCrudRepository.for<User>('users');

const createdUser: User = userRepository.create(user);

LocalStorageCrudRepository

LocalStorageCrudRepository is an implementation of the CrudRepository interface tailored for browsers and NodeJS Local Storage, providing seamless integration for client-side and server-side data persistence.

Features

  • CRUD Operations: Perform Create, Read, Update, and Delete operations on browser and NodeJS Local Storage.
  • Query Options: Limited query options are available for filtering data.
  • Client-Side Data Persistence: Store data locally in the browser or NodeJS server, ensuring data availability even after page refresh or server restarts.

Usage

# .env

TSPA_APP_NAME=your-app-name
TSPA_STORAGE_PATH=your-app-storage-path #where the data will be stored (default: './db' for NodeJS and 'localStorage' for browser)
TSPA_LOG_LEVEL=info #none, error, warn, info, trace, debug
TSPA_INTERNAL_LOG_LEVEL=none #none, error, warn, info, trace, debug
import { Entity, LocalStorageCrudRepository, CrudRepository } from 'tspa';

interface User extends Entity {
  name: string;
  email: string;
}

const user: User = {
  id: '1',
  name: 'John Doe',
  email: '[email protected]'
};

const userRepository: CrudRepository<User> = LocalStorageCrudRepository.initFor<User>('user', {
  appName: 'your-app-name',
  storagePath: './db' //where the data will be stored (default: './db' for NodeJS and 'localStorage' for browser)
});

//OR

LocalStorageCrudRepository.init<User>({
  appName: 'your-app-name',
  storagePath: './db' //where the data will be stored (default: './db' for NodeJS and 'localStorage' for browser)
});
const userRepository: CrudRepository<User> = LocalStorageCrudRepository.for<User>('users');

const createdUser: User = userRepository.create(user);

API Reference

All repositories implement the CrudRepository which includes the following methods (except for executeTransaction which is from TransactionalCrudRepository which at the moment is only supported by MongoDB):

  • findById(id: string, queryOptions?: QueryOptions<T>): Promise<Optional<T>>: Find a document by its ID.
  • findOneBy(filter: Partial<T>, queryOptions?: QueryOptions<T>): Promise<Optional<T>>: Find a single document matching the provided filter.
  • findAll(filter?: Partial<T>, queryOptions?: QueryOptions<T>): Promise<T[]>: Find all documents optionally matching the provided filter.
  • create(payload: T, queryOptions?: QueryOptions<T>): Promise<T>: Create a new document.
  • createAll(payload: T[], queryOptions?: QueryOptions<T>): Promise<T[]>: Create multiple documents.
  • update(id: string, payload: Partial<T>, queryOptions?: QueryOptions<T>): Promise: Update a document by ID.
  • remove(id: string, queryOptions?: QueryOptions<T>): Promise<boolean>: Remove a document by ID.
  • createId(): string: Generate a new unique ID.
  • executeTransaction<R>(execution: TransactionExecution<R>): Promise<R>: Creates a transaction context to execute a set of transactional operations.

TESTS

To run tests, ensure you have docker installed, and also ensure you have firebase emulator running, then update your /etc/hosts file with the following:

127.0.0.1 mongodb

Then run the following command:

yarn run test:all

Examples

  • Vending Machine: A simple vending machine backend application built with TSPA, NodeJS, Express, supporting OAuth2 authentication/authorization, and also transactional sessions with TSPA's TransactionalCrudRepository for MongoDB.

Author

👤 Anietie Asuquo [email protected]

🤝 Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page. You can also take a look at the contributing guide.

📝 License

Copyright © 2024 Anietie Asuquo [email protected]. This project is MIT licensed.