@augment-vir/common 31.29.0 → 31.30.0
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,4 +1,5 @@
|
|
|
1
|
-
import { type CompleteValues } from '@augment-vir/core';
|
|
1
|
+
import { type CompleteValues, type ExcludeKeysWithMatchingValues, type ExtractKeysWithMatchingValues } from '@augment-vir/core';
|
|
2
|
+
import { type OptionalKeysOf, type RequiredKeysOf } from 'type-fest';
|
|
2
3
|
/**
|
|
3
4
|
* Filters an object. Like
|
|
4
5
|
* [`[].filter`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
|
|
@@ -19,4 +20,65 @@ import { type CompleteValues } from '@augment-vir/core';
|
|
|
19
20
|
*
|
|
20
21
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
21
22
|
*/
|
|
22
|
-
export declare function filterObject<ObjectGeneric>(inputObject: ObjectGeneric
|
|
23
|
+
export declare function filterObject<ObjectGeneric>(inputObject: Readonly<ObjectGeneric>, callback: (key: keyof ObjectGeneric, value: CompleteValues<ObjectGeneric>, fullObject: ObjectGeneric) => boolean): Partial<ObjectGeneric>;
|
|
24
|
+
/**
|
|
25
|
+
* Converts any optionally `undefined` keys to partials with non-undefined values. This does not
|
|
26
|
+
* exclude `null`.
|
|
27
|
+
*
|
|
28
|
+
* @category Object
|
|
29
|
+
* @category Package : @augment-vir/common
|
|
30
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
31
|
+
*/
|
|
32
|
+
export type RemoveUndefinedValues<ObjectGeneric> = {
|
|
33
|
+
[Key in ExcludeKeysWithMatchingValues<ObjectGeneric, undefined>]: ObjectGeneric[Key];
|
|
34
|
+
} & {
|
|
35
|
+
[Key in ExtractKeysWithMatchingValues<ObjectGeneric, undefined>]?: Exclude<ObjectGeneric[Key], undefined>;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Converts any `undefined` values into `null`.
|
|
39
|
+
*
|
|
40
|
+
* @category Object
|
|
41
|
+
* @category Package : @augment-vir/common
|
|
42
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
43
|
+
*/
|
|
44
|
+
export type ReplaceUndefinedValuesWithNull<ObjectGeneric> = {
|
|
45
|
+
[Key in RequiredKeysOf<Extract<ObjectGeneric, object>>]: undefined extends ObjectGeneric[Key] ? Exclude<ObjectGeneric[Key], undefined> | null : ObjectGeneric[Key];
|
|
46
|
+
} & {
|
|
47
|
+
[Key in OptionalKeysOf<Extract<ObjectGeneric, object>>]?: undefined extends Required<ObjectGeneric>[Key] ? Exclude<ObjectGeneric[Key], undefined> | null : ObjectGeneric[Key];
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Converts any `null` values into `undefined`.
|
|
51
|
+
*
|
|
52
|
+
* @category Object
|
|
53
|
+
* @category Package : @augment-vir/common
|
|
54
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
55
|
+
*/
|
|
56
|
+
export type ReplaceNullValuesWithUndefined<ObjectGeneric> = {
|
|
57
|
+
[Key in RequiredKeysOf<Extract<ObjectGeneric, object>>]: null extends ObjectGeneric[Key] ? Exclude<ObjectGeneric[Key], null> | undefined : ObjectGeneric[Key];
|
|
58
|
+
} & {
|
|
59
|
+
[Key in OptionalKeysOf<Extract<ObjectGeneric, object>>]?: null extends Required<ObjectGeneric>[Key] ? Exclude<ObjectGeneric[Key], null> | undefined : ObjectGeneric[Key];
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Removes keys for values that are `undefined`.
|
|
63
|
+
*
|
|
64
|
+
* @category Object
|
|
65
|
+
* @category Package : @augment-vir/common
|
|
66
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
67
|
+
*/
|
|
68
|
+
export declare function removeUndefinedValues<ObjectGeneric>(input: Readonly<ObjectGeneric>): RemoveUndefinedValues<ObjectGeneric>;
|
|
69
|
+
/**
|
|
70
|
+
* Replaces all `undefined` values with `null`.
|
|
71
|
+
*
|
|
72
|
+
* @category Object
|
|
73
|
+
* @category Package : @augment-vir/common
|
|
74
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
75
|
+
*/
|
|
76
|
+
export declare function replaceUndefinedValuesWithNull<ObjectGeneric>(input: Readonly<ObjectGeneric>): ReplaceUndefinedValuesWithNull<ObjectGeneric>;
|
|
77
|
+
/**
|
|
78
|
+
* Replaces all `null` values with `undefined`.
|
|
79
|
+
*
|
|
80
|
+
* @category Object
|
|
81
|
+
* @category Package : @augment-vir/common
|
|
82
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
83
|
+
*/
|
|
84
|
+
export declare function replaceNullValuesWithUndefined<ObjectGeneric>(input: Readonly<ObjectGeneric>): ReplaceNullValuesWithUndefined<ObjectGeneric>;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { mapObject } from './map-entries.js';
|
|
2
|
+
import { mapObjectValues } from './map-values.js';
|
|
1
3
|
import { getObjectTypedEntries, typedObjectFromEntries } from './object-entries.js';
|
|
2
4
|
/**
|
|
3
5
|
* Filters an object. Like
|
|
@@ -25,3 +27,40 @@ export function filterObject(inputObject, callback) {
|
|
|
25
27
|
});
|
|
26
28
|
return typedObjectFromEntries(filteredEntries);
|
|
27
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Removes keys for values that are `undefined`.
|
|
32
|
+
*
|
|
33
|
+
* @category Object
|
|
34
|
+
* @category Package : @augment-vir/common
|
|
35
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
36
|
+
*/
|
|
37
|
+
export function removeUndefinedValues(input) {
|
|
38
|
+
return mapObject(input, (key, value) => {
|
|
39
|
+
if (value === undefined) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return { key, value };
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Replaces all `undefined` values with `null`.
|
|
49
|
+
*
|
|
50
|
+
* @category Object
|
|
51
|
+
* @category Package : @augment-vir/common
|
|
52
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
53
|
+
*/
|
|
54
|
+
export function replaceUndefinedValuesWithNull(input) {
|
|
55
|
+
return mapObjectValues(input, (key, value) => value === undefined ? null : value);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Replaces all `null` values with `undefined`.
|
|
59
|
+
*
|
|
60
|
+
* @category Object
|
|
61
|
+
* @category Package : @augment-vir/common
|
|
62
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
63
|
+
*/
|
|
64
|
+
export function replaceNullValuesWithUndefined(input) {
|
|
65
|
+
return mapObjectValues(input, (key, value) => value === null ? undefined : value);
|
|
66
|
+
}
|
|
@@ -1,13 +1,30 @@
|
|
|
1
1
|
import { type BaseTypeMap } from './base-prisma-types.js';
|
|
2
2
|
import { type PrismaBasicModel } from './prisma-basic-model.js';
|
|
3
|
-
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Gets the full model type with all nested models for Prisma.
|
|
5
|
+
*
|
|
6
|
+
* @category Prisma : Common
|
|
7
|
+
* @category Package : @augment-vir/common
|
|
8
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
9
|
+
*/
|
|
10
|
+
export type PrismaFullModel<TypeMap extends BaseTypeMap, Model extends keyof TypeMap['model']> = PrismaBasicModel<TypeMap, Model> & ExpandModelObjects<TypeMap['model'][Model]['payload']['objects'], TypeMap>;
|
|
11
|
+
/**
|
|
12
|
+
* Expand a model's objects (nested models).
|
|
13
|
+
*
|
|
14
|
+
* @category Prisma : Common
|
|
15
|
+
* @category Package : @augment-vir/common
|
|
16
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
17
|
+
*/
|
|
18
|
+
export type ExpandModelObjects<Objects, TypeMap extends BaseTypeMap> = {
|
|
19
|
+
[Key in keyof Objects]: Objects[Key] extends ReadonlyArray<infer Entry> ? ExpandModel<TypeMap, Entry>[] : ExpandModel<TypeMap, Objects[Key]>;
|
|
12
20
|
};
|
|
13
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Expand a model entry from {@link ExpandModelObjects}.
|
|
23
|
+
*
|
|
24
|
+
* @category Prisma : Common
|
|
25
|
+
* @category Package : @augment-vir/common
|
|
26
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
27
|
+
*/
|
|
28
|
+
export type ExpandModel<TypeMap extends BaseTypeMap, Entry> = Entry extends Readonly<{
|
|
29
|
+
name: infer ModelName extends keyof TypeMap['model'];
|
|
30
|
+
}> ? PrismaFullModel<TypeMap, ModelName> : never;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/common",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.30.0",
|
|
4
4
|
"description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"test:web": "virmator --no-deps test web"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@augment-vir/assert": "^31.
|
|
44
|
-
"@augment-vir/core": "^31.
|
|
43
|
+
"@augment-vir/assert": "^31.30.0",
|
|
44
|
+
"@augment-vir/core": "^31.30.0",
|
|
45
45
|
"@date-vir/duration": "^7.3.2",
|
|
46
46
|
"ansi-styles": "^6.2.1",
|
|
47
47
|
"deepcopy-esm": "^2.1.1",
|