first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled

This commit is contained in:
2026-03-17 16:22:57 +03:30
commit 3d5eaf9445
15349 changed files with 2847338 additions and 0 deletions
@@ -0,0 +1,62 @@
import {
DATA_TABLE_SYSTEM_COLUMNS,
type IDataObject,
type IDisplayOptions,
type IExecuteFunctions,
type INodeProperties,
} from 'n8n-workflow';
import { DATA_TABLE_ID_FIELD } from './fields';
import { dataObjectToApiInput } from './utils';
export function makeAddRow(operation: string, displayOptions: IDisplayOptions) {
return {
displayName: 'Columns',
name: 'columns',
type: 'resourceMapper',
default: {
mappingMode: 'defineBelow',
value: null,
},
noDataExpression: true,
required: true,
typeOptions: {
loadOptionsDependsOn: [`${DATA_TABLE_ID_FIELD}.value`],
resourceMapper: {
valuesLabel: `Values to ${operation}`,
resourceMapperMethod: 'getDataTables',
mode: 'add',
fieldWords: {
singular: 'column',
plural: 'columns',
},
addAllFields: true,
multiKeyMatch: true,
hideNoDataError: true,
},
},
displayOptions,
} satisfies INodeProperties;
}
export function getAddRow(ctx: IExecuteFunctions, index: number) {
const items = ctx.getInputData();
const dataMode = ctx.getNodeParameter('columns.mappingMode', index) as string;
let data: IDataObject;
if (dataMode === 'autoMapInputData') {
data = { ...items[index].json };
// We automatically remove our system columns for better UX when feeding data table outputs
// into another data table node
for (const systemColumn of DATA_TABLE_SYSTEM_COLUMNS) {
delete data[systemColumn];
}
} else {
const fields = ctx.getNodeParameter('columns.value', index, {}) as IDataObject;
data = fields;
}
return dataObjectToApiInput(data, ctx.getNode(), index);
}
@@ -0,0 +1,19 @@
import type { DataTableColumnJsType } from 'n8n-workflow';
export const ANY_CONDITION = 'anyCondition';
export const ALL_CONDITIONS = 'allConditions';
export const ROWS_LIMIT_DEFAULT = 50;
export type FilterType = typeof ANY_CONDITION | typeof ALL_CONDITIONS;
export type FieldEntry =
| {
keyName: string;
condition: 'isEmpty' | 'isNotEmpty' | 'isTrue' | 'isFalse';
}
| {
keyName: string;
condition?: 'eq' | 'neq' | 'like' | 'ilike' | 'gt' | 'gte' | 'lt' | 'lte';
keyValue: DataTableColumnJsType;
};
@@ -0,0 +1,44 @@
import type { INodeProperties } from 'n8n-workflow';
export const DATA_TABLE_ID_FIELD = 'dataTableId';
export const DRY_RUN = {
displayName: 'Dry Run',
name: 'dryRun',
type: 'boolean',
default: false,
description:
'Whether the operation simulates and returns affected rows in their "before" and "after" states',
} satisfies INodeProperties;
export const DATA_TABLE_RESOURCE_LOCATOR_BASE = {
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
displayName: 'Data table',
name: DATA_TABLE_ID_FIELD,
type: 'resourceLocator',
default: { mode: 'list', value: '' },
required: true,
builderHint: { message: "Default to mode: 'list' which is easier for users to set up" },
modes: [
{
displayName: 'From List',
name: 'list',
type: 'list',
typeOptions: {
searchListMethod: 'tableSearch',
searchable: true,
},
},
{
displayName: 'By Name',
name: 'name',
type: 'string',
placeholder: 'e.g. My Table',
},
{
displayName: 'ID',
name: 'id',
type: 'string',
},
],
} as const satisfies Omit<INodeProperties, 'displayOptions'>;
@@ -0,0 +1,174 @@
import {
DATA_TABLE_SYSTEM_COLUMN_TYPE_MAP,
type ILoadOptionsFunctions,
type INodeListSearchResult,
type INodePropertyOptions,
type ResourceMapperField,
type ResourceMapperFields,
} from 'n8n-workflow';
import { getDataTableAggregateProxy, getDataTableProxyLoadOptions } from './utils';
// @ADO-3904: Pagination here does not work until a filter is entered or removed, suspected bug in ResourceLocator
export async function tableSearch(
this: ILoadOptionsFunctions,
filterString?: string,
prevPaginationToken?: string,
): Promise<INodeListSearchResult> {
const proxy = await getDataTableAggregateProxy(this);
const skip = prevPaginationToken === undefined ? 0 : parseInt(prevPaginationToken, 10);
const take = 100;
const filter = filterString === undefined ? {} : { filter: { name: filterString.toLowerCase() } };
const result = await proxy.getManyAndCount({
skip,
take,
...filter,
});
const results = result.data.map((row) => {
return {
name: row.name,
value: row.id,
url: `/projects/${proxy.getProjectId()}/datatables/${row.id}`,
};
});
const paginationToken = results.length === take ? `${skip + take}` : undefined;
return {
results,
paginationToken,
};
}
export async function getDataTableColumns(this: ILoadOptionsFunctions) {
const returnData: Array<INodePropertyOptions & { type: string }> = Object.entries(
DATA_TABLE_SYSTEM_COLUMN_TYPE_MAP,
).map(([name, type]) => ({
name: `${name} (${type})`,
value: name,
type,
}));
const proxy = await getDataTableProxyLoadOptions(this);
if (!proxy) {
return returnData;
}
const columns = await proxy.getColumns();
for (const column of columns) {
returnData.push({
name: `${column.name} (${column.type})`,
value: column.name,
type: column.type,
});
}
return returnData;
}
export async function getConditionsForColumn(this: ILoadOptionsFunctions) {
const proxy = await getDataTableProxyLoadOptions(this);
if (!proxy) {
return [];
}
const keyName = this.getCurrentNodeParameter('&keyName') as string;
const nullConditions: INodePropertyOptions[] = [
{ name: 'Is Empty', value: 'isEmpty' },
{ name: 'Is Not Empty', value: 'isNotEmpty' },
];
const equalsConditions: INodePropertyOptions[] = [
{ name: 'Equals', value: 'eq' },
{ name: 'Not Equals', value: 'neq' },
];
const booleanConditions: INodePropertyOptions[] = [
{ name: 'Is True', value: 'isTrue' },
{ name: 'Is False', value: 'isFalse' },
];
const comparableConditions: INodePropertyOptions[] = [
{ name: 'Greater Than', value: 'gt' },
{ name: 'Greater Than or Equal', value: 'gte' },
{ name: 'Less Than', value: 'lt' },
{ name: 'Less Than or Equal', value: 'lte' },
];
const stringConditions: INodePropertyOptions[] = [
{ name: 'Contains (Case-Sensitive)', value: 'like' },
{ name: 'Contains (Case-Insensitive)', value: 'ilike' },
];
const allConditions = [
...nullConditions,
...equalsConditions,
...booleanConditions,
...comparableConditions,
...stringConditions,
];
// If no column is selected yet, return all conditions
if (!keyName) {
return allConditions;
}
// Get column type to determine available conditions
const type =
DATA_TABLE_SYSTEM_COLUMN_TYPE_MAP[keyName] ??
(await proxy.getColumns()).find((col) => col.name === keyName)?.type;
if (!type) {
return [...equalsConditions, ...nullConditions];
}
const conditions: INodePropertyOptions[] = [];
if (type === 'boolean') {
conditions.push.apply(conditions, booleanConditions);
}
// String columns get LIKE operators
if (type === 'string') {
conditions.push.apply(conditions, equalsConditions);
conditions.push.apply(conditions, stringConditions);
conditions.push.apply(conditions, comparableConditions);
}
if (['number', 'date'].includes(type)) {
conditions.push.apply(conditions, equalsConditions);
conditions.push.apply(conditions, comparableConditions);
}
conditions.push.apply(conditions, nullConditions);
return conditions;
}
export async function getDataTables(this: ILoadOptionsFunctions): Promise<ResourceMapperFields> {
const proxy = await getDataTableProxyLoadOptions(this);
if (!proxy) {
return { fields: [] };
}
const result = await proxy.getColumns();
const fields: ResourceMapperField[] = [];
for (const field of result) {
const type = field.type === 'date' ? 'dateTime' : field.type;
fields.push({
id: field.name,
displayName: field.name,
required: false,
defaultMatch: false,
display: true,
type,
readOnly: false,
removed: false,
});
}
return { fields };
}
@@ -0,0 +1,242 @@
import { DATA_TABLE_SYSTEM_COLUMN_TYPE_MAP, NodeOperationError } from 'n8n-workflow';
import type {
DataTableFilter,
DataTableRowReturn,
IDataTableProjectService,
IDisplayOptions,
IExecuteFunctions,
INodeProperties,
DataTableColumnType,
} from 'n8n-workflow';
import { ALL_CONDITIONS, ANY_CONDITION, ROWS_LIMIT_DEFAULT, type FilterType } from './constants';
import { DATA_TABLE_ID_FIELD } from './fields';
import { buildGetManyFilter, isFieldArray, isMatchType, getDataTableProxyExecute } from './utils';
/**
* Recursively converts Date objects to ISO strings in an object
* This ensures that all output data is JSON-compatible
*/
function convertDatesToIsoStrings<T>(obj: T): T {
if (obj === null || obj === undefined) {
return obj;
}
if (obj instanceof Date) {
return obj.toISOString() as T;
}
if (Array.isArray(obj)) {
return obj.map(convertDatesToIsoStrings) as T;
}
if (typeof obj === 'object') {
const converted: Record<string, unknown> = {};
for (const [key, value] of Object.entries(obj)) {
converted[key] = convertDatesToIsoStrings(value);
}
return converted as T;
}
return obj;
}
export function getSelectFields(
displayOptions: IDisplayOptions,
requireCondition = false,
skipOperator = false,
): INodeProperties[] {
return [
{
displayName: 'Must Match',
name: 'matchType',
type: 'options',
options: [
{
name: 'Any Condition',
value: ANY_CONDITION,
},
{
name: 'All Conditions',
value: ALL_CONDITIONS,
},
] satisfies Array<{ value: FilterType; name: string }>,
displayOptions,
default: ANY_CONDITION,
},
{
displayName: 'Conditions',
name: 'filters',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
minRequiredFields: requireCondition ? 1 : 0,
},
displayOptions,
default: {},
placeholder: 'Add Condition',
options: [
{
displayName: 'Conditions',
name: 'conditions',
values: [
{
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-options
displayName: 'Column',
name: 'keyName',
type: 'options',
// eslint-disable-next-line n8n-nodes-base/node-param-description-wrong-for-dynamic-options
description:
'Choose from the list, or specify using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
typeOptions: {
loadOptionsDependsOn: [`${DATA_TABLE_ID_FIELD}.value`],
loadOptionsMethod: 'getDataTableColumns',
},
default: 'id',
},
{
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-options
displayName: 'Condition',
name: 'condition',
// eslint-disable-next-line n8n-nodes-base/node-param-description-missing-from-dynamic-options
type: 'options',
typeOptions: {
loadOptionsDependsOn: ['&keyName'],
loadOptionsMethod: 'getConditionsForColumn',
},
default: 'eq',
displayOptions: skipOperator
? {
show: { '@version': [{ _cnd: { lt: 0 } }] },
}
: undefined,
},
{
displayName: 'Value',
name: 'keyValue',
type: 'string',
default: '',
displayOptions: {
hide: {
condition: ['isEmpty', 'isNotEmpty', 'isTrue', 'isFalse'],
},
},
},
],
},
],
description: 'Filter to decide which rows get',
},
];
}
export async function getSelectFilter(
ctx: IExecuteFunctions,
index: number,
): Promise<DataTableFilter> {
const fields = ctx.getNodeParameter('filters.conditions', index, []);
const matchType = ctx.getNodeParameter('matchType', index, ANY_CONDITION);
const node = ctx.getNode();
if (!isMatchType(matchType)) {
throw new NodeOperationError(node, 'unexpected match type');
}
if (!isFieldArray(fields)) {
throw new NodeOperationError(node, 'unexpected fields input');
}
// Validate filter conditions against current table schema
let allColumnsWithTypes: Record<string, DataTableColumnType> = DATA_TABLE_SYSTEM_COLUMN_TYPE_MAP;
if (fields.length > 0) {
const dataTableProxy = await getDataTableProxyExecute(ctx, index);
const availableColumns = await dataTableProxy.getColumns();
// Add system columns with their types
allColumnsWithTypes = {
...DATA_TABLE_SYSTEM_COLUMN_TYPE_MAP,
...Object.fromEntries(availableColumns.map((col) => [col.name, col.type])),
};
const invalidConditions = fields.filter((field) => !allColumnsWithTypes[field.keyName]);
if (invalidConditions.length > 0) {
const invalidColumnNames = invalidConditions.map((c) => c.keyName).join(', ');
throw new NodeOperationError(
node,
`Filter validation failed: Column(s) "${invalidColumnNames}" do not exist in the selected table. ` +
'This often happens when switching between tables with different schemas. ' +
'Please update your filter conditions.',
);
}
}
return buildGetManyFilter(fields, matchType, allColumnsWithTypes, node);
}
export async function executeSelectMany(
ctx: IExecuteFunctions,
index: number,
dataTableProxy: IDataTableProjectService,
rejectEmpty = false,
limit?: number,
sortBy?: [string, 'ASC' | 'DESC'],
): Promise<Array<{ json: DataTableRowReturn }>> {
const filter = await getSelectFilter(ctx, index);
if (rejectEmpty && filter.filters.length === 0) {
throw new NodeOperationError(ctx.getNode(), 'At least one condition is required');
}
const PAGE_SIZE = 1000;
const result: Array<{ json: DataTableRowReturn }> = [];
const returnAll = ctx.getNodeParameter('returnAll', index, false);
limit = limit ?? (!returnAll ? ctx.getNodeParameter('limit', index, ROWS_LIMIT_DEFAULT) : 0);
const nodeVersion = ctx.getNode().typeVersion;
const shouldConvertDates = nodeVersion >= 1.1;
let expectedTotal: number | undefined;
let skip = 0;
let take = PAGE_SIZE;
while (true) {
const { data, count } = await dataTableProxy.getManyRowsAndCount({
skip,
take: limit ? Math.min(take, limit - result.length) : take,
filter,
sortBy,
});
const wrapped = data.map((json) => ({
json: shouldConvertDates ? convertDatesToIsoStrings(json) : json,
}));
// Fast path: everything fits in a single page
if (skip === 0 && count === data.length) {
return wrapped;
}
// Ensure the total doesn't change mid-pagination
if (expectedTotal !== undefined && count !== expectedTotal) {
throw new NodeOperationError(
ctx.getNode(),
'synchronization error: result count changed during pagination',
);
}
expectedTotal = count;
result.push.apply(result, wrapped);
// Stop if we've hit the limit
if (limit && result.length >= limit) break;
// Stop if we've collected everything
if (result.length >= count) break;
skip = result.length;
take = Math.min(PAGE_SIZE, count - result.length);
}
return result;
}
@@ -0,0 +1,244 @@
import { DateTime } from 'luxon';
import type {
IDataObject,
INode,
DataTableFilter,
IDataTableProjectAggregateService,
IDataTableProjectService,
IExecuteFunctions,
ILoadOptionsFunctions,
DataTableColumnJsType,
DataTableColumnType,
} from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import type { FieldEntry, FilterType } from './constants';
import { ALL_CONDITIONS, ANY_CONDITION } from './constants';
import { DATA_TABLE_ID_FIELD, DRY_RUN } from './fields';
type DateLike = { toISOString: () => string };
function isDateLike(v: unknown): v is DateLike {
return (
v !== null && typeof v === 'object' && 'toISOString' in v && typeof v.toISOString === 'function'
);
}
// Helper function to resolve data table ID from resourceLocator
export async function resolveDataTableId(
ctx: IExecuteFunctions | ILoadOptionsFunctions,
resourceLocator: { mode: 'list' | 'id' | 'name'; value: string },
): Promise<string> {
if (resourceLocator.mode === 'name') {
// Look up table by name
const aggregateProxy = await getDataTableAggregateProxy(ctx);
const response = await aggregateProxy.getManyAndCount({
filter: { name: resourceLocator.value.toLowerCase() },
take: 1,
});
if (response.data.length === 0) {
throw new NodeOperationError(
ctx.getNode(),
`Data table with name "${resourceLocator.value}" not found`,
);
}
return response.data[0].id;
} else {
// For 'list' and 'id' modes, use the value from the resource locator
return resourceLocator.value;
}
}
// We need two functions here since the available getNodeParameter
// overloads vary with the index
export async function getDataTableProxyExecute(
ctx: IExecuteFunctions,
index: number = 0,
): Promise<IDataTableProjectService> {
if (ctx.helpers.getDataTableProxy === undefined)
throw new NodeOperationError(
ctx.getNode(),
'Attempted to use Data table node but the module is disabled',
);
const resourceLocator = ctx.getNodeParameter(DATA_TABLE_ID_FIELD, index) as {
mode: 'list' | 'id' | 'name';
value: string;
};
const dataTableId = await resolveDataTableId(ctx, resourceLocator);
return await ctx.helpers.getDataTableProxy(dataTableId);
}
export async function getDataTableProxyLoadOptions(
ctx: ILoadOptionsFunctions,
): Promise<IDataTableProjectService | undefined> {
if (ctx.helpers.getDataTableProxy === undefined)
throw new NodeOperationError(
ctx.getNode(),
'Attempted to use Data table node but the module is disabled',
);
const resourceLocator = ctx.getNodeParameter(DATA_TABLE_ID_FIELD) as {
mode: 'list' | 'id' | 'name';
value: string;
};
if (!resourceLocator || !resourceLocator.value) {
return;
}
const dataTableId = await resolveDataTableId(ctx, resourceLocator);
return await ctx.helpers.getDataTableProxy(dataTableId);
}
export async function getDataTableAggregateProxy(
ctx: IExecuteFunctions | ILoadOptionsFunctions,
): Promise<IDataTableProjectAggregateService> {
if (ctx.helpers.getDataTableAggregateProxy === undefined)
throw new NodeOperationError(
ctx.getNode(),
'Attempted to use Data table node but the module is disabled',
);
return await ctx.helpers.getDataTableAggregateProxy();
}
export function isFieldEntry(obj: unknown): obj is FieldEntry {
if (obj === null || typeof obj !== 'object') return false;
return 'keyName' in obj; // keyValue and condition are optional
}
export function isMatchType(obj: unknown): obj is FilterType {
return typeof obj === 'string' && (obj === ANY_CONDITION || obj === ALL_CONDITIONS);
}
export function buildGetManyFilter(
fieldEntries: FieldEntry[],
matchType: FilterType,
columnTypeMap: Record<string, DataTableColumnType>,
node: INode,
): DataTableFilter {
const filters = fieldEntries.map((x) => {
switch (x.condition) {
case 'isEmpty':
return {
columnName: x.keyName,
condition: 'eq' as const,
value: null,
};
case 'isNotEmpty':
return {
columnName: x.keyName,
condition: 'neq' as const,
value: null,
};
case 'isTrue':
return {
columnName: x.keyName,
condition: 'eq' as const,
value: true,
};
case 'isFalse':
return {
columnName: x.keyName,
condition: 'eq' as const,
value: false,
};
default: {
let value = x.keyValue;
const columnType = columnTypeMap[x.keyName];
// Convert ISO date strings to Date objects for date columns
if (columnType === 'date' && typeof value === 'string') {
const parsed = new Date(value);
if (isNaN(parsed.getTime())) {
throw new NodeOperationError(
node,
`Invalid date string '${value}' for column '${x.keyName}'`,
);
}
value = parsed;
}
return {
columnName: x.keyName,
condition: x.condition ?? 'eq',
value,
};
}
}
});
return { type: matchType === ALL_CONDITIONS ? 'and' : 'or', filters };
}
export function isFieldArray(value: unknown): value is FieldEntry[] {
return (
value !== null && typeof value === 'object' && Array.isArray(value) && value.every(isFieldEntry)
);
}
export function dataObjectToApiInput(
data: IDataObject,
node: INode,
row: number,
): Record<string, DataTableColumnJsType> {
return Object.fromEntries(
Object.entries(data).map(([k, v]): [string, DataTableColumnJsType] => {
if (v === undefined || v === null) return [k, null];
if (Array.isArray(v)) {
throw new NodeOperationError(
node,
`unexpected array input '${JSON.stringify(v)}' in row ${row}`,
);
}
if (v instanceof Date) {
return [k, v];
}
if (typeof v === 'object') {
// Luxon DateTime
if (DateTime.isDateTime(v)) {
return [k, v.toJSDate()];
}
if (isDateLike(v)) {
try {
const dateObj = new Date(v.toISOString());
if (isNaN(dateObj.getTime())) {
throw new Error('Invalid date');
}
return [k, dateObj];
} catch {
// Fall through
}
}
throw new NodeOperationError(
node,
`unexpected object input '${JSON.stringify(v)}' in row ${row}`,
);
}
return [k, v];
}),
);
}
export function getDryRunParameter(ctx: IExecuteFunctions, index: number): boolean {
const dryRun = ctx.getNodeParameter(`options.${DRY_RUN.name}`, index, false);
if (typeof dryRun !== 'boolean') {
throw new NodeOperationError(
ctx.getNode(),
`unexpected input ${JSON.stringify(dryRun)} for boolean dryRun`,
);
}
return dryRun;
}