maraj 2.7.2 → 2.7.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/dist/index.d.mts +16 -10
- package/dist/index.d.ts +16 -10
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -51,7 +51,7 @@ declare const extendableUpdate: ExtendableImmutableUpdate;
|
|
|
51
51
|
/** Primitives and browser native objects. */
|
|
52
52
|
type PrimitivesAndNativeObjects = null | undefined | string | number | boolean | symbol | bigint | Date | FileList | File;
|
|
53
53
|
/** Array indexes type. */
|
|
54
|
-
type ArrayIndexes = number | LiteralIndex;
|
|
54
|
+
type ArrayIndexes = number | `${number}` | LiteralIndex;
|
|
55
55
|
/** To check if a ReadonlyArray is a tuple or not. */
|
|
56
56
|
type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false : true;
|
|
57
57
|
/**
|
|
@@ -60,15 +60,21 @@ type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false
|
|
|
60
60
|
* --------------------------------------------
|
|
61
61
|
*/
|
|
62
62
|
/** Dot-paths of an array. */
|
|
63
|
-
type ArrayPaths<TInnerType, TAllowedTypes> = TInnerType extends TAllowedTypes ? TInnerType extends PrimitivesAndNativeObjects ?
|
|
63
|
+
type ArrayPaths<TInnerType, TAllowedTypes> = TInnerType extends TAllowedTypes ? TInnerType extends PrimitivesAndNativeObjects ? ArrayIndexes : ArrayIndexes | `${ArrayIndexes}.${DotPathsImplementation<TInnerType, TAllowedTypes>}` : `${ArrayIndexes}.${DotPathsImplementation<TInnerType, TAllowedTypes>}`;
|
|
64
64
|
/** Dot-paths of an object. */
|
|
65
65
|
type ObjectPaths<T, TAllowedTypes> = {
|
|
66
|
-
[Key in keyof T & (string | number)]: T[Key] extends TAllowedTypes ? T[Key] extends PrimitivesAndNativeObjects ? `${Key}` : `${Key}` | `${Key}.${
|
|
67
|
-
}[keyof T & (string | number)];
|
|
66
|
+
[Key in keyof T & (string | number)]: T[Key] extends TAllowedTypes ? T[Key] extends PrimitivesAndNativeObjects ? `${Key}` : `${Key}` | `${Key}.${DotPathsImplementation<T[Key], TAllowedTypes>}` : `${Key}.${DotPathsImplementation<T[Key], TAllowedTypes>}`;
|
|
67
|
+
}[keyof T & (string | number)] & unknown;
|
|
68
68
|
/** Dot-paths of a tuple. */
|
|
69
|
-
type TuplePaths<T, TAllowedTypes> = ObjectPaths<Omit<T, keyof any[]>, TAllowedTypes
|
|
69
|
+
type TuplePaths<T, TAllowedTypes> = ObjectPaths<Omit<T, keyof any[]>, TAllowedTypes> & unknown;
|
|
70
|
+
/** Dot-paths implementation */
|
|
71
|
+
type DotPathsImplementation<T, TAllowedTypes = any> = T extends ReadonlyArray<infer U> ? IsTuple<T> extends true ? TuplePaths<T, TAllowedTypes> : ArrayPaths<U, TAllowedTypes> : T extends PrimitivesAndNativeObjects ? never : ObjectPaths<T, TAllowedTypes>;
|
|
72
|
+
/** Extract Keys from any kind of type, including objects, arrays, tuples. */
|
|
73
|
+
type KeyOf<T, TAllowedTypes = any> = T extends ReadonlyArray<infer U> ? U extends TAllowedTypes ? IsTuple<T> extends true ? keyof Omit<T, keyof any[]> : ArrayIndexes : never : T extends PrimitivesAndNativeObjects ? never : {
|
|
74
|
+
[Key in keyof T]: T[Key] extends TAllowedTypes ? Key : never;
|
|
75
|
+
}[keyof T];
|
|
70
76
|
/** Literal union of all posible dot-paths which satisfy provided types as second argument (default: any). */
|
|
71
|
-
type DotPaths<T, TAllowedTypes = any> =
|
|
77
|
+
type DotPaths<T, TAllowedTypes = any> = KeyOf<T, TAllowedTypes> | DotPathsImplementation<T, TAllowedTypes>;
|
|
72
78
|
/**
|
|
73
79
|
* --------------------------------------------
|
|
74
80
|
* VALUE OF A NESTED PROPERTY PROVIDING A DOT PATH
|
|
@@ -89,10 +95,10 @@ type ReturnedValueInPath<TObject, TPath> = TPath extends '' ? TObject : TPath ex
|
|
|
89
95
|
* --------------------------------------------
|
|
90
96
|
*/
|
|
91
97
|
/** Value of a dot-path update object, can be the value or a function. */
|
|
92
|
-
type UpdateValue<TObject, TPath> = ValueInPath<TObject, TPath> | ((fieldValue: ValueInPath<TObject, TPath>) => ValueInPath<TObject, TPath>);
|
|
98
|
+
type UpdateValue<TObject, TPath> = ValueInPath<TObject, TPath> extends never ? never : ValueInPath<TObject, TPath> | ((fieldValue: ValueInPath<TObject, TPath>) => ValueInPath<TObject, TPath>);
|
|
93
99
|
/** Dot-path update object, used to give updates to the updateImmutably function. */
|
|
94
100
|
type UpdateObject<TObject, TPaths extends PropertyKey = DotPaths<TObject>> = {
|
|
95
|
-
[
|
|
101
|
+
[Path in TPaths]?: UpdateValue<TObject, Path>;
|
|
96
102
|
};
|
|
97
103
|
/**
|
|
98
104
|
* --------------------------------------------
|
|
@@ -133,7 +139,7 @@ type ExtractTypeFromDotPathUpdateObject<T extends Record<string, any>> = T exten
|
|
|
133
139
|
}>;
|
|
134
140
|
} & unknown;
|
|
135
141
|
/** New expanded value after aplying updates including new properties */
|
|
136
|
-
type ExtendedUpdate<TObject, TDotPathUpdateObject extends Record<PropertyKey, any>> = TObject extends Array<infer U> ? ExtractTypeFromDotPathUpdateObject<TDotPathUpdateObject> extends Array<infer W> ? Array<U | W> : TObject & ExtractTypeFromDotPathUpdateObject<TDotPathUpdateObject> :
|
|
142
|
+
type ExtendedUpdate<TObject, TDotPathUpdateObject extends Record<PropertyKey, any>> = TObject extends Array<infer U> ? ExtractTypeFromDotPathUpdateObject<TDotPathUpdateObject> extends Array<infer W> ? Array<U | W> : TObject & ExtractTypeFromDotPathUpdateObject<TDotPathUpdateObject> : TObject & ExtractTypeFromDotPathUpdateObject<TDotPathUpdateObject>;
|
|
137
143
|
|
|
138
144
|
type Select = {
|
|
139
145
|
<T, TPath extends DotPaths<T>>(state: T, path: TPath): ReturnedValueInPath<T, TPath>;
|
|
@@ -171,4 +177,4 @@ declare const isObjectLiteral: (valueToTest: any) => boolean;
|
|
|
171
177
|
declare const parseStringIndex: (v: string) => number | null;
|
|
172
178
|
declare const isStringIndex: (v: string) => boolean;
|
|
173
179
|
|
|
174
|
-
export { type DotPaths, type LiteralIndex, type ReturnedValueInPath, type UpdateObject, type UpdateValue, type ValueInPath, extendableUpdate, isObjectLiteral, isStringIndex, parseStringIndex, remove, select, set, splitPathAtLastKey, update };
|
|
180
|
+
export { type DotPaths, type KeyOf, type LiteralIndex, type ReturnedValueInPath, type UpdateObject, type UpdateValue, type ValueInPath, extendableUpdate, isObjectLiteral, isStringIndex, parseStringIndex, remove, select, set, splitPathAtLastKey, update };
|
package/dist/index.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ declare const extendableUpdate: ExtendableImmutableUpdate;
|
|
|
51
51
|
/** Primitives and browser native objects. */
|
|
52
52
|
type PrimitivesAndNativeObjects = null | undefined | string | number | boolean | symbol | bigint | Date | FileList | File;
|
|
53
53
|
/** Array indexes type. */
|
|
54
|
-
type ArrayIndexes = number | LiteralIndex;
|
|
54
|
+
type ArrayIndexes = number | `${number}` | LiteralIndex;
|
|
55
55
|
/** To check if a ReadonlyArray is a tuple or not. */
|
|
56
56
|
type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false : true;
|
|
57
57
|
/**
|
|
@@ -60,15 +60,21 @@ type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false
|
|
|
60
60
|
* --------------------------------------------
|
|
61
61
|
*/
|
|
62
62
|
/** Dot-paths of an array. */
|
|
63
|
-
type ArrayPaths<TInnerType, TAllowedTypes> = TInnerType extends TAllowedTypes ? TInnerType extends PrimitivesAndNativeObjects ?
|
|
63
|
+
type ArrayPaths<TInnerType, TAllowedTypes> = TInnerType extends TAllowedTypes ? TInnerType extends PrimitivesAndNativeObjects ? ArrayIndexes : ArrayIndexes | `${ArrayIndexes}.${DotPathsImplementation<TInnerType, TAllowedTypes>}` : `${ArrayIndexes}.${DotPathsImplementation<TInnerType, TAllowedTypes>}`;
|
|
64
64
|
/** Dot-paths of an object. */
|
|
65
65
|
type ObjectPaths<T, TAllowedTypes> = {
|
|
66
|
-
[Key in keyof T & (string | number)]: T[Key] extends TAllowedTypes ? T[Key] extends PrimitivesAndNativeObjects ? `${Key}` : `${Key}` | `${Key}.${
|
|
67
|
-
}[keyof T & (string | number)];
|
|
66
|
+
[Key in keyof T & (string | number)]: T[Key] extends TAllowedTypes ? T[Key] extends PrimitivesAndNativeObjects ? `${Key}` : `${Key}` | `${Key}.${DotPathsImplementation<T[Key], TAllowedTypes>}` : `${Key}.${DotPathsImplementation<T[Key], TAllowedTypes>}`;
|
|
67
|
+
}[keyof T & (string | number)] & unknown;
|
|
68
68
|
/** Dot-paths of a tuple. */
|
|
69
|
-
type TuplePaths<T, TAllowedTypes> = ObjectPaths<Omit<T, keyof any[]>, TAllowedTypes
|
|
69
|
+
type TuplePaths<T, TAllowedTypes> = ObjectPaths<Omit<T, keyof any[]>, TAllowedTypes> & unknown;
|
|
70
|
+
/** Dot-paths implementation */
|
|
71
|
+
type DotPathsImplementation<T, TAllowedTypes = any> = T extends ReadonlyArray<infer U> ? IsTuple<T> extends true ? TuplePaths<T, TAllowedTypes> : ArrayPaths<U, TAllowedTypes> : T extends PrimitivesAndNativeObjects ? never : ObjectPaths<T, TAllowedTypes>;
|
|
72
|
+
/** Extract Keys from any kind of type, including objects, arrays, tuples. */
|
|
73
|
+
type KeyOf<T, TAllowedTypes = any> = T extends ReadonlyArray<infer U> ? U extends TAllowedTypes ? IsTuple<T> extends true ? keyof Omit<T, keyof any[]> : ArrayIndexes : never : T extends PrimitivesAndNativeObjects ? never : {
|
|
74
|
+
[Key in keyof T]: T[Key] extends TAllowedTypes ? Key : never;
|
|
75
|
+
}[keyof T];
|
|
70
76
|
/** Literal union of all posible dot-paths which satisfy provided types as second argument (default: any). */
|
|
71
|
-
type DotPaths<T, TAllowedTypes = any> =
|
|
77
|
+
type DotPaths<T, TAllowedTypes = any> = KeyOf<T, TAllowedTypes> | DotPathsImplementation<T, TAllowedTypes>;
|
|
72
78
|
/**
|
|
73
79
|
* --------------------------------------------
|
|
74
80
|
* VALUE OF A NESTED PROPERTY PROVIDING A DOT PATH
|
|
@@ -89,10 +95,10 @@ type ReturnedValueInPath<TObject, TPath> = TPath extends '' ? TObject : TPath ex
|
|
|
89
95
|
* --------------------------------------------
|
|
90
96
|
*/
|
|
91
97
|
/** Value of a dot-path update object, can be the value or a function. */
|
|
92
|
-
type UpdateValue<TObject, TPath> = ValueInPath<TObject, TPath> | ((fieldValue: ValueInPath<TObject, TPath>) => ValueInPath<TObject, TPath>);
|
|
98
|
+
type UpdateValue<TObject, TPath> = ValueInPath<TObject, TPath> extends never ? never : ValueInPath<TObject, TPath> | ((fieldValue: ValueInPath<TObject, TPath>) => ValueInPath<TObject, TPath>);
|
|
93
99
|
/** Dot-path update object, used to give updates to the updateImmutably function. */
|
|
94
100
|
type UpdateObject<TObject, TPaths extends PropertyKey = DotPaths<TObject>> = {
|
|
95
|
-
[
|
|
101
|
+
[Path in TPaths]?: UpdateValue<TObject, Path>;
|
|
96
102
|
};
|
|
97
103
|
/**
|
|
98
104
|
* --------------------------------------------
|
|
@@ -133,7 +139,7 @@ type ExtractTypeFromDotPathUpdateObject<T extends Record<string, any>> = T exten
|
|
|
133
139
|
}>;
|
|
134
140
|
} & unknown;
|
|
135
141
|
/** New expanded value after aplying updates including new properties */
|
|
136
|
-
type ExtendedUpdate<TObject, TDotPathUpdateObject extends Record<PropertyKey, any>> = TObject extends Array<infer U> ? ExtractTypeFromDotPathUpdateObject<TDotPathUpdateObject> extends Array<infer W> ? Array<U | W> : TObject & ExtractTypeFromDotPathUpdateObject<TDotPathUpdateObject> :
|
|
142
|
+
type ExtendedUpdate<TObject, TDotPathUpdateObject extends Record<PropertyKey, any>> = TObject extends Array<infer U> ? ExtractTypeFromDotPathUpdateObject<TDotPathUpdateObject> extends Array<infer W> ? Array<U | W> : TObject & ExtractTypeFromDotPathUpdateObject<TDotPathUpdateObject> : TObject & ExtractTypeFromDotPathUpdateObject<TDotPathUpdateObject>;
|
|
137
143
|
|
|
138
144
|
type Select = {
|
|
139
145
|
<T, TPath extends DotPaths<T>>(state: T, path: TPath): ReturnedValueInPath<T, TPath>;
|
|
@@ -171,4 +177,4 @@ declare const isObjectLiteral: (valueToTest: any) => boolean;
|
|
|
171
177
|
declare const parseStringIndex: (v: string) => number | null;
|
|
172
178
|
declare const isStringIndex: (v: string) => boolean;
|
|
173
179
|
|
|
174
|
-
export { type DotPaths, type LiteralIndex, type ReturnedValueInPath, type UpdateObject, type UpdateValue, type ValueInPath, extendableUpdate, isObjectLiteral, isStringIndex, parseStringIndex, remove, select, set, splitPathAtLastKey, update };
|
|
180
|
+
export { type DotPaths, type KeyOf, type LiteralIndex, type ReturnedValueInPath, type UpdateObject, type UpdateValue, type ValueInPath, extendableUpdate, isObjectLiteral, isStringIndex, parseStringIndex, remove, select, set, splitPathAtLastKey, update };
|