@augment-vir/common 29.1.8 → 29.1.10

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.
@@ -24,6 +24,9 @@ function selectFrom(originalObject, selectionSet) {
24
24
  keysToRemove.push(key);
25
25
  return undefined;
26
26
  }
27
+ else if (shouldPreserve(value)) {
28
+ return value;
29
+ }
27
30
  else {
28
31
  return selectFrom(value, selection);
29
32
  }
@@ -20,6 +20,9 @@ export function selectFrom(originalObject, selectionSet) {
20
20
  keysToRemove.push(key);
21
21
  return undefined;
22
22
  }
23
+ else if (shouldPreserve(value)) {
24
+ return value;
25
+ }
23
26
  else {
24
27
  return selectFrom(value, selection);
25
28
  }
@@ -1,4 +1,4 @@
1
- import { Writable } from 'type-fest';
1
+ import { RequireAtLeastOne, Writable } from 'type-fest';
2
2
  export type PartialAndNullable<T extends object> = {
3
3
  [Prop in keyof T]?: T[Prop] | null | undefined;
4
4
  };
@@ -17,3 +17,5 @@ export type ExcludeKeysWithMatchingValues<OriginalObject extends object, Matcher
17
17
  [Prop in keyof OriginalObject as OriginalObject[Prop] extends Matcher ? never : Prop]: Prop;
18
18
  };
19
19
  export type RemovePartial<Input> = Input extends Partial<Record<infer K extends PropertyKey, infer V>> ? Required<Record<K, V>> : Required<Input>;
20
+ /** Excludes empty objects from a union. */
21
+ export type ExcludeEmpty<T> = T extends RequireAtLeastOne<T> ? T : never;
@@ -3,7 +3,7 @@ import { TsRecurse, TsRecursionStart, TsRecursionTracker, TsTooMuchRecursion } f
3
3
  import { UnionToIntersection } from '../union';
4
4
  import { AnyObject } from './any-object';
5
5
  import { KeyCount } from './key-count';
6
- import { PropertyValueType } from './object';
6
+ import { ExcludeEmpty, PropertyValueType } from './object';
7
7
  /** All types that won't be recursed into when defining a {@link SelectionSet}. */
8
8
  export type SelectionTypesToPreserve = Primitive | RegExp | Promise<any>;
9
9
  /** A generic selection set without specific keys. */
@@ -18,10 +18,10 @@ export type PickSelection<Full extends Readonly<AnyObject>, Selection extends Ge
18
18
  * Collapses a selected value to the first part of the selection that contains more than 1 key or
19
19
  * that is not an object.
20
20
  */
21
- export type PickCollapsedSelection<Full extends Readonly<AnyObject>, Selection extends GenericSelectionSet, Depth extends TsRecursionTracker = TsRecursionStart> = Depth extends TsTooMuchRecursion ? 'Error: recursive object depth is too deep.' : KeyCount<PickSelection<Full, Selection, Depth>> extends 1 ? Selection[keyof PickSelection<Full, Selection, Depth>] extends GenericSelectionSet ? PickCollapsedSelection<Full[keyof PickSelection<Full, Selection, Depth>], Selection[keyof PickSelection<Full, Selection, Depth>], TsRecurse<Depth>> : PropertyValueType<PickSelection<Full, Selection, Depth>> : PickSelection<Full, Selection, Depth>;
21
+ export type PickCollapsedSelection<Full extends Readonly<AnyObject>, Selection extends GenericSelectionSet, Depth extends TsRecursionTracker = TsRecursionStart> = Depth extends TsTooMuchRecursion ? 'Error: recursive object depth is too deep.' : KeyCount<ExcludeEmpty<NonNullable<PickSelection<Full, Selection, Depth>>>> extends 1 ? Selection[keyof PickSelection<Full, Selection, Depth>] extends GenericSelectionSet ? PickCollapsedSelection<NonNullable<Full[keyof PickSelection<Full, Selection, Depth>]>, Selection[keyof PickSelection<Full, Selection, Depth>], TsRecurse<Depth>> | Extract<Full[keyof PickSelection<Full, Selection, Depth>], undefined | null> : PropertyValueType<PickSelection<Full, Selection, Depth>> : PickSelection<Full, Selection, Depth>;
22
22
  /** Defines a selection set for the given object. */
23
- export type SelectionSet<Full extends Readonly<AnyObject>, Depth extends TsRecursionTracker = TsRecursionStart> = IsAny<Full> extends true ? any : Depth extends TsTooMuchRecursion ? ['Error: recursive object depth is too deep.'] : Full extends ReadonlyArray<infer FullChild extends AnyObject> ? SelectionSet<FullChild, TsRecurse<Depth>> : Partial<{
24
- [Key in keyof Full]: IsNever<Exclude<Full[Key], SelectionTypesToPreserve>> extends true ? boolean : boolean | UnionToIntersection<SelectionSet<Full[Key], TsRecurse<Depth>>>;
23
+ export type SelectionSet<Full extends Readonly<AnyObject>, Depth extends TsRecursionTracker = TsRecursionStart> = IsAny<Full> extends true ? any : Depth extends TsTooMuchRecursion ? boolean : Full extends ReadonlyArray<infer FullChild extends AnyObject> ? SelectionSet<FullChild, TsRecurse<Depth>> : Partial<{
24
+ [Key in keyof Full]: IsNever<Exclude<Full[Key], SelectionTypesToPreserve>> extends true ? boolean : UnionToIntersection<SelectionSet<NonNullable<Required<Full>[Key]>, TsRecurse<Depth>>> | boolean;
25
25
  }>;
26
26
  export declare function selectFrom<Full extends AnyObject, const Selection extends SelectionSet<NoInfer<Full>>>(originalObject: Readonly<Full>, selectionSet: Readonly<Selection>): PickSelection<Full, Selection>;
27
27
  export declare function selectCollapsedFrom<Full extends AnyObject, const Selection extends SelectionSet<NoInfer<Full>>>(originalObject: Readonly<Full>, selectionSet: Readonly<Selection>): PickCollapsedSelection<Full, Selection>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "29.1.8",
3
+ "version": "29.1.10",
4
4
  "homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
5
5
  "bugs": {
6
6
  "url": "https://github.com/electrovir/augment-vir/issues"
@@ -26,7 +26,7 @@
26
26
  "dependencies": {
27
27
  "browser-or-node": "^3.0.0",
28
28
  "run-time-assertions": "^1.5.1",
29
- "type-fest": "^4.20.1"
29
+ "type-fest": "^4.21.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "typescript": "5.5.2"