@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abort.d.ts","sourceRoot":"","sources":["../../src/runtime/abort.ts"],"names":[],"mappings":"AAGA,oFAAoF;AACpF,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAKxD;AAED;uFACuF;AACvF,wBAAgB,qBAAqB,IAAI,eAAe,CAavD"}
@@ -0,0 +1,32 @@
1
+ const fallbackReasons = new WeakMap();
2
+ const aborted = () => new DOMException('The operation was aborted.', 'AbortError');
3
+ /** Legacy caller signals cannot expose a reason their runtime already discarded. */
4
+ export function abortReason(signal) {
5
+ if (signal.reason !== undefined)
6
+ return signal.reason;
7
+ let reason = fallbackReasons.get(signal);
8
+ if (!reason) {
9
+ reason = aborted();
10
+ fallbackReasons.set(signal, reason);
11
+ }
12
+ return reason;
13
+ }
14
+ /** Keep the platform's real signal and synchronous abort event, adding reason
15
+ * only to SDK-owned legacy signals. Globals and caller-owned signals are untouched. */
16
+ export function createAbortController() {
17
+ const controller = new AbortController();
18
+ if ('reason' in controller.signal)
19
+ return controller;
20
+ let reason;
21
+ Object.defineProperty(controller.signal, 'reason', { get: () => reason });
22
+ return {
23
+ signal: controller.signal,
24
+ abort(value) {
25
+ if (controller.signal.aborted)
26
+ return;
27
+ reason = value === undefined ? aborted() : value;
28
+ controller.abort();
29
+ },
30
+ };
31
+ }
32
+ //# sourceMappingURL=abort.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abort.js","sourceRoot":"","sources":["../../src/runtime/abort.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe,GAAG,IAAI,OAAO,EAA6B,CAAC;AACjE,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,YAAY,CAAC,4BAA4B,EAAE,YAAY,CAAC,CAAC;AAEnF,oFAAoF;AACpF,MAAM,UAAU,WAAW,CAAC,MAAmB;IAC3C,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC;IACtD,IAAI,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACzC,IAAI,CAAC,MAAM,EAAE,CAAC;QAAC,MAAM,GAAG,OAAO,EAAE,CAAC;QAAC,eAAe,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,CAAC;IACzE,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;uFACuF;AACvF,MAAM,UAAU,qBAAqB;IACjC,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,IAAI,QAAQ,IAAI,UAAU,CAAC,MAAM;QAAE,OAAO,UAAU,CAAC;IACrD,IAAI,MAAe,CAAC;IACpB,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1E,OAAO;QACH,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,KAAK,CAAC,KAAe;YACjB,IAAI,UAAU,CAAC,MAAM,CAAC,OAAO;gBAAE,OAAO;YACtC,MAAM,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;YACjD,UAAU,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;KACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** Serializes state changes without poisoning subsequent operations after a failure. */
2
+ export declare class AsyncGate {
3
+ private tail;
4
+ run<T>(operation: () => T | Promise<T>, signal?: AbortSignal): Promise<T>;
5
+ }
6
+ //# sourceMappingURL=async-gate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-gate.d.ts","sourceRoot":"","sources":["../../src/runtime/async-gate.ts"],"names":[],"mappings":"AAEA,wFAAwF;AACxF,qBAAa,SAAS;IAClB,OAAO,CAAC,IAAI,CAAoC;IAEhD,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAQxE;CACJ"}
@@ -0,0 +1,15 @@
1
+ import { throwIfAborted } from './clock.js';
2
+ /** Serializes state changes without poisoning subsequent operations after a failure. */
3
+ export class AsyncGate {
4
+ tail = Promise.resolve();
5
+ run(operation, signal) {
6
+ const result = this.tail.then(() => {
7
+ throwIfAborted(signal);
8
+ return operation();
9
+ });
10
+ // Callers receive the original rejection; only the queue tail is recovered.
11
+ this.tail = result.then(() => undefined, () => undefined);
12
+ return result;
13
+ }
14
+ }
15
+ //# sourceMappingURL=async-gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-gate.js","sourceRoot":"","sources":["../../src/runtime/async-gate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,wFAAwF;AACxF,MAAM,OAAO,SAAS;IACV,IAAI,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAEhD,GAAG,CAAI,SAA+B,EAAE,MAAoB;QACxD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;YAC/B,cAAc,CAAC,MAAM,CAAC,CAAC;YACvB,OAAO,SAAS,EAAE,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,4EAA4E;QAC5E,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC1D,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
@@ -0,0 +1,7 @@
1
+ /** One consumer, coalesced wakeups. Pulses received during processing remain pending. */
2
+ export declare class AsyncPulse {
3
+ #private;
4
+ pulse(): void;
5
+ wait(signal: AbortSignal): Promise<void>;
6
+ }
7
+ //# sourceMappingURL=async-pulse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-pulse.d.ts","sourceRoot":"","sources":["../../src/runtime/async-pulse.ts"],"names":[],"mappings":"AAGA,yFAAyF;AACzF,qBAAa,UAAU;;IAGnB,KAAK,IAAI,IAAI,CAA0C;IACjD,IAAI,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAU7C;CACJ"}
@@ -0,0 +1,23 @@
1
+ import { throwIfAborted } from './clock.js';
2
+ import { abortReason } from './abort.js';
3
+ /** One consumer, coalesced wakeups. Pulses received during processing remain pending. */
4
+ export class AsyncPulse {
5
+ #pending = false;
6
+ #wake;
7
+ pulse() { this.#pending = true; this.#wake?.(); }
8
+ async wait(signal) {
9
+ throwIfAborted(signal);
10
+ if (this.#wake)
11
+ throw new Error('AsyncPulse supports only one consumer.');
12
+ if (!this.#pending)
13
+ await new Promise((resolve, reject) => {
14
+ const cleanup = () => { this.#wake = undefined; signal.removeEventListener('abort', aborted); };
15
+ const aborted = () => { cleanup(); reject(abortReason(signal)); };
16
+ this.#wake = () => { cleanup(); resolve(); };
17
+ signal.addEventListener('abort', aborted, { once: true });
18
+ });
19
+ throwIfAborted(signal);
20
+ this.#pending = false;
21
+ }
22
+ }
23
+ //# sourceMappingURL=async-pulse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-pulse.js","sourceRoot":"","sources":["../../src/runtime/async-pulse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,yFAAyF;AACzF,MAAM,OAAO,UAAU;IACnB,QAAQ,GAAG,KAAK,CAAC;IACjB,KAAK,CAA2B;IAChC,KAAK,KAAW,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;IACvD,KAAK,CAAC,IAAI,CAAC,MAAmB;QAC1B,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,IAAI,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAC1E,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBAC5D,MAAM,OAAO,GAAG,GAAS,EAAE,GAAG,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;gBACtG,MAAM,OAAO,GAAG,GAAS,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACxE,IAAI,CAAC,KAAK,GAAG,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;gBAC7C,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAC9D,CAAC,CAAC,CAAC;QACH,cAAc,CAAC,MAAM,CAAC,CAAC;QAAC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;IAClD,CAAC;CACJ"}
@@ -0,0 +1,16 @@
1
+ /** Wall time signs timestamps; monotonic time measures session and backoff lifetimes. */
2
+ export interface RuntimeClock {
3
+ nowSeconds(): number;
4
+ monotonicMilliseconds(): number;
5
+ delay(milliseconds: number, signal?: AbortSignal): Promise<void>;
6
+ }
7
+ export declare function throwIfAborted(signal?: AbortSignal): void;
8
+ export declare const systemClock: RuntimeClock;
9
+ /** A caller can abandon a shared operation without canceling other callers' work. */
10
+ export declare function awaitWithSignal<T>(promise: Promise<T>, signal?: AbortSignal): Promise<T>;
11
+ /** Explicit cleanup avoids accumulating listeners or request deadline timers. */
12
+ export declare function abortScope(signals: readonly (AbortSignal | undefined)[], timeoutMilliseconds?: number): {
13
+ signal: AbortSignal;
14
+ dispose(): void;
15
+ };
16
+ //# sourceMappingURL=clock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clock.d.ts","sourceRoot":"","sources":["../../src/runtime/clock.ts"],"names":[],"mappings":"AAEA,yFAAyF;AACzF,MAAM,WAAW,YAAY;IACzB,UAAU,IAAI,MAAM,CAAC;IACrB,qBAAqB,IAAI,MAAM,CAAC;IAChC,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpE;AAED,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,CAEzD;AAED,eAAO,MAAM,WAAW,EAAE,YAiBzB,CAAC;AAEF,qFAAqF;AACrF,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAUxF;AAED,iFAAiF;AACjF,wBAAgB,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC,WAAW,GAAG,SAAS,CAAC,EAAE,EAAE,mBAAmB,CAAC,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,OAAO,IAAI,IAAI,CAAA;CAAE,CAgBhJ"}
@@ -0,0 +1,62 @@
1
+ import { abortReason, createAbortController } from './abort.js';
2
+ export function throwIfAborted(signal) {
3
+ if (signal?.aborted)
4
+ throw abortReason(signal);
5
+ }
6
+ export const systemClock = {
7
+ nowSeconds: () => Math.floor(Date.now() / 1000),
8
+ monotonicMilliseconds: () => performance.now(),
9
+ delay(milliseconds, signal) {
10
+ throwIfAborted(signal);
11
+ if (!Number.isFinite(milliseconds) || milliseconds < 0 || milliseconds > 60_000)
12
+ throw new RangeError('An individual delay must be between zero and 60000 milliseconds.');
13
+ return new Promise((resolve, reject) => {
14
+ const onAbort = () => {
15
+ clearTimeout(timer);
16
+ signal?.removeEventListener('abort', onAbort);
17
+ reject(abortReason(signal));
18
+ };
19
+ const timer = setTimeout(() => { signal?.removeEventListener('abort', onAbort); resolve(); }, milliseconds);
20
+ signal?.addEventListener('abort', onAbort, { once: true });
21
+ });
22
+ },
23
+ };
24
+ /** A caller can abandon a shared operation without canceling other callers' work. */
25
+ export function awaitWithSignal(promise, signal) {
26
+ throwIfAborted(signal);
27
+ if (!signal)
28
+ return promise;
29
+ return new Promise((resolve, reject) => {
30
+ const onAbort = () => { signal.removeEventListener('abort', onAbort); reject(abortReason(signal)); };
31
+ signal.addEventListener('abort', onAbort, { once: true });
32
+ promise.then(value => { signal.removeEventListener('abort', onAbort); resolve(value); }, error => {
33
+ signal.removeEventListener('abort', onAbort);
34
+ reject(error);
35
+ });
36
+ });
37
+ }
38
+ /** Explicit cleanup avoids accumulating listeners or request deadline timers. */
39
+ export function abortScope(signals, timeoutMilliseconds) {
40
+ const controller = createAbortController();
41
+ const listeners = new Map();
42
+ for (const signal of signals) {
43
+ if (!signal || listeners.has(signal))
44
+ continue;
45
+ const onAbort = () => controller.abort(abortReason(signal));
46
+ if (signal.aborted)
47
+ onAbort();
48
+ else {
49
+ signal.addEventListener('abort', onAbort, { once: true });
50
+ listeners.set(signal, onAbort);
51
+ }
52
+ }
53
+ const timer = timeoutMilliseconds === undefined ? undefined : setTimeout(() => {
54
+ controller.abort(new DOMException('The relay request timed out.', 'TimeoutError'));
55
+ }, timeoutMilliseconds);
56
+ return {
57
+ signal: controller.signal,
58
+ dispose() { clearTimeout(timer); for (const [signal, listener] of listeners)
59
+ signal.removeEventListener('abort', listener); listeners.clear(); },
60
+ };
61
+ }
62
+ //# sourceMappingURL=clock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clock.js","sourceRoot":"","sources":["../../src/runtime/clock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAShE,MAAM,UAAU,cAAc,CAAC,MAAoB;IAC/C,IAAI,MAAM,EAAE,OAAO;QAAE,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAiB;IACrC,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;IAC/C,qBAAqB,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE;IAC9C,KAAK,CAAC,YAAY,EAAE,MAAM;QACtB,cAAc,CAAC,MAAM,CAA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;IACxB,OAAO;QACH,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,OAAO,KAAK,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,SAAS;YAAE,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;KACnJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,11 @@
1
+ export type EventListener<T> = (value: T) => void | Promise<void>;
2
+ /** Typed subscriptions with awaited dispatch or nonblocking notifications. */
3
+ export declare class EventHub<Events extends object> {
4
+ #private;
5
+ on<K extends keyof Events>(event: K, listener: EventListener<Events[K]>): () => void;
6
+ emit<K extends keyof Events>(event: K, value: Events[K]): Promise<void>;
7
+ /** Invoke every subscriber immediately; application async work never delays other subscribers or the publisher. */
8
+ notify<K extends keyof Events>(event: K, value: Events[K], failed: (error: AggregateError) => void): void;
9
+ clear(): void;
10
+ }
11
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/runtime/events.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAElE,8EAA8E;AAC9E,qBAAa,QAAQ,CAAC,MAAM,SAAS,MAAM;;IAEvC,EAAE,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,CAKnF;IACK,IAAI,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAO5E;IACD,mHAAmH;IACnH,MAAM,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,GAAG,IAAI,CAQxG;IACD,KAAK,IAAI,IAAI,CAA6B;CAC7C"}
@@ -0,0 +1,45 @@
1
+ /** Typed subscriptions with awaited dispatch or nonblocking notifications. */
2
+ export class EventHub {
3
+ #listeners = new Map();
4
+ on(event, listener) {
5
+ let listeners = this.#listeners.get(event);
6
+ if (!listeners) {
7
+ listeners = new Set();
8
+ this.#listeners.set(event, listeners);
9
+ }
10
+ listeners.add(listener);
11
+ return () => { listeners.delete(listener); };
12
+ }
13
+ async emit(event, value) {
14
+ const failures = [];
15
+ for (const listener of [...(this.#listeners.get(event) ?? [])]) {
16
+ try {
17
+ await listener(value);
18
+ }
19
+ catch (error) {
20
+ failures.push(error);
21
+ }
22
+ }
23
+ if (failures.length !== 0)
24
+ throw new AggregateError(failures, `A ${String(event)} event handler failed.`);
25
+ }
26
+ /** Invoke every subscriber immediately; application async work never delays other subscribers or the publisher. */
27
+ notify(event, value, failed) {
28
+ const failures = [];
29
+ const report = (errors) => { if (errors.length)
30
+ failed(new AggregateError(errors, `A ${String(event)} event handler failed.`)); };
31
+ for (const listener of [...(this.#listeners.get(event) ?? [])]) {
32
+ try {
33
+ const result = listener(value);
34
+ if (result)
35
+ void Promise.resolve(result).catch(error => report([error]));
36
+ }
37
+ catch (error) {
38
+ failures.push(error);
39
+ }
40
+ }
41
+ report(failures);
42
+ }
43
+ clear() { this.#listeners.clear(); }
44
+ }
45
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/runtime/events.ts"],"names":[],"mappings":"AAEA,8EAA8E;AAC9E,MAAM,OAAO,QAAQ;IACR,UAAU,GAAG,IAAI,GAAG,EAA2C,CAAC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AM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACnJ,KAAK,MAAM,QAAQ,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;YAC7D,IAAI,CAAC;gBAAC,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAc,CAAC,CAAC;gBAAC,IAAI,MAAM;oBAAE,KAAK,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAAC,CAAC;YAC1H,OAAO,KAAK,EAAE,CAAC;gBAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAAC,CAAC;QAC3C,CAAC;QACD,MAAM,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC;IACD,KAAK,KAAW,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAC7C"}
@@ -0,0 +1,3 @@
1
+ /** Normalize domain names before the platform parser, including Expo's ASCII-only URL. */
2
+ export declare function parseAbsoluteUrl(input: string): URL;
3
+ //# sourceMappingURL=url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/runtime/url.ts"],"names":[],"mappings":"AAEA,0FAA0F;AAC1F,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAanD"}
@@ -0,0 +1,23 @@
1
+ import { toASCII } from 'tr46';
2
+ /** Normalize domain names before the platform parser, including Expo's ASCII-only URL. */
3
+ export function parseAbsoluteUrl(input) {
4
+ const match = /^([a-z][a-z0-9+.-]*:\/\/)([^/?#]*)([\s\S]*)$/i.exec(input);
5
+ if (!match)
6
+ return new URL(input);
7
+ const authority = match[2];
8
+ const at = authority.lastIndexOf('@');
9
+ const credentials = authority.slice(0, at + 1);
10
+ const address = authority.slice(at + 1);
11
+ if (!address || address.startsWith('['))
12
+ return new URL(input); // IPv6 belongs to the URL parser.
13
+ const colon = address.lastIndexOf(':');
14
+ const port = colon === -1 ? '' : address.slice(colon);
15
+ const host = decodeURIComponent(colon === -1 ? address : address.slice(0, colon));
16
+ const ascii = toASCII(host, { checkBidi: true, checkJoiners: true, checkHyphens: false,
17
+ transitionalProcessing: false, useSTD3ASCIIRules: false, verifyDNSLength: false });
18
+ // Prevent escaped or mapped separators from changing authority boundaries.
19
+ if (!ascii || /[\u0000-\u0020\u007f#%/:<>?@[\\\]^|]/.test(ascii))
20
+ throw new TypeError('Invalid international domain name.');
21
+ return new URL(match[1] + credentials + ascii + port + match[3]);
22
+ }
23
+ //# sourceMappingURL=url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/runtime/url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,0FAA0F;AAC1F,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC1C,MAAM,KAAK,GAAG,+CAA+C,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1E,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IAClC,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC;IAAC,MAAM,EAAE,GAAG,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACnE,MAAM,WAAW,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;IAAC,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACxF,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,kCAAkC;IAClG,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAAC,MAAM,IAAI,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC9F,MAAM,IAAI,GAAG,kBAAkB,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IAClF,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK;QAClF,sBAAsB,EAAE,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,CAAC;IACvF,2EAA2E;IAC3E,IAAI,CAAC,KAAK,IAAI,sCAAsC,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,oCAAoC,CAAC,CAAC;IAC5H,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAE,GAAG,WAAW,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC;AACvE,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { type JsonObject } from '../protocol/json.js';
2
+ import type { MeshlineStore, RecordKey, StoreMutation } from './store.js';
3
+ export interface SignedRequest {
4
+ readonly relayId: string;
5
+ readonly revision: number;
6
+ readonly document: JsonObject;
7
+ readonly pending: boolean;
8
+ }
9
+ export declare const requestKey: (method: string) => RecordKey;
10
+ export declare function readSignedRequest(value: JsonObject | undefined): SignedRequest | undefined;
11
+ export declare function putSignedRequest(method: string, value: SignedRequest): StoreMutation;
12
+ /** Never clear a newer request installed by a different component/process. No caller cancellation. */
13
+ export declare function finishSignedRequest(store: MeshlineStore, method: string, expected: SignedRequest): Promise<void>;
14
+ //# sourceMappingURL=signed-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signed-request.d.ts","sourceRoot":"","sources":["../../src/storage/signed-request.ts"],"names":[],"mappings":"AAEA,OAAO,EAAoD,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACxG,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG1E,MAAM,WAAW,aAAa;IAAG,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAAE;AAChJ,eAAO,MAAM,UAAU,WAAY,MAAM,KAAG,SAA6D,CAAC;AAC1G,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,aAAa,GAAG,SAAS,CAM1F;AACD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,aAAa,CAEpF;AACD,sGAAsG;AACtG,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAMtH"}
@@ -0,0 +1,26 @@
1
+ import { ProtocolError } from '../errors.js';
2
+ import { validateRelayId } from '../identity/neo.js';
3
+ import { canonicalJson, requireObject, requireSafeInteger } from '../protocol/json.js';
4
+ import { updateStore } from './transaction.js';
5
+ export const requestKey = (method) => ({ collection: 'signed_requests', key: method });
6
+ export function readSignedRequest(value) {
7
+ if (value === undefined)
8
+ return undefined;
9
+ if (typeof value.relayId !== 'string' || typeof value.pending !== 'boolean' || value.document === undefined)
10
+ throw new ProtocolError('invalid_storage', 'Invalid persisted signed request.');
11
+ validateRelayId(value.relayId);
12
+ requireSafeInteger(value.revision, 0);
13
+ return { relayId: value.relayId, revision: value.revision, document: requireObject(value.document), pending: value.pending };
14
+ }
15
+ export function putSignedRequest(method, value) {
16
+ return { ...requestKey(method), kind: 'put', value: { ...value } };
17
+ }
18
+ /** Never clear a newer request installed by a different component/process. No caller cancellation. */
19
+ export async function finishSignedRequest(store, method, expected) {
20
+ await updateStore(store, [requestKey(method)], snapshot => {
21
+ const current = readSignedRequest(snapshot.sets[0][0]?.value);
22
+ const matches = current?.pending && current.relayId === expected.relayId && canonicalJson(current.document) === canonicalJson(expected.document);
23
+ return { mutations: matches ? [putSignedRequest(method, { ...current, pending: false })] : [], result: undefined };
24
+ });
25
+ }
26
+ //# sourceMappingURL=signed-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signed-request.js","sourceRoot":"","sources":["../../src/storage/signed-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,kBAAkB,EAAmB,MAAM,qBAAqB,CAAC;AAExG,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAc,EAAa,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;AAC1G,MAAM,UAAU,iBAAiB,CAAC,KAA6B;IAC3D,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS;QACvG,MAAM,IAAI,aAAa,CAAC,iBAAiB,EAAE,mCAA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CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { type JsonObject } from '../protocol/json.js';
2
+ /** A storage instance belongs to one network/account and its persisted local device. */
3
+ export interface StorageBinding {
4
+ readonly context: string;
5
+ readonly accountId: string;
6
+ }
7
+ export interface RecordKey {
8
+ readonly collection: string;
9
+ readonly key: string;
10
+ }
11
+ export interface StoredRecord extends RecordKey {
12
+ readonly revision: number;
13
+ readonly value: JsonObject;
14
+ }
15
+ /** Keys are canonical ASCII SDK identifiers or sortable indexes, never user-facing text. */
16
+ export interface RecordQuery {
17
+ readonly collection: string;
18
+ readonly key?: string;
19
+ readonly prefix?: string;
20
+ readonly reverse?: boolean;
21
+ }
22
+ export type StoreMutation = (RecordKey & {
23
+ readonly kind: 'put';
24
+ readonly value: JsonObject;
25
+ }) | (RecordKey & {
26
+ readonly kind: 'delete';
27
+ });
28
+ export interface StoreSnapshot {
29
+ readonly version: number;
30
+ readonly sets: readonly (readonly StoredRecord[])[];
31
+ }
32
+ /** Fixed at open time. An empty batch marks completion; dispose releases the snapshot. */
33
+ export interface QueryReader<T> {
34
+ readNext(count: number, signal?: AbortSignal): Promise<readonly T[]>;
35
+ dispose(): Promise<void>;
36
+ }
37
+ /**
38
+ * Atomic compare-and-commit storage. Computation, signing, and network I/O happen
39
+ * outside database transactions. A conflicting commit must be recomputed from a
40
+ * new read; it must never blindly replay an external business request.
41
+ */
42
+ export interface MeshlineStore {
43
+ migrate(signal?: AbortSignal): Promise<void>;
44
+ initialize(binding: StorageBinding, signal?: AbortSignal): Promise<void>;
45
+ read(queries: readonly RecordQuery[], signal?: AbortSignal): Promise<StoreSnapshot>;
46
+ commit(expectedVersion: number, mutations: readonly StoreMutation[], signal?: AbortSignal): Promise<number>;
47
+ openQuery(query: RecordQuery, signal?: AbortSignal): Promise<QueryReader<StoredRecord>>;
48
+ dispose(): Promise<void>;
49
+ }
50
+ export declare function bindingJson(binding: StorageBinding): string;
51
+ export declare function validateRecordKey(value: RecordKey): void;
52
+ export declare function validateRecordQuery(query: RecordQuery): void;
53
+ /** Copies and validates a commit before an adapter opens its write transaction. */
54
+ export declare function prepareCommit(expectedVersion: number, mutations: readonly StoreMutation[]): readonly StoreMutation[];
55
+ export declare function requireBatchCount(count: number): void;
56
+ /** Preserves fixed snapshot semantics while projecting stored rows into domain results. */
57
+ export declare function mapQueryReader<T, U>(reader: QueryReader<T>, project: (value: T) => U): QueryReader<U>;
58
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/storage/store.ts"],"names":[],"mappings":"AAGA,OAAO,EAA+D,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEnH,wFAAwF;AACxF,MAAM,WAAW,cAAc;IAAG,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE;AAExF,MAAM,WAAW,SAAS;IAAG,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE;AAChF,MAAM,WAAW,YAAa,SAAQ,SAAS;IAAG,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;CAAE;AAEzG,4FAA4F;AAC5F,MAAM,WAAW,WAAW;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;CAAE,CAAC,GACxF,CAAC,SAAS,GAAG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,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAK5D;AAED,mFAAmF;AACnF,wBAAgB,aAAa,CAAC,eAAe,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,aAAa,EAAE,GAAG,SAAS,aAAa,EAAE,CAcpH;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAkC;AAExF,2FAA2F;AAC3F,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAKrG"}
@@ -0,0 +1,52 @@
1
+ import { ProtocolError } from '../errors.js';
2
+ import { validateAccountId } from '../identity/neo.js';
3
+ import { NetworkContext } from '../protocol/context.js';
4
+ import { canonicalJson, parseJson, requireObject, requireSafeInteger } from '../protocol/json.js';
5
+ export function bindingJson(binding) {
6
+ NetworkContext.parse(binding.context);
7
+ validateAccountId(binding.accountId);
8
+ return canonicalJson({ context: binding.context, accountId: binding.accountId });
9
+ }
10
+ export function validateRecordKey(value) {
11
+ if (typeof value.collection !== 'string' || !/^[a-z][a-z0-9_.-]{0,63}$/.test(value.collection) || /[^a-z0-9_.-]/.test(value.collection))
12
+ throw new ProtocolError('invalid_storage_key', 'Collection must be a lowercase SDK identifier.');
13
+ if (typeof value.key !== 'string' || value.key.length > 4096 || /[^\x20-\x7e]/.test(value.key))
14
+ throw new ProtocolError('invalid_storage_key', 'Record keys must be at most 4096 printable ASCII characters.');
15
+ }
16
+ export function validateRecordQuery(query) {
17
+ if (query.key !== undefined && query.prefix !== undefined)
18
+ throw new ProtocolError('invalid_storage_query', 'Specify either key or prefix.');
19
+ validateRecordKey({ collection: query.collection, key: query.key ?? query.prefix ?? '' });
20
+ if (query.reverse !== undefined && typeof query.reverse !== 'boolean')
21
+ throw new ProtocolError('invalid_storage_query', 'reverse must be boolean.');
22
+ }
23
+ /** Copies and validates a commit before an adapter opens its write transaction. */
24
+ export function prepareCommit(expectedVersion, mutations) {
25
+ requireSafeInteger(expectedVersion, 0);
26
+ if (expectedVersion === Number.MAX_SAFE_INTEGER)
27
+ throw new ProtocolError('revision_exhausted', 'Storage revision is exhausted.');
28
+ if (mutations.length === 0)
29
+ throw new ProtocolError('empty_commit', 'A commit requires at least one mutation.');
30
+ const keys = new Set();
31
+ return mutations.map(mutation => {
32
+ validateRecordKey(mutation);
33
+ const id = mutation.collection + '\0' + mutation.key;
34
+ if (keys.has(id))
35
+ throw new ProtocolError('duplicate_mutation', 'A record may be changed only once per commit.');
36
+ keys.add(id);
37
+ if (mutation.kind === 'put')
38
+ return { ...mutation, value: requireObject(parseJson(canonicalJson(mutation.value))) };
39
+ if (mutation.kind === 'delete')
40
+ return { ...mutation };
41
+ throw new ProtocolError('invalid_mutation', 'Unknown store mutation.');
42
+ });
43
+ }
44
+ export function requireBatchCount(count) { requireSafeInteger(count, 1); }
45
+ /** Preserves fixed snapshot semantics while projecting stored rows into domain results. */
46
+ export function mapQueryReader(reader, project) {
47
+ return {
48
+ async readNext(count, signal) { return (await reader.readNext(count, signal)).map(project); },
49
+ dispose() { return reader.dispose(); },
50
+ };
51
+ }
52
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/storage/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,kBAAkB,EAAmB,MAAM,qBAAqB,CAAC;AAyCnH,MAAM,UAAU,WAAW,CAAC,OAAuB;IAC/C,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,C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,CAAC,KAAK,EAAE,MAAM,IAAI,OAAO,CAAC,MAAM,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC7F,OAAO,KAAK,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;KACzC,CAAC;AACN,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { MeshlineStore, RecordQuery, StoreMutation, StoreSnapshot } from './store.js';
2
+ /** Recomputes local changes on CAS contention. The planner must be synchronous and side-effect free. */
3
+ export declare function updateStore<T>(store: MeshlineStore, queries: readonly RecordQuery[], plan: (snapshot: StoreSnapshot) => {
4
+ readonly mutations: readonly StoreMutation[];
5
+ readonly result: T;
6
+ }, signal?: AbortSignal): Promise<T>;
7
+ //# sourceMappingURL=transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/storage/transaction.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3F,wGAAwG;AACxG,wBAAsB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,WAAW,EAAE,EACtF,IAAI,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK;IAAE,QAAQ,CAAC,SAAS,EAAE,SAAS,aAAa,EAAE,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;CAAE,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAU7I"}
@@ -0,0 +1,22 @@
1
+ import { StateConflictError } from '../errors.js';
2
+ import { throwIfAborted } from '../runtime/clock.js';
3
+ /** Recomputes local changes on CAS contention. The planner must be synchronous and side-effect free. */
4
+ export async function updateStore(store, queries, plan, signal) {
5
+ for (let attempt = 0; attempt < 16; attempt++) {
6
+ throwIfAborted(signal);
7
+ const snapshot = await store.read(queries, signal);
8
+ const update = plan(snapshot);
9
+ if (!update.mutations.length)
10
+ return update.result;
11
+ try {
12
+ await store.commit(snapshot.version, update.mutations, signal);
13
+ return update.result;
14
+ }
15
+ catch (error) {
16
+ if (!(error instanceof StateConflictError) || attempt === 15)
17
+ throw error;
18
+ }
19
+ }
20
+ throw new StateConflictError('Storage remained busy.');
21
+ }
22
+ //# sourceMappingURL=transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/storage/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,wGAAwG;AACxG,MAAM,CAAC,KAAK,UAAU,WAAW,CAAI,KAAoB,EAAE,OAA+B,EACtF,IAAuG,EAAE,MAAoB;IAC7H,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC;QAC5C,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACnD,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM;YAAE,OAAO,MAAM,CAAC,MAAM,CAAC;QACnD,IAAI,CAAC;YAAC,MAAM,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAAC,OAAO,MAAM,CAAC,MAAM,CAAC;QAAC,CAAC;QAC7F,OAAO,KAAK,EAAE,CAAC;YAAC,IAAI,CAAC,CAAC,KAAK,YAAY,kBAAkB,CAAC,IAAI,OAAO,KAAK,EAAE;gBAAE,MAAM,KAAK,CAAC;QAAC,CAAC;IAChG,CAAC;IACD,MAAM,IAAI,kBAAkB,CAAC,wBAAwB,CAAC,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,61 @@
1
+ import { type RandomSource } from '../crypto/primitives.js';
2
+ import type { RelayRegistry } from '../interactions.js';
3
+ import type { SessionMode } from '../models/authentication.js';
4
+ import type { RelayDescriptor, RelayInfo } from '../models/relay.js';
5
+ import type { JsonObject, JsonValue } from '../protocol/json.js';
6
+ import { type RuntimeClock } from '../runtime/clock.js';
7
+ import { type EventListener } from '../runtime/events.js';
8
+ import { type HttpMethod, type RelayFetch } from './http.js';
9
+ import type { RpcNotification } from './rpc.js';
10
+ import { RelayAuthenticator } from './session.js';
11
+ import { type RelaySocketFactory } from './socket.js';
12
+ import { RelaySubscription, type RelaySubscriptionOptions, type SubscriptionMethod } from './subscription.js';
13
+ export type RelayConnectionState = 'disconnected' | 'connecting' | 'connected';
14
+ export type RelayAuthenticationState = 'none' | 'authenticating' | 'account' | 'device' | 'expired' | 'rejected';
15
+ export interface RelayClientState {
16
+ readonly connection: RelayConnectionState;
17
+ readonly authentication: RelayAuthenticationState;
18
+ readonly sessionMode: SessionMode | undefined;
19
+ readonly lastError: unknown;
20
+ }
21
+ export interface RelayClientEvents {
22
+ readonly stateChanged: RelayClientState;
23
+ readonly socketConnected: {
24
+ readonly generation: number;
25
+ };
26
+ readonly notificationReceived: RpcNotification;
27
+ readonly errorOccurred: unknown;
28
+ readonly faulted: unknown;
29
+ }
30
+ export interface RelayTransportOptions {
31
+ readonly fetch?: RelayFetch;
32
+ readonly socketFactory?: RelaySocketFactory;
33
+ readonly clock?: RuntimeClock;
34
+ readonly random?: RandomSource;
35
+ readonly requestTimeoutMilliseconds?: number;
36
+ }
37
+ export interface HttpRequestOptions {
38
+ readonly authenticated?: boolean;
39
+ readonly signal?: AbortSignal;
40
+ }
41
+ /** Pool-owned transport for one relay and one immutable session identity. No constructor I/O. */
42
+ export declare class RelayClient {
43
+ #private;
44
+ readonly relayId: string;
45
+ constructor(relayId: string, registry: RelayRegistry, options?: RelayTransportOptions, authenticator?: RelayAuthenticator);
46
+ get sessionMode(): SessionMode | undefined;
47
+ get isDisposed(): boolean;
48
+ get state(): RelayClientState;
49
+ on<K extends keyof RelayClientEvents>(event: K, listener: EventListener<RelayClientEvents[K]>): () => void;
50
+ getDescriptor(signal?: AbortSignal): Promise<RelayDescriptor>;
51
+ getInfo(signal?: AbortSignal): Promise<RelayInfo>;
52
+ authenticate(signal?: AbortSignal): Promise<void>;
53
+ requestHttp(method: HttpMethod, name: string, parameters?: JsonObject, options?: HttpRequestOptions): Promise<JsonValue | undefined>;
54
+ /** Device notification reconnection restores transport only; callers synchronize after socketConnected. */
55
+ startNotifications(): void;
56
+ requestWebSocket(method: string, parameters?: JsonObject, signal?: AbortSignal): Promise<JsonValue>;
57
+ /** Owns the complete replacement stream for this method; dispose it after stopping its update producers. */
58
+ createSubscription(method: SubscriptionMethod, empty: JsonObject, options?: RelaySubscriptionOptions): RelaySubscription;
59
+ dispose(): Promise<void>;
60
+ }
61
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/transport/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAA4D,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClH,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEpE,OAAO,EAA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