@synnaxlabs/x 0.42.1 → 0.43.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 (296) hide show
  1. package/.turbo/turbo-build.log +93 -105
  2. package/.vscode/settings.json +4 -6
  3. package/README.md +1 -7
  4. package/dist/array.cjs +1 -0
  5. package/dist/array.js +7 -0
  6. package/dist/base-B5lQIJKc.js +38 -0
  7. package/dist/base-CTq-lhpU.cjs +1 -0
  8. package/dist/binary.cjs +1 -1
  9. package/dist/binary.js +1 -1
  10. package/dist/bounds.cjs +1 -1
  11. package/dist/bounds.js +2 -2
  12. package/dist/box.cjs +1 -1
  13. package/dist/box.js +1 -1
  14. package/dist/caseconv.cjs +1 -1
  15. package/dist/caseconv.js +2 -2
  16. package/dist/change.cjs +1 -1
  17. package/dist/change.js +10 -2
  18. package/dist/compare.cjs +1 -1
  19. package/dist/compare.js +1 -1
  20. package/dist/deep.cjs +1 -1
  21. package/dist/deep.js +92 -79
  22. package/dist/dimensions.cjs +1 -1
  23. package/dist/dimensions.js +41 -2
  24. package/dist/direction.cjs +1 -1
  25. package/dist/direction.js +1 -1
  26. package/dist/index-4GlOgZuh.js +99 -0
  27. package/dist/{direction-C-b6XTeU.cjs → index-B58dnYRu.cjs} +1 -1
  28. package/dist/index-BMGaoK93.cjs +1 -0
  29. package/dist/index-BTet04Hd.cjs +6 -0
  30. package/dist/{scale-DfJe9755.js → index-BUa-NXAX.js} +46 -46
  31. package/dist/{xy-D_LqxaGt.js → index-C-qYOegc.js} +62 -62
  32. package/dist/index-C07SBJhr.js +128 -0
  33. package/dist/{bounds-Bn5_l4Z3.js → index-C9EdKeu1.js} +77 -76
  34. package/dist/index-CM8ZDZ6s.cjs +1 -0
  35. package/dist/index-CV2JaHfw.cjs +1 -0
  36. package/dist/index-CeBvOwG8.cjs +3 -0
  37. package/dist/index-ClrGyGDp.js +205 -0
  38. package/dist/index-CqQXXeCI.cjs +1 -0
  39. package/dist/{location-C3aeu046.js → index-D6V-8SKw.js} +26 -26
  40. package/dist/index-DBGAIs_7.js +2492 -0
  41. package/dist/index-DEdq2tza.cjs +1 -0
  42. package/dist/index-DKMnHBGR.cjs +1 -0
  43. package/dist/index-Dql5FMcH.js +47 -0
  44. package/dist/{direction-BL0PhD1k.js → index-DxU1zwsd.js} +1 -1
  45. package/dist/index-WwMnwoLy.cjs +1 -0
  46. package/dist/index.cjs +5 -3
  47. package/dist/index.js +5372 -649
  48. package/dist/kv.cjs +1 -1
  49. package/dist/kv.js +45 -2
  50. package/dist/location.cjs +1 -1
  51. package/dist/location.js +1 -1
  52. package/dist/position.cjs +1 -1
  53. package/dist/position.js +83 -2
  54. package/dist/record.cjs +1 -1
  55. package/dist/record.js +8 -10
  56. package/dist/runtime.cjs +1 -1
  57. package/dist/runtime.js +27 -2
  58. package/dist/scale.cjs +1 -1
  59. package/dist/scale.js +1 -1
  60. package/dist/schemas-55Usj0Fg.js +3998 -0
  61. package/dist/schemas-DbXuI2Qr.cjs +27 -0
  62. package/dist/spatial.cjs +1 -1
  63. package/dist/spatial.js +25 -18
  64. package/dist/src/array/index.d.ts +2 -0
  65. package/dist/src/array/index.d.ts.map +1 -0
  66. package/dist/src/array/toArray.d.ts +19 -0
  67. package/dist/src/array/toArray.d.ts.map +1 -0
  68. package/dist/src/array/toArray.spec.d.ts +2 -0
  69. package/dist/src/array/toArray.spec.d.ts.map +1 -0
  70. package/dist/src/binary/codec.d.ts +8 -16
  71. package/dist/src/binary/codec.d.ts.map +1 -1
  72. package/dist/src/breaker/breaker.d.ts +6 -6
  73. package/dist/src/breaker/breaker.d.ts.map +1 -1
  74. package/dist/src/caseconv/caseconv.d.ts +1 -1
  75. package/dist/src/caseconv/caseconv.d.ts.map +1 -1
  76. package/dist/src/change/change.d.ts +3 -3
  77. package/dist/src/change/change.d.ts.map +1 -1
  78. package/dist/src/color/color.d.ts +63 -28
  79. package/dist/src/color/color.d.ts.map +1 -1
  80. package/dist/src/color/external.d.ts +0 -1
  81. package/dist/src/color/external.d.ts.map +1 -1
  82. package/dist/src/color/gradient.d.ts +9 -5
  83. package/dist/src/color/gradient.d.ts.map +1 -1
  84. package/dist/src/color/palette.d.ts +14 -6
  85. package/dist/src/color/palette.d.ts.map +1 -1
  86. package/dist/src/compare/compare.d.ts +4 -4
  87. package/dist/src/compare/compare.d.ts.map +1 -1
  88. package/dist/src/control/control.d.ts +32 -32
  89. package/dist/src/control/control.d.ts.map +1 -1
  90. package/dist/src/debounce/debounce.d.ts +1 -1
  91. package/dist/src/debounce/debounce.d.ts.map +1 -1
  92. package/dist/src/deep/delete.d.ts +1 -1
  93. package/dist/src/deep/delete.d.ts.map +1 -1
  94. package/dist/src/deep/difference.d.ts.map +1 -1
  95. package/dist/src/deep/equal.d.ts +4 -4
  96. package/dist/src/deep/equal.d.ts.map +1 -1
  97. package/dist/src/deep/merge.d.ts +1 -1
  98. package/dist/src/deep/merge.d.ts.map +1 -1
  99. package/dist/src/errors/errors.d.ts +62 -36
  100. package/dist/src/errors/errors.d.ts.map +1 -1
  101. package/dist/src/index.d.ts +4 -1
  102. package/dist/src/index.d.ts.map +1 -1
  103. package/dist/src/instance/index.d.ts +2 -0
  104. package/dist/src/instance/index.d.ts.map +1 -0
  105. package/dist/src/instance/matcher.d.ts +79 -0
  106. package/dist/src/instance/matcher.d.ts.map +1 -0
  107. package/dist/src/instance/matcher.spec.d.ts +2 -0
  108. package/dist/src/instance/matcher.spec.d.ts.map +1 -0
  109. package/dist/src/jsonrpc/jsonrpc.d.ts +40 -9
  110. package/dist/src/jsonrpc/jsonrpc.d.ts.map +1 -1
  111. package/dist/src/kv/types.d.ts +2 -2
  112. package/dist/src/kv/types.d.ts.map +1 -1
  113. package/dist/src/migrate/migrate.d.ts +5 -5
  114. package/dist/src/migrate/migrate.d.ts.map +1 -1
  115. package/dist/src/notation/notation.d.ts +1 -1
  116. package/dist/src/notation/notation.d.ts.map +1 -1
  117. package/dist/src/primitive/index.d.ts +2 -0
  118. package/dist/src/primitive/index.d.ts.map +1 -0
  119. package/dist/src/primitive/primitive.d.ts +39 -0
  120. package/dist/src/primitive/primitive.d.ts.map +1 -0
  121. package/dist/src/primitive/primitive.spec.d.ts +2 -0
  122. package/dist/src/primitive/primitive.spec.d.ts.map +1 -0
  123. package/dist/src/record.d.ts +2 -2
  124. package/dist/src/record.d.ts.map +1 -1
  125. package/dist/src/renderable.d.ts +1 -1
  126. package/dist/src/renderable.d.ts.map +1 -1
  127. package/dist/src/replace.d.ts.map +1 -1
  128. package/dist/src/runtime/detect.d.ts.map +1 -1
  129. package/dist/src/runtime/os.d.ts +1 -1
  130. package/dist/src/runtime/os.d.ts.map +1 -1
  131. package/dist/src/spatial/base.d.ts +10 -10
  132. package/dist/src/spatial/base.d.ts.map +1 -1
  133. package/dist/src/spatial/bounds/bounds.d.ts +82 -16
  134. package/dist/src/spatial/bounds/bounds.d.ts.map +1 -1
  135. package/dist/src/spatial/box/box.d.ts +7 -7
  136. package/dist/src/spatial/box/box.d.ts.map +1 -1
  137. package/dist/src/spatial/dimensions/dimensions.d.ts +5 -5
  138. package/dist/src/spatial/dimensions/dimensions.d.ts.map +1 -1
  139. package/dist/src/spatial/direction/direction.d.ts +1 -1
  140. package/dist/src/spatial/location/location.d.ts +4 -4
  141. package/dist/src/spatial/location/location.d.ts.map +1 -1
  142. package/dist/src/spatial/scale/scale.d.ts +11 -11
  143. package/dist/src/spatial/scale/scale.d.ts.map +1 -1
  144. package/dist/src/spatial/xy/xy.d.ts +5 -5
  145. package/dist/src/spatial/xy/xy.d.ts.map +1 -1
  146. package/dist/src/status/index.d.ts +2 -0
  147. package/dist/src/status/index.d.ts.map +1 -0
  148. package/dist/src/status/types.d.ts +11 -0
  149. package/dist/src/status/types.d.ts.map +1 -0
  150. package/dist/src/sync/index.d.ts.map +1 -1
  151. package/dist/src/sync/mutex.d.ts +0 -1
  152. package/dist/src/sync/mutex.d.ts.map +1 -1
  153. package/dist/src/telem/gl.d.ts +1 -1
  154. package/dist/src/telem/gl.d.ts.map +1 -1
  155. package/dist/src/telem/series.d.ts +468 -62
  156. package/dist/src/telem/series.d.ts.map +1 -1
  157. package/dist/src/telem/telem.d.ts +243 -53
  158. package/dist/src/telem/telem.d.ts.map +1 -1
  159. package/dist/src/uuid/index.d.ts +2 -0
  160. package/dist/src/uuid/index.d.ts.map +1 -0
  161. package/dist/src/uuid/uuid.d.ts +35 -0
  162. package/dist/src/uuid/uuid.d.ts.map +1 -0
  163. package/dist/src/uuid/uuid.spec.d.ts +2 -0
  164. package/dist/src/uuid/uuid.spec.d.ts.map +1 -0
  165. package/dist/src/zod/external.d.ts +1 -1
  166. package/dist/src/zod/external.d.ts.map +1 -1
  167. package/dist/src/zod/nullToUndefined.d.ts +3 -0
  168. package/dist/src/zod/nullToUndefined.d.ts.map +1 -0
  169. package/dist/src/zod/nullToUndefined.spec.d.ts +2 -0
  170. package/dist/src/zod/nullToUndefined.spec.d.ts.map +1 -0
  171. package/dist/src/zod/util.d.ts +2 -2
  172. package/dist/src/zod/util.d.ts.map +1 -1
  173. package/dist/telem.cjs +1 -1
  174. package/dist/telem.js +1 -1
  175. package/dist/xy.cjs +1 -1
  176. package/dist/xy.js +1 -1
  177. package/dist/zod.cjs +1 -1
  178. package/dist/zod.js +19 -2
  179. package/eslint.config.js +1 -1
  180. package/package.json +16 -14
  181. package/src/{toArray.ts → array/index.ts} +1 -5
  182. package/src/array/toArray.spec.ts +56 -0
  183. package/src/array/toArray.ts +28 -0
  184. package/src/binary/codec.spec.ts +201 -278
  185. package/src/binary/codec.ts +20 -76
  186. package/src/breaker/breaker.ts +3 -3
  187. package/src/caseconv/caseconv.ts +6 -4
  188. package/src/change/change.ts +2 -2
  189. package/src/color/color.spec.ts +121 -2
  190. package/src/color/color.ts +90 -54
  191. package/src/color/external.ts +0 -1
  192. package/src/color/gradient.ts +20 -28
  193. package/src/color/palette.ts +1 -1
  194. package/src/compare/compare.ts +5 -5
  195. package/src/control/control.ts +22 -19
  196. package/src/debounce/debounce.ts +1 -1
  197. package/src/deep/delete.ts +5 -4
  198. package/src/deep/difference.ts +6 -2
  199. package/src/deep/equal.spec.ts +1 -1
  200. package/src/deep/equal.ts +5 -5
  201. package/src/deep/merge.spec.ts +13 -1
  202. package/src/deep/merge.ts +16 -7
  203. package/src/deep/path.ts +1 -1
  204. package/src/errors/errors.ts +65 -44
  205. package/src/index.ts +4 -1
  206. package/src/instance/index.ts +10 -0
  207. package/src/instance/matcher.spec.ts +78 -0
  208. package/src/instance/matcher.ts +98 -0
  209. package/src/jsonrpc/jsonrpc.spec.ts +2 -1
  210. package/src/jsonrpc/jsonrpc.ts +36 -7
  211. package/src/kv/types.ts +1 -1
  212. package/src/migrate/migrate.spec.ts +1 -1
  213. package/src/migrate/migrate.ts +7 -7
  214. package/src/notation/notation.ts +1 -1
  215. package/src/primitive/index.ts +10 -0
  216. package/src/primitive/primitive.spec.ts +126 -0
  217. package/src/primitive/primitive.ts +82 -0
  218. package/src/record.ts +3 -5
  219. package/src/renderable.ts +1 -1
  220. package/src/replace.ts +9 -0
  221. package/src/runtime/detect.ts +0 -2
  222. package/src/runtime/os.ts +1 -1
  223. package/src/spatial/base.ts +1 -1
  224. package/src/spatial/bounds/bounds.spec.ts +20 -0
  225. package/src/spatial/bounds/bounds.ts +101 -18
  226. package/src/spatial/box/box.ts +1 -1
  227. package/src/spatial/dimensions/dimensions.ts +3 -3
  228. package/src/spatial/location/location.ts +1 -1
  229. package/src/spatial/scale/scale.ts +1 -1
  230. package/src/spatial/xy/xy.ts +1 -1
  231. package/src/status/index.ts +10 -0
  232. package/src/status/types.ts +22 -0
  233. package/src/sync/index.ts +9 -0
  234. package/src/sync/mutex.ts +9 -4
  235. package/src/telem/gl.ts +1 -1
  236. package/src/telem/series.spec.ts +735 -68
  237. package/src/telem/series.ts +536 -195
  238. package/src/telem/telem.spec.ts +60 -7
  239. package/src/telem/telem.ts +287 -95
  240. package/src/uuid/index.ts +10 -0
  241. package/src/uuid/uuid.spec.ts +82 -0
  242. package/src/uuid/uuid.ts +48 -0
  243. package/src/zod/external.ts +1 -1
  244. package/src/zod/nullToUndefined.spec.ts +31 -0
  245. package/src/zod/nullToUndefined.ts +23 -0
  246. package/src/zod/util.spec.ts +1 -1
  247. package/src/zod/util.ts +6 -6
  248. package/tsconfig.json +1 -1
  249. package/tsconfig.tsbuildinfo +1 -1
  250. package/vite.config.ts +1 -1
  251. package/dist/base-BAM2mqCy.cjs +0 -1
  252. package/dist/base-DFq0vvGn.js +0 -38
  253. package/dist/bounds-BQo7rvs9.cjs +0 -1
  254. package/dist/box-0YrQibkB.cjs +0 -1
  255. package/dist/box-Cc8IzcNo.js +0 -205
  256. package/dist/change-C-YELKx6.cjs +0 -1
  257. package/dist/change-DLl6DccR.js +0 -12
  258. package/dist/dimensions-CRgergMS.js +0 -43
  259. package/dist/dimensions-D2QGoNXO.cjs +0 -1
  260. package/dist/external-BPgtxa8d.js +0 -29
  261. package/dist/external-C-dNgNQw.cjs +0 -1
  262. package/dist/external-C8TFju8Q.js +0 -29
  263. package/dist/external-DWQITF5_.cjs +0 -1
  264. package/dist/external-DqPrWKvU.js +0 -47
  265. package/dist/external-uXk0Avrg.cjs +0 -1
  266. package/dist/index-BywOGO8U.js +0 -1074
  267. package/dist/index-CYYjI7Uf.cjs +0 -1
  268. package/dist/index-C_6NXBlg.cjs +0 -3
  269. package/dist/index-Dd8DLyMx.cjs +0 -1
  270. package/dist/index-DizUWH6z.js +0 -47
  271. package/dist/index-QGplUHuy.js +0 -98
  272. package/dist/location-BGl5Ddds.cjs +0 -1
  273. package/dist/position-Cai5-wi1.cjs +0 -1
  274. package/dist/position-DIglP1l2.js +0 -85
  275. package/dist/scale-BtZINJ-A.cjs +0 -1
  276. package/dist/series-B9JERcqi.js +0 -1977
  277. package/dist/series-DqJ6f97G.cjs +0 -11
  278. package/dist/spatial-BSWPzMkK.js +0 -11
  279. package/dist/spatial-DGpZ2sO3.cjs +0 -1
  280. package/dist/src/color/transformColorsToHex.d.ts +0 -6
  281. package/dist/src/color/transformColorsToHex.d.ts.map +0 -1
  282. package/dist/src/primitive.d.ts +0 -9
  283. package/dist/src/primitive.d.ts.map +0 -1
  284. package/dist/src/toArray.d.ts +0 -3
  285. package/dist/src/toArray.d.ts.map +0 -1
  286. package/dist/src/zod/integer.d.ts +0 -10
  287. package/dist/src/zod/integer.d.ts.map +0 -1
  288. package/dist/src/zod/integer.spec.d.ts +0 -2
  289. package/dist/src/zod/integer.spec.d.ts.map +0 -1
  290. package/dist/toArray.cjs +0 -1
  291. package/dist/toArray.js +0 -5
  292. package/dist/xy-B7065J2S.cjs +0 -1
  293. package/src/color/transformColorsToHex.ts +0 -30
  294. package/src/primitive.ts +0 -46
  295. package/src/zod/integer.spec.ts +0 -148
  296. package/src/zod/integer.ts +0 -38
