vue3-pouch 0.0.4 → 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 CHANGED
@@ -7,24 +7,21 @@
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
- type PouchFindParams<T extends {}> = PouchDB.Find.FindRequest<T>;
16
- type PouchFindResponse<T extends {}> = PouchDB.Find.FindResponse<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
+ }
17
20
  type PouchExistingDocument<T extends {}> = PouchDB.Core.ExistingDocument<T>;
18
21
  //#endregion
19
22
  //#region src/composable/usePouchRef.d.ts
20
- declare function usePouchRef<C extends {}>(findParams: PouchFindParams<C> | "all" | string, db: PouchDatabase<C>): {
21
- content: vue0.DeepReadonly<vue0.UnwrapNestedRefs<[PouchFindResponse<C> | PouchExistingDocument<C> | null] extends [vue0.Ref<any, any>] ? _vue_shared0.IfAny<vue0.Ref<any, any> & (PouchFindResponse<C> | PouchExistingDocument<C> | null), vue0.Ref<vue0.Ref<any, any> & (PouchFindResponse<C> | PouchExistingDocument<C> | null), vue0.Ref<any, any> & (PouchFindResponse<C> | PouchExistingDocument<C> | null)>, vue0.Ref<any, any> & (PouchFindResponse<C> | PouchExistingDocument<C> | null)> : vue0.Ref<{
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>>>;
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>>>;
28
25
  };
29
26
  //#endregion
30
27
  export { usePouchRef };
package/dist/index.js CHANGED
@@ -1,21 +1,23 @@
1
1
  import { onMounted, onUnmounted, readonly, ref } from "vue";
2
2
 
3
3
  //#region src/composable/usePouchRef.ts
4
- function usePouchRef(findParams, db) {
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 (findParams === "all") contentWrite.value = await db.allDocs();
10
- else if (typeof findParams === "string") contentWrite.value = await db.get(findParams);
11
- else contentWrite.value = await db.find(findParams);
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;
12
14
  observer = db.changes({
13
15
  since: "now",
14
16
  live: true
15
17
  }).on("change", async () => {
16
- if (findParams === "all") contentWrite.value = await db.allDocs();
17
- else if (typeof findParams === "string") contentWrite.value = await db.get(findParams);
18
- else contentWrite.value = await db.find(findParams);
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;
19
21
  });
20
22
  });
21
23
  onUnmounted(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue3-pouch",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,35 +1,42 @@
1
1
  import { ref, onMounted, onUnmounted, readonly } from 'vue'
2
- import type { PouchDatabase, PouchExistingDocument, PouchFindParams, PouchFindResponse, PouchObserver } from '../types';
2
+ import type { PouchDatabase, PouchExistingDocument, PouchFindParams, PouchObserver } from '../types';
3
3
 
4
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)
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 (findParams === "all") {
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 findParams === 'string') {
16
- contentWrite.value = await db.get(findParams)
22
+ else if (typeof config === 'string') {
23
+ contentWrite.value = await db.get(config)
17
24
  }
18
25
  else {
19
- contentWrite.value = await db.find(findParams)
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 (findParams === "all") {
32
+ if (config === "all") {
26
33
  contentWrite.value = await db.allDocs()
27
34
  }
28
- else if (typeof findParams === 'string') {
29
- contentWrite.value = await db.get(findParams)
35
+ else if (typeof config === 'string') {
36
+ contentWrite.value = await db.get(config)
30
37
  }
31
38
  else {
32
- contentWrite.value = await db.find(findParams)
39
+ contentWrite.value = (await db.find(config)).docs
33
40
  }
34
41
  })
35
42
  })
@@ -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