@synnaxlabs/x 0.43.0 → 0.44.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 (288) hide show
  1. package/.turbo/turbo-build.log +105 -93
  2. package/dist/base-BAM2mqCy.cjs +1 -0
  3. package/dist/base-DFq0vvGn.js +38 -0
  4. package/dist/binary.cjs +1 -1
  5. package/dist/binary.js +1 -1
  6. package/dist/bounds-D6e9xoHt.cjs +1 -0
  7. package/dist/bounds-Dj9nG39I.js +174 -0
  8. package/dist/bounds.cjs +1 -1
  9. package/dist/bounds.js +2 -2
  10. package/dist/box-BcGdqkt4.cjs +1 -0
  11. package/dist/box-D_qdUyEe.js +205 -0
  12. package/dist/box.cjs +1 -1
  13. package/dist/box.js +1 -1
  14. package/dist/caseconv.cjs +1 -1
  15. package/dist/caseconv.js +2 -2
  16. package/dist/change-C-YELKx6.cjs +1 -0
  17. package/dist/change-DLl6DccR.js +12 -0
  18. package/dist/change.cjs +1 -1
  19. package/dist/change.js +2 -10
  20. package/dist/compare.cjs +1 -1
  21. package/dist/compare.js +1 -1
  22. package/dist/deep.cjs +1 -1
  23. package/dist/deep.js +95 -96
  24. package/dist/dimensions-CRgergMS.js +43 -0
  25. package/dist/dimensions-D2QGoNXO.cjs +1 -0
  26. package/dist/dimensions.cjs +1 -1
  27. package/dist/dimensions.js +2 -41
  28. package/dist/direction-386XDm2w.cjs +1 -0
  29. package/dist/{index-DxU1zwsd.js → direction-8etxfKaR.js} +4 -3
  30. package/dist/direction.cjs +1 -1
  31. package/dist/direction.js +1 -1
  32. package/dist/external-B9AAGv50.cjs +1 -0
  33. package/dist/external-BFgJjMcS.js +23 -0
  34. package/dist/external-BPgtxa8d.js +29 -0
  35. package/dist/external-BYuXBYJh.js +40 -0
  36. package/dist/external-mffsMzJx.cjs +1 -0
  37. package/dist/external-uXk0Avrg.cjs +1 -0
  38. package/dist/index-B1m2qvBT.cjs +1 -0
  39. package/dist/{index-4GlOgZuh.js → index-B5l_quQn.js} +35 -42
  40. package/dist/index-BQe8OIgm.cjs +3 -0
  41. package/dist/index-D2xcvEO5.js +46 -0
  42. package/dist/index-DdhM_E4k.cjs +1 -0
  43. package/dist/index-PNh31WTW.js +125 -0
  44. package/dist/index.cjs +3 -5
  45. package/dist/index.js +685 -5363
  46. package/dist/kv.cjs +1 -1
  47. package/dist/kv.js +2 -45
  48. package/dist/{index-D6V-8SKw.js → location-Ar5y2DX2.js} +26 -26
  49. package/dist/location-DZi8ftXp.cjs +1 -0
  50. package/dist/location.cjs +1 -1
  51. package/dist/location.js +1 -1
  52. package/dist/observe.cjs +1 -1
  53. package/dist/observe.js +16 -20
  54. package/dist/path-BXdMenka.js +101 -0
  55. package/dist/path-st_E5-LJ.cjs +1 -0
  56. package/dist/position-DAL0Qqdf.cjs +1 -0
  57. package/dist/position-bA6pUwLn.js +85 -0
  58. package/dist/position.cjs +1 -1
  59. package/dist/position.js +2 -83
  60. package/dist/record-CAcQ5PNX.js +14 -0
  61. package/dist/record-YvCh7bzB.cjs +1 -0
  62. package/dist/record.cjs +1 -1
  63. package/dist/record.js +2 -8
  64. package/dist/runtime.cjs +1 -1
  65. package/dist/runtime.js +2 -27
  66. package/dist/scale-Bzn1Cl0r.cjs +1 -0
  67. package/dist/{index-BUa-NXAX.js → scale-CdTNWu-d.js} +55 -59
  68. package/dist/scale.cjs +1 -1
  69. package/dist/scale.js +1 -1
  70. package/dist/{index-DBGAIs_7.js → series-BeJyqCoP.js} +835 -759
  71. package/dist/series-anlpaR_I.cjs +6 -0
  72. package/dist/spatial-BSWPzMkK.js +11 -0
  73. package/dist/spatial-DGpZ2sO3.cjs +1 -0
  74. package/dist/spatial.cjs +1 -1
  75. package/dist/spatial.js +18 -25
  76. package/dist/src/binary/codec.d.ts +1 -1
  77. package/dist/src/binary/codec.d.ts.map +1 -1
  78. package/dist/src/breaker/breaker.d.ts +2 -2
  79. package/dist/src/breaker/breaker.d.ts.map +1 -1
  80. package/dist/src/caseconv/caseconv.d.ts +0 -1
  81. package/dist/src/caseconv/caseconv.d.ts.map +1 -1
  82. package/dist/src/change/change.d.ts +1 -1
  83. package/dist/src/change/change.d.ts.map +1 -1
  84. package/dist/src/color/color.d.ts +2 -2
  85. package/dist/src/color/color.d.ts.map +1 -1
  86. package/dist/src/color/gradient.d.ts +1 -1
  87. package/dist/src/color/gradient.d.ts.map +1 -1
  88. package/dist/src/color/palette.d.ts +3 -3
  89. package/dist/src/color/palette.d.ts.map +1 -1
  90. package/dist/src/compare/compare.d.ts +4 -4
  91. package/dist/src/compare/compare.d.ts.map +1 -1
  92. package/dist/src/control/control.d.ts +9 -9
  93. package/dist/src/control/control.d.ts.map +1 -1
  94. package/dist/src/deep/merge.d.ts +1 -1
  95. package/dist/src/deep/merge.d.ts.map +1 -1
  96. package/dist/src/deep/path.d.ts +6 -6
  97. package/dist/src/deep/path.d.ts.map +1 -1
  98. package/dist/src/destructor.d.ts +6 -2
  99. package/dist/src/destructor.d.ts.map +1 -1
  100. package/dist/src/errors/errors.d.ts +5 -1
  101. package/dist/src/errors/errors.d.ts.map +1 -1
  102. package/dist/src/flush.d.ts +11 -0
  103. package/dist/src/flush.d.ts.map +1 -0
  104. package/dist/src/id/id.d.ts +1 -0
  105. package/dist/src/id/id.d.ts.map +1 -1
  106. package/dist/src/identity.d.ts +2 -2
  107. package/dist/src/identity.d.ts.map +1 -1
  108. package/dist/src/index.d.ts +3 -1
  109. package/dist/src/index.d.ts.map +1 -1
  110. package/dist/src/jsonrpc/jsonrpc.d.ts +1 -1
  111. package/dist/src/jsonrpc/jsonrpc.d.ts.map +1 -1
  112. package/dist/src/kv/types.d.ts +1 -1
  113. package/dist/src/kv/types.d.ts.map +1 -1
  114. package/dist/src/map/index.d.ts +2 -0
  115. package/dist/src/map/index.d.ts.map +1 -0
  116. package/dist/src/map/map.d.ts +2 -0
  117. package/dist/src/map/map.d.ts.map +1 -0
  118. package/dist/src/map/map.spec.d.ts +2 -0
  119. package/dist/src/map/map.spec.d.ts.map +1 -0
  120. package/dist/src/math/math.d.ts +2 -4
  121. package/dist/src/math/math.d.ts.map +1 -1
  122. package/dist/src/migrate/migrate.d.ts +1 -1
  123. package/dist/src/migrate/migrate.d.ts.map +1 -1
  124. package/dist/src/notation/notation.d.ts +1 -1
  125. package/dist/src/notation/notation.d.ts.map +1 -1
  126. package/dist/src/optional.d.ts +0 -3
  127. package/dist/src/optional.d.ts.map +1 -1
  128. package/dist/src/record/index.d.ts +2 -0
  129. package/dist/src/record/index.d.ts.map +1 -0
  130. package/dist/src/record/record.d.ts +90 -0
  131. package/dist/src/record/record.d.ts.map +1 -0
  132. package/dist/src/record/record.spec.d.ts.map +1 -0
  133. package/dist/src/runtime/os.d.ts +1 -1
  134. package/dist/src/runtime/os.d.ts.map +1 -1
  135. package/dist/src/spatial/base.d.ts +1 -1
  136. package/dist/src/spatial/base.d.ts.map +1 -1
  137. package/dist/src/spatial/box/box.d.ts +1 -1
  138. package/dist/src/spatial/box/box.d.ts.map +1 -1
  139. package/dist/src/spatial/dimensions/dimensions.d.ts +1 -1
  140. package/dist/src/spatial/dimensions/dimensions.d.ts.map +1 -1
  141. package/dist/src/spatial/direction/direction.d.ts +3 -3
  142. package/dist/src/spatial/direction/direction.d.ts.map +1 -1
  143. package/dist/src/spatial/location/location.d.ts +1 -1
  144. package/dist/src/spatial/location/location.d.ts.map +1 -1
  145. package/dist/src/spatial/scale/scale.d.ts +1 -1
  146. package/dist/src/spatial/scale/scale.d.ts.map +1 -1
  147. package/dist/src/spatial/xy/xy.d.ts +1 -1
  148. package/dist/src/spatial/xy/xy.d.ts.map +1 -1
  149. package/dist/src/status/index.d.ts +1 -1
  150. package/dist/src/status/index.d.ts.map +1 -1
  151. package/dist/src/status/status.d.ts +42 -0
  152. package/dist/src/status/status.d.ts.map +1 -0
  153. package/dist/src/status/status.spec.d.ts +2 -0
  154. package/dist/src/status/status.spec.d.ts.map +1 -0
  155. package/dist/src/strings/strings.d.ts +16 -0
  156. package/dist/src/strings/strings.d.ts.map +1 -1
  157. package/dist/src/telem/gl.d.ts +1 -1
  158. package/dist/src/telem/gl.d.ts.map +1 -1
  159. package/dist/src/telem/series.d.ts +17 -16
  160. package/dist/src/telem/series.d.ts.map +1 -1
  161. package/dist/src/telem/telem.d.ts +42 -19
  162. package/dist/src/telem/telem.d.ts.map +1 -1
  163. package/dist/src/testutil/testutil.d.ts +1 -0
  164. package/dist/src/testutil/testutil.d.ts.map +1 -1
  165. package/dist/src/testutil/testutil.spec.d.ts +2 -0
  166. package/dist/src/testutil/testutil.spec.d.ts.map +1 -0
  167. package/dist/src/zod/external.d.ts +1 -0
  168. package/dist/src/zod/external.d.ts.map +1 -1
  169. package/dist/src/zod/nullToUndefined.d.ts +1 -1
  170. package/dist/src/zod/nullToUndefined.d.ts.map +1 -1
  171. package/dist/src/zod/toArray.d.ts +3 -0
  172. package/dist/src/zod/toArray.d.ts.map +1 -0
  173. package/dist/src/zod/toArray.spec.d.ts +2 -0
  174. package/dist/src/zod/toArray.spec.d.ts.map +1 -0
  175. package/dist/src/zod/util.d.ts +1 -1
  176. package/dist/src/zod/util.d.ts.map +1 -1
  177. package/dist/telem.cjs +1 -1
  178. package/dist/telem.js +10 -11
  179. package/dist/url.cjs +1 -1
  180. package/dist/url.js +16 -19
  181. package/dist/worker.cjs +1 -1
  182. package/dist/worker.js +18 -22
  183. package/dist/xy-B7065J2S.cjs +1 -0
  184. package/dist/{index-C-qYOegc.js → xy-D_LqxaGt.js} +62 -62
  185. package/dist/xy.cjs +1 -1
  186. package/dist/xy.js +1 -1
  187. package/dist/zod.cjs +1 -1
  188. package/dist/zod.js +2 -19
  189. package/package.json +13 -18
  190. package/src/binary/codec.spec.ts +1 -1
  191. package/src/binary/codec.ts +1 -1
  192. package/src/breaker/breaker.ts +1 -1
  193. package/src/caseconv/caseconv.ts +10 -12
  194. package/src/change/change.ts +1 -1
  195. package/src/color/color.ts +1 -1
  196. package/src/color/gradient.ts +1 -1
  197. package/src/color/palette.ts +1 -1
  198. package/src/compare/compare.ts +5 -5
  199. package/src/control/control.ts +2 -2
  200. package/src/deep/merge.spec.ts +2 -15
  201. package/src/deep/merge.ts +1 -1
  202. package/src/deep/path.spec.ts +41 -0
  203. package/src/deep/path.ts +48 -17
  204. package/src/destructor.ts +6 -2
  205. package/src/errors/errors.spec.ts +20 -20
  206. package/src/errors/errors.ts +4 -1
  207. package/src/flush.ts +21 -0
  208. package/src/id/id.spec.ts +1 -1
  209. package/src/id/id.ts +3 -1
  210. package/src/identity.ts +2 -2
  211. package/src/index.ts +3 -1
  212. package/src/instance/matcher.spec.ts +7 -7
  213. package/src/jsonrpc/jsonrpc.ts +1 -1
  214. package/src/kv/types.ts +1 -1
  215. package/src/map/index.ts +10 -0
  216. package/src/map/map.spec.ts +132 -0
  217. package/src/map/map.ts +17 -0
  218. package/src/math/math.ts +19 -27
  219. package/src/migrate/migrate.spec.ts +2 -2
  220. package/src/migrate/migrate.ts +2 -2
  221. package/src/notation/notation.ts +1 -1
  222. package/src/optional.ts +0 -4
  223. package/src/primitive/primitive.spec.ts +1 -1
  224. package/src/record/index.ts +10 -0
  225. package/src/record/record.spec.ts +319 -0
  226. package/src/record/record.ts +118 -0
  227. package/src/runtime/os.ts +1 -1
  228. package/src/spatial/base.ts +1 -1
  229. package/src/spatial/box/box.ts +1 -1
  230. package/src/spatial/dimensions/dimensions.ts +1 -1
  231. package/src/spatial/direction/direction.ts +1 -1
  232. package/src/spatial/location/location.ts +1 -1
  233. package/src/spatial/scale/scale.ts +1 -1
  234. package/src/spatial/xy/xy.ts +1 -1
  235. package/src/status/index.ts +1 -1
  236. package/src/status/status.spec.ts +25 -0
  237. package/src/status/status.ts +91 -0
  238. package/src/strings/strings.spec.ts +51 -13
  239. package/src/strings/strings.ts +20 -0
  240. package/src/telem/gl.ts +1 -1
  241. package/src/telem/series.spec.ts +193 -53
  242. package/src/telem/series.ts +53 -18
  243. package/src/telem/telem.spec.ts +202 -83
  244. package/src/telem/telem.ts +53 -35
  245. package/src/testutil/testutil.spec.ts +161 -0
  246. package/src/testutil/testutil.ts +12 -0
  247. package/src/zod/external.ts +1 -0
  248. package/src/zod/nullToUndefined.spec.ts +1 -1
  249. package/src/zod/nullToUndefined.ts +1 -1
  250. package/src/zod/toArray.spec.ts +182 -0
  251. package/src/{status/types.ts → zod/toArray.ts} +3 -12
  252. package/src/zod/util.spec.ts +2 -2
  253. package/src/zod/util.ts +3 -3
  254. package/tsconfig.tsbuildinfo +1 -1
  255. package/vite.config.ts +1 -2
  256. package/dist/base-B5lQIJKc.js +0 -38
  257. package/dist/base-CTq-lhpU.cjs +0 -1
  258. package/dist/index-B58dnYRu.cjs +0 -1
  259. package/dist/index-BMGaoK93.cjs +0 -1
  260. package/dist/index-BTet04Hd.cjs +0 -6
  261. package/dist/index-C07SBJhr.js +0 -128
  262. package/dist/index-C9EdKeu1.js +0 -174
  263. package/dist/index-CM8ZDZ6s.cjs +0 -1
  264. package/dist/index-CV2JaHfw.cjs +0 -1
  265. package/dist/index-CeBvOwG8.cjs +0 -3
  266. package/dist/index-ClrGyGDp.js +0 -205
  267. package/dist/index-CqQXXeCI.cjs +0 -1
  268. package/dist/index-DEdq2tza.cjs +0 -1
  269. package/dist/index-DKMnHBGR.cjs +0 -1
  270. package/dist/index-Dql5FMcH.js +0 -47
  271. package/dist/index-WwMnwoLy.cjs +0 -1
  272. package/dist/path-1tZLZ4AN.cjs +0 -1
  273. package/dist/path-DD6ytXzr.js +0 -76
  274. package/dist/schemas-55Usj0Fg.js +0 -3998
  275. package/dist/schemas-DbXuI2Qr.cjs +0 -27
  276. package/dist/search.cjs +0 -1
  277. package/dist/search.js +0 -14
  278. package/dist/src/record.d.ts +0 -18
  279. package/dist/src/record.d.ts.map +0 -1
  280. package/dist/src/record.spec.d.ts.map +0 -1
  281. package/dist/src/search.d.ts +0 -18
  282. package/dist/src/search.d.ts.map +0 -1
  283. package/dist/src/status/types.d.ts +0 -11
  284. package/dist/src/status/types.d.ts.map +0 -1
  285. package/src/record.spec.ts +0 -38
  286. package/src/record.ts +0 -45
  287. package/src/search.ts +0 -42
  288. /package/dist/src/{record.spec.d.ts → record/record.spec.d.ts} +0 -0
