cojson 0.20.12 → 0.20.15
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 +1 -1
- package/CHANGELOG.md +29 -0
- package/dist/coValueCore/verifiedState.js +1 -1
- package/dist/coValueCore/verifiedState.js.map +1 -1
- package/dist/crypto/NapiCrypto.js +3 -0
- package/dist/crypto/NapiCrypto.js.map +1 -1
- package/dist/crypto/RNCrypto.js +3 -0
- package/dist/crypto/RNCrypto.js.map +1 -1
- package/dist/crypto/WasmCrypto.js +3 -0
- package/dist/crypto/WasmCrypto.js.map +1 -1
- package/dist/crypto/crypto.d.ts +1 -0
- package/dist/crypto/crypto.d.ts.map +1 -1
- package/dist/queue/IncomingMessagesQueue.d.ts +3 -0
- package/dist/queue/IncomingMessagesQueue.d.ts.map +1 -1
- package/dist/queue/IncomingMessagesQueue.js +23 -0
- package/dist/queue/IncomingMessagesQueue.js.map +1 -1
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +4 -0
- package/dist/sync.js.map +1 -1
- package/dist/tests/IncomingMessagesQueue.test.js +16 -0
- package/dist/tests/IncomingMessagesQueue.test.js.map +1 -1
- package/dist/tests/SyncManager.processQueues.test.js +50 -2
- package/dist/tests/SyncManager.processQueues.test.js.map +1 -1
- package/dist/tests/coValueCore.isStreaming.test.js +45 -1
- package/dist/tests/coValueCore.isStreaming.test.js.map +1 -1
- package/package.json +4 -4
- package/src/coValueCore/verifiedState.ts +1 -1
- package/src/crypto/NapiCrypto.ts +4 -0
- package/src/crypto/RNCrypto.ts +4 -0
- package/src/crypto/WasmCrypto.ts +4 -0
- package/src/crypto/crypto.ts +1 -0
- package/src/queue/IncomingMessagesQueue.ts +30 -1
- package/src/sync.ts +6 -0
- package/src/tests/IncomingMessagesQueue.test.ts +32 -0
- package/src/tests/SyncManager.processQueues.test.ts +90 -1
- package/src/tests/coValueCore.isStreaming.test.ts +70 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assert, beforeEach, describe, expect, test } from "vitest";
|
|
1
|
+
import { assert, beforeEach, describe, expect, test, vi } from "vitest";
|
|
2
2
|
import {
|
|
3
3
|
SyncMessagesLog,
|
|
4
4
|
TEST_NODE_CONFIG,
|
|
@@ -114,6 +114,75 @@ describe("isStreaming", () => {
|
|
|
114
114
|
expect(mapInNewSession.core.isStreaming()).toBe(false);
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
+
test("isStreaming uses the native streaming flag", async () => {
|
|
118
|
+
const client = setupTestNode({
|
|
119
|
+
connected: true,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const group = client.node.createGroup();
|
|
123
|
+
|
|
124
|
+
await group.core.waitForSync();
|
|
125
|
+
client.disconnect();
|
|
126
|
+
|
|
127
|
+
const map = fillCoMapWithLargeData(group.createMap());
|
|
128
|
+
|
|
129
|
+
const newSession = client.spawnNewSession();
|
|
130
|
+
|
|
131
|
+
await loadCoValueOrFail(client.node, group.id);
|
|
132
|
+
|
|
133
|
+
const content = map.core.verified.newContentSince(undefined);
|
|
134
|
+
assert(content);
|
|
135
|
+
const lastChunk = content.pop();
|
|
136
|
+
assert(lastChunk);
|
|
137
|
+
|
|
138
|
+
for (const chunk of content) {
|
|
139
|
+
newSession.node.syncManager.handleNewContent(chunk, "import");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const mapInNewSession = await loadCoValueOrFail(newSession.node, map.id);
|
|
143
|
+
const impl = (mapInNewSession.core.verified as any).impl;
|
|
144
|
+
const isStreamingSpy = vi.spyOn(impl, "isStreaming");
|
|
145
|
+
const getKnownStateWithStreamingSpy = vi.spyOn(
|
|
146
|
+
impl,
|
|
147
|
+
"getKnownStateWithStreaming",
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
expect(mapInNewSession.core.isStreaming()).toBe(true);
|
|
151
|
+
expect(isStreamingSpy).toHaveBeenCalledTimes(1);
|
|
152
|
+
expect(getKnownStateWithStreamingSpy).not.toHaveBeenCalled();
|
|
153
|
+
|
|
154
|
+
expect(
|
|
155
|
+
mapInNewSession.core.knownStateWithStreaming().sessions,
|
|
156
|
+
).toBeDefined();
|
|
157
|
+
expect(getKnownStateWithStreamingSpy).toHaveBeenCalledTimes(1);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("newContentSince checks streaming once and loads the target once", async () => {
|
|
161
|
+
const client = setupTestNode({
|
|
162
|
+
connected: true,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const group = client.node.createGroup();
|
|
166
|
+
const map = group.createMap();
|
|
167
|
+
map.set("hello", "world", "trusting");
|
|
168
|
+
|
|
169
|
+
const sessionId = Object.keys(map.core.knownState().sessions)[0];
|
|
170
|
+
assert(sessionId);
|
|
171
|
+
|
|
172
|
+
map.core.verified.setStreamingKnownState({ [sessionId]: 2 });
|
|
173
|
+
|
|
174
|
+
const impl = (map.core.verified as any).impl;
|
|
175
|
+
const isStreamingSpy = vi.spyOn(impl, "isStreaming");
|
|
176
|
+
const getKnownStateWithStreamingSpy = vi.spyOn(
|
|
177
|
+
impl,
|
|
178
|
+
"getKnownStateWithStreaming",
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
expect(() => map.core.verified.newContentSince(undefined)).not.toThrow();
|
|
182
|
+
expect(isStreamingSpy).toHaveBeenCalledTimes(1);
|
|
183
|
+
expect(getKnownStateWithStreamingSpy).toHaveBeenCalledTimes(1);
|
|
184
|
+
});
|
|
185
|
+
|
|
117
186
|
// TODO: We can't handle client-to-client streaming until we
|
|
118
187
|
// handle the streaming state reset on disconnection
|
|
119
188
|
// Otherwise the other client might wait for a content that will never be sent
|