@dxos/feed 0.8.4-main.9735255 → 0.8.4-main.ef1bc66f44

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 (45) hide show
  1. package/README.md +7 -2
  2. package/dist/lib/neutral/chunk-Q5PE2Q5P.mjs +735 -0
  3. package/dist/lib/neutral/chunk-Q5PE2Q5P.mjs.map +7 -0
  4. package/dist/lib/neutral/index.mjs +17 -0
  5. package/dist/lib/neutral/meta.json +1 -0
  6. package/dist/lib/neutral/testing/index.mjs +173 -0
  7. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  8. package/dist/types/src/errors.d.ts +79 -0
  9. package/dist/types/src/errors.d.ts.map +1 -0
  10. package/dist/types/src/feed-store.d.ts +68 -9
  11. package/dist/types/src/feed-store.d.ts.map +1 -1
  12. package/dist/types/src/index.d.ts +3 -1
  13. package/dist/types/src/index.d.ts.map +1 -1
  14. package/dist/types/src/sync-client.d.ts +53 -0
  15. package/dist/types/src/sync-client.d.ts.map +1 -0
  16. package/dist/types/src/sync-server.d.ts +27 -0
  17. package/dist/types/src/sync-server.d.ts.map +1 -0
  18. package/dist/types/src/testing/index.d.ts +1 -1
  19. package/dist/types/src/testing/index.d.ts.map +1 -1
  20. package/dist/types/src/testing/test-builder.d.ts +78 -0
  21. package/dist/types/src/testing/test-builder.d.ts.map +1 -0
  22. package/dist/types/tsconfig.tsbuildinfo +1 -1
  23. package/package.json +16 -13
  24. package/src/errors.ts +33 -0
  25. package/src/feed-store.test.ts +283 -35
  26. package/src/feed-store.ts +479 -132
  27. package/src/index.ts +3 -1
  28. package/src/sync-client.ts +188 -0
  29. package/src/sync-server.ts +92 -0
  30. package/src/sync.test.ts +151 -91
  31. package/src/testing/index.ts +1 -1
  32. package/src/testing/test-builder.ts +223 -0
  33. package/dist/lib/browser/index.mjs +0 -342
  34. package/dist/lib/browser/index.mjs.map +0 -7
  35. package/dist/lib/browser/meta.json +0 -1
  36. package/dist/lib/browser/testing/index.mjs +0 -1
  37. package/dist/lib/node-esm/index.mjs +0 -344
  38. package/dist/lib/node-esm/index.mjs.map +0 -7
  39. package/dist/lib/node-esm/meta.json +0 -1
  40. package/dist/lib/node-esm/testing/index.mjs +0 -2
  41. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  42. package/dist/types/src/protocol.d.ts +0 -120
  43. package/dist/types/src/protocol.d.ts.map +0 -1
  44. package/src/protocol.ts +0 -110
  45. /package/dist/lib/{browser/testing → neutral}/index.mjs.map +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/feed",
3
- "version": "0.8.4-main.9735255",
3
+ "version": "0.8.4-main.ef1bc66f44",
4
4
  "description": "Append-only replicatable log",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -16,14 +16,12 @@
16
16
  ".": {
17
17
  "types": "./dist/types/src/index.d.ts",
18
18
  "source": "./src/index.ts",
19
- "browser": "./dist/lib/browser/index.mjs",
20
- "node": "./dist/lib/node-esm/index.mjs"
19
+ "default": "./dist/lib/neutral/index.mjs"
21
20
  },
22
21
  "./testing": {
23
22
  "types": "./dist/types/src/testing/index.d.ts",
24
23
  "source": "./src/testing/index.ts",
25
- "browser": "./dist/lib/browser/testing/index.mjs",
26
- "node": "./dist/lib/node-esm/testing/index.mjs"
24
+ "default": "./dist/lib/neutral/testing/index.mjs"
27
25
  }
28
26
  },
29
27
  "types": "dist/types/src/index.d.ts",
@@ -39,15 +37,20 @@
39
37
  "src"
40
38
  ],
