fast-tree-builder 2.0.0-beta.6 → 2.0.1

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 (3) hide show
  1. package/index.d.cts +8 -10
  2. package/index.d.mts +8 -10
  3. package/package.json +1 -1
package/index.d.cts CHANGED
@@ -8,10 +8,10 @@ type TreeNode<TValue, TValueKey extends PropertyKey | false, TParentKey extends
8
8
  [k in Exclude<TDepthKey, false>]: number;
9
9
  });
10
10
  type AccessorReturnType<O, P extends (keyof O) | ((item: O) => any)> = P extends ((item: O) => infer R) ? R : P extends (keyof O) ? O[P] : never;
11
- type ObjectKeysOfIterableProperties<T> = {
11
+ type ObjectKeysOfIterableProperties<T> = 0 extends (1 & T) ? PropertyKey : {
12
12
  [K in keyof T]: T[K] extends (Iterable<unknown> & object) | null | undefined ? K : never;
13
13
  }[keyof T];
14
- declare function buildTree<TIdAccessor extends (keyof NoInfer<TInputValue>) | ((item: NoInfer<TInputValue>) => unknown), TValueKey extends PropertyKey | false = 'value', TParentKey extends PropertyKey | false = 'parent', TChildrenKey extends PropertyKey = 'children', TDepthKey extends PropertyKey | false = false, TInputValue extends (TValueKey extends false ? object : TIdAccessor extends PropertyKey ? object : unknown) = any, TResolvedValue extends (TValueKey extends false ? object : unknown) = TInputValue>(items: Iterable<TInputValue>, options: {
14
+ declare function buildTree<TIdAccessor extends NoInfer<keyof TInputValue> | ((item: NoInfer<TInputValue>) => unknown), TValueKey extends PropertyKey | false = 'value', TParentKey extends PropertyKey | false = 'parent', TChildrenKey extends PropertyKey = 'children', TDepthKey extends PropertyKey | false = false, TInputValue extends (TValueKey extends false ? object : TIdAccessor extends PropertyKey ? object : unknown) = any, TResolvedValue extends (TValueKey extends false ? object : unknown) = TInputValue>(items: Iterable<TInputValue>, options: {
15
15
  /**
16
16
  * A string key or function used to get the item's unique identifier.
17
17
  */
@@ -69,13 +69,11 @@ declare function buildTree<TIdAccessor extends (keyof NoInfer<TInputValue>) | ((
69
69
  */
70
70
  validateTree?: boolean;
71
71
  /**
72
- * Validates referential integrity of the input.
72
+ * When true, verifies all parentId or childIds resolve to real items.
73
+ * Only `null` and `undefined` are acceptable as parent id for root nodes in parentId mode.
74
+ * Every item in the children list must resolve to a real item in childIds mode.
73
75
  *
74
- * In strict mode:
75
- * - All parent and child references must point to existing items in the input.
76
- * - Root items must have their `parentId` unset, `null`, or `undefined`.
77
- *
78
- * Any invalid or missing references will result in an error during tree construction.
76
+ * Errors are thrown on invalid references.
79
77
  *
80
78
  * Defaults to `false`.
81
79
  */
@@ -92,14 +90,14 @@ declare function buildTree<TIdAccessor extends (keyof NoInfer<TInputValue>) | ((
92
90
  *
93
91
  * Either `parentId` or `childIds` must be provided.
94
92
  */
95
- childIds: ObjectKeysOfIterableProperties<NoInfer<TInputValue>> | ((item: NoInfer<TInputValue>) => (Iterable<unknown> & object) | null | undefined);
93
+ childIds: NoInfer<ObjectKeysOfIterableProperties<TInputValue>> | ((item: NoInfer<TInputValue>) => (Iterable<unknown> & object) | null | undefined);
96
94
  } | {
97
95
  /**
98
96
  * A string key or function used to get the item's parent identifier.
99
97
  *
100
98
  * Either `parentId` or `childIds` must be provided.
101
99
  */
102
- parentId: (keyof NoInfer<TInputValue>) | ((item: NoInfer<TInputValue>) => unknown);
100
+ parentId: NoInfer<keyof TInputValue> | ((item: NoInfer<TInputValue>) => unknown);
103
101
  /**
104
102
  * A string key or function to retrieve a list of child identifiers from an item.
105
103
  *
package/index.d.mts CHANGED
@@ -8,10 +8,10 @@ type TreeNode<TValue, TValueKey extends PropertyKey | false, TParentKey extends
8
8
  [k in Exclude<TDepthKey, false>]: number;
9
9
  });
10
10
  type AccessorReturnType<O, P extends (keyof O) | ((item: O) => any)> = P extends ((item: O) => infer R) ? R : P extends (keyof O) ? O[P] : never;
11
- type ObjectKeysOfIterableProperties<T> = {
11
+ type ObjectKeysOfIterableProperties<T> = 0 extends (1 & T) ? PropertyKey : {
12
12
  [K in keyof T]: T[K] extends (Iterable<unknown> & object) | null | undefined ? K : never;
13
13
  }[keyof T];
14
- export default function buildTree<TIdAccessor extends (keyof NoInfer<TInputValue>) | ((item: NoInfer<TInputValue>) => unknown), TValueKey extends PropertyKey | false = 'value', TParentKey extends PropertyKey | false = 'parent', TChildrenKey extends PropertyKey = 'children', TDepthKey extends PropertyKey | false = false, TInputValue extends (TValueKey extends false ? object : TIdAccessor extends PropertyKey ? object : unknown) = any, TResolvedValue extends (TValueKey extends false ? object : unknown) = TInputValue>(items: Iterable<TInputValue>, options: {
14
+ export default function buildTree<TIdAccessor extends NoInfer<keyof TInputValue> | ((item: NoInfer<TInputValue>) => unknown), TValueKey extends PropertyKey | false = 'value', TParentKey extends PropertyKey | false = 'parent', TChildrenKey extends PropertyKey = 'children', TDepthKey extends PropertyKey | false = false, TInputValue extends (TValueKey extends false ? object : TIdAccessor extends PropertyKey ? object : unknown) = any, TResolvedValue extends (TValueKey extends false ? object : unknown) = TInputValue>(items: Iterable<TInputValue>, options: {
15
15
  /**
16
16
  * A string key or function used to get the item's unique identifier.
17
17
  */
@@ -69,13 +69,11 @@ export default function buildTree<TIdAccessor extends (keyof NoInfer<TInputValue
69
69
  */
70
70
  validateTree?: boolean;
71
71
  /**
72
- * Validates referential integrity of the input.
72
+ * When true, verifies all parentId or childIds resolve to real items.
73
+ * Only `null` and `undefined` are acceptable as parent id for root nodes in parentId mode.
74
+ * Every item in the children list must resolve to a real item in childIds mode.
73
75
  *
74
- * In strict mode:
75
- * - All parent and child references must point to existing items in the input.
76
- * - Root items must have their `parentId` unset, `null`, or `undefined`.
77
- *
78
- * Any invalid or missing references will result in an error during tree construction.
76
+ * Errors are thrown on invalid references.
79
77
  *
80
78
  * Defaults to `false`.
81
79
  */
@@ -92,14 +90,14 @@ export default function buildTree<TIdAccessor extends (keyof NoInfer<TInputValue
92
90
  *
93
91
  * Either `parentId` or `childIds` must be provided.
94
92
  */
95
- childIds: ObjectKeysOfIterableProperties<NoInfer<TInputValue>> | ((item: NoInfer<TInputValue>) => (Iterable<unknown> & object) | null | undefined);
93
+ childIds: NoInfer<ObjectKeysOfIterableProperties<TInputValue>> | ((item: NoInfer<TInputValue>) => (Iterable<unknown> & object) | null | undefined);
96
94
  } | {
97
95
  /**
98
96
  * A string key or function used to get the item's parent identifier.
99
97
  *
100
98
  * Either `parentId` or `childIds` must be provided.
101
99
  */
102
- parentId: (keyof NoInfer<TInputValue>) | ((item: NoInfer<TInputValue>) => unknown);
100
+ parentId: NoInfer<keyof TInputValue> | ((item: NoInfer<TInputValue>) => unknown);
103
101
  /**
104
102
  * A string key or function to retrieve a list of child identifiers from an item.
105
103
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-tree-builder",
3
- "version": "2.0.0-beta.6",
3
+ "version": "2.0.1",
4
4
  "description": "Easily construct highly customizable bi-directional tree structures from iterable data.",
5
5
  "types": "./index.d.mts",
6
6
  "module": "./index.mjs",