refactor: comprehensive permissionOverwrites refactor (#2818)

* wip: comprehensive permissionOverwrites refactor

* PermissionOverwrites.resolve should Promise.reject()

where a promise is the expected return value

* On second thought, async rewrite to automatically reject on throw

* Fix some docs

* Fix a bug

* fix 2 more bugs

* typings: Updated for latest commit

* typings: Add missing method in GuildChannel

* typings: Add missing `| null` in PermissionOverwriteOption type

* Suggested changes
This commit is contained in:
bdistin
2018-09-21 05:21:51 -05:00
committed by SpaceEEC
parent 6d184257b3
commit 3d8207a3db
6 changed files with 202 additions and 118 deletions

View File

@@ -2,6 +2,7 @@ const { Colors, DefaultOptions, Endpoints } = require('./Constants');
const fetch = require('node-fetch');
const { Error: DiscordError, RangeError, TypeError } = require('../errors');
const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
const isObject = d => typeof d === 'object' && d !== null;
const { parse } = require('path');
/**
@@ -19,7 +20,6 @@ class Util {
* @returns {Object}
*/
static flatten(obj, ...props) {
const isObject = d => typeof d === 'object' && d !== null;
if (!isObject(obj)) return obj;
props = Object.assign(...Object.keys(obj).filter(k => !k.startsWith('_')).map(k => ({ [k]: true })), ...props);
@@ -39,7 +39,7 @@ class Util {
// If it's an array, flatten each element
else if (Array.isArray(element)) out[newProp] = element.map(e => Util.flatten(e));
// If it's an object with a primitive `valueOf`, use that value
else if (valueOf && !isObject(valueOf)) out[newProp] = valueOf;
else if (typeof valueOf !== 'object') out[newProp] = valueOf;
// If it's a primitive
else if (!elemIsObj) out[newProp] = element;
}