vue3-pouch 0.0.3 → 0.0.5
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/dist/index.d.ts +27 -0
- package/dist/index.js +30 -0
- package/package.json +1 -1
- package/src/composable/usePouchRef.ts +19 -12
- package/src/types/index.d.ts +5 -1
- package/.vscode/extensions.json +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
import * as vue0 from "vue";
|
|
9
|
+
import * as _vue_shared0 from "@vue/shared";
|
|
10
|
+
|
|
11
|
+
//#region src/types/index.d.ts
|
|
12
|
+
|
|
13
|
+
type PouchDatabase<T extends {}> = PouchDB.Database<T>;
|
|
14
|
+
|
|
15
|
+
//export type PouchFindParams<T extends {}> = PouchDB.Find.FindRequest<T>
|
|
16
|
+
|
|
17
|
+
interface PouchFindParams<T extends {}, S extends boolean = false> extends PouchDB.Find.FindRequest<T> {
|
|
18
|
+
single?: S;
|
|
19
|
+
}
|
|
20
|
+
type PouchExistingDocument<T extends {}> = PouchDB.Core.ExistingDocument<T>;
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/composable/usePouchRef.d.ts
|
|
23
|
+
declare function usePouchRef<TContent extends TDatabaseType, TDatabaseType extends {} = {}, TDatabase extends PouchDatabase<TDatabaseType> = PouchDatabase<TDatabaseType>, TIsSingle extends boolean = false>(config: PouchFindParams<TContent, TIsSingle> | "all" | string, db: TDatabase): {
|
|
24
|
+
content: vue0.DeepReadonly<vue0.UnwrapNestedRefs<[(TIsSingle extends true ? PouchExistingDocument<TContent> : PouchExistingDocument<TContent>[]) | null] extends [vue0.Ref<any, any>] ? _vue_shared0.IfAny<vue0.Ref<any, any> & (TIsSingle extends true ? PouchExistingDocument<TContent> : PouchExistingDocument<TContent>[]), vue0.Ref<vue0.Ref<any, any> & (TIsSingle extends true ? PouchExistingDocument<TContent> : PouchExistingDocument<TContent>[]), vue0.Ref<any, any> & (TIsSingle extends true ? PouchExistingDocument<TContent> : PouchExistingDocument<TContent>[])>, vue0.Ref<any, any> & (TIsSingle extends true ? PouchExistingDocument<TContent> : PouchExistingDocument<TContent>[])> : vue0.Ref<vue0.UnwrapRef<TIsSingle extends true ? PouchExistingDocument<TContent> : PouchExistingDocument<TContent>[]> | null, (TIsSingle extends true ? PouchExistingDocument<TContent> : PouchExistingDocument<TContent>[]) | vue0.UnwrapRef<TIsSingle extends true ? PouchExistingDocument<TContent> : PouchExistingDocument<TContent>[]> | null>>>;
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { usePouchRef };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { onMounted, onUnmounted, readonly, ref } from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/composable/usePouchRef.ts
|
|
4
|
+
function usePouchRef(config, db) {
|
|
5
|
+
const contentWrite = ref(null);
|
|
6
|
+
const content = readonly(contentWrite);
|
|
7
|
+
let observer;
|
|
8
|
+
onMounted(async () => {
|
|
9
|
+
if (config === "all") contentWrite.value = (await db.allDocs({ include_docs: true })).rows.map((d) => {
|
|
10
|
+
return d.doc;
|
|
11
|
+
});
|
|
12
|
+
else if (typeof config === "string") contentWrite.value = await db.get(config);
|
|
13
|
+
else contentWrite.value = (await db.find(config)).docs;
|
|
14
|
+
observer = db.changes({
|
|
15
|
+
since: "now",
|
|
16
|
+
live: true
|
|
17
|
+
}).on("change", async () => {
|
|
18
|
+
if (config === "all") contentWrite.value = await db.allDocs();
|
|
19
|
+
else if (typeof config === "string") contentWrite.value = await db.get(config);
|
|
20
|
+
else contentWrite.value = (await db.find(config)).docs;
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
onUnmounted(() => {
|
|
24
|
+
observer?.cancel();
|
|
25
|
+
});
|
|
26
|
+
return { content };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { usePouchRef };
|
package/package.json
CHANGED
|
@@ -1,35 +1,42 @@
|
|
|
1
1
|
import { ref, onMounted, onUnmounted, readonly } from 'vue'
|
|
2
|
-
import type { PouchDatabase, PouchExistingDocument, PouchFindParams,
|
|
2
|
+
import type { PouchDatabase, PouchExistingDocument, PouchFindParams, PouchObserver } from '../types';
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
export function usePouchRef<
|
|
6
|
-
|
|
5
|
+
export function usePouchRef<TContent extends TDatabaseType,
|
|
6
|
+
TDatabaseType extends {} = {},
|
|
7
|
+
TDatabase extends PouchDatabase<TDatabaseType> = PouchDatabase<TDatabaseType>,
|
|
8
|
+
TIsSingle extends boolean = false>(config: PouchFindParams<TContent, TIsSingle> | "all" | string, db: TDatabase) {
|
|
9
|
+
const contentWrite = ref<(TIsSingle extends true ? PouchExistingDocument<TContent> : PouchExistingDocument<TContent>[]) | null>(null)
|
|
7
10
|
|
|
8
11
|
const content = readonly(contentWrite)
|
|
9
12
|
|
|
10
13
|
let observer: PouchObserver | undefined;
|
|
11
14
|
onMounted(async () => {
|
|
12
|
-
if (
|
|
13
|
-
contentWrite.value = await db.allDocs(
|
|
15
|
+
if (config === "all") {
|
|
16
|
+
contentWrite.value = (await db.allDocs({
|
|
17
|
+
include_docs: true
|
|
18
|
+
})).rows.map((d) => {
|
|
19
|
+
return d.doc!
|
|
20
|
+
})
|
|
14
21
|
}
|
|
15
|
-
else if (typeof
|
|
16
|
-
contentWrite.value = await db.get(
|
|
22
|
+
else if (typeof config === 'string') {
|
|
23
|
+
contentWrite.value = await db.get(config)
|
|
17
24
|
}
|
|
18
25
|
else {
|
|
19
|
-
contentWrite.value = await db.find(
|
|
26
|
+
contentWrite.value = (await db.find(config)).docs
|
|
20
27
|
}
|
|
21
28
|
observer = db.changes({
|
|
22
29
|
since: 'now',
|
|
23
30
|
live: true
|
|
24
31
|
}).on('change', async () => {
|
|
25
|
-
if (
|
|
32
|
+
if (config === "all") {
|
|
26
33
|
contentWrite.value = await db.allDocs()
|
|
27
34
|
}
|
|
28
|
-
else if (typeof
|
|
29
|
-
contentWrite.value = await db.get(
|
|
35
|
+
else if (typeof config === 'string') {
|
|
36
|
+
contentWrite.value = await db.get(config)
|
|
30
37
|
}
|
|
31
38
|
else {
|
|
32
|
-
contentWrite.value = await db.find(
|
|
39
|
+
contentWrite.value = (await db.find(config)).docs
|
|
33
40
|
}
|
|
34
41
|
})
|
|
35
42
|
})
|
package/src/types/index.d.ts
CHANGED
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
|
|
10
10
|
export type PouchDatabase<T extends {}> = PouchDB.Database<T>
|
|
11
11
|
|
|
12
|
-
export type PouchFindParams<T extends {}> = PouchDB.Find.FindRequest<T>
|
|
12
|
+
//export type PouchFindParams<T extends {}> = PouchDB.Find.FindRequest<T>
|
|
13
|
+
|
|
14
|
+
export interface PouchFindParams<T extends {}, S extends boolean = false> extends PouchDB.Find.FindRequest<T> {
|
|
15
|
+
single?: S
|
|
16
|
+
}
|
|
13
17
|
|
|
14
18
|
export type PouchFindResponse<T extends {}> = PouchDB.Find.FindResponse<T>
|
|
15
19
|
|
package/.vscode/extensions.json
DELETED