@triplit/svelte 1.0.47 → 1.0.49

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,19 @@
1
1
  # @triplit/svelte
2
2
 
3
+ ## 1.0.49
4
+
5
+ ### Patch Changes
6
+
7
+ - @triplit/client@1.0.49
8
+
9
+ ## 1.0.48
10
+
11
+ ### Patch Changes
12
+
13
+ - 0c92a165: Add enabled parameter to subscriptions
14
+ - Updated dependencies [0c92a165]
15
+ - @triplit/client@1.0.48
16
+
3
17
  ## 1.0.47
4
18
 
5
19
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import type { CollectionNameFromModels, FetchResult, Models, SchemaQuery, SubscriptionOptions, SubscriptionSignalPayload, TriplitClient } from '@triplit/client';
1
+ import type { CollectionNameFromModels, FetchResult, Models, SchemaQuery, SubscriptionSignalPayload, TriplitClient, EnabledSubscriptionOptions } from '@triplit/client';
2
2
  import { WorkerClient } from '@triplit/client/worker-client';
3
3
  /**
4
4
  * A hook that subscribes to a query
@@ -10,7 +10,7 @@ import { WorkerClient } from '@triplit/client/worker-client';
10
10
  * @param options.onRemoteFulfilled - An optional callback that is called when the remote query has been fulfilled.
11
11
  * @returns An object containing the fetching state, the result of the query, any error that occurred, and a function to update the query
12
12
  */
13
- export declare function useQuery<M extends Models<M>, Q extends SchemaQuery<M>>(client: TriplitClient<M> | WorkerClient<M>, query: Q, options?: Partial<SubscriptionOptions>): SubscriptionSignalPayload<M, Q>;
13
+ export declare function useQuery<M extends Models<M>, Q extends SchemaQuery<M>>(client: TriplitClient<M> | WorkerClient<M>, query: Q, options?: Partial<EnabledSubscriptionOptions>): SubscriptionSignalPayload<M, Q>;
14
14
  /**
15
15
  * A hook that subscribes to the connection status of a client with the server
16
16
  *
@@ -28,7 +28,7 @@ export declare function useConnectionStatus(client: TriplitClient<any> | WorkerC
28
28
  * @param options - Additional options for the subscription
29
29
  * @returns An object containing the fetching state, the result of the query, and any error that occurred
30
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'> & {
31
+ export declare function useQueryOne<M extends Models<M>, Q extends SchemaQuery<M>>(client: TriplitClient<M> | WorkerClient<M>, query: Q, options?: Partial<EnabledSubscriptionOptions>): Omit<SubscriptionSignalPayload<M, Q>, 'results'> & {
32
32
  result: FetchResult<M, Q, 'one'>;
33
33
  };
34
34
  /**
@@ -40,6 +40,6 @@ export declare function useQueryOne<M extends Models<M>, Q extends SchemaQuery<M
40
40
  * @param options - Additional options for the subscription
41
41
  * @returns - An object containing the fetching state, the result of the query, and any error that occurred
42
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"> & {
43
+ export declare function useEntity<M extends Models<M>, CN extends CollectionNameFromModels<M>>(client: TriplitClient<M> | WorkerClient<M>, collectionName: CN, id: string, options?: Partial<EnabledSubscriptionOptions>): Omit<SubscriptionSignalPayload<M, import("@triplit/client").QueryBuilder<M, CN, import("@triplit/client").WithInclusion<import("@triplit/client").CollectionQuery<M, CN>, {}>>>, "results"> & {
44
44
  result: FetchResult<M, import("@triplit/client").QueryBuilder<M, CN, import("@triplit/client").WithInclusion<import("@triplit/client").CollectionQuery<M, CN>, {}>>, "one">;
45
45
  };
@@ -1,4 +1,5 @@
1
1
  /// <reference types="svelte" />
2
+ import { getInitialState, getDisabledSubscriptionState, isSubscriptionEnabled, } from '@triplit/client';
2
3
  /**
3
4
  * A hook that subscribes to a query
4
5
  *
@@ -10,12 +11,22 @@
10
11
  * @returns An object containing the fetching state, the result of the query, any error that occurred, and a function to update the query
11
12
  */
12
13
  export function useQuery(client, query, options) {
13
- let results = $state(undefined);
14
- let fetching = $state(true);
15
- let fetchingLocal = $state(true);
16
- let fetchingRemote = $state(false);
17
- let error = $state(undefined);
14
+ const initialState = getInitialState(options);
15
+ let results = $state(initialState.results);
16
+ let fetching = $state(initialState.fetching);
17
+ let fetchingLocal = $state(initialState.fetchingLocal);
18
+ let fetchingRemote = $state(initialState.fetchingRemote);
19
+ let error = $state(initialState.error);
18
20
  $effect(() => {
21
+ if (!isSubscriptionEnabled(options)) {
22
+ const disabledState = getDisabledSubscriptionState();
23
+ results = disabledState.results;
24
+ fetching = disabledState.fetching;
25
+ fetchingLocal = disabledState.fetchingLocal;
26
+ fetchingRemote = disabledState.fetchingRemote;
27
+ error = disabledState.error;
28
+ return;
29
+ }
19
30
  const unsub = client.subscribeWithStatus(query, (newVal) => {
20
31
  results = newVal.results;
21
32
  fetching = newVal.fetching;
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.47",
4
+ "version": "1.0.49",
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.47"
32
+ "@triplit/client": "^1.0.49"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@sveltejs/package": "^2.3.10",