@docstack/pouchdb-adapter-googledrive 0.0.6 → 0.0.9
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/.env.example +3 -0
- package/README.md +72 -72
- package/compaction_test.log +725 -0
- package/docs/DEBUG_BIDIRECTIONAL_REPLICATION.ipynb +481 -0
- package/{DOCUMENTATION.md → docs/DOCUMENTATION.md} +61 -0
- package/docs/PROMISE_SUPPORT.md +75 -0
- package/docs/REPLICATION_ISSUE.md +63 -0
- package/emulation-test.log +163 -0
- package/failing_test.log +31 -0
- package/final_test.log +2620 -0
- package/jest.config.js +8 -8
- package/lib/adapter.d.ts +3 -0
- package/lib/adapter.js +373 -163
- package/lib/cache.d.ts +0 -0
- package/lib/cache.js +0 -0
- package/lib/client.d.ts +5 -0
- package/lib/client.js +43 -20
- package/lib/drive.d.ts +12 -2
- package/lib/drive.js +373 -189
- package/lib/index.d.ts +0 -0
- package/lib/index.js +4 -3
- package/lib/types.d.ts +6 -0
- package/lib/types.js +0 -0
- package/live_test.log +1209 -0
- package/package.json +47 -40
- package/test_output.log +563 -0
- package/test_output_2.log +1408 -0
- package/test_output_3.log +2445 -0
package/.env.example
CHANGED
package/README.md
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
# PouchDB Adapter for Google Drive
|
|
2
|
-
|
|
3
|
-
A persistent, serverless PouchDB adapter that uses Google Drive as a backend storage. Designed for high concurrency, large datasets (via lazy loading), and offline resilience.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **🚀 Append-Only Log**: Uses an efficient append-only log pattern for fast, conflict-free writes.
|
|
8
|
-
- **⚡ Lazy Loading**: Optimizes memory and bandwidth by loading only the **Index** into memory. Document bodies are fetched on-demand.
|
|
9
|
-
- **🛡️ Optimistic Concurrency Control**: Uses ETag-based locking on metadata to prevent race conditions.
|
|
10
|
-
- **📦 Auto-Compaction**: Automatically merges logs for performance.
|
|
11
|
-
- **🌍 Universal**: Works natively in Node.js 18+, Browsers, and Edge environments (no `googleapis` dependency).
|
|
12
|
-
|
|
13
|
-
## Requirements
|
|
14
|
-
|
|
15
|
-
- **Node.js 18+** (for global `fetch` support) or a modern browser.
|
|
16
|
-
|
|
17
|
-
## Installation
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
npm install @docstack/pouchdb-adapter-googledrive
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Usage
|
|
24
|
-
|
|
25
|
-
The adapter is initialized as a plugin with your Google Drive access token.
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
import PouchDB from 'pouchdb-core';
|
|
29
|
-
import GoogleDriveAdapter from '@docstack/pouchdb-adapter-googledrive';
|
|
30
|
-
|
|
31
|
-
// 1. Initialize the Adapter Plugin Factory
|
|
32
|
-
const adapterPlugin = GoogleDriveAdapter({
|
|
33
|
-
accessToken: 'YOUR_GOOGLE_ACCESS_TOKEN',
|
|
34
|
-
folderName: 'my-app-db-folder', // Root folder in Drive
|
|
35
|
-
pollingIntervalMs: 2000 // Optional: check for remote changes
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// 2. Register Plugin
|
|
39
|
-
PouchDB.plugin(adapterPlugin);
|
|
40
|
-
|
|
41
|
-
// 3. Create Database
|
|
42
|
-
const db = new PouchDB('user_db', {
|
|
43
|
-
adapter: 'googledrive'
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
await db.post({ title: 'Hello World' });
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### Dynamic Tokens
|
|
50
|
-
|
|
51
|
-
If your token expires, you can provide an async function that returns a valid token:
|
|
52
|
-
|
|
53
|
-
```typescript
|
|
54
|
-
const adapterPlugin = GoogleDriveAdapter({
|
|
55
|
-
accessToken: async () => {
|
|
56
|
-
const session = await getMySession();
|
|
57
|
-
return session.accessToken;
|
|
58
|
-
},
|
|
59
|
-
folderName: 'my-app-db'
|
|
60
|
-
});
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## Architecture
|
|
64
|
-
|
|
65
|
-
The adapter implements a **"Remote-First"** architecture:
|
|
66
|
-
- **Lazy Loading**: `db.get(id)` fetches data on-demand from Drive.
|
|
67
|
-
- **Caching**: Changes are indexed locally but bodies are cached in an LRU cache.
|
|
68
|
-
- **Resilience**: Writes use optimistic locking to handle multi-client concurrency safer.
|
|
69
|
-
|
|
70
|
-
## License
|
|
71
|
-
|
|
72
|
-
CC-BY-SA-4.0
|
|
1
|
+
# PouchDB Adapter for Google Drive
|
|
2
|
+
|
|
3
|
+
A persistent, serverless PouchDB adapter that uses Google Drive as a backend storage. Designed for high concurrency, large datasets (via lazy loading), and offline resilience.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **🚀 Append-Only Log**: Uses an efficient append-only log pattern for fast, conflict-free writes.
|
|
8
|
+
- **⚡ Lazy Loading**: Optimizes memory and bandwidth by loading only the **Index** into memory. Document bodies are fetched on-demand.
|
|
9
|
+
- **🛡️ Optimistic Concurrency Control**: Uses ETag-based locking on metadata to prevent race conditions.
|
|
10
|
+
- **📦 Auto-Compaction**: Automatically merges logs for performance.
|
|
11
|
+
- **🌍 Universal**: Works natively in Node.js 18+, Browsers, and Edge environments (no `googleapis` dependency).
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
- **Node.js 18+** (for global `fetch` support) or a modern browser.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @docstack/pouchdb-adapter-googledrive
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
The adapter is initialized as a plugin with your Google Drive access token.
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import PouchDB from 'pouchdb-core';
|
|
29
|
+
import GoogleDriveAdapter from '@docstack/pouchdb-adapter-googledrive';
|
|
30
|
+
|
|
31
|
+
// 1. Initialize the Adapter Plugin Factory
|
|
32
|
+
const adapterPlugin = GoogleDriveAdapter({
|
|
33
|
+
accessToken: 'YOUR_GOOGLE_ACCESS_TOKEN',
|
|
34
|
+
folderName: 'my-app-db-folder', // Root folder in Drive
|
|
35
|
+
pollingIntervalMs: 2000 // Optional: check for remote changes
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// 2. Register Plugin
|
|
39
|
+
PouchDB.plugin(adapterPlugin);
|
|
40
|
+
|
|
41
|
+
// 3. Create Database
|
|
42
|
+
const db = new PouchDB('user_db', {
|
|
43
|
+
adapter: 'googledrive'
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
await db.post({ title: 'Hello World' });
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Dynamic Tokens
|
|
50
|
+
|
|
51
|
+
If your token expires, you can provide an async function that returns a valid token:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
const adapterPlugin = GoogleDriveAdapter({
|
|
55
|
+
accessToken: async () => {
|
|
56
|
+
const session = await getMySession();
|
|
57
|
+
return session.accessToken;
|
|
58
|
+
},
|
|
59
|
+
folderName: 'my-app-db'
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Architecture
|
|
64
|
+
|
|
65
|
+
The adapter implements a **"Remote-First"** architecture:
|
|
66
|
+
- **Lazy Loading**: `db.get(id)` fetches data on-demand from Drive.
|
|
67
|
+
- **Caching**: Changes are indexed locally but bodies are cached in an LRU cache.
|
|
68
|
+
- **Resilience**: Writes use optimistic locking to handle multi-client concurrency safer.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
CC-BY-SA-4.0
|