@triplit/svelte 0.2.33 → 1.0.0
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 +12 -0
- package/dist/index.svelte.d.ts +4 -12
- package/dist/index.svelte.js +11 -50
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
package/dist/index.svelte.d.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
import type {
|
2
|
-
import { WorkerClient } from '@triplit/client/worker-client';
|
1
|
+
import type { Models, SchemaQuery, SubscriptionOptions, SubscriptionSignalPayload, TriplitClient } from '@triplit/client';
|
3
2
|
/**
|
4
3
|
* A hook that subscribes to a query
|
5
4
|
*
|
@@ -10,20 +9,13 @@ import { WorkerClient } from '@triplit/client/worker-client';
|
|
10
9
|
* @param options.onRemoteFulfilled - An optional callback that is called when the remote query has been fulfilled.
|
11
10
|
* @returns An object containing the fetching state, the result of the query, any error that occurred, and a function to update the query
|
12
11
|
*/
|
13
|
-
export declare function useQuery<M extends Models
|
14
|
-
fetching: boolean;
|
15
|
-
fetchingLocal: boolean;
|
16
|
-
fetchingRemote: boolean;
|
17
|
-
results: Unalias<FetchResult<M, Q>> | undefined;
|
18
|
-
error: any;
|
19
|
-
updateQuery: (query: ClientQueryBuilder<M, CN, Q>) => void;
|
20
|
-
};
|
12
|
+
export declare function useQuery<M extends Models<M>, Q extends SchemaQuery<M>>(client: TriplitClient<M>, query: Q, options?: Partial<SubscriptionOptions>): SubscriptionSignalPayload<M, Q>;
|
21
13
|
/**
|
22
14
|
* A hook that subscribes to the connection status of a client with the server
|
23
15
|
*
|
24
16
|
* @param client - The client instance to get the connection status of
|
25
17
|
* @returns An object containing `status`, the current connection status of the client with the server
|
26
18
|
*/
|
27
|
-
export declare function useConnectionStatus(client: TriplitClient<any>
|
28
|
-
readonly status:
|
19
|
+
export declare function useConnectionStatus(client: TriplitClient<any>): {
|
20
|
+
readonly status: import("@triplit/client").ConnectionStatus;
|
29
21
|
};
|
package/dist/index.svelte.js
CHANGED
@@ -11,57 +11,19 @@
|
|
11
11
|
*/
|
12
12
|
export function useQuery(client, query, options) {
|
13
13
|
let results = $state(undefined);
|
14
|
-
let
|
14
|
+
let fetching = $state(true);
|
15
15
|
let fetchingLocal = $state(true);
|
16
|
-
let fetchingRemote = $state(
|
17
|
-
let fetching = $derived(fetchingLocal || (isInitialFetch && fetchingRemote));
|
16
|
+
let fetchingRemote = $state(false);
|
18
17
|
let error = $state(undefined);
|
19
|
-
let hasResponseFromServer = false;
|
20
|
-
let builtQuery = $state(query && query.build());
|
21
|
-
function updateQuery(query) {
|
22
|
-
builtQuery = query.build();
|
23
|
-
results = undefined;
|
24
|
-
fetchingLocal = true;
|
25
|
-
hasResponseFromServer = false;
|
26
|
-
}
|
27
18
|
$effect(() => {
|
28
|
-
client
|
29
|
-
.
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
return;
|
37
|
-
}
|
38
|
-
if (status === 'OPEN' && hasResponseFromServer === false) {
|
39
|
-
fetchingRemote = true;
|
40
|
-
return;
|
41
|
-
}
|
42
|
-
}, true);
|
43
|
-
return () => {
|
44
|
-
unsub();
|
45
|
-
};
|
46
|
-
});
|
47
|
-
$effect(() => {
|
48
|
-
const unsubscribe = client.subscribe($state.snapshot(builtQuery), (localResults) => {
|
49
|
-
fetchingLocal = false;
|
50
|
-
error = undefined;
|
51
|
-
results = localResults;
|
52
|
-
}, (error) => {
|
53
|
-
fetchingLocal = false;
|
54
|
-
error = error;
|
55
|
-
}, {
|
56
|
-
...(options ?? {}),
|
57
|
-
onRemoteFulfilled: () => {
|
58
|
-
hasResponseFromServer = true;
|
59
|
-
fetchingRemote = false;
|
60
|
-
},
|
61
|
-
});
|
62
|
-
return () => {
|
63
|
-
unsubscribe();
|
64
|
-
};
|
19
|
+
const unsub = client.subscribeWithStatus(query, (newVal) => {
|
20
|
+
results = newVal.results;
|
21
|
+
fetching = newVal.fetching;
|
22
|
+
fetchingLocal = newVal.fetchingLocal;
|
23
|
+
fetchingRemote = newVal.fetchingRemote;
|
24
|
+
error = newVal.error;
|
25
|
+
}, options);
|
26
|
+
return unsub;
|
65
27
|
});
|
66
28
|
return {
|
67
29
|
get fetching() {
|
@@ -79,7 +41,6 @@ export function useQuery(client, query, options) {
|
|
79
41
|
get error() {
|
80
42
|
return error;
|
81
43
|
},
|
82
|
-
updateQuery,
|
83
44
|
};
|
84
45
|
}
|
85
46
|
/**
|
@@ -89,7 +50,7 @@ export function useQuery(client, query, options) {
|
|
89
50
|
* @returns An object containing `status`, the current connection status of the client with the server
|
90
51
|
*/
|
91
52
|
export function useConnectionStatus(client) {
|
92
|
-
let status = $state(
|
53
|
+
let status = $state(client.connectionStatus);
|
93
54
|
$effect(() => {
|
94
55
|
const unsub = client.onConnectionStatusChange((newStatus) => {
|
95
56
|
status = newStatus;
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@triplit/svelte",
|
3
3
|
"packageManager": "yarn@3.4.1",
|
4
|
-
"version": "0.
|
4
|
+
"version": "1.0.0",
|
5
5
|
"source": "./src/index.svelte.ts",
|
6
6
|
"main": "./dist/index.svelte.js",
|
7
7
|
"module": "./dist/index.svelte.js",
|
@@ -29,13 +29,13 @@
|
|
29
29
|
"/dist"
|
30
30
|
],
|
31
31
|
"dependencies": {
|
32
|
-
"@triplit/client": "^0.
|
32
|
+
"@triplit/client": "^1.0.0"
|
33
33
|
},
|
34
34
|
"devDependencies": {
|
35
|
-
"@sveltejs/package": "^2.3.
|
36
|
-
"@tsconfig/svelte": "^5.0.
|
37
|
-
"svelte": "^5.
|
38
|
-
"svelte-check": "^4.
|
35
|
+
"@sveltejs/package": "^2.3.10",
|
36
|
+
"@tsconfig/svelte": "^5.0.4",
|
37
|
+
"svelte": "^5.22.6",
|
38
|
+
"svelte-check": "^4.1.5",
|
39
39
|
"tslib": "^2.6.2",
|
40
40
|
"typescript": "^5.2.2"
|
41
41
|
},
|