@synnaxlabs/client 0.46.1 → 0.47.0

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 (503) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/dist/client.cjs +21 -21
  3. package/dist/client.js +2730 -2689
  4. package/dist/eslint.config.d.ts +3 -0
  5. package/dist/eslint.config.d.ts.map +1 -0
  6. package/dist/src/access/client.d.ts.map +1 -0
  7. package/dist/src/access/external.d.ts.map +1 -0
  8. package/dist/src/access/index.d.ts.map +1 -0
  9. package/dist/src/access/payload.d.ts.map +1 -0
  10. package/dist/src/access/policy/client.d.ts.map +1 -0
  11. package/dist/src/access/policy/external.d.ts.map +1 -0
  12. package/dist/src/access/policy/index.d.ts.map +1 -0
  13. package/dist/src/access/policy/payload.d.ts.map +1 -0
  14. package/dist/src/access/policy/policy.spec.d.ts.map +1 -0
  15. package/dist/{arc → src/arc}/client.d.ts +17 -2
  16. package/dist/src/arc/client.d.ts.map +1 -0
  17. package/dist/src/arc/external.d.ts.map +1 -0
  18. package/dist/src/arc/index.d.ts.map +1 -0
  19. package/dist/src/arc/lsp.spec.d.ts +2 -0
  20. package/dist/src/arc/lsp.spec.d.ts.map +1 -0
  21. package/dist/{arc → src/arc}/payload.d.ts +11 -9
  22. package/dist/src/arc/payload.d.ts.map +1 -0
  23. package/dist/src/auth/auth.d.ts.map +1 -0
  24. package/dist/{auth → src/auth}/auth.spec.d.ts.map +1 -1
  25. package/dist/src/auth/index.d.ts.map +1 -0
  26. package/dist/src/channel/batchRetriever.spec.d.ts.map +1 -0
  27. package/dist/src/channel/channel.spec.d.ts.map +1 -0
  28. package/dist/{channel → src/channel}/client.d.ts +8 -8
  29. package/dist/src/channel/client.d.ts.map +1 -0
  30. package/dist/src/channel/external.d.ts.map +1 -0
  31. package/dist/src/channel/index.d.ts.map +1 -0
  32. package/dist/src/channel/payload.d.ts +259 -0
  33. package/dist/src/channel/payload.d.ts.map +1 -0
  34. package/dist/{channel → src/channel}/retriever.d.ts +2 -1
  35. package/dist/src/channel/retriever.d.ts.map +1 -0
  36. package/dist/src/channel/writer.d.ts.map +1 -0
  37. package/dist/{client.d.ts → src/client.d.ts} +1 -1
  38. package/dist/src/client.d.ts.map +1 -0
  39. package/dist/{connection → src/connection}/checker.d.ts +1 -1
  40. package/dist/src/connection/checker.d.ts.map +1 -0
  41. package/dist/src/connection/connection.spec.d.ts.map +1 -0
  42. package/dist/src/connection/index.d.ts.map +1 -0
  43. package/dist/src/control/client.d.ts.map +1 -0
  44. package/dist/src/control/external.d.ts.map +1 -0
  45. package/dist/src/control/index.d.ts.map +1 -0
  46. package/dist/{control → src/control}/state.d.ts +1 -2
  47. package/dist/src/control/state.d.ts.map +1 -0
  48. package/dist/{control → src/control}/state.spec.d.ts.map +1 -1
  49. package/dist/src/errors.d.ts.map +1 -0
  50. package/dist/{errors.spec.d.ts.map → src/errors.spec.d.ts.map} +1 -1
  51. package/dist/{framer → src/framer}/adapter.d.ts +1 -1
  52. package/dist/src/framer/adapter.d.ts.map +1 -0
  53. package/dist/src/framer/adapter.spec.d.ts.map +1 -0
  54. package/dist/src/framer/client.d.ts.map +1 -0
  55. package/dist/src/framer/client.spec.d.ts.map +1 -0
  56. package/dist/src/framer/codec.d.ts.map +1 -0
  57. package/dist/{framer → src/framer}/codec.spec.d.ts.map +1 -1
  58. package/dist/src/framer/deleter.d.ts.map +1 -0
  59. package/dist/src/framer/deleter.spec.d.ts.map +1 -0
  60. package/dist/{framer → src/framer}/external.d.ts +1 -0
  61. package/dist/src/framer/external.d.ts.map +1 -0
  62. package/dist/{framer → src/framer}/frame.d.ts +4 -4
  63. package/dist/src/framer/frame.d.ts.map +1 -0
  64. package/dist/{framer → src/framer}/frame.spec.d.ts.map +1 -1
  65. package/dist/src/framer/index.d.ts.map +1 -0
  66. package/dist/{framer → src/framer}/iterator.d.ts +1 -2
  67. package/dist/src/framer/iterator.d.ts.map +1 -0
  68. package/dist/src/framer/iterator.spec.d.ts.map +1 -0
  69. package/dist/src/framer/payload.d.ts +7 -0
  70. package/dist/src/framer/payload.d.ts.map +1 -0
  71. package/dist/src/framer/streamProxy.d.ts.map +1 -0
  72. package/dist/{framer → src/framer}/streamer.d.ts +106 -4
  73. package/dist/src/framer/streamer.d.ts.map +1 -0
  74. package/dist/src/framer/streamer.spec.d.ts.map +1 -0
  75. package/dist/{framer → src/framer}/writer.d.ts +133 -36
  76. package/dist/src/framer/writer.d.ts.map +1 -0
  77. package/dist/src/framer/writer.spec.d.ts.map +1 -0
  78. package/dist/src/hardware/client.d.ts.map +1 -0
  79. package/dist/src/hardware/device/client.d.ts.map +1 -0
  80. package/dist/src/hardware/device/device.spec.d.ts.map +1 -0
  81. package/dist/src/hardware/device/external.d.ts.map +1 -0
  82. package/dist/src/hardware/device/index.d.ts.map +1 -0
  83. package/dist/{hardware → src/hardware}/device/payload.d.ts +4 -4
  84. package/dist/src/hardware/device/payload.d.ts.map +1 -0
  85. package/dist/src/hardware/external.d.ts.map +1 -0
  86. package/dist/src/hardware/index.d.ts.map +1 -0
  87. package/dist/src/hardware/rack/client.d.ts.map +1 -0
  88. package/dist/src/hardware/rack/external.d.ts.map +1 -0
  89. package/dist/src/hardware/rack/index.d.ts.map +1 -0
  90. package/dist/{hardware → src/hardware}/rack/payload.d.ts +4 -4
  91. package/dist/src/hardware/rack/payload.d.ts.map +1 -0
  92. package/dist/src/hardware/rack/rack.spec.d.ts.map +1 -0
  93. package/dist/{hardware → src/hardware}/task/client.d.ts +1 -2
  94. package/dist/src/hardware/task/client.d.ts.map +1 -0
  95. package/dist/src/hardware/task/external.d.ts.map +1 -0
  96. package/dist/src/hardware/task/index.d.ts.map +1 -0
  97. package/dist/src/hardware/task/payload.d.ts.map +1 -0
  98. package/dist/src/hardware/task/task.spec.d.ts.map +1 -0
  99. package/dist/{index.d.ts → src/index.d.ts} +1 -1
  100. package/dist/src/index.d.ts.map +1 -0
  101. package/dist/src/label/client.d.ts.map +1 -0
  102. package/dist/src/label/external.d.ts.map +1 -0
  103. package/dist/src/label/index.d.ts.map +1 -0
  104. package/dist/{label → src/label}/label.spec.d.ts.map +1 -1
  105. package/dist/src/label/payload.d.ts.map +1 -0
  106. package/dist/src/ontology/client.d.ts.map +1 -0
  107. package/dist/src/ontology/external.d.ts.map +1 -0
  108. package/dist/src/ontology/group/client.d.ts.map +1 -0
  109. package/dist/src/ontology/group/external.d.ts.map +1 -0
  110. package/dist/src/ontology/group/group.spec.d.ts.map +1 -0
  111. package/dist/src/ontology/group/index.d.ts.map +1 -0
  112. package/dist/src/ontology/group/payload.d.ts.map +1 -0
  113. package/dist/src/ontology/index.d.ts.map +1 -0
  114. package/dist/src/ontology/ontology.spec.d.ts.map +1 -0
  115. package/dist/src/ontology/payload.d.ts.map +1 -0
  116. package/dist/src/ontology/writer.d.ts.map +1 -0
  117. package/dist/{ranger → src/ranger}/alias.d.ts +1 -1
  118. package/dist/src/ranger/alias.d.ts.map +1 -0
  119. package/dist/{ranger → src/ranger}/client.d.ts +1 -2
  120. package/dist/src/ranger/client.d.ts.map +1 -0
  121. package/dist/src/ranger/external.d.ts.map +1 -0
  122. package/dist/src/ranger/index.d.ts.map +1 -0
  123. package/dist/src/ranger/kv.d.ts.map +1 -0
  124. package/dist/{ranger → src/ranger}/payload.d.ts +1 -1
  125. package/dist/src/ranger/payload.d.ts.map +1 -0
  126. package/dist/src/ranger/ranger.spec.d.ts.map +1 -0
  127. package/dist/src/ranger/writer.d.ts.map +1 -0
  128. package/dist/src/status/client.d.ts.map +1 -0
  129. package/dist/src/status/external.d.ts.map +1 -0
  130. package/dist/src/status/index.d.ts.map +1 -0
  131. package/dist/{status → src/status}/payload.d.ts +2 -2
  132. package/dist/src/status/payload.d.ts.map +1 -0
  133. package/dist/src/status/status.spec.d.ts.map +1 -0
  134. package/dist/src/testutil/channels.d.ts.map +1 -0
  135. package/dist/src/testutil/client.d.ts.map +1 -0
  136. package/dist/src/testutil/telem.d.ts.map +1 -0
  137. package/dist/{transport.d.ts → src/transport.d.ts} +1 -2
  138. package/dist/src/transport.d.ts.map +1 -0
  139. package/dist/src/user/client.d.ts.map +1 -0
  140. package/dist/src/user/external.d.ts.map +1 -0
  141. package/dist/src/user/index.d.ts.map +1 -0
  142. package/dist/src/user/payload.d.ts.map +1 -0
  143. package/dist/src/user/retriever.d.ts.map +1 -0
  144. package/dist/{user → src/user}/user.spec.d.ts.map +1 -1
  145. package/dist/src/user/writer.d.ts.map +1 -0
  146. package/dist/src/util/decodeJSONString.d.ts.map +1 -0
  147. package/dist/src/util/parseWithoutKeyConversion.d.ts +3 -0
  148. package/dist/src/util/parseWithoutKeyConversion.d.ts.map +1 -0
  149. package/dist/src/util/retrieve.d.ts.map +1 -0
  150. package/dist/src/util/retrieve.spec.d.ts.map +1 -0
  151. package/dist/src/util/telem.d.ts +3 -0
  152. package/dist/src/util/telem.d.ts.map +1 -0
  153. package/dist/src/workspace/client.d.ts.map +1 -0
  154. package/dist/src/workspace/external.d.ts.map +1 -0
  155. package/dist/src/workspace/index.d.ts.map +1 -0
  156. package/dist/src/workspace/lineplot/client.d.ts.map +1 -0
  157. package/dist/src/workspace/lineplot/external.d.ts.map +1 -0
  158. package/dist/src/workspace/lineplot/index.d.ts.map +1 -0
  159. package/dist/src/workspace/lineplot/lineplot.spec.d.ts.map +1 -0
  160. package/dist/{workspace → src/workspace}/lineplot/payload.d.ts +1 -1
  161. package/dist/src/workspace/lineplot/payload.d.ts.map +1 -0
  162. package/dist/src/workspace/log/client.d.ts.map +1 -0
  163. package/dist/src/workspace/log/external.d.ts.map +1 -0
  164. package/dist/src/workspace/log/index.d.ts.map +1 -0
  165. package/dist/src/workspace/log/log.spec.d.ts.map +1 -0
  166. package/dist/{workspace → src/workspace}/log/payload.d.ts +1 -1
  167. package/dist/src/workspace/log/payload.d.ts.map +1 -0
  168. package/dist/{workspace → src/workspace}/payload.d.ts +1 -1
  169. package/dist/src/workspace/payload.d.ts.map +1 -0
  170. package/dist/src/workspace/schematic/client.d.ts.map +1 -0
  171. package/dist/src/workspace/schematic/external.d.ts.map +1 -0
  172. package/dist/src/workspace/schematic/index.d.ts.map +1 -0
  173. package/dist/{workspace → src/workspace}/schematic/payload.d.ts +1 -1
  174. package/dist/src/workspace/schematic/payload.d.ts.map +1 -0
  175. package/dist/src/workspace/schematic/schematic.spec.d.ts.map +1 -0
  176. package/dist/src/workspace/schematic/symbol/client.d.ts.map +1 -0
  177. package/dist/src/workspace/schematic/symbol/client.spec.d.ts.map +1 -0
  178. package/dist/src/workspace/schematic/symbol/external.d.ts.map +1 -0
  179. package/dist/src/workspace/schematic/symbol/index.d.ts.map +1 -0
  180. package/dist/src/workspace/schematic/symbol/payload.d.ts.map +1 -0
  181. package/dist/src/workspace/table/client.d.ts.map +1 -0
  182. package/dist/src/workspace/table/external.d.ts.map +1 -0
  183. package/dist/src/workspace/table/index.d.ts.map +1 -0
  184. package/dist/{workspace → src/workspace}/table/payload.d.ts +1 -1
  185. package/dist/src/workspace/table/payload.d.ts.map +1 -0
  186. package/dist/src/workspace/table/table.spec.d.ts.map +1 -0
  187. package/dist/src/workspace/workspace.spec.d.ts.map +1 -0
  188. package/examples/node/streamWrite.js +0 -1
  189. package/package.json +7 -7
  190. package/src/arc/client.ts +27 -2
  191. package/src/arc/lsp.spec.ts +852 -0
  192. package/src/arc/payload.ts +13 -8
  193. package/src/auth/auth.spec.ts +1 -1
  194. package/src/channel/batchRetriever.spec.ts +3 -2
  195. package/src/channel/channel.spec.ts +8 -22
  196. package/src/channel/client.ts +22 -14
  197. package/src/channel/payload.ts +25 -4
  198. package/src/channel/retriever.ts +2 -3
  199. package/src/client.ts +2 -4
  200. package/src/connection/checker.ts +3 -4
  201. package/src/connection/connection.spec.ts +1 -1
  202. package/src/control/state.ts +1 -3
  203. package/src/errors.ts +2 -2
  204. package/src/framer/adapter.spec.ts +1 -1
  205. package/src/framer/adapter.ts +1 -2
  206. package/src/framer/client.ts +0 -2
  207. package/src/framer/codec.spec.ts +11 -1
  208. package/src/framer/codec.ts +3 -2
  209. package/src/framer/deleter.spec.ts +1 -1
  210. package/src/framer/deleter.ts +1 -3
  211. package/src/framer/external.ts +1 -0
  212. package/src/framer/frame.spec.ts +1 -1
  213. package/src/framer/frame.ts +6 -5
  214. package/src/framer/iterator.spec.ts +1 -2
  215. package/src/framer/iterator.ts +3 -4
  216. package/src/framer/payload.ts +15 -0
  217. package/src/framer/streamer.spec.ts +15 -12
  218. package/src/framer/streamer.ts +1 -3
  219. package/src/framer/writer.spec.ts +1 -9
  220. package/src/framer/writer.ts +29 -35
  221. package/src/hardware/task/client.ts +9 -2
  222. package/src/index.ts +1 -1
  223. package/src/label/client.ts +1 -1
  224. package/src/ranger/alias.ts +1 -2
  225. package/src/ranger/client.ts +1 -2
  226. package/src/ranger/kv.ts +1 -2
  227. package/src/ranger/payload.ts +1 -2
  228. package/src/ranger/ranger.spec.ts +1 -2
  229. package/src/status/client.ts +1 -1
  230. package/src/status/payload.ts +4 -2
  231. package/src/transport.ts +1 -3
  232. package/src/user/writer.ts +1 -1
  233. package/src/util/parseWithoutKeyConversion.ts +1 -1
  234. package/src/util/telem.ts +1 -1
  235. package/src/workspace/lineplot/payload.ts +1 -1
  236. package/src/workspace/log/payload.ts +1 -1
  237. package/src/workspace/payload.ts +1 -1
  238. package/src/workspace/schematic/payload.ts +1 -1
  239. package/src/workspace/table/payload.ts +1 -1
  240. package/tsconfig.json +1 -1
  241. package/dist/access/client.d.ts.map +0 -1
  242. package/dist/access/external.d.ts.map +0 -1
  243. package/dist/access/index.d.ts.map +0 -1
  244. package/dist/access/payload.d.ts.map +0 -1
  245. package/dist/access/policy/client.d.ts.map +0 -1
  246. package/dist/access/policy/external.d.ts.map +0 -1
  247. package/dist/access/policy/index.d.ts.map +0 -1
  248. package/dist/access/policy/payload.d.ts.map +0 -1
  249. package/dist/access/policy/policy.spec.d.ts.map +0 -1
  250. package/dist/arc/client.d.ts.map +0 -1
  251. package/dist/arc/external.d.ts.map +0 -1
  252. package/dist/arc/index.d.ts.map +0 -1
  253. package/dist/arc/payload.d.ts.map +0 -1
  254. package/dist/auth/auth.d.ts.map +0 -1
  255. package/dist/auth/index.d.ts.map +0 -1
  256. package/dist/channel/batchRetriever.spec.d.ts.map +0 -1
  257. package/dist/channel/channel.spec.d.ts.map +0 -1
  258. package/dist/channel/client.d.ts.map +0 -1
  259. package/dist/channel/external.d.ts.map +0 -1
  260. package/dist/channel/index.d.ts.map +0 -1
  261. package/dist/channel/payload.d.ts +0 -150
  262. package/dist/channel/payload.d.ts.map +0 -1
  263. package/dist/channel/retriever.d.ts.map +0 -1
  264. package/dist/channel/writer.d.ts.map +0 -1
  265. package/dist/client.d.ts.map +0 -1
  266. package/dist/connection/checker.d.ts.map +0 -1
  267. package/dist/connection/connection.spec.d.ts.map +0 -1
  268. package/dist/connection/index.d.ts.map +0 -1
  269. package/dist/control/client.d.ts.map +0 -1
  270. package/dist/control/external.d.ts.map +0 -1
  271. package/dist/control/index.d.ts.map +0 -1
  272. package/dist/control/state.d.ts.map +0 -1
  273. package/dist/errors.d.ts.map +0 -1
  274. package/dist/framer/adapter.d.ts.map +0 -1
  275. package/dist/framer/adapter.spec.d.ts.map +0 -1
  276. package/dist/framer/client.d.ts.map +0 -1
  277. package/dist/framer/client.spec.d.ts.map +0 -1
  278. package/dist/framer/codec.d.ts.map +0 -1
  279. package/dist/framer/deleter.d.ts.map +0 -1
  280. package/dist/framer/deleter.spec.d.ts.map +0 -1
  281. package/dist/framer/external.d.ts.map +0 -1
  282. package/dist/framer/frame.d.ts.map +0 -1
  283. package/dist/framer/index.d.ts.map +0 -1
  284. package/dist/framer/iterator.d.ts.map +0 -1
  285. package/dist/framer/iterator.spec.d.ts.map +0 -1
  286. package/dist/framer/streamProxy.d.ts.map +0 -1
  287. package/dist/framer/streamer.d.ts.map +0 -1
  288. package/dist/framer/streamer.spec.d.ts.map +0 -1
  289. package/dist/framer/writer.d.ts.map +0 -1
  290. package/dist/framer/writer.spec.d.ts.map +0 -1
  291. package/dist/hardware/client.d.ts.map +0 -1
  292. package/dist/hardware/device/client.d.ts.map +0 -1
  293. package/dist/hardware/device/device.spec.d.ts.map +0 -1
  294. package/dist/hardware/device/external.d.ts.map +0 -1
  295. package/dist/hardware/device/index.d.ts.map +0 -1
  296. package/dist/hardware/device/payload.d.ts.map +0 -1
  297. package/dist/hardware/external.d.ts.map +0 -1
  298. package/dist/hardware/index.d.ts.map +0 -1
  299. package/dist/hardware/rack/client.d.ts.map +0 -1
  300. package/dist/hardware/rack/external.d.ts.map +0 -1
  301. package/dist/hardware/rack/index.d.ts.map +0 -1
  302. package/dist/hardware/rack/payload.d.ts.map +0 -1
  303. package/dist/hardware/rack/rack.spec.d.ts.map +0 -1
  304. package/dist/hardware/task/client.d.ts.map +0 -1
  305. package/dist/hardware/task/external.d.ts.map +0 -1
  306. package/dist/hardware/task/index.d.ts.map +0 -1
  307. package/dist/hardware/task/payload.d.ts.map +0 -1
  308. package/dist/hardware/task/task.spec.d.ts.map +0 -1
  309. package/dist/index.d.ts.map +0 -1
  310. package/dist/label/client.d.ts.map +0 -1
  311. package/dist/label/external.d.ts.map +0 -1
  312. package/dist/label/index.d.ts.map +0 -1
  313. package/dist/label/payload.d.ts.map +0 -1
  314. package/dist/ontology/client.d.ts.map +0 -1
  315. package/dist/ontology/external.d.ts.map +0 -1
  316. package/dist/ontology/group/client.d.ts.map +0 -1
  317. package/dist/ontology/group/external.d.ts.map +0 -1
  318. package/dist/ontology/group/group.spec.d.ts.map +0 -1
  319. package/dist/ontology/group/index.d.ts.map +0 -1
  320. package/dist/ontology/group/payload.d.ts.map +0 -1
  321. package/dist/ontology/index.d.ts.map +0 -1
  322. package/dist/ontology/ontology.spec.d.ts.map +0 -1
  323. package/dist/ontology/payload.d.ts.map +0 -1
  324. package/dist/ontology/writer.d.ts.map +0 -1
  325. package/dist/ranger/alias.d.ts.map +0 -1
  326. package/dist/ranger/client.d.ts.map +0 -1
  327. package/dist/ranger/external.d.ts.map +0 -1
  328. package/dist/ranger/index.d.ts.map +0 -1
  329. package/dist/ranger/kv.d.ts.map +0 -1
  330. package/dist/ranger/payload.d.ts.map +0 -1
  331. package/dist/ranger/ranger.spec.d.ts.map +0 -1
  332. package/dist/ranger/writer.d.ts.map +0 -1
  333. package/dist/status/client.d.ts.map +0 -1
  334. package/dist/status/external.d.ts.map +0 -1
  335. package/dist/status/index.d.ts.map +0 -1
  336. package/dist/status/payload.d.ts.map +0 -1
  337. package/dist/status/status.spec.d.ts.map +0 -1
  338. package/dist/testutil/channels.d.ts.map +0 -1
  339. package/dist/testutil/client.d.ts.map +0 -1
  340. package/dist/testutil/telem.d.ts.map +0 -1
  341. package/dist/transport.d.ts.map +0 -1
  342. package/dist/user/client.d.ts.map +0 -1
  343. package/dist/user/external.d.ts.map +0 -1
  344. package/dist/user/index.d.ts.map +0 -1
  345. package/dist/user/payload.d.ts.map +0 -1
  346. package/dist/user/retriever.d.ts.map +0 -1
  347. package/dist/user/writer.d.ts.map +0 -1
  348. package/dist/util/decodeJSONString.d.ts.map +0 -1
  349. package/dist/util/parseWithoutKeyConversion.d.ts +0 -3
  350. package/dist/util/parseWithoutKeyConversion.d.ts.map +0 -1
  351. package/dist/util/retrieve.d.ts.map +0 -1
  352. package/dist/util/retrieve.spec.d.ts.map +0 -1
  353. package/dist/util/telem.d.ts +0 -3
  354. package/dist/util/telem.d.ts.map +0 -1
  355. package/dist/workspace/client.d.ts.map +0 -1
  356. package/dist/workspace/external.d.ts.map +0 -1
  357. package/dist/workspace/index.d.ts.map +0 -1
  358. package/dist/workspace/lineplot/client.d.ts.map +0 -1
  359. package/dist/workspace/lineplot/external.d.ts.map +0 -1
  360. package/dist/workspace/lineplot/index.d.ts.map +0 -1
  361. package/dist/workspace/lineplot/lineplot.spec.d.ts.map +0 -1
  362. package/dist/workspace/lineplot/payload.d.ts.map +0 -1
  363. package/dist/workspace/log/client.d.ts.map +0 -1
  364. package/dist/workspace/log/external.d.ts.map +0 -1
  365. package/dist/workspace/log/index.d.ts.map +0 -1
  366. package/dist/workspace/log/log.spec.d.ts.map +0 -1
  367. package/dist/workspace/log/payload.d.ts.map +0 -1
  368. package/dist/workspace/payload.d.ts.map +0 -1
  369. package/dist/workspace/schematic/client.d.ts.map +0 -1
  370. package/dist/workspace/schematic/external.d.ts.map +0 -1
  371. package/dist/workspace/schematic/index.d.ts.map +0 -1
  372. package/dist/workspace/schematic/payload.d.ts.map +0 -1
  373. package/dist/workspace/schematic/schematic.spec.d.ts.map +0 -1
  374. package/dist/workspace/schematic/symbol/client.d.ts.map +0 -1
  375. package/dist/workspace/schematic/symbol/client.spec.d.ts.map +0 -1
  376. package/dist/workspace/schematic/symbol/external.d.ts.map +0 -1
  377. package/dist/workspace/schematic/symbol/index.d.ts.map +0 -1
  378. package/dist/workspace/schematic/symbol/payload.d.ts.map +0 -1
  379. package/dist/workspace/table/client.d.ts.map +0 -1
  380. package/dist/workspace/table/external.d.ts.map +0 -1
  381. package/dist/workspace/table/index.d.ts.map +0 -1
  382. package/dist/workspace/table/payload.d.ts.map +0 -1
  383. package/dist/workspace/table/table.spec.d.ts.map +0 -1
  384. package/dist/workspace/workspace.spec.d.ts.map +0 -1
  385. /package/dist/{access → src/access}/client.d.ts +0 -0
  386. /package/dist/{access → src/access}/external.d.ts +0 -0
  387. /package/dist/{access → src/access}/index.d.ts +0 -0
  388. /package/dist/{access → src/access}/payload.d.ts +0 -0
  389. /package/dist/{access → src/access}/policy/client.d.ts +0 -0
  390. /package/dist/{access → src/access}/policy/external.d.ts +0 -0
  391. /package/dist/{access → src/access}/policy/index.d.ts +0 -0
  392. /package/dist/{access → src/access}/policy/payload.d.ts +0 -0
  393. /package/dist/{access → src/access}/policy/policy.spec.d.ts +0 -0
  394. /package/dist/{arc → src/arc}/external.d.ts +0 -0
  395. /package/dist/{arc → src/arc}/index.d.ts +0 -0
  396. /package/dist/{auth → src/auth}/auth.d.ts +0 -0
  397. /package/dist/{auth → src/auth}/auth.spec.d.ts +0 -0
  398. /package/dist/{auth → src/auth}/index.d.ts +0 -0
  399. /package/dist/{channel → src/channel}/batchRetriever.spec.d.ts +0 -0
  400. /package/dist/{channel → src/channel}/channel.spec.d.ts +0 -0
  401. /package/dist/{channel → src/channel}/external.d.ts +0 -0
  402. /package/dist/{channel → src/channel}/index.d.ts +0 -0
  403. /package/dist/{channel → src/channel}/writer.d.ts +0 -0
  404. /package/dist/{connection → src/connection}/connection.spec.d.ts +0 -0
  405. /package/dist/{connection → src/connection}/index.d.ts +0 -0
  406. /package/dist/{control → src/control}/client.d.ts +0 -0
  407. /package/dist/{control → src/control}/external.d.ts +0 -0
  408. /package/dist/{control → src/control}/index.d.ts +0 -0
  409. /package/dist/{control → src/control}/state.spec.d.ts +0 -0
  410. /package/dist/{errors.d.ts → src/errors.d.ts} +0 -0
  411. /package/dist/{errors.spec.d.ts → src/errors.spec.d.ts} +0 -0
  412. /package/dist/{framer → src/framer}/adapter.spec.d.ts +0 -0
  413. /package/dist/{framer → src/framer}/client.d.ts +0 -0
  414. /package/dist/{framer → src/framer}/client.spec.d.ts +0 -0
  415. /package/dist/{framer → src/framer}/codec.d.ts +0 -0
  416. /package/dist/{framer → src/framer}/codec.spec.d.ts +0 -0
  417. /package/dist/{framer → src/framer}/deleter.d.ts +0 -0
  418. /package/dist/{framer → src/framer}/deleter.spec.d.ts +0 -0
  419. /package/dist/{framer → src/framer}/frame.spec.d.ts +0 -0
  420. /package/dist/{framer → src/framer}/index.d.ts +0 -0
  421. /package/dist/{framer → src/framer}/iterator.spec.d.ts +0 -0
  422. /package/dist/{framer → src/framer}/streamProxy.d.ts +0 -0
  423. /package/dist/{framer → src/framer}/streamer.spec.d.ts +0 -0
  424. /package/dist/{framer → src/framer}/writer.spec.d.ts +0 -0
  425. /package/dist/{hardware → src/hardware}/client.d.ts +0 -0
  426. /package/dist/{hardware → src/hardware}/device/client.d.ts +0 -0
  427. /package/dist/{hardware → src/hardware}/device/device.spec.d.ts +0 -0
  428. /package/dist/{hardware → src/hardware}/device/external.d.ts +0 -0
  429. /package/dist/{hardware → src/hardware}/device/index.d.ts +0 -0
  430. /package/dist/{hardware → src/hardware}/external.d.ts +0 -0
  431. /package/dist/{hardware → src/hardware}/index.d.ts +0 -0
  432. /package/dist/{hardware → src/hardware}/rack/client.d.ts +0 -0
  433. /package/dist/{hardware → src/hardware}/rack/external.d.ts +0 -0
  434. /package/dist/{hardware → src/hardware}/rack/index.d.ts +0 -0
  435. /package/dist/{hardware → src/hardware}/rack/rack.spec.d.ts +0 -0
  436. /package/dist/{hardware → src/hardware}/task/external.d.ts +0 -0
  437. /package/dist/{hardware → src/hardware}/task/index.d.ts +0 -0
  438. /package/dist/{hardware → src/hardware}/task/payload.d.ts +0 -0
  439. /package/dist/{hardware → src/hardware}/task/task.spec.d.ts +0 -0
  440. /package/dist/{label → src/label}/client.d.ts +0 -0
  441. /package/dist/{label → src/label}/external.d.ts +0 -0
  442. /package/dist/{label → src/label}/index.d.ts +0 -0
  443. /package/dist/{label → src/label}/label.spec.d.ts +0 -0
  444. /package/dist/{label → src/label}/payload.d.ts +0 -0
  445. /package/dist/{ontology → src/ontology}/client.d.ts +0 -0
  446. /package/dist/{ontology → src/ontology}/external.d.ts +0 -0
  447. /package/dist/{ontology → src/ontology}/group/client.d.ts +0 -0
  448. /package/dist/{ontology → src/ontology}/group/external.d.ts +0 -0
  449. /package/dist/{ontology → src/ontology}/group/group.spec.d.ts +0 -0
  450. /package/dist/{ontology → src/ontology}/group/index.d.ts +0 -0
  451. /package/dist/{ontology → src/ontology}/group/payload.d.ts +0 -0
  452. /package/dist/{ontology → src/ontology}/index.d.ts +0 -0
  453. /package/dist/{ontology → src/ontology}/ontology.spec.d.ts +0 -0
  454. /package/dist/{ontology → src/ontology}/payload.d.ts +0 -0
  455. /package/dist/{ontology → src/ontology}/writer.d.ts +0 -0
  456. /package/dist/{ranger → src/ranger}/external.d.ts +0 -0
  457. /package/dist/{ranger → src/ranger}/index.d.ts +0 -0
  458. /package/dist/{ranger → src/ranger}/kv.d.ts +0 -0
  459. /package/dist/{ranger → src/ranger}/ranger.spec.d.ts +0 -0
  460. /package/dist/{ranger → src/ranger}/writer.d.ts +0 -0
  461. /package/dist/{status → src/status}/client.d.ts +0 -0
  462. /package/dist/{status → src/status}/external.d.ts +0 -0
  463. /package/dist/{status → src/status}/index.d.ts +0 -0
  464. /package/dist/{status → src/status}/status.spec.d.ts +0 -0
  465. /package/dist/{testutil → src/testutil}/channels.d.ts +0 -0
  466. /package/dist/{testutil → src/testutil}/client.d.ts +0 -0
  467. /package/dist/{testutil → src/testutil}/telem.d.ts +0 -0
  468. /package/dist/{user → src/user}/client.d.ts +0 -0
  469. /package/dist/{user → src/user}/external.d.ts +0 -0
  470. /package/dist/{user → src/user}/index.d.ts +0 -0
  471. /package/dist/{user → src/user}/payload.d.ts +0 -0
  472. /package/dist/{user → src/user}/retriever.d.ts +0 -0
  473. /package/dist/{user → src/user}/user.spec.d.ts +0 -0
  474. /package/dist/{user → src/user}/writer.d.ts +0 -0
  475. /package/dist/{util → src/util}/decodeJSONString.d.ts +0 -0
  476. /package/dist/{util → src/util}/retrieve.d.ts +0 -0
  477. /package/dist/{util → src/util}/retrieve.spec.d.ts +0 -0
  478. /package/dist/{workspace → src/workspace}/client.d.ts +0 -0
  479. /package/dist/{workspace → src/workspace}/external.d.ts +0 -0
  480. /package/dist/{workspace → src/workspace}/index.d.ts +0 -0
  481. /package/dist/{workspace → src/workspace}/lineplot/client.d.ts +0 -0
  482. /package/dist/{workspace → src/workspace}/lineplot/external.d.ts +0 -0
  483. /package/dist/{workspace → src/workspace}/lineplot/index.d.ts +0 -0
  484. /package/dist/{workspace → src/workspace}/lineplot/lineplot.spec.d.ts +0 -0
  485. /package/dist/{workspace → src/workspace}/log/client.d.ts +0 -0
  486. /package/dist/{workspace → src/workspace}/log/external.d.ts +0 -0
  487. /package/dist/{workspace → src/workspace}/log/index.d.ts +0 -0
  488. /package/dist/{workspace → src/workspace}/log/log.spec.d.ts +0 -0
  489. /package/dist/{workspace → src/workspace}/schematic/client.d.ts +0 -0
  490. /package/dist/{workspace → src/workspace}/schematic/external.d.ts +0 -0
  491. /package/dist/{workspace → src/workspace}/schematic/index.d.ts +0 -0
  492. /package/dist/{workspace → src/workspace}/schematic/schematic.spec.d.ts +0 -0
  493. /package/dist/{workspace → src/workspace}/schematic/symbol/client.d.ts +0 -0
  494. /package/dist/{workspace → src/workspace}/schematic/symbol/client.spec.d.ts +0 -0
  495. /package/dist/{workspace → src/workspace}/schematic/symbol/external.d.ts +0 -0
  496. /package/dist/{workspace → src/workspace}/schematic/symbol/index.d.ts +0 -0
  497. /package/dist/{workspace → src/workspace}/schematic/symbol/payload.d.ts +0 -0
  498. /package/dist/{workspace → src/workspace}/table/client.d.ts +0 -0
  499. /package/dist/{workspace → src/workspace}/table/external.d.ts +0 -0
  500. /package/dist/{workspace → src/workspace}/table/index.d.ts +0 -0
  501. /package/dist/{workspace → src/workspace}/table/table.spec.d.ts +0 -0
  502. /package/dist/{workspace → src/workspace}/workspace.spec.d.ts +0 -0
  503. /package/{eslint.config.js → eslint.config.ts} +0 -0
package/dist/client.cjs CHANGED
@@ -1,26 +1,26 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("zod"),Rl=t=>{const e=t.replace(/_[a-z]/g,r=>r[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},ma=t=>{const e=(r,n=Mn)=>{if(typeof r=="string")return t(r);if(Array.isArray(r))return r.map(o=>e(o,n));if(!wn(r))return r;n=Dl(n);const s={},a=r;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),n):(Object.keys(a).forEach(o=>{let c=a[o];const l=t(o);n.recursive&&(wn(c)?oi(c)||(c=e(c,n)):n.recursiveInArray&&ai(c)&&(c=[...c].map(u=>{let h=u;return wn(u)?oi(h)||(h=e(u,n)):ai(u)&&(h=e({key:u},n).key),h}))),s[l]=c}),s)};return e},ga=ma(Rl),_l=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,r,n)=>`${r}_${n.toLowerCase()}`),jl=ma(_l),Ml=[Number,String,Uint8Array],Mn={recursive:!0,recursiveInArray:!0},Dl=(t=Mn)=>(t.recursive==null?t=Mn:t.recursiveInArray??=!1,t),ai=t=>t!=null&&Array.isArray(t),wn=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),oi=t=>Ml.some(e=>t instanceof e);let Pl=class{contentType="application/json";decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e))}decode(e,r){return this.decodeString(this.decoder.decode(e),r)}decodeString(e,r){const n=JSON.parse(e),s=ga(n);return r!=null?r.parse(s):s}encodeString(e){const r=jl(e);return JSON.stringify(r,(n,s)=>ArrayBuffer.isView(s)?Array.from(s):typeof s=="bigint"?s.toString():s)}};const Dn=new Pl,le=t=>t!=null&&typeof t=="object"&&"value"in t;let Et=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const Ul=t=>t!=null&&typeof t=="object"&&"toString"in t,Ll=(t,e=!1)=>{const r=Ul(t)?"stringer":typeof t;let n;switch(r){case"string":n=(s,a)=>s.localeCompare(a);break;case"stringer":n=(s,a)=>s.toString().localeCompare(a.toString());break;case"number":n=(s,a)=>Number(s)-Number(a);break;case"bigint":n=(s,a)=>BigInt(s)-BigInt(a)>0n?1:-1;break;case"boolean":n=(s,a)=>Number(s)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${r}`),()=>-1}return e?Bl(n):n},Bl=t=>(e,r)=>t(r,e),Br=i.z.tuple([i.z.number(),i.z.number()]);i.z.tuple([i.z.bigint(),i.z.bigint()]);const wa=i.z.object({width:i.z.number(),height:i.z.number()}),ql=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),Fl=["width","height"];i.z.enum(Fl);const Vl=["start","center","end"],Yl=["signedWidth","signedHeight"];i.z.enum(Yl);const Zr=i.z.object({x:i.z.number(),y:i.z.number()}),Wl=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),Hl=["x","y"],ba=i.z.enum(Hl),va=["top","right","bottom","left"];i.z.enum(va);const Gl=["left","right"],Ta=i.z.enum(Gl),Jl=["top","bottom"],za=i.z.enum(Jl),Ea=["center"],ci=i.z.enum(Ea),Kl=[...va,...Ea],Na=i.z.enum(Kl);i.z.enum(Vl);const Xl=["first","last"];i.z.enum(Xl);const Ql=i.z.object({lower:i.z.number(),upper:i.z.number()}),eh=i.z.object({lower:i.z.bigint(),upper:i.z.bigint()});i.z.union([Ql,Br]);i.z.union([eh,Br]);i.z.enum([...ba.options,...Na.options]);i.z.enum(["x","left","right"]);i.z.enum(["y","top","bottom"]);i.z.union([ba,Na,i.z.instanceof(String)]);const qr=t=>(e,r)=>{if(typeof e=="bigint"){if(th(r))return t(e,BigInt(r));const n=t(Number(e),Number(r));return typeof n=="number"?BigInt(Math.round(n)):n}return t(Number(e),Number(r))},Fr=qr((t,e)=>t-e),Vr=qr((t,e)=>t+e),th=t=>typeof t=="bigint"?!0:Number.isInteger(t),$e=qr((t,e)=>t*e),Yr=qr((t,e)=>t/e),Qe=(t,e,r)=>{const n={};if(typeof e=="object"&&(r=e,e=void 0),r={makeValid:!0,...r},typeof t=="number"||typeof t=="bigint")e!=null?(n.lower=t,n.upper=e):(n.lower=typeof t=="bigint"?0n:0,n.upper=t);else if(Array.isArray(t)){if(t.length!==2)throw new Error("bounds: expected array of length 2");[n.lower,n.upper]=t}else n.lower=t.lower,n.upper=t.upper;return r?.makeValid?rh(n):n},rh=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t,ui=(t,e)=>{const r=Qe(t);return e<r.lower?r.lower:e>=r.upper?r.upper-(typeof r.upper=="number"?1:1n):e};i.z.object({x:Ta.or(ci),y:za.or(ci)});const nh=i.z.object({x:Ta,y:za}),sh=Object.freeze({x:"left",y:"top"}),ih=(t,e)=>t.x===e.x&&t.y===e.y,li=i.z.union([i.z.number(),Zr,Br,wa,ql,Wl]),ah=(t,e)=>{if(typeof t=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return t==="x"?{x:e,y:0}:{x:0,y:e}}return typeof t=="number"?{x:t,y:e??t}:Array.isArray(t)?{x:t[0],y:t[1]}:"signedWidth"in t?{x:t.signedWidth,y:t.signedHeight}:"clientX"in t?{x:t.clientX,y:t.clientY}:"width"in t?{x:t.width,y:t.height}:{x:t.x,y:t.y}},hi=Object.freeze({x:0,y:0}),mr=i.z.union([i.z.number(),i.z.string()]);i.z.object({top:mr,left:mr,width:mr,height:mr});i.z.object({left:i.z.number(),top:i.z.number(),right:i.z.number(),bottom:i.z.number()});i.z.object({one:Zr,two:Zr,root:nh});const ms=(t,e,r=0,n=0,s)=>{const a={one:{...hi},two:{...hi},root:s??sh};if(typeof t=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:t,y:e},a.two={x:a.one.x+r,y:a.one.y+n},a}return"one"in t&&"two"in t&&"root"in t?{...t,root:s??t.root}:("getBoundingClientRect"in t&&(t=t.getBoundingClientRect()),"left"in t?(a.one={x:t.left,y:t.top},a.two={x:t.right,y:t.bottom},a):(a.one=t,e==null?a.two={x:a.one.x+r,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+r}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},bn=t=>{const e=ms(t);return{lower:e.one.x,upper:e.two.x}},vn=t=>{const e=ms(t);return{lower:e.one.y,upper:e.two.y}},oh=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t,ch=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([wa,ch,Zr,Br]);const uh=(t,e,r)=>e!==void 0&&t<e?e:r!==void 0&&t>r?r:t;i.z.object({offset:li,scale:li});i.z.object({offset:i.z.number(),scale:i.z.number()});const lh=t=>(e,r,n,s)=>r==="dimension"?[e,n]:[e,s?n-t:n+t],hh=t=>(e,r,n,s)=>[e,s?n/t:n*t],fh=t=>(e,r,n)=>{if(e===null)return[t,n];const{lower:s,upper:a}=e,{lower:o,upper:c}=t,l=a-s,u=c-o;if(r==="dimension")return[t,n*(u/l)];const h=(n-s)*(u/l)+o;return[t,h]},dh=t=>(e,r,n)=>[t,n],ph=()=>(t,e,r)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,r];const{lower:n,upper:s}=t;return[t,s-(r-n)]},yh=t=>(e,r,n)=>{const{lower:s,upper:a}=t;return n=uh(n,s,a),[e,n]};let fi=class ut{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new ut().translate(e)}static magnify(e){return new ut().magnify(e)}static scale(e,r){return new ut().scale(e,r)}translate(e){const r=this.new(),n=lh(e);return n.type="translate",r.ops.push(n),r}magnify(e){const r=this.new(),n=hh(e);return n.type="magnify",r.ops.push(n),r}scale(e,r){const n=Qe(e,r),s=this.new(),a=fh(n);return a.type="scale",s.ops.push(a),s}clamp(e,r){const n=Qe(e,r),s=this.new(),a=yh(n);return a.type="clamp",s.ops.push(a),s}reBound(e,r){const n=Qe(e,r),s=this.new(),a=dh(n);return a.type="re-bound",s.ops.push(a),s}invert(){const e=ph();e.type="invert";const r=this.new();return r.ops.push(e),r}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new ut;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,r){return this.currBounds=null,this.ops.reduce(([n,s],a)=>a(n,e,s,this.reversed),[null,r])[1]}reverse(){const e=this.new();e.ops.reverse();const r=[];return e.ops.forEach((n,s)=>{if(n.type==="scale"||r.some(([o,c])=>s>=o&&s<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>s);a!==-1&&r.push([s,a])}),r.forEach(([n,s])=>{const a=e.ops.slice(n,s);a.unshift(e.ops[s]),e.ops.splice(n,s-n+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new ut};(class ze{x;y;currRoot;constructor(e=new fi,r=new fi,n=null){this.x=e,this.y=r,this.currRoot=n}static translate(e,r){return new ze().translate(e,r)}static translateX(e){return new ze().translateX(e)}static translateY(e){return new ze().translateY(e)}static clamp(e){return new ze().clamp(e)}static magnify(e){return new ze().magnify(e)}static scale(e){return new ze().scale(e)}static reBound(e){return new ze().reBound(e)}translate(e,r){const n=ah(e,r),s=this.copy();return s.x=this.x.translate(n.x),s.y=this.y.translate(n.y),s}translateX(e){const r=this.copy();return r.x=this.x.translate(e),r}translateY(e){const r=this.copy();return r.y=this.y.translate(e),r}magnify(e){const r=this.copy();return r.x=this.x.magnify(e.x),r.y=this.y.magnify(e.y),r}scale(e){const r=this.copy();if(oh(e)){const n=this.currRoot;return r.currRoot=e.root,n!=null&&!ih(n,e.root)&&(n.x!==e.root.x&&(r.x=r.x.invert()),n.y!==e.root.y&&(r.y=r.y.invert())),r.x=r.x.scale(bn(e)),r.y=r.y.scale(vn(e)),r}return r.x=r.x.scale(e.width),r.y=r.y.scale(e.height),r}reBound(e){const r=this.copy();return r.x=this.x.reBound(bn(e)),r.y=this.y.reBound(vn(e)),r}clamp(e){const r=this.copy();return r.x=this.x.clamp(bn(e)),r.y=this.y.clamp(vn(e)),r}copy(){const e=new ze;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return ms(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}static IDENTITY=new ze});let Oa=(t,e=21)=>(r=e)=>{let n="",s=r|0;for(;s--;)n+=t[Math.random()*t.length|0];return n};const $a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",mh=`0123456789${$a}`,gh=11,wh=Oa($a,1),bh=Oa(mh,gh-1),vh=()=>`${wh()}${bh()}`,Th=(t,e)=>r=>r instanceof e||typeof r=="object"&&r!==null&&"discriminator"in r&&r.discriminator===t,Pn=2n**63n-1n,zh=2**63-1,Eh=i.z.enum(["static","dynamic"]),di=365,gr=30,Nh=i.z.union([i.z.tuple([i.z.int()]),i.z.tuple([i.z.int(),i.z.int().min(1).max(12)]),i.z.tuple([i.z.int(),i.z.int().min(1).max(12),i.z.int().min(1).max(31)])]),Sa=(t,e)=>{const r=new _(e);if(![C.DAY,C.HOUR,C.MINUTE,C.SECOND,C.MILLISECOND,C.MICROSECOND,C.NANOSECOND].some(s=>s.equals(r)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=t.valueOf()%r.valueOf();return t instanceof _?new _(n):new C(n)};let _=class E extends Et{constructor(e,r="UTC"){if(e==null)super(E.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*E.MILLISECOND.valueOf());else if(typeof e=="string")super(E.parseDateTimeString(e,r).valueOf());else if(Array.isArray(e))super(E.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),r==="local"&&(n=E.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e===zh?e=Pn:e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=E.MAX:e=E.MIN)),le(e)&&(e=e.value),super(BigInt(e.valueOf())+n)}}static parseDate([e=1970,r=1,n=1]){const s=new Date(e,r-1,n,0,0,0,0);return new E(BigInt(s.getTime())*E.MILLISECOND.valueOf()).truncate(E.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,r="UTC"){const[n,s,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let l=E.hours(parseInt(n??"00")).add(E.minutes(parseInt(s??"00"))).add(E.seconds(parseInt(o??"00"))).add(E.milliseconds(parseInt(c??"00")));return r==="local"&&(l=l.add(E.utcOffset)),l.valueOf()}static parseDateTimeString(e,r="UTC"){if(!e.includes("/")&&!e.includes("-"))return E.parseTimeString(e,r);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new E(BigInt(n.getTime())*E.MILLISECOND.valueOf(),r).valueOf()}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(E.utcOffset).date().toISOString()}timeString(e=!1,r="UTC"){const n=this.toISOString(r);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),r=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${r} ${n}`}static get utcOffset(){return new C(BigInt(new Date().getTimezoneOffset())*E.MINUTE.valueOf())}static since(e){return new E().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new E(e).valueOf()}span(e){return this.range(e).span}range(e){return new Rt(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new E(e).valueOf()}afterEq(e){return this.valueOf()>=new E(e).valueOf()}before(e){return this.valueOf()<new E(e).valueOf()}beforeEq(e){return this.valueOf()<=new E(e).valueOf()}add(e){return new E(Vr(this.valueOf(),new C(e).valueOf()))}sub(e){return new E(Fr(this.valueOf(),new C(e).valueOf()))}get hours(){return Number(this.valueOf())/Number(C.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(C.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(C.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(C.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(E.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(E.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}setYear(e){const r=this.date();return r.setUTCFullYear(e),new E(r)}get month(){return this.date().getUTCMonth()}setMonth(e){const r=this.date();return r.setUTCMonth(e),new E(r)}get day(){return this.date().getUTCDate()}setDay(e){const r=this.date();return r.setUTCDate(e),new E(r)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(e){const r=this.date();return r.setHours(e),new E(r)}setHour(e){const r=this.date();return r.setUTCHours(e),new E(r)}get minute(){return this.date().getUTCMinutes()}setMinute(e){const r=this.date();return r.setUTCMinutes(e),new E(r)}get second(){return this.date().getUTCSeconds()}setSecond(e){const r=this.date();return r.setUTCSeconds(e),new E(r)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const r=this.date();return r.setUTCMilliseconds(e),new E(r)}toString(e="ISO",r="UTC"){switch(e){case"ISODate":return this.toISOString(r).slice(0,10);case"ISOTime":return this.toISOString(r).slice(11,23);case"time":return this.timeString(!1,r);case"preciseTime":return this.timeString(!0,r);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,r)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,r)}`;default:return this.toISOString(r)}}remainder(e){return Sa(this,e)}get isToday(){return this.truncate(C.DAY).equals(E.now().truncate(C.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new E(new Date)}static max(...e){let r=E.MIN;for(const n of e){const s=new E(n);s.after(r)&&(r=s)}return r}static min(...e){let r=E.MAX;for(const n of e){const s=new E(n);s.before(r)&&(r=s)}return r}static nanoseconds(e,r="UTC"){return new E(e,r)}static NANOSECOND=E.nanoseconds(1);static microseconds(e,r="UTC"){return E.nanoseconds(e*1e3,r)}static MICROSECOND=E.microseconds(1);static milliseconds(e,r="UTC"){return E.microseconds(e*1e3,r)}static MILLISECOND=E.milliseconds(1);static seconds(e,r="UTC"){return E.milliseconds(e*1e3,r)}static SECOND=E.seconds(1);static minutes(e,r="UTC"){return E.seconds(e*60,r)}static MINUTE=E.minutes(1);static hours(e,r="UTC"){return E.minutes(e*60,r)}static HOUR=E.hours(1);static days(e,r="UTC"){return E.hours(e*24,r)}static DAY=E.days(1);static MAX=new E(Pn);static MIN=new E(0);static ZERO=new E(0);static z=i.z.union([i.z.instanceof(E),i.z.object({value:i.z.bigint()}).transform(e=>new E(e.value)),i.z.string().transform(e=>new E(BigInt(e))),i.z.number().transform(e=>new E(e)),i.z.bigint().transform(e=>new E(e)),i.z.date().transform(e=>new E(e)),i.z.custom(e=>e instanceof C).transform(e=>new E(e)),Nh.transform(e=>new E(e))]);static sort(e,r){return Number(e.valueOf()-r.valueOf())}},C=class N extends Et{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),le(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof N?e:e instanceof Tn?e.period:e instanceof _?new N(e):(le(e)&&(e=e.value),["number","bigint"].includes(typeof e)?N.seconds(e):new N(e))}static fromMilliseconds(e){return e instanceof N?e:e instanceof Tn?e.period:e instanceof _?new N(e):(le(e)&&(e=e.value),["number","bigint"].includes(typeof e)?N.milliseconds(e):new N(e))}valueOf(){return this.value}lessThan(e){return this.valueOf()<new N(e).valueOf()}greaterThan(e){return this.valueOf()>new N(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new N(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new N(e).valueOf()}remainder(e){return Sa(this,e)}truncate(e){return new N(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(e="full"){if(e==="semantic")return this.toSemanticString();const r=this.truncate(N.DAY),n=this.truncate(N.HOUR),s=this.truncate(N.MINUTE),a=this.truncate(N.SECOND),o=this.truncate(N.MILLISECOND),c=this.truncate(N.MICROSECOND),l=this.truncate(N.NANOSECOND),u=r,h=n.sub(r),d=s.sub(n),f=a.sub(s),v=o.sub(a),S=c.sub(o),Z=l.sub(c);let b="";return u.isZero||(b+=`${u.days}d `),h.isZero||(b+=`${h.hours}h `),d.isZero||(b+=`${d.minutes}m `),f.isZero||(b+=`${f.seconds}s `),v.isZero||(b+=`${v.milliseconds}ms `),S.isZero||(b+=`${S.microseconds}µs `),Z.isZero||(b+=`${Z.nanoseconds}ns`),b.trim()}toSemanticString(){const e=this.valueOf()<0n?-this.valueOf():this.valueOf(),r=new N(e),n=this.valueOf()<0n;if(r.valueOf()===0n)return"0s";if(r.lessThan(N.SECOND))return"< 1s";const s=r.days,a=r.hours,o=r.minutes,c=r.seconds,l=Math.floor(s/di),u=Math.floor(s/gr),h=Math.floor(s/7),d=Math.floor(s),f=Math.floor(a),v=Math.floor(o),S=Math.floor(c),Z=n?"-":"";if(l>=1){let b=`${l}y`;if(l<2){const z=Math.floor(s%di/gr);z>0&&(b+=` ${z}mo`)}return Z+b}if(h>=1&&s<gr&&s%7===0){let b=`${h}w`;const z=Math.floor(s%7),k=Math.floor(a-h*7*24);return h<2&&(z>0?b+=` ${z}d`:k>0&&k<24&&(b+=` ${k}h`)),Z+b}if(u>=1){let b=`${u}mo`;if(u<3){const z=Math.floor(s%gr);z>0&&(b+=` ${z}d`)}return Z+b}if(h>=1){let b=`${h}w`;const z=Math.floor(s%7),k=Math.floor(a-h*7*24);return h<2&&(z>0?b+=` ${z}d`:k>0&&k<24&&(b+=` ${k}h`)),Z+b}if(d>=1){let b=`${d}d`;const z=Math.floor(a-d*24);return d<2&&z>0&&(b+=` ${z}h`),Z+b}if(f>=1){let b=`${f}h`;if(f<3){const z=Math.floor(o-f*60);z>0&&(b+=` ${z}m`)}return Z+b}if(v>=1){let b=`${v}m`;if(v<5){const z=Math.floor(c-v*60);z>0&&(b+=` ${z}s`)}return Z+b}return`${Z}${S}s`}mult(e){return new N($e(this.valueOf(),e))}div(e){return new N(Yr(this.valueOf(),e))}get days(){return Number(this.valueOf())/Number(N.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(N.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(N.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(N.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(N.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(N.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new N(e).valueOf()}add(e){return new N(this.valueOf()+new N(e).valueOf())}sub(e){return new N(this.valueOf()-new N(e).valueOf())}static nanoseconds(e=1){return new N(e)}static NANOSECOND=N.nanoseconds(1);static microseconds(e=1){return N.nanoseconds($e(e,1e3))}static MICROSECOND=N.microseconds(1);static milliseconds(e=1){return N.microseconds($e(e,1e3))}static MILLISECOND=N.milliseconds(1);static seconds(e=1){return N.milliseconds($e(e,1e3))}static SECOND=N.seconds(1);static minutes(e=1){return N.seconds($e(e,60))}static MINUTE=N.minutes(1);static hours(e){return N.minutes($e(e,60))}static HOUR=N.hours(1);static days(e){return N.hours($e(e,24))}static DAY=N.days(1);static MAX=new N(Pn);static MIN=new N(0);static ZERO=new N(0);static z=i.z.union([i.z.object({value:i.z.bigint()}).transform(e=>new N(e.value)),i.z.string().transform(e=>new N(BigInt(e))),i.z.number().transform(e=>new N(e)),i.z.bigint().transform(e=>new N(e)),i.z.instanceof(N),i.z.instanceof(_).transform(e=>new N(e)),i.z.custom(e=>e instanceof Tn).transform(e=>new N(e))])},Tn=class ue extends Et{constructor(e){le(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new ue(e).valueOf()}get period(){return C.seconds(1/this.valueOf())}sampleCount(e){return new C(e).seconds*this.valueOf()}byteCount(e,r){return this.sampleCount(e)*new te(r).valueOf()}span(e){return C.seconds(e/this.valueOf())}byteSpan(e,r){return this.span(e.valueOf()/new te(r).valueOf())}add(e){return new ue(Vr(this.valueOf(),new ue(e).valueOf()))}sub(e){return new ue(Fr(this.valueOf(),new ue(e).valueOf()))}mult(e){return new ue($e(this.valueOf(),e))}div(e){return new ue(Yr(this.valueOf(),e))}static hz(e){return new ue(e)}static khz(e){return ue.hz(e*1e3)}static z=i.z.union([i.z.number().transform(e=>new ue(e)),i.z.instanceof(ue)])},te=class ne extends Et{constructor(e){le(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new Un(e*this.valueOf())}add(e){return new ne(Vr(this.valueOf(),new ne(e).valueOf()))}sub(e){return new ne(Fr(this.valueOf(),new ne(e).valueOf()))}mult(e){return new ne($e(this.valueOf(),e))}div(e){return new ne(Yr(this.valueOf(),e))}static UNKNOWN=new ne(0);static BIT128=new ne(16);static BIT64=new ne(8);static BIT32=new ne(4);static BIT16=new ne(2);static BIT8=new ne(1);static z=i.z.union([i.z.number().transform(e=>new ne(e)),i.z.instanceof(ne)])},Rt=class Ee{start;end;constructor(e,r){typeof e=="object"&&"start"in e?(this.start=new _(e.start),this.end=new _(e.end)):(this.start=new _(e),this.end=new _(r))}get span(){return new C(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.start.isZero&&this.end.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new Ee(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,r=C.ZERO){if(r.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let n=this.start.sub(e.start).valueOf(),s=this.end.sub(e.end).valueOf();return n<0&&(n=-n),s<0&&(s=-s),n<=r.valueOf()&&s<=r.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.toString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,r=C.ZERO){e=e.makeValid();const n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;const s=_.max(n.start,e.start),a=_.min(n.end,e.end);return a.before(s)?!1:new C(a.sub(s)).greaterThanOrEqual(r)}contains(e){return e instanceof Ee?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const r=new Ee(this.start,this.end);return e.start.after(this.start)&&(r.start=e.start),e.start.after(this.end)&&(r.end=e.start),e.end.before(this.end)&&(r.end=e.end),e.end.before(this.start)&&(r.start=e.end),r}static max(...e){return new Ee(_.min(...e.map(r=>r.start)),_.max(...e.map(r=>r.end)))}static MAX=new Ee(_.MIN,_.MAX);static ZERO=new Ee(_.ZERO,_.ZERO);static z=i.z.union([i.z.object({start:_.z,end:_.z}).transform(e=>new Ee(e.start,e.end)),i.z.instanceof(Ee)]);static sort(e,r){return _.sort(e.start,r.start)||_.sort(e.end,r.end)}static simplify(e){return e.map(r=>r.makeValid()).sort((r,n)=>Ee.sort(r,n)).reduce((r,n)=>{if(n.span.isZero)return r;if(r.length===0)return r.push(n),r;const s=r[r.length-1];return s.overlapsWith(n)||s.end.equals(n.start)?s.end=_.max(s.end,n.end):r.push(n),r},[])}},B=class m extends Et{constructor(e){if(le(e)&&(e=e.value),e instanceof m||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const r=m.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(r==null)throw new Error(`unable to find data type for ${e.toString()}`);super(r.valueOf())}}get Array(){const e=m.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(r=>this.equals(r))}toString(e=!1){return e?m.SHORT_STRINGS.get(this.valueOf())??this.valueOf():this.valueOf()}get isVariable(){return this.equals(m.JSON)||this.equals(m.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(m.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=m.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(m.UINT8)||this.equals(m.UINT16)||this.equals(m.UINT32)||this.equals(m.UINT64)}get isSignedInteger(){return this.equals(m.INT8)||this.equals(m.INT16)||this.equals(m.INT32)||this.equals(m.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsignedInteger&&e.isSignedInteger?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(m.INT32)&&e.equals(m.FLOAT64)||this.equals(m.INT8)&&e.equals(m.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsignedInteger===e.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return m.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new m("unknown");static FLOAT64=new m("float64");static FLOAT32=new m("float32");static INT64=new m("int64");static INT32=new m("int32");static INT16=new m("int16");static INT8=new m("int8");static UINT64=new m("uint64");static UINT32=new m("uint32");static UINT16=new m("uint16");static UINT8=new m("uint8");static BOOLEAN=new m("boolean");static TIMESTAMP=new m("timestamp");static UUID=new m("uuid");static STRING=new m("string");static JSON=new m("json");static ARRAY_CONSTRUCTORS=new Map([[m.UINT8.toString(),Uint8Array],[m.UINT16.toString(),Uint16Array],[m.UINT32.toString(),Uint32Array],[m.UINT64.toString(),BigUint64Array],[m.FLOAT32.toString(),Float32Array],[m.FLOAT64.toString(),Float64Array],[m.INT8.toString(),Int8Array],[m.INT16.toString(),Int16Array],[m.INT32.toString(),Int32Array],[m.INT64.toString(),BigInt64Array],[m.TIMESTAMP.toString(),BigInt64Array],[m.STRING.toString(),Uint8Array],[m.JSON.toString(),Uint8Array],[m.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,m.UINT8],[Uint16Array.name,m.UINT16],[Uint32Array.name,m.UINT32],[BigUint64Array.name,m.UINT64],[Float32Array.name,m.FLOAT32],[Float64Array.name,m.FLOAT64],[Int8Array.name,m.INT8],[Int16Array.name,m.INT16],[Int32Array.name,m.INT32],[BigInt64Array.name,m.INT64]]);static DENSITIES=new Map([[m.UINT8.toString(),te.BIT8],[m.UINT16.toString(),te.BIT16],[m.UINT32.toString(),te.BIT32],[m.UINT64.toString(),te.BIT64],[m.FLOAT32.toString(),te.BIT32],[m.FLOAT64.toString(),te.BIT64],[m.INT8.toString(),te.BIT8],[m.INT16.toString(),te.BIT16],[m.INT32.toString(),te.BIT32],[m.INT64.toString(),te.BIT64],[m.TIMESTAMP.toString(),te.BIT64],[m.STRING.toString(),te.UNKNOWN],[m.JSON.toString(),te.UNKNOWN],[m.UUID.toString(),te.BIT128]]);static ALL=[m.UNKNOWN,m.FLOAT64,m.FLOAT32,m.INT64,m.INT32,m.INT16,m.INT8,m.UINT64,m.UINT32,m.UINT16,m.UINT8,m.TIMESTAMP,m.UUID,m.STRING,m.JSON];static SHORT_STRINGS=new Map([[m.UINT8.toString(),"u8"],[m.UINT16.toString(),"u16"],[m.UINT32.toString(),"u32"],[m.UINT64.toString(),"u64"],[m.INT8.toString(),"i8"],[m.INT16.toString(),"i16"],[m.INT32.toString(),"i32"],[m.INT64.toString(),"i64"],[m.FLOAT32.toString(),"f32"],[m.FLOAT64.toString(),"f64"],[m.BOOLEAN.toString(),"bool"],[m.TIMESTAMP.toString(),"ts"],[m.UUID.toString(),"uuid"],[m.STRING.toString(),"str"],[m.JSON.toString(),"json"]]);static BIG_INT_TYPES=[m.INT64,m.UINT64,m.TIMESTAMP];static z=i.z.union([i.z.string().transform(e=>new m(e)),i.z.instanceof(m)])},Un=class A extends Et{constructor(e){le(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return le(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return le(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return le(e)&&(e=e.value),new A(Vr(this.valueOf(),e.valueOf()))}sub(e){return le(e)&&(e=e.value),new A(Fr(this.valueOf(),e.valueOf()))}mult(e){return new A($e(this.valueOf(),e))}div(e){return new A(Yr(this.valueOf(),e))}truncate(e){return new A(Math.trunc(this.valueOf()/new A(e).valueOf())*new A(e).valueOf())}remainder(e){return A.bytes(this.valueOf()%new A(e).valueOf())}get gigabytes(){return this.valueOf()/A.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/A.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/A.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/A.TERABYTE.valueOf()}toString(){const e=this.truncate(A.TERABYTE),r=this.truncate(A.GIGABYTE),n=this.truncate(A.MEGABYTE),s=this.truncate(A.KILOBYTE),a=this.truncate(A.BYTE),o=e,c=r.sub(e),l=n.sub(r),u=s.sub(n),h=a.sub(s);let d="";return o.isZero||(d+=`${o.terabytes}TB `),c.isZero||(d+=`${c.gigabytes}GB `),l.isZero||(d+=`${l.megabytes}MB `),u.isZero||(d+=`${u.kilobytes}KB `),(!h.isZero||d==="")&&(d+=`${h.valueOf()}B`),d.trim()}static bytes(e=1){return new A(e)}static BYTE=new A(1);static kilobytes(e=1){return A.bytes(new A(e).valueOf()*1e3)}static KILOBYTE=A.kilobytes(1);static megabytes(e=1){return A.kilobytes(new A(e).valueOf()*1e3)}static MEGABYTE=A.megabytes(1);static gigabytes(e=1){return A.megabytes(new A(e).valueOf()*1e3)}static GIGABYTE=A.gigabytes(1);static terabytes(e){return A.gigabytes(new A(e).valueOf()*1e3)}static TERABYTE=A.terabytes(1);static ZERO=new A(0);static z=i.z.union([i.z.number().transform(e=>new A(e)),i.z.instanceof(A)]);get isZero(){return this.valueOf()===0}};i.z.object({start:i.z.number(),end:i.z.number()});i.z.union([i.z.instanceof(Uint8Array),i.z.instanceof(Uint16Array),i.z.instanceof(Uint32Array),i.z.instanceof(BigUint64Array),i.z.instanceof(Float32Array),i.z.instanceof(Float64Array),i.z.instanceof(Int8Array),i.z.instanceof(Int16Array),i.z.instanceof(Int32Array),i.z.instanceof(BigInt64Array)]);const Ia=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof _||t instanceof C||t instanceof Date},Oh=(t,e,r,n=0)=>t.usesBigInt&&!e.usesBigInt?Number(r)-Number(n):!t.usesBigInt&&e.usesBigInt?BigInt(r.valueOf())-BigInt(n.valueOf()):$r(r,-n),$r=(t,e)=>e==0?t:t==0?e:typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number"?t+e:Number(t)+Number(e),$h=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function Sh(t){return typeof t=="string"&&$h.test(t)}const K=[];for(let t=0;t<256;++t)K.push((t+256).toString(16).slice(1));function Ih(t,e=0){return(K[t[e+0]]+K[t[e+1]]+K[t[e+2]]+K[t[e+3]]+"-"+K[t[e+4]]+K[t[e+5]]+"-"+K[t[e+6]]+K[t[e+7]]+"-"+K[t[e+8]]+K[t[e+9]]+"-"+K[t[e+10]]+K[t[e+11]]+K[t[e+12]]+K[t[e+13]]+K[t[e+14]]+K[t[e+15]]).toLowerCase()}function kh(t,e=0){const r=Ih(t,e);if(!Sh(r))throw TypeError("Stringified UUID is invalid");return r}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const ka=(t,e)=>kh(t,e),Re=-1,Ah=i.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer),xh=i.z.union([i.z.null(),i.z.undefined()]).transform(()=>new Uint8Array().buffer),Ln=10,Zh=(t,e)=>{if(t==="number"&&!e.isNumeric)throw new Error(`cannot convert series of type ${e.toString()} to number`);if(t==="bigint"&&!e.usesBigInt)throw new Error(`cannot convert series of type ${e.toString()} to bigint`)},Aa="sy_x_telem_series";let xa=class De{key;discriminator=Aa;dataType;sampleOffset;gl;_data;timeRange=Rt.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=Re;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=i.z.object({timeRange:Rt.z.optional(),dataType:B.z,alignment:i.z.coerce.bigint().optional(),data:i.z.union([Ah,xh,i.z.instanceof(ArrayBuffer),i.z.instanceof(Uint8Array)]),glBufferUsage:Eh.optional().default("static").optional()});static z=De.crudeZ.transform(e=>new De(e));constructor(e){Ch(e)&&(e={data:e}),e.data??=[];const{dataType:r,timeRange:n,sampleOffset:s=0,glBufferUsage:a="static",alignment:o=0n,alignmentMultiple:c=1n,key:l=vh(),data:u}=e;if(Rh(u)){const f=u;this.key=f.key,this.dataType=f.dataType,this.sampleOffset=f.sampleOffset,this.gl=f.gl,this._data=f._data,this.timeRange=f.timeRange,this.alignment=f.alignment,this.alignmentMultiple=f.alignmentMultiple,this.cachedMin=f.cachedMin,this.cachedMax=f.cachedMax,this.writePos=f.writePos,this._refCount=f._refCount,this.cachedLength=f.cachedLength;return}const h=Ia(u),d=Array.isArray(u);if(r!=null)this.dataType=new B(r);else{if(u instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(d||h){let f=u;if(!h){if(u.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");f=u[0]}if(typeof f=="string")this.dataType=B.STRING;else if(typeof f=="number")this.dataType=B.FLOAT64;else if(typeof f=="bigint")this.dataType=B.INT64;else if(typeof f=="boolean")this.dataType=B.BOOLEAN;else if(f instanceof _||f instanceof Date||f instanceof _)this.dataType=B.TIMESTAMP;else if(typeof f=="object")this.dataType=B.JSON;else throw new Error(`cannot infer data type of ${typeof f} when constructing a Series from a JS array`)}else this.dataType=new B(u)}if(!d&&!h)this._data=u;else if(d&&u.length===0)this._data=new this.dataType.Array([]).buffer;else{let f=h?[u]:u;const v=f[0];(v instanceof _||v instanceof Date||v instanceof C)&&(f=f.map(S=>new _(S).valueOf())),this.dataType.equals(B.STRING)?(this.cachedLength=f.length,this._data=new TextEncoder().encode(`${f.join(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("zod"),Ll=t=>{const e=t.replace(/_[a-z]/g,r=>r[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},ga=t=>{const e=(r,n=Mn)=>{if(typeof r=="string")return t(r);if(Array.isArray(r))return r.map(o=>e(o,n));if(!wn(r))return r;n=Vl(n);const s={},a=r;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),n):(Object.keys(a).forEach(o=>{let c=a[o];const l=t(o);n.recursive&&(wn(c)?ci(c)||(c=e(c,n)):n.recursiveInArray&&oi(c)&&(c=[...c].map(u=>{let h=u;return wn(u)?ci(h)||(h=e(u,n)):oi(u)&&(h=e({key:u},n).key),h}))),s[l]=c}),s)};return e},wa=ga(Ll),Bl=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,r,n)=>`${r}_${n.toLowerCase()}`),ql=ga(Bl),Fl=[Number,String,Uint8Array],Mn={recursive:!0,recursiveInArray:!0},Vl=(t=Mn)=>(t.recursive==null?t=Mn:t.recursiveInArray??=!1,t),oi=t=>t!=null&&Array.isArray(t),wn=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),ci=t=>Fl.some(e=>t instanceof e);let Yl=class{contentType="application/json";decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e))}decode(e,r){return this.decodeString(this.decoder.decode(e),r)}decodeString(e,r){const n=JSON.parse(e),s=wa(n);return r!=null?r.parse(s):s}encodeString(e){const r=ql(e);return JSON.stringify(r,(n,s)=>ArrayBuffer.isView(s)?Array.from(s):typeof s=="bigint"?s.toString():s)}};const Dn=new Yl,le=t=>t!=null&&typeof t=="object"&&"value"in t;let Nt=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const Hl=t=>t!=null&&typeof t=="object"&&"toString"in t,Wl=(t,e=!1)=>{const r=Hl(t)?"stringer":typeof t;let n;switch(r){case"string":n=(s,a)=>s.localeCompare(a);break;case"stringer":n=(s,a)=>s.toString().localeCompare(a.toString());break;case"number":n=(s,a)=>Number(s)-Number(a);break;case"bigint":n=(s,a)=>BigInt(s)-BigInt(a)>0n?1:-1;break;case"boolean":n=(s,a)=>Number(s)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${r}`),()=>-1}return e?Gl(n):n},Gl=t=>(e,r)=>t(r,e),Fr=i.z.tuple([i.z.number(),i.z.number()]);i.z.tuple([i.z.bigint(),i.z.bigint()]);const ba=i.z.object({width:i.z.number(),height:i.z.number()}),Kl=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),Jl=["width","height"];i.z.enum(Jl);const Xl=["start","center","end"],Ql=["signedWidth","signedHeight"];i.z.enum(Ql);const Rr=i.z.object({x:i.z.number(),y:i.z.number()}),eh=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),th=["x","y"],va=i.z.enum(th),Ta=["top","right","bottom","left"];i.z.enum(Ta);const rh=["left","right"],za=i.z.enum(rh),nh=["top","bottom"],Ea=i.z.enum(nh),Na=["center"],ui=i.z.enum(Na),sh=[...Ta,...Na],Oa=i.z.enum(sh);i.z.enum(Xl);const ih=["first","last"];i.z.enum(ih);const ah=i.z.object({lower:i.z.number(),upper:i.z.number()}),oh=i.z.object({lower:i.z.bigint(),upper:i.z.bigint()});i.z.union([ah,Fr]);i.z.union([oh,Fr]);i.z.enum([...va.options,...Oa.options]);i.z.enum(["x","left","right"]);i.z.enum(["y","top","bottom"]);i.z.union([va,Oa,i.z.instanceof(String)]);const Vr=t=>(e,r)=>{if(typeof e=="bigint"){if(ch(r))return t(e,BigInt(r));const n=t(Number(e),Number(r));return typeof n=="number"?BigInt(Math.round(n)):n}return t(Number(e),Number(r))},Yr=Vr((t,e)=>t-e),Hr=Vr((t,e)=>t+e),ch=t=>typeof t=="bigint"?!0:Number.isInteger(t),$e=Vr((t,e)=>t*e),Wr=Vr((t,e)=>t/e),et=(t,e,r)=>{const n={};if(typeof e=="object"&&(r=e,e=void 0),r={makeValid:!0,...r},typeof t=="number"||typeof t=="bigint")e!=null?(n.lower=t,n.upper=e):(n.lower=typeof t=="bigint"?0n:0,n.upper=t);else if(Array.isArray(t)){if(t.length!==2)throw new Error("bounds: expected array of length 2");[n.lower,n.upper]=t}else n.lower=t.lower,n.upper=t.upper;return r?.makeValid?uh(n):n},uh=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t,li=(t,e)=>{const r=et(t);return e<r.lower?r.lower:e>=r.upper?r.upper-(typeof r.upper=="number"?1:1n):e};i.z.object({x:za.or(ui),y:Ea.or(ui)});const lh=i.z.object({x:za,y:Ea}),hh=Object.freeze({x:"left",y:"top"}),fh=(t,e)=>t.x===e.x&&t.y===e.y,hi=i.z.union([i.z.number(),Rr,Fr,ba,Kl,eh]),dh=(t,e)=>{if(typeof t=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return t==="x"?{x:e,y:0}:{x:0,y:e}}return typeof t=="number"?{x:t,y:e??t}:Array.isArray(t)?{x:t[0],y:t[1]}:"signedWidth"in t?{x:t.signedWidth,y:t.signedHeight}:"clientX"in t?{x:t.clientX,y:t.clientY}:"width"in t?{x:t.width,y:t.height}:{x:t.x,y:t.y}},fi=Object.freeze({x:0,y:0}),wr=i.z.union([i.z.number(),i.z.string()]);i.z.object({top:wr,left:wr,width:wr,height:wr});i.z.object({left:i.z.number(),top:i.z.number(),right:i.z.number(),bottom:i.z.number()});i.z.object({one:Rr,two:Rr,root:lh});const ms=(t,e,r=0,n=0,s)=>{const a={one:{...fi},two:{...fi},root:s??hh};if(typeof t=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:t,y:e},a.two={x:a.one.x+r,y:a.one.y+n},a}return"one"in t&&"two"in t&&"root"in t?{...t,root:s??t.root}:("getBoundingClientRect"in t&&(t=t.getBoundingClientRect()),"left"in t?(a.one={x:t.left,y:t.top},a.two={x:t.right,y:t.bottom},a):(a.one=t,e==null?a.two={x:a.one.x+r,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+r}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},bn=t=>{const e=ms(t);return{lower:e.one.x,upper:e.two.x}},vn=t=>{const e=ms(t);return{lower:e.one.y,upper:e.two.y}},ph=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t,yh=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([ba,yh,Rr,Fr]);const mh=(t,e,r)=>e!==void 0&&t<e?e:r!==void 0&&t>r?r:t;i.z.object({offset:hi,scale:hi});i.z.object({offset:i.z.number(),scale:i.z.number()});const gh=t=>(e,r,n,s)=>r==="dimension"?[e,n]:[e,s?n-t:n+t],wh=t=>(e,r,n,s)=>[e,s?n/t:n*t],bh=t=>(e,r,n)=>{if(e===null)return[t,n];const{lower:s,upper:a}=e,{lower:o,upper:c}=t,l=a-s,u=c-o;if(r==="dimension")return[t,n*(u/l)];const h=(n-s)*(u/l)+o;return[t,h]},vh=t=>(e,r,n)=>[t,n],Th=()=>(t,e,r)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,r];const{lower:n,upper:s}=t;return[t,s-(r-n)]},zh=t=>(e,r,n)=>{const{lower:s,upper:a}=t;return n=mh(n,s,a),[e,n]};let di=class lt{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new lt().translate(e)}static magnify(e){return new lt().magnify(e)}static scale(e,r){return new lt().scale(e,r)}translate(e){const r=this.new(),n=gh(e);return n.type="translate",r.ops.push(n),r}magnify(e){const r=this.new(),n=wh(e);return n.type="magnify",r.ops.push(n),r}scale(e,r){const n=et(e,r),s=this.new(),a=bh(n);return a.type="scale",s.ops.push(a),s}clamp(e,r){const n=et(e,r),s=this.new(),a=zh(n);return a.type="clamp",s.ops.push(a),s}reBound(e,r){const n=et(e,r),s=this.new(),a=vh(n);return a.type="re-bound",s.ops.push(a),s}invert(){const e=Th();e.type="invert";const r=this.new();return r.ops.push(e),r}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new lt;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,r){return this.currBounds=null,this.ops.reduce(([n,s],a)=>a(n,e,s,this.reversed),[null,r])[1]}reverse(){const e=this.new();e.ops.reverse();const r=[];return e.ops.forEach((n,s)=>{if(n.type==="scale"||r.some(([o,c])=>s>=o&&s<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>s);a!==-1&&r.push([s,a])}),r.forEach(([n,s])=>{const a=e.ops.slice(n,s);a.unshift(e.ops[s]),e.ops.splice(n,s-n+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new lt};(class ze{x;y;currRoot;constructor(e=new di,r=new di,n=null){this.x=e,this.y=r,this.currRoot=n}static translate(e,r){return new ze().translate(e,r)}static translateX(e){return new ze().translateX(e)}static translateY(e){return new ze().translateY(e)}static clamp(e){return new ze().clamp(e)}static magnify(e){return new ze().magnify(e)}static scale(e){return new ze().scale(e)}static reBound(e){return new ze().reBound(e)}translate(e,r){const n=dh(e,r),s=this.copy();return s.x=this.x.translate(n.x),s.y=this.y.translate(n.y),s}translateX(e){const r=this.copy();return r.x=this.x.translate(e),r}translateY(e){const r=this.copy();return r.y=this.y.translate(e),r}magnify(e){const r=this.copy();return r.x=this.x.magnify(e.x),r.y=this.y.magnify(e.y),r}scale(e){const r=this.copy();if(ph(e)){const n=this.currRoot;return r.currRoot=e.root,n!=null&&!fh(n,e.root)&&(n.x!==e.root.x&&(r.x=r.x.invert()),n.y!==e.root.y&&(r.y=r.y.invert())),r.x=r.x.scale(bn(e)),r.y=r.y.scale(vn(e)),r}return r.x=r.x.scale(e.width),r.y=r.y.scale(e.height),r}reBound(e){const r=this.copy();return r.x=this.x.reBound(bn(e)),r.y=this.y.reBound(vn(e)),r}clamp(e){const r=this.copy();return r.x=this.x.clamp(bn(e)),r.y=this.y.clamp(vn(e)),r}copy(){const e=new ze;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return ms(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}static IDENTITY=new ze});let $a=(t,e=21)=>(r=e)=>{let n="",s=r|0;for(;s--;)n+=t[Math.random()*t.length|0];return n};const Sa="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Eh=`0123456789${Sa}`,Nh=11,Oh=$a(Sa,1),$h=$a(Eh,Nh-1),Sh=()=>`${Oh()}${$h()}`,Ih=(t,e)=>r=>r instanceof e||typeof r=="object"&&r!==null&&"discriminator"in r&&r.discriminator===t,Ah=i.z.enum(["static","dynamic"]),Pn=2n**63n-1n,kh=2**63-1,pi=365,br=30,xh=i.z.union([i.z.tuple([i.z.int()]),i.z.tuple([i.z.int(),i.z.int().min(1).max(12)]),i.z.tuple([i.z.int(),i.z.int().min(1).max(12),i.z.int().min(1).max(31)])]),Ia=(t,e)=>{const r=new _(e);if(![C.DAY,C.HOUR,C.MINUTE,C.SECOND,C.MILLISECOND,C.MICROSECOND,C.NANOSECOND].some(s=>s.equals(r)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=t.valueOf()%r.valueOf();return t instanceof _?new _(n):new C(n)};let _=class E extends Nt{constructor(e,r="UTC"){if(e==null)super(E.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*E.MILLISECOND.valueOf());else if(typeof e=="string")super(E.parseDateTimeString(e,r).valueOf());else if(Array.isArray(e))super(E.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),r==="local"&&(n=E.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e===kh?e=Pn:e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=E.MAX:e=E.MIN)),le(e)&&(e=e.value),super(BigInt(e.valueOf())+n)}}static parseDate([e=1970,r=1,n=1]){const s=new Date(e,r-1,n,0,0,0,0);return new E(BigInt(s.getTime())*E.MILLISECOND.valueOf()).truncate(E.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,r="UTC"){const[n,s,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let l=E.hours(parseInt(n??"00")).add(E.minutes(parseInt(s??"00"))).add(E.seconds(parseInt(o??"00"))).add(E.milliseconds(parseInt(c??"00")));return r==="local"&&(l=l.add(E.utcOffset)),l.valueOf()}static parseDateTimeString(e,r="UTC"){if(!e.includes("/")&&!e.includes("-"))return E.parseTimeString(e,r);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new E(BigInt(n.getTime())*E.MILLISECOND.valueOf(),r).valueOf()}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(E.utcOffset).date().toISOString()}timeString(e=!1,r="UTC"){const n=this.toISOString(r);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),r=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${r} ${n}`}static get utcOffset(){return new C(BigInt(new Date().getTimezoneOffset())*E.MINUTE.valueOf())}static since(e){return new E().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new E(e).valueOf()}span(e){return this.range(e).span}range(e){return new _t(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new E(e).valueOf()}afterEq(e){return this.valueOf()>=new E(e).valueOf()}before(e){return this.valueOf()<new E(e).valueOf()}beforeEq(e){return this.valueOf()<=new E(e).valueOf()}add(e){return new E(Hr(this.valueOf(),new C(e).valueOf()))}sub(e){return new E(Yr(this.valueOf(),new C(e).valueOf()))}get hours(){return Number(this.valueOf())/Number(C.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(C.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(C.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(C.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(E.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(E.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}setYear(e){const r=this.date();return r.setUTCFullYear(e),new E(r)}get month(){return this.date().getUTCMonth()}setMonth(e){const r=this.date();return r.setUTCMonth(e),new E(r)}get day(){return this.date().getUTCDate()}setDay(e){const r=this.date();return r.setUTCDate(e),new E(r)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(e){const r=this.date();return r.setHours(e),new E(r)}setHour(e){const r=this.date();return r.setUTCHours(e),new E(r)}get minute(){return this.date().getUTCMinutes()}setMinute(e){const r=this.date();return r.setUTCMinutes(e),new E(r)}get second(){return this.date().getUTCSeconds()}setSecond(e){const r=this.date();return r.setUTCSeconds(e),new E(r)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const r=this.date();return r.setUTCMilliseconds(e),new E(r)}toString(e="ISO",r="UTC"){switch(e){case"ISODate":return this.toISOString(r).slice(0,10);case"ISOTime":return this.toISOString(r).slice(11,23);case"time":return this.timeString(!1,r);case"preciseTime":return this.timeString(!0,r);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,r)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,r)}`;default:return this.toISOString(r)}}remainder(e){return Ia(this,e)}get isToday(){return this.truncate(C.DAY).equals(E.now().truncate(C.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new E(new Date)}static max(...e){let r=E.MIN;for(const n of e){const s=new E(n);s.after(r)&&(r=s)}return r}static min(...e){let r=E.MAX;for(const n of e){const s=new E(n);s.before(r)&&(r=s)}return r}static nanoseconds(e,r="UTC"){return new E(e,r)}static NANOSECOND=E.nanoseconds(1);static microseconds(e,r="UTC"){return E.nanoseconds(e*1e3,r)}static MICROSECOND=E.microseconds(1);static milliseconds(e,r="UTC"){return E.microseconds(e*1e3,r)}static MILLISECOND=E.milliseconds(1);static seconds(e,r="UTC"){return E.milliseconds(e*1e3,r)}static SECOND=E.seconds(1);static minutes(e,r="UTC"){return E.seconds(e*60,r)}static MINUTE=E.minutes(1);static hours(e,r="UTC"){return E.minutes(e*60,r)}static HOUR=E.hours(1);static days(e,r="UTC"){return E.hours(e*24,r)}static DAY=E.days(1);static MAX=new E(Pn);static MIN=new E(0);static ZERO=new E(0);static z=i.z.union([i.z.instanceof(E),i.z.object({value:i.z.bigint()}).transform(e=>new E(e.value)),i.z.string().transform(e=>new E(BigInt(e))),i.z.number().transform(e=>new E(e)),i.z.bigint().transform(e=>new E(e)),i.z.date().transform(e=>new E(e)),i.z.custom(e=>e instanceof C).transform(e=>new E(e)),xh.transform(e=>new E(e))]);static sort(e,r){return Number(e.valueOf()-r.valueOf())}},C=class N extends Nt{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),le(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof N?e:e instanceof Tn?e.period:e instanceof _?new N(e):(le(e)&&(e=e.value),["number","bigint"].includes(typeof e)?N.seconds(e):new N(e))}static fromMilliseconds(e){return e instanceof N?e:e instanceof Tn?e.period:e instanceof _?new N(e):(le(e)&&(e=e.value),["number","bigint"].includes(typeof e)?N.milliseconds(e):new N(e))}valueOf(){return this.value}lessThan(e){return this.valueOf()<new N(e).valueOf()}greaterThan(e){return this.valueOf()>new N(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new N(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new N(e).valueOf()}remainder(e){return Ia(this,e)}truncate(e){return new N(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(e="full"){if(e==="semantic")return this.toSemanticString();const r=this.truncate(N.DAY),n=this.truncate(N.HOUR),s=this.truncate(N.MINUTE),a=this.truncate(N.SECOND),o=this.truncate(N.MILLISECOND),c=this.truncate(N.MICROSECOND),l=this.truncate(N.NANOSECOND),u=r,h=n.sub(r),d=s.sub(n),f=a.sub(s),v=o.sub(a),S=c.sub(o),Z=l.sub(c);let b="";return u.isZero||(b+=`${u.days}d `),h.isZero||(b+=`${h.hours}h `),d.isZero||(b+=`${d.minutes}m `),f.isZero||(b+=`${f.seconds}s `),v.isZero||(b+=`${v.milliseconds}ms `),S.isZero||(b+=`${S.microseconds}µs `),Z.isZero||(b+=`${Z.nanoseconds}ns`),b.trim()}toSemanticString(){const e=this.valueOf()<0n?-this.valueOf():this.valueOf(),r=new N(e),n=this.valueOf()<0n;if(r.valueOf()===0n)return"0s";if(r.lessThan(N.SECOND))return"< 1s";const s=r.days,a=r.hours,o=r.minutes,c=r.seconds,l=Math.floor(s/pi),u=Math.floor(s/br),h=Math.floor(s/7),d=Math.floor(s),f=Math.floor(a),v=Math.floor(o),S=Math.floor(c),Z=n?"-":"";if(l>=1){let b=`${l}y`;if(l<2){const z=Math.floor(s%pi/br);z>0&&(b+=` ${z}mo`)}return Z+b}if(h>=1&&s<br&&s%7===0){let b=`${h}w`;const z=Math.floor(s%7),A=Math.floor(a-h*7*24);return h<2&&(z>0?b+=` ${z}d`:A>0&&A<24&&(b+=` ${A}h`)),Z+b}if(u>=1){let b=`${u}mo`;if(u<3){const z=Math.floor(s%br);z>0&&(b+=` ${z}d`)}return Z+b}if(h>=1){let b=`${h}w`;const z=Math.floor(s%7),A=Math.floor(a-h*7*24);return h<2&&(z>0?b+=` ${z}d`:A>0&&A<24&&(b+=` ${A}h`)),Z+b}if(d>=1){let b=`${d}d`;const z=Math.floor(a-d*24);return d<2&&z>0&&(b+=` ${z}h`),Z+b}if(f>=1){let b=`${f}h`;if(f<3){const z=Math.floor(o-f*60);z>0&&(b+=` ${z}m`)}return Z+b}if(v>=1){let b=`${v}m`;if(v<5){const z=Math.floor(c-v*60);z>0&&(b+=` ${z}s`)}return Z+b}return`${Z}${S}s`}mult(e){return new N($e(this.valueOf(),e))}div(e){return new N(Wr(this.valueOf(),e))}get days(){return Number(this.valueOf())/Number(N.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(N.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(N.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(N.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(N.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(N.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new N(e).valueOf()}add(e){return new N(this.valueOf()+new N(e).valueOf())}sub(e){return new N(this.valueOf()-new N(e).valueOf())}static nanoseconds(e=1){return new N(e)}static NANOSECOND=N.nanoseconds(1);static microseconds(e=1){return N.nanoseconds($e(e,1e3))}static MICROSECOND=N.microseconds(1);static milliseconds(e=1){return N.microseconds($e(e,1e3))}static MILLISECOND=N.milliseconds(1);static seconds(e=1){return N.milliseconds($e(e,1e3))}static SECOND=N.seconds(1);static minutes(e=1){return N.seconds($e(e,60))}static MINUTE=N.minutes(1);static hours(e){return N.minutes($e(e,60))}static HOUR=N.hours(1);static days(e){return N.hours($e(e,24))}static DAY=N.days(1);static MAX=new N(Pn);static MIN=new N(0);static ZERO=new N(0);static z=i.z.union([i.z.object({value:i.z.bigint()}).transform(e=>new N(e.value)),i.z.string().transform(e=>new N(BigInt(e))),i.z.number().transform(e=>new N(e)),i.z.bigint().transform(e=>new N(e)),i.z.instanceof(N),i.z.instanceof(_).transform(e=>new N(e)),i.z.custom(e=>e instanceof Tn).transform(e=>new N(e))])},Tn=class ue extends Nt{constructor(e){le(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new ue(e).valueOf()}get period(){return C.seconds(1/this.valueOf())}sampleCount(e){return new C(e).seconds*this.valueOf()}byteCount(e,r){return this.sampleCount(e)*new re(r).valueOf()}span(e){return C.seconds(e/this.valueOf())}byteSpan(e,r){return this.span(e.valueOf()/new re(r).valueOf())}add(e){return new ue(Hr(this.valueOf(),new ue(e).valueOf()))}sub(e){return new ue(Yr(this.valueOf(),new ue(e).valueOf()))}mult(e){return new ue($e(this.valueOf(),e))}div(e){return new ue(Wr(this.valueOf(),e))}static hz(e){return new ue(e)}static khz(e){return ue.hz(e*1e3)}static z=i.z.union([i.z.number().transform(e=>new ue(e)),i.z.instanceof(ue)])},re=class se extends Nt{constructor(e){le(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new Un(e*this.valueOf())}add(e){return new se(Hr(this.valueOf(),new se(e).valueOf()))}sub(e){return new se(Yr(this.valueOf(),new se(e).valueOf()))}mult(e){return new se($e(this.valueOf(),e))}div(e){return new se(Wr(this.valueOf(),e))}static UNKNOWN=new se(0);static BIT128=new se(16);static BIT64=new se(8);static BIT32=new se(4);static BIT16=new se(2);static BIT8=new se(1);static z=i.z.union([i.z.number().transform(e=>new se(e)),i.z.instanceof(se)])},_t=class Ee{start;end;constructor(e,r){typeof e=="object"&&"start"in e?(this.start=new _(e.start),this.end=new _(e.end)):(this.start=new _(e),this.end=new _(r))}get span(){return new C(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.start.isZero&&this.end.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new Ee(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,r=C.ZERO){if(r.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let n=this.start.sub(e.start).valueOf(),s=this.end.sub(e.end).valueOf();return n<0&&(n=-n),s<0&&(s=-s),n<=r.valueOf()&&s<=r.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.toString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,r=C.ZERO){e=e.makeValid();const n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;const s=_.max(n.start,e.start),a=_.min(n.end,e.end);return a.before(s)?!1:new C(a.sub(s)).greaterThanOrEqual(r)}contains(e){return e instanceof Ee?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const r=new Ee(this.start,this.end);return e.start.after(this.start)&&(r.start=e.start),e.start.after(this.end)&&(r.end=e.start),e.end.before(this.end)&&(r.end=e.end),e.end.before(this.start)&&(r.start=e.end),r}static max(...e){return new Ee(_.min(...e.map(r=>r.start)),_.max(...e.map(r=>r.end)))}static MAX=new Ee(_.MIN,_.MAX);static ZERO=new Ee(_.ZERO,_.ZERO);static z=i.z.union([i.z.object({start:_.z,end:_.z}).transform(e=>new Ee(e.start,e.end)),i.z.instanceof(Ee)]);static sort(e,r){return _.sort(e.start,r.start)||_.sort(e.end,r.end)}static simplify(e){return e.map(r=>r.makeValid()).sort((r,n)=>Ee.sort(r,n)).reduce((r,n)=>{if(n.span.isZero)return r;if(r.length===0)return r.push(n),r;const s=r[r.length-1];return s.overlapsWith(n)||s.end.equals(n.start)?s.end=_.max(s.end,n.end):r.push(n),r},[])}},B=class m extends Nt{constructor(e){if(le(e)&&(e=e.value),e instanceof m||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const r=m.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(r==null)throw new Error(`unable to find data type for ${e.toString()}`);super(r.valueOf())}}get Array(){const e=m.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(r=>this.equals(r))}toString(e=!1){return e?m.SHORT_STRINGS.get(this.valueOf())??this.valueOf():this.valueOf()}get isVariable(){return this.equals(m.JSON)||this.equals(m.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(m.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=m.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(m.UINT8)||this.equals(m.UINT16)||this.equals(m.UINT32)||this.equals(m.UINT64)}get isSignedInteger(){return this.equals(m.INT8)||this.equals(m.INT16)||this.equals(m.INT32)||this.equals(m.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsignedInteger&&e.isSignedInteger?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(m.INT32)&&e.equals(m.FLOAT64)||this.equals(m.INT8)&&e.equals(m.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsignedInteger===e.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return m.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new m("unknown");static FLOAT64=new m("float64");static FLOAT32=new m("float32");static INT64=new m("int64");static INT32=new m("int32");static INT16=new m("int16");static INT8=new m("int8");static UINT64=new m("uint64");static UINT32=new m("uint32");static UINT16=new m("uint16");static UINT8=new m("uint8");static BOOLEAN=new m("boolean");static TIMESTAMP=new m("timestamp");static UUID=new m("uuid");static STRING=new m("string");static JSON=new m("json");static ARRAY_CONSTRUCTORS=new Map([[m.UINT8.toString(),Uint8Array],[m.UINT16.toString(),Uint16Array],[m.UINT32.toString(),Uint32Array],[m.UINT64.toString(),BigUint64Array],[m.FLOAT32.toString(),Float32Array],[m.FLOAT64.toString(),Float64Array],[m.INT8.toString(),Int8Array],[m.INT16.toString(),Int16Array],[m.INT32.toString(),Int32Array],[m.INT64.toString(),BigInt64Array],[m.TIMESTAMP.toString(),BigInt64Array],[m.STRING.toString(),Uint8Array],[m.JSON.toString(),Uint8Array],[m.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,m.UINT8],[Uint16Array.name,m.UINT16],[Uint32Array.name,m.UINT32],[BigUint64Array.name,m.UINT64],[Float32Array.name,m.FLOAT32],[Float64Array.name,m.FLOAT64],[Int8Array.name,m.INT8],[Int16Array.name,m.INT16],[Int32Array.name,m.INT32],[BigInt64Array.name,m.INT64]]);static DENSITIES=new Map([[m.UINT8.toString(),re.BIT8],[m.UINT16.toString(),re.BIT16],[m.UINT32.toString(),re.BIT32],[m.UINT64.toString(),re.BIT64],[m.FLOAT32.toString(),re.BIT32],[m.FLOAT64.toString(),re.BIT64],[m.INT8.toString(),re.BIT8],[m.INT16.toString(),re.BIT16],[m.INT32.toString(),re.BIT32],[m.INT64.toString(),re.BIT64],[m.TIMESTAMP.toString(),re.BIT64],[m.STRING.toString(),re.UNKNOWN],[m.JSON.toString(),re.UNKNOWN],[m.UUID.toString(),re.BIT128]]);static ALL=[m.UNKNOWN,m.FLOAT64,m.FLOAT32,m.INT64,m.INT32,m.INT16,m.INT8,m.UINT64,m.UINT32,m.UINT16,m.UINT8,m.TIMESTAMP,m.UUID,m.STRING,m.JSON];static SHORT_STRINGS=new Map([[m.UINT8.toString(),"u8"],[m.UINT16.toString(),"u16"],[m.UINT32.toString(),"u32"],[m.UINT64.toString(),"u64"],[m.INT8.toString(),"i8"],[m.INT16.toString(),"i16"],[m.INT32.toString(),"i32"],[m.INT64.toString(),"i64"],[m.FLOAT32.toString(),"f32"],[m.FLOAT64.toString(),"f64"],[m.BOOLEAN.toString(),"bool"],[m.TIMESTAMP.toString(),"ts"],[m.UUID.toString(),"uuid"],[m.STRING.toString(),"str"],[m.JSON.toString(),"json"]]);static BIG_INT_TYPES=[m.INT64,m.UINT64,m.TIMESTAMP];static z=i.z.union([i.z.string().transform(e=>new m(e)),i.z.instanceof(m)])},Un=class k extends Nt{constructor(e){le(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return le(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return le(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return le(e)&&(e=e.value),new k(Hr(this.valueOf(),e.valueOf()))}sub(e){return le(e)&&(e=e.value),new k(Yr(this.valueOf(),e.valueOf()))}mult(e){return new k($e(this.valueOf(),e))}div(e){return new k(Wr(this.valueOf(),e))}truncate(e){return new k(Math.trunc(this.valueOf()/new k(e).valueOf())*new k(e).valueOf())}remainder(e){return k.bytes(this.valueOf()%new k(e).valueOf())}get gigabytes(){return this.valueOf()/k.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/k.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/k.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/k.TERABYTE.valueOf()}toString(){const e=this.truncate(k.TERABYTE),r=this.truncate(k.GIGABYTE),n=this.truncate(k.MEGABYTE),s=this.truncate(k.KILOBYTE),a=this.truncate(k.BYTE),o=e,c=r.sub(e),l=n.sub(r),u=s.sub(n),h=a.sub(s);let d="";return o.isZero||(d+=`${o.terabytes}TB `),c.isZero||(d+=`${c.gigabytes}GB `),l.isZero||(d+=`${l.megabytes}MB `),u.isZero||(d+=`${u.kilobytes}KB `),(!h.isZero||d==="")&&(d+=`${h.valueOf()}B`),d.trim()}static bytes(e=1){return new k(e)}static BYTE=new k(1);static kilobytes(e=1){return k.bytes(new k(e).valueOf()*1e3)}static KILOBYTE=k.kilobytes(1);static megabytes(e=1){return k.kilobytes(new k(e).valueOf()*1e3)}static MEGABYTE=k.megabytes(1);static gigabytes(e=1){return k.megabytes(new k(e).valueOf()*1e3)}static GIGABYTE=k.gigabytes(1);static terabytes(e){return k.gigabytes(new k(e).valueOf()*1e3)}static TERABYTE=k.terabytes(1);static ZERO=new k(0);static z=i.z.union([i.z.number().transform(e=>new k(e)),i.z.instanceof(k)]);get isZero(){return this.valueOf()===0}};i.z.object({start:i.z.number(),end:i.z.number()});i.z.union([i.z.instanceof(Uint8Array),i.z.instanceof(Uint16Array),i.z.instanceof(Uint32Array),i.z.instanceof(BigUint64Array),i.z.instanceof(Float32Array),i.z.instanceof(Float64Array),i.z.instanceof(Int8Array),i.z.instanceof(Int16Array),i.z.instanceof(Int32Array),i.z.instanceof(BigInt64Array)]);const Aa=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof _||t instanceof C||t instanceof Date},Zh=(t,e,r,n=0)=>t.usesBigInt&&!e.usesBigInt?Number(r)-Number(n):!t.usesBigInt&&e.usesBigInt?BigInt(r.valueOf())-BigInt(n.valueOf()):Ir(r,-n),Ir=(t,e)=>e==0?t:t==0?e:typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number"?t+e:Number(t)+Number(e),Ch=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function Rh(t){return typeof t=="string"&&Ch.test(t)}const J=[];for(let t=0;t<256;++t)J.push((t+256).toString(16).slice(1));function _h(t,e=0){return(J[t[e+0]]+J[t[e+1]]+J[t[e+2]]+J[t[e+3]]+"-"+J[t[e+4]]+J[t[e+5]]+"-"+J[t[e+6]]+J[t[e+7]]+"-"+J[t[e+8]]+J[t[e+9]]+"-"+J[t[e+10]]+J[t[e+11]]+J[t[e+12]]+J[t[e+13]]+J[t[e+14]]+J[t[e+15]]).toLowerCase()}function jh(t,e=0){const r=_h(t,e);if(!Rh(r))throw TypeError("Stringified UUID is invalid");return r}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const ka=(t,e)=>jh(t,e),_e=-1,Mh=i.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer),Dh=i.z.union([i.z.null(),i.z.undefined()]).transform(()=>new Uint8Array().buffer),Ln=10,Ph=(t,e)=>{if(t==="number"&&!e.isNumeric)throw new Error(`cannot convert series of type ${e.toString()} to number`);if(t==="bigint"&&!e.usesBigInt)throw new Error(`cannot convert series of type ${e.toString()} to bigint`)},xa="sy_x_telem_series";let Za=class Pe{key;discriminator=xa;dataType;sampleOffset;gl;_data;timeRange=_t.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=_e;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=i.z.object({timeRange:_t.z.optional(),dataType:B.z,alignment:i.z.coerce.bigint().optional(),data:i.z.union([Mh,Dh,i.z.instanceof(ArrayBuffer),i.z.instanceof(Uint8Array)]),glBufferUsage:Ah.optional().default("static").optional()});static z=Pe.crudeZ.transform(e=>new Pe(e));constructor(e){Uh(e)&&(e={data:e}),e.data??=[];const{dataType:r,timeRange:n,sampleOffset:s=0,glBufferUsage:a="static",alignment:o=0n,alignmentMultiple:c=1n,key:l=Sh(),data:u}=e;if(Lh(u)){const f=u;this.key=f.key,this.dataType=f.dataType,this.sampleOffset=f.sampleOffset,this.gl=f.gl,this._data=f._data,this.timeRange=f.timeRange,this.alignment=f.alignment,this.alignmentMultiple=f.alignmentMultiple,this.cachedMin=f.cachedMin,this.cachedMax=f.cachedMax,this.writePos=f.writePos,this._refCount=f._refCount,this.cachedLength=f.cachedLength;return}const h=Aa(u),d=Array.isArray(u);if(r!=null)this.dataType=new B(r);else{if(u instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(d||h){let f=u;if(!h){if(u.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");f=u[0]}if(typeof f=="string")this.dataType=B.STRING;else if(typeof f=="number")this.dataType=B.FLOAT64;else if(typeof f=="bigint")this.dataType=B.INT64;else if(typeof f=="boolean")this.dataType=B.BOOLEAN;else if(f instanceof _||f instanceof Date||f instanceof _)this.dataType=B.TIMESTAMP;else if(typeof f=="object")this.dataType=B.JSON;else throw new Error(`cannot infer data type of ${typeof f} when constructing a Series from a JS array`)}else this.dataType=new B(u)}if(!d&&!h)this._data=u;else if(d&&u.length===0)this._data=new this.dataType.Array([]).buffer;else{let f=h?[u]:u;const v=f[0];(v instanceof _||v instanceof Date||v instanceof C)&&(f=f.map(S=>new _(S).valueOf())),this.dataType.equals(B.STRING)?(this.cachedLength=f.length,this._data=new TextEncoder().encode(`${f.join(`
2
2
  `)}
3
3
  `).buffer):this.dataType.equals(B.JSON)?(this.cachedLength=f.length,this._data=new TextEncoder().encode(`${f.map(S=>Dn.encodeString(S)).join(`
4
4
  `)}
5
- `).buffer):this.dataType.usesBigInt&&typeof v=="number"?this._data=new this.dataType.Array(f.map(S=>BigInt(Math.round(S)))).buffer:!this.dataType.usesBigInt&&typeof v=="bigint"?this._data=new this.dataType.Array(f.map(Number)).buffer:this._data=new this.dataType.Array(f).buffer}this.key=l,this.alignment=o,this.alignmentMultiple=c,this.sampleOffset=s??0,this.timeRange=n??Rt.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:r,...n}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const s=new new B(r).Array(e),a=new De({data:s.buffer,dataType:r,...n});return a.writePos=0,a}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn("cannot release a series with a negative reference count")}write(e){if(!e.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===Re)return 0;const r=this.byteCapacity.valueOf()-this.writePos,n=e.subBytes(0,r);return this.writeToUnderlyingData(n),this.writePos+=n.byteLength.valueOf(),this.cachedLength!=null&&(this.cachedLength+=n.length,this.calculateCachedLength()),n.length}writeFixed(e){if(this.writePos===Re)return 0;const r=this.capacity-this.writePos,n=e.sub(0,r);return this.writeToUnderlyingData(n),this.cachedLength=void 0,this.maybeRecomputeMinMax(n),this.writePos+=n.length,n.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data=="object"&&"buffer"in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===Re?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){return this.dataType.isVariable?new TextDecoder().decode(this.underlyingData).split(`
6
- `).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(B.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(r=>e.parse(Dn.decodeString(r)))}get byteCapacity(){return new Un(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Re?this.byteCapacity:this.dataType.isVariable?new Un(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Re?this.byteCapacity.valueOf()/this.dataType.density.valueOf():this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const r=[0];return this.data.forEach((n,s)=>{n===Ln&&(e++,r.push(s+1))}),this._cachedIndexes=r,this.cachedLength=e,e}convert(e,r=0){if(this.dataType.equals(e))return this;const n=new e.Array(this.length);for(let s=0;s<this.length;s++)n[s]=Oh(this.dataType,e,this.data[s],r);return new De({data:n.buffer,dataType:e,timeRange:this.timeRange,sampleOffset:r,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(B.TIMESTAMP))this.cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMax=e.reduce((r,n)=>r>n?r:n)}else{const e=this.data;this.cachedMax=e.reduce((r,n)=>r>n?r:n)}return this.cachedMax}get max(){return this.calcMax()}calcMax(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this.cachedMax??=this.calcRawMax(),$r(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(B.TIMESTAMP))this.cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMin=e.reduce((r,n)=>r<n?r:n)}else{const e=this.data;this.cachedMin=e.reduce((r,n)=>r<n?r:n)}return this.cachedMin}get min(){return this.calcMin()}calcMin(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this.cachedMin??=this.calcRawMin(),$r(this.cachedMin,this.sampleOffset))}get bounds(){return Qe(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){const r=e.cachedMin??e.calcRawMin();r<this.cachedMin&&(this.cachedMin=r)}if(this.cachedMax!=null){const r=e.cachedMax??e.calcRawMax();r>this.cachedMax&&(this.cachedMax=r)}}atAlignment(e,r){const n=Number((e-this.alignment)/this.alignmentMultiple);if(n<0||n>=this.length){if(r===!0)throw new Error(`[series] - no value at index ${n}`);return}return this.at(n,r)}at(e,r=!1){if(this.dataType.isVariable)return this.atVariable(e,r??!1);if(this.dataType.equals(B.UUID))return this.atUUID(e,r);e<0&&(e=this.length+e);const n=this.data[e];if(n==null){if(r===!0)throw new Error(`[series] - no value at index ${e}`);return}return $r(n,this.sampleOffset)}atUUID(e,r){e<0&&(e=this.length+e);const n=ka(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(n==null){if(r)throw new Error(`[series] - no value at index ${e}`);return}return n}atVariable(e,r){let n=0,s=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],s=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let o=0;o<this.data.length;o++)if(this.data[o]===Ln){if(e===0){s=o;break}n=o+1,e--}if(s===0&&(s=this.data.length),n>=s||e>0){if(r)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(n,s);return this.dataType.equals(B.STRING)?new TextDecoder().decode(a):ga(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let r=0,n=this.length-1;const s=Ll(e);for(;r<=n;){const a=Math.floor((r+n)/2),o=s(this.at(a,!0),e);if(o===0)return a;o<0?r=a+1:n=a-1}return r}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(B.FLOAT32)&&!this.dataType.equals(B.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:r,bufferUsage:n,prevBuffer:s}=this.gl;if(r==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==s)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==Re){s===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(s).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Re}as(e){return Zh(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:yi(this.alignmentBounds.lower),upper:yi(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return Qe(this.alignment,this.alignment+BigInt(this.length)*this.alignmentMultiple)}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new _h(this);return this.dataType.equals(B.JSON)?new jh(e):e}return this.dataType.equals(B.UUID)?new Mh(this):new Dh(this)}slice(e,r){return this.sliceSub(!1,e,r)}sub(e,r){return this.sliceSub(!0,e,r)}subIterator(e,r){return new pi(this,e,r??this.length)}subAlignmentIterator(e,r){const n=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),s=Math.ceil(Number(r-this.alignment)/Number(this.alignmentMultiple));return new pi(this,n,s)}subBytes(e,r){if(e>=0&&(r==null||r>=this.byteLength.valueOf()))return this;const n=this.data.subarray(e,r);return new De({data:n,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,r,n){if(r<=0&&(n==null||n>=this.length))return this;let s;return e?s=this.data.subarray(r,n):s=this.data.slice(r,n),new De({data:s,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(r)})}reAlign(e){return new De({data:this.buffer,dataType:this.dataType,timeRange:Rt.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}toString(){let e=`Series(${this.dataType.toString()} ${this.length} [`;if(this.length<=10)e+=Array.from(this).map(r=>r.toString());else{for(let r=0;r<5;r++)e+=`${this.at(r)?.toString()}`,e+=",";e+="...,";for(let r=-5;r<0;r++)e+=this.at(r)?.toString(),r<-1&&(e+=",")}return e+="])",e}};const Ch=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof xa?!0:Ia(t),Rh=Th(Aa,xa);class pi{series;end;index;constructor(e,r,n){this.series=e;const s=Qe(0,e.length+1);this.end=ui(s,n),this.index=ui(s,r)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}}class _h{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=e,this.index=0,this.decoder=new TextDecoder}next(){const e=this.index,r=this.series.data;for(;this.index<r.length&&r[this.index]!==Ln;)this.index++;const n=this.index;return e===n?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,n))})}}let jh=class Za{wrapped;static schema=i.z.record(i.z.string(),i.z.unknown());constructor(e){this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:Dn.decodeString(e.value,Za.schema)}}};class Mh{series;index;data;density;constructor(e){if(!e.dataType.equals(B.UUID))throw new Error("cannot create a UUID series iterator for a non-UUID series");this.series=e,this.index=0,this.data=new Uint8Array(e.buffer),this.density=B.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=ka(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}let Dh=class{series;index;constructor(t){this.series=t,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}};const yi=t=>{const e=t>>32n,r=t&0xffffffffn;return{domain:e,sample:r}};i.z.object({key:i.z.string(),value:i.z.string()});i.z.record(i.z.union([i.z.number(),i.z.string(),i.z.symbol()]),i.z.unknown());const Ph=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";Ph();const Uh=["macOS","Windows","Linux"],Lh=["macos","windows","linux"],Bh={macos:"macOS",windows:"Windows",linux:"Linux"};i.z.enum(Uh).or(i.z.enum(Lh).transform(t=>Bh[t]));const qh=(...t)=>t.map(Ca).join(""),Ca=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),Fh=t=>t.endsWith("/")?t.slice(0,-1):t,Vh=(t,e="")=>t===null?"":`?${Object.entries(t).filter(([,r])=>r==null?!1:Array.isArray(r)?r.length>0:!0).map(([r,n])=>`${e}${r}=${n}`).join("&")}`;let Yh=class Sr{protocol;host;port;path;constructor({host:e,port:r,protocol:n="",pathPrefix:s=""}){this.protocol=n,this.host=e,this.port=r,this.path=Ca(s)}replace(e){return new Sr({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Sr({...this,pathPrefix:qh(this.path,e)})}toString(){return Fh(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new Sr({host:"unknown",port:0})};const Wh=async t=>await new Promise(e=>setTimeout(e,C.fromMilliseconds(t).milliseconds));class Hh{config;retries;interval;constructor(e){this.config={baseInterval:new C(e?.baseInterval??C.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??Wh},this.retries=0,this.interval=new C(this.config.baseInterval)}async wait(){const{maxRetries:e,scale:r,sleepFn:n}=this.config;return this.retries>=e?!1:(await n(this.interval),this.interval=this.interval.mult(r),this.retries++,!0)}get retryMessage(){return`breaker triggered ${this.retries+1}/${this.config.maxRetries} times, retrying in ${this.interval.toString()}`}reset(){this.retries=0,this.interval=this.config.baseInterval}}const Gh=i.z.object({baseInterval:C.z.optional(),maxRetries:i.z.number().optional(),scale:i.z.number().optional()}),Jh=Object.freeze(Object.defineProperty({__proto__:null,Breaker:Hh,breakerConfigZ:Gh},Symbol.toStringTag,{value:"Module"})),Kh=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,Ra=i.z.string().regex(Kh),yt=i.z.number().min(0).max(255),_a=i.z.number().min(0).max(1),ja=i.z.tuple([yt,yt,yt,_a]),Xh=i.z.tuple([yt,yt,yt]),Qh=i.z.object({rgba255:ja}),ef=i.z.number().min(0).max(360),tf=i.z.number().min(0).max(100),rf=i.z.number().min(0).max(100),nf=i.z.tuple([ef,tf,rf,_a]),gs=i.z.union([Ra,Xh,ja,nf,Qh]),sf=gs.transform(t=>ws(t)),ws=(t,e=1)=>{if(t=gs.parse(t),typeof t=="string")return af(t,e);if(Array.isArray(t)){if(t.length<3||t.length>4)throw new Error(`Invalid color: [${t.join(", ")}]`);return t.length===3?[...t,e]:t}return t.rgba255},af=(t,e=1)=>(t=Ra.parse(t),t=of(t),[wr(t,0),wr(t,2),wr(t,4),t.length===8?wr(t,6)/255:e]),wr=(t,e)=>parseInt(t.slice(e,e+2),16),of=t=>t.startsWith("#")?t.slice(1):t;ws("#000000");ws("#ffffff");const cf=i.z.object({key:i.z.string(),color:gs,position:i.z.number(),switched:i.z.boolean().optional()});i.z.array(cf);const uf=i.z.object({key:i.z.string(),name:i.z.string(),color:sf});i.z.object({key:i.z.string(),name:i.z.string(),swatches:i.z.array(uf)});i.z.int().min(0).max(255);i.z.object({name:i.z.string(),key:i.z.string()});const lf=t=>Object.getOwnPropertySymbols(globalThis).includes(t),hf=(t,e)=>{const r=Symbol.for(t);if(!lf(r)){const n=e();Object.defineProperty(globalThis,r,{value:n})}return()=>globalThis[r]},Ma="sy_x_error",ff=t=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.startsWith(t):e instanceof Error?e.message.startsWith(t):typeof e!="string"?!1:e.startsWith(t),rr=t=>class _t extends Error{static discriminator=Ma;discriminator=_t.discriminator;static TYPE=t;type=_t.TYPE;static matches=ff(t);matches=_t.matches;constructor(r,n){super(r,n),this.name=_t.TYPE}static sub(r){return rr(`${t}.${r}`)}},Da=t=>{if(t==null||typeof t!="object")return!1;const e=t;if(e.discriminator!==Ma)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},lt="unknown",Bn="nil";class df{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Bn,data:""};if(Da(e))for(const r of this.providers){const n=r.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:lt,data:e.message};if(typeof e=="string")return{type:lt,data:e};try{return{type:lt,data:JSON.stringify(e)}}catch{return{type:lt,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===Bn)return null;if(e.type===lt)return new qn(e.data);for(const r of this.providers){const n=r.decode(e);if(n!=null)return n}return new qn(e.data)}}const bs=hf("synnax-error-registry",()=>new df),pf=({encode:t,decode:e})=>bs().register({encode:t,decode:e}),yf=t=>bs().encode(t),mf=t=>t==null?null:bs().decode(t);let qn=class extends rr("unknown"){};const gf=i.z.object({type:i.z.string(),data:i.z.string()});class wf extends rr("canceled"){}class bf extends rr("not_implemented"){}const Le=Object.freeze(Object.defineProperty({__proto__:null,Canceled:wf,NONE:Bn,NotImplemented:bf,UNKNOWN:lt,Unknown:qn,createTyped:rr,decode:mf,encode:yf,isTyped:Da,payloadZ:gf,register:pf},Symbol.toStringTag,{value:"Module"})),vf=i.object({jsonrpc:i.literal("2.0"),method:i.string(),params:i.any().optional(),id:i.union([i.string(),i.number(),i.null()]).optional()}),Pa=i.object({jsonrpc:i.literal("2.0"),id:i.union([i.string(),i.number(),i.null()])}),Tf=Pa.extend({result:i.json()}),zf=Pa.extend({error:i.object({code:i.number().int(),message:i.string().optional(),data:i.json().optional()})}),Ef=i.union([Tf,zf]);i.union([vf,Ef]);const Nf=i.uuid();i.object({key:Nf,name:i.string().min(1),color:i.string()});i.z.string().regex(/^\d+\.\d+\.\d+$/);const Of=["standard","scientific","engineering"];i.z.enum(Of);i.z.enum(["success","info","warning","error","loading","disabled"]);i.z.object({stack:i.z.string(),error:i.z.instanceof(Error)});let nr=class extends Le.createTyped("freighter"){},we=class extends nr.sub("eof"){constructor(){super("EOF")}},bt=class extends nr.sub("stream_closed"){constructor(){super("StreamClosed")}},Be=class extends nr.sub("unreachable"){url;constructor(e={}){const{message:r="Unreachable",url:n=Yh.UNKNOWN}=e;super(r),this.url=n}};const $f=t=>{if(!t.type.startsWith(nr.TYPE))return null;if(we.matches(t))return{type:we.TYPE,data:"EOF"};if(bt.matches(t))return{type:bt.TYPE,data:"StreamClosed"};if(Be.matches(t))return{type:Be.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${t.type}: ${t.message}`)},Sf=t=>{if(!t.type.startsWith(nr.TYPE))return null;switch(t.type){case we.TYPE:return new we;case bt.TYPE:return new bt;case Be.TYPE:return new Be;default:throw new Le.Unknown(`Unknown error type: ${t.data}`)}};Le.register({encode:$f,decode:Sf});let Ua=class{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,r){let n=0;const s=async a=>{if(n===this.middleware.length)return await r(a);const o=this.middleware[n];return n++,await o(a,s)};return await s(e)}};const La="Content-Type",If=new Set(["ECONNREFUSED","ECONNRESET","ETIMEDOUT","EPIPE","UND_ERR_CONNECT_TIMEOUT","UND_ERR_SOCKET"]),kf=t=>{const e=t?.cause?.code??t?.code??t?.errno;if(typeof e=="string"&&If.has(e))return!0;if(t.name==="TypeError"){const r=String(t.message||"").toLowerCase();if(/load failed|failed to fetch|networkerror|network error/.test(r))return!0}return t?.name==="AbortError"||t?.code,!1},Af=400;let xf=class extends Ua{endpoint;encoder;constructor(e,r,n=!1){return super(),this.endpoint=e.replace({protocol:n?"https":"http"}),this.encoder=r,new Proxy(this,{get:(s,a,o)=>a==="endpoint"?this.endpoint:Reflect.get(s,a,o)})}get headers(){return{[La]:this.encoder.contentType}}async send(e,r,n,s){r=n?.parse(r);let a=null;const o=this.endpoint.child(e),c={};c.method="POST",c.body=this.encoder.encode(r??{});const[,l]=await this.executeMiddleware({target:o.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async u=>{const h={...u,params:{}};c.headers={...this.headers,...u.params};let d;try{d=await fetch(u.target,c)}catch(v){if(!(v instanceof Error))throw v;return[h,kf(v)?new Be({url:o}):v]}const f=await d.arrayBuffer();if(d?.ok)return s!=null&&(a=this.encoder.decode(f,s)),[h,null];try{if(d.status!==Af)return[h,new Error(d.statusText)];const v=this.encoder.decode(f,Le.payloadZ),S=Le.decode(v);return[h,S]}catch(v){return[h,new Error(`[freighter] - failed to decode error: ${d.statusText}: ${v.message}`)]}});if(l!=null)return[null,l];if(a==null)throw new Error("Response must be defined");return[a,null]}};const Zf=(t,e)=>{class r{wrapped;constructor(s){this.wrapped=s}use(...s){this.wrapped.use(...s)}async send(s,a,o,c){const l=new Jh.Breaker(e);do{const[u,h]=await this.wrapped.send(s,a,o,c);if(h==null)return[u,null];if(!Be.matches(h))return[null,h];if(console.warn(`[freighter] ${l.retryMessage}`,h),!await l.wait())return[u,h]}while(!0)}}return new r(t)},w=async(t,e,r,n,s)=>{const[a,o]=await t.send(e,r,n,s);if(o!=null)throw o;return a},Cf=i.z.object({type:i.z.enum(["data","close","open"]),payload:i.z.unknown(),error:i.z.optional(Le.payloadZ)});class Rf{codec;reqSchema;resSchema;ws;serverClosed;sendClosed;receiveDataQueue=[];receiveCallbacksQueue=[];constructor(e,r,n,s){this.codec=r,this.reqSchema=n,this.resSchema=s,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}async receiveOpenAck(){const e=await this.receiveMsg();if(e.type!=="open"){if(e.error==null)throw new Error("Message error must be defined");return Le.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new we;if(this.sendClosed)throw new bt;return this.ws.send(this.codec.encode({type:"data",payload:e})),null}async receive(){if(this.serverClosed!=null)return[null,this.serverClosed];const e=await this.receiveMsg();if(e.type==="close"){if(e.error==null)throw new Error("Message error must be defined");if(this.serverClosed=Le.decode(e.error),this.serverClosed==null)throw new Error("Message error must be defined");return[null,this.serverClosed]}return[this.resSchema.parse(e.payload),null]}received(){return this.receiveDataQueue.length!==0}closeSend(){if(this.sendClosed||this.serverClosed!=null)return;const e={type:"close"};try{this.ws.send(this.codec.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){return this.receiveDataQueue.shift()??await new Promise((r,n)=>this.receiveCallbacksQueue.push({resolve:r,reject:n}))}addMessage(e){const r=this.receiveCallbacksQueue.shift();r!=null?r.resolve(e):this.receiveDataQueue.push(e)}listenForMessages(){this.ws.onmessage=this.onMessage.bind(this),this.ws.onclose=this.onClose.bind(this)}onMessage(e){this.addMessage(this.codec.decode(e.data,Cf))}onClose(e){this.addMessage({type:"close",error:{type:e.code===jf?we.TYPE:bt.TYPE,data:""}})}}const _f="freighterctx",jf=1e3;class Cr extends Ua{baseUrl;encoder;secure;static MESSAGE_TYPE="arraybuffer";constructor(e,r,n=!1){super(),this.secure=n,this.baseUrl=e.replace({protocol:n?"wss":"ws"}),this.encoder=r}withCodec(e){const r=new Cr(this.baseUrl,e,this.secure);return r.use(...this.middleware),r}async stream(e,r,n){let s;const[,a]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async o=>{const c=new WebSocket(this.buildURL(e,o)),l={...o,params:{}};c.binaryType=Cr.MESSAGE_TYPE;const u=await this.wrapSocket(c,r,n);return u instanceof Error?[l,u]:(s=u,[l,null])});if(a!=null)throw a;return s}buildURL(e,r){const n=Vh({[La]:this.encoder.contentType,...r.params},_f);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,r,n){return await new Promise(s=>{e.onopen=()=>{const a=new Rf(e,this.encoder,r,n);a.receiveOpenAck().then(o=>{o!=null?s(o):s(a)}).catch(o=>s(o))},e.onerror=a=>{const o=a;s(new Error(o.message))}})}}const Ba=t=>i.union([i.union([i.null(),i.undefined()]).transform(()=>[]),t.array()]),Mf=t=>Array.isArray(t)?t:t==null?[]:[t],qa=(t,e)=>{if(Array.isArray(e))return e.reduce((s,a)=>qa(s,a),t??[]);if(t==null)return[e];const r=t.findIndex(s=>s==e),n=[...t];return r===-1?n.push(e):n[r]=e,n},Df=((t,e)=>{if(t!=null)return Array.isArray(e)?t.filter(r=>!e.includes(r)):t.filter(r=>r!=e)}),Fa=(t,e)=>{if(Array.isArray(e))return e.reduce((s,a)=>Fa(s,a),t??[]);if(t==null)return[e];const r=t.findIndex(s=>s.key===e.key),n=[...t];return r===-1?n.push(e):n[r]=e,n},Pf=((t,e)=>{if(t!=null)return Array.isArray(e)?t.filter(r=>!e.includes(r.key)):t.filter(r=>r.key!==e)}),T=Object.freeze(Object.defineProperty({__proto__:null,nullableZ:Ba,remove:Df,removeKeyed:Pf,toArray:Mf,upsert:qa,upsertKeyed:Fa},Symbol.toStringTag,{value:"Module"})),Uf=t=>{const e=t.replace(/_[a-z]/g,r=>r[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},Wr=t=>{const e=(r,n=Fn)=>{if(typeof r=="string")return t(r);if(Array.isArray(r))return r.map(o=>e(o,n));if(!zn(r))return r;n=qf(n);const s={},a=r;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),n):(Object.keys(a).forEach(o=>{let c=a[o];const l=t(o);n.recursive&&(zn(c)?gi(c)||(c=e(c,n)):n.recursiveInArray&&mi(c)&&(c=[...c].map(u=>{let h=u;return zn(u)?gi(h)||(h=e(u,n)):mi(u)&&(h=e({key:u},n).key),h}))),s[l]=c}),s)};return e},vs=Wr(Uf),Lf=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,r,n)=>`${r}_${n.toLowerCase()}`),Va=Wr(Lf),Ya=t=>t.length===0?t:t[0].toUpperCase()+t.slice(1),Bf=[Number,String,Uint8Array],Fn={recursive:!0,recursiveInArray:!0},qf=(t=Fn)=>(t.recursive==null?t=Fn:t.recursiveInArray??=!1,t),mi=t=>t!=null&&Array.isArray(t),zn=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),gi=t=>Bf.some(e=>t instanceof e),Ff=t=>t.replace(/[\s_]+/g,"-").replace(/([a-z0-9])([A-Z])/g,(e,r,n)=>`${r}-${n.toLowerCase()}`).toLowerCase(),Vf=Wr(Ff),Yf=t=>{if(t.length===0)return t;let e=t.replace(/[_-]/g," ");return e=e.replace(/([a-z0-9])([A-Z])/g,(r,n,s)=>`${n} ${s}`),e=e.replace(/([A-Z]+)([A-Z][a-z])/g,(r,n,s)=>`${n} ${s}`),e=e.replace(/\s+/g," ").trim(),e=e.replace(/\b\w/g,r=>r.toUpperCase()),e},Wf=Wr(Yf),Hf=Object.freeze(Object.defineProperty({__proto__:null,camelToSnake:Va,capitalize:Ya,snakeToCamel:vs,toKebab:Vf,toProperNoun:Wf},Symbol.toStringTag,{value:"Module"})),Wa=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);let Ha=class{contentType="application/json";decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e))}decode(e,r){return this.decodeString(this.decoder.decode(e),r)}decodeString(e,r){const n=JSON.parse(e),s=vs(n);return r!=null?r.parse(s):s}encodeString(e){const r=Va(e);return JSON.stringify(r,(n,s)=>ArrayBuffer.isView(s)?Array.from(s):typeof s=="bigint"?s.toString():s)}},Ga=class{contentType="text/csv";encode(e){const r=this.encodeString(e);return new TextEncoder().encode(r)}decode(e,r){const n=new TextDecoder().decode(e);return this.decodeString(n,r)}encodeString(e){if(!Array.isArray(e)||e.length===0||!Wa(e[0]))throw new Error("Payload must be an array of objects");const r=Object.keys(e[0]),n=[r.join(",")];return e.forEach(s=>{const a=r.map(o=>JSON.stringify(s[o]??""));n.push(a.join(","))}),n.join(`
5
+ `).buffer):this.dataType.usesBigInt&&typeof v=="number"?this._data=new this.dataType.Array(f.map(S=>BigInt(Math.round(S)))).buffer:!this.dataType.usesBigInt&&typeof v=="bigint"?this._data=new this.dataType.Array(f.map(Number)).buffer:this._data=new this.dataType.Array(f).buffer}this.key=l,this.alignment=o,this.alignmentMultiple=c,this.sampleOffset=s??0,this.timeRange=n??_t.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:r,...n}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const s=new new B(r).Array(e),a=new Pe({data:s.buffer,dataType:r,...n});return a.writePos=0,a}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn("cannot release a series with a negative reference count")}write(e){if(!e.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===_e)return 0;const r=this.byteCapacity.valueOf()-this.writePos,n=e.subBytes(0,r);return this.writeToUnderlyingData(n),this.writePos+=n.byteLength.valueOf(),this.cachedLength!=null&&(this.cachedLength+=n.length,this.calculateCachedLength()),n.length}writeFixed(e){if(this.writePos===_e)return 0;const r=this.capacity-this.writePos,n=e.sub(0,r);return this.writeToUnderlyingData(n),this.cachedLength=void 0,this.maybeRecomputeMinMax(n),this.writePos+=n.length,n.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data=="object"&&"buffer"in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===_e?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){return this.dataType.isVariable?new TextDecoder().decode(this.underlyingData).split(`
6
+ `).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(B.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(r=>e.parse(Dn.decodeString(r)))}get byteCapacity(){return new Un(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===_e?this.byteCapacity:this.dataType.isVariable?new Un(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===_e?this.byteCapacity.valueOf()/this.dataType.density.valueOf():this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const r=[0];return this.data.forEach((n,s)=>{n===Ln&&(e++,r.push(s+1))}),this._cachedIndexes=r,this.cachedLength=e,e}convert(e,r=0){if(this.dataType.equals(e))return this;const n=new e.Array(this.length);for(let s=0;s<this.length;s++)n[s]=Zh(this.dataType,e,this.data[s],r);return new Pe({data:n.buffer,dataType:e,timeRange:this.timeRange,sampleOffset:r,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(B.TIMESTAMP))this.cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMax=e.reduce((r,n)=>r>n?r:n)}else{const e=this.data;this.cachedMax=e.reduce((r,n)=>r>n?r:n)}return this.cachedMax}get max(){return this.calcMax()}calcMax(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this.cachedMax??=this.calcRawMax(),Ir(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(B.TIMESTAMP))this.cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMin=e.reduce((r,n)=>r<n?r:n)}else{const e=this.data;this.cachedMin=e.reduce((r,n)=>r<n?r:n)}return this.cachedMin}get min(){return this.calcMin()}calcMin(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this.cachedMin??=this.calcRawMin(),Ir(this.cachedMin,this.sampleOffset))}get bounds(){return et(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){const r=e.cachedMin??e.calcRawMin();r<this.cachedMin&&(this.cachedMin=r)}if(this.cachedMax!=null){const r=e.cachedMax??e.calcRawMax();r>this.cachedMax&&(this.cachedMax=r)}}atAlignment(e,r){const n=Number((e-this.alignment)/this.alignmentMultiple);if(n<0||n>=this.length){if(r===!0)throw new Error(`[series] - no value at index ${n}`);return}return this.at(n,r)}at(e,r=!1){if(this.dataType.isVariable)return this.atVariable(e,r??!1);if(this.dataType.equals(B.UUID))return this.atUUID(e,r);e<0&&(e=this.length+e);const n=this.data[e];if(n==null){if(r===!0)throw new Error(`[series] - no value at index ${e}`);return}return Ir(n,this.sampleOffset)}atUUID(e,r){e<0&&(e=this.length+e);const n=ka(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(n==null){if(r)throw new Error(`[series] - no value at index ${e}`);return}return n}atVariable(e,r){let n=0,s=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],s=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let o=0;o<this.data.length;o++)if(this.data[o]===Ln){if(e===0){s=o;break}n=o+1,e--}if(s===0&&(s=this.data.length),n>=s||e>0){if(r)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(n,s);return this.dataType.equals(B.STRING)?new TextDecoder().decode(a):wa(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let r=0,n=this.length-1;const s=Wl(e);for(;r<=n;){const a=Math.floor((r+n)/2),o=s(this.at(a,!0),e);if(o===0)return a;o<0?r=a+1:n=a-1}return r}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(B.FLOAT32)&&!this.dataType.equals(B.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:r,bufferUsage:n,prevBuffer:s}=this.gl;if(r==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==s)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==_e){s===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(s).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=_e}as(e){return Ph(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:mi(this.alignmentBounds.lower),upper:mi(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return et(this.alignment,this.alignment+BigInt(this.length)*this.alignmentMultiple)}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new Bh(this);return this.dataType.equals(B.JSON)?new qh(e):e}return this.dataType.equals(B.UUID)?new Fh(this):new Vh(this)}slice(e,r){return this.sliceSub(!1,e,r)}sub(e,r){return this.sliceSub(!0,e,r)}subIterator(e,r){return new yi(this,e,r??this.length)}subAlignmentIterator(e,r){const n=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),s=Math.ceil(Number(r-this.alignment)/Number(this.alignmentMultiple));return new yi(this,n,s)}subBytes(e,r){if(e>=0&&(r==null||r>=this.byteLength.valueOf()))return this;const n=this.data.subarray(e,r);return new Pe({data:n,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,r,n){if(r<=0&&(n==null||n>=this.length))return this;let s;return e?s=this.data.subarray(r,n):s=this.data.slice(r,n),new Pe({data:s,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(r)})}reAlign(e){return new Pe({data:this.buffer,dataType:this.dataType,timeRange:_t.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}toString(){let e=`Series(${this.dataType.toString()} ${this.length} [`;if(this.length<=10)e+=Array.from(this).map(r=>r.toString());else{for(let r=0;r<5;r++)e+=`${this.at(r)?.toString()}`,e+=",";e+="...,";for(let r=-5;r<0;r++)e+=this.at(r)?.toString(),r<-1&&(e+=",")}return e+="])",e}};const Uh=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Za?!0:Aa(t),Lh=Ih(xa,Za);class yi{series;end;index;constructor(e,r,n){this.series=e;const s=et(0,e.length+1);this.end=li(s,n),this.index=li(s,r)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}}class Bh{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=e,this.index=0,this.decoder=new TextDecoder}next(){const e=this.index,r=this.series.data;for(;this.index<r.length&&r[this.index]!==Ln;)this.index++;const n=this.index;return e===n?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,n))})}}let qh=class Ca{wrapped;static schema=i.z.record(i.z.string(),i.z.unknown());constructor(e){this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:Dn.decodeString(e.value,Ca.schema)}}};class Fh{series;index;data;density;constructor(e){if(!e.dataType.equals(B.UUID))throw new Error("cannot create a UUID series iterator for a non-UUID series");this.series=e,this.index=0,this.data=new Uint8Array(e.buffer),this.density=B.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=ka(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}let Vh=class{series;index;constructor(t){this.series=t,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}};const mi=t=>{const e=t>>32n,r=t&0xffffffffn;return{domain:e,sample:r}};i.z.object({key:i.z.string(),value:i.z.string()});i.z.record(i.z.union([i.z.number(),i.z.string(),i.z.symbol()]),i.z.unknown());const Yh=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";Yh();const Hh=["macOS","Windows","Linux"],Wh=["macos","windows","linux"],Gh={macos:"macOS",windows:"Windows",linux:"Linux"};i.z.enum(Hh).or(i.z.enum(Wh).transform(t=>Gh[t]));const Kh=(...t)=>t.map(Ra).join(""),Ra=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),Jh=t=>t.endsWith("/")?t.slice(0,-1):t,Xh=(t,e="")=>t===null?"":`?${Object.entries(t).filter(([,r])=>r==null?!1:Array.isArray(r)?r.length>0:!0).map(([r,n])=>`${e}${r}=${n}`).join("&")}`;let Qh=class Ar{protocol;host;port;path;constructor({host:e,port:r,protocol:n="",pathPrefix:s=""}){this.protocol=n,this.host=e,this.port=r,this.path=Ra(s)}replace(e){return new Ar({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Ar({...this,pathPrefix:Kh(this.path,e)})}toString(){return Jh(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new Ar({host:"unknown",port:0})};const ef=async t=>await new Promise(e=>setTimeout(e,C.fromMilliseconds(t).milliseconds));class tf{config;retries;interval;constructor(e){this.config={baseInterval:new C(e?.baseInterval??C.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??ef},this.retries=0,this.interval=new C(this.config.baseInterval)}async wait(){const{maxRetries:e,scale:r,sleepFn:n}=this.config;return this.retries>=e?!1:(await n(this.interval),this.interval=this.interval.mult(r),this.retries++,!0)}get retryMessage(){return`breaker triggered ${this.retries+1}/${this.config.maxRetries} times, retrying in ${this.interval.toString()}`}reset(){this.retries=0,this.interval=this.config.baseInterval}}const rf=i.z.object({baseInterval:C.z.optional(),maxRetries:i.z.number().optional(),scale:i.z.number().optional()}),nf=Object.freeze(Object.defineProperty({__proto__:null,Breaker:tf,breakerConfigZ:rf},Symbol.toStringTag,{value:"Module"})),sf=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,_a=i.z.string().regex(sf),mt=i.z.number().min(0).max(255),ja=i.z.number().min(0).max(1),Ma=i.z.tuple([mt,mt,mt,ja]),af=i.z.tuple([mt,mt,mt]),of=i.z.object({rgba255:Ma}),cf=i.z.number().min(0).max(360),uf=i.z.number().min(0).max(100),lf=i.z.number().min(0).max(100),hf=i.z.tuple([cf,uf,lf,ja]),gs=i.z.union([_a,af,Ma,hf,of]),ff=gs.transform(t=>ws(t)),ws=(t,e=1)=>{if(t=gs.parse(t),typeof t=="string")return df(t,e);if(Array.isArray(t)){if(t.length<3||t.length>4)throw new Error(`Invalid color: [${t.join(", ")}]`);return t.length===3?[...t,e]:t}return t.rgba255},df=(t,e=1)=>(t=_a.parse(t),t=pf(t),[vr(t,0),vr(t,2),vr(t,4),t.length===8?vr(t,6)/255:e]),vr=(t,e)=>parseInt(t.slice(e,e+2),16),pf=t=>t.startsWith("#")?t.slice(1):t;ws("#000000");ws("#ffffff");const yf=i.z.object({key:i.z.string(),color:gs,position:i.z.number(),switched:i.z.boolean().optional()});i.z.array(yf);const mf=i.z.object({key:i.z.string(),name:i.z.string(),color:ff});i.z.object({key:i.z.string(),name:i.z.string(),swatches:i.z.array(mf)});i.z.int().min(0).max(255);i.z.object({name:i.z.string(),key:i.z.string()});const gf=t=>Object.getOwnPropertySymbols(globalThis).includes(t),wf=(t,e)=>{const r=Symbol.for(t);if(!gf(r)){const n=e();Object.defineProperty(globalThis,r,{value:n})}return()=>globalThis[r]},Da="sy_x_error",bf=t=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.startsWith(t):e instanceof Error?e.message.startsWith(t):typeof e!="string"?!1:e.startsWith(t),tr=t=>class jt extends Error{static discriminator=Da;discriminator=jt.discriminator;static TYPE=t;type=jt.TYPE;static matches=bf(t);matches=jt.matches;constructor(r,n){super(r,n),this.name=jt.TYPE}static sub(r){return tr(`${t}.${r}`)}},Pa=t=>{if(t==null||typeof t!="object")return!1;const e=t;if(e.discriminator!==Da)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},ht="unknown",Bn="nil";class vf{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Bn,data:""};if(Pa(e))for(const r of this.providers){const n=r.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:ht,data:e.message};if(typeof e=="string")return{type:ht,data:e};try{return{type:ht,data:JSON.stringify(e)}}catch{return{type:ht,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===Bn)return null;if(e.type===ht)return new qn(e.data);for(const r of this.providers){const n=r.decode(e);if(n!=null)return n}return new qn(e.data)}}const bs=wf("synnax-error-registry",()=>new vf),Tf=({encode:t,decode:e})=>bs().register({encode:t,decode:e}),zf=t=>bs().encode(t),Ef=t=>t==null?null:bs().decode(t);let qn=class extends tr("unknown"){};const Nf=i.z.object({type:i.z.string(),data:i.z.string()});class Of extends tr("canceled"){}class $f extends tr("not_implemented"){}const Be=Object.freeze(Object.defineProperty({__proto__:null,Canceled:Of,NONE:Bn,NotImplemented:$f,UNKNOWN:ht,Unknown:qn,createTyped:tr,decode:Ef,encode:zf,isTyped:Pa,payloadZ:Nf,register:Tf},Symbol.toStringTag,{value:"Module"})),Sf=i.object({jsonrpc:i.literal("2.0"),method:i.string(),params:i.any().optional(),id:i.union([i.string(),i.number(),i.null()]).optional()}),Ua=i.object({jsonrpc:i.literal("2.0"),id:i.union([i.string(),i.number(),i.null()])}),If=Ua.extend({result:i.json()}),Af=Ua.extend({error:i.object({code:i.number().int(),message:i.string().optional(),data:i.json().optional()})}),kf=i.union([If,Af]);i.union([Sf,kf]);const xf=i.uuid();i.object({key:xf,name:i.string().min(1),color:i.string()});i.z.string().regex(/^\d+\.\d+\.\d+$/);const Zf=["standard","scientific","engineering"];i.z.enum(Zf);i.z.enum(["success","info","warning","error","loading","disabled"]);i.z.object({stack:i.z.string(),error:i.z.instanceof(Error)});let rr=class extends Be.createTyped("freighter"){},we=class extends rr.sub("eof"){constructor(){super("EOF")}},vt=class extends rr.sub("stream_closed"){constructor(){super("StreamClosed")}},qe=class extends rr.sub("unreachable"){url;constructor(e={}){const{message:r="Unreachable",url:n=Qh.UNKNOWN}=e;super(r),this.url=n}};const Cf=t=>{if(!t.type.startsWith(rr.TYPE))return null;if(we.matches(t))return{type:we.TYPE,data:"EOF"};if(vt.matches(t))return{type:vt.TYPE,data:"StreamClosed"};if(qe.matches(t))return{type:qe.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${t.type}: ${t.message}`)},Rf=t=>{if(!t.type.startsWith(rr.TYPE))return null;switch(t.type){case we.TYPE:return new we;case vt.TYPE:return new vt;case qe.TYPE:return new qe;default:throw new Be.Unknown(`Unknown error type: ${t.data}`)}};Be.register({encode:Cf,decode:Rf});let La=class{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,r){let n=0;const s=async a=>{if(n===this.middleware.length)return await r(a);const o=this.middleware[n];return n++,await o(a,s)};return await s(e)}};const Ba="Content-Type",_f=new Set(["ECONNREFUSED","ECONNRESET","ETIMEDOUT","EPIPE","UND_ERR_CONNECT_TIMEOUT","UND_ERR_SOCKET"]),jf=t=>{const e=t?.cause?.code??t?.code??t?.errno;if(typeof e=="string"&&_f.has(e))return!0;if(t.name==="TypeError"){const r=String(t.message||"").toLowerCase();if(/load failed|failed to fetch|networkerror|network error/.test(r))return!0}return t?.name==="AbortError"||t?.code,!1},Mf=400;let Df=class extends La{endpoint;encoder;constructor(e,r,n=!1){return super(),this.endpoint=e.replace({protocol:n?"https":"http"}),this.encoder=r,new Proxy(this,{get:(s,a,o)=>a==="endpoint"?this.endpoint:Reflect.get(s,a,o)})}get headers(){return{[Ba]:this.encoder.contentType}}async send(e,r,n,s){r=n?.parse(r);let a=null;const o=this.endpoint.child(e),c={};c.method="POST",c.body=this.encoder.encode(r??{});const[,l]=await this.executeMiddleware({target:o.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async u=>{const h={...u,params:{}};c.headers={...this.headers,...u.params};let d;try{d=await fetch(u.target,c)}catch(v){if(!(v instanceof Error))throw v;return[h,jf(v)?new qe({url:o}):v]}const f=await d.arrayBuffer();if(d?.ok)return s!=null&&(a=this.encoder.decode(f,s)),[h,null];try{if(d.status!==Mf)return[h,new Error(d.statusText)];const v=this.encoder.decode(f,Be.payloadZ),S=Be.decode(v);return[h,S]}catch(v){return[h,new Error(`[freighter] - failed to decode error: ${d.statusText}: ${v.message}`)]}});if(l!=null)return[null,l];if(a==null)throw new Error("Response must be defined");return[a,null]}};const Pf=(t,e)=>{class r{wrapped;constructor(s){this.wrapped=s}use(...s){this.wrapped.use(...s)}async send(s,a,o,c){const l=new nf.Breaker(e);do{const[u,h]=await this.wrapped.send(s,a,o,c);if(h==null)return[u,null];if(!qe.matches(h))return[null,h];if(console.warn(`[freighter] ${l.retryMessage}`,h),!await l.wait())return[u,h]}while(!0)}}return new r(t)},w=async(t,e,r,n,s)=>{const[a,o]=await t.send(e,r,n,s);if(o!=null)throw o;return a},Uf=i.z.object({type:i.z.enum(["data","close","open"]),payload:i.z.unknown(),error:i.z.optional(Be.payloadZ)});class Lf{codec;reqSchema;resSchema;ws;serverClosed;sendClosed;receiveDataQueue=[];receiveCallbacksQueue=[];constructor(e,r,n,s){this.codec=r,this.reqSchema=n,this.resSchema=s,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}async receiveOpenAck(){const e=await this.receiveMsg();if(e.type!=="open"){if(e.error==null)throw new Error("Message error must be defined");return Be.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new we;if(this.sendClosed)throw new vt;return this.ws.send(this.codec.encode({type:"data",payload:e})),null}async receive(){if(this.serverClosed!=null)return[null,this.serverClosed];const e=await this.receiveMsg();if(e.type==="close"){if(e.error==null)throw new Error("Message error must be defined");if(this.serverClosed=Be.decode(e.error),this.serverClosed==null)throw new Error("Message error must be defined");return[null,this.serverClosed]}return[this.resSchema.parse(e.payload),null]}received(){return this.receiveDataQueue.length!==0}closeSend(){if(this.sendClosed||this.serverClosed!=null)return;const e={type:"close"};try{this.ws.send(this.codec.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){return this.receiveDataQueue.shift()??await new Promise((r,n)=>this.receiveCallbacksQueue.push({resolve:r,reject:n}))}addMessage(e){const r=this.receiveCallbacksQueue.shift();r!=null?r.resolve(e):this.receiveDataQueue.push(e)}listenForMessages(){this.ws.onmessage=this.onMessage.bind(this),this.ws.onclose=this.onClose.bind(this)}onMessage(e){this.addMessage(this.codec.decode(e.data,Uf))}onClose(e){this.addMessage({type:"close",error:{type:e.code===qf?we.TYPE:vt.TYPE,data:""}})}}const Bf="freighterctx",qf=1e3;class _r extends La{baseUrl;encoder;secure;static MESSAGE_TYPE="arraybuffer";constructor(e,r,n=!1){super(),this.secure=n,this.baseUrl=e.replace({protocol:n?"wss":"ws"}),this.encoder=r}withCodec(e){const r=new _r(this.baseUrl,e,this.secure);return r.use(...this.middleware),r}async stream(e,r,n){let s;const[,a]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async o=>{const c=new WebSocket(this.buildURL(e,o)),l={...o,params:{}};c.binaryType=_r.MESSAGE_TYPE;const u=await this.wrapSocket(c,r,n);return u instanceof Error?[l,u]:(s=u,[l,null])});if(a!=null)throw a;return s}buildURL(e,r){const n=Xh({[Ba]:this.encoder.contentType,...r.params},Bf);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,r,n){return await new Promise(s=>{e.onopen=()=>{const a=new Lf(e,this.encoder,r,n);a.receiveOpenAck().then(o=>{o!=null?s(o):s(a)}).catch(o=>s(o))},e.onerror=a=>{const o=a;s(new Error(o.message))}})}}const qa=t=>i.union([i.union([i.null(),i.undefined()]).transform(()=>[]),t.array()]),Ff=t=>Array.isArray(t)?t:t==null?[]:[t],Fa=(t,e)=>{if(Array.isArray(e))return e.reduce((s,a)=>Fa(s,a),t??[]);if(t==null)return[e];const r=t.findIndex(s=>s==e),n=[...t];return r===-1?n.push(e):n[r]=e,n},Vf=((t,e)=>{if(t!=null)return Array.isArray(e)?t.filter(r=>!e.includes(r)):t.filter(r=>r!=e)}),Va=(t,e)=>{if(Array.isArray(e))return e.reduce((s,a)=>Va(s,a),t??[]);if(t==null)return[e];const r=t.findIndex(s=>s.key===e.key),n=[...t];return r===-1?n.push(e):n[r]=e,n},Yf=((t,e)=>{if(t!=null)return Array.isArray(e)?t.filter(r=>!e.includes(r.key)):t.filter(r=>r.key!==e)}),T=Object.freeze(Object.defineProperty({__proto__:null,nullableZ:qa,remove:Vf,removeKeyed:Yf,toArray:Ff,upsert:Fa,upsertKeyed:Va},Symbol.toStringTag,{value:"Module"})),Hf=t=>{const e=t.replace(/_[a-z]/g,r=>r[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},Gr=t=>{const e=(r,n=Fn)=>{if(typeof r=="string")return t(r);if(Array.isArray(r))return r.map(o=>e(o,n));if(!zn(r))return r;n=Kf(n);const s={},a=r;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),n):(Object.keys(a).forEach(o=>{let c=a[o];const l=t(o);n.recursive&&(zn(c)?wi(c)||(c=e(c,n)):n.recursiveInArray&&gi(c)&&(c=[...c].map(u=>{let h=u;return zn(u)?wi(h)||(h=e(u,n)):gi(u)&&(h=e({key:u},n).key),h}))),s[l]=c}),s)};return e},vs=Gr(Hf),Wf=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,r,n)=>`${r}_${n.toLowerCase()}`),Ya=Gr(Wf),Ha=t=>t.length===0?t:t[0].toUpperCase()+t.slice(1),Gf=[Number,String,Uint8Array],Fn={recursive:!0,recursiveInArray:!0},Kf=(t=Fn)=>(t.recursive==null?t=Fn:t.recursiveInArray??=!1,t),gi=t=>t!=null&&Array.isArray(t),zn=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),wi=t=>Gf.some(e=>t instanceof e),Jf=t=>t.replace(/[\s_]+/g,"-").replace(/([a-z0-9])([A-Z])/g,(e,r,n)=>`${r}-${n.toLowerCase()}`).toLowerCase(),Xf=Gr(Jf),Qf=t=>{if(t.length===0)return t;let e=t.replace(/[_-]/g," ");return e=e.replace(/([a-z0-9])([A-Z])/g,(r,n,s)=>`${n} ${s}`),e=e.replace(/([A-Z]+)([A-Z][a-z])/g,(r,n,s)=>`${n} ${s}`),e=e.replace(/\s+/g," ").trim(),e=e.replace(/\b\w/g,r=>r.toUpperCase()),e},ed=Gr(Qf),td=Object.freeze(Object.defineProperty({__proto__:null,camelToSnake:Ya,capitalize:Ha,snakeToCamel:vs,toKebab:Xf,toProperNoun:ed},Symbol.toStringTag,{value:"Module"})),Wa=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);let Ga=class{contentType="application/json";decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e))}decode(e,r){return this.decodeString(this.decoder.decode(e),r)}decodeString(e,r){const n=JSON.parse(e),s=vs(n);return r!=null?r.parse(s):s}encodeString(e){const r=Ya(e);return JSON.stringify(r,(n,s)=>ArrayBuffer.isView(s)?Array.from(s):typeof s=="bigint"?s.toString():s)}},Ka=class{contentType="text/csv";encode(e){const r=this.encodeString(e);return new TextEncoder().encode(r)}decode(e,r){const n=new TextDecoder().decode(e);return this.decodeString(n,r)}encodeString(e){if(!Array.isArray(e)||e.length===0||!Wa(e[0]))throw new Error("Payload must be an array of objects");const r=Object.keys(e[0]),n=[r.join(",")];return e.forEach(s=>{const a=r.map(o=>JSON.stringify(s[o]??""));n.push(a.join(","))}),n.join(`
7
7
  `)}decodeString(e,r){const[n,...s]=e.trim().split(`
8
- `).map(c=>c.trim());if(n.length===0)return r!=null?r.parse({}):{};const a=n.split(",").map(c=>c.trim()),o={};return a.forEach(c=>{o[c]=[]}),s.forEach(c=>{const l=c.split(",").map(u=>u.trim());a.forEach((u,h)=>{const d=this.parseValue(l[h]);d!=null&&o[u].push(d)})}),r!=null?r.parse(o):o}parseValue(e){if(e==null||e.length===0)return null;const r=Number(e);return isNaN(r)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:r}},Ja=class{contentType="text/plain";encode(e){if(typeof e!="string")throw new Error("TextCodec.encode payload must be a string");return new TextEncoder().encode(e)}decode(e,r){const n=new TextDecoder().decode(e);return r!=null?r.parse(n):n}};const Bt=new Ha,Gf=new Ga,Jf=new Ja,Kf=[Bt],st=Object.freeze(Object.defineProperty({__proto__:null,CSVCodec:Ga,CSV_CODEC:Gf,ENCODERS:Kf,JSONCodec:Ha,JSON_CODEC:Bt,TEXT_CODEC:Jf,TextCodec:Ja},Symbol.toStringTag,{value:"Module"})),Vn=t=>[...new Set(t)],Xf=(t,e,r=!0)=>{const n=new Map;return t.forEach(s=>{const a=e(s);if(n.has(a)){if(r)return;n.delete(a)}n.set(a,s)}),Array.from(n.values())},wi=Object.freeze(Object.defineProperty({__proto__:null,by:Xf,unique:Vn},Symbol.toStringTag,{value:"Module"})),he=t=>t!=null&&typeof t=="object"&&"value"in t;let Nt=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const Qf=t=>t!=null&&typeof t=="object"&&"toString"in t,Hr=(t,e=!1)=>{const r=Qf(t)?"stringer":typeof t;let n;switch(r){case"string":n=(s,a)=>s.localeCompare(a);break;case"stringer":n=(s,a)=>s.toString().localeCompare(a.toString());break;case"number":n=(s,a)=>Number(s)-Number(a);break;case"bigint":n=(s,a)=>BigInt(s)-BigInt(a)>0n?1:-1;break;case"boolean":n=(s,a)=>Number(s)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${r}`),()=>-1}return e?Xa(n):n},ed=(t,e,r)=>{const n=Hr(e[t],r);return(s,a)=>n(s[t],a[t])},td=(t,e)=>t.length!==e.length?t.length-e.length:t.every((r,n)=>r===e[n])?0:-1,Ka=(t,e)=>{if(t.length!==e.length)return t.length-e.length;if(t.length===0)return 0;const r=Hr(t[0]),n=[...t].sort(r),s=[...e].sort(r);return n.every((a,o)=>a===s[o])?0:-1},rd=(t,e)=>{const r=Vn(t),n=Vn(e);return Ka(r,n)},nd=(t,e)=>t===e?0:t==="first"&&e==="last"?1:-1,Xa=t=>(e,r)=>t(r,e),Ot=0,Ir=-1,kr=1,Qa=t=>t<Ot,eo=t=>t>Ot,sd=t=>t>=Ot,to=t=>t===Ot,id=(t,e)=>{const r=/([a-zA-Z]+)|(\d+)/g,n=t.replace(/[\s_.-]+/g,"").match(r),s=e.replace(/[\s_.-]+/g,"").match(r);if(!n||!s)return 0;for(let a=0;a<Math.min(n.length,s.length);a++){const o=n[a],c=s[a];if(isNaN(Number(o))&&isNaN(Number(c))){const l=o.localeCompare(c);if(l!==0)return l}else if(!isNaN(Number(o))&&!isNaN(Number(c))){const l=Number(o)-Number(c);if(l!==0)return l}else return isNaN(Number(o))?-1:1}return n.length-s.length},bi=Object.freeze(Object.defineProperty({__proto__:null,EQUAL:Ot,GREATER_THAN:kr,LESS_THAN:Ir,isEqualTo:to,isGreaterThan:eo,isGreaterThanEqual:sd,isLessThan:Qa,newF:Hr,newFieldF:ed,order:nd,primitiveArrays:td,reverseF:Xa,stringsWithNumbers:id,uniqueUnorderedPrimitiveArrays:rd,unorderedPrimitiveArrays:Ka},Symbol.toStringTag,{value:"Module"})),Gr=i.z.tuple([i.z.number(),i.z.number()]);i.z.tuple([i.z.bigint(),i.z.bigint()]);const ro=i.z.object({width:i.z.number(),height:i.z.number()}),ad=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),od=["width","height"];i.z.enum(od);const cd=["start","center","end"],ud=["signedWidth","signedHeight"];i.z.enum(ud);const qt=i.z.object({x:i.z.number(),y:i.z.number()}),no=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),so=["x","y"],io=i.z.enum(so),Ts=["top","right","bottom","left"],ld=i.z.enum(Ts),ao=["left","right"],zs=i.z.enum(ao),oo=["top","bottom"],Es=i.z.enum(oo),Ns=["center"],Yn=i.z.enum(Ns),hd=[...Ts,...Ns],Os=i.z.enum(hd);i.z.enum(cd);const fd=["first","last"];i.z.enum(fd);const dd=i.z.object({lower:i.z.number(),upper:i.z.number()}),pd=i.z.object({lower:i.z.bigint(),upper:i.z.bigint()});i.z.union([dd,Gr]);i.z.union([pd,Gr]);i.z.enum([...io.options,...Os.options]);i.z.enum(["x","left","right"]);i.z.enum(["y","top","bottom"]);const yd=i.z.union([io,Os,i.z.instanceof(String)]),$t=t=>(e,r)=>{if(typeof e=="bigint"){if(Rr(r))return t(e,BigInt(r));const n=t(Number(e),Number(r));return typeof n=="number"?BigInt(Math.round(n)):n}return t(Number(e),Number(r))},Ue=$t((t,e)=>t-e),St=$t((t,e)=>t+e),md=(t,e,r=1e-4)=>Math.abs(t-e)<r,Wn=(t,e)=>{const r=typeof t=="bigint",n=typeof e=="bigint";return r&&n?t===e:r&&Rr(e)?t===BigInt(e):n&&Rr(t)?e===BigInt(t):t===e},gd=t=>{const e=10**Math.floor(Math.log10(t));return Math.round(t/e)*e},co=$t((t,e)=>t<=e?t:e),Rr=t=>typeof t=="bigint"?!0:Number.isInteger(t),wd=$t((t,e)=>t>=e?t:e),uo=t=>typeof t=="bigint"?t<0n?-t:t:t<0?-t:t,me=$t((t,e)=>t*e),sr=$t((t,e)=>t/e),J=(t,e,r)=>{const n={};if(typeof e=="object"&&(r=e,e=void 0),r={makeValid:!0,...r},typeof t=="number"||typeof t=="bigint")e!=null?(n.lower=t,n.upper=e):(n.lower=typeof t=="bigint"?0n:0,n.upper=t);else if(Array.isArray(t)){if(t.length!==2)throw new Error("bounds: expected array of length 2");[n.lower,n.upper]=t}else n.lower=t.lower,n.upper=t.upper;return r?.makeValid?bd(n):n},bd=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t,vi=(t,e)=>{const r=J(t);return e<r.lower?r.lower:e>=r.upper?r.upper-(typeof r.upper=="number"?1:1n):e},br=(t,e)=>{const r=J(t);if(typeof e=="number"||typeof e=="bigint")return e>=r.lower&&e<r.upper;const n=J(e);return n.lower>=r.lower&&n.upper<=r.upper},lo=t=>{const e=J(t);return e.upper-e.lower},vd=t=>({lower:Math.min(...t.map(e=>J(e).lower)),upper:Math.max(...t.map(e=>J(e).upper))}),Td=(t,e,r)=>{const n=t.map(c=>J(c)),s=r>0?1:r<0?-1:0;if(s===0)return e;let a=r,o=e;for(;Wn(a,0)===!1;){const c=n.findIndex(l=>s>0?o>=l.lower&&o<l.upper:o>l.lower&&o<=l.upper);if(c!==-1){const l=n[c];let u;if(s>0?u=Ue(l.upper,o):u=Ue(o,l.lower),u>0){const h=co(uo(a),u);if(o=St(o,s>0?h:-h),a=Ue(a,s>0?h:-h),Wn(a,0))return o;continue}}if(s>0){const l=n.filter(u=>u.lower>o);if(l.length>0)o=l[0].lower;else return o}else{const l=n.filter(u=>u.upper<o);if(l.length>0)o=l[l.length-1].upper;else return o}}return o},zd=(t,e,r)=>{const n=t.map(o=>J(o));if(e===r)return typeof e=="bigint"?0n:0;const s=e<r?J([e,r]):J([r,e]);let a=typeof e=="bigint"?0n:0;for(const o of n){const c=o.lower>s.lower?o.lower:s.lower,l=o.upper<s.upper?o.upper:s.upper;if(c<l){const u=l-c;a=a+u}}return a},Ed=zs,Nd=Es,Od=Yn,$d={top:"bottom",right:"left",bottom:"top",left:"right",center:"center"},Sd={top:"left",right:"top",bottom:"right",left:"bottom",center:"center"},Id=yd,qe=t=>t instanceof String||!so.includes(t)?t:t==="x"?"left":"top",kd=t=>$d[qe(t)],Ad=t=>Sd[qe(t)],Ft=t=>{const e=qe(t);return e==="top"||e==="bottom"?"y":"x"},xd=i.z.object({x:zs.or(Yn),y:Es.or(Yn)}),ho=i.z.object({x:zs,y:Es}),$s=Object.freeze({x:"left",y:"top"}),fo=Object.freeze({x:"right",y:"top"}),po=Object.freeze({x:"left",y:"bottom"}),yo=Object.freeze({x:"right",y:"bottom"}),Ss=Object.freeze({x:"center",y:"center"}),mo=Object.freeze({x:"center",y:"top"}),go=Object.freeze({x:"center",y:"bottom"}),wo=Object.freeze({x:"right",y:"center"}),bo=Object.freeze({x:"left",y:"center"}),Zd=Object.freeze([bo,wo,mo,go,$s,fo,po,yo,Ss]),vo=(t,e)=>t.x===e.x&&t.y===e.y,Cd=(t,e)=>{if(typeof e=="object"){let r=!0;return"x"in e&&(t.x===e.x||(r=!1)),"y"in e&&(t.y===e.y||(r=!1)),r}return t.x===e||t.y===e},Rd=t=>[t.x,t.y],Ar=t=>Ft(qe(t))==="x",_d=t=>Ft(qe(t))==="y",jd=t=>`${t.x}${Ya(t.y)}`,Md=(t,e)=>{let r,n;if(typeof t=="object"&&"x"in t?(r=t.x,n=t.y):(r=qe(t),n=qe(e??t)),Ft(r)===Ft(n)&&r!=="center"&&n!=="center")throw new Error(`[XYLocation] - encountered two locations with the same direction: ${r.toString()} - ${n.toString()}`);const s={...Ss};return r==="center"?Ar(n)?[s.x,s.y]=[n,r]:[s.x,s.y]=[r,n]:n==="center"?Ar(r)?[s.x,s.y]=[r,n]:[s.x,s.y]=[n,r]:Ar(r)?[s.x,s.y]=[r,n]:[s.x,s.y]=[n,r],s},Dd=Object.freeze(Object.defineProperty({__proto__:null,BOTTOM_CENTER:go,BOTTOM_LEFT:po,BOTTOM_RIGHT:yo,CENTER:Ss,CENTER_LEFT:bo,CENTER_LOCATIONS:Ns,CENTER_RIGHT:wo,OUTER_LOCATIONS:Ts,TOP_CENTER:mo,TOP_LEFT:$s,TOP_RIGHT:fo,XY_LOCATIONS:Zd,X_LOCATIONS:ao,Y_LOCATIONS:oo,center:Od,construct:qe,constructXY:Md,corner:ho,crude:Id,direction:Ft,isX:Ar,isY:_d,location:Os,outer:ld,rotate90:Ad,swap:kd,x:Ed,xy:xd,xyCouple:Rd,xyEquals:vo,xyMatches:Cd,xyToString:jd,y:Nd},Symbol.toStringTag,{value:"Module"})),Hn=i.z.union([i.z.number(),qt,Gr,ro,ad,no]),M=(t,e)=>{if(typeof t=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return t==="x"?{x:e,y:0}:{x:0,y:e}}return typeof t=="number"?{x:t,y:e??t}:Array.isArray(t)?{x:t[0],y:t[1]}:"signedWidth"in t?{x:t.signedWidth,y:t.signedHeight}:"clientX"in t?{x:t.clientX,y:t.clientY}:"width"in t?{x:t.width,y:t.height}:{x:t.x,y:t.y}},tt=Object.freeze({x:0,y:0}),Pd=Object.freeze({x:1,y:1}),Ud=Object.freeze({x:1/0,y:1/0}),Ld=Object.freeze({x:NaN,y:NaN}),To=(t,e,r=0)=>{const n=M(t),s=M(e);return r===0?n.x===s.x&&n.y===s.y:Math.abs(n.x-s.x)<=r&&Math.abs(n.y-s.y)<=r},Bd=t=>To(t,tt),Is=(t,e,r)=>{const n=M(t),s=M(e,r);return{x:n.x*s.x,y:n.y*s.y}},zo=(t,e)=>{const r=M(t);return{x:r.x+e,y:r.y}},Eo=(t,e)=>{const r=M(t);return{x:r.x,y:r.y+e}},No=(t,e,r,...n)=>{if(typeof e=="string"){if(typeof r!="number")throw new Error("The value must be a number.");return e==="x"?zo(t,r):Eo(t,r)}if(typeof e=="object"&&"x"in e&&typeof e.x=="string"){const s=M(r),a=M(t);return e.x==="left"?s.x=-s.x:e.x==="center"&&(s.x=0),e.y==="top"?s.y=-s.y:e.y==="center"&&(s.y=0),{x:a.x+s.x,y:a.y+s.y}}return[t,e,r??tt,...n].reduce((s,a)=>{const o=M(a);return{x:s.x+o.x,y:s.y+o.y}},tt)},qd=(t,e,r)=>{const n=M(t);return e==="x"?{x:r,y:n.y}:{x:n.x,y:r}},Fd=(t,e)=>{const r=M(t),n=M(e);return Math.sqrt((r.x-n.x)**2+(r.y-n.y)**2)},Vd=(t,e)=>{const r=M(t),n=M(e);return{x:n.x-r.x,y:n.y-r.y}},Yd=t=>{const e=M(t);return Number.isNaN(e.x)||Number.isNaN(e.y)},Wd=t=>{const e=M(t);return Number.isFinite(e.x)&&Number.isFinite(e.y)},Hd=t=>{const e=M(t);return[e.x,e.y]},Gd=t=>{const e=M(t);return{left:e.x,top:e.y}},Jd=(t,e=0)=>{const r=M(t);return{x:Number(r.x.toFixed(e)),y:Number(r.y.toFixed(e))}},jt=(t,e)=>{const r=M(t),n=M(e);return{x:r.x-n.x,y:r.y-n.y}},Mt=t=>{const e=M(t),r=Math.hypot(e.x,e.y);return r===0?{x:0,y:0}:{x:-e.y/r,y:e.x/r}},Oo=t=>{const e=M(t),r=Math.hypot(e.x,e.y);return r===0?{x:0,y:0}:{x:e.x/r,y:e.y/r}},$o=(...t)=>{const e=t.reduce((r,n)=>No(r,n),tt);return Is(e,1/t.length)},Kd=(t,e)=>{const r=[];for(let n=0;n<t.length;n++){const s=t[n];let a,o,c,l;if(n===0){const u=t[n+1],h=jt(u,s);o=Mt(h),c=o,l=e}else if(n===t.length-1){const u=t[n-1],h=jt(s,u);a=Mt(h),c=a,l=e}else{const u=t[n-1],h=t[n+1],d=jt(s,u),f=jt(h,s);a=Mt(d),o=Mt(f);const v=Math.acos((d.x*f.x+d.y*f.y)/(Math.hypot(d.x,d.y)*Math.hypot(f.x,f.y))),S=Math.sin(v/2);S===0?l=e:l=e/S,c=Oo($o(a,o))}r.push(Is(c,l))}return r},Xd=t=>{const e=M(t);return{x:e.y,y:e.x}},Qd=t=>{const e=M(t);return{x:Math.round(e.x),y:Math.round(e.y)}},ep=t=>{const e=M(t);return{x:1/e.x,y:1/e.y}},ks=Object.freeze(Object.defineProperty({__proto__:null,INFINITY:Ud,NAN:Ld,ONE:Pd,ZERO:tt,average:$o,calculateMiters:Kd,clientXY:no,construct:M,couple:Hd,crudeZ:Hn,css:Gd,distance:Fd,equals:To,isFinite:Wd,isNan:Yd,isZero:Bd,normal:Mt,normalize:Oo,reciprocal:ep,round:Qd,scale:Is,set:qd,sub:jt,swap:Xd,translate:No,translateX:zo,translateY:Eo,translation:Vd,truncate:Jd,xy:qt},Symbol.toStringTag,{value:"Module"})),vr=i.z.union([i.z.number(),i.z.string()]);i.z.object({top:vr,left:vr,width:vr,height:vr});i.z.object({left:i.z.number(),top:i.z.number(),right:i.z.number(),bottom:i.z.number()});i.z.object({one:qt,two:qt,root:ho});const As=(t,e,r=0,n=0,s)=>{const a={one:{...tt},two:{...tt},root:s??$s};if(typeof t=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:t,y:e},a.two={x:a.one.x+r,y:a.one.y+n},a}return"one"in t&&"two"in t&&"root"in t?{...t,root:s??t.root}:("getBoundingClientRect"in t&&(t=t.getBoundingClientRect()),"left"in t?(a.one={x:t.left,y:t.top},a.two={x:t.right,y:t.bottom},a):(a.one=t,e==null?a.two={x:a.one.x+r,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+r}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},En=t=>{const e=As(t);return{lower:e.one.x,upper:e.two.x}},Nn=t=>{const e=As(t);return{lower:e.one.y,upper:e.two.y}},tp=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t,rp=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([ro,rp,qt,Gr]);const np=(t,e,r)=>e!==void 0&&t<e?e:r!==void 0&&t>r?r:t;i.z.object({offset:Hn,scale:Hn});i.z.object({offset:i.z.number(),scale:i.z.number()});const sp=t=>(e,r,n,s)=>r==="dimension"?[e,n]:[e,s?n-t:n+t],ip=t=>(e,r,n,s)=>[e,s?n/t:n*t],ap=t=>(e,r,n)=>{if(e===null)return[t,n];const{lower:s,upper:a}=e,{lower:o,upper:c}=t,l=a-s,u=c-o;if(r==="dimension")return[t,n*(u/l)];const h=(n-s)*(u/l)+o;return[t,h]},op=t=>(e,r,n)=>[t,n],cp=()=>(t,e,r)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,r];const{lower:n,upper:s}=t;return[t,s-(r-n)]},up=t=>(e,r,n)=>{const{lower:s,upper:a}=t;return n=np(n,s,a),[e,n]};let Ti=class ht{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new ht().translate(e)}static magnify(e){return new ht().magnify(e)}static scale(e,r){return new ht().scale(e,r)}translate(e){const r=this.new(),n=sp(e);return n.type="translate",r.ops.push(n),r}magnify(e){const r=this.new(),n=ip(e);return n.type="magnify",r.ops.push(n),r}scale(e,r){const n=J(e,r),s=this.new(),a=ap(n);return a.type="scale",s.ops.push(a),s}clamp(e,r){const n=J(e,r),s=this.new(),a=up(n);return a.type="clamp",s.ops.push(a),s}reBound(e,r){const n=J(e,r),s=this.new(),a=op(n);return a.type="re-bound",s.ops.push(a),s}invert(){const e=cp();e.type="invert";const r=this.new();return r.ops.push(e),r}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new ht;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,r){return this.currBounds=null,this.ops.reduce(([n,s],a)=>a(n,e,s,this.reversed),[null,r])[1]}reverse(){const e=this.new();e.ops.reverse();const r=[];return e.ops.forEach((n,s)=>{if(n.type==="scale"||r.some(([o,c])=>s>=o&&s<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>s);a!==-1&&r.push([s,a])}),r.forEach(([n,s])=>{const a=e.ops.slice(n,s);a.unshift(e.ops[s]),e.ops.splice(n,s-n+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new ht},$S=class Ne{x;y;currRoot;constructor(e=new Ti,r=new Ti,n=null){this.x=e,this.y=r,this.currRoot=n}static translate(e,r){return new Ne().translate(e,r)}static translateX(e){return new Ne().translateX(e)}static translateY(e){return new Ne().translateY(e)}static clamp(e){return new Ne().clamp(e)}static magnify(e){return new Ne().magnify(e)}static scale(e){return new Ne().scale(e)}static reBound(e){return new Ne().reBound(e)}translate(e,r){const n=M(e,r),s=this.copy();return s.x=this.x.translate(n.x),s.y=this.y.translate(n.y),s}translateX(e){const r=this.copy();return r.x=this.x.translate(e),r}translateY(e){const r=this.copy();return r.y=this.y.translate(e),r}magnify(e){const r=this.copy();return r.x=this.x.magnify(e.x),r.y=this.y.magnify(e.y),r}scale(e){const r=this.copy();if(tp(e)){const n=this.currRoot;return r.currRoot=e.root,n!=null&&!vo(n,e.root)&&(n.x!==e.root.x&&(r.x=r.x.invert()),n.y!==e.root.y&&(r.y=r.y.invert())),r.x=r.x.scale(En(e)),r.y=r.y.scale(Nn(e)),r}return r.x=r.x.scale(e.width),r.y=r.y.scale(e.height),r}reBound(e){const r=this.copy();return r.x=this.x.reBound(En(e)),r.y=this.y.reBound(Nn(e)),r}clamp(e){const r=this.copy();return r.x=this.x.clamp(En(e)),r.y=this.y.clamp(Nn(e)),r}copy(){const e=new Ne;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return As(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}static IDENTITY=new Ne},So=(t,e=21)=>(r=e)=>{let n="",s=r|0;for(;s--;)n+=t[Math.random()*t.length|0];return n};const Io="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",lp=`0123456789${Io}`,ko=11,hp=So(Io,1),fp=So(lp,ko-1),xs=()=>`${hp()}${fp()}`,dp=Object.freeze(Object.defineProperty({__proto__:null,LENGTH:ko,create:xs},Symbol.toStringTag,{value:"Module"})),pp=(t,e)=>r=>r instanceof e||typeof r=="object"&&r!==null&&"discriminator"in r&&r.discriminator===t,yp=2**8-1,mp=2**16-1,gp=2**32-1,wp=2n**64n-1n,bp=2**64-1,vp=-128,Tp=2**7-1,zp=-32768,Ep=2**15-1,Np=-2147483648,Op=2**31-1,$p=-(2n**63n),_r=2n**63n-1n,Sp=-9223372036854776e3,Ao=2**63-1,Ip=i.z.enum(["static","dynamic"]),zi=365,Tr=30,kp=i.z.union([i.z.tuple([i.z.int()]),i.z.tuple([i.z.int(),i.z.int().min(1).max(12)]),i.z.tuple([i.z.int(),i.z.int().min(1).max(12),i.z.int().min(1).max(31)])]),xo=(t,e)=>{const r=new p(e);if(![I.DAY,I.HOUR,I.MINUTE,I.SECOND,I.MILLISECOND,I.MICROSECOND,I.NANOSECOND].some(s=>s.equals(r)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=t.valueOf()%r.valueOf();return t instanceof p?new p(n):new I(n)};class p extends Nt{constructor(e,r="UTC"){if(e==null)super(p.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*p.MILLISECOND.valueOf());else if(typeof e=="string")super(p.parseDateTimeString(e,r).valueOf());else if(Array.isArray(e))super(p.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),r==="local"&&(n=p.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e===Ao?e=_r:e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=p.MAX:e=p.MIN)),he(e)&&(e=e.value),super(BigInt(e.valueOf())+n)}}static parseDate([e=1970,r=1,n=1]){const s=new Date(e,r-1,n,0,0,0,0);return new p(BigInt(s.getTime())*p.MILLISECOND.valueOf()).truncate(p.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,r="UTC"){const[n,s,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let l=p.hours(parseInt(n??"00")).add(p.minutes(parseInt(s??"00"))).add(p.seconds(parseInt(o??"00"))).add(p.milliseconds(parseInt(c??"00")));return r==="local"&&(l=l.add(p.utcOffset)),l.valueOf()}static parseDateTimeString(e,r="UTC"){if(!e.includes("/")&&!e.includes("-"))return p.parseTimeString(e,r);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new p(BigInt(n.getTime())*p.MILLISECOND.valueOf(),r).valueOf()}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(p.utcOffset).date().toISOString()}timeString(e=!1,r="UTC"){const n=this.toISOString(r);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),r=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${r} ${n}`}static get utcOffset(){return new I(BigInt(new Date().getTimezoneOffset())*p.MINUTE.valueOf())}static since(e){return new p().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new p(e).valueOf()}span(e){return this.range(e).span}range(e){return new P(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new p(e).valueOf()}afterEq(e){return this.valueOf()>=new p(e).valueOf()}before(e){return this.valueOf()<new p(e).valueOf()}beforeEq(e){return this.valueOf()<=new p(e).valueOf()}add(e){return new p(St(this.valueOf(),new I(e).valueOf()))}sub(e){return new p(Ue(this.valueOf(),new I(e).valueOf()))}get hours(){return Number(this.valueOf())/Number(I.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(I.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(I.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(I.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(p.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(p.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}setYear(e){const r=this.date();return r.setUTCFullYear(e),new p(r)}get month(){return this.date().getUTCMonth()}setMonth(e){const r=this.date();return r.setUTCMonth(e),new p(r)}get day(){return this.date().getUTCDate()}setDay(e){const r=this.date();return r.setUTCDate(e),new p(r)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(e){const r=this.date();return r.setHours(e),new p(r)}setHour(e){const r=this.date();return r.setUTCHours(e),new p(r)}get minute(){return this.date().getUTCMinutes()}setMinute(e){const r=this.date();return r.setUTCMinutes(e),new p(r)}get second(){return this.date().getUTCSeconds()}setSecond(e){const r=this.date();return r.setUTCSeconds(e),new p(r)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const r=this.date();return r.setUTCMilliseconds(e),new p(r)}toString(e="ISO",r="UTC"){switch(e){case"ISODate":return this.toISOString(r).slice(0,10);case"ISOTime":return this.toISOString(r).slice(11,23);case"time":return this.timeString(!1,r);case"preciseTime":return this.timeString(!0,r);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,r)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,r)}`;default:return this.toISOString(r)}}remainder(e){return xo(this,e)}get isToday(){return this.truncate(I.DAY).equals(p.now().truncate(I.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new p(new Date)}static max(...e){let r=p.MIN;for(const n of e){const s=new p(n);s.after(r)&&(r=s)}return r}static min(...e){let r=p.MAX;for(const n of e){const s=new p(n);s.before(r)&&(r=s)}return r}static nanoseconds(e,r="UTC"){return new p(e,r)}static NANOSECOND=p.nanoseconds(1);static microseconds(e,r="UTC"){return p.nanoseconds(e*1e3,r)}static MICROSECOND=p.microseconds(1);static milliseconds(e,r="UTC"){return p.microseconds(e*1e3,r)}static MILLISECOND=p.milliseconds(1);static seconds(e,r="UTC"){return p.milliseconds(e*1e3,r)}static SECOND=p.seconds(1);static minutes(e,r="UTC"){return p.seconds(e*60,r)}static MINUTE=p.minutes(1);static hours(e,r="UTC"){return p.minutes(e*60,r)}static HOUR=p.hours(1);static days(e,r="UTC"){return p.hours(e*24,r)}static DAY=p.days(1);static MAX=new p(_r);static MIN=new p(0);static ZERO=new p(0);static z=i.z.union([i.z.instanceof(p),i.z.object({value:i.z.bigint()}).transform(e=>new p(e.value)),i.z.string().transform(e=>new p(BigInt(e))),i.z.number().transform(e=>new p(e)),i.z.bigint().transform(e=>new p(e)),i.z.date().transform(e=>new p(e)),i.z.custom(e=>e instanceof I).transform(e=>new p(e)),kp.transform(e=>new p(e))]);static sort(e,r){return Number(e.valueOf()-r.valueOf())}}let I=class O extends Nt{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),he(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof O?e:e instanceof re?e.period:e instanceof p?new O(e):(he(e)&&(e=e.value),["number","bigint"].includes(typeof e)?O.seconds(e):new O(e))}static fromMilliseconds(e){return e instanceof O?e:e instanceof re?e.period:e instanceof p?new O(e):(he(e)&&(e=e.value),["number","bigint"].includes(typeof e)?O.milliseconds(e):new O(e))}valueOf(){return this.value}lessThan(e){return this.valueOf()<new O(e).valueOf()}greaterThan(e){return this.valueOf()>new O(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new O(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new O(e).valueOf()}remainder(e){return xo(this,e)}truncate(e){return new O(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(e="full"){if(e==="semantic")return this.toSemanticString();const r=this.truncate(O.DAY),n=this.truncate(O.HOUR),s=this.truncate(O.MINUTE),a=this.truncate(O.SECOND),o=this.truncate(O.MILLISECOND),c=this.truncate(O.MICROSECOND),l=this.truncate(O.NANOSECOND),u=r,h=n.sub(r),d=s.sub(n),f=a.sub(s),v=o.sub(a),S=c.sub(o),Z=l.sub(c);let b="";return u.isZero||(b+=`${u.days}d `),h.isZero||(b+=`${h.hours}h `),d.isZero||(b+=`${d.minutes}m `),f.isZero||(b+=`${f.seconds}s `),v.isZero||(b+=`${v.milliseconds}ms `),S.isZero||(b+=`${S.microseconds}µs `),Z.isZero||(b+=`${Z.nanoseconds}ns`),b.trim()}toSemanticString(){const e=this.valueOf()<0n?-this.valueOf():this.valueOf(),r=new O(e),n=this.valueOf()<0n;if(r.valueOf()===0n)return"0s";if(r.lessThan(O.SECOND))return"< 1s";const s=r.days,a=r.hours,o=r.minutes,c=r.seconds,l=Math.floor(s/zi),u=Math.floor(s/Tr),h=Math.floor(s/7),d=Math.floor(s),f=Math.floor(a),v=Math.floor(o),S=Math.floor(c),Z=n?"-":"";if(l>=1){let b=`${l}y`;if(l<2){const z=Math.floor(s%zi/Tr);z>0&&(b+=` ${z}mo`)}return Z+b}if(h>=1&&s<Tr&&s%7===0){let b=`${h}w`;const z=Math.floor(s%7),k=Math.floor(a-h*7*24);return h<2&&(z>0?b+=` ${z}d`:k>0&&k<24&&(b+=` ${k}h`)),Z+b}if(u>=1){let b=`${u}mo`;if(u<3){const z=Math.floor(s%Tr);z>0&&(b+=` ${z}d`)}return Z+b}if(h>=1){let b=`${h}w`;const z=Math.floor(s%7),k=Math.floor(a-h*7*24);return h<2&&(z>0?b+=` ${z}d`:k>0&&k<24&&(b+=` ${k}h`)),Z+b}if(d>=1){let b=`${d}d`;const z=Math.floor(a-d*24);return d<2&&z>0&&(b+=` ${z}h`),Z+b}if(f>=1){let b=`${f}h`;if(f<3){const z=Math.floor(o-f*60);z>0&&(b+=` ${z}m`)}return Z+b}if(v>=1){let b=`${v}m`;if(v<5){const z=Math.floor(c-v*60);z>0&&(b+=` ${z}s`)}return Z+b}return`${Z}${S}s`}mult(e){return new O(me(this.valueOf(),e))}div(e){return new O(sr(this.valueOf(),e))}get days(){return Number(this.valueOf())/Number(O.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(O.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(O.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(O.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(O.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(O.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new O(e).valueOf()}add(e){return new O(this.valueOf()+new O(e).valueOf())}sub(e){return new O(this.valueOf()-new O(e).valueOf())}static nanoseconds(e=1){return new O(e)}static NANOSECOND=O.nanoseconds(1);static microseconds(e=1){return O.nanoseconds(me(e,1e3))}static MICROSECOND=O.microseconds(1);static milliseconds(e=1){return O.microseconds(me(e,1e3))}static MILLISECOND=O.milliseconds(1);static seconds(e=1){return O.milliseconds(me(e,1e3))}static SECOND=O.seconds(1);static minutes(e=1){return O.seconds(me(e,60))}static MINUTE=O.minutes(1);static hours(e){return O.minutes(me(e,60))}static HOUR=O.hours(1);static days(e){return O.hours(me(e,24))}static DAY=O.days(1);static MAX=new O(_r);static MIN=new O(0);static ZERO=new O(0);static z=i.z.union([i.z.object({value:i.z.bigint()}).transform(e=>new O(e.value)),i.z.string().transform(e=>new O(BigInt(e))),i.z.number().transform(e=>new O(e)),i.z.bigint().transform(e=>new O(e)),i.z.instanceof(O),i.z.instanceof(p).transform(e=>new O(e)),i.z.custom(e=>e instanceof re).transform(e=>new O(e))])};class re extends Nt{constructor(e){he(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new re(e).valueOf()}get period(){return I.seconds(1/this.valueOf())}sampleCount(e){return new I(e).seconds*this.valueOf()}byteCount(e,r){return this.sampleCount(e)*new Q(r).valueOf()}span(e){return I.seconds(e/this.valueOf())}byteSpan(e,r){return this.span(e.valueOf()/new Q(r).valueOf())}add(e){return new re(St(this.valueOf(),new re(e).valueOf()))}sub(e){return new re(Ue(this.valueOf(),new re(e).valueOf()))}mult(e){return new re(me(this.valueOf(),e))}div(e){return new re(sr(this.valueOf(),e))}static hz(e){return new re(e)}static khz(e){return re.hz(e*1e3)}static z=i.z.union([i.z.number().transform(e=>new re(e)),i.z.instanceof(re)])}let Q=class se extends Nt{constructor(e){he(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new vt(e*this.valueOf())}add(e){return new se(St(this.valueOf(),new se(e).valueOf()))}sub(e){return new se(Ue(this.valueOf(),new se(e).valueOf()))}mult(e){return new se(me(this.valueOf(),e))}div(e){return new se(sr(this.valueOf(),e))}static UNKNOWN=new se(0);static BIT128=new se(16);static BIT64=new se(8);static BIT32=new se(4);static BIT16=new se(2);static BIT8=new se(1);static z=i.z.union([i.z.number().transform(e=>new se(e)),i.z.instanceof(se)])},P=class Oe{start;end;constructor(e,r){typeof e=="object"&&"start"in e?(this.start=new p(e.start),this.end=new p(e.end)):(this.start=new p(e),this.end=new p(r))}get span(){return new I(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.start.isZero&&this.end.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new Oe(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,r=I.ZERO){if(r.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let n=this.start.sub(e.start).valueOf(),s=this.end.sub(e.end).valueOf();return n<0&&(n=-n),s<0&&(s=-s),n<=r.valueOf()&&s<=r.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.toString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,r=I.ZERO){e=e.makeValid();const n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;const s=p.max(n.start,e.start),a=p.min(n.end,e.end);return a.before(s)?!1:new I(a.sub(s)).greaterThanOrEqual(r)}contains(e){return e instanceof Oe?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const r=new Oe(this.start,this.end);return e.start.after(this.start)&&(r.start=e.start),e.start.after(this.end)&&(r.end=e.start),e.end.before(this.end)&&(r.end=e.end),e.end.before(this.start)&&(r.start=e.end),r}static max(...e){return new Oe(p.min(...e.map(r=>r.start)),p.max(...e.map(r=>r.end)))}static MAX=new Oe(p.MIN,p.MAX);static ZERO=new Oe(p.ZERO,p.ZERO);static z=i.z.union([i.z.object({start:p.z,end:p.z}).transform(e=>new Oe(e.start,e.end)),i.z.instanceof(Oe)]);static sort(e,r){return p.sort(e.start,r.start)||p.sort(e.end,r.end)}static simplify(e){return e.map(r=>r.makeValid()).sort((r,n)=>Oe.sort(r,n)).reduce((r,n)=>{if(n.span.isZero)return r;if(r.length===0)return r.push(n),r;const s=r[r.length-1];return s.overlapsWith(n)||s.end.equals(n.start)?s.end=p.max(s.end,n.end):r.push(n),r},[])}},R=class g extends Nt{constructor(e){if(he(e)&&(e=e.value),e instanceof g||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const r=g.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(r==null)throw new Error(`unable to find data type for ${e.toString()}`);super(r.valueOf())}}get Array(){const e=g.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(r=>this.equals(r))}toString(e=!1){return e?g.SHORT_STRINGS.get(this.valueOf())??this.valueOf():this.valueOf()}get isVariable(){return this.equals(g.JSON)||this.equals(g.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(g.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=g.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(g.UINT8)||this.equals(g.UINT16)||this.equals(g.UINT32)||this.equals(g.UINT64)}get isSignedInteger(){return this.equals(g.INT8)||this.equals(g.INT16)||this.equals(g.INT32)||this.equals(g.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsignedInteger&&e.isSignedInteger?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(g.INT32)&&e.equals(g.FLOAT64)||this.equals(g.INT8)&&e.equals(g.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsignedInteger===e.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return g.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new g("unknown");static FLOAT64=new g("float64");static FLOAT32=new g("float32");static INT64=new g("int64");static INT32=new g("int32");static INT16=new g("int16");static INT8=new g("int8");static UINT64=new g("uint64");static UINT32=new g("uint32");static UINT16=new g("uint16");static UINT8=new g("uint8");static BOOLEAN=new g("boolean");static TIMESTAMP=new g("timestamp");static UUID=new g("uuid");static STRING=new g("string");static JSON=new g("json");static ARRAY_CONSTRUCTORS=new Map([[g.UINT8.toString(),Uint8Array],[g.UINT16.toString(),Uint16Array],[g.UINT32.toString(),Uint32Array],[g.UINT64.toString(),BigUint64Array],[g.FLOAT32.toString(),Float32Array],[g.FLOAT64.toString(),Float64Array],[g.INT8.toString(),Int8Array],[g.INT16.toString(),Int16Array],[g.INT32.toString(),Int32Array],[g.INT64.toString(),BigInt64Array],[g.TIMESTAMP.toString(),BigInt64Array],[g.STRING.toString(),Uint8Array],[g.JSON.toString(),Uint8Array],[g.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,g.UINT8],[Uint16Array.name,g.UINT16],[Uint32Array.name,g.UINT32],[BigUint64Array.name,g.UINT64],[Float32Array.name,g.FLOAT32],[Float64Array.name,g.FLOAT64],[Int8Array.name,g.INT8],[Int16Array.name,g.INT16],[Int32Array.name,g.INT32],[BigInt64Array.name,g.INT64]]);static DENSITIES=new Map([[g.UINT8.toString(),Q.BIT8],[g.UINT16.toString(),Q.BIT16],[g.UINT32.toString(),Q.BIT32],[g.UINT64.toString(),Q.BIT64],[g.FLOAT32.toString(),Q.BIT32],[g.FLOAT64.toString(),Q.BIT64],[g.INT8.toString(),Q.BIT8],[g.INT16.toString(),Q.BIT16],[g.INT32.toString(),Q.BIT32],[g.INT64.toString(),Q.BIT64],[g.TIMESTAMP.toString(),Q.BIT64],[g.STRING.toString(),Q.UNKNOWN],[g.JSON.toString(),Q.UNKNOWN],[g.UUID.toString(),Q.BIT128]]);static ALL=[g.UNKNOWN,g.FLOAT64,g.FLOAT32,g.INT64,g.INT32,g.INT16,g.INT8,g.UINT64,g.UINT32,g.UINT16,g.UINT8,g.TIMESTAMP,g.UUID,g.STRING,g.JSON];static SHORT_STRINGS=new Map([[g.UINT8.toString(),"u8"],[g.UINT16.toString(),"u16"],[g.UINT32.toString(),"u32"],[g.UINT64.toString(),"u64"],[g.INT8.toString(),"i8"],[g.INT16.toString(),"i16"],[g.INT32.toString(),"i32"],[g.INT64.toString(),"i64"],[g.FLOAT32.toString(),"f32"],[g.FLOAT64.toString(),"f64"],[g.BOOLEAN.toString(),"bool"],[g.TIMESTAMP.toString(),"ts"],[g.UUID.toString(),"uuid"],[g.STRING.toString(),"str"],[g.JSON.toString(),"json"]]);static BIG_INT_TYPES=[g.INT64,g.UINT64,g.TIMESTAMP];static z=i.z.union([i.z.string().transform(e=>new g(e)),i.z.instanceof(g)])},vt=class x extends Nt{constructor(e){he(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return he(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return he(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return he(e)&&(e=e.value),new x(St(this.valueOf(),e.valueOf()))}sub(e){return he(e)&&(e=e.value),new x(Ue(this.valueOf(),e.valueOf()))}mult(e){return new x(me(this.valueOf(),e))}div(e){return new x(sr(this.valueOf(),e))}truncate(e){return new x(Math.trunc(this.valueOf()/new x(e).valueOf())*new x(e).valueOf())}remainder(e){return x.bytes(this.valueOf()%new x(e).valueOf())}get gigabytes(){return this.valueOf()/x.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/x.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/x.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/x.TERABYTE.valueOf()}toString(){const e=this.truncate(x.TERABYTE),r=this.truncate(x.GIGABYTE),n=this.truncate(x.MEGABYTE),s=this.truncate(x.KILOBYTE),a=this.truncate(x.BYTE),o=e,c=r.sub(e),l=n.sub(r),u=s.sub(n),h=a.sub(s);let d="";return o.isZero||(d+=`${o.terabytes}TB `),c.isZero||(d+=`${c.gigabytes}GB `),l.isZero||(d+=`${l.megabytes}MB `),u.isZero||(d+=`${u.kilobytes}KB `),(!h.isZero||d==="")&&(d+=`${h.valueOf()}B`),d.trim()}static bytes(e=1){return new x(e)}static BYTE=new x(1);static kilobytes(e=1){return x.bytes(new x(e).valueOf()*1e3)}static KILOBYTE=x.kilobytes(1);static megabytes(e=1){return x.kilobytes(new x(e).valueOf()*1e3)}static MEGABYTE=x.megabytes(1);static gigabytes(e=1){return x.megabytes(new x(e).valueOf()*1e3)}static GIGABYTE=x.gigabytes(1);static terabytes(e){return x.gigabytes(new x(e).valueOf()*1e3)}static TERABYTE=x.terabytes(1);static ZERO=new x(0);static z=i.z.union([i.z.number().transform(e=>new x(e)),i.z.instanceof(x)]);get isZero(){return this.valueOf()===0}};i.z.object({start:i.z.number(),end:i.z.number()});i.z.union([i.z.instanceof(Uint8Array),i.z.instanceof(Uint16Array),i.z.instanceof(Uint32Array),i.z.instanceof(BigUint64Array),i.z.instanceof(Float32Array),i.z.instanceof(Float64Array),i.z.instanceof(Int8Array),i.z.instanceof(Int16Array),i.z.instanceof(Int32Array),i.z.instanceof(BigInt64Array)]);const Zo=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof p||t instanceof I||t instanceof Date},Ap=(t,e,r,n=0)=>t.usesBigInt&&!e.usesBigInt?Number(r)-Number(n):!t.usesBigInt&&e.usesBigInt?BigInt(r.valueOf())-BigInt(n.valueOf()):xr(r,-n),xr=(t,e)=>e==0?t:t==0?e:typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number"?t+e:Number(t)+Number(e),xp=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function Zp(t){return typeof t=="string"&&xp.test(t)}const X=[];for(let t=0;t<256;++t)X.push((t+256).toString(16).slice(1));function Cp(t,e=0){return(X[t[e+0]]+X[t[e+1]]+X[t[e+2]]+X[t[e+3]]+"-"+X[t[e+4]]+X[t[e+5]]+"-"+X[t[e+6]]+X[t[e+7]]+"-"+X[t[e+8]]+X[t[e+9]]+"-"+X[t[e+10]]+X[t[e+11]]+X[t[e+12]]+X[t[e+13]]+X[t[e+14]]+X[t[e+15]]).toLowerCase()}function Rp(t,e=0){const r=Cp(t,e);if(!Zp(r))throw TypeError("Stringified UUID is invalid");return r}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Co=(t,e)=>Rp(t,e),_e=-1,Gn={[Symbol.iterator]:()=>Gn,next:()=>({done:!0,value:void 0})},_p=i.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer),jp=i.z.union([i.z.null(),i.z.undefined()]).transform(()=>new Uint8Array().buffer),Jn=10,Ro=(t,e)=>{if(t==="number"&&!e.isNumeric)throw new Error(`cannot convert series of type ${e.toString()} to number`);if(t==="bigint"&&!e.usesBigInt)throw new Error(`cannot convert series of type ${e.toString()} to bigint`)},_o="sy_x_telem_series";let Ae=class Pe{key;discriminator=_o;dataType;sampleOffset;gl;_data;timeRange=P.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=_e;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=i.z.object({timeRange:P.z.optional(),dataType:R.z,alignment:i.z.coerce.bigint().optional(),data:i.z.union([_p,jp,i.z.instanceof(ArrayBuffer),i.z.instanceof(Uint8Array)]),glBufferUsage:Ip.optional().default("static").optional()});static z=Pe.crudeZ.transform(e=>new Pe(e));constructor(e){Mp(e)&&(e={data:e}),e.data??=[];const{dataType:r,timeRange:n,sampleOffset:s=0,glBufferUsage:a="static",alignment:o=0n,alignmentMultiple:c=1n,key:l=xs(),data:u}=e;if(jo(u)){const f=u;this.key=f.key,this.dataType=f.dataType,this.sampleOffset=f.sampleOffset,this.gl=f.gl,this._data=f._data,this.timeRange=f.timeRange,this.alignment=f.alignment,this.alignmentMultiple=f.alignmentMultiple,this.cachedMin=f.cachedMin,this.cachedMax=f.cachedMax,this.writePos=f.writePos,this._refCount=f._refCount,this.cachedLength=f.cachedLength;return}const h=Zo(u),d=Array.isArray(u);if(r!=null)this.dataType=new R(r);else{if(u instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(d||h){let f=u;if(!h){if(u.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");f=u[0]}if(typeof f=="string")this.dataType=R.STRING;else if(typeof f=="number")this.dataType=R.FLOAT64;else if(typeof f=="bigint")this.dataType=R.INT64;else if(typeof f=="boolean")this.dataType=R.BOOLEAN;else if(f instanceof p||f instanceof Date||f instanceof p)this.dataType=R.TIMESTAMP;else if(typeof f=="object")this.dataType=R.JSON;else throw new Error(`cannot infer data type of ${typeof f} when constructing a Series from a JS array`)}else this.dataType=new R(u)}if(!d&&!h)this._data=u;else if(d&&u.length===0)this._data=new this.dataType.Array([]).buffer;else{let f=h?[u]:u;const v=f[0];(v instanceof p||v instanceof Date||v instanceof I)&&(f=f.map(S=>new p(S).valueOf())),this.dataType.equals(R.STRING)?(this.cachedLength=f.length,this._data=new TextEncoder().encode(`${f.join(`
8
+ `).map(c=>c.trim());if(n.length===0)return r!=null?r.parse({}):{};const a=n.split(",").map(c=>c.trim()),o={};return a.forEach(c=>{o[c]=[]}),s.forEach(c=>{const l=c.split(",").map(u=>u.trim());a.forEach((u,h)=>{const d=this.parseValue(l[h]);d!=null&&o[u].push(d)})}),r!=null?r.parse(o):o}parseValue(e){if(e==null||e.length===0)return null;const r=Number(e);return isNaN(r)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:r}},Ja=class{contentType="text/plain";encode(e){if(typeof e!="string")throw new Error("TextCodec.encode payload must be a string");return new TextEncoder().encode(e)}decode(e,r){const n=new TextDecoder().decode(e);return r!=null?r.parse(n):n}};const qt=new Ga,rd=new Ka,nd=new Ja,sd=[qt],it=Object.freeze(Object.defineProperty({__proto__:null,CSVCodec:Ka,CSV_CODEC:rd,ENCODERS:sd,JSONCodec:Ga,JSON_CODEC:qt,TEXT_CODEC:nd,TextCodec:Ja},Symbol.toStringTag,{value:"Module"})),Vn=t=>[...new Set(t)],id=(t,e,r=!0)=>{const n=new Map;return t.forEach(s=>{const a=e(s);if(n.has(a)){if(r)return;n.delete(a)}n.set(a,s)}),Array.from(n.values())},bi=Object.freeze(Object.defineProperty({__proto__:null,by:id,unique:Vn},Symbol.toStringTag,{value:"Module"})),he=t=>t!=null&&typeof t=="object"&&"value"in t;let Ot=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const ad=t=>t!=null&&typeof t=="object"&&"toString"in t,nr=(t,e=!1)=>{const r=ad(t)?"stringer":typeof t;let n;switch(r){case"string":n=(s,a)=>s.localeCompare(a);break;case"stringer":n=(s,a)=>s.toString().localeCompare(a.toString());break;case"number":n=(s,a)=>Number(s)-Number(a);break;case"bigint":n=(s,a)=>BigInt(s)-BigInt(a)>0n?1:-1;break;case"boolean":n=(s,a)=>Number(s)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${r}`),()=>-1}return e?Qa(n):n},od=(t,e,r)=>{const n=nr(e[t],r);return(s,a)=>n(s[t],a[t])},cd=(t,e)=>t.length!==e.length?t.length-e.length:t.every((r,n)=>r===e[n])?0:-1,Xa=(t,e)=>{if(t.length!==e.length)return t.length-e.length;if(t.length===0)return 0;const r=nr(t[0]),n=[...t].sort(r),s=[...e].sort(r);return n.every((a,o)=>a===s[o])?0:-1},ud=(t,e)=>{const r=Vn(t),n=Vn(e);return Xa(r,n)},ld=(t,e)=>t===e?0:t==="first"&&e==="last"?1:-1,Qa=t=>(e,r)=>t(r,e),$t=0,kr=-1,xr=1,eo=t=>t<$t,to=t=>t>$t,hd=t=>t>=$t,ro=t=>t===$t,fd=(t,e)=>{const r=/([a-zA-Z]+)|(\d+)/g,n=t.replace(/[\s_.-]+/g,"").match(r),s=e.replace(/[\s_.-]+/g,"").match(r);if(!n||!s)return 0;for(let a=0;a<Math.min(n.length,s.length);a++){const o=n[a],c=s[a];if(isNaN(Number(o))&&isNaN(Number(c))){const l=o.localeCompare(c);if(l!==0)return l}else if(!isNaN(Number(o))&&!isNaN(Number(c))){const l=Number(o)-Number(c);if(l!==0)return l}else return isNaN(Number(o))?-1:1}return n.length-s.length},Kr=i.z.tuple([i.z.number(),i.z.number()]);i.z.tuple([i.z.bigint(),i.z.bigint()]);const no=i.z.object({width:i.z.number(),height:i.z.number()}),dd=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),pd=["width","height"];i.z.enum(pd);const yd=["start","center","end"],md=["signedWidth","signedHeight"];i.z.enum(md);const Ft=i.z.object({x:i.z.number(),y:i.z.number()}),so=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),io=["x","y"],ao=i.z.enum(io),Ts=["top","right","bottom","left"],gd=i.z.enum(Ts),oo=["left","right"],zs=i.z.enum(oo),co=["top","bottom"],Es=i.z.enum(co),Ns=["center"],Yn=i.z.enum(Ns),wd=[...Ts,...Ns],Os=i.z.enum(wd);i.z.enum(yd);const bd=["first","last"];i.z.enum(bd);const vd=i.z.object({lower:i.z.number(),upper:i.z.number()}),Td=i.z.object({lower:i.z.bigint(),upper:i.z.bigint()});i.z.union([vd,Kr]);i.z.union([Td,Kr]);i.z.enum([...ao.options,...Os.options]);i.z.enum(["x","left","right"]);i.z.enum(["y","top","bottom"]);const zd=i.z.union([ao,Os,i.z.instanceof(String)]),St=t=>(e,r)=>{if(typeof e=="bigint"){if(jr(r))return t(e,BigInt(r));const n=t(Number(e),Number(r));return typeof n=="number"?BigInt(Math.round(n)):n}return t(Number(e),Number(r))},Le=St((t,e)=>t-e),It=St((t,e)=>t+e),Ed=(t,e,r=1e-4)=>Math.abs(t-e)<r,Hn=(t,e)=>{const r=typeof t=="bigint",n=typeof e=="bigint";return r&&n?t===e:r&&jr(e)?t===BigInt(e):n&&jr(t)?e===BigInt(t):t===e},Nd=t=>{const e=10**Math.floor(Math.log10(t));return Math.round(t/e)*e},uo=St((t,e)=>t<=e?t:e),jr=t=>typeof t=="bigint"?!0:Number.isInteger(t),Od=St((t,e)=>t>=e?t:e),lo=t=>typeof t=="bigint"?t<0n?-t:t:t<0?-t:t,me=St((t,e)=>t*e),sr=St((t,e)=>t/e),K=(t,e,r)=>{const n={};if(typeof e=="object"&&(r=e,e=void 0),r={makeValid:!0,...r},typeof t=="number"||typeof t=="bigint")e!=null?(n.lower=t,n.upper=e):(n.lower=typeof t=="bigint"?0n:0,n.upper=t);else if(Array.isArray(t)){if(t.length!==2)throw new Error("bounds: expected array of length 2");[n.lower,n.upper]=t}else n.lower=t.lower,n.upper=t.upper;return r?.makeValid?$d(n):n},$d=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t,vi=(t,e)=>{const r=K(t);return e<r.lower?r.lower:e>=r.upper?r.upper-(typeof r.upper=="number"?1:1n):e},Tr=(t,e)=>{const r=K(t);if(typeof e=="number"||typeof e=="bigint")return e>=r.lower&&e<r.upper;const n=K(e);return n.lower>=r.lower&&n.upper<=r.upper},ho=t=>{const e=K(t);return e.upper-e.lower},Sd=t=>({lower:Math.min(...t.map(e=>K(e).lower)),upper:Math.max(...t.map(e=>K(e).upper))}),Id=(t,e,r)=>{const n=t.map(c=>K(c)),s=r>0?1:r<0?-1:0;if(s===0)return e;let a=r,o=e;for(;Hn(a,0)===!1;){const c=n.findIndex(l=>s>0?o>=l.lower&&o<l.upper:o>l.lower&&o<=l.upper);if(c!==-1){const l=n[c];let u;if(s>0?u=Le(l.upper,o):u=Le(o,l.lower),u>0){const h=uo(lo(a),u);if(o=It(o,s>0?h:-h),a=Le(a,s>0?h:-h),Hn(a,0))return o;continue}}if(s>0){const l=n.filter(u=>u.lower>o);if(l.length>0)o=l[0].lower;else return o}else{const l=n.filter(u=>u.upper<o);if(l.length>0)o=l[l.length-1].upper;else return o}}return o},Ad=(t,e,r)=>{const n=t.map(o=>K(o));if(e===r)return typeof e=="bigint"?0n:0;const s=e<r?K([e,r]):K([r,e]);let a=typeof e=="bigint"?0n:0;for(const o of n){const c=o.lower>s.lower?o.lower:s.lower,l=o.upper<s.upper?o.upper:s.upper;if(c<l){const u=l-c;a=a+u}}return a},kd=zs,xd=Es,Zd=Yn,Cd={top:"bottom",right:"left",bottom:"top",left:"right",center:"center"},Rd={top:"left",right:"top",bottom:"right",left:"bottom",center:"center"},_d=zd,Fe=t=>t instanceof String||!io.includes(t)?t:t==="x"?"left":"top",jd=t=>Cd[Fe(t)],Md=t=>Rd[Fe(t)],Vt=t=>{const e=Fe(t);return e==="top"||e==="bottom"?"y":"x"},Dd=i.z.object({x:zs.or(Yn),y:Es.or(Yn)}),fo=i.z.object({x:zs,y:Es}),$s=Object.freeze({x:"left",y:"top"}),po=Object.freeze({x:"right",y:"top"}),yo=Object.freeze({x:"left",y:"bottom"}),mo=Object.freeze({x:"right",y:"bottom"}),Ss=Object.freeze({x:"center",y:"center"}),go=Object.freeze({x:"center",y:"top"}),wo=Object.freeze({x:"center",y:"bottom"}),bo=Object.freeze({x:"right",y:"center"}),vo=Object.freeze({x:"left",y:"center"}),Pd=Object.freeze([vo,bo,go,wo,$s,po,yo,mo,Ss]),To=(t,e)=>t.x===e.x&&t.y===e.y,Ud=(t,e)=>{if(typeof e=="object"){let r=!0;return"x"in e&&(t.x===e.x||(r=!1)),"y"in e&&(t.y===e.y||(r=!1)),r}return t.x===e||t.y===e},Ld=t=>[t.x,t.y],Zr=t=>Vt(Fe(t))==="x",Bd=t=>Vt(Fe(t))==="y",qd=t=>`${t.x}${Ha(t.y)}`,Fd=(t,e)=>{let r,n;if(typeof t=="object"&&"x"in t?(r=t.x,n=t.y):(r=Fe(t),n=Fe(e??t)),Vt(r)===Vt(n)&&r!=="center"&&n!=="center")throw new Error(`[XYLocation] - encountered two locations with the same direction: ${r.toString()} - ${n.toString()}`);const s={...Ss};return r==="center"?Zr(n)?[s.x,s.y]=[n,r]:[s.x,s.y]=[r,n]:n==="center"?Zr(r)?[s.x,s.y]=[r,n]:[s.x,s.y]=[n,r]:Zr(r)?[s.x,s.y]=[r,n]:[s.x,s.y]=[n,r],s},Vd=Object.freeze(Object.defineProperty({__proto__:null,BOTTOM_CENTER:wo,BOTTOM_LEFT:yo,BOTTOM_RIGHT:mo,CENTER:Ss,CENTER_LEFT:vo,CENTER_LOCATIONS:Ns,CENTER_RIGHT:bo,OUTER_LOCATIONS:Ts,TOP_CENTER:go,TOP_LEFT:$s,TOP_RIGHT:po,XY_LOCATIONS:Pd,X_LOCATIONS:oo,Y_LOCATIONS:co,center:Zd,construct:Fe,constructXY:Fd,corner:fo,crude:_d,direction:Vt,isX:Zr,isY:Bd,location:Os,outer:gd,rotate90:Md,swap:jd,x:kd,xy:Dd,xyCouple:Ld,xyEquals:To,xyMatches:Ud,xyToString:qd,y:xd},Symbol.toStringTag,{value:"Module"})),Wn=i.z.union([i.z.number(),Ft,Kr,no,dd,so]),M=(t,e)=>{if(typeof t=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return t==="x"?{x:e,y:0}:{x:0,y:e}}return typeof t=="number"?{x:t,y:e??t}:Array.isArray(t)?{x:t[0],y:t[1]}:"signedWidth"in t?{x:t.signedWidth,y:t.signedHeight}:"clientX"in t?{x:t.clientX,y:t.clientY}:"width"in t?{x:t.width,y:t.height}:{x:t.x,y:t.y}},rt=Object.freeze({x:0,y:0}),Yd=Object.freeze({x:1,y:1}),Hd=Object.freeze({x:1/0,y:1/0}),Wd=Object.freeze({x:NaN,y:NaN}),zo=(t,e,r=0)=>{const n=M(t),s=M(e);return r===0?n.x===s.x&&n.y===s.y:Math.abs(n.x-s.x)<=r&&Math.abs(n.y-s.y)<=r},Gd=t=>zo(t,rt),Is=(t,e,r)=>{const n=M(t),s=M(e,r);return{x:n.x*s.x,y:n.y*s.y}},Eo=(t,e)=>{const r=M(t);return{x:r.x+e,y:r.y}},No=(t,e)=>{const r=M(t);return{x:r.x,y:r.y+e}},Oo=(t,e,r,...n)=>{if(typeof e=="string"){if(typeof r!="number")throw new Error("The value must be a number.");return e==="x"?Eo(t,r):No(t,r)}if(typeof e=="object"&&"x"in e&&typeof e.x=="string"){const s=M(r),a=M(t);return e.x==="left"?s.x=-s.x:e.x==="center"&&(s.x=0),e.y==="top"?s.y=-s.y:e.y==="center"&&(s.y=0),{x:a.x+s.x,y:a.y+s.y}}return[t,e,r??rt,...n].reduce((s,a)=>{const o=M(a);return{x:s.x+o.x,y:s.y+o.y}},rt)},Kd=(t,e,r)=>{const n=M(t);return e==="x"?{x:r,y:n.y}:{x:n.x,y:r}},Jd=(t,e)=>{const r=M(t),n=M(e);return Math.sqrt((r.x-n.x)**2+(r.y-n.y)**2)},Xd=(t,e)=>{const r=M(t),n=M(e);return{x:n.x-r.x,y:n.y-r.y}},Qd=t=>{const e=M(t);return Number.isNaN(e.x)||Number.isNaN(e.y)},ep=t=>{const e=M(t);return Number.isFinite(e.x)&&Number.isFinite(e.y)},tp=t=>{const e=M(t);return[e.x,e.y]},rp=t=>{const e=M(t);return{left:e.x,top:e.y}},np=(t,e=0)=>{const r=M(t);return{x:Number(r.x.toFixed(e)),y:Number(r.y.toFixed(e))}},Mt=(t,e)=>{const r=M(t),n=M(e);return{x:r.x-n.x,y:r.y-n.y}},Dt=t=>{const e=M(t),r=Math.hypot(e.x,e.y);return r===0?{x:0,y:0}:{x:-e.y/r,y:e.x/r}},$o=t=>{const e=M(t),r=Math.hypot(e.x,e.y);return r===0?{x:0,y:0}:{x:e.x/r,y:e.y/r}},So=(...t)=>{const e=t.reduce((r,n)=>Oo(r,n),rt);return Is(e,1/t.length)},sp=(t,e)=>{const r=[];for(let n=0;n<t.length;n++){const s=t[n];let a,o,c,l;if(n===0){const u=t[n+1],h=Mt(u,s);o=Dt(h),c=o,l=e}else if(n===t.length-1){const u=t[n-1],h=Mt(s,u);a=Dt(h),c=a,l=e}else{const u=t[n-1],h=t[n+1],d=Mt(s,u),f=Mt(h,s);a=Dt(d),o=Dt(f);const v=Math.acos((d.x*f.x+d.y*f.y)/(Math.hypot(d.x,d.y)*Math.hypot(f.x,f.y))),S=Math.sin(v/2);S===0?l=e:l=e/S,c=$o(So(a,o))}r.push(Is(c,l))}return r},ip=t=>{const e=M(t);return{x:e.y,y:e.x}},ap=t=>{const e=M(t);return{x:Math.round(e.x),y:Math.round(e.y)}},op=t=>{const e=M(t);return{x:1/e.x,y:1/e.y}},As=Object.freeze(Object.defineProperty({__proto__:null,INFINITY:Hd,NAN:Wd,ONE:Yd,ZERO:rt,average:So,calculateMiters:sp,clientXY:so,construct:M,couple:tp,crudeZ:Wn,css:rp,distance:Jd,equals:zo,isFinite:ep,isNan:Qd,isZero:Gd,normal:Dt,normalize:$o,reciprocal:op,round:ap,scale:Is,set:Kd,sub:Mt,swap:ip,translate:Oo,translateX:Eo,translateY:No,translation:Xd,truncate:np,xy:Ft},Symbol.toStringTag,{value:"Module"})),zr=i.z.union([i.z.number(),i.z.string()]);i.z.object({top:zr,left:zr,width:zr,height:zr});i.z.object({left:i.z.number(),top:i.z.number(),right:i.z.number(),bottom:i.z.number()});i.z.object({one:Ft,two:Ft,root:fo});const ks=(t,e,r=0,n=0,s)=>{const a={one:{...rt},two:{...rt},root:s??$s};if(typeof t=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:t,y:e},a.two={x:a.one.x+r,y:a.one.y+n},a}return"one"in t&&"two"in t&&"root"in t?{...t,root:s??t.root}:("getBoundingClientRect"in t&&(t=t.getBoundingClientRect()),"left"in t?(a.one={x:t.left,y:t.top},a.two={x:t.right,y:t.bottom},a):(a.one=t,e==null?a.two={x:a.one.x+r,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+r}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},En=t=>{const e=ks(t);return{lower:e.one.x,upper:e.two.x}},Nn=t=>{const e=ks(t);return{lower:e.one.y,upper:e.two.y}},cp=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t,up=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([no,up,Ft,Kr]);const lp=(t,e,r)=>e!==void 0&&t<e?e:r!==void 0&&t>r?r:t;i.z.object({offset:Wn,scale:Wn});i.z.object({offset:i.z.number(),scale:i.z.number()});const hp=t=>(e,r,n,s)=>r==="dimension"?[e,n]:[e,s?n-t:n+t],fp=t=>(e,r,n,s)=>[e,s?n/t:n*t],dp=t=>(e,r,n)=>{if(e===null)return[t,n];const{lower:s,upper:a}=e,{lower:o,upper:c}=t,l=a-s,u=c-o;if(r==="dimension")return[t,n*(u/l)];const h=(n-s)*(u/l)+o;return[t,h]},pp=t=>(e,r,n)=>[t,n],yp=()=>(t,e,r)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,r];const{lower:n,upper:s}=t;return[t,s-(r-n)]},mp=t=>(e,r,n)=>{const{lower:s,upper:a}=t;return n=lp(n,s,a),[e,n]};let Ti=class ft{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new ft().translate(e)}static magnify(e){return new ft().magnify(e)}static scale(e,r){return new ft().scale(e,r)}translate(e){const r=this.new(),n=hp(e);return n.type="translate",r.ops.push(n),r}magnify(e){const r=this.new(),n=fp(e);return n.type="magnify",r.ops.push(n),r}scale(e,r){const n=K(e,r),s=this.new(),a=dp(n);return a.type="scale",s.ops.push(a),s}clamp(e,r){const n=K(e,r),s=this.new(),a=mp(n);return a.type="clamp",s.ops.push(a),s}reBound(e,r){const n=K(e,r),s=this.new(),a=pp(n);return a.type="re-bound",s.ops.push(a),s}invert(){const e=yp();e.type="invert";const r=this.new();return r.ops.push(e),r}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new ft;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,r){return this.currBounds=null,this.ops.reduce(([n,s],a)=>a(n,e,s,this.reversed),[null,r])[1]}reverse(){const e=this.new();e.ops.reverse();const r=[];return e.ops.forEach((n,s)=>{if(n.type==="scale"||r.some(([o,c])=>s>=o&&s<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>s);a!==-1&&r.push([s,a])}),r.forEach(([n,s])=>{const a=e.ops.slice(n,s);a.unshift(e.ops[s]),e.ops.splice(n,s-n+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new ft},MS=class Ne{x;y;currRoot;constructor(e=new Ti,r=new Ti,n=null){this.x=e,this.y=r,this.currRoot=n}static translate(e,r){return new Ne().translate(e,r)}static translateX(e){return new Ne().translateX(e)}static translateY(e){return new Ne().translateY(e)}static clamp(e){return new Ne().clamp(e)}static magnify(e){return new Ne().magnify(e)}static scale(e){return new Ne().scale(e)}static reBound(e){return new Ne().reBound(e)}translate(e,r){const n=M(e,r),s=this.copy();return s.x=this.x.translate(n.x),s.y=this.y.translate(n.y),s}translateX(e){const r=this.copy();return r.x=this.x.translate(e),r}translateY(e){const r=this.copy();return r.y=this.y.translate(e),r}magnify(e){const r=this.copy();return r.x=this.x.magnify(e.x),r.y=this.y.magnify(e.y),r}scale(e){const r=this.copy();if(cp(e)){const n=this.currRoot;return r.currRoot=e.root,n!=null&&!To(n,e.root)&&(n.x!==e.root.x&&(r.x=r.x.invert()),n.y!==e.root.y&&(r.y=r.y.invert())),r.x=r.x.scale(En(e)),r.y=r.y.scale(Nn(e)),r}return r.x=r.x.scale(e.width),r.y=r.y.scale(e.height),r}reBound(e){const r=this.copy();return r.x=this.x.reBound(En(e)),r.y=this.y.reBound(Nn(e)),r}clamp(e){const r=this.copy();return r.x=this.x.clamp(En(e)),r.y=this.y.clamp(Nn(e)),r}copy(){const e=new Ne;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return ks(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}static IDENTITY=new Ne},Io=(t,e=21)=>(r=e)=>{let n="",s=r|0;for(;s--;)n+=t[Math.random()*t.length|0];return n};const Ao="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",gp=`0123456789${Ao}`,ko=11,wp=Io(Ao,1),bp=Io(gp,ko-1),xs=()=>`${wp()}${bp()}`,vp=Object.freeze(Object.defineProperty({__proto__:null,LENGTH:ko,create:xs},Symbol.toStringTag,{value:"Module"})),Tp=(t,e)=>r=>r instanceof e||typeof r=="object"&&r!==null&&"discriminator"in r&&r.discriminator===t,zp=i.z.enum(["static","dynamic"]),Ep=2**8-1,Np=2**16-1,Op=2**32-1,$p=2n**64n-1n,Sp=2**64-1,Ip=-128,Ap=2**7-1,kp=-32768,xp=2**15-1,Zp=-2147483648,Cp=2**31-1,Rp=-(2n**63n),Mr=2n**63n-1n,_p=-9223372036854776e3,xo=2**63-1,zi=365,Er=30,jp=i.z.union([i.z.tuple([i.z.int()]),i.z.tuple([i.z.int(),i.z.int().min(1).max(12)]),i.z.tuple([i.z.int(),i.z.int().min(1).max(12),i.z.int().min(1).max(31)])]),Zo=(t,e)=>{const r=new p(e);if(![I.DAY,I.HOUR,I.MINUTE,I.SECOND,I.MILLISECOND,I.MICROSECOND,I.NANOSECOND].some(s=>s.equals(r)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=t.valueOf()%r.valueOf();return t instanceof p?new p(n):new I(n)};class p extends Ot{constructor(e,r="UTC"){if(e==null)super(p.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*p.MILLISECOND.valueOf());else if(typeof e=="string")super(p.parseDateTimeString(e,r).valueOf());else if(Array.isArray(e))super(p.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),r==="local"&&(n=p.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e===xo?e=Mr:e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=p.MAX:e=p.MIN)),he(e)&&(e=e.value),super(BigInt(e.valueOf())+n)}}static parseDate([e=1970,r=1,n=1]){const s=new Date(e,r-1,n,0,0,0,0);return new p(BigInt(s.getTime())*p.MILLISECOND.valueOf()).truncate(p.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,r="UTC"){const[n,s,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let l=p.hours(parseInt(n??"00")).add(p.minutes(parseInt(s??"00"))).add(p.seconds(parseInt(o??"00"))).add(p.milliseconds(parseInt(c??"00")));return r==="local"&&(l=l.add(p.utcOffset)),l.valueOf()}static parseDateTimeString(e,r="UTC"){if(!e.includes("/")&&!e.includes("-"))return p.parseTimeString(e,r);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new p(BigInt(n.getTime())*p.MILLISECOND.valueOf(),r).valueOf()}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(p.utcOffset).date().toISOString()}timeString(e=!1,r="UTC"){const n=this.toISOString(r);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),r=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${r} ${n}`}static get utcOffset(){return new I(BigInt(new Date().getTimezoneOffset())*p.MINUTE.valueOf())}static since(e){return new p().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new p(e).valueOf()}span(e){return this.range(e).span}range(e){return new D(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new p(e).valueOf()}afterEq(e){return this.valueOf()>=new p(e).valueOf()}before(e){return this.valueOf()<new p(e).valueOf()}beforeEq(e){return this.valueOf()<=new p(e).valueOf()}add(e){return new p(It(this.valueOf(),new I(e).valueOf()))}sub(e){return new p(Le(this.valueOf(),new I(e).valueOf()))}get hours(){return Number(this.valueOf())/Number(I.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(I.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(I.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(I.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(p.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(p.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}setYear(e){const r=this.date();return r.setUTCFullYear(e),new p(r)}get month(){return this.date().getUTCMonth()}setMonth(e){const r=this.date();return r.setUTCMonth(e),new p(r)}get day(){return this.date().getUTCDate()}setDay(e){const r=this.date();return r.setUTCDate(e),new p(r)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(e){const r=this.date();return r.setHours(e),new p(r)}setHour(e){const r=this.date();return r.setUTCHours(e),new p(r)}get minute(){return this.date().getUTCMinutes()}setMinute(e){const r=this.date();return r.setUTCMinutes(e),new p(r)}get second(){return this.date().getUTCSeconds()}setSecond(e){const r=this.date();return r.setUTCSeconds(e),new p(r)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const r=this.date();return r.setUTCMilliseconds(e),new p(r)}toString(e="ISO",r="UTC"){switch(e){case"ISODate":return this.toISOString(r).slice(0,10);case"ISOTime":return this.toISOString(r).slice(11,23);case"time":return this.timeString(!1,r);case"preciseTime":return this.timeString(!0,r);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,r)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,r)}`;default:return this.toISOString(r)}}remainder(e){return Zo(this,e)}get isToday(){return this.truncate(I.DAY).equals(p.now().truncate(I.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new p(new Date)}static max(...e){let r=p.MIN;for(const n of e){const s=new p(n);s.after(r)&&(r=s)}return r}static min(...e){let r=p.MAX;for(const n of e){const s=new p(n);s.before(r)&&(r=s)}return r}static nanoseconds(e,r="UTC"){return new p(e,r)}static NANOSECOND=p.nanoseconds(1);static microseconds(e,r="UTC"){return p.nanoseconds(e*1e3,r)}static MICROSECOND=p.microseconds(1);static milliseconds(e,r="UTC"){return p.microseconds(e*1e3,r)}static MILLISECOND=p.milliseconds(1);static seconds(e,r="UTC"){return p.milliseconds(e*1e3,r)}static SECOND=p.seconds(1);static minutes(e,r="UTC"){return p.seconds(e*60,r)}static MINUTE=p.minutes(1);static hours(e,r="UTC"){return p.minutes(e*60,r)}static HOUR=p.hours(1);static days(e,r="UTC"){return p.hours(e*24,r)}static DAY=p.days(1);static MAX=new p(Mr);static MIN=new p(0);static ZERO=new p(0);static z=i.z.union([i.z.instanceof(p),i.z.object({value:i.z.bigint()}).transform(e=>new p(e.value)),i.z.string().transform(e=>new p(BigInt(e))),i.z.number().transform(e=>new p(e)),i.z.bigint().transform(e=>new p(e)),i.z.date().transform(e=>new p(e)),i.z.custom(e=>e instanceof I).transform(e=>new p(e)),jp.transform(e=>new p(e))]);static sort(e,r){return Number(e.valueOf()-r.valueOf())}}let I=class O extends Ot{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),he(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof O?e:e instanceof ne?e.period:e instanceof p?new O(e):(he(e)&&(e=e.value),["number","bigint"].includes(typeof e)?O.seconds(e):new O(e))}static fromMilliseconds(e){return e instanceof O?e:e instanceof ne?e.period:e instanceof p?new O(e):(he(e)&&(e=e.value),["number","bigint"].includes(typeof e)?O.milliseconds(e):new O(e))}valueOf(){return this.value}lessThan(e){return this.valueOf()<new O(e).valueOf()}greaterThan(e){return this.valueOf()>new O(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new O(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new O(e).valueOf()}remainder(e){return Zo(this,e)}truncate(e){return new O(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(e="full"){if(e==="semantic")return this.toSemanticString();const r=this.truncate(O.DAY),n=this.truncate(O.HOUR),s=this.truncate(O.MINUTE),a=this.truncate(O.SECOND),o=this.truncate(O.MILLISECOND),c=this.truncate(O.MICROSECOND),l=this.truncate(O.NANOSECOND),u=r,h=n.sub(r),d=s.sub(n),f=a.sub(s),v=o.sub(a),S=c.sub(o),Z=l.sub(c);let b="";return u.isZero||(b+=`${u.days}d `),h.isZero||(b+=`${h.hours}h `),d.isZero||(b+=`${d.minutes}m `),f.isZero||(b+=`${f.seconds}s `),v.isZero||(b+=`${v.milliseconds}ms `),S.isZero||(b+=`${S.microseconds}µs `),Z.isZero||(b+=`${Z.nanoseconds}ns`),b.trim()}toSemanticString(){const e=this.valueOf()<0n?-this.valueOf():this.valueOf(),r=new O(e),n=this.valueOf()<0n;if(r.valueOf()===0n)return"0s";if(r.lessThan(O.SECOND))return"< 1s";const s=r.days,a=r.hours,o=r.minutes,c=r.seconds,l=Math.floor(s/zi),u=Math.floor(s/Er),h=Math.floor(s/7),d=Math.floor(s),f=Math.floor(a),v=Math.floor(o),S=Math.floor(c),Z=n?"-":"";if(l>=1){let b=`${l}y`;if(l<2){const z=Math.floor(s%zi/Er);z>0&&(b+=` ${z}mo`)}return Z+b}if(h>=1&&s<Er&&s%7===0){let b=`${h}w`;const z=Math.floor(s%7),A=Math.floor(a-h*7*24);return h<2&&(z>0?b+=` ${z}d`:A>0&&A<24&&(b+=` ${A}h`)),Z+b}if(u>=1){let b=`${u}mo`;if(u<3){const z=Math.floor(s%Er);z>0&&(b+=` ${z}d`)}return Z+b}if(h>=1){let b=`${h}w`;const z=Math.floor(s%7),A=Math.floor(a-h*7*24);return h<2&&(z>0?b+=` ${z}d`:A>0&&A<24&&(b+=` ${A}h`)),Z+b}if(d>=1){let b=`${d}d`;const z=Math.floor(a-d*24);return d<2&&z>0&&(b+=` ${z}h`),Z+b}if(f>=1){let b=`${f}h`;if(f<3){const z=Math.floor(o-f*60);z>0&&(b+=` ${z}m`)}return Z+b}if(v>=1){let b=`${v}m`;if(v<5){const z=Math.floor(c-v*60);z>0&&(b+=` ${z}s`)}return Z+b}return`${Z}${S}s`}mult(e){return new O(me(this.valueOf(),e))}div(e){return new O(sr(this.valueOf(),e))}get days(){return Number(this.valueOf())/Number(O.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(O.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(O.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(O.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(O.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(O.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new O(e).valueOf()}add(e){return new O(this.valueOf()+new O(e).valueOf())}sub(e){return new O(this.valueOf()-new O(e).valueOf())}static nanoseconds(e=1){return new O(e)}static NANOSECOND=O.nanoseconds(1);static microseconds(e=1){return O.nanoseconds(me(e,1e3))}static MICROSECOND=O.microseconds(1);static milliseconds(e=1){return O.microseconds(me(e,1e3))}static MILLISECOND=O.milliseconds(1);static seconds(e=1){return O.milliseconds(me(e,1e3))}static SECOND=O.seconds(1);static minutes(e=1){return O.seconds(me(e,60))}static MINUTE=O.minutes(1);static hours(e){return O.minutes(me(e,60))}static HOUR=O.hours(1);static days(e){return O.hours(me(e,24))}static DAY=O.days(1);static MAX=new O(Mr);static MIN=new O(0);static ZERO=new O(0);static z=i.z.union([i.z.object({value:i.z.bigint()}).transform(e=>new O(e.value)),i.z.string().transform(e=>new O(BigInt(e))),i.z.number().transform(e=>new O(e)),i.z.bigint().transform(e=>new O(e)),i.z.instanceof(O),i.z.instanceof(p).transform(e=>new O(e)),i.z.custom(e=>e instanceof ne).transform(e=>new O(e))])};class ne extends Ot{constructor(e){he(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new ne(e).valueOf()}get period(){return I.seconds(1/this.valueOf())}sampleCount(e){return new I(e).seconds*this.valueOf()}byteCount(e,r){return this.sampleCount(e)*new Q(r).valueOf()}span(e){return I.seconds(e/this.valueOf())}byteSpan(e,r){return this.span(e.valueOf()/new Q(r).valueOf())}add(e){return new ne(It(this.valueOf(),new ne(e).valueOf()))}sub(e){return new ne(Le(this.valueOf(),new ne(e).valueOf()))}mult(e){return new ne(me(this.valueOf(),e))}div(e){return new ne(sr(this.valueOf(),e))}static hz(e){return new ne(e)}static khz(e){return ne.hz(e*1e3)}static z=i.z.union([i.z.number().transform(e=>new ne(e)),i.z.instanceof(ne)])}let Q=class ie extends Ot{constructor(e){he(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new Tt(e*this.valueOf())}add(e){return new ie(It(this.valueOf(),new ie(e).valueOf()))}sub(e){return new ie(Le(this.valueOf(),new ie(e).valueOf()))}mult(e){return new ie(me(this.valueOf(),e))}div(e){return new ie(sr(this.valueOf(),e))}static UNKNOWN=new ie(0);static BIT128=new ie(16);static BIT64=new ie(8);static BIT32=new ie(4);static BIT16=new ie(2);static BIT8=new ie(1);static z=i.z.union([i.z.number().transform(e=>new ie(e)),i.z.instanceof(ie)])},D=class Oe{start;end;constructor(e,r){typeof e=="object"&&"start"in e?(this.start=new p(e.start),this.end=new p(e.end)):(this.start=new p(e),this.end=new p(r))}get span(){return new I(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.start.isZero&&this.end.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new Oe(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,r=I.ZERO){if(r.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let n=this.start.sub(e.start).valueOf(),s=this.end.sub(e.end).valueOf();return n<0&&(n=-n),s<0&&(s=-s),n<=r.valueOf()&&s<=r.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.toString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,r=I.ZERO){e=e.makeValid();const n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;const s=p.max(n.start,e.start),a=p.min(n.end,e.end);return a.before(s)?!1:new I(a.sub(s)).greaterThanOrEqual(r)}contains(e){return e instanceof Oe?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const r=new Oe(this.start,this.end);return e.start.after(this.start)&&(r.start=e.start),e.start.after(this.end)&&(r.end=e.start),e.end.before(this.end)&&(r.end=e.end),e.end.before(this.start)&&(r.start=e.end),r}static max(...e){return new Oe(p.min(...e.map(r=>r.start)),p.max(...e.map(r=>r.end)))}static MAX=new Oe(p.MIN,p.MAX);static ZERO=new Oe(p.ZERO,p.ZERO);static z=i.z.union([i.z.object({start:p.z,end:p.z}).transform(e=>new Oe(e.start,e.end)),i.z.instanceof(Oe)]);static sort(e,r){return p.sort(e.start,r.start)||p.sort(e.end,r.end)}static simplify(e){return e.map(r=>r.makeValid()).sort((r,n)=>Oe.sort(r,n)).reduce((r,n)=>{if(n.span.isZero)return r;if(r.length===0)return r.push(n),r;const s=r[r.length-1];return s.overlapsWith(n)||s.end.equals(n.start)?s.end=p.max(s.end,n.end):r.push(n),r},[])}},R=class g extends Ot{constructor(e){if(he(e)&&(e=e.value),e instanceof g||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const r=g.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(r==null)throw new Error(`unable to find data type for ${e.toString()}`);super(r.valueOf())}}get Array(){const e=g.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(r=>this.equals(r))}toString(e=!1){return e?g.SHORT_STRINGS.get(this.valueOf())??this.valueOf():this.valueOf()}get isVariable(){return this.equals(g.JSON)||this.equals(g.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(g.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=g.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(g.UINT8)||this.equals(g.UINT16)||this.equals(g.UINT32)||this.equals(g.UINT64)}get isSignedInteger(){return this.equals(g.INT8)||this.equals(g.INT16)||this.equals(g.INT32)||this.equals(g.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsignedInteger&&e.isSignedInteger?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(g.INT32)&&e.equals(g.FLOAT64)||this.equals(g.INT8)&&e.equals(g.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsignedInteger===e.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return g.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new g("unknown");static FLOAT64=new g("float64");static FLOAT32=new g("float32");static INT64=new g("int64");static INT32=new g("int32");static INT16=new g("int16");static INT8=new g("int8");static UINT64=new g("uint64");static UINT32=new g("uint32");static UINT16=new g("uint16");static UINT8=new g("uint8");static BOOLEAN=new g("boolean");static TIMESTAMP=new g("timestamp");static UUID=new g("uuid");static STRING=new g("string");static JSON=new g("json");static ARRAY_CONSTRUCTORS=new Map([[g.UINT8.toString(),Uint8Array],[g.UINT16.toString(),Uint16Array],[g.UINT32.toString(),Uint32Array],[g.UINT64.toString(),BigUint64Array],[g.FLOAT32.toString(),Float32Array],[g.FLOAT64.toString(),Float64Array],[g.INT8.toString(),Int8Array],[g.INT16.toString(),Int16Array],[g.INT32.toString(),Int32Array],[g.INT64.toString(),BigInt64Array],[g.TIMESTAMP.toString(),BigInt64Array],[g.STRING.toString(),Uint8Array],[g.JSON.toString(),Uint8Array],[g.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,g.UINT8],[Uint16Array.name,g.UINT16],[Uint32Array.name,g.UINT32],[BigUint64Array.name,g.UINT64],[Float32Array.name,g.FLOAT32],[Float64Array.name,g.FLOAT64],[Int8Array.name,g.INT8],[Int16Array.name,g.INT16],[Int32Array.name,g.INT32],[BigInt64Array.name,g.INT64]]);static DENSITIES=new Map([[g.UINT8.toString(),Q.BIT8],[g.UINT16.toString(),Q.BIT16],[g.UINT32.toString(),Q.BIT32],[g.UINT64.toString(),Q.BIT64],[g.FLOAT32.toString(),Q.BIT32],[g.FLOAT64.toString(),Q.BIT64],[g.INT8.toString(),Q.BIT8],[g.INT16.toString(),Q.BIT16],[g.INT32.toString(),Q.BIT32],[g.INT64.toString(),Q.BIT64],[g.TIMESTAMP.toString(),Q.BIT64],[g.STRING.toString(),Q.UNKNOWN],[g.JSON.toString(),Q.UNKNOWN],[g.UUID.toString(),Q.BIT128]]);static ALL=[g.UNKNOWN,g.FLOAT64,g.FLOAT32,g.INT64,g.INT32,g.INT16,g.INT8,g.UINT64,g.UINT32,g.UINT16,g.UINT8,g.TIMESTAMP,g.UUID,g.STRING,g.JSON];static SHORT_STRINGS=new Map([[g.UINT8.toString(),"u8"],[g.UINT16.toString(),"u16"],[g.UINT32.toString(),"u32"],[g.UINT64.toString(),"u64"],[g.INT8.toString(),"i8"],[g.INT16.toString(),"i16"],[g.INT32.toString(),"i32"],[g.INT64.toString(),"i64"],[g.FLOAT32.toString(),"f32"],[g.FLOAT64.toString(),"f64"],[g.BOOLEAN.toString(),"bool"],[g.TIMESTAMP.toString(),"ts"],[g.UUID.toString(),"uuid"],[g.STRING.toString(),"str"],[g.JSON.toString(),"json"]]);static BIG_INT_TYPES=[g.INT64,g.UINT64,g.TIMESTAMP];static z=i.z.union([i.z.string().transform(e=>new g(e)),i.z.instanceof(g)])},Tt=class x extends Ot{constructor(e){he(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return he(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return he(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return he(e)&&(e=e.value),new x(It(this.valueOf(),e.valueOf()))}sub(e){return he(e)&&(e=e.value),new x(Le(this.valueOf(),e.valueOf()))}mult(e){return new x(me(this.valueOf(),e))}div(e){return new x(sr(this.valueOf(),e))}truncate(e){return new x(Math.trunc(this.valueOf()/new x(e).valueOf())*new x(e).valueOf())}remainder(e){return x.bytes(this.valueOf()%new x(e).valueOf())}get gigabytes(){return this.valueOf()/x.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/x.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/x.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/x.TERABYTE.valueOf()}toString(){const e=this.truncate(x.TERABYTE),r=this.truncate(x.GIGABYTE),n=this.truncate(x.MEGABYTE),s=this.truncate(x.KILOBYTE),a=this.truncate(x.BYTE),o=e,c=r.sub(e),l=n.sub(r),u=s.sub(n),h=a.sub(s);let d="";return o.isZero||(d+=`${o.terabytes}TB `),c.isZero||(d+=`${c.gigabytes}GB `),l.isZero||(d+=`${l.megabytes}MB `),u.isZero||(d+=`${u.kilobytes}KB `),(!h.isZero||d==="")&&(d+=`${h.valueOf()}B`),d.trim()}static bytes(e=1){return new x(e)}static BYTE=new x(1);static kilobytes(e=1){return x.bytes(new x(e).valueOf()*1e3)}static KILOBYTE=x.kilobytes(1);static megabytes(e=1){return x.kilobytes(new x(e).valueOf()*1e3)}static MEGABYTE=x.megabytes(1);static gigabytes(e=1){return x.megabytes(new x(e).valueOf()*1e3)}static GIGABYTE=x.gigabytes(1);static terabytes(e){return x.gigabytes(new x(e).valueOf()*1e3)}static TERABYTE=x.terabytes(1);static ZERO=new x(0);static z=i.z.union([i.z.number().transform(e=>new x(e)),i.z.instanceof(x)]);get isZero(){return this.valueOf()===0}};i.z.object({start:i.z.number(),end:i.z.number()});i.z.union([i.z.instanceof(Uint8Array),i.z.instanceof(Uint16Array),i.z.instanceof(Uint32Array),i.z.instanceof(BigUint64Array),i.z.instanceof(Float32Array),i.z.instanceof(Float64Array),i.z.instanceof(Int8Array),i.z.instanceof(Int16Array),i.z.instanceof(Int32Array),i.z.instanceof(BigInt64Array)]);const Co=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof p||t instanceof I||t instanceof Date},Mp=(t,e,r,n=0)=>t.usesBigInt&&!e.usesBigInt?Number(r)-Number(n):!t.usesBigInt&&e.usesBigInt?BigInt(r.valueOf())-BigInt(n.valueOf()):Cr(r,-n),Cr=(t,e)=>e==0?t:t==0?e:typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number"?t+e:Number(t)+Number(e),Dp=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function Pp(t){return typeof t=="string"&&Dp.test(t)}const X=[];for(let t=0;t<256;++t)X.push((t+256).toString(16).slice(1));function Up(t,e=0){return(X[t[e+0]]+X[t[e+1]]+X[t[e+2]]+X[t[e+3]]+"-"+X[t[e+4]]+X[t[e+5]]+"-"+X[t[e+6]]+X[t[e+7]]+"-"+X[t[e+8]]+X[t[e+9]]+"-"+X[t[e+10]]+X[t[e+11]]+X[t[e+12]]+X[t[e+13]]+X[t[e+14]]+X[t[e+15]]).toLowerCase()}function Lp(t,e=0){const r=Up(t,e);if(!Pp(r))throw TypeError("Stringified UUID is invalid");return r}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Ro=(t,e)=>Lp(t,e),je=-1,Gn={[Symbol.iterator]:()=>Gn,next:()=>({done:!0,value:void 0})},Bp=i.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer),qp=i.z.union([i.z.null(),i.z.undefined()]).transform(()=>new Uint8Array().buffer),Kn=10,_o=(t,e)=>{if(t==="number"&&!e.isNumeric)throw new Error(`cannot convert series of type ${e.toString()} to number`);if(t==="bigint"&&!e.usesBigInt)throw new Error(`cannot convert series of type ${e.toString()} to bigint`)},jo="sy_x_telem_series";let xe=class Ue{key;discriminator=jo;dataType;sampleOffset;gl;_data;timeRange=D.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=je;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=i.z.object({timeRange:D.z.optional(),dataType:R.z,alignment:i.z.coerce.bigint().optional(),data:i.z.union([Bp,qp,i.z.instanceof(ArrayBuffer),i.z.instanceof(Uint8Array)]),glBufferUsage:zp.optional().default("static").optional()});static z=Ue.crudeZ.transform(e=>new Ue(e));constructor(e){Fp(e)&&(e={data:e}),e.data??=[];const{dataType:r,timeRange:n,sampleOffset:s=0,glBufferUsage:a="static",alignment:o=0n,alignmentMultiple:c=1n,key:l=xs(),data:u}=e;if(Mo(u)){const f=u;this.key=f.key,this.dataType=f.dataType,this.sampleOffset=f.sampleOffset,this.gl=f.gl,this._data=f._data,this.timeRange=f.timeRange,this.alignment=f.alignment,this.alignmentMultiple=f.alignmentMultiple,this.cachedMin=f.cachedMin,this.cachedMax=f.cachedMax,this.writePos=f.writePos,this._refCount=f._refCount,this.cachedLength=f.cachedLength;return}const h=Co(u),d=Array.isArray(u);if(r!=null)this.dataType=new R(r);else{if(u instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(d||h){let f=u;if(!h){if(u.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");f=u[0]}if(typeof f=="string")this.dataType=R.STRING;else if(typeof f=="number")this.dataType=R.FLOAT64;else if(typeof f=="bigint")this.dataType=R.INT64;else if(typeof f=="boolean")this.dataType=R.BOOLEAN;else if(f instanceof p||f instanceof Date||f instanceof p)this.dataType=R.TIMESTAMP;else if(typeof f=="object")this.dataType=R.JSON;else throw new Error(`cannot infer data type of ${typeof f} when constructing a Series from a JS array`)}else this.dataType=new R(u)}if(!d&&!h)this._data=u;else if(d&&u.length===0)this._data=new this.dataType.Array([]).buffer;else{let f=h?[u]:u;const v=f[0];(v instanceof p||v instanceof Date||v instanceof I)&&(f=f.map(S=>new p(S).valueOf())),this.dataType.equals(R.STRING)?(this.cachedLength=f.length,this._data=new TextEncoder().encode(`${f.join(`
9
9
  `)}
10
- `).buffer):this.dataType.equals(R.JSON)?(this.cachedLength=f.length,this._data=new TextEncoder().encode(`${f.map(S=>Bt.encodeString(S)).join(`
10
+ `).buffer):this.dataType.equals(R.JSON)?(this.cachedLength=f.length,this._data=new TextEncoder().encode(`${f.map(S=>qt.encodeString(S)).join(`
11
11
  `)}
12
- `).buffer):this.dataType.usesBigInt&&typeof v=="number"?this._data=new this.dataType.Array(f.map(S=>BigInt(Math.round(S)))).buffer:!this.dataType.usesBigInt&&typeof v=="bigint"?this._data=new this.dataType.Array(f.map(Number)).buffer:this._data=new this.dataType.Array(f).buffer}this.key=l,this.alignment=o,this.alignmentMultiple=c,this.sampleOffset=s??0,this.timeRange=n??P.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:r,...n}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const s=new new R(r).Array(e),a=new Pe({data:s.buffer,dataType:r,...n});return a.writePos=0,a}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn("cannot release a series with a negative reference count")}write(e){if(!e.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===_e)return 0;const r=this.byteCapacity.valueOf()-this.writePos,n=e.subBytes(0,r);return this.writeToUnderlyingData(n),this.writePos+=n.byteLength.valueOf(),this.cachedLength!=null&&(this.cachedLength+=n.length,this.calculateCachedLength()),n.length}writeFixed(e){if(this.writePos===_e)return 0;const r=this.capacity-this.writePos,n=e.sub(0,r);return this.writeToUnderlyingData(n),this.cachedLength=void 0,this.maybeRecomputeMinMax(n),this.writePos+=n.length,n.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data=="object"&&"buffer"in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===_e?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){return this.dataType.isVariable?new TextDecoder().decode(this.underlyingData).split(`
13
- `).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(R.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(r=>e.parse(Bt.decodeString(r)))}get byteCapacity(){return new vt(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===_e?this.byteCapacity:this.dataType.isVariable?new vt(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===_e?this.byteCapacity.valueOf()/this.dataType.density.valueOf():this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const r=[0];return this.data.forEach((n,s)=>{n===Jn&&(e++,r.push(s+1))}),this._cachedIndexes=r,this.cachedLength=e,e}convert(e,r=0){if(this.dataType.equals(e))return this;const n=new e.Array(this.length);for(let s=0;s<this.length;s++)n[s]=Ap(this.dataType,e,this.data[s],r);return new Pe({data:n.buffer,dataType:e,timeRange:this.timeRange,sampleOffset:r,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(R.TIMESTAMP))this.cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMax=e.reduce((r,n)=>r>n?r:n)}else{const e=this.data;this.cachedMax=e.reduce((r,n)=>r>n?r:n)}return this.cachedMax}get max(){return this.calcMax()}calcMax(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this.cachedMax??=this.calcRawMax(),xr(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(R.TIMESTAMP))this.cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMin=e.reduce((r,n)=>r<n?r:n)}else{const e=this.data;this.cachedMin=e.reduce((r,n)=>r<n?r:n)}return this.cachedMin}get min(){return this.calcMin()}calcMin(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this.cachedMin??=this.calcRawMin(),xr(this.cachedMin,this.sampleOffset))}get bounds(){return J(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){const r=e.cachedMin??e.calcRawMin();r<this.cachedMin&&(this.cachedMin=r)}if(this.cachedMax!=null){const r=e.cachedMax??e.calcRawMax();r>this.cachedMax&&(this.cachedMax=r)}}atAlignment(e,r){const n=Number((e-this.alignment)/this.alignmentMultiple);if(n<0||n>=this.length){if(r===!0)throw new Error(`[series] - no value at index ${n}`);return}return this.at(n,r)}at(e,r=!1){if(this.dataType.isVariable)return this.atVariable(e,r??!1);if(this.dataType.equals(R.UUID))return this.atUUID(e,r);e<0&&(e=this.length+e);const n=this.data[e];if(n==null){if(r===!0)throw new Error(`[series] - no value at index ${e}`);return}return xr(n,this.sampleOffset)}atUUID(e,r){e<0&&(e=this.length+e);const n=Co(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(n==null){if(r)throw new Error(`[series] - no value at index ${e}`);return}return n}atVariable(e,r){let n=0,s=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],s=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let o=0;o<this.data.length;o++)if(this.data[o]===Jn){if(e===0){s=o;break}n=o+1,e--}if(s===0&&(s=this.data.length),n>=s||e>0){if(r)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(n,s);return this.dataType.equals(R.STRING)?new TextDecoder().decode(a):vs(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let r=0,n=this.length-1;const s=Hr(e);for(;r<=n;){const a=Math.floor((r+n)/2),o=s(this.at(a,!0),e);if(o===0)return a;o<0?r=a+1:n=a-1}return r}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(R.FLOAT32)&&!this.dataType.equals(R.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:r,bufferUsage:n,prevBuffer:s}=this.gl;if(r==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==s)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==_e){s===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(s).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=_e}as(e){return Ro(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:Ni(this.alignmentBounds.lower),upper:Ni(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return J(this.alignment,this.alignment+BigInt(this.length)*this.alignmentMultiple)}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new Dp(this);return this.dataType.equals(R.JSON)?new Pp(e):e}return this.dataType.equals(R.UUID)?new Up(this):new Lp(this)}slice(e,r){return this.sliceSub(!1,e,r)}sub(e,r){return this.sliceSub(!0,e,r)}subIterator(e,r){return new Ei(this,e,r??this.length)}subAlignmentIterator(e,r){const n=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),s=Math.ceil(Number(r-this.alignment)/Number(this.alignmentMultiple));return new Ei(this,n,s)}subBytes(e,r){if(e>=0&&(r==null||r>=this.byteLength.valueOf()))return this;const n=this.data.subarray(e,r);return new Pe({data:n,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,r,n){if(r<=0&&(n==null||n>=this.length))return this;let s;return e?s=this.data.subarray(r,n):s=this.data.slice(r,n),new Pe({data:s,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(r)})}reAlign(e){return new Pe({data:this.buffer,dataType:this.dataType,timeRange:P.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}toString(){let e=`Series(${this.dataType.toString()} ${this.length} [`;if(this.length<=10)e+=Array.from(this).map(r=>r.toString());else{for(let r=0;r<5;r++)e+=`${this.at(r)?.toString()}`,e+=",";e+="...,";for(let r=-5;r<0;r++)e+=this.at(r)?.toString(),r<-1&&(e+=",")}return e+="])",e}};const Mp=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Ae?!0:Zo(t),jo=pp(_o,Ae);let Ei=class{series;end;index;constructor(e,r,n){this.series=e;const s=J(0,e.length+1);this.end=vi(s,n),this.index=vi(s,r)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},Dp=class{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=e,this.index=0,this.decoder=new TextDecoder}next(){const e=this.index,r=this.series.data;for(;this.index<r.length&&r[this.index]!==Jn;)this.index++;const n=this.index;return e===n?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,n))})}},Pp=class Mo{wrapped;static schema=i.z.record(i.z.string(),i.z.unknown());constructor(e){this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:Bt.decodeString(e.value,Mo.schema)}}};class Up{series;index;data;density;constructor(e){if(!e.dataType.equals(R.UUID))throw new Error("cannot create a UUID series iterator for a non-UUID series");this.series=e,this.index=0,this.data=new Uint8Array(e.buffer),this.density=R.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=Co(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}let Lp=class{series;index;constructor(e){this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}};class Do{series;constructor(e=[]){if(e.length!==0){const r=e[0].dataType;for(let n=1;n<e.length;n++)if(!e[n].dataType.equals(r))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){return Ro(e,this.dataType),this}get dataType(){return this.series.length===0?R.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?P.ZERO:new P(this.series[0].timeRange.start,this.series[this.series.length-1].timeRange.end)}get alignment(){return this.series.length===0?0n:this.series[0].alignment}get alignmentBounds(){return this.series.length===0?J(0n,0n):J(this.series[0].alignmentBounds.lower,this.series[this.series.length-1].alignmentBounds.upper)}push(e){const r=()=>new Error(`cannot push a ${e.dataType.toString()} series to a ${this.dataType.toString()} multi-series`),n=e.dataType.equals(this.dataType);if(jo(e)){if(this.series.length!==0&&!n)throw r();this.series.push(e)}else{if(this.series.length!==0&&e.series.length!==0&&!n)throw r();this.series.push(...e.series)}}get length(){return this.series.reduce((e,r)=>e+r.length,0)}atAlignment(e,r){for(const n of this.series)if(br(n.alignmentBounds,e))return n.atAlignment(e,r);if(r)throw new Error(`[series] - no value at alignment ${e}`)}at(e,r=!1){e<0&&(e=this.length+e);for(const n of this.series){if(e<n.length)return n.at(e,r);e-=n.length}if(r)throw new Error(`[series] - no value at index ${e}`)}subIterator(e,r){return new On(this,e,r??this.length)}subAlignmentIterator(e,r){if(e>=this.alignmentBounds.upper||r<=this.alignmentBounds.lower)return Gn;let n=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(e<o.alignment)break;if(e>=o.alignmentBounds.upper)n+=o.length;else if(br(o.alignmentBounds,e)){n+=Math.ceil(Number(e-o.alignment)/Number(o.alignmentMultiple));break}}let s=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(r<o.alignment)break;if(r>=o.alignmentBounds.upper)s+=o.length;else if(br(o.alignmentBounds,r)){s+=Math.ceil(Number(r-o.alignment)/Number(o.alignmentMultiple));break}}return new On(this,n,s)}subAlignmentSpanIterator(e,r){if(e>=this.alignmentBounds.upper)return Gn;r=Math.min(r,Number(this.distance(e,this.alignmentBounds.upper)));let n=0;for(let s=0;s<this.series.length;s++){const a=this.series[s];if(e<a.alignment)break;if(e>=a.alignmentBounds.upper)n+=a.length;else if(br(a.alignmentBounds,e)){n+=Number(e-a.alignment);break}}return new On(this,n,n+r)}updateGLBuffer(e){this.series.forEach(r=>r.updateGLBuffer(e))}get bounds(){return vd(this.series.map(e=>e.bounds))}get byteLength(){return new vt(this.series.reduce((e,r)=>e+r.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let r=0;for(const n of this.series)e.set(n.data,r),r+=n.length;return new this.dataType.Array(e.buffer)}traverseAlignment(e,r){const n=this.series.map(s=>s.alignmentBounds);return Td(n,e,r)}acquire(e){this.series.forEach(r=>r.acquire(e))}release(){this.series.forEach(e=>e.release())}distance(e,r){const n=this.series.map(s=>s.alignmentBounds);return zd(n,e,r)}parseJSON(e){if(!this.dataType.equals(R.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.series.flatMap(r=>r.parseJSON(e))}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new Bp(this.series)}toStrings(){return this.series.flatMap(e=>e.toStrings())}}let Bp=class{series;seriesIndex;internal;constructor(e){this.series=e,this.seriesIndex=0,this.internal=e[0][Symbol.iterator]()}next(){const e=this.internal.next();return e.done===!1?e:this.seriesIndex===this.series.length-1?{done:!0,value:void 0}:(this.internal=this.series[++this.seriesIndex][Symbol.iterator](),this.next())}[Symbol.iterator](){return this}},On=class{series;index;end;constructor(e,r,n){this.series=e,this.end=n,this.index=r}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}};const Ni=t=>{const e=t>>32n,r=t&0xffffffffn;return{domain:e,sample:r}},qp=(t,e)=>{let r=null;return e===0?t:(...n)=>{r!==null&&(clearTimeout(r),r=null),r=setTimeout(()=>t(...n),e)}},Fp=(t,e,r=".")=>{const n=t.split(r);return n.map((s,a)=>{const o=e(s,a,n);return o==null?null:typeof o=="string"?o:o.join(r)}).filter(s=>s!=null).join(r)},Vp=(t,e)=>{if(!Array.isArray(t))return t[e];const r=t[e];if(r!=null||t.length==0)return r;const n=t[0];if(typeof n=="object"&&"key"in n)return t.find(s=>s.key===e)},Yp=((t,e,r={optional:!1})=>{const{optional:n,getter:s=Vp}=r;if(e==="")return t;const a=e.split(".");if(a.length===1){const c=s(t,a[0]);if(c===void 0){if(n)return null;throw new Error(`Path ${e} does not exist. ${a[0]} is undefined`)}return c}const o=(c,l)=>{if(l>=a.length)return c;for(let u=a.length-l;u>=1;u--){const h=a.slice(l,l+u).join("."),d=s(c,h);if(d!==void 0){if(l+u===a.length)return d;if(d===null){if(n)return null;throw new Error(`Path ${e} does not exist. ${h} is null`)}return o(d,l+u)}}if(n)return null;throw new Error(`Path ${e} does not exist. ${a[l]} is undefined`)};return o(t,0)});i.z.object({key:i.z.string(),value:i.z.string()});let Wp=class{handlers;transform;closer;constructor(e,r){this.transform=e,this.handlers=r??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){let r=e;if(this.transform!=null){const[n,s]=this.transform(e);if(!s)return;r=n}this.handlers.forEach((n,s)=>s(r))}setCloser(e){this.closer=e}async close(){return await this.closer?.()}},Hp=class{handlers;constructor(e){this.handlers=e??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){this.handlers.forEach((r,n)=>n(e))}};const Gp=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:Hp,Observer:Wp},Symbol.toStringTag,{value:"Module"})),Jp=i.z.record(i.z.union([i.z.number(),i.z.string(),i.z.symbol()]),i.z.unknown()),Zs=t=>Object.entries(t),Kp=(t,e)=>Object.fromEntries(Zs(t).map(([r,n])=>[r,e(n,r)])),Xp=t=>Object.fromEntries(Zs(t).filter(([e,r])=>r!==void 0)),Qp=(t,...e)=>{const r={...t};for(const n of e)delete r[n];return r},be=Object.freeze(Object.defineProperty({__proto__:null,entries:Zs,map:Kp,omit:Qp,purgeUndefined:Xp,unknownZ:Jp},Symbol.toStringTag,{value:"Module"})),ey=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";ey();const ty=["macOS","Windows","Linux"],ry=["macos","windows","linux"],ny={macos:"macOS",windows:"Windows",linux:"Linux"};i.z.enum(ty).or(i.z.enum(ry).transform(t=>ny[t]));const sy=(...t)=>t.map(Po).join(""),Po=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),iy=t=>t.endsWith("/")?t.slice(0,-1):t;class Ut{protocol;host;port;path;constructor({host:e,port:r,protocol:n="",pathPrefix:s=""}){this.protocol=n,this.host=e,this.port=r,this.path=Po(s)}replace(e){return new Ut({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Ut({...this,pathPrefix:sy(this.path,e)})}toString(){return iy(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new Ut({host:"unknown",port:0})}const ay=t=>t.nullable().transform(e=>e===null?void 0:e).optional(),oy=t=>i.array(t).or(t.transform(e=>[e])),Uo=t=>Fp(t,(e,r,n)=>{const s=r===n.length-1,a=!isNaN(parseInt(e)),o=!isNaN(parseInt(n[r+1]));return a&&(e="element"),s||o?e:[e,"shape"]}),Oi=(t,e)=>{if(t==null)return null;const r=t[e];return r==null&&typeof t=="object"&&"sourceType"in t?t.sourceType()[e]:r},cy=((t,e,r)=>e===""?t:Yp(Oi(t,"shape"),Uo(e),{...r,getter:Oi})),Lt=Object.freeze(Object.defineProperty({__proto__:null,getFieldSchema:cy,getFieldSchemaPath:Uo,nullToUndefined:ay,toArray:oy},Symbol.toStringTag,{value:"Module"})),Kn=2,Xn=3,Lo=2,uy=(t,e)=>{if(Number.isNaN(t)||!Number.isFinite(t))return t;const r=lo(e);if(r==0)return t;let n;r>=1e3?n=Kn:r>=1?n=Xn:n=Math.ceil(-Math.log10(r))+Lo;const s=10**n;return Math.round(t*s)/s},ly=5,hy=1e-10,fy=(t,e)=>{if(Number.isNaN(t)||!Number.isFinite(t))return t;const r=Math.abs(t);if(r===0)return 0;let n=!1,s=0;if(e!=null){s=lo(e);const c=s/r;n=s>0&&c>hy}if(n){let c;s>=1e3?c=Kn:s>=1?c=Xn:c=Math.ceil(-Math.log10(s))+Lo;const l=10**c;return Math.round(t*l)/l}if(r>=1e3){const c=10**Kn;return Math.round(t*c)/c}if(r>=1){const c=10**Xn;return Math.round(t*c)/c}const a=Math.floor(Math.log10(r)),o=10**(ly-a-1);return Math.round(t*o)/o},Qn=Object.freeze(Object.defineProperty({__proto__:null,MAX_INT16:Ep,MAX_INT32:Op,MAX_INT64:_r,MAX_INT64_NUMBER:Ao,MAX_INT8:Tp,MAX_UINT16:mp,MAX_UINT32:gp,MAX_UINT64:wp,MAX_UINT64_NUMBER:bp,MAX_UINT8:yp,MIN_INT16:zp,MIN_INT32:Np,MIN_INT64:$p,MIN_INT64_NUMBER:Sp,MIN_INT8:vp,abs:uo,add:St,closeTo:md,div:sr,equal:Wn,isInteger:Rr,max:wd,min:co,mult:me,roundBySpan:uy,roundToNearestMagnitude:gd,smartRound:fy,sub:Ue},Symbol.toStringTag,{value:"Module"})),dy=async t=>await new Promise(e=>setTimeout(e,I.fromMilliseconds(t).milliseconds));class py{config;retries;interval;constructor(e){this.config={baseInterval:new I(e?.baseInterval??I.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??dy},this.retries=0,this.interval=new I(this.config.baseInterval)}async wait(){const{maxRetries:e,scale:r,sleepFn:n}=this.config;return this.retries>=e?!1:(await n(this.interval),this.interval=this.interval.mult(r),this.retries++,!0)}get retryMessage(){return`breaker triggered ${this.retries+1}/${this.config.maxRetries} times, retrying in ${this.interval.toString()}`}reset(){this.retries=0,this.interval=this.config.baseInterval}}const yy=i.z.object({baseInterval:I.z.optional(),maxRetries:i.z.number().optional(),scale:i.z.number().optional()}),Bo=Object.freeze(Object.defineProperty({__proto__:null,Breaker:py,breakerConfigZ:yy},Symbol.toStringTag,{value:"Module"})),my=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,qo=i.z.string().regex(my),mt=i.z.number().min(0).max(255),Fo=i.z.number().min(0).max(1),Vo=i.z.tuple([mt,mt,mt,Fo]),gy=i.z.tuple([mt,mt,mt]),wy=i.z.object({rgba255:Vo}),by=i.z.number().min(0).max(360),vy=i.z.number().min(0).max(100),Ty=i.z.number().min(0).max(100),zy=i.z.tuple([by,vy,Ty,Fo]),Cs=i.z.union([qo,gy,Vo,zy,wy]),Ey=Cs.transform(t=>Rs(t)),Rs=(t,e=1)=>{if(t=Cs.parse(t),typeof t=="string")return Ny(t,e);if(Array.isArray(t)){if(t.length<3||t.length>4)throw new Error(`Invalid color: [${t.join(", ")}]`);return t.length===3?[...t,e]:t}return t.rgba255},Ny=(t,e=1)=>(t=qo.parse(t),t=Oy(t),[zr(t,0),zr(t,2),zr(t,4),t.length===8?zr(t,6)/255:e]),zr=(t,e)=>parseInt(t.slice(e,e+2),16),Oy=t=>t.startsWith("#")?t.slice(1):t;Rs("#000000");Rs("#ffffff");const $y=i.z.object({key:i.z.string(),color:Cs,position:i.z.number(),switched:i.z.boolean().optional()});i.z.array($y);const Sy=i.z.object({key:i.z.string(),name:i.z.string(),color:Ey});i.z.object({key:i.z.string(),name:i.z.string(),swatches:i.z.array(Sy)});const Yo=i.z.int().min(0).max(255),Wo=255,Ho=0,Iy={lower:Ho,upper:Wo+1},Go=i.z.object({name:i.z.string(),key:i.z.string()}),Vt=t=>i.z.object({subject:Go,resource:t,authority:Yo}),ky=(...t)=>e=>e.filter(r=>{let n=!1;return r.to!=null&&(n=t.includes(r.to.resource)),r.from!=null&&!n&&(n=t.includes(r.from.resource)),n}),Jo=t=>i.z.object({from:Vt(t),to:i.z.null()}),Ko=t=>i.z.object({from:i.z.null(),to:Vt(t)}),Ay=t=>i.z.union([Jo(t),Ko(t),i.z.object({from:Vt(t),to:Vt(t)})]),fe=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:Wo,AUTHORITY_BOUNDS:Iy,ZERO_AUTHORITY:Ho,acquireZ:Ko,authorityZ:Yo,filterTransfersByChannelKey:ky,releaseZ:Jo,stateZ:Vt,subjectZ:Go,transferZ:Ay},Symbol.toStringTag,{value:"Module"})),xy=t=>Object.getOwnPropertySymbols(globalThis).includes(t),Zy=(t,e)=>{const r=Symbol.for(t);if(!xy(r)){const n=e();Object.defineProperty(globalThis,r,{value:n})}return()=>globalThis[r]},Xo="sy_x_error",Cy=t=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.startsWith(t):e instanceof Error?e.message.startsWith(t):typeof e!="string"?!1:e.startsWith(t),ir=t=>class Dt extends Error{static discriminator=Xo;discriminator=Dt.discriminator;static TYPE=t;type=Dt.TYPE;static matches=Cy(t);matches=Dt.matches;constructor(r,n){super(r,n),this.name=Dt.TYPE}static sub(r){return ir(`${t}.${r}`)}},Qo=t=>{if(t==null||typeof t!="object")return!1;const e=t;if(e.discriminator!==Xo)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},ft="unknown",es="nil";class Ry{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:es,data:""};if(Qo(e))for(const r of this.providers){const n=r.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:ft,data:e.message};if(typeof e=="string")return{type:ft,data:e};try{return{type:ft,data:JSON.stringify(e)}}catch{return{type:ft,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===es)return null;if(e.type===ft)return new ts(e.data);for(const r of this.providers){const n=r.decode(e);if(n!=null)return n}return new ts(e.data)}}const _s=Zy("synnax-error-registry",()=>new Ry),_y=({encode:t,decode:e})=>_s().register({encode:t,decode:e}),jy=t=>_s().encode(t),My=t=>t==null?null:_s().decode(t);class ts extends ir("unknown"){}const Dy=i.z.object({type:i.z.string(),data:i.z.string()});class Py extends ir("canceled"){}class Uy extends ir("not_implemented"){}const Ze=Object.freeze(Object.defineProperty({__proto__:null,Canceled:Py,NONE:es,NotImplemented:Uy,UNKNOWN:ft,Unknown:ts,createTyped:ir,decode:My,encode:jy,isTyped:Qo,payloadZ:Dy,register:_y},Symbol.toStringTag,{value:"Module"})),Ly=i.object({jsonrpc:i.literal("2.0"),method:i.string(),params:i.any().optional(),id:i.union([i.string(),i.number(),i.null()]).optional()}),ec=i.object({jsonrpc:i.literal("2.0"),id:i.union([i.string(),i.number(),i.null()])}),By=ec.extend({result:i.json()}),qy=ec.extend({error:i.object({code:i.number().int(),message:i.string().optional(),data:i.json().optional()})}),Fy=i.union([By,qy]);i.union([Ly,Fy]);const tc=i.uuid(),rc=i.object({key:tc,name:i.string().min(1),color:i.string()}),nc=Object.freeze(Object.defineProperty({__proto__:null,keyZ:tc,labelZ:rc},Symbol.toStringTag,{value:"Module"})),rs=i.z.string().regex(/^\d+\.\d+\.\d+$/),ar=((t,e,r={})=>{r.checkMajor??=!0,r.checkMinor??=!0,r.checkPatch??=!0;const n=rs.parse(t),s=rs.parse(e),[a,o,c]=n.split(".").map(Number),[l,u,h]=s.split(".").map(Number);if(r.checkMajor){if(a<l)return Ir;if(a>l)return kr}if(r.checkMinor){if(o<u)return Ir;if(o>u)return kr}if(r.checkPatch){if(c<h)return Ir;if(c>h)return kr}return Ot}),Vy=(t,e,r={})=>to(ar(t,e,r)),sc=(t,e,r={})=>eo(ar(t,e,r)),Yy=(t,e,r={})=>Qa(ar(t,e,r)),Wy=({name:t,migrate:e})=>r=>{try{const n=e(r);return console.log(`${t} migrated: ${r.version} -> ${n.version}`),n}catch(n){throw console.log(`${t} failed to migrate from ${r.version}`),console.error(n),n}},Hy=({name:t,migrations:e,targetSchema:r,defaultVersion:n,def:s})=>{const a=Object.keys(e).sort(ar).pop();if(a==null)return u=>{if(u.version??=n,u.version!==s.version)return console.log(`${t} version ${u.version} is newer than latest version of ${s.version}.
12
+ `).buffer):this.dataType.usesBigInt&&typeof v=="number"?this._data=new this.dataType.Array(f.map(S=>BigInt(Math.round(S)))).buffer:!this.dataType.usesBigInt&&typeof v=="bigint"?this._data=new this.dataType.Array(f.map(Number)).buffer:this._data=new this.dataType.Array(f).buffer}this.key=l,this.alignment=o,this.alignmentMultiple=c,this.sampleOffset=s??0,this.timeRange=n??D.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:r,...n}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const s=new new R(r).Array(e),a=new Ue({data:s.buffer,dataType:r,...n});return a.writePos=0,a}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn("cannot release a series with a negative reference count")}write(e){if(!e.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===je)return 0;const r=this.byteCapacity.valueOf()-this.writePos,n=e.subBytes(0,r);return this.writeToUnderlyingData(n),this.writePos+=n.byteLength.valueOf(),this.cachedLength!=null&&(this.cachedLength+=n.length,this.calculateCachedLength()),n.length}writeFixed(e){if(this.writePos===je)return 0;const r=this.capacity-this.writePos,n=e.sub(0,r);return this.writeToUnderlyingData(n),this.cachedLength=void 0,this.maybeRecomputeMinMax(n),this.writePos+=n.length,n.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data=="object"&&"buffer"in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===je?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){return this.dataType.isVariable?new TextDecoder().decode(this.underlyingData).split(`
13
+ `).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(R.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(r=>e.parse(qt.decodeString(r)))}get byteCapacity(){return new Tt(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===je?this.byteCapacity:this.dataType.isVariable?new Tt(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===je?this.byteCapacity.valueOf()/this.dataType.density.valueOf():this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const r=[0];return this.data.forEach((n,s)=>{n===Kn&&(e++,r.push(s+1))}),this._cachedIndexes=r,this.cachedLength=e,e}convert(e,r=0){if(this.dataType.equals(e))return this;const n=new e.Array(this.length);for(let s=0;s<this.length;s++)n[s]=Mp(this.dataType,e,this.data[s],r);return new Ue({data:n.buffer,dataType:e,timeRange:this.timeRange,sampleOffset:r,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(R.TIMESTAMP))this.cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMax=e.reduce((r,n)=>r>n?r:n)}else{const e=this.data;this.cachedMax=e.reduce((r,n)=>r>n?r:n)}return this.cachedMax}get max(){return this.calcMax()}calcMax(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this.cachedMax??=this.calcRawMax(),Cr(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(R.TIMESTAMP))this.cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMin=e.reduce((r,n)=>r<n?r:n)}else{const e=this.data;this.cachedMin=e.reduce((r,n)=>r<n?r:n)}return this.cachedMin}get min(){return this.calcMin()}calcMin(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this.cachedMin??=this.calcRawMin(),Cr(this.cachedMin,this.sampleOffset))}get bounds(){return K(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){const r=e.cachedMin??e.calcRawMin();r<this.cachedMin&&(this.cachedMin=r)}if(this.cachedMax!=null){const r=e.cachedMax??e.calcRawMax();r>this.cachedMax&&(this.cachedMax=r)}}atAlignment(e,r){const n=Number((e-this.alignment)/this.alignmentMultiple);if(n<0||n>=this.length){if(r===!0)throw new Error(`[series] - no value at index ${n}`);return}return this.at(n,r)}at(e,r=!1){if(this.dataType.isVariable)return this.atVariable(e,r??!1);if(this.dataType.equals(R.UUID))return this.atUUID(e,r);e<0&&(e=this.length+e);const n=this.data[e];if(n==null){if(r===!0)throw new Error(`[series] - no value at index ${e}`);return}return Cr(n,this.sampleOffset)}atUUID(e,r){e<0&&(e=this.length+e);const n=Ro(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(n==null){if(r)throw new Error(`[series] - no value at index ${e}`);return}return n}atVariable(e,r){let n=0,s=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],s=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let o=0;o<this.data.length;o++)if(this.data[o]===Kn){if(e===0){s=o;break}n=o+1,e--}if(s===0&&(s=this.data.length),n>=s||e>0){if(r)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(n,s);return this.dataType.equals(R.STRING)?new TextDecoder().decode(a):vs(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let r=0,n=this.length-1;const s=nr(e);for(;r<=n;){const a=Math.floor((r+n)/2),o=s(this.at(a,!0),e);if(o===0)return a;o<0?r=a+1:n=a-1}return r}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(R.FLOAT32)&&!this.dataType.equals(R.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:r,bufferUsage:n,prevBuffer:s}=this.gl;if(r==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==s)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==je){s===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(s).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=je}as(e){return _o(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:Ni(this.alignmentBounds.lower),upper:Ni(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return K(this.alignment,this.alignment+BigInt(this.length)*this.alignmentMultiple)}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new Vp(this);return this.dataType.equals(R.JSON)?new Yp(e):e}return this.dataType.equals(R.UUID)?new Hp(this):new Wp(this)}slice(e,r){return this.sliceSub(!1,e,r)}sub(e,r){return this.sliceSub(!0,e,r)}subIterator(e,r){return new Ei(this,e,r??this.length)}subAlignmentIterator(e,r){const n=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),s=Math.ceil(Number(r-this.alignment)/Number(this.alignmentMultiple));return new Ei(this,n,s)}subBytes(e,r){if(e>=0&&(r==null||r>=this.byteLength.valueOf()))return this;const n=this.data.subarray(e,r);return new Ue({data:n,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,r,n){if(r<=0&&(n==null||n>=this.length))return this;let s;return e?s=this.data.subarray(r,n):s=this.data.slice(r,n),new Ue({data:s,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(r)})}reAlign(e){return new Ue({data:this.buffer,dataType:this.dataType,timeRange:D.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}toString(){let e=`Series(${this.dataType.toString()} ${this.length} [`;if(this.length<=10)e+=Array.from(this).map(r=>r.toString());else{for(let r=0;r<5;r++)e+=`${this.at(r)?.toString()}`,e+=",";e+="...,";for(let r=-5;r<0;r++)e+=this.at(r)?.toString(),r<-1&&(e+=",")}return e+="])",e}};const Fp=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof xe?!0:Co(t),Mo=Tp(jo,xe);let Ei=class{series;end;index;constructor(e,r,n){this.series=e;const s=K(0,e.length+1);this.end=vi(s,n),this.index=vi(s,r)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},Vp=class{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=e,this.index=0,this.decoder=new TextDecoder}next(){const e=this.index,r=this.series.data;for(;this.index<r.length&&r[this.index]!==Kn;)this.index++;const n=this.index;return e===n?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,n))})}},Yp=class Do{wrapped;static schema=i.z.record(i.z.string(),i.z.unknown());constructor(e){this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:qt.decodeString(e.value,Do.schema)}}};class Hp{series;index;data;density;constructor(e){if(!e.dataType.equals(R.UUID))throw new Error("cannot create a UUID series iterator for a non-UUID series");this.series=e,this.index=0,this.data=new Uint8Array(e.buffer),this.density=R.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=Ro(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}let Wp=class{series;index;constructor(e){this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}};class Po{series;constructor(e=[]){if(e.length!==0){const r=e[0].dataType;for(let n=1;n<e.length;n++)if(!e[n].dataType.equals(r))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){return _o(e,this.dataType),this}get dataType(){return this.series.length===0?R.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?D.ZERO:new D(this.series[0].timeRange.start,this.series[this.series.length-1].timeRange.end)}get alignment(){return this.series.length===0?0n:this.series[0].alignment}get alignmentBounds(){return this.series.length===0?K(0n,0n):K(this.series[0].alignmentBounds.lower,this.series[this.series.length-1].alignmentBounds.upper)}push(e){const r=()=>new Error(`cannot push a ${e.dataType.toString()} series to a ${this.dataType.toString()} multi-series`),n=e.dataType.equals(this.dataType);if(Mo(e)){if(this.series.length!==0&&!n)throw r();this.series.push(e)}else{if(this.series.length!==0&&e.series.length!==0&&!n)throw r();this.series.push(...e.series)}}get length(){return this.series.reduce((e,r)=>e+r.length,0)}atAlignment(e,r){for(const n of this.series)if(Tr(n.alignmentBounds,e))return n.atAlignment(e,r);if(r)throw new Error(`[series] - no value at alignment ${e}`)}at(e,r=!1){e<0&&(e=this.length+e);for(const n of this.series){if(e<n.length)return n.at(e,r);e-=n.length}if(r)throw new Error(`[series] - no value at index ${e}`)}subIterator(e,r){return new On(this,e,r??this.length)}subAlignmentIterator(e,r){if(e>=this.alignmentBounds.upper||r<=this.alignmentBounds.lower)return Gn;let n=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(e<o.alignment)break;if(e>=o.alignmentBounds.upper)n+=o.length;else if(Tr(o.alignmentBounds,e)){n+=Math.ceil(Number(e-o.alignment)/Number(o.alignmentMultiple));break}}let s=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(r<o.alignment)break;if(r>=o.alignmentBounds.upper)s+=o.length;else if(Tr(o.alignmentBounds,r)){s+=Math.ceil(Number(r-o.alignment)/Number(o.alignmentMultiple));break}}return new On(this,n,s)}subAlignmentSpanIterator(e,r){if(e>=this.alignmentBounds.upper)return Gn;r=Math.min(r,Number(this.distance(e,this.alignmentBounds.upper)));let n=0;for(let s=0;s<this.series.length;s++){const a=this.series[s];if(e<a.alignment)break;if(e>=a.alignmentBounds.upper)n+=a.length;else if(Tr(a.alignmentBounds,e)){n+=Number(e-a.alignment);break}}return new On(this,n,n+r)}updateGLBuffer(e){this.series.forEach(r=>r.updateGLBuffer(e))}get bounds(){return Sd(this.series.map(e=>e.bounds))}get byteLength(){return new Tt(this.series.reduce((e,r)=>e+r.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let r=0;for(const n of this.series)e.set(n.data,r),r+=n.length;return new this.dataType.Array(e.buffer)}traverseAlignment(e,r){const n=this.series.map(s=>s.alignmentBounds);return Id(n,e,r)}acquire(e){this.series.forEach(r=>r.acquire(e))}release(){this.series.forEach(e=>e.release())}distance(e,r){const n=this.series.map(s=>s.alignmentBounds);return Ad(n,e,r)}parseJSON(e){if(!this.dataType.equals(R.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.series.flatMap(r=>r.parseJSON(e))}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new Gp(this.series)}toStrings(){return this.series.flatMap(e=>e.toStrings())}}let Gp=class{series;seriesIndex;internal;constructor(e){this.series=e,this.seriesIndex=0,this.internal=e[0][Symbol.iterator]()}next(){const e=this.internal.next();return e.done===!1?e:this.seriesIndex===this.series.length-1?{done:!0,value:void 0}:(this.internal=this.series[++this.seriesIndex][Symbol.iterator](),this.next())}[Symbol.iterator](){return this}},On=class{series;index;end;constructor(e,r,n){this.series=e,this.end=n,this.index=r}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}};const Ni=t=>{const e=t>>32n,r=t&0xffffffffn;return{domain:e,sample:r}},Uo=(t,e,r)=>{let n=0,s=t.length;const a=r??nr(e);for(;n<s;){const o=Math.floor((n+s)/2),c=a(t[o],e);if(c===0)return o;c<0?n=o+1:s=o}return n},Kp=(t,e,r)=>{const n=Uo(t,e,r);t.splice(n,0,e)},Oi=Object.freeze(Object.defineProperty({__proto__:null,EQUAL:$t,GREATER_THAN:xr,LESS_THAN:kr,insert:Kp,isEqualTo:ro,isGreaterThan:to,isGreaterThanEqual:hd,isLessThan:eo,newF:nr,newFieldF:od,order:ld,primitiveArrays:cd,reverseF:Qa,search:Uo,stringsWithNumbers:fd,uniqueUnorderedPrimitiveArrays:ud,unorderedPrimitiveArrays:Xa},Symbol.toStringTag,{value:"Module"})),Jp=(t,e)=>{let r=null;return e===0?t:(...n)=>{r!==null&&(clearTimeout(r),r=null),r=setTimeout(()=>t(...n),e)}},Xp=(t,e,r=".")=>{const n=t.split(r);return n.map((s,a)=>{const o=e(s,a,n);return o==null?null:typeof o=="string"?o:o.join(r)}).filter(s=>s!=null).join(r)},Qp=(t,e)=>{if(!Array.isArray(t))return t[e];const r=t[e];if(r!=null||t.length==0)return r;const n=t[0];if(typeof n=="object"&&"key"in n)return t.find(s=>s.key===e)},ey=((t,e,r={optional:!1})=>{const{optional:n,getter:s=Qp}=r;if(e==="")return t;const a=e.split(".");if(a.length===1){const c=s(t,a[0]);if(c===void 0){if(n)return null;throw new Error(`Path ${e} does not exist. ${a[0]} is undefined`)}return c}const o=(c,l)=>{if(l>=a.length)return c;for(let u=a.length-l;u>=1;u--){const h=a.slice(l,l+u).join("."),d=s(c,h);if(d!==void 0){if(l+u===a.length)return d;if(d===null){if(n)return null;throw new Error(`Path ${e} does not exist. ${h} is null`)}return o(d,l+u)}}if(n)return null;throw new Error(`Path ${e} does not exist. ${a[l]} is undefined`)};return o(t,0)});i.z.object({key:i.z.string(),value:i.z.string()});let ty=class{handlers;transform;closer;constructor(e,r){this.transform=e,this.handlers=r??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){let r=e;if(this.transform!=null){const[n,s]=this.transform(e);if(!s)return;r=n}this.handlers.forEach((n,s)=>s(r))}setCloser(e){this.closer=e}async close(){return await this.closer?.()}},ry=class{handlers;constructor(e){this.handlers=e??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){this.handlers.forEach((r,n)=>n(e))}};const ny=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:ry,Observer:ty},Symbol.toStringTag,{value:"Module"})),sy=i.z.record(i.z.union([i.z.number(),i.z.string(),i.z.symbol()]),i.z.unknown()),Zs=t=>Object.entries(t),iy=(t,e)=>Object.fromEntries(Zs(t).map(([r,n])=>[r,e(n,r)])),ay=t=>Object.fromEntries(Zs(t).filter(([e,r])=>r!==void 0)),oy=(t,...e)=>{const r={...t};for(const n of e)delete r[n];return r},be=Object.freeze(Object.defineProperty({__proto__:null,entries:Zs,map:iy,omit:oy,purgeUndefined:ay,unknownZ:sy},Symbol.toStringTag,{value:"Module"})),cy=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";cy();const uy=["macOS","Windows","Linux"],ly=["macos","windows","linux"],hy={macos:"macOS",windows:"Windows",linux:"Linux"};i.z.enum(uy).or(i.z.enum(ly).transform(t=>hy[t]));const fy=(...t)=>t.map(Lo).join(""),Lo=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),dy=t=>t.endsWith("/")?t.slice(0,-1):t;class Lt{protocol;host;port;path;constructor({host:e,port:r,protocol:n="",pathPrefix:s=""}){this.protocol=n,this.host=e,this.port=r,this.path=Lo(s)}replace(e){return new Lt({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Lt({...this,pathPrefix:fy(this.path,e)})}toString(){return dy(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new Lt({host:"unknown",port:0})}const py=t=>t.nullable().transform(e=>e===null?void 0:e).optional(),yy=t=>i.array(t).or(t.transform(e=>[e])),Bo=t=>Xp(t,(e,r,n)=>{const s=r===n.length-1,a=!isNaN(parseInt(e)),o=!isNaN(parseInt(n[r+1]));return a&&(e="element"),s||o?e:[e,"shape"]}),$i=(t,e)=>{if(t==null)return null;const r=t[e];return r==null&&typeof t=="object"&&"sourceType"in t?t.sourceType()[e]:r},my=((t,e,r)=>e===""?t:ey($i(t,"shape"),Bo(e),{...r,getter:$i})),Bt=Object.freeze(Object.defineProperty({__proto__:null,getFieldSchema:my,getFieldSchemaPath:Bo,nullToUndefined:py,toArray:yy},Symbol.toStringTag,{value:"Module"})),Jn=2,Xn=3,qo=2,gy=(t,e)=>{if(Number.isNaN(t)||!Number.isFinite(t))return t;const r=ho(e);if(r==0)return t;let n;r>=1e3?n=Jn:r>=1?n=Xn:n=Math.ceil(-Math.log10(r))+qo;const s=10**n;return Math.round(t*s)/s},wy=5,by=1e-10,vy=(t,e)=>{if(Number.isNaN(t)||!Number.isFinite(t))return t;const r=Math.abs(t);if(r===0)return 0;let n=!1,s=0;if(e!=null){s=ho(e);const c=s/r;n=s>0&&c>by}if(n){let c;s>=1e3?c=Jn:s>=1?c=Xn:c=Math.ceil(-Math.log10(s))+qo;const l=10**c;return Math.round(t*l)/l}if(r>=1e3){const c=10**Jn;return Math.round(t*c)/c}if(r>=1){const c=10**Xn;return Math.round(t*c)/c}const a=Math.floor(Math.log10(r)),o=10**(wy-a-1);return Math.round(t*o)/o},Qn=Object.freeze(Object.defineProperty({__proto__:null,MAX_INT16:xp,MAX_INT32:Cp,MAX_INT64:Mr,MAX_INT64_NUMBER:xo,MAX_INT8:Ap,MAX_UINT16:Np,MAX_UINT32:Op,MAX_UINT64:$p,MAX_UINT64_NUMBER:Sp,MAX_UINT8:Ep,MIN_INT16:kp,MIN_INT32:Zp,MIN_INT64:Rp,MIN_INT64_NUMBER:_p,MIN_INT8:Ip,abs:lo,add:It,closeTo:Ed,div:sr,equal:Hn,isInteger:jr,max:Od,min:uo,mult:me,roundBySpan:gy,roundToNearestMagnitude:Nd,smartRound:vy,sub:Le},Symbol.toStringTag,{value:"Module"})),Ty=async t=>await new Promise(e=>setTimeout(e,I.fromMilliseconds(t).milliseconds));class zy{config;retries;interval;constructor(e){this.config={baseInterval:new I(e?.baseInterval??I.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??Ty},this.retries=0,this.interval=new I(this.config.baseInterval)}async wait(){const{maxRetries:e,scale:r,sleepFn:n}=this.config;return this.retries>=e?!1:(await n(this.interval),this.interval=this.interval.mult(r),this.retries++,!0)}get retryMessage(){return`breaker triggered ${this.retries+1}/${this.config.maxRetries} times, retrying in ${this.interval.toString()}`}reset(){this.retries=0,this.interval=this.config.baseInterval}}const Ey=i.z.object({baseInterval:I.z.optional(),maxRetries:i.z.number().optional(),scale:i.z.number().optional()}),Fo=Object.freeze(Object.defineProperty({__proto__:null,Breaker:zy,breakerConfigZ:Ey},Symbol.toStringTag,{value:"Module"})),Ny=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,Vo=i.z.string().regex(Ny),gt=i.z.number().min(0).max(255),Yo=i.z.number().min(0).max(1),Ho=i.z.tuple([gt,gt,gt,Yo]),Oy=i.z.tuple([gt,gt,gt]),$y=i.z.object({rgba255:Ho}),Sy=i.z.number().min(0).max(360),Iy=i.z.number().min(0).max(100),Ay=i.z.number().min(0).max(100),ky=i.z.tuple([Sy,Iy,Ay,Yo]),Cs=i.z.union([Vo,Oy,Ho,ky,$y]),xy=Cs.transform(t=>Rs(t)),Rs=(t,e=1)=>{if(t=Cs.parse(t),typeof t=="string")return Zy(t,e);if(Array.isArray(t)){if(t.length<3||t.length>4)throw new Error(`Invalid color: [${t.join(", ")}]`);return t.length===3?[...t,e]:t}return t.rgba255},Zy=(t,e=1)=>(t=Vo.parse(t),t=Cy(t),[Nr(t,0),Nr(t,2),Nr(t,4),t.length===8?Nr(t,6)/255:e]),Nr=(t,e)=>parseInt(t.slice(e,e+2),16),Cy=t=>t.startsWith("#")?t.slice(1):t;Rs("#000000");Rs("#ffffff");const Ry=i.z.object({key:i.z.string(),color:Cs,position:i.z.number(),switched:i.z.boolean().optional()});i.z.array(Ry);const _y=i.z.object({key:i.z.string(),name:i.z.string(),color:xy});i.z.object({key:i.z.string(),name:i.z.string(),swatches:i.z.array(_y)});const Wo=i.z.int().min(0).max(255),Go=255,Ko=0,jy={lower:Ko,upper:Go+1},Jo=i.z.object({name:i.z.string(),key:i.z.string()}),Yt=t=>i.z.object({subject:Jo,resource:t,authority:Wo}),My=(...t)=>e=>e.filter(r=>{let n=!1;return r.to!=null&&(n=t.includes(r.to.resource)),r.from!=null&&!n&&(n=t.includes(r.from.resource)),n}),Xo=t=>i.z.object({from:Yt(t),to:i.z.null()}),Qo=t=>i.z.object({from:i.z.null(),to:Yt(t)}),Dy=t=>i.z.union([Xo(t),Qo(t),i.z.object({from:Yt(t),to:Yt(t)})]),fe=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:Go,AUTHORITY_BOUNDS:jy,ZERO_AUTHORITY:Ko,acquireZ:Qo,authorityZ:Wo,filterTransfersByChannelKey:My,releaseZ:Xo,stateZ:Yt,subjectZ:Jo,transferZ:Dy},Symbol.toStringTag,{value:"Module"})),Py=t=>Object.getOwnPropertySymbols(globalThis).includes(t),Uy=(t,e)=>{const r=Symbol.for(t);if(!Py(r)){const n=e();Object.defineProperty(globalThis,r,{value:n})}return()=>globalThis[r]},ec="sy_x_error",Ly=t=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.startsWith(t):e instanceof Error?e.message.startsWith(t):typeof e!="string"?!1:e.startsWith(t),ir=t=>class Pt extends Error{static discriminator=ec;discriminator=Pt.discriminator;static TYPE=t;type=Pt.TYPE;static matches=Ly(t);matches=Pt.matches;constructor(r,n){super(r,n),this.name=Pt.TYPE}static sub(r){return ir(`${t}.${r}`)}},tc=t=>{if(t==null||typeof t!="object")return!1;const e=t;if(e.discriminator!==ec)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},dt="unknown",es="nil";class By{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:es,data:""};if(tc(e))for(const r of this.providers){const n=r.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:dt,data:e.message};if(typeof e=="string")return{type:dt,data:e};try{return{type:dt,data:JSON.stringify(e)}}catch{return{type:dt,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===es)return null;if(e.type===dt)return new ts(e.data);for(const r of this.providers){const n=r.decode(e);if(n!=null)return n}return new ts(e.data)}}const _s=Uy("synnax-error-registry",()=>new By),qy=({encode:t,decode:e})=>_s().register({encode:t,decode:e}),Fy=t=>_s().encode(t),Vy=t=>t==null?null:_s().decode(t);class ts extends ir("unknown"){}const Yy=i.z.object({type:i.z.string(),data:i.z.string()});class Hy extends ir("canceled"){}class Wy extends ir("not_implemented"){}const Ce=Object.freeze(Object.defineProperty({__proto__:null,Canceled:Hy,NONE:es,NotImplemented:Wy,UNKNOWN:dt,Unknown:ts,createTyped:ir,decode:Vy,encode:Fy,isTyped:tc,payloadZ:Yy,register:qy},Symbol.toStringTag,{value:"Module"})),Gy=i.object({jsonrpc:i.literal("2.0"),method:i.string(),params:i.any().optional(),id:i.union([i.string(),i.number(),i.null()]).optional()}),rc=i.object({jsonrpc:i.literal("2.0"),id:i.union([i.string(),i.number(),i.null()])}),Ky=rc.extend({result:i.json()}),Jy=rc.extend({error:i.object({code:i.number().int(),message:i.string().optional(),data:i.json().optional()})}),Xy=i.union([Ky,Jy]);i.union([Gy,Xy]);const nc=i.uuid(),sc=i.object({key:nc,name:i.string().min(1),color:i.string()}),ic=Object.freeze(Object.defineProperty({__proto__:null,keyZ:nc,labelZ:sc},Symbol.toStringTag,{value:"Module"})),rs=i.z.string().regex(/^\d+\.\d+\.\d+$/),ar=((t,e,r={})=>{r.checkMajor??=!0,r.checkMinor??=!0,r.checkPatch??=!0;const n=rs.parse(t),s=rs.parse(e),[a,o,c]=n.split(".").map(Number),[l,u,h]=s.split(".").map(Number);if(r.checkMajor){if(a<l)return kr;if(a>l)return xr}if(r.checkMinor){if(o<u)return kr;if(o>u)return xr}if(r.checkPatch){if(c<h)return kr;if(c>h)return xr}return $t}),Qy=(t,e,r={})=>ro(ar(t,e,r)),ac=(t,e,r={})=>to(ar(t,e,r)),em=(t,e,r={})=>eo(ar(t,e,r)),tm=({name:t,migrate:e})=>r=>{try{const n=e(r);return console.log(`${t} migrated: ${r.version} -> ${n.version}`),n}catch(n){throw console.log(`${t} failed to migrate from ${r.version}`),console.error(n),n}},rm=({name:t,migrations:e,targetSchema:r,defaultVersion:n,def:s})=>{const a=Object.keys(e).sort(ar).pop();if(a==null)return u=>{if(u.version??=n,u.version!==s.version)return console.log(`${t} version ${u.version} is newer than latest version of ${s.version}.
14
14
  Returning default instead.
15
- `),s;try{return r!=null?r.parse(u):u}catch(h){return console.log(`${t} failed to parse default. Exiting with default`),console.error(h),s}};const o=Object.keys(e).length;let c=!1;const l=u=>{try{if(o===0||sc(u.version,a))return console.log(c?`${t} ${u.version} now up to date`:`${t} version ${u.version} is up to date with target version ${s.version}`),u;const h=u.version,d=e[h],f=d(u);return c=!0,l(f)}catch(h){return console.log(`${t} failed to migrate from ${u.version} to ${a}`),console.error(h),s}};return u=>{try{if(u.version==null)if(n!=null)console.log(`${t} version is null. Setting version to default of ${n}`),u.version=n;else return console.log(`${t} version is null and no default version set. Exiting with default`),s;return l(u)}catch(h){return console.log(`${t} failed to parse final result. Exiting with default`),console.error(h),s}}},$i=Object.freeze(Object.defineProperty({__proto__:null,compareSemVer:ar,createMigration:Wy,migrator:Hy,semVerNewer:sc,semVerOlder:Yy,semVerZ:rs,versionsEqual:Vy},Symbol.toStringTag,{value:"Module"})),Gy=["standard","scientific","engineering"];i.z.enum(Gy);const ic=i.z.enum(["success","info","warning","error","loading","disabled"]),Jy=t=>i.z.object({key:i.z.string(),name:i.z.string().default(""),variant:ic,message:i.z.string(),description:i.z.string().optional(),time:p.z,labels:Ba(rc).optional(),details:t??i.z.unknown().optional()}),Ky=i.z.object({stack:i.z.string(),error:i.z.instanceof(Error)}),Xy=(t,e)=>{if(!(t instanceof Error))throw t;return ac({variant:"error",message:e??t.message,description:e!=null?t.message:void 0,details:{stack:t.stack??"",error:t}})},ac=t=>({key:xs(),time:p.now(),name:"",...t}),Qy=(t,e=[])=>{if(t!=null)return Array.isArray(e)?e.includes(t)?t:void 0:e===t?t:void 0},em=(t,e=[])=>{if(t!=null)return Array.isArray(e)?e.includes(t)?void 0:t:e===t?void 0:t},It=Object.freeze(Object.defineProperty({__proto__:null,create:ac,exceptionDetailsSchema:Ky,fromException:Xy,keepVariants:Qy,removeVariants:em,statusZ:Jy,variantZ:ic},Symbol.toStringTag,{value:"Module"})),tm=(t,e="")=>{if(typeof t=="string")return t;const r=t.length;return r===0?e:r===1?t[0]:r===2?`${t[0]} and ${t[1]}`:`${t.slice(0,-1).join(", ")}, and ${t[r-1]}`},rm=t=>{const e=t.split(" "),r=new Set,n=e.map(o=>o.charAt(0).toLowerCase()).join("");r.add(n.replace(/-/g,"_")),r.add(n.replace(/(.)(.)/g,"$1_$2").replace(/-/g,"_"));const s=/\d+/g;t.match(s)&&e.forEach((o,c)=>{if(s.test(o)){const l=e.map((u,h)=>h!==c?u.charAt(0).toLowerCase():u).join("");r.add(l.replace(/-/g,"_")),r.add(l.replace(/(.)(.)/g,"$1_$2").replace(/-/g,"_"))}});const a=e.map(o=>(o.length>3?o.substring(0,3):o).toLowerCase());return r.add(a.join("").replace(/-/g,"_")),r.add(a.join("_").replace(/-/g,"_")),Array.from(r).filter(o=>o.length>=2&&o.length<=12&&!/^\d/.test(o))},nm=(t,e)=>t.startsWith(e)?t.slice(e.length):t,sm=t=>t.length===0?t:t[t.length-1]==="y"?`${t.slice(0,-1)}ies`:t[t.length-1]==="s"||t[t.length-1]==="x"||t[t.length-1]==="z"||t.endsWith("ch")||t.endsWith("sh")?`${t}es`:`${t}s`,ns=Object.freeze(Object.defineProperty({__proto__:null,createShortIdentifiers:rm,naturalLanguageJoin:tm,pluralName:sm,trimPrefix:nm},Symbol.toStringTag,{value:"Module"})),oc="all",cc="create",uc="delete",lc="retrieve",hc="update",jr=i.z.enum([oc,cc,uc,lc,hc]);class Se extends Ze.createTyped("sy"){}class Y extends Se.sub("validation"){}class Yt extends Y.sub("path"){path;error;static encodedSchema=i.z.object({path:i.z.string().array(),error:Ze.payloadZ});constructor(e,r){const n=T.toArray(e);super(`${n.join(".")}: ${r.message}`),this.path=n.flatMap(s=>s.split(".")),this.error=r}static decode(e){const r=Yt.encodedSchema.parse(JSON.parse(e.data));return new Yt(r.path,Ze.decode(r.error))}}class Wt extends Se.sub("auth"){}class ss extends Wt.sub("invalid_token"){}class is extends Wt.sub("expired_token"){}class gt extends Se.sub("unexpected"){constructor(e){super(`
15
+ `),s;try{return r!=null?r.parse(u):u}catch(h){return console.log(`${t} failed to parse default. Exiting with default`),console.error(h),s}};const o=Object.keys(e).length;let c=!1;const l=u=>{try{if(o===0||ac(u.version,a))return console.log(c?`${t} ${u.version} now up to date`:`${t} version ${u.version} is up to date with target version ${s.version}`),u;const h=u.version,d=e[h],f=d(u);return c=!0,l(f)}catch(h){return console.log(`${t} failed to migrate from ${u.version} to ${a}`),console.error(h),s}};return u=>{try{if(u.version==null)if(n!=null)console.log(`${t} version is null. Setting version to default of ${n}`),u.version=n;else return console.log(`${t} version is null and no default version set. Exiting with default`),s;return l(u)}catch(h){return console.log(`${t} failed to parse final result. Exiting with default`),console.error(h),s}}},Si=Object.freeze(Object.defineProperty({__proto__:null,compareSemVer:ar,createMigration:tm,migrator:rm,semVerNewer:ac,semVerOlder:em,semVerZ:rs,versionsEqual:Qy},Symbol.toStringTag,{value:"Module"})),nm=["standard","scientific","engineering"];i.z.enum(nm);const oc=i.z.enum(["success","info","warning","error","loading","disabled"]),sm=t=>i.z.object({key:i.z.string(),name:i.z.string().default(""),variant:oc,message:i.z.string(),description:i.z.string().optional(),time:p.z,labels:qa(sc).optional(),details:t??i.z.unknown().optional()}),im=i.z.object({stack:i.z.string(),error:i.z.instanceof(Error)}),am=(t,e)=>{if(!(t instanceof Error))throw t;return cc({variant:"error",message:e??t.message,description:e!=null?t.message:void 0,details:{stack:t.stack??"",error:t}})},cc=t=>({key:xs(),time:p.now(),name:"",...t}),om=(t,e=[])=>{if(t!=null)return Array.isArray(e)?e.includes(t)?t:void 0:e===t?t:void 0},cm=(t,e=[])=>{if(t!=null)return Array.isArray(e)?e.includes(t)?void 0:t:e===t?void 0:t},At=Object.freeze(Object.defineProperty({__proto__:null,create:cc,exceptionDetailsSchema:im,fromException:am,keepVariants:om,removeVariants:cm,statusZ:sm,variantZ:oc},Symbol.toStringTag,{value:"Module"})),um=(t,e)=>{if(!e.has(t))return t;let r=t,n=1,s=t;for(;e.has(s);){const a=s.match(lm);a?(r=s.slice(0,a.index).trim(),n=parseInt(a[1])+1):(r=s,n=1),s=`${r} (${n})`}return s},lm=/\((\d+)\)$/,hm=(t,e="")=>{if(typeof t=="string")return t;const r=t.length;return r===0?e:r===1?t[0]:r===2?`${t[0]} and ${t[1]}`:`${t.slice(0,-1).join(", ")}, and ${t[r-1]}`},fm=t=>{const e=t.split(" "),r=new Set,n=e.map(o=>o.charAt(0).toLowerCase()).join("");r.add(n.replace(/-/g,"_")),r.add(n.replace(/(.)(.)/g,"$1_$2").replace(/-/g,"_"));const s=/\d+/g;t.match(s)&&e.forEach((o,c)=>{if(s.test(o)){const l=e.map((u,h)=>h!==c?u.charAt(0).toLowerCase():u).join("");r.add(l.replace(/-/g,"_")),r.add(l.replace(/(.)(.)/g,"$1_$2").replace(/-/g,"_"))}});const a=e.map(o=>(o.length>3?o.substring(0,3):o).toLowerCase());return r.add(a.join("").replace(/-/g,"_")),r.add(a.join("_").replace(/-/g,"_")),Array.from(r).filter(o=>o.length>=2&&o.length<=12&&!/^\d/.test(o))},dm=(t,e)=>t.startsWith(e)?t.slice(e.length):t,ns=Object.freeze(Object.defineProperty({__proto__:null,createShortIdentifiers:fm,deduplicateFileName:um,naturalLanguageJoin:hm,trimPrefix:dm},Symbol.toStringTag,{value:"Module"})),uc="all",lc="create",hc="delete",fc="retrieve",dc="update",Dr=i.z.enum([uc,lc,hc,fc,dc]);class Ie extends Ce.createTyped("sy"){}class Y extends Ie.sub("validation"){}class Ht extends Y.sub("path"){path;error;static encodedSchema=i.z.object({path:i.z.string().array(),error:Ce.payloadZ});constructor(e,r){const n=T.toArray(e);super(`${n.join(".")}: ${r.message}`),this.path=n.flatMap(s=>s.split(".")),this.error=r}static decode(e){const r=Ht.encodedSchema.parse(JSON.parse(e.data));return new Ht(r.path,Ce.decode(r.error))}}class Wt extends Ie.sub("auth"){}class ss extends Wt.sub("invalid_token"){}class is extends Wt.sub("expired_token"){}class wt extends Ie.sub("unexpected"){constructor(e){super(`
16
16
  Unexpected error encountered:
17
17
 
18
18
  ${e}
19
19
 
20
20
  Please report this to the Synnax team.
21
- `)}}class Fe extends Se.sub("query"){}class Ht extends Fe.sub("not_found"){}class Gt extends Fe.sub("multiple_results"){}class as extends Se.sub("route"){path;constructor(e,r){super(e),this.path=r}}class os extends Se.sub("control"){}class Si extends os.sub("unauthorized"){}class im extends Se.sub("disconnected"){constructor(e="Operation failed because no cluster is connected."){super(e)}}class am extends Se.sub("contiguity"){}const om=t=>t.type.startsWith(Se.TYPE)?t.type.startsWith(Y.TYPE)?t.type===Yt.TYPE?Yt.decode(t):new Y(t.data):t.type.startsWith(Wt.TYPE)?t.type.startsWith(ss.TYPE)?new ss(t.data):t.type.startsWith(is.TYPE)?new is(t.data):new Wt(t.data):t.type.startsWith(gt.TYPE)?new gt(t.data):t.type.startsWith(Fe.TYPE)?t.type.startsWith(Ht.TYPE)?new Ht(t.data):t.type.startsWith(Gt.TYPE)?new Gt(t.data):new Fe(t.data):t.type.startsWith(os.TYPE)?t.type.startsWith(Si.TYPE)?new Si(t.data):new os(t.data):t.type.startsWith(as.TYPE)?new as(t.data,t.data):new gt(t.data):null,cm=()=>{throw new Ze.NotImplemented};Ze.register({encode:cm,decode:om});const um=async(t,e)=>{const[r,n]=await e(t);return n==null?[r,n]:n instanceof Be?[r,new Be({message:`Cannot reach cluster at ${n.url.host}:${n.url.port}`,url:n.url})]:[r,n]},or=i.z.uuid(),fc=i.z.string(),Jr=i.z.object({key:or,name:fc}),lm=t=>({type:"group",key:t}),Kr=i.z.enum(["label","log","allow_all","builtin","cluster","channel","node","group","range","framer","range-alias","user","workspace","schematic","lineplot","rack","device","task","policy","table","arc","schematic_symbol","status"]),dc=i.z.string().transform(t=>{const[e,r]=t.split(":");return{type:Kr.parse(e),key:r??""}}),j=i.z.object({type:Kr,key:i.z.string()}).or(dc),hm={type:"builtin",key:"root"},Tt=(t=>(typeof t=="string"&&(t=dc.parse(t)),Array.isArray(t)?t.map(e=>Tt(e)):`${t.type}:${t.key}`)),fm=(t,e)=>t.type===e.type&&t.key===e.key,pc=t=>{const e=T.toArray(t);return e.length===0?[]:typeof e[0]=="object"&&"id"in e[0]?e.map(({id:r})=>r):e.map(r=>j.parse(r))},yc=i.z.object({id:j,name:i.z.string(),data:be.unknownZ.optional().nullable()}).transform(t=>({key:Tt(t.id),...t})),dm=t=>t==="to"?"from":"to",pm=i.z.object({from:j,type:i.z.string(),to:j}).or(i.z.string().transform(t=>{const[e,r,n]=t.split("->");return{from:j.parse(e),type:r,to:j.parse(n)}})),ym=t=>`${Tt(t.from)}->${t.type}->${Tt(t.to)}`,mm="parent",gm=(t,e)=>!(e.type!=null&&e.type!==t.type||e.from?.type!=null&&e.from.type!==t.from.type||e.to?.type!=null&&e.to.type!==t.to.type||e.from?.key!=null&&e.from.key!==t.from.key||e.to?.key!=null&&e.to.key!==t.to.key),wm="sy_group_set",bm="sy_group_delete",vm=i.object({group:Jr}),Tm=i.object({parent:j,key:or.optional(),name:i.string()}),zm=i.object({key:or,name:i.string()}),Em=i.object({keys:i.array(or)}),Nm="/ontology/create-group",Om="/ontology/rename-group",$m="/ontology/delete-group";let mc=class{client;constructor(e){this.client=e}async create(e){return(await w(this.client,Nm,e,Tm,vm)).group}async rename(e,r){await w(this.client,Om,{key:e,name:r},zm,i.object({}))}async delete(e){await w(this.client,$m,{keys:T.toArray(e)},Em,i.object({}))}};const Sm=Object.freeze(Object.defineProperty({__proto__:null,Client:mc,DELETE_CHANNEL_NAME:bm,SET_CHANNEL_NAME:wm,groupZ:Jr,keyZ:or,nameZ:fc,ontologyID:lm},Symbol.toStringTag,{value:"Module"})),Im="/ontology/add-children",km="/ontology/remove-children",Am="/ontology/move-children",Ii=i.z.object({id:j,children:j.array()}),xm=i.z.object({from:j,to:j,children:j.array()}),$n=i.z.object({});let Zm=class{client;constructor(e){this.client=e}async addChildren(e,...r){await w(this.client,Im,{id:e,children:r},Ii,$n)}async removeChildren(e,...r){await w(this.client,km,{id:e,children:r},Ii,$n)}async moveChildren(e,r,...n){await w(this.client,Am,{from:e,to:r,children:n},xm,$n)}};const Cm="/ontology/retrieve",Rm=i.z.object({ids:j.array().optional(),children:i.z.boolean().optional(),parents:i.z.boolean().optional(),excludeFieldData:i.z.boolean().optional(),searchTerm:i.z.string().optional(),limit:i.z.number().optional(),offset:i.z.number().optional(),types:Kr.array().optional()}),_m=i.z.object({resources:yc.array()});let gc=class{type="ontology";groups;client;writer;framer;constructor(e,r){this.client=e,this.writer=new Zm(e),this.groups=new mc(e),this.framer=r}async retrieve(e,r){if(!Array.isArray(e)&&typeof e=="object"&&!("key"in e))return this.execRetrieve(e);const n=pc(e),s=await this.execRetrieve({ids:n,...r});if(Array.isArray(e))return s;if(s.length===0)throw new Fe(`No resource found with ID ${ns.naturalLanguageJoin(n.map(a=>Tt(a)))}`);return s[0]}async retrieveChildren(e,r){return await this.execRetrieve({ids:T.toArray(e),children:!0,...r})}async retrieveParents(e,r){return await this.execRetrieve({ids:T.toArray(e),parents:!0,...r})}async addChildren(e,...r){return await this.writer.addChildren(e,...r)}async removeChildren(e,...r){return await this.writer.removeChildren(e,...r)}async moveChildren(e,r,...n){return await this.writer.moveChildren(e,r,...n)}async execRetrieve(e){const{resources:r}=await w(this.client,Cm,e,Rm,_m);return r}};const jm="sy_ontology_resource_set",Mm="sy_ontology_resource_delete",Dm="sy_ontology_relationship_set",Pm="sy_ontology_relationship_delete",Um=Object.freeze(Object.defineProperty({__proto__:null,Client:gc,PARENT_OF_RELATIONSHIP_TYPE:mm,RELATIONSHIP_DELETE_CHANNEL_NAME:Pm,RELATIONSHIP_SET_CHANNEL_NAME:Dm,RESOURCE_DELETE_CHANNEL_NAME:Mm,RESOURCE_SET_CHANNEL_NAME:jm,ROOT_ID:hm,idToString:Tt,idZ:j,idsEqual:fm,matchRelationship:gm,oppositeRelationshipDirection:dm,parseIDs:pc,relationshipToString:ym,relationshipZ:pm,resourceTypeZ:Kr,resourceZ:yc},Symbol.toStringTag,{value:"Module"})),kt=i.z.uuid(),Xr=i.z.object({key:kt,subjects:T.nullableZ(j),objects:T.nullableZ(j),actions:T.nullableZ(jr)}),wc=i.z.object({key:kt.optional(),subjects:j.array().or(j),objects:j.array().or(j),actions:jr.array().or(jr)}),Lm=i.z.object({keys:kt.array().optional(),subjects:j.array().optional()}),Bm=i.z.object({key:kt}).transform(({key:t})=>({keys:[t]})),qm=i.z.union([i.z.object({for:j}).transform(({for:t})=>({subjects:[t]})),i.z.object({for:j.array()}).transform(({for:t})=>({subjects:t})),Lm]),Fm=i.z.union([Bm,qm]),Vm=i.z.object({policies:T.nullableZ(Xr)}),Ym=i.z.object({policies:Xr.partial({key:!0}).array()}),Wm=i.z.object({policies:Xr.array()}),Hm=i.z.object({keys:kt.array()}),Gm=i.z.object({}),Jm="/access/policy/retrieve",Km="/access/policy/create",Xm="/access/policy/delete";let bc=class{client;constructor(e){this.client=e}async create(e){const r=Array.isArray(e),s=wc.array().parse(T.toArray(e)).map(o=>({objects:T.toArray(o.objects),actions:T.toArray(o.actions),subjects:T.toArray(o.subjects)})),a=await w(this.client,Km,{policies:s},Ym,Wm);return r?a.policies:a.policies[0]}async retrieve(e){const r="key"in e,n=await w(this.client,Jm,e,Fm,Vm);return r?n.policies[0]:n.policies}async delete(e){await w(this.client,Xm,{keys:T.toArray(e)},Hm,Gm)}};const Qm=t=>({type:"policy",key:t}),eg={type:"allow_all",key:""},tg=Object.freeze(Object.defineProperty({__proto__:null,ALLOW_ALL_ONTOLOGY_ID:eg,Client:bc,keyZ:kt,newZ:wc,ontologyID:Qm,policyZ:Xr},Symbol.toStringTag,{value:"Module"}));let vc=class{policy;constructor(e){this.policy=new bc(e)}};const rg=Object.freeze(Object.defineProperty({__proto__:null,ALL_ACTION:oc,CREATE_ACTION:cc,Client:vc,DELETE_ACTION:uc,RETRIEVE_ACTION:lc,UPDATE_ACTION:hc,actionZ:jr},Symbol.toStringTag,{value:"Module"}));function y(t,e,r){function n(c,l){var u;Object.defineProperty(c,"_zod",{value:c._zod??{},enumerable:!1}),(u=c._zod).traits??(u.traits=new Set),c._zod.traits.add(t),e(c,l);for(const h in o.prototype)h in c||Object.defineProperty(c,h,{value:o.prototype[h].bind(c)});c._zod.constr=o,c._zod.def=l}const s=r?.Parent??Object;class a extends s{}Object.defineProperty(a,"name",{value:t});function o(c){var l;const u=r?.Parent?new a:this;n(u,c),(l=u._zod).deferred??(l.deferred=[]);for(const h of u._zod.deferred)h();return u}return Object.defineProperty(o,"init",{value:n}),Object.defineProperty(o,Symbol.hasInstance,{value:c=>r?.Parent&&c instanceof r.Parent?!0:c?._zod?.traits?.has(t)}),Object.defineProperty(o,"name",{value:t}),o}class wt extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Tc extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const zc={};function rt(t){return zc}function ng(t){const e=Object.values(t).filter(n=>typeof n=="number");return Object.entries(t).filter(([n,s])=>e.indexOf(+n)===-1).map(([n,s])=>s)}function cs(t,e){return typeof e=="bigint"?e.toString():e}function js(t){return{get value(){{const e=t();return Object.defineProperty(this,"value",{value:e}),e}}}}function Ms(t){return t==null}function Ds(t){const e=t.startsWith("^")?1:0,r=t.endsWith("$")?t.length-1:t.length;return t.slice(e,r)}function sg(t,e){const r=(t.toString().split(".")[1]||"").length,n=e.toString();let s=(n.split(".")[1]||"").length;if(s===0&&/\d?e-\d?/.test(n)){const l=n.match(/\d?e-(\d?)/);l?.[1]&&(s=Number.parseInt(l[1]))}const a=r>s?r:s,o=Number.parseInt(t.toFixed(a).replace(".","")),c=Number.parseInt(e.toFixed(a).replace(".",""));return o%c/10**a}const ki=Symbol("evaluating");function U(t,e,r){let n;Object.defineProperty(t,e,{get(){if(n!==ki)return n===void 0&&(n=ki,n=r()),n},set(s){Object.defineProperty(t,e,{value:s})},configurable:!0})}function ig(t){return Object.create(Object.getPrototypeOf(t),Object.getOwnPropertyDescriptors(t))}function Ve(t,e,r){Object.defineProperty(t,e,{value:r,writable:!0,enumerable:!0,configurable:!0})}function At(...t){const e={};for(const r of t){const n=Object.getOwnPropertyDescriptors(r);Object.assign(e,n)}return Object.defineProperties({},e)}function Ai(t){return JSON.stringify(t)}const Ec="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function Mr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}const ag=js(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const t=Function;return new t(""),!0}catch{return!1}});function Jt(t){if(Mr(t)===!1)return!1;const e=t.constructor;if(e===void 0)return!0;const r=e.prototype;return!(Mr(r)===!1||Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")===!1)}function Nc(t){return Jt(t)?{...t}:Array.isArray(t)?[...t]:t}const og=new Set(["string","number","symbol"]);function Qr(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ye(t,e,r){const n=new t._zod.constr(e??t._zod.def);return(!e||r?.parent)&&(n._zod.parent=t),n}function $(t){const e=t;if(!e)return{};if(typeof e=="string")return{error:()=>e};if(e?.message!==void 0){if(e?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");e.error=e.message}return delete e.message,typeof e.error=="string"?{...e,error:()=>e.error}:e}function cg(t){return Object.keys(t).filter(e=>t[e]._zod.optin==="optional"&&t[e]._zod.optout==="optional")}const ug={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function lg(t,e){const r=t._zod.def,n=At(t._zod.def,{get shape(){const s={};for(const a in e){if(!(a in r.shape))throw new Error(`Unrecognized key: "${a}"`);e[a]&&(s[a]=r.shape[a])}return Ve(this,"shape",s),s},checks:[]});return Ye(t,n)}function hg(t,e){const r=t._zod.def,n=At(t._zod.def,{get shape(){const s={...t._zod.def.shape};for(const a in e){if(!(a in r.shape))throw new Error(`Unrecognized key: "${a}"`);e[a]&&delete s[a]}return Ve(this,"shape",s),s},checks:[]});return Ye(t,n)}function fg(t,e){if(!Jt(e))throw new Error("Invalid input to extend: expected a plain object");const r=t._zod.def.checks;if(r&&r.length>0)throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");const s=At(t._zod.def,{get shape(){const a={...t._zod.def.shape,...e};return Ve(this,"shape",a),a},checks:[]});return Ye(t,s)}function dg(t,e){if(!Jt(e))throw new Error("Invalid input to safeExtend: expected a plain object");const r={...t._zod.def,get shape(){const n={...t._zod.def.shape,...e};return Ve(this,"shape",n),n},checks:t._zod.def.checks};return Ye(t,r)}function pg(t,e){const r=At(t._zod.def,{get shape(){const n={...t._zod.def.shape,...e._zod.def.shape};return Ve(this,"shape",n),n},get catchall(){return e._zod.def.catchall},checks:[]});return Ye(t,r)}function yg(t,e,r){const n=At(e._zod.def,{get shape(){const s=e._zod.def.shape,a={...s};if(r)for(const o in r){if(!(o in s))throw new Error(`Unrecognized key: "${o}"`);r[o]&&(a[o]=t?new t({type:"optional",innerType:s[o]}):s[o])}else for(const o in s)a[o]=t?new t({type:"optional",innerType:s[o]}):s[o];return Ve(this,"shape",a),a},checks:[]});return Ye(e,n)}function mg(t,e,r){const n=At(e._zod.def,{get shape(){const s=e._zod.def.shape,a={...s};if(r)for(const o in r){if(!(o in a))throw new Error(`Unrecognized key: "${o}"`);r[o]&&(a[o]=new t({type:"nonoptional",innerType:s[o]}))}else for(const o in s)a[o]=new t({type:"nonoptional",innerType:s[o]});return Ve(this,"shape",a),a},checks:[]});return Ye(e,n)}function dt(t,e=0){if(t.aborted===!0)return!0;for(let r=e;r<t.issues.length;r++)if(t.issues[r]?.continue!==!0)return!0;return!1}function Oc(t,e){return e.map(r=>{var n;return(n=r).path??(n.path=[]),r.path.unshift(t),r})}function Er(t){return typeof t=="string"?t:t?.message}function nt(t,e,r){const n={...t,path:t.path??[]};if(!t.message){const s=Er(t.inst?._zod.def?.error?.(t))??Er(e?.error?.(t))??Er(r.customError?.(t))??Er(r.localeError?.(t))??"Invalid input";n.message=s}return delete n.inst,delete n.continue,e?.reportInput||delete n.input,n}function Ps(t){return Array.isArray(t)?"array":typeof t=="string"?"string":"unknown"}function Kt(...t){const[e,r,n]=t;return typeof e=="string"?{message:e,code:"custom",input:r,inst:n}:{...e}}const $c=(t,e)=>{t.name="$ZodError",Object.defineProperty(t,"_zod",{value:t._zod,enumerable:!1}),Object.defineProperty(t,"issues",{value:e,enumerable:!1}),t.message=JSON.stringify(e,cs,2),Object.defineProperty(t,"toString",{value:()=>t.message,enumerable:!1})},Sc=y("$ZodError",$c),Ic=y("$ZodError",$c,{Parent:Error});function gg(t,e=r=>r.message){const r={},n=[];for(const s of t.issues)s.path.length>0?(r[s.path[0]]=r[s.path[0]]||[],r[s.path[0]].push(e(s))):n.push(e(s));return{formErrors:n,fieldErrors:r}}function wg(t,e){const r=e||function(a){return a.message},n={_errors:[]},s=a=>{for(const o of a.issues)if(o.code==="invalid_union"&&o.errors.length)o.errors.map(c=>s({issues:c}));else if(o.code==="invalid_key")s({issues:o.issues});else if(o.code==="invalid_element")s({issues:o.issues});else if(o.path.length===0)n._errors.push(r(o));else{let c=n,l=0;for(;l<o.path.length;){const u=o.path[l];l===o.path.length-1?(c[u]=c[u]||{_errors:[]},c[u]._errors.push(r(o))):c[u]=c[u]||{_errors:[]},c=c[u],l++}}};return s(t),n}const Us=t=>(e,r,n,s)=>{const a=n?Object.assign(n,{async:!1}):{async:!1},o=e._zod.run({value:r,issues:[]},a);if(o instanceof Promise)throw new wt;if(o.issues.length){const c=new(s?.Err??t)(o.issues.map(l=>nt(l,a,rt())));throw Ec(c,s?.callee),c}return o.value},Ls=t=>async(e,r,n,s)=>{const a=n?Object.assign(n,{async:!0}):{async:!0};let o=e._zod.run({value:r,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){const c=new(s?.Err??t)(o.issues.map(l=>nt(l,a,rt())));throw Ec(c,s?.callee),c}return o.value},en=t=>(e,r,n)=>{const s=n?{...n,async:!1}:{async:!1},a=e._zod.run({value:r,issues:[]},s);if(a instanceof Promise)throw new wt;return a.issues.length?{success:!1,error:new(t??Sc)(a.issues.map(o=>nt(o,s,rt())))}:{success:!0,data:a.value}},bg=en(Ic),tn=t=>async(e,r,n)=>{const s=n?Object.assign(n,{async:!0}):{async:!0};let a=e._zod.run({value:r,issues:[]},s);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new t(a.issues.map(o=>nt(o,s,rt())))}:{success:!0,data:a.value}},vg=tn(Ic),Tg=t=>(e,r,n)=>{const s=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return Us(t)(e,r,s)},zg=t=>(e,r,n)=>Us(t)(e,r,n),Eg=t=>async(e,r,n)=>{const s=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return Ls(t)(e,r,s)},Ng=t=>async(e,r,n)=>Ls(t)(e,r,n),Og=t=>(e,r,n)=>{const s=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return en(t)(e,r,s)},$g=t=>(e,r,n)=>en(t)(e,r,n),Sg=t=>async(e,r,n)=>{const s=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return tn(t)(e,r,s)},Ig=t=>async(e,r,n)=>tn(t)(e,r,n),kg=/^[cC][^\s-]{8,}$/,Ag=/^[0-9a-z]+$/,xg=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Zg=/^[0-9a-vA-V]{20}$/,Cg=/^[A-Za-z0-9]{27}$/,Rg=/^[a-zA-Z0-9_-]{21}$/,_g=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,jg=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,xi=t=>t?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Mg=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Dg="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Pg(){return new RegExp(Dg,"u")}const Ug=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Lg=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,Bg=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,qg=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Fg=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,kc=/^[A-Za-z0-9_-]*$/,Vg=/^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/,Yg=/^\+(?:[0-9]){6,14}[0-9]$/,Ac="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",Wg=new RegExp(`^${Ac}$`);function xc(t){const e="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof t.precision=="number"?t.precision===-1?`${e}`:t.precision===0?`${e}:[0-5]\\d`:`${e}:[0-5]\\d\\.\\d{${t.precision}}`:`${e}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Hg(t){return new RegExp(`^${xc(t)}$`)}function Gg(t){const e=xc({precision:t.precision}),r=["Z"];t.local&&r.push(""),t.offset&&r.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const n=`${e}(?:${r.join("|")})`;return new RegExp(`^${Ac}T(?:${n})$`)}const Jg=t=>{const e=t?`[\\s\\S]{${t?.minimum??0},${t?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${e}$`)},Kg=/^-?\d+$/,Xg=/^-?\d+(?:\.\d+)?/,Qg=/^(?:true|false)$/i,ew=/^[^A-Z]*$/,tw=/^[^a-z]*$/,ae=y("$ZodCheck",(t,e)=>{var r;t._zod??(t._zod={}),t._zod.def=e,(r=t._zod).onattach??(r.onattach=[])}),Zc={number:"number",bigint:"bigint",object:"date"},Cc=y("$ZodCheckLessThan",(t,e)=>{ae.init(t,e);const r=Zc[typeof e.value];t._zod.onattach.push(n=>{const s=n._zod.bag,a=(e.inclusive?s.maximum:s.exclusiveMaximum)??Number.POSITIVE_INFINITY;e.value<a&&(e.inclusive?s.maximum=e.value:s.exclusiveMaximum=e.value)}),t._zod.check=n=>{(e.inclusive?n.value<=e.value:n.value<e.value)||n.issues.push({origin:r,code:"too_big",maximum:e.value,input:n.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),Rc=y("$ZodCheckGreaterThan",(t,e)=>{ae.init(t,e);const r=Zc[typeof e.value];t._zod.onattach.push(n=>{const s=n._zod.bag,a=(e.inclusive?s.minimum:s.exclusiveMinimum)??Number.NEGATIVE_INFINITY;e.value>a&&(e.inclusive?s.minimum=e.value:s.exclusiveMinimum=e.value)}),t._zod.check=n=>{(e.inclusive?n.value>=e.value:n.value>e.value)||n.issues.push({origin:r,code:"too_small",minimum:e.value,input:n.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),rw=y("$ZodCheckMultipleOf",(t,e)=>{ae.init(t,e),t._zod.onattach.push(r=>{var n;(n=r._zod.bag).multipleOf??(n.multipleOf=e.value)}),t._zod.check=r=>{if(typeof r.value!=typeof e.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof r.value=="bigint"?r.value%e.value===BigInt(0):sg(r.value,e.value)===0)||r.issues.push({origin:typeof r.value,code:"not_multiple_of",divisor:e.value,input:r.value,inst:t,continue:!e.abort})}}),nw=y("$ZodCheckNumberFormat",(t,e)=>{ae.init(t,e),e.format=e.format||"float64";const r=e.format?.includes("int"),n=r?"int":"number",[s,a]=ug[e.format];t._zod.onattach.push(o=>{const c=o._zod.bag;c.format=e.format,c.minimum=s,c.maximum=a,r&&(c.pattern=Kg)}),t._zod.check=o=>{const c=o.value;if(r){if(!Number.isInteger(c)){o.issues.push({expected:n,format:e.format,code:"invalid_type",continue:!1,input:c,inst:t});return}if(!Number.isSafeInteger(c)){c>0?o.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:n,continue:!e.abort}):o.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:n,continue:!e.abort});return}}c<s&&o.issues.push({origin:"number",input:c,code:"too_small",minimum:s,inclusive:!0,inst:t,continue:!e.abort}),c>a&&o.issues.push({origin:"number",input:c,code:"too_big",maximum:a,inst:t})}}),sw=y("$ZodCheckMaxLength",(t,e)=>{var r;ae.init(t,e),(r=t._zod.def).when??(r.when=n=>{const s=n.value;return!Ms(s)&&s.length!==void 0}),t._zod.onattach.push(n=>{const s=n._zod.bag.maximum??Number.POSITIVE_INFINITY;e.maximum<s&&(n._zod.bag.maximum=e.maximum)}),t._zod.check=n=>{const s=n.value;if(s.length<=e.maximum)return;const o=Ps(s);n.issues.push({origin:o,code:"too_big",maximum:e.maximum,inclusive:!0,input:s,inst:t,continue:!e.abort})}}),iw=y("$ZodCheckMinLength",(t,e)=>{var r;ae.init(t,e),(r=t._zod.def).when??(r.when=n=>{const s=n.value;return!Ms(s)&&s.length!==void 0}),t._zod.onattach.push(n=>{const s=n._zod.bag.minimum??Number.NEGATIVE_INFINITY;e.minimum>s&&(n._zod.bag.minimum=e.minimum)}),t._zod.check=n=>{const s=n.value;if(s.length>=e.minimum)return;const o=Ps(s);n.issues.push({origin:o,code:"too_small",minimum:e.minimum,inclusive:!0,input:s,inst:t,continue:!e.abort})}}),aw=y("$ZodCheckLengthEquals",(t,e)=>{var r;ae.init(t,e),(r=t._zod.def).when??(r.when=n=>{const s=n.value;return!Ms(s)&&s.length!==void 0}),t._zod.onattach.push(n=>{const s=n._zod.bag;s.minimum=e.length,s.maximum=e.length,s.length=e.length}),t._zod.check=n=>{const s=n.value,a=s.length;if(a===e.length)return;const o=Ps(s),c=a>e.length;n.issues.push({origin:o,...c?{code:"too_big",maximum:e.length}:{code:"too_small",minimum:e.length},inclusive:!0,exact:!0,input:n.value,inst:t,continue:!e.abort})}}),rn=y("$ZodCheckStringFormat",(t,e)=>{var r,n;ae.init(t,e),t._zod.onattach.push(s=>{const a=s._zod.bag;a.format=e.format,e.pattern&&(a.patterns??(a.patterns=new Set),a.patterns.add(e.pattern))}),e.pattern?(r=t._zod).check??(r.check=s=>{e.pattern.lastIndex=0,!e.pattern.test(s.value)&&s.issues.push({origin:"string",code:"invalid_format",format:e.format,input:s.value,...e.pattern?{pattern:e.pattern.toString()}:{},inst:t,continue:!e.abort})}):(n=t._zod).check??(n.check=()=>{})}),ow=y("$ZodCheckRegex",(t,e)=>{rn.init(t,e),t._zod.check=r=>{e.pattern.lastIndex=0,!e.pattern.test(r.value)&&r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:e.pattern.toString(),inst:t,continue:!e.abort})}}),cw=y("$ZodCheckLowerCase",(t,e)=>{e.pattern??(e.pattern=ew),rn.init(t,e)}),uw=y("$ZodCheckUpperCase",(t,e)=>{e.pattern??(e.pattern=tw),rn.init(t,e)}),lw=y("$ZodCheckIncludes",(t,e)=>{ae.init(t,e);const r=Qr(e.includes),n=new RegExp(typeof e.position=="number"?`^.{${e.position}}${r}`:r);e.pattern=n,t._zod.onattach.push(s=>{const a=s._zod.bag;a.patterns??(a.patterns=new Set),a.patterns.add(n)}),t._zod.check=s=>{s.value.includes(e.includes,e.position)||s.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:e.includes,input:s.value,inst:t,continue:!e.abort})}}),hw=y("$ZodCheckStartsWith",(t,e)=>{ae.init(t,e);const r=new RegExp(`^${Qr(e.prefix)}.*`);e.pattern??(e.pattern=r),t._zod.onattach.push(n=>{const s=n._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(r)}),t._zod.check=n=>{n.value.startsWith(e.prefix)||n.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:e.prefix,input:n.value,inst:t,continue:!e.abort})}}),fw=y("$ZodCheckEndsWith",(t,e)=>{ae.init(t,e);const r=new RegExp(`.*${Qr(e.suffix)}$`);e.pattern??(e.pattern=r),t._zod.onattach.push(n=>{const s=n._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(r)}),t._zod.check=n=>{n.value.endsWith(e.suffix)||n.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:e.suffix,input:n.value,inst:t,continue:!e.abort})}}),dw=y("$ZodCheckOverwrite",(t,e)=>{ae.init(t,e),t._zod.check=r=>{r.value=e.tx(r.value)}});class pw{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e=="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}const n=e.split(`
21
+ `)}}class Ve extends Ie.sub("query"){}class Gt extends Ve.sub("not_found"){}class Kt extends Ve.sub("multiple_results"){}class as extends Ie.sub("route"){path;constructor(e,r){super(e),this.path=r}}class os extends Ie.sub("control"){}class Ii extends os.sub("unauthorized"){}class pm extends Ie.sub("disconnected"){constructor(e="Operation failed because no Core is connected."){super(e)}}class ym extends Ie.sub("contiguity"){}const mm=t=>t.type.startsWith(Ie.TYPE)?t.type.startsWith(Y.TYPE)?t.type===Ht.TYPE?Ht.decode(t):new Y(t.data):t.type.startsWith(Wt.TYPE)?t.type.startsWith(ss.TYPE)?new ss(t.data):t.type.startsWith(is.TYPE)?new is(t.data):new Wt(t.data):t.type.startsWith(wt.TYPE)?new wt(t.data):t.type.startsWith(Ve.TYPE)?t.type.startsWith(Gt.TYPE)?new Gt(t.data):t.type.startsWith(Kt.TYPE)?new Kt(t.data):new Ve(t.data):t.type.startsWith(os.TYPE)?t.type.startsWith(Ii.TYPE)?new Ii(t.data):new os(t.data):t.type.startsWith(as.TYPE)?new as(t.data,t.data):new wt(t.data):null,gm=()=>{throw new Ce.NotImplemented};Ce.register({encode:gm,decode:mm});const wm=async(t,e)=>{const[r,n]=await e(t);return n==null?[r,n]:n instanceof qe?[r,new qe({message:`Cannot reach Core at ${n.url.host}:${n.url.port}`,url:n.url})]:[r,n]},or=i.z.uuid(),pc=i.z.string(),Jr=i.z.object({key:or,name:pc}),bm=t=>({type:"group",key:t}),Xr=i.z.enum(["label","log","allow_all","builtin","cluster","channel","node","group","range","framer","range-alias","user","workspace","schematic","lineplot","rack","device","task","policy","table","arc","schematic_symbol","status"]),yc=i.z.string().transform(t=>{const[e,r]=t.split(":");return{type:Xr.parse(e),key:r??""}}),j=i.z.object({type:Xr,key:i.z.string()}).or(yc),vm={type:"builtin",key:"root"},zt=(t=>(typeof t=="string"&&(t=yc.parse(t)),Array.isArray(t)?t.map(e=>zt(e)):`${t.type}:${t.key}`)),Tm=(t,e)=>t.type===e.type&&t.key===e.key,mc=t=>{const e=T.toArray(t);return e.length===0?[]:typeof e[0]=="object"&&"id"in e[0]?e.map(({id:r})=>r):e.map(r=>j.parse(r))},gc=i.z.object({id:j,name:i.z.string(),data:be.unknownZ.optional().nullable()}).transform(t=>({key:zt(t.id),...t})),zm=t=>t==="to"?"from":"to",Em=i.z.object({from:j,type:i.z.string(),to:j}).or(i.z.string().transform(t=>{const[e,r,n]=t.split("->");return{from:j.parse(e),type:r,to:j.parse(n)}})),Nm=t=>`${zt(t.from)}->${t.type}->${zt(t.to)}`,Om="parent",$m=(t,e)=>!(e.type!=null&&e.type!==t.type||e.from?.type!=null&&e.from.type!==t.from.type||e.to?.type!=null&&e.to.type!==t.to.type||e.from?.key!=null&&e.from.key!==t.from.key||e.to?.key!=null&&e.to.key!==t.to.key),Sm="sy_group_set",Im="sy_group_delete",Am=i.object({group:Jr}),km=i.object({parent:j,key:or.optional(),name:i.string()}),xm=i.object({key:or,name:i.string()}),Zm=i.object({keys:i.array(or)}),Cm="/ontology/create-group",Rm="/ontology/rename-group",_m="/ontology/delete-group";let wc=class{client;constructor(e){this.client=e}async create(e){return(await w(this.client,Cm,e,km,Am)).group}async rename(e,r){await w(this.client,Rm,{key:e,name:r},xm,i.object({}))}async delete(e){await w(this.client,_m,{keys:T.toArray(e)},Zm,i.object({}))}};const jm=Object.freeze(Object.defineProperty({__proto__:null,Client:wc,DELETE_CHANNEL_NAME:Im,SET_CHANNEL_NAME:Sm,groupZ:Jr,keyZ:or,nameZ:pc,ontologyID:bm},Symbol.toStringTag,{value:"Module"})),Mm="/ontology/add-children",Dm="/ontology/remove-children",Pm="/ontology/move-children",Ai=i.z.object({id:j,children:j.array()}),Um=i.z.object({from:j,to:j,children:j.array()}),$n=i.z.object({});let Lm=class{client;constructor(e){this.client=e}async addChildren(e,...r){await w(this.client,Mm,{id:e,children:r},Ai,$n)}async removeChildren(e,...r){await w(this.client,Dm,{id:e,children:r},Ai,$n)}async moveChildren(e,r,...n){await w(this.client,Pm,{from:e,to:r,children:n},Um,$n)}};const Bm="/ontology/retrieve",qm=i.z.object({ids:j.array().optional(),children:i.z.boolean().optional(),parents:i.z.boolean().optional(),excludeFieldData:i.z.boolean().optional(),searchTerm:i.z.string().optional(),limit:i.z.number().optional(),offset:i.z.number().optional(),types:Xr.array().optional()}),Fm=i.z.object({resources:gc.array()});let bc=class{type="ontology";groups;client;writer;framer;constructor(e,r){this.client=e,this.writer=new Lm(e),this.groups=new wc(e),this.framer=r}async retrieve(e,r){if(!Array.isArray(e)&&typeof e=="object"&&!("key"in e))return this.execRetrieve(e);const n=mc(e),s=await this.execRetrieve({ids:n,...r});if(Array.isArray(e))return s;if(s.length===0)throw new Ve(`No resource found with ID ${ns.naturalLanguageJoin(n.map(a=>zt(a)))}`);return s[0]}async retrieveChildren(e,r){return await this.execRetrieve({ids:T.toArray(e),children:!0,...r})}async retrieveParents(e,r){return await this.execRetrieve({ids:T.toArray(e),parents:!0,...r})}async addChildren(e,...r){return await this.writer.addChildren(e,...r)}async removeChildren(e,...r){return await this.writer.removeChildren(e,...r)}async moveChildren(e,r,...n){return await this.writer.moveChildren(e,r,...n)}async execRetrieve(e){const{resources:r}=await w(this.client,Bm,e,qm,Fm);return r}};const Vm="sy_ontology_resource_set",Ym="sy_ontology_resource_delete",Hm="sy_ontology_relationship_set",Wm="sy_ontology_relationship_delete",Gm=Object.freeze(Object.defineProperty({__proto__:null,Client:bc,PARENT_OF_RELATIONSHIP_TYPE:Om,RELATIONSHIP_DELETE_CHANNEL_NAME:Wm,RELATIONSHIP_SET_CHANNEL_NAME:Hm,RESOURCE_DELETE_CHANNEL_NAME:Ym,RESOURCE_SET_CHANNEL_NAME:Vm,ROOT_ID:vm,idToString:zt,idZ:j,idsEqual:Tm,matchRelationship:$m,oppositeRelationshipDirection:zm,parseIDs:mc,relationshipToString:Nm,relationshipZ:Em,resourceTypeZ:Xr,resourceZ:gc},Symbol.toStringTag,{value:"Module"})),kt=i.z.uuid(),Qr=i.z.object({key:kt,subjects:T.nullableZ(j),objects:T.nullableZ(j),actions:T.nullableZ(Dr)}),vc=i.z.object({key:kt.optional(),subjects:j.array().or(j),objects:j.array().or(j),actions:Dr.array().or(Dr)}),Km=i.z.object({keys:kt.array().optional(),subjects:j.array().optional()}),Jm=i.z.object({key:kt}).transform(({key:t})=>({keys:[t]})),Xm=i.z.union([i.z.object({for:j}).transform(({for:t})=>({subjects:[t]})),i.z.object({for:j.array()}).transform(({for:t})=>({subjects:t})),Km]),Qm=i.z.union([Jm,Xm]),eg=i.z.object({policies:T.nullableZ(Qr)}),tg=i.z.object({policies:Qr.partial({key:!0}).array()}),rg=i.z.object({policies:Qr.array()}),ng=i.z.object({keys:kt.array()}),sg=i.z.object({}),ig="/access/policy/retrieve",ag="/access/policy/create",og="/access/policy/delete";let Tc=class{client;constructor(e){this.client=e}async create(e){const r=Array.isArray(e),s=vc.array().parse(T.toArray(e)).map(o=>({objects:T.toArray(o.objects),actions:T.toArray(o.actions),subjects:T.toArray(o.subjects)})),a=await w(this.client,ag,{policies:s},tg,rg);return r?a.policies:a.policies[0]}async retrieve(e){const r="key"in e,n=await w(this.client,ig,e,Qm,eg);return r?n.policies[0]:n.policies}async delete(e){await w(this.client,og,{keys:T.toArray(e)},ng,sg)}};const cg=t=>({type:"policy",key:t}),ug={type:"allow_all",key:""},lg=Object.freeze(Object.defineProperty({__proto__:null,ALLOW_ALL_ONTOLOGY_ID:ug,Client:Tc,keyZ:kt,newZ:vc,ontologyID:cg,policyZ:Qr},Symbol.toStringTag,{value:"Module"}));let zc=class{policy;constructor(e){this.policy=new Tc(e)}};const hg=Object.freeze(Object.defineProperty({__proto__:null,ALL_ACTION:uc,CREATE_ACTION:lc,Client:zc,DELETE_ACTION:hc,RETRIEVE_ACTION:fc,UPDATE_ACTION:dc,actionZ:Dr},Symbol.toStringTag,{value:"Module"}));function y(t,e,r){function n(c,l){var u;Object.defineProperty(c,"_zod",{value:c._zod??{},enumerable:!1}),(u=c._zod).traits??(u.traits=new Set),c._zod.traits.add(t),e(c,l);for(const h in o.prototype)h in c||Object.defineProperty(c,h,{value:o.prototype[h].bind(c)});c._zod.constr=o,c._zod.def=l}const s=r?.Parent??Object;class a extends s{}Object.defineProperty(a,"name",{value:t});function o(c){var l;const u=r?.Parent?new a:this;n(u,c),(l=u._zod).deferred??(l.deferred=[]);for(const h of u._zod.deferred)h();return u}return Object.defineProperty(o,"init",{value:n}),Object.defineProperty(o,Symbol.hasInstance,{value:c=>r?.Parent&&c instanceof r.Parent?!0:c?._zod?.traits?.has(t)}),Object.defineProperty(o,"name",{value:t}),o}class bt extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Ec extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const Nc={};function nt(t){return Nc}function fg(t){const e=Object.values(t).filter(n=>typeof n=="number");return Object.entries(t).filter(([n,s])=>e.indexOf(+n)===-1).map(([n,s])=>s)}function cs(t,e){return typeof e=="bigint"?e.toString():e}function js(t){return{get value(){{const e=t();return Object.defineProperty(this,"value",{value:e}),e}}}}function Ms(t){return t==null}function Ds(t){const e=t.startsWith("^")?1:0,r=t.endsWith("$")?t.length-1:t.length;return t.slice(e,r)}function dg(t,e){const r=(t.toString().split(".")[1]||"").length,n=e.toString();let s=(n.split(".")[1]||"").length;if(s===0&&/\d?e-\d?/.test(n)){const l=n.match(/\d?e-(\d?)/);l?.[1]&&(s=Number.parseInt(l[1]))}const a=r>s?r:s,o=Number.parseInt(t.toFixed(a).replace(".","")),c=Number.parseInt(e.toFixed(a).replace(".",""));return o%c/10**a}const ki=Symbol("evaluating");function P(t,e,r){let n;Object.defineProperty(t,e,{get(){if(n!==ki)return n===void 0&&(n=ki,n=r()),n},set(s){Object.defineProperty(t,e,{value:s})},configurable:!0})}function pg(t){return Object.create(Object.getPrototypeOf(t),Object.getOwnPropertyDescriptors(t))}function Ye(t,e,r){Object.defineProperty(t,e,{value:r,writable:!0,enumerable:!0,configurable:!0})}function xt(...t){const e={};for(const r of t){const n=Object.getOwnPropertyDescriptors(r);Object.assign(e,n)}return Object.defineProperties({},e)}function xi(t){return JSON.stringify(t)}const Oc="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function Pr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}const yg=js(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const t=Function;return new t(""),!0}catch{return!1}});function Jt(t){if(Pr(t)===!1)return!1;const e=t.constructor;if(e===void 0)return!0;const r=e.prototype;return!(Pr(r)===!1||Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")===!1)}function $c(t){return Jt(t)?{...t}:Array.isArray(t)?[...t]:t}const mg=new Set(["string","number","symbol"]);function en(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function He(t,e,r){const n=new t._zod.constr(e??t._zod.def);return(!e||r?.parent)&&(n._zod.parent=t),n}function $(t){const e=t;if(!e)return{};if(typeof e=="string")return{error:()=>e};if(e?.message!==void 0){if(e?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");e.error=e.message}return delete e.message,typeof e.error=="string"?{...e,error:()=>e.error}:e}function gg(t){return Object.keys(t).filter(e=>t[e]._zod.optin==="optional"&&t[e]._zod.optout==="optional")}const wg={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function bg(t,e){const r=t._zod.def,n=xt(t._zod.def,{get shape(){const s={};for(const a in e){if(!(a in r.shape))throw new Error(`Unrecognized key: "${a}"`);e[a]&&(s[a]=r.shape[a])}return Ye(this,"shape",s),s},checks:[]});return He(t,n)}function vg(t,e){const r=t._zod.def,n=xt(t._zod.def,{get shape(){const s={...t._zod.def.shape};for(const a in e){if(!(a in r.shape))throw new Error(`Unrecognized key: "${a}"`);e[a]&&delete s[a]}return Ye(this,"shape",s),s},checks:[]});return He(t,n)}function Tg(t,e){if(!Jt(e))throw new Error("Invalid input to extend: expected a plain object");const r=t._zod.def.checks;if(r&&r.length>0)throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");const s=xt(t._zod.def,{get shape(){const a={...t._zod.def.shape,...e};return Ye(this,"shape",a),a},checks:[]});return He(t,s)}function zg(t,e){if(!Jt(e))throw new Error("Invalid input to safeExtend: expected a plain object");const r={...t._zod.def,get shape(){const n={...t._zod.def.shape,...e};return Ye(this,"shape",n),n},checks:t._zod.def.checks};return He(t,r)}function Eg(t,e){const r=xt(t._zod.def,{get shape(){const n={...t._zod.def.shape,...e._zod.def.shape};return Ye(this,"shape",n),n},get catchall(){return e._zod.def.catchall},checks:[]});return He(t,r)}function Ng(t,e,r){const n=xt(e._zod.def,{get shape(){const s=e._zod.def.shape,a={...s};if(r)for(const o in r){if(!(o in s))throw new Error(`Unrecognized key: "${o}"`);r[o]&&(a[o]=t?new t({type:"optional",innerType:s[o]}):s[o])}else for(const o in s)a[o]=t?new t({type:"optional",innerType:s[o]}):s[o];return Ye(this,"shape",a),a},checks:[]});return He(e,n)}function Og(t,e,r){const n=xt(e._zod.def,{get shape(){const s=e._zod.def.shape,a={...s};if(r)for(const o in r){if(!(o in a))throw new Error(`Unrecognized key: "${o}"`);r[o]&&(a[o]=new t({type:"nonoptional",innerType:s[o]}))}else for(const o in s)a[o]=new t({type:"nonoptional",innerType:s[o]});return Ye(this,"shape",a),a},checks:[]});return He(e,n)}function pt(t,e=0){if(t.aborted===!0)return!0;for(let r=e;r<t.issues.length;r++)if(t.issues[r]?.continue!==!0)return!0;return!1}function Sc(t,e){return e.map(r=>{var n;return(n=r).path??(n.path=[]),r.path.unshift(t),r})}function Or(t){return typeof t=="string"?t:t?.message}function st(t,e,r){const n={...t,path:t.path??[]};if(!t.message){const s=Or(t.inst?._zod.def?.error?.(t))??Or(e?.error?.(t))??Or(r.customError?.(t))??Or(r.localeError?.(t))??"Invalid input";n.message=s}return delete n.inst,delete n.continue,e?.reportInput||delete n.input,n}function Ps(t){return Array.isArray(t)?"array":typeof t=="string"?"string":"unknown"}function Xt(...t){const[e,r,n]=t;return typeof e=="string"?{message:e,code:"custom",input:r,inst:n}:{...e}}const Ic=(t,e)=>{t.name="$ZodError",Object.defineProperty(t,"_zod",{value:t._zod,enumerable:!1}),Object.defineProperty(t,"issues",{value:e,enumerable:!1}),t.message=JSON.stringify(e,cs,2),Object.defineProperty(t,"toString",{value:()=>t.message,enumerable:!1})},Ac=y("$ZodError",Ic),kc=y("$ZodError",Ic,{Parent:Error});function $g(t,e=r=>r.message){const r={},n=[];for(const s of t.issues)s.path.length>0?(r[s.path[0]]=r[s.path[0]]||[],r[s.path[0]].push(e(s))):n.push(e(s));return{formErrors:n,fieldErrors:r}}function Sg(t,e){const r=e||function(a){return a.message},n={_errors:[]},s=a=>{for(const o of a.issues)if(o.code==="invalid_union"&&o.errors.length)o.errors.map(c=>s({issues:c}));else if(o.code==="invalid_key")s({issues:o.issues});else if(o.code==="invalid_element")s({issues:o.issues});else if(o.path.length===0)n._errors.push(r(o));else{let c=n,l=0;for(;l<o.path.length;){const u=o.path[l];l===o.path.length-1?(c[u]=c[u]||{_errors:[]},c[u]._errors.push(r(o))):c[u]=c[u]||{_errors:[]},c=c[u],l++}}};return s(t),n}const Us=t=>(e,r,n,s)=>{const a=n?Object.assign(n,{async:!1}):{async:!1},o=e._zod.run({value:r,issues:[]},a);if(o instanceof Promise)throw new bt;if(o.issues.length){const c=new(s?.Err??t)(o.issues.map(l=>st(l,a,nt())));throw Oc(c,s?.callee),c}return o.value},Ls=t=>async(e,r,n,s)=>{const a=n?Object.assign(n,{async:!0}):{async:!0};let o=e._zod.run({value:r,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){const c=new(s?.Err??t)(o.issues.map(l=>st(l,a,nt())));throw Oc(c,s?.callee),c}return o.value},tn=t=>(e,r,n)=>{const s=n?{...n,async:!1}:{async:!1},a=e._zod.run({value:r,issues:[]},s);if(a instanceof Promise)throw new bt;return a.issues.length?{success:!1,error:new(t??Ac)(a.issues.map(o=>st(o,s,nt())))}:{success:!0,data:a.value}},Ig=tn(kc),rn=t=>async(e,r,n)=>{const s=n?Object.assign(n,{async:!0}):{async:!0};let a=e._zod.run({value:r,issues:[]},s);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new t(a.issues.map(o=>st(o,s,nt())))}:{success:!0,data:a.value}},Ag=rn(kc),kg=t=>(e,r,n)=>{const s=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return Us(t)(e,r,s)},xg=t=>(e,r,n)=>Us(t)(e,r,n),Zg=t=>async(e,r,n)=>{const s=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return Ls(t)(e,r,s)},Cg=t=>async(e,r,n)=>Ls(t)(e,r,n),Rg=t=>(e,r,n)=>{const s=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return tn(t)(e,r,s)},_g=t=>(e,r,n)=>tn(t)(e,r,n),jg=t=>async(e,r,n)=>{const s=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return rn(t)(e,r,s)},Mg=t=>async(e,r,n)=>rn(t)(e,r,n),Dg=/^[cC][^\s-]{8,}$/,Pg=/^[0-9a-z]+$/,Ug=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Lg=/^[0-9a-vA-V]{20}$/,Bg=/^[A-Za-z0-9]{27}$/,qg=/^[a-zA-Z0-9_-]{21}$/,Fg=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Vg=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Zi=t=>t?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Yg=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Hg="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Wg(){return new RegExp(Hg,"u")}const Gg=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Kg=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,Jg=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Xg=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Qg=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,xc=/^[A-Za-z0-9_-]*$/,ew=/^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/,tw=/^\+(?:[0-9]){6,14}[0-9]$/,Zc="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",rw=new RegExp(`^${Zc}$`);function Cc(t){const e="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof t.precision=="number"?t.precision===-1?`${e}`:t.precision===0?`${e}:[0-5]\\d`:`${e}:[0-5]\\d\\.\\d{${t.precision}}`:`${e}(?::[0-5]\\d(?:\\.\\d+)?)?`}function nw(t){return new RegExp(`^${Cc(t)}$`)}function sw(t){const e=Cc({precision:t.precision}),r=["Z"];t.local&&r.push(""),t.offset&&r.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const n=`${e}(?:${r.join("|")})`;return new RegExp(`^${Zc}T(?:${n})$`)}const iw=t=>{const e=t?`[\\s\\S]{${t?.minimum??0},${t?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${e}$`)},aw=/^-?\d+$/,ow=/^-?\d+(?:\.\d+)?/,cw=/^(?:true|false)$/i,uw=/^[^A-Z]*$/,lw=/^[^a-z]*$/,ae=y("$ZodCheck",(t,e)=>{var r;t._zod??(t._zod={}),t._zod.def=e,(r=t._zod).onattach??(r.onattach=[])}),Rc={number:"number",bigint:"bigint",object:"date"},_c=y("$ZodCheckLessThan",(t,e)=>{ae.init(t,e);const r=Rc[typeof e.value];t._zod.onattach.push(n=>{const s=n._zod.bag,a=(e.inclusive?s.maximum:s.exclusiveMaximum)??Number.POSITIVE_INFINITY;e.value<a&&(e.inclusive?s.maximum=e.value:s.exclusiveMaximum=e.value)}),t._zod.check=n=>{(e.inclusive?n.value<=e.value:n.value<e.value)||n.issues.push({origin:r,code:"too_big",maximum:e.value,input:n.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),jc=y("$ZodCheckGreaterThan",(t,e)=>{ae.init(t,e);const r=Rc[typeof e.value];t._zod.onattach.push(n=>{const s=n._zod.bag,a=(e.inclusive?s.minimum:s.exclusiveMinimum)??Number.NEGATIVE_INFINITY;e.value>a&&(e.inclusive?s.minimum=e.value:s.exclusiveMinimum=e.value)}),t._zod.check=n=>{(e.inclusive?n.value>=e.value:n.value>e.value)||n.issues.push({origin:r,code:"too_small",minimum:e.value,input:n.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),hw=y("$ZodCheckMultipleOf",(t,e)=>{ae.init(t,e),t._zod.onattach.push(r=>{var n;(n=r._zod.bag).multipleOf??(n.multipleOf=e.value)}),t._zod.check=r=>{if(typeof r.value!=typeof e.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof r.value=="bigint"?r.value%e.value===BigInt(0):dg(r.value,e.value)===0)||r.issues.push({origin:typeof r.value,code:"not_multiple_of",divisor:e.value,input:r.value,inst:t,continue:!e.abort})}}),fw=y("$ZodCheckNumberFormat",(t,e)=>{ae.init(t,e),e.format=e.format||"float64";const r=e.format?.includes("int"),n=r?"int":"number",[s,a]=wg[e.format];t._zod.onattach.push(o=>{const c=o._zod.bag;c.format=e.format,c.minimum=s,c.maximum=a,r&&(c.pattern=aw)}),t._zod.check=o=>{const c=o.value;if(r){if(!Number.isInteger(c)){o.issues.push({expected:n,format:e.format,code:"invalid_type",continue:!1,input:c,inst:t});return}if(!Number.isSafeInteger(c)){c>0?o.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:n,continue:!e.abort}):o.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:n,continue:!e.abort});return}}c<s&&o.issues.push({origin:"number",input:c,code:"too_small",minimum:s,inclusive:!0,inst:t,continue:!e.abort}),c>a&&o.issues.push({origin:"number",input:c,code:"too_big",maximum:a,inst:t})}}),dw=y("$ZodCheckMaxLength",(t,e)=>{var r;ae.init(t,e),(r=t._zod.def).when??(r.when=n=>{const s=n.value;return!Ms(s)&&s.length!==void 0}),t._zod.onattach.push(n=>{const s=n._zod.bag.maximum??Number.POSITIVE_INFINITY;e.maximum<s&&(n._zod.bag.maximum=e.maximum)}),t._zod.check=n=>{const s=n.value;if(s.length<=e.maximum)return;const o=Ps(s);n.issues.push({origin:o,code:"too_big",maximum:e.maximum,inclusive:!0,input:s,inst:t,continue:!e.abort})}}),pw=y("$ZodCheckMinLength",(t,e)=>{var r;ae.init(t,e),(r=t._zod.def).when??(r.when=n=>{const s=n.value;return!Ms(s)&&s.length!==void 0}),t._zod.onattach.push(n=>{const s=n._zod.bag.minimum??Number.NEGATIVE_INFINITY;e.minimum>s&&(n._zod.bag.minimum=e.minimum)}),t._zod.check=n=>{const s=n.value;if(s.length>=e.minimum)return;const o=Ps(s);n.issues.push({origin:o,code:"too_small",minimum:e.minimum,inclusive:!0,input:s,inst:t,continue:!e.abort})}}),yw=y("$ZodCheckLengthEquals",(t,e)=>{var r;ae.init(t,e),(r=t._zod.def).when??(r.when=n=>{const s=n.value;return!Ms(s)&&s.length!==void 0}),t._zod.onattach.push(n=>{const s=n._zod.bag;s.minimum=e.length,s.maximum=e.length,s.length=e.length}),t._zod.check=n=>{const s=n.value,a=s.length;if(a===e.length)return;const o=Ps(s),c=a>e.length;n.issues.push({origin:o,...c?{code:"too_big",maximum:e.length}:{code:"too_small",minimum:e.length},inclusive:!0,exact:!0,input:n.value,inst:t,continue:!e.abort})}}),nn=y("$ZodCheckStringFormat",(t,e)=>{var r,n;ae.init(t,e),t._zod.onattach.push(s=>{const a=s._zod.bag;a.format=e.format,e.pattern&&(a.patterns??(a.patterns=new Set),a.patterns.add(e.pattern))}),e.pattern?(r=t._zod).check??(r.check=s=>{e.pattern.lastIndex=0,!e.pattern.test(s.value)&&s.issues.push({origin:"string",code:"invalid_format",format:e.format,input:s.value,...e.pattern?{pattern:e.pattern.toString()}:{},inst:t,continue:!e.abort})}):(n=t._zod).check??(n.check=()=>{})}),mw=y("$ZodCheckRegex",(t,e)=>{nn.init(t,e),t._zod.check=r=>{e.pattern.lastIndex=0,!e.pattern.test(r.value)&&r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:e.pattern.toString(),inst:t,continue:!e.abort})}}),gw=y("$ZodCheckLowerCase",(t,e)=>{e.pattern??(e.pattern=uw),nn.init(t,e)}),ww=y("$ZodCheckUpperCase",(t,e)=>{e.pattern??(e.pattern=lw),nn.init(t,e)}),bw=y("$ZodCheckIncludes",(t,e)=>{ae.init(t,e);const r=en(e.includes),n=new RegExp(typeof e.position=="number"?`^.{${e.position}}${r}`:r);e.pattern=n,t._zod.onattach.push(s=>{const a=s._zod.bag;a.patterns??(a.patterns=new Set),a.patterns.add(n)}),t._zod.check=s=>{s.value.includes(e.includes,e.position)||s.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:e.includes,input:s.value,inst:t,continue:!e.abort})}}),vw=y("$ZodCheckStartsWith",(t,e)=>{ae.init(t,e);const r=new RegExp(`^${en(e.prefix)}.*`);e.pattern??(e.pattern=r),t._zod.onattach.push(n=>{const s=n._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(r)}),t._zod.check=n=>{n.value.startsWith(e.prefix)||n.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:e.prefix,input:n.value,inst:t,continue:!e.abort})}}),Tw=y("$ZodCheckEndsWith",(t,e)=>{ae.init(t,e);const r=new RegExp(`.*${en(e.suffix)}$`);e.pattern??(e.pattern=r),t._zod.onattach.push(n=>{const s=n._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(r)}),t._zod.check=n=>{n.value.endsWith(e.suffix)||n.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:e.suffix,input:n.value,inst:t,continue:!e.abort})}}),zw=y("$ZodCheckOverwrite",(t,e)=>{ae.init(t,e),t._zod.check=r=>{r.value=e.tx(r.value)}});class Ew{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e=="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}const n=e.split(`
22
22
  `).filter(o=>o),s=Math.min(...n.map(o=>o.length-o.trimStart().length)),a=n.map(o=>o.slice(s)).map(o=>" ".repeat(this.indent*2)+o);for(const o of a)this.content.push(o)}compile(){const e=Function,r=this?.args,s=[...(this?.content??[""]).map(a=>` ${a}`)];return new e(...r,s.join(`
23
- `))}}const yw={major:4,minor:1,patch:8},F=y("$ZodType",(t,e)=>{var r;t??(t={}),t._zod.def=e,t._zod.bag=t._zod.bag||{},t._zod.version=yw;const n=[...t._zod.def.checks??[]];t._zod.traits.has("$ZodCheck")&&n.unshift(t);for(const s of n)for(const a of s._zod.onattach)a(t);if(n.length===0)(r=t._zod).deferred??(r.deferred=[]),t._zod.deferred?.push(()=>{t._zod.run=t._zod.parse});else{const s=(o,c,l)=>{let u=dt(o),h;for(const d of c){if(d._zod.def.when){if(!d._zod.def.when(o))continue}else if(u)continue;const f=o.issues.length,v=d._zod.check(o);if(v instanceof Promise&&l?.async===!1)throw new wt;if(h||v instanceof Promise)h=(h??Promise.resolve()).then(async()=>{await v,o.issues.length!==f&&(u||(u=dt(o,f)))});else{if(o.issues.length===f)continue;u||(u=dt(o,f))}}return h?h.then(()=>o):o},a=(o,c,l)=>{if(dt(o))return o.aborted=!0,o;const u=s(c,n,l);if(u instanceof Promise){if(l.async===!1)throw new wt;return u.then(h=>t._zod.parse(h,l))}return t._zod.parse(u,l)};t._zod.run=(o,c)=>{if(c.skipChecks)return t._zod.parse(o,c);if(c.direction==="backward"){const u=t._zod.parse({value:o.value,issues:[]},{...c,skipChecks:!0});return u instanceof Promise?u.then(h=>a(h,o,c)):a(u,o,c)}const l=t._zod.parse(o,c);if(l instanceof Promise){if(c.async===!1)throw new wt;return l.then(u=>s(u,n,c))}return s(l,n,c)}}t["~standard"]={validate:s=>{try{const a=bg(t,s);return a.success?{value:a.data}:{issues:a.error?.issues}}catch{return vg(t,s).then(o=>o.success?{value:o.data}:{issues:o.error?.issues})}},vendor:"zod",version:1}}),Bs=y("$ZodString",(t,e)=>{F.init(t,e),t._zod.pattern=[...t?._zod.bag?.patterns??[]].pop()??Jg(t._zod.bag),t._zod.parse=(r,n)=>{if(e.coerce)try{r.value=String(r.value)}catch{}return typeof r.value=="string"||r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:t}),r}}),L=y("$ZodStringFormat",(t,e)=>{rn.init(t,e),Bs.init(t,e)}),mw=y("$ZodGUID",(t,e)=>{e.pattern??(e.pattern=jg),L.init(t,e)}),gw=y("$ZodUUID",(t,e)=>{if(e.version){const n={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[e.version];if(n===void 0)throw new Error(`Invalid UUID version: "${e.version}"`);e.pattern??(e.pattern=xi(n))}else e.pattern??(e.pattern=xi());L.init(t,e)}),ww=y("$ZodEmail",(t,e)=>{e.pattern??(e.pattern=Mg),L.init(t,e)}),bw=y("$ZodURL",(t,e)=>{L.init(t,e),t._zod.check=r=>{try{const n=r.value.trim(),s=new URL(n);e.hostname&&(e.hostname.lastIndex=0,e.hostname.test(s.hostname)||r.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:Vg.source,input:r.value,inst:t,continue:!e.abort})),e.protocol&&(e.protocol.lastIndex=0,e.protocol.test(s.protocol.endsWith(":")?s.protocol.slice(0,-1):s.protocol)||r.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:e.protocol.source,input:r.value,inst:t,continue:!e.abort})),e.normalize?r.value=s.href:r.value=n;return}catch{r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:t,continue:!e.abort})}}}),vw=y("$ZodEmoji",(t,e)=>{e.pattern??(e.pattern=Pg()),L.init(t,e)}),Tw=y("$ZodNanoID",(t,e)=>{e.pattern??(e.pattern=Rg),L.init(t,e)}),zw=y("$ZodCUID",(t,e)=>{e.pattern??(e.pattern=kg),L.init(t,e)}),Ew=y("$ZodCUID2",(t,e)=>{e.pattern??(e.pattern=Ag),L.init(t,e)}),Nw=y("$ZodULID",(t,e)=>{e.pattern??(e.pattern=xg),L.init(t,e)}),Ow=y("$ZodXID",(t,e)=>{e.pattern??(e.pattern=Zg),L.init(t,e)}),$w=y("$ZodKSUID",(t,e)=>{e.pattern??(e.pattern=Cg),L.init(t,e)}),Sw=y("$ZodISODateTime",(t,e)=>{e.pattern??(e.pattern=Gg(e)),L.init(t,e)}),Iw=y("$ZodISODate",(t,e)=>{e.pattern??(e.pattern=Wg),L.init(t,e)}),kw=y("$ZodISOTime",(t,e)=>{e.pattern??(e.pattern=Hg(e)),L.init(t,e)}),Aw=y("$ZodISODuration",(t,e)=>{e.pattern??(e.pattern=_g),L.init(t,e)}),xw=y("$ZodIPv4",(t,e)=>{e.pattern??(e.pattern=Ug),L.init(t,e),t._zod.onattach.push(r=>{const n=r._zod.bag;n.format="ipv4"})}),Zw=y("$ZodIPv6",(t,e)=>{e.pattern??(e.pattern=Lg),L.init(t,e),t._zod.onattach.push(r=>{const n=r._zod.bag;n.format="ipv6"}),t._zod.check=r=>{try{new URL(`http://[${r.value}]`)}catch{r.issues.push({code:"invalid_format",format:"ipv6",input:r.value,inst:t,continue:!e.abort})}}}),Cw=y("$ZodCIDRv4",(t,e)=>{e.pattern??(e.pattern=Bg),L.init(t,e)}),Rw=y("$ZodCIDRv6",(t,e)=>{e.pattern??(e.pattern=qg),L.init(t,e),t._zod.check=r=>{const n=r.value.split("/");try{if(n.length!==2)throw new Error;const[s,a]=n;if(!a)throw new Error;const o=Number(a);if(`${o}`!==a)throw new Error;if(o<0||o>128)throw new Error;new URL(`http://[${s}]`)}catch{r.issues.push({code:"invalid_format",format:"cidrv6",input:r.value,inst:t,continue:!e.abort})}}});function _c(t){if(t==="")return!0;if(t.length%4!==0)return!1;try{return atob(t),!0}catch{return!1}}const _w=y("$ZodBase64",(t,e)=>{e.pattern??(e.pattern=Fg),L.init(t,e),t._zod.onattach.push(r=>{r._zod.bag.contentEncoding="base64"}),t._zod.check=r=>{_c(r.value)||r.issues.push({code:"invalid_format",format:"base64",input:r.value,inst:t,continue:!e.abort})}});function jw(t){if(!kc.test(t))return!1;const e=t.replace(/[-_]/g,n=>n==="-"?"+":"/"),r=e.padEnd(Math.ceil(e.length/4)*4,"=");return _c(r)}const Mw=y("$ZodBase64URL",(t,e)=>{e.pattern??(e.pattern=kc),L.init(t,e),t._zod.onattach.push(r=>{r._zod.bag.contentEncoding="base64url"}),t._zod.check=r=>{jw(r.value)||r.issues.push({code:"invalid_format",format:"base64url",input:r.value,inst:t,continue:!e.abort})}}),Dw=y("$ZodE164",(t,e)=>{e.pattern??(e.pattern=Yg),L.init(t,e)});function Pw(t,e=null){try{const r=t.split(".");if(r.length!==3)return!1;const[n]=r;if(!n)return!1;const s=JSON.parse(atob(n));return!("typ"in s&&s?.typ!=="JWT"||!s.alg||e&&(!("alg"in s)||s.alg!==e))}catch{return!1}}const Uw=y("$ZodJWT",(t,e)=>{L.init(t,e),t._zod.check=r=>{Pw(r.value,e.alg)||r.issues.push({code:"invalid_format",format:"jwt",input:r.value,inst:t,continue:!e.abort})}}),jc=y("$ZodNumber",(t,e)=>{F.init(t,e),t._zod.pattern=t._zod.bag.pattern??Xg,t._zod.parse=(r,n)=>{if(e.coerce)try{r.value=Number(r.value)}catch{}const s=r.value;if(typeof s=="number"&&!Number.isNaN(s)&&Number.isFinite(s))return r;const a=typeof s=="number"?Number.isNaN(s)?"NaN":Number.isFinite(s)?void 0:"Infinity":void 0;return r.issues.push({expected:"number",code:"invalid_type",input:s,inst:t,...a?{received:a}:{}}),r}}),Lw=y("$ZodNumber",(t,e)=>{nw.init(t,e),jc.init(t,e)}),Bw=y("$ZodBoolean",(t,e)=>{F.init(t,e),t._zod.pattern=Qg,t._zod.parse=(r,n)=>{if(e.coerce)try{r.value=!!r.value}catch{}const s=r.value;return typeof s=="boolean"||r.issues.push({expected:"boolean",code:"invalid_type",input:s,inst:t}),r}}),qw=y("$ZodUnknown",(t,e)=>{F.init(t,e),t._zod.parse=r=>r}),Fw=y("$ZodNever",(t,e)=>{F.init(t,e),t._zod.parse=(r,n)=>(r.issues.push({expected:"never",code:"invalid_type",input:r.value,inst:t}),r)});function Zi(t,e,r){t.issues.length&&e.issues.push(...Oc(r,t.issues)),e.value[r]=t.value}const Vw=y("$ZodArray",(t,e)=>{F.init(t,e),t._zod.parse=(r,n)=>{const s=r.value;if(!Array.isArray(s))return r.issues.push({expected:"array",code:"invalid_type",input:s,inst:t}),r;r.value=Array(s.length);const a=[];for(let o=0;o<s.length;o++){const c=s[o],l=e.element._zod.run({value:c,issues:[]},n);l instanceof Promise?a.push(l.then(u=>Zi(u,r,o))):Zi(l,r,o)}return a.length?Promise.all(a).then(()=>r):r}});function Dr(t,e,r,n){t.issues.length&&e.issues.push(...Oc(r,t.issues)),t.value===void 0?r in n&&(e.value[r]=void 0):e.value[r]=t.value}function Mc(t){const e=Object.keys(t.shape);for(const n of e)if(!t.shape?.[n]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${n}": expected a Zod schema`);const r=cg(t.shape);return{...t,keys:e,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(r)}}function Dc(t,e,r,n,s,a){const o=[],c=s.keySet,l=s.catchall._zod,u=l.def.type;for(const h of Object.keys(e)){if(c.has(h))continue;if(u==="never"){o.push(h);continue}const d=l.run({value:e[h],issues:[]},n);d instanceof Promise?t.push(d.then(f=>Dr(f,r,h,e))):Dr(d,r,h,e)}return o.length&&r.issues.push({code:"unrecognized_keys",keys:o,input:e,inst:a}),t.length?Promise.all(t).then(()=>r):r}const Yw=y("$ZodObject",(t,e)=>{F.init(t,e);const r=js(()=>Mc(e));U(t._zod,"propValues",()=>{const o=e.shape,c={};for(const l in o){const u=o[l]._zod;if(u.values){c[l]??(c[l]=new Set);for(const h of u.values)c[l].add(h)}}return c});const n=Mr,s=e.catchall;let a;t._zod.parse=(o,c)=>{a??(a=r.value);const l=o.value;if(!n(l))return o.issues.push({expected:"object",code:"invalid_type",input:l,inst:t}),o;o.value={};const u=[],h=a.shape;for(const d of a.keys){const v=h[d]._zod.run({value:l[d],issues:[]},c);v instanceof Promise?u.push(v.then(S=>Dr(S,o,d,l))):Dr(v,o,d,l)}return s?Dc(u,l,o,c,r.value,t):u.length?Promise.all(u).then(()=>o):o}}),Ww=y("$ZodObjectJIT",(t,e)=>{Yw.init(t,e);const r=t._zod.parse,n=js(()=>Mc(e)),s=f=>{const v=new pw(["shape","payload","ctx"]),S=n.value,Z=G=>{const V=Ai(G);return`shape[${V}]._zod.run({ value: input[${V}], issues: [] }, ctx)`};v.write("const input = payload.value;");const b=Object.create(null);let z=0;for(const G of S.keys)b[G]=`key_${z++}`;v.write("const newResult = {};");for(const G of S.keys){const V=b[G],ye=Ai(G);v.write(`const ${V} = ${Z(G)};`),v.write(`
23
+ `))}}const Nw={major:4,minor:1,patch:8},F=y("$ZodType",(t,e)=>{var r;t??(t={}),t._zod.def=e,t._zod.bag=t._zod.bag||{},t._zod.version=Nw;const n=[...t._zod.def.checks??[]];t._zod.traits.has("$ZodCheck")&&n.unshift(t);for(const s of n)for(const a of s._zod.onattach)a(t);if(n.length===0)(r=t._zod).deferred??(r.deferred=[]),t._zod.deferred?.push(()=>{t._zod.run=t._zod.parse});else{const s=(o,c,l)=>{let u=pt(o),h;for(const d of c){if(d._zod.def.when){if(!d._zod.def.when(o))continue}else if(u)continue;const f=o.issues.length,v=d._zod.check(o);if(v instanceof Promise&&l?.async===!1)throw new bt;if(h||v instanceof Promise)h=(h??Promise.resolve()).then(async()=>{await v,o.issues.length!==f&&(u||(u=pt(o,f)))});else{if(o.issues.length===f)continue;u||(u=pt(o,f))}}return h?h.then(()=>o):o},a=(o,c,l)=>{if(pt(o))return o.aborted=!0,o;const u=s(c,n,l);if(u instanceof Promise){if(l.async===!1)throw new bt;return u.then(h=>t._zod.parse(h,l))}return t._zod.parse(u,l)};t._zod.run=(o,c)=>{if(c.skipChecks)return t._zod.parse(o,c);if(c.direction==="backward"){const u=t._zod.parse({value:o.value,issues:[]},{...c,skipChecks:!0});return u instanceof Promise?u.then(h=>a(h,o,c)):a(u,o,c)}const l=t._zod.parse(o,c);if(l instanceof Promise){if(c.async===!1)throw new bt;return l.then(u=>s(u,n,c))}return s(l,n,c)}}t["~standard"]={validate:s=>{try{const a=Ig(t,s);return a.success?{value:a.data}:{issues:a.error?.issues}}catch{return Ag(t,s).then(o=>o.success?{value:o.data}:{issues:o.error?.issues})}},vendor:"zod",version:1}}),Bs=y("$ZodString",(t,e)=>{F.init(t,e),t._zod.pattern=[...t?._zod.bag?.patterns??[]].pop()??iw(t._zod.bag),t._zod.parse=(r,n)=>{if(e.coerce)try{r.value=String(r.value)}catch{}return typeof r.value=="string"||r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:t}),r}}),L=y("$ZodStringFormat",(t,e)=>{nn.init(t,e),Bs.init(t,e)}),Ow=y("$ZodGUID",(t,e)=>{e.pattern??(e.pattern=Vg),L.init(t,e)}),$w=y("$ZodUUID",(t,e)=>{if(e.version){const n={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[e.version];if(n===void 0)throw new Error(`Invalid UUID version: "${e.version}"`);e.pattern??(e.pattern=Zi(n))}else e.pattern??(e.pattern=Zi());L.init(t,e)}),Sw=y("$ZodEmail",(t,e)=>{e.pattern??(e.pattern=Yg),L.init(t,e)}),Iw=y("$ZodURL",(t,e)=>{L.init(t,e),t._zod.check=r=>{try{const n=r.value.trim(),s=new URL(n);e.hostname&&(e.hostname.lastIndex=0,e.hostname.test(s.hostname)||r.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:ew.source,input:r.value,inst:t,continue:!e.abort})),e.protocol&&(e.protocol.lastIndex=0,e.protocol.test(s.protocol.endsWith(":")?s.protocol.slice(0,-1):s.protocol)||r.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:e.protocol.source,input:r.value,inst:t,continue:!e.abort})),e.normalize?r.value=s.href:r.value=n;return}catch{r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:t,continue:!e.abort})}}}),Aw=y("$ZodEmoji",(t,e)=>{e.pattern??(e.pattern=Wg()),L.init(t,e)}),kw=y("$ZodNanoID",(t,e)=>{e.pattern??(e.pattern=qg),L.init(t,e)}),xw=y("$ZodCUID",(t,e)=>{e.pattern??(e.pattern=Dg),L.init(t,e)}),Zw=y("$ZodCUID2",(t,e)=>{e.pattern??(e.pattern=Pg),L.init(t,e)}),Cw=y("$ZodULID",(t,e)=>{e.pattern??(e.pattern=Ug),L.init(t,e)}),Rw=y("$ZodXID",(t,e)=>{e.pattern??(e.pattern=Lg),L.init(t,e)}),_w=y("$ZodKSUID",(t,e)=>{e.pattern??(e.pattern=Bg),L.init(t,e)}),jw=y("$ZodISODateTime",(t,e)=>{e.pattern??(e.pattern=sw(e)),L.init(t,e)}),Mw=y("$ZodISODate",(t,e)=>{e.pattern??(e.pattern=rw),L.init(t,e)}),Dw=y("$ZodISOTime",(t,e)=>{e.pattern??(e.pattern=nw(e)),L.init(t,e)}),Pw=y("$ZodISODuration",(t,e)=>{e.pattern??(e.pattern=Fg),L.init(t,e)}),Uw=y("$ZodIPv4",(t,e)=>{e.pattern??(e.pattern=Gg),L.init(t,e),t._zod.onattach.push(r=>{const n=r._zod.bag;n.format="ipv4"})}),Lw=y("$ZodIPv6",(t,e)=>{e.pattern??(e.pattern=Kg),L.init(t,e),t._zod.onattach.push(r=>{const n=r._zod.bag;n.format="ipv6"}),t._zod.check=r=>{try{new URL(`http://[${r.value}]`)}catch{r.issues.push({code:"invalid_format",format:"ipv6",input:r.value,inst:t,continue:!e.abort})}}}),Bw=y("$ZodCIDRv4",(t,e)=>{e.pattern??(e.pattern=Jg),L.init(t,e)}),qw=y("$ZodCIDRv6",(t,e)=>{e.pattern??(e.pattern=Xg),L.init(t,e),t._zod.check=r=>{const n=r.value.split("/");try{if(n.length!==2)throw new Error;const[s,a]=n;if(!a)throw new Error;const o=Number(a);if(`${o}`!==a)throw new Error;if(o<0||o>128)throw new Error;new URL(`http://[${s}]`)}catch{r.issues.push({code:"invalid_format",format:"cidrv6",input:r.value,inst:t,continue:!e.abort})}}});function Mc(t){if(t==="")return!0;if(t.length%4!==0)return!1;try{return atob(t),!0}catch{return!1}}const Fw=y("$ZodBase64",(t,e)=>{e.pattern??(e.pattern=Qg),L.init(t,e),t._zod.onattach.push(r=>{r._zod.bag.contentEncoding="base64"}),t._zod.check=r=>{Mc(r.value)||r.issues.push({code:"invalid_format",format:"base64",input:r.value,inst:t,continue:!e.abort})}});function Vw(t){if(!xc.test(t))return!1;const e=t.replace(/[-_]/g,n=>n==="-"?"+":"/"),r=e.padEnd(Math.ceil(e.length/4)*4,"=");return Mc(r)}const Yw=y("$ZodBase64URL",(t,e)=>{e.pattern??(e.pattern=xc),L.init(t,e),t._zod.onattach.push(r=>{r._zod.bag.contentEncoding="base64url"}),t._zod.check=r=>{Vw(r.value)||r.issues.push({code:"invalid_format",format:"base64url",input:r.value,inst:t,continue:!e.abort})}}),Hw=y("$ZodE164",(t,e)=>{e.pattern??(e.pattern=tw),L.init(t,e)});function Ww(t,e=null){try{const r=t.split(".");if(r.length!==3)return!1;const[n]=r;if(!n)return!1;const s=JSON.parse(atob(n));return!("typ"in s&&s?.typ!=="JWT"||!s.alg||e&&(!("alg"in s)||s.alg!==e))}catch{return!1}}const Gw=y("$ZodJWT",(t,e)=>{L.init(t,e),t._zod.check=r=>{Ww(r.value,e.alg)||r.issues.push({code:"invalid_format",format:"jwt",input:r.value,inst:t,continue:!e.abort})}}),Dc=y("$ZodNumber",(t,e)=>{F.init(t,e),t._zod.pattern=t._zod.bag.pattern??ow,t._zod.parse=(r,n)=>{if(e.coerce)try{r.value=Number(r.value)}catch{}const s=r.value;if(typeof s=="number"&&!Number.isNaN(s)&&Number.isFinite(s))return r;const a=typeof s=="number"?Number.isNaN(s)?"NaN":Number.isFinite(s)?void 0:"Infinity":void 0;return r.issues.push({expected:"number",code:"invalid_type",input:s,inst:t,...a?{received:a}:{}}),r}}),Kw=y("$ZodNumber",(t,e)=>{fw.init(t,e),Dc.init(t,e)}),Jw=y("$ZodBoolean",(t,e)=>{F.init(t,e),t._zod.pattern=cw,t._zod.parse=(r,n)=>{if(e.coerce)try{r.value=!!r.value}catch{}const s=r.value;return typeof s=="boolean"||r.issues.push({expected:"boolean",code:"invalid_type",input:s,inst:t}),r}}),Xw=y("$ZodUnknown",(t,e)=>{F.init(t,e),t._zod.parse=r=>r}),Qw=y("$ZodNever",(t,e)=>{F.init(t,e),t._zod.parse=(r,n)=>(r.issues.push({expected:"never",code:"invalid_type",input:r.value,inst:t}),r)});function Ci(t,e,r){t.issues.length&&e.issues.push(...Sc(r,t.issues)),e.value[r]=t.value}const eb=y("$ZodArray",(t,e)=>{F.init(t,e),t._zod.parse=(r,n)=>{const s=r.value;if(!Array.isArray(s))return r.issues.push({expected:"array",code:"invalid_type",input:s,inst:t}),r;r.value=Array(s.length);const a=[];for(let o=0;o<s.length;o++){const c=s[o],l=e.element._zod.run({value:c,issues:[]},n);l instanceof Promise?a.push(l.then(u=>Ci(u,r,o))):Ci(l,r,o)}return a.length?Promise.all(a).then(()=>r):r}});function Ur(t,e,r,n){t.issues.length&&e.issues.push(...Sc(r,t.issues)),t.value===void 0?r in n&&(e.value[r]=void 0):e.value[r]=t.value}function Pc(t){const e=Object.keys(t.shape);for(const n of e)if(!t.shape?.[n]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${n}": expected a Zod schema`);const r=gg(t.shape);return{...t,keys:e,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(r)}}function Uc(t,e,r,n,s,a){const o=[],c=s.keySet,l=s.catchall._zod,u=l.def.type;for(const h of Object.keys(e)){if(c.has(h))continue;if(u==="never"){o.push(h);continue}const d=l.run({value:e[h],issues:[]},n);d instanceof Promise?t.push(d.then(f=>Ur(f,r,h,e))):Ur(d,r,h,e)}return o.length&&r.issues.push({code:"unrecognized_keys",keys:o,input:e,inst:a}),t.length?Promise.all(t).then(()=>r):r}const tb=y("$ZodObject",(t,e)=>{F.init(t,e);const r=js(()=>Pc(e));P(t._zod,"propValues",()=>{const o=e.shape,c={};for(const l in o){const u=o[l]._zod;if(u.values){c[l]??(c[l]=new Set);for(const h of u.values)c[l].add(h)}}return c});const n=Pr,s=e.catchall;let a;t._zod.parse=(o,c)=>{a??(a=r.value);const l=o.value;if(!n(l))return o.issues.push({expected:"object",code:"invalid_type",input:l,inst:t}),o;o.value={};const u=[],h=a.shape;for(const d of a.keys){const v=h[d]._zod.run({value:l[d],issues:[]},c);v instanceof Promise?u.push(v.then(S=>Ur(S,o,d,l))):Ur(v,o,d,l)}return s?Uc(u,l,o,c,r.value,t):u.length?Promise.all(u).then(()=>o):o}}),rb=y("$ZodObjectJIT",(t,e)=>{tb.init(t,e);const r=t._zod.parse,n=js(()=>Pc(e)),s=f=>{const v=new Ew(["shape","payload","ctx"]),S=n.value,Z=G=>{const V=xi(G);return`shape[${V}]._zod.run({ value: input[${V}], issues: [] }, ctx)`};v.write("const input = payload.value;");const b=Object.create(null);let z=0;for(const G of S.keys)b[G]=`key_${z++}`;v.write("const newResult = {};");for(const G of S.keys){const V=b[G],ye=xi(G);v.write(`const ${V} = ${Z(G)};`),v.write(`
24
24
  if (${V}.issues.length) {
25
25
  payload.issues = payload.issues.concat(${V}.issues.map(iss => ({
26
26
  ...iss,
@@ -37,27 +37,27 @@
37
37
  newResult[${ye}] = ${V}.value;
38
38
  }
39
39
 
40
- `)}v.write("payload.value = newResult;"),v.write("return payload;");const k=v.compile();return(G,V)=>k(f,G,V)};let a;const o=Mr,c=!zc.jitless,u=c&&ag.value,h=e.catchall;let d;t._zod.parse=(f,v)=>{d??(d=n.value);const S=f.value;return o(S)?c&&u&&v?.async===!1&&v.jitless!==!0?(a||(a=s(e.shape)),f=a(f,v),h?Dc([],S,f,v,d,t):f):r(f,v):(f.issues.push({expected:"object",code:"invalid_type",input:S,inst:t}),f)}});function Ci(t,e,r,n){for(const a of t)if(a.issues.length===0)return e.value=a.value,e;const s=t.filter(a=>!dt(a));return s.length===1?(e.value=s[0].value,s[0]):(e.issues.push({code:"invalid_union",input:e.value,inst:r,errors:t.map(a=>a.issues.map(o=>nt(o,n,rt())))}),e)}const Hw=y("$ZodUnion",(t,e)=>{F.init(t,e),U(t._zod,"optin",()=>e.options.some(s=>s._zod.optin==="optional")?"optional":void 0),U(t._zod,"optout",()=>e.options.some(s=>s._zod.optout==="optional")?"optional":void 0),U(t._zod,"values",()=>{if(e.options.every(s=>s._zod.values))return new Set(e.options.flatMap(s=>Array.from(s._zod.values)))}),U(t._zod,"pattern",()=>{if(e.options.every(s=>s._zod.pattern)){const s=e.options.map(a=>a._zod.pattern);return new RegExp(`^(${s.map(a=>Ds(a.source)).join("|")})$`)}});const r=e.options.length===1,n=e.options[0]._zod.run;t._zod.parse=(s,a)=>{if(r)return n(s,a);let o=!1;const c=[];for(const l of e.options){const u=l._zod.run({value:s.value,issues:[]},a);if(u instanceof Promise)c.push(u),o=!0;else{if(u.issues.length===0)return u;c.push(u)}}return o?Promise.all(c).then(l=>Ci(l,s,t,a)):Ci(c,s,t,a)}}),Gw=y("$ZodIntersection",(t,e)=>{F.init(t,e),t._zod.parse=(r,n)=>{const s=r.value,a=e.left._zod.run({value:s,issues:[]},n),o=e.right._zod.run({value:s,issues:[]},n);return a instanceof Promise||o instanceof Promise?Promise.all([a,o]).then(([l,u])=>Ri(r,l,u)):Ri(r,a,o)}});function us(t,e){if(t===e)return{valid:!0,data:t};if(t instanceof Date&&e instanceof Date&&+t==+e)return{valid:!0,data:t};if(Jt(t)&&Jt(e)){const r=Object.keys(e),n=Object.keys(t).filter(a=>r.indexOf(a)!==-1),s={...t,...e};for(const a of n){const o=us(t[a],e[a]);if(!o.valid)return{valid:!1,mergeErrorPath:[a,...o.mergeErrorPath]};s[a]=o.data}return{valid:!0,data:s}}if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return{valid:!1,mergeErrorPath:[]};const r=[];for(let n=0;n<t.length;n++){const s=t[n],a=e[n],o=us(s,a);if(!o.valid)return{valid:!1,mergeErrorPath:[n,...o.mergeErrorPath]};r.push(o.data)}return{valid:!0,data:r}}return{valid:!1,mergeErrorPath:[]}}function Ri(t,e,r){if(e.issues.length&&t.issues.push(...e.issues),r.issues.length&&t.issues.push(...r.issues),dt(t))return t;const n=us(e.value,r.value);if(!n.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(n.mergeErrorPath)}`);return t.value=n.data,t}const Jw=y("$ZodEnum",(t,e)=>{F.init(t,e);const r=ng(e.entries),n=new Set(r);t._zod.values=n,t._zod.pattern=new RegExp(`^(${r.filter(s=>og.has(typeof s)).map(s=>typeof s=="string"?Qr(s):s.toString()).join("|")})$`),t._zod.parse=(s,a)=>{const o=s.value;return n.has(o)||s.issues.push({code:"invalid_value",values:r,input:o,inst:t}),s}}),Kw=y("$ZodTransform",(t,e)=>{F.init(t,e),t._zod.parse=(r,n)=>{if(n.direction==="backward")throw new Tc(t.constructor.name);const s=e.transform(r.value,r);if(n.async)return(s instanceof Promise?s:Promise.resolve(s)).then(o=>(r.value=o,r));if(s instanceof Promise)throw new wt;return r.value=s,r}});function _i(t,e){return t.issues.length&&e===void 0?{issues:[],value:void 0}:t}const Xw=y("$ZodOptional",(t,e)=>{F.init(t,e),t._zod.optin="optional",t._zod.optout="optional",U(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,void 0]):void 0),U(t._zod,"pattern",()=>{const r=e.innerType._zod.pattern;return r?new RegExp(`^(${Ds(r.source)})?$`):void 0}),t._zod.parse=(r,n)=>{if(e.innerType._zod.optin==="optional"){const s=e.innerType._zod.run(r,n);return s instanceof Promise?s.then(a=>_i(a,r.value)):_i(s,r.value)}return r.value===void 0?r:e.innerType._zod.run(r,n)}}),Qw=y("$ZodNullable",(t,e)=>{F.init(t,e),U(t._zod,"optin",()=>e.innerType._zod.optin),U(t._zod,"optout",()=>e.innerType._zod.optout),U(t._zod,"pattern",()=>{const r=e.innerType._zod.pattern;return r?new RegExp(`^(${Ds(r.source)}|null)$`):void 0}),U(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,null]):void 0),t._zod.parse=(r,n)=>r.value===null?r:e.innerType._zod.run(r,n)}),eb=y("$ZodDefault",(t,e)=>{F.init(t,e),t._zod.optin="optional",U(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(r,n)=>{if(n.direction==="backward")return e.innerType._zod.run(r,n);if(r.value===void 0)return r.value=e.defaultValue,r;const s=e.innerType._zod.run(r,n);return s instanceof Promise?s.then(a=>ji(a,e)):ji(s,e)}});function ji(t,e){return t.value===void 0&&(t.value=e.defaultValue),t}const tb=y("$ZodPrefault",(t,e)=>{F.init(t,e),t._zod.optin="optional",U(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(r,n)=>(n.direction==="backward"||r.value===void 0&&(r.value=e.defaultValue),e.innerType._zod.run(r,n))}),rb=y("$ZodNonOptional",(t,e)=>{F.init(t,e),U(t._zod,"values",()=>{const r=e.innerType._zod.values;return r?new Set([...r].filter(n=>n!==void 0)):void 0}),t._zod.parse=(r,n)=>{const s=e.innerType._zod.run(r,n);return s instanceof Promise?s.then(a=>Mi(a,t)):Mi(s,t)}});function Mi(t,e){return!t.issues.length&&t.value===void 0&&t.issues.push({code:"invalid_type",expected:"nonoptional",input:t.value,inst:e}),t}const nb=y("$ZodCatch",(t,e)=>{F.init(t,e),U(t._zod,"optin",()=>e.innerType._zod.optin),U(t._zod,"optout",()=>e.innerType._zod.optout),U(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(r,n)=>{if(n.direction==="backward")return e.innerType._zod.run(r,n);const s=e.innerType._zod.run(r,n);return s instanceof Promise?s.then(a=>(r.value=a.value,a.issues.length&&(r.value=e.catchValue({...r,error:{issues:a.issues.map(o=>nt(o,n,rt()))},input:r.value}),r.issues=[]),r)):(r.value=s.value,s.issues.length&&(r.value=e.catchValue({...r,error:{issues:s.issues.map(a=>nt(a,n,rt()))},input:r.value}),r.issues=[]),r)}}),sb=y("$ZodPipe",(t,e)=>{F.init(t,e),U(t._zod,"values",()=>e.in._zod.values),U(t._zod,"optin",()=>e.in._zod.optin),U(t._zod,"optout",()=>e.out._zod.optout),U(t._zod,"propValues",()=>e.in._zod.propValues),t._zod.parse=(r,n)=>{if(n.direction==="backward"){const a=e.out._zod.run(r,n);return a instanceof Promise?a.then(o=>Nr(o,e.in,n)):Nr(a,e.in,n)}const s=e.in._zod.run(r,n);return s instanceof Promise?s.then(a=>Nr(a,e.out,n)):Nr(s,e.out,n)}});function Nr(t,e,r){return t.issues.length?(t.aborted=!0,t):e._zod.run({value:t.value,issues:t.issues},r)}const ib=y("$ZodReadonly",(t,e)=>{F.init(t,e),U(t._zod,"propValues",()=>e.innerType._zod.propValues),U(t._zod,"values",()=>e.innerType._zod.values),U(t._zod,"optin",()=>e.innerType._zod.optin),U(t._zod,"optout",()=>e.innerType._zod.optout),t._zod.parse=(r,n)=>{if(n.direction==="backward")return e.innerType._zod.run(r,n);const s=e.innerType._zod.run(r,n);return s instanceof Promise?s.then(Di):Di(s)}});function Di(t){return t.value=Object.freeze(t.value),t}const ab=y("$ZodCustom",(t,e)=>{ae.init(t,e),F.init(t,e),t._zod.parse=(r,n)=>r,t._zod.check=r=>{const n=r.value,s=e.fn(n);if(s instanceof Promise)return s.then(a=>Pi(a,r,n,t));Pi(s,r,n,t)}});function Pi(t,e,r,n){if(!t){const s={code:"custom",input:r,inst:n,path:[...n._zod.def.path??[]],continue:!n._zod.def.abort};n._zod.def.params&&(s.params=n._zod.def.params),e.issues.push(Kt(s))}}class ob{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...r){const n=r[0];if(this._map.set(e,n),n&&typeof n=="object"&&"id"in n){if(this._idmap.has(n.id))throw new Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){const r=this._map.get(e);return r&&typeof r=="object"&&"id"in r&&this._idmap.delete(r.id),this._map.delete(e),this}get(e){const r=e._zod.parent;if(r){const n={...this.get(r)??{}};delete n.id;const s={...n,...this._map.get(e)};return Object.keys(s).length?s:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}function cb(){return new ob}const Or=cb();function ub(t,e){return new t({type:"string",...$(e)})}function lb(t,e){return new t({type:"string",format:"email",check:"string_format",abort:!1,...$(e)})}function Ui(t,e){return new t({type:"string",format:"guid",check:"string_format",abort:!1,...$(e)})}function Pc(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,...$(e)})}function hb(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...$(e)})}function fb(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...$(e)})}function db(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...$(e)})}function pb(t,e){return new t({type:"string",format:"url",check:"string_format",abort:!1,...$(e)})}function yb(t,e){return new t({type:"string",format:"emoji",check:"string_format",abort:!1,...$(e)})}function mb(t,e){return new t({type:"string",format:"nanoid",check:"string_format",abort:!1,...$(e)})}function gb(t,e){return new t({type:"string",format:"cuid",check:"string_format",abort:!1,...$(e)})}function wb(t,e){return new t({type:"string",format:"cuid2",check:"string_format",abort:!1,...$(e)})}function bb(t,e){return new t({type:"string",format:"ulid",check:"string_format",abort:!1,...$(e)})}function vb(t,e){return new t({type:"string",format:"xid",check:"string_format",abort:!1,...$(e)})}function Tb(t,e){return new t({type:"string",format:"ksuid",check:"string_format",abort:!1,...$(e)})}function zb(t,e){return new t({type:"string",format:"ipv4",check:"string_format",abort:!1,...$(e)})}function Eb(t,e){return new t({type:"string",format:"ipv6",check:"string_format",abort:!1,...$(e)})}function Nb(t,e){return new t({type:"string",format:"cidrv4",check:"string_format",abort:!1,...$(e)})}function Ob(t,e){return new t({type:"string",format:"cidrv6",check:"string_format",abort:!1,...$(e)})}function $b(t,e){return new t({type:"string",format:"base64",check:"string_format",abort:!1,...$(e)})}function Sb(t,e){return new t({type:"string",format:"base64url",check:"string_format",abort:!1,...$(e)})}function Ib(t,e){return new t({type:"string",format:"e164",check:"string_format",abort:!1,...$(e)})}function kb(t,e){return new t({type:"string",format:"jwt",check:"string_format",abort:!1,...$(e)})}function Ab(t,e){return new t({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...$(e)})}function xb(t,e){return new t({type:"string",format:"date",check:"string_format",...$(e)})}function Zb(t,e){return new t({type:"string",format:"time",check:"string_format",precision:null,...$(e)})}function Cb(t,e){return new t({type:"string",format:"duration",check:"string_format",...$(e)})}function Rb(t,e){return new t({type:"number",checks:[],...$(e)})}function _b(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"safeint",...$(e)})}function jb(t,e){return new t({type:"boolean",...$(e)})}function Mb(t){return new t({type:"unknown"})}function Db(t,e){return new t({type:"never",...$(e)})}function Li(t,e){return new Cc({check:"less_than",...$(e),value:t,inclusive:!1})}function Sn(t,e){return new Cc({check:"less_than",...$(e),value:t,inclusive:!0})}function Bi(t,e){return new Rc({check:"greater_than",...$(e),value:t,inclusive:!1})}function In(t,e){return new Rc({check:"greater_than",...$(e),value:t,inclusive:!0})}function qi(t,e){return new rw({check:"multiple_of",...$(e),value:t})}function Uc(t,e){return new sw({check:"max_length",...$(e),maximum:t})}function Pr(t,e){return new iw({check:"min_length",...$(e),minimum:t})}function Lc(t,e){return new aw({check:"length_equals",...$(e),length:t})}function Pb(t,e){return new ow({check:"string_format",format:"regex",...$(e),pattern:t})}function Ub(t){return new cw({check:"string_format",format:"lowercase",...$(t)})}function Lb(t){return new uw({check:"string_format",format:"uppercase",...$(t)})}function Bb(t,e){return new lw({check:"string_format",format:"includes",...$(e),includes:t})}function qb(t,e){return new hw({check:"string_format",format:"starts_with",...$(e),prefix:t})}function Fb(t,e){return new fw({check:"string_format",format:"ends_with",...$(e),suffix:t})}function cr(t){return new dw({check:"overwrite",tx:t})}function Vb(t){return cr(e=>e.normalize(t))}function Yb(){return cr(t=>t.trim())}function Wb(){return cr(t=>t.toLowerCase())}function Hb(){return cr(t=>t.toUpperCase())}function Gb(t,e,r){return new t({type:"array",element:e,...$(r)})}function Jb(t,e,r){return new t({type:"custom",check:"custom",fn:e,...$(r)})}function Kb(t){const e=Xb(r=>(r.addIssue=n=>{if(typeof n=="string")r.issues.push(Kt(n,r.value,e._zod.def));else{const s=n;s.fatal&&(s.continue=!1),s.code??(s.code="custom"),s.input??(s.input=r.value),s.inst??(s.inst=e),s.continue??(s.continue=!e._zod.def.abort),r.issues.push(Kt(s))}},t(r.value,r)));return e}function Xb(t,e){const r=new ae({check:"custom",...$(e)});return r._zod.check=t,r}const Qb=y("ZodISODateTime",(t,e)=>{Sw.init(t,e),q.init(t,e)});function ev(t){return Ab(Qb,t)}const tv=y("ZodISODate",(t,e)=>{Iw.init(t,e),q.init(t,e)});function rv(t){return xb(tv,t)}const nv=y("ZodISOTime",(t,e)=>{kw.init(t,e),q.init(t,e)});function sv(t){return Zb(nv,t)}const iv=y("ZodISODuration",(t,e)=>{Aw.init(t,e),q.init(t,e)});function av(t){return Cb(iv,t)}const ov=(t,e)=>{Sc.init(t,e),t.name="ZodError",Object.defineProperties(t,{format:{value:r=>wg(t,r)},flatten:{value:r=>gg(t,r)},addIssue:{value:r=>{t.issues.push(r),t.message=JSON.stringify(t.issues,cs,2)}},addIssues:{value:r=>{t.issues.push(...r),t.message=JSON.stringify(t.issues,cs,2)}},isEmpty:{get(){return t.issues.length===0}}})},pe=y("ZodError",ov,{Parent:Error}),cv=Us(pe),uv=Ls(pe),lv=en(pe),hv=tn(pe),fv=Tg(pe),dv=zg(pe),pv=Eg(pe),yv=Ng(pe),mv=Og(pe),gv=$g(pe),wv=Sg(pe),bv=Ig(pe),H=y("ZodType",(t,e)=>(F.init(t,e),t.def=e,t.type=e.type,Object.defineProperty(t,"_def",{value:e}),t.check=(...r)=>t.clone({...e,checks:[...e.checks??[],...r.map(n=>typeof n=="function"?{_zod:{check:n,def:{check:"custom"},onattach:[]}}:n)]}),t.clone=(r,n)=>Ye(t,r,n),t.brand=()=>t,t.register=((r,n)=>(r.add(t,n),t)),t.parse=(r,n)=>cv(t,r,n,{callee:t.parse}),t.safeParse=(r,n)=>lv(t,r,n),t.parseAsync=async(r,n)=>uv(t,r,n,{callee:t.parseAsync}),t.safeParseAsync=async(r,n)=>hv(t,r,n),t.spa=t.safeParseAsync,t.encode=(r,n)=>fv(t,r,n),t.decode=(r,n)=>dv(t,r,n),t.encodeAsync=async(r,n)=>pv(t,r,n),t.decodeAsync=async(r,n)=>yv(t,r,n),t.safeEncode=(r,n)=>mv(t,r,n),t.safeDecode=(r,n)=>gv(t,r,n),t.safeEncodeAsync=async(r,n)=>wv(t,r,n),t.safeDecodeAsync=async(r,n)=>bv(t,r,n),t.refine=(r,n)=>t.check(hT(r,n)),t.superRefine=r=>t.check(fT(r)),t.overwrite=r=>t.check(cr(r)),t.optional=()=>Hi(t),t.nullable=()=>Gi(t),t.nullish=()=>Hi(Gi(t)),t.nonoptional=r=>sT(t,r),t.array=()=>Vv(t),t.or=r=>qs([t,r]),t.and=r=>Gv(t,r),t.transform=r=>Ji(t,Xv(r)),t.default=r=>tT(t,r),t.prefault=r=>nT(t,r),t.catch=r=>aT(t,r),t.pipe=r=>Ji(t,r),t.readonly=()=>uT(t),t.describe=r=>{const n=t.clone();return Or.add(n,{description:r}),n},Object.defineProperty(t,"description",{get(){return Or.get(t)?.description},configurable:!0}),t.meta=(...r)=>{if(r.length===0)return Or.get(t);const n=t.clone();return Or.add(n,r[0]),n},t.isOptional=()=>t.safeParse(void 0).success,t.isNullable=()=>t.safeParse(null).success,t)),Bc=y("_ZodString",(t,e)=>{Bs.init(t,e),H.init(t,e);const r=t._zod.bag;t.format=r.format??null,t.minLength=r.minimum??null,t.maxLength=r.maximum??null,t.regex=(...n)=>t.check(Pb(...n)),t.includes=(...n)=>t.check(Bb(...n)),t.startsWith=(...n)=>t.check(qb(...n)),t.endsWith=(...n)=>t.check(Fb(...n)),t.min=(...n)=>t.check(Pr(...n)),t.max=(...n)=>t.check(Uc(...n)),t.length=(...n)=>t.check(Lc(...n)),t.nonempty=(...n)=>t.check(Pr(1,...n)),t.lowercase=n=>t.check(Ub(n)),t.uppercase=n=>t.check(Lb(n)),t.trim=()=>t.check(Yb()),t.normalize=(...n)=>t.check(Vb(...n)),t.toLowerCase=()=>t.check(Wb()),t.toUpperCase=()=>t.check(Hb())}),vv=y("ZodString",(t,e)=>{Bs.init(t,e),Bc.init(t,e),t.email=r=>t.check(lb(Tv,r)),t.url=r=>t.check(pb(Ev,r)),t.jwt=r=>t.check(kb(Dv,r)),t.emoji=r=>t.check(yb(Nv,r)),t.guid=r=>t.check(Ui(Fi,r)),t.uuid=r=>t.check(Pc(Pt,r)),t.uuidv4=r=>t.check(hb(Pt,r)),t.uuidv6=r=>t.check(fb(Pt,r)),t.uuidv7=r=>t.check(db(Pt,r)),t.nanoid=r=>t.check(mb(Ov,r)),t.guid=r=>t.check(Ui(Fi,r)),t.cuid=r=>t.check(gb($v,r)),t.cuid2=r=>t.check(wb(Sv,r)),t.ulid=r=>t.check(bb(Iv,r)),t.base64=r=>t.check($b(_v,r)),t.base64url=r=>t.check(Sb(jv,r)),t.xid=r=>t.check(vb(kv,r)),t.ksuid=r=>t.check(Tb(Av,r)),t.ipv4=r=>t.check(zb(xv,r)),t.ipv6=r=>t.check(Eb(Zv,r)),t.cidrv4=r=>t.check(Nb(Cv,r)),t.cidrv6=r=>t.check(Ob(Rv,r)),t.e164=r=>t.check(Ib(Mv,r)),t.datetime=r=>t.check(ev(r)),t.date=r=>t.check(rv(r)),t.time=r=>t.check(sv(r)),t.duration=r=>t.check(av(r))});function de(t){return ub(vv,t)}const q=y("ZodStringFormat",(t,e)=>{L.init(t,e),Bc.init(t,e)}),Tv=y("ZodEmail",(t,e)=>{ww.init(t,e),q.init(t,e)}),Fi=y("ZodGUID",(t,e)=>{mw.init(t,e),q.init(t,e)}),Pt=y("ZodUUID",(t,e)=>{gw.init(t,e),q.init(t,e)});function zv(t){return Pc(Pt,t)}const Ev=y("ZodURL",(t,e)=>{bw.init(t,e),q.init(t,e)}),Nv=y("ZodEmoji",(t,e)=>{vw.init(t,e),q.init(t,e)}),Ov=y("ZodNanoID",(t,e)=>{Tw.init(t,e),q.init(t,e)}),$v=y("ZodCUID",(t,e)=>{zw.init(t,e),q.init(t,e)}),Sv=y("ZodCUID2",(t,e)=>{Ew.init(t,e),q.init(t,e)}),Iv=y("ZodULID",(t,e)=>{Nw.init(t,e),q.init(t,e)}),kv=y("ZodXID",(t,e)=>{Ow.init(t,e),q.init(t,e)}),Av=y("ZodKSUID",(t,e)=>{$w.init(t,e),q.init(t,e)}),xv=y("ZodIPv4",(t,e)=>{xw.init(t,e),q.init(t,e)}),Zv=y("ZodIPv6",(t,e)=>{Zw.init(t,e),q.init(t,e)}),Cv=y("ZodCIDRv4",(t,e)=>{Cw.init(t,e),q.init(t,e)}),Rv=y("ZodCIDRv6",(t,e)=>{Rw.init(t,e),q.init(t,e)}),_v=y("ZodBase64",(t,e)=>{_w.init(t,e),q.init(t,e)}),jv=y("ZodBase64URL",(t,e)=>{Mw.init(t,e),q.init(t,e)}),Mv=y("ZodE164",(t,e)=>{Dw.init(t,e),q.init(t,e)}),Dv=y("ZodJWT",(t,e)=>{Uw.init(t,e),q.init(t,e)}),qc=y("ZodNumber",(t,e)=>{jc.init(t,e),H.init(t,e),t.gt=(n,s)=>t.check(Bi(n,s)),t.gte=(n,s)=>t.check(In(n,s)),t.min=(n,s)=>t.check(In(n,s)),t.lt=(n,s)=>t.check(Li(n,s)),t.lte=(n,s)=>t.check(Sn(n,s)),t.max=(n,s)=>t.check(Sn(n,s)),t.int=n=>t.check(Yi(n)),t.safe=n=>t.check(Yi(n)),t.positive=n=>t.check(Bi(0,n)),t.nonnegative=n=>t.check(In(0,n)),t.negative=n=>t.check(Li(0,n)),t.nonpositive=n=>t.check(Sn(0,n)),t.multipleOf=(n,s)=>t.check(qi(n,s)),t.step=(n,s)=>t.check(qi(n,s)),t.finite=()=>t;const r=t._zod.bag;t.minValue=Math.max(r.minimum??Number.NEGATIVE_INFINITY,r.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,t.maxValue=Math.min(r.maximum??Number.POSITIVE_INFINITY,r.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,t.isInt=(r.format??"").includes("int")||Number.isSafeInteger(r.multipleOf??.5),t.isFinite=!0,t.format=r.format??null});function Vi(t){return Rb(qc,t)}const Pv=y("ZodNumberFormat",(t,e)=>{Lw.init(t,e),qc.init(t,e)});function Yi(t){return _b(Pv,t)}const Uv=y("ZodBoolean",(t,e)=>{Bw.init(t,e),H.init(t,e)});function nn(t){return jb(Uv,t)}const Lv=y("ZodUnknown",(t,e)=>{qw.init(t,e),H.init(t,e)});function Wi(){return Mb(Lv)}const Bv=y("ZodNever",(t,e)=>{Fw.init(t,e),H.init(t,e)});function qv(t){return Db(Bv,t)}const Fv=y("ZodArray",(t,e)=>{Vw.init(t,e),H.init(t,e),t.element=e.element,t.min=(r,n)=>t.check(Pr(r,n)),t.nonempty=r=>t.check(Pr(1,r)),t.max=(r,n)=>t.check(Uc(r,n)),t.length=(r,n)=>t.check(Lc(r,n)),t.unwrap=()=>t.element});function Vv(t,e){return Gb(Fv,t,e)}const Yv=y("ZodObject",(t,e)=>{Ww.init(t,e),H.init(t,e),U(t,"shape",()=>e.shape),t.keyof=()=>Jv(Object.keys(t._zod.def.shape)),t.catchall=r=>t.clone({...t._zod.def,catchall:r}),t.passthrough=()=>t.clone({...t._zod.def,catchall:Wi()}),t.loose=()=>t.clone({...t._zod.def,catchall:Wi()}),t.strict=()=>t.clone({...t._zod.def,catchall:qv()}),t.strip=()=>t.clone({...t._zod.def,catchall:void 0}),t.extend=r=>fg(t,r),t.safeExtend=r=>dg(t,r),t.merge=r=>pg(t,r),t.pick=r=>lg(t,r),t.omit=r=>hg(t,r),t.partial=(...r)=>yg(Fc,t,r[0]),t.required=(...r)=>mg(Vc,t,r[0])});function ie(t,e){const r={type:"object",get shape(){return Ve(this,"shape",t?ig(t):{}),this.shape},...$(e)};return new Yv(r)}const Wv=y("ZodUnion",(t,e)=>{Hw.init(t,e),H.init(t,e),t.options=e.options});function qs(t,e){return new Wv({type:"union",options:t,...$(e)})}const Hv=y("ZodIntersection",(t,e)=>{Gw.init(t,e),H.init(t,e)});function Gv(t,e){return new Hv({type:"intersection",left:t,right:e})}const ls=y("ZodEnum",(t,e)=>{Jw.init(t,e),H.init(t,e),t.enum=e.entries,t.options=Object.values(e.entries);const r=new Set(Object.keys(e.entries));t.extract=(n,s)=>{const a={};for(const o of n)if(r.has(o))a[o]=e.entries[o];else throw new Error(`Key ${o} not found in enum`);return new ls({...e,checks:[],...$(s),entries:a})},t.exclude=(n,s)=>{const a={...e.entries};for(const o of n)if(r.has(o))delete a[o];else throw new Error(`Key ${o} not found in enum`);return new ls({...e,checks:[],...$(s),entries:a})}});function Jv(t,e){const r=Array.isArray(t)?Object.fromEntries(t.map(n=>[n,n])):t;return new ls({type:"enum",entries:r,...$(e)})}const Kv=y("ZodTransform",(t,e)=>{Kw.init(t,e),H.init(t,e),t._zod.parse=(r,n)=>{if(n.direction==="backward")throw new Tc(t.constructor.name);r.addIssue=a=>{if(typeof a=="string")r.issues.push(Kt(a,r.value,e));else{const o=a;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=r.value),o.inst??(o.inst=t),r.issues.push(Kt(o))}};const s=e.transform(r.value,r);return s instanceof Promise?s.then(a=>(r.value=a,r)):(r.value=s,r)}});function Xv(t){return new Kv({type:"transform",transform:t})}const Fc=y("ZodOptional",(t,e)=>{Xw.init(t,e),H.init(t,e),t.unwrap=()=>t._zod.def.innerType});function Hi(t){return new Fc({type:"optional",innerType:t})}const Qv=y("ZodNullable",(t,e)=>{Qw.init(t,e),H.init(t,e),t.unwrap=()=>t._zod.def.innerType});function Gi(t){return new Qv({type:"nullable",innerType:t})}const eT=y("ZodDefault",(t,e)=>{eb.init(t,e),H.init(t,e),t.unwrap=()=>t._zod.def.innerType,t.removeDefault=t.unwrap});function tT(t,e){return new eT({type:"default",innerType:t,get defaultValue(){return typeof e=="function"?e():Nc(e)}})}const rT=y("ZodPrefault",(t,e)=>{tb.init(t,e),H.init(t,e),t.unwrap=()=>t._zod.def.innerType});function nT(t,e){return new rT({type:"prefault",innerType:t,get defaultValue(){return typeof e=="function"?e():Nc(e)}})}const Vc=y("ZodNonOptional",(t,e)=>{rb.init(t,e),H.init(t,e),t.unwrap=()=>t._zod.def.innerType});function sT(t,e){return new Vc({type:"nonoptional",innerType:t,...$(e)})}const iT=y("ZodCatch",(t,e)=>{nb.init(t,e),H.init(t,e),t.unwrap=()=>t._zod.def.innerType,t.removeCatch=t.unwrap});function aT(t,e){return new iT({type:"catch",innerType:t,catchValue:typeof e=="function"?e:()=>e})}const oT=y("ZodPipe",(t,e)=>{sb.init(t,e),H.init(t,e),t.in=e.in,t.out=e.out});function Ji(t,e){return new oT({type:"pipe",in:t,out:e})}const cT=y("ZodReadonly",(t,e)=>{ib.init(t,e),H.init(t,e),t.unwrap=()=>t._zod.def.innerType});function uT(t){return new cT({type:"readonly",innerType:t})}const lT=y("ZodCustom",(t,e)=>{ab.init(t,e),H.init(t,e)});function hT(t,e={}){return Jb(lT,t,e)}function fT(t){return Kb(t)}const Ie=t=>t?JSON.parse(t):{},Fs=ie({key:de(),type:de(),config:be.unknownZ.or(de().transform(Ie)),source:de().optional()}),Yc=Fs.extend({position:ks.xy}),hs=ie({param:de(),node:de()}),Vs=ie({source:hs,target:hs}),dT=ie({nodes:Fs.array(),edges:Vs.array()}),Wc=ie({nodes:Yc.array(),edges:Vs.array()}),Hc=ie({raw:de()}),ur=zv(),sn=ie({key:ur,name:de(),graph:Wc,text:Hc,deploy:nn(),version:de()}),Gc=sn.partial({key:!0}),Jc="arc",pT=(t,e,{convertNumericStrings:r=!0}={})=>{const n=!Array.isArray(t);let s=T.toArray(t);const a=s[0],o=typeof a;let c;return o==="string"&&r&&!isNaN(parseInt(a))&&"number"in e?(c=e.number,s=s.map(l=>parseInt(l))):c=e[o],{single:n,variant:c,normalized:s,actual:t}},ce=(t,e,r,n)=>{if(n){if(r.length===0)throw new Ht(`${t} not found matching ${JSON.stringify(e)}`);if(r.length>1)throw new Gt(`Expected one ${t} matching ${JSON.stringify(e)}, but found ${r.length}`)}},yT="/arc/retrieve",mT="/arc/create",gT="/arc/delete",wT=ie({keys:ur.array().optional(),names:de().array().optional(),searchTerm:de().optional(),limit:Vi().optional(),offset:Vi().optional(),includeStatus:nn().optional()}),bT=ie({arcs:Gc.array()}),vT=ie({keys:ur.array()}),TT=ie({arcs:T.nullableZ(sn)}),zT=ie({arcs:sn.array()}),ET=ie({}),NT=ie({key:ur,includeStatus:nn().optional()}).transform(({key:t,includeStatus:e})=>({keys:[t],includeStatus:e})),OT=ie({name:de(),includeStatus:nn().optional()}).transform(({name:t,includeStatus:e})=>({names:[t],includeStatus:e})),Kc=qs([NT,OT]),$T=qs([Kc,wT]);let Xc=class{client;constructor(e){this.client=e}async create(e){const r=Array.isArray(e),n=await w(this.client,mT,{arcs:T.toArray(e)},bT,zT);return r?n.arcs:n.arcs[0]}async retrieve(e){const r="key"in e||"name"in e,n=await w(this.client,yT,e,$T,TT);return ce("Arc",e,n.arcs,r),r?n.arcs[0]:n.arcs}async delete(e){await w(this.client,gT,{keys:T.toArray(e)},vT,ET)}};const ST=t=>({type:Jc,key:t}),IT=Object.freeze(Object.defineProperty({__proto__:null,Client:Xc,ONTOLOGY_TYPE:Jc,arcZ:sn,edgeZ:Vs,graphNodeZ:Yc,graphZ:Wc,handleZ:hs,irNodeZ:Fs,irZ:dT,keyZ:ur,newZ:Gc,ontologyID:ST,singleRetrieveArgsZ:Kc,textZ:Hc},Symbol.toStringTag,{value:"Module"})),Ki="Channel key must be a valid uint32.",D=i.z.uint32().or(i.z.string().refine(t=>!isNaN(Number(t)),{message:Ki}).transform(Number).refine(t=>t<Qn.MAX_UINT32,{message:Ki})),xe=i.z.string(),Qc=It.statusZ(),xt=i.z.object({name:xe,key:D,dataType:R.z,leaseholder:i.z.number(),index:D,isIndex:i.z.boolean(),internal:i.z.boolean(),virtual:i.z.boolean(),alias:i.z.string().optional(),expression:i.z.string().default(""),requires:T.nullableZ(D),status:Qc.optional()}),eu=xt.extend({key:D.optional(),leaseholder:i.z.number().optional(),index:D.optional(),isIndex:i.z.boolean().optional(),internal:i.z.boolean().optional().default(!1),virtual:i.z.boolean().optional().default(!1),expression:i.z.string().optional().default(""),requires:T.nullableZ(D).optional().default([])}),it=i.z.union([Lt.toArray(D),Lt.toArray(xe),Lt.toArray(xt).transform(t=>t.map(e=>e.key))]),kT=new Error("request for lock canceled");var AT=function(t,e,r,n){function s(a){return a instanceof r?a:new r(function(o){o(a)})}return new(r||(r=Promise))(function(a,o){function c(h){try{u(n.next(h))}catch(d){o(d)}}function l(h){try{u(n.throw(h))}catch(d){o(d)}}function u(h){h.done?a(h.value):s(h.value).then(c,l)}u((n=n.apply(t,e||[])).next())})};class xT{constructor(e,r=kT){this._value=e,this._cancelError=r,this._queue=[],this._weightedWaiters=[]}acquire(e=1,r=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((n,s)=>{const a={resolve:n,reject:s,weight:e,priority:r},o=tu(this._queue,c=>r<=c.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return AT(this,arguments,void 0,function*(r,n=1,s=0){const[a,o]=yield this.acquire(n,s);try{return yield r(a)}finally{o()}})}waitForUnlock(e=1,r=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,r)?Promise.resolve():new Promise(n=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),ZT(this._weightedWaiters[e-1],{resolve:n,priority:r})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const r=this._value;this._value-=e.weight,e.resolve([r,this._newReleaser(e.weight)])}_newReleaser(e){let r=!1;return()=>{r||(r=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const r=this._weightedWaiters[e-1];r&&(r.forEach(n=>n.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let r=this._value;r>0;r--){const n=this._weightedWaiters[r-1];if(!n)continue;const s=n.findIndex(a=>a.priority<=e);(s===-1?n:n.splice(0,s)).forEach((a=>a.resolve()))}}}_couldLockImmediately(e,r){return(this._queue.length===0||this._queue[0].priority<r)&&e<=this._value}}function ZT(t,e){const r=tu(t,n=>e.priority<=n.priority);t.splice(r+1,0,e)}function tu(t,e){for(let r=t.length-1;r>=0;r--)if(e(t[r]))return r;return-1}var CT=function(t,e,r,n){function s(a){return a instanceof r?a:new r(function(o){o(a)})}return new(r||(r=Promise))(function(a,o){function c(h){try{u(n.next(h))}catch(d){o(d)}}function l(h){try{u(n.throw(h))}catch(d){o(d)}}function u(h){h.done?a(h.value):s(h.value).then(c,l)}u((n=n.apply(t,e||[])).next())})};class RT{constructor(e){this._semaphore=new xT(1,e)}acquire(){return CT(this,arguments,void 0,function*(e=0){const[,r]=yield this._semaphore.acquire(1,e);return r})}runExclusive(e,r=0){return this._semaphore.runExclusive(()=>e(),1,r)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}const _T=i.z.object({leaseholder:i.z.number().optional(),keys:D.array().optional(),names:i.z.string().array().optional(),searchTerm:i.z.string().optional(),rangeKey:i.z.string().optional(),limit:i.z.number().optional(),offset:i.z.number().optional(),dataTypes:R.z.array().optional(),notDataTypes:R.z.array().optional(),virtual:i.z.boolean().optional(),isIndex:i.z.boolean().optional(),internal:i.z.boolean().optional(),calculated:i.z.boolean().optional()}),jT=i.z.object({channels:T.nullableZ(xt)}),ge=t=>(Array.isArray(t)&&t.length>0&&typeof t[0]=="object"?t=t.map(e=>e.key):typeof t=="object"&&"key"in t&&(t=[t.key]),pT(t,{number:"keys",string:"names"}));class lr{static ENDPOINT="/channel/retrieve";client;constructor(e){this.client=e}async retrieve(e,r){if(!Array.isArray(e)&&typeof e=="object")return await this.execute(e);const n=ge(e),{variant:s}=n;let{normalized:a}=n;return s==="keys"&&a.indexOf(0)!==-1&&(a=a.filter(o=>o!==0)),a.length===0?[]:await this.execute({[s]:a,...r})}async execute(e){const[r,n]=await this.client.send(lr.ENDPOINT,e,_T,jT);if(n!=null)throw n;return r.channels}}class Ys{cache;namesToKeys;wrapped;constructor(e){this.cache=new Map,this.namesToKeys=new Map,this.wrapped=e}async retrieve(e,r){if(!Array.isArray(e)&&typeof e=="object")return await this.wrapped.retrieve(e);const{normalized:n}=ge(e),s=[],a=[];if(n.forEach(c=>{const l=this.get(c);l!=null?s.push(...l):a.push(c)}),a.length===0)return s;const o=await this.wrapped.retrieve(a,r);return this.set(o),s.concat(o)}delete(e){const{variant:r,normalized:n}=ge(e);r==="names"?n.forEach(s=>{const a=this.namesToKeys.get(s);a!=null&&(a.forEach(o=>this.cache.delete(o)),this.namesToKeys.delete(s))}):n.forEach(s=>{const a=this.cache.get(s);a!=null&&(this.cache.delete(s),this.namesToKeys.delete(a.name))})}rename(e,r){e.forEach((n,s)=>{const a=r[s],o=this.cache.get(n);if(o==null)return;this.cache.delete(n);const c=this.namesToKeys.get(o.name);c!=null&&(c.delete(n),c.size===0&&this.namesToKeys.delete(o.name)),o.name=a,this.cache.set(n,o);const l=this.namesToKeys.get(a);l==null?this.namesToKeys.set(a,new Set([n])):l.add(n)})}set(e){e.forEach(r=>{this.cache.set(r.key,r);const n=this.namesToKeys.get(r.name);n==null?this.namesToKeys.set(r.name,new Set([r.key])):n.add(r.key)})}get(e){if(typeof e=="number"){const s=this.cache.get(e);return s==null?void 0:[s]}const r=this.namesToKeys.get(e);if(r==null)return;const n=[];if(r.forEach(s=>{const a=this.cache.get(s);a!=null&&n.push(a)}),n.length!==0)return n}}class ru{mu=new RT;requests=new Map;wrapped;debouncedRun;constructor(e,r){this.wrapped=e,this.debouncedRun=qp(()=>{this.run()},r)}async retrieve(e){if(!Array.isArray(e)&&typeof e=="object")return await this.wrapped.retrieve(e);const{normalized:r,variant:n}=ge(e);return n==="names"?await this.wrapped.retrieve(r):await new Promise((a,o)=>{this.mu.runExclusive(()=>{this.requests.set(r,{resolve:a,reject:o}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{const e=new Set;this.requests.forEach((r,n)=>n.forEach(s=>e.add(s)));try{const r=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((n,s)=>n.resolve(r.filter(a=>s.includes(a.key))))}catch(r){this.requests.forEach(n=>n.reject(r))}finally{this.requests.clear()}})}}const nu=async(t,e)=>{const{normalized:r}=ge(e),n=await t.retrieve(r),s=[];if(r.forEach(a=>{n.find(o=>o.name===a||o.key===a)==null&&s.push(a)}),s.length>0)throw new Fe(`Could not find channels: ${JSON.stringify(s)}`);return n},MT="sy_channel_set",DT="sy_channel_delete";class Ur{_frameClient;key;name;dataType;leaseholder;index;isIndex;internal;alias;virtual;expression;requires;status;constructor({dataType:e,name:r,leaseholder:n=0,key:s=0,isIndex:a=!1,index:o=0,internal:c=!1,virtual:l=!1,frameClient:u,alias:h,status:d,expression:f="",requires:v=[]}){this.key=D.parse(s),this.name=r,this.dataType=new R(e),this.leaseholder=n,this.index=D.parse(o),this.isIndex=a,this.internal=c,this.alias=h,this.virtual=l,this.expression=f,this.requires=D.array().parse(v??[]),d!=null&&(this.status=It.create(d)),this._frameClient=u??null}get framer(){if(this._frameClient==null)throw new Y("cannot read from a channel that has not been created");return this._frameClient}get payload(){return xt.parse({key:this.key,name:this.name,dataType:this.dataType.valueOf(),leaseholder:this.leaseholder,index:this.index,isIndex:this.isIndex,internal:this.internal,virtual:this.virtual,expression:this.expression,requires:this.requires,status:this.status})}get isCalculated(){return Xt(this.payload)}get ontologyID(){return au(this.key)}async read(e){return await this.framer.read(e,this.key)}async write(e,r){return await this.framer.write(e,this.key,r)}}const PT="sy_calculation_status",UT="/channel/retrieve-group",LT=i.z.object({}),BT=i.z.object({group:Jr});let su=class{frameClient;client;retriever;writer;constructor(e,r,n,s){this.frameClient=e,this.retriever=r,this.client=n,this.writer=s}async create(e,r={}){const{retrieveIfNameExists:n=!1}=r,s=!Array.isArray(e);let a=T.toArray(e),o=[];if(n){const c=await this.retriever.retrieve(a.map(u=>u.name)),l=new Set(c.map(u=>u.name));a=a.filter(u=>!l.has(u.name)),o=this.sugar(c)}return o=o.concat(this.sugar(await this.writer.create(a))),s?o[0]:o}async retrieve(e,r){if(typeof e=="object"&&!Array.isArray(e))return this.sugar(await this.retriever.retrieve(e));const n=!Array.isArray(e),s=this.sugar(await this.retriever.retrieve(e,r));return ce("channel",e,s,n),n?s[0]:s}async delete(e){const{normalized:r,variant:n}=ge(e);return n==="keys"?await this.writer.delete({keys:r}):await this.writer.delete({names:r})}async rename(e,r){return await this.writer.rename(T.toArray(e),T.toArray(r))}createDebouncedBatchRetriever(e=10){return new Ys(new ru(new lr(this.client),e))}sugar(e){const{frameClient:r}=this;return Array.isArray(e)?e.map(n=>new Ur({...n,frameClient:r})):new Ur({...e,frameClient:r})}async retrieveGroup(){return(await w(this.client,UT,{},LT,BT)).group}};const Xt=({virtual:t,expression:e})=>t&&e!=="",iu=async(t,e)=>{if(!Xt(e))return e.index;for(const r of e.requires){const n=await t(r);if(n==null)return null;if(!n.virtual)return n.index}for(const r of e.requires){const n=await t(r);if(n==null)return null;if(Xt(n)){const s=await iu(t,n);if(s!=null)return s}}return null},au=t=>({type:"channel",key:t.toString()}),qT=i.z.object({channels:eu.array()}),FT=i.z.object({channels:xt.array()}),VT=i.z.object({keys:D.array().optional(),names:xe.array().optional()}),YT=i.z.object({}),WT=i.z.object({keys:D.array(),names:xe.array()}),HT=i.z.object({}),GT="/channel/create",JT="/channel/delete",KT="/channel/rename";let ou=class{client;cache;constructor(e,r){this.client=e,this.cache=r}async create(e){const{channels:r}=await w(this.client,GT,{channels:e.map(n=>({...n,dataType:n.dataType}))},qT,FT);return this.cache.set(r),r}async delete(e){const r=D.array().parse(e.keys??[]);await w(this.client,JT,e,VT,YT),r.length>0&&this.cache.delete(r),e.names!=null&&this.cache.delete(e.names)}async rename(e,r){await w(this.client,KT,{keys:e,names:r},WT,HT),this.cache.rename(e,r)}};const XT=Object.freeze(Object.defineProperty({__proto__:null,CALCULATION_STATUS_CHANNEL_NAME:PT,CacheRetriever:Ys,Channel:Ur,Client:su,ClusterRetriever:lr,DELETE_CHANNEL_NAME:DT,DebouncedBatchRetriever:ru,SET_CHANNEL_NAME:MT,Writer:ou,analyzeParams:ge,isCalculated:Xt,keyZ:D,nameZ:xe,newZ:eu,ontologyID:au,paramsZ:it,payloadZ:xt,resolveCalculatedIndex:iu,retrieveRequired:nu,statusZ:Qc},Symbol.toStringTag,{value:"Module"})),We=i.z.uuid(),hr=i.z.object({key:We,username:i.z.string().min(1,"Username is required"),firstName:i.z.string().default(""),lastName:i.z.string().default(""),rootUser:i.z.boolean().default(!0)}),cu=hr.partial({key:!0,firstName:!0,lastName:!0}).omit({rootUser:!0}).extend({password:i.z.string().min(1)}),QT=i.z.object({keys:We.array().optional(),usernames:i.z.string().array().optional()}),ez=i.z.object({key:We}).transform(({key:t})=>({keys:[t]})),tz=i.z.object({username:i.z.string()}).transform(({username:t})=>({usernames:[t]})),rz=i.z.object({usernames:i.z.string().array()}).transform(({usernames:t})=>({usernames:t})),nz=i.z.union([ez,tz,rz,QT]),sz=i.z.object({users:T.nullableZ(hr)}),iz=i.z.object({users:cu.array()}),az=i.z.object({users:hr.array()}),oz=i.z.object({key:We,username:i.z.string().min(1)}),cz=i.z.object({}),uz=i.z.object({key:We,firstName:i.z.string().optional(),lastName:i.z.string().optional()}),lz=i.z.object({}),hz=i.z.object({keys:We.array()}),fz=i.z.object({}),dz="/user/retrieve",pz="/user/create",yz="/user/change-username",mz="/user/rename",gz="/user/delete";let uu=class{client;constructor(e){this.client=e}async create(e){const r=Array.isArray(e),n=await w(this.client,pz,{users:T.toArray(e)},iz,az);return r?n.users:n.users[0]}async changeUsername(e,r){await w(this.client,yz,{key:e,username:r},oz,cz)}async retrieve(e){const r="key"in e||"username"in e,n=await w(this.client,dz,e,nz,sz);if(!r)return n.users;if(n.users.length===0){const s="key"in e?`key ${e.key}`:`username ${e.username}`;throw new Ht(`No user with ${s} found`)}if(n.users.length>1){const s="key"in e?`key ${e.key}`:`username ${e.username}`;throw new Gt(`Multiple users found with ${s}`)}return n.users[0]}async rename(e,r,n){await w(this.client,mz,{key:e,firstName:r,lastName:n},uz,lz)}async delete(e){await w(this.client,gz,{keys:T.toArray(e)},hz,fz)}};const wz=t=>({type:"user",key:t}),bz=Object.freeze(Object.defineProperty({__proto__:null,Client:uu,keyZ:We,newZ:cu,ontologyID:wz,userZ:hr},Symbol.toStringTag,{value:"Module"})),vz=i.z.object({username:i.z.string(),password:i.z.string()}),Tz=i.z.object({token:i.z.string(),user:hr}),Xi="/auth/login",zz=3,Ez="/auth/change-password",Nz=i.z.object({username:i.z.string(),password:i.z.string(),newPassword:i.z.string().min(1)}),Oz=i.z.object({}),$z=[ss,is];let Sz=class{token;client;credentials;authenticating;authenticated;user;retryCount;constructor(e,r){this.client=e,this.authenticated=!1,this.credentials=r,this.retryCount=0}async changePassword(e){if(!this.authenticated)throw new Error("Not authenticated");await w(this.client,Ez,{username:this.credentials.username,password:this.credentials.password,newPassword:e},Nz,Oz),this.credentials.password=e}middleware(){const e=async(r,n)=>{if(!this.authenticated&&!r.target.endsWith(Xi)){this.authenticating??=new Promise((c,l)=>{this.client.send(Xi,this.credentials,vz,Tz).then(([u,h])=>{if(h!=null)return c(h);this.token=u?.token,this.user=u?.user,this.authenticated=!0,c(null)}).catch(l)});const o=await this.authenticating;if(o!=null)return[r,o]}r.params.Authorization=`Bearer ${this.token}`;const[s,a]=await n(r);return $z.some(o=>o.matches(a))&&this.retryCount<zz?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,e(r,n)):(this.retryCount=0,[s,a])};return e}};const lu=i.z.enum(["disconnected","connecting","connected","failed"]),hu=i.z.object({status:lu,error:i.z.instanceof(Error).optional(),message:i.z.string().optional(),clusterKey:i.z.string(),clientVersion:i.z.string(),clientServerCompatible:i.z.boolean(),nodeVersion:i.z.string().optional()}),Iz=i.z.object({clusterKey:i.z.string(),nodeVersion:i.z.string().optional()}),Qi={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.46.1"},ea=(t,e,r)=>{const n=r?"cluster":"client";return`Synnax cluster node version ${t!=null?`${t} `:""}is too ${r?"old":"new"} for client version ${e}.
40
+ `)}v.write("payload.value = newResult;"),v.write("return payload;");const A=v.compile();return(G,V)=>A(f,G,V)};let a;const o=Pr,c=!Nc.jitless,u=c&&yg.value,h=e.catchall;let d;t._zod.parse=(f,v)=>{d??(d=n.value);const S=f.value;return o(S)?c&&u&&v?.async===!1&&v.jitless!==!0?(a||(a=s(e.shape)),f=a(f,v),h?Uc([],S,f,v,d,t):f):r(f,v):(f.issues.push({expected:"object",code:"invalid_type",input:S,inst:t}),f)}});function Ri(t,e,r,n){for(const a of t)if(a.issues.length===0)return e.value=a.value,e;const s=t.filter(a=>!pt(a));return s.length===1?(e.value=s[0].value,s[0]):(e.issues.push({code:"invalid_union",input:e.value,inst:r,errors:t.map(a=>a.issues.map(o=>st(o,n,nt())))}),e)}const nb=y("$ZodUnion",(t,e)=>{F.init(t,e),P(t._zod,"optin",()=>e.options.some(s=>s._zod.optin==="optional")?"optional":void 0),P(t._zod,"optout",()=>e.options.some(s=>s._zod.optout==="optional")?"optional":void 0),P(t._zod,"values",()=>{if(e.options.every(s=>s._zod.values))return new Set(e.options.flatMap(s=>Array.from(s._zod.values)))}),P(t._zod,"pattern",()=>{if(e.options.every(s=>s._zod.pattern)){const s=e.options.map(a=>a._zod.pattern);return new RegExp(`^(${s.map(a=>Ds(a.source)).join("|")})$`)}});const r=e.options.length===1,n=e.options[0]._zod.run;t._zod.parse=(s,a)=>{if(r)return n(s,a);let o=!1;const c=[];for(const l of e.options){const u=l._zod.run({value:s.value,issues:[]},a);if(u instanceof Promise)c.push(u),o=!0;else{if(u.issues.length===0)return u;c.push(u)}}return o?Promise.all(c).then(l=>Ri(l,s,t,a)):Ri(c,s,t,a)}}),sb=y("$ZodIntersection",(t,e)=>{F.init(t,e),t._zod.parse=(r,n)=>{const s=r.value,a=e.left._zod.run({value:s,issues:[]},n),o=e.right._zod.run({value:s,issues:[]},n);return a instanceof Promise||o instanceof Promise?Promise.all([a,o]).then(([l,u])=>_i(r,l,u)):_i(r,a,o)}});function us(t,e){if(t===e)return{valid:!0,data:t};if(t instanceof Date&&e instanceof Date&&+t==+e)return{valid:!0,data:t};if(Jt(t)&&Jt(e)){const r=Object.keys(e),n=Object.keys(t).filter(a=>r.indexOf(a)!==-1),s={...t,...e};for(const a of n){const o=us(t[a],e[a]);if(!o.valid)return{valid:!1,mergeErrorPath:[a,...o.mergeErrorPath]};s[a]=o.data}return{valid:!0,data:s}}if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return{valid:!1,mergeErrorPath:[]};const r=[];for(let n=0;n<t.length;n++){const s=t[n],a=e[n],o=us(s,a);if(!o.valid)return{valid:!1,mergeErrorPath:[n,...o.mergeErrorPath]};r.push(o.data)}return{valid:!0,data:r}}return{valid:!1,mergeErrorPath:[]}}function _i(t,e,r){if(e.issues.length&&t.issues.push(...e.issues),r.issues.length&&t.issues.push(...r.issues),pt(t))return t;const n=us(e.value,r.value);if(!n.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(n.mergeErrorPath)}`);return t.value=n.data,t}const ib=y("$ZodEnum",(t,e)=>{F.init(t,e);const r=fg(e.entries),n=new Set(r);t._zod.values=n,t._zod.pattern=new RegExp(`^(${r.filter(s=>mg.has(typeof s)).map(s=>typeof s=="string"?en(s):s.toString()).join("|")})$`),t._zod.parse=(s,a)=>{const o=s.value;return n.has(o)||s.issues.push({code:"invalid_value",values:r,input:o,inst:t}),s}}),ab=y("$ZodTransform",(t,e)=>{F.init(t,e),t._zod.parse=(r,n)=>{if(n.direction==="backward")throw new Ec(t.constructor.name);const s=e.transform(r.value,r);if(n.async)return(s instanceof Promise?s:Promise.resolve(s)).then(o=>(r.value=o,r));if(s instanceof Promise)throw new bt;return r.value=s,r}});function ji(t,e){return t.issues.length&&e===void 0?{issues:[],value:void 0}:t}const ob=y("$ZodOptional",(t,e)=>{F.init(t,e),t._zod.optin="optional",t._zod.optout="optional",P(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,void 0]):void 0),P(t._zod,"pattern",()=>{const r=e.innerType._zod.pattern;return r?new RegExp(`^(${Ds(r.source)})?$`):void 0}),t._zod.parse=(r,n)=>{if(e.innerType._zod.optin==="optional"){const s=e.innerType._zod.run(r,n);return s instanceof Promise?s.then(a=>ji(a,r.value)):ji(s,r.value)}return r.value===void 0?r:e.innerType._zod.run(r,n)}}),cb=y("$ZodNullable",(t,e)=>{F.init(t,e),P(t._zod,"optin",()=>e.innerType._zod.optin),P(t._zod,"optout",()=>e.innerType._zod.optout),P(t._zod,"pattern",()=>{const r=e.innerType._zod.pattern;return r?new RegExp(`^(${Ds(r.source)}|null)$`):void 0}),P(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,null]):void 0),t._zod.parse=(r,n)=>r.value===null?r:e.innerType._zod.run(r,n)}),ub=y("$ZodDefault",(t,e)=>{F.init(t,e),t._zod.optin="optional",P(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(r,n)=>{if(n.direction==="backward")return e.innerType._zod.run(r,n);if(r.value===void 0)return r.value=e.defaultValue,r;const s=e.innerType._zod.run(r,n);return s instanceof Promise?s.then(a=>Mi(a,e)):Mi(s,e)}});function Mi(t,e){return t.value===void 0&&(t.value=e.defaultValue),t}const lb=y("$ZodPrefault",(t,e)=>{F.init(t,e),t._zod.optin="optional",P(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(r,n)=>(n.direction==="backward"||r.value===void 0&&(r.value=e.defaultValue),e.innerType._zod.run(r,n))}),hb=y("$ZodNonOptional",(t,e)=>{F.init(t,e),P(t._zod,"values",()=>{const r=e.innerType._zod.values;return r?new Set([...r].filter(n=>n!==void 0)):void 0}),t._zod.parse=(r,n)=>{const s=e.innerType._zod.run(r,n);return s instanceof Promise?s.then(a=>Di(a,t)):Di(s,t)}});function Di(t,e){return!t.issues.length&&t.value===void 0&&t.issues.push({code:"invalid_type",expected:"nonoptional",input:t.value,inst:e}),t}const fb=y("$ZodCatch",(t,e)=>{F.init(t,e),P(t._zod,"optin",()=>e.innerType._zod.optin),P(t._zod,"optout",()=>e.innerType._zod.optout),P(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(r,n)=>{if(n.direction==="backward")return e.innerType._zod.run(r,n);const s=e.innerType._zod.run(r,n);return s instanceof Promise?s.then(a=>(r.value=a.value,a.issues.length&&(r.value=e.catchValue({...r,error:{issues:a.issues.map(o=>st(o,n,nt()))},input:r.value}),r.issues=[]),r)):(r.value=s.value,s.issues.length&&(r.value=e.catchValue({...r,error:{issues:s.issues.map(a=>st(a,n,nt()))},input:r.value}),r.issues=[]),r)}}),db=y("$ZodPipe",(t,e)=>{F.init(t,e),P(t._zod,"values",()=>e.in._zod.values),P(t._zod,"optin",()=>e.in._zod.optin),P(t._zod,"optout",()=>e.out._zod.optout),P(t._zod,"propValues",()=>e.in._zod.propValues),t._zod.parse=(r,n)=>{if(n.direction==="backward"){const a=e.out._zod.run(r,n);return a instanceof Promise?a.then(o=>$r(o,e.in,n)):$r(a,e.in,n)}const s=e.in._zod.run(r,n);return s instanceof Promise?s.then(a=>$r(a,e.out,n)):$r(s,e.out,n)}});function $r(t,e,r){return t.issues.length?(t.aborted=!0,t):e._zod.run({value:t.value,issues:t.issues},r)}const pb=y("$ZodReadonly",(t,e)=>{F.init(t,e),P(t._zod,"propValues",()=>e.innerType._zod.propValues),P(t._zod,"values",()=>e.innerType._zod.values),P(t._zod,"optin",()=>e.innerType._zod.optin),P(t._zod,"optout",()=>e.innerType._zod.optout),t._zod.parse=(r,n)=>{if(n.direction==="backward")return e.innerType._zod.run(r,n);const s=e.innerType._zod.run(r,n);return s instanceof Promise?s.then(Pi):Pi(s)}});function Pi(t){return t.value=Object.freeze(t.value),t}const yb=y("$ZodCustom",(t,e)=>{ae.init(t,e),F.init(t,e),t._zod.parse=(r,n)=>r,t._zod.check=r=>{const n=r.value,s=e.fn(n);if(s instanceof Promise)return s.then(a=>Ui(a,r,n,t));Ui(s,r,n,t)}});function Ui(t,e,r,n){if(!t){const s={code:"custom",input:r,inst:n,path:[...n._zod.def.path??[]],continue:!n._zod.def.abort};n._zod.def.params&&(s.params=n._zod.def.params),e.issues.push(Xt(s))}}class mb{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...r){const n=r[0];if(this._map.set(e,n),n&&typeof n=="object"&&"id"in n){if(this._idmap.has(n.id))throw new Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){const r=this._map.get(e);return r&&typeof r=="object"&&"id"in r&&this._idmap.delete(r.id),this._map.delete(e),this}get(e){const r=e._zod.parent;if(r){const n={...this.get(r)??{}};delete n.id;const s={...n,...this._map.get(e)};return Object.keys(s).length?s:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}function gb(){return new mb}const Sr=gb();function wb(t,e){return new t({type:"string",...$(e)})}function bb(t,e){return new t({type:"string",format:"email",check:"string_format",abort:!1,...$(e)})}function Li(t,e){return new t({type:"string",format:"guid",check:"string_format",abort:!1,...$(e)})}function Lc(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,...$(e)})}function vb(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...$(e)})}function Tb(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...$(e)})}function zb(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...$(e)})}function Eb(t,e){return new t({type:"string",format:"url",check:"string_format",abort:!1,...$(e)})}function Nb(t,e){return new t({type:"string",format:"emoji",check:"string_format",abort:!1,...$(e)})}function Ob(t,e){return new t({type:"string",format:"nanoid",check:"string_format",abort:!1,...$(e)})}function $b(t,e){return new t({type:"string",format:"cuid",check:"string_format",abort:!1,...$(e)})}function Sb(t,e){return new t({type:"string",format:"cuid2",check:"string_format",abort:!1,...$(e)})}function Ib(t,e){return new t({type:"string",format:"ulid",check:"string_format",abort:!1,...$(e)})}function Ab(t,e){return new t({type:"string",format:"xid",check:"string_format",abort:!1,...$(e)})}function kb(t,e){return new t({type:"string",format:"ksuid",check:"string_format",abort:!1,...$(e)})}function xb(t,e){return new t({type:"string",format:"ipv4",check:"string_format",abort:!1,...$(e)})}function Zb(t,e){return new t({type:"string",format:"ipv6",check:"string_format",abort:!1,...$(e)})}function Cb(t,e){return new t({type:"string",format:"cidrv4",check:"string_format",abort:!1,...$(e)})}function Rb(t,e){return new t({type:"string",format:"cidrv6",check:"string_format",abort:!1,...$(e)})}function _b(t,e){return new t({type:"string",format:"base64",check:"string_format",abort:!1,...$(e)})}function jb(t,e){return new t({type:"string",format:"base64url",check:"string_format",abort:!1,...$(e)})}function Mb(t,e){return new t({type:"string",format:"e164",check:"string_format",abort:!1,...$(e)})}function Db(t,e){return new t({type:"string",format:"jwt",check:"string_format",abort:!1,...$(e)})}function Pb(t,e){return new t({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...$(e)})}function Ub(t,e){return new t({type:"string",format:"date",check:"string_format",...$(e)})}function Lb(t,e){return new t({type:"string",format:"time",check:"string_format",precision:null,...$(e)})}function Bb(t,e){return new t({type:"string",format:"duration",check:"string_format",...$(e)})}function qb(t,e){return new t({type:"number",checks:[],...$(e)})}function Fb(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"safeint",...$(e)})}function Vb(t,e){return new t({type:"boolean",...$(e)})}function Yb(t){return new t({type:"unknown"})}function Hb(t,e){return new t({type:"never",...$(e)})}function Bi(t,e){return new _c({check:"less_than",...$(e),value:t,inclusive:!1})}function Sn(t,e){return new _c({check:"less_than",...$(e),value:t,inclusive:!0})}function qi(t,e){return new jc({check:"greater_than",...$(e),value:t,inclusive:!1})}function In(t,e){return new jc({check:"greater_than",...$(e),value:t,inclusive:!0})}function Fi(t,e){return new hw({check:"multiple_of",...$(e),value:t})}function Bc(t,e){return new dw({check:"max_length",...$(e),maximum:t})}function Lr(t,e){return new pw({check:"min_length",...$(e),minimum:t})}function qc(t,e){return new yw({check:"length_equals",...$(e),length:t})}function Wb(t,e){return new mw({check:"string_format",format:"regex",...$(e),pattern:t})}function Gb(t){return new gw({check:"string_format",format:"lowercase",...$(t)})}function Kb(t){return new ww({check:"string_format",format:"uppercase",...$(t)})}function Jb(t,e){return new bw({check:"string_format",format:"includes",...$(e),includes:t})}function Xb(t,e){return new vw({check:"string_format",format:"starts_with",...$(e),prefix:t})}function Qb(t,e){return new Tw({check:"string_format",format:"ends_with",...$(e),suffix:t})}function cr(t){return new zw({check:"overwrite",tx:t})}function ev(t){return cr(e=>e.normalize(t))}function tv(){return cr(t=>t.trim())}function rv(){return cr(t=>t.toLowerCase())}function nv(){return cr(t=>t.toUpperCase())}function sv(t,e,r){return new t({type:"array",element:e,...$(r)})}function iv(t,e,r){return new t({type:"custom",check:"custom",fn:e,...$(r)})}function av(t){const e=ov(r=>(r.addIssue=n=>{if(typeof n=="string")r.issues.push(Xt(n,r.value,e._zod.def));else{const s=n;s.fatal&&(s.continue=!1),s.code??(s.code="custom"),s.input??(s.input=r.value),s.inst??(s.inst=e),s.continue??(s.continue=!e._zod.def.abort),r.issues.push(Xt(s))}},t(r.value,r)));return e}function ov(t,e){const r=new ae({check:"custom",...$(e)});return r._zod.check=t,r}const cv=y("ZodISODateTime",(t,e)=>{jw.init(t,e),q.init(t,e)});function uv(t){return Pb(cv,t)}const lv=y("ZodISODate",(t,e)=>{Mw.init(t,e),q.init(t,e)});function hv(t){return Ub(lv,t)}const fv=y("ZodISOTime",(t,e)=>{Dw.init(t,e),q.init(t,e)});function dv(t){return Lb(fv,t)}const pv=y("ZodISODuration",(t,e)=>{Pw.init(t,e),q.init(t,e)});function yv(t){return Bb(pv,t)}const mv=(t,e)=>{Ac.init(t,e),t.name="ZodError",Object.defineProperties(t,{format:{value:r=>Sg(t,r)},flatten:{value:r=>$g(t,r)},addIssue:{value:r=>{t.issues.push(r),t.message=JSON.stringify(t.issues,cs,2)}},addIssues:{value:r=>{t.issues.push(...r),t.message=JSON.stringify(t.issues,cs,2)}},isEmpty:{get(){return t.issues.length===0}}})},pe=y("ZodError",mv,{Parent:Error}),gv=Us(pe),wv=Ls(pe),bv=tn(pe),vv=rn(pe),Tv=kg(pe),zv=xg(pe),Ev=Zg(pe),Nv=Cg(pe),Ov=Rg(pe),$v=_g(pe),Sv=jg(pe),Iv=Mg(pe),W=y("ZodType",(t,e)=>(F.init(t,e),t.def=e,t.type=e.type,Object.defineProperty(t,"_def",{value:e}),t.check=(...r)=>t.clone({...e,checks:[...e.checks??[],...r.map(n=>typeof n=="function"?{_zod:{check:n,def:{check:"custom"},onattach:[]}}:n)]}),t.clone=(r,n)=>He(t,r,n),t.brand=()=>t,t.register=((r,n)=>(r.add(t,n),t)),t.parse=(r,n)=>gv(t,r,n,{callee:t.parse}),t.safeParse=(r,n)=>bv(t,r,n),t.parseAsync=async(r,n)=>wv(t,r,n,{callee:t.parseAsync}),t.safeParseAsync=async(r,n)=>vv(t,r,n),t.spa=t.safeParseAsync,t.encode=(r,n)=>Tv(t,r,n),t.decode=(r,n)=>zv(t,r,n),t.encodeAsync=async(r,n)=>Ev(t,r,n),t.decodeAsync=async(r,n)=>Nv(t,r,n),t.safeEncode=(r,n)=>Ov(t,r,n),t.safeDecode=(r,n)=>$v(t,r,n),t.safeEncodeAsync=async(r,n)=>Sv(t,r,n),t.safeDecodeAsync=async(r,n)=>Iv(t,r,n),t.refine=(r,n)=>t.check(vT(r,n)),t.superRefine=r=>t.check(TT(r)),t.overwrite=r=>t.check(cr(r)),t.optional=()=>Gi(t),t.nullable=()=>Ki(t),t.nullish=()=>Gi(Ki(t)),t.nonoptional=r=>dT(t,r),t.array=()=>eT(t),t.or=r=>qs([t,r]),t.and=r=>sT(t,r),t.transform=r=>Ji(t,oT(r)),t.default=r=>lT(t,r),t.prefault=r=>fT(t,r),t.catch=r=>yT(t,r),t.pipe=r=>Ji(t,r),t.readonly=()=>wT(t),t.describe=r=>{const n=t.clone();return Sr.add(n,{description:r}),n},Object.defineProperty(t,"description",{get(){return Sr.get(t)?.description},configurable:!0}),t.meta=(...r)=>{if(r.length===0)return Sr.get(t);const n=t.clone();return Sr.add(n,r[0]),n},t.isOptional=()=>t.safeParse(void 0).success,t.isNullable=()=>t.safeParse(null).success,t)),Fc=y("_ZodString",(t,e)=>{Bs.init(t,e),W.init(t,e);const r=t._zod.bag;t.format=r.format??null,t.minLength=r.minimum??null,t.maxLength=r.maximum??null,t.regex=(...n)=>t.check(Wb(...n)),t.includes=(...n)=>t.check(Jb(...n)),t.startsWith=(...n)=>t.check(Xb(...n)),t.endsWith=(...n)=>t.check(Qb(...n)),t.min=(...n)=>t.check(Lr(...n)),t.max=(...n)=>t.check(Bc(...n)),t.length=(...n)=>t.check(qc(...n)),t.nonempty=(...n)=>t.check(Lr(1,...n)),t.lowercase=n=>t.check(Gb(n)),t.uppercase=n=>t.check(Kb(n)),t.trim=()=>t.check(tv()),t.normalize=(...n)=>t.check(ev(...n)),t.toLowerCase=()=>t.check(rv()),t.toUpperCase=()=>t.check(nv())}),Av=y("ZodString",(t,e)=>{Bs.init(t,e),Fc.init(t,e),t.email=r=>t.check(bb(kv,r)),t.url=r=>t.check(Eb(Zv,r)),t.jwt=r=>t.check(Db(Hv,r)),t.emoji=r=>t.check(Nb(Cv,r)),t.guid=r=>t.check(Li(Vi,r)),t.uuid=r=>t.check(Lc(Ut,r)),t.uuidv4=r=>t.check(vb(Ut,r)),t.uuidv6=r=>t.check(Tb(Ut,r)),t.uuidv7=r=>t.check(zb(Ut,r)),t.nanoid=r=>t.check(Ob(Rv,r)),t.guid=r=>t.check(Li(Vi,r)),t.cuid=r=>t.check($b(_v,r)),t.cuid2=r=>t.check(Sb(jv,r)),t.ulid=r=>t.check(Ib(Mv,r)),t.base64=r=>t.check(_b(Fv,r)),t.base64url=r=>t.check(jb(Vv,r)),t.xid=r=>t.check(Ab(Dv,r)),t.ksuid=r=>t.check(kb(Pv,r)),t.ipv4=r=>t.check(xb(Uv,r)),t.ipv6=r=>t.check(Zb(Lv,r)),t.cidrv4=r=>t.check(Cb(Bv,r)),t.cidrv6=r=>t.check(Rb(qv,r)),t.e164=r=>t.check(Mb(Yv,r)),t.datetime=r=>t.check(uv(r)),t.date=r=>t.check(hv(r)),t.time=r=>t.check(dv(r)),t.duration=r=>t.check(yv(r))});function de(t){return wb(Av,t)}const q=y("ZodStringFormat",(t,e)=>{L.init(t,e),Fc.init(t,e)}),kv=y("ZodEmail",(t,e)=>{Sw.init(t,e),q.init(t,e)}),Vi=y("ZodGUID",(t,e)=>{Ow.init(t,e),q.init(t,e)}),Ut=y("ZodUUID",(t,e)=>{$w.init(t,e),q.init(t,e)});function xv(t){return Lc(Ut,t)}const Zv=y("ZodURL",(t,e)=>{Iw.init(t,e),q.init(t,e)}),Cv=y("ZodEmoji",(t,e)=>{Aw.init(t,e),q.init(t,e)}),Rv=y("ZodNanoID",(t,e)=>{kw.init(t,e),q.init(t,e)}),_v=y("ZodCUID",(t,e)=>{xw.init(t,e),q.init(t,e)}),jv=y("ZodCUID2",(t,e)=>{Zw.init(t,e),q.init(t,e)}),Mv=y("ZodULID",(t,e)=>{Cw.init(t,e),q.init(t,e)}),Dv=y("ZodXID",(t,e)=>{Rw.init(t,e),q.init(t,e)}),Pv=y("ZodKSUID",(t,e)=>{_w.init(t,e),q.init(t,e)}),Uv=y("ZodIPv4",(t,e)=>{Uw.init(t,e),q.init(t,e)}),Lv=y("ZodIPv6",(t,e)=>{Lw.init(t,e),q.init(t,e)}),Bv=y("ZodCIDRv4",(t,e)=>{Bw.init(t,e),q.init(t,e)}),qv=y("ZodCIDRv6",(t,e)=>{qw.init(t,e),q.init(t,e)}),Fv=y("ZodBase64",(t,e)=>{Fw.init(t,e),q.init(t,e)}),Vv=y("ZodBase64URL",(t,e)=>{Yw.init(t,e),q.init(t,e)}),Yv=y("ZodE164",(t,e)=>{Hw.init(t,e),q.init(t,e)}),Hv=y("ZodJWT",(t,e)=>{Gw.init(t,e),q.init(t,e)}),Vc=y("ZodNumber",(t,e)=>{Dc.init(t,e),W.init(t,e),t.gt=(n,s)=>t.check(qi(n,s)),t.gte=(n,s)=>t.check(In(n,s)),t.min=(n,s)=>t.check(In(n,s)),t.lt=(n,s)=>t.check(Bi(n,s)),t.lte=(n,s)=>t.check(Sn(n,s)),t.max=(n,s)=>t.check(Sn(n,s)),t.int=n=>t.check(Hi(n)),t.safe=n=>t.check(Hi(n)),t.positive=n=>t.check(qi(0,n)),t.nonnegative=n=>t.check(In(0,n)),t.negative=n=>t.check(Bi(0,n)),t.nonpositive=n=>t.check(Sn(0,n)),t.multipleOf=(n,s)=>t.check(Fi(n,s)),t.step=(n,s)=>t.check(Fi(n,s)),t.finite=()=>t;const r=t._zod.bag;t.minValue=Math.max(r.minimum??Number.NEGATIVE_INFINITY,r.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,t.maxValue=Math.min(r.maximum??Number.POSITIVE_INFINITY,r.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,t.isInt=(r.format??"").includes("int")||Number.isSafeInteger(r.multipleOf??.5),t.isFinite=!0,t.format=r.format??null});function Yi(t){return qb(Vc,t)}const Wv=y("ZodNumberFormat",(t,e)=>{Kw.init(t,e),Vc.init(t,e)});function Hi(t){return Fb(Wv,t)}const Gv=y("ZodBoolean",(t,e)=>{Jw.init(t,e),W.init(t,e)});function ur(t){return Vb(Gv,t)}const Kv=y("ZodUnknown",(t,e)=>{Xw.init(t,e),W.init(t,e)});function Wi(){return Yb(Kv)}const Jv=y("ZodNever",(t,e)=>{Qw.init(t,e),W.init(t,e)});function Xv(t){return Hb(Jv,t)}const Qv=y("ZodArray",(t,e)=>{eb.init(t,e),W.init(t,e),t.element=e.element,t.min=(r,n)=>t.check(Lr(r,n)),t.nonempty=r=>t.check(Lr(1,r)),t.max=(r,n)=>t.check(Bc(r,n)),t.length=(r,n)=>t.check(qc(r,n)),t.unwrap=()=>t.element});function eT(t,e){return sv(Qv,t,e)}const tT=y("ZodObject",(t,e)=>{rb.init(t,e),W.init(t,e),P(t,"shape",()=>e.shape),t.keyof=()=>iT(Object.keys(t._zod.def.shape)),t.catchall=r=>t.clone({...t._zod.def,catchall:r}),t.passthrough=()=>t.clone({...t._zod.def,catchall:Wi()}),t.loose=()=>t.clone({...t._zod.def,catchall:Wi()}),t.strict=()=>t.clone({...t._zod.def,catchall:Xv()}),t.strip=()=>t.clone({...t._zod.def,catchall:void 0}),t.extend=r=>Tg(t,r),t.safeExtend=r=>zg(t,r),t.merge=r=>Eg(t,r),t.pick=r=>bg(t,r),t.omit=r=>vg(t,r),t.partial=(...r)=>Ng(Yc,t,r[0]),t.required=(...r)=>Og(Hc,t,r[0])});function te(t,e){const r={type:"object",get shape(){return Ye(this,"shape",t?pg(t):{}),this.shape},...$(e)};return new tT(r)}const rT=y("ZodUnion",(t,e)=>{nb.init(t,e),W.init(t,e),t.options=e.options});function qs(t,e){return new rT({type:"union",options:t,...$(e)})}const nT=y("ZodIntersection",(t,e)=>{sb.init(t,e),W.init(t,e)});function sT(t,e){return new nT({type:"intersection",left:t,right:e})}const ls=y("ZodEnum",(t,e)=>{ib.init(t,e),W.init(t,e),t.enum=e.entries,t.options=Object.values(e.entries);const r=new Set(Object.keys(e.entries));t.extract=(n,s)=>{const a={};for(const o of n)if(r.has(o))a[o]=e.entries[o];else throw new Error(`Key ${o} not found in enum`);return new ls({...e,checks:[],...$(s),entries:a})},t.exclude=(n,s)=>{const a={...e.entries};for(const o of n)if(r.has(o))delete a[o];else throw new Error(`Key ${o} not found in enum`);return new ls({...e,checks:[],...$(s),entries:a})}});function iT(t,e){const r=Array.isArray(t)?Object.fromEntries(t.map(n=>[n,n])):t;return new ls({type:"enum",entries:r,...$(e)})}const aT=y("ZodTransform",(t,e)=>{ab.init(t,e),W.init(t,e),t._zod.parse=(r,n)=>{if(n.direction==="backward")throw new Ec(t.constructor.name);r.addIssue=a=>{if(typeof a=="string")r.issues.push(Xt(a,r.value,e));else{const o=a;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=r.value),o.inst??(o.inst=t),r.issues.push(Xt(o))}};const s=e.transform(r.value,r);return s instanceof Promise?s.then(a=>(r.value=a,r)):(r.value=s,r)}});function oT(t){return new aT({type:"transform",transform:t})}const Yc=y("ZodOptional",(t,e)=>{ob.init(t,e),W.init(t,e),t.unwrap=()=>t._zod.def.innerType});function Gi(t){return new Yc({type:"optional",innerType:t})}const cT=y("ZodNullable",(t,e)=>{cb.init(t,e),W.init(t,e),t.unwrap=()=>t._zod.def.innerType});function Ki(t){return new cT({type:"nullable",innerType:t})}const uT=y("ZodDefault",(t,e)=>{ub.init(t,e),W.init(t,e),t.unwrap=()=>t._zod.def.innerType,t.removeDefault=t.unwrap});function lT(t,e){return new uT({type:"default",innerType:t,get defaultValue(){return typeof e=="function"?e():$c(e)}})}const hT=y("ZodPrefault",(t,e)=>{lb.init(t,e),W.init(t,e),t.unwrap=()=>t._zod.def.innerType});function fT(t,e){return new hT({type:"prefault",innerType:t,get defaultValue(){return typeof e=="function"?e():$c(e)}})}const Hc=y("ZodNonOptional",(t,e)=>{hb.init(t,e),W.init(t,e),t.unwrap=()=>t._zod.def.innerType});function dT(t,e){return new Hc({type:"nonoptional",innerType:t,...$(e)})}const pT=y("ZodCatch",(t,e)=>{fb.init(t,e),W.init(t,e),t.unwrap=()=>t._zod.def.innerType,t.removeCatch=t.unwrap});function yT(t,e){return new pT({type:"catch",innerType:t,catchValue:typeof e=="function"?e:()=>e})}const mT=y("ZodPipe",(t,e)=>{db.init(t,e),W.init(t,e),t.in=e.in,t.out=e.out});function Ji(t,e){return new mT({type:"pipe",in:t,out:e})}const gT=y("ZodReadonly",(t,e)=>{pb.init(t,e),W.init(t,e),t.unwrap=()=>t._zod.def.innerType});function wT(t){return new gT({type:"readonly",innerType:t})}const bT=y("ZodCustom",(t,e)=>{yb.init(t,e),W.init(t,e)});function vT(t,e={}){return iv(bT,t,e)}function TT(t){return av(t)}const sn=i.z.string(),lr=t=>At.statusZ(t),Wc=t=>lr(t).omit({labels:!0}).partial({key:!0}),zT="sy_status_set",ET="sy_status_delete",NT=t=>({type:"status",key:t}),Ae=t=>t?JSON.parse(t):{},Fs=te({key:de(),type:de(),config:be.unknownZ.or(de().transform(Ae))}),Gc=Fs.extend({position:As.xy}),hs=te({param:de(),node:de()}),Vs=te({source:hs,target:hs}),OT=te({nodes:Fs.array(),edges:Vs.array()}),Kc=te({nodes:Gc.array(),edges:Vs.array()}),Jc=te({raw:de()}),hr=xv(),Xc=te({running:ur()}),Qc=lr(Xc),an=te({key:hr,name:de(),graph:Kc,text:Jc,deploy:ur(),version:de(),status:Qc.optional().nullable()}),eu=an.partial({key:!0}).omit({status:!0}),tu="arc",$T=(t,e,{convertNumericStrings:r=!0}={})=>{const n=!Array.isArray(t);let s=T.toArray(t);const a=s[0],o=typeof a;let c;return o==="string"&&r&&!isNaN(parseInt(a))&&"number"in e?(c=e.number,s=s.map(l=>parseInt(l))):c=e[o],{single:n,variant:c,normalized:s,actual:t}},ce=(t,e,r,n)=>{if(n){if(r.length===0)throw new Gt(`${t} not found matching ${JSON.stringify(e)}`);if(r.length>1)throw new Kt(`Expected one ${t} matching ${JSON.stringify(e)}, but found ${r.length}`)}},ST="sy_arc_set",IT="sy_arc_delete",AT="/arc/retrieve",kT="/arc/create",xT="/arc/delete",ZT="/arc/lsp",CT=te({keys:hr.array().optional(),names:de().array().optional(),searchTerm:de().optional(),limit:Yi().optional(),offset:Yi().optional(),includeStatus:ur().optional()}),RT=te({arcs:eu.array()}),_T=te({keys:hr.array()}),jT=te({arcs:T.nullableZ(an)}),MT=te({arcs:an.array()}),DT=te({}),fs=te({content:de()}),PT=te({key:hr,includeStatus:ur().optional()}).transform(({key:t,includeStatus:e})=>({keys:[t],includeStatus:e})),UT=te({name:de(),includeStatus:ur().optional()}).transform(({name:t,includeStatus:e})=>({names:[t],includeStatus:e})),ru=qs([PT,UT]),LT=qs([ru,CT]);let nu=class{client;streamClient;constructor(e,r){this.client=e,this.streamClient=r}async create(e){const r=Array.isArray(e),n=await w(this.client,kT,{arcs:T.toArray(e)},RT,MT);return r?n.arcs:n.arcs[0]}async retrieve(e){const r="key"in e||"name"in e,n=await w(this.client,AT,e,LT,jT);return ce("Arc",e,n.arcs,r),r?n.arcs[0]:n.arcs}async delete(e){await w(this.client,xT,{keys:T.toArray(e)},_T,DT)}async openLSP(){return await this.streamClient.stream(ZT,fs,fs)}};const BT=t=>({type:tu,key:t}),qT=Object.freeze(Object.defineProperty({__proto__:null,Client:nu,DELETE_CHANNEL_NAME:IT,ONTOLOGY_TYPE:tu,SET_CHANNEL_NAME:ST,arcZ:an,edgeZ:Vs,graphNodeZ:Gc,graphZ:Kc,handleZ:hs,irNodeZ:Fs,irZ:OT,keyZ:hr,lspMessageZ:fs,newZ:eu,ontologyID:BT,singleRetrieveArgsZ:ru,statusDetailsZ:Xc,statusZ:Qc,textZ:Jc},Symbol.toStringTag,{value:"Module"})),Xi="Channel key must be a valid uint32.",U=i.z.uint32().or(i.z.string().refine(t=>!isNaN(Number(t)),{message:Xi}).transform(Number).refine(t=>t<Qn.MAX_UINT32,{message:Xi})),Ze=i.z.string(),su=["min","max","avg","none"],iu=i.z.enum(su),Ys=i.z.object({type:iu,resetChannel:U.optional(),duration:I.z.optional()}),au=At.statusZ(),Zt=i.z.object({name:Ze,key:U,dataType:R.z,leaseholder:i.z.number(),index:U,isIndex:i.z.boolean(),internal:i.z.boolean(),virtual:i.z.boolean(),alias:i.z.string().optional(),expression:i.z.string().default(""),status:au.optional(),operations:T.nullableZ(Ys),requires:T.nullableZ(U)}),ou=Zt.omit({requires:!0}).extend({key:U.optional(),leaseholder:i.z.number().optional(),index:U.optional(),isIndex:i.z.boolean().optional(),internal:i.z.boolean().optional().default(!1),virtual:i.z.boolean().optional().default(!1),expression:i.z.string().optional().default(""),operations:T.nullableZ(Ys).optional()}),at=i.z.union([Bt.toArray(U),Bt.toArray(Ze),Bt.toArray(Zt).transform(t=>t.map(e=>e.key))]),FT=new Error("request for lock canceled");var VT=function(t,e,r,n){function s(a){return a instanceof r?a:new r(function(o){o(a)})}return new(r||(r=Promise))(function(a,o){function c(h){try{u(n.next(h))}catch(d){o(d)}}function l(h){try{u(n.throw(h))}catch(d){o(d)}}function u(h){h.done?a(h.value):s(h.value).then(c,l)}u((n=n.apply(t,e||[])).next())})};class YT{constructor(e,r=FT){this._value=e,this._cancelError=r,this._queue=[],this._weightedWaiters=[]}acquire(e=1,r=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((n,s)=>{const a={resolve:n,reject:s,weight:e,priority:r},o=cu(this._queue,c=>r<=c.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return VT(this,arguments,void 0,function*(r,n=1,s=0){const[a,o]=yield this.acquire(n,s);try{return yield r(a)}finally{o()}})}waitForUnlock(e=1,r=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,r)?Promise.resolve():new Promise(n=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),HT(this._weightedWaiters[e-1],{resolve:n,priority:r})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const r=this._value;this._value-=e.weight,e.resolve([r,this._newReleaser(e.weight)])}_newReleaser(e){let r=!1;return()=>{r||(r=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const r=this._weightedWaiters[e-1];r&&(r.forEach(n=>n.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let r=this._value;r>0;r--){const n=this._weightedWaiters[r-1];if(!n)continue;const s=n.findIndex(a=>a.priority<=e);(s===-1?n:n.splice(0,s)).forEach((a=>a.resolve()))}}}_couldLockImmediately(e,r){return(this._queue.length===0||this._queue[0].priority<r)&&e<=this._value}}function HT(t,e){const r=cu(t,n=>e.priority<=n.priority);t.splice(r+1,0,e)}function cu(t,e){for(let r=t.length-1;r>=0;r--)if(e(t[r]))return r;return-1}var WT=function(t,e,r,n){function s(a){return a instanceof r?a:new r(function(o){o(a)})}return new(r||(r=Promise))(function(a,o){function c(h){try{u(n.next(h))}catch(d){o(d)}}function l(h){try{u(n.throw(h))}catch(d){o(d)}}function u(h){h.done?a(h.value):s(h.value).then(c,l)}u((n=n.apply(t,e||[])).next())})};class GT{constructor(e){this._semaphore=new YT(1,e)}acquire(){return WT(this,arguments,void 0,function*(e=0){const[,r]=yield this._semaphore.acquire(1,e);return r})}runExclusive(e,r=0){return this._semaphore.runExclusive(()=>e(),1,r)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}const KT=i.z.object({leaseholder:i.z.number().optional(),keys:U.array().optional(),names:i.z.string().array().optional(),searchTerm:i.z.string().optional(),rangeKey:i.z.string().optional(),limit:i.z.number().optional(),offset:i.z.number().optional(),dataTypes:R.z.array().optional(),notDataTypes:R.z.array().optional(),virtual:i.z.boolean().optional(),isIndex:i.z.boolean().optional(),internal:i.z.boolean().optional(),calculated:i.z.boolean().optional(),legacyCalculated:i.z.boolean().optional()}),JT=i.z.object({channels:T.nullableZ(Zt)}),ge=t=>(Array.isArray(t)&&t.length>0&&typeof t[0]=="object"?t=t.map(e=>e.key):typeof t=="object"&&"key"in t&&(t=[t.key]),$T(t,{number:"keys",string:"names"}));class fr{static ENDPOINT="/channel/retrieve";client;constructor(e){this.client=e}async retrieve(e,r){if(!Array.isArray(e)&&typeof e=="object")return await this.execute(e);const n=ge(e),{variant:s}=n;let{normalized:a}=n;return s==="keys"&&a.indexOf(0)!==-1&&(a=a.filter(o=>o!==0)),a.length===0?[]:await this.execute({[s]:a,...r})}async execute(e){const[r,n]=await this.client.send(fr.ENDPOINT,e,KT,JT);if(n!=null)throw n;return r.channels}}class Hs{cache;namesToKeys;wrapped;constructor(e){this.cache=new Map,this.namesToKeys=new Map,this.wrapped=e}async retrieve(e,r){if(!Array.isArray(e)&&typeof e=="object")return await this.wrapped.retrieve(e);const{normalized:n}=ge(e),s=[],a=[];if(n.forEach(c=>{const l=this.get(c);l!=null?s.push(...l):a.push(c)}),a.length===0)return s;const o=await this.wrapped.retrieve(a,r);return this.set(o),s.concat(o)}delete(e){const{variant:r,normalized:n}=ge(e);r==="names"?n.forEach(s=>{const a=this.namesToKeys.get(s);a!=null&&(a.forEach(o=>this.cache.delete(o)),this.namesToKeys.delete(s))}):n.forEach(s=>{const a=this.cache.get(s);a!=null&&(this.cache.delete(s),this.namesToKeys.delete(a.name))})}rename(e,r){e.forEach((n,s)=>{const a=r[s],o=this.cache.get(n);if(o==null)return;this.cache.delete(n);const c=this.namesToKeys.get(o.name);c!=null&&(c.delete(n),c.size===0&&this.namesToKeys.delete(o.name)),o.name=a,this.cache.set(n,o);const l=this.namesToKeys.get(a);l==null?this.namesToKeys.set(a,new Set([n])):l.add(n)})}set(e){e.forEach(r=>{this.cache.set(r.key,r);const n=this.namesToKeys.get(r.name);n==null?this.namesToKeys.set(r.name,new Set([r.key])):n.add(r.key)})}get(e){if(typeof e=="number"){const s=this.cache.get(e);return s==null?void 0:[s]}const r=this.namesToKeys.get(e);if(r==null)return;const n=[];if(r.forEach(s=>{const a=this.cache.get(s);a!=null&&n.push(a)}),n.length!==0)return n}}class uu{mu=new GT;requests=new Map;wrapped;debouncedRun;constructor(e,r){this.wrapped=e,this.debouncedRun=Jp(()=>{this.run()},r)}async retrieve(e){if(!Array.isArray(e)&&typeof e=="object")return await this.wrapped.retrieve(e);const{normalized:r,variant:n}=ge(e);return n==="names"?await this.wrapped.retrieve(r):await new Promise((a,o)=>{this.mu.runExclusive(()=>{this.requests.set(r,{resolve:a,reject:o}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{const e=new Set;this.requests.forEach((r,n)=>n.forEach(s=>e.add(s)));try{const r=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((n,s)=>n.resolve(r.filter(a=>s.includes(a.key))))}catch(r){this.requests.forEach(n=>n.reject(r))}finally{this.requests.clear()}})}}const lu=async(t,e)=>{const{normalized:r}=ge(e),n=await t.retrieve(r),s=[];if(r.forEach(a=>{n.find(o=>o.name===a||o.key===a)==null&&s.push(a)}),s.length>0)throw new Ve(`Could not find channels: ${JSON.stringify(s)}`);return n},XT="sy_channel_set",QT="sy_channel_delete";class Br{_frameClient;key;name;dataType;leaseholder;index;isIndex;internal;alias;virtual;expression;operations;requires;status;constructor({dataType:e,name:r,leaseholder:n=0,key:s=0,isIndex:a=!1,index:o=0,internal:c=!1,virtual:l=!1,frameClient:u,alias:h,status:d,expression:f="",operations:v=[],requires:S=[]}){this.key=U.parse(s),this.name=r,this.dataType=new R(e),this.leaseholder=n,this.index=U.parse(o),this.isIndex=a,this.internal=c,this.alias=h,this.virtual=l,this.expression=f,this.operations=v,this.requires=S,d!=null&&(this.status=At.create(d)),this._frameClient=u??null}get framer(){if(this._frameClient==null)throw new Y("cannot read from a channel that has not been created");return this._frameClient}get payload(){return Zt.parse({key:this.key,name:this.name,dataType:this.dataType.valueOf(),leaseholder:this.leaseholder,index:this.index,isIndex:this.isIndex,internal:this.internal,virtual:this.virtual,requires:this.requires,expression:this.expression,status:this.status,operations:this.operations})}get isCalculated(){return Et(this.payload)}get ontologyID(){return fu(this.key)}async read(e){return await this.framer.read(e,this.key)}async write(e,r){return await this.framer.write(e,this.key,r)}}const ez="sy_calculation_status",tz="/channel/retrieve-group",rz=i.z.object({}),nz=i.z.object({group:Jr});let hu=class{frameClient;client;retriever;writer;constructor(e,r,n,s){this.frameClient=e,this.retriever=r,this.client=n,this.writer=s}async create(e,r={}){const{retrieveIfNameExists:n=!1}=r,s=!Array.isArray(e);let a=T.toArray(e),o=[];if(n){const c=await this.retriever.retrieve(a.map(u=>u.name)),l=new Set(c.map(u=>u.name));a=a.filter(u=>!l.has(u.name)),o=this.sugar(c)}return o=o.concat(this.sugar(await this.writer.create(a))),s?o[0]:o}async retrieve(e,r){if(typeof e=="object"&&!Array.isArray(e))return this.sugar(await this.retriever.retrieve(e));const n=!Array.isArray(e),s=this.sugar(await this.retriever.retrieve(e,r));return ce("channel",e,s,n),n?s[0]:s}async delete(e){const{normalized:r,variant:n}=ge(e);return n==="keys"?await this.writer.delete({keys:r}):await this.writer.delete({names:r})}async rename(e,r){return await this.writer.rename(T.toArray(e),T.toArray(r))}createDebouncedBatchRetriever(e=10){return new Hs(new uu(new fr(this.client),e))}sugar(e){const{frameClient:r}=this;return Array.isArray(e)?e.map(n=>new Br({...n,frameClient:r})):new Br({...e,frameClient:r})}async retrieveGroup(){return(await w(this.client,tz,{},rz,nz)).group}};const Et=({virtual:t,expression:e})=>t&&e!=="",sz=t=>Et(t)&&t.requires.length>0,fu=t=>({type:"channel",key:t.toString()}),du=async(t,e)=>{if(!Et(e))return e.index;for(const r of e.requires){const n=await t(r);if(n==null)return null;if(!n.virtual)return n.index}for(const r of e.requires){const n=await t(r);if(n==null)return null;if(Et(n)){const s=await du(t,n);if(s!=null)return s}}return null},iz=i.z.object({channels:ou.array()}),az=i.z.object({channels:Zt.array()}),oz=i.z.object({keys:U.array().optional(),names:Ze.array().optional()}),cz=i.z.object({}),uz=i.z.object({keys:U.array(),names:Ze.array()}),lz=i.z.object({}),hz="/channel/create",fz="/channel/delete",dz="/channel/rename";let pu=class{client;cache;constructor(e,r){this.client=e,this.cache=r}async create(e){const{channels:r}=await w(this.client,hz,{channels:e.map(n=>({...n,dataType:n.dataType}))},iz,az);return this.cache.set(r),r}async delete(e){const r=U.array().parse(e.keys??[]);await w(this.client,fz,e,oz,cz),r.length>0&&this.cache.delete(r),e.names!=null&&this.cache.delete(e.names)}async rename(e,r){await w(this.client,dz,{keys:e,names:r},uz,lz),this.cache.rename(e,r)}};const pz=Object.freeze(Object.defineProperty({__proto__:null,CALCULATION_STATUS_CHANNEL_NAME:ez,CacheRetriever:Hs,Channel:Br,Client:hu,ClusterRetriever:fr,DELETE_CHANNEL_NAME:QT,DebouncedBatchRetriever:uu,OPERATION_TYPES:su,SET_CHANNEL_NAME:XT,Writer:pu,analyzeParams:ge,isCalculated:Et,isLegacyCalculated:sz,keyZ:U,nameZ:Ze,newZ:ou,ontologyID:fu,operationType:iu,operationZ:Ys,paramsZ:at,payloadZ:Zt,resolveLegacyCalculatedIndex:du,retrieveRequired:lu,statusZ:au},Symbol.toStringTag,{value:"Module"})),We=i.z.uuid(),dr=i.z.object({key:We,username:i.z.string().min(1,"Username is required"),firstName:i.z.string().default(""),lastName:i.z.string().default(""),rootUser:i.z.boolean().default(!0)}),yu=dr.partial({key:!0,firstName:!0,lastName:!0}).omit({rootUser:!0}).extend({password:i.z.string().min(1)}),yz=i.z.object({keys:We.array().optional(),usernames:i.z.string().array().optional()}),mz=i.z.object({key:We}).transform(({key:t})=>({keys:[t]})),gz=i.z.object({username:i.z.string()}).transform(({username:t})=>({usernames:[t]})),wz=i.z.object({usernames:i.z.string().array()}).transform(({usernames:t})=>({usernames:t})),bz=i.z.union([mz,gz,wz,yz]),vz=i.z.object({users:T.nullableZ(dr)}),Tz=i.z.object({users:yu.array()}),zz=i.z.object({users:dr.array()}),Ez=i.z.object({key:We,username:i.z.string().min(1)}),Nz=i.z.object({}),Oz=i.z.object({key:We,firstName:i.z.string().optional(),lastName:i.z.string().optional()}),$z=i.z.object({}),Sz=i.z.object({keys:We.array()}),Iz=i.z.object({}),Az="/user/retrieve",kz="/user/create",xz="/user/change-username",Zz="/user/rename",Cz="/user/delete";let mu=class{client;constructor(e){this.client=e}async create(e){const r=Array.isArray(e),n=await w(this.client,kz,{users:T.toArray(e)},Tz,zz);return r?n.users:n.users[0]}async changeUsername(e,r){await w(this.client,xz,{key:e,username:r},Ez,Nz)}async retrieve(e){const r="key"in e||"username"in e,n=await w(this.client,Az,e,bz,vz);if(!r)return n.users;if(n.users.length===0){const s="key"in e?`key ${e.key}`:`username ${e.username}`;throw new Gt(`No user with ${s} found`)}if(n.users.length>1){const s="key"in e?`key ${e.key}`:`username ${e.username}`;throw new Kt(`Multiple users found with ${s}`)}return n.users[0]}async rename(e,r,n){await w(this.client,Zz,{key:e,firstName:r,lastName:n},Oz,$z)}async delete(e){await w(this.client,Cz,{keys:T.toArray(e)},Sz,Iz)}};const Rz=t=>({type:"user",key:t}),_z=Object.freeze(Object.defineProperty({__proto__:null,Client:mu,keyZ:We,newZ:yu,ontologyID:Rz,userZ:dr},Symbol.toStringTag,{value:"Module"})),jz=i.z.object({username:i.z.string(),password:i.z.string()}),Mz=i.z.object({token:i.z.string(),user:dr}),Qi="/auth/login",Dz=3,Pz="/auth/change-password",Uz=i.z.object({username:i.z.string(),password:i.z.string(),newPassword:i.z.string().min(1)}),Lz=i.z.object({}),Bz=[ss,is];let qz=class{token;client;credentials;authenticating;authenticated;user;retryCount;constructor(e,r){this.client=e,this.authenticated=!1,this.credentials=r,this.retryCount=0}async changePassword(e){if(!this.authenticated)throw new Error("Not authenticated");await w(this.client,Pz,{username:this.credentials.username,password:this.credentials.password,newPassword:e},Uz,Lz),this.credentials.password=e}middleware(){const e=async(r,n)=>{if(!this.authenticated&&!r.target.endsWith(Qi)){this.authenticating??=new Promise((c,l)=>{this.client.send(Qi,this.credentials,jz,Mz).then(([u,h])=>{if(h!=null)return c(h);this.token=u?.token,this.user=u?.user,this.authenticated=!0,c(null)}).catch(l)});const o=await this.authenticating;if(o!=null)return[r,o]}r.params.Authorization=`Bearer ${this.token}`;const[s,a]=await n(r);return Bz.some(o=>o.matches(a))&&this.retryCount<Dz?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,e(r,n)):(this.retryCount=0,[s,a])};return e}};const gu=i.z.enum(["disconnected","connecting","connected","failed"]),wu=i.z.object({status:gu,error:i.z.instanceof(Error).optional(),message:i.z.string().optional(),clusterKey:i.z.string(),clientVersion:i.z.string(),clientServerCompatible:i.z.boolean(),nodeVersion:i.z.string().optional()}),Fz=i.z.object({clusterKey:i.z.string(),nodeVersion:i.z.string().optional()}),ea={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.47.0"},ta=(t,e,r)=>{const n=r?"Core":"client";return`Synnax Core version ${t!=null?`${t} `:""}is too ${r?"old":"new"} for client version ${e}.
41
41
  This may cause compatibility issues. We recommend updating the ${n}. For more information, see
42
- https://docs.synnaxlabs.com/reference/typescript-client/troubleshooting#old-${n}-version`};class Qt{static ENDPOINT="/connectivity/check";static DEFAULT=Qi;_state;pollFrequency=I.seconds(30);client;name;interval;clientVersion;onChangeHandlers=[];static connectionStateZ=hu;versionWarned=!1;constructor(e,r=I.seconds(30),n,s){this._state={...Qi},this.client=e,this.pollFrequency=r,this.clientVersion=n,this.name=s,this.check(),this.startChecking()}stopChecking(){this.interval!=null&&clearInterval(this.interval)}async check(){const e=this._state.status;try{const[r,n]=await this.client.send(Qt.ENDPOINT,{},i.z.object({}),Iz);if(n!=null)throw n;const s=r.nodeVersion,a=this.clientVersion,o=this.versionWarned;s==null?(this._state.clientServerCompatible=!1,o||(console.warn(ea(null,a,!0)),this.versionWarned=!0)):$i.versionsEqual(a,s,{checkMajor:!0,checkMinor:!0,checkPatch:!1})?this._state.clientServerCompatible=!0:(this._state.clientServerCompatible=!1,o||(console.warn(ea(s,a,$i.semVerNewer(a,s))),this.versionWarned=!0)),this._state.status="connected",this._state.message=`Connected to ${this.name??"cluster"}`,this._state.clusterKey=r.clusterKey,this._state.nodeVersion=r.nodeVersion,this._state.clientVersion=this.clientVersion}catch(r){this._state.status="failed",this._state.error=r,this._state.message=this.state.error?.message}return this.onChangeHandlers.length>0&&e!==this._state.status&&this.onChangeHandlers.forEach(r=>r(this.state)),this.state}get state(){return{...this._state}}onChange(e){this.onChangeHandlers.push(e)}startChecking(){this.interval=setInterval(()=>{this.check()},this.pollFrequency.milliseconds)}}const kz=Object.freeze(Object.defineProperty({__proto__:null,Checker:Qt,stateZ:hu,statusZ:lu},Symbol.toStringTag,{value:"Module"})),Az=i.z.object({keys:D.array().optional(),bounds:P.z,names:xe.array().optional()}),xz=i.z.object({}),Zz="/frame/delete";class Cz{client;constructor(e){this.client=e}async delete(e){await w(this.client,Zz,e,Az,xz)}}const ta=t=>{const e=T.toArray(t);return e.length===0?null:typeof e[0]=="number"||!isNaN(parseInt(e[0]))?"key":"name"},ra=(t,e)=>{const r=T.toArray(t);if(r.length===e.length)return;const n=ta(t);throw ta===null?new Y("[Frame] - channel keys or names must be provided when constructing a frame."):new Y(`[Frame] - ${n}s and series must be the same length.
43
- Got ${r.length} ${n}s and ${e.length} series.`)};class W{columns=[];series=[];constructor(e=[],r=[]){if(e instanceof W){this.columns=e.columns,this.series=e.series;return}if(e instanceof Map){e.forEach((s,a)=>this.push(a,...T.toArray(s)));return}if(typeof e=="object"&&!Array.isArray(e)){if("keys"in e&&"series"in e){const s=e;s.series??=[],s.keys??=[];const a=s.series.map(o=>fu(o));ra(s.keys,a),s.keys.forEach((o,c)=>this.push(o,a[c]))}else Object.entries(e).forEach(([s,a])=>{const o=parseInt(s);if(!isNaN(o))return this.push(o,...T.toArray(a));this.push(s,...T.toArray(a))});return}if(Array.isArray(e)||["string","number"].includes(typeof e)){const s=T.toArray(r),a=T.toArray(e);ra(a,s),s.forEach((o,c)=>this.push(a[c],o));return}throw new Y(`[Frame] - invalid frame construction parameters. data parameter ust be a frame
42
+ https://docs.synnaxlabs.com/reference/typescript-client/troubleshooting#old-${n}-version`};class Qt{static ENDPOINT="/connectivity/check";static DEFAULT=ea;_state;pollFrequency=I.seconds(30);client;name;interval;clientVersion;onChangeHandlers=[];static connectionStateZ=wu;versionWarned=!1;constructor(e,r=I.seconds(30),n,s){this._state={...ea},this.client=e,this.pollFrequency=r,this.clientVersion=n,this.name=s,this.check(),this.startChecking()}stopChecking(){this.interval!=null&&clearInterval(this.interval)}async check(){const e=this._state.status;try{const[r,n]=await this.client.send(Qt.ENDPOINT,{},i.z.object({}),Fz);if(n!=null)throw n;const s=r.nodeVersion,a=this.clientVersion,o=this.versionWarned;s==null?(this._state.clientServerCompatible=!1,o||(console.warn(ta(null,a,!0)),this.versionWarned=!0)):Si.versionsEqual(a,s,{checkMajor:!0,checkMinor:!0,checkPatch:!1})?this._state.clientServerCompatible=!0:(this._state.clientServerCompatible=!1,o||(console.warn(ta(s,a,Si.semVerNewer(a,s))),this.versionWarned=!0)),this._state.status="connected",this._state.message=`Connected to ${this.name??"cluster"}`,this._state.clusterKey=r.clusterKey,this._state.nodeVersion=r.nodeVersion,this._state.clientVersion=this.clientVersion}catch(r){this._state.status="failed",this._state.error=r,this._state.message=this.state.error?.message}return this.onChangeHandlers.length>0&&e!==this._state.status&&this.onChangeHandlers.forEach(r=>r(this.state)),this.state}get state(){return{...this._state}}onChange(e){this.onChangeHandlers.push(e)}startChecking(){this.interval=setInterval(()=>{this.check()},this.pollFrequency.milliseconds)}}const Vz=Object.freeze(Object.defineProperty({__proto__:null,Checker:Qt,stateZ:wu,statusZ:gu},Symbol.toStringTag,{value:"Module"})),Yz=i.z.object({keys:U.array().optional(),bounds:D.z,names:Ze.array().optional()}),Hz=i.z.object({});class Wz{client;constructor(e){this.client=e}async delete(e){await w(this.client,"/frame/delete",e,Yz,Hz)}}const ra=t=>{const e=T.toArray(t);return e.length===0?null:typeof e[0]=="number"||!isNaN(parseInt(e[0]))?"key":"name"},na=(t,e)=>{const r=T.toArray(t);if(r.length===e.length)return;const n=ra(t);throw ra===null?new Y("[Frame] - channel keys or names must be provided when constructing a frame."):new Y(`[Frame] - ${n}s and series must be the same length.
43
+ Got ${r.length} ${n}s and ${e.length} series.`)};class H{columns=[];series=[];constructor(e=[],r=[]){if(e instanceof H){this.columns=e.columns,this.series=e.series;return}if(e instanceof Map){e.forEach((s,a)=>this.push(a,...T.toArray(s)));return}if(typeof e=="object"&&!Array.isArray(e)){if("keys"in e&&"series"in e){const s=e;s.series??=[],s.keys??=[];const a=s.series.map(o=>bu(o));na(s.keys,a),s.keys.forEach((o,c)=>this.push(o,a[c]))}else Object.entries(e).forEach(([s,a])=>{const o=parseInt(s);if(!isNaN(o))return this.push(o,...T.toArray(a));this.push(s,...T.toArray(a))});return}if(Array.isArray(e)||["string","number"].includes(typeof e)){const s=T.toArray(r),a=T.toArray(e);na(a,s),s.forEach((o,c)=>this.push(a[c],o));return}throw new Y(`[Frame] - invalid frame construction parameters. data parameter ust be a frame
44
44
  payload, a list of lazy series, a lazy array, a map, or a record keyed by channel
45
- name. keys parameter must be a set of channel keys or channel names.`)}get colType(){return this.columns.length===0?null:typeof this.columns[0]=="string"?"name":"key"}get keys(){if(this.colType==="name")throw new gt("colType is not key");return this.columns??[]}get uniqueKeys(){return wi.unique(this.keys)}get names(){if(this.colType==="key")throw new gt("colType is not name");return this.columns??[]}get uniqueNames(){return wi.unique(this.names)}get uniqueColumns(){return this.colType==="key"?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>du(e)),keys:[...this.keys]}}get isVertical(){return this.uniqueColumns.length===this.columns.length}get isHorizontal(){return this.uniqueColumns.length===1}get isSquare(){return this.isHorizontal&&this.isVertical}get isWeaklyAligned(){if(this.columns.length<=1)return!0;const e=this.timeRanges;return e.every(r=>r.equals(e[0]))}timeRange(e){if(e==null){if(this.columns.length===0)return P.ZERO;const n=p.min(...this.series.map(a=>a.timeRange.start)),s=p.max(...this.series.map(a=>a.timeRange.end));return new P(n,s)}const r=this.get(e);return r==null?P.ZERO:r.timeRange}latest(){return this.at(-1)}get timeRanges(){return this.uniqueColumns.map(e=>this.timeRange(e))}get(e){return Array.isArray(e)?this.filter(r=>e.includes(r)):new Do(this.series.filter((r,n)=>this.columns[n]===e))}push(e,...r){if(e instanceof W){if(this.colType!==null&&e.colType!==this.colType)throw new Y("keyVariant must match");this.series.push(...e.series),this.columns.push(...e.columns)}else{if(this.series.push(...r),typeof e=="string"&&this.colType==="key")throw new Y("keyVariant must match");if(typeof e!="string"&&this.colType==="name")throw new Y("keyVariant must match");this.columns.push(...Array.from({length:r.length},()=>e))}}concat(e){return new W([...this.columns,...e.columns],[...this.series,...e.series])}has(e){return typeof e=="string"&&this.colType==="key"||typeof e=="number"&&this.colType==="name"?!1:this.columns.includes(e)}map(e){const r=new W;return this.forEach((n,s,a)=>r.push(...e(n,s,a))),r}forEach(e){this.columns.forEach((r,n)=>{const s=this.series[n];e(r,s,n)})}at(e,r=!1){const n={};return this.uniqueColumns.forEach(s=>{n[s]=this.get(s).at(e,r)}),n}filter(e){const r=new W;return this.columns.forEach((n,s)=>{const a=this.series[s];e(n,a,s)&&r.push(n,a)}),r}get byteLength(){return new vt(this.series.reduce((e,r)=>e.add(r.byteLength),vt.ZERO))}get digest(){const e={};return this.keys.forEach((r,n)=>{const s=this.series[n].digest;r in e?e[r].push(s):e[r]=[s]}),e}get length(){return this.series.reduce((e,r)=>e+r.length,0)}toString(){let e=`Frame{
45
+ name. keys parameter must be a set of channel keys or channel names.`)}get colType(){return this.columns.length===0?null:typeof this.columns[0]=="string"?"name":"key"}get keys(){if(this.colType==="name")throw new wt("colType is not key");return this.columns??[]}get uniqueKeys(){return bi.unique(this.keys)}get names(){if(this.colType==="key")throw new wt("colType is not name");return this.columns??[]}get uniqueNames(){return bi.unique(this.names)}get uniqueColumns(){return this.colType==="key"?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>vu(e)),keys:[...this.keys]}}get isVertical(){return this.uniqueColumns.length===this.columns.length}get isHorizontal(){return this.uniqueColumns.length===1}get isSquare(){return this.isHorizontal&&this.isVertical}get isWeaklyAligned(){if(this.columns.length<=1)return!0;const e=this.timeRanges;return e.every(r=>r.equals(e[0]))}timeRange(e){if(e==null){if(this.columns.length===0)return D.ZERO;const n=p.min(...this.series.map(a=>a.timeRange.start)),s=p.max(...this.series.map(a=>a.timeRange.end));return new D(n,s)}const r=this.get(e);return r==null?D.ZERO:r.timeRange}latest(){return this.at(-1)}get timeRanges(){return this.uniqueColumns.map(e=>this.timeRange(e))}get(e){return Array.isArray(e)?this.filter(r=>e.includes(r)):new Po(this.series.filter((r,n)=>this.columns[n]===e))}push(e,...r){if(e instanceof H){if(this.colType!==null&&e.colType!==this.colType)throw new Y("keyVariant must match");this.series.push(...e.series),this.columns.push(...e.columns)}else{if(this.series.push(...r),typeof e=="string"&&this.colType==="key")throw new Y("keyVariant must match");if(typeof e!="string"&&this.colType==="name")throw new Y("keyVariant must match");this.columns.push(...Array.from({length:r.length},()=>e))}}concat(e){return new H([...this.columns,...e.columns],[...this.series,...e.series])}has(e){return typeof e=="string"&&this.colType==="key"||typeof e=="number"&&this.colType==="name"?!1:this.columns.includes(e)}map(e){const r=new H;return this.forEach((n,s,a)=>r.push(...e(n,s,a))),r}forEach(e){this.columns.forEach((r,n)=>{const s=this.series[n];e(r,s,n)})}at(e,r=!1){const n={};return this.uniqueColumns.forEach(s=>{n[s]=this.get(s).at(e,r)}),n}filter(e){const r=new H;return this.columns.forEach((n,s)=>{const a=this.series[s];e(n,a,s)&&r.push(n,a)}),r}get byteLength(){return new Tt(this.series.reduce((e,r)=>e.add(r.byteLength),Tt.ZERO))}get digest(){const e={};return this.keys.forEach((r,n)=>{const s=this.series[n].digest;r in e?e[r].push(s):e[r]=[s]}),e}get length(){return this.series.reduce((e,r)=>e+r.length,0)}toString(){let e=`Frame{
46
46
  `;return this.uniqueColumns.forEach(r=>{e+=` ${r}: ${this.get(r).series.map(n=>n.toString()).join(",")}
47
- `}),e+="}",e}}const an=i.z.object({keys:i.z.union([i.z.null().transform(()=>[]),i.z.number().array().optional().default([])]),series:i.z.union([i.z.null().transform(()=>[]),Ae.crudeZ.array().optional().default([])])}),fu=t=>{const{dataType:e,data:r,timeRange:n,alignment:s}=t;return new Ae({data:r,dataType:e,timeRange:n,glBufferUsage:"static",alignment:s})},du=t=>({timeRange:t.timeRange,dataType:t.dataType,data:new Uint8Array(t.data.buffer),alignment:t.alignment});var zt=(t=>(t[t.Open=0]="Open",t[t.Write=1]="Write",t[t.Commit=2]="Commit",t[t.SetAuthority=3]="SetAuthority",t))(zt||{}),er=(t=>(t[t.PersistStream=1]="PersistStream",t[t.Persist=2]="Persist",t[t.Stream=3]="Stream",t))(er||{});const Rz=new I(-1);class fs extends Se.sub("writer_closed"){constructor(){super("WriterClosed")}}const _z=i.z.enum(er).or(i.z.enum(["persist","stream","persistStream"]).transform(t=>{switch(t){case"persist":return 2;case"stream":return 3;case"persistStream":return 1}})),pu=i.z.object({start:p.z.optional(),controlSubject:fe.subjectZ.optional(),authorities:i.z.union([fe.authorityZ.transform(t=>[t]),fe.authorityZ.array()]).default([fe.ABSOLUTE_AUTHORITY]),mode:_z.default(1),errOnUnauthorized:i.z.boolean().default(!1),enableAutoCommit:i.z.boolean().default(!1),autoIndexPersistInterval:I.z.default(I.SECOND),useHighPerformanceCodec:i.z.boolean().default(!0)}),jz=pu.extend({keys:D.array().optional()}),na=pu.extend({channels:it}),yu=na.or(it.transform(t=>na.parse({channels:t,start:p.now()}))),Mz=i.z.object({command:i.z.enum(zt),config:jz.optional(),frame:an.optional(),buffer:i.z.instanceof(Uint8Array).optional()}),Dz=i.z.object({command:i.z.enum(zt),end:p.z,err:Ze.payloadZ.optional()}),Pz=i.z.tuple([i.z.union([i.z.record(D.or(xe),fe.authorityZ),D.or(xe),fe.authorityZ]),fe.authorityZ.optional()]).transform(([t,e])=>{if(fe.authorityZ.safeParse(t).success)return{keys:[],authorities:[t]};if(D.or(xe).safeParse(t).success){if(e==null)throw new Error("authority is required when setting authority for a single channel");return{keys:[t],authorities:[e]}}const r=t;return{keys:Object.keys(r),authorities:Object.values(r)}});let mu=class ds{static ENDPOINT="/frame/write";stream;adapter;closeErr=null;constructor(e,r){this.stream=e,this.adapter=r}static async _open(e,r,n){const s=yu.parse(n),a=await Hs.open(e,s.channels);s.useHighPerformanceCodec&&(r=r.withCodec(new Vz(a.codec)));const o=await r.stream(ds.ENDPOINT,Mz,Dz),c=new ds(o,a);return await c.execute({command:0,config:{...s,keys:a.keys}}),c}async write(e,r){if(this.closeErr!=null)throw this.closeErr;if(this.stream.received())return await this.close();const n=await this.adapter.adapt(e,r);this.stream.send({command:1,frame:n.toPayload()})}async setAuthority(e,r){if(this.closeErr!=null)throw this.closeErr;const n=Pz.parse([e,r]),s={keys:await this.adapter.adaptParams(n.keys),authorities:n.authorities};await this.execute({command:3,config:s})}async commit(){if(this.closeErr!=null)throw this.closeErr;return this.stream.received()?(await this.closeInternal(null),p.ZERO):(await this.execute({command:2})).end}async close(){await this.closeInternal(null)}async closeInternal(e){if(this.closeErr!=null)throw this.closeErr;for(this.closeErr=e,this.stream.closeSend();;){if(this.closeErr!=null){if(fs.matches(this.closeErr))return null;throw this.closeErr}const[r,n]=await this.stream.receive();n!=null?this.closeErr=we.matches(n)?new fs:n:this.closeErr=Ze.decode(r?.err)}}async execute(e){const r=this.stream.send(e);for(r!=null&&await this.closeInternal(r);;){const[n,s]=await this.stream.receive();s!=null&&await this.closeInternal(s);const a=Ze.decode(n?.err);if(a!=null&&await this.closeInternal(a),n?.command==e.command)return n}}};const sa=t=>t.data.byteLength/t.dataType.density.valueOf(),Uz=t=>{const{keys:e,series:r}=t;e.forEach((n,s)=>{r[s].key=n}),r.sort((n,s)=>n.key-s.key),e.sort((n,s)=>n-s),r.forEach(n=>delete n.key)},ia=5,aa=4,oa=3,ca=2,ua=1,la=0,Te=R.TIMESTAMP.density.valueOf(),je=8,Me=4,kn=4,An=4,Lz=1;class gu{contentType="application/sy-framer";states=new Map;currState;seqNum=0;constructor(e=[],r=[]){(e.length>0||r.length>0)&&this.update(e,r)}update(e,r){this.seqNum++;const n={keys:e,keyDataTypes:new Map,hasVariableDataTypes:!1};e.forEach((s,a)=>{const o=r[a];n.keyDataTypes.set(s,o),o.isVariable&&(n.hasVariableDataTypes=!0)}),n.keys.sort(),this.states.set(this.seqNum,n),this.currState=n}throwIfNotUpdated(e){if(this.seqNum<1)throw new Y(`
47
+ `}),e+="}",e}}const on=i.z.object({keys:i.z.union([i.z.null().transform(()=>[]),i.z.number().array().optional().default([])]),series:i.z.union([i.z.null().transform(()=>[]),xe.crudeZ.array().optional().default([])])}),bu=t=>{const{dataType:e,data:r,timeRange:n,alignment:s}=t;return new xe({data:r,dataType:e,timeRange:n,glBufferUsage:"static",alignment:s})},vu=t=>({timeRange:t.timeRange,dataType:t.dataType,data:new Uint8Array(t.data.buffer),alignment:t.alignment});var Se=(t=>(t[t.Open=0]="Open",t[t.Write=1]="Write",t[t.Commit=2]="Commit",t[t.SetAuthority=3]="SetAuthority",t))(Se||{});const sa=t=>t.data.byteLength/t.dataType.density.valueOf(),Gz=t=>{const{keys:e,series:r}=t;e.forEach((n,s)=>{r[s].key=n}),r.sort((n,s)=>n.key-s.key),e.sort((n,s)=>n-s),r.forEach(n=>delete n.key)},ia=5,aa=4,oa=3,ca=2,ua=1,la=0,Te=R.TIMESTAMP.density.valueOf(),Me=8,De=4,An=4,kn=4,Kz=1;class Tu{contentType="application/sy-framer";states=new Map;currState;seqNum=0;constructor(e=[],r=[]){(e.length>0||r.length>0)&&this.update(e,r)}update(e,r){this.seqNum++;const n={keys:e,keyDataTypes:new Map,hasVariableDataTypes:!1};e.forEach((s,a)=>{const o=r[a];n.keyDataTypes.set(s,o),o.isVariable&&(n.hasVariableDataTypes=!0)}),n.keys.sort(),this.states.set(this.seqNum,n),this.currState=n}throwIfNotUpdated(e){if(this.seqNum<1)throw new Y(`
48
48
  The codec has not been updated with a list of channels and data types.
49
49
  Please call the update method before calling ${e}.
50
- `)}encode(e,r=0){this.throwIfNotUpdated("encode");let n=e;e!=null&&typeof e=="object"&&"toPayload"in e&&(n=e.toPayload()),Uz(n);let s=-1,a,o,c,l=r+Lz+An,u=!this.currState?.hasVariableDataTypes,h=!0,d=!0,f=!0,v=!0,S=!0;n.keys.length!==this.currState?.keys.length&&(f=!1,l+=n.keys.length*kn),n.series.forEach((k,G)=>{const V=sa(k),ye=n.keys[G],Je=this.currState?.keyDataTypes.get(ye);if(Je==null)throw new Y(`Channel ${ye} was not provided in the list of channels when opening the writer`);if(!Je.equals(k.dataType))throw new Y(`Series data type of ${k.dataType.toString()} does not match the data type of ${Je.toString()} for channel ${ye}`);if(l+=k.data.byteLength,s===-1){s=V,a=k.timeRange?.start,o=k.timeRange?.end,c=BigInt(k.alignment??0n);return}s!==V&&(u=!1),(a?.valueOf()!==k.timeRange?.start.valueOf()||o?.valueOf()!==k.timeRange?.end.valueOf())&&(h=!1),c!==BigInt(k.alignment??0)&&(v=!1)}),d=h&&a==null&&o==null,S=v&&(c===void 0||c===0n),u?l+=Me:l+=n.keys.length*Me,d||(h?l+=Te*2:l+=n.keys.length*Te*2),S||(v?l+=je:l+=n.keys.length*je);const Z=new Uint8Array(l),b=new DataView(Z.buffer);let z=r;return Z[z]=Number(S)<<ia|Number(v)<<aa|Number(u)<<oa|Number(h)<<ca|Number(d)<<ua|Number(f)<<la,z++,b.setUint32(z,this.seqNum,!0),z+=An,u&&(b.setUint32(z,s,!0),z+=Me),h&&!d&&(b.setBigUint64(z,a?.valueOf()??0n,!0),b.setBigUint64(z,o?.valueOf()??0n,!0),z+=Te*2),v&&!S&&(b.setBigUint64(z,c??0n,!0),z+=je),n.series.forEach((k,G)=>{if(f||(b.setUint32(z,n.keys[G],!0),z+=kn),!u){let V=k.data.byteLength;k.dataType.isVariable||(V=sa(k)),b.setUint32(z,V,!0),z+=Me}Z.set(new Uint8Array(k.data),z),z+=k.data.byteLength,!h&&!d&&(b.setBigUint64(z,k.timeRange?.start.valueOf()??0n,!0),b.setBigUint64(z,k.timeRange?.end.valueOf()??0n,!0),z+=Te*2),!v&&!S&&(b.setBigUint64(z,k.alignment??0n,!0),z+=je)}),Z}decode(e,r=0){this.throwIfNotUpdated("decode");const n=e instanceof Uint8Array?e:new Uint8Array(e),s={keys:[],series:[]};let a=r,o=0,c=0,l,u,h;const d=new DataView(n.buffer,n.byteOffset,n.byteLength),f=!!(n[a]>>ia&1),v=!!(n[a]>>aa&1),S=!!(n[a]>>oa&1),Z=!!(n[a]>>ca&1),b=!!(n[a]>>ua&1),z=!!(n[a]>>la&1);a++;const k=d.getUint32(a,!0);a+=An;const G=this.states.get(k);if(G==null)return s;if(S){if(a+Me>d.byteLength)return s;o=d.getUint32(a,!0),a+=Me}if(Z&&!b){if(a+Te>d.byteLength)return s;l=new p(d.getBigUint64(a,!0)),a+=Te,u=new p(d.getBigUint64(a,!0)),a+=Te}if(v&&!f){if(a+je>d.byteLength)return s;h=d.getBigUint64(a,!0),a+=je}return z&&(s.keys=[...G.keys]),G.keys.forEach((V,ye)=>{if(!z){if(a>=d.byteLength||d.getUint32(a,!0)!==V)return;a+=kn,s.keys.push(V)}const Je=G.keyDataTypes.get(V);if(c=0,S)c=o;else{if(a+Me>d.byteLength)return;c=d.getUint32(a,!0),a+=Me}let yr=c;if(Je.isVariable||(yr*=Je.density.valueOf()),a+yr>d.byteLength){s.keys.splice(ye,1);return}const Ke={dataType:Je,data:n.slice(a,a+yr).buffer};if(a+=yr,!Z&&!b){if(a+Te*2>d.byteLength)return;const ii=d.getBigUint64(a,!0);a+=Te;const Cl=d.getBigUint64(a,!0);a+=Te,Ke.timeRange=new P({start:ii,end:Cl})}else b?Ke.timeRange=new P({start:0n,end:0n}):Ke.timeRange=new P({start:l?.valueOf()??0n,end:u?.valueOf()??0n});if(!v&&!f){if(a+je>d.byteLength)return;h=d.getBigUint64(a,!0),a+=je,Ke.alignment=h}else f?Ke.alignment=0n:Ke.alignment=h;s.series.push(Ke)}),s}}const Ws=254,Bz=new Uint8Array([Ws]),qz=255,Fz=new Uint8Array([qz]),wu="application/sy-framer";class Vz{contentType=wu;base;lowPerfCodec;constructor(e){this.base=e,this.lowPerfCodec=st.JSON_CODEC}encode(e){const r=e;if(r.type=="close"||r.payload?.command!=zt.Write){const s=this.lowPerfCodec.encode(r),a=new Uint8Array({length:s.byteLength+1});return a.set(Bz,0),a.set(new Uint8Array(s),1),a}const n=this.base.encode(r.payload?.frame,1);return n.set(Fz,0),n}decode(e,r){if(new DataView(e instanceof Uint8Array?e.buffer:e).getUint8(0)===Ws)return this.lowPerfCodec.decode(e.slice(1),r);const a={type:"data"},o=this.base.decode(e,1);return a.payload={command:zt.Write,frame:o},a}}class Yz{contentType=wu;base;lowPerfCodec;constructor(e){this.base=e,this.lowPerfCodec=st.JSON_CODEC}encode(e){return this.lowPerfCodec.encode(e)}decode(e,r){return new DataView(e instanceof Uint8Array?e.buffer:e).getUint8(0)===Ws?this.lowPerfCodec.decode(e.slice(1),r):{type:"data",payload:{frame:this.base.decode(e,1)}}}}class on{adapter;retriever;keys;codec;constructor(e){this.retriever=e,this.adapter=null,this.keys=[],this.codec=new gu}static async open(e,r){const n=new on(e);return await n.update(r),n}async update(e){const{variant:r,normalized:n}=ge(e),s=await this.retriever.retrieve(n),a=s.map(c=>c.key);if(bi.uniqueUnorderedPrimitiveArrays(this.keys,a)===bi.EQUAL)return!1;if(this.codec.update(a,s.map(c=>c.dataType)),r==="keys")return this.adapter=null,this.keys=n,!0;const o=new Map;return this.adapter=o,n.forEach(c=>{const l=s.find(u=>u.name===c);if(l==null)throw new Error(`Channel ${c} not found`);o.set(l.key,l.name)}),this.keys=Array.from(this.adapter.keys()),!0}adapt(e){if(this.adapter==null)return e;const r=this.adapter;return e.map((n,s)=>{if(typeof n=="number"){const a=r.get(n);if(a==null)throw new Error(`Channel ${n} not found`);return[a,s]}return[n,s]})}}class Hs{adapter;retriever;keys;codec;constructor(e){this.retriever=e,this.adapter=null,this.keys=[],this.codec=new gu}static async open(e,r){const n=new Hs(e);return await n.update(r),n}async adaptParams(e){const r=it.parse(e);return await Promise.all(r.map(async s=>await this.adaptToKey(s)))}async update(e){const r=await nu(this.retriever,e),n=r.map(u=>u.key),s=new Set(this.keys),a=new Set(n),o=!a.isSubsetOf(s),c=!s.isSubsetOf(a);return o||c?(this.adapter=new Map(r.map(u=>[u.name,u.key])),this.keys=n,this.codec.update(this.keys,r.map(u=>u.dataType)),!0):!1}async fetchChannel(e){const r=await this.retriever.retrieve(e);if(r.length===0)throw new Error(`Channel ${JSON.stringify(e)} not found`);return r[0]}async adaptToKey(e){return typeof e=="number"?e:(await this.fetchChannel(e)).key}encode(e){return this.codec.encode(e.toPayload())}async adapt(e,r){if(typeof e=="string"||typeof e=="number"){if(r==null)throw new Y(`
50
+ `)}encode(e,r=0){this.throwIfNotUpdated("encode");let n=e;e!=null&&typeof e=="object"&&"toPayload"in e&&(n=e.toPayload()),Gz(n);let s=-1,a,o,c,l=r+Kz+kn,u=!this.currState?.hasVariableDataTypes,h=!0,d=!0,f=!0,v=!0,S=!0;n.keys.length!==this.currState?.keys.length&&(f=!1,l+=n.keys.length*An),n.series.forEach((A,G)=>{const V=sa(A),ye=n.keys[G],Je=this.currState?.keyDataTypes.get(ye);if(Je==null)throw new Y(`Channel ${ye} was not provided in the list of channels when opening the writer`);if(!Je.equals(A.dataType))throw new Y(`Series data type of ${A.dataType.toString()} does not match the data type of ${Je.toString()} for channel ${ye}`);if(l+=A.data.byteLength,s===-1){s=V,a=A.timeRange?.start,o=A.timeRange?.end,c=BigInt(A.alignment??0n);return}s!==V&&(u=!1),(a?.valueOf()!==A.timeRange?.start.valueOf()||o?.valueOf()!==A.timeRange?.end.valueOf())&&(h=!1),c!==BigInt(A.alignment??0)&&(v=!1)}),d=h&&a==null&&o==null,S=v&&(c===void 0||c===0n),u?l+=De:l+=n.keys.length*De,d||(h?l+=Te*2:l+=n.keys.length*Te*2),S||(v?l+=Me:l+=n.keys.length*Me);const Z=new Uint8Array(l),b=new DataView(Z.buffer);let z=r;return Z[z]=Number(S)<<ia|Number(v)<<aa|Number(u)<<oa|Number(h)<<ca|Number(d)<<ua|Number(f)<<la,z++,b.setUint32(z,this.seqNum,!0),z+=kn,u&&(b.setUint32(z,s,!0),z+=De),h&&!d&&(b.setBigUint64(z,a?.valueOf()??0n,!0),b.setBigUint64(z,o?.valueOf()??0n,!0),z+=Te*2),v&&!S&&(b.setBigUint64(z,c??0n,!0),z+=Me),n.series.forEach((A,G)=>{if(f||(b.setUint32(z,n.keys[G],!0),z+=An),!u){let V=A.data.byteLength;A.dataType.isVariable||(V=sa(A)),b.setUint32(z,V,!0),z+=De}Z.set(new Uint8Array(A.data),z),z+=A.data.byteLength,!h&&!d&&(b.setBigUint64(z,A.timeRange?.start.valueOf()??0n,!0),b.setBigUint64(z,A.timeRange?.end.valueOf()??0n,!0),z+=Te*2),!v&&!S&&(b.setBigUint64(z,A.alignment??0n,!0),z+=Me)}),Z}decode(e,r=0){this.throwIfNotUpdated("decode");const n=e instanceof Uint8Array?e:new Uint8Array(e),s={keys:[],series:[]};let a=r,o=0,c=0,l,u,h;const d=new DataView(n.buffer,n.byteOffset,n.byteLength),f=!!(n[a]>>ia&1),v=!!(n[a]>>aa&1),S=!!(n[a]>>oa&1),Z=!!(n[a]>>ca&1),b=!!(n[a]>>ua&1),z=!!(n[a]>>la&1);a++;const A=d.getUint32(a,!0);a+=kn;const G=this.states.get(A);if(G==null)return s;if(S){if(a+De>d.byteLength)return s;o=d.getUint32(a,!0),a+=De}if(Z&&!b){if(a+Te>d.byteLength)return s;l=new p(d.getBigUint64(a,!0)),a+=Te,u=new p(d.getBigUint64(a,!0)),a+=Te}if(v&&!f){if(a+Me>d.byteLength)return s;h=d.getBigUint64(a,!0),a+=Me}return z&&(s.keys=[...G.keys]),G.keys.forEach((V,ye)=>{if(!z){if(a>=d.byteLength||d.getUint32(a,!0)!==V)return;a+=An,s.keys.push(V)}const Je=G.keyDataTypes.get(V);if(c=0,S)c=o;else{if(a+De>d.byteLength)return;c=d.getUint32(a,!0),a+=De}let gr=c;if(Je.isVariable||(gr*=Je.density.valueOf()),a+gr>d.byteLength){s.keys.splice(ye,1);return}const Xe={dataType:Je,data:n.slice(a,a+gr).buffer};if(a+=gr,!Z&&!b){if(a+Te*2>d.byteLength)return;const ai=d.getBigUint64(a,!0);a+=Te;const Ul=d.getBigUint64(a,!0);a+=Te,Xe.timeRange=new D({start:ai,end:Ul})}else b?Xe.timeRange=new D({start:0n,end:0n}):Xe.timeRange=new D({start:l?.valueOf()??0n,end:u?.valueOf()??0n});if(!v&&!f){if(a+Me>d.byteLength)return;h=d.getBigUint64(a,!0),a+=Me,Xe.alignment=h}else f?Xe.alignment=0n:Xe.alignment=h;s.series.push(Xe)}),s}}const Ws=254,Jz=new Uint8Array([Ws]),Xz=255,Qz=new Uint8Array([Xz]),zu="application/sy-framer";class eE{contentType=zu;base;lowPerfCodec;constructor(e){this.base=e,this.lowPerfCodec=it.JSON_CODEC}encode(e){const r=e;if(r.type=="close"||r.payload?.command!=Se.Write){const s=this.lowPerfCodec.encode(r),a=new Uint8Array({length:s.byteLength+1});return a.set(Jz,0),a.set(new Uint8Array(s),1),a}const n=this.base.encode(r.payload?.frame,1);return n.set(Qz,0),n}decode(e,r){if(new DataView(e instanceof Uint8Array?e.buffer:e).getUint8(0)===Ws)return this.lowPerfCodec.decode(e.slice(1),r);const a={type:"data"},o=this.base.decode(e,1);return a.payload={command:Se.Write,frame:o},a}}class tE{contentType=zu;base;lowPerfCodec;constructor(e){this.base=e,this.lowPerfCodec=it.JSON_CODEC}encode(e){return this.lowPerfCodec.encode(e)}decode(e,r){return new DataView(e instanceof Uint8Array?e.buffer:e).getUint8(0)===Ws?this.lowPerfCodec.decode(e.slice(1),r):{type:"data",payload:{frame:this.base.decode(e,1)}}}}class cn{adapter;retriever;keys;codec;constructor(e){this.retriever=e,this.adapter=null,this.keys=[],this.codec=new Tu}static async open(e,r){const n=new cn(e);return await n.update(r),n}async update(e){const{variant:r,normalized:n}=ge(e),s=await this.retriever.retrieve(n),a=s.map(c=>c.key);if(Oi.uniqueUnorderedPrimitiveArrays(this.keys,a)===Oi.EQUAL)return!1;if(this.codec.update(a,s.map(c=>c.dataType)),r==="keys")return this.adapter=null,this.keys=n,!0;const o=new Map;return this.adapter=o,n.forEach(c=>{const l=s.find(u=>u.name===c);if(l==null)throw new Error(`Channel ${c} not found`);o.set(l.key,l.name)}),this.keys=Array.from(this.adapter.keys()),!0}adapt(e){if(this.adapter==null)return e;const r=this.adapter;return e.map((n,s)=>{if(typeof n=="number"){const a=r.get(n);if(a==null)throw new Error(`Channel ${n} not found`);return[a,s]}return[n,s]})}}class Gs{adapter;retriever;keys;codec;constructor(e){this.retriever=e,this.adapter=null,this.keys=[],this.codec=new Tu}static async open(e,r){const n=new Gs(e);return await n.update(r),n}async adaptParams(e){const r=at.parse(e);return await Promise.all(r.map(async s=>await this.adaptToKey(s)))}async update(e){const r=await lu(this.retriever,e),n=r.map(u=>u.key),s=new Set(this.keys),a=new Set(n),o=!a.isSubsetOf(s),c=!s.isSubsetOf(a);return o||c?(this.adapter=new Map(r.map(u=>[u.name,u.key])),this.keys=n,this.codec.update(this.keys,r.map(u=>u.dataType)),!0):!1}async fetchChannel(e){const r=await this.retriever.retrieve(e);if(r.length===0)throw new Error(`Channel ${JSON.stringify(e)} not found`);return r[0]}async adaptToKey(e){return typeof e=="number"?e:(await this.fetchChannel(e)).key}encode(e){return this.codec.encode(e.toPayload())}async adapt(e,r){if(typeof e=="string"||typeof e=="number"){if(r==null)throw new Y(`
51
51
  Received a single channel name or key but no series.
52
- `);if(Array.isArray(r)){if(r.some(l=>l instanceof Ae||Array.isArray(l)))throw new Y(`
52
+ `);if(Array.isArray(r)){if(r.some(l=>l instanceof xe||Array.isArray(l)))throw new Y(`
53
53
  Received a single channel name or key but multiple series.
54
- `);r=r}const o=await this.fetchChannel(e),c=new Ae({data:r,dataType:o.dataType});return new W(o.key,c)}if(Array.isArray(e)){if(r==null)throw new Y(`
54
+ `);r=r}const o=await this.fetchChannel(e),c=new xe({data:r,dataType:o.dataType});return new H(o.key,c)}if(Array.isArray(e)){if(r==null)throw new Y(`
55
55
  Received an array of channel names or keys but no series.
56
56
  `);if(!Array.isArray(r))throw new Y(`
57
57
  Received an array of channel names or keys but no array of series.
58
58
  `);const o=[],c=[];for(let l=0;l<e.length;l++){const u=await this.fetchChannel(e[l]);if(l>=r.length)throw new Y(`
59
59
  Received an array of channel names or keys but not enough series.
60
- `);const h=new Ae({data:r[l],dataType:u.dataType});o.push(u.key),c.push(h)}return new W(o,c)}if(e instanceof W||e instanceof Map){const o=new W(e);if(this.adapter==null)return o;const c=o.columns.map(l=>{const u=typeof l=="string"?this.adapter?.get(l):l;if(u==null)throw new Y(`
60
+ `);const h=new xe({data:r[l],dataType:u.dataType});o.push(u.key),c.push(h)}return new H(o,c)}if(e instanceof H||e instanceof Map){const o=new H(e);if(this.adapter==null)return o;const c=o.columns.map(l=>{const u=typeof l=="string"?this.adapter?.get(l):l;if(u==null)throw new Y(`
61
61
  Channel ${l} was not provided in the list of channels when opening the writer
62
- `);return u});return new W(c,o.series)}const n=[],s=[],a=Object.entries(e);for(let o=0;o<a.length;o++){const[c,l]=a[o],u=await this.fetchChannel(c),h=new Ae({data:l,dataType:u.dataType});n.push(u.key),s.push(h)}return new W(n,s)}}class bu{name;stream;constructor(e,r){this.stream=r,this.name=e}async receive(){const[e,r]=await this.stream.receive();if(r!=null)throw r;return e}received(){return this.stream.received()}async closeAndAck(){for(this.stream.closeSend();;){const[e,r]=await this.stream.receive();if(e!=null&&console.warn(`${this.name} received unexpected response on ${JSON.stringify(e)} closure.
63
- Please report this error to the Synnax team.`),r!=null){if(we.matches(r))return;throw r}}}closeSend(){this.stream.closeSend()}send(e){const r=this.stream.send(e);if(r!=null)throw r}}const Lr=new I(-1);var Gs=(t=>(t[t.Open=0]="Open",t[t.Next=1]="Next",t[t.Prev=2]="Prev",t[t.SeekFirst=3]="SeekFirst",t[t.SeekLast=4]="SeekLast",t[t.SeekLE=5]="SeekLE",t[t.SeekGE=6]="SeekGE",t[t.Valid=7]="Valid",t[t.Error=8]="Error",t))(Gs||{}),vu=(t=>(t[t.None=0]="None",t[t.Ack=1]="Ack",t[t.Data=2]="Data",t))(vu||{});const Wz=i.z.object({command:i.z.enum(Gs),span:I.z.optional(),bounds:P.z.optional(),stamp:p.z.optional(),keys:D.array().optional(),chunkSize:i.z.number().optional()}),Hz=i.z.object({variant:i.z.enum(vu),ack:i.z.boolean(),command:i.z.enum(Gs),error:Ze.payloadZ.optional().nullable(),frame:an.optional()});class tr{static ENDPOINT="/frame/iterate";stream;adapter;value;constructor(e,r){this.stream=new bu("Iterator",e),this.value=new W,this.adapter=r}static async _open(e,r,n,s,a={}){const o=await on.open(n,r),c=await s.stream(tr.ENDPOINT,Wz,Hz),l=new tr(c,o);return await l.execute({command:0,keys:o.keys,bounds:new P(e),chunkSize:a.chunkSize??1e5}),l}async next(e=Lr){return await this.execute({command:1,span:new I(e)})}async prev(e=Lr){return await this.execute({command:2,span:new I(e)})}async seekFirst(){return await this.execute({command:3})}async seekLast(){return await this.execute({command:4})}async seekLE(e){return await this.execute({command:5,stamp:new p(e)})}async seekGE(e){return await this.execute({command:6,stamp:new p(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new Gz(this)}async execute(e){for(this.stream.send(e),this.value=new W;;){const r=await this.stream.receive();if(r.variant===1)return r.ack;this.value.push(this.adapter.adapt(new W(r.frame)))}}}class Gz{iter;open=!1;constructor(e){this.iter=e}async next(){try{let e=!0;return this.open||(await this.iter.seekFirst()||(e=!1),this.open=!0),await this.iter.next()||(e=!1),e||await this.iter.close(),{done:!e,value:this.iter.value}}catch(e){throw await this.iter.close(),e}}}const Jz=i.z.object({keys:i.z.number().array(),downsampleFactor:i.z.number()}),Kz=i.z.object({frame:an}),Xz="/frame/stream",ha=i.z.object({channels:it,downsampleFactor:i.z.number().optional().default(1),useHighPerformanceCodec:i.z.boolean().optional().default(!0)}),Js=ha.or(it.transform(t=>ha.parse({channels:t}))),Tu=(t,e)=>async r=>{const n=Js.parse(r),s=await on.open(t,n.channels);n.useHighPerformanceCodec&&(e=e.withCodec(new Yz(s.codec)));const a=await e.stream(Xz,Jz,Kz),o=new Qz(a,s);a.send({keys:s.keys,downsampleFactor:n.downsampleFactor??1});const[,c]=await a.receive();if(c!=null)throw c;return o},zu=async(t,e,r)=>await Tu(t,e)(r);class Qz{stream;adapter;downsampleFactor;constructor(e,r){this.stream=new bu("Streamer",e),this.adapter=r,this.downsampleFactor=1}get keys(){return this.adapter.keys}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(we.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new W((await this.stream.receive()).frame))}async update(e){await this.adapter.update(e)&&this.stream.send({keys:this.adapter.keys,downsampleFactor:this.downsampleFactor})}close(){this.stream.closeSend()}[Symbol.asyncIterator](){return this}}class cn{wrapped_=null;breaker;opener;config;constructor(e,r,n={}){this.opener=e,this.config=Js.parse(r);const{maxRetries:s=5e3,baseInterval:a=I.seconds(1),scale:o=1}=n??{};this.breaker=new Bo.Breaker({maxRetries:s,baseInterval:a,scale:o})}static async open(e,r,n){const s=new cn(e,r,n);return await s.runStreamer(),s}async runStreamer(){for(;;)try{this.wrapped_!=null&&this.wrapped_.close(),this.wrapped_=await this.opener(this.config),this.breaker.reset();return}catch(e){if(this.wrapped_=null,!await this.breaker.wait())throw e;console.error("failed to open streamer",e);continue}}get wrapped(){if(this.wrapped_==null)throw new Error("stream closed");return this.wrapped_}async update(e){this.config.channels=it.parse(e);try{await this.wrapped.update(e)}catch{return await this.runStreamer(),await this.update(e)}}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(we.matches(e))return{done:!0,value:void 0};throw e}}async read(){try{const e=await this.wrapped.read();return this.breaker.reset(),e}catch(e){if(we.matches(e))throw e;return await this.runStreamer(),await this.read()}}close(){this.wrapped.close()}get keys(){return this.wrapped.keys}[Symbol.asyncIterator](){return this}}class Eu extends Gp.Observer{streamer;closePromise;constructor(e,r){super(r),this.streamer=e,this.closePromise=this.stream()}async update(e){await this.streamer.update(e)}async close(){this.streamer.close(),await this.closePromise}async stream(){for await(const e of this.streamer)this.notify(e)}}const eE=t=>({type:"framer",key:t.toString()});let Nu=class{streamClient;retriever;deleter;constructor(e,r,n){this.streamClient=e,this.retriever=n,this.deleter=new Cz(r)}async openIterator(e,r,n){return await tr._open(e,r,this.retriever,this.streamClient,n)}async openWriter(e){return await mu._open(this.retriever,this.streamClient,e)}async openStreamer(e){return await zu(this.retriever,this.streamClient,e)}async write(e,r,n){if(n==null){const a=r,o=await this.openWriter({start:e,channels:Object.keys(a),mode:er.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:I.MAX});return await o.write(a),await o.close()}const s=await this.openWriter({start:e,channels:r,mode:er.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:I.MAX});await s.write(r,n),await s.close()}async read(e,r){const{single:n}=ge(r),s=await this.readFrame(e,r);return n?s.get(r):s}async readFrame(e,r){const n=await this.openIterator(e,r),s=new W;try{for await(const a of n)s.push(a)}finally{await n.close()}return s}async readLatest(e,r=1){const{single:n}=ge(e),s=await this.readLatestNFrame(e,r);return n?s.get(e):s}async readLatestNFrame(e,r){const n=await this.openIterator(P.MAX,e,{chunkSize:r}),s=new W;if(r>0)try{await n.seekLast(),await n.prev(Lr),s.push(n.value)}finally{await n.close()}return s}async delete(e,r){const{normalized:n,variant:s}=ge(e),a=new P(r);return s==="keys"?await this.deleter.delete({keys:n,bounds:a}):await this.deleter.delete({names:n,bounds:a})}};const tE=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:Rz,AUTO_SPAN:Lr,Client:Nu,Frame:W,HardenedStreamer:cn,Iterator:tr,ObservableStreamer:Eu,Writer:mu,WriterClosedError:fs,WriterCommand:zt,WriterMode:er,createStreamOpener:Tu,frameZ:an,ontologyID:eE,openStreamer:zu,seriesFromPayload:fu,seriesToPayload:du,streamerConfigZ:Js,writerConfigZ:yu},Symbol.toStringTag,{value:"Module"})),rE=fe.ABSOLUTE_AUTHORITY,nE=fe.ZERO_AUTHORITY,sE=fe.stateZ(i.z.number()),iE=t=>t.to==null?`${t.from?.resource} - ${t.from?.subject.name} -> released`:t.from==null?`${t.to.resource} - released -> ${t.to.subject.name} (${t.to.authority.toString()})`:`${t.to.resource} - ${t.from.subject.name} -> ${t.to.subject.name} (${t.to.authority.toString()})`,aE=i.z.object({transfers:i.z.array(fe.transferZ(D))});class Ou extends Eu{states;codec;constructor(e){super(e,r=>{const n=this.codec.decode(r.series[0].buffer,aE);return this.merge(n),[n.transfers,!0]}),this.states=new Map,this.codec=new st.JSONCodec}subjects(){const e=new Map;return this.states.forEach(r=>e.set(r.subject.key,r.subject)),Array.from(e.values())}merge(e){e.transfers.forEach(r=>{r.from==null&&r.to==null&&console.warn("Invalid transfer: ",r),r.to==null?this.states.delete(r.from.resource):this.states.set(r.to.resource,r.to)})}}const $u="sy_node_1_control";let Su=class{framer;constructor(e){this.framer=e}async openStateTracker(){const e=await cn.open(async r=>await this.framer.openStreamer(r),$u);return new Ou(e)}};const oE=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:rE,CONTROL_STATE_CHANNEL_NAME:$u,Client:Su,StateTracker:Ou,ZERO_AUTHORITY:nE,stateZ:sE,transferString:iE},Symbol.toStringTag,{value:"Module"}));let Iu=class{tasks;racks;devices;constructor(e,r,n){this.tasks=e,this.racks=r,this.devices=n}};const cE=Object.freeze(Object.defineProperty({__proto__:null,Client:Iu},Symbol.toStringTag,{value:"Module"})),ve=i.z.uint32(),ku=i.z.object({rack:ve}),Au=It.statusZ(ku),un=i.z.object({key:ve,name:i.z.string(),status:Lt.nullToUndefined(Au)}),xu=un.partial({key:!0}),Zu=t=>t?st.JSON_CODEC.decodeString(t,be.unknownZ):{},Zt=i.z.string(),Cu=i.z.object({rack:ve,device:Zt}),Ru=It.statusZ(Cu),ln=i.z.object({key:Zt,rack:ve.min(1,"Must select a location to connect from"),name:i.z.string().min(1,"Name is required"),make:i.z.string().min(1,"Make is required"),model:i.z.string().min(1,"Model is required"),location:i.z.string().min(1,"Location is required"),configured:i.z.boolean().optional(),properties:be.unknownZ.or(i.z.string().transform(Zu)),status:Lt.nullToUndefined(Ru)}),_u=ln.extend({properties:i.z.unknown().transform(t=>st.JSON_CODEC.encodeString(t))}),uE="sy_device_set",lE="sy_device_delete",hE="sy_device_status",fE="/hardware/device/retrieve",dE="/hardware/device/create",pE="/hardware/device/delete",yE=i.z.object({devices:_u.array()}),mE=i.z.object({devices:ln.array()}),gE=i.z.object({keys:Zt.array()}),wE=i.z.object({}),bE=i.z.object({keys:Zt.array().optional(),names:i.z.string().array().optional(),makes:i.z.string().array().optional(),models:i.z.string().array().optional(),locations:i.z.string().array().optional(),racks:ve.array().optional(),searchTerm:i.z.string().optional(),limit:i.z.number().optional(),offset:i.z.number().optional(),includeStatus:i.z.boolean().optional()}),vE=i.z.object({devices:T.nullableZ(ln)}),TE=i.z.object({key:Zt,includeStatus:i.z.boolean().optional()}).transform(({key:t,includeStatus:e})=>({keys:[t],includeStatus:e})),zE=i.z.union([TE,bE]);let ju=class{client;constructor(e){this.client=e}async retrieve(e){const r=typeof e=="object"&&"key"in e,n=await w(this.client,fE,e,zE,vE);ce("Device",e,n.devices,r);const s=n.devices;return r?s[0]:s}async create(e){const r=!Array.isArray(e),s=(await w(this.client,dE,{devices:T.toArray(e)},yE,mE)).devices;return r?s[0]:s}async delete(e){await w(this.client,pE,{keys:T.toArray(e)},gE,wE)}};const EE=t=>({type:"device",key:t}),NE=Object.freeze(Object.defineProperty({__proto__:null,Client:ju,DELETE_CHANNEL_NAME:lE,SET_CHANNEL_NAME:uE,STATUS_CHANNEL_NAME:hE,deviceZ:ln,keyZ:Zt,newZ:_u,ontologyID:EE,statusDetailsSchema:Cu,statusZ:Ru},Symbol.toStringTag,{value:"Module"})),OE="/hardware/rack/retrieve",$E="/hardware/rack/create",SE="/hardware/rack/delete",IE="sy_rack_status",kE="sy_rack_set",AE="sy_rack_delete",xE=i.z.object({keys:ve.array().optional(),names:i.z.string().array().optional(),searchTerm:i.z.string().optional(),embedded:i.z.boolean().optional(),hostIsNode:i.z.boolean().optional(),limit:i.z.number().optional(),offset:i.z.number().optional(),includeStatus:i.z.boolean().optional()}),ZE=i.z.object({racks:T.nullableZ(un)}),CE=i.z.union([i.z.object({key:ve,includeStatus:i.z.boolean().optional()}).transform(({key:t,includeStatus:e})=>({keys:[t],includeStatus:e})),i.z.object({name:i.z.string(),includeStatus:i.z.boolean().optional()}).transform(({name:t,includeStatus:e})=>({names:[t],includeStatus:e}))]),RE=xE,_E=i.z.union([CE,RE]),jE=i.z.object({racks:xu.array()}),ME=i.z.object({racks:un.array()}),DE=i.z.object({keys:ve.array()}),PE=i.z.object({});let Mu=class{client;tasks;constructor(e,r){this.client=e,this.tasks=r}async delete(e){await w(this.client,SE,{keys:T.toArray(e)},DE,PE)}async create(e){const r=!Array.isArray(e),n=await w(this.client,$E,{racks:T.toArray(e)},jE,ME),s=this.sugar(n.racks);return r?s[0]:s}async retrieve(e){const r="key"in e||"name"in e,n=await w(this.client,OE,e,_E,ZE),s=this.sugar(n.racks);return ce("Rack",e,s,r),r?s[0]:s}sugar(e){const r=!Array.isArray(e),n=T.toArray(e).map(({key:s,name:a,status:o})=>new Du(s,a,this.tasks,o));return r?n[0]:n}};class Du{key;name;status;tasks;constructor(e,r,n,s){this.key=e,this.name=r,this.tasks=n,this.status=s}async listTasks(){return await this.tasks.retrieve({rack:this.key})}async createTask(e,r){return e.key=((BigInt(this.key)<<32n)+(BigInt(e.key??0)&0xffffffffn)).toString(),await this.tasks.create(e,r)}async deleteTask(e){await this.tasks.delete([e])}get payload(){return{key:this.key,name:this.name,status:this.status}}}const UE=t=>({type:"rack",key:t.toString()}),LE=Object.freeze(Object.defineProperty({__proto__:null,Client:Mu,DELETE_CHANNEL_NAME:AE,Rack:Du,SET_CHANNEL_NAME:kE,STATUS_CHANNEL_NAME:IE,keyZ:ve,newZ:xu,ontologyID:UE,rackZ:un,statusDetailsSchema:ku,statusZ:Au},Symbol.toStringTag,{value:"Module"})),Ce=i.z.union([i.z.string(),i.z.bigint().transform(t=>t.toString()),i.z.number().transform(t=>t.toString())]),Pu=t=>i.z.object({task:Ce,running:i.z.boolean(),data:t}),Ks=t=>It.statusZ(Pu(t)),fr=(t={typeSchema:i.z.string(),configSchema:i.z.unknown(),statusDataSchema:i.z.unknown()})=>i.z.object({key:Ce,name:i.z.string(),type:t.typeSchema,internal:i.z.boolean().optional(),config:i.z.string().transform(Zu).or(t.configSchema),status:Ks(t.statusDataSchema).optional().nullable(),snapshot:i.z.boolean().optional()}),Uu=t=>fr(t).omit({key:!0}).extend({key:Ce.transform(e=>e.toString()).optional(),config:i.z.unknown().transform(e=>st.JSON_CODEC.encodeString(e))}),BE=i.z.object({task:Ce,type:i.z.string(),key:i.z.string(),args:be.unknownZ.or(i.z.string().transform(Ie)).or(i.z.array(i.z.unknown())).or(i.z.null()).optional()}),qE=t=>Number(BigInt(t)>>32n),ps="sy_task_status",ys="sy_task_cmd",FE="sy_task_set",VE="sy_task_delete",Xe=new Error("Task not created"),Lu=async(t,e)=>{const r=await e.retrieveParents(Xs(t));return r.length===0?null:r[0]};class Bu{key;name;internal;type;snapshot;config;status;schemas;frameClient_;ontologyClient_;rangeClient_;get frameClient(){if(this.frameClient_==null)throw Xe;return this.frameClient_}get ontologyClient(){if(this.ontologyClient_==null)throw Xe;return this.ontologyClient_}get rangeClient(){if(this.rangeClient_==null)throw Xe;return this.rangeClient_}constructor({key:e,type:r,name:n,config:s,internal:a=!1,snapshot:o=!1,status:c},l,u,h,d){this.key=e,this.name=n,this.type=r,this.config=s,this.schemas=l??{typeSchema:i.z.string(),configSchema:i.z.unknown(),statusDataSchema:i.z.unknown()},this.internal=a,this.snapshot=o,this.status=c,this.frameClient_=u,this.ontologyClient_=h,this.rangeClient_=d}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,status:this.status,internal:this.internal}}get ontologyID(){return Xs(this.key)}async executeCommand(e){return await Vu({...e,frameClient:this.frameClient,task:this.key})}async executeCommandSync(e){return await Yu({...e,frameClient:this.frameClient,task:this.key,name:this.name,statusDataZ:this.schemas?.statusDataSchema})}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw Xe;return this.snapshot?await Lu(this.key,this.ontologyClient):null}}const YE=i.z.object({rack:ve.optional(),keys:Ce.array().optional(),names:i.z.string().array().optional(),types:i.z.string().array().optional(),includeStatus:i.z.boolean().optional(),internal:i.z.boolean().optional(),snapshot:i.z.boolean().optional(),searchTerm:i.z.string().optional(),offset:i.z.number().optional(),limit:i.z.number().optional()}),qu=i.z.union([i.z.object({key:Ce,includeStatus:i.z.boolean().optional()}).transform(({key:t,includeStatus:e})=>({keys:[t],includeStatus:e})),i.z.object({name:i.z.string(),includeStatus:i.z.boolean().optional()}).transform(({name:t,includeStatus:e})=>({names:[t],includeStatus:e})),i.z.object({type:i.z.string(),rack:ve.optional()}).transform(({type:t,rack:e})=>({types:[t],rack:e}))]),WE=YE,HE=i.z.union([qu,WE]),GE=t=>i.z.object({tasks:T.nullableZ(fr(t))}),JE="/hardware/task/retrieve",KE="/hardware/task/create",XE="/hardware/task/delete",QE="/hardware/task/copy",eN=t=>i.z.object({tasks:Uu(t).array()}),tN=t=>i.z.object({tasks:fr(t).array()}),rN=i.z.object({keys:Ce.array()}),nN=i.z.object({}),sN=i.z.object({key:Ce,name:i.z.string(),snapshot:i.z.boolean()}),iN=t=>i.z.object({task:fr(t)});let Fu=class{type="task";client;frameClient;ontologyClient;rangeClient;constructor(e,r,n,s){this.client=e,this.frameClient=r,this.ontologyClient=n,this.rangeClient=s}async create(e,r){const n=!Array.isArray(e),s=eN(r),a=tN(r),o=await w(this.client,KE,{tasks:T.toArray(e)},s,a),c=this.sugar(o.tasks,r);return n?c[0]:c}async delete(e){await w(this.client,XE,{keys:T.toArray(e)},rN,nN)}async retrieve({schemas:e,...r}){const n=qu.safeParse(r).success,a=(await w(this.client,JE,r,HE,GE(e))).tasks,o=this.sugar(a,e);return ce("Task",r,o,n),n?o[0]:o}async copy(e,r,n){const s=iN(),a=await w(this.client,QE,{key:e,name:r,snapshot:n},sN,s);return this.sugar(a.task)}async retrieveSnapshottedTo(e){if(this.ontologyClient==null)throw Xe;return await Lu(e,this.ontologyClient)}sugar(e,r){const n=!Array.isArray(e),s=T.toArray(e).map(({key:a,name:o,type:c,config:l,status:u,internal:h,snapshot:d})=>new Bu({key:a,name:o,type:c,config:l,internal:h,snapshot:d,status:u},r,this.frameClient,this.ontologyClient,this.rangeClient));return n?s[0]:s}async executeCommand(e){return"commands"in e?await Qs({...e,frameClient:this.frameClient}):await Vu({...e,frameClient:this.frameClient})}async executeCommandSync(e){if("commands"in e){const n=async()=>{const{commands:s}=e;return(await this.retrieve({keys:s.map(o=>o.task)})).map(o=>o.name)};return await Wu({...e,frameClient:this.frameClient,name:n})}const r=async()=>{const{task:n}=e;return(await this.retrieve({key:n})).name};return await Yu({frameClient:this.frameClient,name:r,...e})}};const Xs=t=>({type:"task",key:t}),Vu=async({frameClient:t,task:e,type:r,args:n})=>(await Qs({frameClient:t,commands:[{args:n,task:e,type:r}]}))[0],Qs=async({frameClient:t,commands:e})=>{if(t==null)throw Xe;const r=await t.openWriter(ys),n=e.map(s=>({...s,key:dp.create()}));return await r.write(ys,n),await r.close(),n.map(s=>s.key)},Yu=async({frameClient:t,task:e,type:r,timeout:n,name:s,statusDataZ:a,args:o})=>(await Wu({frameClient:t,commands:[{args:o,task:e,type:r}],timeout:n,statusDataZ:a,name:s}))[0],Wu=async({frameClient:t,commands:e,timeout:r=I.seconds(10),statusDataZ:n,name:s})=>{if(t==null)throw Xe;const a=await t.openStreamer(ps),o=await Qs({frameClient:t,commands:e}),c=new I(r);let l=[],u;const h=new Promise((d,f)=>{u=setTimeout(()=>{(async()=>{const v=e.map(S=>S.task);f(await aN("command",s,c,v))})()},c.milliseconds)});try{for(;;){const d=await Promise.race([a.read(),h]),f=Ks(n).parse(d.at(-1)[ps]);if(o.includes(f.key)&&(l=[...l.filter(v=>v.key!==f.key),f],l.length===o.length))return l}}finally{clearTimeout(u),a.close()}},aN=async(t,e,r,n)=>{const s=Hf.capitalize(t),a=r.toString();try{let o;typeof e=="string"?o=[e]:Array.isArray(e)?o=e:o=T.toArray(await e());const c=ns.naturalLanguageJoin(o);return new Error(`${s} command to ${c} timed out after ${a}`)}catch(o){return console.error("Failed to retrieve task name for timeout error:",o),new Error(`${s} command to task with key ${ns.naturalLanguageJoin(n)} timed out after ${a}`)}},oN=Object.freeze(Object.defineProperty({__proto__:null,COMMAND_CHANNEL_NAME:ys,Client:Fu,DELETE_CHANNEL_NAME:VE,SET_CHANNEL_NAME:FE,STATUS_CHANNEL_NAME:ps,Task:Bu,commandZ:BE,keyZ:Ce,newZ:Uu,ontologyID:Xs,rackKey:qE,statusDetailsZ:Pu,statusZ:Ks,taskZ:fr},Symbol.toStringTag,{value:"Module"})),He=nc.keyZ,dr=nc.labelZ,cN="labeled_by",uN="sy_label_set",lN="sy_label_delete",Hu=dr.extend({key:He.optional()}),hN=i.object({labels:Hu.array()}),fN=i.object({labels:dr.array()}),dN=i.object({keys:He.array()}),Gu=i.object({id:j,labels:He.array(),replace:i.boolean().optional()}),pN=Gu.omit({replace:!0}),xn=i.object({}),yN="/label/create",mN="/label/delete",gN="/label/set",wN="/label/remove",bN="/label/retrieve",vN=i.object({keys:He.array().optional(),for:j.optional(),searchTerm:i.string().optional(),offset:i.number().optional(),limit:i.number().optional()}),TN=i.object({key:He}).transform(({key:t})=>({keys:[t]})),zN=i.union([TN,vN]),EN=i.object({labels:T.nullableZ(dr)});let Ju=class{type="label";client;constructor(e){this.client=e}async retrieve(e){const r="key"in e,n=await w(this.client,bN,e,zN,EN);return ce("Label",e,n.labels,r),r?n.labels[0]:n.labels}async label(e,r,n={}){await w(this.client,gN,{id:e,labels:r,replace:n.replace},Gu,xn)}async remove(e,r){await w(this.client,wN,{id:e,labels:r},pN,xn)}async create(e){const r=Array.isArray(e),n=await w(this.client,yN,{labels:T.toArray(e)},hN,fN);return r?n.labels:n.labels[0]}async delete(e){await w(this.client,mN,{keys:T.toArray(e)},dN,xn)}};const NN=t=>({type:"label",key:t}),ON=Object.freeze(Object.defineProperty({__proto__:null,Client:Ju,DELETE_CHANNEL_NAME:lN,LABELED_BY_ONTOLOGY_RELATIONSHIP_TYPE:cN,SET_CHANNEL_NAME:uN,keyZ:He,labelZ:dr,newZ:Hu,ontologyID:NN},Symbol.toStringTag,{value:"Module"})),ee=i.z.uuid(),ei=i.z.string().min(1),pr=i.z.object({key:ee,name:ei,timeRange:P.z.refine(({isValid:t})=>t,{error:"Time range start time must be before or equal to time range end time"}).refine(({end:t})=>t.valueOf()<=Qn.MAX_INT64,{error:"Time range end time must be less than or equal to the maximum value of an int64"}).refine(({start:t})=>t.valueOf()>=Qn.MIN_INT64,{error:"Time range start time must be greater than or equal to the minimum value of an int64"}),color:i.z.string().optional(),labels:dr.array().or(i.z.null().transform(()=>{})).optional(),get parent(){return pr.optional().nullable().transform(t=>t===void 0?null:t)}}),Ku=pr.omit({parent:!0,labels:!0}).partial({key:!0}),$N="sy_range_alias_set",SN="sy_range_alias_delete",IN=i.z.object({range:ee,aliases:i.z.string().array()}),kN=i.z.object({aliases:i.z.record(i.z.string(),D)}),AN=i.z.object({range:ee,aliases:i.z.record(D,i.z.string())}),xN=i.z.unknown(),ZN=i.z.object({range:ee,channels:D.array()}),CN=i.z.unknown(),RN=i.z.object({range:ee}),_N=i.z.object({aliases:i.z.record(i.z.string(),i.z.string())}),jN=i.z.object({range:ee,channels:D.array()}),MN=i.z.object({aliases:i.z.record(i.z.string(),i.z.string())});class oe{static SET_ENDPOINT="/range/alias/set";static RESOLVE_ENDPOINT="/range/alias/resolve";static LIST_ENDPOINT="/range/alias/list";static RETRIEVE_ENDPOINT="/range/alias/retrieve";static DELETE_ENDPOINT="/range/alias/delete";frameClient;cache=new Map;client;rangeKey;constructor(e,r,n){this.rangeKey=e,this.cache=new Map,this.client=n,this.frameClient=r}async resolve(e){const r=[],n=typeof e=="string",s={};if(n){const o=this.cache.get(e);if(o!=null)return o;r.push(e)}else e.forEach(o=>{const c=this.cache.get(o);c!=null?s[o]=c:r.push(o)});if(r.length===0)return s;const a=await w(this.client,oe.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:r},IN,kN);return Object.entries(a.aliases).forEach(([o,c])=>this.cache.set(o,c)),n?a.aliases[r[0]]:{...s,...a.aliases}}async set(e){await w(this.client,oe.SET_ENDPOINT,{range:this.rangeKey,aliases:e},AN,xN)}async list(){return(await w(this.client,oe.LIST_ENDPOINT,{range:this.rangeKey},RN,_N)).aliases}async retrieve(e){const r=typeof e=="number",n=await w(this.client,oe.RETRIEVE_ENDPOINT,{range:this.rangeKey,channels:T.toArray(e)},jN,MN);return r?n.aliases[e]:n.aliases}async delete(e){await w(this.client,oe.DELETE_ENDPOINT,{range:this.rangeKey,channels:T.toArray(e)},ZN,CN)}}const DN=i.z.object({alias:i.z.string().optional(),channel:D,range:ee}),Xu="---",PN=t=>`${t.range}${Xu}${t.channel}`,UN=t=>{const[e,r]=t.split(Xu);return{range:e,channel:Number(r)}},LN="sy_range_kv_set",BN="sy_range_kv_delete",ti=i.z.object({range:ee,key:i.z.string(),value:i.z.string()}),qN=({range:t,key:e})=>`${t}<--->${e}`,FN=i.z.object({range:ee,keys:i.z.string().array()}),VN=i.z.object({pairs:T.nullableZ(ti)}),YN=i.z.object({range:ee,pairs:ti.array()}),WN=i.z.object({range:ee,keys:i.z.string().array()});class et{static GET_ENDPOINT="/range/kv/get";static SET_ENDPOINT="/range/kv/set";static DELETE_ENDPOINT="/range/kv/delete";rangeKey;client;constructor(e,r){this.rangeKey=e,this.client=r}async get(e){const r=await w(this.client,et.GET_ENDPOINT,{range:this.rangeKey,keys:T.toArray(e)},FN,VN);return typeof e=="string"?r.pairs[0].value:Object.fromEntries(r.pairs.map(n=>[n.key,n.value]))}async list(){return this.get([])}async set(e,r=""){let n;Wa(e)?n=Object.entries(e).map(([s,a])=>({range:this.rangeKey,key:s,value:a})):n=[{range:this.rangeKey,key:e,value:r}],await w(this.client,et.SET_ENDPOINT,{range:this.rangeKey,pairs:n},YN,i.z.unknown())}async delete(e){await w(this.client,et.DELETE_ENDPOINT,{range:this.rangeKey,keys:T.toArray(e)},WN,i.z.unknown())}}const HN="sy_range_set",GN="sy_range_delete";class Qu{key;name;kv;timeRange;color;parent;labels;channels;aliaser;frameClient;labelClient;ontologyClient;rangeClient;constructor({name:e,timeRange:r=P.ZERO,key:n,color:s,parent:a,labels:o},{frameClient:c,kv:l,aliaser:u,channels:h,labelClient:d,ontologyClient:f,rangeClient:v}){this.key=n,this.name=e,this.timeRange=r,this.parent=a,this.labels=o,this.frameClient=c,this.color=s,this.kv=l,this.aliaser=u,this.channels=h,this.labelClient=d,this.ontologyClient=f,this.rangeClient=v}get ontologyID(){return pt(this.key)}get payload(){let e=null;return this.parent!=null&&("payload"in this.parent?e=this.parent.payload:e=this.parent),{key:this.key,name:this.name,timeRange:this.timeRange,color:this.color,labels:this.labels,parent:e}}async setAlias(e,r){const n=await this.channels.retrieve(e);if(n.length===0)throw new Fe(`Channel ${e} does not exist`);await this.aliaser.set({[n[0].key]:r})}async deleteAlias(...e){await this.aliaser.delete(e)}async listAliases(){return await this.aliaser.list()}async resolveAlias(e){return await this.aliaser.resolve(e)}async retrieveParent(){return this.rangeClient.retrieveParent(this.key)}async retrieveChildren(){const e=(await this.ontologyClient.retrieveChildren(this.ontologyID,{excludeFieldData:!0,types:["range"]})).map(r=>r.id.key);return await this.rangeClient.retrieve(e)}async read(e){return await this.frameClient.read(this.timeRange,e)}async retrieveLabels(){return await this.labelClient.retrieve({for:pt(this.key)})}async addLabel(...e){await this.labelClient.label(pt(this.key),e)}async removeLabel(...e){await this.labelClient.remove(pt(this.key),e)}static sort(e,r){return P.sort(e.timeRange,r.timeRange)}}const JN=i.z.object({keys:ee.array().optional(),names:i.z.array(i.z.string()).optional(),searchTerm:i.z.string().optional(),overlapsWith:P.z.optional(),limit:i.z.number().int().optional(),offset:i.z.number().int().optional(),hasLabels:He.array().optional(),includeLabels:i.z.boolean().optional(),includeParent:i.z.boolean().optional()}),KN=JN.or(ee.array().transform(t=>({keys:t}))).or(ee.transform(t=>({keys:[t]}))).or(i.z.string().transform(t=>({names:[t]}))).or(i.z.string().array().transform(t=>({names:t}))).or(P.z.transform(t=>({overlapsWith:t}))),XN="/range/retrieve",QN=i.z.object({ranges:T.nullableZ(pr)});let el=class{type="range";frameClient;writer;unaryClient;channels;labelClient;ontologyClient;constructor(e,r,n,s,a,o){this.frameClient=e,this.writer=r,this.unaryClient=n,this.channels=s,this.labelClient=a,this.ontologyClient=o}async create(e,r){const n=!Array.isArray(e),s=this.sugarMany(await this.writer.create(T.toArray(e),r));return n?s[0]:s}async rename(e,r){await this.writer.rename(e,r)}async delete(e){await this.writer.delete(T.toArray(e))}async retrieve(e){const r=typeof e=="string",{ranges:n}=await w(this.unaryClient,XN,e,KN,QN);return ce("Range",e,n,r),r?this.sugarMany(n)[0]:this.sugarMany(n)}getKV(e){return new et(e,this.unaryClient)}async retrieveParent(e){const r=await this.ontologyClient.retrieveParents(pt(e));if(r.length===0)return null;const n=r[0];return n.id.type!=="range"?null:await this.retrieve(n.id.key)}sugarOntologyResource(e){return this.sugarOne(tl(e))}async retrieveAlias(e,r){return await new oe(e,this.frameClient,this.unaryClient).retrieve(r)}async retrieveAliases(e,r){return await new oe(e,this.frameClient,this.unaryClient).retrieve(r)}async listAliases(e){return await new oe(e,this.frameClient,this.unaryClient).list()}async setAlias(e,r,n){await new oe(e,this.frameClient,this.unaryClient).set({[r]:n})}async deleteAlias(e,r){await new oe(e,this.frameClient,this.unaryClient).delete(r)}sugarOne(e){return new Qu(e,{frameClient:this.frameClient,kv:new et(e.key,this.unaryClient),aliaser:new oe(e.key,this.frameClient,this.unaryClient),channels:this.channels,labelClient:this.labelClient,ontologyClient:this.ontologyClient,rangeClient:this})}sugarMany(e){return e.map(r=>this.sugarOne(r))}resourceToRange(e){return this.sugarOne({key:e.id.key,name:e.data?.name,timeRange:new P(e.data?.timeRange),color:e.data?.color,labels:[],parent:null})}};const pt=t=>({type:"range",key:t}),eO=t=>({type:"range-alias",key:t}),tl=({data:t,id:{key:e},name:r})=>{const n=P.z.parse(t?.timeRange);return{key:e,name:r,timeRange:n,color:typeof t?.color=="string"?t.color:void 0,labels:[],parent:null}},tO=i.z.object({ranges:pr.array()}),rO=i.z.object({parent:j.optional(),ranges:Ku.array()}),nO=i.z.object({keys:ee.array()}),sO=i.z.object({}),iO=i.z.object({key:ee,name:ei}),aO=i.z.object({}),oO="/range/create",cO="/range/delete",uO="/range/rename";class rl{client;constructor(e){this.client=e}async rename(e,r){await w(this.client,uO,{key:e,name:r},iO,aO)}async create(e,r){return(await w(this.client,oO,{ranges:e,...r},rO,tO)).ranges}async delete(e){await w(this.client,cO,{keys:e},nO,sO)}}const lO=Object.freeze(Object.defineProperty({__proto__:null,Aliaser:oe,Client:el,DELETE_ALIAS_CHANNEL_NAME:SN,DELETE_CHANNEL_NAME:GN,KV:et,KV_DELETE_CHANNEL:BN,KV_SET_CHANNEL:LN,Range:Qu,SET_ALIAS_CHANNEL_NAME:$N,SET_CHANNEL_NAME:HN,Writer:rl,aliasKey:PN,aliasOntologyID:eO,aliasZ:DN,convertOntologyResourceToPayload:tl,decodeDeleteAliasChange:UN,keyZ:ee,kvPairKey:qN,kvPairZ:ti,nameZ:ei,newZ:Ku,ontologyID:pt,payloadZ:pr},Symbol.toStringTag,{value:"Module"})),hn=i.z.string(),fn=It.statusZ,nl=t=>fn(t).omit({labels:!0}).partial({key:!0}),hO="sy_status_set",fO="sy_status_delete",dO=t=>({type:"status",key:t}),pO=t=>i.object({parent:j.optional(),statuses:nl(t).array()}),yO=t=>i.object({statuses:fn(t).array()}),mO=i.object({keys:hn.array()}),gO=i.object({}),wO="/status/set",bO="/status/delete",vO="/status/retrieve",TO=i.object({keys:hn.array().optional(),searchTerm:i.string().optional(),offset:i.number().optional(),limit:i.number().optional(),includeLabels:i.boolean().optional(),hasLabels:He.array().optional()}),zO=i.object({key:hn,includeLabels:i.boolean().optional()}).transform(({key:t,includeLabels:e})=>({keys:[t],includeLabels:e})),EO=i.union([zO,TO]),NO=t=>i.object({statuses:T.nullableZ(fn(t))});let sl=class{type="status";client;constructor(e){this.client=e}async retrieve(e){const r="key"in e,n=await w(this.client,vO,e,EO,NO(e.detailsSchema));ce("Status",e,n.statuses,r);const s=n.statuses;return r?s[0]:s}async set(e,r={}){const n=Array.isArray(e),a=(await w(this.client,wO,{statuses:T.toArray(e),parent:r.parent},pO(r.detailsSchema),yO(r.detailsSchema))).statuses;return n?a:a[0]}async delete(e){await w(this.client,bO,{keys:T.toArray(e)},mO,gO)}};const OO=Object.freeze(Object.defineProperty({__proto__:null,Client:sl,DELETE_CHANNEL_NAME:fO,SET_CHANNEL_NAME:hO,keyZ:hn,newZ:nl,ontologyID:dO,statusZ:fn},Symbol.toStringTag,{value:"Module"})),$O="/api/v1/";class SO{url;unary;stream;secure;constructor(e,r={},n=!1){this.secure=n,this.url=e.child($O);const s=new st.JSONCodec;this.unary=Zf(new xf(this.url,s,this.secure),r),this.stream=new Cr(this.url,s,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const at=i.z.uuid(),dn=i.z.object({key:at,name:i.z.string(),data:be.unknownZ.or(i.z.string().transform(Ie))}),il=dn.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),ke=i.z.uuid(),pn=i.z.object({key:ke,name:i.z.string().min(1,"Name is required"),layout:be.unknownZ.or(i.z.string().transform(Ie))}),al=pn.partial({key:!0}).transform(t=>({...t,layout:JSON.stringify(t.layout)})),ol=pn.omit({layout:!0}).extend({layout:i.z.string().transform(Ie)}),IO="/workspace/lineplot/retrieve",kO="/workspace/lineplot/create",AO="/workspace/lineplot/rename",xO="/workspace/lineplot/set-data",ZO="/workspace/lineplot/delete",CO=i.z.object({key:at,name:i.z.string()}),RO=i.z.object({key:at,data:i.z.string()}),_O=i.z.object({keys:at.array()}),jO=i.z.object({keys:at.array()}),cl=i.z.object({key:at}).transform(({key:t})=>({keys:[t]})),ul=i.z.union([cl,jO]),MO=i.z.object({linePlots:T.nullableZ(dn)}),DO=i.z.object({workspace:ke,linePlots:il.array()}),PO=i.z.object({linePlots:dn.array()}),Zn=i.z.object({});let ll=class{client;constructor(e){this.client=e}async create(e,r){const n=Array.isArray(r),s=await w(this.client,kO,{workspace:e,linePlots:T.toArray(r)},DO,PO);return n?s.linePlots:s.linePlots[0]}async rename(e,r){await w(this.client,AO,{key:e,name:r},CO,Zn)}async setData(e,r){await w(this.client,xO,{key:e,data:JSON.stringify(r)},RO,Zn)}async retrieve(e){const r=cl.safeParse(e).success,n=await w(this.client,IO,e,ul,MO);return ce("LinePlot",e,n.linePlots,r),r?n.linePlots[0]:n.linePlots}async delete(e){await w(this.client,ZO,{keys:T.toArray(e)},_O,Zn)}};const UO=t=>({type:"lineplot",key:t}),LO=Object.freeze(Object.defineProperty({__proto__:null,Client:ll,keyZ:at,linePlotZ:dn,newZ:il,ontologyID:UO,retrieveArgsZ:ul},Symbol.toStringTag,{value:"Module"})),ot=i.z.uuid(),yn=i.z.object({key:ot,name:i.z.string(),data:be.unknownZ.or(i.z.string().transform(Ie))}),hl=yn.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),BO="/workspace/log/retrieve",qO="/workspace/log/create",FO="/workspace/log/rename",VO="/workspace/log/set-data",YO="/workspace/log/delete",WO=i.z.object({key:ot,name:i.z.string()}),HO=i.z.object({key:ot,data:i.z.string()}),GO=i.z.object({keys:ot.array()}),JO=i.z.object({keys:ot.array()}),fl=i.z.object({key:ot}).transform(({key:t})=>({keys:[t]})),dl=i.z.union([fl,JO]),KO=i.z.object({logs:T.nullableZ(yn)}),XO=i.z.object({workspace:ke,logs:hl.array()}),QO=i.z.object({logs:yn.array()}),Cn=i.z.object({});let pl=class{client;constructor(e){this.client=e}async create(e,r){const n=Array.isArray(r),s=await w(this.client,qO,{workspace:e,logs:T.toArray(r)},XO,QO);return n?s.logs:s.logs[0]}async rename(e,r){await w(this.client,FO,{key:e,name:r},WO,Cn)}async setData(e,r){await w(this.client,VO,{key:e,data:JSON.stringify(r)},HO,Cn)}async retrieve(e){const r=fl.safeParse(e).success,n=await w(this.client,BO,e,dl,KO);return ce("Log",e,n.logs,r),r?n.logs[0]:n.logs}async delete(e){await w(this.client,YO,{keys:T.toArray(e)},GO,Cn)}};const e$=t=>({type:"log",key:t}),t$=Object.freeze(Object.defineProperty({__proto__:null,Client:pl,keyZ:ot,logZ:yn,newZ:hl,ontologyID:e$,retrieveArgsZ:dl},Symbol.toStringTag,{value:"Module"})),Ge=i.z.uuid(),mn=i.z.object({key:Ge,name:i.z.string(),data:be.unknownZ.or(i.z.string().transform(Ie)),snapshot:i.z.boolean()}),yl=mn.partial({key:!0,snapshot:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),ri=mn.extend({data:i.z.string().transform(Ie)}),Ct=i.z.uuid(),ml=i.z.object({key:i.z.string(),name:i.z.string(),selectors:i.z.string().array().default([]),strokeColor:i.z.string().optional(),fillColor:i.z.string().optional()}),gl=i.z.object({key:i.z.string(),name:i.z.string(),regions:ml.array()}),wl=i.z.object({key:i.z.string(),position:ks.xy,orientation:Dd.outer}),r$=i.z.object({zoom:i.z.number().positive().default(1),position:ks.xy}),bl=i.z.object({svg:i.z.string().min(1,"SVG is required"),states:gl.array(),variant:i.z.string().min(1,"Variant is required"),handles:wl.array(),scale:i.z.number().positive().default(1),scaleStroke:i.z.boolean().default(!1),previewViewport:r$.default({zoom:1,position:{x:0,y:0}})}),gn=i.z.object({key:Ct,version:i.z.literal(1).optional().default(1),name:i.z.string().min(1,"Name is required"),data:bl}),vl=gn.partial({key:!0}),n$="/workspace/schematic/symbol/retrieve",s$="/workspace/schematic/symbol/create",i$="/workspace/schematic/symbol/rename",a$="/workspace/schematic/symbol/delete",o$="/workspace/schematic/symbol/retrieve_group",c$=i.z.object({symbols:vl.array(),parent:j}),u$=i.z.object({key:Ct,name:i.z.string()}),l$=i.z.object({keys:Ct.array()}),h$=i.z.object({keys:Ct.array().optional(),searchTerm:i.z.string().optional(),offset:i.z.number().optional(),limit:i.z.number().optional()}),f$=i.z.object({key:Ct}).transform(({key:t})=>({keys:[t]})),d$=i.z.union([f$,h$]),p$=i.z.object({symbols:T.nullableZ(gn)}),y$=i.z.object({symbols:gn.array()}),fa=i.z.object({}),m$=i.z.object({}),g$=i.z.object({group:Jr}),w$="sy_schematic_symbol_set",b$="sy_schematic_symbol_delete";let Tl=class{client;constructor(e){this.client=e}async create(e){const r="symbols"in e,n=r?e.symbols:[e],s=await w(this.client,s$,{symbols:n,parent:e.parent},c$,y$);return r?s.symbols:s.symbols[0]}async rename(e,r){await w(this.client,i$,{key:e,name:r},u$,fa)}async retrieve(e){const r="key"in e,n=await w(this.client,n$,e,d$,p$);return ce("Schematic Symbol",e,n.symbols,r),r?n.symbols[0]:n.symbols}async delete(e){await w(this.client,a$,{keys:T.toArray(e)},l$,fa)}async retrieveGroup(){return(await w(this.client,o$,{},m$,g$)).group}};const v$=t=>({type:"schematic_symbol",key:t}),T$=Object.freeze(Object.defineProperty({__proto__:null,Client:Tl,DELETE_CHANNEL_NAME:b$,SET_CHANNEL_NAME:w$,handleZ:wl,keyZ:Ct,newZ:vl,ontologyID:v$,regionZ:ml,specZ:bl,stateZ:gl,symbolZ:gn},Symbol.toStringTag,{value:"Module"})),z$="/workspace/schematic/retrieve",E$="/workspace/schematic/create",N$="/workspace/schematic/rename",O$="/workspace/schematic/set-data",$$="/workspace/schematic/delete",S$="/workspace/schematic/copy",I$=i.z.object({key:Ge,name:i.z.string()}),k$=i.z.object({key:Ge,data:i.z.string()}),A$=i.z.object({keys:Ge.array()}),x$=i.z.object({key:Ge,name:i.z.string(),snapshot:i.z.boolean()}),Z$=i.z.object({keys:Ge.array()}),zl=i.z.object({key:Ge}).transform(({key:t})=>({keys:[t]})),El=i.z.union([zl,Z$]),C$=i.z.object({schematics:T.nullableZ(ri)}),R$=i.z.object({workspace:ke,schematics:yl.array()}),_$=i.z.object({schematics:ri.array()}),j$=i.z.object({schematic:mn}),Rn=i.z.object({});let Nl=class{symbols;client;constructor(e){this.client=e,this.symbols=new Tl(e)}async create(e,r){const n=Array.isArray(r),s=await w(this.client,E$,{workspace:e,schematics:T.toArray(r)},R$,_$);return n?s.schematics:s.schematics[0]}async rename(e,r){await w(this.client,N$,{key:e,name:r},I$,Rn)}async setData(e,r){await w(this.client,O$,{key:e,data:JSON.stringify(r)},k$,Rn)}async retrieve(e){const r=zl.safeParse(e).success,n=await w(this.client,z$,e,El,C$);return ce("Schematic",e,n.schematics,r),r?n.schematics[0]:n.schematics}async delete(e){await w(this.client,$$,{keys:T.toArray(e)},A$,Rn)}async copy(e){return(await w(this.client,S$,e,x$,j$)).schematic}};const M$=t=>({type:"schematic",key:t}),D$=Object.freeze(Object.defineProperty({__proto__:null,Client:Nl,keyZ:Ge,newZ:yl,ontologyID:M$,remoteZ:ri,retrieveArgsZ:El,schematicZ:mn,symbol:T$},Symbol.toStringTag,{value:"Module"})),ct=i.z.uuid(),ni=i.z.object({key:ct,name:i.z.string(),data:be.unknownZ.or(i.z.string().transform(Ie))}),Ol=ni.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),si=ni.extend({data:i.z.string().transform(Ie)}),P$="/workspace/table/retrieve",U$="/workspace/table/create",L$="/workspace/table/rename",B$="/workspace/table/set-data",q$="/workspace/table/delete",F$=i.z.object({key:ct,name:i.z.string()}),V$=i.z.object({key:ct,data:i.z.string()}),Y$=i.z.object({keys:ct.array()}),W$=i.z.object({keys:ct.array()}),$l=i.z.object({key:ct}).transform(({key:t})=>({keys:[t]})),Sl=i.z.union([$l,W$]),H$=i.z.object({tables:T.nullableZ(si)}),G$=i.z.object({workspace:ke,tables:Ol.array()}),J$=i.z.object({tables:si.array()}),_n=i.z.object({});let Il=class{client;constructor(e){this.client=e}async create(e,r){const n=Array.isArray(r),s=await w(this.client,U$,{workspace:e,tables:T.toArray(r)},G$,J$);return n?s.tables:s.tables[0]}async rename(e,r){await w(this.client,L$,{key:e,name:r},F$,_n)}async setData(e,r){await w(this.client,B$,{key:e,data:JSON.stringify(r)},V$,_n)}async retrieve(e){const r=$l.safeParse(e).success,n=await w(this.client,P$,e,Sl,H$);return ce("Table",e,n.tables,r),r?n.tables[0]:n.tables}async delete(e){await w(this.client,q$,{keys:T.toArray(e)},Y$,_n)}};const K$=t=>({type:"table",key:t}),X$=Object.freeze(Object.defineProperty({__proto__:null,Client:Il,keyZ:ct,newZ:Ol,ontologyID:K$,remoteZ:si,retrieveArgsZ:Sl,tableZ:ni},Symbol.toStringTag,{value:"Module"})),da="/workspace/retrieve",Q$="/workspace/create",eS="/workspace/rename",tS="/workspace/set-layout",rS="/workspace/delete",pa=i.z.object({keys:ke.array().optional(),searchTerm:i.z.string().optional(),author:We.optional(),offset:i.z.number().optional(),limit:i.z.number().optional()}),nS=i.z.object({workspaces:al.array()}),sS=i.z.object({key:ke,name:i.z.string()}),iS=i.z.object({key:ke,layout:be.unknownZ.transform(t=>JSON.stringify(t))}),aS=i.z.object({keys:ke.array()}),ya=i.z.object({workspaces:T.nullableZ(pn)}),oS=i.z.object({workspaces:ol.array()}),jn=i.z.object({}),cS="sy_workspace_set",uS="sy_workspace_delete";class kl{schematics;lineplots;logs;tables;client;constructor(e){this.client=e,this.schematics=new Nl(e),this.lineplots=new ll(e),this.logs=new pl(e),this.tables=new Il(e)}async create(e){const r=Array.isArray(e),n=await w(this.client,Q$,{workspaces:T.toArray(e)},nS,oS);return r?n.workspaces:n.workspaces[0]}async rename(e,r){await w(this.client,eS,{key:e,name:r},sS,jn)}async setLayout(e,r){await w(this.client,tS,{key:e,layout:r},iS,jn)}async retrieve(e){let r;const n=typeof e!="string";typeof e=="string"||Array.isArray(e)?r={keys:T.toArray(e)}:r=e;const s=await w(this.client,da,r,pa,ya);return n?s.workspaces:s.workspaces[0]}async retrieveByAuthor(e){return(await w(this.client,da,{author:e},pa,ya)).workspaces}async delete(e){await w(this.client,rS,{keys:T.toArray(e)},aS,jn)}}const lS=t=>({type:"workspace",key:t}),hS=Object.freeze(Object.defineProperty({__proto__:null,Client:kl,DELETE_CHANNEL_NAME:uS,SET_CHANNEL_NAME:cS,keyZ:ke,newZ:al,ontologyID:lS,remoteZ:ol,workspaceZ:pn},Symbol.toStringTag,{value:"Module"})),Al=i.z.object({host:i.z.string({error:"Host is required"}).min(1,"Host is required"),port:i.z.number({error:"Port is required"}).or(i.z.string({error:"Port is required"})),username:i.z.string().min(1,"Username is required"),password:i.z.string().min(1,"Password is required"),connectivityPollFrequency:I.z.default(I.seconds(30)),secure:i.z.boolean().optional().default(!1),name:i.z.string().optional(),retry:Bo.breakerConfigZ.optional()});class xl extends Nu{createdAt;props;ranges;channels;auth;users;access;connectivity;ontology;workspaces;labels;statuses;hardware;control;arcs;static connectivity=Qt;transport;clientVersion="0.46.1";constructor(e){const r=Al.parse(e),{host:n,port:s,username:a,password:o,connectivityPollFrequency:c,secure:l,retry:u}=r,h=new SO(new Ut({host:n,port:Number(s)}),u,l);h.use(um);let d;a!=null&&o!=null&&(d=new Sz(h.unary,{username:a,password:o}),h.use(d.middleware()));const f=new Ys(new lr(h.unary)),v=new ou(h.unary,f);super(h.stream,h.unary,f),this.createdAt=p.now(),this.props=r,this.auth=d,this.transport=h,this.channels=new su(this,f,h.unary,v),this.connectivity=new Qt(h.unary,c,this.clientVersion,r.name),this.control=new Su(this),this.ontology=new gc(h.unary,this);const S=new rl(this.transport.unary);this.labels=new Ju(this.transport.unary),this.statuses=new sl(this.transport.unary),this.ranges=new el(this,S,this.transport.unary,f,this.labels,this.ontology),this.access=new vc(this.transport.unary),this.users=new uu(this.transport.unary),this.workspaces=new kl(this.transport.unary);const Z=new ju(this.transport.unary),b=new Fu(this.transport.unary,this,this.ontology,this.ranges),z=new Mu(this.transport.unary,b);this.hardware=new Iu(b,z,Z),this.arcs=new Xc(this.transport.unary)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}const Zl={host:"localhost",port:9090,username:"synnax",password:"seldon",retry:{maxRetries:4,baseInterval:I.seconds(1),scale:1.5}},fS=t=>new xl({...Zl,...t});exports.AuthError=Wt;exports.Channel=Ur;exports.ContiguityError=am;exports.DataType=R;exports.Density=Q;exports.DisconnectedError=im;exports.Frame=W;exports.MultiSeries=Do;exports.MultipleFoundError=Gt;exports.NotFoundError=Ht;exports.QueryError=Fe;exports.Rate=re;exports.RouteError=as;exports.Series=Ae;exports.Synnax=xl;exports.TEST_CLIENT_PROPS=Zl;exports.TimeRange=P;exports.TimeSpan=I;exports.TimeStamp=p;exports.UnexpectedError=gt;exports.ValidationError=Y;exports.access=rg;exports.arc=IT;exports.channel=XT;exports.connection=kz;exports.control=oE;exports.createTestClient=fS;exports.device=NE;exports.framer=tE;exports.group=Sm;exports.hardware=cE;exports.isCalculated=Xt;exports.label=ON;exports.lineplot=LO;exports.log=t$;exports.ontology=Um;exports.policy=tg;exports.rack=LE;exports.ranger=lO;exports.schematic=D$;exports.status=OO;exports.synnaxPropsZ=Al;exports.table=X$;exports.task=oN;exports.user=bz;exports.workspace=hS;
62
+ `);return u});return new H(c,o.series)}const n=[],s=[],a=Object.entries(e);for(let o=0;o<a.length;o++){const[c,l]=a[o],u=await this.fetchChannel(c),h=new xe({data:l,dataType:u.dataType});n.push(u.key),s.push(h)}return new H(n,s)}}class Eu{name;stream;constructor(e,r){this.stream=r,this.name=e}async receive(){const[e,r]=await this.stream.receive();if(r!=null)throw r;return e}received(){return this.stream.received()}async closeAndAck(){for(this.stream.closeSend();;){const[e,r]=await this.stream.receive();if(e!=null&&console.warn(`${this.name} received unexpected response on ${JSON.stringify(e)} closure.
63
+ Please report this error to the Synnax team.`),r!=null){if(we.matches(r))return;throw r}}}closeSend(){this.stream.closeSend()}send(e){const r=this.stream.send(e);if(r!=null)throw r}}const qr=new I(-1);var Ks=(t=>(t[t.Open=0]="Open",t[t.Next=1]="Next",t[t.Prev=2]="Prev",t[t.SeekFirst=3]="SeekFirst",t[t.SeekLast=4]="SeekLast",t[t.SeekLE=5]="SeekLE",t[t.SeekGE=6]="SeekGE",t[t.Valid=7]="Valid",t[t.Error=8]="Error",t))(Ks||{}),Nu=(t=>(t[t.None=0]="None",t[t.Ack=1]="Ack",t[t.Data=2]="Data",t))(Nu||{});const rE=i.z.object({command:i.z.enum(Ks),span:I.z.optional(),bounds:D.z.optional(),stamp:p.z.optional(),keys:U.array().optional(),chunkSize:i.z.number().optional()}),nE=i.z.object({variant:i.z.enum(Nu),ack:i.z.boolean(),command:i.z.enum(Ks),error:Ce.payloadZ.optional().nullable(),frame:on.optional()});class un{stream;adapter;value;constructor(e,r){this.stream=new Eu("Iterator",e),this.value=new H,this.adapter=r}static async _open(e,r,n,s,a={}){const o=await cn.open(n,r),c=await s.stream("/frame/iterate",rE,nE),l=new un(c,o);return await l.execute({command:0,keys:o.keys,bounds:new D(e),chunkSize:a.chunkSize??1e5}),l}async next(e=qr){return await this.execute({command:1,span:new I(e)})}async prev(e=qr){return await this.execute({command:2,span:new I(e)})}async seekFirst(){return await this.execute({command:3})}async seekLast(){return await this.execute({command:4})}async seekLE(e){return await this.execute({command:5,stamp:new p(e)})}async seekGE(e){return await this.execute({command:6,stamp:new p(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new sE(this)}async execute(e){for(this.stream.send(e),this.value=new H;;){const r=await this.stream.receive();if(r.variant===1)return r.ack;this.value.push(this.adapter.adapt(new H(r.frame)))}}}class sE{iter;open=!1;constructor(e){this.iter=e}async next(){try{let e=!0;return this.open||(await this.iter.seekFirst()||(e=!1),this.open=!0),await this.iter.next()||(e=!1),e||await this.iter.close(),{done:!e,value:this.iter.value}}catch(e){throw await this.iter.close(),e}}}const iE=i.z.object({keys:i.z.number().array(),downsampleFactor:i.z.number()}),aE=i.z.object({frame:on}),ha=i.z.object({channels:at,downsampleFactor:i.z.number().optional().default(1),useHighPerformanceCodec:i.z.boolean().optional().default(!0)}),Js=ha.or(at.transform(t=>ha.parse({channels:t}))),Ou=(t,e)=>async r=>{const n=Js.parse(r),s=await cn.open(t,n.channels);n.useHighPerformanceCodec&&(e=e.withCodec(new tE(s.codec)));const a=await e.stream("/frame/stream",iE,aE),o=new oE(a,s);a.send({keys:s.keys,downsampleFactor:n.downsampleFactor??1});const[,c]=await a.receive();if(c!=null)throw c;return o},$u=async(t,e,r)=>await Ou(t,e)(r);class oE{stream;adapter;downsampleFactor;constructor(e,r){this.stream=new Eu("Streamer",e),this.adapter=r,this.downsampleFactor=1}get keys(){return this.adapter.keys}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(we.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new H((await this.stream.receive()).frame))}async update(e){await this.adapter.update(e)&&this.stream.send({keys:this.adapter.keys,downsampleFactor:this.downsampleFactor})}close(){this.stream.closeSend()}[Symbol.asyncIterator](){return this}}class ln{wrapped_=null;breaker;opener;config;constructor(e,r,n={}){this.opener=e,this.config=Js.parse(r);const{maxRetries:s=5e3,baseInterval:a=I.seconds(1),scale:o=1}=n??{};this.breaker=new Fo.Breaker({maxRetries:s,baseInterval:a,scale:o})}static async open(e,r,n){const s=new ln(e,r,n);return await s.runStreamer(),s}async runStreamer(){for(;;)try{this.wrapped_!=null&&this.wrapped_.close(),this.wrapped_=await this.opener(this.config),this.breaker.reset();return}catch(e){if(this.wrapped_=null,!await this.breaker.wait())throw e;console.error("failed to open streamer",e);continue}}get wrapped(){if(this.wrapped_==null)throw new Error("stream closed");return this.wrapped_}async update(e){this.config.channels=at.parse(e);try{await this.wrapped.update(e)}catch{return await this.runStreamer(),await this.update(e)}}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(we.matches(e))return{done:!0,value:void 0};throw e}}async read(){try{const e=await this.wrapped.read();return this.breaker.reset(),e}catch(e){if(we.matches(e))throw e;return await this.runStreamer(),await this.read()}}close(){this.wrapped.close()}get keys(){return this.wrapped.keys}[Symbol.asyncIterator](){return this}}class Su extends ny.Observer{streamer;closePromise;constructor(e,r){super(r),this.streamer=e,this.closePromise=this.stream()}async update(e){await this.streamer.update(e)}async close(){this.streamer.close(),await this.closePromise}async stream(){for await(const e of this.streamer)this.notify(e)}}var er=(t=>(t[t.PersistStream=1]="PersistStream",t[t.Persist=2]="Persist",t[t.Stream=3]="Stream",t))(er||{});const cE=new I(-1);class ds extends Ie.sub("writer_closed"){constructor(){super("WriterClosed")}}const uE=i.z.enum(er).or(i.z.enum(["persist","stream","persistStream"]).transform(t=>{switch(t){case"persist":return 2;case"stream":return 3;case"persistStream":return 1}})),Iu=i.z.object({start:p.z.optional(),controlSubject:fe.subjectZ.optional(),authorities:i.z.union([fe.authorityZ.transform(t=>[t]),fe.authorityZ.array()]).default([fe.ABSOLUTE_AUTHORITY]),mode:uE.default(1),errOnUnauthorized:i.z.boolean().default(!1),enableAutoCommit:i.z.boolean().default(!0),autoIndexPersistInterval:I.z.default(I.SECOND),useHighPerformanceCodec:i.z.boolean().default(!0)}),lE=Iu.extend({keys:U.array().optional()}),fa=Iu.extend({channels:at}),Au=fa.or(at.transform(t=>fa.parse({channels:t,start:p.now()}))),hE=i.z.object({command:i.z.enum(Se),config:lE.optional(),frame:on.optional(),buffer:i.z.instanceof(Uint8Array).optional()}),fE=i.z.object({command:i.z.enum(Se),end:p.z,err:Ce.payloadZ.optional()}),dE=i.z.tuple([i.z.union([i.z.record(U.or(Ze),fe.authorityZ),U.or(Ze),fe.authorityZ]),fe.authorityZ.optional()]).transform(([t,e])=>{if(fe.authorityZ.safeParse(t).success)return{keys:[],authorities:[t]};if(U.or(Ze).safeParse(t).success){if(e==null)throw new Error("authority is required when setting authority for a single channel");return{keys:[t],authorities:[e]}}const r=t;return{keys:Object.keys(r),authorities:Object.values(r)}});let ku=class xu{stream;adapter;closeErr=null;constructor(e,r){this.stream=e,this.adapter=r}static async _open(e,r,n){const s=Au.parse(n),a=await Gs.open(e,s.channels);s.useHighPerformanceCodec&&(r=r.withCodec(new eE(a.codec)));const o=await r.stream("/frame/write",hE,fE),c=new xu(o,a);return await c.execute({command:Se.Open,config:{...s,keys:a.keys}}),c}async write(e,r){if(this.closeErr!=null)throw this.closeErr;if(this.stream.received())return await this.close();const n=await this.adapter.adapt(e,r);this.stream.send({command:Se.Write,frame:n.toPayload()})}async setAuthority(e,r){if(this.closeErr!=null)throw this.closeErr;const n=dE.parse([e,r]),s={keys:await this.adapter.adaptParams(n.keys),authorities:n.authorities};await this.execute({command:Se.SetAuthority,config:s})}async commit(){if(this.closeErr!=null)throw this.closeErr;return this.stream.received()?(await this.closeInternal(null),p.ZERO):(await this.execute({command:Se.Commit})).end}async close(){await this.closeInternal(null)}async closeInternal(e){if(this.closeErr!=null)throw this.closeErr;for(this.closeErr=e,this.stream.closeSend();;){if(this.closeErr!=null){if(ds.matches(this.closeErr))return null;throw this.closeErr}const[r,n]=await this.stream.receive();n!=null?this.closeErr=we.matches(n)?new ds:n:this.closeErr=Ce.decode(r?.err)}}async execute(e){const r=this.stream.send(e);for(r!=null&&await this.closeInternal(r);;){const[n,s]=await this.stream.receive();s!=null&&await this.closeInternal(s);const a=Ce.decode(n?.err);if(a!=null&&await this.closeInternal(a),n?.command==e.command)return n}}};const pE=t=>({type:"framer",key:t.toString()});let Zu=class{streamClient;retriever;deleter;constructor(e,r,n){this.streamClient=e,this.retriever=n,this.deleter=new Wz(r)}async openIterator(e,r,n){return await un._open(e,r,this.retriever,this.streamClient,n)}async openWriter(e){return await ku._open(this.retriever,this.streamClient,e)}async openStreamer(e){return await $u(this.retriever,this.streamClient,e)}async write(e,r,n){if(n==null){const a=r,o=await this.openWriter({start:e,channels:Object.keys(a),mode:er.Persist,errOnUnauthorized:!0,autoIndexPersistInterval:I.MAX});return await o.write(a),await o.close()}const s=await this.openWriter({start:e,channels:r,mode:er.Persist,errOnUnauthorized:!0,autoIndexPersistInterval:I.MAX});await s.write(r,n),await s.close()}async read(e,r){const{single:n}=ge(r),s=await this.readFrame(e,r);return n?s.get(r):s}async readFrame(e,r){const n=await this.openIterator(e,r),s=new H;try{for await(const a of n)s.push(a)}finally{await n.close()}return s}async readLatest(e,r=1){const{single:n}=ge(e),s=await this.readLatestNFrame(e,r);return n?s.get(e):s}async readLatestNFrame(e,r){const n=await this.openIterator(D.MAX,e,{chunkSize:r}),s=new H;if(r>0)try{await n.seekLast(),await n.prev(qr),s.push(n.value)}finally{await n.close()}return s}async delete(e,r){const{normalized:n,variant:s}=ge(e),a=new D(r);return s==="keys"?await this.deleter.delete({keys:n,bounds:a}):await this.deleter.delete({names:n,bounds:a})}};const yE=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:cE,AUTO_SPAN:qr,Client:Zu,Frame:H,HardenedStreamer:ln,Iterator:un,ObservableStreamer:Su,Writer:ku,WriterClosedError:ds,WriterCommand:Se,WriterMode:er,createStreamOpener:Ou,frameZ:on,ontologyID:pE,openStreamer:$u,seriesFromPayload:bu,seriesToPayload:vu,streamerConfigZ:Js,writerConfigZ:Au},Symbol.toStringTag,{value:"Module"})),mE=fe.ABSOLUTE_AUTHORITY,gE=fe.ZERO_AUTHORITY,wE=fe.stateZ(i.z.number()),bE=t=>t.to==null?`${t.from?.resource} - ${t.from?.subject.name} -> released`:t.from==null?`${t.to.resource} - released -> ${t.to.subject.name} (${t.to.authority.toString()})`:`${t.to.resource} - ${t.from.subject.name} -> ${t.to.subject.name} (${t.to.authority.toString()})`,vE=i.z.object({transfers:i.z.array(fe.transferZ(U))});class Cu extends Su{states;codec;constructor(e){super(e,r=>{const n=this.codec.decode(r.series[0].buffer,vE);return this.merge(n),[n.transfers,!0]}),this.states=new Map,this.codec=new it.JSONCodec}subjects(){const e=new Map;return this.states.forEach(r=>e.set(r.subject.key,r.subject)),Array.from(e.values())}merge(e){e.transfers.forEach(r=>{r.from==null&&r.to==null&&console.warn("Invalid transfer: ",r),r.to==null?this.states.delete(r.from.resource):this.states.set(r.to.resource,r.to)})}}const Ru="sy_node_1_control";let _u=class{framer;constructor(e){this.framer=e}async openStateTracker(){const e=await ln.open(async r=>await this.framer.openStreamer(r),Ru);return new Cu(e)}};const TE=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:mE,CONTROL_STATE_CHANNEL_NAME:Ru,Client:_u,StateTracker:Cu,ZERO_AUTHORITY:gE,stateZ:wE,transferString:bE},Symbol.toStringTag,{value:"Module"}));let ju=class{tasks;racks;devices;constructor(e,r,n){this.tasks=e,this.racks=r,this.devices=n}};const zE=Object.freeze(Object.defineProperty({__proto__:null,Client:ju},Symbol.toStringTag,{value:"Module"})),ve=i.z.uint32(),Mu=i.z.object({rack:ve}),Du=At.statusZ(Mu),hn=i.z.object({key:ve,name:i.z.string(),status:Bt.nullToUndefined(Du)}),Pu=hn.partial({key:!0}),Uu=t=>t?it.JSON_CODEC.decodeString(t,be.unknownZ):{},Ct=i.z.string(),Lu=i.z.object({rack:ve,device:Ct}),Bu=At.statusZ(Lu),fn=i.z.object({key:Ct,rack:ve.min(1,"Must select a location to connect from"),name:i.z.string().min(1,"Name is required"),make:i.z.string().min(1,"Make is required"),model:i.z.string().min(1,"Model is required"),location:i.z.string().min(1,"Location is required"),configured:i.z.boolean().optional(),properties:be.unknownZ.or(i.z.string().transform(Uu)),status:Bt.nullToUndefined(Bu)}),qu=fn.extend({properties:i.z.unknown().transform(t=>it.JSON_CODEC.encodeString(t))}),EE="sy_device_set",NE="sy_device_delete",OE="sy_device_status",$E="/hardware/device/retrieve",SE="/hardware/device/create",IE="/hardware/device/delete",AE=i.z.object({devices:qu.array()}),kE=i.z.object({devices:fn.array()}),xE=i.z.object({keys:Ct.array()}),ZE=i.z.object({}),CE=i.z.object({keys:Ct.array().optional(),names:i.z.string().array().optional(),makes:i.z.string().array().optional(),models:i.z.string().array().optional(),locations:i.z.string().array().optional(),racks:ve.array().optional(),searchTerm:i.z.string().optional(),limit:i.z.number().optional(),offset:i.z.number().optional(),includeStatus:i.z.boolean().optional()}),RE=i.z.object({devices:T.nullableZ(fn)}),_E=i.z.object({key:Ct,includeStatus:i.z.boolean().optional()}).transform(({key:t,includeStatus:e})=>({keys:[t],includeStatus:e})),jE=i.z.union([_E,CE]);let Fu=class{client;constructor(e){this.client=e}async retrieve(e){const r=typeof e=="object"&&"key"in e,n=await w(this.client,$E,e,jE,RE);ce("Device",e,n.devices,r);const s=n.devices;return r?s[0]:s}async create(e){const r=!Array.isArray(e),s=(await w(this.client,SE,{devices:T.toArray(e)},AE,kE)).devices;return r?s[0]:s}async delete(e){await w(this.client,IE,{keys:T.toArray(e)},xE,ZE)}};const ME=t=>({type:"device",key:t}),DE=Object.freeze(Object.defineProperty({__proto__:null,Client:Fu,DELETE_CHANNEL_NAME:NE,SET_CHANNEL_NAME:EE,STATUS_CHANNEL_NAME:OE,deviceZ:fn,keyZ:Ct,newZ:qu,ontologyID:ME,statusDetailsSchema:Lu,statusZ:Bu},Symbol.toStringTag,{value:"Module"})),PE="/hardware/rack/retrieve",UE="/hardware/rack/create",LE="/hardware/rack/delete",BE="sy_rack_status",qE="sy_rack_set",FE="sy_rack_delete",VE=i.z.object({keys:ve.array().optional(),names:i.z.string().array().optional(),searchTerm:i.z.string().optional(),embedded:i.z.boolean().optional(),hostIsNode:i.z.boolean().optional(),limit:i.z.number().optional(),offset:i.z.number().optional(),includeStatus:i.z.boolean().optional()}),YE=i.z.object({racks:T.nullableZ(hn)}),HE=i.z.union([i.z.object({key:ve,includeStatus:i.z.boolean().optional()}).transform(({key:t,includeStatus:e})=>({keys:[t],includeStatus:e})),i.z.object({name:i.z.string(),includeStatus:i.z.boolean().optional()}).transform(({name:t,includeStatus:e})=>({names:[t],includeStatus:e}))]),WE=VE,GE=i.z.union([HE,WE]),KE=i.z.object({racks:Pu.array()}),JE=i.z.object({racks:hn.array()}),XE=i.z.object({keys:ve.array()}),QE=i.z.object({});let Vu=class{client;tasks;constructor(e,r){this.client=e,this.tasks=r}async delete(e){await w(this.client,LE,{keys:T.toArray(e)},XE,QE)}async create(e){const r=!Array.isArray(e),n=await w(this.client,UE,{racks:T.toArray(e)},KE,JE),s=this.sugar(n.racks);return r?s[0]:s}async retrieve(e){const r="key"in e||"name"in e,n=await w(this.client,PE,e,GE,YE),s=this.sugar(n.racks);return ce("Rack",e,s,r),r?s[0]:s}sugar(e){const r=!Array.isArray(e),n=T.toArray(e).map(({key:s,name:a,status:o})=>new Yu(s,a,this.tasks,o));return r?n[0]:n}};class Yu{key;name;status;tasks;constructor(e,r,n,s){this.key=e,this.name=r,this.tasks=n,this.status=s}async listTasks(){return await this.tasks.retrieve({rack:this.key})}async createTask(e,r){return e.key=((BigInt(this.key)<<32n)+(BigInt(e.key??0)&0xffffffffn)).toString(),await this.tasks.create(e,r)}async deleteTask(e){await this.tasks.delete([e])}get payload(){return{key:this.key,name:this.name,status:this.status}}}const eN=t=>({type:"rack",key:t.toString()}),tN=Object.freeze(Object.defineProperty({__proto__:null,Client:Vu,DELETE_CHANNEL_NAME:FE,Rack:Yu,SET_CHANNEL_NAME:qE,STATUS_CHANNEL_NAME:BE,keyZ:ve,newZ:Pu,ontologyID:eN,rackZ:hn,statusDetailsSchema:Mu,statusZ:Du},Symbol.toStringTag,{value:"Module"})),Re=i.z.union([i.z.string(),i.z.bigint().transform(t=>t.toString()),i.z.number().transform(t=>t.toString())]),Hu=t=>i.z.object({task:Re,running:i.z.boolean(),data:t}),Xs=t=>At.statusZ(Hu(t)),pr=(t={typeSchema:i.z.string(),configSchema:i.z.unknown(),statusDataSchema:i.z.unknown()})=>i.z.object({key:Re,name:i.z.string(),type:t.typeSchema,internal:i.z.boolean().optional(),config:i.z.string().transform(Uu).or(t.configSchema),status:Xs(t.statusDataSchema).optional().nullable(),snapshot:i.z.boolean().optional()}),Wu=t=>pr(t).omit({key:!0}).extend({key:Re.transform(e=>e.toString()).optional(),config:i.z.unknown().transform(e=>it.JSON_CODEC.encodeString(e))}),rN=i.z.object({task:Re,type:i.z.string(),key:i.z.string(),args:be.unknownZ.or(i.z.string().transform(Ae)).or(i.z.array(i.z.unknown())).or(i.z.null()).optional()}),nN=t=>Number(BigInt(t)>>32n),ps="sy_task_status",ys="sy_task_cmd",sN="sy_task_set",iN="sy_task_delete",Qe=new Error("Task not created"),Gu=async(t,e)=>{const r=await e.retrieveParents(Qs(t));return r.length===0?null:r[0]};class Ku{key;name;internal;type;snapshot;config;status;schemas;frameClient_;ontologyClient_;rangeClient_;get frameClient(){if(this.frameClient_==null)throw Qe;return this.frameClient_}get ontologyClient(){if(this.ontologyClient_==null)throw Qe;return this.ontologyClient_}get rangeClient(){if(this.rangeClient_==null)throw Qe;return this.rangeClient_}constructor({key:e,type:r,name:n,config:s,internal:a=!1,snapshot:o=!1,status:c},l,u,h,d){this.key=e,this.name=n,this.type=r,this.config=s,this.schemas=l??{typeSchema:i.z.string(),configSchema:i.z.unknown(),statusDataSchema:i.z.unknown()},this.internal=a,this.snapshot=o,this.status=c,this.frameClient_=u,this.ontologyClient_=h,this.rangeClient_=d}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,status:this.status,internal:this.internal}}get ontologyID(){return Qs(this.key)}async executeCommand(e){return await Qu({...e,frameClient:this.frameClient,task:this.key})}async executeCommandSync(e){return await el({...e,frameClient:this.frameClient,task:this.key,name:this.name,statusDataZ:this.schemas?.statusDataSchema})}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw Qe;return this.snapshot?await Gu(this.key,this.ontologyClient):null}}const aN=i.z.object({rack:ve.optional(),keys:Re.array().optional(),names:i.z.string().array().optional(),types:i.z.string().array().optional(),includeStatus:i.z.boolean().optional(),internal:i.z.boolean().optional(),snapshot:i.z.boolean().optional(),searchTerm:i.z.string().optional(),offset:i.z.number().optional(),limit:i.z.number().optional()}),Ju=i.z.union([i.z.object({key:Re,includeStatus:i.z.boolean().optional()}).transform(({key:t,includeStatus:e})=>({keys:[t],includeStatus:e})),i.z.object({name:i.z.string(),includeStatus:i.z.boolean().optional()}).transform(({name:t,includeStatus:e})=>({names:[t],includeStatus:e})),i.z.object({type:i.z.string(),rack:ve.optional()}).transform(({type:t,rack:e})=>({types:[t],rack:e}))]),oN=aN,cN=i.z.union([Ju,oN]),uN=t=>i.z.object({tasks:T.nullableZ(pr(t))}),lN="/hardware/task/retrieve",hN="/hardware/task/create",fN="/hardware/task/delete",dN="/hardware/task/copy",pN=t=>i.z.object({tasks:Wu(t).array()}),yN=t=>i.z.object({tasks:pr(t).array()}),mN=i.z.object({keys:Re.array()}),gN=i.z.object({}),wN=i.z.object({key:Re,name:i.z.string(),snapshot:i.z.boolean()}),bN=t=>i.z.object({task:pr(t)});let Xu=class{type="task";client;frameClient;ontologyClient;rangeClient;constructor(e,r,n,s){this.client=e,this.frameClient=r,this.ontologyClient=n,this.rangeClient=s}async create(e,r){const n=!Array.isArray(e),s=pN(r),a=yN(r),o=await w(this.client,hN,{tasks:T.toArray(e)},s,a),c=this.sugar(o.tasks,r);return n?c[0]:c}async delete(e){await w(this.client,fN,{keys:T.toArray(e)},mN,gN)}async retrieve({schemas:e,...r}){const n=Ju.safeParse(r).success,a=(await w(this.client,lN,r,cN,uN(e))).tasks,o=this.sugar(a,e);return ce("Task",r,o,n),n?o[0]:o}async copy(e,r,n){const s=bN(),a=await w(this.client,dN,{key:e,name:r,snapshot:n},wN,s);return this.sugar(a.task)}async retrieveSnapshottedTo(e){if(this.ontologyClient==null)throw Qe;return await Gu(e,this.ontologyClient)}sugar(e,r){const n=!Array.isArray(e),s=T.toArray(e).map(({key:a,name:o,type:c,config:l,status:u,internal:h,snapshot:d})=>new Ku({key:a,name:o,type:c,config:l,internal:h,snapshot:d,status:u},r,this.frameClient,this.ontologyClient,this.rangeClient));return n?s[0]:s}async executeCommand(e){return"commands"in e?await ei({...e,frameClient:this.frameClient}):await Qu({...e,frameClient:this.frameClient})}async executeCommandSync(e){if("commands"in e){const n=async()=>{const{commands:s}=e;return(await this.retrieve({keys:s.map(o=>o.task)})).map(o=>o.name)};return await tl({...e,frameClient:this.frameClient,name:n})}const r=async()=>{const{task:n}=e;return(await this.retrieve({key:n})).name};return await el({frameClient:this.frameClient,name:r,...e})}};const Qs=t=>({type:"task",key:t}),Qu=async({frameClient:t,task:e,type:r,args:n})=>(await ei({frameClient:t,commands:[{args:n,task:e,type:r}]}))[0],ei=async({frameClient:t,commands:e})=>{if(t==null)throw Qe;const r=await t.openWriter(ys),n=e.map(s=>({...s,key:vp.create()}));return await r.write(ys,n),await r.close(),n.map(s=>s.key)},el=async({frameClient:t,task:e,type:r,timeout:n,name:s,statusDataZ:a,args:o})=>(await tl({frameClient:t,commands:[{args:o,task:e,type:r}],timeout:n,statusDataZ:a,name:s}))[0],tl=async({frameClient:t,commands:e,timeout:r=I.seconds(10),statusDataZ:n,name:s})=>{if(t==null)throw Qe;const a=await t.openStreamer(ps),o=await ei({frameClient:t,commands:e}),c=new I(r);let l=[],u;const h=new Promise((d,f)=>{u=setTimeout(()=>{(async()=>{const v=e.map(S=>S.task);f(await vN("command",s,c,v))})()},c.milliseconds)});try{for(;;){const d=await Promise.race([a.read(),h]),f=Xs(n).parse(d.at(-1)[ps]);if(o.includes(f.key)&&(l=[...l.filter(v=>v.key!==f.key),f],l.length===o.length))return l}}finally{clearTimeout(u),a.close()}},vN=async(t,e,r,n)=>{const s=td.capitalize(t),a=r.toString();try{let o;typeof e=="string"?o=[e]:Array.isArray(e)?o=e:o=T.toArray(await e());const c=ns.naturalLanguageJoin(o);return new Error(`${s} command to ${c} timed out after ${a}`)}catch(o){return console.error("Failed to retrieve task name for timeout error:",o),new Error(`${s} command to task with key ${ns.naturalLanguageJoin(n)} timed out after ${a}`)}},TN=Object.freeze(Object.defineProperty({__proto__:null,COMMAND_CHANNEL_NAME:ys,Client:Xu,DELETE_CHANNEL_NAME:iN,SET_CHANNEL_NAME:sN,STATUS_CHANNEL_NAME:ps,Task:Ku,commandZ:rN,keyZ:Re,newZ:Wu,ontologyID:Qs,rackKey:nN,statusDetailsZ:Hu,statusZ:Xs,taskZ:pr},Symbol.toStringTag,{value:"Module"})),Ge=ic.keyZ,yr=ic.labelZ,zN="labeled_by",EN="sy_label_set",NN="sy_label_delete",rl=yr.extend({key:Ge.optional()}),ON=i.object({labels:rl.array()}),$N=i.object({labels:yr.array()}),SN=i.object({keys:Ge.array()}),nl=i.object({id:j,labels:Ge.array(),replace:i.boolean().optional()}),IN=nl.omit({replace:!0}),xn=i.object({}),AN="/label/create",kN="/label/delete",xN="/label/set",ZN="/label/remove",CN="/label/retrieve",RN=i.object({keys:Ge.array().optional(),for:j.optional(),searchTerm:i.string().optional(),offset:i.number().optional(),limit:i.number().optional()}),_N=i.object({key:Ge}).transform(({key:t})=>({keys:[t]})),jN=i.union([_N,RN]),MN=i.object({labels:T.nullableZ(yr)});let sl=class{type="label";client;constructor(e){this.client=e}async retrieve(e){const r="key"in e,n=await w(this.client,CN,e,jN,MN);return ce("Label",e,n.labels,r),r?n.labels[0]:n.labels}async label(e,r,n={}){await w(this.client,xN,{id:e,labels:r,replace:n.replace},nl,xn)}async remove(e,r){await w(this.client,ZN,{id:e,labels:r},IN,xn)}async create(e){const r=Array.isArray(e),n=await w(this.client,AN,{labels:T.toArray(e)},ON,$N);return r?n.labels:n.labels[0]}async delete(e){await w(this.client,kN,{keys:T.toArray(e)},SN,xn)}};const DN=t=>({type:"label",key:t}),PN=Object.freeze(Object.defineProperty({__proto__:null,Client:sl,DELETE_CHANNEL_NAME:NN,LABELED_BY_ONTOLOGY_RELATIONSHIP_TYPE:zN,SET_CHANNEL_NAME:EN,keyZ:Ge,labelZ:yr,newZ:rl,ontologyID:DN},Symbol.toStringTag,{value:"Module"})),ee=i.z.uuid(),ti=i.z.string().min(1),mr=i.z.object({key:ee,name:ti,timeRange:D.z.refine(({isValid:t})=>t,{error:"Time range start time must be before or equal to time range end time"}).refine(({end:t})=>t.valueOf()<=Qn.MAX_INT64,{error:"Time range end time must be less than or equal to the maximum value of an int64"}).refine(({start:t})=>t.valueOf()>=Qn.MIN_INT64,{error:"Time range start time must be greater than or equal to the minimum value of an int64"}),color:i.z.string().optional(),labels:yr.array().or(i.z.null().transform(()=>{})).optional(),get parent(){return mr.optional().nullable().transform(t=>t===void 0?null:t)}}),il=mr.omit({parent:!0,labels:!0}).partial({key:!0}),UN="sy_range_alias_set",LN="sy_range_alias_delete",BN=i.z.object({range:ee,aliases:i.z.string().array()}),qN=i.z.object({aliases:i.z.record(i.z.string(),U)}),FN=i.z.object({range:ee,aliases:i.z.record(U,i.z.string())}),VN=i.z.unknown(),YN=i.z.object({range:ee,channels:U.array()}),HN=i.z.unknown(),WN=i.z.object({range:ee}),GN=i.z.object({aliases:i.z.record(i.z.string(),i.z.string())}),KN=i.z.object({range:ee,channels:U.array()}),JN=i.z.object({aliases:i.z.record(i.z.string(),i.z.string())});class oe{static SET_ENDPOINT="/range/alias/set";static RESOLVE_ENDPOINT="/range/alias/resolve";static LIST_ENDPOINT="/range/alias/list";static RETRIEVE_ENDPOINT="/range/alias/retrieve";static DELETE_ENDPOINT="/range/alias/delete";frameClient;cache=new Map;client;rangeKey;constructor(e,r,n){this.rangeKey=e,this.cache=new Map,this.client=n,this.frameClient=r}async resolve(e){const r=[],n=typeof e=="string",s={};if(n){const o=this.cache.get(e);if(o!=null)return o;r.push(e)}else e.forEach(o=>{const c=this.cache.get(o);c!=null?s[o]=c:r.push(o)});if(r.length===0)return s;const a=await w(this.client,oe.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:r},BN,qN);return Object.entries(a.aliases).forEach(([o,c])=>this.cache.set(o,c)),n?a.aliases[r[0]]:{...s,...a.aliases}}async set(e){await w(this.client,oe.SET_ENDPOINT,{range:this.rangeKey,aliases:e},FN,VN)}async list(){return(await w(this.client,oe.LIST_ENDPOINT,{range:this.rangeKey},WN,GN)).aliases}async retrieve(e){const r=typeof e=="number",n=await w(this.client,oe.RETRIEVE_ENDPOINT,{range:this.rangeKey,channels:T.toArray(e)},KN,JN);return r?n.aliases[e]:n.aliases}async delete(e){await w(this.client,oe.DELETE_ENDPOINT,{range:this.rangeKey,channels:T.toArray(e)},YN,HN)}}const XN=i.z.object({alias:i.z.string().optional(),channel:U,range:ee}),al="---",QN=t=>`${t.range}${al}${t.channel}`,eO=t=>{const[e,r]=t.split(al);return{range:e,channel:Number(r)}},tO="sy_range_kv_set",rO="sy_range_kv_delete",ri=i.z.object({range:ee,key:i.z.string(),value:i.z.string()}),nO=({range:t,key:e})=>`${t}<--->${e}`,sO=i.z.object({range:ee,keys:i.z.string().array()}),iO=i.z.object({pairs:T.nullableZ(ri)}),aO=i.z.object({range:ee,pairs:ri.array()}),oO=i.z.object({range:ee,keys:i.z.string().array()});class tt{static GET_ENDPOINT="/range/kv/get";static SET_ENDPOINT="/range/kv/set";static DELETE_ENDPOINT="/range/kv/delete";rangeKey;client;constructor(e,r){this.rangeKey=e,this.client=r}async get(e){const r=await w(this.client,tt.GET_ENDPOINT,{range:this.rangeKey,keys:T.toArray(e)},sO,iO);return typeof e=="string"?r.pairs[0].value:Object.fromEntries(r.pairs.map(n=>[n.key,n.value]))}async list(){return this.get([])}async set(e,r=""){let n;Wa(e)?n=Object.entries(e).map(([s,a])=>({range:this.rangeKey,key:s,value:a})):n=[{range:this.rangeKey,key:e,value:r}],await w(this.client,tt.SET_ENDPOINT,{range:this.rangeKey,pairs:n},aO,i.z.unknown())}async delete(e){await w(this.client,tt.DELETE_ENDPOINT,{range:this.rangeKey,keys:T.toArray(e)},oO,i.z.unknown())}}const cO="sy_range_set",uO="sy_range_delete";class ol{key;name;kv;timeRange;color;parent;labels;channels;aliaser;frameClient;labelClient;ontologyClient;rangeClient;constructor({name:e,timeRange:r=D.ZERO,key:n,color:s,parent:a,labels:o},{frameClient:c,kv:l,aliaser:u,channels:h,labelClient:d,ontologyClient:f,rangeClient:v}){this.key=n,this.name=e,this.timeRange=r,this.parent=a,this.labels=o,this.frameClient=c,this.color=s,this.kv=l,this.aliaser=u,this.channels=h,this.labelClient=d,this.ontologyClient=f,this.rangeClient=v}get ontologyID(){return yt(this.key)}get payload(){let e=null;return this.parent!=null&&("payload"in this.parent?e=this.parent.payload:e=this.parent),{key:this.key,name:this.name,timeRange:this.timeRange,color:this.color,labels:this.labels,parent:e}}async setAlias(e,r){const n=await this.channels.retrieve(e);if(n.length===0)throw new Ve(`Channel ${e} does not exist`);await this.aliaser.set({[n[0].key]:r})}async deleteAlias(...e){await this.aliaser.delete(e)}async listAliases(){return await this.aliaser.list()}async resolveAlias(e){return await this.aliaser.resolve(e)}async retrieveParent(){return this.rangeClient.retrieveParent(this.key)}async retrieveChildren(){const e=(await this.ontologyClient.retrieveChildren(this.ontologyID,{excludeFieldData:!0,types:["range"]})).map(r=>r.id.key);return await this.rangeClient.retrieve(e)}async read(e){return await this.frameClient.read(this.timeRange,e)}async retrieveLabels(){return await this.labelClient.retrieve({for:yt(this.key)})}async addLabel(...e){await this.labelClient.label(yt(this.key),e)}async removeLabel(...e){await this.labelClient.remove(yt(this.key),e)}static sort(e,r){return D.sort(e.timeRange,r.timeRange)}}const lO=i.z.object({keys:ee.array().optional(),names:i.z.array(i.z.string()).optional(),searchTerm:i.z.string().optional(),overlapsWith:D.z.optional(),limit:i.z.number().int().optional(),offset:i.z.number().int().optional(),hasLabels:Ge.array().optional(),includeLabels:i.z.boolean().optional(),includeParent:i.z.boolean().optional()}),hO=lO.or(ee.array().transform(t=>({keys:t}))).or(ee.transform(t=>({keys:[t]}))).or(i.z.string().transform(t=>({names:[t]}))).or(i.z.string().array().transform(t=>({names:t}))).or(D.z.transform(t=>({overlapsWith:t}))),fO="/range/retrieve",dO=i.z.object({ranges:T.nullableZ(mr)});let cl=class{type="range";frameClient;writer;unaryClient;channels;labelClient;ontologyClient;constructor(e,r,n,s,a,o){this.frameClient=e,this.writer=r,this.unaryClient=n,this.channels=s,this.labelClient=a,this.ontologyClient=o}async create(e,r){const n=!Array.isArray(e),s=this.sugarMany(await this.writer.create(T.toArray(e),r));return n?s[0]:s}async rename(e,r){await this.writer.rename(e,r)}async delete(e){await this.writer.delete(T.toArray(e))}async retrieve(e){const r=typeof e=="string",{ranges:n}=await w(this.unaryClient,fO,e,hO,dO);return ce("Range",e,n,r),r?this.sugarMany(n)[0]:this.sugarMany(n)}getKV(e){return new tt(e,this.unaryClient)}async retrieveParent(e){const r=await this.ontologyClient.retrieveParents(yt(e));if(r.length===0)return null;const n=r[0];return n.id.type!=="range"?null:await this.retrieve(n.id.key)}sugarOntologyResource(e){return this.sugarOne(ul(e))}async retrieveAlias(e,r){return await new oe(e,this.frameClient,this.unaryClient).retrieve(r)}async retrieveAliases(e,r){return await new oe(e,this.frameClient,this.unaryClient).retrieve(r)}async listAliases(e){return await new oe(e,this.frameClient,this.unaryClient).list()}async setAlias(e,r,n){await new oe(e,this.frameClient,this.unaryClient).set({[r]:n})}async deleteAlias(e,r){await new oe(e,this.frameClient,this.unaryClient).delete(r)}sugarOne(e){return new ol(e,{frameClient:this.frameClient,kv:new tt(e.key,this.unaryClient),aliaser:new oe(e.key,this.frameClient,this.unaryClient),channels:this.channels,labelClient:this.labelClient,ontologyClient:this.ontologyClient,rangeClient:this})}sugarMany(e){return e.map(r=>this.sugarOne(r))}resourceToRange(e){return this.sugarOne({key:e.id.key,name:e.data?.name,timeRange:new D(e.data?.timeRange),color:e.data?.color,labels:[],parent:null})}};const yt=t=>({type:"range",key:t}),pO=t=>({type:"range-alias",key:t}),ul=({data:t,id:{key:e},name:r})=>{const n=D.z.parse(t?.timeRange);return{key:e,name:r,timeRange:n,color:typeof t?.color=="string"?t.color:void 0,labels:[],parent:null}},yO=i.z.object({ranges:mr.array()}),mO=i.z.object({parent:j.optional(),ranges:il.array()}),gO=i.z.object({keys:ee.array()}),wO=i.z.object({}),bO=i.z.object({key:ee,name:ti}),vO=i.z.object({}),TO="/range/create",zO="/range/delete",EO="/range/rename";class ll{client;constructor(e){this.client=e}async rename(e,r){await w(this.client,EO,{key:e,name:r},bO,vO)}async create(e,r){return(await w(this.client,TO,{ranges:e,...r},mO,yO)).ranges}async delete(e){await w(this.client,zO,{keys:e},gO,wO)}}const NO=Object.freeze(Object.defineProperty({__proto__:null,Aliaser:oe,Client:cl,DELETE_ALIAS_CHANNEL_NAME:LN,DELETE_CHANNEL_NAME:uO,KV:tt,KV_DELETE_CHANNEL:rO,KV_SET_CHANNEL:tO,Range:ol,SET_ALIAS_CHANNEL_NAME:UN,SET_CHANNEL_NAME:cO,Writer:ll,aliasKey:QN,aliasOntologyID:pO,aliasZ:XN,convertOntologyResourceToPayload:ul,decodeDeleteAliasChange:eO,keyZ:ee,kvPairKey:nO,kvPairZ:ri,nameZ:ti,newZ:il,ontologyID:yt,payloadZ:mr},Symbol.toStringTag,{value:"Module"})),OO=t=>i.object({parent:j.optional(),statuses:Wc(t).array()}),$O=t=>i.object({statuses:lr(t).array()}),SO=i.object({keys:sn.array()}),IO=i.object({}),AO="/status/set",kO="/status/delete",xO="/status/retrieve",ZO=i.object({keys:sn.array().optional(),searchTerm:i.string().optional(),offset:i.number().optional(),limit:i.number().optional(),includeLabels:i.boolean().optional(),hasLabels:Ge.array().optional()}),CO=i.object({key:sn,includeLabels:i.boolean().optional()}).transform(({key:t,includeLabels:e})=>({keys:[t],includeLabels:e})),RO=i.union([CO,ZO]),_O=t=>i.object({statuses:T.nullableZ(lr(t))});let hl=class{type="status";client;constructor(e){this.client=e}async retrieve(e){const r="key"in e,n=await w(this.client,xO,e,RO,_O(e.detailsSchema));ce("Status",e,n.statuses,r);const s=n.statuses;return r?s[0]:s}async set(e,r={}){const n=Array.isArray(e),a=(await w(this.client,AO,{statuses:T.toArray(e),parent:r.parent},OO(r.detailsSchema),$O(r.detailsSchema))).statuses;return n?a:a[0]}async delete(e){await w(this.client,kO,{keys:T.toArray(e)},SO,IO)}};const jO=Object.freeze(Object.defineProperty({__proto__:null,Client:hl,DELETE_CHANNEL_NAME:ET,SET_CHANNEL_NAME:zT,keyZ:sn,newZ:Wc,ontologyID:NT,statusZ:lr},Symbol.toStringTag,{value:"Module"})),MO="/api/v1/";class DO{url;unary;stream;secure;constructor(e,r={},n=!1){this.secure=n,this.url=e.child(MO);const s=new it.JSONCodec;this.unary=Pf(new Df(this.url,s,this.secure),r),this.stream=new _r(this.url,s,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const ot=i.z.uuid(),dn=i.z.object({key:ot,name:i.z.string(),data:be.unknownZ.or(i.z.string().transform(Ae))}),fl=dn.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),ke=i.z.uuid(),pn=i.z.object({key:ke,name:i.z.string().min(1,"Name is required"),layout:be.unknownZ.or(i.z.string().transform(Ae))}),dl=pn.partial({key:!0}).transform(t=>({...t,layout:JSON.stringify(t.layout)})),pl=pn.omit({layout:!0}).extend({layout:i.z.string().transform(Ae)}),PO="/workspace/lineplot/retrieve",UO="/workspace/lineplot/create",LO="/workspace/lineplot/rename",BO="/workspace/lineplot/set-data",qO="/workspace/lineplot/delete",FO=i.z.object({key:ot,name:i.z.string()}),VO=i.z.object({key:ot,data:i.z.string()}),YO=i.z.object({keys:ot.array()}),HO=i.z.object({keys:ot.array()}),yl=i.z.object({key:ot}).transform(({key:t})=>({keys:[t]})),ml=i.z.union([yl,HO]),WO=i.z.object({linePlots:T.nullableZ(dn)}),GO=i.z.object({workspace:ke,linePlots:fl.array()}),KO=i.z.object({linePlots:dn.array()}),Zn=i.z.object({});let gl=class{client;constructor(e){this.client=e}async create(e,r){const n=Array.isArray(r),s=await w(this.client,UO,{workspace:e,linePlots:T.toArray(r)},GO,KO);return n?s.linePlots:s.linePlots[0]}async rename(e,r){await w(this.client,LO,{key:e,name:r},FO,Zn)}async setData(e,r){await w(this.client,BO,{key:e,data:JSON.stringify(r)},VO,Zn)}async retrieve(e){const r=yl.safeParse(e).success,n=await w(this.client,PO,e,ml,WO);return ce("LinePlot",e,n.linePlots,r),r?n.linePlots[0]:n.linePlots}async delete(e){await w(this.client,qO,{keys:T.toArray(e)},YO,Zn)}};const JO=t=>({type:"lineplot",key:t}),XO=Object.freeze(Object.defineProperty({__proto__:null,Client:gl,keyZ:ot,linePlotZ:dn,newZ:fl,ontologyID:JO,retrieveArgsZ:ml},Symbol.toStringTag,{value:"Module"})),ct=i.z.uuid(),yn=i.z.object({key:ct,name:i.z.string(),data:be.unknownZ.or(i.z.string().transform(Ae))}),wl=yn.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),QO="/workspace/log/retrieve",e$="/workspace/log/create",t$="/workspace/log/rename",r$="/workspace/log/set-data",n$="/workspace/log/delete",s$=i.z.object({key:ct,name:i.z.string()}),i$=i.z.object({key:ct,data:i.z.string()}),a$=i.z.object({keys:ct.array()}),o$=i.z.object({keys:ct.array()}),bl=i.z.object({key:ct}).transform(({key:t})=>({keys:[t]})),vl=i.z.union([bl,o$]),c$=i.z.object({logs:T.nullableZ(yn)}),u$=i.z.object({workspace:ke,logs:wl.array()}),l$=i.z.object({logs:yn.array()}),Cn=i.z.object({});let Tl=class{client;constructor(e){this.client=e}async create(e,r){const n=Array.isArray(r),s=await w(this.client,e$,{workspace:e,logs:T.toArray(r)},u$,l$);return n?s.logs:s.logs[0]}async rename(e,r){await w(this.client,t$,{key:e,name:r},s$,Cn)}async setData(e,r){await w(this.client,r$,{key:e,data:JSON.stringify(r)},i$,Cn)}async retrieve(e){const r=bl.safeParse(e).success,n=await w(this.client,QO,e,vl,c$);return ce("Log",e,n.logs,r),r?n.logs[0]:n.logs}async delete(e){await w(this.client,n$,{keys:T.toArray(e)},a$,Cn)}};const h$=t=>({type:"log",key:t}),f$=Object.freeze(Object.defineProperty({__proto__:null,Client:Tl,keyZ:ct,logZ:yn,newZ:wl,ontologyID:h$,retrieveArgsZ:vl},Symbol.toStringTag,{value:"Module"})),Ke=i.z.uuid(),mn=i.z.object({key:Ke,name:i.z.string(),data:be.unknownZ.or(i.z.string().transform(Ae)),snapshot:i.z.boolean()}),zl=mn.partial({key:!0,snapshot:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),ni=mn.extend({data:i.z.string().transform(Ae)}),Rt=i.z.uuid(),El=i.z.object({key:i.z.string(),name:i.z.string(),selectors:i.z.string().array().default([]),strokeColor:i.z.string().optional(),fillColor:i.z.string().optional()}),Nl=i.z.object({key:i.z.string(),name:i.z.string(),regions:El.array()}),Ol=i.z.object({key:i.z.string(),position:As.xy,orientation:Vd.outer}),d$=i.z.object({zoom:i.z.number().positive().default(1),position:As.xy}),$l=i.z.object({svg:i.z.string().min(1,"SVG is required"),states:Nl.array(),variant:i.z.string().min(1,"Variant is required"),handles:Ol.array(),scale:i.z.number().positive().default(1),scaleStroke:i.z.boolean().default(!1),previewViewport:d$.default({zoom:1,position:{x:0,y:0}})}),gn=i.z.object({key:Rt,version:i.z.literal(1).optional().default(1),name:i.z.string().min(1,"Name is required"),data:$l}),Sl=gn.partial({key:!0}),p$="/workspace/schematic/symbol/retrieve",y$="/workspace/schematic/symbol/create",m$="/workspace/schematic/symbol/rename",g$="/workspace/schematic/symbol/delete",w$="/workspace/schematic/symbol/retrieve_group",b$=i.z.object({symbols:Sl.array(),parent:j}),v$=i.z.object({key:Rt,name:i.z.string()}),T$=i.z.object({keys:Rt.array()}),z$=i.z.object({keys:Rt.array().optional(),searchTerm:i.z.string().optional(),offset:i.z.number().optional(),limit:i.z.number().optional()}),E$=i.z.object({key:Rt}).transform(({key:t})=>({keys:[t]})),N$=i.z.union([E$,z$]),O$=i.z.object({symbols:T.nullableZ(gn)}),$$=i.z.object({symbols:gn.array()}),da=i.z.object({}),S$=i.z.object({}),I$=i.z.object({group:Jr}),A$="sy_schematic_symbol_set",k$="sy_schematic_symbol_delete";let Il=class{client;constructor(e){this.client=e}async create(e){const r="symbols"in e,n=r?e.symbols:[e],s=await w(this.client,y$,{symbols:n,parent:e.parent},b$,$$);return r?s.symbols:s.symbols[0]}async rename(e,r){await w(this.client,m$,{key:e,name:r},v$,da)}async retrieve(e){const r="key"in e,n=await w(this.client,p$,e,N$,O$);return ce("Schematic Symbol",e,n.symbols,r),r?n.symbols[0]:n.symbols}async delete(e){await w(this.client,g$,{keys:T.toArray(e)},T$,da)}async retrieveGroup(){return(await w(this.client,w$,{},S$,I$)).group}};const x$=t=>({type:"schematic_symbol",key:t}),Z$=Object.freeze(Object.defineProperty({__proto__:null,Client:Il,DELETE_CHANNEL_NAME:k$,SET_CHANNEL_NAME:A$,handleZ:Ol,keyZ:Rt,newZ:Sl,ontologyID:x$,regionZ:El,specZ:$l,stateZ:Nl,symbolZ:gn},Symbol.toStringTag,{value:"Module"})),C$="/workspace/schematic/retrieve",R$="/workspace/schematic/create",_$="/workspace/schematic/rename",j$="/workspace/schematic/set-data",M$="/workspace/schematic/delete",D$="/workspace/schematic/copy",P$=i.z.object({key:Ke,name:i.z.string()}),U$=i.z.object({key:Ke,data:i.z.string()}),L$=i.z.object({keys:Ke.array()}),B$=i.z.object({key:Ke,name:i.z.string(),snapshot:i.z.boolean()}),q$=i.z.object({keys:Ke.array()}),Al=i.z.object({key:Ke}).transform(({key:t})=>({keys:[t]})),kl=i.z.union([Al,q$]),F$=i.z.object({schematics:T.nullableZ(ni)}),V$=i.z.object({workspace:ke,schematics:zl.array()}),Y$=i.z.object({schematics:ni.array()}),H$=i.z.object({schematic:mn}),Rn=i.z.object({});let xl=class{symbols;client;constructor(e){this.client=e,this.symbols=new Il(e)}async create(e,r){const n=Array.isArray(r),s=await w(this.client,R$,{workspace:e,schematics:T.toArray(r)},V$,Y$);return n?s.schematics:s.schematics[0]}async rename(e,r){await w(this.client,_$,{key:e,name:r},P$,Rn)}async setData(e,r){await w(this.client,j$,{key:e,data:JSON.stringify(r)},U$,Rn)}async retrieve(e){const r=Al.safeParse(e).success,n=await w(this.client,C$,e,kl,F$);return ce("Schematic",e,n.schematics,r),r?n.schematics[0]:n.schematics}async delete(e){await w(this.client,M$,{keys:T.toArray(e)},L$,Rn)}async copy(e){return(await w(this.client,D$,e,B$,H$)).schematic}};const W$=t=>({type:"schematic",key:t}),G$=Object.freeze(Object.defineProperty({__proto__:null,Client:xl,keyZ:Ke,newZ:zl,ontologyID:W$,remoteZ:ni,retrieveArgsZ:kl,schematicZ:mn,symbol:Z$},Symbol.toStringTag,{value:"Module"})),ut=i.z.uuid(),si=i.z.object({key:ut,name:i.z.string(),data:be.unknownZ.or(i.z.string().transform(Ae))}),Zl=si.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),ii=si.extend({data:i.z.string().transform(Ae)}),K$="/workspace/table/retrieve",J$="/workspace/table/create",X$="/workspace/table/rename",Q$="/workspace/table/set-data",eS="/workspace/table/delete",tS=i.z.object({key:ut,name:i.z.string()}),rS=i.z.object({key:ut,data:i.z.string()}),nS=i.z.object({keys:ut.array()}),sS=i.z.object({keys:ut.array()}),Cl=i.z.object({key:ut}).transform(({key:t})=>({keys:[t]})),Rl=i.z.union([Cl,sS]),iS=i.z.object({tables:T.nullableZ(ii)}),aS=i.z.object({workspace:ke,tables:Zl.array()}),oS=i.z.object({tables:ii.array()}),_n=i.z.object({});let _l=class{client;constructor(e){this.client=e}async create(e,r){const n=Array.isArray(r),s=await w(this.client,J$,{workspace:e,tables:T.toArray(r)},aS,oS);return n?s.tables:s.tables[0]}async rename(e,r){await w(this.client,X$,{key:e,name:r},tS,_n)}async setData(e,r){await w(this.client,Q$,{key:e,data:JSON.stringify(r)},rS,_n)}async retrieve(e){const r=Cl.safeParse(e).success,n=await w(this.client,K$,e,Rl,iS);return ce("Table",e,n.tables,r),r?n.tables[0]:n.tables}async delete(e){await w(this.client,eS,{keys:T.toArray(e)},nS,_n)}};const cS=t=>({type:"table",key:t}),uS=Object.freeze(Object.defineProperty({__proto__:null,Client:_l,keyZ:ut,newZ:Zl,ontologyID:cS,remoteZ:ii,retrieveArgsZ:Rl,tableZ:si},Symbol.toStringTag,{value:"Module"})),pa="/workspace/retrieve",lS="/workspace/create",hS="/workspace/rename",fS="/workspace/set-layout",dS="/workspace/delete",ya=i.z.object({keys:ke.array().optional(),searchTerm:i.z.string().optional(),author:We.optional(),offset:i.z.number().optional(),limit:i.z.number().optional()}),pS=i.z.object({workspaces:dl.array()}),yS=i.z.object({key:ke,name:i.z.string()}),mS=i.z.object({key:ke,layout:be.unknownZ.transform(t=>JSON.stringify(t))}),gS=i.z.object({keys:ke.array()}),ma=i.z.object({workspaces:T.nullableZ(pn)}),wS=i.z.object({workspaces:pl.array()}),jn=i.z.object({}),bS="sy_workspace_set",vS="sy_workspace_delete";class jl{schematics;lineplots;logs;tables;client;constructor(e){this.client=e,this.schematics=new xl(e),this.lineplots=new gl(e),this.logs=new Tl(e),this.tables=new _l(e)}async create(e){const r=Array.isArray(e),n=await w(this.client,lS,{workspaces:T.toArray(e)},pS,wS);return r?n.workspaces:n.workspaces[0]}async rename(e,r){await w(this.client,hS,{key:e,name:r},yS,jn)}async setLayout(e,r){await w(this.client,fS,{key:e,layout:r},mS,jn)}async retrieve(e){let r;const n=typeof e!="string";typeof e=="string"||Array.isArray(e)?r={keys:T.toArray(e)}:r=e;const s=await w(this.client,pa,r,ya,ma);return n?s.workspaces:s.workspaces[0]}async retrieveByAuthor(e){return(await w(this.client,pa,{author:e},ya,ma)).workspaces}async delete(e){await w(this.client,dS,{keys:T.toArray(e)},gS,jn)}}const TS=t=>({type:"workspace",key:t}),zS=Object.freeze(Object.defineProperty({__proto__:null,Client:jl,DELETE_CHANNEL_NAME:vS,SET_CHANNEL_NAME:bS,keyZ:ke,newZ:dl,ontologyID:TS,remoteZ:pl,workspaceZ:pn},Symbol.toStringTag,{value:"Module"})),Ml=i.z.object({host:i.z.string({error:"Host is required"}).min(1,"Host is required"),port:i.z.number({error:"Port is required"}).or(i.z.string({error:"Port is required"})),username:i.z.string().min(1,"Username is required"),password:i.z.string().min(1,"Password is required"),connectivityPollFrequency:I.z.default(I.seconds(30)),secure:i.z.boolean().optional().default(!1),name:i.z.string().optional(),retry:Fo.breakerConfigZ.optional()});class Dl extends Zu{createdAt;props;ranges;channels;auth;users;access;connectivity;ontology;workspaces;labels;statuses;hardware;control;arcs;static connectivity=Qt;transport;clientVersion="0.47.0";constructor(e){const r=Ml.parse(e),{host:n,port:s,username:a,password:o,connectivityPollFrequency:c,secure:l,retry:u}=r,h=new DO(new Lt({host:n,port:Number(s)}),u,l);h.use(wm);let d;a!=null&&o!=null&&(d=new qz(h.unary,{username:a,password:o}),h.use(d.middleware()));const f=new Hs(new fr(h.unary)),v=new pu(h.unary,f);super(h.stream,h.unary,f),this.createdAt=p.now(),this.props=r,this.auth=d,this.transport=h,this.channels=new hu(this,f,h.unary,v),this.connectivity=new Qt(h.unary,c,this.clientVersion,r.name),this.control=new _u(this),this.ontology=new bc(h.unary,this);const S=new ll(this.transport.unary);this.labels=new sl(this.transport.unary),this.statuses=new hl(this.transport.unary),this.ranges=new cl(this,S,this.transport.unary,f,this.labels,this.ontology),this.access=new zc(this.transport.unary),this.users=new mu(this.transport.unary),this.workspaces=new jl(this.transport.unary);const Z=new Fu(this.transport.unary),b=new Xu(this.transport.unary,this,this.ontology,this.ranges),z=new Vu(this.transport.unary,b);this.hardware=new ju(b,z,Z),this.arcs=new nu(this.transport.unary,this.transport.stream)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}const Pl={host:"localhost",port:9090,username:"synnax",password:"seldon",retry:{maxRetries:4,baseInterval:I.seconds(1),scale:1.5}},ES=t=>new Dl({...Pl,...t});exports.AuthError=Wt;exports.Channel=Br;exports.ContiguityError=ym;exports.DataType=R;exports.Density=Q;exports.DisconnectedError=pm;exports.Frame=H;exports.MultiSeries=Po;exports.MultipleFoundError=Kt;exports.NotFoundError=Gt;exports.QueryError=Ve;exports.Rate=ne;exports.RouteError=as;exports.Series=xe;exports.Synnax=Dl;exports.TEST_CLIENT_PROPS=Pl;exports.TimeRange=D;exports.TimeSpan=I;exports.TimeStamp=p;exports.UnexpectedError=wt;exports.ValidationError=Y;exports.access=hg;exports.arc=qT;exports.channel=pz;exports.connection=Vz;exports.control=TE;exports.createTestClient=ES;exports.device=DE;exports.framer=yE;exports.group=jm;exports.hardware=zE;exports.isCalculated=Et;exports.label=PN;exports.lineplot=XO;exports.log=f$;exports.ontology=Gm;exports.policy=lg;exports.rack=tN;exports.ranger=NO;exports.schematic=G$;exports.status=jO;exports.synnaxPropsZ=Ml;exports.table=uS;exports.task=TN;exports.user=_z;exports.workspace=zS;