@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
package/src/color/external.ts
CHANGED
package/src/color/gradient.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 { 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
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
};
|
package/src/color/palette.ts
CHANGED
package/src/compare/compare.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 {
|
|
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
|
|
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
|
|
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
|
|
98
|
+
export const uniqueUnorderedPrimitiveArrays = <T extends primitive.Value>(
|
|
99
99
|
a: readonly T[] | T[],
|
|
100
100
|
b: readonly T[] | T[],
|
|
101
101
|
): number => {
|
package/src/control/control.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 { 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 = <
|
|
35
|
+
export const stateZ = <R extends z.ZodType>(resource: R) =>
|
|
36
36
|
z.object({
|
|
37
37
|
subject: subjectZ,
|
|
38
|
-
resource
|
|
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.
|
|
64
|
-
|
|
65
|
-
|
|
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.
|
|
74
|
-
|
|
75
|
-
|
|
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.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
+
]);
|
package/src/debounce/debounce.ts
CHANGED
|
@@ -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:
|
|
28
|
+
export const throttle = <F extends (...args: unknown[]) => void>(
|
|
29
29
|
func: F,
|
|
30
30
|
waitFor: number,
|
|
31
31
|
): F => {
|
package/src/deep/delete.ts
CHANGED
|
@@ -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
|
|
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
|
|
18
|
+
let curr = target;
|
|
19
19
|
const arr = key.split(".");
|
|
20
20
|
arr.forEach((k, i) => {
|
|
21
|
-
if (
|
|
22
|
-
|
|
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;
|
package/src/deep/difference.ts
CHANGED
|
@@ -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:
|
|
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(
|
|
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];
|
package/src/deep/equal.spec.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 { 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
|
|
10
|
+
import { type primitive } from "@/primitive";
|
|
11
11
|
|
|
12
12
|
interface DeepEqualBaseRecord {
|
|
13
|
-
equals?: (other:
|
|
13
|
+
equals?: (other: unknown) => boolean;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export const equal = <
|
|
17
|
-
T extends unknown | DeepEqualBaseRecord | DeepEqualBaseRecord[] |
|
|
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:
|
|
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 |
|
|
50
|
+
export const partialEqual = <T extends unknown | DeepEqualBaseRecord | primitive.Value>(
|
|
51
51
|
base: T,
|
|
52
52
|
partial: Partial<T>,
|
|
53
53
|
): boolean => {
|
package/src/deep/merge.spec.ts
CHANGED
|
@@ -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
|
-
|
|
65
|
-
if (shape
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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) =>
|
|
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;
|
package/src/errors/errors.ts
CHANGED
|
@@ -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:
|
|
20
|
+
export type Matcher = (e: unknown) => boolean;
|
|
19
21
|
|
|
20
|
-
/**
|
|
22
|
+
/** an error type that can match against other errors. */
|
|
21
23
|
export interface Matchable {
|
|
22
24
|
/**
|
|
23
|
-
* @returns
|
|
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
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
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:
|
|
36
|
+
discriminator: typeof ERROR_DISCRIMINATOR;
|
|
36
37
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
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
|
-
*
|
|
45
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
57
|
+
* the type of the error.
|
|
57
58
|
*/
|
|
58
59
|
TYPE: string;
|
|
59
60
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
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 =
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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 !==
|
|
137
|
+
if (typedError.discriminator !== ERROR_DISCRIMINATOR) return false;
|
|
136
138
|
if (!("type" in typedError))
|
|
137
139
|
throw new Error(
|
|
138
|
-
`
|
|
140
|
+
`X Error is missing its type property: ${JSON.stringify(typedError)}`,
|
|
139
141
|
);
|
|
140
142
|
return true;
|
|
141
143
|
};
|
|
142
144
|
|
|
143
|
-
/**
|
|
145
|
+
/** Constant representing an unknown error type */
|
|
144
146
|
export const UNKNOWN = "unknown";
|
|
145
147
|
|
|
146
|
-
/**
|
|
148
|
+
/** Constant representing no error (null) */
|
|
147
149
|
export const NONE = "nil";
|
|
148
150
|
|
|
149
|
-
|
|
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:
|
|
173
|
+
private readonly providers: Provider[] = [];
|
|
156
174
|
|
|
157
|
-
register(provider:
|
|
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
|
|
208
|
-
*
|
|
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
|
-
*
|
|
241
|
+
* Generic error for representing unknown errors
|
|
229
242
|
*/
|
|
230
243
|
export class Unknown extends createTyped("unknown") {}
|
|
231
244
|
|
|
232
|
-
/**
|
|
245
|
+
/** Zod schema for validating error payloads */
|
|
233
246
|
export const payloadZ = z.object({ type: z.string(), data: z.string() });
|
|
234
247
|
|
|
235
|
-
/**
|
|
248
|
+
/** Network-portable representation of an error */
|
|
236
249
|
export type Payload = z.infer<typeof payloadZ>;
|
|
237
250
|
|
|
238
|
-
/**
|
|
251
|
+
/** Error for representing the cancellation of an operation */
|
|
239
252
|
export class Canceled extends createTyped("canceled") {}
|
|
240
253
|
|
|
241
|
-
|
|
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";
|