@synnaxlabs/x 0.37.0 → 0.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/.turbo/turbo-build.log +38 -34
  2. package/dist/binary.js +1 -1
  3. package/dist/box-DPJAbf32.js +201 -0
  4. package/dist/box-Daep7oxr.cjs +1 -0
  5. package/dist/box.cjs +1 -1
  6. package/dist/box.js +1 -1
  7. package/dist/caseconv.js +1 -1
  8. package/dist/compare.cjs +1 -1
  9. package/dist/compare.js +1 -1
  10. package/dist/external-C-dNgNQw.cjs +1 -0
  11. package/dist/external-CtAt3tnU.js +29 -0
  12. package/dist/external-DSKjMZ7J.cjs +1 -0
  13. package/dist/external-DqPrWKvU.js +47 -0
  14. package/dist/index-BG3Scw3G.cjs +1 -0
  15. package/dist/{index-HQonyH7n.js → index-BVC_8Cg9.js} +1 -1
  16. package/dist/{index-OHIRoCei.js → index-C3QzbIwt.js} +1 -1
  17. package/dist/index-D4NCYiQB.js +19 -0
  18. package/dist/{index-BfDeGfej.js → index-DizUWH6z.js} +8 -2
  19. package/dist/index-udOjA9d-.cjs +1 -0
  20. package/dist/index.cjs +2 -2
  21. package/dist/index.js +57 -55
  22. package/dist/kv.cjs +1 -1
  23. package/dist/kv.js +2 -2
  24. package/dist/link.cjs +1 -0
  25. package/dist/link.js +10 -0
  26. package/dist/{location-C5Ot4MVG.js → location-BVkZhfQG.js} +1 -1
  27. package/dist/location.js +1 -1
  28. package/dist/position-96CBRKEd.cjs +1 -0
  29. package/dist/position-uVDP52PM.js +85 -0
  30. package/dist/position.cjs +1 -1
  31. package/dist/position.js +1 -1
  32. package/dist/runtime.cjs +1 -1
  33. package/dist/runtime.js +1 -1
  34. package/dist/{scale-BESJN9LG.cjs → scale-Bzjm1mhv.cjs} +1 -1
  35. package/dist/{scale-CV3O6tkY.js → scale-D_UMXSZN.js} +3 -3
  36. package/dist/scale.cjs +1 -1
  37. package/dist/scale.js +1 -1
  38. package/dist/{series-C_B2hAp9.js → series-Cwc_z2OS.js} +296 -286
  39. package/dist/series-DuOxifEy.cjs +11 -0
  40. package/dist/spatial.cjs +1 -1
  41. package/dist/spatial.js +5 -5
  42. package/dist/src/breaker/breaker.d.ts.map +1 -1
  43. package/dist/src/breaker/index.d.ts.map +1 -1
  44. package/dist/src/caseconv/caseconv.d.ts.map +1 -1
  45. package/dist/src/deep/path.d.ts.map +1 -1
  46. package/dist/src/index.d.ts +1 -0
  47. package/dist/src/index.d.ts.map +1 -1
  48. package/dist/src/kv/external.d.ts +3 -0
  49. package/dist/src/kv/external.d.ts.map +1 -0
  50. package/dist/src/kv/index.d.ts +1 -1
  51. package/dist/src/kv/index.d.ts.map +1 -1
  52. package/dist/src/kv/mock.d.ts +24 -0
  53. package/dist/src/kv/mock.d.ts.map +1 -0
  54. package/dist/src/kv/mock.spec.d.ts +2 -0
  55. package/dist/src/kv/mock.spec.d.ts.map +1 -0
  56. package/dist/src/kv/types.d.ts +18 -18
  57. package/dist/src/kv/types.d.ts.map +1 -1
  58. package/dist/src/link/index.d.ts +2 -0
  59. package/dist/src/link/index.d.ts.map +1 -0
  60. package/dist/src/link/link.d.ts +2 -0
  61. package/dist/src/link/link.d.ts.map +1 -0
  62. package/dist/src/link/link.spec.d.ts +2 -0
  63. package/dist/src/link/link.spec.d.ts.map +1 -0
  64. package/dist/src/runtime/os.d.ts +7 -7
  65. package/dist/src/runtime/os.d.ts.map +1 -1
  66. package/dist/src/sleep/index.d.ts.map +1 -1
  67. package/dist/src/sleep/sleep.d.ts.map +1 -1
  68. package/dist/src/telem/index.d.ts +1 -1
  69. package/dist/src/telem/index.d.ts.map +1 -1
  70. package/dist/src/telem/series.d.ts +1 -0
  71. package/dist/src/telem/series.d.ts.map +1 -1
  72. package/dist/src/telem/telem.d.ts +2 -0
  73. package/dist/src/telem/telem.d.ts.map +1 -1
  74. package/dist/src/testutil/index.d.ts +2 -0
  75. package/dist/src/testutil/index.d.ts.map +1 -0
  76. package/dist/src/testutil/testutil.d.ts +2 -0
  77. package/dist/src/testutil/testutil.d.ts.map +1 -0
  78. package/dist/src/unique/index.d.ts +2 -0
  79. package/dist/src/unique/index.d.ts.map +1 -0
  80. package/dist/src/unique/unique.d.ts +42 -0
  81. package/dist/src/unique/unique.d.ts.map +1 -0
  82. package/dist/src/unique/unique.spec.d.ts +2 -0
  83. package/dist/src/unique/unique.spec.d.ts.map +1 -0
  84. package/dist/src/url/url.d.ts +1 -1
  85. package/dist/src/url/url.d.ts.map +1 -1
  86. package/dist/src/zodutil/index.d.ts.map +1 -1
  87. package/dist/src/zodutil/zodutil.d.ts +1 -16
  88. package/dist/src/zodutil/zodutil.d.ts.map +1 -1
  89. package/dist/telem.cjs +1 -1
  90. package/dist/telem.js +1 -1
  91. package/dist/unique.cjs +1 -1
  92. package/dist/unique.js +2 -2
  93. package/dist/url.cjs +1 -1
  94. package/dist/url.js +5 -5
  95. package/dist/{xy-LADI2wVU.cjs → xy-Budz-qz-.cjs} +1 -1
  96. package/dist/{xy-DQdccWlc.js → xy-DxjPL2DZ.js} +4 -4
  97. package/dist/xy.cjs +1 -1
  98. package/dist/xy.js +1 -1
  99. package/dist/zodutil-BfrF8jE3.js +23 -0
  100. package/dist/zodutil-DFJyyQd2.cjs +1 -0
  101. package/dist/zodutil.cjs +1 -1
  102. package/dist/zodutil.js +1 -1
  103. package/eslint.config.js +1 -1
  104. package/package.json +7 -9
  105. package/src/binary/encoder.spec.ts +1 -1
  106. package/src/binary/encoder.ts +1 -1
  107. package/src/binary/index.ts +1 -1
  108. package/src/breaker/breaker.spec.ts +9 -0
  109. package/src/breaker/breaker.ts +9 -0
  110. package/src/breaker/index.ts +9 -0
  111. package/src/caseconv/caseconv.spec.ts +5 -21
  112. package/src/caseconv/caseconv.ts +16 -8
  113. package/src/caseconv/index.ts +1 -1
  114. package/src/change/change.ts +1 -1
  115. package/src/change/index.ts +1 -1
  116. package/src/clamp/clamp.ts +1 -1
  117. package/src/clamp/index.ts +1 -1
  118. package/src/compare/compare.spec.ts +1 -1
  119. package/src/compare/compare.ts +3 -3
  120. package/src/compare/index.ts +1 -1
  121. package/src/control/control.ts +1 -1
  122. package/src/control/index.ts +1 -1
  123. package/src/debounce/debounce.spec.ts +1 -1
  124. package/src/debounce/debounce.ts +1 -1
  125. package/src/debounce/index.ts +1 -1
  126. package/src/deep/copy.ts +1 -1
  127. package/src/deep/delete.spec.ts +1 -1
  128. package/src/deep/delete.ts +1 -1
  129. package/src/deep/difference.spec.ts +1 -1
  130. package/src/deep/difference.ts +1 -1
  131. package/src/deep/equal.spec.ts +1 -1
  132. package/src/deep/equal.ts +1 -1
  133. package/src/deep/external.ts +1 -1
  134. package/src/deep/index.ts +1 -1
  135. package/src/deep/merge.spec.ts +1 -1
  136. package/src/deep/merge.ts +1 -1
  137. package/src/deep/partial.ts +1 -1
  138. package/src/deep/path.spec.ts +2 -3
  139. package/src/deep/path.ts +4 -4
  140. package/src/destructor.ts +1 -1
  141. package/src/errors/errors.ts +1 -1
  142. package/src/errors/index.ts +1 -1
  143. package/src/id/id.ts +6 -6
  144. package/src/id/index.ts +1 -1
  145. package/src/identity.ts +1 -1
  146. package/src/index.ts +2 -1
  147. package/src/invert.ts +1 -1
  148. package/src/join.ts +1 -1
  149. package/src/{unique.ts → kv/external.ts} +3 -2
  150. package/src/kv/index.ts +2 -2
  151. package/src/kv/mock.spec.ts +101 -0
  152. package/src/kv/mock.ts +58 -0
  153. package/src/kv/types.ts +23 -29
  154. package/src/link/index.ts +10 -0
  155. package/src/link/link.spec.ts +68 -0
  156. package/src/link/link.ts +21 -0
  157. package/src/math/index.ts +1 -1
  158. package/src/math/math.spec.ts +1 -1
  159. package/src/math/math.ts +1 -1
  160. package/src/migrate/index.ts +1 -1
  161. package/src/migrate/migrate.spec.ts +1 -1
  162. package/src/migrate/migrate.ts +1 -1
  163. package/src/mock/MockGLBufferController.ts +1 -1
  164. package/src/mock/index.ts +1 -1
  165. package/src/numeric/index.ts +1 -1
  166. package/src/numeric/numeric.ts +1 -1
  167. package/src/observe/index.ts +1 -1
  168. package/src/observe/observe.ts +1 -1
  169. package/src/observe/obsever.spec.ts +1 -1
  170. package/src/optional.ts +1 -1
  171. package/src/primitive.ts +1 -1
  172. package/src/record.spec.ts +9 -0
  173. package/src/record.ts +1 -1
  174. package/src/renderable.ts +1 -1
  175. package/src/runtime/detect.ts +3 -3
  176. package/src/runtime/external.ts +1 -1
  177. package/src/runtime/index.ts +1 -1
  178. package/src/runtime/os.ts +21 -21
  179. package/src/search.ts +1 -1
  180. package/src/shallowCopy.ts +1 -1
  181. package/src/sleep/index.ts +9 -0
  182. package/src/sleep/sleep.ts +9 -0
  183. package/src/spatial/base.ts +1 -1
  184. package/src/spatial/bounds/bounds.spec.ts +4 -3
  185. package/src/spatial/bounds/bounds.ts +4 -4
  186. package/src/spatial/bounds/index.ts +1 -1
  187. package/src/spatial/box/box.spec.ts +1 -1
  188. package/src/spatial/box/box.ts +2 -2
  189. package/src/spatial/box/index.ts +1 -1
  190. package/src/spatial/dimensions/dimensions.spec.ts +1 -1
  191. package/src/spatial/dimensions/dimensions.ts +1 -1
  192. package/src/spatial/dimensions/index.ts +1 -1
  193. package/src/spatial/direction/direction.spec.ts +1 -1
  194. package/src/spatial/direction/direction.ts +1 -1
  195. package/src/spatial/direction/index.ts +1 -1
  196. package/src/spatial/external.ts +1 -1
  197. package/src/spatial/index.ts +1 -1
  198. package/src/spatial/location/index.ts +1 -1
  199. package/src/spatial/location/location.spec.ts +1 -1
  200. package/src/spatial/location/location.ts +2 -2
  201. package/src/spatial/position/index.ts +1 -1
  202. package/src/spatial/position/position.spec.ts +1 -1
  203. package/src/spatial/position/position.ts +1 -1
  204. package/src/spatial/scale/index.ts +1 -1
  205. package/src/spatial/scale/scale.spec.ts +1 -1
  206. package/src/spatial/scale/scale.ts +2 -2
  207. package/src/spatial/spatial.ts +1 -1
  208. package/src/spatial/xy/index.ts +1 -1
  209. package/src/spatial/xy/xy.spec.ts +1 -1
  210. package/src/spatial/xy/xy.ts +1 -1
  211. package/src/strings/index.ts +1 -1
  212. package/src/strings/strings.spec.ts +1 -1
  213. package/src/strings/strings.ts +1 -1
  214. package/src/telem/generate.ts +1 -1
  215. package/src/telem/gl.ts +1 -1
  216. package/src/telem/index.ts +2 -2
  217. package/src/telem/series.spec.ts +22 -1
  218. package/src/telem/series.ts +19 -12
  219. package/src/telem/telem.spec.ts +2 -2
  220. package/src/telem/telem.ts +35 -11
  221. package/src/testutil/index.ts +10 -0
  222. package/src/testutil/testutil.ts +14 -0
  223. package/src/toArray.ts +1 -1
  224. package/src/transform.ts +1 -1
  225. package/src/unique/index.ts +10 -0
  226. package/src/unique/unique.spec.ts +192 -0
  227. package/src/unique/unique.ts +67 -0
  228. package/src/url/index.ts +1 -1
  229. package/src/url/url.spec.ts +1 -1
  230. package/src/url/url.ts +2 -2
  231. package/src/worker/index.ts +1 -1
  232. package/src/worker/worker.spec.ts +1 -1
  233. package/src/worker/worker.ts +1 -1
  234. package/src/zodutil/index.ts +2 -2
  235. package/src/zodutil/zodutil.spec.ts +1 -1
  236. package/src/zodutil/zodutil.ts +3 -31
  237. package/tsconfig.tsbuildinfo +1 -1
  238. package/vite.config.ts +7 -9
  239. package/dist/box-BHIyGhI_.cjs +0 -1
  240. package/dist/box-CfhGfJJH.js +0 -201
  241. package/dist/external-CghVMqCA.cjs +0 -1
  242. package/dist/external-DKQKvgIi.js +0 -30
  243. package/dist/index-h-QAL9T1.cjs +0 -1
  244. package/dist/position-BXFz7I9G.js +0 -85
  245. package/dist/position-CFiSGTz9.cjs +0 -1
  246. package/dist/series-BbxR21uO.cjs +0 -11
  247. package/dist/src/unique.d.ts +0 -2
  248. package/dist/src/unique.d.ts.map +0 -1
  249. package/dist/types-BpAJW2TM.js +0 -11
  250. package/dist/types-zRwnQ1hc.cjs +0 -1
  251. package/dist/zodutil-BRjUdYAv.cjs +0 -1
  252. package/dist/zodutil-DI4gVZkT.js +0 -27
