supabase / functions-dart Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Hi there,
Thanks alot for implementing this quickly on dart.
I have a function that accepts
{
"creator": {
"id": "id",
"name": "Kosh ",
"picture": ""
},
"receiver": {
"id": "id",
"name": "Kosh2 ",
"picture": ""
},
"notificationType": "FOLLOW",
"body": "",
"challengeId": "",
"notificationId": ""
}
while calling function.invoke(body: myObject.toMap())
throws an error and after following the source of the error I found that dart http
does not really support Map<String, dynamic>
however only accepts Map<String, String>
which resulted in an error that is hard to figure.
the solution was to create an extension on Functions and do below:
extension BoltsFunction on FunctionsClient {
Future<FunctionResponse> stringInvoke(
String url,
String functionName, {
required Map<String, String> headers,
required String body,
}) async {
try {
final response = await http.post(
Uri.parse('$url/$functionName'),
headers: headers,
body: body,
);
dynamic data = json.decode(response.body);
return FunctionResponse(data: data);
} catch (error) {
return FunctionResponse(error: error);
}
}
}
And body in here is just a
json.encode({
'receiver': receiver.toShortMap(),
'creator': creator.toShortMap(),
'notificationId': notificationId,
'challengeId': challengeId,
'body': body,
'notificationType': notificationType.name,
})
I will open a PR that fixes this and instead of using map<String, dynamic>
we should accept dynamic
allowing callers to determine the type themselves.
here is what http does eventually with body.
if (body != null) {
if (body is String) {
request.body = body;
} else if (body is List) {
request.bodyBytes = body.cast<int>();
} else if (body is Map) {
request.bodyFields = body.cast<String, String>();
} else {
throw ArgumentError('Invalid request body "$body".');
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.