mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
refactor(core)!: Make getBinaryStream async (#7247)
Story: [PAY-846](https://linear.app/n8n/issue/PAY-846) | Related: https://github.com/n8n-io/n8n/pull/7225 For the S3 backend for external storage of binary data and execution data, the `getAsStream` method in the binary data manager interface used by FS and S3 will need to become async. This is a breaking change for nodes-base.
This commit is contained in:
@@ -138,21 +138,31 @@ export const binaryContentTypes = [
|
||||
export type BodyParametersReducer = (
|
||||
acc: IDataObject,
|
||||
cur: { name: string; value: string },
|
||||
) => IDataObject;
|
||||
) => Promise<IDataObject>;
|
||||
|
||||
export const prepareRequestBody = (
|
||||
export async function reduceAsync<T, R>(
|
||||
arr: T[],
|
||||
reducer: (acc: Awaited<Promise<R>>, cur: T) => Promise<R>,
|
||||
init: Promise<R> = Promise.resolve({} as R),
|
||||
): Promise<R> {
|
||||
return arr.reduce(async (promiseAcc, item) => {
|
||||
return reducer(await promiseAcc, item);
|
||||
}, init);
|
||||
}
|
||||
|
||||
export const prepareRequestBody = async (
|
||||
parameters: BodyParameter[],
|
||||
bodyType: string,
|
||||
version: number,
|
||||
defaultReducer: BodyParametersReducer,
|
||||
) => {
|
||||
if (bodyType === 'json' && version >= 4) {
|
||||
return parameters.reduce((acc, entry) => {
|
||||
const value = entry.value;
|
||||
set(acc, entry.name, value);
|
||||
return acc;
|
||||
}, {} as IDataObject);
|
||||
return parameters.reduce(async (acc, entry) => {
|
||||
const result = await acc;
|
||||
set(result, entry.name, entry.value);
|
||||
return result;
|
||||
}, Promise.resolve({}));
|
||||
} else {
|
||||
return parameters.reduce(defaultReducer, {});
|
||||
return reduceAsync(parameters, defaultReducer);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user