jazz-tools 0.20.0 → 0.20.2
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/.turbo/turbo-build.log +56 -56
- package/CHANGELOG.md +21 -0
- package/dist/{chunk-3CAPPS2F.js → chunk-Q5RNSSUM.js} +269 -95
- package/dist/chunk-Q5RNSSUM.js.map +1 -0
- package/dist/chunk-ZQWSQH6L.js +20 -0
- package/dist/index.js +2 -2
- package/dist/inspector/{chunk-MCTB5ZJC.js → chunk-6JPVMI3V.js} +302 -182
- package/dist/inspector/chunk-6JPVMI3V.js.map +1 -0
- package/dist/inspector/{custom-element-5YWVZBWA.js → custom-element-PWRX4VCA.js} +1337 -206
- package/dist/inspector/custom-element-PWRX4VCA.js.map +1 -0
- package/dist/inspector/in-app.d.ts +1 -0
- package/dist/inspector/in-app.d.ts.map +1 -1
- package/dist/inspector/index.d.ts +1 -0
- package/dist/inspector/index.d.ts.map +1 -1
- package/dist/inspector/index.js +1044 -17
- package/dist/inspector/index.js.map +1 -1
- package/dist/inspector/pages/home.d.ts +4 -1
- package/dist/inspector/pages/home.d.ts.map +1 -1
- package/dist/inspector/pages/performance/PerformancePage.d.ts +7 -0
- package/dist/inspector/pages/performance/PerformancePage.d.ts.map +1 -0
- package/dist/inspector/pages/performance/SubscriptionDetailPanel.d.ts +8 -0
- package/dist/inspector/pages/performance/SubscriptionDetailPanel.d.ts.map +1 -0
- package/dist/inspector/pages/performance/SubscriptionRow.d.ts +11 -0
- package/dist/inspector/pages/performance/SubscriptionRow.d.ts.map +1 -0
- package/dist/inspector/pages/performance/Timeline.d.ts +12 -0
- package/dist/inspector/pages/performance/Timeline.d.ts.map +1 -0
- package/dist/inspector/pages/performance/helpers.d.ts +5 -0
- package/dist/inspector/pages/performance/helpers.d.ts.map +1 -0
- package/dist/inspector/pages/performance/index.d.ts +3 -0
- package/dist/inspector/pages/performance/index.d.ts.map +1 -0
- package/dist/inspector/pages/performance/types.d.ts +13 -0
- package/dist/inspector/pages/performance/types.d.ts.map +1 -0
- package/dist/inspector/pages/performance/usePerformanceEntries.d.ts +3 -0
- package/dist/inspector/pages/performance/usePerformanceEntries.d.ts.map +1 -0
- package/dist/inspector/register-custom-element.js +3 -1
- package/dist/inspector/register-custom-element.js.map +1 -1
- package/dist/inspector/standalone.js +1 -1
- package/dist/inspector/tests/pages/performance/PerformancePage.test.d.ts +2 -0
- package/dist/inspector/tests/pages/performance/PerformancePage.test.d.ts.map +1 -0
- package/dist/inspector/tests/pages/performance/SubscriptionDetailPanel.test.d.ts +2 -0
- package/dist/inspector/tests/pages/performance/SubscriptionDetailPanel.test.d.ts.map +1 -0
- package/dist/inspector/tests/pages/performance/SubscriptionRow.test.d.ts +2 -0
- package/dist/inspector/tests/pages/performance/SubscriptionRow.test.d.ts.map +1 -0
- package/dist/inspector/tests/pages/performance/Timeline.test.d.ts +2 -0
- package/dist/inspector/tests/pages/performance/Timeline.test.d.ts.map +1 -0
- package/dist/inspector/tests/pages/performance/helpers.test.d.ts +2 -0
- package/dist/inspector/tests/pages/performance/helpers.test.d.ts.map +1 -0
- package/dist/inspector/viewer/delete-local-data.d.ts.map +1 -1
- package/dist/inspector/viewer/header.d.ts +4 -2
- package/dist/inspector/viewer/header.d.ts.map +1 -1
- package/dist/inspector/viewer/page-stack.d.ts +3 -1
- package/dist/inspector/viewer/page-stack.d.ts.map +1 -1
- package/dist/react-core/hooks.d.ts +2 -2
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +50 -18
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-core/subscription-provider.d.ts.map +1 -1
- package/dist/react-native-core/media/image.d.ts +1 -1
- package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
- package/dist/svelte/jazz.class.svelte.js +27 -22
- package/dist/testing.js +2 -2
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/exports.d.ts +1 -1
- package/dist/tools/exports.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +2 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +2 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +2 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts +3 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +3 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +2 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +6 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
- package/dist/tools/ssr.js +1 -1
- package/dist/tools/subscribe/SubscriptionCache.d.ts +2 -2
- package/dist/tools/subscribe/SubscriptionCache.d.ts.map +1 -1
- package/dist/tools/subscribe/SubscriptionScope.d.ts +19 -12
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/dist/tools/subscribe/errorReporting.d.ts +6 -0
- package/dist/tools/subscribe/errorReporting.d.ts.map +1 -1
- package/dist/tools/subscribe/index.d.ts +4 -4
- package/dist/tools/subscribe/index.d.ts.map +1 -1
- package/dist/tools/subscribe/types.d.ts +48 -3
- package/dist/tools/subscribe/types.d.ts.map +1 -1
- package/dist/tools/subscribe/utils.d.ts +1 -1
- package/dist/tools/subscribe/utils.d.ts.map +1 -1
- package/dist/tools/tests/SubscriptionScope.performance.test.d.ts +2 -0
- package/dist/tools/tests/SubscriptionScope.performance.test.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/inspector/in-app.tsx +41 -3
- package/src/inspector/index.tsx +5 -1
- package/src/inspector/pages/home.tsx +26 -3
- package/src/inspector/pages/performance/PerformancePage.tsx +215 -0
- package/src/inspector/pages/performance/SubscriptionDetailPanel.tsx +182 -0
- package/src/inspector/pages/performance/SubscriptionRow.tsx +242 -0
- package/src/inspector/pages/performance/Timeline.tsx +513 -0
- package/src/inspector/pages/performance/helpers.ts +70 -0
- package/src/inspector/pages/performance/index.ts +2 -0
- package/src/inspector/pages/performance/types.ts +12 -0
- package/src/inspector/pages/performance/usePerformanceEntries.ts +53 -0
- package/src/inspector/register-custom-element.ts +3 -0
- package/src/inspector/tests/pages/performance/PerformancePage.test.tsx +83 -0
- package/src/inspector/tests/pages/performance/SubscriptionDetailPanel.test.tsx +68 -0
- package/src/inspector/tests/pages/performance/SubscriptionRow.test.tsx +93 -0
- package/src/inspector/tests/pages/performance/Timeline.test.tsx +57 -0
- package/src/inspector/tests/pages/performance/helpers.test.ts +91 -0
- package/src/inspector/viewer/delete-local-data.tsx +24 -5
- package/src/inspector/viewer/header.tsx +96 -17
- package/src/inspector/viewer/page-stack.tsx +22 -18
- package/src/react-core/hooks.ts +34 -4
- package/src/react-core/subscription-provider.tsx +17 -8
- package/src/svelte/jazz.class.svelte.ts +51 -33
- package/src/tools/coValues/coList.ts +73 -37
- package/src/tools/coValues/interfaces.ts +3 -0
- package/src/tools/exports.ts +1 -0
- package/src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts +13 -0
- package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +0 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +5 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +5 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +5 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.ts +6 -2
- package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +6 -2
- package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +5 -2
- package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +9 -2
- package/src/tools/subscribe/SubscriptionCache.ts +6 -4
- package/src/tools/subscribe/SubscriptionScope.ts +141 -23
- package/src/tools/subscribe/errorReporting.ts +1 -1
- package/src/tools/subscribe/index.ts +1 -1
- package/src/tools/subscribe/types.ts +62 -9
- package/src/tools/subscribe/utils.ts +2 -2
- package/src/tools/tests/SubscriptionScope.performance.test.ts +149 -0
- package/src/tools/tests/coList.test.ts +262 -0
- package/src/tools/tests/schema.withPermissions.test.ts +27 -4
- package/dist/chunk-3CAPPS2F.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -10
- package/dist/inspector/chunk-MCTB5ZJC.js.map +0 -1
- package/dist/inspector/custom-element-5YWVZBWA.js.map +0 -1
- /package/dist/{chunk-PZ5AY32C.js.map → chunk-ZQWSQH6L.js.map} +0 -0
package/src/react-core/hooks.ts
CHANGED
|
@@ -101,6 +101,7 @@ export function useCoValueSubscription<
|
|
|
101
101
|
resolve?: ResolveQueryStrict<S, R>;
|
|
102
102
|
unstable_branch?: BranchDefinition;
|
|
103
103
|
},
|
|
104
|
+
source?: string,
|
|
104
105
|
): CoValueSubscription<S, R> | null {
|
|
105
106
|
const resolve = getResolveQuery(Schema, options?.resolve);
|
|
106
107
|
const subscriptions = useCoValueSubscriptions(
|
|
@@ -108,6 +109,7 @@ export function useCoValueSubscription<
|
|
|
108
109
|
[id],
|
|
109
110
|
resolve,
|
|
110
111
|
options?.unstable_branch,
|
|
112
|
+
source,
|
|
111
113
|
);
|
|
112
114
|
return (subscriptions[0] ?? null) as CoValueSubscription<S, R> | null;
|
|
113
115
|
}
|
|
@@ -140,6 +142,7 @@ function useCoValueSubscriptions(
|
|
|
140
142
|
ids: readonly (string | undefined | null)[],
|
|
141
143
|
resolve: ResolveQuery<any>,
|
|
142
144
|
branch?: BranchDefinition,
|
|
145
|
+
source?: string,
|
|
143
146
|
): (SubscriptionScope<CoValue> | null)[] {
|
|
144
147
|
const contextManager = useJazzContext();
|
|
145
148
|
const agent = useAgent();
|
|
@@ -169,6 +172,9 @@ function useCoValueSubscriptions(
|
|
|
169
172
|
subscription.callerStack = callerStack;
|
|
170
173
|
}
|
|
171
174
|
|
|
175
|
+
// Track performance for root subscriptions
|
|
176
|
+
subscription.trackLoadingPerformance(source ?? "unknown");
|
|
177
|
+
|
|
172
178
|
return subscription;
|
|
173
179
|
});
|
|
174
180
|
|
|
@@ -428,7 +434,12 @@ export function useCoState<
|
|
|
428
434
|
},
|
|
429
435
|
): TSelectorReturn {
|
|
430
436
|
useImportCoValueContent(id, options?.preloaded);
|
|
431
|
-
const subscription = useCoValueSubscription(
|
|
437
|
+
const subscription = useCoValueSubscription(
|
|
438
|
+
Schema,
|
|
439
|
+
id,
|
|
440
|
+
options,
|
|
441
|
+
`useCoState`,
|
|
442
|
+
);
|
|
432
443
|
return useSubscriptionSelector(subscription, options);
|
|
433
444
|
}
|
|
434
445
|
|
|
@@ -471,7 +482,12 @@ export function useSuspenseCoState<
|
|
|
471
482
|
): TSelectorReturn {
|
|
472
483
|
useImportCoValueContent(id, options?.preloaded);
|
|
473
484
|
|
|
474
|
-
const subscription = useCoValueSubscription(
|
|
485
|
+
const subscription = useCoValueSubscription(
|
|
486
|
+
Schema,
|
|
487
|
+
id,
|
|
488
|
+
options,
|
|
489
|
+
"useSuspenseCoState",
|
|
490
|
+
);
|
|
475
491
|
|
|
476
492
|
if (!subscription) {
|
|
477
493
|
throw new Error("Subscription not found");
|
|
@@ -534,6 +550,7 @@ export function useAccountSubscription<
|
|
|
534
550
|
resolve?: ResolveQueryStrict<S, R>;
|
|
535
551
|
unstable_branch?: BranchDefinition;
|
|
536
552
|
},
|
|
553
|
+
source?: string,
|
|
537
554
|
) {
|
|
538
555
|
const contextManager = useJazzContext();
|
|
539
556
|
|
|
@@ -570,6 +587,9 @@ export function useAccountSubscription<
|
|
|
570
587
|
subscription.callerStack = callerStack;
|
|
571
588
|
}
|
|
572
589
|
|
|
590
|
+
// Track performance for root subscriptions
|
|
591
|
+
subscription.trackLoadingPerformance(source ?? "unknown");
|
|
592
|
+
|
|
573
593
|
return {
|
|
574
594
|
subscription,
|
|
575
595
|
contextManager,
|
|
@@ -727,7 +747,11 @@ export function useAccount<
|
|
|
727
747
|
unstable_branch?: BranchDefinition;
|
|
728
748
|
},
|
|
729
749
|
): TSelectorReturn {
|
|
730
|
-
const subscription = useAccountSubscription(
|
|
750
|
+
const subscription = useAccountSubscription(
|
|
751
|
+
AccountSchema,
|
|
752
|
+
options,
|
|
753
|
+
"useAccount",
|
|
754
|
+
);
|
|
731
755
|
return useSubscriptionSelector(subscription, options);
|
|
732
756
|
}
|
|
733
757
|
|
|
@@ -765,7 +789,11 @@ export function useSuspenseAccount<
|
|
|
765
789
|
unstable_branch?: BranchDefinition;
|
|
766
790
|
},
|
|
767
791
|
): TSelectorReturn {
|
|
768
|
-
const subscription = useAccountSubscription(
|
|
792
|
+
const subscription = useAccountSubscription(
|
|
793
|
+
AccountSchema,
|
|
794
|
+
options,
|
|
795
|
+
"useSuspenseAccount",
|
|
796
|
+
);
|
|
769
797
|
|
|
770
798
|
if (!subscription) {
|
|
771
799
|
throw new Error(
|
|
@@ -1054,6 +1082,7 @@ export function useSuspenseCoStates<
|
|
|
1054
1082
|
ids,
|
|
1055
1083
|
resolve,
|
|
1056
1084
|
options?.unstable_branch,
|
|
1085
|
+
"useSuspenseCoStates",
|
|
1057
1086
|
) as SubscriptionScope<CoValue>[];
|
|
1058
1087
|
useSuspendUntilLoaded(subscriptionScopes);
|
|
1059
1088
|
return useSubscriptionsSelector(subscriptionScopes, options);
|
|
@@ -1123,6 +1152,7 @@ export function useCoStates<
|
|
|
1123
1152
|
ids,
|
|
1124
1153
|
resolve,
|
|
1125
1154
|
options?.unstable_branch,
|
|
1155
|
+
"useCoStates",
|
|
1126
1156
|
) as SubscriptionScope<CoValue>[];
|
|
1127
1157
|
return useSubscriptionsSelector(subscriptionScopes, options);
|
|
1128
1158
|
}
|
|
@@ -39,10 +39,15 @@ export function createCoValueSubscriptionContext<
|
|
|
39
39
|
loadingFallback?: React.ReactNode;
|
|
40
40
|
unavailableFallback?: React.ReactNode;
|
|
41
41
|
}>) => {
|
|
42
|
-
const subscription = useCoValueSubscription(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
const subscription = useCoValueSubscription(
|
|
43
|
+
schema,
|
|
44
|
+
id,
|
|
45
|
+
{
|
|
46
|
+
...options,
|
|
47
|
+
resolve: resolve,
|
|
48
|
+
},
|
|
49
|
+
"CoValueSubscriptionProvider",
|
|
50
|
+
);
|
|
46
51
|
|
|
47
52
|
const loadState = useSubscriptionSelector(subscription, {
|
|
48
53
|
select: (value) => value.$jazz.loadingState,
|
|
@@ -104,10 +109,14 @@ export function createAccountSubscriptionContext<
|
|
|
104
109
|
loadingFallback?: React.ReactNode;
|
|
105
110
|
unavailableFallback?: React.ReactNode;
|
|
106
111
|
}>) => {
|
|
107
|
-
const subscription = useAccountSubscription(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
const subscription = useAccountSubscription(
|
|
113
|
+
schema,
|
|
114
|
+
{
|
|
115
|
+
...options,
|
|
116
|
+
resolve: resolve,
|
|
117
|
+
},
|
|
118
|
+
"AccountSubscriptionProvider",
|
|
119
|
+
);
|
|
111
120
|
|
|
112
121
|
const loadState = useSubscriptionSelector(subscription, {
|
|
113
122
|
select: (value) => value.$jazz.loadingState,
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
AnyAccountSchema,
|
|
5
5
|
BranchDefinition,
|
|
6
6
|
CoValue,
|
|
7
|
+
CoValueClass,
|
|
7
8
|
CoValueClassOrSchema,
|
|
8
9
|
CoValueFromRaw,
|
|
9
10
|
SchemaResolveQuery,
|
|
@@ -15,10 +16,11 @@ import type {
|
|
|
15
16
|
ResolveQueryStrict,
|
|
16
17
|
} from "jazz-tools";
|
|
17
18
|
import {
|
|
19
|
+
captureStack,
|
|
18
20
|
coValueClassFromCoValueClassOrSchema,
|
|
19
|
-
subscribeToCoValue,
|
|
20
21
|
CoValueLoadingState,
|
|
21
22
|
getUnloadedCoValueWithoutId,
|
|
23
|
+
SubscriptionScope,
|
|
22
24
|
} from "jazz-tools";
|
|
23
25
|
import { untrack } from "svelte";
|
|
24
26
|
import { createSubscriber } from "svelte/reactivity";
|
|
@@ -69,6 +71,7 @@ export class CoState<
|
|
|
69
71
|
id: CoStateId | (() => CoStateId),
|
|
70
72
|
options?: CoStateOptions<V, R> | (() => CoStateOptions<V, R>),
|
|
71
73
|
) {
|
|
74
|
+
const callerStack = captureStack();
|
|
72
75
|
this.#id = $derived.by(typeof id === "function" ? id : () => id);
|
|
73
76
|
this.#options = $derived.by(
|
|
74
77
|
typeof options === "function" ? options : () => options,
|
|
@@ -89,29 +92,36 @@ export class CoState<
|
|
|
89
92
|
getUnloadedCoValueWithoutId(CoValueLoadingState.UNAVAILABLE),
|
|
90
93
|
);
|
|
91
94
|
}
|
|
95
|
+
|
|
92
96
|
const agent = "me" in ctx ? ctx.me : ctx.guest;
|
|
97
|
+
const node = "node" in agent ? agent.node : agent.$jazz.localNode;
|
|
93
98
|
const resolve = getResolveQuery(Schema, options?.resolve);
|
|
99
|
+
const cls = coValueClassFromCoValueClassOrSchema(Schema) as CoValueClass<Loaded<V, R>>;
|
|
94
100
|
|
|
95
|
-
const
|
|
96
|
-
|
|
101
|
+
const subscriptionScope = new SubscriptionScope<Loaded<V, R>>(
|
|
102
|
+
node,
|
|
103
|
+
resolve,
|
|
97
104
|
id,
|
|
98
|
-
{
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
onError: (value) => {
|
|
103
|
-
this.update(value);
|
|
104
|
-
},
|
|
105
|
-
syncResolution: true,
|
|
106
|
-
unstable_branch: options?.unstable_branch,
|
|
107
|
-
},
|
|
108
|
-
(value) => {
|
|
109
|
-
this.update(value as Loaded<V, R>);
|
|
110
|
-
},
|
|
105
|
+
{ ref: cls, optional: false },
|
|
106
|
+
false, // skipRetry
|
|
107
|
+
false, // bestEffortResolution
|
|
108
|
+
options?.unstable_branch,
|
|
111
109
|
);
|
|
112
110
|
|
|
111
|
+
subscriptionScope.callerStack = callerStack;
|
|
112
|
+
|
|
113
|
+
// Track performance for Svelte subscriptions
|
|
114
|
+
subscriptionScope.trackLoadingPerformance("CoState");
|
|
115
|
+
|
|
116
|
+
subscriptionScope.subscribe(() => {
|
|
117
|
+
const value = subscriptionScope.getCurrentValue();
|
|
118
|
+
this.update(value);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
this.update(subscriptionScope.getCurrentValue());
|
|
122
|
+
|
|
113
123
|
return () => {
|
|
114
|
-
|
|
124
|
+
subscriptionScope.destroy();
|
|
115
125
|
};
|
|
116
126
|
});
|
|
117
127
|
});
|
|
@@ -150,6 +160,7 @@ export class AccountCoState<
|
|
|
150
160
|
Schema: A,
|
|
151
161
|
options?: CoStateOptions<A, R> | (() => CoStateOptions<A, R>),
|
|
152
162
|
) {
|
|
163
|
+
const callerStack = captureStack();
|
|
153
164
|
this.#options = $derived.by(
|
|
154
165
|
typeof options === "function" ? options : () => options,
|
|
155
166
|
);
|
|
@@ -170,27 +181,34 @@ export class AccountCoState<
|
|
|
170
181
|
}
|
|
171
182
|
|
|
172
183
|
const me = ctx.me;
|
|
184
|
+
const node = me.$jazz.localNode;
|
|
173
185
|
const resolve = getResolveQuery(Schema, options?.resolve);
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
186
|
+
const cls = coValueClassFromCoValueClassOrSchema(Schema) as CoValueClass<Loaded<A, R>>;
|
|
187
|
+
|
|
188
|
+
const subscriptionScope = new SubscriptionScope<Loaded<A, R>>(
|
|
189
|
+
node,
|
|
190
|
+
resolve,
|
|
177
191
|
me.$jazz.id,
|
|
178
|
-
{
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
this.update(value);
|
|
183
|
-
},
|
|
184
|
-
syncResolution: true,
|
|
185
|
-
unstable_branch: options?.unstable_branch,
|
|
186
|
-
},
|
|
187
|
-
(value) => {
|
|
188
|
-
this.update(value as Loaded<A, R>);
|
|
189
|
-
},
|
|
192
|
+
{ ref: cls, optional: false },
|
|
193
|
+
false, // skipRetry
|
|
194
|
+
false, // bestEffortResolution
|
|
195
|
+
options?.unstable_branch,
|
|
190
196
|
);
|
|
191
197
|
|
|
198
|
+
subscriptionScope.callerStack = callerStack;
|
|
199
|
+
|
|
200
|
+
// Track performance for Svelte subscriptions
|
|
201
|
+
subscriptionScope.trackLoadingPerformance("AccountCoState");
|
|
202
|
+
|
|
203
|
+
subscriptionScope.subscribe(() => {
|
|
204
|
+
const value = subscriptionScope.getCurrentValue();
|
|
205
|
+
this.update(value);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
this.update(subscriptionScope.getCurrentValue());
|
|
209
|
+
|
|
192
210
|
return () => {
|
|
193
|
-
|
|
211
|
+
subscriptionScope.destroy();
|
|
194
212
|
};
|
|
195
213
|
});
|
|
196
214
|
});
|
|
@@ -549,7 +549,7 @@ export class CoListJazzApi<L extends CoList> extends CoValueJazzApi<L> {
|
|
|
549
549
|
"private",
|
|
550
550
|
);
|
|
551
551
|
|
|
552
|
-
return this.raw.
|
|
552
|
+
return this.raw.length();
|
|
553
553
|
}
|
|
554
554
|
|
|
555
555
|
/**
|
|
@@ -567,7 +567,7 @@ export class CoListJazzApi<L extends CoList> extends CoValueJazzApi<L> {
|
|
|
567
567
|
this.raw.prepend(item);
|
|
568
568
|
}
|
|
569
569
|
|
|
570
|
-
return this.raw.
|
|
570
|
+
return this.raw.length();
|
|
571
571
|
}
|
|
572
572
|
|
|
573
573
|
/**
|
|
@@ -936,40 +936,65 @@ function toRawItems<Item>(
|
|
|
936
936
|
return rawItems;
|
|
937
937
|
}
|
|
938
938
|
|
|
939
|
+
function getCoListItemValue(target: CoList, key: string) {
|
|
940
|
+
const rawValue = target.$jazz.raw.get(Number(key));
|
|
941
|
+
|
|
942
|
+
if (rawValue === undefined) {
|
|
943
|
+
return undefined;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
const itemDescriptor: Schema = target.$jazz.schema[ItemsSym];
|
|
947
|
+
|
|
948
|
+
if (itemDescriptor === "json") {
|
|
949
|
+
return rawValue;
|
|
950
|
+
} else if ("encoded" in itemDescriptor) {
|
|
951
|
+
return itemDescriptor.encoded.decode(rawValue);
|
|
952
|
+
} else if (isRefEncoded(itemDescriptor)) {
|
|
953
|
+
if (rawValue === null) {
|
|
954
|
+
return undefined;
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
return accessChildByKey(target, rawValue as string, key);
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
return undefined;
|
|
961
|
+
}
|
|
962
|
+
|
|
939
963
|
const CoListProxyHandler: ProxyHandler<CoList> = {
|
|
940
964
|
get(target, key, receiver) {
|
|
941
|
-
if (typeof key === "
|
|
942
|
-
const itemDescriptor = target.$jazz.schema[ItemsSym] as Schema;
|
|
943
|
-
const rawValue = target.$jazz.raw.get(Number(key));
|
|
944
|
-
if (itemDescriptor === "json") {
|
|
945
|
-
return rawValue;
|
|
946
|
-
} else if ("encoded" in itemDescriptor) {
|
|
947
|
-
return rawValue === undefined
|
|
948
|
-
? undefined
|
|
949
|
-
: itemDescriptor.encoded.decode(rawValue);
|
|
950
|
-
} else if (isRefEncoded(itemDescriptor)) {
|
|
951
|
-
return rawValue === undefined || rawValue === null
|
|
952
|
-
? undefined
|
|
953
|
-
: accessChildByKey(target, rawValue as string, key);
|
|
954
|
-
}
|
|
955
|
-
} else if (key === "length") {
|
|
956
|
-
return target.$jazz.raw.entries().length;
|
|
957
|
-
} else {
|
|
965
|
+
if (typeof key === "symbol") {
|
|
958
966
|
return Reflect.get(target, key, receiver);
|
|
959
967
|
}
|
|
968
|
+
|
|
969
|
+
if (!isNaN(+key)) {
|
|
970
|
+
return getCoListItemValue(target, key);
|
|
971
|
+
} else if (key === "length") {
|
|
972
|
+
return target.$jazz.raw.length();
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
return Reflect.get(target, key, receiver);
|
|
960
976
|
},
|
|
961
977
|
set(target, key, value, receiver) {
|
|
978
|
+
if (typeof key === "symbol") {
|
|
979
|
+
return Reflect.set(target, key, value, receiver);
|
|
980
|
+
}
|
|
981
|
+
|
|
962
982
|
if (key === ItemsSym && typeof value === "object" && SchemaInit in value) {
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
983
|
+
const constructor = target.constructor as typeof CoList;
|
|
984
|
+
|
|
985
|
+
if (!constructor._schema) {
|
|
986
|
+
constructor._schema = {};
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
constructor._schema[ItemsSym] = value[SchemaInit];
|
|
966
990
|
return true;
|
|
967
991
|
}
|
|
968
|
-
|
|
992
|
+
|
|
993
|
+
if (!isNaN(+key)) {
|
|
969
994
|
throw Error("Cannot update a CoList directly. Use `$jazz.set` instead.");
|
|
970
|
-
} else {
|
|
971
|
-
return Reflect.set(target, key, value, receiver);
|
|
972
995
|
}
|
|
996
|
+
|
|
997
|
+
return Reflect.set(target, key, value, receiver);
|
|
973
998
|
},
|
|
974
999
|
defineProperty(target, key, descriptor) {
|
|
975
1000
|
if (
|
|
@@ -978,9 +1003,13 @@ const CoListProxyHandler: ProxyHandler<CoList> = {
|
|
|
978
1003
|
typeof descriptor.value === "object" &&
|
|
979
1004
|
SchemaInit in descriptor.value
|
|
980
1005
|
) {
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1006
|
+
const constructor = target.constructor as typeof CoList;
|
|
1007
|
+
|
|
1008
|
+
if (!constructor._schema) {
|
|
1009
|
+
constructor._schema = {};
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
constructor._schema[ItemsSym] = descriptor.value[SchemaInit];
|
|
984
1013
|
return true;
|
|
985
1014
|
} else {
|
|
986
1015
|
return Reflect.defineProperty(target, key, descriptor);
|
|
@@ -988,7 +1017,7 @@ const CoListProxyHandler: ProxyHandler<CoList> = {
|
|
|
988
1017
|
},
|
|
989
1018
|
has(target, key) {
|
|
990
1019
|
if (typeof key === "string" && !isNaN(+key)) {
|
|
991
|
-
return Number(key) < target.$jazz.raw.
|
|
1020
|
+
return Number(key) < target.$jazz.raw.length();
|
|
992
1021
|
} else {
|
|
993
1022
|
return Reflect.has(target, key);
|
|
994
1023
|
}
|
|
@@ -996,11 +1025,17 @@ const CoListProxyHandler: ProxyHandler<CoList> = {
|
|
|
996
1025
|
ownKeys(target) {
|
|
997
1026
|
const keys = Reflect.ownKeys(target);
|
|
998
1027
|
// Add numeric indices for all entries in the list
|
|
999
|
-
const
|
|
1000
|
-
|
|
1028
|
+
const length = target.$jazz.raw.length();
|
|
1029
|
+
for (let i = 0; i < length; i++) {
|
|
1030
|
+
keys.push(String(i));
|
|
1031
|
+
}
|
|
1001
1032
|
return keys;
|
|
1002
1033
|
},
|
|
1003
1034
|
getOwnPropertyDescriptor(target, key) {
|
|
1035
|
+
if (typeof key === "symbol") {
|
|
1036
|
+
return Reflect.getOwnPropertyDescriptor(target, key);
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1004
1039
|
if (key === TypeSym) {
|
|
1005
1040
|
// Make TypeSym non-enumerable so it doesn't show up in Object.keys()
|
|
1006
1041
|
return {
|
|
@@ -1009,23 +1044,24 @@ const CoListProxyHandler: ProxyHandler<CoList> = {
|
|
|
1009
1044
|
writable: false,
|
|
1010
1045
|
value: target[TypeSym],
|
|
1011
1046
|
};
|
|
1012
|
-
} else if (key
|
|
1013
|
-
return Reflect.getOwnPropertyDescriptor(target, key);
|
|
1014
|
-
} else if (typeof key === "string" && !isNaN(+key)) {
|
|
1047
|
+
} else if (!isNaN(+key)) {
|
|
1015
1048
|
const index = Number(key);
|
|
1016
|
-
if (index >= 0 && index < target.$jazz.raw.
|
|
1049
|
+
if (index >= 0 && index < target.$jazz.raw.length()) {
|
|
1017
1050
|
return {
|
|
1018
1051
|
enumerable: true,
|
|
1019
1052
|
configurable: true,
|
|
1020
|
-
writable:
|
|
1053
|
+
writable: false,
|
|
1054
|
+
value: getCoListItemValue(target, key),
|
|
1021
1055
|
};
|
|
1022
1056
|
}
|
|
1023
1057
|
} else if (key === "length") {
|
|
1024
1058
|
return {
|
|
1025
1059
|
enumerable: false,
|
|
1026
1060
|
configurable: false,
|
|
1027
|
-
writable:
|
|
1061
|
+
writable: true, // Must be writable, otherwise JS complains
|
|
1062
|
+
value: target.$jazz.raw.length(),
|
|
1028
1063
|
};
|
|
1029
1064
|
}
|
|
1065
|
+
return Reflect.getOwnPropertyDescriptor(target, key);
|
|
1030
1066
|
},
|
|
1031
1067
|
};
|
package/src/tools/exports.ts
CHANGED
|
@@ -39,6 +39,19 @@ import {
|
|
|
39
39
|
schemaFieldToCoFieldDef,
|
|
40
40
|
} from "./schemaFieldToCoFieldDef.js";
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* A platform agnostic way to check if we're in development mode
|
|
44
|
+
*
|
|
45
|
+
* Works in Node.js and bundled code, falls back to false if process is not available
|
|
46
|
+
*/
|
|
47
|
+
const isDev = (function () {
|
|
48
|
+
try {
|
|
49
|
+
return process.env.NODE_ENV === "development";
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
})();
|
|
54
|
+
|
|
42
55
|
// Note: if you're editing this function, edit the `isAnyCoValueSchema`
|
|
43
56
|
// function in `zodReExport.ts` as well
|
|
44
57
|
export function isAnyCoValueSchema(
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Account,
|
|
3
|
-
AccountCreationProps,
|
|
4
3
|
BranchDefinition,
|
|
5
4
|
CoMapSchemaDefinition,
|
|
6
5
|
coOptionalDefiner,
|
|
@@ -16,7 +15,6 @@ import {
|
|
|
16
15
|
} from "../../../internal.js";
|
|
17
16
|
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
|
18
17
|
import { InstanceOrPrimitiveOfSchema } from "../typeConverters/InstanceOrPrimitiveOfSchema.js";
|
|
19
|
-
import { InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded } from "../typeConverters/InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded.js";
|
|
20
18
|
import { z } from "../zodReExport.js";
|
|
21
19
|
import { AnyZodOrCoValueSchema, Loaded, ResolveQuery } from "../zodSchema.js";
|
|
22
20
|
import {
|
|
@@ -42,11 +42,14 @@ export class CoFeedSchema<
|
|
|
42
42
|
*/
|
|
43
43
|
resolveQuery: DefaultResolveQuery = true as DefaultResolveQuery;
|
|
44
44
|
|
|
45
|
+
#permissions: SchemaPermissions | null = null;
|
|
45
46
|
/**
|
|
46
47
|
* Permissions to be used when creating or composing CoValues
|
|
47
48
|
* @internal
|
|
48
49
|
*/
|
|
49
|
-
permissions: SchemaPermissions
|
|
50
|
+
get permissions(): SchemaPermissions {
|
|
51
|
+
return this.#permissions ?? DEFAULT_SCHEMA_PERMISSIONS;
|
|
52
|
+
}
|
|
50
53
|
|
|
51
54
|
constructor(
|
|
52
55
|
public element: T,
|
|
@@ -209,7 +212,7 @@ export class CoFeedSchema<
|
|
|
209
212
|
hydrateCoreCoValueSchema(coreSchema);
|
|
210
213
|
// @ts-expect-error TS cannot infer that the resolveQuery type is valid
|
|
211
214
|
copy.resolveQuery = resolveQuery ?? this.resolveQuery;
|
|
212
|
-
copy
|
|
215
|
+
copy.#permissions = permissions ?? this.#permissions;
|
|
213
216
|
return copy;
|
|
214
217
|
}
|
|
215
218
|
}
|
|
@@ -44,11 +44,14 @@ export class CoListSchema<
|
|
|
44
44
|
*/
|
|
45
45
|
resolveQuery: DefaultResolveQuery = true as DefaultResolveQuery;
|
|
46
46
|
|
|
47
|
+
#permissions: SchemaPermissions | null = null;
|
|
47
48
|
/**
|
|
48
49
|
* Permissions to be used when creating or composing CoValues
|
|
49
50
|
* @internal
|
|
50
51
|
*/
|
|
51
|
-
permissions: SchemaPermissions
|
|
52
|
+
get permissions(): SchemaPermissions {
|
|
53
|
+
return this.#permissions ?? DEFAULT_SCHEMA_PERMISSIONS;
|
|
54
|
+
}
|
|
52
55
|
|
|
53
56
|
constructor(
|
|
54
57
|
public element: T,
|
|
@@ -262,7 +265,7 @@ export class CoListSchema<
|
|
|
262
265
|
hydrateCoreCoValueSchema(coreSchema);
|
|
263
266
|
// @ts-expect-error TS cannot infer that the resolveQuery type is valid
|
|
264
267
|
copy.resolveQuery = resolveQuery ?? this.resolveQuery;
|
|
265
|
-
copy
|
|
268
|
+
copy.#permissions = permissions ?? this.#permissions;
|
|
266
269
|
return copy;
|
|
267
270
|
}
|
|
268
271
|
}
|
|
@@ -59,11 +59,14 @@ export class CoMapSchema<
|
|
|
59
59
|
*/
|
|
60
60
|
resolveQuery: DefaultResolveQuery = true as DefaultResolveQuery;
|
|
61
61
|
|
|
62
|
+
#permissions: SchemaPermissions | null = null;
|
|
62
63
|
/**
|
|
63
64
|
* Permissions to be used when creating or composing CoValues
|
|
64
65
|
* @internal
|
|
65
66
|
*/
|
|
66
|
-
permissions: SchemaPermissions
|
|
67
|
+
get permissions(): SchemaPermissions {
|
|
68
|
+
return this.#permissions ?? DEFAULT_SCHEMA_PERMISSIONS;
|
|
69
|
+
}
|
|
67
70
|
|
|
68
71
|
constructor(
|
|
69
72
|
coreSchema: CoreCoMapSchema<Shape, CatchAll>,
|
|
@@ -406,7 +409,7 @@ export class CoMapSchema<
|
|
|
406
409
|
copy.coValueClass.prototype.migrate = this.coValueClass.prototype.migrate;
|
|
407
410
|
// @ts-expect-error TS cannot infer that the resolveQuery type is valid
|
|
408
411
|
copy.resolveQuery = resolveQuery ?? this.resolveQuery;
|
|
409
|
-
copy
|
|
412
|
+
copy.#permissions = permissions ?? this.#permissions;
|
|
410
413
|
return copy;
|
|
411
414
|
}
|
|
412
415
|
}
|
|
@@ -36,10 +36,14 @@ export class CoVectorSchema implements CoreCoVectorSchema {
|
|
|
36
36
|
readonly builtin = "CoVector" as const;
|
|
37
37
|
readonly resolveQuery = true as const;
|
|
38
38
|
|
|
39
|
+
#permissions: SchemaPermissions | null = null;
|
|
39
40
|
/**
|
|
40
41
|
* Permissions to be used when creating or composing CoValues
|
|
42
|
+
* @internal
|
|
41
43
|
*/
|
|
42
|
-
permissions: SchemaPermissions
|
|
44
|
+
get permissions(): SchemaPermissions {
|
|
45
|
+
return this.#permissions ?? DEFAULT_SCHEMA_PERMISSIONS;
|
|
46
|
+
}
|
|
43
47
|
|
|
44
48
|
constructor(
|
|
45
49
|
public dimensions: number,
|
|
@@ -119,7 +123,7 @@ export class CoVectorSchema implements CoreCoVectorSchema {
|
|
|
119
123
|
*/
|
|
120
124
|
withPermissions(permissions: SchemaPermissions): CoVectorSchema {
|
|
121
125
|
const copy = new CoVectorSchema(this.dimensions, this.coValueClass);
|
|
122
|
-
copy
|
|
126
|
+
copy.#permissions = permissions;
|
|
123
127
|
return copy;
|
|
124
128
|
}
|
|
125
129
|
}
|
|
@@ -32,10 +32,14 @@ export class FileStreamSchema implements CoreFileStreamSchema {
|
|
|
32
32
|
readonly builtin = "FileStream" as const;
|
|
33
33
|
readonly resolveQuery = true as const;
|
|
34
34
|
|
|
35
|
+
#permissions: SchemaPermissions | null = null;
|
|
35
36
|
/**
|
|
36
37
|
* Permissions to be used when creating or composing CoValues
|
|
38
|
+
* @internal
|
|
37
39
|
*/
|
|
38
|
-
permissions: SchemaPermissions
|
|
40
|
+
get permissions(): SchemaPermissions {
|
|
41
|
+
return this.#permissions ?? DEFAULT_SCHEMA_PERMISSIONS;
|
|
42
|
+
}
|
|
39
43
|
|
|
40
44
|
constructor(private coValueClass: typeof FileStream) {}
|
|
41
45
|
|
|
@@ -159,7 +163,7 @@ export class FileStreamSchema implements CoreFileStreamSchema {
|
|
|
159
163
|
permissions: Omit<SchemaPermissions, "onInlineCreate">,
|
|
160
164
|
): FileStreamSchema {
|
|
161
165
|
const copy = new FileStreamSchema(this.coValueClass);
|
|
162
|
-
copy
|
|
166
|
+
copy.#permissions = permissions;
|
|
163
167
|
return copy;
|
|
164
168
|
}
|
|
165
169
|
}
|
|
@@ -34,11 +34,14 @@ export class PlainTextSchema implements CorePlainTextSchema {
|
|
|
34
34
|
readonly builtin = "CoPlainText" as const;
|
|
35
35
|
readonly resolveQuery = true as const;
|
|
36
36
|
|
|
37
|
+
#permissions: SchemaPermissions | null = null;
|
|
37
38
|
/**
|
|
38
39
|
* Permissions to be used when creating or composing CoValues
|
|
39
40
|
* @internal
|
|
40
41
|
*/
|
|
41
|
-
permissions: SchemaPermissions
|
|
42
|
+
get permissions(): SchemaPermissions {
|
|
43
|
+
return this.#permissions ?? DEFAULT_SCHEMA_PERMISSIONS;
|
|
44
|
+
}
|
|
42
45
|
|
|
43
46
|
constructor(private coValueClass: typeof CoPlainText) {}
|
|
44
47
|
|
|
@@ -111,7 +114,7 @@ export class PlainTextSchema implements CorePlainTextSchema {
|
|
|
111
114
|
*/
|
|
112
115
|
withPermissions(permissions: SchemaPermissions): PlainTextSchema {
|
|
113
116
|
const copy = new PlainTextSchema(this.coValueClass);
|
|
114
|
-
copy
|
|
117
|
+
copy.#permissions = permissions;
|
|
115
118
|
return copy;
|
|
116
119
|
}
|
|
117
120
|
}
|