@aws-sdk/smithy-client
Advanced tools
Comparing version 3.306.0 to 3.309.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.convertMap = exports.map = void 0; | ||
exports.take = exports.convertMap = exports.map = void 0; | ||
function map(arg0, arg1, arg2) { | ||
@@ -28,21 +28,3 @@ let target; | ||
} | ||
let [filter, value] = instructions[key]; | ||
if (typeof value === "function") { | ||
let _value; | ||
const defaultFilterPassed = filter === undefined && (_value = value()) != null; | ||
const customFilterPassed = (typeof filter === "function" && !!filter(void 0)) || (typeof filter !== "function" && !!filter); | ||
if (defaultFilterPassed) { | ||
target[key] = _value; | ||
} | ||
else if (customFilterPassed) { | ||
target[key] = value(); | ||
} | ||
} | ||
else { | ||
const defaultFilterPassed = filter === undefined && value != null; | ||
const customFilterPassed = (typeof filter === "function" && !!filter(value)) || (typeof filter !== "function" && !!filter); | ||
if (defaultFilterPassed || customFilterPassed) { | ||
target[key] = value; | ||
} | ||
} | ||
applyInstruction(target, null, instructions, key); | ||
} | ||
@@ -60,2 +42,10 @@ return target; | ||
exports.convertMap = convertMap; | ||
const take = (source, instructions) => { | ||
const out = {}; | ||
for (const key in instructions) { | ||
applyInstruction(out, source, instructions, key); | ||
} | ||
return out; | ||
}; | ||
exports.take = take; | ||
const mapWithFilter = (target, filter, instructions) => { | ||
@@ -77,1 +67,35 @@ return map(target, Object.entries(instructions).reduce((_instructions, [key, value]) => { | ||
}; | ||
const applyInstruction = (target, source, instructions, targetKey) => { | ||
if (source !== null) { | ||
let instruction = instructions[targetKey]; | ||
if (typeof instruction === "function") { | ||
instruction = [, instruction]; | ||
} | ||
const [filter = nonNullish, valueFn = pass, sourceKey = targetKey] = instruction; | ||
if ((typeof filter === "function" && filter(source[sourceKey])) || (typeof filter !== "function" && !!filter)) { | ||
target[targetKey] = valueFn(source[sourceKey]); | ||
} | ||
return; | ||
} | ||
let [filter, value] = instructions[targetKey]; | ||
if (typeof value === "function") { | ||
let _value; | ||
const defaultFilterPassed = filter === undefined && (_value = value()) != null; | ||
const customFilterPassed = (typeof filter === "function" && !!filter(void 0)) || (typeof filter !== "function" && !!filter); | ||
if (defaultFilterPassed) { | ||
target[targetKey] = _value; | ||
} | ||
else if (customFilterPassed) { | ||
target[targetKey] = value(); | ||
} | ||
} | ||
else { | ||
const defaultFilterPassed = filter === undefined && value != null; | ||
const customFilterPassed = (typeof filter === "function" && !!filter(value)) || (typeof filter !== "function" && !!filter); | ||
if (defaultFilterPassed || customFilterPassed) { | ||
target[targetKey] = value; | ||
} | ||
} | ||
}; | ||
const nonNullish = (_) => _ != null; | ||
const pass = (_) => _; |
@@ -25,21 +25,3 @@ export function map(arg0, arg1, arg2) { | ||
} | ||
let [filter, value] = instructions[key]; | ||
if (typeof value === "function") { | ||
let _value; | ||
const defaultFilterPassed = filter === undefined && (_value = value()) != null; | ||
const customFilterPassed = (typeof filter === "function" && !!filter(void 0)) || (typeof filter !== "function" && !!filter); | ||
if (defaultFilterPassed) { | ||
target[key] = _value; | ||
} | ||
else if (customFilterPassed) { | ||
target[key] = value(); | ||
} | ||
} | ||
else { | ||
const defaultFilterPassed = filter === undefined && value != null; | ||
const customFilterPassed = (typeof filter === "function" && !!filter(value)) || (typeof filter !== "function" && !!filter); | ||
if (defaultFilterPassed || customFilterPassed) { | ||
target[key] = value; | ||
} | ||
} | ||
applyInstruction(target, null, instructions, key); | ||
} | ||
@@ -55,2 +37,9 @@ return target; | ||
}; | ||
export const take = (source, instructions) => { | ||
const out = {}; | ||
for (const key in instructions) { | ||
applyInstruction(out, source, instructions, key); | ||
} | ||
return out; | ||
}; | ||
const mapWithFilter = (target, filter, instructions) => { | ||
@@ -72,1 +61,35 @@ return map(target, Object.entries(instructions).reduce((_instructions, [key, value]) => { | ||
}; | ||
const applyInstruction = (target, source, instructions, targetKey) => { | ||
if (source !== null) { | ||
let instruction = instructions[targetKey]; | ||
if (typeof instruction === "function") { | ||
instruction = [, instruction]; | ||
} | ||
const [filter = nonNullish, valueFn = pass, sourceKey = targetKey] = instruction; | ||
if ((typeof filter === "function" && filter(source[sourceKey])) || (typeof filter !== "function" && !!filter)) { | ||
target[targetKey] = valueFn(source[sourceKey]); | ||
} | ||
return; | ||
} | ||
let [filter, value] = instructions[targetKey]; | ||
if (typeof value === "function") { | ||
let _value; | ||
const defaultFilterPassed = filter === undefined && (_value = value()) != null; | ||
const customFilterPassed = (typeof filter === "function" && !!filter(void 0)) || (typeof filter !== "function" && !!filter); | ||
if (defaultFilterPassed) { | ||
target[targetKey] = _value; | ||
} | ||
else if (customFilterPassed) { | ||
target[targetKey] = value(); | ||
} | ||
} | ||
else { | ||
const defaultFilterPassed = filter === undefined && value != null; | ||
const customFilterPassed = (typeof filter === "function" && !!filter(value)) || (typeof filter !== "function" && !!filter); | ||
if (defaultFilterPassed || customFilterPassed) { | ||
target[targetKey] = value; | ||
} | ||
} | ||
}; | ||
const nonNullish = (_) => _ != null; | ||
const pass = (_) => _; |
@@ -51,2 +51,10 @@ /** | ||
* | ||
* A variant of the object mapping instruction for the `take` function. | ||
* In this case, the source value is provided to the value function, turning it | ||
* from a supplier into a mapper. | ||
*/ | ||
export type SourceMappingInstructions = Record<string, ValueMapper | SourceMappingInstruction>; | ||
/** | ||
* @internal | ||
* | ||
* An instruction set for assigning a value to a target object. | ||
@@ -79,2 +87,6 @@ */ | ||
* @internal | ||
*/ | ||
export type SourceMappingInstruction = [ValueFilteringFunction?, ValueMapper?, string?]; | ||
/** | ||
* @internal | ||
* | ||
@@ -108,2 +120,9 @@ * Filter is considered passed if | ||
* | ||
* A function that maps the source value to the target value. | ||
* Defaults to pass-through with nullish check. | ||
*/ | ||
export type ValueMapper = (value: any) => any; | ||
/** | ||
* @internal | ||
* | ||
* A non-function value. | ||
@@ -128,7 +147,7 @@ */ | ||
*/ | ||
export declare function map(instructions: Record<string, ObjectMappingInstruction>): any; | ||
export declare function map(instructions: ObjectMappingInstructions): any; | ||
/** | ||
* @internal | ||
*/ | ||
export declare function map(target: any, instructions: Record<string, ObjectMappingInstruction>): typeof target; | ||
export declare function map(target: any, instructions: ObjectMappingInstructions): typeof target; | ||
/** | ||
@@ -141,1 +160,8 @@ * Convert a regular object `{ k: v }` to `{ k: [, v] }` mapping instruction set with default | ||
export declare const convertMap: (target: any) => Record<string, any>; | ||
/** | ||
* @param source - original object with data. | ||
* @param instructions - how to map the data. | ||
* @returns new object mapped from the source object. | ||
* @internal | ||
*/ | ||
export declare const take: (source: any, instructions: SourceMappingInstructions) => any; |
@@ -5,2 +5,6 @@ export type ObjectMappingInstructions = Record< | ||
>; | ||
export type SourceMappingInstructions = Record< | ||
string, | ||
ValueMapper | SourceMappingInstruction | ||
>; | ||
export type ObjectMappingInstruction = | ||
@@ -20,2 +24,7 @@ | LazyValueInstruction | ||
export type ConditionalValueInstruction = [ValueFilteringFunction, Value]; | ||
export type SourceMappingInstruction = [ | ||
ValueFilteringFunction?, | ||
ValueMapper?, | ||
string? | ||
]; | ||
export type FilterStatus = boolean | unknown | void; | ||
@@ -25,2 +34,3 @@ export type FilterStatusSupplier = () => boolean; | ||
export type ValueSupplier = () => any; | ||
export type ValueMapper = (value: any) => any; | ||
export type Value = any; | ||
@@ -32,9 +42,11 @@ export declare function map( | ||
): typeof target; | ||
export declare function map(instructions: ObjectMappingInstructions): any; | ||
export declare function map( | ||
instructions: Record<string, ObjectMappingInstruction> | ||
): any; | ||
export declare function map( | ||
target: any, | ||
instructions: Record<string, ObjectMappingInstruction> | ||
instructions: ObjectMappingInstructions | ||
): typeof target; | ||
export declare const convertMap: (target: any) => Record<string, any>; | ||
export declare const take: ( | ||
source: any, | ||
instructions: SourceMappingInstructions | ||
) => any; |
{ | ||
"name": "@aws-sdk/smithy-client", | ||
"version": "3.306.0", | ||
"version": "3.309.0", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
111513
2642