@synnaxlabs/x 0.16.1 → 0.24.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 (516) hide show
  1. package/.turbo/turbo-build.log +99 -7
  2. package/.vscode/settings.json +5 -1
  3. package/dist/base-B48bPNx5.cjs +1 -0
  4. package/dist/base-DnZzEvvz.js +38 -0
  5. package/dist/binary.cjs +3 -0
  6. package/dist/binary.js +100 -0
  7. package/dist/bounds-Bh_QBZZK.cjs +1 -0
  8. package/dist/bounds-Dmn-hd_-.js +129 -0
  9. package/dist/bounds.cjs +1 -0
  10. package/dist/bounds.js +4 -0
  11. package/dist/box-C92jYSNY.js +205 -0
  12. package/dist/box-m3dlc1kR.cjs +1 -0
  13. package/dist/box.cjs +1 -0
  14. package/dist/box.js +4 -0
  15. package/dist/caseconv.cjs +1 -0
  16. package/dist/caseconv.js +4 -0
  17. package/dist/change-C-YELKx6.cjs +1 -0
  18. package/dist/change-DLl6DccR.js +12 -0
  19. package/dist/change.cjs +1 -0
  20. package/dist/change.js +4 -0
  21. package/dist/compare.cjs +1 -0
  22. package/dist/compare.js +4 -0
  23. package/dist/debounce.cjs +1 -0
  24. package/dist/debounce.js +17 -0
  25. package/dist/deep.cjs +1 -0
  26. package/dist/deep.js +121 -0
  27. package/dist/destructor.cjs +1 -0
  28. package/dist/destructor.js +1 -0
  29. package/dist/dimensions-BAuHfd-b.js +44 -0
  30. package/dist/dimensions-zMcb9pMk.cjs +1 -0
  31. package/dist/dimensions.cjs +1 -0
  32. package/dist/dimensions.js +4 -0
  33. package/dist/direction-CScbfCdT.js +16 -0
  34. package/dist/direction-DZbN47uL.cjs +1 -0
  35. package/dist/direction.cjs +1 -0
  36. package/dist/direction.js +4 -0
  37. package/dist/external-B-DoBvh7.cjs +1 -0
  38. package/dist/external-DI9122wF.js +27 -0
  39. package/dist/identity.cjs +1 -0
  40. package/dist/identity.js +4 -0
  41. package/dist/index-BpCPHf78.cjs +1 -0
  42. package/dist/index-Bt5ivtN9.js +95 -0
  43. package/dist/index-BwkQTA-j.js +360 -0
  44. package/dist/index-CuG8fceO.cjs +1 -0
  45. package/dist/index.cjs +3 -0
  46. package/dist/index.js +178 -0
  47. package/dist/kv.cjs +1 -0
  48. package/dist/kv.js +6 -0
  49. package/dist/location-CfP9TAnW.js +94 -0
  50. package/dist/location-c3g6WKs-.cjs +1 -0
  51. package/dist/location.cjs +1 -0
  52. package/dist/location.js +4 -0
  53. package/dist/observe.cjs +1 -0
  54. package/dist/observe.js +43 -0
  55. package/dist/path-BO4pyGZf.cjs +1 -0
  56. package/dist/path-nTHmt_4i.js +65 -0
  57. package/dist/position-BBnkwGX1.cjs +1 -0
  58. package/dist/position-B_aphAR0.js +87 -0
  59. package/dist/position.cjs +1 -0
  60. package/dist/position.js +4 -0
  61. package/dist/record.cjs +1 -0
  62. package/dist/record.js +9 -0
  63. package/dist/runtime.cjs +1 -0
  64. package/dist/runtime.js +4 -0
  65. package/dist/scale-C8axypQ2.cjs +1 -0
  66. package/dist/scale-CgtgqlYU.js +205 -0
  67. package/dist/scale.cjs +1 -0
  68. package/dist/scale.js +4 -0
  69. package/dist/search.cjs +1 -0
  70. package/dist/search.js +15 -0
  71. package/dist/series-8E6FnWBU.cjs +11 -0
  72. package/dist/series-DCJSrg1P.js +1629 -0
  73. package/dist/spatial-BOhaO8xN.cjs +1 -0
  74. package/dist/spatial-DozyssiN.js +11 -0
  75. package/dist/spatial.cjs +1 -0
  76. package/dist/spatial.js +20 -0
  77. package/dist/{binary → src/binary}/encoder.d.ts +26 -2
  78. package/dist/src/binary/encoder.d.ts.map +1 -0
  79. package/dist/src/binary/encoder.spec.d.ts.map +1 -0
  80. package/dist/src/binary/index.d.ts.map +1 -0
  81. package/dist/src/caseconv/caseconv.d.ts +6 -0
  82. package/dist/src/caseconv/caseconv.d.ts.map +1 -0
  83. package/dist/src/caseconv/index.d.ts +2 -0
  84. package/dist/src/caseconv/index.d.ts.map +1 -0
  85. package/dist/{change → src/change}/change.d.ts +10 -9
  86. package/dist/src/change/change.d.ts.map +1 -0
  87. package/dist/src/change/index.d.ts.map +1 -0
  88. package/dist/src/clamp/clamp.d.ts.map +1 -0
  89. package/dist/src/clamp/index.d.ts +2 -0
  90. package/dist/src/clamp/index.d.ts.map +1 -0
  91. package/dist/{compare → src/compare}/compare.d.ts +6 -4
  92. package/dist/src/compare/compare.d.ts.map +1 -0
  93. package/dist/src/compare/compare.spec.d.ts +2 -0
  94. package/dist/src/compare/compare.spec.d.ts.map +1 -0
  95. package/dist/src/compare/index.d.ts.map +1 -0
  96. package/dist/src/control/control.d.ts +107 -0
  97. package/dist/src/control/control.d.ts.map +1 -0
  98. package/dist/src/control/index.d.ts +2 -0
  99. package/dist/src/control/index.d.ts.map +1 -0
  100. package/dist/src/debounce/debounce.d.ts.map +1 -0
  101. package/dist/src/debounce/debounce.spec.d.ts +2 -0
  102. package/dist/src/debounce/debounce.spec.d.ts.map +1 -0
  103. package/dist/src/debounce/index.d.ts +2 -0
  104. package/dist/src/debounce/index.d.ts.map +1 -0
  105. package/dist/src/deep/copy.d.ts.map +1 -0
  106. package/dist/{deep → src/deep}/delete.d.ts +2 -1
  107. package/dist/src/deep/delete.d.ts.map +1 -0
  108. package/dist/{deep → src/deep}/delete.spec.d.ts.map +1 -1
  109. package/dist/src/deep/difference.d.ts.map +1 -0
  110. package/dist/src/deep/difference.spec.d.ts.map +1 -0
  111. package/dist/src/deep/equal.d.ts.map +1 -0
  112. package/dist/{deep → src/deep}/equal.spec.d.ts.map +1 -1
  113. package/dist/{deep → src/deep}/external.d.ts +3 -4
  114. package/dist/src/deep/external.d.ts.map +1 -0
  115. package/dist/src/deep/index.d.ts.map +1 -0
  116. package/dist/src/deep/merge.d.ts +12 -0
  117. package/dist/src/deep/merge.d.ts.map +1 -0
  118. package/dist/{deep → src/deep}/merge.spec.d.ts.map +1 -1
  119. package/dist/src/deep/partial.d.ts.map +1 -0
  120. package/dist/src/deep/path.d.ts +54 -0
  121. package/dist/src/deep/path.d.ts.map +1 -0
  122. package/dist/{deep → src/deep}/path.spec.d.ts.map +1 -1
  123. package/dist/src/destructor.d.ts.map +1 -0
  124. package/dist/{identity.d.ts → src/identity.d.ts} +2 -1
  125. package/dist/src/identity.d.ts.map +1 -0
  126. package/dist/{index.d.ts → src/index.d.ts} +22 -20
  127. package/dist/src/index.d.ts.map +1 -0
  128. package/dist/src/invert.d.ts.map +1 -0
  129. package/dist/src/join.d.ts.map +1 -0
  130. package/dist/src/kv/index.d.ts.map +1 -0
  131. package/dist/src/kv/types.d.ts.map +1 -0
  132. package/dist/src/math/index.d.ts +2 -0
  133. package/dist/src/math/index.d.ts.map +1 -0
  134. package/dist/src/math/math.d.ts +11 -0
  135. package/dist/src/math/math.d.ts.map +1 -0
  136. package/dist/src/migrate/index.d.ts.map +1 -0
  137. package/dist/src/migrate/migrate.d.ts +29 -0
  138. package/dist/src/migrate/migrate.d.ts.map +1 -0
  139. package/dist/src/migrate/migrate.spec.d.ts.map +1 -0
  140. package/dist/{mock → src/mock}/MockGLBufferController.d.ts +2 -1
  141. package/dist/src/mock/MockGLBufferController.d.ts.map +1 -0
  142. package/dist/src/mock/index.d.ts.map +1 -0
  143. package/dist/src/observe/index.d.ts.map +1 -0
  144. package/dist/src/observe/observe.d.ts +24 -0
  145. package/dist/src/observe/observe.d.ts.map +1 -0
  146. package/dist/src/observe/obsever.spec.d.ts +2 -0
  147. package/dist/src/observe/obsever.spec.d.ts.map +1 -0
  148. package/dist/src/optional.d.ts.map +1 -0
  149. package/dist/{primitive.d.ts → src/primitive.d.ts} +2 -1
  150. package/dist/src/primitive.d.ts.map +1 -0
  151. package/dist/{record.d.ts → src/record.d.ts} +7 -8
  152. package/dist/src/record.d.ts.map +1 -0
  153. package/dist/{renderable.d.ts → src/renderable.d.ts} +2 -1
  154. package/dist/src/renderable.d.ts.map +1 -0
  155. package/dist/src/runtime/detect.d.ts.map +1 -0
  156. package/dist/src/runtime/external.d.ts.map +1 -0
  157. package/dist/src/runtime/index.d.ts.map +1 -0
  158. package/dist/src/runtime/os.d.ts +20 -0
  159. package/dist/src/runtime/os.d.ts.map +1 -0
  160. package/dist/{search.d.ts → src/search.d.ts} +5 -2
  161. package/dist/src/search.d.ts.map +1 -0
  162. package/dist/src/shallowCopy.d.ts +2 -0
  163. package/dist/src/shallowCopy.d.ts.map +1 -0
  164. package/dist/{spatial → src/spatial}/base.d.ts +30 -5
  165. package/dist/src/spatial/base.d.ts.map +1 -0
  166. package/dist/src/spatial/bounds/bounds.d.ts +148 -0
  167. package/dist/src/spatial/bounds/bounds.d.ts.map +1 -0
  168. package/dist/src/spatial/bounds/bounds.spec.d.ts.map +1 -0
  169. package/dist/src/spatial/bounds/index.d.ts.map +1 -0
  170. package/dist/{spatial → src/spatial}/box/box.d.ts +73 -24
  171. package/dist/src/spatial/box/box.d.ts.map +1 -0
  172. package/dist/src/spatial/box/box.spec.d.ts.map +1 -0
  173. package/dist/src/spatial/box/index.d.ts.map +1 -0
  174. package/dist/{spatial → src/spatial}/dimensions/dimensions.d.ts +4 -3
  175. package/dist/src/spatial/dimensions/dimensions.d.ts.map +1 -0
  176. package/dist/src/spatial/dimensions/dimensions.spec.d.ts.map +1 -0
  177. package/dist/src/spatial/dimensions/index.d.ts.map +1 -0
  178. package/dist/{spatial → src/spatial}/direction/direction.d.ts +4 -3
  179. package/dist/src/spatial/direction/direction.d.ts.map +1 -0
  180. package/dist/src/spatial/direction/direction.spec.d.ts.map +1 -0
  181. package/dist/src/spatial/direction/index.d.ts.map +1 -0
  182. package/dist/{spatial → src/spatial}/external.d.ts +2 -2
  183. package/dist/src/spatial/external.d.ts.map +1 -0
  184. package/dist/src/spatial/index.d.ts.map +1 -0
  185. package/dist/src/spatial/location/index.d.ts.map +1 -0
  186. package/dist/{spatial → src/spatial}/location/location.d.ts +4 -3
  187. package/dist/src/spatial/location/location.d.ts.map +1 -0
  188. package/dist/src/spatial/location/location.spec.d.ts.map +1 -0
  189. package/dist/src/spatial/position/index.d.ts.map +1 -0
  190. package/dist/{spatial → src/spatial}/position/position.d.ts +4 -4
  191. package/dist/src/spatial/position/position.d.ts.map +1 -0
  192. package/dist/src/spatial/position/position.spec.d.ts.map +1 -0
  193. package/dist/src/spatial/scale/index.d.ts.map +1 -0
  194. package/dist/{spatial → src/spatial}/scale/scale.d.ts +15 -62
  195. package/dist/src/spatial/scale/scale.d.ts.map +1 -0
  196. package/dist/src/spatial/scale/scale.spec.d.ts.map +1 -0
  197. package/dist/src/spatial/spatial.d.ts +2 -0
  198. package/dist/src/spatial/spatial.d.ts.map +1 -0
  199. package/dist/src/spatial/xy/index.d.ts.map +1 -0
  200. package/dist/{spatial → src/spatial}/xy/xy.d.ts +16 -25
  201. package/dist/src/spatial/xy/xy.d.ts.map +1 -0
  202. package/dist/{spatial → src/spatial}/xy/xy.spec.d.ts.map +1 -1
  203. package/dist/src/telem/generate.d.ts +4 -0
  204. package/dist/src/telem/generate.d.ts.map +1 -0
  205. package/dist/src/telem/gl.d.ts.map +1 -0
  206. package/dist/{telem → src/telem}/index.d.ts +1 -1
  207. package/dist/src/telem/index.d.ts.map +1 -0
  208. package/dist/{telem → src/telem}/series.d.ts +10 -8
  209. package/dist/src/telem/series.d.ts.map +1 -0
  210. package/dist/{telem → src/telem}/series.spec.d.ts.map +1 -1
  211. package/dist/{telem → src/telem}/telem.d.ts +19 -21
  212. package/dist/src/telem/telem.d.ts.map +1 -0
  213. package/dist/{telem → src/telem}/telem.spec.d.ts.map +1 -1
  214. package/dist/src/toArray.d.ts.map +1 -0
  215. package/dist/src/transform.d.ts +6 -0
  216. package/dist/src/transform.d.ts.map +1 -0
  217. package/dist/src/unique.d.ts.map +1 -0
  218. package/dist/src/url/index.d.ts +2 -0
  219. package/dist/src/url/index.d.ts.map +1 -0
  220. package/dist/src/url/url.d.ts.map +1 -0
  221. package/dist/{url → src/url}/url.spec.d.ts.map +1 -1
  222. package/dist/src/worker/index.d.ts +2 -0
  223. package/dist/src/worker/index.d.ts.map +1 -0
  224. package/dist/{worker → src/worker}/worker.d.ts +4 -4
  225. package/dist/src/worker/worker.d.ts.map +1 -0
  226. package/dist/src/worker/worker.spec.d.ts.map +1 -0
  227. package/dist/src/zodutil/index.d.ts +2 -0
  228. package/dist/src/zodutil/index.d.ts.map +1 -0
  229. package/dist/src/zodutil/zodutil.d.ts +6 -0
  230. package/dist/src/zodutil/zodutil.d.ts.map +1 -0
  231. package/dist/src/zodutil/zodutil.spec.d.ts +2 -0
  232. package/dist/src/zodutil/zodutil.spec.d.ts.map +1 -0
  233. package/dist/telem.cjs +1 -0
  234. package/dist/telem.js +17 -0
  235. package/dist/toArray.cjs +1 -0
  236. package/dist/toArray.js +5 -0
  237. package/dist/unique.cjs +1 -0
  238. package/dist/unique.js +4 -0
  239. package/dist/url.cjs +1 -0
  240. package/dist/url.js +54 -0
  241. package/dist/worker.cjs +1 -0
  242. package/dist/worker.js +47 -0
  243. package/dist/xy-D1ZbIqpT.js +90 -0
  244. package/dist/xy-cP-FXJtR.cjs +1 -0
  245. package/dist/xy.cjs +1 -0
  246. package/dist/xy.js +4 -0
  247. package/dist/zodutil.cjs +1 -0
  248. package/dist/zodutil.js +21 -0
  249. package/eslint.config.js +12 -0
  250. package/package.json +157 -13
  251. package/src/binary/encoder.spec.ts +150 -7
  252. package/src/binary/encoder.ts +110 -9
  253. package/src/binary/index.ts +1 -1
  254. package/src/caseconv/caseconv.ts +31 -0
  255. package/src/caseconv/index.ts +10 -0
  256. package/src/change/change.ts +7 -6
  257. package/src/change/index.ts +1 -1
  258. package/src/{clamp.ts → clamp/clamp.ts} +1 -1
  259. package/src/clamp/index.ts +10 -0
  260. package/src/compare/compare.spec.ts +49 -0
  261. package/src/compare/compare.ts +37 -10
  262. package/src/compare/index.ts +1 -1
  263. package/src/control/control.ts +77 -0
  264. package/src/control/index.ts +1 -0
  265. package/src/debounce/debounce.spec.ts +52 -0
  266. package/src/{debounce.ts → debounce/debounce.ts} +4 -4
  267. package/src/debounce/index.ts +10 -0
  268. package/src/deep/copy.ts +2 -3
  269. package/src/deep/delete.spec.ts +2 -2
  270. package/src/deep/delete.ts +3 -2
  271. package/src/deep/difference.spec.ts +28 -27
  272. package/src/deep/difference.ts +13 -11
  273. package/src/deep/equal.spec.ts +4 -4
  274. package/src/deep/equal.ts +5 -5
  275. package/src/deep/external.ts +4 -5
  276. package/src/deep/index.ts +1 -1
  277. package/src/deep/merge.spec.ts +120 -4
  278. package/src/deep/merge.ts +50 -6
  279. package/src/deep/partial.ts +1 -1
  280. package/src/deep/path.spec.ts +91 -39
  281. package/src/deep/path.ts +111 -46
  282. package/src/destructor.ts +2 -2
  283. package/src/identity.ts +1 -1
  284. package/src/index.ts +23 -21
  285. package/src/invert.ts +9 -0
  286. package/src/join.ts +1 -1
  287. package/src/kv/index.ts +1 -1
  288. package/src/kv/types.ts +1 -1
  289. package/src/math/index.ts +10 -0
  290. package/src/math/math.ts +33 -0
  291. package/src/migrate/index.ts +9 -0
  292. package/src/migrate/migrate.spec.ts +65 -54
  293. package/src/migrate/migrate.ts +126 -17
  294. package/src/mock/MockGLBufferController.ts +6 -6
  295. package/src/mock/index.ts +1 -1
  296. package/src/observe/index.ts +1 -1
  297. package/src/observe/observe.ts +37 -6
  298. package/src/observe/obsever.spec.ts +56 -0
  299. package/src/optional.ts +3 -4
  300. package/src/primitive.ts +1 -1
  301. package/src/record.ts +10 -6
  302. package/src/renderable.ts +1 -1
  303. package/src/runtime/detect.ts +3 -3
  304. package/src/runtime/external.ts +1 -1
  305. package/src/runtime/index.ts +1 -1
  306. package/src/runtime/os.ts +17 -5
  307. package/src/search.ts +3 -1
  308. package/src/shallowCopy.ts +5 -6
  309. package/src/spatial/base.ts +13 -5
  310. package/src/spatial/bounds/bounds.spec.ts +259 -180
  311. package/src/spatial/bounds/bounds.ts +200 -85
  312. package/src/spatial/bounds/index.ts +2 -2
  313. package/src/spatial/box/box.spec.ts +211 -2
  314. package/src/spatial/box/box.ts +97 -49
  315. package/src/spatial/box/index.ts +2 -2
  316. package/src/spatial/dimensions/dimensions.spec.ts +1 -1
  317. package/src/spatial/dimensions/dimensions.ts +4 -4
  318. package/src/spatial/dimensions/index.ts +2 -2
  319. package/src/spatial/direction/direction.spec.ts +1 -1
  320. package/src/spatial/direction/direction.ts +7 -7
  321. package/src/spatial/direction/index.ts +2 -2
  322. package/src/spatial/external.ts +3 -3
  323. package/src/spatial/index.ts +1 -1
  324. package/src/spatial/location/index.ts +2 -2
  325. package/src/spatial/location/location.spec.ts +1 -1
  326. package/src/spatial/location/location.ts +21 -21
  327. package/src/spatial/position/index.ts +1 -1
  328. package/src/spatial/position/position.spec.ts +1 -1
  329. package/src/spatial/position/position.ts +3 -20
  330. package/src/spatial/scale/index.ts +2 -2
  331. package/src/spatial/scale/scale.spec.ts +3 -3
  332. package/src/spatial/scale/scale.ts +3 -3
  333. package/src/spatial/spatial.ts +5 -5
  334. package/src/spatial/xy/index.ts +2 -2
  335. package/src/spatial/xy/xy.spec.ts +93 -44
  336. package/src/spatial/xy/xy.ts +20 -27
  337. package/src/telem/generate.ts +1 -1
  338. package/src/telem/gl.ts +1 -1
  339. package/src/telem/index.ts +2 -2
  340. package/src/telem/series.spec.ts +64 -5
  341. package/src/telem/series.ts +47 -35
  342. package/src/telem/telem.spec.ts +130 -2
  343. package/src/telem/telem.ts +63 -23
  344. package/src/toArray.ts +2 -2
  345. package/src/transform.ts +9 -2
  346. package/src/unique.ts +1 -1
  347. package/src/url/index.ts +2 -2
  348. package/src/url/url.spec.ts +2 -2
  349. package/src/url/url.ts +4 -4
  350. package/src/worker/index.ts +10 -0
  351. package/src/worker/worker.spec.ts +2 -2
  352. package/src/worker/worker.ts +13 -13
  353. package/src/zodutil/index.ts +10 -0
  354. package/src/zodutil/zodutil.spec.ts +103 -0
  355. package/src/zodutil/zodutil.ts +44 -0
  356. package/tsconfig.json +1 -0
  357. package/tsconfig.tsbuildinfo +1 -0
  358. package/vite.config.ts +39 -3
  359. package/.eslintrc.cjs +0 -18
  360. package/dist/binary/encoder.d.ts.map +0 -1
  361. package/dist/binary/encoder.spec.d.ts.map +0 -1
  362. package/dist/binary/index.d.ts.map +0 -1
  363. package/dist/case.d.ts +0 -6
  364. package/dist/case.d.ts.map +0 -1
  365. package/dist/change/change.d.ts.map +0 -1
  366. package/dist/change/index.d.ts.map +0 -1
  367. package/dist/clamp.d.ts.map +0 -1
  368. package/dist/compare/compare.d.ts.map +0 -1
  369. package/dist/compare/index.d.ts.map +0 -1
  370. package/dist/debounce.d.ts.map +0 -1
  371. package/dist/deep/copy.d.ts.map +0 -1
  372. package/dist/deep/delete.d.ts.map +0 -1
  373. package/dist/deep/difference.d.ts.map +0 -1
  374. package/dist/deep/difference.spec.d.ts.map +0 -1
  375. package/dist/deep/equal.d.ts.map +0 -1
  376. package/dist/deep/external.d.ts.map +0 -1
  377. package/dist/deep/index.d.ts.map +0 -1
  378. package/dist/deep/memo.d.ts +0 -2
  379. package/dist/deep/memo.d.ts.map +0 -1
  380. package/dist/deep/merge.d.ts +0 -3
  381. package/dist/deep/merge.d.ts.map +0 -1
  382. package/dist/deep/partial.d.ts.map +0 -1
  383. package/dist/deep/path.d.ts +0 -37
  384. package/dist/deep/path.d.ts.map +0 -1
  385. package/dist/destructor.d.ts.map +0 -1
  386. package/dist/identity.d.ts.map +0 -1
  387. package/dist/index.d.ts.map +0 -1
  388. package/dist/invert.d.ts.map +0 -1
  389. package/dist/join.d.ts.map +0 -1
  390. package/dist/kv/index.d.ts.map +0 -1
  391. package/dist/kv/types.d.ts.map +0 -1
  392. package/dist/migrate/index.d.ts.map +0 -1
  393. package/dist/migrate/migrate.d.ts +0 -16
  394. package/dist/migrate/migrate.d.ts.map +0 -1
  395. package/dist/migrate/migrate.spec.d.ts.map +0 -1
  396. package/dist/mock/MockGLBufferController.d.ts.map +0 -1
  397. package/dist/mock/index.d.ts.map +0 -1
  398. package/dist/observe/index.d.ts.map +0 -1
  399. package/dist/observe/observe.d.ts +0 -12
  400. package/dist/observe/observe.d.ts.map +0 -1
  401. package/dist/optional.d.ts.map +0 -1
  402. package/dist/primitive.d.ts.map +0 -1
  403. package/dist/record.d.ts.map +0 -1
  404. package/dist/renderable.d.ts.map +0 -1
  405. package/dist/runtime/detect.d.ts.map +0 -1
  406. package/dist/runtime/external.d.ts.map +0 -1
  407. package/dist/runtime/index.d.ts.map +0 -1
  408. package/dist/runtime/os.d.ts +0 -10
  409. package/dist/runtime/os.d.ts.map +0 -1
  410. package/dist/search.d.ts.map +0 -1
  411. package/dist/shallowCopy.d.ts +0 -2
  412. package/dist/shallowCopy.d.ts.map +0 -1
  413. package/dist/spatial/base.d.ts.map +0 -1
  414. package/dist/spatial/bounds/bounds.d.ts +0 -71
  415. package/dist/spatial/bounds/bounds.d.ts.map +0 -1
  416. package/dist/spatial/bounds/bounds.spec.d.ts.map +0 -1
  417. package/dist/spatial/bounds/index.d.ts.map +0 -1
  418. package/dist/spatial/box/box.d.ts.map +0 -1
  419. package/dist/spatial/box/box.spec.d.ts.map +0 -1
  420. package/dist/spatial/box/index.d.ts.map +0 -1
  421. package/dist/spatial/dimensions/dimensions.d.ts.map +0 -1
  422. package/dist/spatial/dimensions/dimensions.spec.d.ts.map +0 -1
  423. package/dist/spatial/dimensions/index.d.ts.map +0 -1
  424. package/dist/spatial/direction/direction.d.ts.map +0 -1
  425. package/dist/spatial/direction/direction.spec.d.ts.map +0 -1
  426. package/dist/spatial/direction/index.d.ts.map +0 -1
  427. package/dist/spatial/external.d.ts.map +0 -1
  428. package/dist/spatial/index.d.ts.map +0 -1
  429. package/dist/spatial/location/index.d.ts.map +0 -1
  430. package/dist/spatial/location/location.d.ts.map +0 -1
  431. package/dist/spatial/location/location.spec.d.ts.map +0 -1
  432. package/dist/spatial/position/index.d.ts.map +0 -1
  433. package/dist/spatial/position/position.d.ts.map +0 -1
  434. package/dist/spatial/position/position.spec.d.ts.map +0 -1
  435. package/dist/spatial/scale/index.d.ts.map +0 -1
  436. package/dist/spatial/scale/scale.d.ts.map +0 -1
  437. package/dist/spatial/scale/scale.spec.d.ts.map +0 -1
  438. package/dist/spatial/spatial.d.ts +0 -2
  439. package/dist/spatial/spatial.d.ts.map +0 -1
  440. package/dist/spatial/xy/index.d.ts.map +0 -1
  441. package/dist/spatial/xy/xy.d.ts.map +0 -1
  442. package/dist/telem/generate.d.ts +0 -3
  443. package/dist/telem/generate.d.ts.map +0 -1
  444. package/dist/telem/gl.d.ts.map +0 -1
  445. package/dist/telem/index.d.ts.map +0 -1
  446. package/dist/telem/series.d.ts.map +0 -1
  447. package/dist/telem/telem.d.ts.map +0 -1
  448. package/dist/toArray.d.ts.map +0 -1
  449. package/dist/transform.d.ts +0 -2
  450. package/dist/transform.d.ts.map +0 -1
  451. package/dist/unique.d.ts.map +0 -1
  452. package/dist/url/index.d.ts +0 -2
  453. package/dist/url/index.d.ts.map +0 -1
  454. package/dist/url/url.d.ts.map +0 -1
  455. package/dist/worker/worker.d.ts.map +0 -1
  456. package/dist/worker/worker.spec.d.ts.map +0 -1
  457. package/dist/x.cjs +0 -12
  458. package/dist/x.cjs.map +0 -1
  459. package/dist/x.js +0 -5935
  460. package/dist/x.js.map +0 -1
  461. package/src/case.ts +0 -27
  462. package/src/deep/memo.ts +0 -24
  463. /package/dist/{binary → src/binary}/encoder.spec.d.ts +0 -0
  464. /package/dist/{binary → src/binary}/index.d.ts +0 -0
  465. /package/dist/{change → src/change}/index.d.ts +0 -0
  466. /package/dist/{clamp.d.ts → src/clamp/clamp.d.ts} +0 -0
  467. /package/dist/{compare → src/compare}/index.d.ts +0 -0
  468. /package/dist/{debounce.d.ts → src/debounce/debounce.d.ts} +0 -0
  469. /package/dist/{deep → src/deep}/copy.d.ts +0 -0
  470. /package/dist/{deep → src/deep}/delete.spec.d.ts +0 -0
  471. /package/dist/{deep → src/deep}/difference.d.ts +0 -0
  472. /package/dist/{deep → src/deep}/difference.spec.d.ts +0 -0
  473. /package/dist/{deep → src/deep}/equal.d.ts +0 -0
  474. /package/dist/{deep → src/deep}/equal.spec.d.ts +0 -0
  475. /package/dist/{deep → src/deep}/index.d.ts +0 -0
  476. /package/dist/{deep → src/deep}/merge.spec.d.ts +0 -0
  477. /package/dist/{deep → src/deep}/partial.d.ts +0 -0
  478. /package/dist/{deep → src/deep}/path.spec.d.ts +0 -0
  479. /package/dist/{destructor.d.ts → src/destructor.d.ts} +0 -0
  480. /package/dist/{invert.d.ts → src/invert.d.ts} +0 -0
  481. /package/dist/{join.d.ts → src/join.d.ts} +0 -0
  482. /package/dist/{kv → src/kv}/index.d.ts +0 -0
  483. /package/dist/{kv → src/kv}/types.d.ts +0 -0
  484. /package/dist/{migrate → src/migrate}/index.d.ts +0 -0
  485. /package/dist/{migrate → src/migrate}/migrate.spec.d.ts +0 -0
  486. /package/dist/{mock → src/mock}/index.d.ts +0 -0
  487. /package/dist/{observe → src/observe}/index.d.ts +0 -0
  488. /package/dist/{optional.d.ts → src/optional.d.ts} +0 -0
  489. /package/dist/{runtime → src/runtime}/detect.d.ts +0 -0
  490. /package/dist/{runtime → src/runtime}/external.d.ts +0 -0
  491. /package/dist/{runtime → src/runtime}/index.d.ts +0 -0
  492. /package/dist/{spatial → src/spatial}/bounds/bounds.spec.d.ts +0 -0
  493. /package/dist/{spatial → src/spatial}/bounds/index.d.ts +0 -0
  494. /package/dist/{spatial → src/spatial}/box/box.spec.d.ts +0 -0
  495. /package/dist/{spatial → src/spatial}/box/index.d.ts +0 -0
  496. /package/dist/{spatial → src/spatial}/dimensions/dimensions.spec.d.ts +0 -0
  497. /package/dist/{spatial → src/spatial}/dimensions/index.d.ts +0 -0
  498. /package/dist/{spatial → src/spatial}/direction/direction.spec.d.ts +0 -0
  499. /package/dist/{spatial → src/spatial}/direction/index.d.ts +0 -0
  500. /package/dist/{spatial → src/spatial}/index.d.ts +0 -0
  501. /package/dist/{spatial → src/spatial}/location/index.d.ts +0 -0
  502. /package/dist/{spatial → src/spatial}/location/location.spec.d.ts +0 -0
  503. /package/dist/{spatial → src/spatial}/position/index.d.ts +0 -0
  504. /package/dist/{spatial → src/spatial}/position/position.spec.d.ts +0 -0
  505. /package/dist/{spatial → src/spatial}/scale/index.d.ts +0 -0
  506. /package/dist/{spatial → src/spatial}/scale/scale.spec.d.ts +0 -0
  507. /package/dist/{spatial → src/spatial}/xy/index.d.ts +0 -0
  508. /package/dist/{spatial → src/spatial}/xy/xy.spec.d.ts +0 -0
  509. /package/dist/{telem → src/telem}/gl.d.ts +0 -0
  510. /package/dist/{telem → src/telem}/series.spec.d.ts +0 -0
  511. /package/dist/{telem → src/telem}/telem.spec.d.ts +0 -0
  512. /package/dist/{toArray.d.ts → src/toArray.d.ts} +0 -0
  513. /package/dist/{unique.d.ts → src/unique.d.ts} +0 -0
  514. /package/dist/{url → src/url}/url.d.ts +0 -0
  515. /package/dist/{url → src/url}/url.spec.d.ts +0 -0
  516. /package/dist/{worker → src/worker}/worker.spec.d.ts +0 -0
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@synnaxlabs/x",
3
- "private": false,
4
- "version": "0.16.1",
3
+ "version": "0.24.0",
5
4
  "type": "module",
