jazz-tools 0.8.50 → 0.9.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/.turbo/turbo-build.log +7 -5
- package/CHANGELOG.md +16 -0
- package/dist/{chunk-6OHBW32Q.js → chunk-EK2I4C5W.js} +72 -44
- package/dist/chunk-EK2I4C5W.js.map +1 -0
- package/dist/index.native.js +1 -1
- package/dist/index.web.js +1 -1
- package/dist/testing.js +71 -0
- package/dist/testing.js.map +1 -0
- package/package.json +6 -2
- package/src/coValues/coFeed.ts +19 -13
- package/src/coValues/coList.ts +10 -6
- package/src/coValues/coMap.ts +14 -9
- package/src/coValues/group.ts +3 -2
- package/src/coValues/interfaces.ts +64 -28
- package/src/implementation/refs.ts +17 -0
- package/src/implementation/subscriptionScope.ts +4 -4
- package/src/testing.ts +103 -0
- package/src/tests/coFeed.test.ts +16 -0
- package/src/tests/coList.test.ts +14 -0
- package/src/tests/coMap.test.ts +19 -0
- package/src/tests/schemaUnion.test.ts +6 -2
- package/src/tests/subscribe.test.ts +12 -2
- package/src/tests/utils.ts +10 -6
- package/tsup.config.ts +1 -0
- package/dist/chunk-6OHBW32Q.js.map +0 -1
package/.turbo/turbo-build.log
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
|
2
|
-
> jazz-tools@0.
|
2
|
+
> jazz-tools@0.9.0 build /home/runner/work/jazz/jazz/packages/jazz-tools
|
3
3
|
> tsup
|
4
4
|
|
5
|
-
[34mCLI[39m Building entry: {"index.web":"src/index.web.ts","index.native":"src/index.native.ts"}
|
5
|
+
[34mCLI[39m Building entry: {"index.web":"src/index.web.ts","index.native":"src/index.native.ts","testing":"src/testing.ts"}
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
7
7
|
[34mCLI[39m tsup v8.3.5
|
8
8
|
[34mCLI[39m Using tsup config: /home/runner/work/jazz/jazz/packages/jazz-tools/tsup.config.ts
|
@@ -10,9 +10,11 @@
|
|
10
10
|
[34mCLI[39m Cleaning output folder
|
11
11
|
[34mESM[39m Build start
|
12
12
|
[32mESM[39m [1mdist/index.web.js [22m[32m1.08 KB[39m
|
13
|
+
[32mESM[39m [1mdist/testing.js [22m[32m2.10 KB[39m
|
13
14
|
[32mESM[39m [1mdist/index.native.js [22m[32m1.07 KB[39m
|
14
|
-
[32mESM[39m [1mdist/chunk-
|
15
|
+
[32mESM[39m [1mdist/chunk-EK2I4C5W.js [22m[32m82.83 KB[39m
|
15
16
|
[32mESM[39m [1mdist/index.web.js.map [22m[32m270.00 B[39m
|
17
|
+
[32mESM[39m [1mdist/testing.js.map [22m[32m4.48 KB[39m
|
18
|
+
[32mESM[39m [1mdist/chunk-EK2I4C5W.js.map [22m[32m190.92 KB[39m
|
16
19
|
[32mESM[39m [1mdist/index.native.js.map [22m[32m280.00 B[39m
|
17
|
-
[32mESM[39m
|
18
|
-
[32mESM[39m ⚡️ Build success in 81ms
|
20
|
+
[32mESM[39m ⚡️ Build success in 92ms
|
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# jazz-tools
|
2
2
|
|
3
|
+
## 0.9.0
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 8eda792: Optimize the subscribe to resolve the CoValues stored in memory synchronously
|
8
|
+
- Updated dependencies [8eda792]
|
9
|
+
- Updated dependencies [1ef3226]
|
10
|
+
- cojson@0.9.0
|
11
|
+
|
12
|
+
## 0.8.51
|
13
|
+
|
14
|
+
### Patch Changes
|
15
|
+
|
16
|
+
- dc62b95: Return field name on \_edits
|
17
|
+
- 1de26f8: Simplify the .create calls by accepting directly "Account | Group" as second param
|
18
|
+
|
3
19
|
## 0.8.50
|
4
20
|
|
5
21
|
### Patch Changes
|
@@ -63,6 +63,16 @@ var Ref = class _Ref {
|
|
63
63
|
return new _Ref(this.id, this.controlledAccount, this.schema).value;
|
64
64
|
}
|
65
65
|
}
|
66
|
+
syncLoad() {
|
67
|
+
const node = "node" in this.controlledAccount ? this.controlledAccount.node : this.controlledAccount._raw.core.node;
|
68
|
+
const entry = node.coValuesStore.get(
|
69
|
+
this.id
|
70
|
+
);
|
71
|
+
if (entry.state.type === "available") {
|
72
|
+
return new _Ref(this.id, this.controlledAccount, this.schema).value;
|
73
|
+
}
|
74
|
+
return void 0;
|
75
|
+
}
|
66
76
|
async load() {
|
67
77
|
const result = await this.loadHelper();
|
68
78
|
if (result === "unavailable") {
|
@@ -240,6 +250,16 @@ var SubscriptionScope = class {
|
|
240
250
|
this.scheduledUpdate = false;
|
241
251
|
this.cachedValues = {};
|
242
252
|
this.parents = {};
|
253
|
+
this.unsubscribeAll = () => {
|
254
|
+
for (const entry of this.entries.values()) {
|
255
|
+
if (entry.state === "loaded") {
|
256
|
+
entry.rawUnsub();
|
257
|
+
} else {
|
258
|
+
entry.immediatelyUnsub = true;
|
259
|
+
}
|
260
|
+
}
|
261
|
+
this.entries.clear();
|
262
|
+
};
|
243
263
|
this.rootEntry = {
|
244
264
|
state: "loaded",
|
245
265
|
value: root._raw,
|
@@ -253,7 +273,7 @@ var SubscriptionScope = class {
|
|
253
273
|
this.scheduleUpdate = () => {
|
254
274
|
const value = rootSchema.fromRaw(this.rootEntry.value);
|
255
275
|
subscriptionsScopes.set(value, this);
|
256
|
-
onUpdate(value);
|
276
|
+
onUpdate(value, this);
|
257
277
|
};
|
258
278
|
this.rootEntry.rawUnsub = root._raw.core.subscribe(
|
259
279
|
(rawUpdate) => {
|
@@ -307,16 +327,6 @@ var SubscriptionScope = class {
|
|
307
327
|
this.invalidate(parent, id, seen);
|
308
328
|
}
|
309
329
|
}
|
310
|
-
unsubscribeAll() {
|
311
|
-
for (const entry of this.entries.values()) {
|
312
|
-
if (entry.state === "loaded") {
|
313
|
-
entry.rawUnsub();
|
314
|
-
} else {
|
315
|
-
entry.immediatelyUnsub = true;
|
316
|
-
}
|
317
|
-
}
|
318
|
-
this.entries.clear();
|
319
|
-
}
|
320
330
|
};
|
321
331
|
|
322
332
|
// src/coValues/deepLoading.ts
|
@@ -677,18 +687,17 @@ var CoValueBase = class {
|
|
677
687
|
};
|
678
688
|
function loadCoValue(cls, id, as, depth) {
|
679
689
|
return new Promise((resolve) => {
|
680
|
-
|
690
|
+
subscribeToCoValue(
|
681
691
|
cls,
|
682
692
|
id,
|
683
693
|
as,
|
684
694
|
depth,
|
685
|
-
(value) => {
|
695
|
+
(value, unsubscribe) => {
|
686
696
|
resolve(value);
|
687
697
|
unsubscribe();
|
688
698
|
},
|
689
699
|
() => {
|
690
700
|
resolve(void 0);
|
691
|
-
unsubscribe();
|
692
701
|
}
|
693
702
|
);
|
694
703
|
});
|
@@ -701,11 +710,11 @@ function ensureCoValueLoaded(existing, depth) {
|
|
701
710
|
depth
|
702
711
|
);
|
703
712
|
}
|
704
|
-
function subscribeToCoValue(cls, id, as, depth, listener, onUnavailable) {
|
713
|
+
function subscribeToCoValue(cls, id, as, depth, listener, onUnavailable, syncResolution) {
|
705
714
|
const ref2 = new Ref(id, as, { ref: cls, optional: false });
|
706
715
|
let unsubscribed = false;
|
707
716
|
let unsubscribe;
|
708
|
-
|
717
|
+
function subscribe(value) {
|
709
718
|
if (!value) {
|
710
719
|
onUnavailable && onUnavailable();
|
711
720
|
return;
|
@@ -714,22 +723,31 @@ function subscribeToCoValue(cls, id, as, depth, listener, onUnavailable) {
|
|
714
723
|
const subscription = new SubscriptionScope(
|
715
724
|
value,
|
716
725
|
cls,
|
717
|
-
(update) => {
|
726
|
+
(update, subscription2) => {
|
718
727
|
if (fulfillsDepth(depth, update)) {
|
719
|
-
listener(
|
728
|
+
listener(
|
729
|
+
update,
|
730
|
+
subscription2.unsubscribeAll
|
731
|
+
);
|
720
732
|
}
|
721
733
|
}
|
722
734
|
);
|
723
|
-
unsubscribe =
|
724
|
-
}
|
725
|
-
|
726
|
-
|
735
|
+
unsubscribe = subscription.unsubscribeAll;
|
736
|
+
}
|
737
|
+
const sync = syncResolution ? ref2.syncLoad() : void 0;
|
738
|
+
if (sync) {
|
739
|
+
subscribe(sync);
|
740
|
+
} else {
|
741
|
+
ref2.load().then((value) => subscribe(value)).catch((e) => {
|
742
|
+
console.error("Failed to load / subscribe to CoValue", e);
|
743
|
+
});
|
744
|
+
}
|
727
745
|
return function unsubscribeAtAnyPoint() {
|
728
746
|
unsubscribed = true;
|
729
747
|
unsubscribe && unsubscribe();
|
730
748
|
};
|
731
749
|
}
|
732
|
-
function createCoValueObservable() {
|
750
|
+
function createCoValueObservable(options) {
|
733
751
|
let currentValue = void 0;
|
734
752
|
let subscriberCount = 0;
|
735
753
|
function subscribe(cls, id, as, depth, listener, onUnavailable) {
|
@@ -743,7 +761,8 @@ function createCoValueObservable() {
|
|
743
761
|
currentValue = value;
|
744
762
|
listener();
|
745
763
|
},
|
746
|
-
onUnavailable
|
764
|
+
onUnavailable,
|
765
|
+
options?.syncResolution
|
747
766
|
);
|
748
767
|
return () => {
|
749
768
|
unsubscribe();
|
@@ -768,6 +787,12 @@ function subscribeToExistingCoValue(existing, depth, listener) {
|
|
768
787
|
listener
|
769
788
|
);
|
770
789
|
}
|
790
|
+
function parseCoValueCreateOptions(options) {
|
791
|
+
return "_type" in options && (options._type === "Account" || options._type === "Group") ? { owner: options, uniqueness: void 0 } : {
|
792
|
+
owner: options.owner,
|
793
|
+
uniqueness: options.unique ? { uniqueness: options.unique } : void 0
|
794
|
+
};
|
795
|
+
}
|
771
796
|
|
772
797
|
// src/coValues/inbox.ts
|
773
798
|
import {
|
@@ -1050,7 +1075,8 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
1050
1075
|
ref: RegisteredSchemas["Account"],
|
1051
1076
|
optional: false
|
1052
1077
|
}).accessFrom(target, "_edits." + key + ".by"),
|
1053
|
-
madeAt: rawEdit.at
|
1078
|
+
madeAt: rawEdit.at,
|
1079
|
+
key
|
1054
1080
|
};
|
1055
1081
|
}
|
1056
1082
|
/** @category Collaboration */
|
@@ -1124,11 +1150,8 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
1124
1150
|
**/
|
1125
1151
|
static create(init, options) {
|
1126
1152
|
const instance = new this();
|
1127
|
-
const
|
1128
|
-
|
1129
|
-
options.owner,
|
1130
|
-
options.unique === void 0 ? void 0 : { uniqueness: options.unique }
|
1131
|
-
);
|
1153
|
+
const { owner, uniqueness } = parseCoValueCreateOptions(options);
|
1154
|
+
const raw = instance.rawFromInit(init, owner, uniqueness);
|
1132
1155
|
Object.defineProperties(instance, {
|
1133
1156
|
id: {
|
1134
1157
|
value: raw.id,
|
@@ -1761,7 +1784,7 @@ var _Group = class _Group extends CoValueBase {
|
|
1761
1784
|
return new Proxy(this, AccountAndGroupProxyHandler);
|
1762
1785
|
}
|
1763
1786
|
static create(options) {
|
1764
|
-
return new this(options);
|
1787
|
+
return new this(parseCoValueCreateOptions(options));
|
1765
1788
|
}
|
1766
1789
|
myRole() {
|
1767
1790
|
return this._raw.myRole();
|
@@ -1911,8 +1934,9 @@ var _CoFeed = class _CoFeed extends CoValueBase {
|
|
1911
1934
|
* @category Creation
|
1912
1935
|
*/
|
1913
1936
|
static create(init, options) {
|
1914
|
-
const
|
1915
|
-
const
|
1937
|
+
const { owner } = parseCoValueCreateOptions(options);
|
1938
|
+
const instance = new this({ init, owner });
|
1939
|
+
const raw = owner._raw.createStream();
|
1916
1940
|
Object.defineProperties(instance, {
|
1917
1941
|
id: {
|
1918
1942
|
value: raw.id,
|
@@ -2224,7 +2248,7 @@ var FileStream = class extends CoValueBase {
|
|
2224
2248
|
});
|
2225
2249
|
}
|
2226
2250
|
static create(options) {
|
2227
|
-
return new this(options);
|
2251
|
+
return new this(parseCoValueCreateOptions(options));
|
2228
2252
|
}
|
2229
2253
|
getChunks(options) {
|
2230
2254
|
return this._raw.getBinaryChunks(options?.allowUnfinished);
|
@@ -2259,7 +2283,7 @@ var FileStream = class extends CoValueBase {
|
|
2259
2283
|
let stream = await this.load(id, as, []);
|
2260
2284
|
if (!options?.allowUnfinished && !stream?.isBinaryStreamEnded()) {
|
2261
2285
|
stream = await new Promise((resolve) => {
|
2262
|
-
|
2286
|
+
subscribeToCoValue(this, id, as, [], (value, unsubscribe) => {
|
2263
2287
|
if (value.isBinaryStreamEnded()) {
|
2264
2288
|
unsubscribe();
|
2265
2289
|
resolve(value);
|
@@ -2283,7 +2307,8 @@ var FileStream = class extends CoValueBase {
|
|
2283
2307
|
* @category Content
|
2284
2308
|
*/
|
2285
2309
|
static async createFromBlob(blob, options) {
|
2286
|
-
const stream = this.create(
|
2310
|
+
const stream = this.create(options);
|
2311
|
+
const onProgress = "onProgress" in options ? options.onProgress : void 0;
|
2287
2312
|
const start = Date.now();
|
2288
2313
|
const data = new Uint8Array(await blob.arrayBuffer());
|
2289
2314
|
stream.start({
|
@@ -2296,7 +2321,7 @@ var FileStream = class extends CoValueBase {
|
|
2296
2321
|
for (let idx = 0; idx < data.length; idx += chunkSize) {
|
2297
2322
|
stream.push(data.slice(idx, idx + chunkSize));
|
2298
2323
|
if (Date.now() - lastProgressUpdate > 100) {
|
2299
|
-
|
2324
|
+
onProgress?.(idx / data.length);
|
2300
2325
|
lastProgressUpdate = Date.now();
|
2301
2326
|
}
|
2302
2327
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
@@ -2309,7 +2334,7 @@ var FileStream = class extends CoValueBase {
|
|
2309
2334
|
"s - Throughput in MB/s",
|
2310
2335
|
1e3 * (blob.size / (end - start)) / (1024 * 1024)
|
2311
2336
|
);
|
2312
|
-
|
2337
|
+
onProgress?.(1);
|
2313
2338
|
return stream;
|
2314
2339
|
}
|
2315
2340
|
/**
|
@@ -2482,8 +2507,9 @@ var _CoList = class _CoList extends Array {
|
|
2482
2507
|
* @category Creation
|
2483
2508
|
**/
|
2484
2509
|
static create(items, options) {
|
2485
|
-
const
|
2486
|
-
const
|
2510
|
+
const { owner } = parseCoValueCreateOptions(options);
|
2511
|
+
const instance = new this({ init: items, owner });
|
2512
|
+
const raw = owner._raw.createList(
|
2487
2513
|
toRawItems(items, instance._schema[ItemsSym])
|
2488
2514
|
);
|
2489
2515
|
Object.defineProperties(instance, {
|
@@ -2496,9 +2522,11 @@ var _CoList = class _CoList extends Array {
|
|
2496
2522
|
return instance;
|
2497
2523
|
}
|
2498
2524
|
push(...items) {
|
2499
|
-
|
2500
|
-
this.
|
2501
|
-
|
2525
|
+
this._raw.appendItems(
|
2526
|
+
toRawItems(items, this._schema[ItemsSym]),
|
2527
|
+
void 0,
|
2528
|
+
"private"
|
2529
|
+
);
|
2502
2530
|
return this._raw.entries().length;
|
2503
2531
|
}
|
2504
2532
|
unshift(...items) {
|
@@ -2850,4 +2878,4 @@ export {
|
|
2850
2878
|
SchemaUnion
|
2851
2879
|
};
|
2852
2880
|
/* istanbul ignore file -- @preserve */
|
2853
|
-
//# sourceMappingURL=chunk-
|
2881
|
+
//# sourceMappingURL=chunk-EK2I4C5W.js.map
|