Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Expression extension framework #4372

Merged
merged 73 commits into from
Jan 10, 2023

Conversation

valya
Copy link
Contributor

@valya valya commented Oct 18, 2022

No description provided.

@linear
Copy link

linear bot commented Oct 18, 2022

N8N-4486

@CLAassistant
Copy link

CLAassistant commented Oct 18, 2022

CLA assistant check
All committers have signed the CLA.

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Oct 18, 2022
@valya valya marked this pull request as ready for review October 20, 2022 08:41
@valya valya requested a review from ivov October 20, 2022 08:41
@valya valya force-pushed the n8n-4486-implement-framework-for-extensions branch 2 times, most recently from d99e7e9 to e9448cd Compare October 24, 2022 15:32
@valya valya force-pushed the n8n-4486-implement-framework-for-extensions branch from f1f1d99 to 6b6cffa Compare November 8, 2022 10:24
@valya valya changed the title feat: expression extension framework feat: Expression extension framework Nov 8, 2022
@valya valya force-pushed the n8n-4486-implement-framework-for-extensions branch from 0a64d0b to b5c8119 Compare November 9, 2022 10:03
package.json Outdated Show resolved Hide resolved
@netroy
Copy link
Member

netroy commented Nov 9, 2022

I don't know enough about our current expressions code to approve, but overall (besides the minor linting issues) this looks good to me. Thanks for adding all the tests.

Copy link
Contributor

@krynble krynble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not something severe but I was able to break the expression parser by using the following expression:

{{$json["propertyName"].sayHi().substring(4).substring(2) + '{{' + "}}" }}

package.json Outdated Show resolved Hide resolved
packages/workflow/src/Expression.ts Outdated Show resolved Hide resolved
packages/workflow/src/Expression.ts Outdated Show resolved Hide resolved
packages/workflow/src/Expression.ts Outdated Show resolved Hide resolved
packages/workflow/src/Expression.ts Outdated Show resolved Hide resolved
throw new ExpressionError('arguments must be passed to filter');
}
const terms = extraArgs as string[] | number[];
return value.filter((v: string | number) => (terms as Array<typeof v>).includes(v));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to spec, we also need a flag to decide whether to keep or remove the matched keys

function isDateTime(date: any): date is DateTime {
if (date) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
return DateTime.isDateTime(date);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't really work - n8n always gets data as strings, it's never going to be an instance of DateTime. We need to check whether the string can be converted to a date instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an internal function for this file only. It's used to check if it's a DateTime as opposed to a Date object. Anything that comes into the date functions will either be a Date or DateTime due to this check.

Comment on lines +104 to +106
function sayHi(value: string) {
return `hi ${value}`;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this function since it was used just for testing

krynble
krynble previously approved these changes Jan 10, 2023
@krynble krynble merged commit 3d05acf into master Jan 10, 2023
@krynble krynble deleted the n8n-4486-implement-framework-for-extensions branch January 10, 2023 13:06
@krynble krynble added the Upcoming Release Will be part of the upcoming release label Jan 10, 2023
MiloradFilipovic added a commit that referenced this pull request Jan 11, 2023
* master:
  fix(core): Fixes event msg confirmations if no subscribers present (#5118)
  refactor(core): Diverge syntax error handling in expressions (#5124)
  fix(editor): Recover from unsaved finished execution  (#5121)
  feat(editor): Executions page (#4997)
  docs: Update the contribution guidelines for node creation (#5120)
  feat: Expression extension framework (#4372)
  fix(editor): Fixes event bus test (#5119)
  refactor(TelegramTrigger Node, ShopifyTrigger Node): Standardize node triggers actions (#5117)
  feat(editor): Remove prevent-ndv-auto-open feature flag (#5114)
  refactor: On workflow deletion, cascade delete all entities associated with it (#5102)

# Conflicts:
#	packages/editor-ui/src/Interface.ts
});

test('.toDate() should work on a string', () => {
expect(evaluate('={{ "2022-01-03T00:00:00.000+00:00".toDate() }}')).toEqual(new Date(2022, 0, 3));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is consistently failing for me locally. Looks like a UTC/Timezone issue
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this test will only pass on a system running in UTC, as new Date(2022, 0, 3) will produce a different ISO string for different timezomes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here: #5142

@janober
Copy link
Member

janober commented Jan 13, 2023

Got released with n8n@0.211.0

@janober janober removed the Upcoming Release Will be part of the upcoming release label Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants