@augment-vir/common
Advanced tools
Comparing version 19.4.0 to 19.4.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mapObjectValues = exports.mapObjectValuesSync = void 0; | ||
const __1 = require("../.."); | ||
const object_entries_1 = require("./object-entries"); | ||
/** | ||
@@ -12,11 +12,7 @@ * Map an object's keys to new values synchronously. This is different from plain mapObjectValues in | ||
* @example | ||
* mapObjectValuesSync({objectToIterateOver: 'initial value'})<{objectToIterateOver: number}>( | ||
* (key, value) => ({ | ||
* newValue: value.length, | ||
* }), | ||
* ); | ||
* mapObjectValuesSync({objectToIterateOver: 'initial value'})(callback); | ||
*/ | ||
function mapObjectValuesSync(inputObject) { | ||
function innerMap(mapCallback) { | ||
const mappedObject = (0, __1.getObjectTypedKeys)(inputObject).reduce((accum, currentKey) => { | ||
const mappedObject = (0, object_entries_1.getObjectTypedKeys)(inputObject).reduce((accum, currentKey) => { | ||
const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject); | ||
@@ -39,3 +35,3 @@ return { | ||
let gotAPromise = false; | ||
const mappedObject = (0, __1.getObjectTypedKeys)(inputObject).reduce((accum, currentKey) => { | ||
const mappedObject = (0, object_entries_1.getObjectTypedKeys)(inputObject).reduce((accum, currentKey) => { | ||
const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject); | ||
@@ -53,3 +49,3 @@ if (mappedValue instanceof Promise) { | ||
try { | ||
await Promise.all((0, __1.getObjectTypedKeys)(mappedObject).map(async (key) => { | ||
await Promise.all((0, object_entries_1.getObjectTypedKeys)(mappedObject).map(async (key) => { | ||
const value = await mappedObject[key]; | ||
@@ -56,0 +52,0 @@ mappedObject[key] = value; |
@@ -1,2 +0,2 @@ | ||
import { isPromiseLike, isTruthy, typedHasProperty, } from '..'; | ||
import { isPromiseLike, isTruthy, typedHasProperty } from '..'; | ||
export function combineErrors(errors) { | ||
@@ -3,0 +3,0 @@ if (!errors || errors.length === 0) { |
@@ -1,2 +0,2 @@ | ||
import { getObjectTypedKeys } from '../..'; | ||
import { getObjectTypedKeys } from './object-entries'; | ||
/** | ||
@@ -9,7 +9,3 @@ * Map an object's keys to new values synchronously. This is different from plain mapObjectValues in | ||
* @example | ||
* mapObjectValuesSync({objectToIterateOver: 'initial value'})<{objectToIterateOver: number}>( | ||
* (key, value) => ({ | ||
* newValue: value.length, | ||
* }), | ||
* ); | ||
* mapObjectValuesSync({objectToIterateOver: 'initial value'})(callback); | ||
*/ | ||
@@ -16,0 +12,0 @@ export function mapObjectValuesSync(inputObject) { |
import { RequireExactlyOne } from 'type-fest'; | ||
import { AtLeastTuple, NoInputsFunction, UnPromise } from '..'; | ||
import { AtLeastTuple, NoInputsFunction } from '..'; | ||
export declare function combineErrors(errors: AtLeastTuple<Error, 1>): Error; | ||
@@ -18,3 +18,3 @@ export declare function combineErrors(errors: ReadonlyArray<never>): undefined; | ||
export declare function wrapInTry<CallbackReturn, FallbackReturn>(inputs: TryWrapInputs<CallbackReturn, FallbackReturn>): FallbackReturn | CallbackReturn; | ||
export declare function executeAndReturnError<CallbackGeneric extends NoInputsFunction<PromiseLike<any>>>(callback: CallbackGeneric): Promise<Error | UnPromise<ReturnType<CallbackGeneric>>>; | ||
export declare function executeAndReturnError<CallbackGeneric extends NoInputsFunction<PromiseLike<any>>>(callback: CallbackGeneric): Promise<Error | Awaited<ReturnType<CallbackGeneric>>>; | ||
export declare function executeAndReturnError<CallbackGeneric extends NoInputsFunction>(callback: CallbackGeneric): Error | ReturnType<CallbackGeneric>; |
@@ -1,6 +0,6 @@ | ||
import { PropertyValueType, UnPromise } from '../..'; | ||
import { PropertyValueType } from './object'; | ||
export type InnerMappedValues<EntireInputGeneric extends object, MappedValueGeneric> = { | ||
[MappedProp in keyof EntireInputGeneric]: MappedValueGeneric; | ||
}; | ||
export type MappedValues<EntireInputGeneric extends object, MappedValueGeneric> = MappedValueGeneric extends PromiseLike<unknown> ? Promise<InnerMappedValues<EntireInputGeneric, UnPromise<MappedValueGeneric>>> : InnerMappedValues<EntireInputGeneric, UnPromise<MappedValueGeneric>>; | ||
export type MappedValues<EntireInputGeneric extends object, MappedValueGeneric> = MappedValueGeneric extends PromiseLike<unknown> ? Promise<InnerMappedValues<EntireInputGeneric, Awaited<MappedValueGeneric>>> : InnerMappedValues<EntireInputGeneric, Awaited<MappedValueGeneric>>; | ||
/** | ||
@@ -13,7 +13,3 @@ * Map an object's keys to new values synchronously. This is different from plain mapObjectValues in | ||
* @example | ||
* mapObjectValuesSync({objectToIterateOver: 'initial value'})<{objectToIterateOver: number}>( | ||
* (key, value) => ({ | ||
* newValue: value.length, | ||
* }), | ||
* ); | ||
* mapObjectValuesSync({objectToIterateOver: 'initial value'})(callback); | ||
*/ | ||
@@ -20,0 +16,0 @@ 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; |
export declare function wait(delayMs: number): Promise<void>; | ||
export declare function waitValue<ResolutionValue>(delayMs: number, returnValue: ResolutionValue): Promise<ResolutionValue>; | ||
export declare function isPromiseLike<T>(input: T | unknown): input is T extends PromiseLike<infer ValueType> ? PromiseLike<ValueType> : PromiseLike<unknown>; | ||
export type UnPromise<T> = T extends PromiseLike<infer PromiseType> ? Awaited<PromiseType> : T; | ||
export type MaybePromise<T> = Promise<UnPromise<T>> | UnPromise<T>; | ||
export type MaybePromise<T> = Promise<T> | T; | ||
export declare class PromiseTimeoutError extends Error { | ||
@@ -7,0 +6,0 @@ readonly durationMs: number; |
{ | ||
"name": "@augment-vir/common", | ||
"version": "19.4.0", | ||
"version": "19.4.1", | ||
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common", | ||
@@ -5,0 +5,0 @@ "bugs": { |
154810
3740