-
Notifications
You must be signed in to change notification settings - Fork 586
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
Implement Realm.User.push() #2995
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright 2020 Realm Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
"use strict"; | ||
|
||
|
||
module.exports = { | ||
/** | ||
* Helper to wrap callback-taking C++ function into a Promise-returning JS function | ||
* @example | ||
* // floop() is a wrapper method on a type with a _floop C++ method. | ||
* function floop(how, why) { | ||
* return promisify(cb => this._floop(how, why, cb)); | ||
* } | ||
*/ | ||
promisify(func) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice simplification!! |
||
return new Promise((resolve, reject) => { | ||
func((...cbargs) => { | ||
if (cbargs.length < 1 || cbargs.length > 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So only 1 or 2 arguments? Maybe |
||
throw Error(`invalid cbargs length ${cbargs.length}`) | ||
let error = cbargs[cbargs.length-1]; | ||
if (error) { | ||
reject(error); | ||
} else if (cbargs.length == 2) { | ||
resolve(cbargs[0]); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,8 +140,11 @@ template<typename T> | |
void CredentialsClass<T>::function(ContextType ctx, ObjectType this_object, Arguments& arguments, ReturnValue& return_value) { | ||
arguments.validate_count(1); | ||
const std::string payload_json = Value::validated_to_string(ctx, arguments[0], "payload"); | ||
const auto payload_bson = bson::parse(payload_json); | ||
if (payload_bson.type() != bson::Bson::Type::Document) | ||
throw std::invalid_argument("payload must be a json object"); | ||
|
||
auto credentials = realm::app::AppCredentials::function(payload_json); | ||
auto credentials = realm::app::AppCredentials::function(payload_bson.operator const bson::BsonDocument&()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Upstream object-store changed the parameter type. |
||
return_value.set(create_object<T, CredentialsClass<T>>(ctx, new app::AppCredentials(credentials))); | ||
} | ||
|
||
|
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.
Perhaps we can elaborate a bit more what this is (in end user terms). (I can see we also missed to do that with RemoteMongoClient.
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.
Unfortunately, I don't actually know what "Push" does in end user terms. This sounds like a good thing to have our Docs team work on so that they can ensure that release notes use consistent terminology with the rest of the documentation.