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

Fixing chrome debugging on v10 #3411

Merged
merged 18 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from 12 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ NOTE: This version uses the Realm file format to version 20. It is not possible
### Fixed
* Fixed RN Android error: couldn't find DSO to load: librealmreact.so caused by: dlopen failed: cannot locate symbol. ([#3347](https://github.com/realm/realm-js/issues/3347), since v10.0.0)
* Fixed TS declaration for `app.allUsers` to `Record<string, User>` instead of an array of `User`. ([#3346](https://github.com/realm/realm-js/pull/3346))
* Fixing the creation of an RPC session when running in React Native Chrome debugging mode. ([#3411](https://github.com/realm/realm-js/pull/3411), since v10.0.0)
kraenhansen marked this conversation as resolved.
Show resolved Hide resolved

### Compatibility
* MongoDB Realm Cloud.
Expand Down
5 changes: 5 additions & 0 deletions docs/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,11 @@ class Credentials {
* @returns {string} The identity provider, such as Google, Facebook, etc.
*/
get provider() { }

/**
* @returns {object} A simple object which can be passed to the server as the body of a request to authenticate.
*/
get payload() { }
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const {promisify} = require("./utils.js");

const instanceMethods = {
logIn(credentials) {
return promisify(cb => this._login(credentials, cb));
return promisify(cb => this._logIn(credentials, cb));
},

removeUser(user) {
Expand Down
33 changes: 26 additions & 7 deletions lib/browser/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,40 @@
//
////////////////////////////////////////////////////////////////////////////

'use strict';
"use strict";

import { keys, objectTypes } from './constants';
import { createMethods } from './util';
import { keys, objectTypes } from "./constants";
import { createMethods, getterForProperty } from "./util";
import { createAppRPC, _logInRPC } from "./rpc";
import { promisify } from "../utils";

function setupApp(app, info) {
app[keys.id] = info.id;
app[keys.realm] = "(App object)";
app[keys.type] = objectTypes.APP;
}

export default class App {
constructor(config) {
let info = createAppRPC(config);
setupApp(this, info);
}

logIn(credentials) {
return promisify(cb => this._logIn(credentials, cb));
}
}

createMethods(App.prototype, objectTypes.APP, [
'logIn',
'allUsers',
'currentUser',
'switchUser'
"_logIn",
"switchUser"
]);

Object.defineProperties(App.prototype, {
currentUser: { get: getterForProperty("currentUser") },
allUsers: { get: getterForProperty("allUsers") },
});

export function createApp(realmId, info) {
const appProxy = Object.create(App.prototype);

Expand Down
2 changes: 2 additions & 0 deletions lib/browser/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const propTypes = {};
'DATA',
'DATE',
'DICT',
'ERROR',
'FUNCTION',
'LIST',
'OBJECT',
Expand All @@ -44,6 +45,7 @@ export const propTypes = {};
'ASYNCOPENTASK',
'APP',
'CREDENTIALS',
'FETCHRESPONSEHANDLER',
'UNDEFINED',
].forEach(function(type) {
Object.defineProperty(objectTypes, type, {
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//
////////////////////////////////////////////////////////////////////////////

'use strict';
"use strict";

import { keys, objectTypes } from "./constants";
import { _anonymousRPC, _facebookRPC, _functionRPC, _googleRPC, _appleRPC, _emailPasswordRPC, _userApiKeyRPC, _serverApiKeyRPC, _jwtRPC } from "./rpc";
Expand Down
64 changes: 64 additions & 0 deletions lib/browser/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 Realm Inc.
kraenhansen marked this conversation as resolved.
Show resolved Hide resolved
//
// 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";

import { objectTypes } from "./constants";
import { callMethod, registerTypeConverter } from "./rpc";

export function performFetch(request, responseHandler) {
const { url, ...init } = request;
if (typeof url !== "string") {
throw new Error("Expected a URL");
}
if (typeof responseHandler !== "object") {
throw new Error("Expected a response handler object");
}
const { onSuccess, onError } = responseHandler;
// Delegate to fetch
fetch(url, init).then(async (response) => {
const decodedBody = await response.text();
// Pull out the headers of the response
const headers = {};
response.headers.forEach((value, key) => {
headers[key] = value;
});
return {
statusCode: response.status,
headers,
body: decodedBody,
};
}).then(onSuccess, onError);
}

function deserializeResponseHandler(realmId, info) {
const { id } = info;
if (typeof id !== "number") {
throw new Error("Expected a nummeric id");
}
return {
onSuccess: function() {
callMethod(undefined, id, "onSuccess", Array.from(arguments));
},
onError: function() {
callMethod(undefined, id, "onError", Array.from(arguments));
},
}
}

registerTypeConverter(objectTypes.FETCHRESPONSEHANDLER, deserializeResponseHandler);
6 changes: 2 additions & 4 deletions lib/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import App, { createApp } from './app';
import Credentials, { createCredentials } from './credentials';
import * as rpc from './rpc';
import * as util from './util';
import { static as staticUserMethods } from '../user';
import { createSession } from './session';
import { invalidateCache } from './cache';
import { performFetch } from "./fetch";

const {debugHosts, debugPort} = NativeModules.Realm;

Expand Down Expand Up @@ -212,9 +212,7 @@ Object.defineProperties(Realm, {

for (let i = 0, len = debugHosts.length; i < len; i++) {
try {
let refreshAccessTokenCallback = staticUserMethods && staticUserMethods._refreshAccessToken ? staticUserMethods._refreshAccessToken.bind(User) : () => {};
// The session ID refers to the Realm constructor object in the RPC server.
Realm[keys.id] = createSession(refreshAccessTokenCallback, debugHosts[i] + ':' + debugPort);
Realm[keys.id] = rpc.createSession(debugHosts[i] + ":" + debugPort, { performFetch });
break;
} catch (e) {
// Only throw exception after all hosts have been tried.
Expand Down
Loading