6
5
  "description": "Common Utilities for Synnax Labs",
7
6
  "repository": "https://github.com/synnaxlabs/synnax/tree/main/x/go",
@@ -14,25 +13,170 @@
14
13
  "control systems"
15
14
  ],
16
15
  "dependencies": {
17
- "async-mutex": "^0.4.1",
18
16
  "js-convert-case": "^4.2.0",
19
- "nanoid": "^3.3.7",
20
- "typescript": "^5.4.5",
21
- "zod": "3.22.4"
17
+ "nanoid": "^3.0.0",
18
+ "zod": "3.23.8"
22
19
  },
23
20
  "devDependencies": {
24
21
  "@types/node": "^20.12.7",
25
- "@vitest/coverage-v8": "1.2.2",
26
- "eslint": "^8.57.0",
27
- "vite": "5.1.2",
28
- "vitest": "1.2.2",
22
+ "@vitest/coverage-v8": "^1.5.0",
23
+ "vitest": "^1.5.0",
24
+ "vite": "5.2.11",
25
+ "typescript": "^5.4.5",
29
26
  "@synnaxlabs/tsconfig": "0.0.2",
30
27
  "@synnaxlabs/vite-plugin": "0.0.1",
31
28
  "eslint-config-synnaxlabs": "0.0.1"
32
29
  },
