lisb-hubot
Advanced tools
Comparing version
{ | ||
"name": "lisb-hubot", | ||
"version": "3.5.1+forked.3.3.2", | ||
"version": "4.0.0+forked.3.3.2", | ||
"author": "hubot", | ||
@@ -18,3 +18,2 @@ "keywords": [ | ||
"dependencies": { | ||
"hubot-direct": "^1.0.0", | ||
"async": ">=0.1.0 <1.0.0", | ||
@@ -26,2 +25,3 @@ "chalk": "^1.0.0", | ||
"express": "^4.16.3", | ||
"hubot-direct": ">=2 <3", | ||
"log": "1.4.0", | ||
@@ -46,4 +46,4 @@ "optparse": "1.0.4", | ||
"engines": { | ||
"node": "> 4.0.0", | ||
"npm": "> 2.0.0" | ||
"node": ">= 12", | ||
"npm": ">= 7" | ||
}, | ||
@@ -58,3 +58,3 @@ "main": "./index", | ||
"pretest": "standard", | ||
"test": "nyc --reporter=html --reporter=text mocha", | ||
"test": "nyc --reporter=html --reporter=text mocha --timeout 3000", | ||
"test:types": "tsc -p ./test-types/tsconfig.json", | ||
@@ -61,0 +61,0 @@ "coverage": "nyc report --reporter=text-lcov | coveralls", |
@@ -7,29 +7,2 @@ 'use strict' | ||
// If necessary, reconstructs a User object. Returns either: | ||
// | ||
// 1. If the original object was falsy, null | ||
// 2. If the original object was a User object, the original object | ||
// 3. If the original object was a plain JavaScript object, return | ||
// a User object with all of the original object's properties. | ||
let reconstructUserIfNecessary = function (user, robot) { | ||
if (!user) { | ||
return null | ||
} | ||
if (!user.constructor || (user.constructor && user.constructor.name !== 'User')) { | ||
let id = user.id | ||
delete user.id | ||
// Use the old user as the "options" object, | ||
// populating the new user with its values. | ||
// Also add the `robot` field so it gets a reference. | ||
user.robot = robot | ||
let newUser = new User(id, user) | ||
delete user.robot | ||
return newUser | ||
} else { | ||
return user | ||
} | ||
} | ||
class Brain extends EventEmitter { | ||
@@ -41,3 +14,2 @@ // Represents somewhat persistent storage for the robot. Extend this. | ||
super() | ||
this.robot = robot | ||
this.data = { | ||
@@ -168,7 +140,7 @@ users: {}, | ||
// Returns an Array of User objects. | ||
users () { | ||
const adapter = this.robot.adapter | ||
users (domainId) { | ||
const adapter = this.getRobot().adapter | ||
const delegateToMe = require('./adapter').prototype.users | ||
if (adapter && adapter.users !== delegateToMe) { | ||
return adapter.users() | ||
return adapter.users(domainId) | ||
} | ||
@@ -182,3 +154,9 @@ return this.data.users | ||
userForId (id, options) { | ||
const users = this.users() | ||
let domainId | ||
if (typeof options === 'string') { | ||
domainId = options | ||
options = undefined | ||
} | ||
const users = this.users(domainId) | ||
let user = users[id] | ||
@@ -207,6 +185,6 @@ if (!options) { | ||
// Returns a User instance for the user with the specified name. | ||
userForName (name) { | ||
userForName (name, domainId) { | ||
let result = null | ||
const lowerName = name.toLowerCase() | ||
const users = this.users() | ||
const users = this.users(domainId) | ||
for (let k in users || {}) { | ||
@@ -227,6 +205,6 @@ const userName = users[k]['name'] | ||
// Returns an Array of User instances matching the fuzzy name. | ||
usersForRawFuzzyName (fuzzyName) { | ||
usersForRawFuzzyName (fuzzyName, domainId) { | ||
const lowerFuzzyName = fuzzyName.toLowerCase() | ||
const users = this.users() || {} | ||
const users = this.users(domainId) || {} | ||
@@ -247,4 +225,4 @@ return Object.keys(users).reduce((result, key) => { | ||
// Returns an Array of User instances matching the fuzzy name. | ||
usersForFuzzyName (fuzzyName) { | ||
const matchedUsers = this.usersForRawFuzzyName(fuzzyName) | ||
usersForFuzzyName (fuzzyName, domainId) { | ||
const matchedUsers = this.usersForRawFuzzyName(fuzzyName, domainId) | ||
const lowerFuzzyName = fuzzyName.toLowerCase() | ||
@@ -260,3 +238,3 @@ const fuzzyMatchedUsers = matchedUsers.filter(user => user.name.toLowerCase() === lowerFuzzyName) | ||
rooms () { | ||
const adapter = this.robot.adapter | ||
const adapter = this.getRobot().adapter | ||
if (adapter && typeof adapter.talks === 'function') return adapter.talks() | ||
@@ -270,3 +248,3 @@ return this.data.talks | ||
domains () { | ||
const adapter = this.robot.adapter | ||
const adapter = this.getRobot().adapter | ||
if (adapter && typeof adapter.domains === 'function') return adapter.domains() | ||
@@ -273,0 +251,0 @@ return this.data.domains |
@@ -23,4 +23,4 @@ 'use strict' | ||
this.mockRobot = { | ||
emit () {}, | ||
on () {} | ||
emit () { }, | ||
on () { } | ||
} | ||
@@ -34,5 +34,5 @@ | ||
this.user1 = this.brain.userForId('1', {name: 'Guy One'}) | ||
this.user2 = this.brain.userForId('2', {name: 'Guy One Two'}) | ||
this.user3 = this.brain.userForId('3', {name: 'Girl Three'}) | ||
this.user1 = this.brain.userForId('1', { name: 'Guy One' }) | ||
this.user2 = this.brain.userForId('2', { name: 'Guy One Two' }) | ||
this.user3 = this.brain.userForId('3', { name: 'Girl Three' }) | ||
}) | ||
@@ -52,3 +52,3 @@ | ||
this.brain.mergeData({2: 'new'}) | ||
this.brain.mergeData({ 2: 'new' }) | ||
@@ -67,8 +67,8 @@ expect(this.brain.data).to.deep.equal({ | ||
it('coerces loaded data into User objects', function () { | ||
this.brain.mergeData({users: {'4': {'name': 'new', 'id': '4'}}}) | ||
it('discards loaded data and creates new user object instead', function () { | ||
this.brain.mergeData({ users: { '4': { 'name': 'new', 'id': '4' } } }) | ||
let user = this.brain.userForId('4') | ||
expect(user.constructor.name).to.equal('User') | ||
expect(user.id).to.equal('4') | ||
expect(user.name).to.equal('new') | ||
expect(user.name).to.equal('4') | ||
expect(isCircular(this.brain)).to.be.false | ||
@@ -220,3 +220,3 @@ }) | ||
it('passes the provided options to the new User', function () { | ||
const newUser = this.brain.userForId('all-new-user', {name: 'All New User', prop: 'mine'}) | ||
const newUser = this.brain.userForId('all-new-user', { name: 'All New User', prop: 'mine' }) | ||
expect(newUser.name).to.equal('All New User') | ||
@@ -288,2 +288,9 @@ expect(newUser.prop).to.equal('mine') | ||
describe('#users', function () { | ||
it('returns all user objects if mock robot (no adapter)', function () { | ||
const result = this.brain.users() | ||
expect(Object.keys(result)).to.deep.equal(['1', '2', '3']) | ||
}) | ||
}) | ||
describe('#rooms', function () { | ||
@@ -290,0 +297,0 @@ it('returns the empty value if mock robot', function () { |
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
321877
3.46%71
2.9%5477
4.24%+ Added
- Removed
Updated