@@ -10,4 +10,3 @@
10
10
  export * from "@/color/color";
11
11
  export * from "@/color/gradient";
12
12
  export * from "@/color/palette";
13
- export * from "@/color/transformColorsToHex";
@@ -7,7 +7,7 @@
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 { z } from "zod";
10
+ import { z } from "zod/v4";
11
11
 
12
12
  import {
13
13
  aValue,
@@ -41,38 +41,30 @@ export const fromGradient = (gradient: Gradient, position: number): Color => {
41
41
  if (position >= gradient[gradient.length - 1].position)
42
42
  return construct(gradient[gradient.length - 1].color);
43
43
 
44
- // Find the two stops between which the position lies
45
44
  for (let i = 0; i < gradient.length - 1; i++) {
46
45
  const start = gradient[i];
47
46
  const end = gradient[i + 1];
48
47
 
49
- if (position >= start.position && position <= end.position) {
50
- if (position === start.position) return construct(start.color);
51
-
52
- if (position === end.position) return construct(end.color);
53
-
54
- // Interpolate
55
- const t = (position - start.position) / (end.position - start.position);
56
-
57
- // Convert colors to RGBA
58
- const startColor = construct(start.color);
59
- const endColor = construct(end.color);
60
-
61
- const r = Math.round(
62
- rValue(startColor) + t * (rValue(endColor) - rValue(startColor)),
63
- );
64
- const g = Math.round(
65
- gValue(startColor) + t * (gValue(endColor) - gValue(startColor)),
66
- );
67
- const b = Math.round(
68
- bValue(startColor) + t * (bValue(endColor) - bValue(startColor)),
69
- );
70
- const a = aValue(startColor) + t * (aValue(endColor) - aValue(startColor)); // Interpolate alpha directly
71
-
72
- return construct([r, g, b, a]);
73
- }
48
+ if (position < start.position || position > end.position) continue;
49
+ if (position === start.position) return construct(start.color);
50
+ if (position === end.position) return construct(end.color);
51
+ const t = (position - start.position) / (end.position - start.position);
52
+ const startColor = construct(start.color);
53
+ const endColor = construct(end.color);
54
+
55
+ const r = Math.round(
56
+ rValue(startColor) + t * (rValue(endColor) - rValue(startColor)),
57
+ );
58
+ const g = Math.round(
59
+ gValue(startColor) + t * (gValue(endColor) - gValue(startColor)),
60
+ );
61
+ const b = Math.round(
62
+ bValue(startColor) + t * (bValue(endColor) - bValue(startColor)),
63
+ );
64
+ const a = aValue(startColor) + t * (aValue(endColor) - aValue(startColor));
65
+
66
+ return construct([r, g, b, a]);
74
67
  }
75
68
 
76
- // If position didn't match any interval, return the last color
77
69
  return construct(gradient[gradient.length - 1].color);
78
70
  };
@@ -7,7 +7,7 @@
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 { z } from "zod";
10
+ import { z } from "zod/v4";
11
11
 
12
12
  import { colorZ } from "@/color/color";
13
13
 
@@ -7,7 +7,7 @@
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 { isStringer, type Primitive } from "@/primitive";
10
+ import { primitive } from "@/primitive";
11
11
  import { type spatial } from "@/spatial";
12
12
  import { unique } from "@/unique";
13
13
 
@@ -22,7 +22,7 @@ export type CompareF<T> = (a: T, b: T) => number;
22
22
  * @param reverse Whether to reverse the sort order.
23
23
  */
24
24
  export const newF = <T>(v: T, reverse: boolean = false): CompareF<T> => {
25
- const t = isStringer(v) ? "stringer" : typeof v;
25
+ const t = primitive.isStringer(v) ? "stringer" : typeof v;
26
26
  let f: CompareF<T>;
27
27
  switch (t) {
28
28
  case "string":
@@ -75,7 +75,7 @@ export const newFieldF = <T>(
75
75
  * @returns The array with the greater length if the array lengths are not equal. If the
76
76
  * arrays are the same length, returns 0 if all elements are equal, otherwise returns -1.
77
77
  */
78
- export const primitiveArrays = <T extends Primitive>(
78
+ export const primitiveArrays = <T extends primitive.Value>(
79
79
  a: readonly T[] | T[],
80
80
  b: readonly T[] | T[],
81
81
  ): number => {
@@ -83,7 +83,7 @@ export const primitiveArrays = <T extends Primitive>(
83
83
  return a.every((v, i) => v === b[i]) ? 0 : -1;
84
84
  };
85
85
 
86
- export const unorderedPrimitiveArrays = <T extends Primitive>(
86
+ export const unorderedPrimitiveArrays = <T extends primitive.Value>(
87
87
  a: readonly T[] | T[],
88
88
  b: readonly T[] | T[],
89
89
  ): number => {
@@ -95,7 +95,7 @@ export const unorderedPrimitiveArrays = <T extends Primitive>(
95
95
  return aSorted.every((v, i) => v === bSorted[i]) ? 0 : -1;
96
96
  };
97
97
 
98
- export const uniqueUnorderedPrimitiveArrays = <T extends Primitive>(
98
+ export const uniqueUnorderedPrimitiveArrays = <T extends primitive.Value>(
99
99
  a: readonly T[] | T[],
100
100
  b: readonly T[] | T[],
101
101
  ): number => {
@@ -7,7 +7,7 @@
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 { z } from "zod";
10
+ import { z } from "zod/v4";
11
11
 
12
12
  import { type bounds } from "@/spatial";
13
13
 
@@ -32,10 +32,10 @@ export interface Subject {
32
32
  key: string;
33
33
  }
34
34
 
35
- export const stateZ = <T extends z.ZodTypeAny>(r: T) =>
35
+ export const stateZ = <R extends z.ZodType>(resource: R) =>
36
36
  z.object({
37
37
  subject: subjectZ,
38
- resource: r,
38
+ resource,
39
39
  authority: authorityZ,
40
40
  });
41
41
 
@@ -60,20 +60,22 @@ interface Release<R> {
60
60
  to?: null;
61
61
  }
62
62
 
63
- export const releaseZ = z.object({
64
- from: stateZ(z.any()),
65
- to: z.null(),
66
- });
63
+ export const releaseZ = <R extends z.ZodType>(resource: R) =>
64
+ z.object({
65
+ from: stateZ(resource),
66
+ to: z.null(),
67
+ });
67
68
 
68
69
  interface Acquire<R> {
69
70
  from?: null;
70
71
  to: State<R>;
71
72
  }
72
73
 
73
- export const acquireZ = z.object({
74
- from: z.null(),
75
- to: stateZ(z.any()),
76
- });
74
+ export const acquireZ = <R extends z.ZodType>(resource: R) =>
75
+ z.object({
76
+ from: z.null(),
77
+ to: stateZ(resource),
78
+ });
77
79
 
78
80
  export type Transfer<R> =
79
81
  | {
@@ -83,11 +85,12 @@ export type Transfer<R> =
83
85
  | Release<R>
84
86
  | Acquire<R>;
85
87
 
86
- export const transferZ = z.union([
87
- releaseZ,
88
- acquireZ,
89
- z.object({
90
- from: stateZ(z.any()),
91
- to: stateZ(z.any()),
92
- }),
93
- ]);
88
+ export const transferZ = <R extends z.ZodType>(resource: R) =>
89
+ z.union([
90
+ releaseZ(resource),
91
+ acquireZ(resource),
92
+ z.object({
93
+ from: stateZ(resource),
94
+ to: stateZ(resource),
95
+ }),
96
+ ]);
@@ -25,7 +25,7 @@ export const debounce = <F extends (...args: any[]) => void>(
25
25
  return debounced as F;
26
26
  };
27
27
 
28
- export const throttle = <F extends (...args: any[]) => void>(
28
+ export const throttle = <F extends (...args: unknown[]) => void>(
29
29
  func: F,
30
30
  waitFor: number,
31
31
  ): F => {
@@ -10,16 +10,17 @@
10
10
  import { type Key } from "@/deep/path";
11
11
 
12
12
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
13
- export const deleteD = <T extends any, D extends number = 5>(
13
+ export const deleteD = <T extends unknown, D extends number = 5>(
14
14
  target: T,
15
15
  ...keys: Array<Key<T, D>>
16
16
  ): T => {
17
17
  keys.forEach((key) => {
18
- let curr: any = target;
18
+ let curr = target;
19
19
  const arr = key.split(".");
20
20
  arr.forEach((k, i) => {
21
- if (i === arr.length - 1) delete curr[k];
22
- else if (k in curr) curr = curr[k];
21
+ if (typeof curr !== "object" || curr === null) return;
22
+ if (i === arr.length - 1) delete curr[k as keyof typeof curr];
23
+ else if (k in curr) curr = curr[k as keyof typeof curr] as T;
23
24
  });
24
25
  });
25
26
  return target;
@@ -16,7 +16,7 @@ export const difference = (
16
16
  ): Record<string, PathValueTuple> => {
17
17
  const diffMap: Record<string, PathValueTuple> = {};
18
18
 
19
- const compare = (a: any, b: any, currentPath: string): void => {
19
+ const compare = (a: unknown, b: unknown, currentPath: string): void => {
20
20
  if (typeof a !== typeof b || a === null || b === null) {
21
21
  diffMap[currentPath] = [a, b];
22
22
  return;
@@ -32,7 +32,11 @@ export const difference = (
32
32
  } else {
33
33
  const keys = new Set([...Object.keys(a as {}), ...Object.keys(b as {})]);
34
34
  keys.forEach((key) => {
35
- compare(a[key], b[key], currentPath !== "" ? `${currentPath}.${key}` : key);
35
+ compare(
36
+ a[key as keyof typeof a],
37
+ b[key as keyof typeof b],
38
+ currentPath !== "" ? `${currentPath}.${key}` : key,
39
+ );
36
40
  });
37
41
  }
38
42
  else if (a !== b) diffMap[currentPath] = [a, b];
@@ -7,7 +7,7 @@
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,it } from "vitest";
10
+ import { describe, expect, it } from "vitest";
11
11
 
12
12
  import { deep } from "@/deep";
13
13
 
package/src/deep/equal.ts CHANGED
@@ -7,14 +7,14 @@
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 Primitive } from "@/primitive";
10
+ import { type primitive } from "@/primitive";
11
11
 
12
12
  interface DeepEqualBaseRecord {
13
- equals?: (other: any) => boolean;
13
+ equals?: (other: unknown) => boolean;
14
14
  }
15
15
 
16
16
  export const equal = <
17
- T extends unknown | DeepEqualBaseRecord | DeepEqualBaseRecord[] | Primitive[],
17
+ T extends unknown | DeepEqualBaseRecord | DeepEqualBaseRecord[] | primitive.Value[],
18
18
  >(
19
19
  a: T,
20
20
  b: T,
@@ -31,7 +31,7 @@ export const equal = <
31
31
  }
32
32
  if (a == null || b == null || typeof a !== "object" || typeof b !== "object")
33
33
  return a === b;
34
- if ("equals" in a) return (a.equals as (other: any) => boolean)(b);
34
+ if ("equals" in a) return (a.equals as (other: unknown) => boolean)(b);
35
35
  const aKeys = Object.keys(a);
36
36
  const bKeys = Object.keys(b);
37
37
  if (aKeys.length !== bKeys.length) return false;
@@ -47,7 +47,7 @@ export const equal = <
47
47
  return true;
48
48
  };
49
49
 
50
- export const partialEqual = <T extends unknown | DeepEqualBaseRecord | Primitive>(
50
+ export const partialEqual = <T extends unknown | DeepEqualBaseRecord | primitive.Value>(
51
51
  base: T,
52
52
  partial: Partial<T>,
53
53
  ): boolean => {
@@ -8,7 +8,7 @@
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
10
  import { describe, expect, it } from "vitest";
11
- import { z } from "zod";
11
+ import { z } from "zod/v4";
12
12
 
13
13
  import { deep } from "@/deep";
14
14
 
@@ -243,6 +243,18 @@ describe("deepMerge", () => {
243
243
  });
244
244
  });
245
245
 
246
+ it("should work with multiple extensions", () => {
247
+ const az = z.object({ a: z.number() });
248
+ const cz = z.object({ c: z.boolean() });
249
+ const extendedSchema = az.extend(cz);
250
+ const base = { a: 1 };
251
+ const override = { b: "2", c: true };
252
+ expect(deep.overrideValidItems(base, override, extendedSchema)).toEqual({
253
+ a: 1,
254
+ c: true,
255
+ });
256
+ });
257
+
246
258
  it("should work with intersection", () => {
247
259
  const schema1 = z.object({
248
260
  a: z.number(),
package/src/deep/merge.ts CHANGED
@@ -7,7 +7,7 @@
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 z } from "zod";
10
+ import { type z } from "zod/v4";
11
11
 
12
12
  import { type Partial } from "@/deep/partial";
13
13
  import { isObject } from "@/identity";
@@ -61,12 +61,21 @@ export const overrideValidItems = <A, B>(
61
61
  // Iterate over each property in the override object
62
62
  for (const key in overrideObj) {
63
63
  const overrideValue = overrideObj[key];
64
- const shape = currentSchema?.shape;
65
- if (shape?.[key]) {
66
- const result = shape[key].safeParse(overrideValue);
67
- // Check if parsing succeeded
68
- if (result.success) baseObj[key] = result.data;
69
- } else if (
64
+ let shape = currentSchema?.shape;
65
+ if (shape != null)
66
+ while (shape != null) {
67
+ if (shape[key] != null) {
68
+ const result = shape[key].safeParse(overrideValue);
69
+ // Check if parsing succeeded
70
+ if (result.success) {
71
+ baseObj[key] = result.data;
72
+ break;
73
+ }
74
+ }
75
+ shape = shape.def?.shape;
76
+ }
77
+
78
+ if (
70
79
  typeof overrideValue === "object" &&
71
80
  !Array.isArray(overrideValue) &&
72
81
  overrideValue !== null
package/src/deep/path.ts CHANGED
@@ -133,7 +133,7 @@ export const get = (<V = unknown, T = UnknownRecord>(
133
133
  opts: GetOptions = { optional: false, separator: "." },
134
134
  ): V | null => {
135
135
  opts.separator ??= ".";
136
- const { optional, getter = (obj, key) => (obj)[key] } = opts;
136
+ const { optional, getter = (obj, key) => obj[key] } = opts;
137
137
  const parts = path.split(opts.separator);
138
138
  if (parts.length === 1 && parts[0] === "") return obj as unknown as V;
139
139
  let result: UnknownRecord = obj as UnknownRecord;
@@ -7,59 +7,60 @@
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 { z } from "zod";
10
+ import { z } from "zod/v4";
11
11
 
12
12
  import { singleton } from "@/singleton";
13
13
 
14
+ const ERROR_DISCRIMINATOR = "sy_x_error";
15
+
14
16
  /**
15
17
  * @returns general function that returns true if an error matches a set of
16
18
  * abstracted criteria
17
19
  */
18
- export type Matcher = (e: string | Error | unknown) => boolean;
20
+ export type Matcher = (e: unknown) => boolean;
19
21
 
20
- /** @description an error type that can match against other errors. */
22
+ /** an error type that can match against other errors. */
21
23
  export interface Matchable {
22
24
  /**
23
- * @returns a function that matches errors of the given type. Returns true if
24
- * the provided instance of Error or a string message contains the provided error type.
25
+ * @returns true if the provided error matches the matchable.
25
26
  */
26
27
  matches: Matcher;
27
28
  }
28
29
 
29
30
  /**
30
- * @description an error that has a network-portable type, allowing it to be encoded/
31
- * decoded by freighter. Also allows for simpler matching using @method matches instead
32
- * of using instanceof, which has a number of caveats.
31
+ * An error that has a network-portable type, allowing it to be encoded/decoded into
32
+ * a JSON representation. Also allows for simpler matching using @method matches instead of using
33
+ * instanceof, which has a number of caveats.
33
34
  */
34
35
  export interface Typed extends Error, Matchable {
35
- discriminator: "FreighterError";
36
+ discriminator: typeof ERROR_DISCRIMINATOR;
36
37
  /**
37
- * @description Returns a unique type identifier for the error. Freighter uses this to
38
- * determine the correct decoder to use on the other end of the freighter.
38
+ * Returns a unique type identifier for the error. The errors package uses this to
39
+ * determine the correct decoder to use when encoding/decoding errors.
39
40
  */
40
41
  type: string;
41
42
  }
42
43
 
43
44
  /**
44
- * @description a class that, when constructed, implements the TypedError interface.
45
- * Also provides utilities for matching and creating subclasses.
45
+ * a class that, when constructed, implements the TypedError interface. Also provides
46
+ * utilities for matching and creating subclasses.
46
47
  */
47
48
  export interface TypedClass extends Matchable {
48
49
  /**
49
- * @description constructs a new TypedError. Identical to the Error constructor.
50
+ * constructs a new TypedError. Identical to the Error constructor.
50
51
  * @param message - the error message.
51
52
  * @param options - the error options.
52
53
  * @returns a new TypedError.
53
54
  */
54
55
  new (message?: string, options?: ErrorOptions): Typed;
55
56
  /**
56
- * @description the type of the error.
57
+ * the type of the error.
57
58
  */
58
59
  TYPE: string;
59
60
  /**
60
- * @description creates a new subclass of the error that extends its type. So if
61
- * the type of this class is `dog` and subType is `labrador`, the type of the new
62
- * class will be `dog.labrador`.
61
+ * creates a new subclass of the error that extends its type. So if the type of this
62
+ * class is `dog` and subType is `labrador`, the type of the new class will be
63
+ * `dog.labrador`.
63
64
  * @param subType - the type of the new error.
64
65
  * @returns a new TypedErrorClass.
65
66
  */
@@ -92,7 +93,7 @@ const createTypeMatcher =
92
93
  */
93
94
  export const createTyped = (type: string): TypedClass =>
94
95
  class Internal extends Error implements Typed {
95
- static readonly discriminator = "FreighterError";
96
+ static readonly discriminator = ERROR_DISCRIMINATOR;
96
97
  readonly discriminator = Internal.discriminator;
97
98
 
98
99
  static readonly TYPE = type;
@@ -111,50 +112,67 @@ export const createTyped = (type: string): TypedClass =>
111
112
  };
112
113
 
113
114
  /**
114
- * @description Function that decodes an encoded error payload back into an error object
115
+ * Function that decodes an encoded error payload back into an error object
115
116
  * @param encoded - The encoded error payload to decode
116
- * @returns The decoded error object or null if the decoder cannot handle this error type
117
+ * @returns The decoded error object or null if the decoder cannot handle this error
118
+ * type
117
119
  */
118
120
  export type Decoder = (encoded: Payload) => Error | null;
119
121
 
120
122
  /**
121
- * @description Function that encodes a typed error into a network-portable payload
123
+ * Function that encodes a typed error into a network-portable payload
122
124
  * @param error - The typed error to encode
123
125
  * @returns The encoded error payload or null if the encoder cannot handle this error type
124
126
  */
125
127
  export type Encoder = (error: Typed) => Payload | null;
126
128
 
127
129
  /**
128
- * @description Checks if an unknown value is a TypedError
130
+ * Checks if an unknown value is a TypedError
129
131
  * @param error - The value to check
130
132
  * @returns True if the value is a TypedError, false otherwise
131
133
  */
132
134
  export const isTyped = (error: unknown): error is Typed => {
133
135
  if (error == null || typeof error !== "object") return false;
134
136
  const typedError = error as Typed;
135
- if (typedError.discriminator !== "FreighterError") return false;
137
+ if (typedError.discriminator !== ERROR_DISCRIMINATOR) return false;
136
138
  if (!("type" in typedError))
137
139
  throw new Error(
138
- `Freighter error is missing its type property: ${JSON.stringify(typedError)}`,
140
+ `X Error is missing its type property: ${JSON.stringify(typedError)}`,
139
141
  );
140
142
  return true;
141
143
  };
142
144
 
143
- /** @description Constant representing an unknown error type */
145
+ /** Constant representing an unknown error type */
144
146
  export const UNKNOWN = "unknown";
145
147
 
146
- /** @description Constant representing no error (null) */
148
+ /** Constant representing no error (null) */
147
149
  export const NONE = "nil";
148
150
 
149
- interface provider {
151
+ /**
152
+ * provides custom encoding/decoding mechanisms for specific error
153
+ * categories.
154
+ */
155
+ interface Provider {
156
+ /**
157
+ * Encodes an error into a primitive payload that can be sent over the network or stored
158
+ * on disk.
159
+ * @param error - The error to encode.
160
+ * @returns The encoded error.
161
+ */
150
162
  encode: Encoder;
163
+ /**
164
+ * Decodes an error from a primitive payload that can be sent over the network or stored
165
+ * on disk.
166
+ * @param payload - The encoded error.
167
+ * @returns The decoded error.
168
+ */
151
169
  decode: Decoder;
152
170
  }
153
171
 
154
172
  class Registry {
155
- private readonly providers: provider[] = [];
173
+ private readonly providers: Provider[] = [];
156
174
 
157
- register(provider: provider): void {
175
+ register(provider: Provider): void {
158
176
  this.providers.push(provider);
159
177
  }
160
178
 
@@ -195,17 +213,12 @@ const getRegistry = singleton.define("synnax-error-registry", () => new Registry
195
213
  * @param encode - A function that encodes the error into a string.
196
214
  * @param decode - A function that decodes the error from a string.
197
215
  */
198
- export const register = ({
199
- encode,
200
- decode,
201
- }: {
202
- encode: Encoder;
203
- decode: Decoder;
204
- }): void => getRegistry().register({ encode, decode });
216
+ export const register = ({ encode, decode }: Provider): void =>
217
+ getRegistry().register({ encode, decode });
205
218
 
206
219
  /**
207
- * Encodes an error into a payload that can be sent between a freighter server
208
- * and client.
220
+ * Encodes an error into a primitive payload that can be sent over the network or stored
221
+ * on disk.
209
222
  * @param error - The error to encode.
210
223
  * @returns The encoded error.
211
224
  */
@@ -225,17 +238,25 @@ export const decode = (payload?: Payload | null): Error | null => {
225
238
  };
226
239
 
227
240
  /**
228
- * @description Generic error for representing unknown errors
241
+ * Generic error for representing unknown errors
229
242
  */
230
243
  export class Unknown extends createTyped("unknown") {}
231
244
 
232
- /** @description Zod schema for validating error payloads */
245
+ /** Zod schema for validating error payloads */
233
246
  export const payloadZ = z.object({ type: z.string(), data: z.string() });
234
247
 
235
- /** @description Network-portable representation of an error */
248
+ /** Network-portable representation of an error */
236
249
  export type Payload = z.infer<typeof payloadZ>;
237
250
 
238
- /** @description Error for representing the cancellation of an operation */
251
+ /** Error for representing the cancellation of an operation */
239
252
  export class Canceled extends createTyped("canceled") {}
240
253
 
241
- export type Return<T> = [T, null] | [null, Error];
254
+ /** A payload representing a native JavaScript Error */
255
+ export interface NativePayload {
256
+ /** The name of the error */
257
+ name: string;
258
+ /** The message of the error */
259
+ message: string;
260
+ /** The stack trace of the error */
261
+ stack?: string;
262
+ }
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@
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
+ export * from "@/array";
10
11
  export * from "@/binary";
11
12
  export * from "@/breaker";
12
13
  export * from "@/caseconv";
@@ -21,6 +22,7 @@ export * from "@/destructor";
21
22
  export * from "@/errors";
22
23
  export * from "@/id";
23
24
  export * from "@/identity";
25
+ export * from "@/instance";
24
26
  export * from "@/invert";
25
27
  export * from "@/jsonrpc";
26
28
  export * from "@/kv";
@@ -40,12 +42,13 @@ export * from "@/search";
40
42
  export * from "@/shallowCopy";
41
43
  export * from "@/sleep";
42
44
  export * from "@/spatial";
45
+ export * from "@/status";
43
46
  export * from "@/strings";
44
47
  export * from "@/sync";
45
48
  export * from "@/telem";
46
- export * from "@/toArray";
47
49
  export * from "@/transform";
48
50
  export * from "@/unique";
49
51
  export * from "@/url";
52
+ export * from "@/uuid";
50
53
  export * from "@/worker";
51
54
  export * from "@/zod";
@@ -0,0 +1,10 @@
1
+ // Copyright 2025 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 instance from "@/instance/matcher";