@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.
- package/.turbo/turbo-build.log +38 -34
- package/dist/binary.js +1 -1
- package/dist/box-DPJAbf32.js +201 -0
- package/dist/box-Daep7oxr.cjs +1 -0
- package/dist/box.cjs +1 -1
- package/dist/box.js +1 -1
- package/dist/caseconv.js +1 -1
- package/dist/compare.cjs +1 -1
- package/dist/compare.js +1 -1
- package/dist/external-C-dNgNQw.cjs +1 -0
- package/dist/external-CtAt3tnU.js +29 -0
- package/dist/external-DSKjMZ7J.cjs +1 -0
- package/dist/external-DqPrWKvU.js +47 -0
- package/dist/index-BG3Scw3G.cjs +1 -0
- package/dist/{index-HQonyH7n.js → index-BVC_8Cg9.js} +1 -1
- package/dist/{index-OHIRoCei.js → index-C3QzbIwt.js} +1 -1
- package/dist/index-D4NCYiQB.js +19 -0
- package/dist/{index-BfDeGfej.js → index-DizUWH6z.js} +8 -2
- package/dist/index-udOjA9d-.cjs +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.js +57 -55
- package/dist/kv.cjs +1 -1
- package/dist/kv.js +2 -2
- package/dist/link.cjs +1 -0
- package/dist/link.js +10 -0
- package/dist/{location-C5Ot4MVG.js → location-BVkZhfQG.js} +1 -1
- package/dist/location.js +1 -1
- package/dist/position-96CBRKEd.cjs +1 -0
- package/dist/position-uVDP52PM.js +85 -0
- package/dist/position.cjs +1 -1
- package/dist/position.js +1 -1
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +1 -1
- package/dist/{scale-BESJN9LG.cjs → scale-Bzjm1mhv.cjs} +1 -1
- package/dist/{scale-CV3O6tkY.js → scale-D_UMXSZN.js} +3 -3
- package/dist/scale.cjs +1 -1
- package/dist/scale.js +1 -1
- package/dist/{series-C_B2hAp9.js → series-Cwc_z2OS.js} +296 -286
- package/dist/series-DuOxifEy.cjs +11 -0
- package/dist/spatial.cjs +1 -1
- package/dist/spatial.js +5 -5
- package/dist/src/breaker/breaker.d.ts.map +1 -1
- package/dist/src/breaker/index.d.ts.map +1 -1
- package/dist/src/caseconv/caseconv.d.ts.map +1 -1
- package/dist/src/deep/path.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/kv/external.d.ts +3 -0
- package/dist/src/kv/external.d.ts.map +1 -0
- package/dist/src/kv/index.d.ts +1 -1
- package/dist/src/kv/index.d.ts.map +1 -1
- package/dist/src/kv/mock.d.ts +24 -0
- package/dist/src/kv/mock.d.ts.map +1 -0
- package/dist/src/kv/mock.spec.d.ts +2 -0
- package/dist/src/kv/mock.spec.d.ts.map +1 -0
- package/dist/src/kv/types.d.ts +18 -18
- package/dist/src/kv/types.d.ts.map +1 -1
- package/dist/src/link/index.d.ts +2 -0
- package/dist/src/link/index.d.ts.map +1 -0
- package/dist/src/link/link.d.ts +2 -0
- package/dist/src/link/link.d.ts.map +1 -0
- package/dist/src/link/link.spec.d.ts +2 -0
- package/dist/src/link/link.spec.d.ts.map +1 -0
- package/dist/src/runtime/os.d.ts +7 -7
- package/dist/src/runtime/os.d.ts.map +1 -1
- package/dist/src/sleep/index.d.ts.map +1 -1
- package/dist/src/sleep/sleep.d.ts.map +1 -1
- package/dist/src/telem/index.d.ts +1 -1
- package/dist/src/telem/index.d.ts.map +1 -1
- package/dist/src/telem/series.d.ts +1 -0
- package/dist/src/telem/series.d.ts.map +1 -1
- package/dist/src/telem/telem.d.ts +2 -0
- package/dist/src/telem/telem.d.ts.map +1 -1
- package/dist/src/testutil/index.d.ts +2 -0
- package/dist/src/testutil/index.d.ts.map +1 -0
- package/dist/src/testutil/testutil.d.ts +2 -0
- package/dist/src/testutil/testutil.d.ts.map +1 -0
- package/dist/src/unique/index.d.ts +2 -0
- package/dist/src/unique/index.d.ts.map +1 -0
- package/dist/src/unique/unique.d.ts +42 -0
- package/dist/src/unique/unique.d.ts.map +1 -0
- package/dist/src/unique/unique.spec.d.ts +2 -0
- package/dist/src/unique/unique.spec.d.ts.map +1 -0
- package/dist/src/url/url.d.ts +1 -1
- package/dist/src/url/url.d.ts.map +1 -1
- package/dist/src/zodutil/index.d.ts.map +1 -1
- package/dist/src/zodutil/zodutil.d.ts +1 -16
- package/dist/src/zodutil/zodutil.d.ts.map +1 -1
- package/dist/telem.cjs +1 -1
- package/dist/telem.js +1 -1
- package/dist/unique.cjs +1 -1
- package/dist/unique.js +2 -2
- package/dist/url.cjs +1 -1
- package/dist/url.js +5 -5
- package/dist/{xy-LADI2wVU.cjs → xy-Budz-qz-.cjs} +1 -1
- package/dist/{xy-DQdccWlc.js → xy-DxjPL2DZ.js} +4 -4
- package/dist/xy.cjs +1 -1
- package/dist/xy.js +1 -1
- package/dist/zodutil-BfrF8jE3.js +23 -0
- package/dist/zodutil-DFJyyQd2.cjs +1 -0
- package/dist/zodutil.cjs +1 -1
- package/dist/zodutil.js +1 -1
- package/eslint.config.js +1 -1
- package/package.json +7 -9
- package/src/binary/encoder.spec.ts +1 -1
- package/src/binary/encoder.ts +1 -1
- package/src/binary/index.ts +1 -1
- package/src/breaker/breaker.spec.ts +9 -0
- package/src/breaker/breaker.ts +9 -0
- package/src/breaker/index.ts +9 -0
- package/src/caseconv/caseconv.spec.ts +5 -21
- package/src/caseconv/caseconv.ts +16 -8
- package/src/caseconv/index.ts +1 -1
- package/src/change/change.ts +1 -1
- package/src/change/index.ts +1 -1
- package/src/clamp/clamp.ts +1 -1
- package/src/clamp/index.ts +1 -1
- package/src/compare/compare.spec.ts +1 -1
- package/src/compare/compare.ts +3 -3
- package/src/compare/index.ts +1 -1
- package/src/control/control.ts +1 -1
- package/src/control/index.ts +1 -1
- package/src/debounce/debounce.spec.ts +1 -1
- package/src/debounce/debounce.ts +1 -1
- package/src/debounce/index.ts +1 -1
- package/src/deep/copy.ts +1 -1
- package/src/deep/delete.spec.ts +1 -1
- package/src/deep/delete.ts +1 -1
- package/src/deep/difference.spec.ts +1 -1
- package/src/deep/difference.ts +1 -1
- package/src/deep/equal.spec.ts +1 -1
- package/src/deep/equal.ts +1 -1
- package/src/deep/external.ts +1 -1
- package/src/deep/index.ts +1 -1
- package/src/deep/merge.spec.ts +1 -1
- package/src/deep/merge.ts +1 -1
- package/src/deep/partial.ts +1 -1
- package/src/deep/path.spec.ts +2 -3
- package/src/deep/path.ts +4 -4
- package/src/destructor.ts +1 -1
- package/src/errors/errors.ts +1 -1
- package/src/errors/index.ts +1 -1
- package/src/id/id.ts +6 -6
- package/src/id/index.ts +1 -1
- package/src/identity.ts +1 -1
- package/src/index.ts +2 -1
- package/src/invert.ts +1 -1
- package/src/join.ts +1 -1
- package/src/{unique.ts → kv/external.ts} +3 -2
- package/src/kv/index.ts +2 -2
- package/src/kv/mock.spec.ts +101 -0
- package/src/kv/mock.ts +58 -0
- package/src/kv/types.ts +23 -29
- package/src/link/index.ts +10 -0
- package/src/link/link.spec.ts +68 -0
- package/src/link/link.ts +21 -0
- package/src/math/index.ts +1 -1
- package/src/math/math.spec.ts +1 -1
- package/src/math/math.ts +1 -1
- package/src/migrate/index.ts +1 -1
- package/src/migrate/migrate.spec.ts +1 -1
- package/src/migrate/migrate.ts +1 -1
- package/src/mock/MockGLBufferController.ts +1 -1
- package/src/mock/index.ts +1 -1
- package/src/numeric/index.ts +1 -1
- package/src/numeric/numeric.ts +1 -1
- package/src/observe/index.ts +1 -1
- package/src/observe/observe.ts +1 -1
- package/src/observe/obsever.spec.ts +1 -1
- package/src/optional.ts +1 -1
- package/src/primitive.ts +1 -1
- package/src/record.spec.ts +9 -0
- package/src/record.ts +1 -1
- package/src/renderable.ts +1 -1
- package/src/runtime/detect.ts +3 -3
- package/src/runtime/external.ts +1 -1
- package/src/runtime/index.ts +1 -1
- package/src/runtime/os.ts +21 -21
- package/src/search.ts +1 -1
- package/src/shallowCopy.ts +1 -1
- package/src/sleep/index.ts +9 -0
- package/src/sleep/sleep.ts +9 -0
- package/src/spatial/base.ts +1 -1
- package/src/spatial/bounds/bounds.spec.ts +4 -3
- package/src/spatial/bounds/bounds.ts +4 -4
- package/src/spatial/bounds/index.ts +1 -1
- package/src/spatial/box/box.spec.ts +1 -1
- package/src/spatial/box/box.ts +2 -2
- package/src/spatial/box/index.ts +1 -1
- package/src/spatial/dimensions/dimensions.spec.ts +1 -1
- package/src/spatial/dimensions/dimensions.ts +1 -1
- package/src/spatial/dimensions/index.ts +1 -1
- package/src/spatial/direction/direction.spec.ts +1 -1
- package/src/spatial/direction/direction.ts +1 -1
- package/src/spatial/direction/index.ts +1 -1
- package/src/spatial/external.ts +1 -1
- package/src/spatial/index.ts +1 -1
- package/src/spatial/location/index.ts +1 -1
- package/src/spatial/location/location.spec.ts +1 -1
- package/src/spatial/location/location.ts +2 -2
- package/src/spatial/position/index.ts +1 -1
- package/src/spatial/position/position.spec.ts +1 -1
- package/src/spatial/position/position.ts +1 -1
- package/src/spatial/scale/index.ts +1 -1
- package/src/spatial/scale/scale.spec.ts +1 -1
- package/src/spatial/scale/scale.ts +2 -2
- package/src/spatial/spatial.ts +1 -1
- package/src/spatial/xy/index.ts +1 -1
- package/src/spatial/xy/xy.spec.ts +1 -1
- package/src/spatial/xy/xy.ts +1 -1
- package/src/strings/index.ts +1 -1
- package/src/strings/strings.spec.ts +1 -1
- package/src/strings/strings.ts +1 -1
- package/src/telem/generate.ts +1 -1
- package/src/telem/gl.ts +1 -1
- package/src/telem/index.ts +2 -2
- package/src/telem/series.spec.ts +22 -1
- package/src/telem/series.ts +19 -12
- package/src/telem/telem.spec.ts +2 -2
- package/src/telem/telem.ts +35 -11
- package/src/testutil/index.ts +10 -0
- package/src/testutil/testutil.ts +14 -0
- package/src/toArray.ts +1 -1
- package/src/transform.ts +1 -1
- package/src/unique/index.ts +10 -0
- package/src/unique/unique.spec.ts +192 -0
- package/src/unique/unique.ts +67 -0
- package/src/url/index.ts +1 -1
- package/src/url/url.spec.ts +1 -1
- package/src/url/url.ts +2 -2
- package/src/worker/index.ts +1 -1
- package/src/worker/worker.spec.ts +1 -1
- package/src/worker/worker.ts +1 -1
- package/src/zodutil/index.ts +2 -2
- package/src/zodutil/zodutil.spec.ts +1 -1
- package/src/zodutil/zodutil.ts +3 -31
- package/tsconfig.tsbuildinfo +1 -1
- package/vite.config.ts +7 -9
- package/dist/box-BHIyGhI_.cjs +0 -1
- package/dist/box-CfhGfJJH.js +0 -201
- package/dist/external-CghVMqCA.cjs +0 -1
- package/dist/external-DKQKvgIi.js +0 -30
- package/dist/index-h-QAL9T1.cjs +0 -1
- package/dist/position-BXFz7I9G.js +0 -85
- package/dist/position-CFiSGTz9.cjs +0 -1
- package/dist/series-BbxR21uO.cjs +0 -11
- package/dist/src/unique.d.ts +0 -2
- package/dist/src/unique.d.ts.map +0 -1
- package/dist/types-BpAJW2TM.js +0 -11
- package/dist/types-zRwnQ1hc.cjs +0 -1
- package/dist/zodutil-BRjUdYAv.cjs +0 -1
- package/dist/zodutil-DI4gVZkT.js +0 -27
package/src/telem/telem.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
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
|
-
|
|
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
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
if (
|
|
1258
|
-
|
|
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
package/src/transform.ts
CHANGED
|
@@ -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
package/src/url/url.spec.ts
CHANGED
package/src/url/url.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
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,
|
|
39
|
+
request: Record<string, string>,
|
|
40
40
|
prefix: string = "",
|
|
41
41
|
): string => {
|
|
42
42
|
if (request === null) return "";
|
package/src/worker/index.ts
CHANGED
package/src/worker/worker.ts
CHANGED
package/src/zodutil/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
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 "
|
|
10
|
+
export * as zodutil from "@/zodutil/zodutil";
|
package/src/zodutil/zodutil.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
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
|
|
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
|
-
)
|
|
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));
|