@dxos/feed 0.8.4-main.9be5663bfe → 0.8.4-main.bc2380dfbc
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/LICENSE +102 -5
- package/dist/lib/neutral/{chunk-53CMKQL5.mjs → chunk-YYASRWLE.mjs} +169 -23
- package/dist/lib/neutral/chunk-YYASRWLE.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +1 -1
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/lib/neutral/testing/index.mjs +3 -9
- package/dist/lib/neutral/testing/index.mjs.map +2 -2
- package/dist/types/src/errors.d.ts +6 -6
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/feed-store.d.ts +1 -1
- package/dist/types/src/feed-store.d.ts.map +1 -1
- package/dist/types/src/sync-client.d.ts.map +1 -1
- package/dist/types/src/sync-server.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts +3 -3
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -20
- package/src/feed-store.test.ts +3 -1
- package/src/feed-store.ts +23 -10
- package/src/sync-client.ts +90 -5
- package/src/sync-server.ts +62 -8
- package/dist/lib/neutral/chunk-53CMKQL5.mjs.map +0 -7
package/LICENSE
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2022 DXOS
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Abbreviation
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 DXOS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
|
@@ -77,7 +77,9 @@ var FeedStore = class {
|
|
|
77
77
|
const rows = yield* sql`
|
|
78
78
|
SELECT feedPrivateId FROM feeds WHERE spaceId = ${spaceId} AND feedId = ${feedId}
|
|
79
79
|
`;
|
|
80
|
-
if (rows.length > 0)
|
|
80
|
+
if (rows.length > 0) {
|
|
81
|
+
return rows[0].feedPrivateId;
|
|
82
|
+
}
|
|
81
83
|
const newRows = yield* sql`
|
|
82
84
|
INSERT INTO feeds (spaceId, feedId, feedNamespace) VALUES (${spaceId}, ${feedId}, ${namespace}) RETURNING feedPrivateId
|
|
83
85
|
`;
|
|
@@ -89,7 +91,9 @@ var FeedStore = class {
|
|
|
89
91
|
#ensureCursorToken = Effect.fn("Feed.ensureCursorToken")((spaceId) => Effect.gen(this, function* () {
|
|
90
92
|
const sql = yield* SqlClient.SqlClient;
|
|
91
93
|
const rows = yield* sql`SELECT token FROM cursor_tokens WHERE spaceId = ${spaceId}`;
|
|
92
|
-
if (rows.length > 0)
|
|
94
|
+
if (rows.length > 0) {
|
|
95
|
+
return rows[0].token;
|
|
96
|
+
}
|
|
93
97
|
const token = crypto.randomUUID().replace(/-/g, "").slice(0, 6);
|
|
94
98
|
yield* sql`INSERT INTO cursor_tokens (spaceId, token) VALUES (${spaceId}, ${token})`;
|
|
95
99
|
return token;
|
|
@@ -461,6 +465,19 @@ var FeedStore = class {
|
|
|
461
465
|
setPosition = (request) => Effect.gen(this, function* () {
|
|
462
466
|
const sql = yield* SqlClient.SqlClient;
|
|
463
467
|
for (const block of request.blocks) {
|
|
468
|
+
const updated = yield* sql`
|
|
469
|
+
UPDATE blocks SET position = ${block.position}
|
|
470
|
+
WHERE feedPrivateId = (
|
|
471
|
+
SELECT feedPrivateId FROM feeds
|
|
472
|
+
WHERE spaceId = ${request.spaceId} AND feedId = ${block.feedId} AND feedNamespace = ${block.feedNamespace}
|
|
473
|
+
)
|
|
474
|
+
AND actorId = ${block.actorId} AND sequence = ${block.sequence}
|
|
475
|
+
AND (position IS NULL OR position = ${block.position})
|
|
476
|
+
RETURNING position
|
|
477
|
+
`;
|
|
478
|
+
if (updated.length > 0) {
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
464
481
|
const existing = yield* sql`
|
|
465
482
|
SELECT position FROM blocks
|
|
466
483
|
WHERE feedPrivateId = (
|
|
@@ -479,14 +496,6 @@ var FeedStore = class {
|
|
|
479
496
|
requestedPosition: block.position
|
|
480
497
|
}));
|
|
481
498
|
}
|
|
482
|
-
yield* sql`
|
|
483
|
-
UPDATE blocks SET position = ${block.position}
|
|
484
|
-
WHERE feedPrivateId = (
|
|
485
|
-
SELECT feedPrivateId FROM feeds
|
|
486
|
-
WHERE spaceId = ${request.spaceId} AND feedId = ${block.feedId} AND feedNamespace = ${block.feedNamespace}
|
|
487
|
-
)
|
|
488
|
-
AND actorId = ${block.actorId} AND sequence = ${block.sequence}
|
|
489
|
-
`;
|
|
490
499
|
}
|
|
491
500
|
}).pipe(Effect.withSpan("FeedStore.setPosition"));
|
|
492
501
|
/**
|
|
@@ -532,6 +541,19 @@ var decodeCursor = (cursor) => {
|
|
|
532
541
|
|
|
533
542
|
// src/sync-server.ts
|
|
534
543
|
import * as Effect2 from "effect/Effect";
|
|
544
|
+
import { log } from "@dxos/log";
|
|
545
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/feed/src/sync-server.ts";
|
|
546
|
+
var inboundSummary = (message) => ({
|
|
547
|
+
tag: message._tag,
|
|
548
|
+
senderPeerId: message.senderPeerId,
|
|
549
|
+
recipientPeerId: message.recipientPeerId,
|
|
550
|
+
requestId: "requestId" in message ? message.requestId : void 0,
|
|
551
|
+
spaceId: "spaceId" in message ? message.spaceId : void 0,
|
|
552
|
+
feedNamespace: "feedNamespace" in message ? message.feedNamespace : void 0,
|
|
553
|
+
blockCount: "blocks" in message ? message.blocks.length : void 0,
|
|
554
|
+
position: "position" in message ? message.position : void 0,
|
|
555
|
+
limit: "limit" in message ? message.limit : void 0
|
|
556
|
+
});
|
|
535
557
|
var SyncServer = class {
|
|
536
558
|
#peerId;
|
|
537
559
|
#feedStore;
|
|
@@ -546,6 +568,10 @@ var SyncServer = class {
|
|
|
546
568
|
*/
|
|
547
569
|
handleMessage(ctx, message) {
|
|
548
570
|
const self = this;
|
|
571
|
+
log("feed sync server received message", {
|
|
572
|
+
peerId: self.#peerId,
|
|
573
|
+
...inboundSummary(message)
|
|
574
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 33, S: this });
|
|
549
575
|
const recipientPeerId = message.senderPeerId;
|
|
550
576
|
const withPeerIds = (payload) => ({
|
|
551
577
|
...payload,
|
|
@@ -557,29 +583,70 @@ var SyncServer = class {
|
|
|
557
583
|
const req = message;
|
|
558
584
|
return Effect2.gen(function* () {
|
|
559
585
|
const response = yield* self.#feedStore.query(req);
|
|
586
|
+
log("feed sync server query completed", {
|
|
587
|
+
peerId: self.#peerId,
|
|
588
|
+
recipientPeerId,
|
|
589
|
+
requestId: req.requestId,
|
|
590
|
+
spaceId: req.spaceId,
|
|
591
|
+
feedNamespace: req.feedNamespace,
|
|
592
|
+
returnedBlocks: response.blocks.length,
|
|
593
|
+
hasMore: response.hasMore
|
|
594
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 49, S: this });
|
|
560
595
|
yield* self.#sendMessage(ctx, withPeerIds({
|
|
561
596
|
_tag: "QueryResponse",
|
|
562
597
|
...response
|
|
563
598
|
}));
|
|
564
|
-
}).pipe(Effect2.catchAll((err) =>
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
599
|
+
}).pipe(Effect2.catchAll((err) => {
|
|
600
|
+
log("feed sync server query failed", {
|
|
601
|
+
peerId: self.#peerId,
|
|
602
|
+
recipientPeerId,
|
|
603
|
+
requestId: req.requestId,
|
|
604
|
+
spaceId: req.spaceId,
|
|
605
|
+
feedNamespace: req.feedNamespace,
|
|
606
|
+
cause: err instanceof Error ? err.message : String(err)
|
|
607
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 63, S: this });
|
|
608
|
+
return self.#sendMessage(ctx, withPeerIds({
|
|
609
|
+
_tag: "Error",
|
|
610
|
+
message: err instanceof Error ? err.message : String(err)
|
|
611
|
+
}));
|
|
612
|
+
}));
|
|
568
613
|
}
|
|
569
614
|
case "AppendRequest": {
|
|
570
615
|
const req = message;
|
|
571
616
|
return Effect2.gen(function* () {
|
|
572
617
|
const response = yield* self.#feedStore.append(req);
|
|
618
|
+
log("feed sync server append completed", {
|
|
619
|
+
peerId: self.#peerId,
|
|
620
|
+
recipientPeerId,
|
|
621
|
+
requestId: req.requestId,
|
|
622
|
+
spaceId: req.spaceId,
|
|
623
|
+
feedNamespace: req.feedNamespace,
|
|
624
|
+
assignedPositions: response.positions.length
|
|
625
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 82, S: this });
|
|
573
626
|
yield* self.#sendMessage(ctx, withPeerIds({
|
|
574
627
|
_tag: "AppendResponse",
|
|
575
628
|
...response
|
|
576
629
|
}));
|
|
577
|
-
}).pipe(Effect2.catchAll((err) =>
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
630
|
+
}).pipe(Effect2.catchAll((err) => {
|
|
631
|
+
log("feed sync server append failed", {
|
|
632
|
+
peerId: self.#peerId,
|
|
633
|
+
recipientPeerId,
|
|
634
|
+
requestId: req.requestId,
|
|
635
|
+
spaceId: req.spaceId,
|
|
636
|
+
feedNamespace: req.feedNamespace,
|
|
637
|
+
cause: err instanceof Error ? err.message : String(err)
|
|
638
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 95, S: this });
|
|
639
|
+
return self.#sendMessage(ctx, withPeerIds({
|
|
640
|
+
_tag: "Error",
|
|
641
|
+
message: err instanceof Error ? err.message : String(err)
|
|
642
|
+
}));
|
|
643
|
+
}));
|
|
581
644
|
}
|
|
582
645
|
default:
|
|
646
|
+
log("feed sync server ignoring unsupported message", {
|
|
647
|
+
peerId: self.#peerId,
|
|
648
|
+
tag: message._tag
|
|
649
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 110, S: this });
|
|
583
650
|
return Effect2.void;
|
|
584
651
|
}
|
|
585
652
|
}
|
|
@@ -589,6 +656,9 @@ var SyncServer = class {
|
|
|
589
656
|
import * as Array from "effect/Array";
|
|
590
657
|
import * as Deferred from "effect/Deferred";
|
|
591
658
|
import * as Effect3 from "effect/Effect";
|
|
659
|
+
import { ContextDisposedError } from "@dxos/context";
|
|
660
|
+
import { log as log2 } from "@dxos/log";
|
|
661
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/echo/feed/src/sync-client.ts";
|
|
592
662
|
var SyncClient = class {
|
|
593
663
|
#peerId;
|
|
594
664
|
#serverPeerId;
|
|
@@ -620,10 +690,30 @@ var SyncClient = class {
|
|
|
620
690
|
*/
|
|
621
691
|
handleMessage(message) {
|
|
622
692
|
const requestId = "requestId" in message && message.requestId != null ? String(message.requestId) : void 0;
|
|
623
|
-
if (requestId == null)
|
|
693
|
+
if (requestId == null) {
|
|
694
|
+
log2.trace("feed sync client response ignored (no request id)", {
|
|
695
|
+
tag: message._tag,
|
|
696
|
+
senderPeerId: message.senderPeerId
|
|
697
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 45, S: this });
|
|
698
|
+
return Effect3.void;
|
|
699
|
+
}
|
|
624
700
|
const deferred = this.#handlers.get(requestId);
|
|
625
|
-
if (deferred == null)
|
|
701
|
+
if (deferred == null) {
|
|
702
|
+
log2.trace("feed sync client response ignored (no pending rpc)", {
|
|
703
|
+
requestId,
|
|
704
|
+
tag: message._tag,
|
|
705
|
+
senderPeerId: message.senderPeerId
|
|
706
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 53, S: this });
|
|
707
|
+
return Effect3.void;
|
|
708
|
+
}
|
|
626
709
|
this.#handlers.delete(requestId);
|
|
710
|
+
log2("feed sync client rpc completed", {
|
|
711
|
+
requestId,
|
|
712
|
+
tag: message._tag,
|
|
713
|
+
blockCount: "blocks" in message ? message.blocks.length : void 0,
|
|
714
|
+
positionCount: "positions" in message ? message.positions.length : void 0,
|
|
715
|
+
error: message._tag === "Error" ? message.message : void 0
|
|
716
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 61, S: this });
|
|
627
717
|
if (message._tag === "Error") {
|
|
628
718
|
return Effect3.andThen(Deferred.fail(deferred, new Error(message.message)), () => Effect3.void);
|
|
629
719
|
}
|
|
@@ -639,6 +729,13 @@ var SyncClient = class {
|
|
|
639
729
|
const requestId = crypto.randomUUID();
|
|
640
730
|
const deferred = yield* Deferred.make();
|
|
641
731
|
self.#handlers.set(requestId, deferred);
|
|
732
|
+
const cleanupDispose = ctx.disposed ? () => {
|
|
733
|
+
} : ctx.onDispose(() => {
|
|
734
|
+
Effect3.runFork(Deferred.fail(deferred, new ContextDisposedError()));
|
|
735
|
+
});
|
|
736
|
+
if (ctx.disposed) {
|
|
737
|
+
yield* Deferred.fail(deferred, new ContextDisposedError());
|
|
738
|
+
}
|
|
642
739
|
const request = {
|
|
643
740
|
_tag: "QueryRequest",
|
|
644
741
|
requestId,
|
|
@@ -647,10 +744,25 @@ var SyncClient = class {
|
|
|
647
744
|
position: lastPulledPosition,
|
|
648
745
|
limit: opts.limit
|
|
649
746
|
};
|
|
747
|
+
log2("feed sync client pull rpc sending", {
|
|
748
|
+
requestId,
|
|
749
|
+
spaceId: opts.spaceId,
|
|
750
|
+
feedNamespace: opts.feedNamespace,
|
|
751
|
+
afterPosition: lastPulledPosition,
|
|
752
|
+
limit: opts.limit
|
|
753
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 97, S: this });
|
|
650
754
|
yield* self.#sendMessage(ctx, self.#withPeerIds(request));
|
|
651
|
-
const message = yield* Deferred.await(deferred)
|
|
755
|
+
const message = yield* Effect3.ensuring(Deferred.await(deferred), Effect3.sync(() => {
|
|
756
|
+
cleanupDispose();
|
|
757
|
+
self.#handlers.delete(requestId);
|
|
758
|
+
}));
|
|
652
759
|
const response = yield* self.#expectResponse(requestId, message, "QueryResponse");
|
|
653
760
|
if (response.blocks.length === 0) {
|
|
761
|
+
log2.trace("feed sync client pull done (empty batch)", {
|
|
762
|
+
requestId,
|
|
763
|
+
spaceId: opts.spaceId,
|
|
764
|
+
feedNamespace: opts.feedNamespace
|
|
765
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 111, S: this });
|
|
654
766
|
return {
|
|
655
767
|
done: true
|
|
656
768
|
};
|
|
@@ -666,6 +778,14 @@ var SyncClient = class {
|
|
|
666
778
|
feedNamespace: opts.feedNamespace,
|
|
667
779
|
lastPulledPosition: maxPulledPosition
|
|
668
780
|
});
|
|
781
|
+
log2("feed sync client pull applied batch", {
|
|
782
|
+
requestId,
|
|
783
|
+
spaceId: opts.spaceId,
|
|
784
|
+
feedNamespace: opts.feedNamespace,
|
|
785
|
+
batchSize: response.blocks.length,
|
|
786
|
+
hasMore: response.hasMore,
|
|
787
|
+
maxPulledPosition
|
|
788
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 132, S: this });
|
|
669
789
|
return {
|
|
670
790
|
done: false
|
|
671
791
|
};
|
|
@@ -681,6 +801,10 @@ var SyncClient = class {
|
|
|
681
801
|
limit: opts.limit
|
|
682
802
|
});
|
|
683
803
|
if (unpositioned.blocks.length === 0) {
|
|
804
|
+
log2.trace("feed sync client push skipped (nothing to send)", {
|
|
805
|
+
spaceId: opts.spaceId,
|
|
806
|
+
feedNamespace: opts.feedNamespace
|
|
807
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 155, S: this });
|
|
684
808
|
return {
|
|
685
809
|
done: true
|
|
686
810
|
};
|
|
@@ -688,6 +812,13 @@ var SyncClient = class {
|
|
|
688
812
|
const requestId = crypto.randomUUID();
|
|
689
813
|
const deferred = yield* Deferred.make();
|
|
690
814
|
self.#handlers.set(requestId, deferred);
|
|
815
|
+
const cleanupDispose = ctx.disposed ? () => {
|
|
816
|
+
} : ctx.onDispose(() => {
|
|
817
|
+
Effect3.runFork(Deferred.fail(deferred, new ContextDisposedError()));
|
|
818
|
+
});
|
|
819
|
+
if (ctx.disposed) {
|
|
820
|
+
yield* Deferred.fail(deferred, new ContextDisposedError());
|
|
821
|
+
}
|
|
691
822
|
const request = {
|
|
692
823
|
_tag: "AppendRequest",
|
|
693
824
|
requestId,
|
|
@@ -695,8 +826,17 @@ var SyncClient = class {
|
|
|
695
826
|
feedNamespace: opts.feedNamespace,
|
|
696
827
|
blocks: unpositioned.blocks
|
|
697
828
|
};
|
|
829
|
+
log2("feed sync client push rpc sending", {
|
|
830
|
+
requestId,
|
|
831
|
+
spaceId: opts.spaceId,
|
|
832
|
+
feedNamespace: opts.feedNamespace,
|
|
833
|
+
blockCount: unpositioned.blocks.length
|
|
834
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 179, S: this });
|
|
698
835
|
yield* self.#sendMessage(ctx, self.#withPeerIds(request));
|
|
699
|
-
const message = yield* Deferred.await(deferred)
|
|
836
|
+
const message = yield* Effect3.ensuring(Deferred.await(deferred), Effect3.sync(() => {
|
|
837
|
+
cleanupDispose();
|
|
838
|
+
self.#handlers.delete(requestId);
|
|
839
|
+
}));
|
|
700
840
|
const response = yield* self.#expectResponse(requestId, message, "AppendResponse");
|
|
701
841
|
yield* self.#feedStore.setPosition({
|
|
702
842
|
spaceId: opts.spaceId,
|
|
@@ -708,6 +848,12 @@ var SyncClient = class {
|
|
|
708
848
|
position
|
|
709
849
|
}))
|
|
710
850
|
});
|
|
851
|
+
log2("feed sync client push positions applied", {
|
|
852
|
+
requestId,
|
|
853
|
+
spaceId: opts.spaceId,
|
|
854
|
+
feedNamespace: opts.feedNamespace,
|
|
855
|
+
positionCount: response.positions.length
|
|
856
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 201, S: this });
|
|
711
857
|
return {
|
|
712
858
|
done: false
|
|
713
859
|
};
|
|
@@ -731,4 +877,4 @@ export {
|
|
|
731
877
|
SyncServer,
|
|
732
878
|
SyncClient
|
|
733
879
|
};
|
|
734
|
-
//# sourceMappingURL=chunk-
|
|
880
|
+
//# sourceMappingURL=chunk-YYASRWLE.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/errors.ts", "../../../src/feed-store.ts", "../../../src/sync-server.ts", "../../../src/sync-client.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2026 DXOS.org\n//\n\nimport { BaseError } from '@dxos/errors';\n\nexport class PositionConflictError extends BaseError.extend('PositionConflictError') {\n constructor(args: {\n feedId?: string;\n actorId: string;\n sequence: number;\n currentPosition: number;\n requestedPosition: number | null;\n }) {\n super({\n message: `Block already has position ${args.currentPosition}, cannot set to ${args.requestedPosition} (feedId=${args.feedId} actorId=${args.actorId} sequence=${args.sequence}).`,\n context: args,\n });\n }\n}\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport * as SqlClient from '@effect/sql/SqlClient';\nimport type * as SqlError from '@effect/sql/SqlError';\nimport * as Effect from 'effect/Effect';\n\nimport { Event } from '@dxos/async';\nimport { assertArgument } from '@dxos/invariant';\nimport { type SpaceId } from '@dxos/keys';\nimport { FeedProtocol } from '@dxos/protocols';\nimport { SqlTransaction } from '@dxos/sql-sqlite';\n\nimport { PositionConflictError } from './errors';\n\ntype AppendRequest = FeedProtocol.AppendRequest;\ntype AppendResponse = FeedProtocol.AppendResponse;\ntype Block = FeedProtocol.Block;\nconst FeedCursor = FeedProtocol.FeedCursor;\ntype FeedCursor = FeedProtocol.FeedCursor;\nconst isWellKnownNamespace = FeedProtocol.isWellKnownNamespace;\ntype QueryRequest = FeedProtocol.QueryRequest;\ntype QueryResponse = FeedProtocol.QueryResponse;\ntype SubscribeRequest = FeedProtocol.SubscribeRequest;\ntype SubscribeResponse = FeedProtocol.SubscribeResponse;\n\nexport interface FeedStoreOptions {\n /**\n * The actor ID of the local user.\n */\n localActorId: string;\n\n /**\n * Whether to assign positions to appended blocks.\n * Only a single peer (usually the server) can assign positions.\n */\n assignPositions: boolean;\n}\n\n/**\n * Persistent storage for feed metadata, blocks, subscriptions, and sync state.\n *\n */\nexport class FeedStore {\n readonly #options: FeedStoreOptions;\n\n constructor(options: FeedStoreOptions) {\n this.#options = options;\n }\n\n /**\n * Emits after successful block append operations.\n */\n readonly onNewBlocks = new Event<void>();\n\n /**\n * Creates required feed store tables and indexes if they do not exist.\n */\n migrate = Effect.fn('FeedStore.migrate')(() =>\n Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n\n // Feeds Table\n yield* sql`CREATE TABLE IF NOT EXISTS feeds (\n feedPrivateId INTEGER PRIMARY KEY AUTOINCREMENT,\n spaceId TEXT NOT NULL,\n feedId TEXT NOT NULL,\n feedNamespace TEXT\n )`;\n yield* sql`CREATE UNIQUE INDEX IF NOT EXISTS idx_feeds_spaceId_feedId ON feeds(spaceId, feedId)`;\n\n // Blocks Table\n yield* sql`CREATE TABLE IF NOT EXISTS blocks (\n insertionId INTEGER PRIMARY KEY AUTOINCREMENT,\n feedPrivateId INTEGER NOT NULL,\n position INTEGER,\n sequence INTEGER NOT NULL,\n actorId TEXT NOT NULL,\n prevSequence INTEGER,\n prevActorId TEXT,\n timestamp INTEGER NOT NULL,\n data BLOB NOT NULL,\n FOREIGN KEY(feedPrivateId) REFERENCES feeds(feedPrivateId)\n )`;\n yield* sql`CREATE UNIQUE INDEX IF NOT EXISTS idx_blocks_feedPrivateId_position ON blocks(feedPrivateId, position)`;\n yield* sql`CREATE UNIQUE INDEX IF NOT EXISTS idx_blocks_feedPrivateId_sequence_actorId ON blocks(feedPrivateId, sequence, actorId)`;\n\n // Subscriptions Table\n yield* sql`CREATE TABLE IF NOT EXISTS subscriptions (\n subscriptionId TEXT PRIMARY KEY,\n expiresAt INTEGER NOT NULL,\n feedPrivateIds TEXT NOT NULL -- JSON array\n )`;\n\n // Cursor Tokens Table\n yield* sql`CREATE TABLE IF NOT EXISTS cursor_tokens (\n spaceId TEXT PRIMARY KEY,\n token TEXT NOT NULL\n )`;\n\n // Sync State Table.\n yield* sql`CREATE TABLE IF NOT EXISTS sync_state (\n spaceId TEXT NOT NULL,\n feedNamespace TEXT NOT NULL,\n lastPulledPosition INTEGER NOT NULL DEFAULT -1,\n PRIMARY KEY (spaceId, feedNamespace)\n )`;\n }).pipe(Effect.withSpan('FeedStore.migrate')),\n );\n\n /**\n * Ensures a feed row exists and returns its internal feed ID.\n */\n #ensureFeed = Effect.fn('Feed.ensureFeed')(\n (\n spaceId: string,\n feedId: string,\n namespace?: string,\n ): Effect.Effect<number, SqlError.SqlError, SqlClient.SqlClient> =>\n Effect.gen(this, function* () {\n const sql = yield* SqlClient.SqlClient;\n\n const rows = yield* sql<{ feedPrivateId: number }>`\n SELECT feedPrivateId FROM feeds WHERE spaceId = ${spaceId} AND feedId = ${feedId}\n `;\n if (rows.length > 0) {\n return rows[0].feedPrivateId;\n }\n\n const newRows = yield* sql<{ feedPrivateId: number }>`\n INSERT INTO feeds (spaceId, feedId, feedNamespace) VALUES (${spaceId}, ${feedId}, ${namespace}) RETURNING feedPrivateId\n `;\n return newRows[0].feedPrivateId;\n }).pipe(Effect.withSpan('FeedStore.ensureFeed')),\n );\n\n /**\n * Ensures cursor token exists for a space and returns it.\n */\n #ensureCursorToken = Effect.fn('Feed.ensureCursorToken')(\n (spaceId: string): Effect.Effect<string, SqlError.SqlError, SqlClient.SqlClient> =>\n Effect.gen(this, function* () {\n const sql = yield* SqlClient.SqlClient;\n const rows = yield* sql<{ token: string }>`SELECT token FROM cursor_tokens WHERE spaceId = ${spaceId}`;\n if (rows.length > 0) {\n return rows[0].token;\n }\n\n const token = crypto.randomUUID().replace(/-/g, '').slice(0, 6);\n yield* sql`INSERT INTO cursor_tokens (spaceId, token) VALUES (${spaceId}, ${token})`;\n return token;\n }).pipe(Effect.withSpan('FeedStore.ensureCursorToken')),\n );\n\n /**\n * Queries feed blocks by feed IDs or subscription with cursor/position pagination.\n */\n query = Effect.fn('Feed.query')(\n (request: QueryRequest): Effect.Effect<QueryResponse, SqlError.SqlError, SqlClient.SqlClient> =>\n Effect.gen(this, function* () {\n const sql = yield* SqlClient.SqlClient;\n let feedIds: string[] | undefined = [];\n let cursorInsertionId = -1;\n let cursorToken: string | undefined;\n\n if (!request.spaceId) {\n return yield* Effect.die(new Error('spaceId is required'));\n }\n\n if (\n (request.position !== undefined ? 1 : 0) +\n (request.cursor !== undefined ? 1 : 0) +\n (request.unpositionedOnly === true ? 1 : 0) >\n 1\n ) {\n return yield* Effect.die(new Error('Only one of position, cursor, or unpositionedOnly can be used'));\n }\n\n if (request.cursor) {\n const { token, insertionId } = decodeCursor(request.cursor as FeedCursor);\n if (!token || insertionId === undefined || isNaN(insertionId)) {\n return yield* Effect.die(new Error(`Invalid cursor format`));\n }\n cursorToken = token;\n cursorInsertionId = insertionId;\n }\n\n // Validate Token if cursor used.\n const validCursorToken = yield* this.#ensureCursorToken(request.spaceId);\n if (request.cursor && cursorToken !== validCursorToken) {\n return yield* Effect.die(new Error(`Cursor token mismatch`));\n }\n\n // If cursor is provided, we must validate it against the space token.\n // If spaceId is not provided in request (e.g. feedIds query), we can't easily validate token unless we look up spaceId for feedIds.\n // Ideally spaceId should be required for token validation.\n\n /*\n Logic:\n 1. If `cursor` is present, it's `token|insertionId`.\n 2. If `position` is present, it's `position` (legacy/manual).\n \n We prioritize `cursor`.\n */\n\n const position = request.position ?? -1;\n\n // Resolve subscriptions or feed IDs.\n if (request.query && 'subscriptionId' in request.query) {\n const rows = yield* sql<{ feedPrivateIds: string; expiresAt: number }>`\n SELECT feedPrivateIds, expiresAt FROM subscriptions WHERE subscriptionId = ${request.query.subscriptionId}\n `;\n if (rows.length > 0) {\n const { feedPrivateIds, expiresAt } = rows[0];\n if (Date.now() <= expiresAt) {\n const privateIds = JSON.parse(feedPrivateIds) as number[];\n if (privateIds.length > 0) {\n const feedRows = yield* sql<{ feedId: string }>`\n SELECT feedId FROM feeds WHERE feedPrivateId IN ${sql.in(privateIds)}\n `;\n feedIds = feedRows.map((r) => r.feedId);\n }\n }\n }\n } else if (request.query && 'feedIds' in request.query) {\n feedIds = [...request.query.feedIds];\n } else {\n feedIds = undefined;\n }\n\n if (feedIds !== undefined && feedIds.length === 0) {\n return {\n requestId: request.requestId,\n blocks: [],\n nextCursor: encodeCursor(validCursorToken, -1),\n hasMore: false,\n };\n }\n\n // Fetch blocks.\n const query = sql<Block>`\n SELECT blocks.*, feeds.feedId, feeds.feedNamespace\n FROM blocks\n JOIN feeds ON blocks.feedPrivateId = feeds.feedPrivateId\n WHERE 1=1\n ${feedIds !== undefined ? sql`AND feeds.feedId IN ${sql.in(feedIds)}` : sql``}\n ${request.spaceId ? sql`AND feeds.spaceId = ${request.spaceId}` : sql``}\n ${sql`AND feeds.feedNamespace = ${request.feedNamespace}`}\n `;\n\n // Add filter based on cursor or position.\n const filter = request.cursor\n ? sql`AND blocks.insertionId > ${cursorInsertionId}`\n : request.unpositionedOnly\n ? sql`AND blocks.position IS NULL`\n : sql`AND (blocks.position > ${position} OR blocks.position IS NULL)`;\n\n const orderBy = request.cursor\n ? sql`ORDER BY blocks.insertionId ASC`\n : sql`ORDER BY blocks.position ASC NULLS LAST`;\n\n const requestLimit = request.limit;\n const queryLimit = requestLimit != null ? requestLimit + 1 : undefined;\n const rows = yield* sql<Block>`\n ${query}\n ${filter}\n ${orderBy}\n ${queryLimit != null ? sql`LIMIT ${queryLimit}` : sql``}\n `;\n\n const hasMore = requestLimit != null && rows.length > requestLimit;\n const slice = hasMore ? rows.slice(0, requestLimit) : rows;\n const blocks = slice.map((row) => ({\n ...row,\n // Have to clone buffer otherwise we get empty Uint8Array.\n data: new Uint8Array(row.data),\n }));\n\n let nextCursor: FeedCursor = request.cursor ?? encodeCursor(validCursorToken, -1);\n if (blocks.length > 0 && request.spaceId) {\n const lastBlock = blocks[blocks.length - 1];\n if (lastBlock.insertionId !== undefined) {\n nextCursor = encodeCursor(validCursorToken, lastBlock.insertionId);\n }\n }\n\n return { requestId: request.requestId, blocks, nextCursor, hasMore } satisfies QueryResponse;\n }).pipe(Effect.withSpan('FeedStore.query')),\n );\n\n /**\n * Creates a subscription and stores the resolved internal feed IDs.\n */\n subscribe = Effect.fn('Feed.subscribe')(\n (request: SubscribeRequest): Effect.Effect<SubscribeResponse, SqlError.SqlError, SqlClient.SqlClient> =>\n Effect.gen(this, function* () {\n const sql = yield* SqlClient.SqlClient;\n const ttl = 60 * 60 * 1000;\n const subscriptionId = crypto.randomUUID();\n const expiresAt = Date.now() + ttl;\n\n if (!request.spaceId) {\n // TODO(dmaretskyi): Define error type.\n return yield* Effect.die(new Error('spaceId required for subscribe'));\n }\n\n const feedPrivateIds = yield* Effect.forEach(\n request.feedIds,\n (feedId) => this.#ensureFeed(request.spaceId!, feedId),\n { concurrency: 'unbounded' },\n );\n\n yield* sql`\n INSERT INTO subscriptions (subscriptionId, expiresAt, feedPrivateIds)\n VALUES (${subscriptionId}, ${expiresAt}, ${JSON.stringify(feedPrivateIds)})\n `;\n\n return {\n requestId: request.requestId,\n subscriptionId,\n expiresAt,\n };\n }).pipe(Effect.withSpan('FeedStore.subscribe')),\n );\n\n /**\n * Get the last pulled position for the given space and namespace.\n * Returns -1 if no sync state exists yet.\n */\n getSyncState = (opts: {\n spaceId: SpaceId;\n feedNamespace: string;\n }): Effect.Effect<number, SqlError.SqlError, SqlClient.SqlClient> =>\n Effect.gen(this, function* () {\n const sql = yield* SqlClient.SqlClient;\n const rows = yield* sql<{ lastPulledPosition: number }>`\n SELECT lastPulledPosition FROM sync_state\n WHERE spaceId = ${opts.spaceId} AND feedNamespace = ${opts.feedNamespace}\n `;\n return rows[0]?.lastPulledPosition ?? -1;\n }).pipe(Effect.withSpan('FeedStore.getSyncState'));\n\n /**\n * Update the last pulled position for the given space and namespace.\n */\n setSyncState = (opts: {\n spaceId: SpaceId;\n feedNamespace: string;\n lastPulledPosition: number;\n }): Effect.Effect<void, SqlError.SqlError, SqlClient.SqlClient> =>\n Effect.gen(this, function* () {\n const sql = yield* SqlClient.SqlClient;\n yield* sql`\n INSERT INTO sync_state (spaceId, feedNamespace, lastPulledPosition)\n VALUES (${opts.spaceId}, ${opts.feedNamespace}, ${opts.lastPulledPosition})\n ON CONFLICT (spaceId, feedNamespace) DO UPDATE SET lastPulledPosition = ${opts.lastPulledPosition}\n `;\n }).pipe(Effect.withSpan('FeedStore.setSyncState'));\n\n /**\n * Returns the number of stored blocks for a single feed in a space/namespace.\n * Intended as a low-level primitive for callers (for example Cloudflare Worker code)\n * that need to make retention decisions under constrained storage resources.\n */\n countBlocks = (opts: {\n spaceId: SpaceId;\n feedNamespace: string;\n feedId: string;\n }): Effect.Effect<number, SqlError.SqlError, SqlClient.SqlClient> =>\n Effect.gen(this, function* () {\n const sql = yield* SqlClient.SqlClient;\n const rows = yield* sql<{ count: number }>`\n SELECT COUNT(*) AS count\n FROM blocks\n JOIN feeds ON blocks.feedPrivateId = feeds.feedPrivateId\n WHERE feeds.spaceId = ${opts.spaceId}\n AND feeds.feedNamespace = ${opts.feedNamespace}\n AND feeds.feedId = ${opts.feedId}\n `;\n return rows[0]?.count ?? 0;\n }).pipe(Effect.withSpan('FeedStore.countBlocks'));\n\n /**\n * Deletes the oldest blocks for a single feed in a space/namespace.\n * This API intentionally does not enforce any retention policy (such as max size);\n * callers decide when and how much to prune, which is useful for constrained\n * environments like Cloudflare Workers.\n *\n * @returns Number of deleted rows.\n */\n deleteOldestBlocks = (opts: {\n spaceId: SpaceId;\n feedNamespace: string;\n feedId: string;\n count: number;\n }): Effect.Effect<number, SqlError.SqlError, SqlClient.SqlClient> =>\n Effect.gen(this, function* () {\n const sql = yield* SqlClient.SqlClient;\n if (opts.count <= 0) {\n return 0;\n }\n\n const deletedRows = yield* sql<{ insertionId: number }>`\n DELETE FROM blocks\n WHERE insertionId IN (\n SELECT blocks.insertionId\n FROM blocks\n JOIN feeds ON blocks.feedPrivateId = feeds.feedPrivateId\n WHERE feeds.spaceId = ${opts.spaceId}\n AND feeds.feedNamespace = ${opts.feedNamespace}\n AND feeds.feedId = ${opts.feedId}\n ORDER BY blocks.insertionId ASC\n LIMIT ${opts.count}\n )\n RETURNING insertionId\n `;\n\n return deletedRows.length;\n }).pipe(Effect.withSpan('FeedStore.deleteOldestBlocks'));\n\n /**\n * Appends blocks for a space/namespace and optionally assigns global positions.\n */\n append = (\n request: AppendRequest,\n ): Effect.Effect<AppendResponse, SqlError.SqlError, SqlClient.SqlClient | SqlTransaction.SqlTransaction> =>\n Effect.gen(this, function* () {\n if (!request.spaceId) {\n return yield* Effect.die(new Error('spaceId required for append'));\n }\n\n assertArgument(\n isWellKnownNamespace(request.feedNamespace),\n 'request.feedNamespace',\n 'specified well-known namespace',\n );\n\n // Validate all blocks upfront.\n for (const block of request.blocks) {\n assertArgument(block.feedId, 'block.feedId', 'feedId is required');\n }\n\n // Wrap in transaction to ensure atomicity when assigning positions.\n const sqlTransaction = yield* SqlTransaction.SqlTransaction;\n const positions = yield* sqlTransaction.withTransaction(\n Effect.gen(this, function* () {\n const sql = yield* SqlClient.SqlClient;\n\n // 1. Collect unique feed IDs and batch #ensureFeed calls.\n const feedKeys = new Map<string, { feedId: string }>();\n for (const block of request.blocks) {\n const key = block.feedId!;\n if (!feedKeys.has(key)) {\n feedKeys.set(key, { feedId: block.feedId! });\n }\n }\n\n const feedPrivateIds = new Map<string, number>();\n yield* Effect.forEach(\n [...feedKeys.entries()],\n ([key, { feedId }]) =>\n Effect.gen(this, function* () {\n const id = yield* this.#ensureFeed(request.spaceId!, feedId, request.feedNamespace);\n feedPrivateIds.set(key, id);\n }),\n { concurrency: 'unbounded' },\n );\n\n // 2. Get max position per namespace ONCE (not per block).\n const maxPositions = new Map<string, number>();\n if (this.#options.assignPositions) {\n const maxPosResult = yield* sql<{ maxPos: number | null }>`\n SELECT MAX(position) as maxPos \n FROM blocks \n JOIN feeds ON blocks.feedPrivateId = feeds.feedPrivateId\n WHERE feeds.spaceId = ${request.spaceId} AND feeds.feedNamespace = ${request.feedNamespace}\n `;\n maxPositions.set(request.feedNamespace, maxPosResult[0]?.maxPos ?? -1);\n }\n\n // 3. Insert all blocks and compute positions.\n const positions: number[] = [];\n for (const block of request.blocks) {\n const key = block.feedId!;\n const feedPrivateId = feedPrivateIds.get(key)!;\n\n let positionToInsert: number | null = null;\n if (this.#options.assignPositions) {\n const currentMax = maxPositions.get(request.feedNamespace)!;\n positionToInsert = currentMax + 1;\n maxPositions.set(request.feedNamespace, positionToInsert); // Increment for next block in same namespace.\n positions.push(positionToInsert);\n } else if (block.position != null) {\n positionToInsert = block.position;\n }\n\n yield* sql`\n INSERT INTO blocks (\n feedPrivateId, position, sequence, actorId, \n prevSequence, prevActorId, timestamp, data\n ) VALUES (\n ${feedPrivateId}, ${positionToInsert}, ${block.sequence}, ${block.actorId},\n ${block.prevSequence}, ${block.prevActorId}, ${block.timestamp}, ${block.data}\n ) ON CONFLICT DO NOTHING\n `;\n }\n\n return positions;\n }),\n );\n\n this.onNewBlocks.emit();\n\n return { requestId: request.requestId, positions };\n }).pipe(Effect.withSpan('FeedStore.append'));\n\n /**\n * Creates local blocks with sequential predecessors and appends grouped batches.\n */\n appendLocal = Effect.fn('Feed.appendLocal')(\n (\n messages: { spaceId: string; feedId: string; feedNamespace: string; data: Uint8Array }[],\n ): Effect.Effect<Block[], SqlError.SqlError, SqlClient.SqlClient | SqlTransaction.SqlTransaction> =>\n Effect.gen(this, function* () {\n const sql = yield* SqlClient.SqlClient;\n\n // 1. Collect unique feeds and ensure they exist.\n type FeedKey = string; // `${spaceId}|${feedNamespace}|${feedId}`\n const feedKeys = new Map<FeedKey, { spaceId: string; feedId: string; feedNamespace: string }>();\n for (const msg of messages) {\n const key = `${msg.spaceId}|${msg.feedNamespace}|${msg.feedId}`;\n if (!feedKeys.has(key)) {\n feedKeys.set(key, { spaceId: msg.spaceId, feedId: msg.feedId, feedNamespace: msg.feedNamespace });\n }\n }\n\n // Batch ensure feeds and get their private IDs.\n const feedPrivateIds = new Map<FeedKey, number>();\n yield* Effect.forEach(\n [...feedKeys.entries()],\n ([key, { spaceId, feedId, feedNamespace }]) =>\n Effect.gen(this, function* () {\n const id = yield* this.#ensureFeed(spaceId, feedId, feedNamespace);\n feedPrivateIds.set(key, id);\n }),\n { concurrency: 'unbounded' },\n );\n\n // 2. Get last sequence for each unique feed (batch query).\n const lastSeqs = new Map<FeedKey, { sequence: number; actorId: string } | null>();\n for (const [key] of feedKeys) {\n const feedPrivateId = feedPrivateIds.get(key)!;\n const lastBlockResult = yield* sql<{ sequence: number; actorId: string }>`\n SELECT sequence, actorId FROM blocks \n WHERE feedPrivateId = ${feedPrivateId} \n ORDER BY sequence DESC \n LIMIT 1\n `;\n lastSeqs.set(key, lastBlockResult[0] ?? null);\n }\n\n // 3. Build all blocks with correct sequences.\n // Track in-flight sequences per feed to handle multiple messages to same feed.\n const currentSeqs = new Map<FeedKey, { sequence: number; actorId: string }>();\n const blocks: Block[] = [];\n const blocksBySpaceNamespace = new Map<string, { spaceId: string; feedNamespace: string; blocks: Block[] }>();\n\n for (const msg of messages) {\n const key = `${msg.spaceId}|${msg.feedNamespace}|${msg.feedId}`;\n\n // Determine predecessor: either from in-flight blocks or from DB.\n let sequence: number;\n let prevSequence: number | null;\n let prevActorId: string | null;\n\n const inFlight = currentSeqs.get(key);\n if (inFlight) {\n // We've already added blocks for this feed - continue from last in-flight.\n sequence = inFlight.sequence + 1;\n prevSequence = inFlight.sequence;\n prevActorId = inFlight.actorId;\n } else {\n // First block for this feed - use DB state.\n const lastBlock = lastSeqs.get(key);\n sequence = (lastBlock?.sequence ?? -1) + 1;\n prevSequence = lastBlock?.sequence ?? null;\n prevActorId = lastBlock?.actorId ?? null;\n }\n\n const block: Block = {\n feedId: msg.feedId,\n actorId: this.#options.localActorId,\n sequence,\n prevActorId,\n prevSequence,\n timestamp: Date.now(),\n data: msg.data,\n position: null, // Assigned by append.\n };\n\n blocks.push(block);\n\n // Update in-flight tracking.\n currentSeqs.set(key, { sequence, actorId: this.#options.localActorId });\n\n // Group by (spaceId, feedNamespace).\n const spaceNamespaceKey = `${msg.spaceId}|${msg.feedNamespace}`;\n if (!blocksBySpaceNamespace.has(spaceNamespaceKey)) {\n blocksBySpaceNamespace.set(spaceNamespaceKey, {\n spaceId: msg.spaceId,\n feedNamespace: msg.feedNamespace,\n blocks: [],\n });\n }\n blocksBySpaceNamespace.get(spaceNamespaceKey)!.blocks.push(block);\n }\n\n // 4. Call append once per (spaceId, namespace) batch and assign returned positions.\n const positionByBlock = new Map<Block, number | null>();\n for (const { spaceId, feedNamespace, blocks: batchBlocks } of blocksBySpaceNamespace.values()) {\n const { positions } = yield* this.append({\n requestId: 'local-append',\n blocks: batchBlocks,\n spaceId,\n feedNamespace,\n });\n for (let i = 0; i < batchBlocks.length; i++) {\n positionByBlock.set(batchBlocks[i], positions[i] ?? null);\n }\n }\n\n return blocks.map((block) => ({\n ...block,\n position: positionByBlock.get(block) ?? block.position,\n }));\n }).pipe(Effect.withSpan('FeedStore.appendLocal')),\n );\n\n /**\n * Sets positions for existing blocks while preventing conflicting reassignments.\n */\n setPosition = (request: {\n spaceId: string;\n blocks: (Pick<Block, 'feedId' | 'actorId' | 'sequence' | 'position'> & { feedNamespace: string })[];\n }): Effect.Effect<void, SqlError.SqlError | PositionConflictError, SqlClient.SqlClient> =>\n Effect.gen(this, function* () {\n const sql = yield* SqlClient.SqlClient;\n for (const block of request.blocks) {\n // Fold the conflict check into the UPDATE itself: only write when the row is\n // unset or already at the requested position. RETURNING tells us whether the\n // write took effect, so we avoid the per-block SELECT round-trip on the\n // common path. Conflicts (rare) take the slow path below.\n const updated = yield* sql<{ position: number | null }>`\n UPDATE blocks SET position = ${block.position}\n WHERE feedPrivateId = (\n SELECT feedPrivateId FROM feeds\n WHERE spaceId = ${request.spaceId} AND feedId = ${block.feedId} AND feedNamespace = ${block.feedNamespace}\n )\n AND actorId = ${block.actorId} AND sequence = ${block.sequence}\n AND (position IS NULL OR position = ${block.position})\n RETURNING position\n `;\n if (updated.length > 0) {\n continue;\n }\n const existing = yield* sql<{ position: number | null }>`\n SELECT position FROM blocks\n WHERE feedPrivateId = (\n SELECT feedPrivateId FROM feeds\n WHERE spaceId = ${request.spaceId} AND feedId = ${block.feedId} AND feedNamespace = ${block.feedNamespace}\n )\n AND actorId = ${block.actorId} AND sequence = ${block.sequence}\n `;\n const current = existing[0];\n if (current?.position != null && current.position !== block.position) {\n yield* Effect.fail(\n new PositionConflictError({\n feedId: block.feedId,\n actorId: block.actorId,\n sequence: block.sequence,\n currentPosition: current.position,\n requestedPosition: block.position,\n }),\n );\n }\n }\n }).pipe(Effect.withSpan('FeedStore.setPosition'));\n\n /**\n * Gets all feeds and their blocks for a space, organized by feed ID and namespace.\n * Used for space archive export.\n */\n getAllFeedsForSpace = (opts: {\n spaceId: SpaceId;\n }): Effect.Effect<\n Array<{\n feedId: string;\n feedNamespace: string;\n blocks: Block[];\n }>,\n SqlError.SqlError,\n SqlClient.SqlClient\n > =>\n Effect.gen(this, function* () {\n const sql = yield* SqlClient.SqlClient;\n\n const feeds = yield* sql<{ feedId: string; feedNamespace: string }>`\n SELECT DISTINCT feedId, feedNamespace FROM feeds WHERE spaceId = ${opts.spaceId}\n `;\n\n const result: Array<{ feedId: string; feedNamespace: string; blocks: Block[] }> = [];\n\n for (const feed of feeds) {\n const blocks = yield* sql<Block>`\n SELECT blocks.*, feeds.feedId, feeds.feedNamespace\n FROM blocks\n JOIN feeds ON blocks.feedPrivateId = feeds.feedPrivateId\n WHERE feeds.spaceId = ${opts.spaceId}\n AND feeds.feedId = ${feed.feedId}\n AND feeds.feedNamespace = ${feed.feedNamespace}\n ORDER BY blocks.sequence ASC\n `;\n\n result.push({\n feedId: feed.feedId,\n feedNamespace: feed.feedNamespace,\n blocks: blocks.map((row) => ({\n ...row,\n data: new Uint8Array(row.data),\n })),\n });\n }\n\n return result;\n }).pipe(Effect.withSpan('FeedStore.getAllFeedsForSpace'));\n}\n\nconst encodeCursor = (token: string, insertionId: number) => FeedCursor.make(`${token}|${insertionId}`);\nconst decodeCursor = (cursor: FeedCursor) => {\n const [token, insertionId] = cursor.split('|');\n return { token, insertionId: Number(insertionId) };\n};\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport type * as SqlClient from '@effect/sql/SqlClient';\nimport * as Effect from 'effect/Effect';\n\nimport { Context } from '@dxos/context';\nimport { log } from '@dxos/log';\nimport { type FeedProtocol } from '@dxos/protocols';\nimport type { SqlTransaction } from '@dxos/sql-sqlite';\n\nimport type { FeedStore } from './feed-store';\n\ntype AppendRequest = FeedProtocol.AppendRequest;\ntype ProtocolMessage = FeedProtocol.ProtocolMessage;\ntype QueryRequest = FeedProtocol.QueryRequest;\ntype QueryResponse = FeedProtocol.QueryResponse;\n\nconst inboundSummary = (message: ProtocolMessage) => ({\n tag: message._tag,\n senderPeerId: message.senderPeerId,\n recipientPeerId: message.recipientPeerId,\n requestId: 'requestId' in message ? message.requestId : undefined,\n spaceId: 'spaceId' in message ? message.spaceId : undefined,\n feedNamespace: 'feedNamespace' in message ? message.feedNamespace : undefined,\n blockCount: 'blocks' in message ? message.blocks.length : undefined,\n position: 'position' in message ? message.position : undefined,\n limit: 'limit' in message ? message.limit : undefined,\n});\n\nexport type SyncServerOptions = {\n /** This server's peer id. Set as senderPeerId on all replies. */\n peerId: string;\n feedStore: FeedStore;\n /** Send a protocol message to a client. Receives full message (recipient is set by server). Returns Effect. */\n sendMessage: (ctx: Context, message: ProtocolMessage) => Effect.Effect<void, unknown, never>;\n};\n\n/**\n * Server-side sync: receives protocol messages, runs query/append against the store, sends responses.\n * Reusable for many peers: sets senderPeerId = peerId and recipientPeerId = incoming message's senderPeerId on replies.\n */\nexport class SyncServer {\n readonly #peerId: string;\n readonly #feedStore: FeedStore;\n readonly #sendMessage: SyncServerOptions['sendMessage'];\n\n constructor(options: SyncServerOptions) {\n this.#peerId = options.peerId;\n this.#feedStore = options.feedStore;\n this.#sendMessage = options.sendMessage;\n }\n\n /**\n * Receive a message from a client. Handles QueryRequest and AppendRequest; sends response via sendMessage with correct peer ids.\n */\n handleMessage(\n ctx: Context,\n message: ProtocolMessage,\n ): Effect.Effect<void, unknown, SqlClient.SqlClient | SqlTransaction.SqlTransaction> {\n const self = this;\n log('feed sync server received message', {\n peerId: self.#peerId,\n ...inboundSummary(message),\n });\n const recipientPeerId = message.senderPeerId;\n const withPeerIds = (payload: Omit<ProtocolMessage, 'senderPeerId' | 'recipientPeerId'>): ProtocolMessage =>\n ({\n ...payload,\n senderPeerId: self.#peerId,\n recipientPeerId,\n }) as ProtocolMessage;\n switch (message._tag) {\n case 'QueryRequest': {\n const req = message as QueryRequest;\n return Effect.gen(function* () {\n const response: QueryResponse = yield* self.#feedStore.query(req);\n log('feed sync server query completed', {\n peerId: self.#peerId,\n recipientPeerId,\n requestId: req.requestId,\n spaceId: req.spaceId,\n feedNamespace: req.feedNamespace,\n returnedBlocks: response.blocks.length,\n hasMore: response.hasMore,\n });\n yield* self.#sendMessage(ctx, withPeerIds({ _tag: 'QueryResponse', ...response }));\n }).pipe(\n Effect.catchAll((err: unknown) => {\n log('feed sync server query failed', {\n peerId: self.#peerId,\n recipientPeerId,\n requestId: req.requestId,\n spaceId: req.spaceId,\n feedNamespace: req.feedNamespace,\n cause: err instanceof Error ? err.message : String(err),\n });\n return self.#sendMessage(\n ctx,\n withPeerIds({\n _tag: 'Error',\n message: err instanceof Error ? err.message : String(err),\n } as Omit<ProtocolMessage, 'senderPeerId' | 'recipientPeerId'>),\n );\n }),\n );\n }\n case 'AppendRequest': {\n const req = message as AppendRequest;\n return Effect.gen(function* () {\n const response = yield* self.#feedStore.append(req);\n log('feed sync server append completed', {\n peerId: self.#peerId,\n recipientPeerId,\n requestId: req.requestId,\n spaceId: req.spaceId,\n feedNamespace: req.feedNamespace,\n assignedPositions: response.positions.length,\n });\n yield* self.#sendMessage(ctx, withPeerIds({ _tag: 'AppendResponse', ...response }));\n }).pipe(\n Effect.catchAll((err: unknown) => {\n log('feed sync server append failed', {\n peerId: self.#peerId,\n recipientPeerId,\n requestId: req.requestId,\n spaceId: req.spaceId,\n feedNamespace: req.feedNamespace,\n cause: err instanceof Error ? err.message : String(err),\n });\n return self.#sendMessage(\n ctx,\n withPeerIds({\n _tag: 'Error',\n message: err instanceof Error ? err.message : String(err),\n } as Omit<ProtocolMessage, 'senderPeerId' | 'recipientPeerId'>),\n );\n }),\n );\n }\n default:\n log('feed sync server ignoring unsupported message', {\n peerId: self.#peerId,\n tag: message._tag,\n });\n return Effect.void;\n }\n }\n}\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport type * as SqlClient from '@effect/sql/SqlClient';\nimport * as Array from 'effect/Array';\nimport * as Deferred from 'effect/Deferred';\nimport * as Effect from 'effect/Effect';\n\nimport { Context, ContextDisposedError } from '@dxos/context';\nimport type { SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type FeedProtocol } from '@dxos/protocols';\nimport type { SqlTransaction } from '@dxos/sql-sqlite';\n\nimport type { FeedStore } from './feed-store';\n\ntype AppendResponse = FeedProtocol.AppendResponse;\ntype ProtocolMessage = FeedProtocol.ProtocolMessage;\ntype QueryResponse = FeedProtocol.QueryResponse;\ntype QueryRequestMessage = Extract<ProtocolMessage, { _tag: 'QueryRequest' }>;\ntype AppendRequestMessage = Extract<ProtocolMessage, { _tag: 'AppendRequest' }>;\ntype RequestMessage = QueryRequestMessage | AppendRequestMessage;\ntype RequestPayload =\n | Omit<QueryRequestMessage, 'senderPeerId' | 'recipientPeerId'>\n | Omit<AppendRequestMessage, 'senderPeerId' | 'recipientPeerId'>;\n\nexport type SyncClientOptions = {\n /** This client's peer id. Set as senderPeerId on all requests. */\n peerId: string;\n /** The server's peer id. Set as recipientPeerId on all requests. */\n serverPeerId?: string;\n feedStore: FeedStore;\n /** Send a protocol message to the server. Returns Effect. */\n sendMessage: (ctx: Context, message: RequestMessage) => Effect.Effect<void, unknown, never>;\n};\n\n/**\n * Client-side sync: pull/push by sending protocol messages and handling responses.\n * Sets senderPeerId = peerId and recipientPeerId = serverPeerId on all requests.\n * Uses a map of requestId -> Deferred to match responses to in-flight requests.\n * handleMessage completes the Deferred for the requestId (if any) and removes the handler; no handler = noop.\n */\nexport class SyncClient {\n readonly #peerId: string;\n readonly #serverPeerId: string | undefined;\n readonly #feedStore: FeedStore;\n readonly #sendMessage: SyncClientOptions['sendMessage'];\n readonly #handlers = new Map<string, Deferred.Deferred<ProtocolMessage, Error>>();\n\n constructor(options: SyncClientOptions) {\n this.#peerId = options.peerId;\n this.#serverPeerId = options.serverPeerId;\n this.#feedStore = options.feedStore;\n this.#sendMessage = options.sendMessage;\n }\n\n #withPeerIds(payload: RequestPayload): RequestMessage {\n if (payload._tag === 'QueryRequest') {\n return {\n ...payload,\n senderPeerId: this.#peerId,\n recipientPeerId: this.#serverPeerId,\n };\n }\n return {\n ...payload,\n senderPeerId: this.#peerId,\n recipientPeerId: this.#serverPeerId,\n };\n }\n\n /**\n * Receive a message from the server. If a handler is registered for the message's requestId, complete it and remove; else noop.\n */\n handleMessage(message: ProtocolMessage): Effect.Effect<void, never, never> {\n const requestId = 'requestId' in message && message.requestId != null ? String(message.requestId) : undefined;\n if (requestId == null) {\n log.trace('feed sync client response ignored (no request id)', {\n tag: message._tag,\n senderPeerId: message.senderPeerId,\n });\n return Effect.void;\n }\n const deferred = this.#handlers.get(requestId);\n if (deferred == null) {\n log.trace('feed sync client response ignored (no pending rpc)', {\n requestId,\n tag: message._tag,\n senderPeerId: message.senderPeerId,\n });\n return Effect.void;\n }\n this.#handlers.delete(requestId);\n log('feed sync client rpc completed', {\n requestId,\n tag: message._tag,\n blockCount: 'blocks' in message ? message.blocks.length : undefined,\n positionCount: 'positions' in message ? message.positions.length : undefined,\n error: message._tag === 'Error' ? message.message : undefined,\n });\n if (message._tag === 'Error') {\n return Effect.andThen(Deferred.fail(deferred, new Error(message.message)), () => Effect.void);\n }\n return Effect.andThen(Deferred.succeed(deferred, message), () => Effect.void);\n }\n\n pull(\n ctx: Context,\n opts: {\n spaceId: SpaceId;\n feedNamespace: string;\n limit?: number;\n },\n ): Effect.Effect<{ done: boolean }, unknown, SqlClient.SqlClient | SqlTransaction.SqlTransaction> {\n const self = this;\n return Effect.gen(function* () {\n const lastPulledPosition = yield* self.#feedStore.getSyncState({\n spaceId: opts.spaceId,\n feedNamespace: opts.feedNamespace,\n });\n const requestId = crypto.randomUUID();\n const deferred = yield* Deferred.make<ProtocolMessage, Error>();\n self.#handlers.set(requestId, deferred);\n const cleanupDispose = ctx.disposed\n ? () => {}\n : ctx.onDispose(() => {\n Effect.runFork(Deferred.fail(deferred, new ContextDisposedError()));\n });\n if (ctx.disposed) {\n yield* Deferred.fail(deferred, new ContextDisposedError());\n }\n const request: RequestPayload = {\n _tag: 'QueryRequest',\n requestId,\n spaceId: opts.spaceId,\n feedNamespace: opts.feedNamespace,\n position: lastPulledPosition,\n limit: opts.limit,\n };\n log('feed sync client pull rpc sending', {\n requestId,\n spaceId: opts.spaceId,\n feedNamespace: opts.feedNamespace,\n afterPosition: lastPulledPosition,\n limit: opts.limit,\n });\n yield* self.#sendMessage(ctx, self.#withPeerIds(request));\n const message = yield* Effect.ensuring(\n Deferred.await(deferred),\n Effect.sync(() => {\n cleanupDispose();\n self.#handlers.delete(requestId);\n }),\n );\n const response = yield* self.#expectResponse<QueryResponse>(requestId, message, 'QueryResponse');\n if (response.blocks.length === 0) {\n log.trace('feed sync client pull done (empty batch)', {\n requestId,\n spaceId: opts.spaceId,\n feedNamespace: opts.feedNamespace,\n });\n return { done: true };\n }\n yield* self.#feedStore.append({\n spaceId: opts.spaceId,\n feedNamespace: opts.feedNamespace,\n blocks: response.blocks,\n });\n\n // Update sync state with the max position from the pulled batch.\n const maxPulledPosition = response.blocks.reduce(\n (max, block) => (block.position != null && block.position > max ? block.position : max),\n lastPulledPosition,\n );\n yield* self.#feedStore.setSyncState({\n spaceId: opts.spaceId,\n feedNamespace: opts.feedNamespace,\n lastPulledPosition: maxPulledPosition,\n });\n\n log('feed sync client pull applied batch', {\n requestId,\n spaceId: opts.spaceId,\n feedNamespace: opts.feedNamespace,\n batchSize: response.blocks.length,\n hasMore: response.hasMore,\n maxPulledPosition,\n });\n return { done: false };\n });\n }\n\n push(\n ctx: Context,\n opts: {\n spaceId: SpaceId;\n feedNamespace: string;\n limit?: number;\n },\n ): Effect.Effect<{ done: boolean }, unknown, SqlClient.SqlClient | SqlTransaction.SqlTransaction> {\n const self = this;\n return Effect.gen(function* () {\n const unpositioned = yield* self.#feedStore.query({\n spaceId: opts.spaceId,\n feedNamespace: opts.feedNamespace,\n unpositionedOnly: true,\n limit: opts.limit,\n });\n if (unpositioned.blocks.length === 0) {\n log.trace('feed sync client push skipped (nothing to send)', {\n spaceId: opts.spaceId,\n feedNamespace: opts.feedNamespace,\n });\n return { done: true };\n }\n const requestId = crypto.randomUUID();\n const deferred = yield* Deferred.make<ProtocolMessage, Error>();\n self.#handlers.set(requestId, deferred);\n const cleanupDispose = ctx.disposed\n ? () => {}\n : ctx.onDispose(() => {\n Effect.runFork(Deferred.fail(deferred, new ContextDisposedError()));\n });\n if (ctx.disposed) {\n yield* Deferred.fail(deferred, new ContextDisposedError());\n }\n const request: RequestPayload = {\n _tag: 'AppendRequest',\n requestId,\n spaceId: opts.spaceId,\n feedNamespace: opts.feedNamespace,\n blocks: unpositioned.blocks,\n };\n log('feed sync client push rpc sending', {\n requestId,\n spaceId: opts.spaceId,\n feedNamespace: opts.feedNamespace,\n blockCount: unpositioned.blocks.length,\n });\n yield* self.#sendMessage(ctx, self.#withPeerIds(request));\n const message = yield* Effect.ensuring(\n Deferred.await(deferred),\n Effect.sync(() => {\n cleanupDispose();\n self.#handlers.delete(requestId);\n }),\n );\n const response = yield* self.#expectResponse<AppendResponse>(requestId, message, 'AppendResponse');\n yield* self.#feedStore.setPosition({\n spaceId: opts.spaceId,\n blocks: Array.zipWith(response.positions, unpositioned.blocks, (position, block) => ({\n feedId: block.feedId,\n feedNamespace: opts.feedNamespace,\n actorId: block.actorId,\n sequence: block.sequence,\n position,\n })),\n });\n log('feed sync client push positions applied', {\n requestId,\n spaceId: opts.spaceId,\n feedNamespace: opts.feedNamespace,\n positionCount: response.positions.length,\n });\n return { done: false };\n });\n }\n\n #expectResponse<T>(requestId: string, message: ProtocolMessage, expectedTag: string): Effect.Effect<T, Error, never> {\n if (message._tag === 'Error') {\n return Effect.fail(new Error(message.message));\n }\n const requestIdMsg = 'requestId' in message ? String(message.requestId) : undefined;\n if (message._tag !== expectedTag || requestIdMsg !== requestId) {\n return Effect.fail(new Error(`Unexpected message: expected ${expectedTag} with requestId ${requestId}`));\n }\n return Effect.succeed(message as T);\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,iBAAiB;AAEnB,IAAMC,wBAAN,cAAoCD,UAAUE,OAAO,uBAAA,EAAA;EAC1D,YAAYC,MAMT;AACD,UAAM;MACJC,SAAS,8BAA8BD,KAAKE,eAAe,mBAAmBF,KAAKG,iBAAiB,YAAYH,KAAKI,MAAM,YAAYJ,KAAKK,OAAO,aAAaL,KAAKM,QAAQ;MAC7KC,SAASP;IACX,CAAA;EACF;AACF;;;ACfA,YAAYQ,eAAe;AAE3B,YAAYC,YAAY;AAExB,SAASC,aAAa;AACtB,SAASC,sBAAsB;AAE/B,SAASC,oBAAoB;AAC7B,SAASC,sBAAsB;AAO/B,IAAMC,aAAaC,aAAaD;AAEhC,IAAME,uBAAuBD,aAAaC;AAuBnC,IAAMC,YAAN,MAAMA;EACF;EAET,YAAYC,SAA2B;AACrC,SAAK,WAAWA;EAClB;;;;EAKSC,cAAc,IAAIC,MAAAA;;;;EAK3BC,UAAiBC,UAAG,mBAAA,EAAqB,MAChCC,WAAI,aAAA;AACT,UAAMC,MAAM,OAAiBC;AAG7B,WAA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CAAA,CAAA;YACEJ,WAASC,OAAKD,KAAO,gBAAA,WAAA,SAAA,gBAAA;aACrBe,KAAQxC,WAAM+C,YAAiBC;iBAC7BC,KAAAA;gBACAtB,cAAAA,SAAoBA,WAAa,aAAA,QAAA,CAAA,UAAA,WAAA;UACjCuB,QAAAA,MAASC;UACTC,eAAUD,KAAMC;UAChBjB,SAAAA,MAAAA;UACF,UAAA,MAAA;UACF;QACI,EAAA;;WAEFV,2CAAqB;QACrBE;QACAV,SAAAA,KAAAA;QACF,eAAA,KAAA;QACA,eAAO,SAAA,UAAA;uBAAQ,YAAA,GAAAZ,eAAA,GAAA,KAAA,GAAA,KAAA,CAAA;AAAM,aAAA;QACvB,MAAA;MACF;IAEA,CAAA;;kBAEWH,WAAY,SAAImD,aAAczC;AACvC,QAAA,QAAA,SAAA,SAAA;AACA,aAAM0C,aAAe,IAAA,MAAA,QAAe1C,OAAU2C,CAAAA;IAC9C;UACE,eAActB,eAAgB,UAAA,OAAA,QAAA,SAA+BuB,IAAAA;AAC/D,QAAA,QAAA,SAAA,eAAA,iBAAA,WAAA;AACA,aAAclC,aAAQV,IAAAA,MAAAA,gCAAAA,WAAAA,mBAAAA,SAAAA,EAAAA,CAAAA;IACxB;AACF,WAAA,gBAAA,OAAA;;;",
|
|
6
|
+
"names": ["BaseError", "PositionConflictError", "extend", "args", "message", "currentPosition", "requestedPosition", "feedId", "actorId", "sequence", "context", "SqlClient", "Effect", "Event", "assertArgument", "FeedProtocol", "SqlTransaction", "FeedCursor", "FeedProtocol", "isWellKnownNamespace", "FeedStore", "options", "onNewBlocks", "Event", "migrate", "fn", "gen", "sql", "SqlClient", "pipe", "withSpan", "spaceId", "feedId", "namespace", "rows", "length", "feedPrivateId", "newRows", "token", "crypto", "randomUUID", "replace", "slice", "query", "request", "feedIds", "cursorInsertionId", "cursorToken", "die", "Error", "position", "undefined", "cursor", "unpositionedOnly", "insertionId", "decodeCursor", "isNaN", "validCursorToken", "subscriptionId", "feedPrivateIds", "expiresAt", "Date", "now", "privateIds", "JSON", "parse", "feedRows", "in", "map", "r", "requestId", "blocks", "nextCursor", "encodeCursor", "hasMore", "feedNamespace", "filter", "orderBy", "requestLimit", "limit", "queryLimit", "row", "data", "Uint8Array", "lastBlock", "subscribe", "ttl", "forEach", "concurrency", "stringify", "getSyncState", "opts", "lastPulledPosition", "setSyncState", "countBlocks", "count", "deleteOldestBlocks", "deletedRows", "append", "assertArgument", "block", "sqlTransaction", "SqlTransaction", "positions", "withTransaction", "feedKeys", "Map", "key", "has", "set", "entries", "id", "maxPositions", "assignPositions", "maxPosResult", "maxPos", "get", "positionToInsert", "currentMax", "push", "sequence", "actorId", "prevSequence", "prevActorId", "timestamp", "emit", "appendLocal", "messages", "msg", "lastSeqs", "lastBlockResult", "currentSeqs", "blocksBySpaceNamespace", "inFlight", "localActorId", "spaceNamespaceKey", "positionByBlock", "batchBlocks", "values", "i", "setPosition", "updated", "existing", "current", "fail", "PositionConflictError", "currentPosition", "requestedPosition", "getAllFeedsForSpace", "feeds", "result", "feed", "make", "split", "Number", "Effect", "log", "inboundSummary", "message", "senderPeerId", "recipientPeerId", "requestId", "spaceId", "feedNamespace", "blockCount", "length", "position", "undefined", "limit", "options", "peerId", "self", "withPeerIds", "payload", "response", "req", "returnedBlocks", "hasMore", "cause", "err", "ctx", "Error", "assignedPositions", "tag", "void", "Array", "Deferred", "Effect", "ContextDisposedError", "log", "__dxlog_file", "options", "sendMessage", "payload", "senderPeerId", "recipientPeerId", "requestId", "message", "_tag", "tag", "delete", "blockCount", "positionCount", "error", "undefined", "deferred", "andThen", "succeed", "pull", "lastPulledPosition", "spaceId", "opts", "feedNamespace", "crypto", "self", "cleanupDispose", "disposed", "runFork", "fail", "ctx", "position", "limit", "afterPosition", "await", "response", "blocks", "batchSize", "hasMore", "maxPulledPosition", "push", "unpositioned", "unpositionedOnly", "zipWith", "positions", "feedId", "actorId", "block", "sequence", "Error", "requestIdMsg", "String", "expectedTag"]
|
|
7
|
+
}
|