@meshline/sdk 0.0.0-stage → 0.1.0-alpha.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 (338) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +43 -2
  3. package/dist/channels/repository.d.ts +73 -0
  4. package/dist/channels/repository.d.ts.map +1 -0
  5. package/dist/channels/repository.js +367 -0
  6. package/dist/channels/repository.js.map +1 -0
  7. package/dist/client/account-operations.d.ts +41 -0
  8. package/dist/client/account-operations.d.ts.map +1 -0
  9. package/dist/client/account-operations.js +304 -0
  10. package/dist/client/account-operations.js.map +1 -0
  11. package/dist/client/conversations.d.ts +36 -0
  12. package/dist/client/conversations.d.ts.map +1 -0
  13. package/dist/client/conversations.js +144 -0
  14. package/dist/client/conversations.js.map +1 -0
  15. package/dist/client.d.ts +53 -0
  16. package/dist/client.d.ts.map +1 -0
  17. package/dist/client.js +162 -0
  18. package/dist/client.js.map +1 -0
  19. package/dist/components/account.d.ts +38 -0
  20. package/dist/components/account.d.ts.map +1 -0
  21. package/dist/components/account.js +243 -0
  22. package/dist/components/account.js.map +1 -0
  23. package/dist/components/channel.d.ts +78 -0
  24. package/dist/components/channel.d.ts.map +1 -0
  25. package/dist/components/channel.js +475 -0
  26. package/dist/components/channel.js.map +1 -0
  27. package/dist/components/component.d.ts +49 -0
  28. package/dist/components/component.d.ts.map +1 -0
  29. package/dist/components/component.js +194 -0
  30. package/dist/components/component.js.map +1 -0
  31. package/dist/components/device.d.ts +60 -0
  32. package/dist/components/device.d.ts.map +1 -0
  33. package/dist/components/device.js +648 -0
  34. package/dist/components/device.js.map +1 -0
  35. package/dist/components/group.d.ts +141 -0
  36. package/dist/components/group.d.ts.map +1 -0
  37. package/dist/components/group.js +933 -0
  38. package/dist/components/group.js.map +1 -0
  39. package/dist/components/message.d.ts +63 -0
  40. package/dist/components/message.d.ts.map +1 -0
  41. package/dist/components/message.js +439 -0
  42. package/dist/components/message.js.map +1 -0
  43. package/dist/components/profile.d.ts +37 -0
  44. package/dist/components/profile.d.ts.map +1 -0
  45. package/dist/components/profile.js +232 -0
  46. package/dist/components/profile.js.map +1 -0
  47. package/dist/crypto/groups.d.ts +56 -0
  48. package/dist/crypto/groups.d.ts.map +1 -0
  49. package/dist/crypto/groups.js +163 -0
  50. package/dist/crypto/groups.js.map +1 -0
  51. package/dist/crypto/messages.d.ts +52 -0
  52. package/dist/crypto/messages.d.ts.map +1 -0
  53. package/dist/crypto/messages.js +180 -0
  54. package/dist/crypto/messages.js.map +1 -0
  55. package/dist/crypto/primitives.d.ts +30 -0
  56. package/dist/crypto/primitives.d.ts.map +1 -0
  57. package/dist/crypto/primitives.js +102 -0
  58. package/dist/crypto/primitives.js.map +1 -0
  59. package/dist/errors.d.ts +11 -0
  60. package/dist/errors.d.ts.map +1 -0
  61. package/dist/errors.js +14 -0
  62. package/dist/errors.js.map +1 -0
  63. package/dist/groups/account-sync.d.ts +28 -0
  64. package/dist/groups/account-sync.d.ts.map +1 -0
  65. package/dist/groups/account-sync.js +235 -0
  66. package/dist/groups/account-sync.js.map +1 -0
  67. package/dist/groups/messages.d.ts +39 -0
  68. package/dist/groups/messages.d.ts.map +1 -0
  69. package/dist/groups/messages.js +141 -0
  70. package/dist/groups/messages.js.map +1 -0
  71. package/dist/groups/operations.d.ts +57 -0
  72. package/dist/groups/operations.d.ts.map +1 -0
  73. package/dist/groups/operations.js +225 -0
  74. package/dist/groups/operations.js.map +1 -0
  75. package/dist/groups/repository.d.ts +56 -0
  76. package/dist/groups/repository.d.ts.map +1 -0
  77. package/dist/groups/repository.js +254 -0
  78. package/dist/groups/repository.js.map +1 -0
  79. package/dist/groups/secrets.d.ts +67 -0
  80. package/dist/groups/secrets.d.ts.map +1 -0
  81. package/dist/groups/secrets.js +452 -0
  82. package/dist/groups/secrets.js.map +1 -0
  83. package/dist/groups/state.d.ts +39 -0
  84. package/dist/groups/state.d.ts.map +1 -0
  85. package/dist/groups/state.js +201 -0
  86. package/dist/groups/state.js.map +1 -0
  87. package/dist/identity/identifiers.d.ts +9 -0
  88. package/dist/identity/identifiers.d.ts.map +1 -0
  89. package/dist/identity/identifiers.js +37 -0
  90. package/dist/identity/identifiers.js.map +1 -0
  91. package/dist/identity/neo.d.ts +11 -0
  92. package/dist/identity/neo.d.ts.map +1 -0
  93. package/dist/identity/neo.js +77 -0
  94. package/dist/identity/neo.js.map +1 -0
  95. package/dist/index.d.ts +53 -0
  96. package/dist/index.d.ts.map +1 -0
  97. package/dist/index.js +46 -0
  98. package/dist/index.js.map +1 -0
  99. package/dist/interactions.d.ts +31 -0
  100. package/dist/interactions.d.ts.map +1 -0
  101. package/dist/interactions.js +2 -0
  102. package/dist/interactions.js.map +1 -0
  103. package/dist/messages/account-sender.d.ts +9 -0
  104. package/dist/messages/account-sender.d.ts.map +1 -0
  105. package/dist/messages/account-sender.js +46 -0
  106. package/dist/messages/account-sender.js.map +1 -0
  107. package/dist/messages/contacts.d.ts +103 -0
  108. package/dist/messages/contacts.d.ts.map +1 -0
  109. package/dist/messages/contacts.js +525 -0
  110. package/dist/messages/contacts.js.map +1 -0
  111. package/dist/messages/outbox.d.ts +66 -0
  112. package/dist/messages/outbox.d.ts.map +1 -0
  113. package/dist/messages/outbox.js +167 -0
  114. package/dist/messages/outbox.js.map +1 -0
  115. package/dist/messages/receiver.d.ts +35 -0
  116. package/dist/messages/receiver.d.ts.map +1 -0
  117. package/dist/messages/receiver.js +113 -0
  118. package/dist/messages/receiver.js.map +1 -0
  119. package/dist/messages/repository.d.ts +89 -0
  120. package/dist/messages/repository.d.ts.map +1 -0
  121. package/dist/messages/repository.js +295 -0
  122. package/dist/messages/repository.js.map +1 -0
  123. package/dist/models/authentication.d.ts +37 -0
  124. package/dist/models/authentication.d.ts.map +1 -0
  125. package/dist/models/authentication.js +53 -0
  126. package/dist/models/authentication.js.map +1 -0
  127. package/dist/models/channels.d.ts +141 -0
  128. package/dist/models/channels.d.ts.map +1 -0
  129. package/dist/models/channels.js +258 -0
  130. package/dist/models/channels.js.map +1 -0
  131. package/dist/models/contacts.d.ts +68 -0
  132. package/dist/models/contacts.d.ts.map +1 -0
  133. package/dist/models/contacts.js +186 -0
  134. package/dist/models/contacts.js.map +1 -0
  135. package/dist/models/content.d.ts +37 -0
  136. package/dist/models/content.d.ts.map +1 -0
  137. package/dist/models/content.js +137 -0
  138. package/dist/models/content.js.map +1 -0
  139. package/dist/models/device-state.d.ts +8 -0
  140. package/dist/models/device-state.d.ts.map +1 -0
  141. package/dist/models/device-state.js +22 -0
  142. package/dist/models/device-state.js.map +1 -0
  143. package/dist/models/group-admission.d.ts +111 -0
  144. package/dist/models/group-admission.d.ts.map +1 -0
  145. package/dist/models/group-admission.js +153 -0
  146. package/dist/models/group-admission.js.map +1 -0
  147. package/dist/models/group-keys.d.ts +30 -0
  148. package/dist/models/group-keys.d.ts.map +1 -0
  149. package/dist/models/group-keys.js +52 -0
  150. package/dist/models/group-keys.js.map +1 -0
  151. package/dist/models/group-management.d.ts +190 -0
  152. package/dist/models/group-management.d.ts.map +1 -0
  153. package/dist/models/group-management.js +263 -0
  154. package/dist/models/group-management.js.map +1 -0
  155. package/dist/models/groups.d.ts +81 -0
  156. package/dist/models/groups.d.ts.map +1 -0
  157. package/dist/models/groups.js +127 -0
  158. package/dist/models/groups.js.map +1 -0
  159. package/dist/models/identity.d.ts +47 -0
  160. package/dist/models/identity.d.ts.map +1 -0
  161. package/dist/models/identity.js +136 -0
  162. package/dist/models/identity.js.map +1 -0
  163. package/dist/models/messages.d.ts +104 -0
  164. package/dist/models/messages.d.ts.map +1 -0
  165. package/dist/models/messages.js +168 -0
  166. package/dist/models/messages.js.map +1 -0
  167. package/dist/models/profile.d.ts +24 -0
  168. package/dist/models/profile.d.ts.map +1 -0
  169. package/dist/models/profile.js +47 -0
  170. package/dist/models/profile.js.map +1 -0
  171. package/dist/models/relay.d.ts +39 -0
  172. package/dist/models/relay.d.ts.map +1 -0
  173. package/dist/models/relay.js +160 -0
  174. package/dist/models/relay.js.map +1 -0
  175. package/dist/protocol/codec.d.ts +36 -0
  176. package/dist/protocol/codec.d.ts.map +1 -0
  177. package/dist/protocol/codec.js +144 -0
  178. package/dist/protocol/codec.js.map +1 -0
  179. package/dist/protocol/context.d.ts +14 -0
  180. package/dist/protocol/context.d.ts.map +1 -0
  181. package/dist/protocol/context.js +43 -0
  182. package/dist/protocol/context.js.map +1 -0
  183. package/dist/protocol/encoding.d.ts +15 -0
  184. package/dist/protocol/encoding.d.ts.map +1 -0
  185. package/dist/protocol/encoding.js +133 -0
  186. package/dist/protocol/encoding.js.map +1 -0
  187. package/dist/protocol/json.d.ts +16 -0
  188. package/dist/protocol/json.d.ts.map +1 -0
  189. package/dist/protocol/json.js +172 -0
  190. package/dist/protocol/json.js.map +1 -0
  191. package/dist/protocol/validation.d.ts +4 -0
  192. package/dist/protocol/validation.d.ts.map +1 -0
  193. package/dist/protocol/validation.js +18 -0
  194. package/dist/protocol/validation.js.map +1 -0
  195. package/dist/runtime/abort.d.ts +6 -0
  196. package/dist/runtime/abort.d.ts.map +1 -0
  197. package/dist/runtime/abort.js +32 -0
  198. package/dist/runtime/abort.js.map +1 -0
  199. package/dist/runtime/async-gate.d.ts +6 -0
  200. package/dist/runtime/async-gate.d.ts.map +1 -0
  201. package/dist/runtime/async-gate.js +15 -0
  202. package/dist/runtime/async-gate.js.map +1 -0
  203. package/dist/runtime/async-pulse.d.ts +7 -0
  204. package/dist/runtime/async-pulse.d.ts.map +1 -0
  205. package/dist/runtime/async-pulse.js +23 -0
  206. package/dist/runtime/async-pulse.js.map +1 -0
  207. package/dist/runtime/clock.d.ts +16 -0
  208. package/dist/runtime/clock.d.ts.map +1 -0
  209. package/dist/runtime/clock.js +62 -0
  210. package/dist/runtime/clock.js.map +1 -0
  211. package/dist/runtime/events.d.ts +11 -0
  212. package/dist/runtime/events.d.ts.map +1 -0
  213. package/dist/runtime/events.js +45 -0
  214. package/dist/runtime/events.js.map +1 -0
  215. package/dist/runtime/url.d.ts +3 -0
  216. package/dist/runtime/url.d.ts.map +1 -0
  217. package/dist/runtime/url.js +23 -0
  218. package/dist/runtime/url.js.map +1 -0
  219. package/dist/storage/signed-request.d.ts +14 -0
  220. package/dist/storage/signed-request.d.ts.map +1 -0
  221. package/dist/storage/signed-request.js +26 -0
  222. package/dist/storage/signed-request.js.map +1 -0
  223. package/dist/storage/store.d.ts +58 -0
  224. package/dist/storage/store.d.ts.map +1 -0
  225. package/dist/storage/store.js +52 -0
  226. package/dist/storage/store.js.map +1 -0
  227. package/dist/storage/transaction.d.ts +7 -0
  228. package/dist/storage/transaction.d.ts.map +1 -0
  229. package/dist/storage/transaction.js +22 -0
  230. package/dist/storage/transaction.js.map +1 -0
  231. package/dist/transport/client.d.ts +61 -0
  232. package/dist/transport/client.d.ts.map +1 -0
  233. package/dist/transport/client.js +392 -0
  234. package/dist/transport/client.js.map +1 -0
  235. package/dist/transport/discovery.d.ts +19 -0
  236. package/dist/transport/discovery.d.ts.map +1 -0
  237. package/dist/transport/discovery.js +75 -0
  238. package/dist/transport/discovery.js.map +1 -0
  239. package/dist/transport/endpoint.d.ts +6 -0
  240. package/dist/transport/endpoint.d.ts.map +1 -0
  241. package/dist/transport/endpoint.js +35 -0
  242. package/dist/transport/endpoint.js.map +1 -0
  243. package/dist/transport/http.d.ts +52 -0
  244. package/dist/transport/http.d.ts.map +1 -0
  245. package/dist/transport/http.js +128 -0
  246. package/dist/transport/http.js.map +1 -0
  247. package/dist/transport/pool.d.ts +31 -0
  248. package/dist/transport/pool.d.ts.map +1 -0
  249. package/dist/transport/pool.js +137 -0
  250. package/dist/transport/pool.js.map +1 -0
  251. package/dist/transport/relay-error.d.ts +23 -0
  252. package/dist/transport/relay-error.d.ts.map +1 -0
  253. package/dist/transport/relay-error.js +47 -0
  254. package/dist/transport/relay-error.js.map +1 -0
  255. package/dist/transport/rpc.d.ts +31 -0
  256. package/dist/transport/rpc.d.ts.map +1 -0
  257. package/dist/transport/rpc.js +56 -0
  258. package/dist/transport/rpc.js.map +1 -0
  259. package/dist/transport/session.d.ts +49 -0
  260. package/dist/transport/session.d.ts.map +1 -0
  261. package/dist/transport/session.js +169 -0
  262. package/dist/transport/session.js.map +1 -0
  263. package/dist/transport/socket.d.ts +55 -0
  264. package/dist/transport/socket.d.ts.map +1 -0
  265. package/dist/transport/socket.js +266 -0
  266. package/dist/transport/socket.js.map +1 -0
  267. package/dist/transport/subscription.d.ts +36 -0
  268. package/dist/transport/subscription.d.ts.map +1 -0
  269. package/dist/transport/subscription.js +169 -0
  270. package/dist/transport/subscription.js.map +1 -0
  271. package/package.json +35 -4
  272. package/src/channels/repository.ts +244 -0
  273. package/src/client/account-operations.ts +183 -0
  274. package/src/client/conversations.ts +95 -0
  275. package/src/client.ts +108 -0
  276. package/src/components/account.ts +206 -0
  277. package/src/components/channel.ts +253 -0
  278. package/src/components/component.ts +151 -0
  279. package/src/components/device.ts +455 -0
  280. package/src/components/group.ts +546 -0
  281. package/src/components/message.ts +253 -0
  282. package/src/components/profile.ts +179 -0
  283. package/src/crypto/groups.ts +107 -0
  284. package/src/crypto/messages.ts +129 -0
  285. package/src/crypto/primitives.ts +103 -0
  286. package/src/errors.ts +13 -0
  287. package/src/groups/account-sync.ts +144 -0
  288. package/src/groups/messages.ts +89 -0
  289. package/src/groups/operations.ts +145 -0
  290. package/src/groups/repository.ts +161 -0
  291. package/src/groups/secrets.ts +256 -0
  292. package/src/groups/state.ts +138 -0
  293. package/src/identity/identifiers.ts +41 -0
  294. package/src/identity/neo.ts +72 -0
  295. package/src/index.ts +52 -0
  296. package/src/interactions.ts +35 -0
  297. package/src/messages/account-sender.ts +33 -0
  298. package/src/messages/contacts.ts +379 -0
  299. package/src/messages/outbox.ts +152 -0
  300. package/src/messages/receiver.ts +86 -0
  301. package/src/messages/repository.ts +230 -0
  302. package/src/models/authentication.ts +63 -0
  303. package/src/models/channels.ts +155 -0
  304. package/src/models/contacts.ts +141 -0
  305. package/src/models/content.ts +105 -0
  306. package/src/models/device-state.ts +18 -0
  307. package/src/models/group-admission.ts +110 -0
  308. package/src/models/group-keys.ts +34 -0
  309. package/src/models/group-management.ts +182 -0
  310. package/src/models/groups.ts +100 -0
  311. package/src/models/identity.ts +164 -0
  312. package/src/models/messages.ts +139 -0
  313. package/src/models/profile.ts +46 -0
  314. package/src/models/relay.ts +151 -0
  315. package/src/protocol/codec.ts +144 -0
  316. package/src/protocol/context.ts +39 -0
  317. package/src/protocol/encoding.ts +106 -0
  318. package/src/protocol/json.ts +140 -0
  319. package/src/protocol/validation.ts +13 -0
  320. package/src/runtime/abort.ts +27 -0
  321. package/src/runtime/async-gate.ts +16 -0
  322. package/src/runtime/async-pulse.ts +20 -0
  323. package/src/runtime/clock.ts +63 -0
  324. package/src/runtime/events.ts +31 -0
  325. package/src/runtime/url.ts +17 -0
  326. package/src/storage/signed-request.ts +26 -0
  327. package/src/storage/store.ts +90 -0
  328. package/src/storage/transaction.ts +17 -0
  329. package/src/transport/client.ts +328 -0
  330. package/src/transport/discovery.ts +64 -0
  331. package/src/transport/endpoint.ts +32 -0
  332. package/src/transport/http.ts +129 -0
  333. package/src/transport/pool.ts +115 -0
  334. package/src/transport/relay-error.ts +46 -0
  335. package/src/transport/rpc.ts +56 -0
  336. package/src/transport/session.ts +154 -0
  337. package/src/transport/socket.ts +248 -0
  338. package/src/transport/subscription.ts +117 -0
