dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
27 lines (26 loc) • 995 B
JavaScript
import { $SET } from '../../../../../entity/actions/update/symbols/index.js';
import { Parser } from '../../../../../schema/actions/parse/index.js';
import { isObject } from '../../../../../utils/validation/isObject.js';
export const parseRecordExtension = (schema, input, { transform = true, valuePath } = {}) => {
if (isObject(input)) {
return {
isExtension: true,
*extensionParser() {
const parser = new Parser(schema).start(input, { fill: false, transform, valuePath });
const parsedValue = { [$SET]: parser.next().value };
if (transform) {
yield parsedValue;
}
else {
return parsedValue;
}
const transformedValue = { [$SET]: parser.next().value };
return transformedValue;
}
};
}
return {
isExtension: false,
unextendedInput: input
};
};