From bc2d387e0f4d6fa118d0e4da444a86a6b6aaf80c Mon Sep 17 00:00:00 2001 From: DominicGBauer Date: Mon, 29 Apr 2024 09:10:39 +0200 Subject: [PATCH 1/7] chore: add latest changes --- packages/vue/package.json | 5 +- .../vue/src/composables/usePowerSyncQuery.ts | 28 +- .../vue/src/composables/usePowerSyncStatus.ts | 22 +- .../composables/usePowerSyncWatchedQuery.ts | 4 +- packages/vue/src/composables/useQuery.ts | 110 +++ packages/vue/src/composables/useStatus.ts | 14 + packages/vue/tests/tsconfig.json | 27 + packages/vue/tests/useQuery.test.ts | 58 ++ packages/vue/tests/useStatus.test.ts | 30 + packages/vue/tests/utils.ts | 14 + packages/vue/tsconfig.json | 8 +- packages/vue/vitest.config.ts | 9 + pnpm-lock.yaml | 821 ++++-------------- 13 files changed, 459 insertions(+), 691 deletions(-) create mode 100644 packages/vue/src/composables/useQuery.ts create mode 100644 packages/vue/src/composables/useStatus.ts create mode 100644 packages/vue/tests/tsconfig.json create mode 100644 packages/vue/tests/useQuery.test.ts create mode 100644 packages/vue/tests/useStatus.test.ts create mode 100644 packages/vue/tests/utils.ts create mode 100644 packages/vue/vitest.config.ts diff --git a/packages/vue/package.json b/packages/vue/package.json index 129cd9c3e..a8c6973d6 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -14,7 +14,8 @@ "scripts": { "build": "tsc -b", "clean": "rm -rf lib tsconfig.tsbuildinfo", - "watch": "tsc -b -w" + "watch": "tsc -b -w", + "test": "vitest" }, "repository": { "type": "git", @@ -33,7 +34,9 @@ "vue": "*" }, "devDependencies": { + "jsdom": "^24.0.0", "typescript": "^5.1.3", + "vitest": "^1.5.1", "vue": "3.4.21" } } diff --git a/packages/vue/src/composables/usePowerSyncQuery.ts b/packages/vue/src/composables/usePowerSyncQuery.ts index ec39e656a..64591b492 100644 --- a/packages/vue/src/composables/usePowerSyncQuery.ts +++ b/packages/vue/src/composables/usePowerSyncQuery.ts @@ -14,12 +14,25 @@ export type QueryOptions = { */ immediate: boolean; }; -export type Result = { data: Ref; loading: Ref; error: Ref; refresh: () => Promise }; +export type Result = { data: Ref; isLoading: Ref; error: Ref; refresh: () => Promise }; /** + * @deprecated use {@link useQuery} instead. + * * A composable to access a single static query. * SQL Statement and query Parameters are watched by default. * For a result that updates as the source data changes, use {@link usePowerSyncWatchedQuery} instead. + * @example + * diff --git a/demos/vue-supabase-todolist/src/components/widgets/TodoListsWidget.vue b/demos/vue-supabase-todolist/src/components/widgets/TodoListsWidget.vue index 4aea95035..14456484e 100644 --- a/demos/vue-supabase-todolist/src/components/widgets/TodoListsWidget.vue +++ b/demos/vue-supabase-todolist/src/components/widgets/TodoListsWidget.vue @@ -1,6 +1,6 @@ ``` -### Queries +## Query -The `usePowerSyncQuery` composable provides a static view of a given query. You can use refs as parameters instead to automatically refresh the query when they change. The composable exposes reactive variables for the results, the loading state and error state, as well as a refresh callback that can be invoked to rerun the query manually. +The `useQuery` composable provides a dynamic view of a given query. The data will automatically update when a dependent table is updated. + +You can use refs as parameters to refresh the query when they change. The composable exposes reactive variables for the results as well as the loading, fetching, and and error states. Note that `isLoading` indicates that the initial result is being retrieved and `isFetching` indicates the query is fetching data, which could be for the initial load or any time when the query is re-evaluating due to a change in a dependent table. ```Vue // TodoListDisplayQuery.vue ``` -### Watched Queries - -The `usePowerSyncWatchedQuery` composable provides a dynamic view of a given query. The data will automatically update when a dependent table is updated. +### Static query -You can use refs as parameters to refresh the query when they change. The composable exposes reactive variables for the results as well as the loading, fetching, and and error states. Note that `loading` initicates that the initial result is being retrieved and `fetching` indicates the query is fetching data, which could be for the initial load or any time when the query is re-evaluating due to a change in a dependent table. +The `useQuery` composable can be configured to only execute initially and not every time changes to dependent tables are detected. The query can be manually re-executed by using the returned `refresh` function. ```Vue -// TodoListDisplayWatchedQuery.vue +// TodoListDisplayStaticQuery.vue -
{{ error }}
-
    -
  • {{ l.name }}
  • -
- +``` + +### TypeScript Support + +A type can be specified for each row returned by `useQuery`. Remember to declare `lang="ts"` when defining a `script setup` block. + +```Vue + + + ``` -### Connection Status +## Connection Status -The `usePowerSyncStatus` composable provides general connectivity information such as the connection status, whether the initial full sync has completed, when the last sync completed, and whether any data is being uploaded or downloaded. +The `useStatus` composable provides general connectivity information such as the connection status, whether the initial full sync has completed, when the last sync completed, and whether any data is being uploaded or downloaded. ```Vue // ConnectionStatus.vue