@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.
Files changed (269) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +6 -2
  3. package/dist/Account.d.ts +131 -0
  4. package/dist/Account.d.ts.map +1 -0
  5. package/dist/Account.js +169 -0
  6. package/dist/Account.js.map +1 -0
  7. package/dist/Agent.d.ts +496 -0
  8. package/dist/Agent.d.ts.map +1 -0
  9. package/dist/Agent.js +228 -0
  10. package/dist/Agent.js.map +1 -0
  11. package/dist/AgentSync.d.ts +990 -0
  12. package/dist/AgentSync.d.ts.map +1 -0
  13. package/dist/AgentSync.js +46 -0
  14. package/dist/AgentSync.js.map +1 -0
  15. package/dist/AppState.d.ts +127 -0
  16. package/dist/AppState.d.ts.map +1 -0
  17. package/dist/AppState.js +145 -0
  18. package/dist/AppState.js.map +1 -0
  19. package/dist/AppStateSync.d.ts +193 -0
  20. package/dist/AppStateSync.d.ts.map +1 -0
  21. package/dist/AppStateSync.js +23 -0
  22. package/dist/AppStateSync.js.map +1 -0
  23. package/dist/Auth.d.ts +95 -0
  24. package/dist/Auth.d.ts.map +1 -0
  25. package/dist/Auth.js +139 -0
  26. package/dist/Auth.js.map +1 -0
  27. package/dist/Avatars.d.ts +53 -0
  28. package/dist/Avatars.d.ts.map +1 -0
  29. package/dist/Avatars.js +121 -0
  30. package/dist/Avatars.js.map +1 -0
  31. package/dist/BrowserAnalytics.d.ts +56 -0
  32. package/dist/BrowserAnalytics.d.ts.map +1 -0
  33. package/dist/BrowserAnalytics.js +94 -0
  34. package/dist/BrowserAnalytics.js.map +1 -0
  35. package/dist/Chat.d.ts +712 -0
  36. package/dist/Chat.d.ts.map +1 -0
  37. package/dist/Chat.js +883 -0
  38. package/dist/Chat.js.map +1 -0
  39. package/dist/ChatIntegrity.d.ts +63 -0
  40. package/dist/ChatIntegrity.d.ts.map +1 -0
  41. package/dist/ChatIntegrity.js +89 -0
  42. package/dist/ChatIntegrity.js.map +1 -0
  43. package/dist/ChatSends.d.ts +103 -0
  44. package/dist/ChatSends.d.ts.map +1 -0
  45. package/dist/ChatSends.js +157 -0
  46. package/dist/ChatSends.js.map +1 -0
  47. package/dist/Client.d.ts +113 -0
  48. package/dist/Client.d.ts.map +1 -0
  49. package/dist/Client.js +189 -0
  50. package/dist/Client.js.map +1 -0
  51. package/dist/Collab.d.ts +138 -0
  52. package/dist/Collab.d.ts.map +1 -0
  53. package/dist/Collab.js +454 -0
  54. package/dist/Collab.js.map +1 -0
  55. package/dist/CollabTools.d.ts +129 -0
  56. package/dist/CollabTools.d.ts.map +1 -0
  57. package/dist/CollabTools.js +277 -0
  58. package/dist/CollabTools.js.map +1 -0
  59. package/dist/Connections.d.ts +288 -0
  60. package/dist/Connections.d.ts.map +1 -0
  61. package/dist/Connections.js +316 -0
  62. package/dist/Connections.js.map +1 -0
  63. package/dist/Consent.d.ts +338 -0
  64. package/dist/Consent.d.ts.map +1 -0
  65. package/dist/Consent.js +142 -0
  66. package/dist/Consent.js.map +1 -0
  67. package/dist/Desktop.d.ts +61 -0
  68. package/dist/Desktop.d.ts.map +1 -0
  69. package/dist/Desktop.js +101 -0
  70. package/dist/Desktop.js.map +1 -0
  71. package/dist/Directory.d.ts +36 -0
  72. package/dist/Directory.d.ts.map +1 -0
  73. package/dist/Directory.js +42 -0
  74. package/dist/Directory.js.map +1 -0
  75. package/dist/ErrorReporter.d.ts +48 -0
  76. package/dist/ErrorReporter.d.ts.map +1 -0
  77. package/dist/ErrorReporter.js +70 -0
  78. package/dist/ErrorReporter.js.map +1 -0
  79. package/dist/ExpoSqlite.d.ts +7 -0
  80. package/dist/ExpoSqlite.d.ts.map +1 -0
  81. package/dist/ExpoSqlite.js +7 -0
  82. package/dist/ExpoSqlite.js.map +1 -0
  83. package/dist/FileSync.d.ts +265 -0
  84. package/dist/FileSync.d.ts.map +1 -0
  85. package/dist/FileSync.js +29 -0
  86. package/dist/FileSync.js.map +1 -0
  87. package/dist/FileTables.gen.d.ts +109 -0
  88. package/dist/FileTables.gen.d.ts.map +1 -0
  89. package/dist/FileTables.gen.js +23 -0
  90. package/dist/FileTables.gen.js.map +1 -0
  91. package/dist/Foldkit.d.ts +487 -0
  92. package/dist/Foldkit.d.ts.map +1 -0
  93. package/dist/Foldkit.js +617 -0
  94. package/dist/Foldkit.js.map +1 -0
  95. package/dist/History.d.ts +133 -0
  96. package/dist/History.d.ts.map +1 -0
  97. package/dist/History.js +210 -0
  98. package/dist/History.js.map +1 -0
  99. package/dist/InboxSync.d.ts +428 -0
  100. package/dist/InboxSync.d.ts.map +1 -0
  101. package/dist/InboxSync.js +37 -0
  102. package/dist/InboxSync.js.map +1 -0
  103. package/dist/KernelTables.gen.d.ts +1522 -0
  104. package/dist/KernelTables.gen.d.ts.map +1 -0
  105. package/dist/KernelTables.gen.js +307 -0
  106. package/dist/KernelTables.gen.js.map +1 -0
  107. package/dist/Make.d.ts +75 -0
  108. package/dist/Make.d.ts.map +1 -0
  109. package/dist/Make.js +70 -0
  110. package/dist/Make.js.map +1 -0
  111. package/dist/Models.d.ts +88 -0
  112. package/dist/Models.d.ts.map +1 -0
  113. package/dist/Models.js +80 -0
  114. package/dist/Models.js.map +1 -0
  115. package/dist/Optimistic.d.ts +120 -0
  116. package/dist/Optimistic.d.ts.map +1 -0
  117. package/dist/Optimistic.js +231 -0
  118. package/dist/Optimistic.js.map +1 -0
  119. package/dist/PlatformSync.d.ts +273 -0
  120. package/dist/PlatformSync.d.ts.map +1 -0
  121. package/dist/PlatformSync.js +92 -0
  122. package/dist/PlatformSync.js.map +1 -0
  123. package/dist/Poll.d.ts +113 -0
  124. package/dist/Poll.d.ts.map +1 -0
  125. package/dist/Poll.js +179 -0
  126. package/dist/Poll.js.map +1 -0
  127. package/dist/Preferences.d.ts +18 -0
  128. package/dist/Preferences.d.ts.map +1 -0
  129. package/dist/Preferences.js +22 -0
  130. package/dist/Preferences.js.map +1 -0
  131. package/dist/Proposals.d.ts +29 -0
  132. package/dist/Proposals.d.ts.map +1 -0
  133. package/dist/Proposals.js +41 -0
  134. package/dist/Proposals.js.map +1 -0
  135. package/dist/React.d.ts +17 -0
  136. package/dist/React.d.ts.map +1 -0
  137. package/dist/React.js +17 -0
  138. package/dist/React.js.map +1 -0
  139. package/dist/Reader.d.ts +35 -0
  140. package/dist/Reader.d.ts.map +1 -0
  141. package/dist/Reader.js +136 -0
  142. package/dist/Reader.js.map +1 -0
  143. package/dist/Resources.d.ts +98 -0
  144. package/dist/Resources.d.ts.map +1 -0
  145. package/dist/Resources.js +161 -0
  146. package/dist/Resources.js.map +1 -0
  147. package/dist/Rows.d.ts +4 -0
  148. package/dist/Rows.d.ts.map +1 -0
  149. package/dist/Rows.js +16 -0
  150. package/dist/Rows.js.map +1 -0
  151. package/dist/Runtime.d.ts +254 -0
  152. package/dist/Runtime.d.ts.map +1 -0
  153. package/dist/Runtime.js +1283 -0
  154. package/dist/Runtime.js.map +1 -0
  155. package/dist/RuntimeRuns.d.ts +74 -0
  156. package/dist/RuntimeRuns.d.ts.map +1 -0
  157. package/dist/RuntimeRuns.js +118 -0
  158. package/dist/RuntimeRuns.js.map +1 -0
  159. package/dist/ServicesSync.d.ts +286 -0
  160. package/dist/ServicesSync.d.ts.map +1 -0
  161. package/dist/ServicesSync.js +40 -0
  162. package/dist/ServicesSync.js.map +1 -0
  163. package/dist/Session.d.ts +228 -0
  164. package/dist/Session.d.ts.map +1 -0
  165. package/dist/Session.js +792 -0
  166. package/dist/Session.js.map +1 -0
  167. package/dist/ShareGrant.d.ts +47 -0
  168. package/dist/ShareGrant.d.ts.map +1 -0
  169. package/dist/ShareGrant.js +20 -0
  170. package/dist/ShareGrant.js.map +1 -0
  171. package/dist/Sharing.d.ts +203 -0
  172. package/dist/Sharing.d.ts.map +1 -0
  173. package/dist/Sharing.js +520 -0
  174. package/dist/Sharing.js.map +1 -0
  175. package/dist/Skew.d.ts +52 -0
  176. package/dist/Skew.d.ts.map +1 -0
  177. package/dist/Skew.js +77 -0
  178. package/dist/Skew.js.map +1 -0
  179. package/dist/SpacesSync.d.ts +247 -0
  180. package/dist/SpacesSync.d.ts.map +1 -0
  181. package/dist/SpacesSync.js +30 -0
  182. package/dist/SpacesSync.js.map +1 -0
  183. package/dist/Storage.d.ts +51 -0
  184. package/dist/Storage.d.ts.map +1 -0
  185. package/dist/Storage.js +107 -0
  186. package/dist/Storage.js.map +1 -0
  187. package/dist/Sync.d.ts +48 -0
  188. package/dist/Sync.d.ts.map +1 -0
  189. package/dist/Sync.js +48 -0
  190. package/dist/Sync.js.map +1 -0
  191. package/dist/SyncTables.d.ts +13 -0
  192. package/dist/SyncTables.d.ts.map +1 -0
  193. package/dist/SyncTables.js +13 -0
  194. package/dist/SyncTables.js.map +1 -0
  195. package/dist/Tab.d.ts +36 -0
  196. package/dist/Tab.d.ts.map +1 -0
  197. package/dist/Tab.js +44 -0
  198. package/dist/Tab.js.map +1 -0
  199. package/dist/Transport.d.ts +139 -0
  200. package/dist/Transport.d.ts.map +1 -0
  201. package/dist/Transport.js +232 -0
  202. package/dist/Transport.js.map +1 -0
  203. package/dist/Upload.d.ts +41 -0
  204. package/dist/Upload.d.ts.map +1 -0
  205. package/dist/Upload.js +93 -0
  206. package/dist/Upload.js.map +1 -0
  207. package/dist/WebMcp.d.ts +78 -0
  208. package/dist/WebMcp.d.ts.map +1 -0
  209. package/dist/WebMcp.js +204 -0
  210. package/dist/WebMcp.js.map +1 -0
  211. package/dist/index.d.ts +27 -0
  212. package/dist/index.d.ts.map +1 -0
  213. package/dist/index.js +27 -0
  214. package/dist/index.js.map +1 -0
  215. package/package.json +97 -3
  216. package/src/Account.ts +249 -0
  217. package/src/Agent.ts +387 -0
  218. package/src/AgentSync.ts +59 -0
  219. package/src/AppState.ts +222 -0
  220. package/src/AppStateSync.ts +26 -0
  221. package/src/Auth.ts +225 -0
  222. package/src/Avatars.ts +144 -0
  223. package/src/BrowserAnalytics.ts +133 -0
  224. package/src/Chat.ts +1150 -0
  225. package/src/ChatIntegrity.ts +130 -0
  226. package/src/ChatSends.ts +209 -0
  227. package/src/Client.ts +319 -0
  228. package/src/Collab.ts +524 -0
  229. package/src/CollabTools.ts +381 -0
  230. package/src/Connections.ts +517 -0
  231. package/src/Consent.ts +176 -0
  232. package/src/Desktop.ts +139 -0
  233. package/src/Directory.ts +71 -0
  234. package/src/ErrorReporter.ts +112 -0
  235. package/src/ExpoSqlite.ts +6 -0
  236. package/src/FileSync.ts +34 -0
  237. package/src/FileTables.gen.ts +23 -0
  238. package/src/Foldkit.ts +960 -0
  239. package/src/History.ts +337 -0
  240. package/src/InboxSync.ts +47 -0
  241. package/src/KernelTables.gen.ts +329 -0
  242. package/src/Make.ts +120 -0
  243. package/src/Models.ts +134 -0
  244. package/src/Optimistic.ts +364 -0
  245. package/src/PlatformSync.ts +156 -0
  246. package/src/Poll.ts +227 -0
  247. package/src/Preferences.ts +42 -0
  248. package/src/Proposals.ts +57 -0
  249. package/src/React.ts +26 -0
  250. package/src/Reader.ts +180 -0
  251. package/src/Resources.ts +257 -0
  252. package/src/Rows.ts +16 -0
  253. package/src/Runtime.ts +1442 -0
  254. package/src/RuntimeRuns.ts +180 -0
  255. package/src/ServicesSync.ts +58 -0
  256. package/src/Session.ts +844 -0
  257. package/src/ShareGrant.ts +20 -0
  258. package/src/Sharing.ts +696 -0
  259. package/src/Skew.ts +97 -0
  260. package/src/SpacesSync.ts +61 -0
  261. package/src/Storage.ts +167 -0
  262. package/src/Sync.ts +125 -0
  263. package/src/SyncTables.ts +12 -0
  264. package/src/Tab.ts +59 -0
  265. package/src/Transport.ts +321 -0
  266. package/src/Upload.ts +125 -0
  267. package/src/WebMcp.ts +279 -0
  268. package/src/index.ts +26 -0
  269. package/src/web-globals.d.ts +103 -0
