Skip to content

Commit 1ebc464

Browse files
doc: start add doc localforage
1 parent a5d55ab commit 1ebc464

4 files changed

Lines changed: 83 additions & 104 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# localforage
2+
3+
[@kalisio/localforage](https://github.com/kalisio/localforage/) is a database service adapter wrapping `localForage` that persists to either `IndexedDB`, `WebSQL`, or `LocalStorage` making it very useful for mobile and offline-first applications with the additional ability to seamlessly handle Blobs, TypedArrays, and other JS objects.
4+
5+
> __Important:__ `@feathersjs-offline/localforage` implements the [Feathers Common database adapter API](https://docs.feathersjs.com/api/databases/common.html) and [querying syntax](https://docs.feathersjs.com/api/databases/querying.html).
6+
7+
## API
8+
9+
### `service(options)`
10+
11+
Returns a new service instance initialized with the given options.
12+
13+
```js
14+
const service = require('@feathersjs-offline/localforage');
15+
16+
app.use('/messages', service({
17+
storage: ['IndexedDB', 'localStorage']
18+
}));
19+
app.use('/messages', service({ storage, id, startId, name, store, paginate }));
20+
```
21+
22+
__Options:__
23+
24+
- `storage` (*optional*, default: `'INDEXEDDB'`) - The storage backend. Must be one or more of `'INDEXEDDB'`, `'WEBSQL'`, or `'LOCALSTORAGE'`. The adapter will use the same sequence as fall-back if the desired storage type is not supported on the actual device. Alternatively, you can supply an array of storage backends determining the priority of your choice.
25+
- `version` (*optional*, default: `1.0`) - `localforage` driver version to use. Currently only `1.0` exists.
26+
- `size` (*optional*, default `4980736`) - The maximum database size required. Default DB size is _JUST UNDER_ 5MB, as it's the highest size we can use without a prompt in any browser.
27+
- `id` (*optional*, default: `'id'`) - The name of the id field property.
28+
- `name` (*optional*, default: `'feathersjs-offline'`) - The name of the underlying localforage database. With local storage, this is used as a key prefix.
29+
- `storeName` (*optional*, default: `'feathers'`) - The name of the datastore. Depending on the storage backend it could be the name of the key/value table in the database (eg WebSQL) or the key (eg local storage). Must be alphanumeric, with underscores.
30+
- `store` (*optional*) - An object with id to item assignments to pre-initialize the data store.
31+
- `dates` (*optional*, default `false`) - Convert ISO-formatted date strings to `Date` objects in result sets.
32+
- `events` (*optional*) - A list of [custom service events](https://docs.feathersjs.com/api/events.html#custom-events) sent by this service.
33+
- `paginate` (*optional*) - A [pagination object](https://docs.feathersjs.com/api/databases/common.html#pagination) containing a `default` and `max` page size.
34+
- `whitelist` (*optional*) - A list of additional query parameters to allow.
35+
- `multi` (*optional*) - Allow `create` with arrays and `update` and `remove` with `id` `null` to change multiple items. Can be `true` for all methods or an array of allowed methods (e.g. `[ 'remove', 'create' ]`).
36+
- `reuseKeys` (*optional*, default: `false`) Allow duplicate keys (see `name`) i.e. last definition wins. Mostly useful for demonstration and testing purposes.
37+
38+
## Storing Blobs, TypedArrays, and other JS objects
39+
40+
As this is an implementation on top of `localForage` you can store any type in `@feathersjs-offline/localforage`; you aren't limited to strings like in `localStorage`. Even if `localStorage` is your storage backend, `@feathersjs-offline/localforage` automatically does JSON.parse() and JSON.stringify() when getting/setting values.
41+
42+
`feathers-localforage` supports storing all native JS objects that can be serialized to JSON, as well as ArrayBuffers, Blobs, and TypedArrays. Check the [localForage API docs](https://localforage.github.io/localForage/#data-api-setitem) for a full list of types supported. In addition, setting the option `dates` to `true` will make sure any ISO-formatted dates in your results will in fact be date objects and not text strings.
43+
44+
> All types are supported in every storage backend, though storage limits in `localStorage` make storing many large Blobs impossible.
45+
46+
We default to `indexedDB` if available and fall-back to `localStorage` as a last resort.
47+
48+
49+
## Example
50+
51+
See the [clients](https://docs.feathersjs.com/api/client.html) chapter for more information about using Feathers in the browser and React Native.
52+
53+
### Browser
54+
55+
```html
56+
<script type="text/javascript" src="//unpkg.com/@feathersjs/client@^4.5.11/dist/feathers.js"></script>
57+
<script type="text/javascript" src="//unpkg.com/@feathersjs-offline/localforage@^1.0.0/dist/localforage.js"></script>
58+
<script type="text/javascript">
59+
var service = feathersjsOfflineLocalforage.init({
60+
storage: ['indexeddb', 'websql', 'localStorage']
61+
});
62+
var app = feathers().use('/messages', service);
63+
64+
var messages = app.service('messages');
65+
66+
messages.on('created', function(message) {
67+
console.log('Someone created a message', message);
68+
});
69+
70+
messages.create({
71+
text: 'Message created in browser'
72+
});
73+
</script>
74+
```

packages/feathers-localforage/.npmignore

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/feathers-localforage/CHANGELOG.md

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 9 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,17 @@
1-
# \@kalisio/localforage
1+
# feathers-localforage
22

3-
[![Latest Release](https://img.shields.io/github/v/tag/kalisio/feathers-localforage?sort=semver&label=latest)](https://github.com/kalisio/feathers-localforage/releases)
4-
[![CI](https://github.com/kalisio/feathers-localforage/actions/workflows/main.yaml/badge.svg)](https://github.com/kalisio/feathers-localforage/actions/workflows/main.yaml)
5-
[![Code Climate](https://codeclimate.com/github/kalisio/feathers-localforage/badges/gpa.svg)](https://codeclimate.com/github/kalisio/feathers-localforage)
6-
[![Test Coverage](https://codeclimate.com/github/kalisio/feathers-localforage/badges/coverage.svg)](https://codeclimate.com/github/kalisio/feathers-localforage/coverage)
7-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3+
__
84

9-
[@kalisio/localforage](https://github.com/kalisio/localforage/) is a database service adapter wrapping `localForage` that persists to either `IndexedDB`, `WebSQL`, or `LocalStorage` making it very useful for mobile and offline-first applications with the additional ability to seamlessly handle Blobs, TypedArrays, and other JS objects.
5+
---
106

11-
```bash
12-
$ npm install --save @kalisio/localforage
13-
```
7+
## Documentation
148

15-
> __Important:__ `@feathersjs-offline/localforage` implements the [Feathers Common database adapter API](https://docs.feathersjs.com/api/databases/common.html) and [querying syntax](https://docs.feathersjs.com/api/databases/querying.html).
16-
17-
The changelog of this fork is managed through GitHub [Milestones](https://github.com/kalisio/feathers-localforage/milestones) and related issues.
18-
19-
## API
20-
21-
### `service(options)`
22-
23-
Returns a new service instance initialized with the given options.
24-
25-
```js
26-
const service = require('@feathersjs-offline/localforage');
27-
28-
app.use('/messages', service({
29-
storage: ['IndexedDB', 'localStorage']
30-
}));
31-
app.use('/messages', service({ storage, id, startId, name, store, paginate }));
32-
```
33-
34-
__Options:__
35-
36-
- `storage` (*optional*, default: `'INDEXEDDB'`) - The storage backend. Must be one or more of `'INDEXEDDB'`, `'WEBSQL'`, or `'LOCALSTORAGE'`. The adapter will use the same sequence as fall-back if the desired storage type is not supported on the actual device. Alternatively, you can supply an array of storage backends determining the priority of your choice.
37-
- `version` (*optional*, default: `1.0`) - `localforage` driver version to use. Currently only `1.0` exists.
38-
- `size` (*optional*, default `4980736`) - The maximum database size required. Default DB size is _JUST UNDER_ 5MB, as it's the highest size we can use without a prompt in any browser.
39-
- `id` (*optional*, default: `'id'`) - The name of the id field property.
40-
- `name` (*optional*, default: `'feathersjs-offline'`) - The name of the underlying localforage database. With local storage, this is used as a key prefix.
41-
- `storeName` (*optional*, default: `'feathers'`) - The name of the datastore. Depending on the storage backend it could be the name of the key/value table in the database (eg WebSQL) or the key (eg local storage). Must be alphanumeric, with underscores.
42-
- `store` (*optional*) - An object with id to item assignments to pre-initialize the data store.
43-
- `dates` (*optional*, default `false`) - Convert ISO-formatted date strings to `Date` objects in result sets.
44-
- `events` (*optional*) - A list of [custom service events](https://docs.feathersjs.com/api/events.html#custom-events) sent by this service.
45-
- `paginate` (*optional*) - A [pagination object](https://docs.feathersjs.com/api/databases/common.html#pagination) containing a `default` and `max` page size.
46-
- `whitelist` (*optional*) - A list of additional query parameters to allow.
47-
- `multi` (*optional*) - Allow `create` with arrays and `update` and `remove` with `id` `null` to change multiple items. Can be `true` for all methods or an array of allowed methods (e.g. `[ 'remove', 'create' ]`).
48-
- `reuseKeys` (*optional*, default: `false`) Allow duplicate keys (see `name`) i.e. last definition wins. Mostly useful for demonstration and testing purposes.
49-
50-
## Storing Blobs, TypedArrays, and other JS objects
51-
52-
As this is an implementation on top of `localForage` you can store any type in `@feathersjs-offline/localforage`; you aren't limited to strings like in `localStorage`. Even if `localStorage` is your storage backend, `@feathersjs-offline/localforage` automatically does JSON.parse() and JSON.stringify() when getting/setting values.
53-
54-
`feathers-localforage` supports storing all native JS objects that can be serialized to JSON, as well as ArrayBuffers, Blobs, and TypedArrays. Check the [localForage API docs](https://localforage.github.io/localForage/#data-api-setitem) for a full list of types supported. In addition, setting the option `dates` to `true` will make sure any ISO-formatted dates in your results will in fact be date objects and not text strings.
55-
56-
> All types are supported in every storage backend, though storage limits in `localStorage` make storing many large Blobs impossible.
57-
58-
We default to `indexedDB` if available and fall-back to `localStorage` as a last resort.
59-
60-
61-
## Example
62-
63-
See the [clients](https://docs.feathersjs.com/api/client.html) chapter for more information about using Feathers in the browser and React Native.
64-
65-
### Browser
66-
67-
```html
68-
<script type="text/javascript" src="//unpkg.com/@feathersjs/client@^4.5.11/dist/feathers.js"></script>
69-
<script type="text/javascript" src="//unpkg.com/@feathersjs-offline/localforage@^1.0.0/dist/localforage.js"></script>
70-
<script type="text/javascript">
71-
var service = feathersjsOfflineLocalforage.init({
72-
storage: ['indexeddb', 'websql', 'localStorage']
73-
});
74-
var app = feathers().use('/messages', service);
75-
76-
var messages = app.service('messages');
77-
78-
messages.on('created', function(message) {
79-
console.log('Someone created a message', message);
80-
});
81-
82-
messages.create({
83-
text: 'Message created in browser'
84-
});
85-
</script>
86-
```
9+
Detailed documentation is available at the following [link](https://kalisio.github.io/feathers-ekosystem/pacakges/feathers-localforage).
8710

8811
## License
8912

90-
Copyright (c) 2021 by Feathers
91-
9213
Licensed under the [MIT license](LICENSE).
14+
15+
Copyright (c) 2026 [Kalisio](https://kalisio.com)
16+
17+
[![Kalisio](https://kalisio.github.io/kalisioscope/kalisio/kalisio-logo-light-256x96.png)](https://kalisio.com)

0 commit comments

Comments
 (0)