zcb 0.3.2 → 0.3.3

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zcb",
3
3
  "description": "Build configs with type safety from zod schema.",
4
- "version": "0.3.2",
4
+ "version": "0.3.3",
5
5
  "author": "miami-man",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/badbatch/zod-config-builder",
@@ -56,6 +56,7 @@ describe('createConfigReader', () => {
56
56
  it('should throw the expected error', () => {
57
57
  const reader = createReader();
58
58
 
59
+ // @ts-expect-error Required to test error
59
60
  expect(() => reader.read('pages.contactDetails.sections')).toThrow(
60
61
  'Path resolved to an object or an array of objects, but `read` can only resolve to a primitive value or an array of primitives. Use the `scope` method instead',
61
62
  );
package/src/types.ts CHANGED
@@ -55,16 +55,11 @@ export type Primitive = string | number | boolean | bigint | symbol | null | und
55
55
 
56
56
  export type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...0[]];
57
57
 
58
- export type Leaves<T, LeafPath extends string[] = [], Depth extends number = 10> = Depth extends never
59
- ? never
60
- : T extends Primitive
61
- ? LeafPath
62
- : // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
- T extends readonly any[]
64
- ? LeafPath
65
- : {
66
- [K in keyof T & string]: Leaves<T[K], [...LeafPath, K], Prev[Depth]>;
67
- }[keyof T & string];
58
+ export type IsArrayOfPrimitives<T> = T extends readonly (infer U)[]
59
+ ? Exclude<U, Primitive> extends never
60
+ ? true
61
+ : false
62
+ : false;
68
63
 
69
64
  export type OwnKeys<T> = Exclude<
70
65
  {
@@ -74,6 +69,16 @@ export type OwnKeys<T> = Exclude<
74
69
  `${string}[Symbol.${string}`
75
70
  >;
76
71
 
72
+ export type Leaves<T, LeafPath extends string[] = [], Depth extends number = 10> = Depth extends never
73
+ ? never
74
+ : T extends Primitive
75
+ ? LeafPath
76
+ : IsArrayOfPrimitives<T> extends true
77
+ ? LeafPath
78
+ : {
79
+ [K in OwnKeys<T>]: Leaves<T[K], [...LeafPath, K], Prev[Depth]>;
80
+ }[OwnKeys<T>];
81
+
77
82
  export type Paths<T, ScopePath extends string[] = [], Depth extends number = 10> = Depth extends never
78
83
  ? never
79
84
  : T extends Primitive