-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathconnectors.py
More file actions
55 lines (47 loc) · 1.89 KB
/
Copy pathconnectors.py
File metadata and controls
55 lines (47 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import typing
from . import meta
class ConnectorTriggerConverter(meta.InConverter, binding='connectorTrigger',
trigger=True):
@classmethod
def check_input_type_annotation(cls, pytype: type) -> bool:
return issubclass(pytype, (str, dict, bytes))
@classmethod
def has_implicit_output(cls) -> bool:
return True
@classmethod
def decode(cls, data: meta.Datum, *, trigger_metadata):
"""
Decode incoming connector trigger request data.
Returns the raw data in its native format (string, dict, bytes).
"""
# Handle different data types appropriately
if data.type == 'json':
# If it's already parsed JSON, use the value directly
return data.value
elif data.type == 'string':
# If it's a string, use it as-is
return data.value
elif data.type == 'bytes':
return data.value
else:
# Fallback to python_value for other types
return data.python_value if hasattr(data, 'python_value') else data.value
@classmethod
def encode(cls, obj: typing.Any, *, expected_type: typing.Optional[type] = None):
"""
Encode the return value from connector trigger functions.
"""
if obj is None:
return meta.Datum(type='string', value='')
elif isinstance(obj, str):
return meta.Datum(type='string', value=obj)
elif isinstance(obj, (bytes, bytearray)):
return meta.Datum(type='bytes', value=bytes(obj))
elif isinstance(obj, dict):
import json
return meta.Datum(type='string', value=json.dumps(obj))
else:
# Convert other types to string
return meta.Datum(type='string', value=str(obj))