fix(AWS DynamoDB Node): Add missing type assertion (no-changelog) (#5003)

fix(AWS DynamoDB Node): add type assertion
This commit is contained in:
Csaba Tuncsik 2022-12-22 10:27:14 +01:00 committed by GitHub
parent 87d8865ad3
commit e4785da2e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 3 deletions

View file

@ -1,4 +1,4 @@
import { deepCopy, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { deepCopy, IDataObject, INodeExecutionData, assert } from 'n8n-workflow';
import {
AdjustedPutItem,
@ -82,7 +82,11 @@ function decodeAttribute(type: AttributeValueType, attribute: string | IAttribut
case 'NS':
return attribute;
case 'M':
return simplify(attribute as IAttributeValue);
assert(
typeof attribute === 'object' && !Array.isArray(attribute) && attribute !== null,
'Attribute must be an object',
);
return simplify(attribute);
default:
return null;
}

View file

@ -18,7 +18,7 @@ export * from './WorkflowErrors';
export * from './WorkflowHooks';
export * from './VersionedNodeType';
export { LoggerProxy, NodeHelpers, ObservableObject, TelemetryHelpers };
export { deepCopy, jsonParse, sleep, fileTypeFromMimeType } from './utils';
export { deepCopy, jsonParse, sleep, fileTypeFromMimeType, assert } from './utils';
export {
isINodeProperties,
isINodePropertyOptions,

View file

@ -74,3 +74,21 @@ export function fileTypeFromMimeType(mimeType: string): BinaryFileType | undefin
if (mimeType.startsWith('text/')) return 'text';
return;
}
export function assert<T>(condition: T, msg?: string): asserts condition {
if (!condition) {
const error = new Error(msg ?? 'Invalid assertion');
// hide assert stack frame if supported
if (Error.hasOwnProperty('captureStackTrace')) {
// V8 only - https://nodejs.org/api/errors.html#errors_error_capturestacktrace_targetobject_constructoropt
Error.captureStackTrace(error, assert);
} else if (error.stack) {
// fallback for IE and Firefox
error.stack = error.stack
.split('\n')
.slice(1) // skip assert function from stack frames
.join('\n');
}
throw error;
}
}