Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
TypeScript Persistence API (TSPA) is a TypeScript library providing a flexible and easy-to-use Persistence API, allowing developers to perform CRUD operations in various data storage systems including LocalStorage, Firestore, and MongoDB (more storage systems to be supported). The library simplifies data management tasks by abstracting away the underlying storage implementation details and providing a unified interface.
yarn install tspa
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.
TransactionalCrudRepository
, allowing transactional operations for
MongoDB transactions.# .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: 'johndoe@email.com'
}
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 is an implementation of the CrudRepository
interface tailored for Firestore. It offers
seamless
integration with Firestore storage.
# .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: 'johndoe@email.com'
}
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
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.
# .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: 'johndoe@email.com'
};
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);
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.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
TransactionalCrudRepository
for MongoDB.👤 Anietie Asuquo hello@anietieasuquo.com
Contributions, issues and feature requests are welcome!
Feel free to
check issues page. You can also take a look at
the contributing guide.
Copyright © 2024 Anietie Asuquo hello@anietieasuquo.com.
This project is MIT licensed.
FAQs
TypeScript Persistence API
The npm package tspa receives a total of 2 weekly downloads. As such, tspa popularity was classified as not popular.
We found that tspa demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.