41
39
  "dependencies": {
42
- "@effect/sql": "0.48.6",
43
- "@effect/sql-sqlite-node": "0.49.1",
40
+ "@dxos/errors": "^0.8.3",
41
+ "@effect/sql": "0.49.0",
42
+ "@effect/sql-sqlite-node": "0.50.1",
44
43
  "@effect/vitest": "0.27.0",
45
- "effect": "3.19.11",
46
- "@dxos/invariant": "0.8.4-main.9735255",
47
- "@dxos/keys": "0.8.4-main.9735255",
48
- "@dxos/util": "0.8.4-main.9735255",
49
- "@dxos/log": "0.8.4-main.9735255",
50
- "@dxos/async": "0.8.4-main.9735255"
44
+ "effect": "3.19.16",
45
+ "@dxos/async": "0.8.4-main.ef1bc66f44",
46
+ "@dxos/invariant": "0.8.4-main.ef1bc66f44",
47
+ "@dxos/keys": "0.8.4-main.ef1bc66f44",
48
+ "@dxos/context": "0.8.4-main.ef1bc66f44",
49
+ "@dxos/log": "0.8.4-main.ef1bc66f44",
50
+ "@dxos/protocols": "0.8.4-main.ef1bc66f44",
51
+ "@dxos/util": "0.8.4-main.ef1bc66f44",
52
+ "@dxos/sql-sqlite": "0.8.4-main.ef1bc66f44",
53
+ "@dxos/effect": "0.8.4-main.ef1bc66f44"
51
54
  },
