mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-15 09:04:07 -08:00
a1259898c0
* WIP * 🔥 Remove unneeded watch * ⚡ Further setup * ⚡ Fix import * ⚡ Minor tweaks * 🔥 Remove logging * 🎨 Add some styling * 🎨 More styling changes * 🐛 Fix wrong marking of stale data * 🎨 Prevent fx on dragging * 🔥 Remove logging * ⚡ Refine draggable target offsets * refactor(editor): Consolidate expression management logic (#4836) * ⚡ Extract `ExpressionFunctionIcon` * ⚡ Simplify syntax * ⚡ Move to mixin * 🎨 Format * 📘 Unify types * ⚡ Dedup double brace handler * ⚡ Consolidate resolvable highlighter * 🎨 Format * ⚡ Consolidate language pack * ✏️ Add comment * ⚡ Move completions to plugins * ⚡ Partially deduplicate themes * refactor(editor): Apply styling feedback to inline expression editor (#4846) * 🎨 Adjust styling for expression parameter input * 🎨 Style outputs differently * ⚡ Set single line for RLC * 🎨 Style both openers identically * 🐛 Prevent defocus on resize * ⚡ Adjust line height * 🎨 Adjust border with for expression input * ⚡ Fix font family for inline output * ⚡ Set up telemetry * ⚡ Complete telemetry * ⚡ Simplify event source * ⚡ Set monospaced font for inline output * 🎨 Hide cursor on schema pill drop * 🧪 Update snapshots * ⚡ Consolidate editor styles * ✏️ Add tech debt comments * ⚡ Improve naming * ⚡ Improve inside resolvable detection * ⚡ Improve var naming * 🔥 Remove outdated comment * 🚚 Move constant to data * ✏️ Clarify comments * 🔥 Remove outdated comments * 🔥 Remove unneeded try-catch * 🔥 Remove unneeded method * 🔥 Remove unneeded check * 🔥 Remove `openExpression` check * 🔥 Remove unused timeout * 🔥 Remove commented out sections * ⚡ Use Pinia naming convention * ⚡ Re-evaluate on change of `ndvInputData` * 🐛 Fix handling of `0` in number-type input * 🐛 Surface focus and blur for mapping hints * 🔥 Remove logging * ✏️ Reword error * ⚡ Change kebab-case to PascalCase * ⚡ Refactor state fields for clarity * ⚡ Support double bracing on selection * 🎨 More styling * ⚡ Miscellaneous cleanup * ⚡ Disregard error on drop * 🎨 Fix schema pill styling * 🎨 More `background` to `background-color` fixes * 🧪 Update snapshots * 🎨 Replace non-existing var with white * 🧪 Update snapshot * 📦 Integrate `codemirror-lang-n8n-expression` * 🎨 Fix formatting * 🧪 Re-update test snapshots * 🧪 Update selectors for inline editor * 🔥 Remove unused test ID * 📘 Add type for `currentNodePaneType` * ⚡ Refactor mixin to util * ⚡ Use `:global` * 🔥 Remove comment * ⚡ Add watch * ⚡ Change import style * 👕 Fix lint * ⚡ Refactor preventing blur on resize * 🔥 Remove comment * 🧪 Re-update snapshots * 🎨 Prettify * 👕 Fix lint * 🔥 Remove comment Co-authored-by: Mutasem <mutdmour@gmail.com>
81 lines
2.2 KiB
TypeScript
81 lines
2.2 KiB
TypeScript
import { hasExpressionMapping } from '@/utils';
|
|
|
|
import type { Resolvable, Segment } from '@/types/expressions';
|
|
|
|
export function createExpressionTelemetryPayload(
|
|
segments: Segment[],
|
|
value: string,
|
|
workflowId: string,
|
|
sessionId: string,
|
|
activeNodeType: string,
|
|
eventSource = 'ndv',
|
|
) {
|
|
const resolvables = segments.filter((s): s is Resolvable => s.kind === 'resolvable');
|
|
const erroringResolvables = resolvables.filter((r) => r.error);
|
|
|
|
return {
|
|
empty_expression: value === '=' || value === '={{}}' || !value,
|
|
workflow_id: workflowId,
|
|
source: eventSource,
|
|
session_id: sessionId,
|
|
is_transforming_data: resolvables.some((r) => isTransformingData(r.resolvable)),
|
|
has_parameter: value.includes('$parameter'),
|
|
has_mapping: hasExpressionMapping(value),
|
|
node_type: activeNodeType,
|
|
handlebar_count: resolvables.length,
|
|
handlebar_error_count: erroringResolvables.length,
|
|
short_errors: erroringResolvables.map((r) => r.resolved ?? null),
|
|
full_errors: erroringResolvables.map((erroringResolvable) => {
|
|
if (!erroringResolvable.fullError) return null;
|
|
|
|
return {
|
|
...exposeErrorProperties(erroringResolvable.fullError),
|
|
stack: erroringResolvable.fullError.stack,
|
|
};
|
|
}),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Whether the resolvable is transforming data from another node,
|
|
* i.e. operating on `$input()`, `$json`, `$()` or `$node[]`.
|
|
*
|
|
* ```
|
|
* $input.all().
|
|
* $input.first().
|
|
* $input.last().
|
|
*
|
|
* $json['field'].
|
|
* $json["field"].
|
|
* $json.field'.
|
|
*
|
|
* $('nodeName').all().
|
|
* $('nodeName').first().
|
|
* $('nodeName').last().
|
|
*
|
|
* $("nodeName").all().
|
|
* $("nodeName").first().
|
|
* $("nodeName").last().
|
|
*
|
|
* $node['nodeName'].all().
|
|
* $node['nodeName'].first().
|
|
* $node['nodeName'].last().
|
|
*
|
|
* $node["nodeName"].all().
|
|
* $node["nodeName"].first().
|
|
* $node["nodeName"].last().
|
|
* ```
|
|
*/
|
|
function isTransformingData(resolvable: string) {
|
|
const regex =
|
|
/(\$input\.\w+\(\)\.|\$json(\[('|")|\.)\w+('|")]?\.|\$\(('|")\w+('|")\)\.\w+\(\)\.|\$node\[('|")\w+('|")\]\.\w+\(\)\.)/;
|
|
|
|
return regex.test(resolvable);
|
|
}
|
|
|
|
function exposeErrorProperties(error: Error) {
|
|
return Object.getOwnPropertyNames(error).reduce<Record<string, unknown>>((acc, key) => {
|
|
return (acc[key] = error[key as keyof Error]), acc;
|
|
}, {});
|
|
}
|