@augment-vir/common 19.4.0 → 19.4.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.
- package/dist/cjs/augments/object/map-object.js +5 -9
- package/dist/esm/augments/error.js +1 -1
- package/dist/esm/augments/object/map-object.js +2 -6
- package/dist/types/augments/error.d.ts +2 -2
- package/dist/types/augments/object/map-object.d.ts +3 -7
- package/dist/types/augments/promise.d.ts +1 -2
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mapObjectValues = exports.mapObjectValuesSync = void 0;
|
|
4
|
-
const
|
|
4
|
+
const object_entries_1 = require("./object-entries");
|
|
5
5
|
/**
|
|
6
6
|
* Map an object's keys to new values synchronously. This is different from plain mapObjectValues in
|
|
7
7
|
* that this will not wrap the return value in a promise if any of the new object values are
|
|
@@ -9,15 +9,11 @@ const __1 = require("../..");
|
|
|
9
9
|
* to explicitly state the return type.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
|
-
* mapObjectValuesSync({objectToIterateOver: 'initial value'})
|
|
13
|
-
* (key, value) => ({
|
|
14
|
-
* newValue: value.length,
|
|
15
|
-
* }),
|
|
16
|
-
* );
|
|
12
|
+
* mapObjectValuesSync({objectToIterateOver: 'initial value'})(callback);
|
|
17
13
|
*/
|
|
18
14
|
function mapObjectValuesSync(inputObject) {
|
|
19
15
|
function innerMap(mapCallback) {
|
|
20
|
-
const mappedObject = (0,
|
|
16
|
+
const mappedObject = (0, object_entries_1.getObjectTypedKeys)(inputObject).reduce((accum, currentKey) => {
|
|
21
17
|
const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject);
|
|
22
18
|
return {
|
|
23
19
|
...accum,
|
|
@@ -35,7 +31,7 @@ exports.mapObjectValuesSync = mapObjectValuesSync;
|
|
|
35
31
|
*/
|
|
36
32
|
function mapObjectValues(inputObject, mapCallback) {
|
|
37
33
|
let gotAPromise = false;
|
|
38
|
-
const mappedObject = (0,
|
|
34
|
+
const mappedObject = (0, object_entries_1.getObjectTypedKeys)(inputObject).reduce((accum, currentKey) => {
|
|
39
35
|
const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject);
|
|
40
36
|
if (mappedValue instanceof Promise) {
|
|
41
37
|
gotAPromise = true;
|
|
@@ -48,7 +44,7 @@ function mapObjectValues(inputObject, mapCallback) {
|
|
|
48
44
|
if (gotAPromise) {
|
|
49
45
|
return new Promise(async (resolve, reject) => {
|
|
50
46
|
try {
|
|
51
|
-
await Promise.all((0,
|
|
47
|
+
await Promise.all((0, object_entries_1.getObjectTypedKeys)(mappedObject).map(async (key) => {
|
|
52
48
|
const value = await mappedObject[key];
|
|
53
49
|
mappedObject[key] = value;
|
|
54
50
|
}));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getObjectTypedKeys } from '
|
|
1
|
+
import { getObjectTypedKeys } from './object-entries';
|
|
2
2
|
/**
|
|
3
3
|
* Map an object's keys to new values synchronously. This is different from plain mapObjectValues in
|
|
4
4
|
* that this will not wrap the return value in a promise if any of the new object values are
|
|
@@ -6,11 +6,7 @@ import { getObjectTypedKeys } from '../..';
|
|
|
6
6
|
* to explicitly state the return type.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
* mapObjectValuesSync({objectToIterateOver: 'initial value'})
|
|
10
|
-
* (key, value) => ({
|
|
11
|
-
* newValue: value.length,
|
|
12
|
-
* }),
|
|
13
|
-
* );
|
|
9
|
+
* mapObjectValuesSync({objectToIterateOver: 'initial value'})(callback);
|
|
14
10
|
*/
|
|
15
11
|
export function mapObjectValuesSync(inputObject) {
|
|
16
12
|
function innerMap(mapCallback) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RequireExactlyOne } from 'type-fest';
|
|
2
|
-
import { AtLeastTuple, NoInputsFunction
|
|
2
|
+
import { AtLeastTuple, NoInputsFunction } from '..';
|
|
3
3
|
export declare function combineErrors(errors: AtLeastTuple<Error, 1>): Error;
|
|
4
4
|
export declare function combineErrors(errors: ReadonlyArray<never>): undefined;
|
|
5
5
|
export declare function combineErrors(errors: ReadonlyArray<Error>): Error | undefined;
|
|
@@ -15,5 +15,5 @@ export type TryWrapInputs<CallbackReturn, FallbackReturn> = {
|
|
|
15
15
|
catchCallback: (error: unknown) => FallbackReturn;
|
|
16
16
|
}>;
|
|
17
17
|
export declare function wrapInTry<CallbackReturn, FallbackReturn>(inputs: TryWrapInputs<CallbackReturn, FallbackReturn>): FallbackReturn | CallbackReturn;
|
|
18
|
-
export declare function executeAndReturnError<CallbackGeneric extends NoInputsFunction<PromiseLike<any>>>(callback: CallbackGeneric): Promise<Error |
|
|
18
|
+
export declare function executeAndReturnError<CallbackGeneric extends NoInputsFunction<PromiseLike<any>>>(callback: CallbackGeneric): Promise<Error | Awaited<ReturnType<CallbackGeneric>>>;
|
|
19
19
|
export declare function executeAndReturnError<CallbackGeneric extends NoInputsFunction>(callback: CallbackGeneric): Error | ReturnType<CallbackGeneric>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { PropertyValueType
|
|
1
|
+
import { PropertyValueType } from './object';
|
|
2
2
|
export type InnerMappedValues<EntireInputGeneric extends object, MappedValueGeneric> = {
|
|
3
3
|
[MappedProp in keyof EntireInputGeneric]: MappedValueGeneric;
|
|
4
4
|
};
|
|
5
|
-
export type MappedValues<EntireInputGeneric extends object, MappedValueGeneric> = MappedValueGeneric extends PromiseLike<unknown> ? Promise<InnerMappedValues<EntireInputGeneric,
|
|
5
|
+
export type MappedValues<EntireInputGeneric extends object, MappedValueGeneric> = MappedValueGeneric extends PromiseLike<unknown> ? Promise<InnerMappedValues<EntireInputGeneric, Awaited<MappedValueGeneric>>> : InnerMappedValues<EntireInputGeneric, Awaited<MappedValueGeneric>>;
|
|
6
6
|
/**
|
|
7
7
|
* Map an object's keys to new values synchronously. This is different from plain mapObjectValues in
|
|
8
8
|
* that this will not wrap the return value in a promise if any of the new object values are
|
|
@@ -10,11 +10,7 @@ export type MappedValues<EntireInputGeneric extends object, MappedValueGeneric>
|
|
|
10
10
|
* to explicitly state the return type.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
|
-
* mapObjectValuesSync({objectToIterateOver: 'initial value'})
|
|
14
|
-
* (key, value) => ({
|
|
15
|
-
* newValue: value.length,
|
|
16
|
-
* }),
|
|
17
|
-
* );
|
|
13
|
+
* mapObjectValuesSync({objectToIterateOver: 'initial value'})(callback);
|
|
18
14
|
*/
|
|
19
15
|
export declare function mapObjectValuesSync<EntireInputGeneric extends object>(inputObject: EntireInputGeneric): <OutputObjectGeneric extends object>(mapCallback: (inputKey: keyof EntireInputGeneric, keyValue: EntireInputGeneric[keyof EntireInputGeneric], fullObject: EntireInputGeneric) => never extends PropertyValueType<OutputObjectGeneric> ? any : PropertyValueType<OutputObjectGeneric>) => OutputObjectGeneric;
|
|
20
16
|
/**
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export declare function wait(delayMs: number): Promise<void>;
|
|
2
2
|
export declare function waitValue<ResolutionValue>(delayMs: number, returnValue: ResolutionValue): Promise<ResolutionValue>;
|
|
3
3
|
export declare function isPromiseLike<T>(input: T | unknown): input is T extends PromiseLike<infer ValueType> ? PromiseLike<ValueType> : PromiseLike<unknown>;
|
|
4
|
-
export type
|
|
5
|
-
export type MaybePromise<T> = Promise<UnPromise<T>> | UnPromise<T>;
|
|
4
|
+
export type MaybePromise<T> = Promise<T> | T;
|
|
6
5
|
export declare class PromiseTimeoutError extends Error {
|
|
7
6
|
readonly durationMs: number;
|
|
8
7
|
readonly message: string;
|