@@ -1,4 +1,4 @@
1
- // Copyright 2024 Synnax Labs, Inc.
1
+ // Copyright 2025 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.
@@ -1231,7 +1231,8 @@ export class DataType extends String implements Stringer {
1231
1231
  }
1232
1232
 
1233
1233
  get isInteger(): boolean {
1234
- return this.toString().startsWith("int");
1234
+ const str = this.toString();
1235
+ return str.startsWith("int") || str.startsWith("uint");
1235
1236
  }
1236
1237
 
1237
1238
  get isFloat(): boolean {
@@ -1244,18 +1245,41 @@ export class DataType extends String implements Stringer {
1244
1245
  return v;
1245
1246
  }
1246
1247
 
1248
+ get isUnsigned(): boolean {
1249
+ return (
1250
+ this.equals(DataType.UINT8) ||
1251
+ this.equals(DataType.UINT16) ||
1252
+ this.equals(DataType.UINT32) ||
1253
+ this.equals(DataType.UINT64)
1254
+ );
1255
+ }
1256
+
1257
+ get isSigned(): boolean {
1258
+ return (
1259
+ this.equals(DataType.INT8) ||
1260
+ this.equals(DataType.INT16) ||
1261
+ this.equals(DataType.INT32) ||
1262
+ this.equals(DataType.INT64)
1263
+ );
1264
+ }
1265
+
1247
1266
  /** @returns true if the data type can be cast to the other data type without loss of precision. */
1248
1267
  canSafelyCastTo(other: DataType): boolean {
1249
1268
  if (this.equals(other)) return true;
1250
- if (
1251
- (this.isVariable && !other.isVariable) ||
1252
- (!this.isVariable && other.isVariable)
1253
- )
1254
- return false;
1255
- if ((this.isFloat && other.isInteger) || (this.isInteger && other.isFloat))
1256
- return this.density.valueOf() < other.density.valueOf();
1257
- if ((this.isFloat && other.isFloat) || (this.isInteger && other.isInteger))
1258
- return this.density.valueOf() <= other.density.valueOf();
1269
+ if (!this.isNumeric || !other.isNumeric) return false;
1270
+ if (this.isVariable || other.isVariable) return false;
1271
+ if (this.isUnsigned && other.isSigned) return false;
1272
+
1273
+ if (this.isFloat)
1274
+ return other.isFloat && this.density.valueOf() <= other.density.valueOf();
1275
+ if (this.equals(DataType.INT32) && other.equals(DataType.FLOAT64)) return true;
1276
+ if (this.equals(DataType.INT8) && other.equals(DataType.FLOAT32)) return true;
1277
+ if (this.isInteger && other.isInteger)
1278
+ return (
1279
+ this.density.valueOf() <= other.density.valueOf() &&
1280
+ this.isUnsigned === other.isUnsigned
1281
+ );
1282
+
1259
1283
  return false;
1260
1284
  }
1261
1285
 
@@ -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 testutil from "@/testutil/testutil";
@@ -0,0 +1,14 @@
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 const toString = (value: unknown): string =>
11
+ JSON.stringify(value, (_, value) => {
12
+ if (typeof value === "bigint") return value.toString();
13
+ return value;
14
+ });
package/src/toArray.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2024 Synnax Labs, Inc.
1
+ // Copyright 2025 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.
package/src/transform.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2024 Synnax Labs, Inc.
1
+ // Copyright 2025 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 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 unique from "@/unique/unique";
@@ -0,0 +1,192 @@
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
+ import { describe, expect, it } from "vitest";
11
+
12
+ import { unique } from "@/unique";
13
+
14
+ describe("unique", () => {
15
+ it("removes duplicate primitive values", () => {
16
+ const result = unique.unique([1, 2, 2, 3, 4, 4, 5]);
17
+ expect(result).toEqual([1, 2, 3, 4, 5]);
18
+ });
19
+
20
+ it("works with strings", () => {
21
+ const result = unique.unique(["a", "b", "a", "c", "b"]);
22
+ expect(result).toEqual(["a", "b", "c"]);
23
+ });
24
+
25
+ it("works with mixed types", () => {
26
+ const result = unique.unique([1, "1", 2, "2", 1, "1"]);
27
+ expect(result).toEqual([1, "1", 2, "2"]);
28
+ });
29
+
30
+ it("handles an empty array", () => {
31
+ const result = unique.unique([]);
32
+ expect(result).toEqual([]);
33
+ });
34
+
35
+ it("works with readonly arrays", () => {
36
+ const values: readonly number[] = [1, 1, 2, 3];
37
+ const result = unique.unique(values);
38
+ expect(result).toEqual([1, 2, 3]);
39
+ });
40
+ });
41
+
42
+ describe("by", () => {
43
+ interface IDTestCase {
44
+ id: number;
45
+ }
46
+
47
+ it("removes duplicates based on a key function and keeps the first instance by default", () => {
48
+ const result = unique.by(
49
+ [
50
+ { id: 1, name: "A" },
51
+ { id: 2, name: "B" },
52
+ { id: 1, name: "C" },
53
+ ],
54
+ (value: IDTestCase) => value.id,
55
+ );
56
+ expect(result).toEqual([
57
+ { id: 1, name: "A" },
58
+ { id: 2, name: "B" },
59
+ ]);
60
+ });
61
+
62
+ it("removes duplicates based on a key function and keeps the first instance when keepFirst is true", () => {
63
+ const result = unique.by(
64
+ [
65
+ { id: 1, name: "A" },
66
+ { id: 2, name: "B" },
67
+ { id: 1, name: "C" },
68
+ ],
69
+ (value: IDTestCase) => value.id,
70
+ true,
71
+ );
72
+ expect(result).toEqual([
73
+ { id: 1, name: "A" },
74
+ { id: 2, name: "B" },
75
+ ]);
76
+ });
77
+
78
+ it("removes duplicates based on a key function and keeps the last instance when keepFirst is false", () => {
79
+ const result = unique.by(
80
+ [
81
+ { id: 1, name: "A" },
82
+ { id: 2, name: "B" },
83
+ { id: 1, name: "C" },
84
+ ],
85
+ (value: IDTestCase) => value.id,
86
+ false,
87
+ );
88
+ expect(result).toEqual([
89
+ { id: 2, name: "B" },
90
+ { id: 1, name: "C" },
91
+ ]);
92
+ });
93
+
94
+ interface ValueTestCase {
95
+ value: string;
96
+ }
97
+
98
+ it("works with a custom key function", () => {
99
+ const result = unique.by(
100
+ [{ value: "apple" }, { value: "banana" }, { value: "apple" }],
101
+ (v: ValueTestCase) => v.value,
102
+ );
103
+ expect(result).toEqual([{ value: "apple" }, { value: "banana" }]);
104
+ });
105
+
106
+ it("handles an empty array", () => {
107
+ const result = unique.by([], (v: unknown) => v);
108
+ expect(result).toEqual([]);
109
+ });
110
+
111
+ it("works with readonly arrays and keeps the first instance by default", () => {
112
+ const values: readonly { id: number; name: string }[] = [
113
+ { id: 1, name: "A" },
114
+ { id: 1, name: "B" },
115
+ ];
116
+ const result = unique.by(values, (v: IDTestCase) => v.id);
117
+ expect(result).toEqual([{ id: 1, name: "A" }]);
118
+ });
119
+
120
+ it("works with readonly arrays and keeps the last instance when keepFirst is false", () => {
121
+ const values: readonly { id: number; name: string }[] = [
122
+ { id: 1, name: "A" },
123
+ { id: 1, name: "B" },
124
+ ];
125
+ const result = unique.by(values, (v: IDTestCase) => v.id, false);
126
+ expect(result).toEqual([{ id: 1, name: "B" }]);
127
+ });
128
+
129
+ interface ComplexTestCase {
130
+ id: number;
131
+ nested: { value: string };
132
+ }
133
+
134
+ it("works with complex keys and keeps the first instance by default", () => {
135
+ const result = unique.by(
136
+ [
137
+ { id: 1, nested: { value: "A" } },
138
+ { id: 1, nested: { value: "B" } },
139
+ { id: 1, nested: { value: "A", otherKey: "4" } },
140
+ ],
141
+ (v: ComplexTestCase) => `${v.id}-${v.nested.value}`,
142
+ );
143
+ expect(result).toEqual([
144
+ { id: 1, nested: { value: "A" } },
145
+ { id: 1, nested: { value: "B" } },
146
+ ]);
147
+ });
148
+
149
+ it("works with complex keys and keeps the last instance when keepFirst is false", () => {
150
+ const result = unique.by(
151
+ [
152
+ { id: 1, nested: { value: "A" } },
153
+ { id: 1, nested: { value: "B" } },
154
+ { id: 1, nested: { value: "A", otherKey: "4" } },
155
+ ],
156
+ (v: ComplexTestCase) => `${v.id}-${v.nested.value}`,
157
+ false,
158
+ );
159
+ expect(result).toEqual([
160
+ { id: 1, nested: { value: "B" } },
161
+ { id: 1, nested: { value: "A", otherKey: "4" } },
162
+ ]);
163
+ });
164
+
165
+ it("handles cases where all keys are unique", () => {
166
+ const result = unique.by(
167
+ [
168
+ { id: 1, name: "A" },
169
+ { id: 2, name: "B" },
170
+ { id: 3, name: "C" },
171
+ ],
172
+ (v: IDTestCase) => v.id,
173
+ );
174
+ expect(result).toEqual([
175
+ { id: 1, name: "A" },
176
+ { id: 2, name: "B" },
177
+ { id: 3, name: "C" },
178
+ ]);
179
+ });
180
+
181
+ it("handles cases where all values are identical", () => {
182
+ const result = unique.by(
183
+ [
184
+ { id: 1, name: "A" },
185
+ { id: 1, name: "A" },
186
+ { id: 1, name: "A" },
187
+ ],
188
+ (v: IDTestCase) => v.id,
189
+ );
190
+ expect(result).toEqual([{ id: 1, name: "A" }]);
191
+ });
192
+ });
@@ -0,0 +1,67 @@
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
+ /**
11
+ * Removes duplicate values from an array, preserving the order of the first occurrence
12
+ * of each unique value.
13
+ *
14
+ * @param values - An array or readonly array of values to deduplicate.
15
+ * @returns A new array containing only unique values.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * unique([1, 2, 2, 3, 4, 4, 5]); // [1, 2, 3, 4, 5]
20
+ * ```
21
+ */
22
+ export const unique = <V>(values: V[] | readonly V[]): V[] => [...new Set(values)];
23
+
24
+ /**
25
+ * Removes duplicate values from an array based on a key function, preserving either
26
+ * the first or last occurrence of each unique key. If
27
+ *
28
+ * @param values - An array or readonly array of values to deduplicate.
29
+ * @param key - A function that generates a unique key for each value.
30
+ * @param keepFirst - An optional boolean indicating whether to keep the first instance
31
+ * (`true`, default) or the last instance (`false`) of each unique key.
32
+ * @returns A new array containing only unique values based on the generated keys.
33
+ *
34
+ * @example
35
+ * // Default behavior (keep first instance):
36
+ * by(
37
+ * [{ id: 1, name: "A" }, { id: 2, name: "B" }, { id: 1, name: "C" }],
38
+ * (value) => value.id
39
+ * );
40
+ * // Result: [{ id: 1, name: "A" }, { id: 2, name: "B" }]
41
+ *
42
+ * @example
43
+ * // Keep last instance:
44
+ * by(
45
+ * [{ id: 1, name: "A" }, { id: 2, name: "B" }, { id: 1, name: "C" }],
46
+ * (value) => value.id,
47
+ * false
48
+ * );
49
+ * // Result: [{ id: 2, name: "B" }, { id: 1, name: "C" }]
50
+ */
51
+ export const by = <V>(
52
+ values: V[] | readonly V[],
53
+ key: (value: V) => unknown,
54
+ keepFirst: boolean = true,
55
+ ): V[] => {
56
+ const map = new Map<unknown, V>();
57
+ values.forEach((v) => {
58
+ const k = key(v);
59
+ if (map.has(k)) {
60
+ if (keepFirst) return;
61
+ map.delete(k);
62
+ }
63
+ // different delete and set operations for keepLast so order is preserved
64
+ map.set(k, v);
65
+ });
66
+ return Array.from(map.values());
67
+ };
package/src/url/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2024 Synnax Labs, Inc.
1
+ // Copyright 2025 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 2024 Synnax Labs, Inc.
1
+ // Copyright 2025 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.
package/src/url/url.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2024 Synnax Labs, Inc.
1
+ // Copyright 2025 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.
@@ -36,7 +36,7 @@ const removeTrailingSlash = (path: string): string =>
36
36
  * @returns the query string.
37
37
  */
38
38
  export const buildQueryString = (
39
- request: Record<string, unknown>,
39
+ request: Record<string, string>,
40
40
  prefix: string = "",
41
41
  ): string => {
42
42
  if (request === null) return "";
@@ -1,4 +1,4 @@
1
- // Copyright 2024 Synnax Labs, Inc.
1
+ // Copyright 2025 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 2024 Synnax Labs, Inc.
1
+ // Copyright 2025 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 2024 Synnax Labs, Inc.
1
+ // Copyright 2025 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 2024 Synnax Labs, Inc.
1
+ // Copyright 2025 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,4 +7,4 @@
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 * as zodutil from "./zodutil";
10
+ export * as zodutil from "@/zodutil/zodutil";
@@ -1,4 +1,4 @@
1
- // Copyright 2024 Synnax Labs, Inc.
1
+ // Copyright 2025 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 2024 Synnax Labs, Inc.
1
+ // Copyright 2025 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,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, type ZodSchema } from "zod";
10
+ import { z } from "zod";
11
11
 
12
12
  import { deep } from "@/deep";
13
13
  import { type UnknownRecord } from "@/record";
@@ -41,34 +41,6 @@ export const getFieldSchema: deep.TypedGet<z.ZodTypeAny, z.ZodTypeAny> = ((
41
41
  sourceTypeGetter(schema, "shape") as unknown as z.AnyZodObject,
42
42
  getFieldSchemaPath(path),
43
43
  { ...options, getter: sourceTypeGetter } as deep.GetOptions<boolean | undefined>,
44
- ) as z.ZodTypeAny | null) as deep.TypedGet<z.ZodTypeAny, z.ZodTypeAny>;
45
-
46
- /**
47
- * Creates a transformer function that validates and transforms input values based on
48
- * provided schemas. The first schema to successfully validate the input value is used
49
- * in the transformation. If no schema is found that validates the input, the
50
- * transformer function returns null.
51
- *
52
- * @template Input - The type of the input value.
53
- * @template Output - The type of the output value.
54
- * @param transform - The function to transform the input value to the output value.
55
- * @param schemas - An array of Zod schemas to validate the input value against.
56
- * @returns A function that takes an unknown value, validates it against the schemas,
57
- * and uses the first valid schema to transform the input type. If no schema can
58
- * validate the input, the function returns null.
59
- */
60
- export const transformer =
61
- <Input, Output>(
62
- transform: (input: Input) => Output,
63
- schemas: ZodSchema<Input>[],
64
- ): ((value: unknown) => Output | null) =>
65
- (value) => {
66
- const matchingSchema = schemas.find((schema) => {
67
- const res = schema.safeParse(value);
68
- return res.success;
69
- });
70
- if (matchingSchema == null) return null;
71
- return transform(matchingSchema.parse(value));
72
- };
44
+ )) as deep.TypedGet<z.ZodTypeAny, z.ZodTypeAny>;
73
45
 
74
46
  export const bigInt = z.bigint().or(z.string().transform(BigInt));