mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
n8n-3867-progressively-apply-prettier-to-all (#3873)
* 🔨 formatting nodes with prettier
This commit is contained in:
@@ -1,17 +1,8 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
import { OptionsWithUri } from 'request';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
IPollFunctions,
|
||||
NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
import { IDataObject, ILoadOptionsFunctions, IPollFunctions, NodeApiError } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
TDtableMetadataColumns,
|
||||
@@ -20,9 +11,7 @@ import {
|
||||
TEndpointVariableName,
|
||||
} from './types';
|
||||
|
||||
import {
|
||||
schema,
|
||||
} from './Schema';
|
||||
import { schema } from './Schema';
|
||||
|
||||
import {
|
||||
ICredential,
|
||||
@@ -36,8 +25,18 @@ import {
|
||||
|
||||
import _ from 'lodash';
|
||||
|
||||
export async function seaTableApiRequest(this: IExecuteFunctions | ILoadOptionsFunctions | IPollFunctions, ctx: ICtx, method: string, endpoint: string, body: any = {}, qs: IDataObject = {}, url: string | undefined = undefined, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
export async function seaTableApiRequest(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions | IPollFunctions,
|
||||
ctx: ICtx,
|
||||
method: string,
|
||||
endpoint: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
body: any = {},
|
||||
qs: IDataObject = {},
|
||||
url: string | undefined = undefined,
|
||||
option: IDataObject = {},
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const credentials = await this.getCredentials('seaTableApi');
|
||||
|
||||
ctx.credentials = credentials as unknown as ICredential;
|
||||
@@ -71,8 +70,16 @@ export async function seaTableApiRequest(this: IExecuteFunctions | ILoadOptionsF
|
||||
}
|
||||
}
|
||||
|
||||
export async function setableApiRequestAllItems(this: IExecuteFunctions | IPollFunctions, ctx: ICtx, propertyName: string, method: string, endpoint: string, body: IDataObject, query?: IDataObject): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
export async function setableApiRequestAllItems(
|
||||
this: IExecuteFunctions | IPollFunctions,
|
||||
ctx: ICtx,
|
||||
propertyName: string,
|
||||
method: string,
|
||||
endpoint: string,
|
||||
body: IDataObject,
|
||||
query?: IDataObject,
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
if (query === undefined) {
|
||||
query = {};
|
||||
}
|
||||
@@ -85,7 +92,14 @@ export async function setableApiRequestAllItems(this: IExecuteFunctions | IPollF
|
||||
let responseData;
|
||||
|
||||
do {
|
||||
responseData = await seaTableApiRequest.call(this, ctx, method, endpoint, body, query) as unknown as IRow[];
|
||||
responseData = (await seaTableApiRequest.call(
|
||||
this,
|
||||
ctx,
|
||||
method,
|
||||
endpoint,
|
||||
body,
|
||||
query,
|
||||
)) as unknown as IRow[];
|
||||
//@ts-ignore
|
||||
returnData.push.apply(returnData, responseData[propertyName]);
|
||||
query.start = +query.start + segment;
|
||||
@@ -94,9 +108,19 @@ export async function setableApiRequestAllItems(this: IExecuteFunctions | IPollF
|
||||
return returnData;
|
||||
}
|
||||
|
||||
|
||||
export async function getTableColumns(this: ILoadOptionsFunctions | IExecuteFunctions | IPollFunctions, tableName: string, ctx: ICtx = {}): Promise<TDtableMetadataColumns> {
|
||||
const { metadata: { tables } } = await seaTableApiRequest.call(this, ctx, 'GET', `/dtable-server/api/v1/dtables/{{dtable_uuid}}/metadata`);
|
||||
export async function getTableColumns(
|
||||
this: ILoadOptionsFunctions | IExecuteFunctions | IPollFunctions,
|
||||
tableName: string,
|
||||
ctx: ICtx = {},
|
||||
): Promise<TDtableMetadataColumns> {
|
||||
const {
|
||||
metadata: { tables },
|
||||
} = await seaTableApiRequest.call(
|
||||
this,
|
||||
ctx,
|
||||
'GET',
|
||||
`/dtable-server/api/v1/dtables/{{dtable_uuid}}/metadata`,
|
||||
);
|
||||
for (const table of tables) {
|
||||
if (table.name === tableName) {
|
||||
return table.columns;
|
||||
@@ -105,13 +129,26 @@ export async function getTableColumns(this: ILoadOptionsFunctions | IExecuteFunc
|
||||
return [];
|
||||
}
|
||||
|
||||
export async function getTableViews(this: ILoadOptionsFunctions | IExecuteFunctions, tableName: string, ctx: ICtx = {}): Promise<TDtableViewColumns> {
|
||||
const { views } = await seaTableApiRequest.call(this, ctx, 'GET', `/dtable-server/api/v1/dtables/{{dtable_uuid}}/views`, {}, { table_name: tableName });
|
||||
export async function getTableViews(
|
||||
this: ILoadOptionsFunctions | IExecuteFunctions,
|
||||
tableName: string,
|
||||
ctx: ICtx = {},
|
||||
): Promise<TDtableViewColumns> {
|
||||
const { views } = await seaTableApiRequest.call(
|
||||
this,
|
||||
ctx,
|
||||
'GET',
|
||||
`/dtable-server/api/v1/dtables/{{dtable_uuid}}/views`,
|
||||
{},
|
||||
{ table_name: tableName },
|
||||
);
|
||||
return views;
|
||||
}
|
||||
|
||||
export async function getBaseAccessToken(this: IExecuteFunctions | ILoadOptionsFunctions | IPollFunctions, ctx: ICtx) {
|
||||
|
||||
export async function getBaseAccessToken(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions | IPollFunctions,
|
||||
ctx: ICtx,
|
||||
) {
|
||||
if (ctx?.base?.access_token !== undefined) {
|
||||
return;
|
||||
}
|
||||
@@ -128,8 +165,9 @@ export async function getBaseAccessToken(this: IExecuteFunctions | ILoadOptionsF
|
||||
}
|
||||
|
||||
export function resolveBaseUri(ctx: ICtx) {
|
||||
return (ctx?.credentials?.environment === 'cloudHosted')
|
||||
? 'https://cloud.seatable.io' : userBaseUri(ctx?.credentials?.domain);
|
||||
return ctx?.credentials?.environment === 'cloudHosted'
|
||||
? 'https://cloud.seatable.io'
|
||||
: userBaseUri(ctx?.credentials?.domain);
|
||||
}
|
||||
|
||||
export function simplify(data: { results: IRow[] }, metadata: IDataObject) {
|
||||
@@ -144,32 +182,37 @@ export function simplify(data: { results: IRow[] }, metadata: IDataObject) {
|
||||
});
|
||||
}
|
||||
|
||||
export function getColumns(data: { metadata: [{ key: string, name: string }] }) {
|
||||
return data.metadata.reduce((obj, value) => Object.assign(obj, { [`${value.key}`]: value.name }), {});
|
||||
export function getColumns(data: { metadata: [{ key: string; name: string }] }) {
|
||||
return data.metadata.reduce(
|
||||
(obj, value) => Object.assign(obj, { [`${value.key}`]: value.name }),
|
||||
{},
|
||||
);
|
||||
}
|
||||
|
||||
export function getDownloadableColumns(data: { metadata: [{ key: string, name: string, type: string }] }) {
|
||||
return data.metadata.filter(row => (['image', 'file'].includes(row.type))).map(row => row.name);
|
||||
export function getDownloadableColumns(data: {
|
||||
metadata: [{ key: string; name: string; type: string }];
|
||||
}) {
|
||||
return data.metadata.filter((row) => ['image', 'file'].includes(row.type)).map((row) => row.name);
|
||||
}
|
||||
|
||||
const uniquePredicate = (current: string, index: number, all: string[]) => all.indexOf(current) === index;
|
||||
const uniquePredicate = (current: string, index: number, all: string[]) =>
|
||||
all.indexOf(current) === index;
|
||||
const nonInternalPredicate = (name: string) => !Object.keys(schema.internalNames).includes(name);
|
||||
const namePredicate = (name: string) => (named: IName) => named.name === name;
|
||||
export const nameOfPredicate = (names: ReadonlyArray<IName>) => (name: string) => names.find(namePredicate(name));
|
||||
export const nameOfPredicate = (names: ReadonlyArray<IName>) => (name: string) =>
|
||||
names.find(namePredicate(name));
|
||||
|
||||
export function columnNamesToArray(columnNames: string): string[] {
|
||||
return columnNames
|
||||
? split(columnNames)
|
||||
.filter(nonInternalPredicate)
|
||||
.filter(uniquePredicate)
|
||||
: []
|
||||
;
|
||||
return columnNames ? split(columnNames).filter(nonInternalPredicate).filter(uniquePredicate) : [];
|
||||
}
|
||||
|
||||
export function columnNamesGlob(columnNames: string[], dtableColumns: TDtableMetadataColumns): string[] {
|
||||
export function columnNamesGlob(
|
||||
columnNames: string[],
|
||||
dtableColumns: TDtableMetadataColumns,
|
||||
): string[] {
|
||||
const buffer: string[] = [];
|
||||
const names: string[] = dtableColumns.map(c => c.name).filter(nonInternalPredicate);
|
||||
columnNames.forEach(columnName => {
|
||||
const names: string[] = dtableColumns.map((c) => c.name).filter(nonInternalPredicate);
|
||||
columnNames.forEach((columnName) => {
|
||||
if (columnName !== '*') {
|
||||
buffer.push(columnName);
|
||||
return;
|
||||
@@ -190,13 +233,13 @@ export function rowsSequence(rows: IRow[]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < l;) {
|
||||
for (let i = 0; i < l; ) {
|
||||
rows[i]._seq = ++i;
|
||||
}
|
||||
}
|
||||
|
||||
export function rowDeleteInternalColumns(row: IRow): IRow {
|
||||
Object.keys(schema.internalNames).forEach(columnName => delete row[columnName]);
|
||||
Object.keys(schema.internalNames).forEach((columnName) => delete row[columnName]);
|
||||
return row;
|
||||
}
|
||||
|
||||
@@ -213,7 +256,7 @@ function rowFormatColumn(input: unknown): boolean | number | string | string[] |
|
||||
return input;
|
||||
}
|
||||
|
||||
if (Array.isArray(input) && input.every(i => (typeof i === 'string'))) {
|
||||
if (Array.isArray(input) && input.every((i) => typeof i === 'string')) {
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -242,8 +285,8 @@ export function rowMapKeyToName(row: IRow, columns: TDtableMetadataColumns): IRo
|
||||
});
|
||||
|
||||
// pick each by its key for name
|
||||
Object.keys(row).forEach(key => {
|
||||
const column = columns.find(c => c.key === key);
|
||||
Object.keys(row).forEach((key) => {
|
||||
const column = columns.find((c) => c.key === key);
|
||||
if (column) {
|
||||
mappedRow[column.name] = row[key];
|
||||
}
|
||||
@@ -278,20 +321,21 @@ function endpointCtxExpr(this: void, ctx: ICtx, endpoint: string): string {
|
||||
endpointVariables.access_token = ctx?.base?.access_token;
|
||||
endpointVariables.dtable_uuid = ctx?.base?.dtable_uuid;
|
||||
|
||||
return endpoint.replace(/({{ *(access_token|dtable_uuid|server) *}})/g, (match: string, expr: string, name: TEndpointVariableName) => {
|
||||
return endpointVariables[name] || match;
|
||||
}) as TEndpointResolvedExpr;
|
||||
return endpoint.replace(
|
||||
/({{ *(access_token|dtable_uuid|server) *}})/g,
|
||||
(match: string, expr: string, name: TEndpointVariableName) => {
|
||||
return endpointVariables[name] || match;
|
||||
},
|
||||
) as TEndpointResolvedExpr;
|
||||
}
|
||||
|
||||
|
||||
const normalize = (subject: string): string => subject ? subject.normalize() : '';
|
||||
const normalize = (subject: string): string => (subject ? subject.normalize() : '');
|
||||
|
||||
export const split = (subject: string): string[] =>
|
||||
normalize(subject)
|
||||
.split(/\s*((?:[^\\,]*?(?:\\[\s\S])*)*?)\s*(?:,|$)/)
|
||||
.filter(s => s.length)
|
||||
.map(s => s.replace(/\\([\s\S])/gm, ($0, $1) => $1))
|
||||
;
|
||||
.filter((s) => s.length)
|
||||
.map((s) => s.replace(/\\([\s\S])/gm, ($0, $1) => $1));
|
||||
|
||||
const userBaseUri = (uri?: string) => {
|
||||
if (uri === undefined) {
|
||||
|
||||
Reference in New Issue
Block a user