jazz-svelte 0.11.8 → 0.12.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/dist/jazz.svelte.d.ts +14 -18
- package/dist/jazz.svelte.js +20 -28
- package/package.json +4 -4
package/dist/jazz.svelte.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
import type { AnonymousJazzAgent, AuthSecretStorage, CoValue, CoValueClass,
|
1
|
+
import type { AnonymousJazzAgent, AuthSecretStorage, CoValue, CoValueClass, ID, JazzContextType, RefsToResolve, Resolved } from 'jazz-tools';
|
2
2
|
import { Account } from 'jazz-tools';
|
3
3
|
import Provider from './Provider.svelte';
|
4
|
+
import type { RefsToResolveStrict } from 'jazz-tools';
|
4
5
|
export { Provider as JazzProvider };
|
5
6
|
/**
|
6
7
|
* The key for the Jazz context.
|
@@ -31,29 +32,24 @@ declare module "jazz-tools" {
|
|
31
32
|
Account: RegisteredAccount;
|
32
33
|
}
|
33
34
|
}
|
34
|
-
export declare function useAccount(
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
export declare function useAccount<D extends DepthsIn<RegisteredAccount>>(depth: D): {
|
39
|
-
me: DeeplyLoaded<RegisteredAccount, D> | undefined | null;
|
35
|
+
export declare function useAccount<const R extends RefsToResolve<RegisteredAccount>>(options?: {
|
36
|
+
resolve?: RefsToResolveStrict<RegisteredAccount, R>;
|
37
|
+
}): {
|
38
|
+
me: Resolved<RegisteredAccount, R> | undefined | null;
|
40
39
|
logOut: () => void;
|
41
40
|
};
|
42
41
|
export declare function useAccountOrGuest(): {
|
43
42
|
me: RegisteredAccount | AnonymousJazzAgent;
|
44
43
|
};
|
45
|
-
export declare function useAccountOrGuest<
|
46
|
-
|
44
|
+
export declare function useAccountOrGuest<R extends RefsToResolve<RegisteredAccount>>(options?: {
|
45
|
+
resolve?: RefsToResolveStrict<RegisteredAccount, R>;
|
46
|
+
}): {
|
47
|
+
me: Resolved<RegisteredAccount, R> | undefined | null | AnonymousJazzAgent;
|
47
48
|
};
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
* @param depth - The depth.
|
53
|
-
* @returns The CoValue.
|
54
|
-
*/
|
55
|
-
export declare function useCoState<V extends CoValue, D extends DepthsIn<V> = []>(Schema: CoValueClass<V>, id: ID<CoValue> | undefined, depth?: D): {
|
56
|
-
current?: DeeplyLoaded<V, D> | null;
|
49
|
+
export declare function useCoState<V extends CoValue, R extends RefsToResolve<V>>(Schema: CoValueClass<V>, id: ID<CoValue> | undefined, options?: {
|
50
|
+
resolve?: RefsToResolveStrict<V, R>;
|
51
|
+
}): {
|
52
|
+
current: Resolved<V, R> | undefined | null;
|
57
53
|
};
|
58
54
|
/**
|
59
55
|
* Use the accept invite hook.
|
package/dist/jazz.svelte.js
CHANGED
@@ -29,12 +29,7 @@ export function getAuthSecretStorage() {
|
|
29
29
|
}
|
30
30
|
return context;
|
31
31
|
}
|
32
|
-
|
33
|
-
* Use the current account with a optional depth.
|
34
|
-
* @param depth - The depth.
|
35
|
-
* @returns The current account.
|
36
|
-
*/
|
37
|
-
export function useAccount(depth) {
|
32
|
+
export function useAccount(options) {
|
38
33
|
const ctx = getJazzContext();
|
39
34
|
if (!ctx?.current) {
|
40
35
|
throw new Error('useAccount must be used within a JazzProvider');
|
@@ -43,7 +38,7 @@ export function useAccount(depth) {
|
|
43
38
|
throw new Error("useAccount can't be used in a JazzProvider with auth === 'guest' - consider using useAccountOrGuest()");
|
44
39
|
}
|
45
40
|
// If no depth is specified, return the context's me directly
|
46
|
-
if (
|
41
|
+
if (options?.resolve === undefined) {
|
47
42
|
return {
|
48
43
|
get me() {
|
49
44
|
return ctx.current.me;
|
@@ -54,7 +49,7 @@ export function useAccount(depth) {
|
|
54
49
|
};
|
55
50
|
}
|
56
51
|
// If depth is specified, use useCoState to get the deeply loaded version
|
57
|
-
const me = useCoState(ctx.current.me.constructor, ctx.current.me.id,
|
52
|
+
const me = useCoState(ctx.current.me.constructor, ctx.current.me.id, options);
|
58
53
|
return {
|
59
54
|
get me() {
|
60
55
|
return me.current;
|
@@ -64,23 +59,18 @@ export function useAccount(depth) {
|
|
64
59
|
}
|
65
60
|
};
|
66
61
|
}
|
67
|
-
|
68
|
-
* Use the current account or guest with a optional depth.
|
69
|
-
* @param depth - The depth.
|
70
|
-
* @returns The current account or guest.
|
71
|
-
*/
|
72
|
-
export function useAccountOrGuest(depth) {
|
62
|
+
export function useAccountOrGuest(options) {
|
73
63
|
const ctx = getJazzContext();
|
74
64
|
if (!ctx?.current) {
|
75
65
|
throw new Error('useAccountOrGuest must be used within a JazzProvider');
|
76
66
|
}
|
77
67
|
const contextMe = 'me' in ctx.current ? ctx.current.me : undefined;
|
78
|
-
const me = useCoState(contextMe?.constructor, contextMe?.id,
|
68
|
+
const me = useCoState(contextMe?.constructor, contextMe?.id, options);
|
79
69
|
// If the context has a me, return the account.
|
80
70
|
if ('me' in ctx.current) {
|
81
71
|
return {
|
82
72
|
get me() {
|
83
|
-
return
|
73
|
+
return options?.resolve === undefined
|
84
74
|
? me.current || ctx.current?.me
|
85
75
|
: me.current;
|
86
76
|
}
|
@@ -95,14 +85,7 @@ export function useAccountOrGuest(depth) {
|
|
95
85
|
};
|
96
86
|
}
|
97
87
|
}
|
98
|
-
|
99
|
-
* Use a CoValue with a optional depth.
|
100
|
-
* @param Schema - The CoValue schema.
|
101
|
-
* @param id - The CoValue id.
|
102
|
-
* @param depth - The depth.
|
103
|
-
* @returns The CoValue.
|
104
|
-
*/
|
105
|
-
export function useCoState(Schema, id, depth = []) {
|
88
|
+
export function useCoState(Schema, id, options) {
|
106
89
|
const ctx = getJazzContext();
|
107
90
|
// Create state and a stable observable
|
108
91
|
let state = $state.raw(undefined);
|
@@ -113,13 +96,22 @@ export function useCoState(Schema, id, depth = []) {
|
|
113
96
|
// Return early if no context or id, effectively cleaning up any previous subscription
|
114
97
|
if (!ctx?.current || !id)
|
115
98
|
return;
|
99
|
+
const agent = "me" in ctx.current ? ctx.current.me : ctx.current.guest;
|
116
100
|
// Setup subscription with current values
|
117
|
-
return subscribeToCoValue(Schema, id,
|
101
|
+
return subscribeToCoValue(Schema, id, {
|
102
|
+
resolve: options?.resolve,
|
103
|
+
loadAs: agent,
|
104
|
+
onUnavailable: () => {
|
105
|
+
state = null;
|
106
|
+
},
|
107
|
+
onUnauthorized: () => {
|
108
|
+
state = null;
|
109
|
+
},
|
110
|
+
syncResolution: true,
|
111
|
+
}, (value) => {
|
118
112
|
// Get current value from our stable observable
|
119
113
|
state = value;
|
120
|
-
}
|
121
|
-
state = null;
|
122
|
-
}, true);
|
114
|
+
});
|
123
115
|
});
|
124
116
|
return {
|
125
117
|
get current() {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "jazz-svelte",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.12.0",
|
4
4
|
"files": [
|
5
5
|
"dist",
|
6
6
|
"!dist/**/*.test.*",
|
@@ -51,9 +51,9 @@
|
|
51
51
|
"vitest": "3.0.5"
|
52
52
|
},
|
53
53
|
"dependencies": {
|
54
|
-
"cojson": "0.
|
55
|
-
"jazz-browser": "0.
|
56
|
-
"jazz-tools": "0.
|
54
|
+
"cojson": "0.12.0",
|
55
|
+
"jazz-browser": "0.12.0",
|
56
|
+
"jazz-tools": "0.12.0"
|
57
57
|
},
|
58
58
|
"scripts": {
|
59
59
|
"dev": "vite dev",
|