@graffiti-garden/implementation-local 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -0
- package/dist/database.browser.js +27 -0
- package/dist/database.browser.js.map +1 -0
- package/dist/database.cjs.js +2 -0
- package/dist/database.cjs.js.map +1 -0
- package/dist/database.js +2 -0
- package/dist/database.js.map +1 -0
- package/dist/index.browser.js +32 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/session-manager.browser.js +2 -0
- package/dist/session-manager.browser.js.map +1 -0
- package/dist/session-manager.cjs.js +2 -0
- package/dist/session-manager.cjs.js.map +1 -0
- package/dist/session-manager.js +2 -0
- package/dist/session-manager.js.map +1 -0
- package/dist/src/database.d.ts +57 -0
- package/dist/src/database.d.ts.map +1 -0
- package/dist/src/index.d.ts +26 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/session-manager.d.ts +22 -0
- package/dist/src/session-manager.d.ts.map +1 -0
- package/dist/src/synchronize.d.ts +25 -0
- package/dist/src/synchronize.d.ts.map +1 -0
- package/dist/src/tests.spec.d.ts +2 -0
- package/dist/src/tests.spec.d.ts.map +1 -0
- package/dist/src/utilities.d.ts +15 -0
- package/dist/src/utilities.d.ts.map +1 -0
- package/dist/synchronize.browser.js +18 -0
- package/dist/synchronize.browser.js.map +1 -0
- package/dist/synchronize.cjs.js +2 -0
- package/dist/synchronize.cjs.js.map +1 -0
- package/dist/synchronize.js +2 -0
- package/dist/synchronize.js.map +1 -0
- package/dist/utilities.browser.js +2 -0
- package/dist/utilities.browser.js.map +1 -0
- package/dist/utilities.cjs.js +2 -0
- package/dist/utilities.cjs.js.map +1 -0
- package/dist/utilities.js +2 -0
- package/dist/utilities.js.map +1 -0
- package/package.json +110 -0
- package/src/database.ts +450 -0
- package/src/index.ts +58 -0
- package/src/session-manager.ts +122 -0
- package/src/synchronize.ts +154 -0
- package/src/tests.spec.ts +16 -0
- package/src/utilities.ts +128 -0
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Graffiti Local Implementation
|
|
2
|
+
|
|
3
|
+
This is a local implementation of the [Graffiti API](https://api.graffiti.garden/classes/Graffiti.html)
|
|
4
|
+
using [PouchDB](https://pouchdb.com/).
|
|
5
|
+
By default, it automatically persist data in both the browser and Node.js using
|
|
6
|
+
whatever stoage is available in each environment.
|
|
7
|
+
It can also be configured to use an external [CouchDB](https://couchdb.apache.org/) instance,
|
|
8
|
+
but using a remote database is insecure.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
In node.js, simply install the package with npm:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @graffiti-garden/implementation-local
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
In the browser, you can use a CDN like jsDelivr. Add an import map the the `<head>` of your HTML file:
|
|
19
|
+
```html
|
|
20
|
+
<head>
|
|
21
|
+
<script type="importmap">
|
|
22
|
+
{
|
|
23
|
+
"imports": {
|
|
24
|
+
"@graffiti-garden/implementation-local": "https://cdn.jsdelivr.net/npm/@graffiti-garden/implementation-local/dist/index.browser.js"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
</script>
|
|
28
|
+
</head>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
In either case, you can then import the package like so:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { GraffitiLocal } from "@graffiti-garden/implementation-local";
|
|
35
|
+
const graffiti = new GraffitiLocal()
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
This is an implementation of the Graffiti API,
|
|
41
|
+
so to use it please refer to the [Graffiti API documentation](https://api.graffiti.garden/classes/Graffiti.html).
|
|
42
|
+
|
|
43
|
+
The only major difference is that options can be passed to the constructor
|
|
44
|
+
to configure the PouchDB instance.
|
|
45
|
+
The PouchDB instance will create a local database by default,
|
|
46
|
+
in either the browser or Node.js.
|
|
47
|
+
However, you could configure it to use an external CouchDB instance as follows:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { GraffitiLocal } from "@graffiti-garden/implementation-local";
|
|
51
|
+
const graffiti = new GraffitiLocal({
|
|
52
|
+
pouchDBOptions: {
|
|
53
|
+
name: "http://admin:password@localhost:5984/graffiti",
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
See the [PouchDB documentation](https://pouchdb.com/api.html#create_database) for more options.
|
|
59
|
+
|
|
60
|
+
## Extending
|
|
61
|
+
|
|
62
|
+
Pieces of this implementation can be pulled out to use in other implementations.
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
// The basic database interface based on PouchDB
|
|
66
|
+
import { GraffitiLocalDatabase } from "@graffiti-garden/implementation-local/database";
|
|
67
|
+
// A wrapper around any implementation of the database methods that provides synchronize
|
|
68
|
+
import { GraffitiSynchronize } from "@graffiti-garden/implementation-local/synchronize";
|
|
69
|
+
// The log in and out methods and events - insecure but useful for testing
|
|
70
|
+
import { GraffitiLocalSessionManager } from "@graffiti-garden/implementation-local/session-manager";
|
|
71
|
+
// Various utilities for implementing the Graffiti API
|
|
72
|
+
import * as GraffitiUtilities from "@graffiti-garden/implementation-local/utilities";
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## TODO
|
|
76
|
+
|
|
77
|
+
- Remove tombstones according to the `tombstoneRetention` setting.
|
|
78
|
+
- Implement `listOrphans` and `listChannels`.
|