@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.
- package/.turbo/turbo-build.log +93 -105
- package/.vscode/settings.json +4 -6
- package/README.md +1 -7
- package/dist/array.cjs +1 -0
- package/dist/array.js +7 -0
- package/dist/base-B5lQIJKc.js +38 -0
- package/dist/base-CTq-lhpU.cjs +1 -0
- package/dist/binary.cjs +1 -1
- package/dist/binary.js +1 -1
- package/dist/bounds.cjs +1 -1
- package/dist/bounds.js +2 -2
- package/dist/box.cjs +1 -1
- package/dist/box.js +1 -1
- package/dist/caseconv.cjs +1 -1
- package/dist/caseconv.js +2 -2
- package/dist/change.cjs +1 -1
- package/dist/change.js +10 -2
- package/dist/compare.cjs +1 -1
- package/dist/compare.js +1 -1
- package/dist/deep.cjs +1 -1
- package/dist/deep.js +92 -79
- package/dist/dimensions.cjs +1 -1
- package/dist/dimensions.js +41 -2
- package/dist/direction.cjs +1 -1
- package/dist/direction.js +1 -1
- package/dist/index-4GlOgZuh.js +99 -0
- package/dist/{direction-C-b6XTeU.cjs → index-B58dnYRu.cjs} +1 -1
- package/dist/index-BMGaoK93.cjs +1 -0
- package/dist/index-BTet04Hd.cjs +6 -0
- package/dist/{scale-DfJe9755.js → index-BUa-NXAX.js} +46 -46
- package/dist/{xy-D_LqxaGt.js → index-C-qYOegc.js} +62 -62
- package/dist/index-C07SBJhr.js +128 -0
- package/dist/{bounds-Bn5_l4Z3.js → index-C9EdKeu1.js} +77 -76
- package/dist/index-CM8ZDZ6s.cjs +1 -0
- package/dist/index-CV2JaHfw.cjs +1 -0
- package/dist/index-CeBvOwG8.cjs +3 -0
- package/dist/index-ClrGyGDp.js +205 -0
- package/dist/index-CqQXXeCI.cjs +1 -0
- package/dist/{location-C3aeu046.js → index-D6V-8SKw.js} +26 -26
- package/dist/index-DBGAIs_7.js +2492 -0
- package/dist/index-DEdq2tza.cjs +1 -0
- package/dist/index-DKMnHBGR.cjs +1 -0
- package/dist/index-Dql5FMcH.js +47 -0
- package/dist/{direction-BL0PhD1k.js → index-DxU1zwsd.js} +1 -1
- package/dist/index-WwMnwoLy.cjs +1 -0
- package/dist/index.cjs +5 -3
- package/dist/index.js +5372 -649
- package/dist/kv.cjs +1 -1
- package/dist/kv.js +45 -2
- package/dist/location.cjs +1 -1
- package/dist/location.js +1 -1
- package/dist/position.cjs +1 -1
- package/dist/position.js +83 -2
- package/dist/record.cjs +1 -1
- package/dist/record.js +8 -10
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +27 -2
- package/dist/scale.cjs +1 -1
- package/dist/scale.js +1 -1
- package/dist/schemas-55Usj0Fg.js +3998 -0
- package/dist/schemas-DbXuI2Qr.cjs +27 -0
- package/dist/spatial.cjs +1 -1
- package/dist/spatial.js +25 -18
- package/dist/src/array/index.d.ts +2 -0
- package/dist/src/array/index.d.ts.map +1 -0
- package/dist/src/array/toArray.d.ts +19 -0
- package/dist/src/array/toArray.d.ts.map +1 -0
- package/dist/src/array/toArray.spec.d.ts +2 -0
- package/dist/src/array/toArray.spec.d.ts.map +1 -0
- package/dist/src/binary/codec.d.ts +8 -16
- package/dist/src/binary/codec.d.ts.map +1 -1
- package/dist/src/breaker/breaker.d.ts +6 -6
- package/dist/src/breaker/breaker.d.ts.map +1 -1
- package/dist/src/caseconv/caseconv.d.ts +1 -1
- package/dist/src/caseconv/caseconv.d.ts.map +1 -1
- package/dist/src/change/change.d.ts +3 -3
- package/dist/src/change/change.d.ts.map +1 -1
- package/dist/src/color/color.d.ts +63 -28
- package/dist/src/color/color.d.ts.map +1 -1
- package/dist/src/color/external.d.ts +0 -1
- package/dist/src/color/external.d.ts.map +1 -1
- package/dist/src/color/gradient.d.ts +9 -5
- package/dist/src/color/gradient.d.ts.map +1 -1
- package/dist/src/color/palette.d.ts +14 -6
- package/dist/src/color/palette.d.ts.map +1 -1
- package/dist/src/compare/compare.d.ts +4 -4
- package/dist/src/compare/compare.d.ts.map +1 -1
- package/dist/src/control/control.d.ts +32 -32
- package/dist/src/control/control.d.ts.map +1 -1
- package/dist/src/debounce/debounce.d.ts +1 -1
- package/dist/src/debounce/debounce.d.ts.map +1 -1
- package/dist/src/deep/delete.d.ts +1 -1
- package/dist/src/deep/delete.d.ts.map +1 -1
- package/dist/src/deep/difference.d.ts.map +1 -1
- package/dist/src/deep/equal.d.ts +4 -4
- package/dist/src/deep/equal.d.ts.map +1 -1
- package/dist/src/deep/merge.d.ts +1 -1
- package/dist/src/deep/merge.d.ts.map +1 -1
- package/dist/src/errors/errors.d.ts +62 -36
- package/dist/src/errors/errors.d.ts.map +1 -1
- package/dist/src/index.d.ts +4 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/instance/index.d.ts +2 -0
- package/dist/src/instance/index.d.ts.map +1 -0
- package/dist/src/instance/matcher.d.ts +79 -0
- package/dist/src/instance/matcher.d.ts.map +1 -0
- package/dist/src/instance/matcher.spec.d.ts +2 -0
- package/dist/src/instance/matcher.spec.d.ts.map +1 -0
- package/dist/src/jsonrpc/jsonrpc.d.ts +40 -9
- package/dist/src/jsonrpc/jsonrpc.d.ts.map +1 -1
- package/dist/src/kv/types.d.ts +2 -2
- package/dist/src/kv/types.d.ts.map +1 -1
- package/dist/src/migrate/migrate.d.ts +5 -5
- package/dist/src/migrate/migrate.d.ts.map +1 -1
- package/dist/src/notation/notation.d.ts +1 -1
- package/dist/src/notation/notation.d.ts.map +1 -1
- package/dist/src/primitive/index.d.ts +2 -0
- package/dist/src/primitive/index.d.ts.map +1 -0
- package/dist/src/primitive/primitive.d.ts +39 -0
- package/dist/src/primitive/primitive.d.ts.map +1 -0
- package/dist/src/primitive/primitive.spec.d.ts +2 -0
- package/dist/src/primitive/primitive.spec.d.ts.map +1 -0
- package/dist/src/record.d.ts +2 -2
- package/dist/src/record.d.ts.map +1 -1
- package/dist/src/renderable.d.ts +1 -1
- package/dist/src/renderable.d.ts.map +1 -1
- package/dist/src/replace.d.ts.map +1 -1
- package/dist/src/runtime/detect.d.ts.map +1 -1
- package/dist/src/runtime/os.d.ts +1 -1
- package/dist/src/runtime/os.d.ts.map +1 -1
- package/dist/src/spatial/base.d.ts +10 -10
- package/dist/src/spatial/base.d.ts.map +1 -1
- package/dist/src/spatial/bounds/bounds.d.ts +82 -16
- package/dist/src/spatial/bounds/bounds.d.ts.map +1 -1
- package/dist/src/spatial/box/box.d.ts +7 -7
- package/dist/src/spatial/box/box.d.ts.map +1 -1
- package/dist/src/spatial/dimensions/dimensions.d.ts +5 -5
- package/dist/src/spatial/dimensions/dimensions.d.ts.map +1 -1
- package/dist/src/spatial/direction/direction.d.ts +1 -1
- package/dist/src/spatial/location/location.d.ts +4 -4
- package/dist/src/spatial/location/location.d.ts.map +1 -1
- package/dist/src/spatial/scale/scale.d.ts +11 -11
- package/dist/src/spatial/scale/scale.d.ts.map +1 -1
- package/dist/src/spatial/xy/xy.d.ts +5 -5
- package/dist/src/spatial/xy/xy.d.ts.map +1 -1
- package/dist/src/status/index.d.ts +2 -0
- package/dist/src/status/index.d.ts.map +1 -0
- package/dist/src/status/types.d.ts +11 -0
- package/dist/src/status/types.d.ts.map +1 -0
- package/dist/src/sync/index.d.ts.map +1 -1
- package/dist/src/sync/mutex.d.ts +0 -1
- package/dist/src/sync/mutex.d.ts.map +1 -1
- package/dist/src/telem/gl.d.ts +1 -1
- package/dist/src/telem/gl.d.ts.map +1 -1
- package/dist/src/telem/series.d.ts +468 -62
- package/dist/src/telem/series.d.ts.map +1 -1
- package/dist/src/telem/telem.d.ts +243 -53
- package/dist/src/telem/telem.d.ts.map +1 -1
- package/dist/src/uuid/index.d.ts +2 -0
- package/dist/src/uuid/index.d.ts.map +1 -0
- package/dist/src/uuid/uuid.d.ts +35 -0
- package/dist/src/uuid/uuid.d.ts.map +1 -0
- package/dist/src/uuid/uuid.spec.d.ts +2 -0
- package/dist/src/uuid/uuid.spec.d.ts.map +1 -0
- package/dist/src/zod/external.d.ts +1 -1
- package/dist/src/zod/external.d.ts.map +1 -1
- package/dist/src/zod/nullToUndefined.d.ts +3 -0
- package/dist/src/zod/nullToUndefined.d.ts.map +1 -0
- package/dist/src/zod/nullToUndefined.spec.d.ts +2 -0
- package/dist/src/zod/nullToUndefined.spec.d.ts.map +1 -0
- package/dist/src/zod/util.d.ts +2 -2
- package/dist/src/zod/util.d.ts.map +1 -1
- package/dist/telem.cjs +1 -1
- package/dist/telem.js +1 -1
- package/dist/xy.cjs +1 -1
- package/dist/xy.js +1 -1
- package/dist/zod.cjs +1 -1
- package/dist/zod.js +19 -2
- package/eslint.config.js +1 -1
- package/package.json +16 -14
- package/src/{toArray.ts → array/index.ts} +1 -5
- package/src/array/toArray.spec.ts +56 -0
- package/src/array/toArray.ts +28 -0
- package/src/binary/codec.spec.ts +201 -278
- package/src/binary/codec.ts +20 -76
- package/src/breaker/breaker.ts +3 -3
- package/src/caseconv/caseconv.ts +6 -4
- package/src/change/change.ts +2 -2
- package/src/color/color.spec.ts +121 -2
- package/src/color/color.ts +90 -54
- package/src/color/external.ts +0 -1
- package/src/color/gradient.ts +20 -28
- package/src/color/palette.ts +1 -1
- package/src/compare/compare.ts +5 -5
- package/src/control/control.ts +22 -19
- package/src/debounce/debounce.ts +1 -1
- package/src/deep/delete.ts +5 -4
- package/src/deep/difference.ts +6 -2
- package/src/deep/equal.spec.ts +1 -1
- package/src/deep/equal.ts +5 -5
- package/src/deep/merge.spec.ts +13 -1
- package/src/deep/merge.ts +16 -7
- package/src/deep/path.ts +1 -1
- package/src/errors/errors.ts +65 -44
- package/src/index.ts +4 -1
- package/src/instance/index.ts +10 -0
- package/src/instance/matcher.spec.ts +78 -0
- package/src/instance/matcher.ts +98 -0
- package/src/jsonrpc/jsonrpc.spec.ts +2 -1
- package/src/jsonrpc/jsonrpc.ts +36 -7
- package/src/kv/types.ts +1 -1
- package/src/migrate/migrate.spec.ts +1 -1
- package/src/migrate/migrate.ts +7 -7
- package/src/notation/notation.ts +1 -1
- package/src/primitive/index.ts +10 -0
- package/src/primitive/primitive.spec.ts +126 -0
- package/src/primitive/primitive.ts +82 -0
- package/src/record.ts +3 -5
- package/src/renderable.ts +1 -1
- package/src/replace.ts +9 -0
- package/src/runtime/detect.ts +0 -2
- package/src/runtime/os.ts +1 -1
- package/src/spatial/base.ts +1 -1
- package/src/spatial/bounds/bounds.spec.ts +20 -0
- package/src/spatial/bounds/bounds.ts +101 -18
- package/src/spatial/box/box.ts +1 -1
- package/src/spatial/dimensions/dimensions.ts +3 -3
- package/src/spatial/location/location.ts +1 -1
- package/src/spatial/scale/scale.ts +1 -1
- package/src/spatial/xy/xy.ts +1 -1
- package/src/status/index.ts +10 -0
- package/src/status/types.ts +22 -0
- package/src/sync/index.ts +9 -0
- package/src/sync/mutex.ts +9 -4
- package/src/telem/gl.ts +1 -1
- package/src/telem/series.spec.ts +735 -68
- package/src/telem/series.ts +536 -195
- package/src/telem/telem.spec.ts +60 -7
- package/src/telem/telem.ts +287 -95
- package/src/uuid/index.ts +10 -0
- package/src/uuid/uuid.spec.ts +82 -0
- package/src/uuid/uuid.ts +48 -0
- package/src/zod/external.ts +1 -1
- package/src/zod/nullToUndefined.spec.ts +31 -0
- package/src/zod/nullToUndefined.ts +23 -0
- package/src/zod/util.spec.ts +1 -1
- package/src/zod/util.ts +6 -6
- package/tsconfig.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/vite.config.ts +1 -1
- package/dist/base-BAM2mqCy.cjs +0 -1
- package/dist/base-DFq0vvGn.js +0 -38
- package/dist/bounds-BQo7rvs9.cjs +0 -1
- package/dist/box-0YrQibkB.cjs +0 -1
- package/dist/box-Cc8IzcNo.js +0 -205
- package/dist/change-C-YELKx6.cjs +0 -1
- package/dist/change-DLl6DccR.js +0 -12
- package/dist/dimensions-CRgergMS.js +0 -43
- package/dist/dimensions-D2QGoNXO.cjs +0 -1
- package/dist/external-BPgtxa8d.js +0 -29
- package/dist/external-C-dNgNQw.cjs +0 -1
- package/dist/external-C8TFju8Q.js +0 -29
- package/dist/external-DWQITF5_.cjs +0 -1
- package/dist/external-DqPrWKvU.js +0 -47
- package/dist/external-uXk0Avrg.cjs +0 -1
- package/dist/index-BywOGO8U.js +0 -1074
- package/dist/index-CYYjI7Uf.cjs +0 -1
- package/dist/index-C_6NXBlg.cjs +0 -3
- package/dist/index-Dd8DLyMx.cjs +0 -1
- package/dist/index-DizUWH6z.js +0 -47
- package/dist/index-QGplUHuy.js +0 -98
- package/dist/location-BGl5Ddds.cjs +0 -1
- package/dist/position-Cai5-wi1.cjs +0 -1
- package/dist/position-DIglP1l2.js +0 -85
- package/dist/scale-BtZINJ-A.cjs +0 -1
- package/dist/series-B9JERcqi.js +0 -1977
- package/dist/series-DqJ6f97G.cjs +0 -11
- package/dist/spatial-BSWPzMkK.js +0 -11
- package/dist/spatial-DGpZ2sO3.cjs +0 -1
- package/dist/src/color/transformColorsToHex.d.ts +0 -6
- package/dist/src/color/transformColorsToHex.d.ts.map +0 -1
- package/dist/src/primitive.d.ts +0 -9
- package/dist/src/primitive.d.ts.map +0 -1
- package/dist/src/toArray.d.ts +0 -3
- package/dist/src/toArray.d.ts.map +0 -1
- package/dist/src/zod/integer.d.ts +0 -10
- package/dist/src/zod/integer.d.ts.map +0 -1
- package/dist/src/zod/integer.spec.d.ts +0 -2
- package/dist/src/zod/integer.spec.d.ts.map +0 -1
- package/dist/toArray.cjs +0 -1
- package/dist/toArray.js +0 -5
- package/dist/xy-B7065J2S.cjs +0 -1
- package/src/color/transformColorsToHex.ts +0 -30
- package/src/primitive.ts +0 -46
- package/src/zod/integer.spec.ts +0 -148
- package/src/zod/integer.ts +0 -38
|
@@ -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 uuid from "@/uuid/uuid";
|
|
@@ -0,0 +1,82 @@
|
|
|
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 { uuid } from "@/uuid";
|
|
13
|
+
|
|
14
|
+
describe("UUID", () => {
|
|
15
|
+
describe("create", () => {
|
|
16
|
+
it("should generate a valid UUID v4", () => {
|
|
17
|
+
const uid = uuid.create();
|
|
18
|
+
expect(uid).toMatch(
|
|
19
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("should generate unique UUIDs", () => {
|
|
24
|
+
const uuids = new Set();
|
|
25
|
+
for (let i = 0; i < 1000; i++) {
|
|
26
|
+
const uid = uuid.create();
|
|
27
|
+
expect(uuids.has(uid)).toBe(false);
|
|
28
|
+
uuids.add(uid);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe("parse", () => {
|
|
34
|
+
it("should parse a valid UUID from bytes", () => {
|
|
35
|
+
// Example UUID: 123e4567-e89b-12d3-a456-426614174000
|
|
36
|
+
const bytes = new Uint8Array([
|
|
37
|
+
0x12, 0x3e, 0x45, 0x67, 0xe8, 0x9b, 0x12, 0xd3, 0xa4, 0x56, 0x42, 0x66, 0x14,
|
|
38
|
+
0x17, 0x40, 0x00,
|
|
39
|
+
]);
|
|
40
|
+
const uid = uuid.parse(bytes);
|
|
41
|
+
expect(uid).toBe("123e4567-e89b-12d3-a456-426614174000");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should handle zero bytes", () => {
|
|
45
|
+
const bytes = new Uint8Array(16);
|
|
46
|
+
const uid = uuid.parse(bytes);
|
|
47
|
+
expect(uid).toBe("00000000-0000-0000-0000-000000000000");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should handle all ones", () => {
|
|
51
|
+
const bytes = new Uint8Array(16).fill(0xff);
|
|
52
|
+
const uid = uuid.parse(bytes);
|
|
53
|
+
expect(uid).toBe("ffffffff-ffff-ffff-ffff-ffffffffffff");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("should handle random bytes", () => {
|
|
57
|
+
const bytes = new Uint8Array([
|
|
58
|
+
0x7f, 0x3e, 0x45, 0x67, 0xe8, 0x9b, 0x12, 0xd3, 0xa4, 0x56, 0x42, 0x66, 0x14,
|
|
59
|
+
0x17, 0x40, 0x00,
|
|
60
|
+
]);
|
|
61
|
+
const uid = uuid.parse(bytes);
|
|
62
|
+
expect(uid).toMatch(
|
|
63
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should throw error for invalid byte length", () => {
|
|
68
|
+
const bytes = new Uint8Array(15); // Invalid length
|
|
69
|
+
expect(() => uuid.parse(bytes)).toThrow();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("should maintain byte order", () => {
|
|
73
|
+
// Test with a specific pattern to verify byte order
|
|
74
|
+
const bytes = new Uint8Array([
|
|
75
|
+
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd,
|
|
76
|
+
0xee, 0xff, 0x00,
|
|
77
|
+
]);
|
|
78
|
+
const uid = uuid.parse(bytes);
|
|
79
|
+
expect(uid).toBe("11223344-5566-7788-99aa-bbccddeeff00");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
package/src/uuid/uuid.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
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 { NIL, stringify, v4 as uuid } from "uuid";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new random UUID (Universally Unique Identifier) version 4.
|
|
14
|
+
* This function uses the cryptographically secure random number generator
|
|
15
|
+
* to generate a UUID that is suitable for use as a unique identifier.
|
|
16
|
+
*
|
|
17
|
+
* @returns {string} A new UUID v4 string in the format 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
|
|
18
|
+
* where x is any hexadecimal digit and y is one of 8, 9, A, or B.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const id = create(); // Returns something like "123e4567-e89b-12d3-a456-426614174000"
|
|
22
|
+
*/
|
|
23
|
+
export const create = (): string => uuid();
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Parses a UUID from a byte array.
|
|
27
|
+
* This function converts a 16-byte array into a standard UUID string format.
|
|
28
|
+
* It can optionally start parsing from a specific offset in the byte array.
|
|
29
|
+
*
|
|
30
|
+
* @param {Uint8Array} bytes - The byte array containing the UUID. Must be at least 16 bytes long.
|
|
31
|
+
* @param {number} [offset=0] - Optional offset in the byte array to start parsing from.
|
|
32
|
+
*
|
|
33
|
+
* @returns {string} A UUID string in the format 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
|
34
|
+
*
|
|
35
|
+
* @throws {Error} If the byte array is less than 16 bytes long (accounting for offset)
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const bytes = new Uint8Array([
|
|
39
|
+
* 0x12, 0x3e, 0x45, 0x67, 0xe8, 0x9b, 0x12, 0xd3,
|
|
40
|
+
* 0xa4, 0x56, 0x42, 0x66, 0x14, 0x17, 0x40, 0x00
|
|
41
|
+
* ]);
|
|
42
|
+
* const uuid = parse(bytes); // Returns "123e4567-e89b-12d3-a456-426614174000"
|
|
43
|
+
*/
|
|
44
|
+
export const parse = (bytes: Uint8Array, offset?: number): string =>
|
|
45
|
+
stringify(bytes, offset);
|
|
46
|
+
|
|
47
|
+
/** The zero value for a UUID - 00000000-0000-0000-0000-000000000000 */
|
|
48
|
+
export const ZERO = NIL;
|
package/src/zod/external.ts
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
import { z } from "zod/v4";
|
|
12
|
+
|
|
13
|
+
import { zod } from "@/zod";
|
|
14
|
+
|
|
15
|
+
describe("zod", () => {
|
|
16
|
+
describe("nullToUndefined", () => {
|
|
17
|
+
const schema = zod.nullToUndefined(z.string());
|
|
18
|
+
it("should parse the normal case", () => {
|
|
19
|
+
expect(schema.parse("string")).toBe("string");
|
|
20
|
+
});
|
|
21
|
+
it("should parse null as undefined", () => {
|
|
22
|
+
expect(schema.parse(null)).toBe(undefined);
|
|
23
|
+
});
|
|
24
|
+
it("should parse undefined as undefined", () => {
|
|
25
|
+
expect(schema.parse(undefined)).toBe(undefined);
|
|
26
|
+
});
|
|
27
|
+
it("should throw for other values", () => {
|
|
28
|
+
expect(() => schema.parse(1)).toThrow(z.ZodError);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
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 { type z } from "zod/v4";
|
|
11
|
+
|
|
12
|
+
export const nullToUndefined = <Input, Output>(
|
|
13
|
+
schema: z.ZodType<Input, Output>,
|
|
14
|
+
): z.ZodOptional<
|
|
15
|
+
z.ZodPipe<
|
|
16
|
+
z.ZodNullable<z.ZodType<Input, Output>>,
|
|
17
|
+
z.ZodTransform<Awaited<Input & {}> | undefined, Input | null>
|
|
18
|
+
>
|
|
19
|
+
> =>
|
|
20
|
+
schema
|
|
21
|
+
.nullable()
|
|
22
|
+
.transform((s) => (s === null ? undefined : s))
|
|
23
|
+
.optional();
|
package/src/zod/util.spec.ts
CHANGED
package/src/zod/util.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 { deep } from "@/deep";
|
|
13
13
|
import { type UnknownRecord } from "@/record";
|
|
@@ -34,13 +34,13 @@ const sourceTypeGetter = (obj: unknown, key: string): z.ZodAny | null => {
|
|
|
34
34
|
return v;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
export const getFieldSchema: deep.TypedGet<z.
|
|
38
|
-
schema: z.
|
|
37
|
+
export const getFieldSchema: deep.TypedGet<z.ZodType, z.ZodType> = ((
|
|
38
|
+
schema: z.ZodType,
|
|
39
39
|
path: string,
|
|
40
40
|
options?: Omit<deep.GetOptions, "getter">,
|
|
41
|
-
): z.
|
|
42
|
-
deep.get<z.
|
|
41
|
+
): z.ZodType | null =>
|
|
42
|
+
deep.get<z.ZodType, z.ZodType>(
|
|
43
43
|
sourceTypeGetter(schema, "shape") as unknown as z.ZodObject<z.ZodRawShape>,
|
|
44
44
|
getFieldSchemaPath(path),
|
|
45
45
|
{ ...options, getter: sourceTypeGetter } as deep.GetOptions<boolean | undefined>,
|
|
46
|
-
)) as deep.TypedGet<z.
|
|
46
|
+
)) as deep.TypedGet<z.ZodType, z.ZodType>;
|