-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Changes from 63 commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
4dcca35
:zap: Introduce a framework for expression extension
valya 8bed02e
:bulb: Add some inline comments
valya e621548
:zap: Introduce hash alias for encrypt
valya a456849
:zap: Introduce a manual granular level approach to shadowing/overrid…
valya ab9610b
:fire: Cleanup comments
valya 1a1936d
:zap: Introduce a basic method of extension for native functions
valya a55cbc8
:zap: Add length to StringExtension
valya 56ee445
:zap: Add number type to extension return types
valya 0b1dd25
:zap: Temporarily introduce DateTime with extension
valya e451d0c
:zap: Cleanup comments
valya 38e6748
:zap: Organize imports
valya 5def027
:recycle: Fix up some typings
valya 0c0d038
:zap: Fix typings
valya 244067f
:recycle: Remove unnecessary resolve of expression
valya d4f489c
:zap: Extensions Improvement
valya 294fcec
:recycle: Refactor EXPRESSION_EXTENSION_METHODS
valya 5ecea0d
:recycle: Refactor EXPRESSION_EXTENSION_METHODS
valya c039bae
Merge branch 'n8n-4486' of https://github.com/n8n-io/n8n into n8n-4486
valya e1e625d
:recycle: Update extraArgs types
valya 38d9e16
:recycle: Fix tests
valya 4d7d335
:recycle: Fix bind type issue
valya 715d076
:recycle: Fixing duration type issue
valya df70f1b
:recycle: Refactor to allow overrides on native methods
valya ae507ec
:recycle: Temporarily remove Date Extensions to pass tests
valya d65b6c6
feat(dt-functions): introduce date expression extensions (#4045)
valya c4b94bc
:recycle: Refactor extension for native types
valya 6593d16
:fire: Move sayHi method to String Extension class
valya 0df9286
:recycle: Update scope when binding member methods
valya 7e098f1
:white_check_mark: Add String Extension tests
valya b258e88
feat(dt-functions): introduce array expression extensions (#4044)
valya 76a3235
feat(dt-functions): introduce number expression extensions (#4046)
valya 4698913
Merge branch 'master' into n8n-4486
valya 3f42b64
Fixed up tests
valya 4658226
:fire: Remove remove markdown
valya 44fd645
:recylce: Replace remove-markdown dependencies with implementation
valya 92ebde6
:recycle: Replace remove-markdown dependencies with implementation
valya b245eb4
Merge branch 'n8n-4486' of https://github.com/n8n-io/n8n into n8n-4486
valya e41e45a
:white_check_mark: Update tests
valya 9fb3bc1
:recycle: Fix scoping and cleanup
valya f99a5d2
:recycle: Update comments and errors
valya dfd7d4c
:recycle: Fix linting errors
valya da3454c
:heavy_minus_sign: Remove unused dependencies
valya 212dc35
fix: expression extension not working with multiple extensions
valya 574a39f
refactor: change extension transform to be more efficient
valya f57dab5
test: update most test to work with new extend function
valya 316d5b5
Merge remote-tracking branch 'origin/master' into n8n-4486-implement-…
valya f4447ee
fix: update and fix type error in config
cstuncsik a5f6fff
refactor: replace babel with recast
valya 2c6a92b
feat: add hashing functions to string extension
valya d19e4cc
fix: removed export
valya dda3579
Merge remote-tracking branch 'origin/master' into n8n-4486-implement-…
valya f2b21f0
test: add extension parser and transform tests
valya c67f707
fix: vite tests breaking
valya f1446a0
refactor: remove commented out code
valya 2379e73
fix: parse dates passed from $json in extend function
valya 34ef71d
refactor: review feedback changes for date extensions
valya ba83583
refactor: review feedback changes for number extensions
valya abe4a51
fix: date extension beginningOf test
valya 41754d9
Merge remote-tracking branch 'origin/master' into n8n-4486-implement-…
valya eb9c291
fix: broken build from merge
valya 1006672
Merge remote-tracking branch 'origin/master' into n8n-4486-implement-…
valya b5c8119
fix: another merge issue
valya 5a8b553
refactor: address review feedback (remove ignores)
valya e23cd35
Merge remote-tracking branch 'origin/master' into n8n-4486-implement-…
valya 0dae735
feat: new extension functions and tests
valya 7b0d4a4
feat: non-dot notation functions
valya 25de979
test: most of the other tests
valya 7b5033b
Merge remote-tracking branch 'origin/master' into n8n-4486-implement-…
valya c31e9f1
fix: toSentenceCase for node versions below 16.6
valya f3a81bb
feat: add $if and $not expression extensions
valya c178d67
Merge master
krynble b03a763
Fix test to work on every timezone
krynble f00fc43
lint: fix remaining lint issues
valya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/unbound-method */ | ||
/* eslint-disable @typescript-eslint/explicit-member-accessibility */ | ||
// eslint-disable-next-line import/no-cycle | ||
import { ExpressionError } from '../ExpressionError'; | ||
import { ExtensionMap } from './Extensions'; | ||
// import { BaseExtension, ExtensionMethodHandler } from './Extensions'; | ||
|
||
function filter(value: any[], extraArgs?: any[]): any[] { | ||
if (!Array.isArray(extraArgs)) { | ||
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)); | ||
} | ||
|
||
function first(value: any[]): any { | ||
return value[0]; | ||
} | ||
|
||
function isBlank(value: any[]): boolean { | ||
return value.length === 0; | ||
} | ||
|
||
function isPresent(value: any[]): boolean { | ||
return value.length > 0; | ||
} | ||
|
||
function last(value: any[]): any { | ||
return value[value.length - 1]; | ||
} | ||
|
||
function length(value: any[]): number { | ||
return Array.isArray(value) ? value.length : 0; | ||
} | ||
|
||
function pluck(value: any[], extraArgs: any[]): any[] { | ||
if (!Array.isArray(extraArgs)) { | ||
throw new ExpressionError('arguments must be passed to pluck'); | ||
} | ||
const fieldsToPluck = extraArgs; | ||
return value.map((element: object) => { | ||
const entries = Object.entries(element); | ||
return entries.reduce((p, c) => { | ||
const [key, val] = c as [string, Date | string | number]; | ||
if (fieldsToPluck.includes(key)) { | ||
Object.assign(p, { [key]: val }); | ||
} | ||
return p; | ||
}, {}); | ||
}); | ||
} | ||
|
||
function random(value: any[]): any { | ||
const len = value === undefined ? 0 : value.length; | ||
return len ? value[Math.floor(Math.random() * len)] : undefined; | ||
} | ||
|
||
function unique(value: any[]): any[] { | ||
return Array.from(new Set(value)); | ||
} | ||
|
||
export const arrayExtensions: ExtensionMap = { | ||
typeName: 'Array', | ||
functions: { | ||
count: length, | ||
duplicates: unique, | ||
filter, | ||
first, | ||
last, | ||
length, | ||
pluck, | ||
unique, | ||
random, | ||
randomItem: random, | ||
remove: unique, | ||
size: length, | ||
isPresent, | ||
isBlank, | ||
}, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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