vue3-pouch 0.0.1
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/.vscode/extensions.json +3 -0
- package/LICENSE +21 -0
- package/README.md +62 -0
- package/package.json +27 -0
- package/src/composable/usePouchRef.ts +41 -0
- package/src/plugin/index.ts +1 -0
- package/src/types/index.d.ts +22 -0
- package/tsconfig.json +22 -0
- package/tsdown.config.ts +12 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Loseq
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# pouch-db-vue
|
|
2
|
+
|
|
3
|
+
A Vue 3 composable for reactive PouchDB integration.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Reactive PouchDB queries using Vue 3 composition API
|
|
8
|
+
- Real-time updates through PouchDB change events
|
|
9
|
+
- Type-safe database operations
|
|
10
|
+
- Supports find queries, document retrieval and allDocs
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install vue3-pouch pouchdb pouchdb-find
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { usePouchRef } from 'vue3-pouch'
|
|
22
|
+
import PouchDB from 'pouchdb-browser'
|
|
23
|
+
import find from 'pouchdb-find'
|
|
24
|
+
|
|
25
|
+
// Register PouchDB plugins
|
|
26
|
+
PouchDB.plugin(find)
|
|
27
|
+
|
|
28
|
+
// Initialize database
|
|
29
|
+
const db = new PouchDB<YourDocType>('my-database')
|
|
30
|
+
|
|
31
|
+
// Use in component
|
|
32
|
+
|
|
33
|
+
// Query by selector
|
|
34
|
+
const { content: posts } = usePouchRef({
|
|
35
|
+
selector: { type: 'post' }
|
|
36
|
+
}, db)
|
|
37
|
+
|
|
38
|
+
// Get single document
|
|
39
|
+
const { content: singleDoc } = usePouchRef('doc-id', db)
|
|
40
|
+
|
|
41
|
+
// Get all documents
|
|
42
|
+
const { content: allDocs } = usePouchRef('all', db)
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## API
|
|
47
|
+
|
|
48
|
+
### usePouchRef(findParams, db)
|
|
49
|
+
|
|
50
|
+
Creates a reactive reference to PouchDB query results.
|
|
51
|
+
|
|
52
|
+
Parameters:
|
|
53
|
+
- `findParams`: PouchDB find query object, document ID string, or "all"
|
|
54
|
+
- `db`: PouchDB database instance
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
- `content`: Readonly ref containing query results
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vue3-pouch",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "tsdown"
|
|
7
|
+
},
|
|
8
|
+
"peerDependencies": {
|
|
9
|
+
"pouchdb": "9.0.0",
|
|
10
|
+
"pouchdb-find": "9.0.0",
|
|
11
|
+
"vue": "^3.5.17"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@tsconfig/node22": "^22.0.2",
|
|
15
|
+
"@types/pouchdb": "^6.4.2",
|
|
16
|
+
"@types/pouchdb-find": "^7.3.3",
|
|
17
|
+
"@vitejs/plugin-vue": "^6.0.0",
|
|
18
|
+
"@vue/tsconfig": "^0.7.0",
|
|
19
|
+
"npm-run-all2": "^8.0.4",
|
|
20
|
+
"tsdown": "^0.14.2",
|
|
21
|
+
"typescript": "~5.8.0",
|
|
22
|
+
"unplugin-vue": "^7.0.1",
|
|
23
|
+
"vite": "npm:rolldown-vite@latest",
|
|
24
|
+
"vite-plugin-vue-devtools": "^7.7.7",
|
|
25
|
+
"vue-tsc": "^2.2.10"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ref, onMounted, onUnmounted, readonly } from 'vue'
|
|
2
|
+
import type { PouchDatabase, PouchExistingDocument, PouchFindParams, PouchFindResponse, PouchObserver } from '../types';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export function usePouchRef<C extends {}>(findParams: PouchFindParams<C> | "all" | string, db: PouchDatabase<C>) {
|
|
6
|
+
const contentWrite = ref<PouchFindResponse<C> | PouchExistingDocument<C> | null>(null)
|
|
7
|
+
|
|
8
|
+
const content = readonly(contentWrite)
|
|
9
|
+
|
|
10
|
+
let observer: PouchObserver | undefined;
|
|
11
|
+
onMounted(async () => {
|
|
12
|
+
if (findParams === "all") {
|
|
13
|
+
contentWrite.value = await db.allDocs()
|
|
14
|
+
}
|
|
15
|
+
else if (typeof findParams === 'string') {
|
|
16
|
+
contentWrite.value = await db.get(findParams)
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
contentWrite.value = await db.find(findParams)
|
|
20
|
+
}
|
|
21
|
+
observer = db.changes({
|
|
22
|
+
since: 'now',
|
|
23
|
+
live: true
|
|
24
|
+
}).on('change', async () => {
|
|
25
|
+
if (findParams === "all") {
|
|
26
|
+
contentWrite.value = await db.allDocs()
|
|
27
|
+
}
|
|
28
|
+
else if (typeof findParams === 'string') {
|
|
29
|
+
contentWrite.value = await db.get(findParams)
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
contentWrite.value = await db.find(findParams)
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
onUnmounted(() => {
|
|
37
|
+
observer?.cancel()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
return { content }
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { usePouchRef } from '../composable/usePouchRef'
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="pouchdb-core" />
|
|
2
|
+
/// <reference types="pouchdb-adapter-idb" />
|
|
3
|
+
/// <reference types="pouchdb-adapter-websql" />
|
|
4
|
+
/// <reference types="pouchdb-adapter-http" />
|
|
5
|
+
/// <reference types="pouchdb-mapreduce" />
|
|
6
|
+
/// <reference types="pouchdb-replication" />
|
|
7
|
+
/// <reference types="pouchdb-find" />
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export type PouchDatabase<T extends {}> = PouchDB.Database<T>
|
|
11
|
+
|
|
12
|
+
export type PouchFindParams<T extends {}> = PouchDB.Find.FindRequest<T>
|
|
13
|
+
|
|
14
|
+
export type PouchFindResponse<T extends {}> = PouchDB.Find.FindResponse<T>
|
|
15
|
+
|
|
16
|
+
export type PouchObserver = PouchDB.Core.Changes<{}>
|
|
17
|
+
|
|
18
|
+
export type PouchExistingDocument<T extends {}> = PouchDB.Core.ExistingDocument<T>
|
|
19
|
+
|
|
20
|
+
export type PouchExistingDocumentArray<T extends {}> = Array<{
|
|
21
|
+
docs: PouchDB.Core.ExistingDocument<T>
|
|
22
|
+
}>
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@tsconfig/node22/tsconfig.json",
|
|
3
|
+
"include": [
|
|
4
|
+
"vite.config.*",
|
|
5
|
+
"vitest.config.*",
|
|
6
|
+
"cypress.config.*",
|
|
7
|
+
"nightwatch.conf.*",
|
|
8
|
+
"playwright.config.*",
|
|
9
|
+
"eslint.config.*",
|
|
10
|
+
"test/vite.config.ts"
|
|
11
|
+
],
|
|
12
|
+
"compilerOptions": {
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
|
15
|
+
"allowSyntheticDefaultImports": true,
|
|
16
|
+
"module": "ESNext",
|
|
17
|
+
"moduleResolution": "Bundler",
|
|
18
|
+
"types": [
|
|
19
|
+
"node"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
}
|
package/tsdown.config.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineConfig } from 'tsdown'
|
|
2
|
+
import Vue from 'unplugin-vue/rolldown'
|
|
3
|
+
export default defineConfig([
|
|
4
|
+
{
|
|
5
|
+
entry: ['./src/plugin/index.ts'],
|
|
6
|
+
target: 'node20',
|
|
7
|
+
platform: 'neutral',
|
|
8
|
+
plugins: [Vue({ isProduction: true })],
|
|
9
|
+
dts: true,
|
|
10
|
+
|
|
11
|
+
},
|
|
12
|
+
])
|