n8n-3867-progressively-apply-prettier-to-all (#3873)

* 🔨 formatting nodes with prettier
This commit is contained in:
Michael Kret
2022-08-17 18:50:24 +03:00
committed by GitHub
parent f2d326c7f0
commit 91d7e16c81
1072 changed files with 42357 additions and 59109 deletions

View File

@@ -1,21 +1,21 @@
import {
OptionsWithUri,
} from 'request';
import { OptionsWithUri } from 'request';
import {
IExecuteFunctions,
IExecuteSingleFunctions,
ILoadOptionsFunctions,
} from 'n8n-core';
import { IExecuteFunctions, IExecuteSingleFunctions, ILoadOptionsFunctions } from 'n8n-core';
import {
IDataObject, NodeApiError,
} from 'n8n-workflow';
import { IDataObject, NodeApiError } from 'n8n-workflow';
import moment from 'moment-timezone';
export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri: string | null = null): Promise<any> { // tslint:disable-line:no-any
export async function googleApiRequest(
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
method: string,
resource: string,
// tslint:disable-next-line:no-any
body: any = {},
qs: IDataObject = {},
uri: string | null = null,
// tslint:disable-next-line:no-any
): Promise<any> {
const options: OptionsWithUri = {
headers: {
'Content-Type': 'application/json',
@@ -35,14 +35,27 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
}
//@ts-ignore
return await this.helpers.requestOAuth2.call(this, 'googleFirebaseCloudFirestoreOAuth2Api', options);
return await this.helpers.requestOAuth2.call(
this,
'googleFirebaseCloudFirestoreOAuth2Api',
options,
);
} catch (error) {
throw new NodeApiError(this.getNode(), error);
}
}
export async function googleApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions, propertyName: string, method: string, endpoint: string, body: any = {}, query: IDataObject = {}, uri: string | null = null): Promise<any> { // tslint:disable-line:no-any
export async function googleApiRequestAllItems(
this: IExecuteFunctions | ILoadOptionsFunctions,
propertyName: string,
method: string,
endpoint: string,
// tslint:disable-next-line:no-any
body: any = {},
query: IDataObject = {},
uri: string | null = null,
// tslint:disable-next-line:no-any
): Promise<any> {
const returnData: IDataObject[] = [];
let responseData;
@@ -52,44 +65,42 @@ export async function googleApiRequestAllItems(this: IExecuteFunctions | ILoadOp
responseData = await googleApiRequest.call(this, method, endpoint, body, query, uri);
query.pageToken = responseData['nextPageToken'];
returnData.push.apply(returnData, responseData[propertyName]);
} while (
responseData['nextPageToken'] !== undefined &&
responseData['nextPageToken'] !== ''
);
} while (responseData['nextPageToken'] !== undefined && responseData['nextPageToken'] !== '');
return returnData;
}
const isValidDate = (str: string) => moment(str, ['YYYY-MM-DD HH:mm:ss Z', moment.ISO_8601], true).isValid();
const isValidDate = (str: string) =>
moment(str, ['YYYY-MM-DD HH:mm:ss Z', moment.ISO_8601], true).isValid();
// Both functions below were taken from Stack Overflow jsonToDocument was fixed as it was unable to handle null values correctly
// https://stackoverflow.com/questions/62246410/how-to-convert-a-firestore-document-to-plain-json-and-vice-versa
// Great thanks to https://stackoverflow.com/users/3915246/mahindar
export function jsonToDocument(value: string | number | IDataObject | IDataObject[]): IDataObject {
if (value === 'true' || value === 'false' || typeof value === 'boolean') {
return { 'booleanValue': value };
return { booleanValue: value };
} else if (value === null) {
return { 'nullValue': null };
return { nullValue: null };
} else if (!isNaN(value as number)) {
if (value.toString().indexOf('.') !== -1) {
return { 'doubleValue': value };
return { doubleValue: value };
} else {
return { 'integerValue': value };
return { integerValue: value };
}
} else if (isValidDate(value as string)) {
const date = new Date(Date.parse(value as string));
return { 'timestampValue': date.toISOString() };
return { timestampValue: date.toISOString() };
} else if (typeof value === 'string') {
return { 'stringValue': value };
return { stringValue: value };
} else if (value && value.constructor === Array) {
return { 'arrayValue': { values: value.map(v => jsonToDocument(v)) } };
return { arrayValue: { values: value.map((v) => jsonToDocument(v)) } };
} else if (typeof value === 'object') {
const obj = {};
for (const o of Object.keys(value)) {
//@ts-ignore
obj[o] = jsonToDocument(value[o]);
}
return { 'mapValue': { fields: obj } };
return { mapValue: { fields: obj } };
}
return {};
@@ -109,17 +120,33 @@ export function fullDocumentToJson(data: IDataObject): IDataObject {
};
}
export function documentToJson(fields: IDataObject): IDataObject {
if (fields === undefined) return {};
const result = {};
for (const f of Object.keys(fields)) {
const key = f, value = fields[f],
isDocumentType = ['stringValue', 'booleanValue', 'doubleValue',
'integerValue', 'timestampValue', 'mapValue', 'arrayValue', 'nullValue', 'geoPointValue'].find(t => t === key);
const key = f,
value = fields[f],
isDocumentType = [
'stringValue',
'booleanValue',
'doubleValue',
'integerValue',
'timestampValue',
'mapValue',
'arrayValue',
'nullValue',
'geoPointValue',
].find((t) => t === key);
if (isDocumentType) {
const item = ['stringValue', 'booleanValue', 'doubleValue', 'integerValue', 'timestampValue', 'nullValue', 'geoPointValue']
.find(t => t === key);
const item = [
'stringValue',
'booleanValue',
'doubleValue',
'integerValue',
'timestampValue',
'nullValue',
'geoPointValue',
].find((t) => t === key);
if (item) {
return value as IDataObject;
} else if ('mapValue' === key) {
@@ -129,7 +156,7 @@ export function documentToJson(fields: IDataObject): IDataObject {
// @ts-ignore
const list = value.values as IDataObject[];
// @ts-ignore
return !!list ? list.map(l => documentToJson(l)) : [];
return !!list ? list.map((l) => documentToJson(l)) : [];
}
} else {
// @ts-ignore