@smthrs/sync 0.0.0-stage → 1.0.0-rc.4
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/CHANGELOG.md +208 -0
- package/LICENSE +21 -0
- package/README.md +208 -2
- package/dist/cjs/BranchCommands.d.ts +228 -0
- package/dist/cjs/BranchCommands.d.ts.map +1 -0
- package/dist/cjs/BranchCommands.js +316 -0
- package/dist/cjs/BranchCommands.js.map +7 -0
- package/dist/cjs/BranchIds.d.ts +65 -0
- package/dist/cjs/BranchIds.d.ts.map +1 -0
- package/dist/cjs/BranchIds.js +53 -0
- package/dist/cjs/BranchIds.js.map +7 -0
- package/dist/cjs/BranchPresence.d.ts +195 -0
- package/dist/cjs/BranchPresence.d.ts.map +1 -0
- package/dist/cjs/BranchPresence.js +276 -0
- package/dist/cjs/BranchPresence.js.map +7 -0
- package/dist/cjs/BranchProjection.d.ts +179 -0
- package/dist/cjs/BranchProjection.d.ts.map +1 -0
- package/dist/cjs/BranchProjection.js +197 -0
- package/dist/cjs/BranchProjection.js.map +7 -0
- package/dist/cjs/BranchProtocol.d.ts +415 -0
- package/dist/cjs/BranchProtocol.d.ts.map +1 -0
- package/dist/cjs/BranchProtocol.js +172 -0
- package/dist/cjs/BranchProtocol.js.map +7 -0
- package/dist/cjs/BranchRpcs.d.ts +177 -0
- package/dist/cjs/BranchRpcs.d.ts.map +1 -0
- package/dist/cjs/BranchRpcs.js +85 -0
- package/dist/cjs/BranchRpcs.js.map +7 -0
- package/dist/cjs/BranchServer.d.ts +55 -0
- package/dist/cjs/BranchServer.d.ts.map +1 -0
- package/dist/cjs/BranchServer.js +147 -0
- package/dist/cjs/BranchServer.js.map +7 -0
- package/dist/cjs/BranchShare.d.ts +159 -0
- package/dist/cjs/BranchShare.d.ts.map +1 -0
- package/dist/cjs/BranchShare.js +147 -0
- package/dist/cjs/BranchShare.js.map +7 -0
- package/dist/cjs/RunCatalog.d.ts +207 -0
- package/dist/cjs/RunCatalog.d.ts.map +1 -0
- package/dist/cjs/RunCatalog.js +122 -0
- package/dist/cjs/RunCatalog.js.map +7 -0
- package/dist/cjs/SyncAuth.d.ts +70 -0
- package/dist/cjs/SyncAuth.d.ts.map +1 -0
- package/dist/cjs/SyncAuth.js +109 -0
- package/dist/cjs/SyncAuth.js.map +7 -0
- package/dist/cjs/SyncClient.d.ts +274 -0
- package/dist/cjs/SyncClient.d.ts.map +1 -0
- package/dist/cjs/SyncClient.js +474 -0
- package/dist/cjs/SyncClient.js.map +7 -0
- package/dist/cjs/SyncError.d.ts +107 -0
- package/dist/cjs/SyncError.d.ts.map +1 -0
- package/dist/cjs/SyncError.js +110 -0
- package/dist/cjs/SyncError.js.map +7 -0
- package/dist/cjs/SyncPrincipal.d.ts +100 -0
- package/dist/cjs/SyncPrincipal.d.ts.map +1 -0
- package/dist/cjs/SyncPrincipal.js +48 -0
- package/dist/cjs/SyncPrincipal.js.map +7 -0
- package/dist/cjs/SyncProtocol.d.ts +592 -0
- package/dist/cjs/SyncProtocol.d.ts.map +1 -0
- package/dist/cjs/SyncProtocol.js +165 -0
- package/dist/cjs/SyncProtocol.js.map +7 -0
- package/dist/cjs/SyncRpcs.d.ts +92 -0
- package/dist/cjs/SyncRpcs.d.ts.map +1 -0
- package/dist/cjs/SyncRpcs.js +35 -0
- package/dist/cjs/SyncRpcs.js.map +7 -0
- package/dist/cjs/SyncServer.d.ts +184 -0
- package/dist/cjs/SyncServer.d.ts.map +1 -0
- package/dist/cjs/SyncServer.js +513 -0
- package/dist/cjs/SyncServer.js.map +7 -0
- package/dist/cjs/WorkspaceShare.d.ts +174 -0
- package/dist/cjs/WorkspaceShare.d.ts.map +1 -0
- package/dist/cjs/WorkspaceShare.js +149 -0
- package/dist/cjs/WorkspaceShare.js.map +7 -0
- package/dist/cjs/index.d.ts +91 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +67 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/internal/Admission.d.ts +43 -0
- package/dist/cjs/internal/Admission.d.ts.map +1 -0
- package/dist/cjs/internal/Admission.js +90 -0
- package/dist/cjs/internal/Admission.js.map +7 -0
- package/dist/cjs/internal/CauseText.d.ts +55 -0
- package/dist/cjs/internal/CauseText.d.ts.map +1 -0
- package/dist/cjs/internal/CauseText.js +38 -0
- package/dist/cjs/internal/CauseText.js.map +7 -0
- package/dist/cjs/internal/JournalErrorCode.d.ts +23 -0
- package/dist/cjs/internal/JournalErrorCode.d.ts.map +1 -0
- package/dist/cjs/internal/JournalErrorCode.js +34 -0
- package/dist/cjs/internal/JournalErrorCode.js.map +7 -0
- package/dist/cjs/internal/PolicyOptions.d.ts +57 -0
- package/dist/cjs/internal/PolicyOptions.d.ts.map +1 -0
- package/dist/cjs/internal/PolicyOptions.js +62 -0
- package/dist/cjs/internal/PolicyOptions.js.map +7 -0
- package/dist/cjs/internal/ProtocolVersion.d.ts +17 -0
- package/dist/cjs/internal/ProtocolVersion.d.ts.map +1 -0
- package/dist/cjs/internal/ProtocolVersion.js +44 -0
- package/dist/cjs/internal/ProtocolVersion.js.map +7 -0
- package/dist/cjs/internal/ShareSigner.d.ts +173 -0
- package/dist/cjs/internal/ShareSigner.d.ts.map +1 -0
- package/dist/cjs/internal/ShareSigner.js +150 -0
- package/dist/cjs/internal/ShareSigner.js.map +7 -0
- package/dist/cjs/internal/SnapshotBoundary.d.ts +17 -0
- package/dist/cjs/internal/SnapshotBoundary.d.ts.map +1 -0
- package/dist/cjs/internal/SnapshotBoundary.js +97 -0
- package/dist/cjs/internal/SnapshotBoundary.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/test/TestSocket.d.ts +55 -0
- package/dist/cjs/test/TestSocket.d.ts.map +1 -0
- package/dist/cjs/test/TestSocket.js +145 -0
- package/dist/cjs/test/TestSocket.js.map +7 -0
- package/dist/cjs/test/TestSync.d.ts +54 -0
- package/dist/cjs/test/TestSync.d.ts.map +1 -0
- package/dist/cjs/test/TestSync.js +96 -0
- package/dist/cjs/test/TestSync.js.map +7 -0
- package/dist/esm/BranchCommands.d.ts +228 -0
- package/dist/esm/BranchCommands.d.ts.map +1 -0
- package/dist/esm/BranchCommands.js +496 -0
- package/dist/esm/BranchCommands.js.map +1 -0
- package/dist/esm/BranchIds.d.ts +65 -0
- package/dist/esm/BranchIds.d.ts.map +1 -0
- package/dist/esm/BranchIds.js +61 -0
- package/dist/esm/BranchIds.js.map +1 -0
- package/dist/esm/BranchPresence.d.ts +195 -0
- package/dist/esm/BranchPresence.d.ts.map +1 -0
- package/dist/esm/BranchPresence.js +361 -0
- package/dist/esm/BranchPresence.js.map +1 -0
- package/dist/esm/BranchProjection.d.ts +179 -0
- package/dist/esm/BranchProjection.d.ts.map +1 -0
- package/dist/esm/BranchProjection.js +269 -0
- package/dist/esm/BranchProjection.js.map +1 -0
- package/dist/esm/BranchProtocol.d.ts +415 -0
- package/dist/esm/BranchProtocol.d.ts.map +1 -0
- package/dist/esm/BranchProtocol.js +323 -0
- package/dist/esm/BranchProtocol.js.map +1 -0
- package/dist/esm/BranchRpcs.d.ts +177 -0
- package/dist/esm/BranchRpcs.d.ts.map +1 -0
- package/dist/esm/BranchRpcs.js +103 -0
- package/dist/esm/BranchRpcs.js.map +1 -0
- package/dist/esm/BranchServer.d.ts +55 -0
- package/dist/esm/BranchServer.d.ts.map +1 -0
- package/dist/esm/BranchServer.js +168 -0
- package/dist/esm/BranchServer.js.map +1 -0
- package/dist/esm/BranchShare.d.ts +159 -0
- package/dist/esm/BranchShare.d.ts.map +1 -0
- package/dist/esm/BranchShare.js +213 -0
- package/dist/esm/BranchShare.js.map +1 -0
- package/dist/esm/RunCatalog.d.ts +207 -0
- package/dist/esm/RunCatalog.d.ts.map +1 -0
- package/dist/esm/RunCatalog.js +196 -0
- package/dist/esm/RunCatalog.js.map +1 -0
- package/dist/esm/SyncAuth.d.ts +70 -0
- package/dist/esm/SyncAuth.d.ts.map +1 -0
- package/dist/esm/SyncAuth.js +119 -0
- package/dist/esm/SyncAuth.js.map +1 -0
- package/dist/esm/SyncClient.d.ts +274 -0
- package/dist/esm/SyncClient.d.ts.map +1 -0
- package/dist/esm/SyncClient.js +586 -0
- package/dist/esm/SyncClient.js.map +1 -0
- package/dist/esm/SyncError.d.ts +107 -0
- package/dist/esm/SyncError.d.ts.map +1 -0
- package/dist/esm/SyncError.js +133 -0
- package/dist/esm/SyncError.js.map +1 -0
- package/dist/esm/SyncPrincipal.d.ts +100 -0
- package/dist/esm/SyncPrincipal.d.ts.map +1 -0
- package/dist/esm/SyncPrincipal.js +58 -0
- package/dist/esm/SyncPrincipal.js.map +1 -0
- package/dist/esm/SyncProtocol.d.ts +592 -0
- package/dist/esm/SyncProtocol.d.ts.map +1 -0
- package/dist/esm/SyncProtocol.js +434 -0
- package/dist/esm/SyncProtocol.js.map +1 -0
- package/dist/esm/SyncRpcs.d.ts +92 -0
- package/dist/esm/SyncRpcs.d.ts.map +1 -0
- package/dist/esm/SyncRpcs.js +35 -0
- package/dist/esm/SyncRpcs.js.map +1 -0
- package/dist/esm/SyncServer.d.ts +184 -0
- package/dist/esm/SyncServer.d.ts.map +1 -0
- package/dist/esm/SyncServer.js +897 -0
- package/dist/esm/SyncServer.js.map +1 -0
- package/dist/esm/WorkspaceShare.d.ts +174 -0
- package/dist/esm/WorkspaceShare.d.ts.map +1 -0
- package/dist/esm/WorkspaceShare.js +208 -0
- package/dist/esm/WorkspaceShare.js.map +1 -0
- package/dist/esm/index.d.ts +91 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +91 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal/Admission.d.ts +43 -0
- package/dist/esm/internal/Admission.d.ts.map +1 -0
- package/dist/esm/internal/Admission.js +80 -0
- package/dist/esm/internal/Admission.js.map +1 -0
- package/dist/esm/internal/CauseText.d.ts +55 -0
- package/dist/esm/internal/CauseText.d.ts.map +1 -0
- package/dist/esm/internal/CauseText.js +67 -0
- package/dist/esm/internal/CauseText.js.map +1 -0
- package/dist/esm/internal/JournalErrorCode.d.ts +23 -0
- package/dist/esm/internal/JournalErrorCode.d.ts.map +1 -0
- package/dist/esm/internal/JournalErrorCode.js +44 -0
- package/dist/esm/internal/JournalErrorCode.js.map +1 -0
- package/dist/esm/internal/PolicyOptions.d.ts +57 -0
- package/dist/esm/internal/PolicyOptions.d.ts.map +1 -0
- package/dist/esm/internal/PolicyOptions.js +70 -0
- package/dist/esm/internal/PolicyOptions.js.map +1 -0
- package/dist/esm/internal/ProtocolVersion.d.ts +17 -0
- package/dist/esm/internal/ProtocolVersion.d.ts.map +1 -0
- package/dist/esm/internal/ProtocolVersion.js +24 -0
- package/dist/esm/internal/ProtocolVersion.js.map +1 -0
- package/dist/esm/internal/ShareSigner.d.ts +173 -0
- package/dist/esm/internal/ShareSigner.d.ts.map +1 -0
- package/dist/esm/internal/ShareSigner.js +219 -0
- package/dist/esm/internal/ShareSigner.js.map +1 -0
- package/dist/esm/internal/SnapshotBoundary.d.ts +17 -0
- package/dist/esm/internal/SnapshotBoundary.d.ts.map +1 -0
- package/dist/esm/internal/SnapshotBoundary.js +68 -0
- package/dist/esm/internal/SnapshotBoundary.js.map +1 -0
- package/dist/esm/test/TestSocket.d.ts +55 -0
- package/dist/esm/test/TestSocket.d.ts.map +1 -0
- package/dist/esm/test/TestSocket.js +128 -0
- package/dist/esm/test/TestSocket.js.map +1 -0
- package/dist/esm/test/TestSync.d.ts +54 -0
- package/dist/esm/test/TestSync.d.ts.map +1 -0
- package/dist/esm/test/TestSync.js +76 -0
- package/dist/esm/test/TestSync.js.map +1 -0
- package/docs/README.md +156 -0
- package/docs/api.md +328 -0
- package/docs/concepts/authorization.md +117 -0
- package/docs/concepts/branches.md +195 -0
- package/docs/concepts/compaction.md +144 -0
- package/docs/concepts/replay-then-follow.md +129 -0
- package/docs/concepts/scopes-and-cursors.md +135 -0
- package/docs/guides/authorize-a-connection.md +174 -0
- package/docs/guides/follow-a-run.md +174 -0
- package/docs/guides/handle-a-compacted-run.md +158 -0
- package/docs/guides/list-workspace-runs.md +120 -0
- package/docs/guides/run-a-long-soak.md +80 -0
- package/docs/guides/serve-the-read-path.md +146 -0
- package/docs/guides/test-a-follower.md +273 -0
- package/docs/installation.md +92 -0
- package/docs/protocol.md +183 -0
- package/docs/quickstart.md +159 -0
- package/docs/troubleshooting.md +234 -0
- package/package.json +304 -3
- package/src/BranchCommands.ts +684 -0
- package/src/BranchIds.ts +76 -0
- package/src/BranchPresence.ts +512 -0
- package/src/BranchProjection.ts +308 -0
- package/src/BranchProtocol.ts +411 -0
- package/src/BranchRpcs.ts +163 -0
- package/src/BranchServer.ts +202 -0
- package/src/BranchShare.ts +297 -0
- package/src/RunCatalog.ts +308 -0
- package/src/SyncAuth.ts +146 -0
- package/src/SyncClient.ts +902 -0
- package/src/SyncError.ts +147 -0
- package/src/SyncPrincipal.ts +115 -0
- package/src/SyncProtocol.ts +594 -0
- package/src/SyncRpcs.ts +40 -0
- package/src/SyncServer.ts +1184 -0
- package/src/WorkspaceShare.ts +292 -0
- package/src/index.ts +107 -0
- package/src/internal/Admission.ts +119 -0
- package/src/internal/CauseText.ts +74 -0
- package/src/internal/JournalErrorCode.ts +46 -0
- package/src/internal/PolicyOptions.ts +97 -0
- package/src/internal/ProtocolVersion.ts +28 -0
- package/src/internal/ShareSigner.ts +300 -0
- package/src/internal/SnapshotBoundary.ts +91 -0
- package/src/test/TestSocket.ts +192 -0
- package/src/test/TestSync.ts +113 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ephemeral presence and cursors for one shared branch.
|
|
3
|
+
*
|
|
4
|
+
* Presence is deliberately NOT journalled. A roster is a lease table: every
|
|
5
|
+
* announcement extends a lease, and a participant that stops announcing —
|
|
6
|
+
* because the tab closed, the network dropped, or the process died — ages out
|
|
7
|
+
* without anyone reporting the disconnect. Writing presence to the journal
|
|
8
|
+
* would make "who was looking at this" part of the durable, replayable history
|
|
9
|
+
* of a run, which is both unbounded and wrong: replaying a branch must not
|
|
10
|
+
* resurrect a stranger's caret.
|
|
11
|
+
*
|
|
12
|
+
* Every operation authorizes through {@link BranchShare}, so a capability for
|
|
13
|
+
* one branch can neither read nor write another branch's roster. A live
|
|
14
|
+
* participant is bound to the capability that announced it: announcing or
|
|
15
|
+
* leaving under that `participantId` with any other capability is refused
|
|
16
|
+
* with `unauthorized` until the lease lapses.
|
|
17
|
+
*
|
|
18
|
+
* @since 0.1.0
|
|
19
|
+
*/
|
|
20
|
+
import * as Context from "effect/Context";
|
|
21
|
+
import * as Effect from "effect/Effect";
|
|
22
|
+
import * as Layer from "effect/Layer";
|
|
23
|
+
import * as Stream from "effect/Stream";
|
|
24
|
+
import { type Announcement, type BranchId, type LeaveRequest, Participant, type RosterRequest } from "./BranchProtocol.ts";
|
|
25
|
+
import * as BranchShare from "./BranchShare.ts";
|
|
26
|
+
import { SyncError } from "./SyncError.ts";
|
|
27
|
+
/**
|
|
28
|
+
* Ephemeral branch presence operations.
|
|
29
|
+
*
|
|
30
|
+
* @category models
|
|
31
|
+
* @since 0.1.0
|
|
32
|
+
*/
|
|
33
|
+
export interface Service {
|
|
34
|
+
readonly announce: (announcement: Announcement) => Effect.Effect<Participant, SyncError>;
|
|
35
|
+
readonly leave: (request: LeaveRequest) => Effect.Effect<void, SyncError>;
|
|
36
|
+
/**
|
|
37
|
+
* One branch's live roster, as a fresh array of detached participants and
|
|
38
|
+
* cursors. Reading drops expired leases and advances a cross-branch sweep.
|
|
39
|
+
*/
|
|
40
|
+
readonly list: (request: RosterRequest) => Effect.Effect<ReadonlyArray<Participant>, SyncError>;
|
|
41
|
+
/**
|
|
42
|
+
* Returns `unknown` for one lease after host startup or while a required
|
|
43
|
+
* heartbeat source is unavailable; otherwise reports `present` or `empty`.
|
|
44
|
+
*
|
|
45
|
+
* @since 1.0.0
|
|
46
|
+
*/
|
|
47
|
+
readonly presenceOn: (request: RosterRequest) => Effect.Effect<"unknown" | "present" | "empty", SyncError>;
|
|
48
|
+
readonly changes: Stream.Stream<BranchId>;
|
|
49
|
+
/**
|
|
50
|
+
* How long one announcement keeps a participant on the roster, in
|
|
51
|
+
* milliseconds.
|
|
52
|
+
*
|
|
53
|
+
* A lease lapses without anyone reporting it, and nothing publishes on
|
|
54
|
+
* `changes` when it does, so a watcher cannot learn of the last
|
|
55
|
+
* participant's departure from the change feed alone. It re-lists on this
|
|
56
|
+
* cadence capped at one second, bounding how long an expired lease stays visible.
|
|
57
|
+
*/
|
|
58
|
+
readonly leaseMs: number;
|
|
59
|
+
}
|
|
60
|
+
declare const BranchPresence_base: Context.ServiceClass<BranchPresence, "@smthrs/sync/BranchPresence", Service>;
|
|
61
|
+
/**
|
|
62
|
+
* The branch presence registry.
|
|
63
|
+
*
|
|
64
|
+
* @category services
|
|
65
|
+
* @since 0.1.0
|
|
66
|
+
*/
|
|
67
|
+
export declare class BranchPresence extends BranchPresence_base {
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The lease {@link makeNoop} reports. It holds no one, so the value only has
|
|
71
|
+
* to be a positive number a watcher can build a re-list cadence from.
|
|
72
|
+
*
|
|
73
|
+
* @category constants
|
|
74
|
+
* @since 1.0.0-rc.0
|
|
75
|
+
*/
|
|
76
|
+
export declare const defaultLeaseMs = 30000;
|
|
77
|
+
/**
|
|
78
|
+
* Constructs an unavailable presence registry.
|
|
79
|
+
*
|
|
80
|
+
* @category constructors
|
|
81
|
+
* @since 0.1.0
|
|
82
|
+
*/
|
|
83
|
+
export declare const makeNoop: (overrides?: Partial<Service>) => Service;
|
|
84
|
+
/**
|
|
85
|
+
* Provides an unavailable presence registry.
|
|
86
|
+
*
|
|
87
|
+
* @category layers
|
|
88
|
+
* @since 0.1.0
|
|
89
|
+
*/
|
|
90
|
+
export declare const layerNoop: Layer.Layer<BranchPresence>;
|
|
91
|
+
/**
|
|
92
|
+
* The policy one presence registry runs under. Every field defaults, and
|
|
93
|
+
* {@link makeMemory} and {@link layerWith} validate what a caller supplies.
|
|
94
|
+
*
|
|
95
|
+
* @category models
|
|
96
|
+
* @since 0.1.0
|
|
97
|
+
*/
|
|
98
|
+
export interface PresenceOptions {
|
|
99
|
+
/**
|
|
100
|
+
* How long an announcement keeps a participant on the roster, in
|
|
101
|
+
* milliseconds. Defaults to {@link defaultLeaseMs}.
|
|
102
|
+
*/
|
|
103
|
+
readonly leaseMs?: number | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Roster changes a stalled {@link Service.changes} subscriber may fall
|
|
106
|
+
* behind by. Defaults to {@link defaultChangesCapacity}.
|
|
107
|
+
*/
|
|
108
|
+
readonly changesCapacity?: number | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Participants one branch may hold at once. Defaults to
|
|
111
|
+
* {@link defaultMaxParticipants}.
|
|
112
|
+
*/
|
|
113
|
+
readonly maxParticipants?: number | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Host readiness, including authorization, revocation, bridge and session
|
|
116
|
+
* sources. Defaults to unavailable.
|
|
117
|
+
*
|
|
118
|
+
* @since 1.0.0
|
|
119
|
+
*/
|
|
120
|
+
readonly sourcesReady?: ((branchId: BranchId) => Effect.Effect<boolean>) | undefined;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Roster changes a stalled {@link Service.changes} subscriber may fall behind
|
|
124
|
+
* by before the oldest are dropped.
|
|
125
|
+
*
|
|
126
|
+
* Presence is a lease table, and `changes` only says that some branch's roster
|
|
127
|
+
* moved: a follower answers it with `list`. Holding an unbounded backlog for a
|
|
128
|
+
* subscriber that has stopped pulling would let one abandoned watcher retain
|
|
129
|
+
* every announcement the process has seen since. A subscriber that falls
|
|
130
|
+
* further behind than this bound loses the oldest notifications and re-lists;
|
|
131
|
+
* because every notification is answered by a fresh `list`, dropping one never
|
|
132
|
+
* loses roster state.
|
|
133
|
+
*
|
|
134
|
+
* @category constants
|
|
135
|
+
* @since 0.1.0
|
|
136
|
+
*/
|
|
137
|
+
export declare const defaultChangesCapacity = 256;
|
|
138
|
+
/**
|
|
139
|
+
* Participants one branch may hold at once.
|
|
140
|
+
*
|
|
141
|
+
* A roster is unbounded fan-out in two directions: it is walked on every
|
|
142
|
+
* `list`, and `Branch.Roster` returns it whole, which no frame ceiling covers.
|
|
143
|
+
* Nothing caps how many distinct `participantId`s one write capability may
|
|
144
|
+
* announce, so without this a single share link could pin an arbitrary number
|
|
145
|
+
* of `Participant` objects until their leases expired. Two hundred and fifty
|
|
146
|
+
* six is far above any real collaborative session; a further announce is
|
|
147
|
+
* refused with `backpressure`.
|
|
148
|
+
*
|
|
149
|
+
* @category constants
|
|
150
|
+
* @since 1.0.0-rc.0
|
|
151
|
+
*/
|
|
152
|
+
export declare const defaultMaxParticipants = 256;
|
|
153
|
+
/**
|
|
154
|
+
* Constructs the in-memory, lease-expiring presence registry.
|
|
155
|
+
*
|
|
156
|
+
* Announcing requires write access: a read-only share link may watch the
|
|
157
|
+
* roster but never appears on it, so a shared read link cannot be used to
|
|
158
|
+
* impersonate a collaborator. A live participant belongs to the capability
|
|
159
|
+
* that announced it, so another write link can neither overwrite nor evict it.
|
|
160
|
+
* Holders of one link share its `capabilityId` and stay indistinguishable.
|
|
161
|
+
*
|
|
162
|
+
* The roster is keyed by branch and then by participant, so listing one branch
|
|
163
|
+
* costs that branch plus a bounded sweep of other branches, and no two
|
|
164
|
+
* branches can share a slot. One flat key built by concatenation collided
|
|
165
|
+
* for valid branded ids, which let one announcement overwrite another branch's
|
|
166
|
+
* participant.
|
|
167
|
+
*
|
|
168
|
+
* The change feed slides at {@link defaultChangesCapacity}: announcing never
|
|
169
|
+
* waits on a stalled watcher, and never grows the process on its behalf.
|
|
170
|
+
*
|
|
171
|
+
* Fails with `invalid_request` when an option is not a positive safe integer.
|
|
172
|
+
*
|
|
173
|
+
* @category constructors
|
|
174
|
+
* @since 0.1.0
|
|
175
|
+
*/
|
|
176
|
+
export declare const makeMemory: (options?: PresenceOptions) => Effect.Effect<Service, SyncError, BranchShare.BranchShare>;
|
|
177
|
+
/**
|
|
178
|
+
* Provides the in-memory, lease-expiring presence registry under the default
|
|
179
|
+
* policy, which is valid by construction and so cannot fail.
|
|
180
|
+
*
|
|
181
|
+
* @category layers
|
|
182
|
+
* @since 0.1.0
|
|
183
|
+
*/
|
|
184
|
+
export declare const layer: Layer.Layer<BranchPresence, never, BranchShare.BranchShare>;
|
|
185
|
+
/**
|
|
186
|
+
* Provides the in-memory, lease-expiring presence registry under an explicit
|
|
187
|
+
* policy. Fails with `invalid_request` when an option is not a positive safe
|
|
188
|
+
* integer, so a bad policy fails the composition rather than an announcement.
|
|
189
|
+
*
|
|
190
|
+
* @category layers
|
|
191
|
+
* @since 1.0.0-rc.0
|
|
192
|
+
*/
|
|
193
|
+
export declare const layerWith: (options: PresenceOptions) => Layer.Layer<BranchPresence, SyncError, BranchShare.BranchShare>;
|
|
194
|
+
export {};
|
|
195
|
+
//# sourceMappingURL=BranchPresence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BranchPresence.d.ts","sourceRoot":"","sources":["../../src/BranchPresence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAGrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,QAAQ,EAEb,KAAK,YAAY,EACjB,WAAW,EAGX,KAAK,aAAa,EACnB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,QAAQ,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,MAAM,CAAC,MAAM,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AAQ,EAAE,QAAQ,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAA;CACrF;AA8BD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,sBAAsB,MAAM,CAAA;AAEzC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,sBAAsB,MAAM,CAAA;AASzC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,UAAU,GACrB,UAAS,eAAoB,KAC5B,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,WAAW,CAAC,WAAW,CAgBzD,CAAA;AAqOH;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,EAAE,WAAW,CAAC,WAAW,CAG7E,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,GACpB,SAAS,eAAe,KACvB,KAAK,CAAC,KAAK,CAAC,cAAc,EAAE,SAAS,EAAE,WAAW,CAAC,WAAW,CAAsD,CAAA"}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var BranchPresence_exports = {};
|
|
30
|
+
__export(BranchPresence_exports, {
|
|
31
|
+
BranchPresence: () => BranchPresence,
|
|
32
|
+
defaultChangesCapacity: () => defaultChangesCapacity,
|
|
33
|
+
defaultLeaseMs: () => defaultLeaseMs,
|
|
34
|
+
defaultMaxParticipants: () => defaultMaxParticipants,
|
|
35
|
+
layer: () => layer,
|
|
36
|
+
layerNoop: () => layerNoop,
|
|
37
|
+
layerWith: () => layerWith,
|
|
38
|
+
makeMemory: () => makeMemory,
|
|
39
|
+
makeNoop: () => makeNoop
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(BranchPresence_exports);
|
|
42
|
+
var Clock = __toESM(require("effect/Clock"), 1);
|
|
43
|
+
var Context = __toESM(require("effect/Context"), 1);
|
|
44
|
+
var Effect = __toESM(require("effect/Effect"), 1);
|
|
45
|
+
var Layer = __toESM(require("effect/Layer"), 1);
|
|
46
|
+
var PubSub = __toESM(require("effect/PubSub"), 1);
|
|
47
|
+
var Schema = __toESM(require("effect/Schema"), 1);
|
|
48
|
+
var Stream = __toESM(require("effect/Stream"), 1);
|
|
49
|
+
var import_BranchProtocol = require("./BranchProtocol.js");
|
|
50
|
+
var BranchShare = __toESM(require("./BranchShare.js"), 1);
|
|
51
|
+
var import_PolicyOptions = require("./internal/PolicyOptions.js");
|
|
52
|
+
var import_SyncError = require("./SyncError.js");
|
|
53
|
+
class BranchPresence extends Context.Service()("@smthrs/sync/BranchPresence") {
|
|
54
|
+
}
|
|
55
|
+
const unavailable = new import_SyncError.SyncError({ code: "unsupported", message: "Branch presence is unavailable" });
|
|
56
|
+
const defaultLeaseMs = 3e4;
|
|
57
|
+
const makeNoop = (overrides = {}) => BranchPresence.of({
|
|
58
|
+
announce: () => Effect.fail(unavailable),
|
|
59
|
+
leave: () => Effect.fail(unavailable),
|
|
60
|
+
list: () => Effect.fail(unavailable),
|
|
61
|
+
presenceOn: () => Effect.succeed("unknown"),
|
|
62
|
+
changes: Stream.empty,
|
|
63
|
+
leaseMs: defaultLeaseMs,
|
|
64
|
+
...overrides
|
|
65
|
+
});
|
|
66
|
+
const layerNoop = Layer.succeed(BranchPresence, makeNoop());
|
|
67
|
+
const heldByAnother = (participantId) => new import_SyncError.SyncError({
|
|
68
|
+
code: "unauthorized",
|
|
69
|
+
message: `Participant ${participantId} is held by another share capability`
|
|
70
|
+
});
|
|
71
|
+
const defaultChangesCapacity = 256;
|
|
72
|
+
const defaultMaxParticipants = 256;
|
|
73
|
+
const defaults = {
|
|
74
|
+
leaseMs: defaultLeaseMs,
|
|
75
|
+
changesCapacity: defaultChangesCapacity,
|
|
76
|
+
maxParticipants: defaultMaxParticipants,
|
|
77
|
+
sourcesReady: () => Effect.succeed(false)
|
|
78
|
+
};
|
|
79
|
+
const makeMemory = (options = {}) => Effect.flatMap(
|
|
80
|
+
Effect.all({
|
|
81
|
+
leaseMs: (0, import_PolicyOptions.positiveInt)("BranchPresence.PresenceOptions.leaseMs", options.leaseMs, defaults.leaseMs),
|
|
82
|
+
changesCapacity: (0, import_PolicyOptions.positiveInt)(
|
|
83
|
+
"BranchPresence.PresenceOptions.changesCapacity",
|
|
84
|
+
options.changesCapacity,
|
|
85
|
+
defaults.changesCapacity
|
|
86
|
+
),
|
|
87
|
+
maxParticipants: (0, import_PolicyOptions.positiveInt)(
|
|
88
|
+
"BranchPresence.PresenceOptions.maxParticipants",
|
|
89
|
+
options.maxParticipants,
|
|
90
|
+
defaults.maxParticipants
|
|
91
|
+
)
|
|
92
|
+
}),
|
|
93
|
+
(resolved) => makeResolved({ ...resolved, sourcesReady: options.sourcesReady ?? defaults.sourcesReady })
|
|
94
|
+
);
|
|
95
|
+
const makeResolved = ({ changesCapacity, leaseMs, maxParticipants, sourcesReady }) => Effect.gen(function* () {
|
|
96
|
+
const startedAtMs = yield* Clock.currentTimeMillis;
|
|
97
|
+
const share = yield* BranchShare.BranchShare;
|
|
98
|
+
const roster = /* @__PURE__ */ new Map();
|
|
99
|
+
const changes = yield* PubSub.sliding(changesCapacity);
|
|
100
|
+
const expire = (branchId, nowMs) => {
|
|
101
|
+
const branch = roster.get(branchId);
|
|
102
|
+
if (branch === void 0) return void 0;
|
|
103
|
+
for (const [participantId, seat] of branch) {
|
|
104
|
+
if (seat.participant.leaseExpiresAtMs <= nowMs) branch.delete(participantId);
|
|
105
|
+
}
|
|
106
|
+
if (branch.size === 0) {
|
|
107
|
+
roster.delete(branchId);
|
|
108
|
+
return void 0;
|
|
109
|
+
}
|
|
110
|
+
return branch;
|
|
111
|
+
};
|
|
112
|
+
let sweepCursor = roster.keys();
|
|
113
|
+
const sweep = (nowMs) => {
|
|
114
|
+
for (let index = 0; index < 16; index++) {
|
|
115
|
+
const next = sweepCursor.next();
|
|
116
|
+
if (next.done) {
|
|
117
|
+
sweepCursor = roster.keys();
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
expire(next.value, nowMs);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const seatKey = (request) => JSON.stringify([request.participantId, request.sessionId ?? ""]);
|
|
124
|
+
const copyWhere = (where) => ({ ...where });
|
|
125
|
+
const detach = (participant) => new import_BranchProtocol.Participant({
|
|
126
|
+
...participant,
|
|
127
|
+
...participant.where === void 0 ? {} : { where: copyWhere(participant.where) },
|
|
128
|
+
cursor: participant.cursor === null ? null : new import_BranchProtocol.Cursor(participant.cursor)
|
|
129
|
+
});
|
|
130
|
+
const live = (branchId, nowMs) => {
|
|
131
|
+
sweep(nowMs);
|
|
132
|
+
const branch = expire(branchId, nowMs);
|
|
133
|
+
if (branch === void 0) return [];
|
|
134
|
+
return Array.from(branch.values(), (seat) => detach(seat.participant)).sort(
|
|
135
|
+
(left, right) => seatKey(left) < seatKey(right) ? -1 : 1
|
|
136
|
+
);
|
|
137
|
+
};
|
|
138
|
+
const detachRoster = (request) => ({
|
|
139
|
+
capability: request.capability,
|
|
140
|
+
branchId: request.branchId
|
|
141
|
+
});
|
|
142
|
+
const detachLeave = (request) => ({
|
|
143
|
+
...detachRoster(request),
|
|
144
|
+
participantId: request.participantId,
|
|
145
|
+
...request.sessionId === void 0 ? {} : { sessionId: request.sessionId }
|
|
146
|
+
});
|
|
147
|
+
const detachAnnouncement = (request) => {
|
|
148
|
+
const suppliedCursor = request.cursor;
|
|
149
|
+
const cursor = suppliedCursor === null ? null : typeof suppliedCursor === "object" ? { cardId: suppliedCursor.cardId, offset: suppliedCursor.offset } : { cardId: void 0, offset: void 0 };
|
|
150
|
+
return {
|
|
151
|
+
...detachLeave(request),
|
|
152
|
+
displayName: request.displayName,
|
|
153
|
+
cursor,
|
|
154
|
+
...request.kind === void 0 ? {} : { kind: request.kind },
|
|
155
|
+
...request.where === void 0 ? {} : { where: copyWhere(request.where) },
|
|
156
|
+
...request.watching === void 0 ? {} : { watching: request.watching },
|
|
157
|
+
...request.for_member === void 0 ? {} : { for_member: request.for_member },
|
|
158
|
+
...request.agentKind === void 0 ? {} : { agentKind: request.agentKind },
|
|
159
|
+
...request.via === void 0 ? {} : { via: request.via },
|
|
160
|
+
...request.runId === void 0 ? {} : { runId: request.runId }
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
const announce = Effect.fn("BranchPresence.announce")(function* (supplied) {
|
|
164
|
+
const detached = detachAnnouncement(supplied);
|
|
165
|
+
yield* Effect.annotateCurrentSpan({
|
|
166
|
+
branchId: detached.branchId,
|
|
167
|
+
participantId: detached.participantId
|
|
168
|
+
});
|
|
169
|
+
const claims = yield* share.verify(detached.capability, {
|
|
170
|
+
branchId: detached.branchId,
|
|
171
|
+
access: "write"
|
|
172
|
+
});
|
|
173
|
+
if (detached.displayName.length === 0) {
|
|
174
|
+
return yield* Effect.fail(
|
|
175
|
+
new import_SyncError.SyncError({ code: "invalid_request", message: "A participant's display name must not be empty" })
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
if (detached.where !== void 0 && !Schema.is(import_BranchProtocol.PresenceWhere)(detached.where)) {
|
|
179
|
+
return yield* Effect.fail(new import_SyncError.SyncError({ code: "invalid_request", message: "Invalid presence location" }));
|
|
180
|
+
}
|
|
181
|
+
if (detached.sessionId !== void 0 && detached.sessionId.length === 0) {
|
|
182
|
+
return yield* Effect.fail(new import_SyncError.SyncError({ code: "invalid_request", message: "Invalid presence session" }));
|
|
183
|
+
}
|
|
184
|
+
let cursor = null;
|
|
185
|
+
if (detached.cursor !== null) {
|
|
186
|
+
const { cardId, offset } = detached.cursor;
|
|
187
|
+
if (typeof cardId !== "string" || cardId.length === 0) {
|
|
188
|
+
return yield* Effect.fail(
|
|
189
|
+
new import_SyncError.SyncError({ code: "invalid_request", message: "A cursor's card ID must not be empty" })
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
if (typeof offset !== "number" || !Number.isSafeInteger(offset) || offset < 0) {
|
|
193
|
+
return yield* Effect.fail(
|
|
194
|
+
new import_SyncError.SyncError({ code: "invalid_request", message: "A cursor's offset must be a nonnegative safe integer" })
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
cursor = new import_BranchProtocol.Cursor({ cardId, offset });
|
|
198
|
+
}
|
|
199
|
+
const announcement = { ...detached, cursor };
|
|
200
|
+
const nowMs = yield* Clock.currentTimeMillis;
|
|
201
|
+
live(announcement.branchId, nowMs);
|
|
202
|
+
const branch = roster.get(announcement.branchId) ?? /* @__PURE__ */ new Map();
|
|
203
|
+
const held = branch.get(seatKey(announcement));
|
|
204
|
+
const foreignActor = Array.from(branch.values()).some(
|
|
205
|
+
(seat) => seat.participant.participantId === announcement.participantId && seat.capabilityId !== claims.capabilityId
|
|
206
|
+
);
|
|
207
|
+
if (foreignActor || held !== void 0 && held.capabilityId !== claims.capabilityId) {
|
|
208
|
+
return yield* Effect.fail(heldByAnother(announcement.participantId));
|
|
209
|
+
}
|
|
210
|
+
if (held === void 0 && branch.size >= maxParticipants) {
|
|
211
|
+
return yield* Effect.fail(
|
|
212
|
+
new import_SyncError.SyncError({
|
|
213
|
+
code: "backpressure",
|
|
214
|
+
message: `Branch ${announcement.branchId} already holds ${maxParticipants} participants`
|
|
215
|
+
})
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
const participant = new import_BranchProtocol.Participant({
|
|
219
|
+
branchId: announcement.branchId,
|
|
220
|
+
participantId: announcement.participantId,
|
|
221
|
+
displayName: announcement.displayName,
|
|
222
|
+
cursor: announcement.cursor,
|
|
223
|
+
...announcement.sessionId === void 0 ? {} : { sessionId: announcement.sessionId },
|
|
224
|
+
...announcement.kind === void 0 ? {} : { kind: announcement.kind },
|
|
225
|
+
...announcement.where === void 0 ? {} : { where: announcement.where },
|
|
226
|
+
...announcement.watching === void 0 ? {} : { watching: announcement.watching },
|
|
227
|
+
...announcement.for_member === void 0 ? {} : { for_member: announcement.for_member },
|
|
228
|
+
...announcement.agentKind === void 0 ? {} : { agentKind: announcement.agentKind },
|
|
229
|
+
...announcement.via === void 0 ? {} : { via: announcement.via },
|
|
230
|
+
...announcement.runId === void 0 ? {} : { runId: announcement.runId },
|
|
231
|
+
leaseExpiresAtMs: nowMs + leaseMs
|
|
232
|
+
});
|
|
233
|
+
branch.set(seatKey(announcement), { participant, capabilityId: claims.capabilityId });
|
|
234
|
+
roster.set(announcement.branchId, branch);
|
|
235
|
+
yield* PubSub.publish(changes, announcement.branchId);
|
|
236
|
+
return detach(participant);
|
|
237
|
+
});
|
|
238
|
+
const leave = Effect.fn("BranchPresence.leave")(function* (supplied) {
|
|
239
|
+
const request = detachLeave(supplied);
|
|
240
|
+
yield* Effect.annotateCurrentSpan({ branchId: request.branchId, participantId: request.participantId });
|
|
241
|
+
const claims = yield* share.verify(request.capability, { branchId: request.branchId, access: "write" });
|
|
242
|
+
const branch = expire(request.branchId, yield* Clock.currentTimeMillis);
|
|
243
|
+
if (branch !== void 0) {
|
|
244
|
+
const keys = request.sessionId === void 0 ? [...branch].filter(([, seat]) => seat.participant.participantId === request.participantId).map(([key]) => key) : [seatKey(request)];
|
|
245
|
+
for (const key of keys) {
|
|
246
|
+
const held = branch.get(key);
|
|
247
|
+
if (held !== void 0 && held.capabilityId !== claims.capabilityId) {
|
|
248
|
+
return yield* Effect.fail(heldByAnother(request.participantId));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
for (const key of keys) branch.delete(key);
|
|
252
|
+
if (branch.size === 0) roster.delete(request.branchId);
|
|
253
|
+
}
|
|
254
|
+
yield* PubSub.publish(changes, request.branchId);
|
|
255
|
+
});
|
|
256
|
+
const list = Effect.fn("BranchPresence.list")(function* (supplied) {
|
|
257
|
+
const request = detachRoster(supplied);
|
|
258
|
+
yield* Effect.annotateCurrentSpan({ branchId: request.branchId });
|
|
259
|
+
yield* share.verify(request.capability, { branchId: request.branchId, access: "read" });
|
|
260
|
+
return live(request.branchId, yield* Clock.currentTimeMillis);
|
|
261
|
+
});
|
|
262
|
+
const presenceOn = Effect.fn("BranchPresence.presenceOn")(function* (supplied) {
|
|
263
|
+
const request = detachRoster(supplied);
|
|
264
|
+
yield* share.verify(request.capability, { branchId: request.branchId, access: "read" });
|
|
265
|
+
const nowMs = yield* Clock.currentTimeMillis;
|
|
266
|
+
if (nowMs - startedAtMs < leaseMs || !(yield* sourcesReady(request.branchId))) return "unknown";
|
|
267
|
+
return live(request.branchId, nowMs).length === 0 ? "empty" : "present";
|
|
268
|
+
});
|
|
269
|
+
return BranchPresence.of({ announce, leave, list, presenceOn, changes: Stream.fromPubSub(changes), leaseMs });
|
|
270
|
+
});
|
|
271
|
+
const layer = Layer.effect(
|
|
272
|
+
BranchPresence,
|
|
273
|
+
makeResolved(defaults)
|
|
274
|
+
);
|
|
275
|
+
const layerWith = (options) => Layer.effect(BranchPresence, makeMemory(options));
|
|
276
|
+
//# sourceMappingURL=BranchPresence.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/BranchPresence.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Ephemeral presence and cursors for one shared branch.\n *\n * Presence is deliberately NOT journalled. A roster is a lease table: every\n * announcement extends a lease, and a participant that stops announcing \u2014\n * because the tab closed, the network dropped, or the process died \u2014 ages out\n * without anyone reporting the disconnect. Writing presence to the journal\n * would make \"who was looking at this\" part of the durable, replayable history\n * of a run, which is both unbounded and wrong: replaying a branch must not\n * resurrect a stranger's caret.\n *\n * Every operation authorizes through {@link BranchShare}, so a capability for\n * one branch can neither read nor write another branch's roster. A live\n * participant is bound to the capability that announced it: announcing or\n * leaving under that `participantId` with any other capability is refused\n * with `unauthorized` until the lease lapses.\n *\n * @since 0.1.0\n */\n\nimport * as Clock from \"effect/Clock\"\nimport * as Context from \"effect/Context\"\nimport * as Effect from \"effect/Effect\"\nimport * as Layer from \"effect/Layer\"\nimport * as PubSub from \"effect/PubSub\"\nimport * as Schema from \"effect/Schema\"\nimport * as Stream from \"effect/Stream\"\nimport {\n type Announcement,\n type BranchId,\n Cursor,\n type LeaveRequest,\n Participant,\n type ParticipantId,\n PresenceWhere,\n type RosterRequest\n} from \"./BranchProtocol.ts\"\nimport * as BranchShare from \"./BranchShare.ts\"\nimport { positiveInt } from \"./internal/PolicyOptions.ts\"\nimport { SyncError } from \"./SyncError.ts\"\n\n/**\n * Ephemeral branch presence operations.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Service {\n readonly announce: (announcement: Announcement) => Effect.Effect<Participant, SyncError>\n readonly leave: (request: LeaveRequest) => Effect.Effect<void, SyncError>\n /**\n * One branch's live roster, as a fresh array of detached participants and\n * cursors. Reading drops expired leases and advances a cross-branch sweep.\n */\n readonly list: (request: RosterRequest) => Effect.Effect<ReadonlyArray<Participant>, SyncError>\n /**\n * Returns `unknown` for one lease after host startup or while a required\n * heartbeat source is unavailable; otherwise reports `present` or `empty`.\n *\n * @since 1.0.0\n */\n readonly presenceOn: (request: RosterRequest) => Effect.Effect<\"unknown\" | \"present\" | \"empty\", SyncError>\n readonly changes: Stream.Stream<BranchId>\n /**\n * How long one announcement keeps a participant on the roster, in\n * milliseconds.\n *\n * A lease lapses without anyone reporting it, and nothing publishes on\n * `changes` when it does, so a watcher cannot learn of the last\n * participant's departure from the change feed alone. It re-lists on this\n * cadence capped at one second, bounding how long an expired lease stays visible.\n */\n readonly leaseMs: number\n}\n\n/**\n * The branch presence registry.\n *\n * @category services\n * @since 0.1.0\n */\nexport class BranchPresence extends Context.Service<BranchPresence, Service>()(\"@smthrs/sync/BranchPresence\") {}\n\nconst unavailable = new SyncError({ code: \"unsupported\", message: \"Branch presence is unavailable\" })\n\n/**\n * The lease {@link makeNoop} reports. It holds no one, so the value only has\n * to be a positive number a watcher can build a re-list cadence from.\n *\n * @category constants\n * @since 1.0.0-rc.0\n */\nexport const defaultLeaseMs = 30_000\n\n/**\n * Constructs an unavailable presence registry.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const makeNoop = (overrides: Partial<Service> = {}): Service =>\n BranchPresence.of({\n announce: () => Effect.fail(unavailable),\n leave: () => Effect.fail(unavailable),\n list: () => Effect.fail(unavailable),\n presenceOn: () => Effect.succeed(\"unknown\"),\n changes: Stream.empty,\n leaseMs: defaultLeaseMs,\n ...overrides\n })\n\n/**\n * Provides an unavailable presence registry.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerNoop: Layer.Layer<BranchPresence> = Layer.succeed(BranchPresence, makeNoop())\n\n/**\n * The policy one presence registry runs under. Every field defaults, and\n * {@link makeMemory} and {@link layerWith} validate what a caller supplies.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface PresenceOptions {\n /**\n * How long an announcement keeps a participant on the roster, in\n * milliseconds. Defaults to {@link defaultLeaseMs}.\n */\n readonly leaseMs?: number | undefined\n /**\n * Roster changes a stalled {@link Service.changes} subscriber may fall\n * behind by. Defaults to {@link defaultChangesCapacity}.\n */\n readonly changesCapacity?: number | undefined\n /**\n * Participants one branch may hold at once. Defaults to\n * {@link defaultMaxParticipants}.\n */\n readonly maxParticipants?: number | undefined\n /**\n * Host readiness, including authorization, revocation, bridge and session\n * sources. Defaults to unavailable.\n *\n * @since 1.0.0\n */\n readonly sourcesReady?: ((branchId: BranchId) => Effect.Effect<boolean>) | undefined\n}\n\n/**\n * One roster slot: the participant, and the capability that announced it.\n *\n * `participantId` is chosen by the client, so it proves nothing on its own.\n * The slot is bound to the verified `capabilityId` of its first live\n * announcement, and only that capability may refresh or leave it until the\n * lease lapses. Without the binding any write link on the branch could\n * rename, move the caret of, or evict another link's participant.\n */\ninterface Seat {\n readonly participant: Participant\n readonly capabilityId: string\n}\n\nconst heldByAnother = (participantId: ParticipantId): SyncError =>\n new SyncError({\n code: \"unauthorized\",\n message: `Participant ${participantId} is held by another share capability`\n })\n\n/** The resolved, already-validated presence policy. */\ninterface Resolved {\n readonly leaseMs: number\n readonly changesCapacity: number\n readonly maxParticipants: number\n readonly sourcesReady: (branchId: BranchId) => Effect.Effect<boolean>\n}\n\n/**\n * Roster changes a stalled {@link Service.changes} subscriber may fall behind\n * by before the oldest are dropped.\n *\n * Presence is a lease table, and `changes` only says that some branch's roster\n * moved: a follower answers it with `list`. Holding an unbounded backlog for a\n * subscriber that has stopped pulling would let one abandoned watcher retain\n * every announcement the process has seen since. A subscriber that falls\n * further behind than this bound loses the oldest notifications and re-lists;\n * because every notification is answered by a fresh `list`, dropping one never\n * loses roster state.\n *\n * @category constants\n * @since 0.1.0\n */\nexport const defaultChangesCapacity = 256\n\n/**\n * Participants one branch may hold at once.\n *\n * A roster is unbounded fan-out in two directions: it is walked on every\n * `list`, and `Branch.Roster` returns it whole, which no frame ceiling covers.\n * Nothing caps how many distinct `participantId`s one write capability may\n * announce, so without this a single share link could pin an arbitrary number\n * of `Participant` objects until their leases expired. Two hundred and fifty\n * six is far above any real collaborative session; a further announce is\n * refused with `backpressure`.\n *\n * @category constants\n * @since 1.0.0-rc.0\n */\nexport const defaultMaxParticipants = 256\n\nconst defaults: Resolved = {\n leaseMs: defaultLeaseMs,\n changesCapacity: defaultChangesCapacity,\n maxParticipants: defaultMaxParticipants,\n sourcesReady: () => Effect.succeed(false)\n}\n\n/**\n * Constructs the in-memory, lease-expiring presence registry.\n *\n * Announcing requires write access: a read-only share link may watch the\n * roster but never appears on it, so a shared read link cannot be used to\n * impersonate a collaborator. A live participant belongs to the capability\n * that announced it, so another write link can neither overwrite nor evict it.\n * Holders of one link share its `capabilityId` and stay indistinguishable.\n *\n * The roster is keyed by branch and then by participant, so listing one branch\n * costs that branch plus a bounded sweep of other branches, and no two\n * branches can share a slot. One flat key built by concatenation collided\n * for valid branded ids, which let one announcement overwrite another branch's\n * participant.\n *\n * The change feed slides at {@link defaultChangesCapacity}: announcing never\n * waits on a stalled watcher, and never grows the process on its behalf.\n *\n * Fails with `invalid_request` when an option is not a positive safe integer.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const makeMemory = (\n options: PresenceOptions = {}\n): Effect.Effect<Service, SyncError, BranchShare.BranchShare> =>\n Effect.flatMap(\n Effect.all({\n leaseMs: positiveInt(\"BranchPresence.PresenceOptions.leaseMs\", options.leaseMs, defaults.leaseMs),\n changesCapacity: positiveInt(\n \"BranchPresence.PresenceOptions.changesCapacity\",\n options.changesCapacity,\n defaults.changesCapacity\n ),\n maxParticipants: positiveInt(\n \"BranchPresence.PresenceOptions.maxParticipants\",\n options.maxParticipants,\n defaults.maxParticipants\n )\n }),\n (resolved) => makeResolved({ ...resolved, sourcesReady: options.sourcesReady ?? defaults.sourcesReady })\n )\n\n/** The registry over an already-validated policy. */\nconst makeResolved = (\n { changesCapacity, leaseMs, maxParticipants, sourcesReady }: Resolved\n): Effect.Effect<Service, never, BranchShare.BranchShare> =>\n Effect.gen(function*() {\n const startedAtMs = yield* Clock.currentTimeMillis\n const share = yield* BranchShare.BranchShare\n const roster = new Map<BranchId, Map<string, Seat>>()\n const changes = yield* PubSub.sliding<BranchId>(changesCapacity)\n\n const expire = (branchId: BranchId, nowMs: number) => {\n const branch = roster.get(branchId)\n if (branch === undefined) return undefined\n for (const [participantId, seat] of branch) {\n if (seat.participant.leaseExpiresAtMs <= nowMs) branch.delete(participantId)\n }\n if (branch.size === 0) {\n roster.delete(branchId)\n return undefined\n }\n return branch\n }\n\n // Each announce/list advances through at most 16 branch maps. Their\n // participant counts are capped, so unrelated activity reclaims abandoned\n // rosters without scanning the entire registry in a single request.\n let sweepCursor = roster.keys()\n const sweep = (nowMs: number) => {\n for (let index = 0; index < 16; index++) {\n const next = sweepCursor.next()\n if (next.done) {\n sweepCursor = roster.keys()\n break\n }\n expire(next.value, nowMs)\n }\n }\n\n const seatKey = (request: { participantId: ParticipantId; sessionId?: string }) =>\n JSON.stringify([request.participantId, request.sessionId ?? \"\"])\n const copyWhere = (where: NonNullable<Participant[\"where\"]>) => ({ ...where })\n const detach = (participant: Participant): Participant =>\n new Participant({\n ...participant,\n ...(participant.where === undefined ? {} : { where: copyWhere(participant.where) }),\n cursor: participant.cursor === null ? null : new Cursor(participant.cursor)\n })\n\n /**\n * Drop this branch's expired leases and advance cleanup of other branches.\n * Abandoned maps are reclaimed as announce/list calls advance the sweep;\n * an idle registry keeps them until activity resumes. Results are detached\n * from storage, including each participant's cursor.\n */\n const live = (branchId: BranchId, nowMs: number): Array<Participant> => {\n sweep(nowMs)\n const branch = expire(branchId, nowMs)\n if (branch === undefined) return []\n // Map entries have distinct seat keys, so compared seats cannot be equal.\n return Array.from(branch.values(), (seat) => detach(seat.participant)).sort((left, right) =>\n seatKey(left) < seatKey(right) ? -1 : 1\n )\n }\n\n /**\n * Copy a request out of the caller's object before the first await.\n *\n * `share.verify` awaits Web Crypto between authorizing `branchId` and the\n * roster access that follows. The request objects are plain structs the\n * in-process caller still holds, so reading them again after the await let\n * a caller move `branchId` (or the participant identity) onto a branch the\n * capability never authorized. Matches the claim snapshot in `BranchShare`.\n */\n const detachRoster = (request: RosterRequest): RosterRequest => ({\n capability: request.capability,\n branchId: request.branchId\n })\n const detachLeave = (request: LeaveRequest): LeaveRequest => ({\n ...detachRoster(request),\n participantId: request.participantId,\n ...(request.sessionId === undefined ? {} : { sessionId: request.sessionId })\n })\n const detachAnnouncement = (request: Announcement) => {\n const suppliedCursor: unknown = request.cursor\n const cursor: { readonly cardId: unknown; readonly offset: unknown } | null = suppliedCursor === null\n ? null\n : typeof suppliedCursor === \"object\"\n ? { cardId: (suppliedCursor as Cursor).cardId, offset: (suppliedCursor as Cursor).offset }\n : { cardId: undefined, offset: undefined }\n return {\n ...detachLeave(request),\n displayName: request.displayName,\n cursor,\n ...(request.kind === undefined ? {} : { kind: request.kind }),\n ...(request.where === undefined ? {} : { where: copyWhere(request.where) }),\n ...(request.watching === undefined ? {} : { watching: request.watching }),\n ...(request.for_member === undefined ? {} : { for_member: request.for_member }),\n ...(request.agentKind === undefined ? {} : { agentKind: request.agentKind }),\n ...(request.via === undefined ? {} : { via: request.via }),\n ...(request.runId === undefined ? {} : { runId: request.runId })\n }\n }\n\n const announce = Effect.fn(\"BranchPresence.announce\")(function*(supplied: Announcement) {\n const detached = detachAnnouncement(supplied)\n yield* Effect.annotateCurrentSpan({\n branchId: detached.branchId,\n participantId: detached.participantId\n })\n const claims = yield* share.verify(detached.capability, {\n branchId: detached.branchId,\n access: \"write\"\n })\n // The wire schema IS `Announcement`, so a remote caller cannot reach\n // here with an empty name. An in-process caller can, and `Participant`\n // requires a `NonEmptyString`: without this the constructor threw a\n // defect out of an operation whose type promises a `SyncError`.\n if (detached.displayName.length === 0) {\n return yield* Effect.fail(\n new SyncError({ code: \"invalid_request\", message: \"A participant's display name must not be empty\" })\n )\n }\n if (detached.where !== undefined && !Schema.is(PresenceWhere)(detached.where)) {\n return yield* Effect.fail(new SyncError({ code: \"invalid_request\", message: \"Invalid presence location\" }))\n }\n if (detached.sessionId !== undefined && detached.sessionId.length === 0) {\n return yield* Effect.fail(new SyncError({ code: \"invalid_request\", message: \"Invalid presence session\" }))\n }\n let cursor: Cursor | null = null\n if (detached.cursor !== null) {\n const { cardId, offset } = detached.cursor\n if (typeof cardId !== \"string\" || cardId.length === 0) {\n return yield* Effect.fail(\n new SyncError({ code: \"invalid_request\", message: \"A cursor's card ID must not be empty\" })\n )\n }\n if (typeof offset !== \"number\" || !Number.isSafeInteger(offset) || offset < 0) {\n return yield* Effect.fail(\n new SyncError({ code: \"invalid_request\", message: \"A cursor's offset must be a nonnegative safe integer\" })\n )\n }\n cursor = new Cursor({ cardId, offset })\n }\n const announcement = { ...detached, cursor }\n const nowMs = yield* Clock.currentTimeMillis\n // Run-out leases are dropped before the cap is judged, so a branch that\n // has simply been busy over time is never refused for a stale roster.\n live(announcement.branchId, nowMs)\n const branch = roster.get(announcement.branchId) ?? new Map<string, Seat>()\n const held = branch.get(seatKey(announcement))\n // A session suffix must not bypass the existing participant ownership\n // fence. The host may bind multiple sessions to one actor capability.\n const foreignActor = Array.from(branch.values()).some((seat) =>\n seat.participant.participantId === announcement.participantId && seat.capabilityId !== claims.capabilityId\n )\n if (foreignActor || (held !== undefined && held.capabilityId !== claims.capabilityId)) {\n return yield* Effect.fail(heldByAnother(announcement.participantId))\n }\n if (held === undefined && branch.size >= maxParticipants) {\n return yield* Effect.fail(\n new SyncError({\n code: \"backpressure\",\n message: `Branch ${announcement.branchId} already holds ${maxParticipants} participants`\n })\n )\n }\n const participant = new Participant({\n branchId: announcement.branchId,\n participantId: announcement.participantId,\n displayName: announcement.displayName,\n cursor: announcement.cursor,\n ...(announcement.sessionId === undefined ? {} : { sessionId: announcement.sessionId }),\n ...(announcement.kind === undefined ? {} : { kind: announcement.kind }),\n ...(announcement.where === undefined ? {} : { where: announcement.where }),\n ...(announcement.watching === undefined ? {} : { watching: announcement.watching }),\n ...(announcement.for_member === undefined ? {} : { for_member: announcement.for_member }),\n ...(announcement.agentKind === undefined ? {} : { agentKind: announcement.agentKind }),\n ...(announcement.via === undefined ? {} : { via: announcement.via }),\n ...(announcement.runId === undefined ? {} : { runId: announcement.runId }),\n leaseExpiresAtMs: nowMs + leaseMs\n })\n branch.set(seatKey(announcement), { participant, capabilityId: claims.capabilityId })\n roster.set(announcement.branchId, branch)\n yield* PubSub.publish(changes, announcement.branchId)\n return detach(participant)\n })\n\n const leave = Effect.fn(\"BranchPresence.leave\")(function*(supplied: LeaveRequest) {\n const request = detachLeave(supplied)\n yield* Effect.annotateCurrentSpan({ branchId: request.branchId, participantId: request.participantId })\n const claims = yield* share.verify(request.capability, { branchId: request.branchId, access: \"write\" })\n const branch = expire(request.branchId, yield* Clock.currentTimeMillis)\n if (branch !== undefined) {\n const keys = request.sessionId === undefined\n ? [...branch].filter(([, seat]) => seat.participant.participantId === request.participantId)\n .map(([key]) => key)\n : [seatKey(request)]\n for (const key of keys) {\n const held = branch.get(key)\n if (held !== undefined && held.capabilityId !== claims.capabilityId) {\n return yield* Effect.fail(heldByAnother(request.participantId))\n }\n }\n for (const key of keys) branch.delete(key)\n if (branch.size === 0) roster.delete(request.branchId)\n }\n yield* PubSub.publish(changes, request.branchId)\n })\n\n const list = Effect.fn(\"BranchPresence.list\")(function*(supplied: RosterRequest) {\n const request = detachRoster(supplied)\n yield* Effect.annotateCurrentSpan({ branchId: request.branchId })\n yield* share.verify(request.capability, { branchId: request.branchId, access: \"read\" })\n return live(request.branchId, yield* Clock.currentTimeMillis)\n })\n\n const presenceOn = Effect.fn(\"BranchPresence.presenceOn\")(function*(supplied: RosterRequest) {\n const request = detachRoster(supplied)\n yield* share.verify(request.capability, { branchId: request.branchId, access: \"read\" })\n const nowMs = yield* Clock.currentTimeMillis\n if (nowMs - startedAtMs < leaseMs || !(yield* sourcesReady(request.branchId))) return \"unknown\" as const\n return live(request.branchId, nowMs).length === 0 ? \"empty\" as const : \"present\" as const\n })\n\n return BranchPresence.of({ announce, leave, list, presenceOn, changes: Stream.fromPubSub(changes), leaseMs })\n })\n\n/**\n * Provides the in-memory, lease-expiring presence registry under the default\n * policy, which is valid by construction and so cannot fail.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layer: Layer.Layer<BranchPresence, never, BranchShare.BranchShare> = Layer.effect(\n BranchPresence,\n makeResolved(defaults)\n)\n\n/**\n * Provides the in-memory, lease-expiring presence registry under an explicit\n * policy. Fails with `invalid_request` when an option is not a positive safe\n * integer, so a bad policy fails the composition rather than an announcement.\n *\n * @category layers\n * @since 1.0.0-rc.0\n */\nexport const layerWith = (\n options: PresenceOptions\n): Layer.Layer<BranchPresence, SyncError, BranchShare.BranchShare> => Layer.effect(BranchPresence, makeMemory(options))\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBA,YAAuB;AACvB,cAAyB;AACzB,aAAwB;AACxB,YAAuB;AACvB,aAAwB;AACxB,aAAwB;AACxB,aAAwB;AACxB,4BASO;AACP,kBAA6B;AAC7B,2BAA4B;AAC5B,uBAA0B;AA0CnB,MAAM,uBAAuB,QAAQ,QAAiC,EAAE,6BAA6B,EAAE;AAAC;AAE/G,MAAM,cAAc,IAAI,2BAAU,EAAE,MAAM,eAAe,SAAS,iCAAiC,CAAC;AAS7F,MAAM,iBAAiB;AAQvB,MAAM,WAAW,CAAC,YAA8B,CAAC,MACtD,eAAe,GAAG;AAAA,EAChB,UAAU,MAAM,OAAO,KAAK,WAAW;AAAA,EACvC,O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