Skip to content

Commit

Permalink
Merge branch 'main' into chore/email-update
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Jul 31, 2024
2 parents ec7dd55 + dc13324 commit 5fdd9c9
Show file tree
Hide file tree
Showing 32 changed files with 753 additions and 2,688 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ApplicationCommandType,
ApplicationIntegrationType,
ChannelType,
InteractionContextType,
Expand Down Expand Up @@ -133,6 +134,10 @@ describe('Slash Commands', () => {
});

describe('Builder with simple options', () => {
test('GIVEN valid builder THEN returns type included', () => {
expect(getNamedBuilder().toJSON()).includes({ type: ApplicationCommandType.ChatInput });
});

test('GIVEN valid builder with options THEN does not throw error', () => {
expect(() =>
getBuilder()
Expand Down
2 changes: 1 addition & 1 deletion packages/builders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"@discordjs/formatters": "workspace:^",
"@discordjs/util": "workspace:^",
"@sapphire/shapeshift": "^3.9.7",
"discord-api-types": "0.37.90",
"discord-api-types": "0.37.93",
"fast-deep-equal": "^3.1.3",
"ts-mixer": "^6.0.4",
"tslib": "^2.6.2"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type {
ApplicationIntegrationType,
InteractionContextType,
LocalizationMap,
Permissions,
RESTPostAPIChatInputApplicationCommandsJSONBody,
import {
ApplicationCommandType,
type ApplicationIntegrationType,
type InteractionContextType,
type LocalizationMap,
type Permissions,
type RESTPostAPIChatInputApplicationCommandsJSONBody,
} from 'discord-api-types/v10';
import type { RestOrArray } from '../../../util/normalizeArray.js';
import { normalizeArray } from '../../../util/normalizeArray.js';
Expand Down Expand Up @@ -149,6 +150,7 @@ export class SharedSlashCommand {

return {
...this,
type: ApplicationCommandType.ChatInput,
options: this.options.map((option) => option.toJSON()),
};
}
Expand Down
75 changes: 45 additions & 30 deletions packages/collection/__tests__/collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,14 +713,57 @@ describe('reduce() tests', () => {
expect<number>(sum).toStrictEqual(6);
});

test('reduce collection into a single value with different accumulator type', () => {
const str = coll.reduce((a, x) => a.concat(x.toString()), '');
expect<string>(str).toStrictEqual('123');
});

test('reduce empty collection with initial value', () => {
const coll = createCollection();
expect<number>(coll.reduce((a, x) => a + x, 0)).toStrictEqual(0);
});

test('reduce empty collection without initial value', () => {
const coll = createCollection();
expect(() => coll.reduce((a, x) => a + x)).toThrowError(
new TypeError('Reduce of empty collection with no initial value'),
);
});
});

describe('reduceRight() tests', () => {
const coll = createTestCollection();

test('throws if fn is not a function', () => {
// @ts-expect-error: Invalid function
expectInvalidFunctionError(() => coll.reduceRight());
// @ts-expect-error: Invalid function
expectInvalidFunctionError(() => coll.reduceRight(123), 123);
});

test('reduce collection into a single value with initial value', () => {
const sum = coll.reduceRight((a, x) => a + x, 0);
expect<number>(sum).toStrictEqual(6);
});

test('reduce collection into a single value without initial value', () => {
const sum = coll.reduceRight((a, x) => a + x);
expect<number>(sum).toStrictEqual(6);
});

test('reduce collection into a single value with different accumulator type', () => {
const str = coll.reduceRight((a, x) => a.concat(x.toString()), '');
expect<string>(str).toStrictEqual('321');
});

test('reduce empty collection with initial value', () => {
const coll = createCollection();
expect(coll.reduce((a, x) => a + x, 0)).toStrictEqual(0);
expect<number>(coll.reduceRight((a, x) => a + x, 0)).toStrictEqual(0);
});

test('reduce empty collection without initial value', () => {
const coll = createCollection();
expect(() => coll.reduce((a: number, x) => a + x)).toThrowError(
expect(() => coll.reduceRight((a, x) => a + x)).toThrowError(
new TypeError('Reduce of empty collection with no initial value'),
);
});
Expand Down Expand Up @@ -1013,31 +1056,3 @@ describe('findLastKey() tests', () => {
}, null);
});
});

describe('reduceRight() tests', () => {
const coll = createTestCollection();

test('throws if fn is not a function', () => {
// @ts-expect-error: Invalid function
expectInvalidFunctionError(() => coll.reduceRight());
// @ts-expect-error: Invalid function
expectInvalidFunctionError(() => coll.reduceRight(123), 123);
});

test('reduce collection into a single value with initial value', () => {
const sum = coll.reduceRight((a, x) => a + x, 0);
expect(sum).toStrictEqual(6);
});

test('reduce collection into a single value without initial value', () => {
const sum = coll.reduceRight<number>((a, x) => a + x);
expect(sum).toStrictEqual(6);
});

test('reduce empty collection without initial value', () => {
const coll = createCollection();
expect(() => coll.reduceRight((a: number, x) => a + x)).toThrowError(
new TypeError('Reduce of empty collection with no initial value'),
);
});
});
18 changes: 17 additions & 1 deletion packages/collection/src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,15 @@ export class Collection<Key, Value> extends Map<Key, Value> {
* collection.reduce((acc, guild) => acc + guild.memberCount, 0);
* ```
*/
public reduce<InitialValue = Value>(
public reduce(
fn: (accumulator: Value, value: Value, key: Key, collection: this) => Value,
initialValue?: Value,
): Value;
public reduce<InitialValue>(
fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue,
initialValue: InitialValue,
): InitialValue;
public reduce<InitialValue>(
fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue,
initialValue?: InitialValue,
): InitialValue {
Expand Down Expand Up @@ -645,6 +653,14 @@ export class Collection<Key, Value> extends Map<Key, Value> {
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
* @param initialValue - Starting value for the accumulator
*/
public reduceRight(
fn: (accumulator: Value, value: Value, key: Key, collection: this) => Value,
initialValue?: Value,
): Value;
public reduceRight<InitialValue>(
fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue,
initialValue: InitialValue,
): InitialValue;
public reduceRight<InitialValue>(
fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue,
initialValue?: InitialValue,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@discordjs/ws": "workspace:^",
"@sapphire/snowflake": "^3.5.3",
"@vladfrangu/async_event_emitter": "^2.2.4",
"discord-api-types": "0.37.90"
"discord-api-types": "0.37.93"
},
"devDependencies": {
"@discordjs/api-extractor": "workspace:^",
Expand Down
Loading

0 comments on commit 5fdd9c9

Please sign in to comment.