Compare commits

..

No commits in common. "master" and "v2.0.14" have entirely different histories.

6 changed files with 3007 additions and 4036 deletions

View File

@ -5,7 +5,7 @@
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "webstore",
"description": "A high-performance storage solution for web applications using IndexedDB.",
"description": "high performance storage in the browser using indexed db",
"npmPackagename": "@push.rocks/webstore",
"license": "MIT",
"projectDomain": "push.rocks",
@ -19,9 +19,7 @@
"data persistence",
"storage solution",
"typed requests",
"performance optimization",
"API caching",
"efficient data management"
"performance optimization"
]
}
},

View File

@ -1,8 +1,8 @@
{
"name": "@push.rocks/webstore",
"version": "2.0.20",
"version": "2.0.14",
"private": false,
"description": "A high-performance storage solution for web applications using IndexedDB.",
"description": "high performance storage in the browser using indexed db",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
@ -14,22 +14,22 @@
"buildDocs": "tsdoc"
},
"devDependencies": {
"@git.zone/tsbuild": "^2.1.80",
"@git.zone/tsbuild": "^2.1.72",
"@git.zone/tsrun": "^1.2.46",
"@git.zone/tstest": "^1.0.90",
"@push.rocks/smartntml": "^2.0.4",
"@push.rocks/tapbundle": "^5.0.23",
"@types/node": "^20.12.12"
"@types/node": "^20.12.7"
},
"dependencies": {
"@api.global/typedrequest-interfaces": "^3.0.19",
"@push.rocks/lik": "^6.0.15",
"@apiglobal/typedrequest-interfaces": "^2.0.1",
"@push.rocks/lik": "^6.0.14",
"@push.rocks/smartenv": "^5.0.12",
"@push.rocks/smartjson": "^5.0.19",
"@push.rocks/smartpromise": "^4.0.3",
"@push.rocks/smartrx": "^3.0.7",
"@tempfix/idb": "^8.0.3",
"fake-indexeddb": "^5.0.2"
"fake-indexeddb": "^5.0.2",
"idb": "^8.0.0"
},
"browserslist": [
"last 1 chrome versions"
@ -56,13 +56,6 @@
"data persistence",
"storage solution",
"typed requests",
"performance optimization",
"API caching",
"efficient data management"
],
"homepage": "https://code.foss.global/push.rocks/webstore",
"repository": {
"type": "git",
"url": "https://code.foss.global/push.rocks/webstore.git"
}
}
"performance optimization"
]
}

6894
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

106
readme.md
View File