package/src/deep/path.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
10
  import { type Join } from "@/join";
11
- import { type UnknownRecord } from "@/record";
11
+ import { type record } from "@/record";
12
12
 
13
13
  type Prev = [
14
14
  never,
@@ -53,7 +53,7 @@ export type Key<T, D extends number = 5> = [D] extends [never]
53
53
  /** Options for the get function. */
54
54
  export interface GetOptions<O extends boolean | undefined = boolean | undefined> {
55
55
  optional: O;
56
- getter?: (obj: UnknownRecord, key: string) => unknown;
56
+ getter?: (obj: record.Unknown, key: string) => unknown;
57
57
  separator?: string;
58
58
  }
59
59
 
@@ -69,12 +69,12 @@ export interface GetOptions<O extends boolean | undefined = boolean | undefined>
69
69
  * @returns the value at the given path on the object.
70
70
  */
71
71
  export interface Get {
72
- <V = unknown, T = UnknownRecord>(
72
+ <V = record.Unknown, T = record.Unknown>(
73
73
  obj: T,
74
74
  path: string,
75
75
  options?: GetOptions<false>,
76
76
  ): V;
77
- <V = unknown, T = UnknownRecord>(
77
+ <V = record.Unknown, T = record.Unknown>(
78
78
  obj: T,
79
79
  path: string,
80
80
  options?: GetOptions<boolean | undefined>,
@@ -82,7 +82,7 @@ export interface Get {
82
82
  }
83
83
 
84
84
  /** A strongly typed version of the @link Get function. */
85
- export interface TypedGet<V = unknown, T = UnknownRecord> {
85
+ export interface TypedGet<V = record.Unknown, T = record.Unknown> {
86
86
  (obj: T, path: string, options?: GetOptions<false>): V;
87
87
  (obj: T, path: string, options?: GetOptions<boolean | undefined>): V | null;
88
88
  }
@@ -116,6 +116,16 @@ export const transformPath = (
116
116
  return result.join(separator);
117
117
  };
118
118
 
119
+ const defaultGetter = (obj: record.Unknown, key: string): unknown => {
120
+ if (!Array.isArray(obj)) return obj[key];
121
+ const res = obj[key];
122
+ if (res != null || obj.length == 0) return res;
123
+ const first = obj[0];
124
+ if (typeof first === "object" && "key" in first)
125
+ return obj.find((o) => o.key === key);
126
+ return undefined;
127
+ };
128
+
119
129
  /**
120
130
  * Gets the value at the given path on the object. If the path does not exist
121
131
  * and the optional flag is set to true, null will be returned. If the path does
@@ -127,23 +137,23 @@ export const transformPath = (
127
137
  * @param opts.getter a custom getter function to use on each part of the path.
128
138
  * @returns the value at the given path on the object.
129
139
  */
130
- export const get = (<V = unknown, T = UnknownRecord>(
140
+ export const get = (<V = record.Unknown, T = record.Unknown>(
131
141
  obj: T,
132
142
  path: string,
133
143
  opts: GetOptions = { optional: false, separator: "." },
134
144
  ): V | null => {
135
145
  opts.separator ??= ".";
136
- const { optional, getter = (obj, key) => obj[key] } = opts;
146
+ const { optional, getter = defaultGetter } = opts;
137
147
  const parts = path.split(opts.separator);
138
- if (parts.length === 1 && parts[0] === "") return obj as unknown as V;
139
- let result: UnknownRecord = obj as UnknownRecord;
148
+ if (parts.length === 1 && parts[0] === "") return obj as record.Unknown as V;
149
+ let result: record.Unknown = obj as record.Unknown;
140
150
  for (const part of parts) {
141
151
  const v = getter(result, part);
142
152
  if (v == null) {
143
153
  if (optional) return null;
144
154
  throw new Error(`Path ${path} does not exist. ${part} is null`);
145
155
  }
146
- result = v as UnknownRecord;
156
+ result = v as record.Unknown;
147
157
  }
148
158
  return result as V;
149
159
  }) as Get;
@@ -157,14 +167,32 @@ export const get = (<V = unknown, T = UnknownRecord>(
157
167
  */
158
168
  export const set = <V>(obj: V, path: string, value: unknown): void => {
159
169
  const parts = path.split(".");
160
- let result: UnknownRecord = obj as UnknownRecord;
170
+ let result: record.Unknown = obj as record.Unknown;
161
171
  for (let i = 0; i < parts.length - 1; i++) {
162
172
  const part = parts[i];
163
- result[part] ??= {};
164
- result = result[part] as UnknownRecord;
173
+ const v = defaultGetter(result, part);
174
+ if (v == null) throw new Error(`Path ${path} does not exist. ${part} is null`);
175
+ result = v as record.Unknown;
165
176
  }
166
177
  try {
167
- result[parts[parts.length - 1]] = value;
178
+ if (!Array.isArray(result)) {
179
+ result[parts[parts.length - 1]] = value;
180
+ return;
181
+ }
182
+ if (result.length === 0) return;
183
+ const index = parseInt(parts[parts.length - 1]);
184
+ if (isNaN(index)) {
185
+ const first = result[0];
186
+ if (typeof first === "object" && "key" in first) {
187
+ const objIndex = result.findIndex((o) => o.key === parts[parts.length - 1]);
188
+ if (objIndex !== -1) {
189
+ result[objIndex] = value;
190
+ return;
191
+ }
192
+ }
193
+ return;
194
+ }
195
+ result[index] = value;
168
196
  } catch (e) {
169
197
  console.error("failed to set value", value, "at path", path, "on object", obj);
170
198
  throw e;
@@ -179,11 +207,11 @@ export const set = <V>(obj: V, path: string, value: unknown): void => {
179
207
  */
180
208
  export const remove = <V>(obj: V, path: string): void => {
181
209
  const parts = path.split(".");
182
- let result: UnknownRecord = obj as UnknownRecord;
210
+ let result: record.Unknown = obj as record.Unknown;
183
211
  for (let i = 0; i < parts.length - 1; i++) {
184
212
  const part = parts[i];
185
213
  if (result[part] == null) return;
186
- result = result[part] as UnknownRecord;
214
+ result = result[part] as record.Unknown;
187
215
  }
188
216
  // if its an array, we need to splice it
189
217
  if (Array.isArray(result)) {
@@ -213,7 +241,10 @@ export const element = (path: string, index: number): string => {
213
241
  * @param path the path to check
214
242
  * @returns whether the path exists in the object
215
243
  */
216
- export const has = <V = unknown, T = UnknownRecord>(obj: T, path: string): boolean => {
244
+ export const has = <V = record.Unknown, T = record.Unknown>(
245
+ obj: T,
246
+ path: string,
247
+ ): boolean => {
217
248
  try {
218
249
  get<V, T>(obj, path);
219
250
  return true;
package/src/destructor.ts CHANGED
@@ -7,6 +7,10 @@
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 type Destructor = () => void;
10
+ export interface Destructor {
11
+ (): void;
12
+ }
11
13
 
12
- export type AsyncDestructor = () => Promise<void>;
14
+ export interface AsyncDestructor {
15
+ (): Promise<void>;
16
+ }
@@ -30,14 +30,14 @@ describe("errors", () => {
30
30
  it("should return true if the error implements the TypedError interface", () => {
31
31
  const error = new ErrorOne("test");
32
32
  const fError = errors.isTyped(error);
33
- expect(fError).toBeTruthy();
33
+ expect(fError).toBe(true);
34
34
  expect(error.type).toEqual("one");
35
35
  });
36
36
 
37
37
  it("should return false if the error does not implement the TypedError interface", () => {
38
38
  const error = new Error("rando");
39
39
  const fError = errors.isTyped(error);
40
- expect(fError).toBeFalsy();
40
+ expect(fError).toBe(false);
41
41
  });
42
42
  });
43
43
 
@@ -50,7 +50,7 @@ describe("errors", () => {
50
50
  const error = new ErrorOne("test");
51
51
  const encoded = errors.encode(error);
52
52
  const decoded = errors.decode(encoded);
53
- expect(ErrorOne.matches(decoded)).toBeTruthy();
53
+ expect(ErrorOne.matches(decoded)).toBe(true);
54
54
  });
55
55
 
56
56
  test("should correctly encode/decode a null error", () => {
@@ -85,7 +85,7 @@ describe("errors", () => {
85
85
  expect(encoded.type).toEqual(errors.UNKNOWN);
86
86
  expect(encoded.data).toEqual("test");
87
87
  const decoded = errors.decode(encoded);
88
- expect(errors.Unknown.matches(decoded)).toBeTruthy();
88
+ expect(errors.Unknown.matches(decoded)).toBe(true);
89
89
  });
90
90
 
91
91
  it("should correctly encode/decode a random object", () => {
@@ -94,59 +94,59 @@ describe("errors", () => {
94
94
  expect(encoded.type).toEqual(errors.UNKNOWN);
95
95
  expect(encoded.data).toEqual(JSON.stringify(error));
96
96
  const decoded = errors.decode(encoded);
97
- expect(errors.Unknown.matches(decoded)).toBeTruthy();
97
+ expect(errors.Unknown.matches(decoded)).toBe(true);
98
98
  });
99
99
  });
100
100
 
101
101
  describe("matches", () => {
102
102
  it("should return true if the errors are exactly the same", () => {
103
103
  const v = new ErrorOne("test");
104
- expect(ErrorOne.matches(v)).toBeTruthy();
104
+ expect(ErrorOne.matches(v)).toBe(true);
105
105
  const v2 = new ErrorOne("test");
106
- expect(v2.matches(v)).toBeTruthy();
106
+ expect(v2.matches(v)).toBe(true);
107
107
  });
108
108
 
109
109
  it("should return false if the errors are typed and clearly different", () => {
110
110
  const e1 = new ErrorOne("test");
111
111
  const e2 = new ErrorTwo("test");
112
- expect(e1.matches(e2)).toBeFalsy();
113
- expect(ErrorOne.matches(e2)).toBeFalsy();
114
- expect(ErrorTwo.matches(e1)).toBeFalsy();
112
+ expect(e1.matches(e2)).toBe(false);
113
+ expect(ErrorOne.matches(e2)).toBe(false);
114
+ expect(ErrorTwo.matches(e1)).toBe(false);
115
115
  });
116
116
 
117
117
  it("should return false if the error is not typed", () => {
118
118
  const e1 = new ErrorOne("test");
119
119
  const e2 = new Error("rando");
120
- expect(e1.matches(e2)).toBeFalsy();
121
- expect(ErrorOne.matches(e2)).toBeFalsy();
120
+ expect(e1.matches(e2)).toBe(false);
121
+ expect(ErrorOne.matches(e2)).toBe(false);
122
122
  });
123
123
 
124
124
  it("should return false if the error is not actually an error", () => {
125
125
  const e1 = new ErrorOne("test");
126
126
  const e2 = "rando";
127
- expect(e1.matches(e2)).toBeFalsy();
128
- expect(ErrorOne.matches(e2)).toBeFalsy();
127
+ expect(e1.matches(e2)).toBe(false);
128
+ expect(ErrorOne.matches(e2)).toBe(false);
129
129
  });
130
130
 
131
131
  it("should return false if hte error is undefined", () => {
132
132
  const e1 = new ErrorOne("test");
133
133
  const e2 = undefined;
134
- expect(e1.matches(e2)).toBeFalsy();
135
- expect(ErrorOne.matches(e2)).toBeFalsy();
134
+ expect(e1.matches(e2)).toBe(false);
135
+ expect(ErrorOne.matches(e2)).toBe(false);
136
136
  });
137
137
 
138
138
  it("should return true if the the matching error is a parent", () => {
139
139
  const e1 = new ErrorOne("rando");
140
140
  const e2 = new SubError("rando");
141
- expect(e1.matches(e2)).toBeTruthy();
142
- expect(ErrorOne.matches(e1)).toBeTruthy();
141
+ expect(e1.matches(e2)).toBe(true);
142
+ expect(ErrorOne.matches(e1)).toBe(true);
143
143
  });
144
144
 
145
145
  it("should return false if the matching error is a sub-error", () => {
146
146
  const e1 = new ErrorOne("random");
147
147
  const e2 = new SubError("random");
148
- expect(e2.matches(e1)).toBeFalsy();
149
- expect(SubError.matches(e1)).toBeFalsy();
148
+ expect(e2.matches(e1)).toBe(false);
149
+ expect(SubError.matches(e1)).toBe(false);
150
150
  });
151
151
  });
152
152
  });
@@ -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/v4";
10
+ import { z } from "zod";
11
11
 
12
12
  import { singleton } from "@/singleton";
13
13
 
@@ -260,3 +260,6 @@ export interface NativePayload {
260
260
  /** The stack trace of the error */
261
261
  stack?: string;
262
262
  }
263
+
264
+ /** Error for representing a method that is not implemented */
265
+ export class NotImplemented extends createTyped("not_implemented") {}
package/src/flush.ts ADDED
@@ -0,0 +1,21 @@
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
+ * Flushes the microtask queue.
12
+ * @returns A promise that resolves when the microtask queue is flushed.
13
+ */
14
+ export const flushMicrotasks = (): Promise<void> => Promise.resolve();
15
+
16
+ /**
17
+ * Flushes the task queue.
18
+ * @returns A promise that resolves when the task queue is flushed.
19
+ */
20
+ export const flushTaskQueue = (): Promise<void> =>
21
+ new Promise((resolve) => setTimeout(resolve, 0));
package/src/id/id.spec.ts CHANGED
@@ -20,7 +20,7 @@ describe("id", () => {
20
20
 
21
21
  it("should create a string of length 11", () => {
22
22
  const newID = id.create();
23
- expect(newID.length).toBe(11);
23
+ expect(newID.length).toBe(id.LENGTH);
24
24
  });
25
25
 
26
26
  it("should only contain alphanumeric characters", () => {
package/src/id/id.ts CHANGED
@@ -11,7 +11,9 @@ import { customAlphabet } from "nanoid/non-secure";
11
11
 
12
12
  const ALPHANUMERIC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
13
13
 
14
- const createInternal = customAlphabet(ALPHANUMERIC, 11);
14
+ export const LENGTH = 11;
15
+
16
+ const createInternal = customAlphabet(ALPHANUMERIC, LENGTH);
15
17
 
16
18
  /**
17
19
  * Creates a unique alphanumeric string of length 11.
package/src/identity.ts CHANGED
@@ -7,8 +7,8 @@
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 UnknownRecord } from "@/record";
10
+ import { type record } from "@/record";
11
11
 
12
- export const isObject = <T extends UnknownRecord = UnknownRecord>(
12
+ export const isObject = <T extends record.Unknown = record.Unknown>(
13
13
  item?: unknown,
14
14
  ): item is T => item != null && typeof item === "object" && !Array.isArray(item);
package/src/index.ts CHANGED
@@ -20,6 +20,7 @@ export * from "@/debounce/debounce";
20
20
  export * from "@/deep";
21
21
  export * from "@/destructor";
22
22
  export * from "@/errors";
23
+ export * from "@/flush";
23
24
  export * from "@/id";
24
25
  export * from "@/identity";
25
26
  export * from "@/instance";
@@ -27,6 +28,7 @@ export * from "@/invert";
27
28
  export * from "@/jsonrpc";
28
29
  export * from "@/kv";
29
30
  export * from "@/link";
31
+ export * from "@/map";
30
32
  export * from "@/math";
31
33
  export * from "@/migrate";
32
34
  export * from "@/notation";
@@ -38,7 +40,6 @@ export * from "@/renderable";
38
40
  export * from "@/replace";
39
41
  export * from "@/runtime";
40
42
  export * from "@/runtime";
41
- export * from "@/search";
42
43
  export * from "@/shallowCopy";
43
44
  export * from "@/sleep";
44
45
  export * from "@/spatial";
@@ -46,6 +47,7 @@ export * from "@/status";
46
47
  export * from "@/strings";
47
48
  export * from "@/sync";
48
49
  export * from "@/telem";
50
+ export * from "@/testutil";
49
51
  export * from "@/transform";
50
52
  export * from "@/unique";
51
53
  export * from "@/url";
@@ -9,15 +9,15 @@
9
9
 
10
10
  import { describe, expect, it } from "vitest";
11
11
 
12
- import { createMatcher, type Discriminated } from "./matcher";
12
+ import { instance } from "@/instance";
13
13
 
14
14
  describe("createMatcher", () => {
15
- class TestClass implements Discriminated {
15
+ class TestClass implements instance.Discriminated {
16
16
  discriminator = "test";
17
17
  constructor(public value: string) {}
18
18
  }
19
19
 
20
- const isTestClass = createMatcher("test", TestClass);
20
+ const isTestClass = instance.createMatcher("test", TestClass);
21
21
 
22
22
  it("should return true for instances of the class", () => {
23
23
  const instance = new TestClass("value");
@@ -54,18 +54,18 @@ describe("createMatcher", () => {
54
54
  });
55
55
 
56
56
  it("should work with multiple class instances", () => {
57
- class ClassA implements Discriminated {
57
+ class ClassA implements instance.Discriminated {
58
58
  discriminator = "a";
59
59
  constructor(public value: string) {}
60
60
  }
61
61
 
62
- class ClassB implements Discriminated {
62
+ class ClassB implements instance.Discriminated {
63
63
  discriminator = "b";
64
64
  constructor(public value: string) {}
65
65
  }
66
66
 
67
- const isClassA = createMatcher("a", ClassA);
68
- const isClassB = createMatcher("b", ClassB);
67
+ const isClassA = instance.createMatcher("a", ClassA);
68
+ const isClassB = instance.createMatcher("b", ClassB);
69
69
 
70
70
  const instanceA = new ClassA("value");
71
71
  const instanceB = new ClassB("value");
@@ -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/v4";
10
+ import z from "zod";
11
11
 
12
12
  import { binary } from "@/binary";
13
13
 
package/src/kv/types.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/v4";
10
+ import { z } from "zod";
11
11
 
12
12
  export interface Reader<V = unknown> {
13
13
  /** @returns the value for a given key, or null if the key is not present. */
@@ -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 map from "@/map/map";
@@ -0,0 +1,132 @@
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 { map } from "@/map";
13
+
14
+ describe("map", () => {
15
+ describe("getOrSetDefault", () => {
16
+ it("should return existing value when key exists", () => {
17
+ const testMap = new Map<string, number>();
18
+ testMap.set("existing", 42);
19
+
20
+ const result = map.getOrSetDefault(testMap, "existing", 100);
21
+
22
+ expect(result).toEqual(42);
23
+ expect(testMap.get("existing")).toEqual(42);
24
+ expect(testMap.size).toEqual(1);
25
+ });
26
+
27
+ it("should set and return default value when key doesn't exist", () => {
28
+ const testMap = new Map<string, number>();
29
+
30
+ const result = map.getOrSetDefault(testMap, "new", 100);
31
+
32
+ expect(result).toEqual(100);
33
+ expect(testMap.get("new")).toEqual(100);
34
+ expect(testMap.size).toEqual(1);
35
+ });
36
+
37
+ it("should replace the value when key exists with undefined value", () => {
38
+ const testMap = new Map<string, number | undefined>();
39
+ testMap.set("undefined", undefined);
40
+
41
+ const result = map.getOrSetDefault(testMap, "undefined", 100);
42
+
43
+ expect(result).toEqual(100);
44
+ expect(testMap.get("undefined")).toEqual(100);
45
+ expect(testMap.size).toEqual(1);
46
+ });
47
+
48
+ it("should return null when key exists with null value", () => {
49
+ const testMap = new Map<string, number | null>();
50
+ testMap.set("null", null);
51
+
52
+ const result = map.getOrSetDefault(testMap, "null", 100);
53
+
54
+ expect(result).toBeNull();
55
+ expect(testMap.get("null")).toBeNull();
56
+ expect(testMap.size).toEqual(1);
57
+ });
58
+
59
+ it("should work with different key types", () => {
60
+ const numberMap = new Map<number, string>();
61
+ const result1 = map.getOrSetDefault(numberMap, 1, "default");
62
+ expect(result1).toEqual("default");
63
+ expect(numberMap.get(1)).toEqual("default");
64
+ const objKey = { id: 1 };
65
+ const objectMap = new Map<object, string>();
66
+ const result2 = map.getOrSetDefault(objectMap, objKey, "object-default");
67
+ expect(result2).toEqual("object-default");
68
+ expect(objectMap.get(objKey)).toEqual("object-default");
69
+ });
70
+
71
+ it("should work with different value types", () => {
72
+ const stringMap = new Map<string, string>();
73
+ const result1 = map.getOrSetDefault(stringMap, "key", "default");
74
+ expect(result1).toEqual("default");
75
+ const boolMap = new Map<string, boolean>();
76
+ const result2 = map.getOrSetDefault(boolMap, "key", true);
77
+ expect(result2).toEqual(true);
78
+ const objValue = { name: "test" };
79
+ const objMap = new Map<string, object>();
80
+ const result3 = map.getOrSetDefault(objMap, "key", objValue);
81
+ expect(result3).toEqual(objValue);
82
+ expect(result3).toBe(objValue);
83
+ });
84
+
85
+ it("should handle empty maps", () => {
86
+ const emptyMap = new Map<string, number>();
87
+
88
+ const result = map.getOrSetDefault(emptyMap, "first", 42);
89
+
90
+ expect(result).toEqual(42);
91
+ expect(emptyMap.get("first")).toEqual(42);
92
+ expect(emptyMap.size).toEqual(1);
93
+ });
94
+
95
+ it("should handle multiple operations on same map", () => {
96
+ const testMap = new Map<string, number>();
97
+ const result1 = map.getOrSetDefault(testMap, "key1", 10);
98
+ expect(result1).toEqual(10);
99
+ expect(testMap.size).toEqual(1);
100
+ const result2 = map.getOrSetDefault(testMap, "key1", 20);
101
+ expect(result2).toEqual(10); // Original value, not new default
102
+ expect(testMap.size).toEqual(1);
103
+ const result3 = map.getOrSetDefault(testMap, "key2", 30);
104
+ expect(result3).toEqual(30);
105
+ expect(testMap.size).toEqual(2);
106
+ });
107
+
108
+ it("should handle falsy values correctly", () => {
109
+ const testMap = new Map<string, number | string | boolean>();
110
+ testMap.set("zero", 0);
111
+ const result1 = map.getOrSetDefault(testMap, "zero", 100);
112
+ expect(result1).toEqual(0);
113
+ testMap.set("empty", "");
114
+ const result2 = map.getOrSetDefault(testMap, "empty", "default");
115
+ expect(result2).toEqual("");
116
+ testMap.set("false", false);
117
+ const result3 = map.getOrSetDefault(testMap, "false", true);
118
+ expect(result3).toEqual(false);
119
+ });
120
+
121
+ it("should handle arrays and complex objects", () => {
122
+ const testMap = new Map<string, number[]>();
123
+ const defaultArray = [1, 2, 3];
124
+
125
+ const result = map.getOrSetDefault(testMap, "array", defaultArray);
126
+
127
+ expect(result).toEqual([1, 2, 3]);
128
+ expect(result).toBe(defaultArray); // Same reference
129
+ expect(testMap.get("array")).toBe(defaultArray);
130
+ });
131
+ });
132
+ });
package/src/map/map.ts ADDED
@@ -0,0 +1,17 @@
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 getOrSetDefault = <K, V>(map: Map<K, V>, key: K, defaultValue: V): V => {
11
+ const value = map.get(key);
12
+ if (value === undefined) {
13
+ map.set(key, defaultValue);
14
+ return defaultValue;
15
+ }
16
+ return value;
17
+ };