@@ -0,0 +1,617 @@
1
+ /**
2
+ * Foldkit bindings for the replica and the action client (`@eloxiv/client/foldkit`, decision 10), so a Foldkit
3
+ * shell reaches sync only through Eloxiv's client (decision 9). The headless SDK (`@eloxiv/client`) does not load
4
+ * Foldkit; this entry needs `foldkit` in the app.
5
+ *
6
+ * Zero keeps replication, local storage, queued optimistic writes and reconciliation. These bindings put its
7
+ * lifetimes and results into The Elm Architecture, with no second entity cache:
8
+ *
9
+ * - **Credentials stay out of the Elm state** (`Credentials`): the Model, Messages and Command arguments name a
10
+ * session by an opaque handle; the bearer token lives in a store outside the program, read by Commands and the
11
+ * replica's resource when they run, so DevTools, traces and diagnostics never see it.
12
+ * - **The replica is a ManagedResource** (`replicaResources`): the Model says whose replica should be open, in which
13
+ * organisation and under which session (`ReplicaRequirements`, the session's handle); the runtime opens it when that
14
+ * becomes known,
15
+ * closes it (its WebSocket included) when it changes or ends, and reports each transition as a Message
16
+ * (`onOpened` with the replica's `ReplicaKey`, `onClosed`, `onFailed`). A switch closes one replica before the
17
+ * next opens.
18
+ * - **Live queries are Subscriptions** (`liveQuery`): while the Model holds an open replica's key, a named query's
19
+ * results arrive as Messages carrying that key, copied out of Zero's view (rows typed by the entity's row
20
+ * schema, never a second declaration of its fields). Update keeps only snapshots of the replica the Model holds
21
+ * (`receive`), so a snapshot from a closed replica is dropped, never rendered.
22
+ * - **Connection state is a Subscription** (`connectionState`): `needs-auth`, `error` and the rest arrive as Messages.
23
+ * - **Writes are Effects for Commands.** `writeOptimistic` applies an action's prediction to the replica the Command
24
+ * names (refusing any other: `ReplicaUnavailable`) and waits for the server: it fails with the invocation's typed
25
+ * error (`Forbidden`, `InvalidInput`, ...) once the replica has dropped the prediction, or `WriteNotConfirmed`
26
+ * when the replica closes first. `callAction` calls an action through the typed client in the Command's own
27
+ * fiber. Cancellation is explicit: interrupting a Command abandons its wait and aborts an action call's request;
28
+ * it never takes back a write the replica has already queued, which the server still runs once (or refuses) and
29
+ * the replica still reconciles.
30
+ * - **Collaborative documents are Subscriptions** (`collabDocument`): while the Model names a record and a session,
31
+ * its document is open and every change arrives as a snapshot Message (text, status, presence); Commands edit it
32
+ * (`editCollabText`, `setCollabPresence`). The Y.Doc stays in the runtime, never in the Model.
33
+ */
34
+ import { InvocationError } from "@eloxiv/contracts";
35
+ import { Deferred, Effect, Option, Queue, Schema, Stream } from "effect";
36
+ import { ManagedResource } from "foldkit";
37
+ import { applyTextEdits, connectCollab } from "./Collab.js";
38
+ import { write, WriteNotConfirmed as WriteNotConfirmedError } from "./Optimistic.js";
39
+ import { copyRows } from "./Rows.js";
40
+ import { connectSync } from "./Sync.js";
41
+ export const makeCredentials = () => {
42
+ const tokens = new Map();
43
+ let next = 0;
44
+ return {
45
+ keep: (token) => {
46
+ next += 1;
47
+ const handle = `session-${next}`;
48
+ tokens.set(handle, token);
49
+ return handle;
50
+ },
51
+ token: (handle) => tokens.get(handle),
52
+ forget: (handle) => void tokens.delete(handle),
53
+ };
54
+ };
55
+ // ---------------------------------------------------------------------------------------------------------------
56
+ // The replica
57
+ /** Whose replica should be open: one user, in one organisation, under one session (its handle, never its token). */
58
+ export const ReplicaRequirements = Schema.Struct({
59
+ userId: Schema.String,
60
+ orgId: Schema.String,
61
+ session: Schema.String,
62
+ });
63
+ /**
64
+ * An opened replica's identity: its user and organisation, and which opening it is (each opening gets a new
65
+ * number, so a replica reopened for the same user and organisation is a different one). It never holds the token.
66
+ */
67
+ export const ReplicaKey = Schema.Struct({
68
+ userId: Schema.String,
69
+ orgId: Schema.String,
70
+ opening: Schema.Number,
71
+ });
72
+ export const sameReplica = (a, b) => a.userId === b.userId && a.orgId === b.orgId && a.opening === b.opening;
73
+ /** The replica as the Model records it: none, being opened for an organisation, open, or failed to open. */
74
+ export const ReplicaState = Schema.Union([
75
+ Schema.TaggedStruct("Closed", {}),
76
+ Schema.TaggedStruct("Opening", { orgId: Schema.String }),
77
+ Schema.TaggedStruct("Open", { key: ReplicaKey }),
78
+ Schema.TaggedStruct("Failed", { orgId: Schema.String, message: Schema.String }),
79
+ ]);
80
+ export const ReplicaClosed = { _tag: "Closed" };
81
+ export const ReplicaOpening = (orgId) => ({ _tag: "Opening", orgId });
82
+ /** The key of the replica the Model holds open, if any. */
83
+ export const openReplica = (state) => state._tag === "Open" ? Option.some(state.key) : Option.none();
84
+ /** The replica's ManagedResource identity: Commands and Subscriptions reach the open replica through it. */
85
+ export const Replica = ManagedResource.tag()("@eloxiv/client/Replica");
86
+ /** The same identity (one `ReplicaService`), holding the runtime's replica: what `runtimeReplica` provides. */
87
+ const RuntimeReplicaTag = ManagedResource.tag()("@eloxiv/client/Replica");
88
+ const isRuntimeReplica = (replica) => "runtime" in replica;
89
+ /** Opening the replica failed (for the organisation it was opened for). */
90
+ export class ReplicaOpenFailed extends Schema.TaggedError()("ReplicaOpenFailed", {
91
+ orgId: Schema.String,
92
+ message: Schema.String,
93
+ }) {
94
+ }
95
+ let openings = 0;
96
+ /**
97
+ * The replica as a Foldkit ManagedResource record, for `makeApplication({ managedResources })` (combine it with an
98
+ * app's own through `ManagedResource.aggregate`). Opening it connects to zero-cache; releasing it closes Zero,
99
+ * which closes its WebSocket, and ends every wait on its writes.
100
+ *
101
+ * @deprecated A second implementation of the replica's lifetime beside the client core's: use `runtimeReplica` over
102
+ * one `makeClientRuntime` (`@eloxiv/client/runtime`), which owns the session, the organisation's generation, the
103
+ * replica, live queries and writes for every client. `liveQuery`, `writeOptimistic` and `connectionState` work
104
+ * over either.
105
+ */
106
+ export const replicaResources = (options) => ManagedResource.make()((entry) => ({
107
+ eloxivReplica: entry(Schema.Option(ReplicaRequirements), {
108
+ resource: Replica,
109
+ modelToMaybeRequirements: options.requirements,
110
+ acquire: (requirements) => Effect.gen(function* () {
111
+ const closed = yield* Deferred.make();
112
+ const token = options.credentials.token(requirements.session);
113
+ if (token === undefined) {
114
+ return yield* new ReplicaOpenFailed({ orgId: requirements.orgId, message: "The session has ended" });
115
+ }
116
+ const zero = yield* Effect.try({
117
+ try: () => connectSync({
118
+ server: options.server,
119
+ schema: options.schema,
120
+ userId: requirements.userId,
121
+ token,
122
+ orgId: requirements.orgId,
123
+ storage: options.storage ?? "idb",
124
+ mutators: options.mutators,
125
+ clientVersion: options.clientVersion,
126
+ }),
127
+ catch: (error) => new ReplicaOpenFailed({ orgId: requirements.orgId, message: messageOf(error) }),
128
+ });
129
+ openings += 1;
130
+ const replica = {
131
+ key: { userId: requirements.userId, orgId: requirements.orgId, opening: openings },
132
+ zero,
133
+ closed,
134
+ };
135
+ return replica;
136
+ }),
137
+ release: (replica) => Deferred.succeed(replica.closed, undefined).pipe(Effect.andThen(Effect.promise(() => replica.zero.close().catch(() => undefined)))),
138
+ onAcquired: (replica) => options.onOpened(replica.key),
139
+ onReleased: () => options.onClosed(),
140
+ onAcquireError: (error) => options.onFailed(error instanceof ReplicaOpenFailed
141
+ ? { orgId: error.orgId, message: error.message }
142
+ : { orgId: "", message: messageOf(error) }),
143
+ }),
144
+ }));
145
+ const messageOf = (error) => (error instanceof Error ? error.message : String(error));
146
+ /** Which generation of the runtime's context the Model wants to act in: one person, one organisation. */
147
+ export const RuntimeReplicaRequirements = Schema.Struct({
148
+ userId: Schema.String,
149
+ orgId: Schema.String,
150
+ generation: Schema.Number,
151
+ });
152
+ /**
153
+ * The ClientRuntime's replica as a Foldkit ManagedResource record (`makeApplication({ managedResources })`): the
154
+ * runtime owns the replica's lifetime (an organisation change, a sign-out or `needs-auth` destroys its views and closes
155
+ * it before anything of the next context is emitted), and this resource names the generation the Model acts in, so
156
+ * Commands and Subscriptions reach it through `ReplicaService` as before: `liveQuery` runs a named query through
157
+ * `runtime.subscribe`, `writeOptimistic` writes through `runtime.write`, both refused for another generation. The key's
158
+ * `opening` is the generation; `onOpened` reports it once the Model's requirements are taken, `onClosed` when they go.
159
+ */
160
+ export const runtimeReplica = (options) => ManagedResource.make()((entry) => ({
161
+ eloxivReplica: entry(Schema.Option(RuntimeReplicaRequirements), {
162
+ resource: RuntimeReplicaTag,
163
+ modelToMaybeRequirements: options.requirements,
164
+ acquire: (requirements) => Effect.map(Deferred.make(), (closed) => ({
165
+ key: { userId: requirements.userId, orgId: requirements.orgId, opening: requirements.generation },
166
+ runtime: options.runtime,
167
+ owner: options.owner ?? "foldkit",
168
+ closed,
169
+ })),
170
+ release: (replica) => Deferred.succeed(replica.closed, undefined).pipe(Effect.asVoid),
171
+ onAcquired: (replica) => options.onOpened(replica.key),
172
+ onReleased: () => options.onClosed(),
173
+ onAcquireError: (error) => options.onFailed({ orgId: "", message: messageOf(error) }),
174
+ }),
175
+ }));
176
+ /**
177
+ * The runtime's events as a Foldkit Subscription entry, for a `Subscription.make` record: while it runs, `toMessage`
178
+ * turns each event (and, first, the runtime's current state, `initial`) into Messages; `rows` and `write` events are
179
+ * left to `liveQuery` and `writeOptimistic`. The adapter's one way the runtime's session, context and connection reach
180
+ * a Model.
181
+ */
182
+ export const runtimeEvents = (options) => ({
183
+ dependenciesSchema: Schema.Struct({}),
184
+ modelToDependencies: (_model) => ({}),
185
+ dependenciesToStream: () => Stream.callback((queue) => Effect.acquireRelease(Effect.sync(() => {
186
+ const offer = (message) => {
187
+ if (message !== undefined)
188
+ Queue.offerUnsafe(queue, message);
189
+ };
190
+ const stopEvents = options.runtime.onEvent((event) => {
191
+ if (event.type !== "rows" && event.type !== "write")
192
+ offer(options.toMessage(event));
193
+ });
194
+ const stopRevocation = options.onRevocation === undefined
195
+ ? () => undefined
196
+ : options.runtime.onRevocation((status) => offer(options.onRevocation(status)));
197
+ for (const message of options.initial())
198
+ offer(message);
199
+ return () => {
200
+ stopEvents();
201
+ stopRevocation();
202
+ };
203
+ }), (stop) => Effect.sync(stop)).pipe(Effect.andThen(Effect.never))),
204
+ });
205
+ /**
206
+ * The runtime's session behind an opaque handle in `credentials`, for Models, Messages and Command arguments: the
207
+ * same handle while the token is the same, a new one when it changes (a new sign-in, a rotated session), and the old
208
+ * handle forgotten then, or when nobody is signed in, so a Command still holding it reads no token.
209
+ */
210
+ export const runtimeSessionHandle = (runtime, credentials) => {
211
+ let current;
212
+ return () => {
213
+ const token = runtime.token();
214
+ if (current?.token === token)
215
+ return current?.handle;
216
+ if (current !== undefined)
217
+ credentials.forget(current.handle);
218
+ current = token === undefined ? undefined : { token, handle: credentials.keep(token) };
219
+ return current?.handle;
220
+ };
221
+ };
222
+ /** The open replica, if it is the one `key` names; `ReplicaUnavailable` otherwise. */
223
+ export class ReplicaUnavailable extends Schema.TaggedError()("ReplicaUnavailable", {
224
+ message: Schema.String,
225
+ }) {
226
+ }
227
+ export const replicaFor = (key) => Replica.get.pipe(Effect.catchTag("ResourceNotAvailable", () => Effect.fail(new ReplicaUnavailable({ message: "No replica is open" }))),
228
+ // Either kind under the one identity: the adapter's own (`replicaResources`) or the runtime's (`runtimeReplica`).
229
+ Effect.map((replica) => replica), Effect.flatMap((replica) => sameReplica(replica.key, key)
230
+ ? Effect.succeed(replica)
231
+ : Effect.fail(new ReplicaUnavailable({
232
+ message: `The replica of ${key.orgId} (opening ${key.opening}) is no longer open`,
233
+ }))));
234
+ // ---------------------------------------------------------------------------------------------------------------
235
+ // Live queries
236
+ /** Where a query's result stands, as Zero reports it. */
237
+ export const ResultStatus = Schema.Literals(["unknown", "cached", "complete", "error"]);
238
+ /**
239
+ * The schema of a snapshot of rows of type `Row`, checked by `row`: the entity's row schema (`entity.row`) checks
240
+ * each row as it arrives, and `Row` (the generated sync table's row type, `Row<typeof greetingTable>`) types it,
241
+ * both derived from the module's one Drizzle table.
242
+ */
243
+ export const Snapshot = (row) => Schema.Struct({
244
+ key: ReplicaKey,
245
+ rows: Schema.Array(row),
246
+ status: ResultStatus,
247
+ error: Schema.Option(Schema.String),
248
+ });
249
+ /**
250
+ * A query's place in the Model: waiting for the replica's first result, or the latest result of the replica the
251
+ * Model holds. Interaction state only: the rows are what the replica delivered, as delivered.
252
+ */
253
+ export const QueryState = (row) => Schema.Union([Schema.TaggedStruct("Waiting", {}), Schema.TaggedStruct("Received", { snapshot: Snapshot(row) })]);
254
+ export const QueryWaiting = { _tag: "Waiting" };
255
+ /**
256
+ * The query state after a snapshot arrives: kept only when it comes from the replica the Model holds open, so a
257
+ * snapshot that left a closed replica before it closed is never shown.
258
+ */
259
+ export const receive = (state, replica, snapshot) => replica._tag === "Open" && sameReplica(replica.key, snapshot.key) ? { _tag: "Received", snapshot } : state;
260
+ /**
261
+ * A snapshot's rows when it comes from `replica` (the replica a screen was made for: its user, organisation and
262
+ * opening), none otherwise: a snapshot that left another replica (the previous organisation's, a closed one's)
263
+ * before its view was destroyed is never taken. For a handler that keeps rows rather than a `QueryState`.
264
+ */
265
+ export const rowsFrom = (replica, snapshot) => sameReplica(replica, snapshot.key) ? Option.some(snapshot.rows) : Option.none();
266
+ /**
267
+ * `rowsFrom`, once the server has answered: none for a snapshot of another replica, and none while the replica has
268
+ * only what it held before asking (`unknown`), which a screen must not show as the query's answer (an empty list on
269
+ * a slow first sync reads as "nothing there"). For a handler that keeps rows and says it is ready once it has some.
270
+ */
271
+ export const settledRowsFrom = (replica, snapshot) => snapshot.status === "unknown" ? Option.none() : rowsFrom(replica, snapshot);
272
+ /** The rows to render: the received snapshot's, or none while waiting. */
273
+ export const rowsOf = (state) => state._tag === "Received" ? state.snapshot.rows : [];
274
+ /** Whether the server has confirmed the result (this session or a cached earlier one). */
275
+ export const isSettled = (state) => state._tag === "Received" && (state.snapshot.status === "complete" || state.snapshot.status === "cached");
276
+ /**
277
+ * A live query as a Foldkit Subscription entry, for a `Subscription.make` record. While `replica(model)` names an
278
+ * open replica, the query runs there and every change arrives as `toMessage(snapshot, scope)`; when the Model's
279
+ * replica changes or closes, the view is destroyed and a new one opens on the next replica.
280
+ *
281
+ * A record-scoped query (one thread, one person) takes `scope(model)`, the argument it is run with
282
+ * (`query(scope)`): when it changes, the view on the old one is destroyed and one on the new one opens, and each
283
+ * snapshot names the scope it is of.
284
+ */
285
+ export const liveQuery = (options) => ({
286
+ dependenciesSchema: Schema.Struct({ replica: Schema.Option(ReplicaKey), scope: Schema.String }),
287
+ modelToDependencies: (model) => ({ replica: options.replica(model), scope: options.scope?.(model) ?? "" }),
288
+ dependenciesToStream: ({ replica, scope = "", }) => replicaStream(replica, (key, offer, end) => ({
289
+ runtime: (replica) => runtimeQuery(replica, options.query(scope), (rows, status, error) => offer(options.toMessage({ key, rows: rows, status, error }, scope))).pipe(Effect.catch(() => Effect.sync(end))),
290
+ zero: (replica) => Effect.acquireRelease(Effect.sync(() => {
291
+ const view = replica.zero.materialize(options.query(scope));
292
+ view.addListener((data, status, error) => {
293
+ offer(options.toMessage({
294
+ key,
295
+ rows: copyRows(data),
296
+ status,
297
+ error: error === undefined ? Option.none() : Option.some(errorText(error)),
298
+ }, scope));
299
+ });
300
+ return view;
301
+ }), (view) => Effect.sync(() => {
302
+ try {
303
+ view.destroy();
304
+ }
305
+ catch {
306
+ // The replica closed first: its views went with it.
307
+ }
308
+ })).pipe(Effect.asVoid),
309
+ })),
310
+ });
311
+ /**
312
+ * A replica's Subscription stream: nothing without a key; with one, `work` on that replica (`offer` sends a Message,
313
+ * `end` ends the stream), through `onOpenReplica`.
314
+ */
315
+ const replicaStream = (replica, work) => Option.match(replica, {
316
+ onNone: () => Stream.empty,
317
+ onSome: (key) => Stream.callback((queue) => {
318
+ const end = () => Queue.endUnsafe(queue);
319
+ return onOpenReplica(key, end, work(key, (message) => Queue.offerUnsafe(queue, message), end));
320
+ }),
321
+ });
322
+ /**
323
+ * A Subscription's work on the replica `key` names, while the scope lasts: `runtime`'s on the client core's replica,
324
+ * `zero`'s on one this adapter opened; when it is not the replica the Model holds open (it closed, or another
325
+ * opened), nothing (`end`: the stream has nothing to say).
326
+ */
327
+ const onOpenReplica = (key, end, work) => Effect.gen(function* () {
328
+ const open = yield* replicaFor(key).pipe(Effect.option);
329
+ if (Option.isNone(open))
330
+ return end();
331
+ yield* isRuntimeReplica(open.value) ? work.runtime(open.value) : work.zero(open.value);
332
+ yield* Effect.never;
333
+ });
334
+ const errorText = (error) => {
335
+ const e = error;
336
+ if (typeof e.message === "string")
337
+ return e.message;
338
+ return JSON.stringify(error);
339
+ };
340
+ /** Web Crypto, read from `globalThis` (the SDK declares no DOM types). */
341
+ const webCrypto = globalThis.crypto;
342
+ const randomId = () => typeof webCrypto?.randomUUID === "function"
343
+ ? webCrypto.randomUUID()
344
+ : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
345
+ /**
346
+ * A named query run live by the runtime, in the replica's generation (refused for another), for as long as the scope
347
+ * lasts: each `rows` event of it reaches `onRows`. Fails when the runtime refuses it (another generation, signed out).
348
+ */
349
+ const runtimeQuery = (replica, request, onRows) => {
350
+ const id = randomId();
351
+ const name = request.query.queryName;
352
+ return Effect.acquireRelease(Effect.tryPromise({
353
+ try: async () => {
354
+ if (typeof name !== "string")
355
+ throw new Error("Not a named query");
356
+ const stop = replica.runtime.onEvent((event) => {
357
+ if (event.type !== "rows" || event.subscription !== id || event.generation !== replica.key.opening)
358
+ return;
359
+ onRows(event.rows, event.status, event.error === undefined ? Option.none() : Option.some(errorText(event.error)));
360
+ });
361
+ try {
362
+ await replica.runtime.subscribe({ query: name, args: request.args, id, generation: replica.key.opening }, replica.owner);
363
+ }
364
+ catch (error) {
365
+ stop();
366
+ throw error;
367
+ }
368
+ return stop;
369
+ },
370
+ catch: (error) => error,
371
+ }), (stop) => Effect.sync(() => {
372
+ stop();
373
+ try {
374
+ replica.runtime.unsubscribe(id, replica.owner);
375
+ }
376
+ catch {
377
+ // The context changed first: the runtime destroyed the view with it.
378
+ }
379
+ }));
380
+ };
381
+ // ---------------------------------------------------------------------------------------------------------------
382
+ // Connection state
383
+ /** Zero's connection state, as Messages carry it. */
384
+ export const ConnectionState = Schema.Struct({
385
+ key: ReplicaKey,
386
+ state: Schema.Literals(["initializing", "connecting", "disconnected", "connected", "needs-auth", "error", "closed"]),
387
+ reason: Schema.Option(Schema.String),
388
+ });
389
+ /** The runtime's connection states (the LocalClient contract's), as Zero names them. */
390
+ const RUNTIME_CONNECTION = { connecting: "connecting", connected: "connected", disconnected: "disconnected", needsAuth: "needs-auth" };
391
+ /** The open replica's connection state as a Subscription entry: every change (and the current state) as a Message. */
392
+ export const connectionState = (options) => ({
393
+ dependenciesSchema: Schema.Struct({ replica: Schema.Option(ReplicaKey) }),
394
+ modelToDependencies: (model) => ({ replica: options.replica(model) }),
395
+ dependenciesToStream: ({ replica, }) => replicaStream(replica, (key, offer) => ({
396
+ // The runtime's own connection events, while its context is this generation.
397
+ runtime: (replica) => Effect.acquireRelease(Effect.sync(() => replica.runtime.onEvent((event) => {
398
+ if (event.type !== "connection" || replica.runtime.generation() !== key.opening)
399
+ return;
400
+ offer(options.toMessage({ key, state: RUNTIME_CONNECTION[event.state], reason: Option.none() }));
401
+ })), (stop) => Effect.sync(stop)).pipe(Effect.asVoid),
402
+ zero: (replica) => {
403
+ const source = replica.zero.connection.state;
404
+ const emit = (state) => offer(options.toMessage({
405
+ key,
406
+ state: state.name,
407
+ reason: state.reason === undefined
408
+ ? Option.none()
409
+ : Option.some(typeof state.reason === "string" ? state.reason : JSON.stringify(state.reason)),
410
+ }));
411
+ return Effect.acquireRelease(Effect.sync(() => {
412
+ emit(source.current);
413
+ return source.subscribe(emit);
414
+ }), (unsubscribe) => Effect.sync(unsubscribe)).pipe(Effect.asVoid);
415
+ },
416
+ })),
417
+ });
418
+ // ---------------------------------------------------------------------------------------------------------------
419
+ // Writes
420
+ /** The server did not confirm a write: the replica closed or went offline before it answered. It may still run. */
421
+ export class WriteNotConfirmed extends Schema.TaggedError()("WriteNotConfirmed", {
422
+ message: Schema.String,
423
+ }) {
424
+ }
425
+ /** Why a write did not land, as a Message carries it: the invocation's typed error, or no confirmation. */
426
+ export const WriteError = Schema.Union([InvocationError, WriteNotConfirmed, ReplicaUnavailable]);
427
+ const isInvocationError = Schema.is(InvocationError);
428
+ /**
429
+ * Write optimistically on the replica `key` names: `writeOptimistic(key, mutators.hello.greet({ message }))`. The
430
+ * prediction is applied at once (the live queries show it); the Effect succeeds once the server ran the action and
431
+ * the replica holds its rows, and fails with the invocation's typed error once the replica has dropped the
432
+ * prediction, `WriteNotConfirmed` if the replica closes first, or `ReplicaUnavailable` if `key` is not the open
433
+ * replica (nothing is written then). Interrupting it stops the wait, not the write.
434
+ */
435
+ export const writeOptimistic = (key, request) => Effect.gen(function* () {
436
+ const replica = yield* replicaFor(key);
437
+ if (isRuntimeReplica(replica))
438
+ return yield* runtimeWrite(replica, request);
439
+ const pending = write(replica.zero, request);
440
+ const server = Effect.tryPromise({
441
+ try: () => pending.server,
442
+ catch: (error) => isInvocationError(error)
443
+ ? error
444
+ : error instanceof WriteNotConfirmedError
445
+ ? new WriteNotConfirmed({ message: error.message })
446
+ : new WriteNotConfirmed({ message: messageOf(error) }),
447
+ });
448
+ const closed = closedFirst(replica.closed);
449
+ yield* Effect.raceFirst(server, closed);
450
+ });
451
+ const decodeInvocationError = Schema.decodeUnknownOption(InvocationError);
452
+ /** Fails with `WriteNotConfirmed` once the replica is let go of: what a write's wait races. */
453
+ const closedFirst = (closed) => Deferred.await(closed).pipe(Effect.andThen(Effect.fail(new WriteNotConfirmed({ message: "The replica closed before the server answered" }))));
454
+ /**
455
+ * An optimistic write through the runtime, in the replica's generation (nothing predicted or sent for another): it
456
+ * succeeds once confirmed, fails with the kernel's typed error once rejected (after the rollback), or
457
+ * `WriteNotConfirmed` when the replica goes offline, the context changes or the Model lets go of it first.
458
+ */
459
+ const runtimeWrite = (replica, request) => Effect.gen(function* () {
460
+ const id = randomId();
461
+ const outcome = yield* Deferred.make();
462
+ const settle = (exit) => Effect.runSync(exit === undefined ? Deferred.succeed(outcome, undefined) : Deferred.fail(outcome, exit));
463
+ const stop = replica.runtime.onEvent((event) => {
464
+ if (event.type === "context") {
465
+ settle(new WriteNotConfirmed({ message: "The context changed before the server answered" }));
466
+ return;
467
+ }
468
+ if (event.type !== "write" || event.id !== id)
469
+ return;
470
+ if (event.phase === "confirmed")
471
+ settle(undefined);
472
+ else if (event.phase === "rejected")
473
+ settle(Option.getOrElse(decodeInvocationError(event.error), () => new WriteNotConfirmed({ message: errorText(event.error) })));
474
+ else if (event.phase === "notConfirmed")
475
+ settle(new WriteNotConfirmed({ message: event.message ?? "The server did not confirm the write" }));
476
+ });
477
+ const mutator = request.mutator
478
+ ?.mutatorName;
479
+ const started = Effect.tryPromise({
480
+ try: async () => {
481
+ if (typeof mutator !== "string")
482
+ throw new Error("Not a named mutator");
483
+ await replica.runtime.write({
484
+ mutator,
485
+ input: request.args,
486
+ id,
487
+ generation: replica.key.opening,
488
+ }, replica.owner);
489
+ },
490
+ catch: (error) =>
491
+ // The kernel's typed refusal (`InvalidInput`, ...) as it is; anything else (another generation, signed out,
492
+ // closed) means this replica is no longer the one to write to.
493
+ isInvocationError(error) ? error : new ReplicaUnavailable({ message: messageOf(error) }),
494
+ });
495
+ const closed = closedFirst(replica.closed);
496
+ yield* started.pipe(Effect.andThen(Deferred.await(outcome)), (wait) => Effect.raceFirst(wait, closed), Effect.ensuring(Effect.sync(stop)));
497
+ });
498
+ /** A call that did not reach a typed answer (the network, the protocol). */
499
+ export class ActionCallFailed extends Schema.TaggedError()("ActionCallFailed", {
500
+ action: Schema.String,
501
+ message: Schema.String,
502
+ }) {
503
+ }
504
+ /**
505
+ * Call an action through the typed client, in the calling fiber: the Command that runs it owns the request, so
506
+ * interrupting the Command aborts it (a call that already reached the kernel may still run, once with an
507
+ * idempotency key). Fails with the action's typed error, or `ActionCallFailed`.
508
+ */
509
+ export const callAction = (client, action, input, acting) => client
510
+ .callEffect(action, input, acting)
511
+ .pipe(Effect.mapError((error) => isInvocationError(error) ? error : new ActionCallFailed({ action, message: messageOf(error) })));
512
+ // ---------------------------------------------------------------------------------------------------------------
513
+ // Collaborative documents
514
+ /** Which record's collaborative document the Model wants open, under which session (its handle, never its token). */
515
+ export const CollabTarget = Schema.Struct({
516
+ entity: Schema.String,
517
+ id: Schema.String,
518
+ orgId: Schema.String,
519
+ session: Schema.String,
520
+ });
521
+ /** A peer's presence, as Messages carry it. */
522
+ export const CollabPeerState = Schema.Struct({ clientId: Schema.Number, userId: Schema.String, state: Schema.Unknown });
523
+ /**
524
+ * One state of an open collaborative document, as a Message carries it: the text root's text (a copy), whether the
525
+ * caller may change it, the connection's status, others' presence, and why the kernel closed it, if it did.
526
+ */
527
+ export const CollabSnapshot = Schema.Struct({
528
+ entity: Schema.String,
529
+ id: Schema.String,
530
+ orgId: Schema.String,
531
+ text: Schema.String,
532
+ seq: Schema.Number,
533
+ canWrite: Schema.Boolean,
534
+ status: Schema.Literals(["connecting", "synced", "offline", "closed"]),
535
+ peers: Schema.Array(CollabPeerState),
536
+ closedWith: Schema.Option(Schema.String),
537
+ });
538
+ /** No collaborative document is open for that record (the Model no longer wants it, or it has not opened yet). */
539
+ export class CollabUnavailable extends Schema.TaggedError()("CollabUnavailable", {
540
+ message: Schema.String,
541
+ }) {
542
+ }
543
+ /** A text edit whose passage is not in the document: nothing was applied. */
544
+ export class CollabEditRefused extends Schema.TaggedError()("CollabEditRefused", {
545
+ message: Schema.String,
546
+ }) {
547
+ }
548
+ const collabKey = (target) => `${target.orgId}\u0000${target.entity}\u0000${target.id}`;
549
+ /** The documents the `collabDocument` Subscriptions hold open, by record: what Commands edit. */
550
+ const openDocuments = new Map();
551
+ /**
552
+ * A record's collaborative document as a Foldkit Subscription entry. While `document(model)` names a record and a
553
+ * session, the document is open (its WebSocket included) and every change (a local or remote edit, presence, the
554
+ * connection's status) arrives as `toMessage(snapshot)`; when the Model names another record, organisation or
555
+ * session, or none, the connection closes and its presence is withdrawn. The Y.Doc stays inside the runtime: the
556
+ * Model holds snapshots, never the document. Edit it with `editCollabText` and `setCollabPresence` Commands.
557
+ */
558
+ export const collabDocument = (options) => ({
559
+ dependenciesSchema: Schema.Struct({ document: Schema.Option(CollabTarget) }),
560
+ modelToDependencies: (model) => ({ document: options.document(model) }),
561
+ dependenciesToStream: ({ document }) => Option.match(document, {
562
+ onNone: () => Stream.empty,
563
+ onSome: (target) => Stream.callback((queue) => Effect.acquireRelease(Effect.sync(() => {
564
+ const name = options.text ?? "content";
565
+ const connection = connectCollab({
566
+ baseUrl: options.baseUrl,
567
+ entity: target.entity,
568
+ id: target.id,
569
+ orgId: target.orgId,
570
+ token: () => options.credentials.token(target.session),
571
+ WebSocket: options.WebSocket,
572
+ });
573
+ const key = collabKey(target);
574
+ openDocuments.set(key, { connection, text: name });
575
+ const snapshot = () => ({
576
+ entity: target.entity,
577
+ id: target.id,
578
+ orgId: target.orgId,
579
+ text: connection.doc.getText(name).toJSON(),
580
+ seq: connection.seq,
581
+ canWrite: connection.canWrite,
582
+ status: connection.status,
583
+ peers: connection.peers.map((p) => ({ clientId: p.clientId, userId: p.userId, state: p.state })),
584
+ closedWith: connection.closedWith === undefined ? Option.none() : Option.some(connection.closedWith._tag),
585
+ });
586
+ const emit = () => Queue.offerUnsafe(queue, options.toMessage(snapshot()));
587
+ const stop = connection.subscribe(emit);
588
+ connection.doc.on("update", emit);
589
+ emit();
590
+ return { key, connection, stop, emit };
591
+ }), ({ key, connection, stop, emit }) => Effect.sync(() => {
592
+ stop();
593
+ connection.doc.off("update", emit);
594
+ if (openDocuments.get(key)?.connection === connection)
595
+ openDocuments.delete(key);
596
+ connection.close();
597
+ })).pipe(Effect.andThen(Effect.never))),
598
+ }),
599
+ });
600
+ const openDocument = (target) => {
601
+ const open = openDocuments.get(collabKey(target));
602
+ return open === undefined || open.connection.status === "closed"
603
+ ? Effect.fail(new CollabUnavailable({ message: `No collaborative document of ${target.entity} ${target.id} is open` }))
604
+ : Effect.succeed(open);
605
+ };
606
+ /**
607
+ * Edit the open document's text root (the kinds `collab.editText` takes), as one Yjs transaction that the document
608
+ * sends to the kernel: for Commands. Succeeds with the text after the edits; nothing is applied when a passage is
609
+ * not there (`CollabEditRefused`) or the document is not open (`CollabUnavailable`).
610
+ */
611
+ export const editCollabText = (target, edits) => Effect.flatMap(openDocument(target), (open) => Effect.try({
612
+ try: () => applyTextEdits(open.connection.doc, open.text, edits),
613
+ catch: (error) => new CollabEditRefused({ message: messageOf(error) }),
614
+ }));
615
+ /** Publish (or withdraw, with null) this client's presence on the open document: for Commands. */
616
+ export const setCollabPresence = (target, state) => Effect.map(openDocument(target), (open) => open.connection.setPresence(state));
617
+ //# sourceMappingURL=Foldkit.js.map