@triplit/svelte 1.0.29 → 1.0.31

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @triplit/svelte
2
2
 
3
+ ## 1.0.31
4
+
5
+ ### Patch Changes
6
+
7
+ - @triplit/client@1.0.31
8
+
9
+ ## 1.0.30
10
+
11
+ ### Patch Changes
12
+
13
+ - a3b6a4e4: add useQueryOne and useEntity hooks
14
+ - Updated dependencies [d8023d03]
15
+ - Updated dependencies [461d1813]
16
+ - @triplit/client@1.0.30
17
+
3
18
  ## 1.0.29
4
19
 
5
20
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import type { Models, SchemaQuery, SubscriptionOptions, SubscriptionSignalPayload, TriplitClient } from '@triplit/client';
1
+ import type { CollectionNameFromModels, FetchResult, Models, SchemaQuery, SubscriptionOptions, SubscriptionSignalPayload, TriplitClient } from '@triplit/client';
2
2
  import { WorkerClient } from '@triplit/client/worker-client';
3
3
  /**
4
4
  * A hook that subscribes to a query
@@ -17,6 +17,29 @@ export declare function useQuery<M extends Models<M>, Q extends SchemaQuery<M>>(
17
17
  * @param client - The client instance to get the connection status of
18
18
  * @returns An object containing `status`, the current connection status of the client with the server
19
19
  */
20
- export declare function useConnectionStatus(client: TriplitClient<any>): {
20
+ export declare function useConnectionStatus(client: TriplitClient<any> | WorkerClient<any>): {
21
21
  readonly status: import("@triplit/client").ConnectionStatus;
22
22
  };
23
+ /**
24
+ * A hook that subscribes to a query and fetches only one result
25
+ *
26
+ * @param client - The client instance to query with
27
+ * @param query - The query to subscribe to
28
+ * @param options - Additional options for the subscription
29
+ * @returns An object containing the fetching state, the result of the query, and any error that occurred
30
+ */
31
+ export declare function useQueryOne<M extends Models<M>, Q extends SchemaQuery<M>>(client: TriplitClient<M> | WorkerClient<M>, query: Q, options?: Partial<SubscriptionOptions>): Omit<SubscriptionSignalPayload<M, Q>, 'results'> & {
32
+ result: FetchResult<M, Q, 'one'>;
33
+ };
34
+ /**
35
+ * A hook that subscribes to an entity
36
+ *
37
+ * @param client - The client instance to query with
38
+ * @param collectionName - The name of the collection to query
39
+ * @param id - The id of the entity to query
40
+ * @param options - Additional options for the subscription
41
+ * @returns - An object containing the fetching state, the result of the query, and any error that occurred
42
+ */
43
+ export declare function useEntity<M extends Models<M>, CN extends CollectionNameFromModels<M>>(client: TriplitClient<M> | WorkerClient<M>, collectionName: CN, id: string, options?: Partial<SubscriptionOptions>): Omit<SubscriptionSignalPayload<M, import("@triplit/client").QueryBuilder<M, CN, import("@triplit/client").WithInclusion<import("@triplit/client").CollectionQuery<M, CN>, {}>>>, "results"> & {
44
+ result: FetchResult<M, import("@triplit/client").QueryBuilder<M, CN, import("@triplit/client").WithInclusion<import("@triplit/client").CollectionQuery<M, CN>, {}>>, "one">;
45
+ };
@@ -65,3 +65,43 @@ export function useConnectionStatus(client) {
65
65
  },
66
66
  };
67
67
  }
68
+ /**
69
+ * A hook that subscribes to a query and fetches only one result
70
+ *
71
+ * @param client - The client instance to query with
72
+ * @param query - The query to subscribe to
73
+ * @param options - Additional options for the subscription
74
+ * @returns An object containing the fetching state, the result of the query, and any error that occurred
75
+ */
76
+ export function useQueryOne(client, query, options) {
77
+ const queryPayload = useQuery(client, { ...query, limit: 1 }, options);
78
+ return {
79
+ get fetching() {
80
+ return queryPayload.fetching;
81
+ },
82
+ get fetchingLocal() {
83
+ return queryPayload.fetchingLocal;
84
+ },
85
+ get fetchingRemote() {
86
+ return queryPayload.fetchingRemote;
87
+ },
88
+ get result() {
89
+ return queryPayload.results?.[0] ?? null;
90
+ },
91
+ get error() {
92
+ return queryPayload.error;
93
+ },
94
+ };
95
+ }
96
+ /**
97
+ * A hook that subscribes to an entity
98
+ *
99
+ * @param client - The client instance to query with
100
+ * @param collectionName - The name of the collection to query
101
+ * @param id - The id of the entity to query
102
+ * @param options - Additional options for the subscription
103
+ * @returns - An object containing the fetching state, the result of the query, and any error that occurred
104
+ */
105
+ export function useEntity(client, collectionName, id, options) {
106
+ return useQueryOne(client, client.query(collectionName).Id(id), options);
107
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@triplit/svelte",
3
3
  "packageManager": "yarn@3.4.1",
4
- "version": "1.0.29",
4
+ "version": "1.0.31",
5
5
  "source": "./src/index.svelte.ts",
6
6
  "main": "./dist/index.svelte.js",
7
7
  "module": "./dist/index.svelte.js",
@@ -29,7 +29,7 @@
29
29
  "/dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@triplit/client": "^1.0.29"
32
+ "@triplit/client": "^1.0.31"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@sveltejs/package": "^2.3.10",