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.
Files changed (76) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +18 -0
  3. package/dist/coValueCore/SessionMap.d.ts +5 -3
  4. package/dist/coValueCore/SessionMap.d.ts.map +1 -1
  5. package/dist/coValueCore/SessionMap.js +19 -9
  6. package/dist/coValueCore/SessionMap.js.map +1 -1
  7. package/dist/coValueCore/coValueCore.d.ts +5 -2
  8. package/dist/coValueCore/coValueCore.d.ts.map +1 -1
  9. package/dist/coValueCore/coValueCore.js +24 -4
  10. package/dist/coValueCore/coValueCore.js.map +1 -1
  11. package/dist/coValueCore/verifiedState.d.ts +1 -3
  12. package/dist/coValueCore/verifiedState.d.ts.map +1 -1
  13. package/dist/coValueCore/verifiedState.js +10 -14
  14. package/dist/coValueCore/verifiedState.js.map +1 -1
  15. package/dist/coValues/group.d.ts +2 -1
  16. package/dist/coValues/group.d.ts.map +1 -1
  17. package/dist/coValues/group.js +21 -18
  18. package/dist/coValues/group.js.map +1 -1
  19. package/dist/exports.d.ts +5 -4
  20. package/dist/exports.d.ts.map +1 -1
  21. package/dist/exports.js +3 -3
  22. package/dist/exports.js.map +1 -1
  23. package/dist/permissions.d.ts +0 -1
  24. package/dist/permissions.d.ts.map +1 -1
  25. package/dist/permissions.js +83 -89
  26. package/dist/permissions.js.map +1 -1
  27. package/dist/queue/LocalTransactionsSyncQueue.d.ts.map +1 -1
  28. package/dist/queue/LocalTransactionsSyncQueue.js +1 -18
  29. package/dist/queue/LocalTransactionsSyncQueue.js.map +1 -1
  30. package/dist/sync.d.ts.map +1 -1
  31. package/dist/sync.js +8 -0
  32. package/dist/sync.js.map +1 -1
  33. package/dist/tests/StorageApiAsync.test.js +8 -8
  34. package/dist/tests/coValueCore.isStreaming.test.js +30 -40
  35. package/dist/tests/coValueCore.isStreaming.test.js.map +1 -1
  36. package/dist/tests/coValueCore.newContentSince.test.js +242 -132
  37. package/dist/tests/coValueCore.newContentSince.test.js.map +1 -1
  38. package/dist/tests/group.inheritance.test.js +47 -1
  39. package/dist/tests/group.inheritance.test.js.map +1 -1
  40. package/dist/tests/group.invite.test.js +4 -9
  41. package/dist/tests/group.invite.test.js.map +1 -1
  42. package/dist/tests/sync.auth.test.js +6 -6
  43. package/dist/tests/sync.load.test.js +11 -75
  44. package/dist/tests/sync.load.test.js.map +1 -1
  45. package/dist/tests/sync.mesh.test.js +2 -2
  46. package/dist/tests/sync.storage.test.js +22 -48
  47. package/dist/tests/sync.storage.test.js.map +1 -1
  48. package/dist/tests/sync.storageAsync.test.js +121 -71
  49. package/dist/tests/sync.storageAsync.test.js.map +1 -1
  50. package/dist/tests/sync.upload.test.js +11 -75
  51. package/dist/tests/sync.upload.test.js.map +1 -1
  52. package/dist/tests/testUtils.d.ts +4 -1
  53. package/dist/tests/testUtils.d.ts.map +1 -1
  54. package/dist/tests/testUtils.js +11 -0
  55. package/dist/tests/testUtils.js.map +1 -1
  56. package/package.json +3 -3
  57. package/src/coValueCore/SessionMap.ts +25 -15
  58. package/src/coValueCore/coValueCore.ts +32 -2
  59. package/src/coValueCore/verifiedState.ts +11 -20
  60. package/src/coValues/group.ts +28 -24
  61. package/src/exports.ts +5 -2
  62. package/src/permissions.ts +98 -119
  63. package/src/queue/LocalTransactionsSyncQueue.ts +1 -20
  64. package/src/sync.ts +9 -0
  65. package/src/tests/StorageApiAsync.test.ts +8 -8
  66. package/src/tests/coValueCore.isStreaming.test.ts +84 -91
  67. package/src/tests/coValueCore.newContentSince.test.ts +246 -141
  68. package/src/tests/group.inheritance.test.ts +61 -0
  69. package/src/tests/group.invite.test.ts +4 -21
  70. package/src/tests/sync.auth.test.ts +6 -6
  71. package/src/tests/sync.load.test.ts +11 -79
  72. package/src/tests/sync.mesh.test.ts +2 -2
  73. package/src/tests/sync.storage.test.ts +22 -51
  74. package/src/tests/sync.storageAsync.test.ts +159 -76
  75. package/src/tests/sync.upload.test.ts +11 -78
  76. 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
- const dataSize = 1 * 1024 * 100;
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
- test("streaming a large value between two clients should be streaming until all chunks are sent", async () => {
138
- const client = setupTestNode();
139
- client.connectToSyncServer({
140
- ourName: "initialClient",
141
- });
142
- const streamingClient = client.spawnNewSession();
143
- streamingClient.connectToSyncServer({
144
- ourName: "streamingClient",
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
- const group = client.node.createGroup();
162
+ expect(mapInLoadingClient.core.isStreaming()).toBe(true);
148
163
 
149
- await group.core.waitForSync();
150
- client.disconnect();
164
+ streamingClient.node.syncManager.handleNewContent(lastChunk, "import");
151
165
 
152
- const map = group.createMap();
166
+ await waitFor(() => {
167
+ expect(mapInLoadingClient.core.knownState()).toEqual(
168
+ map.core.knownState(),
169
+ );
170
+ });
153
171
 
154
- // Generate a large amount of data that requires multiple chunks
155
- const dataSize = 1 * 1024 * 100;
156
- const chunkSize = 1024; // 1KB chunks
157
- const chunks = dataSize / chunkSize;
172
+ expect(mapInLoadingClient.core.isStreaming()).toBe(false);
173
+ },
174
+ );
158
175
 
159
- const value = Buffer.alloc(chunkSize, `value$`).toString("base64");
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
- for (let i = 0; i < chunks; i++) {
162
- const key = `key${i}`;
163
- map.set(key, value, "trusting");
164
- }
181
+ const group = client.node.createGroup();
165
182
 
166
- const loadingClient = client.spawnNewSession();
167
- loadingClient.connectToSyncServer({
168
- ourName: "loadingClient",
169
- });
183
+ await group.core.waitForSync();
184
+
185
+ const map = fillCoMapWithLargeData(group.createMap());
170
186
 
171
- await loadCoValueOrFail(loadingClient.node, group.id);
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
- streamingClient.node.syncManager.handleNewContent(chunk, "import");
199
+ newSession.node.syncManager.handleNewContent(chunk, "import");
180
200
  }
181
201
 
182
- await streamingClient.node.syncManager.waitForAllCoValuesSync();
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(mapInLoadingClient.core.isStreaming()).toBe(false);
204
+ expect(mapInNewSession.core.isStreaming()).toBe(false);
200
205
  });
201
206
 
202
- test("should be false when getting streaming content that is already in the known state", async () => {
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
- const mapInNewSession1 = await loadCoValueOrFail(newSession.node, map.id);
229
- await mapInNewSession1.core.waitForFullStreaming();
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 mapInNewSession = await loadCoValueOrFail(newSession.node, map.id);
241
-
242
- expect(mapInNewSession.core.isStreaming()).toBe(false);
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 () => {