package/dist/client.js ADDED
@@ -0,0 +1,162 @@
1
+ import { createAbortController } from './runtime/abort.js';
2
+ import { AccountManager } from './components/account.js';
3
+ import { ChannelManager } from './components/channel.js';
4
+ import { ClientComponent } from './components/component.js';
5
+ import { DeviceManager } from './components/device.js';
6
+ import { GroupManager } from './components/group.js';
7
+ import { MessageManager } from './components/message.js';
8
+ import { ProfileManager } from './components/profile.js';
9
+ import { ClientAccountOperations } from './client/account-operations.js';
10
+ import { ClientConversations } from './client/conversations.js';
11
+ import { accountDeviceStateCodec } from './models/identity.js';
12
+ import { AsyncGate } from './runtime/async-gate.js';
13
+ import { AsyncPulse } from './runtime/async-pulse.js';
14
+ import { EventHub } from './runtime/events.js';
15
+ /** Owns six managers; the application retains ownership of the migrated store, pool, signer and protector. */
16
+ export class MeshlineClient extends ClientComponent {
17
+ accountManager;
18
+ deviceManager;
19
+ profileManager;
20
+ messageManager;
21
+ channelManager;
22
+ groupManager;
23
+ #components;
24
+ #detach = [];
25
+ #accountGate = new AsyncGate();
26
+ #accountOperations;
27
+ #conversations;
28
+ #events = new EventHub();
29
+ #conversationLifetime = createAbortController();
30
+ #conversationPulse = new AsyncPulse();
31
+ #pendingConversations = new Set();
32
+ #conversationIds = new Set();
33
+ #conversationJob;
34
+ constructor(options) {
35
+ super(options);
36
+ this.accountManager = new AccountManager(options);
37
+ this.deviceManager = new DeviceManager({ ...options, accountManager: this.accountManager });
38
+ this.profileManager = new ProfileManager({ ...options, accountManager: this.accountManager, deviceSigner: this.deviceManager });
39
+ this.messageManager = new MessageManager({ ...options, accountManager: this.accountManager, deviceManager: this.deviceManager });
40
+ this.channelManager = new ChannelManager({ ...options, deviceManager: this.deviceManager });
41
+ this.groupManager = new GroupManager({ ...options, deviceManager: this.deviceManager, messageManager: this.messageManager });
42
+ this.#components = [this.accountManager, this.deviceManager, this.profileManager, this.messageManager, this.channelManager, this.groupManager];
43
+ for (const component of this.#components)
44
+ this.#detach.push(component.onLifecycle('backgroundError', error => this.notifyBackgroundError(error)));
45
+ this.#accountOperations = new ClientAccountOperations({ store: options.store, pool: options.relayClients, account: this.accountManager, device: this.deviceManager, profile: this.profileManager,
46
+ context: this.context, accountId: this.accountId, clock: this.clock, report: failure => this.notifyBackgroundError(failure) });
47
+ this.#conversations = new ClientConversations(options.store, this.accountId);
48
+ this.#detach.push(this.messageManager.on('messageReceived', messages => { for (const message of messages)
49
+ this.#queueConversation(message.key.sender === this.accountId ? message.recipient : message.key.sender); }), this.messageManager.on('sendStatusChanged', status => { if (status.state === 'queued')
50
+ this.#queueConversation(status.recipient); }), this.channelManager.on('timelineChanged', value => this.#queueConversation(value.channel.channelId)), this.channelManager.on('followChanged', value => this.#queueConversation(value.channel.channelId)), this.groupManager.on('timelineChanged', value => { if (value.message)
51
+ this.#queueConversation(value.group.groupId); }), this.groupManager.on('groupChanged', value => this.#queueConversation(value.ref.groupId)));
52
+ }
53
+ get route() { return this.accountManager.route; }
54
+ get device() { return this.deviceManager.local; }
55
+ get deviceState() { return this.deviceManager.deviceState; }
56
+ get profile() { return this.profileManager.profile; }
57
+ on(event, listener) { return this.#events.on(event, listener); }
58
+ getConversations(query = {}, signal) { const copy = { ...query, ...(query.kinds ? { kinds: [...query.kinds] } : {}) }; return this.runOperation(scope => this.#conversations.list(copy, scope), signal); }
59
+ getConversation(conversationId, signal) { return this.runOperation(scope => this.#conversations.get(conversationId, scope), signal); }
60
+ async markRead(conversationId, signal) { if (await this.runOperation(scope => this.#conversations.markRead(conversationId, scope), signal))
61
+ this.#queueConversation(conversationId); }
62
+ #queueConversation(id) { if (this.#conversationLifetime.signal.aborted)
63
+ return; this.#pendingConversations.add(id); this.#conversationPulse.pulse(); }
64
+ async #observeConversations() {
65
+ const signal = this.#conversationLifetime.signal;
66
+ try {
67
+ for (;;) {
68
+ await this.#conversationPulse.wait(signal);
69
+ const pending = [...this.#pendingConversations];
70
+ this.#pendingConversations.clear();
71
+ if (!pending.length)
72
+ continue;
73
+ let present;
74
+ try {
75
+ present = await this.#conversations.ids(signal);
76
+ }
77
+ catch (error) {
78
+ if (signal.aborted)
79
+ throw error;
80
+ this.notifyBackgroundError({ operation: 'synchronize_conversations', error });
81
+ for (const id of pending)
82
+ this.#queueConversation(id);
83
+ await this.clock.delay(1000, signal);
84
+ continue;
85
+ }
86
+ for (const id of pending) {
87
+ if (signal.aborted)
88
+ return;
89
+ const kind = present.has(id) ? this.#conversationIds.has(id) ? 'updated' : 'created' : this.#conversationIds.has(id) ? 'removed' : undefined;
90
+ if (kind)
91
+ this.#events.notify('conversationChanged', { conversationId: id, kind }, error => this.notifyBackgroundError({ operation: 'observer', resource: 'conversationChanged', error }));
92
+ }
93
+ // Preserve membership for other queued IDs until their own notification is processed.
94
+ const next = new Set(this.#conversationIds);
95
+ for (const id of pending) {
96
+ if (present.has(id))
97
+ next.add(id);
98
+ else
99
+ next.delete(id);
100
+ }
101
+ this.#conversationIds = next;
102
+ }
103
+ }
104
+ catch (error) {
105
+ if (!signal.aborted)
106
+ this.notifyBackgroundError({ operation: 'observe_conversations', error });
107
+ }
108
+ }
109
+ establishAccount(options = {}, signal) {
110
+ const copy = { ...options };
111
+ return this.runOperation(scope => this.#accountGate.run(() => this.#accountOperations.establish(copy, scope), scope), signal);
112
+ }
113
+ recoverAccount(options = {}, signal) {
114
+ const copy = { ...options, ...(options.previousDeviceState ? { previousDeviceState: accountDeviceStateCodec.decode(accountDeviceStateCodec.encode(options.previousDeviceState)) } : {}) };
115
+ return this.runOperation(scope => this.#accountGate.run(() => this.#accountOperations.recover(copy, scope), scope), signal);
116
+ }
117
+ changeHomeRelay(relayId, signal) { return this.runOperation(scope => this.#accountGate.run(() => this.#accountOperations.migrate(relayId, scope), scope), signal); }
118
+ async onInitialize(signal) {
119
+ for (const component of this.#components)
120
+ await component.initialize(signal);
121
+ this.#conversationIds = await this.#conversations.ids(signal);
122
+ this.#conversationJob ??= this.#observeConversations();
123
+ }
124
+ async onStart(signal) {
125
+ await this.accountManager.start(signal);
126
+ await this.#accountGate.run(() => this.#accountOperations.resumeMigration(signal), signal);
127
+ for (const component of this.#components.slice(1))
128
+ await component.start(signal);
129
+ }
130
+ async onStop() {
131
+ const errors = [];
132
+ for (const component of [...this.#components].reverse()) {
133
+ try {
134
+ await component.stop();
135
+ }
136
+ catch (error) {
137
+ errors.push(error);
138
+ }
139
+ }
140
+ if (errors.length)
141
+ throw new AggregateError(errors, 'One or more client components failed to stop.');
142
+ }
143
+ async onDispose() {
144
+ this.#conversationLifetime.abort();
145
+ await this.#conversationJob;
146
+ const errors = [];
147
+ for (const component of [...this.#components].reverse()) {
148
+ try {
149
+ await component.dispose();
150
+ }
151
+ catch (error) {
152
+ errors.push(error);
153
+ }
154
+ }
155
+ for (const detach of this.#detach)
156
+ detach();
157
+ this.#events.clear();
158
+ if (errors.length)
159
+ throw new AggregateError(errors, 'One or more client components failed to dispose.');
160
+ }
161
+ }
162
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAsB,MAAM,2BAA2B,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAiE,MAAM,gCAAgC,CAAC;AACxI,OAAO,EAAE,mBAAmB,EAAmD,MAAM,2BAA2B,CAAC;AAGjH,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAsB,MAAM,qBAAqB,CAAC;AAYnE,8GAA8G;AAC9G,MAAM,OAAO,cAAe,SAAQ,eAAe;IACtC,cAAc,CAAiB;IAAU,aAAa,CAAgB;IAAU,cAAc,CAAiB;IAC/G,cAAc,CAAiB;IAAU,cAAc,CAAiB;IAAU,YAAY,CAAe;IAC7G,WAAW,CAA6B;IAAU,OAAO,GAAmB,EAAE,CAAC;IAC/E,YAAY,GAAG,IAAI,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C;IAC5G,CAAC;CACJ"}
@@ -0,0 +1,38 @@
1
+ import type { AccountSigner } from '../interactions.js';
2
+ import { type AccountRoute } from '../models/identity.js';
3
+ import { type EventListener } from '../runtime/events.js';
4
+ import type { MeshlineStore } from '../storage/store.js';
5
+ import type { RelayClientPool } from '../transport/pool.js';
6
+ import { ClientComponent, type ClientOptions } from './component.js';
7
+ export type AccountState = 'unknown' | 'notEstablished' | 'established';
8
+ export interface AccountSnapshot {
9
+ readonly state: AccountState;
10
+ readonly route: AccountRoute | undefined;
11
+ }
12
+ export interface AccountEvents {
13
+ readonly accountChanged: AccountSnapshot;
14
+ }
15
+ export interface AccountManagerOptions extends ClientOptions {
16
+ readonly store: MeshlineStore;
17
+ readonly relayClients: RelayClientPool;
18
+ readonly accountSigner?: AccountSigner;
19
+ }
20
+ export interface PublishRouteOptions {
21
+ readonly validitySeconds: number;
22
+ readonly revision?: number;
23
+ readonly recovery?: boolean;
24
+ readonly signal?: AbortSignal;
25
+ }
26
+ /** Signed route discovery and durable, explicit publication retries. */
27
+ export declare class AccountManager extends ClientComponent {
28
+ #private;
29
+ constructor(options: AccountManagerOptions);
30
+ get state(): AccountState;
31
+ get route(): AccountRoute | undefined;
32
+ on<K extends keyof AccountEvents>(event: K, listener: EventListener<AccountEvents[K]>): () => void;
33
+ protected onInitialize(signal: AbortSignal): Promise<void>;
34
+ getRoute(accountId?: string, signal?: AbortSignal): Promise<AccountRoute | undefined>;
35
+ publishRoute(relayId: string, options: PublishRouteOptions): Promise<AccountRoute>;
36
+ protected onDispose(): Promise<void>;
37
+ }
38
+ //# sourceMappingURL=account.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/components/account.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAuF,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAK/I,OAAO,EAAY,KAAK,aA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/I,UAAyB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CASxE;IASK,QAAQ,CAAC,SAAS,SAAiB,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAiBlG;IAgCK,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,YAAY,CAAC,CA8BvF;IA8DD,UAAyB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAA0B;CAChF"}
@@ -0,0 +1,243 @@
1
+ import { ProtocolError, StateConflictError } from '../errors.js';
2
+ import { matchesAccount, validateAccountId, validateRelayId, verifyRelay } from '../identity/neo.js';
3
+ import { accountRouteCodec, compareRoutes, routeAccountInput, routeRelayInput, validateRoute } from '../models/identity.js';
4
+ import { nextRevision } from '../protocol/context.js';
5
+ import { canonicalJson, requireSafeInteger } from '../protocol/json.js';
6
+ import { AsyncGate } from '../runtime/async-gate.js';
7
+ import { throwIfAborted } from '../runtime/clock.js';
8
+ import { EventHub } from '../runtime/events.js';
9
+ import { finishSignedRequest, putSignedRequest, readSignedRequest, requestKey } from '../storage/signed-request.js';
10
+ import { updateStore } from '../storage/transaction.js';
11
+ import { RelayError } from '../transport/relay-error.js';
12
+ import { ClientComponent } from './component.js';
13
+ const method = 'account.route.publish';
14
+ const routeKey = (account) => ({ collection: 'account_routes', key: account });
15
+ const clone = (route) => accountRouteCodec.decode(accountRouteCodec.encode(route));
16
+ const fingerprint = (value) => canonicalJson(value ?? null);
17
+ /** Signed route discovery and durable, explicit publication retries. */
18
+ export class AccountManager extends ClientComponent {
19
+ #store;
20
+ #pool;
21
+ #signer;
22
+ #gate = new AsyncGate();
23
+ #events = new EventHub();
24
+ #state = 'unknown';
25
+ #route;
26
+ constructor(options) {
27
+ super(options);
28
+ if (options.relayClients.accountId !== this.accountId || options.relayClients.context.toString() !== this.context.toString())
29
+ throw new ProtocolError('invalid_context', 'Relay pool belongs to another account or network.');
30
+ this.#store = options.store;
31
+ this.#pool = options.relayClients;
32
+ this.#signer = options.accountSigner;
33
+ }
34
+ get state() { return this.#state; }
35
+ get route() { return this.#route && clone(this.#route); }
36
+ on(event, listener) { return this.#events.on(event, listener); }
37
+ async onInitialize(signal) {
38
+ await this.#store.initialize({ context: this.context.toString(), accountId: this.accountId }, signal);
39
+ const value = (await this.#store.read([routeKey(this.accountId)], signal)).sets[0][0]?.value;
40
+ const route = value === undefined ? undefined : accountRouteCodec.decode(value);
41
+ if (route) {
42
+ validateRoute(route, this.context, 0);
43
+ if (route.account !== this.accountId)
44
+ throw new ProtocolError('invalid_storage', 'Stored route belongs to another account.');
45
+ }
46
+ this.#route = route;
47
+ this.#state = route && route.expiresAt > this.clock.nowSeconds() ? 'established' : 'unknown';
48
+ }
49
+ #accept(route) {
50
+ const state = route ? 'established' : 'unknown';
51
+ const changed = this.#state !== state || route !== undefined && accountRouteCodec.stringify(route) !== (this.#route && accountRouteCodec.stringify(this.#route));
52
+ this.#state = state;
53
+ if (route)
54
+ this.#route = clone(route);
55
+ return changed;
56
+ }
57
+ #changed() { this.#events.notify('accountChanged', { state: this.state, route: this.route }, error => this.notifyBackgroundError({ operation: 'observer', resource: 'accountChanged', error })); }
58
+ async getRoute(accountId = this.accountId, signal) {
59
+ validateAccountId(accountId);
60
+ const failures = [];
61
+ let changed = false;
62
+ let route;
63
+ let operationError;
64
+ let failed = false;
65
+ try {
66
+ route = await this.runOperation(scope => this.#gate.run(async () => {
67
+ const resolved = await this.#resolve(accountId, failures, scope);
68
+ if (accountId === this.accountId)
69
+ changed = this.#accept(resolved);
70
+ return resolved;
71
+ }, scope), signal);
72
+ }
73
+ catch (error) {
74
+ failed = true;
75
+ operationError = error;
76
+ }
77
+ for (const failure of failures)
78
+ this.notifyBackgroundError(failure);
79
+ if (changed)
80
+ this.#changed();
81
+ if (failed)
82
+ throw operationError;
83
+ return route && clone(route);
84
+ }
85
+ async #resolve(accountId, failures, signal) {
86
+ const previous = (await this.#store.read([routeKey(accountId)], signal)).sets[0][0]?.value;
87
+ const known = previous === undefined ? undefined : accountRouteCodec.decode(previous);
88
+ let attempted = false;
89
+ for await (const entry of this.#pool.registry.getRelays(signal)) {
90
+ throwIfAborted(signal);
91
+ if (entry.status !== 'active')
92
+ continue;
93
+ attempted = true;
94
+ let route;
95
+ try {
96
+ const client = await this.#pool.get(entry.relayId, undefined, signal);
97
+ const response = await client.requestHttp('GET', 'account.route.resolve', { account: accountId }, { authenticated: false, signal });
98
+ if (response === undefined)
99
+ throw new ProtocolError('invalid_response', 'Route resolution returned no document.');
100
+ route = accountRouteCodec.decode(response);
101
+ if (route.account !== accountId)
102
+ throw new ProtocolError('invalid_identity', 'Resolved route belongs to another account.');
103
+ if (known && route.revision < known.revision)
104
+ throw new ProtocolError('stale_route', 'Relay returned an older route.');
105
+ await this.#verifyRelay(route, signal);
106
+ }
107
+ catch (error) {
108
+ throwIfAborted(signal);
109
+ if (error instanceof RelayError) {
110
+ if (error.code === 'not_found')
111
+ continue;
112
+ if (!['temporarily_unavailable', 'bad_gateway', 'rate_limited'].includes(error.code))
113
+ throw error;
114
+ }
115
+ else if (!(error instanceof Error))
116
+ throw error;
117
+ failures.push({ operation: 'connect', resource: entry.relayId, error });
118
+ continue;
119
+ }
120
+ await this.#save(route, signal);
121
+ return route;
122
+ }
123
+ if (failures.length)
124
+ throw new AggregateError(failures.map(value => value.error), 'Account route discovery failed through the available relays.');
125
+ if (!attempted)
126
+ throw new ProtocolError('no_active_relay', 'No active relay is available for route discovery.');
127
+ return undefined;
128
+ }
129
+ async publishRoute(relayId, options) {
130
+ options = { ...options };
131
+ validateRelayId(relayId);
132
+ requireSafeInteger(options.validitySeconds, 1);
133
+ if (options.validitySeconds > 3650 * 86400)
134
+ throw new RangeError('Route validity cannot exceed 3650 days.');
135
+ if (options.revision !== undefined)
136
+ requireSafeInteger(options.revision, 0);
137
+ const signer = this.#signer;
138
+ if (!signer)
139
+ throw new ProtocolError('signer_required', 'An account signer is required to publish a route.');
140
+ let changed = false;
141
+ const result = await this.runOperation(signal => this.#gate.run(async () => {
142
+ const signed = await this.#prepare(relayId, options, signer, signal);
143
+ const request = accountRouteCodec.decode(signed.document);
144
+ const client = await this.#pool.get(relayId, { mode: 'account', signer }, signal);
145
+ let response;
146
+ try {
147
+ response = await client.requestHttp('PUT', method, signed.document, { signal });
148
+ }
149
+ catch (error) {
150
+ if (error instanceof RelayError && error.isDefinitiveRejection) {
151
+ try {
152
+ await finishSignedRequest(this.#store, method, signed);
153
+ }
154
+ catch (storageError) {
155
+ throw new AggregateError([error, storageError], 'Relay rejected publication but its durable result could not be saved.');
156
+ }
157
+ }
158
+ throw error;
159
+ }
160
+ if (response === undefined)
161
+ throw new ProtocolError('invalid_response', 'Route publication returned no acknowledgement.');
162
+ const route = accountRouteCodec.decode(response);
163
+ const acknowledged = accountRouteCodec.encode(route);
164
+ delete acknowledged.relay_signature;
165
+ if (canonicalJson(acknowledged) !== accountRouteCodec.stringify(request))
166
+ throw new ProtocolError('invalid_response', 'Relay modified the submitted route.');
167
+ await this.#verifyRelay(route, signal);
168
+ await this.#save(route, signal);
169
+ changed = this.#accept(route);
170
+ return route;
171
+ }, signal), options.signal);
172
+ if (changed)
173
+ this.#changed();
174
+ return clone(result);
175
+ }
176
+ async #prepare(relayId, options, signer, signal) {
177
+ const queries = [routeKey(this.accountId), requestKey(method)];
178
+ const snapshot = await this.#store.read(queries, signal);
179
+ const previous = snapshot.sets[0][0]?.value;
180
+ const saved = snapshot.sets[1][0]?.value;
181
+ const known = previous === undefined ? undefined : accountRouteCodec.decode(previous);
182
+ const signed = readSignedRequest(saved);
183
+ const knownRevision = Math.max(known?.revision ?? -1, signed?.revision ?? -1);
184
+ const pending = signed?.pending ? accountRouteCodec.decode(signed.document) : undefined;
185
+ const now = this.clock.nowSeconds();
186
+ requireSafeInteger(now, 0);
187
+ let revision = options.revision;
188
+ if (options.recovery && revision === undefined && (!pending || signed.relayId !== relayId || pending.expiresAt <= now))
189
+ revision = Math.max(nextRevision(knownRevision), now * 1000);
190
+ else if (revision === undefined && pending && signed.relayId === relayId && pending.expiresAt <= now)
191
+ revision = nextRevision(knownRevision);
192
+ if (signed?.pending && (revision === undefined || revision === signed.revision)) {
193
+ const route = pending;
194
+ validateRoute(route, this.context, now);
195
+ if (route.account !== this.accountId || signed.relayId !== relayId || route.relayId !== relayId || route.revision !== signed.revision
196
+ || route.expiresAt - route.updatedAt !== options.validitySeconds)
197
+ throw new StateConflictError('A route publication has an unknown result. Retry the original publication or resolve it first.');
198
+ return signed;
199
+ }
200
+ const publicKey = signer.publicKey.slice();
201
+ if (signer.accountId !== this.accountId || !matchesAccount(this.accountId, publicKey))
202
+ throw new ProtocolError('invalid_identity', 'Account signer identity changed.');
203
+ let request = { account: this.accountId, accountPublicKey: publicKey, relayId, revision: nextRevision(knownRevision, revision),
204
+ updatedAt: now, expiresAt: now + options.validitySeconds, accountSignature: new Uint8Array(64) };
205
+ requireSafeInteger(request.expiresAt, 0);
206
+ request = { ...request, accountSignature: (await signer.sign(routeAccountInput(request, this.context), signal)).slice() };
207
+ validateRoute(request, this.context, this.clock.nowSeconds());
208
+ const prepared = { relayId, revision: request.revision, document: accountRouteCodec.encode(request), pending: true };
209
+ await updateStore(this.#store, queries, current => {
210
+ if (fingerprint(current.sets[0][0]?.value) !== fingerprint(previous) || fingerprint(current.sets[1][0]?.value) !== fingerprint(saved))
211
+ throw new StateConflictError('The route changed while it was being signed. Resolve current state before retrying.');
212
+ return { mutations: [putSignedRequest(method, prepared)], result: undefined };
213
+ }, signal);
214
+ return prepared;
215
+ }
216
+ async #verifyRelay(route, signal) {
217
+ validateRoute(route, this.context, this.clock.nowSeconds());
218
+ const client = await this.#pool.get(route.relayId, undefined, signal);
219
+ const descriptor = await client.getDescriptor(signal);
220
+ if (!route.relaySignature || !verifyRelay(route.relayId, descriptor.publicKey, routeRelayInput(route, this.context), route.relaySignature))
221
+ throw new ProtocolError('invalid_signature', 'Account route lacks a valid signature from its home relay.');
222
+ }
223
+ async #save(route, signal) {
224
+ await updateStore(this.#store, [routeKey(route.account), requestKey(method)], snapshot => {
225
+ const current = snapshot.sets[0][0]?.value;
226
+ if (current) {
227
+ const comparison = compareRoutes(route, accountRouteCodec.decode(current));
228
+ if (comparison === 'older' || comparison === 'conflict')
229
+ throw new ProtocolError('stale_route', 'Returned route is older or conflicts at the same revision.');
230
+ }
231
+ const mutations = [{ kind: 'put', ...routeKey(route.account), value: accountRouteCodec.encode(route) }];
232
+ const signed = readSignedRequest(snapshot.sets[1][0]?.value);
233
+ if (signed?.pending) {
234
+ const request = accountRouteCodec.decode(signed.document);
235
+ if (request.account === route.account && ['equivalent', 'newer'].includes(compareRoutes(route, request)))
236
+ mutations.push(putSignedRequest(method, { ...signed, pending: false }));
237
+ }
238
+ return { mutations, result: undefined };
239
+ }, signal);
240
+ }
241
+ async onDispose() { this.#events.clear(); }
242
+ }
243
+ //# sourceMappingURL=account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/components/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAErG,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAE,aAAa,EAAqB,MAAM,uBAAuB,CAAC;AAC/I,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAmB,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAsB,MAAM,sBAAsB,CAAC;AAE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AO,KAAK,KAAK,CAAC,OAAO,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;oBACpG,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;YAChF,CAAC;YACD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QAC5C,CAAC,EAAE,MAAM,CAAC,CAAC;IACf,CAAC;IACkB,KAAK,CAAC,SAAS,KAAoB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAChF"}
@@ -0,0 +1,78 @@
1
+ import { type RandomSource } from '../crypto/primitives.js';
2
+ import { type ChannelPostRef, type ChannelRef } from '../models/channels.js';
3
+ import type { ContentReference, MessageBody } from '../models/content.js';
4
+ import { type ChannelInfo, type ChannelPostChange, type ChannelPostInfo } from '../channels/repository.js';
5
+ import { type EventListener } from '../runtime/events.js';
6
+ import type { MeshlineStore, QueryReader } from '../storage/store.js';
7
+ import type { RelayClientPool } from '../transport/pool.js';
8
+ import type { DeviceManager } from './device.js';
9
+ import { ClientComponent, type ClientOptions } from './component.js';
10
+ export interface ChannelManagerOptions extends ClientOptions {
11
+ readonly store: MeshlineStore;
12
+ readonly relayClients: RelayClientPool;
13
+ readonly deviceManager: DeviceManager;
14
+ readonly random?: RandomSource;
15
+ }
16
+ export interface ChannelUpdate {
17
+ readonly name?: string;
18
+ readonly description?: string | null;
19
+ readonly moderators?: readonly string[] | null;
20
+ }
21
+ export interface ChannelPostDraft {
22
+ readonly body?: MessageBody;
23
+ readonly attachments?: readonly ContentReference[];
24
+ }
25
+ export interface ChannelPostUpdate {
26
+ readonly body?: MessageBody | null;
27
+ readonly attachments?: readonly ContentReference[] | null;
28
+ }
29
+ export interface ChannelHistoryRequest {
30
+ readonly cursor?: string;
31
+ readonly limit?: number;
32
+ }
33
+ export interface ChannelHistoryPage {
34
+ readonly items: readonly ChannelPostInfo[];
35
+ readonly nextCursor?: string;
36
+ }
37
+ export interface ChannelEvents {
38
+ readonly channelChanged: ChannelInfo;
39
+ readonly timelineChanged: {
40
+ readonly channel: ChannelRef;
41
+ readonly changes: readonly ChannelPostChange[];
42
+ };
43
+ readonly followChanged: {
44
+ readonly channel: ChannelRef;
45
+ readonly isFollowed: boolean;
46
+ };
47
+ }
48
+ /** Public channels with verified historical permissions, durable exact requests and explicit runtime ownership. */
49
+ export declare class ChannelManager extends ClientComponent {
50
+ #private;
51
+ constructor(options: ChannelManagerOptions);
52
+ on<K extends keyof ChannelEvents>(event: K, listener: EventListener<ChannelEvents[K]>): () => void;
53
+ protected onInitialize(signal: AbortSignal): Promise<void>;
54
+ createChannel(relayId: string, name: string, options?: {
55
+ readonly description?: string;
56
+ readonly moderators?: readonly string[];
57
+ readonly signal?: AbortSignal;
58
+ }): Promise<ChannelInfo>;
59
+ getChannel(channel: ChannelRef, signal?: AbortSignal): Promise<ChannelInfo>;
60
+ updateChannel(channel: ChannelRef, update: ChannelUpdate, signal?: AbortSignal): Promise<ChannelInfo>;
61
+ closeChannel(channel: ChannelRef, signal?: AbortSignal): Promise<void>;
62
+ publishPost(channel: ChannelRef, draft: ChannelPostDraft, signal?: AbortSignal): Promise<ChannelPostInfo>;
63
+ editPost(post: ChannelPostRef, update: ChannelPostUpdate, signal?: AbortSignal): Promise<ChannelPostInfo>;
64
+ deletePost(post: ChannelPostRef, signal?: AbortSignal): Promise<void>;
65
+ reportPost(post: ChannelPostRef, reason: string, signal?: AbortSignal): Promise<void>;
66
+ loadChannelHistory(channel: ChannelRef, page?: ChannelHistoryRequest, signal?: AbortSignal): Promise<ChannelHistoryPage>;
67
+ getPosts(query?: {
68
+ readonly channelId?: string;
69
+ readonly author?: string;
70
+ }, signal?: AbortSignal): Promise<QueryReader<ChannelPostInfo>>;
71
+ follow(channel: ChannelRef, signal?: AbortSignal): Promise<void>;
72
+ unfollow(channel: ChannelRef, signal?: AbortSignal): Promise<void>;
73
+ getFollowed(relayId?: string, signal?: AbortSignal): Promise<QueryReader<ChannelInfo>>;
74
+ protected onStart(): Promise<void>;
75
+ protected onStop(): Promise<void>;
76
+ protected onDispose(): Promise<void>;
77
+ }
78
+ //# sourceMappingURL=channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../src/components/channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAIxF,OAAO,EAI4D,KAAK,cAAc,EAAyB,KAAK,UAAU,EAC7H,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAE1E,OAAO,EAA0C,KAAK,WAAW,EAAyB,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAsB,MAAM,2BAA2B,CAAC;AAO9L,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAErE,MAAM,WAAW,qBAAsB,SAAQ,aAAa;IAAG,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,CAAA;CAAE;AAC7M,MAAM,WAAW,aAAa;IAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CA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