jazz-tools 0.13.17 → 0.13.18
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 -7
- package/CHANGELOG.md +11 -0
- package/dist/{chunk-PYBQOYML.js → chunk-ITSHLDQB.js} +729 -595
- package/dist/chunk-ITSHLDQB.js.map +1 -0
- package/dist/coValues/account.d.ts +5 -4
- package/dist/coValues/account.d.ts.map +1 -1
- package/dist/coValues/coFeed.d.ts +1 -0
- package/dist/coValues/coFeed.d.ts.map +1 -1
- package/dist/coValues/coList.d.ts +1 -0
- package/dist/coValues/coList.d.ts.map +1 -1
- package/dist/coValues/coMap.d.ts +4 -2
- package/dist/coValues/coMap.d.ts.map +1 -1
- package/dist/coValues/coPlainText.d.ts +2 -2
- package/dist/coValues/coPlainText.d.ts.map +1 -1
- package/dist/coValues/deepLoading.d.ts +1 -9
- package/dist/coValues/deepLoading.d.ts.map +1 -1
- package/dist/coValues/extensions/imageDef.d.ts.map +1 -1
- package/dist/coValues/group.d.ts.map +1 -1
- package/dist/coValues/inbox.d.ts.map +1 -1
- package/dist/coValues/interfaces.d.ts +4 -1
- package/dist/coValues/interfaces.d.ts.map +1 -1
- package/dist/implementation/createContext.d.ts.map +1 -1
- package/dist/implementation/refs.d.ts +5 -10
- package/dist/implementation/refs.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/subscribe/CoValueCoreSubscription.d.ts +14 -0
- package/dist/subscribe/CoValueCoreSubscription.d.ts.map +1 -0
- package/dist/subscribe/JazzError.d.ts +16 -0
- package/dist/subscribe/JazzError.d.ts.map +1 -0
- package/dist/subscribe/SubscriptionScope.d.ts +42 -0
- package/dist/subscribe/SubscriptionScope.d.ts.map +1 -0
- package/dist/subscribe/index.d.ts +21 -0
- package/dist/subscribe/index.d.ts.map +1 -0
- package/dist/subscribe/types.d.ts +12 -0
- package/dist/subscribe/types.d.ts.map +1 -0
- package/dist/subscribe/utils.d.ts +10 -0
- package/dist/subscribe/utils.d.ts.map +1 -0
- package/dist/testing.js +2 -2
- package/dist/testing.js.map +1 -1
- package/dist/tests/coMap.record.test.d.ts +2 -0
- package/dist/tests/coMap.record.test.d.ts.map +1 -0
- package/dist/tests/utils.d.ts +2 -2
- package/dist/tests/utils.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/coValues/account.ts +43 -31
- package/src/coValues/coFeed.ts +11 -7
- package/src/coValues/coList.ts +13 -17
- package/src/coValues/coMap.ts +72 -80
- package/src/coValues/coPlainText.ts +13 -2
- package/src/coValues/deepLoading.ts +4 -277
- package/src/coValues/extensions/imageDef.ts +1 -7
- package/src/coValues/group.ts +7 -6
- package/src/coValues/inbox.ts +4 -11
- package/src/coValues/interfaces.ts +54 -111
- package/src/implementation/createContext.ts +3 -4
- package/src/implementation/invites.ts +2 -2
- package/src/implementation/refs.ts +30 -121
- package/src/internal.ts +1 -2
- package/src/subscribe/CoValueCoreSubscription.ts +71 -0
- package/src/subscribe/JazzError.ts +48 -0
- package/src/subscribe/SubscriptionScope.ts +523 -0
- package/src/subscribe/index.ts +82 -0
- package/src/subscribe/types.ts +7 -0
- package/src/subscribe/utils.ts +36 -0
- package/src/testing.ts +1 -1
- package/src/tests/ContextManager.test.ts +13 -9
- package/src/tests/coFeed.test.ts +6 -6
- package/src/tests/coList.test.ts +304 -115
- package/src/tests/coMap.record.test.ts +325 -0
- package/src/tests/coMap.test.ts +718 -645
- package/src/tests/coPlainText.test.ts +2 -2
- package/src/tests/createContext.test.ts +8 -8
- package/src/tests/deepLoading.test.ts +8 -34
- package/src/tests/groupsAndAccounts.test.ts +6 -4
- package/src/tests/subscribe.test.ts +357 -42
- package/src/tests/utils.ts +8 -6
- package/dist/chunk-PYBQOYML.js.map +0 -1
- package/dist/implementation/subscriptionScope.d.ts +0 -34
- package/dist/implementation/subscriptionScope.d.ts.map +0 -1
- package/src/implementation/subscriptionScope.ts +0 -165
@@ -1,34 +0,0 @@
|
|
1
|
-
import type { RawCoValue } from "cojson";
|
2
|
-
import { type Account } from "../coValues/account.js";
|
3
|
-
import type { AnonymousJazzAgent, CoValue, CoValueClass, CoValueFromRaw, ID } from "../internal.js";
|
4
|
-
export declare const subscriptionsScopes: WeakMap<CoValue, SubscriptionScope<any>>;
|
5
|
-
export declare class SubscriptionScope<Root extends CoValue> {
|
6
|
-
scopeID: string;
|
7
|
-
subscriber: Account | AnonymousJazzAgent;
|
8
|
-
entries: Map<ID<CoValue>, {
|
9
|
-
state: "loading";
|
10
|
-
immediatelyUnsub?: boolean;
|
11
|
-
} | {
|
12
|
-
state: "loaded";
|
13
|
-
rawUnsub: () => void;
|
14
|
-
}>;
|
15
|
-
rootEntry: {
|
16
|
-
state: "loaded";
|
17
|
-
value: RawCoValue;
|
18
|
-
rawUnsub: () => void;
|
19
|
-
};
|
20
|
-
scheduleUpdate: () => void;
|
21
|
-
scheduledUpdate: boolean;
|
22
|
-
cachedValues: {
|
23
|
-
[id: ID<CoValue>]: CoValue;
|
24
|
-
};
|
25
|
-
parents: {
|
26
|
-
[id: ID<CoValue>]: Set<ID<CoValue>>;
|
27
|
-
};
|
28
|
-
syncResolution: boolean;
|
29
|
-
constructor(root: Root, rootSchema: CoValueClass<Root> & CoValueFromRaw<Root>, onUpdate: (newRoot: Root, scope: SubscriptionScope<Root>) => void);
|
30
|
-
onRefAccessedOrSet(fromId: ID<CoValue>, accessedOrSetId: ID<CoValue> | undefined): void;
|
31
|
-
invalidate(id: ID<CoValue>, seen?: Set<ID<CoValue>>): void;
|
32
|
-
unsubscribeAll: () => void;
|
33
|
-
}
|
34
|
-
//# sourceMappingURL=subscriptionScope.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"subscriptionScope.d.ts","sourceRoot":"","sources":["../../src/implementation/subscriptionScope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA0B,UAAU,EAAE,MAAM,QAAQ,C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AAI,GAAE,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,CAAa;IAU9D,cAAc,aASZ;CACH"}
|
@@ -1,165 +0,0 @@
|
|
1
|
-
import type { CoValueCore, LocalNode, RawCoValue } from "cojson";
|
2
|
-
import { type Account } from "../coValues/account.js";
|
3
|
-
import type {
|
4
|
-
AnonymousJazzAgent,
|
5
|
-
CoValue,
|
6
|
-
CoValueClass,
|
7
|
-
CoValueFromRaw,
|
8
|
-
ID,
|
9
|
-
} from "../internal.js";
|
10
|
-
|
11
|
-
export const subscriptionsScopes = new WeakMap<
|
12
|
-
CoValue,
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
14
|
-
SubscriptionScope<any>
|
15
|
-
>();
|
16
|
-
|
17
|
-
export class SubscriptionScope<Root extends CoValue> {
|
18
|
-
scopeID: string = `scope-${Math.random().toString(36).slice(2)}`;
|
19
|
-
subscriber: Account | AnonymousJazzAgent;
|
20
|
-
entries = new Map<
|
21
|
-
ID<CoValue>,
|
22
|
-
| { state: "loading"; immediatelyUnsub?: boolean }
|
23
|
-
| { state: "loaded"; rawUnsub: () => void }
|
24
|
-
>();
|
25
|
-
rootEntry: {
|
26
|
-
state: "loaded";
|
27
|
-
value: RawCoValue;
|
28
|
-
rawUnsub: () => void;
|
29
|
-
};
|
30
|
-
scheduleUpdate: () => void;
|
31
|
-
scheduledUpdate: boolean = false;
|
32
|
-
cachedValues: { [id: ID<CoValue>]: CoValue } = {};
|
33
|
-
parents: { [id: ID<CoValue>]: Set<ID<CoValue>> } = {};
|
34
|
-
syncResolution: boolean = false;
|
35
|
-
|
36
|
-
constructor(
|
37
|
-
root: Root,
|
38
|
-
rootSchema: CoValueClass<Root> & CoValueFromRaw<Root>,
|
39
|
-
onUpdate: (newRoot: Root, scope: SubscriptionScope<Root>) => void,
|
40
|
-
) {
|
41
|
-
this.rootEntry = {
|
42
|
-
state: "loaded" as const,
|
43
|
-
value: root._raw,
|
44
|
-
rawUnsub: () => {}, // placeholder
|
45
|
-
};
|
46
|
-
this.entries.set(root.id, this.rootEntry);
|
47
|
-
|
48
|
-
subscriptionsScopes.set(root, this);
|
49
|
-
|
50
|
-
this.subscriber = root._loadedAs;
|
51
|
-
|
52
|
-
this.scheduleUpdate = () => {
|
53
|
-
const value = rootSchema.fromRaw(this.rootEntry.value) as Root;
|
54
|
-
subscriptionsScopes.set(value, this);
|
55
|
-
onUpdate(value, this);
|
56
|
-
};
|
57
|
-
|
58
|
-
this.rootEntry.rawUnsub = root._raw.core.subscribe(
|
59
|
-
(rawUpdate: RawCoValue | undefined) => {
|
60
|
-
if (!rawUpdate) return;
|
61
|
-
this.rootEntry.value = rawUpdate;
|
62
|
-
this.scheduleUpdate();
|
63
|
-
},
|
64
|
-
);
|
65
|
-
}
|
66
|
-
|
67
|
-
onRefAccessedOrSet(
|
68
|
-
fromId: ID<CoValue>,
|
69
|
-
accessedOrSetId: ID<CoValue> | undefined,
|
70
|
-
) {
|
71
|
-
// console.log("onRefAccessedOrSet", this.scopeID, accessedOrSetId);
|
72
|
-
if (!accessedOrSetId) {
|
73
|
-
return;
|
74
|
-
}
|
75
|
-
|
76
|
-
this.parents[accessedOrSetId] = this.parents[accessedOrSetId] || new Set();
|
77
|
-
this.parents[accessedOrSetId]!.add(fromId);
|
78
|
-
|
79
|
-
if (!this.entries.has(accessedOrSetId)) {
|
80
|
-
const loadingEntry = {
|
81
|
-
state: "loading",
|
82
|
-
immediatelyUnsub: false,
|
83
|
-
} as const;
|
84
|
-
this.entries.set(accessedOrSetId, loadingEntry);
|
85
|
-
const node =
|
86
|
-
this.subscriber._type === "Account"
|
87
|
-
? this.subscriber._raw.core.node
|
88
|
-
: this.subscriber.node;
|
89
|
-
|
90
|
-
loadCoValue(
|
91
|
-
node,
|
92
|
-
accessedOrSetId,
|
93
|
-
(core) => {
|
94
|
-
if (
|
95
|
-
loadingEntry.state === "loading" &&
|
96
|
-
loadingEntry.immediatelyUnsub
|
97
|
-
) {
|
98
|
-
return;
|
99
|
-
}
|
100
|
-
if (core !== "unavailable") {
|
101
|
-
const entry = {
|
102
|
-
state: "loaded" as const,
|
103
|
-
rawUnsub: () => {}, // placeholder
|
104
|
-
};
|
105
|
-
this.entries.set(accessedOrSetId, entry);
|
106
|
-
|
107
|
-
const rawUnsub = core.subscribe((rawUpdate) => {
|
108
|
-
if (!rawUpdate) return;
|
109
|
-
|
110
|
-
this.invalidate(accessedOrSetId);
|
111
|
-
this.scheduleUpdate();
|
112
|
-
});
|
113
|
-
|
114
|
-
entry.rawUnsub = rawUnsub;
|
115
|
-
}
|
116
|
-
},
|
117
|
-
this.syncResolution,
|
118
|
-
);
|
119
|
-
}
|
120
|
-
}
|
121
|
-
|
122
|
-
invalidate(id: ID<CoValue>, seen: Set<ID<CoValue>> = new Set()) {
|
123
|
-
if (seen.has(id)) return;
|
124
|
-
|
125
|
-
delete this.cachedValues[id];
|
126
|
-
seen.add(id);
|
127
|
-
for (const parent of this.parents[id] || []) {
|
128
|
-
this.invalidate(parent, seen);
|
129
|
-
}
|
130
|
-
}
|
131
|
-
|
132
|
-
unsubscribeAll = () => {
|
133
|
-
for (const entry of this.entries.values()) {
|
134
|
-
if (entry.state === "loaded") {
|
135
|
-
entry.rawUnsub();
|
136
|
-
} else {
|
137
|
-
entry.immediatelyUnsub = true;
|
138
|
-
}
|
139
|
-
}
|
140
|
-
this.entries.clear();
|
141
|
-
};
|
142
|
-
}
|
143
|
-
|
144
|
-
/**
|
145
|
-
* Loads a CoValue from the node and calls the callback with the result.
|
146
|
-
|
147
|
-
* If the CoValue is already loaded, the callback is called synchronously.
|
148
|
-
* If the CoValue is not loaded, the callback is called asynchronously.
|
149
|
-
*/
|
150
|
-
function loadCoValue(
|
151
|
-
node: LocalNode,
|
152
|
-
id: ID<CoValue>,
|
153
|
-
callback: (value: CoValueCore | "unavailable") => void,
|
154
|
-
syncResolution: boolean,
|
155
|
-
) {
|
156
|
-
const entry = node.coValuesStore.get(id);
|
157
|
-
|
158
|
-
if (entry.isAvailable() && syncResolution) {
|
159
|
-
callback(entry.core);
|
160
|
-
} else {
|
161
|
-
void node.loadCoValueCore(id).then((core) => {
|
162
|
-
callback(core);
|
163
|
-
});
|
164
|
-
}
|
165
|
-
}
|