52
55
  "publishConfig": {
53
56
  "access": "public"
package/src/errors.ts ADDED
@@ -0,0 +1,33 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { BaseError } from '@dxos/errors';
6
+
7
+ export class DuplicateBlockPositionError extends BaseError.extend('DuplicateBlockPositionError') {
8
+ constructor(args: { feedId: string; position: number }) {
9
+ super(`Non-unique block position detected (feedId=${args.feedId} position=${args.position}).`);
10
+ }
11
+ }
12
+
13
+ export class DuplicateBlockLamportTimestampError extends BaseError.extend('DuplicateBlockLamportTimestampError') {
14
+ constructor(args: { feedId: string; actorId: string; sequence: number }) {
15
+ super(
16
+ `Non-unique block Lamport timestamp detected (feedId=${args.feedId} actorId=${args.actorId} sequence=${args.sequence}).`,
17
+ );
18
+ }
19
+ }
20
+
21
+ export class PositionConflictError extends BaseError.extend('PositionConflictError') {
22
+ constructor(args: {
23
+ feedId?: string;
24
+ actorId: string;
25
+ sequence: number;
26
+ currentPosition: number;
27
+ requestedPosition: number | null;
28
+ }) {
29
+ super(
30
+ `Block already has position ${args.currentPosition}, cannot set to ${args.requestedPosition} (feedId=${args.feedId} actorId=${args.actorId} sequence=${args.sequence}).`,
31
+ );
32
+ }
33
+ }
@@ -5,20 +5,30 @@
5
5
  import * as SqliteClient from '@effect/sql-sqlite-node/SqliteClient';
6
6
  import { describe, expect, it } from '@effect/vitest';
7
7
  import * as Effect from 'effect/Effect';
8
+ import * as Layer from 'effect/Layer';
8
9
 
9
10
  import { ObjectId, SpaceId } from '@dxos/keys';
10
11
  import { log } from '@dxos/log';
12
+ import { FeedProtocol } from '@dxos/protocols';
13
+ import { SqlTransaction } from '@dxos/sql-sqlite';
11
14
 
15
+ import { DuplicateBlockLamportTimestampError, DuplicateBlockPositionError } from './errors';
12
16
  import { FeedStore } from './feed-store';
13
- import { Block } from './protocol';
14
17
 
15
- const TestLayer = SqliteClient.layer({
16
- filename: ':memory:',
17
- });
18
+ const Block = FeedProtocol.Block;
19
+ type Block = FeedProtocol.Block;
20
+ const WellKnownNamespaces = FeedProtocol.WellKnownNamespaces;
21
+
22
+ const TestLayer = SqlTransaction.layer.pipe(
23
+ Layer.provideMerge(
24
+ SqliteClient.layer({
25
+ filename: ':memory:',
26
+ }),
27
+ ),
28
+ );
18
29
 
19
30
  // ActorIds.
20
31
  const ALICE = 'alice';
21
- const BOB = 'bob';
22
32
 
23
33
  describe('Feed V2', () => {
24
34
  it.effect('should append and query blocks via RPC', () =>
@@ -31,23 +41,34 @@ describe('Feed V2', () => {
31
41
 
32
42
  // Append
33
43
  const block: Block = {
34
- feedId: undefined,
44
+ feedId,
35
45
  actorId: feedId,
36
46
  sequence: 123, // Author sequence provided by peer
37
- predActorId: null,
38
- predSequence: null,
47
+ prevActorId: null,
48
+ prevSequence: null,
39
49
  position: null, // Input doesn't have position
40
50
  timestamp: Date.now(),
41
51
  data: new Uint8Array([1, 2, 3]),
42
52
  };
43
53
 
44
- const appendRes = yield* feed.append({ requestId: 'req-1', blocks: [block], spaceId, feedId, namespace: 'data' });
54
+ const appendRes = yield* feed.append({
55
+ requestId: 'req-1',
56
+ blocks: [block],
57
+ spaceId,
58
+ feedNamespace: WellKnownNamespaces.data,
59
+ });
45
60
  expect(appendRes.positions.length).toBe(1);
46
61
  expect(appendRes.positions[0]).toBeDefined();
47
62
  expect(appendRes.requestId).toBe('req-1');
48
63
 
49
64
  // Query by feedId
50
- const queryRes = yield* feed.query({ requestId: 'req-2', query: { feedIds: [feedId] }, position: -1, spaceId }); // Use position -1 to get everything
65
+ const queryRes = yield* feed.query({
66
+ requestId: 'req-2',
67
+ query: { feedIds: [feedId] },
68
+ position: -1,
69
+ spaceId,
70
+ feedNamespace: WellKnownNamespaces.data,
71
+ }); // Use position -1 to get everything
51
72
  expect(queryRes.blocks.length).toBe(1);
52
73
  expect(queryRes.blocks[0].position).toBe(appendRes.positions[0]);
53
74
  expect(queryRes.blocks[0].sequence).toBe(123); // Verify Author Sequence is preserved
@@ -59,24 +80,24 @@ describe('Feed V2', () => {
59
80
  Effect.gen(function* () {
60
81
  const spaceId = SpaceId.random();
61
82
  const feedId = ObjectId.random();
62
- const namespace = 'data';
83
+ const feedNamespace = WellKnownNamespaces.data;
63
84
 
64
85
  const feed = new FeedStore({ localActorId: ALICE, assignPositions: true });
65
86
  yield* feed.migrate();
66
87
 
67
88
  // Append with namespace
68
89
  const block = Block.make({
69
- feedId: undefined,
90
+ feedId,
70
91
  actorId: ALICE,
71
92
  sequence: 1,
72
- predActorId: null,
73
- predSequence: null,
93
+ prevActorId: null,
94
+ prevSequence: null,
74
95
  position: null,
75
96
  timestamp: Date.now(),
76
97
  data: new Uint8Array([1]),
77
98
  });
78
99
 
79
- yield* feed.append({ requestId: 'req-ns', blocks: [block], namespace, spaceId, feedId });
100
+ yield* feed.append({ requestId: 'req-ns', blocks: [block], spaceId, feedNamespace });
80
101
 
81
102
  // Verify directly from DB (white-box test) to ensure schema is correct
82
103
  const sql = yield* SqliteClient.SqliteClient;
@@ -84,7 +105,7 @@ describe('Feed V2', () => {
84
105
  SELECT feedNamespace FROM feeds WHERE spaceId = ${spaceId} AND feedId = ${feedId}
85
106
  `;
86
107
  expect(rows.length).toBeGreaterThan(0);
87
- expect(rows[0].feedNamespace).toBe(namespace);
108
+ expect(rows[0].feedNamespace).toBe(feedNamespace);
88
109
  }).pipe(Effect.provide(TestLayer)),
89
110
  );
90
111
 
@@ -101,19 +122,18 @@ describe('Feed V2', () => {
101
122
  requestId: 'req-1',
102
123
  blocks: [
103
124
  Block.make({
104
- feedId: undefined,
125
+ feedId,
105
126
  actorId: feedId,
106
127
  sequence: 1,
107
- predActorId: null,
108
- predSequence: null,
128
+ prevActorId: null,
129
+ prevSequence: null,
109
130
  position: null,
110
131
  timestamp: Date.now(),
111
132
  data: new Uint8Array([1]),
112
133
  }),
113
134
  ],
114
135
  spaceId,
115
- feedId,
116
- namespace: 'data',
136
+ feedNamespace: WellKnownNamespaces.data,
117
137
  });
118
138
 
119
139
  // Subscribe
@@ -125,6 +145,7 @@ describe('Feed V2', () => {
125
145
  const queryRes = yield* feed.query({
126
146
  requestId: 'req-3',
127
147
  spaceId,
148
+ feedNamespace: WellKnownNamespaces.data,
128
149
  query: { subscriptionId: subRes.subscriptionId },
129
150
  position: 0,
130
151
  });
@@ -133,6 +154,37 @@ describe('Feed V2', () => {
133
154
  }).pipe(Effect.provide(TestLayer)),
134
155
  );
135
156
 
157
+ it.effect('should allow position query with unpositionedOnly false', () =>
158
+ Effect.gen(function* () {
159
+ const spaceId = SpaceId.random();
160
+ const feedId = ObjectId.random();
161
+
162
+ const feed = new FeedStore({ localActorId: ALICE, assignPositions: true });
163
+ yield* feed.migrate();
164
+
165
+ yield* feed.appendLocal([
166
+ {
167
+ spaceId,
168
+ feedId,
169
+ feedNamespace: WellKnownNamespaces.data,
170
+ data: new Uint8Array([1]),
171
+ },
172
+ ]);
173
+
174
+ const queryRes = yield* feed.query({
175
+ requestId: 'req-position-false',
176
+ spaceId,
177
+ feedNamespace: WellKnownNamespaces.data,
178
+ query: { feedIds: [feedId] },
179
+ position: -1,
180
+ unpositionedOnly: false,
181
+ });
182
+
183
+ expect(queryRes.blocks.length).toBe(1);
184
+ expect(queryRes.blocks[0].feedId).toBe(feedId);
185
+ }).pipe(Effect.provide(TestLayer)),
186
+ );
187
+
136
188
  it.effect('should assign monotonic insertionId', () =>
137
189
  Effect.gen(function* () {
138
190
  const feedStore = new FeedStore({ localActorId: ALICE, assignPositions: true });
@@ -144,7 +196,7 @@ describe('Feed V2', () => {
144
196
  {
145
197
  spaceId,
146
198
  feedId: 'feed-1',
147
- feedNamespace: 'default',
199
+ feedNamespace: WellKnownNamespaces.data,
148
200
  data: new Uint8Array([1]),
149
201
  },
150
202
  ]);
@@ -153,7 +205,7 @@ describe('Feed V2', () => {
153
205
  {
154
206
  spaceId,
155
207
  feedId: 'feed-2',
156
- feedNamespace: 'default',
208
+ feedNamespace: WellKnownNamespaces.data,
157
209
  data: new Uint8Array([2]),
158
210
  },
159
211
  ]);
@@ -161,6 +213,7 @@ describe('Feed V2', () => {
161
213
  const result1 = yield* feedStore.query({
162
214
  requestId: 'req1',
163
215
  spaceId,
216
+ feedNamespace: WellKnownNamespaces.data,
164
217
  query: { feedIds: ['feed-1'] },
165
218
  position: -1,
166
219
  });
@@ -168,6 +221,7 @@ describe('Feed V2', () => {
168
221
  const result2 = yield* feedStore.query({
169
222
  requestId: 'req2',
170
223
  spaceId,
224
+ feedNamespace: WellKnownNamespaces.data,
171
225
  query: { feedIds: ['feed-2'] },
172
226
  position: -1,
173
227
  });
@@ -190,7 +244,7 @@ describe('Feed V2', () => {
190
244
  {
191
245
  spaceId,
192
246
  feedId: 'feed-1',
193
- feedNamespace: 'default',
247
+ feedNamespace: WellKnownNamespaces.data,
194
248
  data: new Uint8Array([1]),
195
249
  },
196
250
  ]);
@@ -198,7 +252,7 @@ describe('Feed V2', () => {
198
252
  {
199
253
  spaceId,
200
254
  feedId: 'feed-2',
201
- feedNamespace: 'default',
255
+ feedNamespace: WellKnownNamespaces.data,
202
256
  data: new Uint8Array([2]),
203
257
  },
204
258
  ]);
@@ -206,7 +260,7 @@ describe('Feed V2', () => {
206
260
  {
207
261
  spaceId,
208
262
  feedId: 'feed-1',
209
- feedNamespace: 'default',
263
+ feedNamespace: WellKnownNamespaces.data,
210
264
  data: new Uint8Array([3]),
211
265
  },
212
266
  ]);
@@ -215,12 +269,14 @@ describe('Feed V2', () => {
215
269
  const feed1Res = yield* feedStore.query({
216
270
  requestId: 'req1',
217
271
  spaceId,
272
+ feedNamespace: WellKnownNamespaces.data,
218
273
  query: { feedIds: ['feed-1'] },
219
274
  cursor: undefined,
220
275
  });
221
276
  const feed2Res = yield* feedStore.query({
222
277
  requestId: 'req2',
223
278
  spaceId,
279
+ feedNamespace: WellKnownNamespaces.data,
224
280
  query: { feedIds: ['feed-2'] },
225
281
  cursor: undefined,
226
282
  });
@@ -243,6 +299,7 @@ describe('Feed V2', () => {
243
299
  .query({
244
300
  requestId: 'req-bad',
245
301
  spaceId,
302
+ feedNamespace: WellKnownNamespaces.data,
246
303
  query: { feedIds: ['feed-1'] },
247
304
  cursor: invalidCursor as any,
248
305
  })
@@ -275,6 +332,7 @@ describe('Feed V2', () => {
275
332
  const nextRes = yield* feedStore.query({
276
333
  requestId: 'req-next',
277
334
  spaceId,
335
+ feedNamespace: WellKnownNamespaces.data,
278
336
  query: { feedIds: ['feed-1'] },
279
337
  cursor: validCursor as any,
280
338
  });
@@ -296,7 +354,7 @@ describe('Feed V2', () => {
296
354
  {
297
355
  spaceId,
298
356
  feedId,
299
- feedNamespace: 'data',
357
+ feedNamespace: WellKnownNamespaces.data,
300
358
  data: new Uint8Array([1]),
301
359
  },
302
360
  ]);
@@ -304,19 +362,111 @@ describe('Feed V2', () => {
304
362
  expect(blocks[0].position).toBeNull();
305
363
  expect(blocks[0].sequence).toBe(0);
306
364
  expect(blocks[0].actorId).toBe(ALICE);
307
- expect(blocks[0].predActorId).toBeNull();
308
- expect(blocks[0].predSequence).toBeNull();
365
+ expect(blocks[0].prevActorId).toBeNull();
366
+ expect(blocks[0].prevSequence).toBeNull();
309
367
  expect(blocks[0].timestamp).toBeGreaterThan(0);
310
368
  expect(blocks[0].data).toEqual(new Uint8Array([1]));
311
369
 
312
370
  // Query by feedId
313
- const queryRes = yield* feed.query({ query: { feedIds: [feedId] }, position: -1, spaceId }); // Use position '-1' to get everything
371
+ const queryRes = yield* feed.query({
372
+ query: { feedIds: [feedId] },
373
+ position: -1,
374
+ spaceId,
375
+ feedNamespace: WellKnownNamespaces.data,
376
+ }); // Use position '-1' to get everything
314
377
  expect(queryRes.blocks.length).toBe(1);
315
378
  expect(queryRes.blocks.length).toBe(1);
316
379
  expect(queryRes.blocks[0]).toMatchObject({ ...blocks[0], feedId, position: expect.any(Number) });
317
380
  }).pipe(Effect.provide(TestLayer)),
318
381
  );
319
382
 
383
+ it.effect('assigns positions independently per feed and namespace pair', () =>
384
+ Effect.gen(function* () {
385
+ const feed = new FeedStore({ localActorId: ALICE, assignPositions: true });
386
+ yield* feed.migrate();
387
+
388
+ const spaceA = SpaceId.random();
389
+ const spaceB = SpaceId.random();
390
+
391
+ const nsData = WellKnownNamespaces.data;
392
+ const nsTrace = WellKnownNamespaces.trace;
393
+ const getPersistedPosition = (spaceId: SpaceId, feedNamespace: string, feedId: string) =>
394
+ feed.query({
395
+ query: { feedIds: [feedId] },
396
+ position: -1,
397
+ spaceId,
398
+ feedNamespace,
399
+ });
400
+
401
+ // First append in each (spaceId, feedNamespace) pair starts at 0.
402
+ const feedAData = ObjectId.random();
403
+ const firstAData = yield* feed.appendLocal([
404
+ {
405
+ spaceId: spaceA,
406
+ feedId: feedAData,
407
+ feedNamespace: nsData,
408
+ data: new Uint8Array([1]),
409
+ },
410
+ ]);
411
+ const feedATrace = ObjectId.random();
412
+ const firstATrace = yield* feed.appendLocal([
413
+ {
414
+ spaceId: spaceA,
415
+ feedId: feedATrace,
416
+ feedNamespace: nsTrace,
417
+ data: new Uint8Array([2]),
418
+ },
419
+ ]);
420
+ const feedBData = ObjectId.random();
421
+ const firstBData = yield* feed.appendLocal([
422
+ {
423
+ spaceId: spaceB,
424
+ feedId: feedBData,
425
+ feedNamespace: nsData,
426
+ data: new Uint8Array([3]),
427
+ },
428
+ ]);
429
+ const feedBTrace = ObjectId.random();
430
+ const firstBHalo = yield* feed.appendLocal([
431
+ {
432
+ spaceId: spaceB,
433
+ feedId: feedBTrace,
434
+ feedNamespace: nsTrace,
435
+ data: new Uint8Array([4]),
436
+ },
437
+ ]);
438
+
439
+ // A second append in one pair should only advance that specific pair.
440
+ const feedAData2 = ObjectId.random();
441
+ const secondAData = yield* feed.appendLocal([
442
+ {
443
+ spaceId: spaceA,
444
+ feedId: feedAData2,
445
+ feedNamespace: nsData,
446
+ data: new Uint8Array([5]),
447
+ },
448
+ ]);
449
+
450
+ expect(firstAData[0].position).toBeNull();
451
+ expect(firstATrace[0].position).toBeNull();
452
+ expect(firstBData[0].position).toBeNull();
453
+ expect(firstBHalo[0].position).toBeNull();
454
+ expect(secondAData[0].position).toBeNull();
455
+
456
+ const posAData = yield* getPersistedPosition(spaceA, nsData, feedAData);
457
+ const posATrace = yield* getPersistedPosition(spaceA, nsTrace, feedATrace);
458
+ const posBData = yield* getPersistedPosition(spaceB, nsData, feedBData);
459
+ const posBTrace = yield* getPersistedPosition(spaceB, nsTrace, feedBTrace);
460
+ const posAData2 = yield* getPersistedPosition(spaceA, nsData, feedAData2);
461
+
462
+ expect(posAData.blocks[0].position).toBe(0);
463
+ expect(posATrace.blocks[0].position).toBe(0);
464
+ expect(posBData.blocks[0].position).toBe(0);
465
+ expect(posBTrace.blocks[0].position).toBe(0);
466
+ expect(posAData2.blocks[0].position).toBe(1);
467
+ }).pipe(Effect.provide(TestLayer)),
468
+ );
469
+
320
470
  it.effect('tailing a feed', () =>
321
471
  Effect.gen(function* () {
322
472
  const spaceId = SpaceId.random();
@@ -329,15 +479,24 @@ describe('Feed V2', () => {
329
479
  {
330
480
  spaceId,
331
481
  feedId,
332
- feedNamespace: 'data',
482
+ feedNamespace: WellKnownNamespaces.data,
333
483
  data: new Uint8Array([1]),
334
484
  },
335
485
  ]);
336
- const query1 = yield* feed.query({ spaceId, query: { feedIds: [feedId] } }); // Use position '-1' to get everything
486
+ const query1 = yield* feed.query({
487
+ spaceId,
488
+ feedNamespace: WellKnownNamespaces.data,
489
+ query: { feedIds: [feedId] },
490
+ }); // Use position '-1' to get everything
337
491
  log.info('query 1', { blocks: query1.blocks.length, cursor: query1.nextCursor });
338
492
  expect(query1.blocks.length).toBe(1);
339
493
 
340
- const query2 = yield* feed.query({ spaceId, query: { feedIds: [feedId] }, cursor: query1.nextCursor });
494
+ const query2 = yield* feed.query({
495
+ spaceId,
496
+ feedNamespace: WellKnownNamespaces.data,
497
+ query: { feedIds: [feedId] },
498
+ cursor: query1.nextCursor,
499
+ });
341
500
  log.info('query 2', { blocks: query2.blocks.length, cursor: query2.nextCursor });
342
501
  expect(query2.blocks.length).toBe(0);
343
502
 
@@ -345,13 +504,102 @@ describe('Feed V2', () => {
345
504
  {
346
505
  spaceId,
347
506
  feedId,
348
- feedNamespace: 'data',
507
+ feedNamespace: WellKnownNamespaces.data,
349
508
  data: new Uint8Array([2]),
350
509
  },
351
510
  ]);
352
- const query3 = yield* feed.query({ spaceId, query: { feedIds: [feedId] }, cursor: query2.nextCursor });
511
+ const query3 = yield* feed.query({
512
+ spaceId,
513
+ feedNamespace: WellKnownNamespaces.data,
514
+ query: { feedIds: [feedId] },
515
+ cursor: query2.nextCursor,
516
+ });
353
517
  log.info('query 3', { blocks: query3.blocks.length, cursor: query3.nextCursor });
354
518
  expect(query3.blocks.length).toBe(1);
355
519
  }).pipe(Effect.provide(TestLayer)),
356
520
  );
521
+
522
+ it.effect('append fails on non-unique position in request', () =>
523
+ Effect.gen(function* () {
524
+ const spaceId = SpaceId.random();
525
+ const feedId = ObjectId.random();
526
+ const feed = new FeedStore({ localActorId: ALICE, assignPositions: false });
527
+ yield* feed.migrate();
528
+
529
+ const error = yield* feed
530
+ .append({
531
+ requestId: 'req-dup-position',
532
+ spaceId,
533
+ feedNamespace: WellKnownNamespaces.data,
534
+ blocks: [
535
+ Block.make({
536
+ feedId,
537
+ actorId: 'actor-1',
538
+ sequence: 1,
539
+ prevActorId: null,
540
+ prevSequence: null,
541
+ position: 10,
542
+ timestamp: Date.now(),
543
+ data: new Uint8Array([1]),
544
+ }),
545
+ Block.make({
546
+ feedId,
547
+ actorId: 'actor-2',
548
+ sequence: 1,
549
+ prevActorId: null,
550
+ prevSequence: null,
551
+ position: 10,
552
+ timestamp: Date.now(),
553
+ data: new Uint8Array([2]),
554
+ }),
555
+ ],
556
+ })
557
+ .pipe(Effect.flip);
558
+
559
+ expect(error).toBeInstanceOf(DuplicateBlockPositionError);
560
+ expect(error.message).toContain('Non-unique block position detected');
561
+ }).pipe(Effect.provide(TestLayer)),
562
+ );
563
+
564
+ it.effect('append fails on non-unique Lamport timestamp in request', () =>
565
+ Effect.gen(function* () {
566
+ const spaceId = SpaceId.random();
567
+ const feedId = ObjectId.random();
568
+ const feed = new FeedStore({ localActorId: ALICE, assignPositions: false });
569
+ yield* feed.migrate();
570
+
571
+ const error = yield* feed
572
+ .append({
573
+ requestId: 'req-dup-lamport',
574
+ spaceId,
575
+ feedNamespace: WellKnownNamespaces.data,
576
+ blocks: [
577
+ Block.make({
578
+ feedId,
579
+ actorId: 'actor-1',
580
+ sequence: 5,
581
+ prevActorId: null,
582
+ prevSequence: null,
583
+ position: 1,
584
+ timestamp: Date.now(),
585
+ data: new Uint8Array([1]),
586
+ }),
587
+ Block.make({
588
+ feedId,
589
+ actorId: 'actor-1',
590
+ sequence: 5,
591
+ prevActorId: null,
592
+ prevSequence: null,
593
+ position: 2,
594
+ timestamp: Date.now(),
595
+ data: new Uint8Array([2]),
596
+ }),
597
+ ],
598
+ })
599
+ .pipe(Effect.flip);
600
+
601
+ expect(error).toBeInstanceOf(DuplicateBlockLamportTimestampError);
602
+ expect(error.message).toContain('Non-unique block Lamport timestamp detected');
603
+ }).pipe(Effect.provide(TestLayer)),
604
+ );
357
605
  });