@eloxiv/client 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +6 -2
- package/dist/Account.d.ts +131 -0
- package/dist/Account.d.ts.map +1 -0
- package/dist/Account.js +169 -0
- package/dist/Account.js.map +1 -0
- package/dist/Agent.d.ts +496 -0
- package/dist/Agent.d.ts.map +1 -0
- package/dist/Agent.js +228 -0
- package/dist/Agent.js.map +1 -0
- package/dist/AgentSync.d.ts +990 -0
- package/dist/AgentSync.d.ts.map +1 -0
- package/dist/AgentSync.js +46 -0
- package/dist/AgentSync.js.map +1 -0
- package/dist/AppState.d.ts +127 -0
- package/dist/AppState.d.ts.map +1 -0
- package/dist/AppState.js +145 -0
- package/dist/AppState.js.map +1 -0
- package/dist/AppStateSync.d.ts +193 -0
- package/dist/AppStateSync.d.ts.map +1 -0
- package/dist/AppStateSync.js +23 -0
- package/dist/AppStateSync.js.map +1 -0
- package/dist/Auth.d.ts +95 -0
- package/dist/Auth.d.ts.map +1 -0
- package/dist/Auth.js +139 -0
- package/dist/Auth.js.map +1 -0
- package/dist/Avatars.d.ts +53 -0
- package/dist/Avatars.d.ts.map +1 -0
- package/dist/Avatars.js +121 -0
- package/dist/Avatars.js.map +1 -0
- package/dist/BrowserAnalytics.d.ts +56 -0
- package/dist/BrowserAnalytics.d.ts.map +1 -0
- package/dist/BrowserAnalytics.js +94 -0
- package/dist/BrowserAnalytics.js.map +1 -0
- package/dist/Chat.d.ts +712 -0
- package/dist/Chat.d.ts.map +1 -0
- package/dist/Chat.js +883 -0
- package/dist/Chat.js.map +1 -0
- package/dist/ChatIntegrity.d.ts +63 -0
- package/dist/ChatIntegrity.d.ts.map +1 -0
- package/dist/ChatIntegrity.js +89 -0
- package/dist/ChatIntegrity.js.map +1 -0
- package/dist/ChatSends.d.ts +103 -0
- package/dist/ChatSends.d.ts.map +1 -0
- package/dist/ChatSends.js +157 -0
- package/dist/ChatSends.js.map +1 -0
- package/dist/Client.d.ts +113 -0
- package/dist/Client.d.ts.map +1 -0
- package/dist/Client.js +189 -0
- package/dist/Client.js.map +1 -0
- package/dist/Collab.d.ts +138 -0
- package/dist/Collab.d.ts.map +1 -0
- package/dist/Collab.js +454 -0
- package/dist/Collab.js.map +1 -0
- package/dist/CollabTools.d.ts +129 -0
- package/dist/CollabTools.d.ts.map +1 -0
- package/dist/CollabTools.js +277 -0
- package/dist/CollabTools.js.map +1 -0
- package/dist/Connections.d.ts +288 -0
- package/dist/Connections.d.ts.map +1 -0
- package/dist/Connections.js +316 -0
- package/dist/Connections.js.map +1 -0
- package/dist/Consent.d.ts +338 -0
- package/dist/Consent.d.ts.map +1 -0
- package/dist/Consent.js +142 -0
- package/dist/Consent.js.map +1 -0
- package/dist/Desktop.d.ts +61 -0
- package/dist/Desktop.d.ts.map +1 -0
- package/dist/Desktop.js +101 -0
- package/dist/Desktop.js.map +1 -0
- package/dist/Directory.d.ts +36 -0
- package/dist/Directory.d.ts.map +1 -0
- package/dist/Directory.js +42 -0
- package/dist/Directory.js.map +1 -0
- package/dist/ErrorReporter.d.ts +48 -0
- package/dist/ErrorReporter.d.ts.map +1 -0
- package/dist/ErrorReporter.js +70 -0
- package/dist/ErrorReporter.js.map +1 -0
- package/dist/ExpoSqlite.d.ts +7 -0
- package/dist/ExpoSqlite.d.ts.map +1 -0
- package/dist/ExpoSqlite.js +7 -0
- package/dist/ExpoSqlite.js.map +1 -0
- package/dist/FileSync.d.ts +265 -0
- package/dist/FileSync.d.ts.map +1 -0
- package/dist/FileSync.js +29 -0
- package/dist/FileSync.js.map +1 -0
- package/dist/FileTables.gen.d.ts +109 -0
- package/dist/FileTables.gen.d.ts.map +1 -0
- package/dist/FileTables.gen.js +23 -0
- package/dist/FileTables.gen.js.map +1 -0
- package/dist/Foldkit.d.ts +487 -0
- package/dist/Foldkit.d.ts.map +1 -0
- package/dist/Foldkit.js +617 -0
- package/dist/Foldkit.js.map +1 -0
- package/dist/History.d.ts +133 -0
- package/dist/History.d.ts.map +1 -0
- package/dist/History.js +210 -0
- package/dist/History.js.map +1 -0
- package/dist/InboxSync.d.ts +428 -0
- package/dist/InboxSync.d.ts.map +1 -0
- package/dist/InboxSync.js +37 -0
- package/dist/InboxSync.js.map +1 -0
- package/dist/KernelTables.gen.d.ts +1522 -0
- package/dist/KernelTables.gen.d.ts.map +1 -0
- package/dist/KernelTables.gen.js +307 -0
- package/dist/KernelTables.gen.js.map +1 -0
- package/dist/Make.d.ts +75 -0
- package/dist/Make.d.ts.map +1 -0
- package/dist/Make.js +70 -0
- package/dist/Make.js.map +1 -0
- package/dist/Models.d.ts +88 -0
- package/dist/Models.d.ts.map +1 -0
- package/dist/Models.js +80 -0
- package/dist/Models.js.map +1 -0
- package/dist/Optimistic.d.ts +120 -0
- package/dist/Optimistic.d.ts.map +1 -0
- package/dist/Optimistic.js +231 -0
- package/dist/Optimistic.js.map +1 -0
- package/dist/PlatformSync.d.ts +273 -0
- package/dist/PlatformSync.d.ts.map +1 -0
- package/dist/PlatformSync.js +92 -0
- package/dist/PlatformSync.js.map +1 -0
- package/dist/Poll.d.ts +113 -0
- package/dist/Poll.d.ts.map +1 -0
- package/dist/Poll.js +179 -0
- package/dist/Poll.js.map +1 -0
- package/dist/Preferences.d.ts +18 -0
- package/dist/Preferences.d.ts.map +1 -0
- package/dist/Preferences.js +22 -0
- package/dist/Preferences.js.map +1 -0
- package/dist/Proposals.d.ts +29 -0
- package/dist/Proposals.d.ts.map +1 -0
- package/dist/Proposals.js +41 -0
- package/dist/Proposals.js.map +1 -0
- package/dist/React.d.ts +17 -0
- package/dist/React.d.ts.map +1 -0
- package/dist/React.js +17 -0
- package/dist/React.js.map +1 -0
- package/dist/Reader.d.ts +35 -0
- package/dist/Reader.d.ts.map +1 -0
- package/dist/Reader.js +136 -0
- package/dist/Reader.js.map +1 -0
- package/dist/Resources.d.ts +98 -0
- package/dist/Resources.d.ts.map +1 -0
- package/dist/Resources.js +161 -0
- package/dist/Resources.js.map +1 -0
- package/dist/Rows.d.ts +4 -0
- package/dist/Rows.d.ts.map +1 -0
- package/dist/Rows.js +16 -0
- package/dist/Rows.js.map +1 -0
- package/dist/Runtime.d.ts +254 -0
- package/dist/Runtime.d.ts.map +1 -0
- package/dist/Runtime.js +1283 -0
- package/dist/Runtime.js.map +1 -0
- package/dist/RuntimeRuns.d.ts +74 -0
- package/dist/RuntimeRuns.d.ts.map +1 -0
- package/dist/RuntimeRuns.js +118 -0
- package/dist/RuntimeRuns.js.map +1 -0
- package/dist/ServicesSync.d.ts +286 -0
- package/dist/ServicesSync.d.ts.map +1 -0
- package/dist/ServicesSync.js +40 -0
- package/dist/ServicesSync.js.map +1 -0
- package/dist/Session.d.ts +228 -0
- package/dist/Session.d.ts.map +1 -0
- package/dist/Session.js +792 -0
- package/dist/Session.js.map +1 -0
- package/dist/ShareGrant.d.ts +47 -0
- package/dist/ShareGrant.d.ts.map +1 -0
- package/dist/ShareGrant.js +20 -0
- package/dist/ShareGrant.js.map +1 -0
- package/dist/Sharing.d.ts +203 -0
- package/dist/Sharing.d.ts.map +1 -0
- package/dist/Sharing.js +520 -0
- package/dist/Sharing.js.map +1 -0
- package/dist/Skew.d.ts +52 -0
- package/dist/Skew.d.ts.map +1 -0
- package/dist/Skew.js +77 -0
- package/dist/Skew.js.map +1 -0
- package/dist/SpacesSync.d.ts +247 -0
- package/dist/SpacesSync.d.ts.map +1 -0
- package/dist/SpacesSync.js +30 -0
- package/dist/SpacesSync.js.map +1 -0
- package/dist/Storage.d.ts +51 -0
- package/dist/Storage.d.ts.map +1 -0
- package/dist/Storage.js +107 -0
- package/dist/Storage.js.map +1 -0
- package/dist/Sync.d.ts +48 -0
- package/dist/Sync.d.ts.map +1 -0
- package/dist/Sync.js +48 -0
- package/dist/Sync.js.map +1 -0
- package/dist/SyncTables.d.ts +13 -0
- package/dist/SyncTables.d.ts.map +1 -0
- package/dist/SyncTables.js +13 -0
- package/dist/SyncTables.js.map +1 -0
- package/dist/Tab.d.ts +36 -0
- package/dist/Tab.d.ts.map +1 -0
- package/dist/Tab.js +44 -0
- package/dist/Tab.js.map +1 -0
- package/dist/Transport.d.ts +139 -0
- package/dist/Transport.d.ts.map +1 -0
- package/dist/Transport.js +232 -0
- package/dist/Transport.js.map +1 -0
- package/dist/Upload.d.ts +41 -0
- package/dist/Upload.d.ts.map +1 -0
- package/dist/Upload.js +93 -0
- package/dist/Upload.js.map +1 -0
- package/dist/WebMcp.d.ts +78 -0
- package/dist/WebMcp.d.ts.map +1 -0
- package/dist/WebMcp.js +204 -0
- package/dist/WebMcp.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/package.json +97 -3
- package/src/Account.ts +249 -0
- package/src/Agent.ts +387 -0
- package/src/AgentSync.ts +59 -0
- package/src/AppState.ts +222 -0
- package/src/AppStateSync.ts +26 -0
- package/src/Auth.ts +225 -0
- package/src/Avatars.ts +144 -0
- package/src/BrowserAnalytics.ts +133 -0
- package/src/Chat.ts +1150 -0
- package/src/ChatIntegrity.ts +130 -0
- package/src/ChatSends.ts +209 -0
- package/src/Client.ts +319 -0
- package/src/Collab.ts +524 -0
- package/src/CollabTools.ts +381 -0
- package/src/Connections.ts +517 -0
- package/src/Consent.ts +176 -0
- package/src/Desktop.ts +139 -0
- package/src/Directory.ts +71 -0
- package/src/ErrorReporter.ts +112 -0
- package/src/ExpoSqlite.ts +6 -0
- package/src/FileSync.ts +34 -0
- package/src/FileTables.gen.ts +23 -0
- package/src/Foldkit.ts +960 -0
- package/src/History.ts +337 -0
- package/src/InboxSync.ts +47 -0
- package/src/KernelTables.gen.ts +329 -0
- package/src/Make.ts +120 -0
- package/src/Models.ts +134 -0
- package/src/Optimistic.ts +364 -0
- package/src/PlatformSync.ts +156 -0
- package/src/Poll.ts +227 -0
- package/src/Preferences.ts +42 -0
- package/src/Proposals.ts +57 -0
- package/src/React.ts +26 -0
- package/src/Reader.ts +180 -0
- package/src/Resources.ts +257 -0
- package/src/Rows.ts +16 -0
- package/src/Runtime.ts +1442 -0
- package/src/RuntimeRuns.ts +180 -0
- package/src/ServicesSync.ts +58 -0
- package/src/Session.ts +844 -0
- package/src/ShareGrant.ts +20 -0
- package/src/Sharing.ts +696 -0
- package/src/Skew.ts +97 -0
- package/src/SpacesSync.ts +61 -0
- package/src/Storage.ts +167 -0
- package/src/Sync.ts +125 -0
- package/src/SyncTables.ts +12 -0
- package/src/Tab.ts +59 -0
- package/src/Transport.ts +321 -0
- package/src/Upload.ts +125 -0
- package/src/WebMcp.ts +279 -0
- package/src/index.ts +26 -0
- package/src/web-globals.d.ts +103 -0
package/dist/Client.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The headless client SDK. The typed client is the action registry projected
|
|
3
|
+
* through `toRpcGroup` (no hand-written glue): every action is a method whose
|
|
4
|
+
* input and output types come from its contract.
|
|
5
|
+
*
|
|
6
|
+
* Uses only web-standard APIs (fetch, WebSocket via Zero), so it runs in
|
|
7
|
+
* browsers, Tauri, Bun, Node and React Native.
|
|
8
|
+
*/
|
|
9
|
+
import type { AnyModuleContract, MakeActionListing, McpServerIdentity, RegistryRpcs, ReleaseInfo } from "@eloxiv/contracts";
|
|
10
|
+
import { Effect } from "effect";
|
|
11
|
+
import { type Rpc, RpcClient, type RpcClientError } from "effect/rpc";
|
|
12
|
+
import { type ReaderOptions } from "./Reader.ts";
|
|
13
|
+
import { type BackendStatus, type Circuit, type RequestOptions, type SignalLike } from "./Transport.ts";
|
|
14
|
+
export interface ClientOptions<Modules extends ReadonlyArray<AnyModuleContract>> {
|
|
15
|
+
/** Kernel base URL, e.g. `http://localhost:4100`. */
|
|
16
|
+
readonly baseUrl: string;
|
|
17
|
+
/** Module contracts the app installed (generated `eloxiv.modules.ts`). */
|
|
18
|
+
readonly modules: Modules;
|
|
19
|
+
/** Current bearer token; read on every call. */
|
|
20
|
+
readonly token?: (() => string | undefined) | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Organisation to act in, when the user belongs to several: a fixed id, or a function read on every call
|
|
23
|
+
* (an app that lets the user switch organisations).
|
|
24
|
+
*/
|
|
25
|
+
readonly orgId?: string | (() => string | undefined) | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* This client's version (the app build), sent as `x-eloxiv-client-version` on every call. The kernel
|
|
28
|
+
* refuses writes from versions older than its minimum (`ClientOutdated`); reads keep working.
|
|
29
|
+
*/
|
|
30
|
+
readonly clientVersion?: string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* A host that supplies no backend says so, with why (a standalone or static build): every call and read is
|
|
33
|
+
* refused before it is made (`BackendDisabled`), and `status()` reports it.
|
|
34
|
+
*/
|
|
35
|
+
readonly backend?: {
|
|
36
|
+
readonly disabled: string;
|
|
37
|
+
} | undefined;
|
|
38
|
+
/** The backend's failure circuit (`makeCircuit`), shared by every request this client makes (default: its own). */
|
|
39
|
+
readonly circuit?: Circuit | undefined;
|
|
40
|
+
/** How `read` batches (`makeReader`'s window, size, retries and timeout). */
|
|
41
|
+
readonly batch?: Pick<ReaderOptions, "windowMs" | "maxItems" | "retries" | "retryBaseMs" | "timeoutMs"> | undefined;
|
|
42
|
+
}
|
|
43
|
+
export interface CallOptions {
|
|
44
|
+
readonly idempotencyKey?: string | undefined;
|
|
45
|
+
/** Give up after this long (ms): the call rejects with `RequestError` `Timeout` (it may still have run). */
|
|
46
|
+
readonly timeoutMs?: number | undefined;
|
|
47
|
+
/** Abort the call (its request is aborted; a write the kernel already received may still run). */
|
|
48
|
+
readonly signal?: SignalLike | undefined;
|
|
49
|
+
}
|
|
50
|
+
export type ActionName<Modules extends ReadonlyArray<AnyModuleContract>> = RegistryRpcs<Modules>["_tag"];
|
|
51
|
+
export type ActionInput<Modules extends ReadonlyArray<AnyModuleContract>, Tag extends string> = Rpc.PayloadConstructor<Rpc.ExtractTag<RegistryRpcs<Modules>, Tag>>;
|
|
52
|
+
export type ActionOutput<Modules extends ReadonlyArray<AnyModuleContract>, Tag extends string> = Rpc.Success<Rpc.ExtractTag<RegistryRpcs<Modules>, Tag>>;
|
|
53
|
+
export declare const makeClient: <const Modules extends ReadonlyArray<AnyModuleContract>>(options: ClientOptions<Modules>) => {
|
|
54
|
+
/** Call an action. Rejects with the action's typed error (`Forbidden`, `ApprovalRequired`, ...). */
|
|
55
|
+
call: <const Tag extends ActionName<Modules>>(action: Tag, input: ActionInput<Modules, Tag>, call?: CallOptions) => Promise<ActionOutput<Modules, Tag>>;
|
|
56
|
+
/**
|
|
57
|
+
* A read-only action's result, read in a batch with the other reads made in the same window (`makeReader`):
|
|
58
|
+
* typed like `call`, rejecting with `RequestError` (the item's own refusal, or the transport's).
|
|
59
|
+
*/
|
|
60
|
+
read: <const Tag extends ActionName<Modules>>(action: Tag, input: ActionInput<Modules, Tag>, request?: {
|
|
61
|
+
readonly signal?: SignalLike | undefined;
|
|
62
|
+
}) => Promise<ActionOutput<Modules, Tag>>;
|
|
63
|
+
/**
|
|
64
|
+
* An action over plain HTTP (`POST /api/actions/<action>`), for what the RPC call does not give: `keepalive`
|
|
65
|
+
* (state published while the page goes away) and retries under an idempotency key, with a timeout and an abort
|
|
66
|
+
* signal. Typed like `call`; rejects with `RequestError`.
|
|
67
|
+
*/
|
|
68
|
+
send: <const Tag extends ActionName<Modules>>(action: Tag, input: ActionInput<Modules, Tag>, request?: RequestOptions) => Promise<ActionOutput<Modules, Tag>>;
|
|
69
|
+
/** Whether there is a backend to talk to: disabled by the host, or the failure circuit's state. */
|
|
70
|
+
status: () => BackendStatus;
|
|
71
|
+
/** Told when the backend becomes unavailable or available again; returns the unsubscribe. */
|
|
72
|
+
onStatus: (listener: (status: BackendStatus) => void) => () => void;
|
|
73
|
+
/**
|
|
74
|
+
* Call an action as an Effect that runs in the caller's fiber, acting with the session and organisation given
|
|
75
|
+
* here (not the client's `token` and `orgId`): interrupting it aborts the request. Fails with the action's
|
|
76
|
+
* typed error, or the protocol's (`RpcClientError`).
|
|
77
|
+
*/
|
|
78
|
+
callEffect: <const Tag extends ActionName<Modules>>(action: Tag, input: ActionInput<Modules, Tag>, acting: {
|
|
79
|
+
readonly token: string;
|
|
80
|
+
readonly orgId: string;
|
|
81
|
+
readonly idempotencyKey?: string | undefined;
|
|
82
|
+
}) => Effect.Effect<ActionOutput<Modules, Tag>, unknown>;
|
|
83
|
+
/**
|
|
84
|
+
* MAKE modules' actions, installed at run time (so not among the typed methods): the ones the caller reaches,
|
|
85
|
+
* and a call of one through the invocation path (its envelope, or its typed error).
|
|
86
|
+
*/
|
|
87
|
+
make: {
|
|
88
|
+
actions: () => Promise<ReadonlyArray<MakeActionListing>>;
|
|
89
|
+
call: (action: string, input: unknown, call?: CallOptions) => Promise<unknown>;
|
|
90
|
+
};
|
|
91
|
+
/** The installed modules this client was projected from. */
|
|
92
|
+
modules: Modules;
|
|
93
|
+
/** The underlying Effect RPC client, for Effect programs. */
|
|
94
|
+
rpc: Promise<RpcClient.RpcClient<RegistryRpcs<Modules>, RpcClientError.RpcClientError>>;
|
|
95
|
+
headers: (call?: CallOptions) => Record<string, string>;
|
|
96
|
+
dispose: () => Promise<void>;
|
|
97
|
+
};
|
|
98
|
+
export type EloxivClient<Modules extends ReadonlyArray<AnyModuleContract>> = ReturnType<typeof makeClient<Modules>>;
|
|
99
|
+
/**
|
|
100
|
+
* A call's result is an envelope: `{ kind: "output", output }` on first execution, or, when an idempotent call
|
|
101
|
+
* is replayed, `{ kind: "replay", receipt }` (facts about what the original call did, never its output).
|
|
102
|
+
*/
|
|
103
|
+
export { isReplay, type InvocationReceipt, type ReplayEnvelope } from "@eloxiv/contracts";
|
|
104
|
+
/** The release a kernel advertises (`GET /release`): its versions and the oldest client it accepts writes from. */
|
|
105
|
+
export declare const fetchRelease: (baseUrl: string) => Promise<ReleaseInfo>;
|
|
106
|
+
/**
|
|
107
|
+
* The kernel's MCP server identity (`GET /.well-known/mcp.json`): the canonical name to list it under, its endpoint
|
|
108
|
+
* and OAuth resource. A settings page or connect flow shows and uses these, never a name of its own.
|
|
109
|
+
*/
|
|
110
|
+
export declare const mcpServerIdentity: (baseUrl: string) => Promise<McpServerIdentity>;
|
|
111
|
+
/** Whether a call failed because this client is older than the kernel's minimum (reload or upgrade, then retry). */
|
|
112
|
+
export declare const isClientOutdated: (error: unknown) => boolean;
|
|
113
|
+
//# sourceMappingURL=Client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../src/Client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACZ,MAAM,mBAAmB,CAAA;AAa1B,OAAO,EAAW,MAAM,EAA8C,MAAM,QAAQ,CAAA;AAEpF,OAAO,EAAE,KAAK,GAAG,EAAE,SAAS,EAAE,KAAK,cAAc,EAAoB,MAAM,YAAY,CAAA;AACvF,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,OAAO,EAIZ,KAAK,cAAc,EACnB,KAAK,UAAU,EAChB,MAAM,gBAAgB,CAAA;AAEvB,MAAM,WAAW,aAAa,CAAC,OAAO,SAAS,aAAa,CAAC,iBAAiB,CAAC;IAC7E,qDAAqD;IACrD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,gDAAgD;IAChD,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,SAAS,CAAA;IACvD;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,SAAS,CAAA;IAChE;;;O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iB,CAAC,CAAC;QAO5D,IAAI,WAAiB,MAAM,SAAS,OAAO,SAAS,WAAW,KAAG,OAAO,CAAC,OAAO,CAAC;;IAUpF,4DAA4D;;IAE5D,6DAA6D;SACjD,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC,cAAc,CAAC,CAAC;qBApIxE,WAAW,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;CA2I7D,CAAA;AAED,MAAM,MAAM,YAAY,CAAC,OAAO,SAAS,aAAa,CAAC,iBAAiB,CAAC,IAAI,UAAU,CAAC,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC,CAAA;AAEnH;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAAE,KAAK,iBAAiB,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEzF,mHAAmH;AACnH,eAAO,MAAM,YAAY,YAAmB,MAAM,KAAG,OAAO,CAAC,WAAW,CAIvE,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,YAAmB,MAAM,KAAG,OAAO,CAAC,iBAAiB,CAIlF,CAAA;AAED,oHAAoH;AACpH,eAAO,MAAM,gBAAgB,UAAW,OAAO,KAAG,OACsD,CAAA"}
|
package/dist/Client.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { actionRegistry, actionResult, CLIENT_VERSION_HEADER, IDEMPOTENCY_HEADER, MAKE_RPC_ACTIONS, MAKE_RPC_CALL, MakeRpcGroup, MCP_IDENTITY_PATH, RELEASE_PATH, toRpcGroup, } from "@eloxiv/contracts";
|
|
2
|
+
import { Context, Effect, Exit, Layer, ManagedRuntime, Schema, Scope } from "effect";
|
|
3
|
+
import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
|
|
4
|
+
import { RpcClient, RpcSerialization } from "effect/rpc";
|
|
5
|
+
import { makeReader } from "./Reader.js";
|
|
6
|
+
import { backendStatus, httpAction, makeCircuit, RequestError, } from "./Transport.js";
|
|
7
|
+
/**
|
|
8
|
+
* The `authorization` header a call is made with, sent on its HTTP request as well as inside the RPC message. The
|
|
9
|
+
* kernel's cookie guard reads the request's headers, not the message's: a runtime that keeps a cookie jar (React
|
|
10
|
+
* Native on Android attaches the session cookie Better Auth set at sign-in to every later request) would otherwise
|
|
11
|
+
* send a cookie POST with no `Authorization` header, which the guard refuses as a forgery (`403`). With it, the guard
|
|
12
|
+
* drops the cookie and the call authenticates by its bearer token only. (Provided to the call's fiber; Effect RPC
|
|
13
|
+
* runs the HTTP send with that fiber's services.)
|
|
14
|
+
*/
|
|
15
|
+
const CallAuthorization = Context.Reference("@eloxiv/client/CallAuthorization", {
|
|
16
|
+
defaultValue: () => undefined,
|
|
17
|
+
});
|
|
18
|
+
export const makeClient = (options) => {
|
|
19
|
+
const group = toRpcGroup(options.modules).merge(MakeRpcGroup);
|
|
20
|
+
const protocol = RpcClient.layerProtocolHttp({
|
|
21
|
+
url: `${options.baseUrl}/rpc`,
|
|
22
|
+
transformClient: HttpClient.mapRequestEffect((request) => Effect.map(Effect.service(CallAuthorization), (authorization) => authorization === undefined ? request : HttpClientRequest.setHeader(request, "authorization", authorization))),
|
|
23
|
+
}).pipe(Layer.provide(FetchHttpClient.layer), Layer.provide(RpcSerialization.layerJson));
|
|
24
|
+
const runtime = ManagedRuntime.make(protocol);
|
|
25
|
+
const scope = Effect.runSync(Scope.make());
|
|
26
|
+
const rpc = runtime.runPromise(Scope.provide(RpcClient.make(group), scope));
|
|
27
|
+
const circuit = options.circuit ?? makeCircuit();
|
|
28
|
+
const reader = makeReader({ ...options, ...options.batch }, circuit);
|
|
29
|
+
const registry = actionRegistry(options.modules);
|
|
30
|
+
const decoders = new Map();
|
|
31
|
+
/** The envelope of `action` as the RPC client would give it (its output decoded by the action's schema). */
|
|
32
|
+
const decodeResult = (action, encoded) => {
|
|
33
|
+
let decode = decoders.get(action);
|
|
34
|
+
if (decode === undefined) {
|
|
35
|
+
const contract = registry.get(action);
|
|
36
|
+
if (contract === undefined)
|
|
37
|
+
throw new RequestError(404, { _tag: "UnknownAction", action, message: `No action ${action}` });
|
|
38
|
+
decode = Schema.decodeUnknownSync(actionResult(contract));
|
|
39
|
+
decoders.set(action, decode);
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
return decode(encoded);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
throw new RequestError(0, { _tag: "InvalidOutput", message: String(error) });
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
/** Refuses a call before it is made while the host supplies no backend or the circuit is open. */
|
|
49
|
+
const admit = () => {
|
|
50
|
+
const status = backendStatus(options, circuit);
|
|
51
|
+
if (status.state === "disabled")
|
|
52
|
+
throw new RequestError(0, { _tag: "BackendDisabled", message: status.reason });
|
|
53
|
+
if (circuit.isOpen() && status.state === "unavailable") {
|
|
54
|
+
throw new RequestError(0, { _tag: "BackendUnavailable", message: status.reason, retryAt: status.retryAt });
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
/** A typed error is the kernel's answer; a protocol error (nothing definitive came back) counts against the circuit. */
|
|
58
|
+
const told = (effect) => effect.pipe(Effect.tap(() => Effect.sync(() => circuit.succeeded())), Effect.tapError((error) => Effect.sync(() => error._tag === "RpcClientError" ? circuit.failed("retry") : circuit.succeeded())));
|
|
59
|
+
const headers = (call) => {
|
|
60
|
+
const result = {};
|
|
61
|
+
const token = options.token?.();
|
|
62
|
+
if (token !== undefined)
|
|
63
|
+
result["authorization"] = `Bearer ${token}`;
|
|
64
|
+
const orgId = typeof options.orgId === "function" ? options.orgId() : options.orgId;
|
|
65
|
+
if (orgId !== undefined)
|
|
66
|
+
result["x-eloxiv-org"] = orgId;
|
|
67
|
+
if (options.clientVersion !== undefined)
|
|
68
|
+
result[CLIENT_VERSION_HEADER] = options.clientVersion;
|
|
69
|
+
if (call?.idempotencyKey !== undefined)
|
|
70
|
+
result[IDEMPOTENCY_HEADER] = call.idempotencyKey;
|
|
71
|
+
return result;
|
|
72
|
+
};
|
|
73
|
+
const methodOf = async (action) => {
|
|
74
|
+
const method = (await rpc)[action];
|
|
75
|
+
if (method === undefined)
|
|
76
|
+
throw new Error(`Unknown action ${action}`);
|
|
77
|
+
return method;
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
/** Call an action. Rejects with the action's typed error (`Forbidden`, `ApprovalRequired`, ...). */
|
|
81
|
+
call: async (action, input, call) => {
|
|
82
|
+
admit();
|
|
83
|
+
const method = await methodOf(action);
|
|
84
|
+
const sent = headers(call);
|
|
85
|
+
let effect = told(method(input, { headers: sent }).pipe(Effect.provideService(CallAuthorization, sent["authorization"])));
|
|
86
|
+
if (call?.timeoutMs !== undefined) {
|
|
87
|
+
const ms = call.timeoutMs;
|
|
88
|
+
effect = effect.pipe(Effect.timeoutOrElse({
|
|
89
|
+
duration: ms,
|
|
90
|
+
orElse: () => Effect.fail(new RequestError(0, { _tag: "Timeout", message: `No answer within ${ms} ms` })),
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
return (await runtime.runPromise(effect, call?.signal === undefined ? undefined : { signal: call.signal }));
|
|
94
|
+
},
|
|
95
|
+
/**
|
|
96
|
+
* A read-only action's result, read in a batch with the other reads made in the same window (`makeReader`):
|
|
97
|
+
* typed like `call`, rejecting with `RequestError` (the item's own refusal, or the transport's).
|
|
98
|
+
*/
|
|
99
|
+
read: async (action, input, request) => {
|
|
100
|
+
const contract = registry.get(action);
|
|
101
|
+
if (contract === undefined)
|
|
102
|
+
throw new RequestError(404, { _tag: "UnknownAction", action, message: `No action ${action}` });
|
|
103
|
+
const encoded = Schema.encodeUnknownSync(contract.input)(input);
|
|
104
|
+
return decodeResult(action, await reader.read(action, encoded, request));
|
|
105
|
+
},
|
|
106
|
+
/**
|
|
107
|
+
* An action over plain HTTP (`POST /api/actions/<action>`), for what the RPC call does not give: `keepalive`
|
|
108
|
+
* (state published while the page goes away) and retries under an idempotency key, with a timeout and an abort
|
|
109
|
+
* signal. Typed like `call`; rejects with `RequestError`.
|
|
110
|
+
*/
|
|
111
|
+
send: async (action, input, request) => {
|
|
112
|
+
const contract = registry.get(action);
|
|
113
|
+
if (contract === undefined)
|
|
114
|
+
throw new RequestError(404, { _tag: "UnknownAction", action, message: `No action ${action}` });
|
|
115
|
+
const encoded = Schema.encodeUnknownSync(contract.input)(input);
|
|
116
|
+
return decodeResult(action, await httpAction(options, circuit, action, encoded, request));
|
|
117
|
+
},
|
|
118
|
+
/** Whether there is a backend to talk to: disabled by the host, or the failure circuit's state. */
|
|
119
|
+
status: () => backendStatus(options, circuit),
|
|
120
|
+
/** Told when the backend becomes unavailable or available again; returns the unsubscribe. */
|
|
121
|
+
onStatus: (listener) => circuit.subscribe(listener),
|
|
122
|
+
/**
|
|
123
|
+
* Call an action as an Effect that runs in the caller's fiber, acting with the session and organisation given
|
|
124
|
+
* here (not the client's `token` and `orgId`): interrupting it aborts the request. Fails with the action's
|
|
125
|
+
* typed error, or the protocol's (`RpcClientError`).
|
|
126
|
+
*/
|
|
127
|
+
callEffect: (action, input, acting) => Effect.promise(() => methodOf(action)).pipe(Effect.flatMap((method) => {
|
|
128
|
+
const sent = {
|
|
129
|
+
authorization: `Bearer ${acting.token}`,
|
|
130
|
+
"x-eloxiv-org": acting.orgId,
|
|
131
|
+
};
|
|
132
|
+
if (options.clientVersion !== undefined)
|
|
133
|
+
sent[CLIENT_VERSION_HEADER] = options.clientVersion;
|
|
134
|
+
if (acting.idempotencyKey !== undefined)
|
|
135
|
+
sent[IDEMPOTENCY_HEADER] = acting.idempotencyKey;
|
|
136
|
+
return method(input, { headers: sent }).pipe(Effect.provideService(CallAuthorization, sent["authorization"]));
|
|
137
|
+
})),
|
|
138
|
+
/**
|
|
139
|
+
* MAKE modules' actions, installed at run time (so not among the typed methods): the ones the caller reaches,
|
|
140
|
+
* and a call of one through the invocation path (its envelope, or its typed error).
|
|
141
|
+
*/
|
|
142
|
+
make: {
|
|
143
|
+
actions: async () => {
|
|
144
|
+
const method = await methodOf(MAKE_RPC_ACTIONS);
|
|
145
|
+
const sent = headers();
|
|
146
|
+
return (await runtime.runPromise(method({}, { headers: sent }).pipe(Effect.provideService(CallAuthorization, sent["authorization"]))));
|
|
147
|
+
},
|
|
148
|
+
call: async (action, input, call) => {
|
|
149
|
+
const method = await methodOf(MAKE_RPC_CALL);
|
|
150
|
+
const sent = headers(call);
|
|
151
|
+
return await runtime.runPromise(method({ action, input }, { headers: sent }).pipe(Effect.provideService(CallAuthorization, sent["authorization"])));
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
/** The installed modules this client was projected from. */
|
|
155
|
+
modules: options.modules,
|
|
156
|
+
/** The underlying Effect RPC client, for Effect programs. */
|
|
157
|
+
rpc: rpc,
|
|
158
|
+
headers,
|
|
159
|
+
dispose: async () => {
|
|
160
|
+
await Effect.runPromise(Scope.close(scope, Exit.void));
|
|
161
|
+
await runtime.dispose();
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* A call's result is an envelope: `{ kind: "output", output }` on first execution, or, when an idempotent call
|
|
167
|
+
* is replayed, `{ kind: "replay", receipt }` (facts about what the original call did, never its output).
|
|
168
|
+
*/
|
|
169
|
+
export { isReplay } from "@eloxiv/contracts";
|
|
170
|
+
/** The release a kernel advertises (`GET /release`): its versions and the oldest client it accepts writes from. */
|
|
171
|
+
export const fetchRelease = async (baseUrl) => {
|
|
172
|
+
const response = await fetch(`${baseUrl}${RELEASE_PATH}`);
|
|
173
|
+
if (!response.ok)
|
|
174
|
+
throw new Error(`${RELEASE_PATH} answered ${response.status}`);
|
|
175
|
+
return (await response.json());
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* The kernel's MCP server identity (`GET /.well-known/mcp.json`): the canonical name to list it under, its endpoint
|
|
179
|
+
* and OAuth resource. A settings page or connect flow shows and uses these, never a name of its own.
|
|
180
|
+
*/
|
|
181
|
+
export const mcpServerIdentity = async (baseUrl) => {
|
|
182
|
+
const response = await fetch(`${baseUrl}${MCP_IDENTITY_PATH}`);
|
|
183
|
+
if (!response.ok)
|
|
184
|
+
throw new Error(`${MCP_IDENTITY_PATH} answered ${response.status}`);
|
|
185
|
+
return (await response.json());
|
|
186
|
+
};
|
|
187
|
+
/** Whether a call failed because this client is older than the kernel's minimum (reload or upgrade, then retry). */
|
|
188
|
+
export const isClientOutdated = (error) => typeof error === "object" && error !== null && error._tag === "ClientOutdated";
|
|
189
|
+
//# sourceMappingURL=Client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../src/Client.ts"],"names":[],"mappings":"AAeA,OAAO,EACL,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,UAAU,GACX,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AACpF,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC5E,OAAO,EAAY,SAAS,EAAuB,gBAAgB,EAAE,MAAM,YAAY,CAAA;AACvF,OAAO,EAAE,UAAU,EAAsB,MAAM,aAAa,CAAA;AAC5D,OAAO,EACL,aAAa,EAGb,UAAU,EACV,WAAW,EACX,YAAY,GAGb,MAAM,gBAAgB,CAAA;AA8CvB;;;;;;;GAOG;AACH,MAAM,iBAAiB,GAAG,OAAO,CAAC,SAAS,CAAqB,kCAAkC,EAAE;IAClG,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS;CAC9B,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAyD,OAA+B,EAAE,EAAE;IACpH,MAAM,KAAK,GAAG,UAAU,CAA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AK,CAAC,GAAG,YAAY,aAAa,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;IAChF,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAgB,CAAA;AAC/C,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,OAAe,EAA8B,EAAE;IACrF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,OAAO,GAAG,iBAAiB,EAAE,CAAC,CAAA;IAC9D,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,iBAAiB,aAAa,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;IACrF,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAsB,CAAA;AACrD,CAAC,CAAA;AAED,oHAAoH;AACpH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAW,EAAE,CAC1D,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAK,KAA4B,CAAC,IAAI,KAAK,gBAAgB,CAAA"}
|
package/dist/Collab.d.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collaborative documents in the client (`@eloxiv/client/collab`, the CollabDocument contract): a record's Yjs
|
|
3
|
+
* document kept in sync with the kernel over its WebSocket transport, with presence. Headless (no DOM): it needs a
|
|
4
|
+
* global `WebSocket` (browsers, Bun, Node 22+) or one passed in.
|
|
5
|
+
*
|
|
6
|
+
* The document is a plain `Y.Doc` the app (or an editor binding) edits. Local changes are sent as they happen
|
|
7
|
+
* (coalesced for `batchMs`); each is one `collab.update` call on the kernel, answered or refused. Offline, changes
|
|
8
|
+
* stay in the document; on reconnect the kernel's state is merged in and everything it lacks is sent, so clients
|
|
9
|
+
* converge whatever order they edit and reconnect in. Remote changes, and other people's presence, arrive as the
|
|
10
|
+
* kernel delivers them (each delivery authorised for this connection's caller, at that moment). A connection the
|
|
11
|
+
* kernel refuses (signed out, access revoked) is closed for good: `status` is `closed` with the reason, and it does
|
|
12
|
+
* not reconnect.
|
|
13
|
+
*/
|
|
14
|
+
import { type CollabOrigin } from "@eloxiv/contracts";
|
|
15
|
+
import * as Y from "yjs";
|
|
16
|
+
/** The origin remote changes are applied with: a `Y.Doc` update with it came from the kernel. */
|
|
17
|
+
export declare const REMOTE_ORIGIN: unique symbol;
|
|
18
|
+
export type CollabStatus = "connecting" | "synced" | "offline" | "closed";
|
|
19
|
+
/** Another collaborator's presence: their client, person (stamped by the kernel) and state. */
|
|
20
|
+
export interface CollabPeer {
|
|
21
|
+
readonly clientId: number;
|
|
22
|
+
readonly userId: string;
|
|
23
|
+
readonly state: unknown;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Who made a remote change, as the kernel stored it (never as a client claims): the person, how (themselves, their
|
|
27
|
+
* agent, the kernel), the update's sequence number and when the kernel accepted it.
|
|
28
|
+
*/
|
|
29
|
+
export interface CollabAuthor {
|
|
30
|
+
readonly userId: string;
|
|
31
|
+
readonly origin: CollabOrigin;
|
|
32
|
+
readonly seq: number;
|
|
33
|
+
readonly at: number;
|
|
34
|
+
}
|
|
35
|
+
export type CollabEvent = {
|
|
36
|
+
readonly type: "status";
|
|
37
|
+
readonly status: CollabStatus;
|
|
38
|
+
} | {
|
|
39
|
+
readonly type: "peers";
|
|
40
|
+
readonly peers: ReadonlyArray<CollabPeer>;
|
|
41
|
+
} | {
|
|
42
|
+
readonly type: "remote";
|
|
43
|
+
readonly seq: number;
|
|
44
|
+
} | {
|
|
45
|
+
readonly type: "refused";
|
|
46
|
+
readonly error: {
|
|
47
|
+
readonly _tag: string;
|
|
48
|
+
readonly message: string;
|
|
49
|
+
};
|
|
50
|
+
} | {
|
|
51
|
+
readonly type: "closed";
|
|
52
|
+
readonly error: {
|
|
53
|
+
readonly _tag: string;
|
|
54
|
+
readonly message: string;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export interface CollabOptions {
|
|
58
|
+
/** The kernel's base URL (`http(s)://...`). */
|
|
59
|
+
readonly baseUrl: string;
|
|
60
|
+
/** The record: its entity's Cedar type (`Notes::Note`) and id. */
|
|
61
|
+
readonly entity: string;
|
|
62
|
+
readonly id: string;
|
|
63
|
+
/** A bearer credential, read at each (re)connection. */
|
|
64
|
+
readonly token?: string | (() => string | undefined) | undefined;
|
|
65
|
+
readonly orgId?: string | undefined;
|
|
66
|
+
/** The document to keep in sync (a new one by default). */
|
|
67
|
+
readonly doc?: Y.Doc | undefined;
|
|
68
|
+
/** Reconnect after a dropped connection (default true); the delay in milliseconds (default 500). */
|
|
69
|
+
readonly reconnect?: boolean | undefined;
|
|
70
|
+
readonly reconnectMs?: number | undefined;
|
|
71
|
+
/** Coalesce local changes for this long before sending them (default 30 ms). */
|
|
72
|
+
readonly batchMs?: number | undefined;
|
|
73
|
+
/** A WebSocket constructor (default `globalThis.WebSocket`). */
|
|
74
|
+
readonly WebSocket?: typeof WebSocket | undefined;
|
|
75
|
+
}
|
|
76
|
+
export interface CollabConnection {
|
|
77
|
+
readonly doc: Y.Doc;
|
|
78
|
+
readonly status: CollabStatus;
|
|
79
|
+
/** Whether the kernel lets this caller change the document (its `collaborate` policy). */
|
|
80
|
+
readonly canWrite: boolean;
|
|
81
|
+
/** The last update sequence number received. */
|
|
82
|
+
readonly seq: number;
|
|
83
|
+
readonly peers: ReadonlyArray<CollabPeer>;
|
|
84
|
+
/**
|
|
85
|
+
* While one remote update is being applied (inside the document's observers), who made it; otherwise undefined,
|
|
86
|
+
* also while a whole state (a first sync, or a reset after compaction) is applied, which is nobody's in particular.
|
|
87
|
+
*/
|
|
88
|
+
readonly remoteAuthor: CollabAuthor | undefined;
|
|
89
|
+
/** Why the kernel closed the connection, once `closed`. */
|
|
90
|
+
readonly closedWith: {
|
|
91
|
+
readonly _tag: string;
|
|
92
|
+
readonly message: string;
|
|
93
|
+
} | undefined;
|
|
94
|
+
/** Publish this client's presence (any JSON), or withdraw it with null. Refreshed while connected. */
|
|
95
|
+
readonly setPresence: (state: unknown) => void;
|
|
96
|
+
readonly subscribe: (listener: (event: CollabEvent) => void) => () => void;
|
|
97
|
+
/** Resolves once the document holds the kernel's state (now, or at the next sync). */
|
|
98
|
+
readonly whenSynced: () => Promise<void>;
|
|
99
|
+
/** Resolves once every local change made so far has been answered by the kernel (accepted or refused). */
|
|
100
|
+
readonly flush: () => Promise<void>;
|
|
101
|
+
/** Go offline (edits keep accumulating locally) and back online. */
|
|
102
|
+
readonly disconnect: () => void;
|
|
103
|
+
readonly connect: () => void;
|
|
104
|
+
/** Close for good (presence withdrawn). */
|
|
105
|
+
readonly close: () => void;
|
|
106
|
+
}
|
|
107
|
+
export declare const toBase64: (bytes: Uint8Array) => string;
|
|
108
|
+
/**
|
|
109
|
+
* Decode exactly as `atob` does (the HTML standard's forgiving-base64 decode), and refuse exactly what it refuses:
|
|
110
|
+
* ASCII whitespace is ignored; padding is accepted only as one or two `=` ending a length that is a multiple of
|
|
111
|
+
* four; a length of 1 modulo 4, or any other character (an `=` elsewhere included), is not base64. So a malformed
|
|
112
|
+
* frame fails here, as the client's error, and never reaches Yjs truncated.
|
|
113
|
+
*/
|
|
114
|
+
export declare const fromBase64: (text: string) => Uint8Array;
|
|
115
|
+
/** Keep a record's collaborative document in sync with the kernel. */
|
|
116
|
+
export declare const connectCollab: (options: CollabOptions) => CollabConnection;
|
|
117
|
+
export type CollabTextEdit = {
|
|
118
|
+
readonly kind: "replace";
|
|
119
|
+
readonly find: string;
|
|
120
|
+
readonly replace: string;
|
|
121
|
+
readonly occurrence?: number;
|
|
122
|
+
} | {
|
|
123
|
+
readonly kind: "insert";
|
|
124
|
+
readonly text: string;
|
|
125
|
+
readonly at: "start" | "end" | {
|
|
126
|
+
readonly after: string;
|
|
127
|
+
};
|
|
128
|
+
} | {
|
|
129
|
+
readonly kind: "set";
|
|
130
|
+
readonly text: string;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Apply text edits (the same kinds `collab.editText` takes) to a text root of a live document, as one Yjs
|
|
134
|
+
* transaction. Throws, applying nothing, if a passage is not there.
|
|
135
|
+
*/
|
|
136
|
+
export declare const applyTextEdits: (doc: Y.Doc, name: string, edits: ReadonlyArray<CollabTextEdit>) => string;
|
|
137
|
+
export * from "./CollabTools.ts";
|
|
138
|
+
//# sourceMappingURL=Collab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Collab.d.ts","sourceRoot":"","sources":["../src/Collab.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAIL,KAAK,YAAY,EAElB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,iGAAiG;AACjG,eAAO,MAAM,aAAa,eAA6C,CAAA;AAEvE,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAA;AAEzE,+FAA+F;AAC/F,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAA;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAA;CAAE,GAC1D;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,U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