Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sebastianspeitel/proxystore
Persistent object storage using proxies
https://github.com/sebastianspeitel/proxystore
es6-proxies npm-package storage
Last synced: 1 day ago
JSON representation
Persistent object storage using proxies
- Host: GitHub
- URL: https://github.com/sebastianspeitel/proxystore
- Owner: SebastianSpeitel
- License: gpl-3.0
- Created: 2020-02-22T11:12:46.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-29T17:58:32.000Z (17 days ago)
- Last Synced: 2024-10-29T19:16:32.200Z (17 days ago)
- Topics: es6-proxies, npm-package, storage
- Language: TypeScript
- Size: 356 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![Tests](https://github.com/SebastianSpeitel/proxystore/workflows/Tests/badge.svg?branch=master)
[![install size](https://packagephobia.now.sh/badge?p=@sebastianspeitel/proxystore)](https://packagephobia.now.sh/result?p=@sebastianspeitel/proxystore)# proxystore
Persistent object storage using proxies
## Usage
### Short way
```javascript
import proxy, { ProxyStoreJSON as ProxyStore } from "../src";const store = proxy(ProxyStore, { path: "store.json" });
store.foo = "bar";
```Now you can use `store` like any other object and it will be saved in `store.json`.
### Long way
```javascript
import { ProxyStoreJSON as ProxyStore } from "../src";const store = new ProxyStore({ foo: "baz" }, { path: "store.json" }).store;
store.foo = "bar";
```## TypeScript
All methods take a type to use for the store, so you can provide it for autocompletion.
### Example
```typescript
interface FooBar {
foo: number;
bar: string;
}const store = proxy(ProxyStore, { path: "store.json" });
store.foo; // works
store.baz; // Property 'baz' does not exist on type 'FooBar'
```## Extensions
You can implement your own ways of serializing the store. Just extends the class `ProxyStore` overwrite the methods you want and call `proxy` with your own class as parameter.
### Example
```javascript
class MyProxyStore extends ProxyStore {
get(path: PropertyKey[], prop: PropertyKey): any {
console.log(`Property ${[...path, prop].join(".")} requested`);
return super.get(path, prop);
}
}const store = proxy({ foo: "bar" }, MyProxyStore);
store.foo; // Property foo requested
```