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