@tolki/types 1.1.3 → 1.1.5

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/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ <p align="center"><img src="https://raw.githubusercontent.com/abetwothree/tolki/refs/heads/master/docs/vitepress/public/tolki-logo-short.svg" width="50%" alt="Laravel Tolki JS Logo"></p>
2
+
1
3
  # Tolki JS Types Package
2
4
 
3
5
  Utility TypeScript types for @tolki packages and Laravel HTTP responses.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolki/types",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "Utility TypeScript types for @tolki packages and Laravel HTTP responses.",
5
5
  "author": "Abraham Arango <https://github.com/abetwothree>",
6
6
  "license": "MIT",
package/src/arrays.d.ts CHANGED
@@ -11,7 +11,58 @@ export interface ArrayAccess<TValue> {
11
11
 
12
12
  export type ArrayInnerValue<X> = X extends ReadonlyArray<infer U> ? U : never;
13
13
 
14
- export type ArrayItems<T> = T[] | Array<T>;
14
+ /**
15
+ * Recursively extracts the deepest non-array value type.
16
+ * Useful for inferring the leaf value type after fully flattening nested arrays.
17
+ *
18
+ * @example
19
+ * FlatArrayValue<number> // number
20
+ * FlatArrayValue<number[]> // number
21
+ * FlatArrayValue<number[][]> // number
22
+ * FlatArrayValue<string | number[]> // string | number
23
+ */
24
+ export type FlatArrayValue<T> = T extends readonly (infer U)[]
25
+ ? FlatArrayValue<U>
26
+ : T;
27
+
28
+ export type ArrayItems<T> = readonly T[];
29
+
30
+ /**
31
+ * Represents a value that may be nested within arrays to any depth.
32
+ * Used by functions like `undot` that produce nested array structures
33
+ * from flat dot-notated keys.
34
+ *
35
+ * @example
36
+ * UndotValue<string> // string | UndotValue<string>[]
37
+ * UndotValue<number> // number | UndotValue<number>[]
38
+ */
39
+ export type UndotValue<T> = T | UndotValue<T>[];
40
+
41
+ /**
42
+ * Checks if a string type contains a dot (.) separator.
43
+ */
44
+ type ContainsDot<S> = S extends `${string}.${string}` ? true : false;
45
+
46
+ /**
47
+ * Determines the return type for array undot operations.
48
+ *
49
+ * - When keys are generic strings (could contain dots): returns `UndotValue<TValue>[]`
50
+ * - When keys are literal strings with dots: returns `UndotValue<TValue>[]`
51
+ * - When keys are literal strings without dots: returns `TValue[]`
52
+ *
53
+ * @example
54
+ * UndotResult<"0" | "1", string> // string[]
55
+ * UndotResult<"0" | "1.0", string> // UndotValue<string>[]
56
+ * UndotResult<string, number> // UndotValue<number>[]
57
+ */
58
+ export type UndotResult<
59
+ TKey extends PropertyKey,
60
+ TValue,
61
+ > = string extends TKey & string
62
+ ? UndotValue<TValue>[]
63
+ : [true] extends [ContainsDot<TKey & string>]
64
+ ? UndotValue<TValue>[]
65
+ : TValue[];
15
66
 
16
67
  /**
17
68
  * Helper type to check if an array is mutable (not readonly)
package/src/enums.d.ts CHANGED
@@ -1,30 +1,34 @@
1
1
  /**
2
2
  * Extract the case key names from the _cases tuple.
3
+ * Returns `never` when `_cases` is not declared on the concrete type.
3
4
  */
4
- export type CaseKeys<TEnum extends EnumConst> = NonNullable<
5
- TEnum["_cases"]
6
- >[number];
5
+ export type CaseKeys<TEnum extends EnumConst> = "_cases" extends keyof TEnum
6
+ ? NonNullable<TEnum["_cases"]>[number]
7
+ : never;
7
8
 
8
9
  /**
9
10
  * Extracts the instance method key names from the `_methods` tuple.
11
+ * Returns `never` when `_methods` is not declared on the concrete type.
10
12
  */
11
- export type MethodKeys<TEnum extends EnumConst> = NonNullable<
12
- TEnum["_methods"]
13
- >[number];
13
+ export type MethodKeys<TEnum extends EnumConst> = "_methods" extends keyof TEnum
14
+ ? NonNullable<TEnum["_methods"]>[number]
15
+ : never;
14
16
 
15
17
  /**
16
18
  * Extracts the static helper key names from the `_static` tuple.
19
+ * Returns `never` when `_static` is not declared on the concrete type.
17
20
  */
18
- export type StaticKeys<TEnum extends EnumConst> = NonNullable<
19
- TEnum["_static"]
20
- >[number];
21
+ export type StaticKeys<TEnum extends EnumConst> = "_static" extends keyof TEnum
22
+ ? NonNullable<TEnum["_static"]>[number]
23
+ : never;
21
24
 
22
25
  /**
23
26
  * Extracts the helper key names from the `_helpers` tuple.
27
+ * Returns `never` when `_helpers` is not declared on the concrete type.
24
28
  */
25
- export type HelperKeys<TEnum extends EnumConst> = NonNullable<
26
- TEnum["_helpers"]
27
- >[number];
29
+ export type HelperKeys<TEnum extends EnumConst> = "_helpers" extends keyof TEnum
30
+ ? NonNullable<TEnum["_helpers"]>[number]
31
+ : never;
28
32
 
29
33
  /**
30
34
  * Constraint for all generated enum const objects.
@@ -38,6 +42,7 @@ export type HelperKeys<TEnum extends EnumConst> = NonNullable<
38
42
  */
39
43
  export type EnumConst = {
40
44
  readonly _cases?: readonly string[];
45
+ readonly _helpers?: readonly string[];
41
46
  readonly _methods?: readonly string[];
42
47
  readonly _static?: readonly string[];
43
48
  readonly [key: string]: unknown;