cojson 0.18.36 → 0.18.38
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 +18 -0
- package/dist/coValueCore/SessionMap.d.ts +5 -3
- package/dist/coValueCore/SessionMap.d.ts.map +1 -1
- package/dist/coValueCore/SessionMap.js +19 -9
- package/dist/coValueCore/SessionMap.js.map +1 -1
- package/dist/coValueCore/coValueCore.d.ts +5 -2
- package/dist/coValueCore/coValueCore.d.ts.map +1 -1
- package/dist/coValueCore/coValueCore.js +24 -4
- package/dist/coValueCore/coValueCore.js.map +1 -1
- package/dist/coValueCore/verifiedState.d.ts +1 -3
- package/dist/coValueCore/verifiedState.d.ts.map +1 -1
- package/dist/coValueCore/verifiedState.js +10 -14
- package/dist/coValueCore/verifiedState.js.map +1 -1
- package/dist/coValues/group.d.ts +2 -1
- package/dist/coValues/group.d.ts.map +1 -1
- package/dist/coValues/group.js +21 -18
- package/dist/coValues/group.js.map +1 -1
- package/dist/exports.d.ts +5 -4
- package/dist/exports.d.ts.map +1 -1
- package/dist/exports.js +3 -3
- package/dist/exports.js.map +1 -1
- package/dist/permissions.d.ts +0 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +83 -89
- package/dist/permissions.js.map +1 -1
- package/dist/queue/LocalTransactionsSyncQueue.d.ts.map +1 -1
- package/dist/queue/LocalTransactionsSyncQueue.js +1 -18
- package/dist/queue/LocalTransactionsSyncQueue.js.map +1 -1
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +8 -0
- package/dist/sync.js.map +1 -1
- package/dist/tests/StorageApiAsync.test.js +8 -8
- package/dist/tests/coValueCore.isStreaming.test.js +30 -40
- package/dist/tests/coValueCore.isStreaming.test.js.map +1 -1
- package/dist/tests/coValueCore.newContentSince.test.js +242 -132
- package/dist/tests/coValueCore.newContentSince.test.js.map +1 -1
- package/dist/tests/group.inheritance.test.js +47 -1
- package/dist/tests/group.inheritance.test.js.map +1 -1
- package/dist/tests/group.invite.test.js +4 -9
- package/dist/tests/group.invite.test.js.map +1 -1
- package/dist/tests/sync.auth.test.js +6 -6
- package/dist/tests/sync.load.test.js +11 -75
- package/dist/tests/sync.load.test.js.map +1 -1
- package/dist/tests/sync.mesh.test.js +2 -2
- package/dist/tests/sync.storage.test.js +22 -48
- package/dist/tests/sync.storage.test.js.map +1 -1
- package/dist/tests/sync.storageAsync.test.js +121 -71
- package/dist/tests/sync.storageAsync.test.js.map +1 -1
- package/dist/tests/sync.upload.test.js +11 -75
- package/dist/tests/sync.upload.test.js.map +1 -1
- package/dist/tests/testUtils.d.ts +4 -1
- package/dist/tests/testUtils.d.ts.map +1 -1
- package/dist/tests/testUtils.js +11 -0
- package/dist/tests/testUtils.js.map +1 -1
- package/package.json +3 -3
- package/src/coValueCore/SessionMap.ts +25 -15
- package/src/coValueCore/coValueCore.ts +32 -2
- package/src/coValueCore/verifiedState.ts +11 -20
- package/src/coValues/group.ts +28 -24
- package/src/exports.ts +5 -2
- package/src/permissions.ts +98 -119
- package/src/queue/LocalTransactionsSyncQueue.ts +1 -20
- package/src/sync.ts +9 -0
- package/src/tests/StorageApiAsync.test.ts +8 -8
- package/src/tests/coValueCore.isStreaming.test.ts +84 -91
- package/src/tests/coValueCore.newContentSince.test.ts +246 -141
- package/src/tests/group.inheritance.test.ts +61 -0
- package/src/tests/group.invite.test.ts +4 -21
- package/src/tests/sync.auth.test.ts +6 -6
- package/src/tests/sync.load.test.ts +11 -79
- package/src/tests/sync.mesh.test.ts +2 -2
- package/src/tests/sync.storage.test.ts +22 -51
- package/src/tests/sync.storageAsync.test.ts +159 -76
- package/src/tests/sync.upload.test.ts +11 -78
- package/src/tests/testUtils.ts +16 -0
|
@@ -2,6 +2,7 @@ import { assert, beforeEach, describe, expect, test } from "vitest";
|
|
|
2
2
|
import {
|
|
3
3
|
SyncMessagesLog,
|
|
4
4
|
TEST_NODE_CONFIG,
|
|
5
|
+
fillCoMapWithLargeData,
|
|
5
6
|
loadCoValueOrFail,
|
|
6
7
|
setupTestAccount,
|
|
7
8
|
setupTestNode,
|
|
@@ -49,19 +50,7 @@ describe("isStreaming", () => {
|
|
|
49
50
|
await group.core.waitForSync();
|
|
50
51
|
client.disconnect();
|
|
51
52
|
|
|
52
|
-
const map = group.createMap();
|
|
53
|
-
|
|
54
|
-
// Generate a large amount of data that requires multiple chunks
|
|
55
|
-
const dataSize = 1 * 1024 * 100;
|
|
56
|
-
const chunkSize = 1024; // 1KB chunks
|
|
57
|
-
const chunks = dataSize / chunkSize;
|
|
58
|
-
|
|
59
|
-
const value = Buffer.alloc(chunkSize, `value$`).toString("base64");
|
|
60
|
-
|
|
61
|
-
for (let i = 0; i < chunks; i++) {
|
|
62
|
-
const key = `key${i}`;
|
|
63
|
-
map.set(key, value, "trusting");
|
|
64
|
-
}
|
|
53
|
+
const map = fillCoMapWithLargeData(group.createMap());
|
|
65
54
|
|
|
66
55
|
const newSession = client.spawnNewSession();
|
|
67
56
|
|
|
@@ -101,16 +90,7 @@ describe("isStreaming", () => {
|
|
|
101
90
|
client.disconnect();
|
|
102
91
|
|
|
103
92
|
// Generate a large amount of data that requires multiple chunks
|
|
104
|
-
|
|
105
|
-
const chunkSize = 1024; // 1KB chunks
|
|
106
|
-
const chunks = dataSize / chunkSize;
|
|
107
|
-
|
|
108
|
-
const value = Buffer.alloc(chunkSize, `value$`).toString("base64");
|
|
109
|
-
|
|
110
|
-
for (let i = 0; i < chunks; i++) {
|
|
111
|
-
const key = `key${i}`;
|
|
112
|
-
map.set(key, value, "trusting");
|
|
113
|
-
}
|
|
93
|
+
fillCoMapWithLargeData(map);
|
|
114
94
|
|
|
115
95
|
const newSession = client.spawnNewSession();
|
|
116
96
|
|
|
@@ -134,41 +114,81 @@ describe("isStreaming", () => {
|
|
|
134
114
|
expect(mapInNewSession.core.isStreaming()).toBe(false);
|
|
135
115
|
});
|
|
136
116
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
117
|
+
// TODO: We can't handle client-to-client streaming until we
|
|
118
|
+
// handle the streaming state reset on disconnection
|
|
119
|
+
// Otherwise the other client might wait for a content that will never be sent
|
|
120
|
+
test.fails(
|
|
121
|
+
"streaming a large value between two clients should be streaming until all chunks are sent",
|
|
122
|
+
async () => {
|
|
123
|
+
const client = setupTestNode();
|
|
124
|
+
client.connectToSyncServer({
|
|
125
|
+
ourName: "initialClient",
|
|
126
|
+
});
|
|
127
|
+
const streamingClient = client.spawnNewSession();
|
|
128
|
+
streamingClient.connectToSyncServer({
|
|
129
|
+
ourName: "streamingClient",
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const group = client.node.createGroup();
|
|
133
|
+
|
|
134
|
+
await group.core.waitForSync();
|
|
135
|
+
client.disconnect();
|
|
136
|
+
|
|
137
|
+
const map = fillCoMapWithLargeData(group.createMap());
|
|
138
|
+
|
|
139
|
+
const loadingClient = client.spawnNewSession();
|
|
140
|
+
loadingClient.connectToSyncServer({
|
|
141
|
+
ourName: "loadingClient",
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
await loadCoValueOrFail(loadingClient.node, group.id);
|
|
145
|
+
|
|
146
|
+
const content = map.core.verified.newContentSince(undefined);
|
|
147
|
+
assert(content);
|
|
148
|
+
const lastChunk = content.pop();
|
|
149
|
+
assert(lastChunk);
|
|
150
|
+
|
|
151
|
+
for (const chunk of content) {
|
|
152
|
+
streamingClient.node.syncManager.handleNewContent(chunk, "import");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
await streamingClient.node.syncManager.waitForAllCoValuesSync();
|
|
156
|
+
|
|
157
|
+
const mapInLoadingClient = await loadCoValueOrFail(
|
|
158
|
+
loadingClient.node,
|
|
159
|
+
map.id,
|
|
160
|
+
);
|
|
146
161
|
|
|
147
|
-
|
|
162
|
+
expect(mapInLoadingClient.core.isStreaming()).toBe(true);
|
|
148
163
|
|
|
149
|
-
|
|
150
|
-
client.disconnect();
|
|
164
|
+
streamingClient.node.syncManager.handleNewContent(lastChunk, "import");
|
|
151
165
|
|
|
152
|
-
|
|
166
|
+
await waitFor(() => {
|
|
167
|
+
expect(mapInLoadingClient.core.knownState()).toEqual(
|
|
168
|
+
map.core.knownState(),
|
|
169
|
+
);
|
|
170
|
+
});
|
|
153
171
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const chunks = dataSize / chunkSize;
|
|
172
|
+
expect(mapInLoadingClient.core.isStreaming()).toBe(false);
|
|
173
|
+
},
|
|
174
|
+
);
|
|
158
175
|
|
|
159
|
-
|
|
176
|
+
test("should be false when getting streaming content that is already in the known state", async () => {
|
|
177
|
+
const client = setupTestNode({
|
|
178
|
+
connected: true,
|
|
179
|
+
});
|
|
160
180
|
|
|
161
|
-
|
|
162
|
-
const key = `key${i}`;
|
|
163
|
-
map.set(key, value, "trusting");
|
|
164
|
-
}
|
|
181
|
+
const group = client.node.createGroup();
|
|
165
182
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
});
|
|
183
|
+
await group.core.waitForSync();
|
|
184
|
+
|
|
185
|
+
const map = fillCoMapWithLargeData(group.createMap());
|
|
170
186
|
|
|
171
|
-
await
|
|
187
|
+
await map.core.waitForSync();
|
|
188
|
+
const newSession = client.spawnNewSession();
|
|
189
|
+
|
|
190
|
+
const mapInNewSession1 = await loadCoValueOrFail(newSession.node, map.id);
|
|
191
|
+
await mapInNewSession1.core.waitForFullStreaming();
|
|
172
192
|
|
|
173
193
|
const content = map.core.verified.newContentSince(undefined);
|
|
174
194
|
assert(content);
|
|
@@ -176,57 +196,28 @@ describe("isStreaming", () => {
|
|
|
176
196
|
assert(lastChunk);
|
|
177
197
|
|
|
178
198
|
for (const chunk of content) {
|
|
179
|
-
|
|
199
|
+
newSession.node.syncManager.handleNewContent(chunk, "import");
|
|
180
200
|
}
|
|
181
201
|
|
|
182
|
-
await
|
|
183
|
-
|
|
184
|
-
const mapInLoadingClient = await loadCoValueOrFail(
|
|
185
|
-
loadingClient.node,
|
|
186
|
-
map.id,
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
expect(mapInLoadingClient.core.isStreaming()).toBe(true);
|
|
190
|
-
|
|
191
|
-
streamingClient.node.syncManager.handleNewContent(lastChunk, "import");
|
|
192
|
-
|
|
193
|
-
await waitFor(() => {
|
|
194
|
-
expect(mapInLoadingClient.core.knownState()).toEqual(
|
|
195
|
-
map.core.knownState(),
|
|
196
|
-
);
|
|
197
|
-
});
|
|
202
|
+
const mapInNewSession = await loadCoValueOrFail(newSession.node, map.id);
|
|
198
203
|
|
|
199
|
-
expect(
|
|
204
|
+
expect(mapInNewSession.core.isStreaming()).toBe(false);
|
|
200
205
|
});
|
|
201
206
|
|
|
202
|
-
test("
|
|
203
|
-
const client = setupTestNode(
|
|
204
|
-
connected: true,
|
|
205
|
-
});
|
|
207
|
+
test("streaming state from clients should be ignored", async () => {
|
|
208
|
+
const client = setupTestNode();
|
|
206
209
|
|
|
207
210
|
const group = client.node.createGroup();
|
|
208
211
|
|
|
209
212
|
await group.core.waitForSync();
|
|
210
213
|
|
|
211
|
-
const map = group.createMap();
|
|
212
|
-
|
|
213
|
-
// Generate a large amount of data that requires multiple chunks
|
|
214
|
-
const dataSize = 1 * 1024 * 100;
|
|
215
|
-
const chunkSize = 1024; // 1KB chunks
|
|
216
|
-
const chunks = dataSize / chunkSize;
|
|
217
|
-
|
|
218
|
-
const value = Buffer.alloc(chunkSize, `value$`).toString("base64");
|
|
219
|
-
|
|
220
|
-
for (let i = 0; i < chunks; i++) {
|
|
221
|
-
const key = `key${i}`;
|
|
222
|
-
map.set(key, value, "trusting");
|
|
223
|
-
}
|
|
214
|
+
const map = fillCoMapWithLargeData(group.createMap());
|
|
224
215
|
|
|
225
216
|
await map.core.waitForSync();
|
|
226
217
|
const newSession = client.spawnNewSession();
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
218
|
+
newSession.connectToSyncServer({
|
|
219
|
+
ourName: "streamingClient",
|
|
220
|
+
});
|
|
230
221
|
|
|
231
222
|
const content = map.core.verified.newContentSince(undefined);
|
|
232
223
|
assert(content);
|
|
@@ -237,9 +228,11 @@ describe("isStreaming", () => {
|
|
|
237
228
|
newSession.node.syncManager.handleNewContent(chunk, "import");
|
|
238
229
|
}
|
|
239
230
|
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
expect(
|
|
231
|
+
const mapOnServer = jazzCloud.node.getCoValue(map.id);
|
|
232
|
+
expect(mapOnServer.isStreaming()).toBe(false);
|
|
233
|
+
expect(mapOnServer.knownState()).toEqual(
|
|
234
|
+
mapOnServer.knownStateWithStreaming(),
|
|
235
|
+
);
|
|
243
236
|
});
|
|
244
237
|
|
|
245
238
|
test("should be false when getting streaming content that's not really streaming", async () => {
|