33
- "main": "dist/x.cjs",
34
- "module": "dist/x.js",
35
- "types": "dist/index.d.ts",
30
+ "main": "./dist/index.cjs",
31
+ "module": "./dist/index.js",
32
+ "types": "./dist/src/index.d.ts",
33
+ "exports": {
34
+ ".": {
35
+ "import": "./dist/index.js",
36
+ "require": "./dist/index.cjs",
37
+ "types": "./dist/src/index.d.ts"
38
+ },
39
+ "./binary": {
40
+ "import": "./dist/binary.js",
41
+ "require": "./dist/binary.cjs",
42
+ "types": "./dist/src/binary/index.d.ts"
43
+ },
44
+ "./compare": {
45
+ "import": "./dist/compare.js",
46
+ "require": "./dist/compare.cjs",
47
+ "types": "./dist/src/compare/index.d.ts"
48
+ },
49
+ "./deep": {
50
+ "import": "./dist/deep.js",
51
+ "require": "./dist/deep.cjs",
52
+ "types": "./dist/src/deep/index.d.ts"
53
+ },
54
+ "./kv": {
55
+ "import": "./dist/kv.js",
56
+ "require": "./dist/kv.cjs",
57
+ "types": "./dist/src/kv/index.d.ts"
58
+ },
59
+ "./runtime": {
60
+ "import": "./dist/runtime.js",
61
+ "require": "./dist/runtime.cjs",
62
+ "types": "./dist/src/runtime/index.d.ts"
63
+ },
64
+ "./observe": {
65
+ "import": "./dist/observe.js",
66
+ "require": "./dist/observe.cjs",
67
+ "types": "./dist/src/observe/index.d.ts"
68
+ },
69
+ "./box": {
70
+ "import": "./dist/box.js",
71
+ "require": "./dist/box.cjs",
72
+ "types": "./dist/src/spatial/box/index.d.ts"
73
+ },
74
+ "./bounds": {
75
+ "import": "./dist/bounds.js",
76
+ "require": "./dist/bounds.cjs",
77
+ "types": "./dist/src/spatial/bounds/index.d.ts"
78
+ },
79
+ "./dimensions": {
80
+ "import": "./dist/dimensions.js",
81
+ "require": "./dist/dimensions.cjs",
82
+ "types": "./dist/src/spatial/dimensions/index.d.ts"
83
+ },
84
+ "./direction": {
85
+ "import": "./dist/direction.js",
86
+ "require": "./dist/direction.cjs",
87
+ "types": "./dist/src/spatial/direction/index.d.ts"
88
+ },
89
+ "./location": {
90
+ "import": "./dist/location.js",
91
+ "require": "./dist/location.cjs",
92
+ "types": "./dist/src/spatial/location/index.d.ts"
93
+ },
94
+ "./position": {
95
+ "import": "./dist/position.js",
96
+ "require": "./dist/position.cjs",
97
+ "types": "./dist/src/spatial/position/index.d.ts"
98
+ },
99
+ "./scale": {
100
+ "import": "./dist/scale.js",
101
+ "require": "./dist/scale.cjs",
102
+ "types": "./dist/src/spatial/scale/index.d.ts"
103
+ },
104
+ "./xy": {
105
+ "import": "./dist/xy.js",
106
+ "require": "./dist/xy.cjs",
107
+ "types": "./dist/src/spatial/xy/index.d.ts"
108
+ },
109
+ "./spatial": {
110
+ "import": "./dist/spatial.js",
111
+ "require": "./dist/spatial.cjs",
112
+ "types": "./dist/src/spatial/index.d.ts"
113
+ },
114
+ "./telem": {
115
+ "import": "./dist/telem.js",
116
+ "require": "./dist/telem.cjs",
117
+ "types": "./dist/src/telem/index.d.ts"
118
+ },
119
+ "./url": {
120
+ "import": "./dist/url.js",
121
+ "require": "./dist/url.cjs",
122
+ "types": "./dist/src/url/index.d.ts"
123
+ },
124
+ "./worker": {
125
+ "import": "./dist/worker.js",
126
+ "require": "./dist/worker.cjs",
127
+ "types": "./dist/src/worker/index.d.ts"
128
+ },
129
+ "./destructor": {
130
+ "import": "./dist/destructor.js",
131
+ "require": "./dist/destructor.cjs",
132
+ "types": "./dist/src/destructor.d.ts"
133
+ },
134
+ "./debounce": {
135
+ "import": "./dist/debounce.js",
136
+ "require": "./dist/debounce.cjs",
137
+ "types": "./dist/src/debounce/index.d.ts"
138
+ },
139
+ "./toArray": {
140
+ "import": "./dist/toArray.js",
141
+ "require": "./dist/toArray.cjs",
142
+ "types": "./dist/src/toArray.d.ts"
143
+ },
144
+ "./search": {
145
+ "import": "./dist/search.js",
146
+ "require": "./dist/search.cjs",
147
+ "types": "./dist/src/search.d.ts"
148
+ },
149
+ "./unique": {
150
+ "import": "./dist/unique.js",
151
+ "require": "./dist/unique.cjs",
152
+ "types": "./dist/src/unique.d.ts"
153
+ },
154
+ "./record": {
155
+ "import": "./dist/record.js",
156
+ "require": "./dist/record.cjs",
157
+ "types": "./dist/src/record.d.ts"
158
+ },
159
+ "./change": {
160
+ "import": "./dist/change.js",
161
+ "require": "./dist/change.cjs",
162
+ "types": "./dist/src/change/index.d.ts"
163
+ },
164
+ "./identity": {
165
+ "import": "./dist/identity.js",
166
+ "require": "./dist/identity.cjs",
167
+ "types": "./dist/src/identity.d.ts"
168
+ },
169
+ "./caseconv": {
170
+ "import": "./dist/caseconv.js",
171
+ "require": "./dist/caseconv.cjs",
172
+ "types": "./dist/src/caseconv/index.d.ts"
173
+ },
174
+ "./zodutil": {
175
+ "import": "./dist/zodutil.js",
176
+ "require": "./dist/zodutil.cjs",
177
+ "types": "./dist/src/zodutil/index.d.ts"
178
+ }
179
+ },
36
180
  "scripts": {
37
181
  "build": "tsc --noEmit && vite build",
38
182
  "test": "vitest",
@@ -1,4 +1,4 @@
1
- // Copyright 2023 Synnax Labs, Inc.
1
+ // Copyright 2024 Synnax Labs, Inc.
2
2
  //
3
3
  // Use of this software is governed by the Business Source License included in the file
4
4
  // licenses/BSL.txt.
@@ -7,25 +7,168 @@
7
7
  // License, use of this software will be governed by the Apache License, Version 2.0,
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
- import { describe, expect, test } from "vitest";
10
+ import { describe, expect, it } from "vitest";
11
11
  import { z } from "zod";
12
12
 
13
13
  import { binary } from "@/binary";
14
14
 
15
- const SampleSchema = z.object({
15
+ const sampleSchema = z.object({
16
16
  channelKey: z.string(),
17
17
  timeStamp: z.number(),
18
18
  value: z.unknown(),
19
19
  });
20
20
 
21
- describe.each(binary.ENCODERS)("encoder", (e) => {
22
- test(`[encoder] - encoder ${e.contentType} should encode correctly`, () => {
21
+ binary.ENCODERS.forEach((e) => {
22
+ describe(`encoder ${e.contentType}`, () => {
23
+ it("should correctly encode and decode items", () => {
24
+ const sample = {
25
+ channelKey: "test",
26
+ timeStamp: 123,
27
+ value: new Array([1, 2, 3]),
28
+ };
29
+ const encoded = e.encode(sample);
30
+ expect(e.decode(encoded, sampleSchema)).toEqual(sample);
31
+ });
32
+ });
33
+ });
34
+
35
+ describe("JSON", () => {
36
+ it("should correctly convert keys to snake case", () => {
23
37
  const sample = {
24
38
  channelKey: "test",
25
39
  timeStamp: 123,
26
40
  value: new Array([1, 2, 3]),
27
41
  };
28
- const encoded = e.encode(sample);
29
- expect(e.decode(encoded, SampleSchema)).toEqual(sample);
42
+ const encoded = binary.JSON_ECD.encodeString(sample);
43
+ const parse = JSON.parse(encoded);
44
+ expect(parse.channel_key).toEqual("test");
45
+ });
46
+ it("should correctly decode keys from snake case", () => {
47
+ const sample = {
48
+ channel_key: "test",
49
+ time_stamp: 123,
50
+ value: new Array([1, 2, 3]),
51
+ };
52
+ const encoded = JSON.stringify(sample);
53
+ const decoded = binary.JSON_ECD.decodeString(encoded, sampleSchema);
54
+ expect(decoded.channelKey).toEqual("test");
55
+ });
56
+
57
+ describe("CSVEncoderDecoder", () => {
58
+ it("should correctly decode CSV data with valid input", () => {
59
+ const sample = `
60
+ channelKey,timeStamp,value
61
+ test,123,5
62
+ test2,124,6
63
+ `;
64
+ const decoded = binary.CSV_ECD.decodeString(sample);
65
+ expect(decoded).toEqual({
66
+ channelKey: ["test", "test2"],
67
+ timeStamp: [123, 124],
68
+ value: [5, 6],
69
+ });
70
+ });
71
+
72
+ it("should handle empty CSV data", () => {
73
+ const sample = `
74
+ `;
75
+ const decoded = binary.CSV_ECD.decodeString(sample);
76
+ expect(decoded).toEqual({});
77
+ });
78
+
79
+ it("should handle CSV with only headers", () => {
80
+ const sample = `
81
+ channelKey,timeStamp,value
82
+ `;
83
+ const decoded = binary.CSV_ECD.decodeString(sample);
84
+ expect(decoded).toEqual({
85
+ channelKey: [],
86
+ timeStamp: [],
87
+ value: [],
88
+ });
89
+ });
90
+
91
+ it("should handle CSV with missing values", () => {
92
+ const sample = `
93
+ channelKey,timeStamp,value
94
+ test,123,
95
+ test2,124,6
96
+ `;
97
+ const decoded = binary.CSV_ECD.decodeString(sample);
98
+ expect(decoded).toEqual({
99
+ channelKey: ["test", "test2"],
100
+ timeStamp: [123, 124],
101
+ value: [6],
102
+ });
103
+ });
104
+
105
+ it("should handle CSV with extra values", () => {
106
+ const sample = `
107
+ channelKey,timeStamp,value
108
+ test,123,5,extra
109
+ test2,124,6
110
+ `;
111
+ const decoded = binary.CSV_ECD.decodeString(sample);
112
+ expect(decoded).toEqual({
113
+ channelKey: ["test", "test2"],
114
+ timeStamp: [123, 124],
115
+ value: [5, 6],
116
+ });
117
+ });
118
+
119
+ it("should handle CSV with different types of values", () => {
120
+ const sample = `
121
+ key,number,string
122
+ test,123,"hello"
123
+ test2,456,"world"
124
+ `;
125
+ const decoded = binary.CSV_ECD.decodeString(sample);
126
+ expect(decoded).toEqual({
127
+ key: ["test", "test2"],
128
+ number: [123, 456],
129
+ string: ["hello", "world"],
130
+ });
131
+ });
132
+
133
+ it("should handle CSV with spaces around values", () => {
134
+ const sample = `
135
+ key, number , string
136
+ test , 123 , "hello"
137
+ test2 , 456 , "world"
138
+ `;
139
+ const decoded = binary.CSV_ECD.decodeString(sample);
140
+ expect(decoded).toEqual({
141
+ key: ["test", "test2"],
142
+ number: [123, 456],
143
+ string: ["hello", "world"],
144
+ });
145
+ });
146
+
147
+ it("should handle CSV with empty rows", () => {
148
+ const sample = `
149
+ key,number,string
150
+ test,123,"hello"
151
+ ,
152
+ test2,456,"world"
153
+ `;
154
+ const decoded = binary.CSV_ECD.decodeString(sample);
155
+ expect(decoded).toEqual({
156
+ key: ["test", "test2"],
157
+ number: [123, 456],
158
+ string: ["hello", "world"],
159
+ });
160
+ });
161
+
162
+ it("should handle CSV with single column", () => {
163
+ const sample = `
164
+ key
165
+ test
166
+ test2
167
+ `;
168
+ const decoded = binary.CSV_ECD.decodeString(sample);
169
+ expect(decoded).toEqual({
170
+ key: ["test", "test2"],
171
+ });
172
+ });
30
173
  });
31
174
  });
@@ -1,4 +1,4 @@
1
- // Copyright 2023 Synnax Labs, Inc.
1
+ // Copyright 2024 Synnax Labs, Inc.
2
2
  //
3
3
  // Use of this software is governed by the Business Source License included in the file
4
4
  // licenses/BSL.txt.
@@ -7,9 +7,9 @@
7
7
  // License, use of this software will be governed by the Apache License, Version 2.0,
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
- import { type ZodSchema, type z } from "zod";
10
+ import { type z, type ZodSchema } from "zod";
11
11
 
12
- import { Case } from "@/case";
12
+ import { caseconv } from "@/caseconv";
13
13
  import { isObject } from "@/identity";
14
14
 
15
15
  /**
@@ -40,14 +40,32 @@ export interface EncoderDecoder {
40
40
  /** JSONEncoderDecoder is a JSON implementation of EncoderDecoder. */
41
41
  export class JSONEncoderDecoder implements EncoderDecoder {
42
42
  contentType = "application/json";
43
- readonly decoder: TextDecoder;
43
+ private readonly decoder: TextDecoder;
44
+ private readonly encoder: TextEncoder;
44
45
 
45
46
  constructor() {
46
47
  this.decoder = new TextDecoder();
48
+ this.encoder = new TextEncoder();
47
49
  }
48
50
 
49
51
  encode(payload: unknown): ArrayBuffer {
50
- const json = JSON.stringify(Case.toSnake(payload), (_, v) => {
52
+ return this.encoder.encode(this.encodeString(payload)).buffer;
53
+ }
54
+
55
+ decode<P extends z.ZodTypeAny>(
56
+ data: Uint8Array | ArrayBuffer,
57
+ schema?: P,
58
+ ): z.output<P> {
59
+ return this.decodeString(this.decoder.decode(data), schema);
60
+ }
61
+
62
+ decodeString<P extends z.ZodTypeAny>(data: string, schema?: P): z.output<P> {
63
+ const unpacked = caseconv.toCamel(JSON.parse(data));
64
+ return schema != null ? schema.parse(unpacked) : (unpacked as z.output<P>);
65
+ }
66
+
67
+ encodeString(payload: unknown): string {
68
+ return JSON.stringify(caseconv.toSnake(payload), (_, v) => {
51
69
  if (ArrayBuffer.isView(v)) return Array.from(v as Uint8Array);
52
70
  if (isObject(v) && "encode_value" in v) {
53
71
  if (typeof v.value === "bigint") return v.value.toString();
@@ -56,18 +74,101 @@ export class JSONEncoderDecoder implements EncoderDecoder {
56
74
  if (typeof v === "bigint") return v.toString();
57
75
  return v;
58
76
  });
59
- return new TextEncoder().encode(json);
77
+ }
78
+
79
+ static registerCustomType(): void {}
80
+ }
81
+
82
+ /**
83
+ * CSVEncoderDecoder is a CSV implementation of EncoderDecoder.
84
+ */
85
+ export class CSVEncoderDecoder implements EncoderDecoder {
86
+ contentType = "text/csv";
87
+
88
+ encode(payload: unknown): ArrayBuffer {
89
+ const csvString = this.encodeString(payload);
90
+ return new TextEncoder().encode(csvString).buffer;
60
91
  }
61
92
 
62
93
  decode<P extends z.ZodTypeAny>(
63
94
  data: Uint8Array | ArrayBuffer,
64
95
  schema?: P,
65
96
  ): z.output<P> {
66
- const unpacked = Case.toCamel(JSON.parse(this.decoder.decode(data)));
67
- return schema != null ? schema.parse(unpacked) : (unpacked as P);
97
+ const csvString = new TextDecoder().decode(data);
98
+ return this.decodeString(csvString, schema);
99
+ }
100
+
101
+ encodeString(payload: unknown): string {
102
+ if (!Array.isArray(payload) || payload.length === 0 || !isObject(payload[0])) {
103
+ throw new Error("Payload must be an array of objects");
104
+ }
105
+
106
+ const keys = Object.keys(payload[0]);
107
+ const csvRows = [keys.join(",")];
108
+
109
+ payload.forEach((item: any) => {
110
+ const values = keys.map((key) => JSON.stringify(item[key] ?? ""));
111
+ csvRows.push(values.join(","));
112
+ });
113
+
114
+ return csvRows.join("\n");
115
+ }
116
+
117
+ decodeString<P extends z.ZodTypeAny>(data: string, schema?: P): z.output<P> {
118
+ const [headerLine, ...lines] = data
119
+ .trim()
120
+ .split("\n")
121
+ .map((line) => line.trim());
122
+ if (headerLine.length === 0)
123
+ return schema != null ? schema.parse({}) : ({} as z.output<P>);
124
+ const headers = headerLine.split(",").map((header) => header.trim());
125
+ const result: { [key: string]: any[] } = {};
126
+
127
+ headers.forEach((header) => {
128
+ result[header] = [];
129
+ });
130
+
131
+ lines.forEach((line) => {
132
+ const values = line.split(",").map((value) => value.trim());
133
+ headers.forEach((header, index) => {
134
+ const v = this.parseValue(values[index]);
135
+ if (v == null) return;
136
+ result[header].push(v);
137
+ });
138
+ });
139
+
140
+ return schema != null ? schema.parse(result) : (result as z.output<P>);
141
+ }
142
+
143
+ private parseValue(value?: string): any {
144
+ if (value == null || value.length === 0) return null;
145
+ const num = Number(value);
146
+ if (!isNaN(num)) return num;
147
+ if (value.startsWith('"') && value.endsWith('"')) return value.slice(1, -1);
148
+ return value;
68
149
  }
69
150
 
70
151
  static registerCustomType(): void {}
71
152
  }
72
153
 
73
- export const ENCODERS: EncoderDecoder[] = [new JSONEncoderDecoder()];
154
+ export class TextEncoderDecoder implements EncoderDecoder {
155
+ contentType = "text/plain";
156
+
157
+ encode(payload: unknown): ArrayBuffer {
158
+ return new TextEncoder().encode(payload as string).buffer;
159
+ }
160
+
161
+ decode<P extends z.ZodTypeAny>(
162
+ data: Uint8Array | ArrayBuffer,
163
+ schema?: P,
164
+ ): z.output<P> {
165
+ const text = new TextDecoder().decode(data);
166
+ return schema != null ? schema.parse(text) : (text as z.output<P>);
167
+ }
168
+ }
169
+
170
+ export const JSON_ECD = new JSONEncoderDecoder();
171
+ export const CSV_ECD = new CSVEncoderDecoder();
172
+ export const TEXT_ECD = new TextEncoderDecoder();
173
+
174
+ export const ENCODERS: EncoderDecoder[] = [JSON_ECD];
@@ -1,4 +1,4 @@
1
- // Copyright 2023 Synnax Labs, Inc.
1
+ // Copyright 2024 Synnax Labs, Inc.
2
2
  //
3
3
  // Use of this software is governed by the Business Source License included in the file
4
4
  // licenses/BSL.txt.
@@ -0,0 +1,31 @@
1
+ // Copyright 2024 Synnax Labs, Inc.
2
+ //
3
+ // Use of this software is governed by the Business Source License included in the file
4
+ // licenses/BSL.txt.
5
+ //
6
+ // As of the Change Date specified in that file, in accordance with the Business Source
7
+ // License, use of this software will be governed by the Apache License, Version 2.0,
8
+ // included in the file licenses/APL.txt.
9
+
10
+ import {
11
+ camelKeys as _camelKeys,
12
+ snakeKeys as _snakeKeys,
13
+ toCamelCase as _toCamelCase,
14
+ toSnakeCase as _toSnakeCase,
15
+ } from "js-convert-case";
16
+
17
+ const options = {
18
+ recursive: true,
19
+ recursiveInArray: true,
20
+ keepTypesOnRecursion: [Number, String, Uint8Array],
21
+ };
22
+
23
+ export const toSnake = <T>(entity: T): T => _snakeKeys(entity, options) as T;
24
+
25
+ export const toCamel = <T>(entity: T): T => _camelKeys(entity, options) as T;
26
+
27
+ export const capitalize = (str: string): string => str[0].toUpperCase() + str.slice(1);
28
+
29
+ export const stringToSnake = (str: string): string => _toSnakeCase(str);
30
+
31
+ export const stringToCamel = (str: string): string => _toCamelCase(str);
@@ -0,0 +1,10 @@
1
+ // Copyright 2024 Synnax Labs, Inc.
2
+ //
3
+ // Use of this software is governed by the Business Source License included in the file
4
+ // licenses/BSL.txt.
5
+ //
6
+ // As of the Change Date specified in that file, in accordance with the Business Source
7
+ // License, use of this software will be governed by the Apache License, Version 2.0,
8
+ // included in the file licenses/APL.txt.
9
+
10
+ export * as caseconv from "@/caseconv/caseconv";
@@ -1,4 +1,4 @@
1
- // Copyright 2023 Synnax Labs, Inc.
1
+ // Copyright 2024 Synnax Labs, Inc.
2
2
  //
3
3
  // Use of this software is governed by the Business Source License included in the file
4
4
  // licenses/BSL.txt.
@@ -11,6 +11,7 @@ import { z } from "zod";
11
11
 
12
12
  export type Variant = "set" | "delete";
13
13
 
14
+
14
15
  export const Z = <V extends z.ZodTypeAny>(value: V) =>
15
16
  z.object({
16
17
  variant: z.enum(["set", "delete"]),
@@ -18,16 +19,16 @@ export const Z = <V extends z.ZodTypeAny>(value: V) =>
18
19
  value,
19
20
  });
20
21
 
21
- export type Set<K, V> = {
22
+ export interface Set<K, V> {
22
23
  variant: "set";
23
24
  key: K;
24
25
  value: V;
25
- };
26
+ }
26
27
 
27
- export type Delete<K, V> = {
28
+ export interface Delete<K, V> {
28
29
  variant: "delete";
29
30
  key: K;
30
31
  value?: V;
31
- };
32
+ }
32
33
 
33
- export type Change<K, V> = Set<K, V> | Delete<K, V>;
34
+ export type Change<K, V> = Set<K, V> | Delete<K, V>;
@@ -1,4 +1,4 @@
1
- // Copyright 2023 Synnax Labs, Inc.
1
+ // Copyright 2024 Synnax Labs, Inc.
2
2
  //
3
3
  // Use of this software is governed by the Business Source License included in the file
4
4
  // licenses/BSL.txt.
@@ -1,4 +1,4 @@
1
- // Copyright 2023 Synnax Labs, Inc.
1
+ // Copyright 2024 Synnax Labs, Inc.
2
2
  //
3
3
  // Use of this software is governed by the Business Source License included in the file
4
4
  // licenses/BSL.txt.
@@ -0,0 +1,10 @@
1
+ // Copyright 2024 Synnax Labs, Inc.
2
+ //
3
+ // Use of this software is governed by the Business Source License included in the file
4
+ // licenses/BSL.txt.
5
+ //
6
+ // As of the Change Date specified in that file, in accordance with the Business Source
7
+ // License, use of this software will be governed by the Apache License, Version 2.0,
8
+ // included in the file licenses/APL.txt.
9
+
10
+ export * as clamp from "@/clamp/clamp";