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

[transform] refactor how the custom predefined function works #336

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- APP-4620 - [transform] Added structured/contextualized exceptions to transform
- APP-4632 - [transform] Added support for attribute.pinned field
- APP-4640 - [api] Updated API hashing method to use SHA256 for FIPS compliance

- APP-4656 - [transform] refactor how the custom predefined function works

## 4.0.6

Expand Down
50 changes: 31 additions & 19 deletions tcex/api/tc/ti_transform/ti_predefined_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,39 @@ class ProcessingFunctions:
def __init__(self, tcex) -> None:
"""."""
self.tcex = tcex
self.custom_fns = {}

def custom(self, value, description: str):
@custom_function_definition(
{
'name': 'custom',
'label': 'Custom',
'help': 'Describe a custom processing function.',
'params': [
{
'default': None,
'name': 'name',
'label': 'Name',
'type': 'str',
'help': 'A unique name for this custom processing function.',
'required': True,
},
{
'default': None,
'name': 'description',
'label': 'Description',
'type': 'str',
'help': 'Describe the custom processing function.',
'required': True,
},
],
}
)
def custom(self, value, name: str, description: str, ti_dict, transform, **kwargs):
"""Allow for custom processing to be described."""
raise RuntimeError(f'Custom function not implemented: {description}')
fn = self.custom_fns.get(name.lower())
if not fn:
raise NotImplementedError(f'Custom function not implemented: {description}')
return fn(value, ti_dict=ti_dict, transform=transform, **kwargs)

def static_map(self, value, mapping: dict):
"""Map values to static values.
Expand All @@ -122,23 +151,6 @@ def value_in(self, value, values: str, delimiter: str = ','):

return value if value in [v.strip() for v in json.loads(values).split(delimiter)] else None

@custom_function_definition(
{
'name': 'format_table',
'label': 'Format Objects as Markdown Table',
'help': 'Format a list of objects as a markdown table.',
'params': [
{
'default': None,
'name': 'column_order',
'label': 'Column Order',
'type': 'str',
'help': 'The order of the columns.',
'required': False,
}
],
}
)
def format_table(self, value, column_order: str):
"""Format a markdown table.

Expand Down
Loading