@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 CHANGED
@@ -4,3 +4,6 @@ GOOGLE_CLIENT_SECRET=your_client_secret
4
4
  GOOGLE_REDIRECT_URL=your_redirect_url
5
5
  GOOGLE_ACCESS_TOKEN=your_access_token
6
6
  GOOGLE_REFRESH_TOKEN=your_refresh_token
7
+
8
+ # Used for testing purposes
9
+ GOOGLE_ACCESS_TOKEN=your_pasted_token_here
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