Skip to content

Commit

Permalink
Merge pull request mainmatter#2874 from mainmatter/remove-rsvp
Browse files Browse the repository at this point in the history
feat: Use native promises, remove RSVP
  • Loading branch information
BobrImperator authored Dec 24, 2024
2 parents d43cb01 + e7c5154 commit 831ad9b
Show file tree
Hide file tree
Showing 20 changed files with 110 additions and 123 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
"volta": {
"node": "20.10.0",
"pnpm": "9.11.0"
}
},
"packageManager": "[email protected]"
}
13 changes: 6 additions & 7 deletions packages/ember-simple-auth/src/authenticators/base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import RSVP from 'rsvp';
import Evented from '@ember/object/evented';
import EmberObject from '@ember/object';

Expand Down Expand Up @@ -104,12 +103,12 @@ export default EmberObject.extend(Evented, {
@memberof BaseAuthenticator
@method restore
@param {Object} data The data to restore the session from
@return {Ember.RSVP.Promise} A promise that when it resolves results in the session becoming or remaining authenticated
@return {Promise} A promise that when it resolves results in the session becoming or remaining authenticated
@member
@public
*/
restore() {
return RSVP.reject();
return Promise.reject();
},

/**
Expand All @@ -133,12 +132,12 @@ export default EmberObject.extend(Evented, {
@memberof BaseAuthenticator
@method authenticate
@param {Any} [...args] The arguments that the authenticator requires to authenticate the session
@return {Ember.RSVP.Promise} A promise that when it resolves results in the session becoming authenticated
@return {Promise} A promise that when it resolves results in the session becoming authenticated
@member
@public
*/
authenticate() {
return RSVP.reject();
return Promise.reject();
},

/**
Expand All @@ -158,11 +157,11 @@ export default EmberObject.extend(Evented, {
@method invalidate
@param {Object} data The current authenticated session data
@param {Array} ...args additional arguments as required by the authenticator
@return {Ember.RSVP.Promise} A promise that when it resolves results in the session being invalidated
@return {Promise} A promise that when it resolves results in the session being invalidated
@member
@public
*/
invalidate() {
return RSVP.resolve();
return Promise.resolve();
},
});
7 changes: 3 additions & 4 deletions packages/ember-simple-auth/src/authenticators/devise.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Promise } from 'rsvp';
import { isEmpty } from '@ember/utils';
import { run } from '@ember/runloop';
import BaseAuthenticator from './base';
Expand Down Expand Up @@ -77,7 +76,7 @@ export default BaseAuthenticator.extend({
@memberof DeviseAuthenticator
@method restore
@param {Object} data The data to restore the session from
@return {Ember.RSVP.Promise} A promise that when it resolves results in the session becoming or remaining authenticated
@return {Promise} A promise that when it resolves results in the session becoming or remaining authenticated
@public
*/
restore(data) {
Expand All @@ -101,7 +100,7 @@ export default BaseAuthenticator.extend({
@method authenticate
@param {String} identification The user's identification
@param {String} password The user's password
@return {Ember.RSVP.Promise} A promise that when it resolves results in the session becoming authenticated. If authentication fails, the promise will reject with the server response; however, the authenticator reads that response already so if you need to read it again you need to clone the response object first
@return {Promise} A promise that when it resolves results in the session becoming authenticated. If authentication fails, the promise will reject with the server response; however, the authenticator reads that response already so if you need to read it again you need to clone the response object first
@public
*/
authenticate(identification, password) {
Expand Down Expand Up @@ -144,7 +143,7 @@ export default BaseAuthenticator.extend({
@memberof DeviseAuthenticator
@method invalidate
@return {Ember.RSVP.Promise} A resolving promise
@return {Promise} A resolving promise
@public
*/
invalidate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** @module ember-simple-auth/authenticators/oauth2-implicit-grant **/

import RSVP from 'rsvp';
import { isEmpty } from '@ember/utils';
import BaseAuthenticator from './base';
/**
Expand Down Expand Up @@ -52,11 +51,11 @@ export default BaseAuthenticator.extend({
@memberof OAuth2ImplicitGrantAuthenticator
@method restore
@param {Object} data The data to restore the session from
@return {Ember.RSVP.Promise} A promise that when it resolves results in the session becoming or remaining authenticated
@return {Promise} A promise that when it resolves results in the session becoming or remaining authenticated
@public
*/
restore(data) {
return new RSVP.Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
if (!this._validateData(data)) {
return reject('Could not restore session - "access_token" missing.');
}
Expand All @@ -77,11 +76,11 @@ export default BaseAuthenticator.extend({
@memberof OAuth2ImplicitGrantAuthenticator
@method authenticate
@param {Object} hash The location hash
@return {Ember.RSVP.Promise} A promise that when it resolves results in the session becoming authenticated
@return {Promise} A promise that when it resolves results in the session becoming authenticated
@public
*/
authenticate(hash) {
return new RSVP.Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
if (hash.error) {
reject(hash.error);
} else if (!this._validateData(hash)) {
Expand All @@ -97,11 +96,11 @@ export default BaseAuthenticator.extend({
@memberof OAuth2ImplicitGrantAuthenticator
@method invalidate
@return {Ember.RSVP.Promise} A promise that when it resolves results in the session being invalidated
@return {Promise} A promise that when it resolves results in the session being invalidated
@public
*/
invalidate() {
return RSVP.Promise.resolve();
return Promise.resolve();
},

_validateData(data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import RSVP from 'rsvp';
import { isEmpty } from '@ember/utils';
import { run, later, cancel } from '@ember/runloop';
import { A, makeArray } from '@ember/array';
Expand Down Expand Up @@ -142,11 +141,11 @@ export default BaseAuthenticator.extend({
@memberof OAuth2PasswordGrantAuthenticator
@method restore
@param {Object} data The data to restore the session from
@return {Ember.RSVP.Promise} A promise that when it resolves results in the session becoming or remaining authenticated. If restoration fails, the promise will reject with the server response (in case the access token had expired and was refreshed using a refresh token); however, the authenticator reads that response already so if you need to read it again you need to clone the response object first
@return {Promise} A promise that when it resolves results in the session becoming or remaining authenticated. If restoration fails, the promise will reject with the server response (in case the access token had expired and was refreshed using a refresh token); however, the authenticator reads that response already so if you need to read it again you need to clone the response object first
@public
*/
restore(data) {
return new RSVP.Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
const now = new Date().getTime();
const refreshAccessTokens = this.get('refreshAccessTokens');
if (!isEmpty(data['expires_at']) && data['expires_at'] < now) {
Expand Down Expand Up @@ -226,11 +225,11 @@ export default BaseAuthenticator.extend({
@param {String} password The resource owner password
@param {String|Array} scope The scope of the access request (see [RFC 6749, section 3.3](http://tools.ietf.org/html/rfc6749#section-3.3))
@param {Object} headers Optional headers that particular backends may require (for example sending 2FA challenge responses)
@return {Ember.RSVP.Promise} A promise that when it resolves results in the session becoming authenticated. If authentication fails, the promise will reject with the server response; however, the authenticator reads that response already so if you need to read it again you need to clone the response object first
@return {Promise} A promise that when it resolves results in the session becoming authenticated. If authentication fails, the promise will reject with the server response; however, the authenticator reads that response already so if you need to read it again you need to clone the response object first
@public
*/
authenticate(identification, password, scope = [], headers = {}) {
return new RSVP.Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
const data = { grant_type: 'password', username: identification, password };
const serverTokenEndpoint = this.get('serverTokenEndpoint');

Expand Down Expand Up @@ -277,7 +276,7 @@ export default BaseAuthenticator.extend({
@memberof OAuth2PasswordGrantAuthenticator
@method invalidate
@param {Object} data The current authenticated session data
@return {Ember.RSVP.Promise} A promise that when it resolves results in the session being invalidated. If invalidation fails, the promise will reject with the server response (in case token revocation is used); however, the authenticator reads that response already so if you need to read it again you need to clone the response object first
@return {Promise} A promise that when it resolves results in the session being invalidated. If invalidation fails, the promise will reject with the server response (in case token revocation is used); however, the authenticator reads that response already so if you need to read it again you need to clone the response object first
@public
*/
invalidate(data) {
Expand All @@ -287,7 +286,7 @@ export default BaseAuthenticator.extend({
delete this._refreshTokenTimeout;
resolve();
}
return new RSVP.Promise(resolve => {
return new Promise(resolve => {
if (isEmpty(serverTokenRevocationEndpoint)) {
success.apply(this, [resolve]);
} else {
Expand All @@ -306,7 +305,7 @@ export default BaseAuthenticator.extend({
const succeed = () => {
success.apply(this, [resolve]);
};
RSVP.all(requests).then(succeed, succeed);
Promise.all(requests).then(succeed, succeed);
}
});
},
Expand Down Expand Up @@ -342,7 +341,7 @@ export default BaseAuthenticator.extend({
method: 'POST',
};

return new RSVP.Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
fetch(url, options)
.then(response => {
response.text().then(text => {
Expand Down Expand Up @@ -396,7 +395,7 @@ export default BaseAuthenticator.extend({
}

const serverTokenEndpoint = this.get('serverTokenEndpoint');
return new RSVP.Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
this.makeRequest(serverTokenEndpoint, data).then(
response => {
run(() => {
Expand Down
7 changes: 3 additions & 4 deletions packages/ember-simple-auth/src/authenticators/test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import RSVP from 'rsvp';
import BaseAuthenticator from './base';

export default BaseAuthenticator.extend({
restore(data) {
return RSVP.resolve(data);
return Promise.resolve(data);
},

authenticate(data) {
return RSVP.resolve(data);
return Promise.resolve(data);
},

invalidate() {
return RSVP.resolve();
return Promise.resolve();
},
});
9 changes: 4 additions & 5 deletions packages/ember-simple-auth/src/authenticators/torii.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import RSVP from 'rsvp';
import { assert, deprecate } from '@ember/debug';
import { isPresent, isEmpty } from '@ember/utils';
import BaseAuthenticator from './base';
Expand Down Expand Up @@ -59,7 +58,7 @@ export default BaseAuthenticator.extend({
@memberof ToriiAuthenticator
@method restore
@param {Object} data The data to restore the session from
@return {Ember.RSVP.Promise} A promise that when it resolves results in the session becoming or remaining authenticated
@return {Promise} A promise that when it resolves results in the session becoming or remaining authenticated
@public
*/
restore(data) {
Expand All @@ -83,7 +82,7 @@ export default BaseAuthenticator.extend({
);
} else {
delete this._provider;
return RSVP.reject();
return Promise.reject();
}
},

Expand All @@ -98,7 +97,7 @@ export default BaseAuthenticator.extend({
@method authenticate
@param {String} provider The torii provider to authenticate the session with
@param {Object} options The options to pass to the torii provider
@return {Ember.RSVP.Promise} A promise that when it resolves results in the session becoming authenticated
@return {Promise} A promise that when it resolves results in the session becoming authenticated
@public
*/
authenticate(provider, options) {
Expand All @@ -119,7 +118,7 @@ export default BaseAuthenticator.extend({
@memberof ToriiAuthenticator
@method invalidate
@return {Ember.RSVP.Promise} A promise that when it resolves results in the session being invalidated
@return {Promise} A promise that when it resolves results in the session being invalidated
@public
*/
invalidate(data) {
Expand Down
9 changes: 4 additions & 5 deletions packages/ember-simple-auth/src/internal-session.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import RSVP from 'rsvp';
import { isEmpty, isNone } from '@ember/utils';
import ObjectProxy from '@ember/object/proxy';
import Evented from '@ember/object/evented';
Expand Down Expand Up @@ -75,7 +74,7 @@ export default ObjectProxy.extend(Evented, {
return this._setup(authenticatorFactory, content, true);
},
error => {
const rejectWithError = () => RSVP.Promise.reject(error);
const rejectWithError = () => Promise.reject(error);

this._busy = false;
return this._clear().then(rejectWithError, rejectWithError);
Expand All @@ -89,7 +88,7 @@ export default ObjectProxy.extend(Evented, {

if (!this.get('isAuthenticated')) {
this._busy = false;
return RSVP.Promise.resolve();
return Promise.resolve();
}

let authenticator = this._lookupAuthenticator(this.authenticator);
Expand All @@ -102,14 +101,14 @@ export default ObjectProxy.extend(Evented, {
error => {
this.trigger('sessionInvalidationFailed', error);
this._busy = false;
return RSVP.Promise.reject(error);
return Promise.reject(error);
}
);
},

restore() {
this._busy = true;
const reject = () => RSVP.Promise.reject();
const reject = () => Promise.reject();

return this.store.restore().then(
restoredContent => {
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-simple-auth/src/services/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export default Service.extend({
@method authenticate
@param {String} authenticator The authenticator to use to authenticate the session
@param {Any} [...args] The arguments to pass to the authenticator; depending on the type of authenticator these might be a set of credentials, a Facebook OAuth Token, etc.
@return {RSVP.Promise} A promise that resolves when the session was authenticated successfully and rejects otherwise
@return {Promise} A promise that resolves when the session was authenticated successfully and rejects otherwise
@public
*/
authenticate() {
Expand Down Expand Up @@ -184,7 +184,7 @@ export default Service.extend({
@memberof SessionService
@method invalidate
@param {Array} ...args arguments that will be passed to the authenticator
@return {RSVP.Promise} A promise that resolves when the session was invalidated successfully and rejects otherwise
@return {Promise} A promise that resolves when the session was invalidated successfully and rejects otherwise
@public
*/
invalidate() {
Expand Down
6 changes: 3 additions & 3 deletions packages/ember-simple-auth/src/session-stores/adaptive.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export default Base.extend({
@memberof AdaptiveStore
@method persist
@param {Object} data The data to persist
@return {Ember.RSVP.Promise} A promise that resolves when the data has successfully been persisted and rejects otherwise.
@return {Promise} A promise that resolves when the data has successfully been persisted and rejects otherwise.
@public
*/
persist() {
Expand All @@ -217,7 +217,7 @@ export default Base.extend({
@memberof AdaptiveStore
@method restore
@return {Ember.RSVP.Promise} A promise that resolves with the data currently persisted in the store when the data has been restored successfully and rejects otherwise.
@return {Promise} A promise that resolves with the data currently persisted in the store when the data has been restored successfully and rejects otherwise.
@public
*/
restore() {
Expand All @@ -231,7 +231,7 @@ export default Base.extend({
@memberof AdaptiveStore
@method clear
@return {Ember.RSVP.Promise} A promise that resolves when the store has been cleared successfully and rejects otherwise.
@return {Promise} A promise that resolves when the store has been cleared successfully and rejects otherwise.
@public
*/
clear() {
Expand Down
Loading

0 comments on commit 831ad9b

Please sign in to comment.