Skip to content

Commit 2a770ff

Browse files
chore: add localforage package
1 parent 0e3b3bc commit 2a770ff

21 files changed

Lines changed: 5777 additions & 56 deletions

.changeset/yummy-trains-take.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@kalisio/feathers-localforage": major
3+
---
4+
5+
ADD localforage package

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"build:feathers-s3": "pnpm --filter @kalisio/feathers-s3 build",
1313
"build:feathers-tasks": "pnpm --filter @kalisio/feathers-tasks build",
1414
"build:feathers-webpush": "pnpm --filter @kalisio/feathers-webpush build",
15+
"build:feathers-localforage": "pnpm --filter @kalisio/feathers-localforage build",
1516
"changeset": "changeset",
1617
"changeset:release": "pnpm build && changeset publish",
1718
"changeset:status": "changeset status",
@@ -26,6 +27,7 @@
2627
"lint:feathers-s3": "pnpm --filter @kalisio/feathers-s3 lint",
2728
"lint:feathers-tasks": "pnpm --filter @kalisio/feathers-tasks lint",
2829
"lint:feathers-webpush": "pnpm --filter @kalisio/feathers-webpush lint",
30+
"lint:feathers-localforage": "pnpm --filter @kalisio/feathers-localforage lint",
2931
"posttest": "pnpm lcov-result-merger --prepend-source-files 'packages/*/coverage/lcov.info' coverage/lcov.info",
3032
"prepare": "husky",
3133
"pretest": "mkdir -p coverage",
@@ -36,7 +38,8 @@
3638
"test:feathers-mongodb-management": "pnpm --filter @kalisio/feathers-mongodb-management test",
3739
"test:feathers-s3": "pnpm --filter @kalisio/feathers-s3 test",
3840
"test:feathers-tasks": "pnpm --filter @kalisio/feathers-tasks test",
39-
"test:feathers-webpush": "pnpm --filter @kalisio/feathers-webpush test"
41+
"test:feathers-webpush": "pnpm --filter @kalisio/feathers-webpush test",
42+
"test:feathers-localforage": "pnpm --filter @kalisio/feathers-localforage test"
4043
},
4144
"keywords": [
4245
"keycloak",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: "2" # required to adjust maintainability checks
2+
checks:
3+
argument-count:
4+
config:
5+
threshold: 6
6+
complex-logic:
7+
config:
8+
threshold: 50
9+
file-lines:
10+
config:
11+
threshold: 300
12+
method-complexity:
13+
config:
14+
threshold: 6
15+
method-count:
16+
config:
17+
threshold: 30
18+
method-lines:
19+
config:
20+
threshold: 100
21+
nested-control-flow:
22+
config:
23+
threshold: 6
24+
return-statements:
25+
config:
26+
threshold: 6
27+
similar-code:
28+
config:
29+
threshold: 50
30+
identical-code:
31+
config:
32+
threshold: 25
33+
plugins:
34+
duplication:
35+
enabled: true
36+
config:
37+
count_threshold: 3
38+
exclude_patterns:
39+
- "**/test/*"
40+
- "**/adapter-tests/*"
41+
- "**/dist/*"
42+
- "**/*.dist.js"
43+
- "**/templates/*"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.editorconfig
2+
.jshintrc
3+
.travis.yml
4+
.istanbul.yml
5+
.babelrc
6+
.idea/
7+
.vscode/
8+
test/
9+
coverage/
10+
.github/
11+
lib/
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"verbose": false,
3+
"tempDirectory": "./coverage/.tmp",
4+
"extension": [
5+
".ts",
6+
".tsx",
7+
".js"
8+
],
9+
"exclude": [
10+
"**/public/*",
11+
"**/test/*",
12+
"**/dist/*",
13+
"**/*.dist.js",
14+
"**/templates/*"
15+
],
16+
"print": "detail",
17+
"reporter": [
18+
"html",
19+
"text",
20+
"text-summary",
21+
"lcov"
22+
],
23+
"watermarks": {
24+
"statements": [
25+
70,
26+
90
27+
],
28+
"lines": [
29+
70,
30+
90
31+
],
32+
"functions": [
33+
70,
34+
90
35+
],
36+
"branches": [
37+
70,
38+
90
39+
]
40+
}
41+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Change Log
2+
3+
## [v1.0.1](https://github.com/feathersjs-offline/feathers-localForage/compare/v1.0.0...v1.0.1.) (2021-10-25)
4+
5+
Added better testing for valid drivers. Added GitHub actions for automation.
6+
7+
## [v1.0.0](https://github.com/feathersjs-offline/feathers-localForage/tree/v1.0.0) (2021-10-23)
8+
9+
LocalForage working [\#1](https://github.com/feathersjs-offline/feathers-localForage/pull/1) ([Michael Hillerström](https://github.com/mhillerstrom))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2021 Feathers
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# \@kalisio/localforage
2+
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)
8+
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.
10+
11+
```bash
12+
$ npm install --save @kalisio/localforage
13+
```
14+
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+
```
87+
88+
## License
89+
90+
Copyright (c) 2021 by Feathers
91+
92+
Licensed under the [MIT license](LICENSE).
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"name": "@kalisio/feathers-localforage",
3+
"version": "1.2.0",
4+
"description": "A FeathersJS client side service based on localforage that persists to IndexedDB, WebSQL, or LocalStorage",
5+
"keywords": [
6+
"feathers",
7+
"feathers-plugin",
8+
"feathersjs-offline",
9+
"offline-first",
10+
"mobile"
11+
],
12+
"author": {
13+
"name": "Feathersjs-offline contributors",
14+
"email": "feathersjs-offline@hillerstrom.name",
15+
"url": "https://github.com/feathersjs-offline"
16+
},
17+
"contributors": [
18+
{
19+
"name": "Kalisio contributors",
20+
"url": "https://github.com/kalisio"
21+
}
22+
],
23+
"bugs": {
24+
"url": "https://github.com/feathersjs-offline/localforage/issues"
25+
},
26+
"homepage": "https://github.com/feathersjs-offline/localforage",
27+
"license": "MIT",
28+
"main": "lib/feathers-localforage.js",
29+
"type": "module",
30+
"directories": {
31+
"src": "src",
32+
"lib": "lib",
33+
"test": "test"
34+
},
35+
"files": [
36+
"src",
37+
"lib"
38+
],
39+
"funding": {
40+
"type": "opencollective",
41+
"url": "https://opencollective.com/feathers"
42+
},
43+
"repository": {
44+
"type": "git",
45+
"url": "git://github.com/feathersjs-offline/localforage.git"
46+
},
47+
"engines": {
48+
"node": ">= 12"
49+
},
50+
"standard": {
51+
"ignore": ["lib/"]
52+
},
53+
"scripts": {
54+
"test": "npm run vitest",
55+
"vitest": "vitest run",
56+
"test:watch": "vitest",
57+
"lint": "standard --fix",
58+
"prepublish": "npm run build",
59+
"publish": "git push origin --tags && git push origin",
60+
"build": "vite build",
61+
"release:patch": "npm version --force patch && npm publish --access public",
62+
"release:minor": "npm version --force minor && npm publish --access public",
63+
"release:major": "npm version --force major && npm publish --access public"
64+
},
65+
"dependencies": {
66+
"@feathersjs/adapter-commons": "catalog:",
67+
"@feathersjs/commons": "catalog:",
68+
"@feathersjs/errors": "catalog:",
69+
"debug": "catalog:",
70+
"localforage": "catalog:",
71+
"sift": "catalog:"
72+
},
73+
"devDependencies": {
74+
"@feathersjs/adapter-tests": "catalog:",
75+
"@feathersjs/express": "catalog:",
76+
"@feathersjs/feathers": "catalog:",
77+
"@feathersjs/socketio": "catalog:",
78+
"@types/debug": "catalog:",
79+
"@types/express": "catalog:",
80+
"@types/node": "catalog:",
81+
"chai": "catalog:",
82+
"core-js": "catalog:",
83+
"cross-env": "catalog:",
84+
"eslint-config-standard": "catalog:",
85+
"fs-extra": "catalog:",
86+
"npm-check-updates": "catalog:",
87+
"nyc": "catalog:",
88+
"parallel-webpack": "catalog:",
89+
"shx": "catalog:",
90+
"ts-node": "catalog:",
91+
"tslint": "catalog:",
92+
"typescript": "catalog:",
93+
"vite": "catalog:",
94+
"vite-plugin-node-polyfills": "catalog:",
95+
"webpack": "catalog:",
96+
"webpack-merge": "catalog:"
97+
}
98+
}

0 commit comments

Comments
 (0)