@ -1,5 +1,5 @@
# @push.rocks/webstore
High performance storage in the browser using IndexedDB.
high performance storage in the browser using indexed db
## Install
To install `@push.rocks/webstore`, use the following npm command:
@ -13,7 +13,7 @@ This will add it to your project's dependencies.
## Usage
The `@push.rocks/webstore` module provides a high-performance storage solution for web applications, leveraging IndexedDB. This guide demonstrates how to use `@push.rocks/webstore` to store, retrieve, check, and manage data in the browser efficiently.
### Basic Setup
### Setting Up
Before using `@push.rocks/webstore`, you must import and instantiate a `WebStore` class. Specify a database name (`dbName`) and a store name (`storeName`) in the options:
```typescript
@ -27,8 +27,8 @@ const myStore = new WebStore<{
});
```
### Initialization
To ensure that IndexedDB is set up correctly, call the `init` method before executing any CRUD operations:
### Initializing the Store
To ensure the IndexedDB is set up correctly, call the `init` method before executing CRUD operations:
```typescript
await myStore.init();
@ -79,31 +79,9 @@ const allKeys = await myStore.keys();
console.log(allKeys); // ['myKey', ...]
```
### Error Handling
One of the strengths of `WebStore` is its built-in error handling using `smartpromise`. All the asynchronous operations (`init`, `get`, `set`, `delete`, `clear`, `keys`) inherently handle errors gracefully by catching them and allowing you to handle them with standard JavaScript try-catch or using `.catch` on the promises.
#### Error Handling Example
In TypeScript, you can write try-catch blocks to handle errors:
```typescript
try {
await myStore.set('myKey', { some: 'data' });
} catch (error) {
console.error('Error storing data:', error);
}
try {
const myData = await myStore.get('myKey');
console.log(myData);
} catch (error) {
console.error('Error retrieving data:', error);
}
```
### Advanced Features: Typed Request Caching
### Typed Request Caching
`@push.rocks/webstore` also includes a feature for caching typed requests using the `TypedrequestCache` class. This is particularly useful for caching API requests and their responses.
#### Setting Up a Typed Request Cache
To set up a `TypedrequestCache`:
```typescript
@ -112,7 +90,6 @@ import { TypedrequestCache } from '@push.rocks/webstore';
const myCache = new TypedrequestCache('domainIdentifier');
```
#### Storing a Request and Its Response
Store a request and its response:
```typescript
@ -123,7 +100,6 @@ await myCache.setByRequest({
});
```
#### Retrieving a Cached Request
Retrieve a cached request by making a partial request:
```typescript
@ -134,77 +110,7 @@ const cachedResponse = await myCache.getByRequest({
console.log(cachedResponse); // { data: 'response data' }
```
### Comprehensive Usage Example
Here is a comprehensive example that covers initialization, data manipulation, and error handling:
```typescript
import { WebStore, TypedrequestCache } from '@push.rocks/webstore';
async function main() {
const myStore = new WebStore<{
[key: string]: any;
}>({
dbName: 'myDatabase',
storeName: 'myStore',
});
try {
await myStore.init();
// Set data
await myStore.set('myKey', { some: 'data' });
console.log('Data set successfully.');
// Get data
const myData = await myStore.get('myKey');
console.log('Retrieved data:', myData); // { some: 'data' }
// Check data existence
const exists = await myStore.check('myKey');
console.log('Key exists:', exists); // true
// Delete data
await myStore.delete('myKey');
console.log('Data deleted.');
// Clear store
await myStore.clear();
console.log('Store cleared.');
// Fetch all keys
const allKeys = await myStore.keys();
console.log('All keys:', allKeys); // []
} catch (error) {
console.error('Error during storage operations:', error);
}
// Typed Request Caching
const myCache = new TypedrequestCache('exampleDomain');
try {
await myCache.setByRequest({
method: 'GET',
request: 'https://example.com/api/data',
response: { data: 'response data' }
});
console.log('Typed request cached.');
const cachedResponse = await myCache.getByRequest({
method: 'GET',
request: 'https://example.com/api/data'
});
console.log('Cached response:', cachedResponse); // { data: 'response data' }
} catch (error) {
console.error('Error during typed request caching operations:', error);
}
}
main().catch(console.error);
```
### Conclusion
The `@push.rocks/webstore` package provides a flexible and efficient way to handle browser storage and caching. With features like error handling, typed request caching, and easy-to-use APIs, it can significantly improve performance and maintainability in web applications. For further exploration, feel free to explore the source code and tests provided in the repository.
`@push.rocks/webstore` provides a comprehensive API to leverage browser storage efficiently while maintaining high performance.
## License and Legal Information

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/webstore',
version: '2.0.20',
description: 'A high-performance storage solution for web applications using IndexedDB.'
version: '2.0.14',
description: 'high performance storage in the browser using indexed db'
}

View File

@ -8,11 +8,11 @@ import * as smartrx from '@push.rocks/smartrx';
export { lik, smartenv, smartjson, smartpromise, smartrx };
// apiglobal scope
import * as typedrequestInterfaces from '@api.global/typedrequest-interfaces';
import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
export { typedrequestInterfaces };
// thirdparty scope
import * as idb from '@tempfix/idb';
import * as idb from 'idb';
export { idb };