jazz-svelte 0.14.2 → 0.14.4
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/Provider.svelte +16 -9
- package/dist/Provider.svelte.d.ts +9 -9
- package/dist/jazz.class.svelte.d.ts +12 -11
- package/dist/jazz.class.svelte.js +19 -10
- package/dist/jazz.svelte.d.ts +3 -33
- package/dist/jazz.svelte.js +4 -99
- package/dist/tests/components/CoState/UpdateNestedValue.svelte +1 -3
- package/dist/tests/components/CoState/UpdateNestedValue.svelte.d.ts +1 -3
- package/dist/tests/components/CoState/UpdateNestedValueAccount.svelte +6 -13
- package/dist/tests/components/CoState/UpdateNestedValueAccount.svelte.d.ts +0 -5
- package/dist/tests/components/CoState/schema.d.ts +11 -13
- package/dist/tests/components/CoState/schema.js +16 -16
- package/dist/tests/components/useAcceptInvite.svelte +4 -4
- package/dist/tests/components/useAcceptInvite.svelte.d.ts +7 -7
- package/package.json +3 -3
- package/dist/tests/components/useAccount.svelte +0 -29
- package/dist/tests/components/useAccount.svelte.d.ts +0 -9
- package/dist/tests/components/useAccountOrGuest.svelte +0 -29
- package/dist/tests/components/useAccountOrGuest.svelte.d.ts +0 -9
- package/dist/tests/components/useCoState.svelte +0 -21
- package/dist/tests/components/useCoState.svelte.d.ts +0 -24
package/dist/Provider.svelte
CHANGED
@@ -1,22 +1,29 @@
|
|
1
1
|
<script lang="ts" module>
|
2
|
-
export type Props<
|
2
|
+
export type Props<
|
3
|
+
S extends (AccountClass<Account> & CoValueFromRaw<Account>) | AnyAccountSchema
|
4
|
+
> = JazzContextManagerProps<S> & {
|
3
5
|
children?: Snippet;
|
4
6
|
};
|
5
7
|
</script>
|
6
8
|
|
7
|
-
<script
|
9
|
+
<script
|
10
|
+
lang="ts"
|
11
|
+
generics="S extends
|
12
|
+
| (AccountClass<Account> & CoValueFromRaw<Account>)
|
13
|
+
| AnyAccountSchema,"
|
14
|
+
>
|
8
15
|
import { JazzBrowserContextManager, type JazzContextManagerProps } from 'jazz-browser';
|
9
|
-
import type { AuthSecretStorage } from 'jazz-tools';
|
10
|
-
import { Account } from 'jazz-tools';
|
16
|
+
import type { AuthSecretStorage, InstanceOfSchema } from 'jazz-tools';
|
17
|
+
import { Account, type AccountClass, type CoValueFromRaw, type AnyAccountSchema } from 'jazz-tools';
|
11
18
|
import { type Snippet, setContext, untrack } from 'svelte';
|
12
19
|
import { JAZZ_AUTH_CTX, JAZZ_CTX, type JazzContext } from './jazz.svelte.js';
|
13
20
|
|
14
|
-
let props: Props<
|
21
|
+
let props: Props<S> = $props();
|
15
22
|
|
16
|
-
const contextManager = new JazzBrowserContextManager<
|
23
|
+
const contextManager = new JazzBrowserContextManager<S>();
|
17
24
|
|
18
|
-
const ctx = $state<JazzContext<
|
19
|
-
setContext<JazzContext<
|
25
|
+
const ctx = $state<JazzContext<InstanceOfSchema<S>>>({ current: undefined });
|
26
|
+
setContext<JazzContext<InstanceOfSchema<S>>>(JAZZ_CTX, ctx);
|
20
27
|
setContext<AuthSecretStorage>(JAZZ_AUTH_CTX, contextManager.getAuthSecretStorage());
|
21
28
|
|
22
29
|
$effect(() => {
|
@@ -35,7 +42,7 @@
|
|
35
42
|
AccountSchema: props.AccountSchema,
|
36
43
|
defaultProfileName: props.defaultProfileName,
|
37
44
|
onAnonymousAccountDiscarded: props.onAnonymousAccountDiscarded,
|
38
|
-
onLogOut: props.onLogOut
|
45
|
+
onLogOut: props.onLogOut
|
39
46
|
})
|
40
47
|
.catch((error) => {
|
41
48
|
console.error('Error creating Jazz browser context:', error);
|
@@ -1,23 +1,23 @@
|
|
1
|
-
export type Props<
|
1
|
+
export type Props<S extends (AccountClass<Account> & CoValueFromRaw<Account>) | AnyAccountSchema> = JazzContextManagerProps<S> & {
|
2
2
|
children?: Snippet;
|
3
3
|
};
|
4
4
|
import { type JazzContextManagerProps } from 'jazz-browser';
|
5
|
-
import { Account } from 'jazz-tools';
|
5
|
+
import { Account, type AccountClass, type CoValueFromRaw, type AnyAccountSchema } from 'jazz-tools';
|
6
6
|
import { type Snippet } from 'svelte';
|
7
|
-
declare class __sveltets_Render<
|
8
|
-
props(): Props<
|
7
|
+
declare class __sveltets_Render<S extends (AccountClass<Account> & CoValueFromRaw<Account>) | AnyAccountSchema> {
|
8
|
+
props(): Props<S>;
|
9
9
|
events(): {};
|
10
10
|
slots(): {};
|
11
11
|
bindings(): "";
|
12
12
|
exports(): {};
|
13
13
|
}
|
14
14
|
interface $$IsomorphicComponent {
|
15
|
-
new <
|
16
|
-
$$bindings?: ReturnType<__sveltets_Render<
|
17
|
-
} & ReturnType<__sveltets_Render<
|
18
|
-
<
|
15
|
+
new <S extends (AccountClass<Account> & CoValueFromRaw<Account>) | AnyAccountSchema>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<S>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<S>['props']>, ReturnType<__sveltets_Render<S>['events']>, ReturnType<__sveltets_Render<S>['slots']>> & {
|
16
|
+
$$bindings?: ReturnType<__sveltets_Render<S>['bindings']>;
|
17
|
+
} & ReturnType<__sveltets_Render<S>['exports']>;
|
18
|
+
<S extends (AccountClass<Account> & CoValueFromRaw<Account>) | AnyAccountSchema>(internal: unknown, props: ReturnType<__sveltets_Render<S>['props']> & {}): ReturnType<__sveltets_Render<S>['exports']>;
|
19
19
|
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
20
20
|
}
|
21
21
|
declare const Provider: $$IsomorphicComponent;
|
22
|
-
type Provider<
|
22
|
+
type Provider<S extends (AccountClass<Account> & CoValueFromRaw<Account>) | AnyAccountSchema> = InstanceType<typeof Provider<S>>;
|
23
23
|
export default Provider;
|
@@ -1,20 +1,21 @@
|
|
1
|
-
import type { Account,
|
2
|
-
export declare class CoState<V extends
|
1
|
+
import type { Account, AccountClass, AnyAccountSchema, CoValueFromRaw, CoValueOrZodSchema, InstanceOfSchema, Loaded, ResolveQuery, ResolveQueryStrict } from "jazz-tools";
|
2
|
+
export declare class CoState<V extends CoValueOrZodSchema, R extends ResolveQuery<V> = true> {
|
3
3
|
#private;
|
4
|
-
constructor(Schema:
|
5
|
-
resolve?:
|
4
|
+
constructor(Schema: V, id: string | undefined | null | (() => string | undefined | null), options?: {
|
5
|
+
resolve?: ResolveQueryStrict<V, R>;
|
6
6
|
});
|
7
7
|
subscribeTo(): void;
|
8
|
-
updateValue(value:
|
9
|
-
get current():
|
8
|
+
updateValue(value: Loaded<V, R> | undefined | null): void;
|
9
|
+
get current(): Loaded<V, R> | null | undefined;
|
10
10
|
}
|
11
|
-
export declare class AccountCoState<A extends Account
|
11
|
+
export declare class AccountCoState<A extends (AccountClass<Account> & CoValueFromRaw<Account>) | AnyAccountSchema, R extends ResolveQuery<A> = true> {
|
12
12
|
#private;
|
13
|
-
constructor(options?: {
|
14
|
-
resolve?:
|
13
|
+
constructor(Schema: A, options?: {
|
14
|
+
resolve?: ResolveQueryStrict<A, R>;
|
15
15
|
});
|
16
16
|
subscribeTo(): void;
|
17
17
|
logOut: () => void;
|
18
|
-
updateValue(value:
|
19
|
-
get current():
|
18
|
+
updateValue(value: Loaded<A, R> | undefined | null): void;
|
19
|
+
get current(): Loaded<A, R> | null | undefined;
|
20
|
+
get agent(): import("jazz-tools").AnonymousJazzAgent | InstanceOfSchema<A>;
|
20
21
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { createSubscriber } from "svelte/reactivity";
|
2
2
|
import { getJazzContext } from "./jazz.svelte.js";
|
3
|
-
import { subscribeToCoValue } from "jazz-tools";
|
3
|
+
import { anySchemaToCoSchema, subscribeToCoValue } from "jazz-tools";
|
4
4
|
export class CoState {
|
5
5
|
#value = undefined;
|
6
6
|
#subscribe;
|
@@ -13,12 +13,12 @@ export class CoState {
|
|
13
13
|
constructor(Schema, id, options) {
|
14
14
|
this.#Schema = Schema;
|
15
15
|
this.#options = options;
|
16
|
-
this.#id = typeof id ===
|
16
|
+
this.#id = typeof id === "function" ? id() : id;
|
17
17
|
this.#subscribe = createSubscriber((update) => {
|
18
18
|
this.#update = update;
|
19
|
-
// Using an effect to react to the id and ctx changes
|
19
|
+
// Using an effect to react to the id and ctx changes
|
20
20
|
$effect.pre(() => {
|
21
|
-
this.#id = typeof id ===
|
21
|
+
this.#id = typeof id === "function" ? id() : id;
|
22
22
|
this.subscribeTo();
|
23
23
|
});
|
24
24
|
return () => {
|
@@ -36,7 +36,8 @@ export class CoState {
|
|
36
36
|
return;
|
37
37
|
const agent = "me" in ctx.current ? ctx.current.me : ctx.current.guest;
|
38
38
|
// Setup subscription with current values
|
39
|
-
this.#unsubscribe = subscribeToCoValue(this.#Schema, id, {
|
39
|
+
this.#unsubscribe = subscribeToCoValue(anySchemaToCoSchema(this.#Schema), id, {
|
40
|
+
// @ts-expect-error The resolve query type isn't compatible with the anySchemaToCoSchema conversion
|
40
41
|
resolve: this.#options?.resolve,
|
41
42
|
loadAs: agent,
|
42
43
|
onUnavailable: () => {
|
@@ -65,10 +66,12 @@ export class AccountCoState {
|
|
65
66
|
#value = undefined;
|
66
67
|
#subscribe;
|
67
68
|
#ctx = $derived(getJazzContext());
|
69
|
+
#Schema;
|
68
70
|
#update = () => { };
|
69
71
|
#unsubscribe = () => { };
|
70
72
|
#options;
|
71
|
-
constructor(options) {
|
73
|
+
constructor(Schema, options) {
|
74
|
+
this.#Schema = Schema;
|
72
75
|
this.#options = options;
|
73
76
|
this.#subscribe = createSubscriber((update) => {
|
74
77
|
this.#update = update;
|
@@ -88,12 +91,12 @@ export class AccountCoState {
|
|
88
91
|
this.#unsubscribe();
|
89
92
|
if (!ctx.current)
|
90
93
|
return;
|
91
|
-
if (!(
|
92
|
-
|
93
|
-
}
|
94
|
+
if (!("me" in ctx.current))
|
95
|
+
return;
|
94
96
|
const me = ctx.current.me;
|
95
97
|
// Setup subscription with current values
|
96
|
-
this.#unsubscribe = subscribeToCoValue(
|
98
|
+
this.#unsubscribe = subscribeToCoValue(anySchemaToCoSchema(this.#Schema), me.id, {
|
99
|
+
// @ts-expect-error The resolve query type isn't compatible with the anySchemaToCoSchema conversion
|
97
100
|
resolve: this.#options?.resolve,
|
98
101
|
loadAs: me,
|
99
102
|
onUnavailable: () => {
|
@@ -120,4 +123,10 @@ export class AccountCoState {
|
|
120
123
|
this.#subscribe();
|
121
124
|
return this.#value;
|
122
125
|
}
|
126
|
+
get agent() {
|
127
|
+
if (!this.#ctx.current) {
|
128
|
+
throw new Error("No context found");
|
129
|
+
}
|
130
|
+
return "me" in this.#ctx.current ? this.#ctx.current.me : this.#ctx.current.guest;
|
131
|
+
}
|
123
132
|
}
|
package/dist/jazz.svelte.d.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
import type {
|
1
|
+
import type { AuthSecretStorage, CoValueOrZodSchema, ID, JazzContextType } from 'jazz-tools';
|
2
2
|
import { Account } from 'jazz-tools';
|
3
3
|
import Provider from './Provider.svelte';
|
4
|
-
import type { RefsToResolveStrict } from 'jazz-tools';
|
5
4
|
export { Provider as JazzProvider };
|
6
5
|
/**
|
7
6
|
* The key for the Jazz context.
|
@@ -22,35 +21,6 @@ export declare function getJazzContext<Acc extends Account>(): {
|
|
22
21
|
current: JazzContextType<Acc>;
|
23
22
|
};
|
24
23
|
export declare function getAuthSecretStorage(): AuthSecretStorage;
|
25
|
-
export interface Register {
|
26
|
-
}
|
27
|
-
export type RegisteredAccount = Register extends {
|
28
|
-
Account: infer Acc;
|
29
|
-
} ? Acc : Account;
|
30
|
-
declare module "jazz-tools" {
|
31
|
-
interface Register {
|
32
|
-
Account: RegisteredAccount;
|
33
|
-
}
|
34
|
-
}
|
35
|
-
export declare function useAccount<const R extends RefsToResolve<RegisteredAccount>>(options?: {
|
36
|
-
resolve?: RefsToResolveStrict<RegisteredAccount, R>;
|
37
|
-
}): {
|
38
|
-
me: Resolved<RegisteredAccount, R> | undefined | null;
|
39
|
-
logOut: () => void;
|
40
|
-
};
|
41
|
-
export declare function useAccountOrGuest(): {
|
42
|
-
me: RegisteredAccount | AnonymousJazzAgent;
|
43
|
-
};
|
44
|
-
export declare function useAccountOrGuest<R extends RefsToResolve<RegisteredAccount>>(options?: {
|
45
|
-
resolve?: RefsToResolveStrict<RegisteredAccount, R>;
|
46
|
-
}): {
|
47
|
-
me: Resolved<RegisteredAccount, R> | undefined | null | AnonymousJazzAgent;
|
48
|
-
};
|
49
|
-
export declare function useCoState<V extends CoValue, R extends RefsToResolve<V>>(Schema: CoValueClass<V>, id: ID<CoValue> | undefined | (() => ID<CoValue> | undefined), options?: {
|
50
|
-
resolve?: RefsToResolveStrict<V, R>;
|
51
|
-
}): {
|
52
|
-
current: Resolved<V, R> | undefined | null;
|
53
|
-
};
|
54
24
|
/**
|
55
25
|
* Use the accept invite hook.
|
56
26
|
* @param invitedObjectSchema - The invited object schema.
|
@@ -58,8 +28,8 @@ export declare function useCoState<V extends CoValue, R extends RefsToResolve<V>
|
|
58
28
|
* @param forValueHint - Hint for the value.
|
59
29
|
* @returns The accept invite hook.
|
60
30
|
*/
|
61
|
-
export declare function useAcceptInvite<V extends
|
62
|
-
invitedObjectSchema:
|
31
|
+
export declare function useAcceptInvite<V extends CoValueOrZodSchema>({ invitedObjectSchema, onAccept, forValueHint }: {
|
32
|
+
invitedObjectSchema: V;
|
63
33
|
onAccept: (projectID: ID<V>) => void;
|
64
34
|
forValueHint?: string;
|
65
35
|
}): void;
|
package/dist/jazz.svelte.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { consumeInviteLinkFromWindowLocation } from 'jazz-browser';
|
2
|
-
import { Account
|
2
|
+
import { Account } from 'jazz-tools';
|
3
3
|
import { getContext, untrack } from 'svelte';
|
4
4
|
import Provider from './Provider.svelte';
|
5
5
|
export { Provider as JazzProvider };
|
@@ -29,97 +29,6 @@ export function getAuthSecretStorage() {
|
|
29
29
|
}
|
30
30
|
return context;
|
31
31
|
}
|
32
|
-
export function useAccount(options) {
|
33
|
-
const ctx = getJazzContext();
|
34
|
-
if (!ctx?.current) {
|
35
|
-
throw new Error('useAccount must be used within a JazzProvider');
|
36
|
-
}
|
37
|
-
if (!('me' in ctx.current)) {
|
38
|
-
throw new Error("useAccount can't be used in a JazzProvider with auth === 'guest' - consider using useAccountOrGuest()");
|
39
|
-
}
|
40
|
-
// If no depth is specified, return the context's me directly
|
41
|
-
if (options?.resolve === undefined) {
|
42
|
-
return {
|
43
|
-
get me() {
|
44
|
-
return ctx.current.me;
|
45
|
-
},
|
46
|
-
logOut() {
|
47
|
-
return ctx.current?.logOut();
|
48
|
-
}
|
49
|
-
};
|
50
|
-
}
|
51
|
-
// If depth is specified, use useCoState to get the deeply loaded version
|
52
|
-
const me = useCoState(ctx.current.me.constructor, ctx.current.me.id, options);
|
53
|
-
return {
|
54
|
-
get me() {
|
55
|
-
return me.current;
|
56
|
-
},
|
57
|
-
logOut() {
|
58
|
-
return ctx.current?.logOut();
|
59
|
-
}
|
60
|
-
};
|
61
|
-
}
|
62
|
-
export function useAccountOrGuest(options) {
|
63
|
-
const ctx = getJazzContext();
|
64
|
-
if (!ctx?.current) {
|
65
|
-
throw new Error('useAccountOrGuest must be used within a JazzProvider');
|
66
|
-
}
|
67
|
-
const contextMe = 'me' in ctx.current ? ctx.current.me : undefined;
|
68
|
-
const me = useCoState(contextMe?.constructor, contextMe?.id, options);
|
69
|
-
// If the context has a me, return the account.
|
70
|
-
if ('me' in ctx.current) {
|
71
|
-
return {
|
72
|
-
get me() {
|
73
|
-
return options?.resolve === undefined
|
74
|
-
? me.current || ctx.current?.me
|
75
|
-
: me.current;
|
76
|
-
}
|
77
|
-
};
|
78
|
-
}
|
79
|
-
// If the context has no me, return the guest.
|
80
|
-
else {
|
81
|
-
return {
|
82
|
-
get me() {
|
83
|
-
return ctx.current?.guest;
|
84
|
-
}
|
85
|
-
};
|
86
|
-
}
|
87
|
-
}
|
88
|
-
export function useCoState(Schema, id, options) {
|
89
|
-
const ctx = getJazzContext();
|
90
|
-
// Create state and a stable observable
|
91
|
-
let state = $state.raw(undefined);
|
92
|
-
// Effect to handle subscription
|
93
|
-
$effect(() => {
|
94
|
-
// Reset state when dependencies change
|
95
|
-
state = undefined;
|
96
|
-
const idValue = typeof id === 'function' ? id() : id;
|
97
|
-
// Return early if no context or id, effectively cleaning up any previous subscription
|
98
|
-
if (!ctx?.current || !idValue)
|
99
|
-
return;
|
100
|
-
const agent = "me" in ctx.current ? ctx.current.me : ctx.current.guest;
|
101
|
-
// Setup subscription with current values
|
102
|
-
return subscribeToCoValue(Schema, idValue, {
|
103
|
-
resolve: options?.resolve,
|
104
|
-
loadAs: agent,
|
105
|
-
onUnavailable: () => {
|
106
|
-
state = null;
|
107
|
-
},
|
108
|
-
onUnauthorized: () => {
|
109
|
-
state = null;
|
110
|
-
},
|
111
|
-
syncResolution: true,
|
112
|
-
}, (value) => {
|
113
|
-
// Get current value from our stable observable
|
114
|
-
state = value;
|
115
|
-
});
|
116
|
-
});
|
117
|
-
return {
|
118
|
-
get current() {
|
119
|
-
return state;
|
120
|
-
}
|
121
|
-
};
|
122
|
-
}
|
123
32
|
/**
|
124
33
|
* Use the accept invite hook.
|
125
34
|
* @param invitedObjectSchema - The invited object schema.
|
@@ -128,16 +37,10 @@ export function useCoState(Schema, id, options) {
|
|
128
37
|
* @returns The accept invite hook.
|
129
38
|
*/
|
130
39
|
export function useAcceptInvite({ invitedObjectSchema, onAccept, forValueHint }) {
|
131
|
-
const ctx = getJazzContext();
|
132
40
|
const _onAccept = onAccept;
|
133
|
-
if (!ctx.current) {
|
134
|
-
throw new Error('useAcceptInvite must be used within a JazzProvider');
|
135
|
-
}
|
136
|
-
if (!('me' in ctx.current)) {
|
137
|
-
throw new Error("useAcceptInvite can't be used in a JazzProvider with auth === 'guest'.");
|
138
|
-
}
|
139
41
|
// Subscribe to the onAccept function.
|
140
42
|
$effect(() => {
|
43
|
+
const ctx = getJazzContext();
|
141
44
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
142
45
|
_onAccept;
|
143
46
|
// Subscribe to the onAccept function.
|
@@ -145,6 +48,8 @@ export function useAcceptInvite({ invitedObjectSchema, onAccept, forValueHint })
|
|
145
48
|
// If there is no context, return.
|
146
49
|
if (!ctx.current)
|
147
50
|
return;
|
51
|
+
if (!('me' in ctx.current))
|
52
|
+
return;
|
148
53
|
// Consume the invite link from the window location.
|
149
54
|
const result = consumeInviteLinkFromWindowLocation({
|
150
55
|
as: ctx.current.me,
|
@@ -1,13 +1,11 @@
|
|
1
1
|
<script lang="ts" module>
|
2
2
|
export type Props = {
|
3
|
-
id:
|
3
|
+
id: string;
|
4
4
|
};
|
5
5
|
</script>
|
6
6
|
|
7
7
|
<script lang="ts">
|
8
8
|
import { CoState } from '../../../jazz.class.svelte.js';
|
9
|
-
|
10
|
-
import { type ID } from 'jazz-tools';
|
11
9
|
import { Person } from './schema.js';
|
12
10
|
|
13
11
|
let props: Props = $props();
|
@@ -1,8 +1,6 @@
|
|
1
1
|
export type Props = {
|
2
|
-
id:
|
2
|
+
id: string;
|
3
3
|
};
|
4
|
-
import { type ID } from 'jazz-tools';
|
5
|
-
import { Person } from './schema.js';
|
6
4
|
declare const UpdateNestedValue: import("svelte").Component<Props, {}, "">;
|
7
5
|
type UpdateNestedValue = ReturnType<typeof UpdateNestedValue>;
|
8
6
|
export default UpdateNestedValue;
|
@@ -1,16 +1,9 @@
|
|
1
|
-
<script lang="ts" module>
|
2
|
-
export type Props = {
|
3
|
-
id: ID<Person>;
|
4
|
-
};
|
5
|
-
</script>
|
6
|
-
|
7
1
|
<script lang="ts">
|
8
2
|
import { AccountCoState } from '../../../jazz.class.svelte.js';
|
9
3
|
|
10
|
-
import {
|
11
|
-
import { MyAccount, Person } from './schema.js';
|
4
|
+
import { MyAccount } from './schema.js';
|
12
5
|
|
13
|
-
const
|
6
|
+
const me = new AccountCoState(MyAccount, {
|
14
7
|
resolve: {
|
15
8
|
root: {
|
16
9
|
dog: true
|
@@ -22,13 +15,13 @@
|
|
22
15
|
<!-- Using non-null assertions because we want to test that locally available values are never null -->
|
23
16
|
<label>
|
24
17
|
Name
|
25
|
-
<input type="text" bind:value={
|
18
|
+
<input type="text" bind:value={me.current!.root.name} />
|
26
19
|
</label>
|
27
20
|
|
28
21
|
<label>
|
29
22
|
Dog
|
30
|
-
<input type="text" bind:value={
|
23
|
+
<input type="text" bind:value={me.current!.root.dog.name} />
|
31
24
|
</label>
|
32
25
|
|
33
|
-
<div data-testid="person-name">{
|
34
|
-
<div data-testid="person-dog-name">{
|
26
|
+
<div data-testid="person-name">{me.current!.root.name}</div>
|
27
|
+
<div data-testid="person-dog-name">{me.current!.root.dog.name}</div>
|
@@ -1,8 +1,3 @@
|
|
1
|
-
export type Props = {
|
2
|
-
id: ID<Person>;
|
3
|
-
};
|
4
|
-
import { type ID } from 'jazz-tools';
|
5
|
-
import { Person } from './schema.js';
|
6
1
|
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
7
2
|
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
8
3
|
$$bindings?: Bindings;
|
@@ -1,13 +1,11 @@
|
|
1
|
-
import {
|
2
|
-
export declare
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
}
|
10
|
-
|
11
|
-
|
12
|
-
migrate(): void;
|
13
|
-
}
|
1
|
+
import { z } from "jazz-tools";
|
2
|
+
export declare const Dog: any;
|
3
|
+
export declare const Person: any;
|
4
|
+
export declare const MyAccount: import("jazz-tools").AccountSchema<{
|
5
|
+
profile: import("jazz-tools/dist/internal").CoProfileSchema<{
|
6
|
+
name: z.core.$ZodString<string>;
|
7
|
+
inbox: z.core.$ZodOptional<z.core.$ZodString>;
|
8
|
+
inboxInvite: z.core.$ZodOptional<z.core.$ZodString>;
|
9
|
+
}>;
|
10
|
+
root: any;
|
11
|
+
}>;
|
@@ -1,17 +1,17 @@
|
|
1
|
-
import {
|
2
|
-
export
|
3
|
-
name
|
4
|
-
}
|
5
|
-
export
|
6
|
-
name
|
7
|
-
age
|
8
|
-
dog
|
9
|
-
}
|
10
|
-
export
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
}
|
1
|
+
import { co, z } from "jazz-tools";
|
2
|
+
export const Dog = co.map({
|
3
|
+
name: z.string(),
|
4
|
+
});
|
5
|
+
export const Person = co.map({
|
6
|
+
name: z.string(),
|
7
|
+
age: z.number(),
|
8
|
+
dog: Dog,
|
9
|
+
});
|
10
|
+
export const MyAccount = co.account({
|
11
|
+
profile: co.profile(),
|
12
|
+
root: Person,
|
13
|
+
}).withMigration((account) => {
|
14
|
+
if (!account._refs.root) {
|
15
|
+
account.root = Person.create({ name: "John", age: 30, dog: Dog.create({ name: "Rex" }, account) }, account);
|
16
16
|
}
|
17
|
-
}
|
17
|
+
});
|
@@ -1,13 +1,13 @@
|
|
1
1
|
<script lang="ts" module>
|
2
|
-
export type Props<R extends
|
3
|
-
invitedObjectSchema:
|
2
|
+
export type Props<R extends CoValueOrZodSchema> = {
|
3
|
+
invitedObjectSchema: R;
|
4
4
|
onAccept: (id: ID<R>) => void;
|
5
5
|
};
|
6
6
|
</script>
|
7
7
|
|
8
|
-
<script lang="ts" generics="R extends
|
8
|
+
<script lang="ts" generics="R extends CoValueOrZodSchema">
|
9
9
|
import { useAcceptInvite } from '../../jazz.svelte.js';
|
10
|
-
import type {
|
10
|
+
import type { CoValueOrZodSchema, ID } from 'jazz-tools';
|
11
11
|
|
12
12
|
let { invitedObjectSchema, onAccept }: Props<R> = $props();
|
13
13
|
|
@@ -1,9 +1,9 @@
|
|
1
|
-
export type Props<R extends
|
2
|
-
invitedObjectSchema:
|
1
|
+
export type Props<R extends CoValueOrZodSchema> = {
|
2
|
+
invitedObjectSchema: R;
|
3
3
|
onAccept: (id: ID<R>) => void;
|
4
4
|
};
|
5
|
-
import type {
|
6
|
-
declare class __sveltets_Render<R extends
|
5
|
+
import type { CoValueOrZodSchema, ID } from 'jazz-tools';
|
6
|
+
declare class __sveltets_Render<R extends CoValueOrZodSchema> {
|
7
7
|
props(): Props<R>;
|
8
8
|
events(): {};
|
9
9
|
slots(): {};
|
@@ -11,12 +11,12 @@ declare class __sveltets_Render<R extends CoValue> {
|
|
11
11
|
exports(): {};
|
12
12
|
}
|
13
13
|
interface $$IsomorphicComponent {
|
14
|
-
new <R extends
|
14
|
+
new <R extends CoValueOrZodSchema>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<R>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<R>['props']>, ReturnType<__sveltets_Render<R>['events']>, ReturnType<__sveltets_Render<R>['slots']>> & {
|
15
15
|
$$bindings?: ReturnType<__sveltets_Render<R>['bindings']>;
|
16
16
|
} & ReturnType<__sveltets_Render<R>['exports']>;
|
17
|
-
<R extends
|
17
|
+
<R extends CoValueOrZodSchema>(internal: unknown, props: ReturnType<__sveltets_Render<R>['props']> & {}): ReturnType<__sveltets_Render<R>['exports']>;
|
18
18
|
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
19
19
|
}
|
20
20
|
declare const UseAcceptInvite: $$IsomorphicComponent;
|
21
|
-
type UseAcceptInvite<R extends
|
21
|
+
type UseAcceptInvite<R extends CoValueOrZodSchema> = InstanceType<typeof UseAcceptInvite<R>>;
|
22
22
|
export default UseAcceptInvite;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "jazz-svelte",
|
3
|
-
"version": "0.14.
|
3
|
+
"version": "0.14.4",
|
4
4
|
"files": [
|
5
5
|
"dist",
|
6
6
|
"!dist/**/*.test.*",
|
@@ -50,8 +50,8 @@
|
|
50
50
|
},
|
51
51
|
"dependencies": {
|
52
52
|
"cojson": "0.14.1",
|
53
|
-
"jazz-browser": "0.14.
|
54
|
-
"jazz-tools": "0.14.
|
53
|
+
"jazz-browser": "0.14.4",
|
54
|
+
"jazz-tools": "0.14.4"
|
55
55
|
},
|
56
56
|
"scripts": {
|
57
57
|
"dev": "vite dev",
|
@@ -1,29 +0,0 @@
|
|
1
|
-
<script lang="ts" module>
|
2
|
-
export type Props = {
|
3
|
-
depth?: RefsToResolve<RegisteredAccount>;
|
4
|
-
setResult: (result: ReturnType<typeof useAccount> | undefined) => void;
|
5
|
-
};
|
6
|
-
</script>
|
7
|
-
|
8
|
-
<script lang="ts">
|
9
|
-
import { useAccount, type RegisteredAccount } from '../../jazz.svelte.js';
|
10
|
-
import type { RefsToResolve } from 'jazz-tools';
|
11
|
-
|
12
|
-
let { depth, setResult }: Props = $props();
|
13
|
-
|
14
|
-
if (depth) {
|
15
|
-
const result = $derived(useAccount({
|
16
|
-
resolve: depth
|
17
|
-
}));
|
18
|
-
|
19
|
-
$effect(() => {
|
20
|
-
setResult(result);
|
21
|
-
});
|
22
|
-
} else {
|
23
|
-
const result = $derived(useAccount());
|
24
|
-
|
25
|
-
$effect(() => {
|
26
|
-
setResult(result);
|
27
|
-
});
|
28
|
-
}
|
29
|
-
</script>
|
@@ -1,9 +0,0 @@
|
|
1
|
-
export type Props = {
|
2
|
-
depth?: RefsToResolve<RegisteredAccount>;
|
3
|
-
setResult: (result: ReturnType<typeof useAccount> | undefined) => void;
|
4
|
-
};
|
5
|
-
import { useAccount, type RegisteredAccount } from '../../jazz.svelte.js';
|
6
|
-
import type { RefsToResolve } from 'jazz-tools';
|
7
|
-
declare const UseAccount: import("svelte").Component<Props, {}, "">;
|
8
|
-
type UseAccount = ReturnType<typeof UseAccount>;
|
9
|
-
export default UseAccount;
|
@@ -1,29 +0,0 @@
|
|
1
|
-
<script lang="ts" module>
|
2
|
-
export type Props = {
|
3
|
-
depth?: RefsToResolve<RegisteredAccount>;
|
4
|
-
setResult: (result: ReturnType<typeof useAccountOrGuest> | undefined) => void;
|
5
|
-
};
|
6
|
-
</script>
|
7
|
-
|
8
|
-
<script lang="ts">
|
9
|
-
import { useAccountOrGuest, type RegisteredAccount } from '../../jazz.svelte.js';
|
10
|
-
import type { RefsToResolve } from 'jazz-tools';
|
11
|
-
|
12
|
-
let { depth, setResult }: Props = $props();
|
13
|
-
|
14
|
-
if (depth) {
|
15
|
-
const result = $derived(useAccountOrGuest({
|
16
|
-
resolve: depth
|
17
|
-
}));
|
18
|
-
|
19
|
-
$effect(() => {
|
20
|
-
setResult(result);
|
21
|
-
});
|
22
|
-
} else {
|
23
|
-
const result = $derived(useAccountOrGuest());
|
24
|
-
|
25
|
-
$effect(() => {
|
26
|
-
setResult(result);
|
27
|
-
});
|
28
|
-
}
|
29
|
-
</script>
|
@@ -1,9 +0,0 @@
|
|
1
|
-
export type Props = {
|
2
|
-
depth?: RefsToResolve<RegisteredAccount>;
|
3
|
-
setResult: (result: ReturnType<typeof useAccountOrGuest> | undefined) => void;
|
4
|
-
};
|
5
|
-
import { useAccountOrGuest, type RegisteredAccount } from '../../jazz.svelte.js';
|
6
|
-
import type { RefsToResolve } from 'jazz-tools';
|
7
|
-
declare const UseAccountOrGuest: import("svelte").Component<Props, {}, "">;
|
8
|
-
type UseAccountOrGuest = ReturnType<typeof UseAccountOrGuest>;
|
9
|
-
export default UseAccountOrGuest;
|
@@ -1,21 +0,0 @@
|
|
1
|
-
<script lang="ts" module>
|
2
|
-
export type Props<R extends CoValue> = {
|
3
|
-
Schema: CoValueClass<R>;
|
4
|
-
id: ID<R>;
|
5
|
-
resolve: RefsToResolve<R>;
|
6
|
-
setResult: (result: R | undefined | null) => void;
|
7
|
-
};
|
8
|
-
</script>
|
9
|
-
|
10
|
-
<script lang="ts" generics="R extends CoValue">
|
11
|
-
import { useCoState } from '../../jazz.svelte.js';
|
12
|
-
import type { CoValue, CoValueClass, RefsToResolve, ID } from 'jazz-tools';
|
13
|
-
|
14
|
-
let { Schema, id, resolve, setResult }: Props<R> = $props();
|
15
|
-
|
16
|
-
const result = $derived(useCoState(Schema, id, { resolve: resolve as any }));
|
17
|
-
|
18
|
-
$effect(() => {
|
19
|
-
setResult(result.current);
|
20
|
-
});
|
21
|
-
</script>
|
@@ -1,24 +0,0 @@
|
|
1
|
-
export type Props<R extends CoValue> = {
|
2
|
-
Schema: CoValueClass<R>;
|
3
|
-
id: ID<R>;
|
4
|
-
resolve: RefsToResolve<R>;
|
5
|
-
setResult: (result: R | undefined | null) => void;
|
6
|
-
};
|
7
|
-
import type { CoValue, CoValueClass, RefsToResolve, ID } from 'jazz-tools';
|
8
|
-
declare class __sveltets_Render<R extends CoValue> {
|
9
|
-
props(): Props<R>;
|
10
|
-
events(): {};
|
11
|
-
slots(): {};
|
12
|
-
bindings(): "";
|
13
|
-
exports(): {};
|
14
|
-
}
|
15
|
-
interface $$IsomorphicComponent {
|
16
|
-
new <R extends CoValue>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<R>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<R>['props']>, ReturnType<__sveltets_Render<R>['events']>, ReturnType<__sveltets_Render<R>['slots']>> & {
|
17
|
-
$$bindings?: ReturnType<__sveltets_Render<R>['bindings']>;
|
18
|
-
} & ReturnType<__sveltets_Render<R>['exports']>;
|
19
|
-
<R extends CoValue>(internal: unknown, props: ReturnType<__sveltets_Render<R>['props']> & {}): ReturnType<__sveltets_Render<R>['exports']>;
|
20
|
-
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
21
|
-
}
|
22
|
-
declare const UseCoState: $$IsomorphicComponent;
|
23
|
-
type UseCoState<R extends CoValue> = InstanceType<typeof UseCoState<R>>;
|
24
|
-
export default UseCoState;
|