vue3-pouch 0.0.7 → 0.0.8
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 +1 -1
- package/dist/index.js +9 -9
- package/package.json +1 -1
- package/src/composable/usePouchRef.ts +9 -9
package/dist/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ type PouchExistingDocument<T extends {}> = PouchDB.Core.ExistingDocument<T>;
|
|
|
19
19
|
//#endregion
|
|
20
20
|
//#region src/composable/usePouchRef.d.ts
|
|
21
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>>>;
|
|
22
|
+
content: vue0.DeepReadonly<vue0.UnwrapNestedRefs<[(TIsSingle extends true ? PouchExistingDocument<TContent> : PouchExistingDocument<TContent>[]) | null | undefined] 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 | undefined, (TIsSingle extends true ? PouchExistingDocument<TContent> : PouchExistingDocument<TContent>[]) | vue0.UnwrapRef<TIsSingle extends true ? PouchExistingDocument<TContent> : PouchExistingDocument<TContent>[]> | null | undefined>>>;
|
|
23
23
|
};
|
|
24
24
|
//#endregion
|
|
25
25
|
export { usePouchRef };
|
package/dist/index.js
CHANGED
|
@@ -2,26 +2,26 @@ import { onMounted, onUnmounted, readonly, ref } from "vue";
|
|
|
2
2
|
|
|
3
3
|
//#region src/composable/usePouchRef.ts
|
|
4
4
|
function usePouchRef(config, db) {
|
|
5
|
-
const contentWrite = ref(
|
|
5
|
+
const contentWrite = ref(void 0);
|
|
6
6
|
const content = readonly(contentWrite);
|
|
7
7
|
let observer;
|
|
8
8
|
onMounted(async () => {
|
|
9
9
|
if (config === "all") contentWrite.value = (await db.allDocs({ include_docs: true })).rows.map((d) => {
|
|
10
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;
|
|
11
|
+
}) ?? null;
|
|
12
|
+
else if (typeof config === "string") contentWrite.value = await db.get(config) ?? null;
|
|
13
|
+
else if (config.limit === 1) contentWrite.value = (await db.find(config)).docs[0] ?? null;
|
|
14
|
+
else contentWrite.value = (await db.find(config)).docs ?? null;
|
|
15
15
|
observer = db.changes({
|
|
16
16
|
since: "now",
|
|
17
17
|
live: true
|
|
18
18
|
}).on("change", async () => {
|
|
19
19
|
if (config === "all") contentWrite.value = (await db.allDocs({ include_docs: true })).rows.map((d) => {
|
|
20
20
|
return d.doc;
|
|
21
|
-
});
|
|
22
|
-
else if (typeof config === "string") contentWrite.value = await db.get(config);
|
|
23
|
-
else if (config.limit === 1) contentWrite.value = (await db.find(config)).docs[0];
|
|
24
|
-
else contentWrite.value = (await db.find(config)).docs;
|
|
21
|
+
}) ?? null;
|
|
22
|
+
else if (typeof config === "string") contentWrite.value = await db.get(config) ?? null;
|
|
23
|
+
else if (config.limit === 1) contentWrite.value = (await db.find(config)).docs[0] ?? null;
|
|
24
|
+
else contentWrite.value = (await db.find(config)).docs ?? null;
|
|
25
25
|
});
|
|
26
26
|
});
|
|
27
27
|
onUnmounted(() => {
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@ export function usePouchRef<TContent extends TDatabaseType,
|
|
|
7
7
|
TIsSingle extends boolean = false,
|
|
8
8
|
TDatabase extends PouchDatabase<TDatabaseType> = PouchDatabase<TDatabaseType>,
|
|
9
9
|
>(config: PouchFindParams<TContent> | "all" | string, db: TDatabase) {
|
|
10
|
-
const contentWrite = ref<(TIsSingle extends true ? PouchExistingDocument<TContent> : PouchExistingDocument<TContent>[]) | null>(
|
|
10
|
+
const contentWrite = ref<(TIsSingle extends true ? PouchExistingDocument<TContent> : PouchExistingDocument<TContent>[]) | null | undefined>(undefined)
|
|
11
11
|
|
|
12
12
|
const content = readonly(contentWrite)
|
|
13
13
|
|
|
@@ -18,17 +18,17 @@ export function usePouchRef<TContent extends TDatabaseType,
|
|
|
18
18
|
include_docs: true
|
|
19
19
|
})).rows.map((d) => {
|
|
20
20
|
return d.doc!
|
|
21
|
-
})
|
|
21
|
+
}) ?? null
|
|
22
22
|
}
|
|
23
23
|
else if (typeof config === 'string') {
|
|
24
|
-
contentWrite.value = await db.get(config)
|
|
24
|
+
contentWrite.value = await db.get(config) ?? null
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
27
|
if (config.limit === 1) {
|
|
28
|
-
contentWrite.value = (await db.find(config)).docs[0]
|
|
28
|
+
contentWrite.value = (await db.find(config)).docs[0] ?? null
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
|
-
contentWrite.value = (await db.find(config)).docs
|
|
31
|
+
contentWrite.value = (await db.find(config)).docs ?? null
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
observer = db.changes({
|
|
@@ -40,17 +40,17 @@ export function usePouchRef<TContent extends TDatabaseType,
|
|
|
40
40
|
include_docs: true
|
|
41
41
|
})).rows.map((d) => {
|
|
42
42
|
return d.doc!
|
|
43
|
-
})
|
|
43
|
+
}) ?? null
|
|
44
44
|
}
|
|
45
45
|
else if (typeof config === 'string') {
|
|
46
|
-
contentWrite.value = await db.get(config)
|
|
46
|
+
contentWrite.value = await db.get(config) ?? null
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
49
|
if (config.limit === 1) {
|
|
50
|
-
contentWrite.value = (await db.find(config)).docs[0]
|
|
50
|
+
contentWrite.value = (await db.find(config)).docs[0] ?? null
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
|
-
contentWrite.value = (await db.find(config)).docs
|
|
53
|
+
contentWrite.value = (await db.find(config)).docs ?? null
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
})
|