jazz-tools 0.19.7 → 0.19.10
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 +65 -59
- package/CHANGELOG.md +34 -3
- package/dist/{chunk-CUS6O5NE.js → chunk-FFEEPZEG.js} +454 -122
- package/dist/chunk-FFEEPZEG.js.map +1 -0
- package/dist/expo/polyfills.js +22 -0
- package/dist/expo/polyfills.js.map +1 -0
- package/dist/index.js +26 -6
- package/dist/index.js.map +1 -1
- package/dist/react/hooks.d.ts +1 -1
- package/dist/react/hooks.d.ts.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +5 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-core/hooks.d.ts +59 -0
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +133 -34
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-core/tests/testUtils.d.ts +1 -0
- package/dist/react-core/tests/testUtils.d.ts.map +1 -1
- package/dist/react-core/tests/useSuspenseAccount.test.d.ts +2 -0
- package/dist/react-core/tests/useSuspenseAccount.test.d.ts.map +1 -0
- package/dist/react-core/tests/useSuspenseCoState.test.d.ts +2 -0
- package/dist/react-core/tests/useSuspenseCoState.test.d.ts.map +1 -0
- package/dist/react-core/use.d.ts +3 -0
- package/dist/react-core/use.d.ts.map +1 -0
- package/dist/react-native/index.d.ts +1 -1
- package/dist/react-native/index.d.ts.map +1 -1
- package/dist/react-native/index.js +717 -9
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native/polyfills.js +22 -0
- package/dist/react-native/polyfills.js.map +1 -0
- package/dist/react-native-core/crypto/RNCrypto.d.ts +2 -0
- package/dist/react-native-core/crypto/RNCrypto.d.ts.map +1 -0
- package/dist/react-native-core/crypto/RNCrypto.js +3 -0
- package/dist/react-native-core/crypto/RNCrypto.js.map +1 -0
- package/dist/react-native-core/hooks.d.ts +1 -1
- package/dist/react-native-core/hooks.d.ts.map +1 -1
- package/dist/react-native-core/index.d.ts.map +1 -1
- package/dist/react-native-core/index.js +5 -1
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/react-native-core/platform.d.ts +2 -1
- package/dist/react-native-core/platform.d.ts.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/testing.js.map +1 -1
- package/dist/tools/coValues/account.d.ts +3 -3
- package/dist/tools/coValues/account.d.ts.map +1 -1
- package/dist/tools/coValues/coFeed.d.ts +3 -3
- package/dist/tools/coValues/coFeed.d.ts.map +1 -1
- package/dist/tools/coValues/coList.d.ts +4 -4
- package/dist/tools/coValues/coList.d.ts.map +1 -1
- package/dist/tools/coValues/coMap.d.ts +7 -7
- package/dist/tools/coValues/coMap.d.ts.map +1 -1
- package/dist/tools/coValues/coPlainText.d.ts +2 -2
- package/dist/tools/coValues/coPlainText.d.ts.map +1 -1
- package/dist/tools/coValues/coVector.d.ts +2 -2
- package/dist/tools/coValues/coVector.d.ts.map +1 -1
- package/dist/tools/coValues/deepLoading.d.ts +24 -0
- package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
- package/dist/tools/coValues/group.d.ts +2 -2
- package/dist/tools/coValues/group.d.ts.map +1 -1
- package/dist/tools/coValues/interfaces.d.ts +7 -7
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/coValues/schemaUnion.d.ts +2 -2
- package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
- package/dist/tools/config.d.ts +3 -0
- package/dist/tools/config.d.ts.map +1 -0
- package/dist/tools/exports.d.ts +2 -0
- package/dist/tools/exports.d.ts.map +1 -1
- package/dist/tools/implementation/ContextManager.d.ts +3 -0
- package/dist/tools/implementation/ContextManager.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +2 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +2 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +2 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +4 -4
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +4 -4
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +4 -4
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +2 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts +2 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +2 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +2 -2
- 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/subscribe/CoValueCoreSubscription.d.ts +8 -22
- package/dist/tools/subscribe/CoValueCoreSubscription.d.ts.map +1 -1
- package/dist/tools/subscribe/JazzError.d.ts.map +1 -1
- package/dist/tools/subscribe/SubscriptionCache.d.ts +51 -0
- package/dist/tools/subscribe/SubscriptionCache.d.ts.map +1 -0
- package/dist/tools/subscribe/SubscriptionScope.d.ts +27 -2
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/dist/tools/subscribe/errorReporting.d.ts +31 -0
- package/dist/tools/subscribe/errorReporting.d.ts.map +1 -0
- package/dist/tools/subscribe/utils.d.ts +9 -1
- package/dist/tools/subscribe/utils.d.ts.map +1 -1
- package/dist/tools/testing.d.ts +2 -2
- package/dist/tools/testing.d.ts.map +1 -1
- package/dist/tools/tests/SubscriptionCache.test.d.ts +2 -0
- package/dist/tools/tests/SubscriptionCache.test.d.ts.map +1 -0
- package/dist/tools/tests/errorReporting.test.d.ts +2 -0
- package/dist/tools/tests/errorReporting.test.d.ts.map +1 -0
- package/package.json +22 -7
- package/src/react/hooks.tsx +2 -0
- package/src/react/index.ts +1 -14
- package/src/react-core/hooks.ts +181 -16
- package/src/react-core/tests/createCoValueSubscriptionContext.test.tsx +18 -8
- package/src/react-core/tests/testUtils.tsx +67 -5
- package/src/react-core/tests/useCoState.test.ts +3 -7
- package/src/react-core/tests/useSubscriptionSelector.test.ts +3 -7
- package/src/react-core/tests/useSuspenseAccount.test.tsx +343 -0
- package/src/react-core/tests/useSuspenseCoState.test.tsx +1182 -0
- package/src/react-core/use.ts +46 -0
- package/src/react-native/index.ts +1 -1
- package/src/react-native-core/crypto/RNCrypto.ts +1 -0
- package/src/react-native-core/hooks.tsx +2 -0
- package/src/react-native-core/index.ts +2 -0
- package/src/react-native-core/platform.ts +2 -1
- package/src/react-native-core/polyfills/index.js +28 -0
- package/src/tools/coValues/account.ts +3 -4
- package/src/tools/coValues/coFeed.ts +3 -2
- package/src/tools/coValues/coList.ts +4 -4
- package/src/tools/coValues/coMap.ts +4 -4
- package/src/tools/coValues/coPlainText.ts +2 -2
- package/src/tools/coValues/coVector.ts +2 -2
- package/src/tools/coValues/deepLoading.ts +31 -0
- package/src/tools/coValues/group.ts +2 -2
- package/src/tools/coValues/interfaces.ts +21 -26
- package/src/tools/coValues/schemaUnion.ts +2 -2
- package/src/tools/config.ts +9 -0
- package/src/tools/exports.ts +4 -0
- package/src/tools/implementation/ContextManager.ts +13 -0
- package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +2 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +2 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +2 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +4 -4
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +4 -4
- package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +4 -10
- package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +2 -2
- package/src/tools/implementation/zodSchema/schemaTypes/GroupSchema.ts +2 -2
- package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +2 -2
- package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +2 -2
- package/src/tools/subscribe/CoValueCoreSubscription.ts +71 -100
- package/src/tools/subscribe/JazzError.ts +9 -6
- package/src/tools/subscribe/SubscriptionCache.ts +272 -0
- package/src/tools/subscribe/SubscriptionScope.ts +218 -29
- package/src/tools/subscribe/errorReporting.ts +67 -0
- package/src/tools/subscribe/utils.ts +77 -0
- package/src/tools/testing.ts +0 -3
- package/src/tools/tests/CoValueCoreSubscription.test.ts +46 -12
- package/src/tools/tests/ContextManager.test.ts +85 -0
- package/src/tools/tests/SubscriptionCache.test.ts +237 -0
- package/src/tools/tests/coMap.test.ts +5 -7
- package/src/tools/tests/deepLoading.test.ts +47 -47
- package/src/tools/tests/errorReporting.test.ts +103 -0
- package/src/tools/tests/load.test.ts +21 -1
- package/src/tools/tests/request.test.ts +2 -1
- package/src/tools/tests/subscribe.test.ts +44 -0
- package/tsup.config.ts +17 -0
- package/dist/chunk-CUS6O5NE.js.map +0 -1
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
DiscriminableCoValueSchemaDefinition,
|
|
7
7
|
DiscriminableCoreCoValueSchema,
|
|
8
8
|
Group,
|
|
9
|
-
|
|
9
|
+
Settled,
|
|
10
10
|
RefsToResolve,
|
|
11
11
|
RefsToResolveStrict,
|
|
12
12
|
Resolved,
|
|
@@ -97,7 +97,7 @@ export class CoMapSchema<
|
|
|
97
97
|
unstable_branch?: BranchDefinition;
|
|
98
98
|
},
|
|
99
99
|
): Promise<
|
|
100
|
-
|
|
100
|
+
Settled<
|
|
101
101
|
Resolved<Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap, R>
|
|
102
102
|
>
|
|
103
103
|
> {
|
|
@@ -183,7 +183,7 @@ export class CoMapSchema<
|
|
|
183
183
|
R
|
|
184
184
|
>;
|
|
185
185
|
}): Promise<
|
|
186
|
-
|
|
186
|
+
Settled<
|
|
187
187
|
Resolved<Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap, R>
|
|
188
188
|
>
|
|
189
189
|
> {
|
|
@@ -210,7 +210,7 @@ export class CoMapSchema<
|
|
|
210
210
|
loadAs?: Account | AnonymousJazzAgent;
|
|
211
211
|
},
|
|
212
212
|
): Promise<
|
|
213
|
-
|
|
213
|
+
Settled<
|
|
214
214
|
Resolved<Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap, R>
|
|
215
215
|
>
|
|
216
216
|
> {
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
CoMapSchemaDefinition,
|
|
7
7
|
Group,
|
|
8
8
|
ID,
|
|
9
|
-
|
|
9
|
+
Settled,
|
|
10
10
|
RefsToResolve,
|
|
11
11
|
RefsToResolveStrict,
|
|
12
12
|
Resolved,
|
|
@@ -64,9 +64,7 @@ export interface CoRecordSchema<
|
|
|
64
64
|
loadAs?: Account | AnonymousJazzAgent;
|
|
65
65
|
unstable_branch?: BranchDefinition;
|
|
66
66
|
},
|
|
67
|
-
): Promise<
|
|
68
|
-
MaybeLoaded<Resolved<CoRecordInstanceCoValuesMaybeLoaded<K, V>, R>>
|
|
69
|
-
>;
|
|
67
|
+
): Promise<Settled<Resolved<CoRecordInstanceCoValuesMaybeLoaded<K, V>, R>>>;
|
|
70
68
|
|
|
71
69
|
unstable_merge<
|
|
72
70
|
const R extends RefsToResolve<
|
|
@@ -119,9 +117,7 @@ export interface CoRecordSchema<
|
|
|
119
117
|
unique: CoValueUniqueness["uniqueness"];
|
|
120
118
|
owner: Account | Group;
|
|
121
119
|
resolve?: RefsToResolveStrict<CoRecordInstanceCoValuesMaybeLoaded<K, V>, R>;
|
|
122
|
-
}): Promise<
|
|
123
|
-
MaybeLoaded<Resolved<CoRecordInstanceCoValuesMaybeLoaded<K, V>, R>>
|
|
124
|
-
>;
|
|
120
|
+
}): Promise<Settled<Resolved<CoRecordInstanceCoValuesMaybeLoaded<K, V>, R>>>;
|
|
125
121
|
|
|
126
122
|
loadUnique<
|
|
127
123
|
const R extends RefsToResolve<
|
|
@@ -138,9 +134,7 @@ export interface CoRecordSchema<
|
|
|
138
134
|
>;
|
|
139
135
|
loadAs?: Account | AnonymousJazzAgent;
|
|
140
136
|
},
|
|
141
|
-
): Promise<
|
|
142
|
-
MaybeLoaded<Resolved<CoRecordInstanceCoValuesMaybeLoaded<K, V>, R>>
|
|
143
|
-
>;
|
|
137
|
+
): Promise<Settled<Resolved<CoRecordInstanceCoValuesMaybeLoaded<K, V>, R>>>;
|
|
144
138
|
|
|
145
139
|
getCoValueClass: () => typeof CoMap;
|
|
146
140
|
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
AnonymousJazzAgent,
|
|
4
4
|
FileStream,
|
|
5
5
|
Group,
|
|
6
|
-
|
|
6
|
+
Settled,
|
|
7
7
|
coOptionalDefiner,
|
|
8
8
|
unstable_mergeBranchWithResolve,
|
|
9
9
|
} from "../../../internal.js";
|
|
@@ -82,7 +82,7 @@ export class FileStreamSchema implements CoreFileStreamSchema {
|
|
|
82
82
|
load(
|
|
83
83
|
id: string,
|
|
84
84
|
options?: { loadAs?: Account | AnonymousJazzAgent },
|
|
85
|
-
): Promise<
|
|
85
|
+
): Promise<Settled<FileStream>> {
|
|
86
86
|
return this.coValueClass.load(id, options);
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "../../../coValues/interfaces.js";
|
|
7
7
|
import {
|
|
8
8
|
Account,
|
|
9
|
-
|
|
9
|
+
Settled,
|
|
10
10
|
RefsToResolve,
|
|
11
11
|
RefsToResolveStrict,
|
|
12
12
|
Resolved,
|
|
@@ -52,7 +52,7 @@ export class GroupSchema implements CoreGroupSchema {
|
|
|
52
52
|
loadAs?: Account;
|
|
53
53
|
resolve?: RefsToResolveStrict<Group, R>;
|
|
54
54
|
},
|
|
55
|
-
): Promise<
|
|
55
|
+
): Promise<Settled<Group>> {
|
|
56
56
|
return Group.load(id, options);
|
|
57
57
|
}
|
|
58
58
|
createInvite<G extends Group>(
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
BranchDefinition,
|
|
5
5
|
CoPlainText,
|
|
6
6
|
Group,
|
|
7
|
-
|
|
7
|
+
Settled,
|
|
8
8
|
coOptionalDefiner,
|
|
9
9
|
unstable_mergeBranchWithResolve,
|
|
10
10
|
} from "../../../internal.js";
|
|
@@ -50,7 +50,7 @@ export class PlainTextSchema implements CorePlainTextSchema {
|
|
|
50
50
|
loadAs: Account | AnonymousJazzAgent;
|
|
51
51
|
unstable_branch?: BranchDefinition;
|
|
52
52
|
},
|
|
53
|
-
): Promise<
|
|
53
|
+
): Promise<Settled<CoPlainText>> {
|
|
54
54
|
return this.coValueClass.load(id, options);
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
BranchDefinition,
|
|
4
4
|
CoRichText,
|
|
5
5
|
Group,
|
|
6
|
-
|
|
6
|
+
Settled,
|
|
7
7
|
coOptionalDefiner,
|
|
8
8
|
unstable_mergeBranchWithResolve,
|
|
9
9
|
} from "../../../internal.js";
|
|
@@ -49,7 +49,7 @@ export class RichTextSchema implements CoreRichTextSchema {
|
|
|
49
49
|
loadAs: Account | AnonymousJazzAgent;
|
|
50
50
|
unstable_branch?: BranchDefinition;
|
|
51
51
|
},
|
|
52
|
-
): Promise<
|
|
52
|
+
): Promise<Settled<CoRichText>> {
|
|
53
53
|
return this.coValueClass.load(id, options);
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
cojsonInternals,
|
|
3
3
|
CoValueCore,
|
|
4
|
+
isRawCoID,
|
|
4
5
|
LocalNode,
|
|
5
6
|
RawCoID,
|
|
6
7
|
RawCoValue,
|
|
@@ -67,121 +68,76 @@ export class CoValueCoreSubscription {
|
|
|
67
68
|
private initializeSubscription(): void {
|
|
68
69
|
const source = this.source;
|
|
69
70
|
|
|
70
|
-
// If the
|
|
71
|
-
if (source.
|
|
72
|
-
this.
|
|
71
|
+
// If the ID is not a valid raw CoID, we immediately emit an unavailable event
|
|
72
|
+
if (!isRawCoID(source.id)) {
|
|
73
|
+
this.emit(CoValueLoadingState.UNAVAILABLE);
|
|
73
74
|
return;
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
// If a
|
|
77
|
+
// If we have a branch name, we handle branching
|
|
77
78
|
if (this.branchName) {
|
|
78
|
-
this.
|
|
79
|
+
this.handleBranching(this.branchName, this.branchOwnerId);
|
|
79
80
|
return;
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
// If we don't have a branch
|
|
83
|
-
this.
|
|
83
|
+
// If we don't have a branch name, we subscribe to the source directly
|
|
84
|
+
this.subscribe(this.source);
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.subscribe(this.source.getCurrentContent());
|
|
87
|
+
private handleBranching(branchName: string, branchOwnerId?: RawCoID) {
|
|
88
|
+
const source = this.source;
|
|
89
|
+
|
|
90
|
+
// If the source is not available, we wait for it to become available and then try to branch
|
|
91
|
+
if (!source.isAvailable()) {
|
|
92
|
+
this.waitForSourceToBecomeAvailable(branchName, branchOwnerId);
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (branch.isAvailable()) {
|
|
100
|
-
// Branch is available, subscribe to it
|
|
101
|
-
this.subscribe(branch.getCurrentContent());
|
|
96
|
+
// If the source is not branchable (e.g. it is a group), we subscribe to it directly
|
|
97
|
+
if (!cojsonInternals.canBeBranched(source)) {
|
|
98
|
+
this.subscribe(source);
|
|
102
99
|
return;
|
|
103
|
-
// If the branch hasn't been created, we create it directly so we can syncronously subscribe to it
|
|
104
|
-
} else if (!this.source.hasBranch(this.branchName, this.branchOwnerId)) {
|
|
105
|
-
this.source.createBranch(this.branchName, this.branchOwnerId);
|
|
106
|
-
this.subscribe(branch.getCurrentContent());
|
|
107
|
-
} else {
|
|
108
|
-
// Branch not available, fall through to checkout logic
|
|
109
|
-
this.handleBranchCheckout();
|
|
110
100
|
}
|
|
111
|
-
}
|
|
112
101
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (value !== CoValueLoadingState.UNAVAILABLE) {
|
|
124
|
-
// Branch checkout successful, subscribe to it
|
|
125
|
-
this.subscribe(value);
|
|
126
|
-
} else {
|
|
127
|
-
// Branch checkout failed, handle the error
|
|
128
|
-
this.handleUnavailableBranch();
|
|
129
|
-
}
|
|
130
|
-
})
|
|
131
|
-
.catch((error) => {
|
|
132
|
-
// Handle unexpected errors during branch checkout
|
|
133
|
-
console.error(error);
|
|
102
|
+
// Try to get the specific branch from the available source
|
|
103
|
+
const branch = source.getBranch(branchName, branchOwnerId);
|
|
104
|
+
|
|
105
|
+
// If the branch hasn't been created, we create it directly so we can syncronously subscribe to it
|
|
106
|
+
if (!branch.isAvailable() && !source.hasBranch(branchName, branchOwnerId)) {
|
|
107
|
+
try {
|
|
108
|
+
source.createBranch(branchName, branchOwnerId);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
// If the branch creation fails (provided group is not available), we emit an unavailable event
|
|
111
|
+
console.error("error creating branch", error);
|
|
134
112
|
this.emit(CoValueLoadingState.UNAVAILABLE);
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Handles the case where a branch checkout fails.
|
|
140
|
-
* Determines whether to retry or report unavailability.
|
|
141
|
-
*/
|
|
142
|
-
private handleUnavailableBranch(): void {
|
|
143
|
-
const source = this.source;
|
|
144
|
-
if (source.isAvailable()) {
|
|
145
|
-
// This should be impossible - if source is available we can create the branch and it should be available
|
|
146
|
-
throw new Error("Branch is unavailable");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
147
115
|
}
|
|
148
116
|
|
|
149
|
-
|
|
150
|
-
this.subscribeToUnavailableSource();
|
|
151
|
-
this.emit(CoValueLoadingState.UNAVAILABLE);
|
|
117
|
+
this.subscribe(branch);
|
|
152
118
|
}
|
|
153
119
|
|
|
154
120
|
/**
|
|
155
|
-
* Loads
|
|
156
|
-
* This is the fallback strategy when immediate availability fails.
|
|
121
|
+
* Loads a CoValue core and emits an unavailable event if it is still unavailable after the retries.
|
|
157
122
|
*/
|
|
158
|
-
|
|
123
|
+
load(value: CoValueCore) {
|
|
159
124
|
this.localNode
|
|
160
|
-
.loadCoValueCore(
|
|
161
|
-
.then((
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (value.isAvailable()) {
|
|
165
|
-
// Loading successful, subscribe to the loaded value
|
|
166
|
-
this.subscribe(value.getCurrentContent());
|
|
167
|
-
} else {
|
|
168
|
-
// Loading failed, subscribe to state changes and report unavailability
|
|
169
|
-
this.subscribeToUnavailableSource();
|
|
125
|
+
.loadCoValueCore(value.id, undefined, this.skipRetry)
|
|
126
|
+
.then(() => {
|
|
127
|
+
// If after the retries the value is still unavailable, we emit an unavailable event
|
|
128
|
+
if (!value.isAvailable()) {
|
|
170
129
|
this.emit(CoValueLoadingState.UNAVAILABLE);
|
|
171
130
|
}
|
|
172
|
-
})
|
|
173
|
-
.catch((error) => {
|
|
174
|
-
// Handle unexpected errors during loading
|
|
175
|
-
console.error(error);
|
|
176
|
-
this.emit(CoValueLoadingState.UNAVAILABLE);
|
|
177
131
|
});
|
|
178
132
|
}
|
|
179
133
|
|
|
180
134
|
/**
|
|
181
|
-
*
|
|
182
|
-
* This allows the subscription to become active when the source becomes available after a first loading attempt.
|
|
135
|
+
* Waits for the source to become available and then tries to branch.
|
|
183
136
|
*/
|
|
184
|
-
private
|
|
137
|
+
private waitForSourceToBecomeAvailable(
|
|
138
|
+
branchName: string,
|
|
139
|
+
branchOwnerId?: RawCoID,
|
|
140
|
+
): void {
|
|
185
141
|
const source = this.source;
|
|
186
142
|
|
|
187
143
|
const handleStateChange = (
|
|
@@ -197,41 +153,60 @@ export class CoValueCoreSubscription {
|
|
|
197
153
|
|
|
198
154
|
unsubFromStateChange();
|
|
199
155
|
|
|
200
|
-
|
|
201
|
-
// Branch was requested, attempt checkout again
|
|
202
|
-
this.handleBranchCheckout();
|
|
203
|
-
} else {
|
|
204
|
-
// No branch requested, subscribe directly and cleanup state subscription
|
|
205
|
-
this.subscribe(source.getCurrentContent());
|
|
206
|
-
}
|
|
156
|
+
this.handleBranching(branchName, branchOwnerId);
|
|
207
157
|
};
|
|
208
158
|
|
|
209
159
|
// Subscribe to state changes and store the unsubscribe function
|
|
210
160
|
this._unsubscribe = source.subscribe(handleStateChange);
|
|
161
|
+
|
|
162
|
+
this.load(source);
|
|
211
163
|
}
|
|
212
164
|
|
|
213
165
|
/**
|
|
214
166
|
* Subscribes to a specific CoValue and notifies the listener.
|
|
215
167
|
* This is the final step where we actually start receiving updates.
|
|
216
168
|
*/
|
|
217
|
-
private subscribe(value:
|
|
169
|
+
private subscribe(value: CoValueCore): void {
|
|
218
170
|
if (this.unsubscribed) return;
|
|
219
171
|
|
|
220
172
|
// Subscribe to the value and store the unsubscribe function
|
|
221
173
|
this._unsubscribe = value.subscribe((value) => {
|
|
222
|
-
|
|
174
|
+
if (value.isAvailable()) {
|
|
175
|
+
this.emit(value.getCurrentContent());
|
|
176
|
+
}
|
|
223
177
|
});
|
|
178
|
+
|
|
179
|
+
if (!value.isAvailable()) {
|
|
180
|
+
this.load(value);
|
|
181
|
+
}
|
|
224
182
|
}
|
|
225
183
|
|
|
184
|
+
lastState: CoValueLoadingState | undefined;
|
|
185
|
+
|
|
226
186
|
emit(value: RawCoValue | typeof CoValueLoadingState.UNAVAILABLE): void {
|
|
227
187
|
if (this.unsubscribed) return;
|
|
228
|
-
if (!isReadyForEmit(value)) {
|
|
188
|
+
if (!this.isReadyForEmit(value)) {
|
|
229
189
|
return;
|
|
230
190
|
}
|
|
231
191
|
|
|
232
192
|
this.listener(value);
|
|
233
193
|
}
|
|
234
194
|
|
|
195
|
+
isReadyForEmit(
|
|
196
|
+
value: RawCoValue | typeof CoValueLoadingState.UNAVAILABLE,
|
|
197
|
+
): boolean {
|
|
198
|
+
if (value === CoValueLoadingState.UNAVAILABLE) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// If the value is not completely downloaded, we don't emit it to avoid providing partial data to the listener.
|
|
203
|
+
if (!isCompletelyDownloaded(value)) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
|
|
235
210
|
/**
|
|
236
211
|
* Unsubscribes from all active subscriptions and marks the instance as unsubscribed.
|
|
237
212
|
* This prevents any further operations and ensures proper cleanup.
|
|
@@ -246,11 +221,7 @@ export class CoValueCoreSubscription {
|
|
|
246
221
|
/**
|
|
247
222
|
* This is true if the value is unavailable, or if the value is a binary coValue or a completely downloaded coValue.
|
|
248
223
|
*/
|
|
249
|
-
function
|
|
250
|
-
if (value === "unavailable") {
|
|
251
|
-
return true;
|
|
252
|
-
}
|
|
253
|
-
|
|
224
|
+
function isCompletelyDownloaded(value: RawCoValue) {
|
|
254
225
|
return (
|
|
255
226
|
value.core.verified?.header.meta?.type === "binary" ||
|
|
256
227
|
value.core.isCompletelyDownloaded()
|
|
@@ -11,21 +11,24 @@ export class JazzError {
|
|
|
11
11
|
) {}
|
|
12
12
|
|
|
13
13
|
toString() {
|
|
14
|
-
|
|
14
|
+
// Build the main error message with inline stack info so it shows even if truncated
|
|
15
|
+
let result = this.issues
|
|
15
16
|
.map((issue) => {
|
|
16
17
|
let message = `${issue.message}`;
|
|
17
18
|
|
|
18
|
-
if (this.id) {
|
|
19
|
-
message += ` from ${this.id}`;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
19
|
if (issue.path.length > 0) {
|
|
23
|
-
|
|
20
|
+
if (this.id) {
|
|
21
|
+
message += `. Subscription starts from ${this.id}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
message += ` and the value is on path ${issue.path.join(".")}`;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
return message;
|
|
27
28
|
})
|
|
28
29
|
.join("\n");
|
|
30
|
+
|
|
31
|
+
return result;
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
prependPath(item: string) {
|