Skip to content

Commit

Permalink
feature: implement more typecasting to reduce type complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
4x8Matrix committed Jan 16, 2025
1 parent 8180841 commit bfcf007
Show file tree
Hide file tree
Showing 16 changed files with 210 additions and 203 deletions.
12 changes: 7 additions & 5 deletions packages/classes/src/application/application.luau
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function Application.Prototype.createSlashCommandAsync(self: Application, slashC
assert(response:isOk(), response:unwrapErr())

return commandObject.new(response:unwrapOk())
end)
end) :: future.FutureLike<string, commandObject.Command>
end

--[[
Expand All @@ -50,7 +50,9 @@ function Application.Prototype.deleteSlashCommandAsync(self: Application, slashC
local response = rest.commands.deleteGlobalApplicationCommandAsync(request, self.id, slashCommandId):await()

assert(response:isOk(), response:unwrapErr())
end)

return nil
end) :: future.FutureLike<string, nil>
end

--[[
Expand All @@ -70,7 +72,7 @@ function Application.Prototype.editSlashCommandAsync(
assert(response:isOk(), response:unwrapErr())

return commandObject.new(response:unwrapOk())
end)
end) :: future.FutureLike<string, commandObject.Command>
end

--[[
Expand All @@ -95,7 +97,7 @@ function Application.Prototype.getSlashCommandsAsync(self: Application, withLoca
end

return commands
end)
end) :: future.FutureLike<string, { commandObject.Command }>
end

--[[
Expand All @@ -120,7 +122,7 @@ function Application.Prototype.overwriteSlashCommandsAsync(
end

return commands
end)
end) :: future.FutureLike<string, { commandObject.Command }>
end

function Application.Prototype.sync(self: Application, applicationData: apiTypes.ApplicationObject)
Expand Down
8 changes: 4 additions & 4 deletions packages/classes/src/channels/behaviour/channel.luau
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ function ChannelBehaviour.Prototype.deleteChannelAsync<T>(self: Channel<T>)

self:sync(response:unwrapOk())

return self :: T
end)
return self
end) :: future.FutureLike<string, Channel<T>>
end

--[[
Expand All @@ -50,7 +50,7 @@ function ChannelBehaviour.Prototype.triggerTypingIndicatorAsync<T>(self: Channel
assert(response:isOk(), response:unwrapErr())

return nil
end)
end) :: future.FutureLike<string, nil>
end

--[[
Expand All @@ -67,7 +67,7 @@ function ChannelBehaviour.Prototype.modifyAsync<T>(self: Channel<T>, json: build
self:sync(response:unwrapOk())

return self
end)
end) :: future.FutureLike<string, Channel<T>>
end

function ChannelBehaviour.Interface.inheritProperties(class: any, channelData: apiTypes.ChannelObject)
Expand Down
2 changes: 1 addition & 1 deletion packages/classes/src/channels/behaviour/forum.luau
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function ForumBehaviour.Prototype.createPostAsync<T>(self: Channel<T>, post: bui
assert(response:isOk(), response:unwrapErr())

return response:unwrapOk().id
end)
end) :: future.FutureLike<string, apiTypes.Snowflake>
end

function ForumBehaviour.Interface.inheritProperties(class: any, channelData: apiTypes.ChannelObject)
Expand Down
9 changes: 4 additions & 5 deletions packages/classes/src/channels/behaviour/groupDM.luau
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ local apiTypes = require("../../../lune_packages/api_types")
local future = require("../../../luau_packages/future")
local rest = require("../../../lune_packages/rest")
local state = require("../../../lune_packages/state")
local builders = require("../../../lune_packages/builders")

local user = require("../../user")

Expand Down Expand Up @@ -37,7 +36,7 @@ function GroupDMBehaviour.Prototype.addRecipient<T>(
assert(response:isOk(), response:unwrapErr())

return nil
end)
end) :: future.FutureLike<string, nil>
end

--[[
Expand All @@ -52,7 +51,7 @@ function GroupDMBehaviour.Prototype.removeRecipient<T>(self: Channel<T>, userId:
assert(response:isOk(), response:unwrapErr())

return nil
end)
end) :: future.FutureLike<string, nil>
end

--[[
Expand All @@ -61,7 +60,7 @@ end
function GroupDMBehaviour.Prototype.setNameAsync<T>(self: Channel<T>, groupName: string)
return self:modifyAsync({
name = groupName,
})
}) :: future.FutureLike<string, Channel<T>>
end

--[[
Expand All @@ -71,7 +70,7 @@ function GroupDMBehaviour.Prototype.setIconAsync<T>(self: Channel<T>, iconData:
return self:modifyAsync({
name = self.name,
icon = iconData,
})
}) :: future.FutureLike<string, Channel<T>>
end

function GroupDMBehaviour.Interface.inheritProperties(class: any, channelData: apiTypes.ChannelObject)
Expand Down
32 changes: 22 additions & 10 deletions packages/classes/src/channels/behaviour/guild.luau
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function GuildBehaviour.Prototype.setPositionAsync<T>(self: Channel<T>, position
assert(response:isOk(), response:unwrapErr())

return nil
end)
end) :: future.FutureLike<string, nil>
end

--[[
Expand All @@ -56,7 +56,7 @@ function GuildBehaviour.Prototype.setParentAsync<T>(self: Channel<T>, parentId:
assert(response:isOk(), response:unwrapErr())

return nil
end)
end) :: future.FutureLike<string, nil>
end

--[[
Expand Down Expand Up @@ -84,7 +84,7 @@ function GuildBehaviour.Prototype.setPermissionsAsync<T>(
assert(response:isOk(), response:unwrapErr())

return nil
end)
end) :: future.FutureLike<string, nil>
end

--[[
Expand All @@ -104,7 +104,7 @@ function GuildBehaviour.Prototype.deletePermissionAsync<T>(
assert(response:isOk(), response:unwrapErr())

return nil
end)
end) :: future.FutureLike<string, nil>
end

--[[
Expand All @@ -125,7 +125,7 @@ function GuildBehaviour.Prototype.getInvitesAsync<T>(self: Channel<T>)
end

return invites
end)
end) :: future.FutureLike<string, { invite.Invite }>
end

--[[
Expand All @@ -140,7 +140,7 @@ function GuildBehaviour.Prototype.createInviteAsync<T>(self: Channel<T>, json: b
assert(response:isOk(), response:unwrapErr())

return invite.new(self.state, response:unwrapOk())
end)
end) :: future.FutureLike<string, invite.Invite>
end

--[[
Expand Down Expand Up @@ -181,7 +181,11 @@ function GuildBehaviour.Prototype.listPublicArchivedThreadsAsync<T>(
end

return returnedValue
end)
end) :: future.FutureLike<string, {
threads: { apiTypes.Snowflake },
members: { threadMember.ThreadMember },
hasMore: boolean,
}>
end

--[[
Expand Down Expand Up @@ -222,7 +226,11 @@ function GuildBehaviour.Prototype.listPrivateArchivedThreadsAsync<T>(
end

return returnedValue
end)
end) :: future.FutureLike<string, {
threads: { apiTypes.Snowflake },
members: { threadMember.ThreadMember },
hasMore: boolean,
}>
end

--[[
Expand Down Expand Up @@ -263,7 +271,11 @@ function GuildBehaviour.Prototype.listJoinedPrivateArchivedThreadsAsync<T>(
end

return returnedValue
end)
end) :: future.FutureLike<string, {
threads: { apiTypes.Snowflake },
members: { threadMember.ThreadMember },
hasMore: boolean,
}>
end

--[[
Expand All @@ -272,7 +284,7 @@ end
function GuildBehaviour.Prototype.setNameAsync<T>(self: Channel<T>, groupName: string)
return self:modifyAsync({
name = groupName,
})
}) :: future.FutureLike<string, Channel<T>>
end

function GuildBehaviour.Interface.inheritProperties(class: any, channelData: apiTypes.ChannelObject)
Expand Down
2 changes: 1 addition & 1 deletion packages/classes/src/channels/behaviour/media.luau
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function MediaBehaviour.Prototype.createPostAsync<T>(self: Channel<T>, post: bui
assert(response:isOk(), response:unwrapErr())

return response:unwrapOk().id
end)
end) :: future.FutureLike<string, apiTypes.Snowflake>
end

function MediaBehaviour.Interface.inheritProperties(class: any, channelData: apiTypes.ChannelObject)
Expand Down
18 changes: 9 additions & 9 deletions packages/classes/src/channels/behaviour/text.luau
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function TextBehaviour.Prototype.bulkDeleteMessagesAsync<T>(self: Channel<T>, me
assert(response:isOk(), response:unwrapErr())

return nil
end)
end) :: future.FutureLike<string, nil>
end

--[[
Expand Down Expand Up @@ -67,7 +67,7 @@ function TextBehaviour.Prototype.getMessagesAsync<T>(
end

return messages
end)
end) :: future.FutureLike<string, { message.Message }>
end

--[[
Expand All @@ -82,7 +82,7 @@ function TextBehaviour.Prototype.getMessageAsync<T>(self: Channel<T>, messageId:
assert(response:isOk(), response:unwrapErr())

return message.new(self.state, response:unwrapOk())
end)
end) :: future.FutureLike<string, message.Message>
end

--[[
Expand All @@ -97,7 +97,7 @@ function TextBehaviour.Prototype.createMessageAsync<T>(self: Channel<T>, json: b
assert(response:isOk(), response:unwrapErr())

return message.new(self.state, response:unwrapOk())
end)
end) :: future.FutureLike<string, message.Message>
end

--[[
Expand All @@ -118,7 +118,7 @@ function TextBehaviour.Prototype.getPinnedMessagesAsync<T>(self: Channel<T>)
end

return messages
end)
end) :: future.FutureLike<string, { message.Message }>
end

--[[
Expand All @@ -133,7 +133,7 @@ function TextBehaviour.Prototype.pinMessageAsync<T>(self: Channel<T>, messageId:
assert(response:isOk(), response:unwrapErr())

return nil
end)
end) :: future.FutureLike<string, nil>
end

--[[
Expand All @@ -148,7 +148,7 @@ function TextBehaviour.Prototype.unpinMessageAsync<T>(self: Channel<T>, messageI
assert(response:isOk(), response:unwrapErr())

return nil
end)
end) :: future.FutureLike<string, nil>
end

--[[
Expand All @@ -162,8 +162,8 @@ function TextBehaviour.Prototype.startThread<T>(self: Channel<T>, json: builders

assert(response:isOk(), response:unwrapErr())

return response.id
end)
return response:unwrapOk().id
end) :: future.FutureLike<string, apiTypes.Snowflake>
end

function TextBehaviour.Interface.inheritProperties(class: any, channelData: apiTypes.ChannelObject)
Expand Down
16 changes: 8 additions & 8 deletions packages/classes/src/channels/behaviour/thread.luau
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function ThreadBehaviour.Prototype.joinThreadAsync<T>(self: Channel<T>)
assert(response:isOk(), response:unwrapErr())

return nil
end)
end) :: future.FutureLike<string, nil>
end

--[[
Expand All @@ -42,7 +42,7 @@ function ThreadBehaviour.Prototype.addMemberToThreadAsync<T>(self: Channel<T>, u
assert(response:isOk(), response:unwrapErr())

return nil
end)
end) :: future.FutureLike<string, nil>
end

--[[
Expand All @@ -57,7 +57,7 @@ function ThreadBehaviour.Prototype.leaveThreadAsync<T>(self: Channel<T>)
assert(response:isOk(), response:unwrapErr())

return nil
end)
end) :: future.FutureLike<string, nil>
end

--[[
Expand All @@ -72,7 +72,7 @@ function ThreadBehaviour.Prototype.removeMemberAsync<T>(self: Channel<T>, userId
assert(response:isOk(), response:unwrapErr())

return nil
end)
end) :: future.FutureLike<string, nil>
end

--[[
Expand All @@ -87,7 +87,7 @@ function ThreadBehaviour.Prototype.removeMemberAsync<T>(self: Channel<T>, userId
assert(response:isOk(), response:unwrapErr())

return nil
end)
end) :: future.FutureLike<string, nil>
end

--[[
Expand All @@ -106,7 +106,7 @@ function ThreadBehaviour.Prototype.getMemberAsync<T>(self: Channel<T>, userId: s
assert(response:isOk(), response:unwrapErr())

return threadMember.new(self.state, self.guildId, response:unwrapOk())
end)
end) :: future.FutureLike<string, threadMember.ThreadMember>
end

--[[
Expand All @@ -133,12 +133,12 @@ function ThreadBehaviour.Prototype.listMembersAsync<T>(

local threadMembers = {}

for _, memberData in response do
for _, memberData in response:unwrapOk() do
table.insert(threadMembers, threadMember.new(self.state, self.guildId, memberData))
end

return threadMembers
end)
end) :: future.FutureLike<string, { threadMember.ThreadMember }>
end

function ThreadBehaviour.Interface.inheritProperties(class: any, channelData: apiTypes.ChannelObject)
Expand Down
Loading

0 comments on commit bfcf007

Please sign in to comment.