@augment-vir/common 31.1.0 → 31.1.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { IsAny, IsNever, Primitive, UnionToIntersection } from 'type-fest';
|
|
3
|
-
import { TsRecurse, TsRecursionStart, TsRecursionTracker, TsTooMuchRecursion } from '../type/type-recursion.js';
|
|
1
|
+
import { type AnyObject, type RequiredKeysOf } from '@augment-vir/core';
|
|
2
|
+
import { type IsAny, type IsNever, type OptionalKeysOf, type Primitive, type UnionToIntersection } from 'type-fest';
|
|
3
|
+
import { type TsRecurse, type TsRecursionStart, type TsRecursionTracker, type TsTooMuchRecursion } from '../type/type-recursion.js';
|
|
4
4
|
/** All types that won't be recursed into when defining a {@link SelectionSet}. */
|
|
5
5
|
type SelectionTypesToPreserve = Primitive | RegExp | Promise<any>;
|
|
6
6
|
/**
|
|
@@ -13,6 +13,15 @@ type SelectionTypesToPreserve = Primitive | RegExp | Promise<any>;
|
|
|
13
13
|
export type GenericSelectionSet = {
|
|
14
14
|
[Key in PropertyKey]: unknown;
|
|
15
15
|
};
|
|
16
|
+
type MakeKeysOptional<Full extends AnyObject, T extends AnyObject> = IsNever<Extract<OptionalKeysOf<Full>, keyof T>> extends true ? {
|
|
17
|
+
[Key in keyof T]: T[Key];
|
|
18
|
+
} : IsNever<Extract<RequiredKeysOf<Full>, keyof T>> extends true ? {
|
|
19
|
+
[Key in keyof T]?: T[Key];
|
|
20
|
+
} : /** Optional and required keys. */ {
|
|
21
|
+
[Key in Extract<RequiredKeysOf<Full>, keyof T>]: T[Key];
|
|
22
|
+
} & {
|
|
23
|
+
[Key in Extract<OptionalKeysOf<Full>, keyof T>]?: T[Key];
|
|
24
|
+
};
|
|
16
25
|
/**
|
|
17
26
|
* Performs a SQL-like nested selection on an object, extracting the selected values. This produces
|
|
18
27
|
* the output type for `selectFrom`.
|
|
@@ -21,9 +30,9 @@ export type GenericSelectionSet = {
|
|
|
21
30
|
* @category Package : @augment-vir/common
|
|
22
31
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
23
32
|
*/
|
|
24
|
-
export type SelectFrom<Full extends Readonly<AnyObject>, Selection extends SelectionSet<Full>, Depth extends TsRecursionTracker = TsRecursionStart> = Depth extends TsTooMuchRecursion ? ['Error: recursive object depth is too deep.'] : Full extends ReadonlyArray<infer Element extends any> ? (SelectFrom<Extract<Element, AnyObject>, Selection, TsRecurse<Depth>> | Exclude<Element, AnyObject>)[] : {
|
|
33
|
+
export type SelectFrom<Full extends Readonly<AnyObject>, Selection extends SelectionSet<Full>, Depth extends TsRecursionTracker = TsRecursionStart> = Depth extends TsTooMuchRecursion ? ['Error: recursive object depth is too deep.'] : Full extends ReadonlyArray<infer Element extends any> ? (SelectFrom<Extract<Element, AnyObject>, Selection, TsRecurse<Depth>> | Exclude<Element, AnyObject>)[] : MakeKeysOptional<Full, {
|
|
25
34
|
-readonly [Key in keyof Selection as Selection[Key] extends false ? never : Key extends keyof Full ? Key : never]: (Selection[Key] extends GenericSelectionSet ? SelectFrom<NonNullable<Extract<Full[Key], AnyObject>>, Selection[Key], TsRecurse<Depth>> : Full[Key]) | Exclude<Full[Key], AnyObject>;
|
|
26
|
-
}
|
|
35
|
+
}>;
|
|
27
36
|
/**
|
|
28
37
|
* Defines a selection set for a given object type. This is used in {@link SelectFrom}.
|
|
29
38
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/common",
|
|
3
|
-
"version": "31.1.
|
|
3
|
+
"version": "31.1.1",
|
|
4
4
|
"description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"test:web": "virmator --no-deps test web"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@augment-vir/assert": "^31.1.
|
|
43
|
-
"@augment-vir/core": "^31.1.
|
|
42
|
+
"@augment-vir/assert": "^31.1.1",
|
|
43
|
+
"@augment-vir/core": "^31.1.1",
|
|
44
44
|
"@date-vir/duration": "^7.0.1",
|
|
45
45
|
"ansi-styles": "^6.2.1",
|
|
46
46
|
"json5": "^2.2.3",
|