@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,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable, schema-backed failures for the sync boundary.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
/**
|
|
8
|
+
* Stable error codes returned by sync operations.
|
|
9
|
+
*
|
|
10
|
+
* `unsupported` reports an unavailable host operation or presence transport
|
|
11
|
+
* (since 1.0.0). It never implies an empty roster.
|
|
12
|
+
*
|
|
13
|
+
* `compacted` reports that the request's cursor for one run starts below that
|
|
14
|
+
* run's compaction floor, so the entries it asks for have been deleted. It is
|
|
15
|
+
* its own code rather than an `unknown` because it is RECOVERABLE and nothing
|
|
16
|
+
* else here is: the accompanying {@link SyncError.resync} names the checkpoint
|
|
17
|
+
* to resume from, and a follower that applies it converges. Folding it into
|
|
18
|
+
* `unknown` cost the checkpoint, and with it every path back.
|
|
19
|
+
*
|
|
20
|
+
* @category models
|
|
21
|
+
* @since 0.1.0
|
|
22
|
+
*/
|
|
23
|
+
export declare const ErrorCode: Schema.Literals<readonly ["invalid_request", "unsupported", "unauthorized", "not_found", "backpressure", "frame_too_large", "decode_failed", "transport_failed", "protocol_violation", "lineage_changed", "compacted", "closed", "unknown"]>;
|
|
24
|
+
/**
|
|
25
|
+
* Stable error code returned by a sync operation.
|
|
26
|
+
*
|
|
27
|
+
* @category models
|
|
28
|
+
* @since 0.1.0
|
|
29
|
+
*/
|
|
30
|
+
export type ErrorCode = typeof ErrorCode.Type;
|
|
31
|
+
declare const SyncError_base: Schema.Class<SyncError, Schema.TaggedStruct<"@smthrs/sync/SyncError", {
|
|
32
|
+
readonly code: Schema.Literals<readonly ["invalid_request", "unsupported", "unauthorized", "not_found", "backpressure", "frame_too_large", "decode_failed", "transport_failed", "protocol_violation", "lineage_changed", "compacted", "closed", "unknown"]>;
|
|
33
|
+
readonly message: Schema.String;
|
|
34
|
+
readonly cause: Schema.optional<Schema.String>;
|
|
35
|
+
readonly resync: Schema.optional<Schema.Struct<{
|
|
36
|
+
readonly runId: Schema.brand<Schema.String, "@smthrs/journal/JournalEvent/RunId">;
|
|
37
|
+
readonly checkpointSeq: Schema.brand<Schema.Int, "@smthrs/journal/JournalEvent/Seq">;
|
|
38
|
+
readonly generation: Schema.optional<Schema.Int>;
|
|
39
|
+
}>>;
|
|
40
|
+
readonly rewind: Schema.optional<Schema.Struct<{
|
|
41
|
+
readonly runId: Schema.brand<Schema.String, "@smthrs/journal/JournalEvent/RunId">;
|
|
42
|
+
readonly generation: Schema.Int;
|
|
43
|
+
readonly afterSeq: Schema.Int;
|
|
44
|
+
}>>;
|
|
45
|
+
}>, import("effect/Cause").YieldableError>;
|
|
46
|
+
/**
|
|
47
|
+
* Error raised by sync validation, transport, framing, or subscription work.
|
|
48
|
+
*
|
|
49
|
+
* `resync` is set only on `compacted`, and names the run and the checkpoint
|
|
50
|
+
* sequence a follower resumes from. It is optional so every other code keeps
|
|
51
|
+
* the shape it already had on the wire.
|
|
52
|
+
*
|
|
53
|
+
* `rewind` is set on server-side `lineage_changed` refusals and names the
|
|
54
|
+
* current generation and archive boundary. The caller rebuilds its projection
|
|
55
|
+
* from retained history and creates a fresh client; the client never retries this failure.
|
|
56
|
+
*
|
|
57
|
+
* `cause` is a bounded STRING, not the host object that failed. This error is
|
|
58
|
+
* the declared error schema of every RPC in both groups, so whatever it
|
|
59
|
+
* carries reaches a remote follower that may hold nothing but a branch share
|
|
60
|
+
* link. A `Schema.Unknown` cause published the host's own failure verbatim —
|
|
61
|
+
* a driver message with SQL text, a rejected credential — counted against no
|
|
62
|
+
* size ceiling, and had no defined wire form for a class instance or a cyclic
|
|
63
|
+
* value. `internal/CauseText` is the one renderer that fills it.
|
|
64
|
+
*
|
|
65
|
+
* @category errors
|
|
66
|
+
* @since 0.1.0
|
|
67
|
+
*/
|
|
68
|
+
export declare class SyncError extends SyncError_base {
|
|
69
|
+
/**
|
|
70
|
+
* Returns `true` when a value carries this error's shape: the tag, a `code`
|
|
71
|
+
* this package declares, a string `message`, and a `resync` only alongside
|
|
72
|
+
* `compacted`.
|
|
73
|
+
*
|
|
74
|
+
* It is a STRUCTURAL check, not a class check, deliberately. Everything that
|
|
75
|
+
* reaches it on a shipped path has crossed a boundary that rebuilds the
|
|
76
|
+
* value — the RPC client's schema-decoded error channel, or a browser
|
|
77
|
+
* `postMessage` that keeps the fields and drops the prototype — and a check
|
|
78
|
+
* that demanded the prototype would refuse an error the package itself sent.
|
|
79
|
+
* What it does not verify is that the value was produced by this package: a
|
|
80
|
+
* value constructed in-process with the right fields passes.
|
|
81
|
+
*
|
|
82
|
+
* It is TOTAL. The value is `unknown`, so ANY property read on it may be a
|
|
83
|
+
* throwing getter — the tag included, which is the first one read and was
|
|
84
|
+
* the one read outside the protection — and this guard decides whether a
|
|
85
|
+
* follow reconnects and whether a cursor moves past a compaction floor: a
|
|
86
|
+
* question about a value's shape must answer, never raise.
|
|
87
|
+
*
|
|
88
|
+
* @since 0.1.0
|
|
89
|
+
*/
|
|
90
|
+
static readonly is: (value: unknown) => value is SyncError;
|
|
91
|
+
}
|
|
92
|
+
declare const SyncGapError_base: Schema.Class<SyncGapError, Schema.TaggedStruct<"@smthrs/sync/SyncGapError", {
|
|
93
|
+
readonly runId: Schema.brand<Schema.String, "@smthrs/journal/JournalEvent/RunId">;
|
|
94
|
+
readonly expectedFrom: Schema.brand<Schema.Int, "@smthrs/journal/JournalEvent/Seq">;
|
|
95
|
+
readonly receivedFrom: Schema.brand<Schema.Int, "@smthrs/journal/JournalEvent/Seq">;
|
|
96
|
+
}>, import("effect/Cause").YieldableError>;
|
|
97
|
+
/**
|
|
98
|
+
* Terminal error raised when a server frame starts beyond the client's
|
|
99
|
+
* covered cursor.
|
|
100
|
+
*
|
|
101
|
+
* @category errors
|
|
102
|
+
* @since 0.1.0
|
|
103
|
+
*/
|
|
104
|
+
export declare class SyncGapError extends SyncGapError_base {
|
|
105
|
+
}
|
|
106
|
+
export {};
|
|
107
|
+
//# sourceMappingURL=SyncError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncError.d.ts","sourceRoot":"","sources":["../../src/SyncError.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAoBvC;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,SAAS,8OAAiF,CAAA;AAIvG;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,IAAI,CAAA;;;;;;;;;;;;;;;;AAQ7C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,SAAU,SAAQ,cAM7B;IACA;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,SAAS,CAoBxD;CACF;;;;;;AAED;;;;;;GAMG;AACH,qBAAa,YAAa,SAAQ,iBAIhC;CAAG"}
|
|
@@ -0,0 +1,110 @@
|
|
|
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 SyncError_exports = {};
|
|
30
|
+
__export(SyncError_exports, {
|
|
31
|
+
ErrorCode: () => ErrorCode,
|
|
32
|
+
SyncError: () => SyncError,
|
|
33
|
+
SyncGapError: () => SyncGapError
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(SyncError_exports);
|
|
36
|
+
var JournalEvent = __toESM(require("@smthrs/journal/JournalEvent"), 1);
|
|
37
|
+
var Predicate = __toESM(require("effect/Predicate"), 1);
|
|
38
|
+
var Schema = __toESM(require("effect/Schema"), 1);
|
|
39
|
+
var import_SyncProtocol = require("./SyncProtocol.js");
|
|
40
|
+
const errorCodes = [
|
|
41
|
+
"invalid_request",
|
|
42
|
+
"unsupported",
|
|
43
|
+
"unauthorized",
|
|
44
|
+
"not_found",
|
|
45
|
+
"backpressure",
|
|
46
|
+
"frame_too_large",
|
|
47
|
+
"decode_failed",
|
|
48
|
+
"transport_failed",
|
|
49
|
+
"protocol_violation",
|
|
50
|
+
"lineage_changed",
|
|
51
|
+
"compacted",
|
|
52
|
+
"closed",
|
|
53
|
+
"unknown"
|
|
54
|
+
];
|
|
55
|
+
const ErrorCode = Schema.Literals(errorCodes).annotate({ identifier: "@smthrs/sync/ErrorCode" });
|
|
56
|
+
const codes = new Set(errorCodes);
|
|
57
|
+
const Rewind = Schema.Struct({
|
|
58
|
+
runId: JournalEvent.RunId,
|
|
59
|
+
generation: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
60
|
+
afterSeq: Schema.Int.check(Schema.isGreaterThanOrEqualTo(-1))
|
|
61
|
+
});
|
|
62
|
+
class SyncError extends Schema.TaggedError()("@smthrs/sync/SyncError", {
|
|
63
|
+
code: ErrorCode,
|
|
64
|
+
message: Schema.String,
|
|
65
|
+
cause: Schema.optional(Schema.String),
|
|
66
|
+
resync: Schema.optional(import_SyncProtocol.Resync),
|
|
67
|
+
rewind: Schema.optional(Rewind)
|
|
68
|
+
}) {
|
|
69
|
+
/**
|
|
70
|
+
* Returns `true` when a value carries this error's shape: the tag, a `code`
|
|
71
|
+
* this package declares, a string `message`, and a `resync` only alongside
|
|
72
|
+
* `compacted`.
|
|
73
|
+
*
|
|
74
|
+
* It is a STRUCTURAL check, not a class check, deliberately. Everything that
|
|
75
|
+
* reaches it on a shipped path has crossed a boundary that rebuilds the
|
|
76
|
+
* value — the RPC client's schema-decoded error channel, or a browser
|
|
77
|
+
* `postMessage` that keeps the fields and drops the prototype — and a check
|
|
78
|
+
* that demanded the prototype would refuse an error the package itself sent.
|
|
79
|
+
* What it does not verify is that the value was produced by this package: a
|
|
80
|
+
* value constructed in-process with the right fields passes.
|
|
81
|
+
*
|
|
82
|
+
* It is TOTAL. The value is `unknown`, so ANY property read on it may be a
|
|
83
|
+
* throwing getter — the tag included, which is the first one read and was
|
|
84
|
+
* the one read outside the protection — and this guard decides whether a
|
|
85
|
+
* follow reconnects and whether a cursor moves past a compaction floor: a
|
|
86
|
+
* question about a value's shape must answer, never raise.
|
|
87
|
+
*
|
|
88
|
+
* @since 0.1.0
|
|
89
|
+
*/
|
|
90
|
+
static is = (value) => {
|
|
91
|
+
try {
|
|
92
|
+
if (!Predicate.isTagged(value, "@smthrs/sync/SyncError")) return false;
|
|
93
|
+
const candidate = value;
|
|
94
|
+
if (typeof candidate.message !== "string") return false;
|
|
95
|
+
if (typeof candidate.code !== "string" || !codes.has(candidate.code)) return false;
|
|
96
|
+
if (candidate.rewind !== void 0 && (candidate.code !== "lineage_changed" || !Schema.is(Rewind)(candidate.rewind))) return false;
|
|
97
|
+
if (candidate.resync === void 0) return true;
|
|
98
|
+
return candidate.code === "compacted" && Schema.is(import_SyncProtocol.Resync)(candidate.resync);
|
|
99
|
+
} catch {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
class SyncGapError extends Schema.TaggedError()("@smthrs/sync/SyncGapError", {
|
|
105
|
+
runId: JournalEvent.RunId,
|
|
106
|
+
expectedFrom: JournalEvent.Seq,
|
|
107
|
+
receivedFrom: JournalEvent.Seq
|
|
108
|
+
}) {
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=SyncError.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/SyncError.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Stable, schema-backed failures for the sync boundary.\n *\n * @since 0.1.0\n */\n\nimport * as JournalEvent from \"@smthrs/journal/JournalEvent\"\nimport * as Predicate from \"effect/Predicate\"\nimport * as Schema from \"effect/Schema\"\nimport { Resync } from \"./SyncProtocol.ts\"\n\n/** The literals behind {@link ErrorCode}, also read by {@link SyncError.is}. */\nconst errorCodes = [\n \"invalid_request\",\n \"unsupported\",\n \"unauthorized\",\n \"not_found\",\n \"backpressure\",\n \"frame_too_large\",\n \"decode_failed\",\n \"transport_failed\",\n \"protocol_violation\",\n \"lineage_changed\",\n \"compacted\",\n \"closed\",\n \"unknown\"\n] as const\n\n/**\n * Stable error codes returned by sync operations.\n *\n * `unsupported` reports an unavailable host operation or presence transport\n * (since 1.0.0). It never implies an empty roster.\n *\n * `compacted` reports that the request's cursor for one run starts below that\n * run's compaction floor, so the entries it asks for have been deleted. It is\n * its own code rather than an `unknown` because it is RECOVERABLE and nothing\n * else here is: the accompanying {@link SyncError.resync} names the checkpoint\n * to resume from, and a follower that applies it converges. Folding it into\n * `unknown` cost the checkpoint, and with it every path back.\n *\n * @category models\n * @since 0.1.0\n */\nexport const ErrorCode = Schema.Literals(errorCodes).annotate({ identifier: \"@smthrs/sync/ErrorCode\" })\n\nconst codes: ReadonlySet<string> = new Set(errorCodes)\n\n/**\n * Stable error code returned by a sync operation.\n *\n * @category models\n * @since 0.1.0\n */\nexport type ErrorCode = typeof ErrorCode.Type\n\nconst Rewind = Schema.Struct({\n runId: JournalEvent.RunId,\n generation: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n afterSeq: Schema.Int.check(Schema.isGreaterThanOrEqualTo(-1))\n})\n\n/**\n * Error raised by sync validation, transport, framing, or subscription work.\n *\n * `resync` is set only on `compacted`, and names the run and the checkpoint\n * sequence a follower resumes from. It is optional so every other code keeps\n * the shape it already had on the wire.\n *\n * `rewind` is set on server-side `lineage_changed` refusals and names the\n * current generation and archive boundary. The caller rebuilds its projection\n * from retained history and creates a fresh client; the client never retries this failure.\n *\n * `cause` is a bounded STRING, not the host object that failed. This error is\n * the declared error schema of every RPC in both groups, so whatever it\n * carries reaches a remote follower that may hold nothing but a branch share\n * link. A `Schema.Unknown` cause published the host's own failure verbatim \u2014\n * a driver message with SQL text, a rejected credential \u2014 counted against no\n * size ceiling, and had no defined wire form for a class instance or a cyclic\n * value. `internal/CauseText` is the one renderer that fills it.\n *\n * @category errors\n * @since 0.1.0\n */\nexport class SyncError extends Schema.TaggedError<SyncError>()(\"@smthrs/sync/SyncError\", {\n code: ErrorCode,\n message: Schema.String,\n cause: Schema.optional(Schema.String),\n resync: Schema.optional(Resync),\n rewind: Schema.optional(Rewind)\n}) {\n /**\n * Returns `true` when a value carries this error's shape: the tag, a `code`\n * this package declares, a string `message`, and a `resync` only alongside\n * `compacted`.\n *\n * It is a STRUCTURAL check, not a class check, deliberately. Everything that\n * reaches it on a shipped path has crossed a boundary that rebuilds the\n * value \u2014 the RPC client's schema-decoded error channel, or a browser\n * `postMessage` that keeps the fields and drops the prototype \u2014 and a check\n * that demanded the prototype would refuse an error the package itself sent.\n * What it does not verify is that the value was produced by this package: a\n * value constructed in-process with the right fields passes.\n *\n * It is TOTAL. The value is `unknown`, so ANY property read on it may be a\n * throwing getter \u2014 the tag included, which is the first one read and was\n * the one read outside the protection \u2014 and this guard decides whether a\n * follow reconnects and whether a cursor moves past a compaction floor: a\n * question about a value's shape must answer, never raise.\n *\n * @since 0.1.0\n */\n static readonly is = (value: unknown): value is SyncError => {\n try {\n if (!Predicate.isTagged(value, \"@smthrs/sync/SyncError\")) return false\n const candidate = value as {\n readonly code?: unknown\n readonly message?: unknown\n readonly resync?: unknown\n readonly rewind?: unknown\n }\n if (typeof candidate.message !== \"string\") return false\n if (typeof candidate.code !== \"string\" || !codes.has(candidate.code)) return false\n if (\n candidate.rewind !== undefined &&\n (candidate.code !== \"lineage_changed\" || !Schema.is(Rewind)(candidate.rewind))\n ) return false\n if (candidate.resync === undefined) return true\n return candidate.code === \"compacted\" && Schema.is(Resync)(candidate.resync)\n } catch {\n return false\n }\n }\n}\n\n/**\n * Terminal error raised when a server frame starts beyond the client's\n * covered cursor.\n *\n * @category errors\n * @since 0.1.0\n */\nexport class SyncGapError extends Schema.TaggedError<SyncGapError>()(\"@smthrs/sync/SyncGapError\", {\n runId: JournalEvent.RunId,\n expectedFrom: JournalEvent.Seq,\n receivedFrom: JournalEvent.Seq\n}) {}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,mBAA8B;AAC9B,gBAA2B;AAC3B,aAAwB;AACxB,0BAAuB;AAGvB,MAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAkBO,MAAM,YAAY,OAAO,SAAS,UAAU,EAAE,SAAS,EAAE,YAAY,yBAAyB,CAAC;AAEtG,MAAM,QAA6B,IAAI,IAAI,UAAU;AAUrD,MAAM,SAAS,OAAO,OAAO;AAAA,EAC3B,OAAO,aAAa;AAAA,EACpB,YAAY,OAAO,IAAI,MAAM,OAAO,uBAAuB,CAAC,CAAC;AAAA,EAC7D,UAAU,OAAO,IAAI,MAAM,OAAO,uBAAuB,EAAE,CAAC;AAC9D,CAAC;AAwBM,MAAM,kBAAkB,OAAO,YAAuB,EAAE,0BAA0B;AAAA,EACvF,MAAM;AAAA,EACN,SAAS,OAAO;AAAA,EAChB,OAAO,OAAO,SAAS,OAAO,MAAM;AAAA,EACpC,QAAQ,OAAO,SAAS,0BAAM;AAAA,EAC9B,QAAQ,OAAO,SAAS,MAAM;AAChC,CAAC,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBD,OAAgB,KAAK,CAAC,UAAuC;AAC3D,QAAI;AACF,UAAI,CAAC,UAAU,SAAS,OAAO,wBAAwB,EAAG,QAAO;AACjE,YAAM,YAAY;AAMlB,UAAI,OAAO,UAAU,YAAY,SAAU,QAAO;AAClD,UAAI,OAAO,UAAU,SAAS,YAAY,CAAC,MAAM,IAAI,UAAU,IAAI,EAAG,QAAO;AAC7E,UACE,UAAU,WAAW,WACpB,UAAU,SAAS,qBAAqB,CAAC,OAAO,GAAG,MAAM,EAAE,UAAU,MAAM,GAC5E,QAAO;AACT,UAAI,UAAU,WAAW,OAAW,QAAO;AAC3C,aAAO,UAAU,SAAS,eAAe,OAAO,GAAG,0BAAM,EAAE,UAAU,MAAM;AAAA,IAC7E,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACF;AASO,MAAM,qBAAqB,OAAO,YAA0B,EAAE,6BAA6B;AAAA,EAChG,OAAO,aAAa;AAAA,EACpB,cAAc,aAAa;AAAA,EAC3B,cAAc,aAAa;AAC7B,CAAC,EAAE;AAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The authenticated identity of one sync request.
|
|
3
|
+
*
|
|
4
|
+
* The principal is a `Context.Reference` whose default is
|
|
5
|
+
* {@link anonymous}, which is what makes the read path fail closed: code
|
|
6
|
+
* that never authenticates runs as anonymous, and the server refuses
|
|
7
|
+
* anonymous access to every non-branch run. The only ways to become the
|
|
8
|
+
* workspace principal are a workspace capability verified by
|
|
9
|
+
* `SyncAuth.layer` at the RPC boundary, or an in-process caller that
|
|
10
|
+
* provides the reference itself — which is the sanctioned path for code
|
|
11
|
+
* already holding the journal, and never for a transport.
|
|
12
|
+
*
|
|
13
|
+
* @since 0.1.0
|
|
14
|
+
*/
|
|
15
|
+
import * as Context from "effect/Context";
|
|
16
|
+
import * as Layer from "effect/Layer";
|
|
17
|
+
/**
|
|
18
|
+
* A request that presented no credential. It may still read branch runs
|
|
19
|
+
* through per-request branch share capabilities.
|
|
20
|
+
*
|
|
21
|
+
* @category models
|
|
22
|
+
* @since 0.1.0
|
|
23
|
+
*/
|
|
24
|
+
export interface Anonymous {
|
|
25
|
+
readonly _tag: "Anonymous";
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A request authenticated for the workspace's non-branch runs.
|
|
29
|
+
* `capabilityId` names the credential for auditing; in-process callers name
|
|
30
|
+
* themselves.
|
|
31
|
+
*
|
|
32
|
+
* @category models
|
|
33
|
+
* @since 0.1.0
|
|
34
|
+
*/
|
|
35
|
+
export interface Workspace {
|
|
36
|
+
readonly _tag: "Workspace";
|
|
37
|
+
readonly capabilityId: string;
|
|
38
|
+
/**
|
|
39
|
+
* When the credential that established this principal stops authorizing,
|
|
40
|
+
* in epoch milliseconds, or `Infinity` for an in-process owner that
|
|
41
|
+
* presented no credential at all.
|
|
42
|
+
*
|
|
43
|
+
* A signed expiry is this package's ONLY revocation mechanism, and an open
|
|
44
|
+
* subscription is not a sequence of requests: it is authorized once, at
|
|
45
|
+
* open, and then streams. Without the expiry on the identity itself,
|
|
46
|
+
* nothing downstream could tell a live subscription to stop, so a holder of
|
|
47
|
+
* an expired capability kept reading for as long as it declined to
|
|
48
|
+
* disconnect.
|
|
49
|
+
*/
|
|
50
|
+
readonly expiresAtMs: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Any authenticated identity a sync request can carry.
|
|
54
|
+
*
|
|
55
|
+
* @category models
|
|
56
|
+
* @since 0.1.0
|
|
57
|
+
*/
|
|
58
|
+
export type Principal = Anonymous | Workspace;
|
|
59
|
+
/**
|
|
60
|
+
* The unauthenticated principal.
|
|
61
|
+
*
|
|
62
|
+
* @category constructors
|
|
63
|
+
* @since 0.1.0
|
|
64
|
+
*/
|
|
65
|
+
export declare const anonymous: Principal;
|
|
66
|
+
/**
|
|
67
|
+
* Constructs the workspace principal for a named credential.
|
|
68
|
+
*
|
|
69
|
+
* `expiresAtMs` defaults to `Infinity`, which is the honest answer for an
|
|
70
|
+
* in-process owner that already holds the journal: it presented no credential,
|
|
71
|
+
* so no credential can expire under it.
|
|
72
|
+
*
|
|
73
|
+
* @category constructors
|
|
74
|
+
* @since 0.1.0
|
|
75
|
+
*/
|
|
76
|
+
export declare const workspace: (capabilityId: string, expiresAtMs?: number) => Principal;
|
|
77
|
+
/**
|
|
78
|
+
* Returns `true` when a principal may read non-branch runs.
|
|
79
|
+
*
|
|
80
|
+
* @category predicates
|
|
81
|
+
* @since 0.1.0
|
|
82
|
+
*/
|
|
83
|
+
export declare const isWorkspace: (principal: Principal) => principal is Workspace;
|
|
84
|
+
/**
|
|
85
|
+
* The current request's principal, defaulting to {@link anonymous}.
|
|
86
|
+
*
|
|
87
|
+
* @category references
|
|
88
|
+
* @since 0.1.0
|
|
89
|
+
*/
|
|
90
|
+
export declare const SyncPrincipal: Context.Reference<Principal>;
|
|
91
|
+
/**
|
|
92
|
+
* Provides the workspace principal directly, bypassing credential
|
|
93
|
+
* verification. For in-process callers that already own the journal — a
|
|
94
|
+
* transport boundary must authenticate through `SyncAuth.layer` instead.
|
|
95
|
+
*
|
|
96
|
+
* @category layers
|
|
97
|
+
* @since 0.1.0
|
|
98
|
+
*/
|
|
99
|
+
export declare const layerWorkspace: (capabilityId: string) => Layer.Layer<never>;
|
|
100
|
+
//# sourceMappingURL=SyncPrincipal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncPrincipal.d.ts","sourceRoot":"","sources":["../../src/SyncPrincipal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAC3B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAC7B;AAED;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;AAE7C;;;;;GAKG;AACH,eAAO,MAAM,SAAS,EAAE,SAAiC,CAAA;AAEzD;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,GACpB,cAAc,MAAM,EACpB,cAAa,MAAiC,KAC7C,SAA+D,CAAA;AAElE;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,WAAW,SAAS,KAAG,SAAS,IAAI,SAA2C,CAAA;AAE3G;;;;;GAKG;AACH,eAAO,MAAM,aAAa,EAAE,OAAO,CAAC,SAAS,CAAC,SAAS,CAGtD,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAAI,cAAc,MAAM,KAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAChB,CAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 SyncPrincipal_exports = {};
|
|
30
|
+
__export(SyncPrincipal_exports, {
|
|
31
|
+
SyncPrincipal: () => SyncPrincipal,
|
|
32
|
+
anonymous: () => anonymous,
|
|
33
|
+
isWorkspace: () => isWorkspace,
|
|
34
|
+
layerWorkspace: () => layerWorkspace,
|
|
35
|
+
workspace: () => workspace
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(SyncPrincipal_exports);
|
|
38
|
+
var Context = __toESM(require("effect/Context"), 1);
|
|
39
|
+
var Layer = __toESM(require("effect/Layer"), 1);
|
|
40
|
+
const anonymous = { _tag: "Anonymous" };
|
|
41
|
+
const workspace = (capabilityId, expiresAtMs = Number.POSITIVE_INFINITY) => ({ _tag: "Workspace", capabilityId, expiresAtMs });
|
|
42
|
+
const isWorkspace = (principal) => principal._tag === "Workspace";
|
|
43
|
+
const SyncPrincipal = Context.Reference(
|
|
44
|
+
"@smthrs/sync/SyncPrincipal",
|
|
45
|
+
{ defaultValue: () => anonymous }
|
|
46
|
+
);
|
|
47
|
+
const layerWorkspace = (capabilityId) => Layer.succeed(SyncPrincipal, workspace(capabilityId));
|
|
48
|
+
//# sourceMappingURL=SyncPrincipal.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/SyncPrincipal.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * The authenticated identity of one sync request.\n *\n * The principal is a `Context.Reference` whose default is\n * {@link anonymous}, which is what makes the read path fail closed: code\n * that never authenticates runs as anonymous, and the server refuses\n * anonymous access to every non-branch run. The only ways to become the\n * workspace principal are a workspace capability verified by\n * `SyncAuth.layer` at the RPC boundary, or an in-process caller that\n * provides the reference itself \u2014 which is the sanctioned path for code\n * already holding the journal, and never for a transport.\n *\n * @since 0.1.0\n */\n\nimport * as Context from \"effect/Context\"\nimport * as Layer from \"effect/Layer\"\n\n/**\n * A request that presented no credential. It may still read branch runs\n * through per-request branch share capabilities.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Anonymous {\n readonly _tag: \"Anonymous\"\n}\n\n/**\n * A request authenticated for the workspace's non-branch runs.\n * `capabilityId` names the credential for auditing; in-process callers name\n * themselves.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Workspace {\n readonly _tag: \"Workspace\"\n readonly capabilityId: string\n /**\n * When the credential that established this principal stops authorizing,\n * in epoch milliseconds, or `Infinity` for an in-process owner that\n * presented no credential at all.\n *\n * A signed expiry is this package's ONLY revocation mechanism, and an open\n * subscription is not a sequence of requests: it is authorized once, at\n * open, and then streams. Without the expiry on the identity itself,\n * nothing downstream could tell a live subscription to stop, so a holder of\n * an expired capability kept reading for as long as it declined to\n * disconnect.\n */\n readonly expiresAtMs: number\n}\n\n/**\n * Any authenticated identity a sync request can carry.\n *\n * @category models\n * @since 0.1.0\n */\nexport type Principal = Anonymous | Workspace\n\n/**\n * The unauthenticated principal.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const anonymous: Principal = { _tag: \"Anonymous\" }\n\n/**\n * Constructs the workspace principal for a named credential.\n *\n * `expiresAtMs` defaults to `Infinity`, which is the honest answer for an\n * in-process owner that already holds the journal: it presented no credential,\n * so no credential can expire under it.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const workspace = (\n capabilityId: string,\n expiresAtMs: number = Number.POSITIVE_INFINITY\n): Principal => ({ _tag: \"Workspace\", capabilityId, expiresAtMs })\n\n/**\n * Returns `true` when a principal may read non-branch runs.\n *\n * @category predicates\n * @since 0.1.0\n */\nexport const isWorkspace = (principal: Principal): principal is Workspace => principal._tag === \"Workspace\"\n\n/**\n * The current request's principal, defaulting to {@link anonymous}.\n *\n * @category references\n * @since 0.1.0\n */\nexport const SyncPrincipal: Context.Reference<Principal> = Context.Reference<Principal>(\n \"@smthrs/sync/SyncPrincipal\",\n { defaultValue: () => anonymous }\n)\n\n/**\n * Provides the workspace principal directly, bypassing credential\n * verification. For in-process callers that already own the journal \u2014 a\n * transport boundary must authenticate through `SyncAuth.layer` instead.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerWorkspace = (capabilityId: string): Layer.Layer<never> =>\n Layer.succeed(SyncPrincipal, workspace(capabilityId))\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,cAAyB;AACzB,YAAuB;AAqDhB,MAAM,YAAuB,EAAE,MAAM,YAAY;AAYjD,MAAM,YAAY,CACvB,cACA,cAAsB,OAAO,uBACd,EAAE,MAAM,aAAa,cAAc,YAAY;AAQzD,MAAM,cAAc,CAAC,cAAiD,UAAU,SAAS;AAQzF,MAAM,gBAA8C,QAAQ;AAAA,EACjE;AAAA,EACA,EAAE,cAAc,MAAM,UAAU;AAClC;AAUO,MAAM,iBAAiB,CAAC,iBAC7B,MAAM,QAAQ,eAAe,UAAU,YAAY,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|