Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tspa

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tspa

TypeScript Persistent API

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-60%
Maintainers
1
Weekly downloads
 
Created
Source

TypeScript Persistent API (TSPA)

Version Documentation Maintenance License: MIT Twitter: anietieasuquo

TypeScript Persistence API (TSPA) is a simple, lightweight, and easy-to-use library for creating and managing persistent data in a TypeScript application.
It provides a simple API for creating, reading, updating, and deleting data in a various data store such as LocalStorage, Firestore, and MongoDB (more to come).

Install

yarn install tspa

Usage

Note that you only need to set the environment variables for the data store you want to use. For example, if you want to use MongoDB, you only need to set the TSPA_MONGO_URI and TSPA_MONGO_APP_NAME environment variables.

.env

TSPA_MONGO_URI=your-mongo-uri
TSPA_MONGO_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_FIREBASE_APP_NAME=your-app-name
TSPA_APP_NAME=your-app-name
TSPA_STORAGE_PATH=your-app-name

MongoDB

//FOR MongoDB
import { Entity, MongoCrudRepository } from 'tspa';

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

const user: User = {
  id: '1',
  name: 'John Doe',
  email: 'johndoe@email.com'
}

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

//OR

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

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

Firestore

//FOR Firestore
import { Entity, FirestoreCrudRepository } from 'tspa';

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

const user: User = {
  id: '1',
  name: 'John Doe',
  email: 'johndoe@email.com'
}

const userRepository = 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 = FirestoreCrudRepository.for<User>('users');

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

LocalStorage

//FOR LocalStorage
import { Entity, LocalStorageCrudRepository } from 'tspa';

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

const user: User = {
  id: '1',
  name: 'John Doe',
  email: 'johndoe@email.com'
};

const userRepository = 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 = LocalStorageCrudRepository.for<User>('users');

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

Author

👤 Anietie Asuquo hello@anietieasuquo.com

🤝 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 hello@anietieasuquo.com.
This project is MIT licensed.

Keywords

FAQs

Package last updated on 19 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc