@synnaxlabs/x 0.54.2 → 0.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/.turbo/turbo-build.log +10 -13
  2. package/dist/src/array/nullable.d.ts +1 -1
  3. package/dist/src/array/nullable.d.ts.map +1 -1
  4. package/dist/src/caseconv/caseconv.d.ts.map +1 -1
  5. package/dist/src/compare/compare.d.ts +14 -0
  6. package/dist/src/compare/compare.d.ts.map +1 -1
  7. package/dist/src/debounce/debounce.d.ts +7 -2
  8. package/dist/src/debounce/debounce.d.ts.map +1 -1
  9. package/dist/src/destructor/destructor.d.ts +1 -0
  10. package/dist/src/destructor/destructor.d.ts.map +1 -1
  11. package/dist/src/errors/errors.d.ts +6 -10
  12. package/dist/src/errors/errors.d.ts.map +1 -1
  13. package/dist/src/index.d.ts +4 -1
  14. package/dist/src/index.d.ts.map +1 -1
  15. package/dist/src/notation/external.d.ts +3 -0
  16. package/dist/src/notation/external.d.ts.map +1 -0
  17. package/dist/src/notation/index.d.ts +1 -1
  18. package/dist/src/notation/notation.d.ts +5 -9
  19. package/dist/src/notation/notation.d.ts.map +1 -1
  20. package/dist/src/notation/types.gen.d.ts +9 -0
  21. package/dist/src/notation/types.gen.d.ts.map +1 -0
  22. package/dist/src/primitive/primitive.d.ts +16 -0
  23. package/dist/src/primitive/primitive.d.ts.map +1 -1
  24. package/dist/src/record/record.d.ts +8 -1
  25. package/dist/src/record/record.d.ts.map +1 -1
  26. package/dist/src/require/index.d.ts +2 -0
  27. package/dist/src/require/index.d.ts.map +1 -0
  28. package/dist/src/require/require.d.ts +2 -0
  29. package/dist/src/require/require.d.ts.map +1 -0
  30. package/dist/src/spatial/base.d.ts +1 -103
  31. package/dist/src/spatial/base.d.ts.map +1 -1
  32. package/dist/src/spatial/bounds/bounds.d.ts +3 -3
  33. package/dist/src/spatial/bounds/bounds.d.ts.map +1 -1
  34. package/dist/src/spatial/box/box.d.ts +7 -13
  35. package/dist/src/spatial/box/box.d.ts.map +1 -1
  36. package/dist/src/spatial/direction/direction.d.ts +17 -16
  37. package/dist/src/spatial/direction/direction.d.ts.map +1 -1
  38. package/dist/src/spatial/external.d.ts +1 -2
  39. package/dist/src/spatial/external.d.ts.map +1 -1
  40. package/dist/src/spatial/location/location.d.ts +28 -28
  41. package/dist/src/spatial/location/location.d.ts.map +1 -1
  42. package/dist/src/spatial/scale/scale.d.ts +2 -2
  43. package/dist/src/spatial/scale/scale.d.ts.map +1 -1
  44. package/dist/src/spatial/sticky/sticky.d.ts +15 -15
  45. package/dist/src/spatial/sticky/sticky.d.ts.map +1 -1
  46. package/dist/src/spatial/types.gen.d.ts +179 -2
  47. package/dist/src/spatial/types.gen.d.ts.map +1 -1
  48. package/dist/src/spatial/xy/xy.d.ts +4 -4
  49. package/dist/src/spatial/xy/xy.d.ts.map +1 -1
  50. package/dist/src/status/status.d.ts +11 -0
  51. package/dist/src/status/status.d.ts.map +1 -1
  52. package/dist/src/strings/strings.d.ts +9 -0
  53. package/dist/src/strings/strings.d.ts.map +1 -1
  54. package/dist/src/telem/clockSkew.d.ts +17 -0
  55. package/dist/src/telem/clockSkew.d.ts.map +1 -0
  56. package/dist/src/telem/clockSkew.spec.d.ts +2 -0
  57. package/dist/src/telem/clockSkew.spec.d.ts.map +1 -0
  58. package/dist/src/telem/external.d.ts +2 -0
  59. package/dist/src/telem/external.d.ts.map +1 -1
  60. package/dist/src/telem/series.d.ts +6 -3
  61. package/dist/src/telem/series.d.ts.map +1 -1
  62. package/dist/src/telem/telem.d.ts +48 -39
  63. package/dist/src/telem/telem.d.ts.map +1 -1
  64. package/dist/src/telem/types.gen.d.ts +19 -0
  65. package/dist/src/telem/types.gen.d.ts.map +1 -0
  66. package/dist/src/text/external.d.ts +3 -0
  67. package/dist/src/text/external.d.ts.map +1 -0
  68. package/dist/src/text/index.d.ts +2 -0
  69. package/dist/src/text/index.d.ts.map +1 -0
  70. package/dist/src/text/types.d.ts +21 -0
  71. package/dist/src/text/types.d.ts.map +1 -0
  72. package/dist/src/text/types.gen.d.ts +13 -0
  73. package/dist/src/text/types.gen.d.ts.map +1 -0
  74. package/dist/src/throttle/index.d.ts +2 -0
  75. package/dist/src/throttle/index.d.ts.map +1 -0
  76. package/dist/src/throttle/throttle.d.ts +3 -0
  77. package/dist/src/throttle/throttle.d.ts.map +1 -0
  78. package/dist/src/throttle/throttle.spec.d.ts +2 -0
  79. package/dist/src/throttle/throttle.spec.d.ts.map +1 -0
  80. package/dist/src/zod/parse.d.ts.map +1 -1
  81. package/dist/x.cjs +10 -13
  82. package/dist/x.js +2271 -2084
  83. package/package.json +12 -12
  84. package/src/array/nullable.ts +1 -4
  85. package/src/caseconv/caseconv.spec.ts +71 -0
  86. package/src/caseconv/caseconv.ts +15 -2
  87. package/src/compare/compare.spec.ts +115 -0
  88. package/src/compare/compare.ts +29 -0
  89. package/src/debounce/debounce.spec.ts +258 -24
  90. package/src/debounce/debounce.ts +49 -30
  91. package/src/deep/copy.spec.ts +13 -0
  92. package/src/deep/difference.ts +1 -1
  93. package/src/destructor/destructor.ts +2 -0
  94. package/src/errors/errors.spec.ts +30 -0
  95. package/src/errors/errors.ts +29 -17
  96. package/src/index.ts +4 -1
  97. package/src/notation/external.ts +11 -0
  98. package/src/notation/index.ts +1 -1
  99. package/src/notation/notation.spec.ts +260 -2
  100. package/src/notation/notation.ts +25 -7
  101. package/src/notation/types.gen.ts +16 -0
  102. package/src/primitive/primitive.spec.ts +58 -5
  103. package/src/primitive/primitive.ts +22 -0
  104. package/src/record/record.spec.ts +26 -0
  105. package/src/record/record.ts +20 -5
  106. package/src/require/index.ts +10 -0
  107. package/src/require/require.ts +10 -0
  108. package/src/spatial/base.ts +1 -93
  109. package/src/spatial/bounds/bounds.ts +10 -10
  110. package/src/spatial/box/box.ts +5 -5
  111. package/src/spatial/direction/direction.ts +16 -17
  112. package/src/spatial/external.ts +1 -2
  113. package/src/spatial/location/location.ts +19 -17
  114. package/src/spatial/scale/scale.ts +2 -2
  115. package/src/spatial/sticky/sticky.spec.ts +2 -2
  116. package/src/spatial/sticky/sticky.ts +6 -13
  117. package/src/spatial/types.gen.ts +140 -0
  118. package/src/spatial/xy/xy.ts +7 -7
  119. package/src/status/status.spec.ts +65 -0
  120. package/src/status/status.ts +20 -0
  121. package/src/strings/strings.spec.ts +19 -0
  122. package/src/strings/strings.ts +16 -0
  123. package/src/telem/clockSkew.spec.ts +58 -0
  124. package/src/telem/clockSkew.ts +46 -0
  125. package/src/telem/external.ts +9 -0
  126. package/src/telem/series.spec.ts +235 -4
  127. package/src/telem/series.ts +172 -58
  128. package/src/telem/telem.spec.ts +147 -9
  129. package/src/telem/telem.ts +101 -84
  130. package/src/telem/types.gen.ts +28 -0
  131. package/src/text/external.ts +11 -0
  132. package/src/text/index.ts +10 -0
  133. package/src/text/types.gen.ts +16 -0
  134. package/src/text/types.ts +37 -0
  135. package/src/{worker → throttle}/index.ts +1 -1
  136. package/src/throttle/throttle.spec.ts +147 -0
  137. package/src/throttle/throttle.ts +44 -0
  138. package/src/zod/parse.ts +2 -3
  139. package/tsconfig.tsbuildinfo +1 -1
  140. package/dist/src/spatial/spatial.d.ts +0 -3
  141. package/dist/src/spatial/spatial.d.ts.map +0 -1
  142. package/dist/src/worker/index.d.ts +0 -2
  143. package/dist/src/worker/index.d.ts.map +0 -1
  144. package/dist/src/worker/worker.d.ts +0 -33
  145. package/dist/src/worker/worker.d.ts.map +0 -1
  146. package/dist/src/worker/worker.spec.d.ts +0 -2
  147. package/dist/src/worker/worker.spec.d.ts.map +0 -1
  148. package/src/spatial/spatial.ts +0 -44
  149. package/src/worker/worker.spec.ts +0 -41
  150. package/src/worker/worker.ts +0 -86
