Merge pull request #17430 from overleaf/dp-callbackify-class
Add callbackifyClass utility GitOrigin-RevId: 762b800ce0eff2f146147908838162f7d32bd855
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const { ObjectId } = require('mongodb')
|
||||
const PublisherModel = require('../../../../app/src/models/Publisher').Publisher
|
||||
const { callbackify } = require('util')
|
||||
const { callbackifyClass } = require('@overleaf/promise-utils')
|
||||
|
||||
let count = parseInt(Math.random() * 999999)
|
||||
|
||||
@@ -32,21 +32,7 @@ class PromisifiedPublisher {
|
||||
}
|
||||
}
|
||||
|
||||
class Publisher extends PromisifiedPublisher {}
|
||||
const Publisher = callbackifyClass(PromisifiedPublisher)
|
||||
Publisher.promises = class extends PromisifiedPublisher {}
|
||||
|
||||
// callbackify publisher class methods
|
||||
const nonPromiseMethods = ['constructor']
|
||||
Object.getOwnPropertyNames(PromisifiedPublisher.prototype).forEach(
|
||||
methodName => {
|
||||
const method = PromisifiedPublisher.prototype[methodName]
|
||||
if (
|
||||
typeof method === 'function' &&
|
||||
!nonPromiseMethods.includes(methodName)
|
||||
) {
|
||||
Publisher.prototype[methodName] = callbackify(method)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
module.exports = Publisher
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { db, ObjectId } = require('../../../../app/src/infrastructure/mongodb')
|
||||
const { expect } = require('chai')
|
||||
const { promisify } = require('util')
|
||||
const { promisifyClass } = require('@overleaf/promise-utils')
|
||||
const SubscriptionUpdater = require('../../../../app/src/Features/Subscription/SubscriptionUpdater')
|
||||
const PermissionsManager = require('../../../../app/src/Features/Authorization/PermissionsManager')
|
||||
const SSOConfigManager = require('../../../../modules/group-settings/app/src/sso/SSOConfigManager')
|
||||
@@ -192,16 +192,8 @@ class Subscription {
|
||||
}
|
||||
}
|
||||
|
||||
Subscription.promises = class extends Subscription {}
|
||||
|
||||
// promisify User class methods - works for methods with 0-1 output parameters,
|
||||
// otherwise we will need to implement the method manually instead
|
||||
const nonPromiseMethods = ['constructor', 'getCapabilities']
|
||||
Object.getOwnPropertyNames(Subscription.prototype).forEach(methodName => {
|
||||
const method = Subscription.prototype[methodName]
|
||||
if (typeof method === 'function' && !nonPromiseMethods.includes(methodName)) {
|
||||
Subscription.promises.prototype[methodName] = promisify(method)
|
||||
}
|
||||
Subscription.promises = promisifyClass(Subscription, {
|
||||
without: ['getCapabilities'],
|
||||
})
|
||||
|
||||
Subscription.promises.prototype.inviteUser = async function (adminUser, email) {
|
||||
|
||||
@@ -5,7 +5,7 @@ const { db, ObjectId } = require('../../../../app/src/infrastructure/mongodb')
|
||||
const UserModel = require('../../../../app/src/models/User').User
|
||||
const UserUpdater = require('../../../../app/src/Features/User/UserUpdater')
|
||||
const AuthenticationManager = require('../../../../app/src/Features/Authentication/AuthenticationManager')
|
||||
const { promisify } = require('util')
|
||||
const { promisifyClass } = require('@overleaf/promise-utils')
|
||||
const fs = require('fs')
|
||||
const Path = require('path')
|
||||
|
||||
@@ -1026,28 +1026,20 @@ class User {
|
||||
}
|
||||
}
|
||||
|
||||
User.promises = class extends User {
|
||||
doRequest(method, params) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.request[method.toLowerCase()](params, (err, response, body) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve({ response, body })
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// promisify User class methods - works for methods with 0-1 output parameters,
|
||||
// otherwise we will need to implement the method manually instead
|
||||
const nonPromiseMethods = ['constructor', 'setExtraAttributes']
|
||||
Object.getOwnPropertyNames(User.prototype).forEach(methodName => {
|
||||
const method = User.prototype[methodName]
|
||||
if (typeof method === 'function' && !nonPromiseMethods.includes(methodName)) {
|
||||
User.promises.prototype[methodName] = promisify(method)
|
||||
}
|
||||
User.promises = promisifyClass(User, {
|
||||
without: ['setExtraAttributes'],
|
||||
})
|
||||
|
||||
User.promises.prototype.doRequest = async function (method, params) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.request[method.toLowerCase()](params, (err, response, body) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve({ response, body })
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = User
|
||||
|
||||
Reference in New Issue
Block a user