Skip to content

Commit

Permalink
feat: migrate to @sapphire/result and re-export the package (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Feb 8, 2022
1 parent fd7be0b commit 9ed3d98
Show file tree
Hide file tree
Showing 52 changed files with 70 additions and 253 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@sapphire/discord.js-utilities": "^4.6.0",
"@sapphire/pieces": "^3.2.0",
"@sapphire/ratelimits": "^2.3.0",
"@sapphire/result": "^1.0.0",
"@sapphire/stopwatch": "^1.3.0",
"@sapphire/utilities": "^3.3.0",
"lexure": "^0.17.0",
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ export {
StoreRegistry,
StoreRegistryEntries
} from '@sapphire/pieces';
export * from '@sapphire/result';
export type { Awaitable } from '@sapphire/utilities';
export * from './lib/errors/ArgumentError';
export * from './lib/errors/Identifiers';
export * from './lib/errors/PreconditionError';
export * from './lib/errors/UserError';
export * from './lib/parsers/Args';
export * from './lib/parsers/Maybe';
export * from './lib/parsers/Result';
export * from './lib/plugins/Plugin';
export * from './lib/plugins/PluginManager';
export * from './lib/plugins/symbols';
Expand Down
13 changes: 9 additions & 4 deletions src/lib/parsers/Args.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ChannelTypes, GuildBasedChannelTypes } from '@sapphire/discord.js-utilities';
import { container } from '@sapphire/pieces';
import { err, isErr, isOk, isSome, maybe, ok, type Err, type Maybe, type Ok, type Result } from '@sapphire/result';
import type {
CategoryChannel,
DMChannel,
Expand All @@ -21,8 +22,6 @@ import { UserError } from '../errors/UserError';
import type { EmojiObject } from '../resolvers';
import type { Argument, IArgument } from '../structures/Argument';
import type { MessageCommand } from '../structures/Command';
import { isSome, maybe, Maybe } from './Maybe';
import { Err, err, isErr, isOk, ok, Ok, Result } from './Result';

/**
* The argument parser to be used in {@link Command}.
Expand Down Expand Up @@ -126,7 +125,9 @@ export class Args {
);
if (result === null) return this.missingArguments();
if (isOk(result)) return result as Ok<ArgType[K]>;
return result;

// We need to typecast here because TS doesn't resolve that the type from @sapphire/result is identical to that of Lexure
return result as Result<ArgType[K], UserError>;
}

/**
Expand Down Expand Up @@ -299,7 +300,11 @@ export class Args {
);
if (result === null) break;
if (isErr(result)) {
if (output.length === 0) return result;
if (output.length === 0) {
// We need to typecast here because TS doesn't resolve that the type from @sapphire/result is identical to that of Lexure
return result as Result<ArgType[K][], UserError>;
}

break;
}

Expand Down
98 changes: 0 additions & 98 deletions src/lib/parsers/Maybe.ts

This file was deleted.

97 changes: 0 additions & 97 deletions src/lib/parsers/Result.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib/resolvers/boolean.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { err, ok, Result } from '@sapphire/result';
import { Identifiers } from '../errors/Identifiers';
import { err, ok, Result } from '../parsers/Result';

const baseTruths = ['1', 'true', '+', 't', 'yes', 'y'] as const;
const baseFalses = ['0', 'false', '-', 'f', 'no', 'n'] as const;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/resolvers/channel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ChannelMentionRegex, ChannelTypes } from '@sapphire/discord.js-utilities';
import { container } from '@sapphire/pieces';
import { err, ok, Result } from '@sapphire/result';
import type { Message, Snowflake } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';
import { err, ok, Result } from '../parsers/Result';

export function resolveChannel(parameter: string, message: Message): Result<ChannelTypes, Identifiers.ArgumentChannelError> {
const channelId = (ChannelMentionRegex.exec(parameter)?.[1] ?? parameter) as Snowflake;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/resolvers/date.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { err, ok, Result } from '@sapphire/result';
import { Identifiers } from '../errors/Identifiers';
import { err, ok, Result } from '../parsers/Result';

export function resolveDate(
parameter: string,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/resolvers/dmChannel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isDMChannel } from '@sapphire/discord.js-utilities';
import { err, ok, Result } from '@sapphire/result';
import type { DMChannel, Message } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';
import { err, ok, Result } from '../parsers/Result';
import { resolveChannel } from './channel';

export function resolveDMChannel(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/resolvers/emoji.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EmojiRegex, TwemojiRegex } from '@sapphire/discord-utilities';
import { Err, err, Ok, ok } from '@sapphire/result';
import { Util } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';
import { Err, err, Ok, ok } from '../parsers/Result';

export function resolveEmoji(parameter: string): Ok<EmojiObject> | Err<Identifiers> {
const twemoji = TwemojiRegex.exec(parameter)?.[0] ?? null;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/resolvers/enum.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { err, ok, Result } from '@sapphire/result';
import { Identifiers } from '../errors/Identifiers';
import { err, ok, Result } from '../parsers/Result';

export function resolveEnum(
parameter: string,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/resolvers/float.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { err, ok, Result } from '@sapphire/result';
import { Identifiers } from '../errors/Identifiers';
import { err, ok, Result } from '../parsers/Result';

export function resolveFloat(
parameter: string,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/resolvers/guildCategoryChannel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isCategoryChannel } from '@sapphire/discord.js-utilities';
import type { Result } from '@sapphire/result';
import type { CategoryChannel, Guild } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';
import type { Result } from '../parsers/Result';
import { resolveGuildChannelPredicate } from '../utils/resolvers/resolveGuildChannelPredicate';

export function resolveGuildCategoryChannel(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/resolvers/guildChannel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ChannelMentionRegex, SnowflakeRegex } from '@sapphire/discord-utilities';
import type { GuildBasedChannelTypes } from '@sapphire/discord.js-utilities';
import { err, ok, Result } from '@sapphire/result';
import type { Guild, Snowflake } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';
import { err, ok, Result } from '../parsers/Result';

export function resolveGuildChannel(parameter: string, guild: Guild): Result<GuildBasedChannelTypes, Identifiers.ArgumentGuildChannelError> {
const channel = resolveById(parameter, guild) ?? resolveByQuery(parameter, guild);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/resolvers/guildNewsChannel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isNewsChannel } from '@sapphire/discord.js-utilities';
import type { Result } from '@sapphire/result';
import type { Guild, NewsChannel } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';
import type { Result } from '../parsers/Result';
import { resolveGuildChannelPredicate } from '../utils/resolvers/resolveGuildChannelPredicate';

export function resolveGuildNewsChannel(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/resolvers/guildNewsThreadChannel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isNewsThreadChannel } from '@sapphire/discord.js-utilities';
import type { Result } from '@sapphire/result';
import type { Guild, ThreadChannel } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';
import type { Result } from '../parsers/Result';
import { resolveGuildChannelPredicate } from '../utils/resolvers/resolveGuildChannelPredicate';

export function resolveGuildNewsThreadChannel(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/resolvers/guildPrivateThreadChannel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isPrivateThreadChannel } from '@sapphire/discord.js-utilities';
import type { Result } from '@sapphire/result';
import type { Guild, ThreadChannel } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';
import type { Result } from '../parsers/Result';
import { resolveGuildChannelPredicate } from '../utils/resolvers/resolveGuildChannelPredicate';

export function resolveGuildPrivateThreadChannel(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/resolvers/guildPublicThreadChannel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isPublicThreadChannel } from '@sapphire/discord.js-utilities';
import type { Result } from '@sapphire/result';
import type { Guild, ThreadChannel } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';
import type { Result } from '../parsers/Result';
import { resolveGuildChannelPredicate } from '../utils/resolvers/resolveGuildChannelPredicate';

export function resolveGuildPublicThreadChannel(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/resolvers/guildStageVoiceChannel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isStageChannel } from '@sapphire/discord.js-utilities';
import type { Result } from '@sapphire/result';
import type { Guild, StageChannel } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';
import type { Result } from '../parsers/Result';
import { resolveGuildChannelPredicate } from '../utils/resolvers/resolveGuildChannelPredicate';

export function resolveGuildStageVoiceChannel(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/resolvers/guildTextChannel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isTextChannel } from '@sapphire/discord.js-utilities';
import type { Result } from '@sapphire/result';
import type { Guild, TextChannel } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';
import type { Result } from '../parsers/Result';
import { resolveGuildChannelPredicate } from '../utils/resolvers/resolveGuildChannelPredicate';

export function resolveGuildTextChannel(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/resolvers/guildThreadChannel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isThreadChannel } from '@sapphire/discord.js-utilities';
import type { Result } from '@sapphire/result';
import type { Guild, ThreadChannel } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';
import type { Result } from '../parsers/Result';
import { resolveGuildChannelPredicate } from '../utils/resolvers/resolveGuildChannelPredicate';

export function resolveGuildThreadChannel(
Expand Down

0 comments on commit 9ed3d98

Please sign in to comment.