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,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) {

View File

@@ -72,7 +72,6 @@ export interface IName {
name: string;
}
type TOperation = 'cloudHosted' | 'selfHosted';
export interface ICredential {
@@ -91,12 +90,12 @@ export interface ICtx {
credentials?: ICredential;
}
export interface IRowResponse{
export interface IRowResponse {
metadata: [
{
key: string,
name: string,
}
key: string;
name: string;
},
];
results: IRow[];
}

View File

@@ -1,6 +1,4 @@
import {
INodeProperties,
} from 'n8n-workflow';
import { INodeProperties } from 'n8n-workflow';
export const rowOperations: INodeProperties[] = [
{
@@ -61,13 +59,12 @@ export const rowFields: INodeProperties[] = [
},
displayOptions: {
hide: {
operation: [
'get',
],
operation: ['get'],
},
},
default: '',
description: 'The name of SeaTable table to access. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
description:
'The name of SeaTable table to access. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
},
{
displayName: 'Table Name or ID',
@@ -80,13 +77,12 @@ export const rowFields: INodeProperties[] = [
},
displayOptions: {
show: {
operation: [
'get',
],
operation: ['get'],
},
},
default: '',
description: 'The name of SeaTable table to access. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
description:
'The name of SeaTable table to access. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
},
// ----------------------------------
@@ -98,9 +94,7 @@ export const rowFields: INodeProperties[] = [
type: 'string',
displayOptions: {
show: {
operation: [
'update',
],
operation: ['update'],
},
},
default: '',
@@ -127,10 +121,7 @@ export const rowFields: INodeProperties[] = [
],
displayOptions: {
show: {
operation: [
'create',
'update',
],
operation: ['create', 'update'],
},
},
default: 'defineBelow',
@@ -142,17 +133,13 @@ export const rowFields: INodeProperties[] = [
type: 'string',
displayOptions: {
show: {
operation: [
'create',
'update',
],
fieldsToSend: [
'autoMapInputData',
],
operation: ['create', 'update'],
fieldsToSend: ['autoMapInputData'],
},
},
default: '',
description: 'List of input properties to avoid sending, separated by commas. Leave empty to send all properties.',
description:
'List of input properties to avoid sending, separated by commas. Leave empty to send all properties.',
placeholder: 'Enter properties...',
},
{
@@ -173,11 +160,10 @@ export const rowFields: INodeProperties[] = [
displayName: 'Column Name or ID',
name: 'columnName',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
typeOptions: {
loadOptionsDependsOn: [
'table',
],
loadOptionsDependsOn: ['table'],
loadOptionsMethod: 'getTableUpdateAbleColumns',
},
default: '',
@@ -193,13 +179,8 @@ export const rowFields: INodeProperties[] = [
],
displayOptions: {
show: {
operation: [
'create',
'update',
],
fieldsToSend: [
'defineBelow',
],
operation: ['create', 'update'],
fieldsToSend: ['defineBelow'],
},
},
default: {},
@@ -214,9 +195,7 @@ export const rowFields: INodeProperties[] = [
type: 'string',
displayOptions: {
show: {
operation: [
'delete',
],
operation: ['delete'],
},
},
default: '',
@@ -231,9 +210,7 @@ export const rowFields: INodeProperties[] = [
type: 'string',
displayOptions: {
show: {
operation: [
'get',
],
operation: ['get'],
},
},
default: '',
@@ -248,9 +225,7 @@ export const rowFields: INodeProperties[] = [
type: 'boolean',
displayOptions: {
show: {
operation: [
'getAll',
],
operation: ['getAll'],
},
},
default: true,
@@ -262,12 +237,8 @@ export const rowFields: INodeProperties[] = [
type: 'number',
displayOptions: {
show: {
operation: [
'getAll',
],
returnAll: [
false,
],
operation: ['getAll'],
returnAll: [false],
},
},
typeOptions: {
@@ -285,9 +256,7 @@ export const rowFields: INodeProperties[] = [
default: {},
displayOptions: {
show: {
operation: [
'getAll',
],
operation: ['getAll'],
},
},
options: [
@@ -295,7 +264,8 @@ export const rowFields: INodeProperties[] = [
displayName: 'View Name or ID',
name: 'view_name',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
typeOptions: {
loadOptionsMethod: 'getViews',
},
@@ -311,9 +281,7 @@ export const rowFields: INodeProperties[] = [
default: {},
displayOptions: {
show: {
operation: [
'getAll',
],
operation: ['getAll'],
},
},
options: [
@@ -322,7 +290,8 @@ export const rowFields: INodeProperties[] = [
name: 'convert_link_id',
type: 'boolean',
default: false,
description: 'Whether the link column in the returned row is the ID of the linked row or the name of the linked row',
description:
'Whether the link column in the returned row is the ID of the linked row or the name of the linked row',
},
{
displayName: 'Direction',
@@ -350,7 +319,8 @@ export const rowFields: INodeProperties[] = [
loadOptionsMethod: 'getAllSortableColumns',
},
default: '',
description: 'A column\'s name or ID, use this column to sort the rows. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
description:
'A column\'s name or ID, use this column to sort the rows. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
},
],
},

View File

@@ -1,49 +1,49 @@
import {TColumnType, TDateTimeFormat, TInheritColumnKey} from './types';
import { TColumnType, TDateTimeFormat, TInheritColumnKey } from './types';
export type ColumnType = keyof typeof schema.columnTypes;
export const schema = {
rowFetchSegmentLimit: 1000,
dateTimeFormat: 'YYYY-MM-DDTHH:mm:ss.SSSZ',
internalNames: {
'_id': 'text',
'_creator': 'creator',
'_ctime': 'ctime',
'_last_modifier': 'last-modifier',
'_mtime': 'mtime',
'_seq': 'auto-number',
},
columnTypes: {
text: 'Text',
'long-text': 'Long Text',
number: 'Number',
collaborator: 'Collaborator',
date: 'Date',
duration: 'Duration',
'single-select': 'Single Select',
'multiple-select': 'Multiple Select',
email: 'Email',
url: 'URL',
'rate': 'Rating',
checkbox: 'Checkbox',
formula: 'Formula',
creator: 'Creator',
ctime: 'Created time',
'last-modifier': 'Last Modifier',
mtime: 'Last modified time',
'auto-number': 'Auto number',
},
nonUpdateAbleColumnTypes: {
'creator': 'creator',
'ctime': 'ctime',
'last-modifier': 'last-modifier',
'mtime': 'mtime',
'auto-number': 'auto-number',
},
rowFetchSegmentLimit: 1000,
dateTimeFormat: 'YYYY-MM-DDTHH:mm:ss.SSSZ',
internalNames: {
_id: 'text',
_creator: 'creator',
_ctime: 'ctime',
_last_modifier: 'last-modifier',
_mtime: 'mtime',
_seq: 'auto-number',
},
columnTypes: {
text: 'Text',
'long-text': 'Long Text',
number: 'Number',
collaborator: 'Collaborator',
date: 'Date',
duration: 'Duration',
'single-select': 'Single Select',
'multiple-select': 'Multiple Select',
email: 'Email',
url: 'URL',
rate: 'Rating',
checkbox: 'Checkbox',
formula: 'Formula',
creator: 'Creator',
ctime: 'Created time',
'last-modifier': 'Last Modifier',
mtime: 'Last modified time',
'auto-number': 'Auto number',
},
nonUpdateAbleColumnTypes: {
creator: 'creator',
ctime: 'ctime',
'last-modifier': 'last-modifier',
mtime: 'mtime',
'auto-number': 'auto-number',
},
} as {
rowFetchSegmentLimit: number,
dateTimeFormat: TDateTimeFormat,
internalNames: { [key in TInheritColumnKey]: ColumnType }
columnTypes: { [key in TColumnType]: string }
nonUpdateAbleColumnTypes: { [key in ColumnType]: ColumnType }
rowFetchSegmentLimit: number;
dateTimeFormat: TDateTimeFormat;
internalNames: { [key in TInheritColumnKey]: ColumnType };
columnTypes: { [key in TColumnType]: string };
nonUpdateAbleColumnTypes: { [key in ColumnType]: ColumnType };
};

View File

@@ -1,6 +1,4 @@
import {
IExecuteFunctions,
} from 'n8n-core';
import { IExecuteFunctions } from 'n8n-core';
import {
IDataObject,
@@ -24,21 +22,11 @@ import {
updateAble,
} from './GenericFunctions';
import {
rowFields,
rowOperations,
} from './RowDescription';
import { rowFields, rowOperations } from './RowDescription';
import {
TColumnsUiValues,
TColumnValue,
} from './types';
import { TColumnsUiValues, TColumnValue } from './types';
import {
ICtx,
IRow,
IRowObject,
} from './Interfaces';
import { ICtx, IRow, IRowObject } from './Interfaces';
export class SeaTable implements INodeType {
description: INodeTypeDescription = {
@@ -83,7 +71,14 @@ export class SeaTable implements INodeType {
loadOptions: {
async getTableNames(this: ILoadOptionsFunctions) {
const returnData: INodePropertyOptions[] = [];
const { metadata: { tables } } = await seaTableApiRequest.call(this, {}, 'GET', `/dtable-server/api/v1/dtables/{{dtable_uuid}}/metadata`);
const {
metadata: { tables },
} = await seaTableApiRequest.call(
this,
{},
'GET',
`/dtable-server/api/v1/dtables/{{dtable_uuid}}/metadata`,
);
for (const table of tables) {
returnData.push({
name: table.name,
@@ -94,7 +89,14 @@ export class SeaTable implements INodeType {
},
async getTableIds(this: ILoadOptionsFunctions) {
const returnData: INodePropertyOptions[] = [];
const { metadata: { tables } } = await seaTableApiRequest.call(this, {}, 'GET', `/dtable-server/api/v1/dtables/{{dtable_uuid}}/metadata`);
const {
metadata: { tables },
} = await seaTableApiRequest.call(
this,
{},
'GET',
`/dtable-server/api/v1/dtables/{{dtable_uuid}}/metadata`,
);
for (const table of tables) {
returnData.push({
name: table.name,
@@ -106,18 +108,25 @@ export class SeaTable implements INodeType {
async getTableUpdateAbleColumns(this: ILoadOptionsFunctions) {
const tableName = this.getNodeParameter('tableName') as string;
const columns = await getTableColumns.call(this, tableName,);
return columns.filter(column => column.editable).map(column => ({ name: column.name, value: column.name }));
const columns = await getTableColumns.call(this, tableName);
return columns
.filter((column) => column.editable)
.map((column) => ({ name: column.name, value: column.name }));
},
async getAllSortableColumns(this: ILoadOptionsFunctions) {
const tableName = this.getNodeParameter('tableName') as string;
const columns = await getTableColumns.call(this, tableName);
return columns.filter(column => !['file', 'image', 'url', 'collaborator', 'long-text'].includes(column.type)).map(column => ({ name: column.name, value: column.name }));
return columns
.filter(
(column) =>
!['file', 'image', 'url', 'collaborator', 'long-text'].includes(column.type),
)
.map((column) => ({ name: column.name, value: column.name }));
},
async getViews(this: ILoadOptionsFunctions) {
const tableName = this.getNodeParameter('tableName') as string;
const views = await getTableViews.call(this, tableName);
return views.map(view => ({ name: view.name, value: view.name }));
return views.map((view) => ({ name: view.name, value: view.name }));
},
},
};
@@ -145,7 +154,9 @@ export class SeaTable implements INodeType {
body.table_name = tableName;
const fieldsToSend = this.getNodeParameter('fieldsToSend', 0) as 'defineBelow' | 'autoMapInputData';
const fieldsToSend = this.getNodeParameter('fieldsToSend', 0) as
| 'defineBelow'
| 'autoMapInputData';
let rowInput: IRowObject = {};
for (let i = 0; i < items.length; i++) {
@@ -153,37 +164,67 @@ export class SeaTable implements INodeType {
try {
if (fieldsToSend === 'autoMapInputData') {
const incomingKeys = Object.keys(items[i].json);
const inputDataToIgnore = split(this.getNodeParameter('inputsToIgnore', i, '') as string);
const inputDataToIgnore = split(
this.getNodeParameter('inputsToIgnore', i, '') as string,
);
for (const key of incomingKeys) {
if (inputDataToIgnore.includes(key)) continue;
rowInput[key] = items[i].json[key] as TColumnValue;
}
} else {
const columns = this.getNodeParameter('columnsUi.columnValues', i, []) as TColumnsUiValues;
const columns = this.getNodeParameter(
'columnsUi.columnValues',
i,
[],
) as TColumnsUiValues;
for (const column of columns) {
rowInput[column.columnName] = column.columnValue;
}
}
body.row = rowExport(rowInput, updateAble(tableColumns));
responseData = await seaTableApiRequest.call(this, ctx, 'POST', `/dtable-server/api/v1/dtables/{{dtable_uuid}}/rows/`, body);
responseData = await seaTableApiRequest.call(
this,
ctx,
'POST',
`/dtable-server/api/v1/dtables/{{dtable_uuid}}/rows/`,
body,
);
const { _id: insertId } = responseData;
if (insertId === undefined) {
throw new NodeOperationError(this.getNode(), 'SeaTable: No identity after appending row.', { itemIndex: i });
throw new NodeOperationError(
this.getNode(),
'SeaTable: No identity after appending row.',
{ itemIndex: i },
);
}
const newRowInsertData = rowMapKeyToName(responseData, tableColumns);
qs.table_name = tableName;
qs.convert = true;
const newRow = await seaTableApiRequest.call(this, ctx, 'GET', `/dtable-server/api/v1/dtables/{{dtable_uuid}}/rows/${encodeURIComponent(insertId)}/`, body, qs);
const newRow = await seaTableApiRequest.call(
this,
ctx,
'GET',
`/dtable-server/api/v1/dtables/{{dtable_uuid}}/rows/${encodeURIComponent(insertId)}/`,
body,
qs,
);
if (newRow._id === undefined) {
throw new NodeOperationError(this.getNode(), 'SeaTable: No identity for appended row.', { itemIndex: i });
throw new NodeOperationError(
this.getNode(),
'SeaTable: No identity for appended row.',
{ itemIndex: i },
);
}
const row = rowFormatColumns({ ...newRowInsertData, ...newRow }, tableColumns.map(({ name }) => name).concat(['_id', '_ctime', '_mtime']));
const row = rowFormatColumns(
{ ...newRowInsertData, ...newRow },
tableColumns.map(({ name }) => name).concat(['_id', '_ctime', '_mtime']),
);
returnData.push(row);
} catch (error) {
@@ -199,9 +240,15 @@ export class SeaTable implements INodeType {
try {
const tableId = this.getNodeParameter('tableId', 0) as string;
const rowId = this.getNodeParameter('rowId', i) as string;
const response = await seaTableApiRequest.call(this, ctx, 'GET', `/dtable-server/api/v1/dtables/{{dtable_uuid}}/rows/${rowId}`, {}, { table_id: tableId, convert: true }) as IDataObject;
const response = (await seaTableApiRequest.call(
this,
ctx,
'GET',
`/dtable-server/api/v1/dtables/{{dtable_uuid}}/rows/${rowId}`,
{},
{ table_id: tableId, convert: true },
)) as IDataObject;
returnData.push(response);
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ error: error.message });
@@ -229,14 +276,27 @@ export class SeaTable implements INodeType {
Object.assign(qs, filters, options);
if (returnAll) {
responseData = await setableApiRequestAllItems.call(this, ctx, 'rows', 'GET', endpoint, body, qs);
responseData = await setableApiRequestAllItems.call(
this,
ctx,
'rows',
'GET',
endpoint,
body,
qs,
);
} else {
qs.limit = this.getNodeParameter('limit', 0) as number;
responseData = await seaTableApiRequest.call(this, ctx, 'GET', endpoint, body, qs);
responseData = responseData.rows;
}
const rows = responseData.map((row: IRow) => rowFormatColumns({ ...row }, tableColumns.map(({ name }) => name).concat(['_id', '_ctime', '_mtime'])));
const rows = responseData.map((row: IRow) =>
rowFormatColumns(
{ ...row },
tableColumns.map(({ name }) => name).concat(['_id', '_ctime', '_mtime']),
),
);
returnData.push(...rows);
}
@@ -255,7 +315,14 @@ export class SeaTable implements INodeType {
table_name: tableName,
row_id: rowId,
};
const response = await seaTableApiRequest.call(this, ctx, 'DELETE', `/dtable-server/api/v1/dtables/{{dtable_uuid}}/rows/`, body, qs) as IDataObject;
const response = (await seaTableApiRequest.call(
this,
ctx,
'DELETE',
`/dtable-server/api/v1/dtables/{{dtable_uuid}}/rows/`,
body,
qs,
)) as IDataObject;
returnData.push(response);
} catch (error) {
if (this.continueOnFail()) {
@@ -275,7 +342,9 @@ export class SeaTable implements INodeType {
body.table_name = tableName;
const fieldsToSend = this.getNodeParameter('fieldsToSend', 0) as 'defineBelow' | 'autoMapInputData';
const fieldsToSend = this.getNodeParameter('fieldsToSend', 0) as
| 'defineBelow'
| 'autoMapInputData';
let rowInput: IRowObject = {};
for (let i = 0; i < items.length; i++) {
@@ -284,13 +353,19 @@ export class SeaTable implements INodeType {
try {
if (fieldsToSend === 'autoMapInputData') {
const incomingKeys = Object.keys(items[i].json);
const inputDataToIgnore = split(this.getNodeParameter('inputsToIgnore', i, '') as string);
const inputDataToIgnore = split(
this.getNodeParameter('inputsToIgnore', i, '') as string,
);
for (const key of incomingKeys) {
if (inputDataToIgnore.includes(key)) continue;
rowInput[key] = items[i].json[key] as TColumnValue;
}
} else {
const columns = this.getNodeParameter('columnsUi.columnValues', i, []) as TColumnsUiValues;
const columns = this.getNodeParameter(
'columnsUi.columnValues',
i,
[],
) as TColumnsUiValues;
for (const column of columns) {
rowInput[column.columnName] = column.columnValue;
}
@@ -298,9 +373,15 @@ export class SeaTable implements INodeType {
body.row = rowExport(rowInput, updateAble(tableColumns));
body.table_name = tableName;
body.row_id = rowId;
responseData = await seaTableApiRequest.call(this, ctx, 'PUT', `/dtable-server/api/v1/dtables/{{dtable_uuid}}/rows/`, body);
responseData = await seaTableApiRequest.call(
this,
ctx,
'PUT',
`/dtable-server/api/v1/dtables/{{dtable_uuid}}/rows/`,
body,
);
returnData.push({ _id: rowId, ... responseData });
returnData.push({ _id: rowId, ...responseData });
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ error: error.message });

View File

@@ -1,6 +1,4 @@
import {
IPollFunctions,
} from 'n8n-core';
import { IPollFunctions } from 'n8n-core';
import {
IDataObject,
@@ -11,18 +9,9 @@ import {
INodeTypeDescription,
} from 'n8n-workflow';
import {
getColumns,
rowFormatColumns,
seaTableApiRequest,
simplify,
} from './GenericFunctions';
import { getColumns, rowFormatColumns, seaTableApiRequest, simplify } from './GenericFunctions';
import {
ICtx,
IRow,
IRowResponse,
} from './Interfaces';
import { ICtx, IRow, IRowResponse } from './Interfaces';
import moment from 'moment';
@@ -57,7 +46,8 @@ export class SeaTableTrigger implements INodeType {
loadOptionsMethod: 'getTableNames',
},
default: '',
description: 'The name of SeaTable table to access. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
description:
'The name of SeaTable table to access. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
},
{
displayName: 'Event',
@@ -82,7 +72,8 @@ export class SeaTableTrigger implements INodeType {
name: 'simple',
type: 'boolean',
default: true,
description: 'Whether to return a simplified version of the response instead of the raw data',
description:
'Whether to return a simplified version of the response instead of the raw data',
},
],
};
@@ -91,7 +82,14 @@ export class SeaTableTrigger implements INodeType {
loadOptions: {
async getTableNames(this: ILoadOptionsFunctions) {
const returnData: INodePropertyOptions[] = [];
const { metadata: { tables } } = await seaTableApiRequest.call(this, {}, 'GET', `/dtable-server/api/v1/dtables/{{dtable_uuid}}/metadata`);
const {
metadata: { tables },
} = await seaTableApiRequest.call(
this,
{},
'GET',
`/dtable-server/api/v1/dtables/{{dtable_uuid}}/metadata`,
);
for (const table of tables) {
returnData.push({
name: table.name,
@@ -111,29 +109,27 @@ export class SeaTableTrigger implements INodeType {
const ctx: ICtx = {};
const credentials = await this.getCredentials('seaTableApi');
const timezone = credentials.timezone as string || 'Europe/Berlin';
const timezone = (credentials.timezone as string) || 'Europe/Berlin';
const now = moment().utc().format();
const startDate = webhookData.lastTimeChecked as string || now;
const startDate = (webhookData.lastTimeChecked as string) || now;
const endDate = now;
webhookData.lastTimeChecked = endDate;
let rows;
const filterField = (event === 'rowCreated') ? '_ctime' : '_mtime';
const filterField = event === 'rowCreated' ? '_ctime' : '_mtime';
const endpoint = `/dtable-db/api/v1/query/{{dtable_uuid}}/`;
if (this.getMode() === 'manual') {
rows = await seaTableApiRequest.call(this, ctx, 'POST', endpoint, { sql: `SELECT * FROM ${tableName} LIMIT 1` }) as IRowResponse;
rows = (await seaTableApiRequest.call(this, ctx, 'POST', endpoint, {
sql: `SELECT * FROM ${tableName} LIMIT 1`,
})) as IRowResponse;
} else {
rows = (await seaTableApiRequest.call(this, ctx, 'POST', endpoint, {
sql: `SELECT * FROM ${tableName}
WHERE ${filterField} BETWEEN "${moment(startDate)
.tz(timezone)
.format('YYYY-MM-D HH:mm:ss')}"
AND "${moment(endDate)
.tz(timezone)
.format('YYYY-MM-D HH:mm:ss')}"`,
WHERE ${filterField} BETWEEN "${moment(startDate).tz(timezone).format('YYYY-MM-D HH:mm:ss')}"
AND "${moment(endDate).tz(timezone).format('YYYY-MM-D HH:mm:ss')}"`,
})) as IRowResponse;
}
@@ -150,9 +146,9 @@ export class SeaTableTrigger implements INodeType {
const allColumns = rows.metadata.map((meta) => meta.name);
response = response
//@ts-ignore
.map((row: IRow) => rowFormatColumns(row, allColumns))
.map((row: IRow) => ({ json: row }));
//@ts-ignore
.map((row: IRow) => rowFormatColumns(row, allColumns))
.map((row: IRow) => ({ json: row }));
}
if (Array.isArray(response) && response.length) {

View File

@@ -9,20 +9,37 @@ type TSeaTableServerEdition = 'enterprise edition';
// dtable
// ----------------------------------
import {IDtableMetadataColumn, IDtableMetadataTable, TDtableViewColumn} from './Interfaces';
import {ICredentialDataDecryptedObject} from 'n8n-workflow';
import { IDtableMetadataColumn, IDtableMetadataTable, TDtableViewColumn } from './Interfaces';
import { ICredentialDataDecryptedObject } from 'n8n-workflow';
type TInheritColumnTypeTime = 'ctime' | 'mtime';
type TInheritColumnTypeUser = 'creator' | 'last-modifier';
type TColumnType = 'text' | 'long-text' | 'number'
type TColumnType =
| 'text'
| 'long-text'
| 'number'
| 'collaborator'
| 'date' | 'duration' | 'single-select' | 'multiple-select' | 'email' | 'url' | 'rate'
| 'checkbox' | 'formula'
| TInheritColumnTypeTime | TInheritColumnTypeUser | 'auto-number';
| 'date'
| 'duration'
| 'single-select'
| 'multiple-select'
| 'email'
| 'url'
| 'rate'
| 'checkbox'
| 'formula'
| TInheritColumnTypeTime
| TInheritColumnTypeUser
| 'auto-number';
type TImplementInheritColumnKey = '_seq';
type TInheritColumnKey = '_id' | '_creator' | '_ctime' | '_last_modifier' | '_mtime' | TImplementInheritColumnKey;
type TInheritColumnKey =
| '_id'
| '_creator'
| '_ctime'
| '_last_modifier'
| '_mtime'
| TImplementInheritColumnKey;
type TColumnValue = undefined | boolean | number | string | string[] | null;
type TColumnKey = TInheritColumnKey | string;
@@ -42,11 +59,13 @@ type TMethod = 'GET' | 'POST';
type TDeferredEndpoint = string;
type TDeferredEndpointExpr = string;
type TEndpoint =
'/api/v2.1/dtable/app-access-token/'
| '/api/v2.1/dtable/app-access-token/'
| '/dtable-server/api/v1/dtables/{{dtable_uuid}}/rows/'
| TDeferredEndpoint;
type TEndpointExpr = TEndpoint | TDeferredEndpointExpr;
type TEndpointResolvedExpr = TEndpoint | string; /* deferred: but already in use for header values, e.g. authentication */
type TEndpointResolvedExpr =
| TEndpoint
| string; /* deferred: but already in use for header values, e.g. authentication */
type TDateTimeFormat = 'YYYY-MM-DDTHH:mm:ss.SSSZ' /* moment.js */;
@@ -61,9 +80,9 @@ type TTriggerOperation = 'create' | 'update';
type TOperation = 'append' | 'list' | 'metadata';
type TLoadedResource = {
name: string;
name: string;
};
export type TColumnsUiValues = Array<{
columnName: string;
columnValue: string;
columnName: string;
columnValue: string;
}>;