@smthrs/sync 1.0.0-rc.4 → 1.0.0-rc.6
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/README.md +6 -6
- package/dist/cjs/BranchRpcs.d.ts +2 -2
- package/dist/cjs/BranchRpcs.d.ts.map +1 -1
- package/dist/cjs/BranchRpcs.js +1 -1
- package/dist/cjs/BranchRpcs.js.map +2 -2
- package/dist/cjs/BranchServer.d.ts +2 -2
- package/dist/cjs/BranchServer.d.ts.map +1 -1
- package/dist/cjs/BranchServer.js.map +2 -2
- package/dist/cjs/SyncAuth.d.ts +1 -1
- package/dist/cjs/SyncAuth.d.ts.map +1 -1
- package/dist/cjs/SyncAuth.js +5 -5
- package/dist/cjs/SyncAuth.js.map +2 -2
- package/dist/cjs/SyncClient.d.ts +3 -3
- package/dist/cjs/SyncClient.d.ts.map +1 -1
- package/dist/cjs/SyncClient.js +2 -2
- package/dist/cjs/SyncClient.js.map +2 -2
- package/dist/cjs/SyncRpcs.d.ts +2 -2
- package/dist/cjs/SyncRpcs.d.ts.map +1 -1
- package/dist/cjs/SyncRpcs.js +1 -1
- package/dist/cjs/SyncRpcs.js.map +1 -1
- package/dist/cjs/SyncServer.d.ts +2 -2
- package/dist/cjs/SyncServer.d.ts.map +1 -1
- package/dist/cjs/SyncServer.js.map +2 -2
- package/dist/cjs/test/TestSocket.d.ts +1 -1
- package/dist/cjs/test/TestSocket.d.ts.map +1 -1
- package/dist/cjs/test/TestSocket.js +1 -1
- package/dist/cjs/test/TestSocket.js.map +1 -1
- package/dist/cjs/test/TestSync.d.ts +1 -1
- package/dist/cjs/test/TestSync.d.ts.map +1 -1
- package/dist/cjs/test/TestSync.js +6 -6
- package/dist/cjs/test/TestSync.js.map +1 -1
- package/dist/esm/BranchRpcs.d.ts +2 -2
- package/dist/esm/BranchRpcs.d.ts.map +1 -1
- package/dist/esm/BranchRpcs.js +1 -1
- package/dist/esm/BranchRpcs.js.map +1 -1
- package/dist/esm/BranchServer.d.ts +2 -2
- package/dist/esm/BranchServer.d.ts.map +1 -1
- package/dist/esm/BranchServer.js.map +1 -1
- package/dist/esm/SyncAuth.d.ts +1 -1
- package/dist/esm/SyncAuth.d.ts.map +1 -1
- package/dist/esm/SyncAuth.js +5 -5
- package/dist/esm/SyncAuth.js.map +1 -1
- package/dist/esm/SyncClient.d.ts +3 -3
- package/dist/esm/SyncClient.d.ts.map +1 -1
- package/dist/esm/SyncClient.js +2 -2
- package/dist/esm/SyncClient.js.map +1 -1
- package/dist/esm/SyncRpcs.d.ts +2 -2
- package/dist/esm/SyncRpcs.d.ts.map +1 -1
- package/dist/esm/SyncRpcs.js +1 -1
- package/dist/esm/SyncRpcs.js.map +1 -1
- package/dist/esm/SyncServer.d.ts +2 -2
- package/dist/esm/SyncServer.d.ts.map +1 -1
- package/dist/esm/SyncServer.js.map +1 -1
- package/dist/esm/test/TestSocket.d.ts +1 -1
- package/dist/esm/test/TestSocket.d.ts.map +1 -1
- package/dist/esm/test/TestSocket.js +1 -1
- package/dist/esm/test/TestSocket.js.map +1 -1
- package/dist/esm/test/TestSync.d.ts +1 -1
- package/dist/esm/test/TestSync.d.ts.map +1 -1
- package/dist/esm/test/TestSync.js +6 -6
- package/dist/esm/test/TestSync.js.map +1 -1
- package/docs/README.md +2 -2
- package/docs/guides/follow-a-run.md +4 -4
- package/docs/guides/serve-the-read-path.md +1 -1
- package/docs/installation.md +3 -3
- package/package.json +9 -9
- package/src/BranchRpcs.ts +1 -1
- package/src/BranchServer.ts +2 -2
- package/src/SyncAuth.ts +5 -5
- package/src/SyncClient.ts +3 -3
- package/src/SyncRpcs.ts +1 -1
- package/src/SyncServer.ts +2 -2
- package/src/test/TestSocket.ts +1 -1
- package/src/test/TestSync.ts +6 -6
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Release candidate scope, host requirements and compatibility review are defined in the [library support policy](https://github.com/smithersai/smithers/blob/main/RELEASE_SUPPORT.md).
|
|
4
4
|
|
|
5
|
-
This package declares `effect` as
|
|
6
|
-
`
|
|
7
|
-
|
|
5
|
+
This package declares `effect` as a `^4.0.4` peer dependency. Install one
|
|
6
|
+
`effect` release in that range so all Smithers packages share one Effect
|
|
7
|
+
runtime.
|
|
8
8
|
|
|
9
9
|
**Documentation:** https://smithers-sync.smithers.sh
|
|
10
10
|
|
|
@@ -22,7 +22,7 @@ commands to a branch's journal run after verifying a write-scoped
|
|
|
22
22
|
|
|
23
23
|
Not on npm yet; see [Installation](https://github.com/smithersai/smithers/blob/main/packages/smithers/flows/flow/docs/installation.md#use-the-libraries).
|
|
24
24
|
|
|
25
|
-
`effect` is a peer dependency
|
|
25
|
+
`effect` is a peer dependency in the range `^4.0.4`. Two copies of `effect`
|
|
26
26
|
in one program are two sets of service tags, so a client built against one copy
|
|
27
27
|
cannot be provided to a program holding the other.
|
|
28
28
|
|
|
@@ -39,9 +39,9 @@ import type { JournalEvent } from "@smthrs/journal"
|
|
|
39
39
|
import * as SyncClient from "@smthrs/sync/SyncClient"
|
|
40
40
|
import * as Effect from "effect/Effect"
|
|
41
41
|
import * as Layer from "effect/Layer"
|
|
42
|
+
import * as RpcClient from "effect/rpc/RpcClient"
|
|
43
|
+
import * as RpcSerialization from "effect/rpc/RpcSerialization"
|
|
42
44
|
import * as Stream from "effect/Stream"
|
|
43
|
-
import * as RpcClient from "effect/unstable/rpc/RpcClient"
|
|
44
|
-
import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization"
|
|
45
45
|
|
|
46
46
|
const runId = "build-42" as JournalEvent.RunId
|
|
47
47
|
|
package/dist/cjs/BranchRpcs.d.ts
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
*
|
|
15
15
|
* @since 0.1.0
|
|
16
16
|
*/
|
|
17
|
+
import { Rpc, RpcGroup } from "effect/rpc";
|
|
17
18
|
import * as Schema from "effect/Schema";
|
|
18
|
-
import { Rpc, RpcGroup } from "effect/unstable/rpc";
|
|
19
19
|
import { CommandReceipt, Participant, ShareCapability } from "./BranchProtocol.ts";
|
|
20
20
|
import { SyncError } from "./SyncError.ts";
|
|
21
21
|
import { SyncAuth } from "./SyncRpcs.ts";
|
|
@@ -171,7 +171,7 @@ export declare const BranchRpcs: RpcGroup.RpcGroup<Rpc.Rpc<"Branch.CreateBranch"
|
|
|
171
171
|
readonly capability: typeof ShareCapability;
|
|
172
172
|
readonly branchId: Schema.brand<Schema.NonEmptyString, "@smthrs/sync/BranchProtocol/BranchId">;
|
|
173
173
|
readonly sourcesReady: Schema.optionalKey<Schema.Boolean>;
|
|
174
|
-
}>, import("effect/
|
|
174
|
+
}>, import("effect/rpc/RpcSchema").Stream<Schema.Struct<{
|
|
175
175
|
readonly participants: Schema.$Array<typeof Participant>;
|
|
176
176
|
}>, typeof SyncError>, Schema.Never, typeof SyncAuth, never>>;
|
|
177
177
|
//# sourceMappingURL=BranchRpcs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BranchRpcs.d.ts","sourceRoot":"","sources":["../../src/BranchRpcs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"BranchRpcs.d.ts","sourceRoot":"","sources":["../../src/BranchRpcs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAIL,cAAc,EAEd,WAAW,EAEX,eAAe,EAEhB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,QAAsB,CAAA;AAErD;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB;;EAK9B,CAAA;AAEF;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAC,IAAI,CAAA;AAEjE;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;;;EAG/B,CAAA;AAEF;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,OAAO,oBAAoB,CAAC,IAAI,CAAA;AAEnE;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB;;;;EAI3B,CAAA;AAEF;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,gBAAgB,CAAC,IAAI,CAAA;AAE3D;;;;;GAKG;AACH,eAAO,MAAM,WAAW;;EAEtB,CAAA;AAEF;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAA;AAEjD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6DAqBD,CAAA"}
|
package/dist/cjs/BranchRpcs.js
CHANGED
|
@@ -36,8 +36,8 @@ __export(BranchRpcs_exports, {
|
|
|
36
36
|
maximumBranchTtlMs: () => maximumBranchTtlMs
|
|
37
37
|
});
|
|
38
38
|
module.exports = __toCommonJS(BranchRpcs_exports);
|
|
39
|
+
var import_rpc = require("effect/rpc");
|
|
39
40
|
var Schema = __toESM(require("effect/Schema"), 1);
|
|
40
|
-
var import_rpc = require("effect/unstable/rpc");
|
|
41
41
|
var import_BranchProtocol = require("./BranchProtocol.js");
|
|
42
42
|
var import_SyncError = require("./SyncError.js");
|
|
43
43
|
var import_SyncRpcs = require("./SyncRpcs.js");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/BranchRpcs.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * The branch collaboration wire contract: the RPC projection of the write\n * and presence paths that complement the read-only {@link SyncRpcs}.\n *\n * Authorization has two stages. Opening a branch is the bootstrap: no\n * capability can exist yet, so `CreateBranch` requires an authenticated\n * workspace principal supplied by the group's {@link SyncAuth} middleware,\n * and its handler refuses any other principal.\n *\n * Every later procedure carries its own share capability and authorizes\n * through {@link BranchShare}: past the bootstrap the capability IS the\n * credential, and cross-branch or expired capabilities are refused by the\n * same service boundary the in-process callers use.\n *\n * @since 0.1.0\n */\n\nimport
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,aAAwB;AACxB,
|
|
4
|
+
"sourcesContent": ["/**\n * The branch collaboration wire contract: the RPC projection of the write\n * and presence paths that complement the read-only {@link SyncRpcs}.\n *\n * Authorization has two stages. Opening a branch is the bootstrap: no\n * capability can exist yet, so `CreateBranch` requires an authenticated\n * workspace principal supplied by the group's {@link SyncAuth} middleware,\n * and its handler refuses any other principal.\n *\n * Every later procedure carries its own share capability and authorizes\n * through {@link BranchShare}: past the bootstrap the capability IS the\n * credential, and cross-branch or expired capabilities are refused by the\n * same service boundary the in-process callers use.\n *\n * @since 0.1.0\n */\n\nimport { Rpc, RpcGroup } from \"effect/rpc\"\nimport * as Schema from \"effect/Schema\"\nimport {\n Access,\n Announcement,\n BranchId,\n CommandReceipt,\n LeaveRequest,\n Participant,\n RosterRequest,\n ShareCapability,\n SubmitRequest\n} from \"./BranchProtocol.ts\"\nimport { SyncError } from \"./SyncError.ts\"\nimport { SyncAuth } from \"./SyncRpcs.ts\"\n\n/**\n * Maximum lifetime the branch bootstrap may mint.\n *\n * @category constants\n * @since 0.1.0\n */\nexport const maximumBranchTtlMs = 24 * 60 * 60 * 1000\n\n/**\n * Schema for a request to open a new shared branch.\n *\n * The RPC authentication middleware must establish the workspace principal\n * before the handler mints the first write capability.\n *\n * @category schemas\n * @since 0.1.0\n */\nexport const CreateBranchPayload = Schema.Struct({\n ttlMs: Schema.Int.check(\n Schema.isGreaterThan(0),\n Schema.isLessThanOrEqualTo(maximumBranchTtlMs)\n )\n})\n\n/**\n * A request to open a new shared branch.\n *\n * @category models\n * @since 0.1.0\n */\nexport type CreateBranchPayload = typeof CreateBranchPayload.Type\n\n/**\n * Schema for the freshly opened branch and its owner capability.\n *\n * @category schemas\n * @since 0.1.0\n */\nexport const CreateBranchResponse = Schema.Struct({\n branchId: BranchId,\n capability: ShareCapability\n})\n\n/**\n * The freshly opened branch and its owner capability.\n *\n * @category models\n * @since 0.1.0\n */\nexport type CreateBranchResponse = typeof CreateBranchResponse.Type\n\n/**\n * Schema for a request to mint a share link for a branch.\n *\n * The presenting capability must hold write access to the branch \u2014 only a\n * collaborator can invite one \u2014 and the minted link never outlives the\n * capability it was minted from.\n *\n * @category schemas\n * @since 0.1.0\n */\nexport const MintSharePayload = Schema.Struct({\n capability: ShareCapability,\n access: Access,\n ttlMs: Schema.Int.check(Schema.isGreaterThan(0))\n})\n\n/**\n * A request to mint a share link for a branch.\n *\n * @category models\n * @since 0.1.0\n */\nexport type MintSharePayload = typeof MintSharePayload.Type\n\n/**\n * Schema for one roster emission on a branch watch stream.\n *\n * @category schemas\n * @since 0.1.0\n */\nexport const RosterFrame = Schema.Struct({\n participants: Schema.Array(Participant)\n})\n\n/**\n * One roster emission on a branch watch stream.\n *\n * @category models\n * @since 0.1.0\n */\nexport type RosterFrame = typeof RosterFrame.Type\n\n/**\n * The remote procedures of branch collaboration.\n *\n * The capability-bearing payloads ARE the `BranchProtocol` request schemas the\n * branch services take, not copies of them. Four wire payloads used to\n * re-declare the message their service already owned, and the announce copy\n * had already drifted: it accepted `displayName: \"\"` where the service\n * requires a non-empty name, so a wire-legal announce reached a `Participant`\n * constructor and threw a defect outside the declared `SyncError` channel.\n * Naming one schema on both sides makes that drift impossible rather than\n * fixed once, and keeps this group free of the services themselves.\n *\n * @category groups\n * @since 0.1.0\n */\nexport const BranchRpcs = RpcGroup.make(\n Rpc.make(\"Branch.CreateBranch\", {\n payload: CreateBranchPayload,\n success: CreateBranchResponse,\n error: SyncError\n }),\n Rpc.make(\"Branch.MintShare\", { payload: MintSharePayload, success: ShareCapability, error: SyncError }),\n Rpc.make(\"Branch.Submit\", { payload: SubmitRequest, success: CommandReceipt, error: SyncError }),\n Rpc.make(\"Branch.Announce\", { payload: Announcement, success: Participant, error: SyncError }),\n Rpc.make(\"Branch.Leave\", { payload: LeaveRequest, success: Schema.Null, error: SyncError }),\n Rpc.make(\"Branch.Roster\", {\n payload: RosterRequest,\n success: Schema.Array(Participant),\n error: SyncError\n }),\n Rpc.make(\"Branch.PresenceOn\", {\n payload: RosterRequest,\n success: Schema.Literals([\"unknown\", \"present\", \"empty\"]),\n error: SyncError\n }),\n Rpc.make(\"Branch.WatchRoster\", { payload: RosterRequest, success: RosterFrame, error: SyncError, stream: true })\n).middleware(SyncAuth)\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,iBAA8B;AAC9B,aAAwB;AACxB,4BAUO;AACP,uBAA0B;AAC1B,sBAAyB;AAQlB,MAAM,qBAAqB,KAAK,KAAK,KAAK;AAW1C,MAAM,sBAAsB,OAAO,OAAO;AAAA,EAC/C,OAAO,OAAO,IAAI;AAAA,IAChB,OAAO,cAAc,CAAC;AAAA,IACtB,OAAO,oBAAoB,kBAAkB;AAAA,EAC/C;AACF,CAAC;AAgBM,MAAM,uBAAuB,OAAO,OAAO;AAAA,EAChD,UAAU;AAAA,EACV,YAAY;AACd,CAAC;AAoBM,MAAM,mBAAmB,OAAO,OAAO;AAAA,EAC5C,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,OAAO,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,CAAC;AACjD,CAAC;AAgBM,MAAM,cAAc,OAAO,OAAO;AAAA,EACvC,cAAc,OAAO,MAAM,iCAAW;AACxC,CAAC;AAyBM,MAAM,aAAa,oBAAS;AAAA,EACjC,eAAI,KAAK,uBAAuB;AAAA,IAC9B,SAAS;AAAA,IACT,SAAS;AAAA,IACT,OAAO;AAAA,EACT,CAAC;AAAA,EACD,eAAI,KAAK,oBAAoB,EAAE,SAAS,kBAAkB,SAAS,uCAAiB,OAAO,2BAAU,CAAC;AAAA,EACtG,eAAI,KAAK,iBAAiB,EAAE,SAAS,qCAAe,SAAS,sCAAgB,OAAO,2BAAU,CAAC;AAAA,EAC/F,eAAI,KAAK,mBAAmB,EAAE,SAAS,oCAAc,SAAS,mCAAa,OAAO,2BAAU,CAAC;AAAA,EAC7F,eAAI,KAAK,gBAAgB,EAAE,SAAS,oCAAc,SAAS,OAAO,MAAM,OAAO,2BAAU,CAAC;AAAA,EAC1F,eAAI,KAAK,iBAAiB;AAAA,IACxB,SAAS;AAAA,IACT,SAAS,OAAO,MAAM,iCAAW;AAAA,IACjC,OAAO;AAAA,EACT,CAAC;AAAA,EACD,eAAI,KAAK,qBAAqB;AAAA,IAC5B,SAAS;AAAA,IACT,SAAS,OAAO,SAAS,CAAC,WAAW,WAAW,OAAO,CAAC;AAAA,IACxD,OAAO;AAAA,EACT,CAAC;AAAA,EACD,eAAI,KAAK,sBAAsB,EAAE,SAAS,qCAAe,SAAS,aAAa,OAAO,4BAAW,QAAQ,KAAK,CAAC;AACjH,EAAE,WAAW,wBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
* @since 0.1.0
|
|
17
17
|
*/
|
|
18
18
|
import type * as Layer from "effect/Layer";
|
|
19
|
-
import type * as Rpc from "effect/
|
|
20
|
-
import type * as RpcGroup from "effect/
|
|
19
|
+
import type * as Rpc from "effect/rpc/Rpc";
|
|
20
|
+
import type * as RpcGroup from "effect/rpc/RpcGroup";
|
|
21
21
|
import * as BranchCommands from "./BranchCommands.ts";
|
|
22
22
|
import * as BranchIds from "./BranchIds.ts";
|
|
23
23
|
import * as BranchPresence from "./BranchPresence.ts";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BranchServer.d.ts","sourceRoot":"","sources":["../../src/BranchServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"BranchServer.d.ts","sourceRoot":"","sources":["../../src/BranchServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,KAAK,GAAG,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAEpD,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAwC/C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,KAAK,CACrC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC,CAAC,EAC/C,KAAK,EACH,WAAW,CAAC,WAAW,GACvB,cAAc,CAAC,cAAc,GAC7B,cAAc,CAAC,cAAc,GAC7B,SAAS,CAAC,SAAS,CAkGtB,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/BranchServer.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * The server-side handlers of {@link BranchRpcs}: a thin projection of the\n * branch services onto the wire.\n *\n * Five procedures forward to the service that owns their boundary and add\n * nothing: `Branch.Submit` to {@link BranchCommands}, and `Branch.Announce`,\n * `Branch.Leave`, `Branch.Roster`, and `Branch.WatchRoster` to\n * {@link BranchPresence}. Two enforce policy here, on top of what\n * {@link BranchShare} checks: `Branch.CreateBranch` refuses any principal that\n * is not an authenticated workspace, and `Branch.MintShare` verifies write\n * access, refuses an expired parent, and caps the child at the parent's\n * expiry. `BranchShare.mint` performs none of those checks, so an in-process\n * host that mints through the service directly must gate the principal and\n * the parent capability itself.\n *\n * @since 0.1.0\n */\n\nimport * as Clock from \"effect/Clock\"\nimport * as Effect from \"effect/Effect\"\nimport type * as Layer from \"effect/Layer\"\nimport * as
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,YAAuB;AACvB,aAAwB;
|
|
4
|
+
"sourcesContent": ["/**\n * The server-side handlers of {@link BranchRpcs}: a thin projection of the\n * branch services onto the wire.\n *\n * Five procedures forward to the service that owns their boundary and add\n * nothing: `Branch.Submit` to {@link BranchCommands}, and `Branch.Announce`,\n * `Branch.Leave`, `Branch.Roster`, and `Branch.WatchRoster` to\n * {@link BranchPresence}. Two enforce policy here, on top of what\n * {@link BranchShare} checks: `Branch.CreateBranch` refuses any principal that\n * is not an authenticated workspace, and `Branch.MintShare` verifies write\n * access, refuses an expired parent, and caps the child at the parent's\n * expiry. `BranchShare.mint` performs none of those checks, so an in-process\n * host that mints through the service directly must gate the principal and\n * the parent capability itself.\n *\n * @since 0.1.0\n */\n\nimport * as Clock from \"effect/Clock\"\nimport * as Effect from \"effect/Effect\"\nimport type * as Layer from \"effect/Layer\"\nimport type * as Rpc from \"effect/rpc/Rpc\"\nimport type * as RpcGroup from \"effect/rpc/RpcGroup\"\nimport * as Stream from \"effect/Stream\"\nimport * as BranchCommands from \"./BranchCommands.ts\"\nimport * as BranchIds from \"./BranchIds.ts\"\nimport * as BranchPresence from \"./BranchPresence.ts\"\nimport { BranchId, type Participant } from \"./BranchProtocol.ts\"\nimport { BranchRpcs } from \"./BranchRpcs.ts\"\nimport * as BranchShare from \"./BranchShare.ts\"\nimport * as Admission from \"./internal/Admission.ts\"\nimport { SyncError } from \"./SyncError.ts\"\nimport * as SyncPrincipal from \"./SyncPrincipal.ts\"\n\n/**\n * Whether two roster emissions say the same thing.\n *\n * `list` returns participants sorted by id, so the comparison is positional.\n * The lease itself is part of the key: a heartbeat that only extends a lease\n * IS a change the watcher wants, because it is the evidence the participant is\n * still there.\n *\n * The rendering is JSON rather than delimiter-joined fields. Participant ids\n * and display names are `NonEmptyString` with no charset constraint, so every\n * separator is a character they may carry, including the control bytes this\n * used to join on. Two rosters differing only in where a field boundary falls\n * then rendered identically and a watcher never observed the change. JSON\n * quotes and escapes each field, so distinct rosters render distinctly.\n */\nconst rosterKey = (participants: ReadonlyArray<Participant>): string =>\n JSON.stringify(\n participants.map((participant) => [\n participant.participantId,\n participant.displayName,\n participant.sessionId,\n participant.kind,\n participant.where,\n participant.watching,\n participant.for_member,\n participant.leaseExpiresAtMs,\n participant.cursor === null ? null : [participant.cursor.cardId, participant.cursor.offset]\n ])\n )\n\nconst sameRoster = (\n left: ReadonlyArray<Participant>,\n right: ReadonlyArray<Participant>\n): boolean => rosterKey(left) === rosterKey(right)\n\n/**\n * Provides the branch RPC handlers over the branch services.\n *\n * With {@link BranchPresence.layerNoop}, roster reads and watches fail with\n * `unsupported`: unavailable presence cannot establish an empty roster.\n *\n * A roster watch emits the roster as of subscription, then re-lists on every\n * presence change for the branch AND at least once per second, emitting\n * only when the roster it read differs from the one it last sent.\n *\n * All three of those are triggers into ONE sequential reader. The roster is\n * mutable state behind an effect, so concurrent readers can complete out of\n * order, and a watcher that receives an older roster after a newer one keeps\n * the older one: `changesWith` compares against the previous emission, not\n * against the freshest state. Serializing the reads is what makes the last\n * value a watcher holds the most recent one that was read.\n *\n * The periodic re-list is what makes expiry observable. A lapsed lease\n * publishes nothing \u2014 the roster drops it the next time somebody lists \u2014 so a\n * watch driven by change events alone never saw the LAST participant leave,\n * and a burst of announcements on unrelated branches could slide the one\n * notification this watch needed out of the shared feed. Both are bounded by\n * one second: a departure is visible within 1 s of lease expiry,\n * whether or not a survivor reports it.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerHandlers: Layer.Layer<\n Rpc.ToHandler<RpcGroup.Rpcs<typeof BranchRpcs>>,\n never,\n | BranchShare.BranchShare\n | BranchPresence.BranchPresence\n | BranchCommands.BranchCommands\n | BranchIds.BranchIds\n> = BranchRpcs.toLayer(\n Effect.gen(function*() {\n const share = yield* BranchShare.BranchShare\n const presence = yield* BranchPresence.BranchPresence\n const commands = yield* BranchCommands.BranchCommands\n const ids = yield* BranchIds.BranchIds\n\n return BranchRpcs.of({\n \"Branch.CreateBranch\": ({ ttlMs }) =>\n Effect.gen(function*() {\n const principal = yield* SyncPrincipal.SyncPrincipal\n if (!SyncPrincipal.isWorkspace(principal)) {\n return yield* new SyncError({\n code: \"unauthorized\",\n message: \"Creating a branch requires an authenticated workspace principal\"\n })\n }\n // Decoded, not branded: `BranchIds` is a host port whose `fresh` is\n // typed `Effect<string>`, so a host id source yielding \"\" turned an\n // asserted `BranchId` into a schema defect inside `mint` rather than\n // the `SyncError` this handler declares.\n const branchId = yield* Admission.decode(BranchId, yield* ids.fresh, \"invalid_request\")\n const capability = yield* share.mint({\n branchId,\n capabilityId: yield* ids.fresh,\n access: \"write\",\n ttlMs\n })\n return { branchId: capability.claims.branchId, capability }\n }),\n \"Branch.MintShare\": ({ capability, access, ttlMs }) =>\n Effect.gen(function*() {\n const claims = yield* share.verify(capability, {\n branchId: capability.claims.branchId,\n access: \"write\"\n })\n const capabilityId = yield* ids.fresh\n const nowMs = yield* Clock.currentTimeMillis\n // ID generation may outlast the parent. Refuse before minting, and\n // pass the absolute ceiling so the signing clock cannot extend it.\n if (nowMs >= claims.expiresAtMs) {\n return yield* new SyncError({\n code: \"unauthorized\",\n message: \"The share capability has expired\"\n })\n }\n // A link never outlives the capability it was minted from.\n return yield* share.mint({\n branchId: claims.branchId,\n capabilityId,\n access,\n ttlMs,\n maxExpiresAtMs: claims.expiresAtMs\n })\n }),\n \"Branch.Submit\": (payload) => commands.submit(payload),\n \"Branch.Announce\": (payload) => presence.announce(payload),\n \"Branch.Leave\": (payload) => Effect.as(presence.leave(payload), null),\n \"Branch.Roster\": (payload) => presence.list(payload),\n \"Branch.PresenceOn\": (payload) => presence.presenceOn(payload),\n \"Branch.WatchRoster\": (payload) =>\n Stream.merge(\n // The subscription's own snapshot is a TRIGGER like the other two,\n // not a fourth reader. Reading it here concurrently with them let\n // the roster a change produced overtake it: `presence.list` is an\n // effect against mutable state, three of them ran at once, and the\n // slowest one won the merge. `changesWith` compares an emission only\n // against the one before it, so the older roster passed the filter\n // and the watcher's LAST value said a participant who had already\n // left was still present, until the next change or lease tick.\n Stream.succeed(undefined),\n Stream.merge(\n presence.changes.pipe(\n Stream.filter((branchId) => branchId === payload.branchId),\n Stream.map(() => undefined)\n ),\n // A lapsed lease publishes nothing, so a watch driven only by\n // change events never observes the LAST participant leaving, and\n // an unrelated branch's burst can slide the one notification this\n // watch needed out of the shared feed. Re-listing at least once per second\n // bounds both: a departure is visible within 1 s of expiry, whether or not anyone reports it.\n Stream.fromEffectRepeat(Effect.sleep(Math.min(presence.leaseMs, 1_000))).pipe(Stream.map(() => undefined))\n )\n ).pipe(\n // ONE reader, sequential by default, so a roster is read in the\n // order its trigger arrived and every emission is at least as fresh\n // as the one before it.\n Stream.mapEffect(() => presence.list(payload)),\n // Deduplicated over the WHOLE stream, initial emission included.\n // Applied to the change half alone, its first value always passed,\n // so a change that left the roster identical still sent the watcher\n // a second copy of what it had just been given.\n Stream.changesWith(sameRoster),\n Stream.map((participants) => ({ participants }))\n )\n })\n })\n)\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,YAAuB;AACvB,aAAwB;AAIxB,aAAwB;AACxB,qBAAgC;AAChC,gBAA2B;AA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AIA,OAAO,UAAU,MAAM,SAAS,KAAK,OAAO,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,QAK7C,OAAO,YAAY,UAAU;AAAA,QAC7B,OAAO,IAAI,CAAC,kBAAkB,EAAE,aAAa,EAAE;AAAA,MACjD;AAAA,IACJ,CAAC;AAAA,EACH,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/SyncAuth.d.ts
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import * as Effect from "effect/Effect";
|
|
23
23
|
import * as Layer from "effect/Layer";
|
|
24
|
-
import * as RpcMiddleware from "effect/
|
|
24
|
+
import * as RpcMiddleware from "effect/rpc/RpcMiddleware";
|
|
25
25
|
import { SyncError } from "./SyncError.ts";
|
|
26
26
|
import { SyncAuth } from "./SyncRpcs.ts";
|
|
27
27
|
import * as WorkspaceShare from "./WorkspaceShare.ts";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyncAuth.d.ts","sourceRoot":"","sources":["../../src/SyncAuth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"SyncAuth.d.ts","sourceRoot":"","sources":["../../src/SyncAuth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,aAAa,MAAM,0BAA0B,CAAA;AAIzD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,yBAAyB,CAAA;AAItD;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAC3B,YAAY,cAAc,CAAC,mBAAmB,KAC7C,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAajC,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,KAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,mBAAmB,EAAE,SAAS,CAe3G,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,cAAc,CAAC,cAAc,CAyB7E,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GACtB,YAAY,cAAc,CAAC,mBAAmB,KAC7C,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,SAAS,CAKxD,CAAA"}
|
package/dist/cjs/SyncAuth.js
CHANGED
|
@@ -36,12 +36,12 @@ __export(SyncAuth_exports, {
|
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(SyncAuth_exports);
|
|
38
38
|
var Effect = __toESM(require("effect/Effect"), 1);
|
|
39
|
-
var
|
|
39
|
+
var Base64Url = __toESM(require("effect/encoding/Base64Url"), 1);
|
|
40
|
+
var Headers = __toESM(require("effect/http/Headers"), 1);
|
|
40
41
|
var Layer = __toESM(require("effect/Layer"), 1);
|
|
41
42
|
var Result = __toESM(require("effect/Result"), 1);
|
|
43
|
+
var RpcMiddleware = __toESM(require("effect/rpc/RpcMiddleware"), 1);
|
|
42
44
|
var Schema = __toESM(require("effect/Schema"), 1);
|
|
43
|
-
var Headers = __toESM(require("effect/unstable/http/Headers"), 1);
|
|
44
|
-
var RpcMiddleware = __toESM(require("effect/unstable/rpc/RpcMiddleware"), 1);
|
|
45
45
|
var import_CauseText = require("./internal/CauseText.js");
|
|
46
46
|
var shareSigner = __toESM(require("./internal/ShareSigner.js"), 1);
|
|
47
47
|
var import_SyncError = require("./SyncError.js");
|
|
@@ -60,10 +60,10 @@ const encodeCapability = (capability) => {
|
|
|
60
60
|
// carries the value it rejected, and the value here is a credential.
|
|
61
61
|
cause: (0, import_CauseText.causeText)(encoded.failure)
|
|
62
62
|
})
|
|
63
|
-
) : Effect.succeed(
|
|
63
|
+
) : Effect.succeed(Base64Url.encode(JSON.stringify(encoded.success)));
|
|
64
64
|
};
|
|
65
65
|
const decodeCapability = (value) => {
|
|
66
|
-
const text =
|
|
66
|
+
const text = Base64Url.decodeString(value);
|
|
67
67
|
if (Result.isFailure(text)) {
|
|
68
68
|
return Effect.fail(denied("The workspace capability header is not a capability"));
|
|
69
69
|
}
|
package/dist/cjs/SyncAuth.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/SyncAuth.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * The sync read path's connection authentication: implementations of the\n * `SyncRpcs.SyncAuth` RPC middleware.\n *\n * A connection presents a {@link WorkspaceShare.WorkspaceCapability} in the\n * {@link capabilityHeader} request header. {@link layer} verifies it against\n * the workspace's {@link WorkspaceShare.WorkspaceShare} authority and runs\n * the handler as the workspace principal. A request with no header runs as\n * the anonymous principal \u2014 branch share capabilities carried in request\n * payloads still authorize branch reads \u2014 and the server refuses anonymous\n * access to every non-branch run. A request whose header is present but\n * malformed, forged, expired, or signed by an unknown key is refused\n * outright: presence of a credential is a claim, and a false claim is never\n * downgraded to anonymity.\n *\n * There is deliberately no trusted pass-through implementation here: the only\n * sanctioned bypass is an in-process caller providing `SyncPrincipal` itself,\n * never a transport.\n *\n * @since 0.1.0\n */\n\nimport * as Effect from \"effect/Effect\"\nimport * as
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBA,aAAwB;AACxB,
|
|
4
|
+
"sourcesContent": ["/**\n * The sync read path's connection authentication: implementations of the\n * `SyncRpcs.SyncAuth` RPC middleware.\n *\n * A connection presents a {@link WorkspaceShare.WorkspaceCapability} in the\n * {@link capabilityHeader} request header. {@link layer} verifies it against\n * the workspace's {@link WorkspaceShare.WorkspaceShare} authority and runs\n * the handler as the workspace principal. A request with no header runs as\n * the anonymous principal \u2014 branch share capabilities carried in request\n * payloads still authorize branch reads \u2014 and the server refuses anonymous\n * access to every non-branch run. A request whose header is present but\n * malformed, forged, expired, or signed by an unknown key is refused\n * outright: presence of a credential is a claim, and a false claim is never\n * downgraded to anonymity.\n *\n * There is deliberately no trusted pass-through implementation here: the only\n * sanctioned bypass is an in-process caller providing `SyncPrincipal` itself,\n * never a transport.\n *\n * @since 0.1.0\n */\n\nimport * as Effect from \"effect/Effect\"\nimport * as Base64Url from \"effect/encoding/Base64Url\"\nimport * as Headers from \"effect/http/Headers\"\nimport * as Layer from \"effect/Layer\"\nimport * as Result from \"effect/Result\"\nimport * as RpcMiddleware from \"effect/rpc/RpcMiddleware\"\nimport * as Schema from \"effect/Schema\"\nimport { causeText } from \"./internal/CauseText.ts\"\nimport * as shareSigner from \"./internal/ShareSigner.ts\"\nimport { SyncError } from \"./SyncError.ts\"\nimport * as SyncPrincipal from \"./SyncPrincipal.ts\"\nimport { SyncAuth } from \"./SyncRpcs.ts\"\nimport * as WorkspaceShare from \"./WorkspaceShare.ts\"\n\n/**\n * The request header a connection presents its workspace capability in.\n *\n * @category constants\n * @since 0.1.0\n */\nexport const capabilityHeader = \"flows-sync-workspace\"\n\nconst denied = shareSigner.unauthorized\n\n/**\n * Renders a workspace capability as its header value: unpadded base64url of\n * the schema-encoded capability JSON.\n *\n * @category encoding\n * @since 0.1.0\n */\nexport const encodeCapability = (\n capability: WorkspaceShare.WorkspaceCapability\n): Effect.Effect<string, SyncError> => {\n const encoded = Schema.encodeUnknownResult(WorkspaceShare.WorkspaceCapability)(capability)\n return Result.isFailure(encoded)\n ? Effect.fail(\n new SyncError({\n code: \"invalid_request\",\n message: \"The workspace capability does not encode\",\n // The rendering, never the parse failure itself: a schema issue\n // carries the value it rejected, and the value here is a credential.\n cause: causeText(encoded.failure)\n })\n )\n : Effect.succeed(Base64Url.encode(JSON.stringify(encoded.success)))\n}\n\n/**\n * Decodes a capability header value. Every malformation folds to the same\n * `unauthorized` refusal so the header is not a parsing oracle.\n *\n * @category encoding\n * @since 0.1.0\n */\nexport const decodeCapability = (value: string): Effect.Effect<WorkspaceShare.WorkspaceCapability, SyncError> => {\n const text = Base64Url.decodeString(value)\n if (Result.isFailure(text)) {\n return Effect.fail(denied(\"The workspace capability header is not a capability\"))\n }\n let parsed: unknown\n try {\n parsed = JSON.parse(text.success)\n } catch {\n return Effect.fail(denied(\"The workspace capability header is not a capability\"))\n }\n const decoded = Schema.decodeUnknownResult(WorkspaceShare.WorkspaceCapability)(parsed)\n return Result.isFailure(decoded)\n ? Effect.fail(denied(\"The workspace capability header is not a capability\"))\n : Effect.succeed(decoded.success)\n}\n\n/**\n * Provides the workspace-capability authentication middleware: no header\n * runs the handler as anonymous, a verified header runs it as the workspace\n * principal, and anything else refuses the request. Verification faults\n * (Web Crypto failing) propagate as their own error rather than as a\n * refusal.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layer: Layer.Layer<SyncAuth, never, WorkspaceShare.WorkspaceShare> = Layer.effect(\n SyncAuth,\n Effect.gen(function*() {\n const share = yield* WorkspaceShare.WorkspaceShare\n const middleware: RpcMiddleware.RpcMiddleware<never, SyncError, never> = (effect, options) => {\n const header = Headers.get(options.headers, capabilityHeader)\n if (header._tag === \"None\") {\n return Effect.provideService(effect, SyncPrincipal.SyncPrincipal, SyncPrincipal.anonymous)\n }\n return decodeCapability(header.value).pipe(\n Effect.flatMap((capability) => share.verify(capability, { access: \"read\" })),\n Effect.flatMap((claims) =>\n Effect.provideService(\n effect,\n SyncPrincipal.SyncPrincipal,\n // The signed expiry travels WITH the identity. A handler that\n // opens a stream authorizes once; reducing the verified claims to\n // a capability id here left the stream with nothing to expire on.\n SyncPrincipal.workspace(claims.capabilityId, claims.expiresAtMs)\n )\n )\n )\n }\n return middleware\n })\n)\n\n/**\n * Stamps every outgoing request from a generated RPC client with the given\n * workspace capability.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerClient = (\n capability: WorkspaceShare.WorkspaceCapability\n): Layer.Layer<RpcMiddleware.ForClient<SyncAuth>, SyncError> =>\n RpcMiddleware.layerClient(\n SyncAuth,\n Effect.map(encodeCapability(capability), (header) => ({ next, request }) =>\n next({ ...request, headers: Headers.set(request.headers, capabilityHeader, header) }))\n )\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBA,aAAwB;AACxB,gBAA2B;AAC3B,cAAyB;AACzB,YAAuB;AACvB,aAAwB;AACxB,oBAA+B;AAC/B,aAAwB;AACxB,uBAA0B;AAC1B,kBAA6B;AAC7B,uBAA0B;AAC1B,oBAA+B;AAC/B,sBAAyB;AACzB,qBAAgC;AAQzB,MAAM,mBAAmB;AAEhC,MAAM,SAAS,YAAY;AASpB,MAAM,mBAAmB,CAC9B,eACqC;AACrC,QAAM,UAAU,OAAO,oBAAoB,eAAe,mBAAmB,EAAE,UAAU;AACzF,SAAO,OAAO,UAAU,OAAO,IAC3B,OAAO;AAAA,IACP,IAAI,2BAAU;AAAA,MACZ,MAAM;AAAA,MACN,SAAS;AAAA;AAAA;AAAA,MAGT,WAAO,4BAAU,QAAQ,OAAO;AAAA,IAClC,CAAC;AAAA,EACH,IACE,OAAO,QAAQ,UAAU,OAAO,KAAK,UAAU,QAAQ,OAAO,CAAC,CAAC;AACtE;AASO,MAAM,mBAAmB,CAAC,UAAgF;AAC/G,QAAM,OAAO,UAAU,aAAa,KAAK;AACzC,MAAI,OAAO,UAAU,IAAI,GAAG;AAC1B,WAAO,OAAO,KAAK,OAAO,qDAAqD,CAAC;AAAA,EAClF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|
@@ -7,10 +7,10 @@ import type * as JournalEvent from "@smthrs/journal/JournalEvent";
|
|
|
7
7
|
import * as Context from "effect/Context";
|
|
8
8
|
import * as Effect from "effect/Effect";
|
|
9
9
|
import * as Layer from "effect/Layer";
|
|
10
|
+
import * as RpcClient from "effect/rpc/RpcClient";
|
|
11
|
+
import * as RpcClientError from "effect/rpc/RpcClientError";
|
|
12
|
+
import type * as RpcGroup from "effect/rpc/RpcGroup";
|
|
10
13
|
import * as Stream from "effect/Stream";
|
|
11
|
-
import * as RpcClient from "effect/unstable/rpc/RpcClient";
|
|
12
|
-
import * as RpcClientError from "effect/unstable/rpc/RpcClientError";
|
|
13
|
-
import type * as RpcGroup from "effect/unstable/rpc/RpcGroup";
|
|
14
14
|
import type { ShareCapability } from "./BranchProtocol.ts";
|
|
15
15
|
import { SyncError, SyncGapError } from "./SyncError.ts";
|
|
16
16
|
import { type Progress, type Resync, RunCursor, type Scope, type Snapshot, type SnapshotRequest, type WorkspaceCursor } from "./SyncProtocol.ts";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyncClient.d.ts","sourceRoot":"","sources":["../../src/SyncClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,KAAK,YAAY,MAAM,8BAA8B,CAAA;AAEjE,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"SyncClient.d.ts","sourceRoot":"","sources":["../../src/SyncClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,KAAK,YAAY,MAAM,8BAA8B,CAAA;AAEjE,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,SA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C,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,QAAQ,CAAC,EAAE,cAAc,CAAC,cAAc,CAAC,CAAA;AA2LhG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,IAAI,GAAI,YAAY;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,KAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAA8B,CAAA;AAElH;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,QAAQ,GAAI,2CAItB,OAAO,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,KAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,CAYxE,CAAA;AAkXH;;;;;GAKG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,EAAE,SAAS,CAAC,QAAQ,CAGpE,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,GAAI,SAAS,OAAO,KAAG,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,SAAS,EAAE,SAAS,CAAC,QAAQ,CACgB,CAAA"}
|
package/dist/cjs/SyncClient.js
CHANGED
|
@@ -45,11 +45,11 @@ var Context = __toESM(require("effect/Context"), 1);
|
|
|
45
45
|
var Effect = __toESM(require("effect/Effect"), 1);
|
|
46
46
|
var Layer = __toESM(require("effect/Layer"), 1);
|
|
47
47
|
var Ref = __toESM(require("effect/Ref"), 1);
|
|
48
|
+
var RpcClient = __toESM(require("effect/rpc/RpcClient"), 1);
|
|
49
|
+
var RpcClientError = __toESM(require("effect/rpc/RpcClientError"), 1);
|
|
48
50
|
var Schedule = __toESM(require("effect/Schedule"), 1);
|
|
49
51
|
var Schema = __toESM(require("effect/Schema"), 1);
|
|
50
52
|
var Stream = __toESM(require("effect/Stream"), 1);
|
|
51
|
-
var RpcClient = __toESM(require("effect/unstable/rpc/RpcClient"), 1);
|
|
52
|
-
var RpcClientError = __toESM(require("effect/unstable/rpc/RpcClientError"), 1);
|
|
53
53
|
var Admission = __toESM(require("./internal/Admission.js"), 1);
|
|
54
54
|
var import_CauseText = require("./internal/CauseText.js");
|
|
55
55
|
var import_PolicyOptions = require("./internal/PolicyOptions.js");
|