@@ -0,0 +1,11 @@
1
+ // Copyright 2026 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 * from "@/text/types";
11
+ export * from "@/text/types.gen";
@@ -0,0 +1,10 @@
1
+ // Copyright 2026 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 text from "@/text/external";
@@ -0,0 +1,16 @@
1
+ // Copyright 2026 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
+ // Code generated by Oracle. DO NOT EDIT.
11
+
12
+ import { z } from "zod";
13
+
14
+ export const LEVELS = ["h1", "h2", "h3", "h4", "h5", "p", "small"] as const;
15
+ export const levelZ = z.enum(LEVELS);
16
+ export type Level = z.infer<typeof levelZ>;
@@ -0,0 +1,37 @@
1
+ // Copyright 2026 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 { z } from "zod";
11
+
12
+ import { type Level, LEVELS } from "@/text/types.gen";
13
+
14
+ /** Steps a typography level down by one rank; bottoms out at the smallest. */
15
+ export const downLevel = (level: Level): Level => {
16
+ const index = LEVELS.indexOf(level);
17
+ if (index === -1 || index === LEVELS.length - 1) return level;
18
+ return LEVELS[index + 1];
19
+ };
20
+
21
+ export const weightZ = z.union([
22
+ z.number(),
23
+ z.enum(["normal", "bold", "bolder", "lighter"]),
24
+ ]);
25
+
26
+ /** Weight sets the weight of the text. */
27
+ export type Weight = z.infer<typeof weightZ>;
28
+
29
+ export const specZ = z.object({
30
+ size: z.number(),
31
+ weight: z.union([z.number(), z.string()]),
32
+ lineHeight: z.number(),
33
+ textTransform: z.string().optional(),
34
+ });
35
+
36
+ /** Defines a particular typography style. */
37
+ export type Spec = z.infer<typeof specZ>;
@@ -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 * from "@/worker/worker";
10
+ export * from "@/throttle/throttle";
@@ -0,0 +1,147 @@
1
+ // Copyright 2026 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 { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
11
+
12
+ import { TimeSpan } from "@/telem/telem";
13
+ import { throttle } from "@/throttle/throttle";
14
+
15
+ describe("throttle", () => {
16
+ beforeEach(() => {
17
+ vi.useFakeTimers();
18
+ });
19
+ afterEach(() => {
20
+ vi.useRealTimers();
21
+ });
22
+
23
+ it("should execute immediately on the leading edge", () => {
24
+ const fn = vi.fn();
25
+ const throttled = throttle(fn, TimeSpan.milliseconds(100));
26
+ expect(fn).toHaveBeenCalledTimes(0);
27
+ throttled(10);
28
+ expect(fn).toHaveBeenCalledTimes(1);
29
+ expect(fn).toHaveBeenLastCalledWith(10);
30
+ });
31
+
32
+ it("should throttle repeated calls during the wait period", () => {
33
+ const fn = vi.fn();
34
+ const throttled = throttle(fn, TimeSpan.milliseconds(100));
35
+ expect(fn).toHaveBeenCalledTimes(0);
36
+ throttled(10);
37
+ expect(fn).toHaveBeenCalledTimes(1);
38
+ expect(fn).toHaveBeenLastCalledWith(10);
39
+ throttled(20);
40
+ throttled(30);
41
+ throttled(40);
42
+ expect(fn).toHaveBeenCalledTimes(1);
43
+ });
44
+
45
+ it("should run a trailing call with the latest arguments", () => {
46
+ const fn = vi.fn();
47
+ const throttled = throttle(fn, TimeSpan.milliseconds(100));
48
+ expect(fn).toHaveBeenCalledTimes(0);
49
+ throttled(10);
50
+ expect(fn).toHaveBeenCalledTimes(1);
51
+ expect(fn).toHaveBeenLastCalledWith(10);
52
+ throttled(20);
53
+ throttled(30);
54
+ throttled(40);
55
+ expect(fn).toHaveBeenCalledTimes(1);
56
+ vi.advanceTimersByTime(100);
57
+ expect(fn).toHaveBeenCalledTimes(2);
58
+ expect(fn).toHaveBeenLastCalledWith(40);
59
+ });
60
+
61
+ it("should schedule the trailing call after only the remaining wait time", () => {
62
+ const fn = vi.fn();
63
+ const throttled = throttle(fn, TimeSpan.milliseconds(100));
64
+ throttled(10);
65
+ expect(fn).toHaveBeenCalledTimes(1);
66
+ expect(fn).toHaveBeenLastCalledWith(10);
67
+ vi.advanceTimersByTime(90);
68
+ throttled(20);
69
+ expect(fn).toHaveBeenCalledTimes(1);
70
+ vi.advanceTimersByTime(9);
71
+ expect(fn).toHaveBeenCalledTimes(1);
72
+ vi.advanceTimersByTime(1);
73
+ expect(fn).toHaveBeenCalledTimes(2);
74
+ expect(fn).toHaveBeenLastCalledWith(20);
75
+ });
76
+
77
+ it("should not schedule multiple trailing calls", () => {
78
+ const fn = vi.fn();
79
+ const throttled = throttle(fn, TimeSpan.milliseconds(100));
80
+ throttled(10);
81
+ throttled(20);
82
+ throttled(30);
83
+
84
+ vi.advanceTimersByTime(100);
85
+
86
+ expect(fn).toHaveBeenCalledTimes(2);
87
+ expect(fn).toHaveBeenNthCalledWith(1, 10);
88
+ expect(fn).toHaveBeenNthCalledWith(2, 30);
89
+
90
+ vi.advanceTimersByTime(100);
91
+ expect(fn).toHaveBeenCalledTimes(2);
92
+ });
93
+
94
+ it("should execute again immediately after the wait period has passed", () => {
95
+ const fn = vi.fn();
96
+ const throttled = throttle(fn, TimeSpan.milliseconds(100));
97
+
98
+ throttled(10);
99
+ vi.advanceTimersByTime(100);
100
+ throttled(20);
101
+
102
+ expect(fn).toHaveBeenCalledTimes(2);
103
+ expect(fn).toHaveBeenNthCalledWith(1, 10);
104
+ expect(fn).toHaveBeenNthCalledWith(2, 20);
105
+ });
106
+
107
+ it("should preserve null arguments", () => {
108
+ const fn = vi.fn();
109
+ const throttled = throttle(fn, TimeSpan.milliseconds(100));
110
+ throttled(null);
111
+ throttled(20);
112
+ throttled(null);
113
+ vi.advanceTimersByTime(100);
114
+ expect(fn).toHaveBeenCalledTimes(2);
115
+ expect(fn).toHaveBeenNthCalledWith(1, null);
116
+ expect(fn).toHaveBeenNthCalledWith(2, null);
117
+ });
118
+
119
+ it("should clear pending state before invoking the function", () => {
120
+ const fn = vi.fn();
121
+ fn.mockImplementation((value: number) => {
122
+ if (value === 20) throttled(30);
123
+ });
124
+
125
+ const throttled = throttle(fn, TimeSpan.milliseconds(100));
126
+
127
+ throttled(10);
128
+ throttled(20);
129
+
130
+ vi.advanceTimersByTime(100);
131
+
132
+ expect(fn).toHaveBeenCalledTimes(2);
133
+ expect(fn).toHaveBeenNthCalledWith(1, 10);
134
+ expect(fn).toHaveBeenNthCalledWith(2, 20);
135
+
136
+ vi.advanceTimersByTime(100);
137
+
138
+ expect(fn).toHaveBeenCalledTimes(3);
139
+ expect(fn).toHaveBeenNthCalledWith(3, 30);
140
+ });
141
+
142
+ it("should not throttle the execution of the given function if the time is 0", () => {
143
+ const fn = vi.fn();
144
+ const throttled = throttle(fn, TimeSpan.ZERO);
145
+ expect(throttled).toBe(fn);
146
+ });
147
+ });
@@ -0,0 +1,44 @@
1
+ // Copyright 2026 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 CrudeTimeSpan, TimeSpan, TimeStamp } from "@/telem/telem";
11
+
12
+ export const throttle = <Args extends unknown[]>(
13
+ func: (...args: Args) => void,
14
+ waitFor: CrudeTimeSpan,
15
+ ): ((...args: Args) => void) => {
16
+ const throttlePeriod = new TimeSpan(waitFor);
17
+ if (throttlePeriod.valueOf() <= 0) return func;
18
+ let timeout: NodeJS.Timeout | undefined;
19
+ let lastInvokeTime: TimeStamp = TimeStamp.MIN;
20
+ let latestArgs: Args | null = null;
21
+ const invoke = (): void => {
22
+ if (latestArgs === null) return;
23
+ lastInvokeTime = TimeStamp.now();
24
+ const args = latestArgs;
25
+ latestArgs = null;
26
+ func(...args);
27
+ };
28
+ return (...args: Args): void => {
29
+ const timeSinceLastInvoke = TimeStamp.since(lastInvokeTime);
30
+ latestArgs = args;
31
+ const remaining = throttlePeriod.sub(timeSinceLastInvoke);
32
+ if (remaining.valueOf() <= 0 || remaining.greaterThan(throttlePeriod)) {
33
+ clearTimeout(timeout);
34
+ timeout = undefined;
35
+ invoke();
36
+ return;
37
+ }
38
+ if (timeout != null) return;
39
+ timeout = setTimeout(() => {
40
+ timeout = undefined;
41
+ invoke();
42
+ }, remaining.milliseconds);
43
+ };
44
+ };
package/src/zod/parse.ts CHANGED
@@ -164,7 +164,7 @@ const flattenIssues = (
164
164
  out.push(...flattenIssues(issue.issues, fullPath));
165
165
  continue;
166
166
  }
167
- out.push({ ...issue, path: fullPath } as z.core.$ZodIssue);
167
+ out.push({ ...issue, path: fullPath });
168
168
  }
169
169
  return out;
170
170
  };
@@ -184,8 +184,7 @@ const expandUnrecognizedKeys = (
184
184
  "keys" in issue &&
185
185
  Array.isArray(issue.keys)
186
186
  ) {
187
- for (const key of issue.keys)
188
- out.push({ ...issue, path: [...issue.path, key] } as z.core.$ZodIssue);
187
+ for (const key of issue.keys) out.push({ ...issue, path: [...issue.path, key] });
189
188
  continue;
190
189
  }
191
190
  out.push(issue);