@erinjs/core 1.0.0 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{core/LICENSE → LICENSE} +203 -203
- package/README.md +46 -0
- package/dist/index.d.mts +2084 -0
- package/dist/index.d.ts +2084 -0
- package/dist/index.js +3867 -0
- package/dist/index.mjs +3809 -0
- package/package.json +50 -15
- package/core/.changeset/README.md +0 -8
- package/core/.changeset/community-bootstrap-release.md +0 -17
- package/core/.changeset/config.json +0 -11
- package/core/.changeset/no-changelog.js +0 -16
- package/core/.changeset/pre.json +0 -17
- package/core/.editorconfig +0 -13
- package/core/.gitattributes +0 -2
- package/core/.github/CODE_OF_CONDUCT.md +0 -23
- package/core/.github/FUNDING.yml +0 -7
- package/core/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
- package/core/.github/ISSUE_TEMPLATE/feature_request.md +0 -23
- package/core/.github/PULL_REQUEST_TEMPLATE.md +0 -16
- package/core/.github/dependabot.yml +0 -16
- package/core/.github/workflows/autoapp.yml +0 -16
- package/core/.github/workflows/ci.yml +0 -187
- package/core/.github/workflows/codeql.yml +0 -30
- package/core/.github/workflows/deploy-docs.yml +0 -54
- package/core/.github/workflows/publish.yml +0 -43
- package/core/.lintstagedrc.json +0 -4
- package/core/.nvmrc +0 -1
- package/core/.prettierignore +0 -8
- package/core/.prettierrc +0 -11
- package/core/CONTRIBUTING.md +0 -70
- package/core/README.md +0 -61
- package/core/SECURITY.md +0 -21
- package/core/apps/docs/index.html +0 -28
- package/core/apps/docs/middleware.ts +0 -21
- package/core/apps/docs/package.json +0 -33
- package/core/apps/docs/public/@flux.png +0 -0
- package/core/apps/docs/public/docs/latest/guides.json +0 -1420
- package/core/apps/docs/public/docs/latest/main.json +0 -14981
- package/core/apps/docs/public/docs/latest/rag-index.json +0 -1
- package/core/apps/docs/public/docs/v1.0.5/guides.json +0 -226
- package/core/apps/docs/public/docs/v1.0.5/main.json +0 -7920
- package/core/apps/docs/public/docs/v1.0.6/guides.json +0 -226
- package/core/apps/docs/public/docs/v1.0.6/main.json +0 -7920
- package/core/apps/docs/public/docs/v1.0.7/guides.json +0 -259
- package/core/apps/docs/public/docs/v1.0.7/main.json +0 -8652
- package/core/apps/docs/public/docs/v1.0.8/guides.json +0 -313
- package/core/apps/docs/public/docs/v1.0.8/main.json +0 -9618
- package/core/apps/docs/public/docs/v1.0.9/guides.json +0 -319
- package/core/apps/docs/public/docs/v1.0.9/main.json +0 -10694
- package/core/apps/docs/public/docs/v1.1.0/guides.json +0 -589
- package/core/apps/docs/public/docs/v1.1.0/main.json +0 -12576
- package/core/apps/docs/public/docs/v1.1.2/guides.json +0 -650
- package/core/apps/docs/public/docs/v1.1.2/main.json +0 -13239
- package/core/apps/docs/public/docs/v1.1.3/guides.json +0 -650
- package/core/apps/docs/public/docs/v1.1.3/main.json +0 -13239
- package/core/apps/docs/public/docs/v1.1.4/guides.json +0 -708
- package/core/apps/docs/public/docs/v1.1.4/main.json +0 -13231
- package/core/apps/docs/public/docs/v1.1.5/guides.json +0 -1035
- package/core/apps/docs/public/docs/v1.1.5/main.json +0 -13838
- package/core/apps/docs/public/docs/v1.1.6/guides.json +0 -1041
- package/core/apps/docs/public/docs/v1.1.6/main.json +0 -14313
- package/core/apps/docs/public/docs/v1.1.8/guides.json +0 -1047
- package/core/apps/docs/public/docs/v1.1.8/main.json +0 -14421
- package/core/apps/docs/public/docs/v1.1.9/guides.json +0 -1047
- package/core/apps/docs/public/docs/v1.1.9/main.json +0 -14421
- package/core/apps/docs/public/docs/v1.2.0/guides.json +0 -1212
- package/core/apps/docs/public/docs/v1.2.0/main.json +0 -14663
- package/core/apps/docs/public/docs/v1.2.1/guides.json +0 -1293
- package/core/apps/docs/public/docs/v1.2.1/main.json +0 -14828
- package/core/apps/docs/public/docs/v1.2.2/guides.json +0 -1293
- package/core/apps/docs/public/docs/v1.2.2/main.json +0 -15025
- package/core/apps/docs/public/docs/v1.2.3/guides.json +0 -1420
- package/core/apps/docs/public/docs/v1.2.3/main.json +0 -14954
- package/core/apps/docs/public/docs/v1.2.4/guides.json +0 -1420
- package/core/apps/docs/public/docs/v1.2.4/main.json +0 -14981
- package/core/apps/docs/public/docs/versions.json +0 -24
- package/core/apps/docs/public/flux.png +0 -0
- package/core/apps/docs/public/locales/en.json +0 -50
- package/core/apps/docs/public/locales/guides-en.json +0 -512
- package/core/apps/docs/public/robots.txt +0 -4
- package/core/apps/docs/public/sitemap.xml +0 -33
- package/core/apps/docs/src/App.vue +0 -538
- package/core/apps/docs/src/components/ApiCategorySection.vue +0 -42
- package/core/apps/docs/src/components/ApiDiscordCompat.vue +0 -65
- package/core/apps/docs/src/components/ApiEndpointCard.vue +0 -313
- package/core/apps/docs/src/components/ApiSchemaBlock.vue +0 -131
- package/core/apps/docs/src/components/CodeBlock.vue +0 -177
- package/core/apps/docs/src/components/CommunityCallout.vue +0 -90
- package/core/apps/docs/src/components/ConstructorSection.vue +0 -82
- package/core/apps/docs/src/components/DocDescription.vue +0 -40
- package/core/apps/docs/src/components/FluxerLogo.vue +0 -3
- package/core/apps/docs/src/components/Footer.vue +0 -106
- package/core/apps/docs/src/components/GuideCodeBlock.vue +0 -102
- package/core/apps/docs/src/components/GuideDiscordCompat.vue +0 -77
- package/core/apps/docs/src/components/GuideDiscordCompatCallout.vue +0 -83
- package/core/apps/docs/src/components/GuideTable.vue +0 -77
- package/core/apps/docs/src/components/GuideTip.vue +0 -38
- package/core/apps/docs/src/components/MethodsSection.vue +0 -195
- package/core/apps/docs/src/components/ParamsTable.vue +0 -70
- package/core/apps/docs/src/components/PropertiesSection.vue +0 -143
- package/core/apps/docs/src/components/SearchBar.vue +0 -76
- package/core/apps/docs/src/components/SearchModal.vue +0 -361
- package/core/apps/docs/src/components/SidebarNav.vue +0 -225
- package/core/apps/docs/src/components/SponsorBanner.vue +0 -153
- package/core/apps/docs/src/components/TypeSignature.vue +0 -187
- package/core/apps/docs/src/components/VersionPicker.vue +0 -191
- package/core/apps/docs/src/composables/useSearchIndex.ts +0 -144
- package/core/apps/docs/src/composables/useVersionedPath.ts +0 -20
- package/core/apps/docs/src/data/apiEndpoints.ts +0 -1073
- package/core/apps/docs/src/data/changelog.ts +0 -717
- package/core/apps/docs/src/data/guides.ts +0 -2362
- package/core/apps/docs/src/env.d.ts +0 -7
- package/core/apps/docs/src/locales/guides-en.json +0 -512
- package/core/apps/docs/src/main.ts +0 -27
- package/core/apps/docs/src/pages/ApiReferenceLayout.vue +0 -175
- package/core/apps/docs/src/pages/ApiReferencePage.vue +0 -128
- package/core/apps/docs/src/pages/Changelog.vue +0 -288
- package/core/apps/docs/src/pages/ClassPage.vue +0 -319
- package/core/apps/docs/src/pages/ClassesList.vue +0 -100
- package/core/apps/docs/src/pages/DocsLayout.vue +0 -127
- package/core/apps/docs/src/pages/GuidePage.vue +0 -279
- package/core/apps/docs/src/pages/GuidesIndex.vue +0 -166
- package/core/apps/docs/src/pages/GuidesLayout.vue +0 -245
- package/core/apps/docs/src/pages/Home.vue +0 -125
- package/core/apps/docs/src/pages/NotFound.vue +0 -57
- package/core/apps/docs/src/pages/TypedefPage.vue +0 -230
- package/core/apps/docs/src/pages/TypedefsList.vue +0 -168
- package/core/apps/docs/src/pages/VersionLayout.vue +0 -15
- package/core/apps/docs/src/router.ts +0 -73
- package/core/apps/docs/src/stores/docs.ts +0 -54
- package/core/apps/docs/src/stores/guides.ts +0 -53
- package/core/apps/docs/src/stores/version.ts +0 -67
- package/core/apps/docs/src/styles/main.css +0 -278
- package/core/apps/docs/src/styles/prism.css +0 -95
- package/core/apps/docs/src/types/doc-schema.ts +0 -112
- package/core/apps/docs/tsconfig.json +0 -17
- package/core/apps/docs/tsconfig.node.json +0 -10
- package/core/apps/docs/vite.config.d.ts +0 -2
- package/core/apps/docs/vite.config.js +0 -26
- package/core/apps/docs/vite.config.ts +0 -28
- package/core/apps/docs-vitepress/.vitepress/config.ts +0 -141
- package/core/apps/docs-vitepress/api-data/latest/main.json +0 -15035
- package/core/apps/docs-vitepress/api-data/v1.2.4/main.json +0 -15035
- package/core/apps/docs-vitepress/api-data/versions.json +0 -6
- package/core/apps/docs-vitepress/index.md +0 -15
- package/core/apps/docs-vitepress/package-lock.json +0 -2924
- package/core/apps/docs-vitepress/package.json +0 -20
- package/core/apps/docs-vitepress/public/CNAME +0 -1
- package/core/apps/docs-vitepress/scripts/generate-api.ts +0 -243
- package/core/apps/docs-vitepress/scripts/migrate-guides.ts +0 -129
- package/core/apps/docs-vitepress/tsconfig.json +0 -11
- package/core/apps/docs-vitepress/v/latest/guides/attachments-by-url.md +0 -57
- package/core/apps/docs-vitepress/v/latest/guides/attachments.md +0 -62
- package/core/apps/docs-vitepress/v/latest/guides/basic-bot.md +0 -49
- package/core/apps/docs-vitepress/v/latest/guides/channels.md +0 -180
- package/core/apps/docs-vitepress/v/latest/guides/deprecated-apis.md +0 -58
- package/core/apps/docs-vitepress/v/latest/guides/discord-js-compatibility.md +0 -42
- package/core/apps/docs-vitepress/v/latest/guides/editing-embeds.md +0 -65
- package/core/apps/docs-vitepress/v/latest/guides/embed-media.md +0 -87
- package/core/apps/docs-vitepress/v/latest/guides/embeds.md +0 -166
- package/core/apps/docs-vitepress/v/latest/guides/emojis.md +0 -77
- package/core/apps/docs-vitepress/v/latest/guides/events.md +0 -202
- package/core/apps/docs-vitepress/v/latest/guides/gifs.md +0 -47
- package/core/apps/docs-vitepress/v/latest/guides/installation.md +0 -10
- package/core/apps/docs-vitepress/v/latest/guides/moderation.md +0 -89
- package/core/apps/docs-vitepress/v/latest/guides/permissions.md +0 -130
- package/core/apps/docs-vitepress/v/latest/guides/prefix-commands.md +0 -41
- package/core/apps/docs-vitepress/v/latest/guides/profile-urls.md +0 -58
- package/core/apps/docs-vitepress/v/latest/guides/reactions.md +0 -69
- package/core/apps/docs-vitepress/v/latest/guides/roles.md +0 -130
- package/core/apps/docs-vitepress/v/latest/guides/sending-without-reply.md +0 -172
- package/core/apps/docs-vitepress/v/latest/guides/voice.md +0 -109
- package/core/apps/docs-vitepress/v/latest/guides/wait-for-guilds.md +0 -37
- package/core/apps/docs-vitepress/v/latest/guides/webhook-attachments-embeds.md +0 -73
- package/core/apps/docs-vitepress/v/latest/guides/webhooks.md +0 -131
- package/core/eslint.config.js +0 -80
- package/core/examples/.env.example +0 -22
- package/core/examples/README.md +0 -68
- package/core/examples/first-steps-bot.js +0 -118
- package/core/examples/minimal-bot.js +0 -17
- package/core/examples/moderation-bot.js +0 -209
- package/core/examples/package.json +0 -14
- package/core/examples/ping-bot.js +0 -1146
- package/core/examples/reaction-bot.js +0 -70
- package/core/examples/reaction-roles-bot.js +0 -140
- package/core/examples/webhook-bot.js +0 -239
- package/core/flux.png +0 -0
- package/core/package.json +0 -78
- package/core/packages/builders/package.json +0 -51
- package/core/packages/builders/src/index.ts +0 -13
- package/core/packages/builders/src/messages/AttachmentBuilder.test.ts +0 -79
- package/core/packages/builders/src/messages/AttachmentBuilder.ts +0 -69
- package/core/packages/builders/src/messages/EmbedBuilder.test.ts +0 -266
- package/core/packages/builders/src/messages/EmbedBuilder.ts +0 -239
- package/core/packages/builders/src/messages/MessagePayload.test.ts +0 -118
- package/core/packages/builders/src/messages/MessagePayload.ts +0 -122
- package/core/packages/builders/tsconfig.json +0 -9
- package/core/packages/builders/tsup.config.ts +0 -9
- package/core/packages/builders/vitest.config.ts +0 -9
- package/core/packages/collection/package.json +0 -47
- package/core/packages/collection/src/Collection.test.ts +0 -232
- package/core/packages/collection/src/Collection.ts +0 -196
- package/core/packages/collection/src/index.ts +0 -1
- package/core/packages/collection/tsconfig.json +0 -9
- package/core/packages/collection/tsup.config.ts +0 -9
- package/core/packages/collection/vitest.config.ts +0 -9
- package/core/packages/docgen/package.json +0 -26
- package/core/packages/docgen/src/extract.ts +0 -262
- package/core/packages/docgen/src/formatType.ts +0 -24
- package/core/packages/docgen/src/index.ts +0 -103
- package/core/packages/docgen/src/schema.ts +0 -100
- package/core/packages/docgen/src/visitor.ts +0 -147
- package/core/packages/docgen/tsconfig.json +0 -9
- package/core/packages/docgen/tsup.config.ts +0 -9
- package/core/packages/fluxer-core/README.md +0 -26
- package/core/packages/fluxer-core/package.json +0 -60
- package/core/packages/fluxer-core/src/client/ChannelManager.ts +0 -143
- package/core/packages/fluxer-core/src/client/Client.gateway.test.ts +0 -84
- package/core/packages/fluxer-core/src/client/Client.resolveEmoji.test.ts +0 -45
- package/core/packages/fluxer-core/src/client/Client.ts +0 -558
- package/core/packages/fluxer-core/src/client/ClientUser.ts +0 -40
- package/core/packages/fluxer-core/src/client/EventHandlerRegistry.ts +0 -469
- package/core/packages/fluxer-core/src/client/GuildManager.ts +0 -79
- package/core/packages/fluxer-core/src/client/GuildMemberManager.ts +0 -91
- package/core/packages/fluxer-core/src/client/MessageManager.ts +0 -58
- package/core/packages/fluxer-core/src/client/UsersManager.ts +0 -122
- package/core/packages/fluxer-core/src/errors/ErrorCodes.test.ts +0 -19
- package/core/packages/fluxer-core/src/errors/ErrorCodes.ts +0 -12
- package/core/packages/fluxer-core/src/errors/FluxerError.test.ts +0 -32
- package/core/packages/fluxer-core/src/errors/FluxerError.ts +0 -15
- package/core/packages/fluxer-core/src/index.ts +0 -85
- package/core/packages/fluxer-core/src/structures/Base.ts +0 -7
- package/core/packages/fluxer-core/src/structures/Channel.ts +0 -508
- package/core/packages/fluxer-core/src/structures/Guild.test.ts +0 -189
- package/core/packages/fluxer-core/src/structures/Guild.ts +0 -734
- package/core/packages/fluxer-core/src/structures/GuildBan.ts +0 -35
- package/core/packages/fluxer-core/src/structures/GuildEmoji.ts +0 -57
- package/core/packages/fluxer-core/src/structures/GuildMember.test.ts +0 -203
- package/core/packages/fluxer-core/src/structures/GuildMember.ts +0 -213
- package/core/packages/fluxer-core/src/structures/GuildMemberRoleManager.ts +0 -121
- package/core/packages/fluxer-core/src/structures/GuildSticker.ts +0 -56
- package/core/packages/fluxer-core/src/structures/Invite.test.ts +0 -103
- package/core/packages/fluxer-core/src/structures/Invite.ts +0 -121
- package/core/packages/fluxer-core/src/structures/Message.test.ts +0 -109
- package/core/packages/fluxer-core/src/structures/Message.ts +0 -397
- package/core/packages/fluxer-core/src/structures/MessageReaction.ts +0 -72
- package/core/packages/fluxer-core/src/structures/PartialMessage.ts +0 -12
- package/core/packages/fluxer-core/src/structures/Role.test.ts +0 -77
- package/core/packages/fluxer-core/src/structures/Role.ts +0 -112
- package/core/packages/fluxer-core/src/structures/User.test.ts +0 -110
- package/core/packages/fluxer-core/src/structures/User.ts +0 -109
- package/core/packages/fluxer-core/src/structures/Webhook.test.ts +0 -109
- package/core/packages/fluxer-core/src/structures/Webhook.ts +0 -258
- package/core/packages/fluxer-core/src/util/Constants.test.ts +0 -16
- package/core/packages/fluxer-core/src/util/Constants.ts +0 -7
- package/core/packages/fluxer-core/src/util/Events.ts +0 -46
- package/core/packages/fluxer-core/src/util/MessageCollector.ts +0 -87
- package/core/packages/fluxer-core/src/util/Options.ts +0 -33
- package/core/packages/fluxer-core/src/util/ReactionCollector.ts +0 -116
- package/core/packages/fluxer-core/src/util/cdn.test.ts +0 -108
- package/core/packages/fluxer-core/src/util/cdn.ts +0 -130
- package/core/packages/fluxer-core/src/util/guildUtils.ts +0 -33
- package/core/packages/fluxer-core/src/util/messageUtils.test.ts +0 -74
- package/core/packages/fluxer-core/src/util/messageUtils.ts +0 -119
- package/core/packages/fluxer-core/src/util/permissions.test.ts +0 -95
- package/core/packages/fluxer-core/src/util/permissions.ts +0 -43
- package/core/packages/fluxer-core/tsconfig.json +0 -9
- package/core/packages/fluxer-core/tsup.config.ts +0 -9
- package/core/packages/fluxer-core/vitest.config.ts +0 -9
- package/core/packages/rest/package.json +0 -52
- package/core/packages/rest/src/REST.test.ts +0 -64
- package/core/packages/rest/src/REST.ts +0 -90
- package/core/packages/rest/src/RateLimitManager.test.ts +0 -71
- package/core/packages/rest/src/RateLimitManager.ts +0 -60
- package/core/packages/rest/src/RequestManager.test.ts +0 -87
- package/core/packages/rest/src/RequestManager.ts +0 -172
- package/core/packages/rest/src/errors/FluxerAPIError.test.ts +0 -57
- package/core/packages/rest/src/errors/FluxerAPIError.ts +0 -21
- package/core/packages/rest/src/errors/HTTPError.test.ts +0 -55
- package/core/packages/rest/src/errors/HTTPError.ts +0 -25
- package/core/packages/rest/src/errors/RateLimitError.test.ts +0 -41
- package/core/packages/rest/src/errors/RateLimitError.ts +0 -15
- package/core/packages/rest/src/errors/index.ts +0 -3
- package/core/packages/rest/src/index.ts +0 -6
- package/core/packages/rest/src/utils/constants.test.ts +0 -31
- package/core/packages/rest/src/utils/constants.ts +0 -5
- package/core/packages/rest/src/utils/files.test.ts +0 -37
- package/core/packages/rest/src/utils/files.ts +0 -75
- package/core/packages/rest/tsconfig.json +0 -9
- package/core/packages/rest/tsup.config.ts +0 -9
- package/core/packages/rest/vitest.config.ts +0 -9
- package/core/packages/types/package.json +0 -46
- package/core/packages/types/src/api/ban.ts +0 -8
- package/core/packages/types/src/api/channel.ts +0 -65
- package/core/packages/types/src/api/embed.ts +0 -82
- package/core/packages/types/src/api/emoji.ts +0 -12
- package/core/packages/types/src/api/errors.ts +0 -68
- package/core/packages/types/src/api/gateway.ts +0 -14
- package/core/packages/types/src/api/guild.ts +0 -123
- package/core/packages/types/src/api/index.ts +0 -15
- package/core/packages/types/src/api/instance.ts +0 -32
- package/core/packages/types/src/api/interaction.ts +0 -26
- package/core/packages/types/src/api/invite.ts +0 -28
- package/core/packages/types/src/api/message.ts +0 -140
- package/core/packages/types/src/api/role.ts +0 -41
- package/core/packages/types/src/api/sticker.ts +0 -14
- package/core/packages/types/src/api/user.ts +0 -79
- package/core/packages/types/src/api/webhook.ts +0 -41
- package/core/packages/types/src/common/index.ts +0 -1
- package/core/packages/types/src/common/snowflake.test.ts +0 -9
- package/core/packages/types/src/common/snowflake.ts +0 -8
- package/core/packages/types/src/gateway/events.ts +0 -189
- package/core/packages/types/src/gateway/index.ts +0 -3
- package/core/packages/types/src/gateway/opcodes.ts +0 -17
- package/core/packages/types/src/gateway/payloads.ts +0 -481
- package/core/packages/types/src/index.ts +0 -4
- package/core/packages/types/src/rest/index.ts +0 -1
- package/core/packages/types/src/rest/routes.test.ts +0 -169
- package/core/packages/types/src/rest/routes.ts +0 -109
- package/core/packages/types/tsconfig.json +0 -9
- package/core/packages/types/tsup.config.ts +0 -9
- package/core/packages/types/vitest.config.ts +0 -9
- package/core/packages/util/package.json +0 -51
- package/core/packages/util/src/BitField.test.ts +0 -96
- package/core/packages/util/src/BitField.ts +0 -105
- package/core/packages/util/src/MessageFlagsBitField.test.ts +0 -42
- package/core/packages/util/src/MessageFlagsBitField.ts +0 -20
- package/core/packages/util/src/PermissionsBitField.test.ts +0 -79
- package/core/packages/util/src/PermissionsBitField.ts +0 -97
- package/core/packages/util/src/SnowflakeUtil.test.ts +0 -69
- package/core/packages/util/src/SnowflakeUtil.ts +0 -65
- package/core/packages/util/src/UserFlagsBitField.test.ts +0 -39
- package/core/packages/util/src/UserFlagsBitField.ts +0 -48
- package/core/packages/util/src/deprecation.test.ts +0 -44
- package/core/packages/util/src/deprecation.ts +0 -28
- package/core/packages/util/src/emojiShortcodes.generated.ts +0 -5
- package/core/packages/util/src/emojiShortcodes.test.ts +0 -41
- package/core/packages/util/src/emojiShortcodes.ts +0 -22
- package/core/packages/util/src/formatters.test.ts +0 -65
- package/core/packages/util/src/formatters.ts +0 -35
- package/core/packages/util/src/index.ts +0 -34
- package/core/packages/util/src/resolvers.test.ts +0 -198
- package/core/packages/util/src/resolvers.ts +0 -127
- package/core/packages/util/src/tenorUtils.test.ts +0 -75
- package/core/packages/util/src/tenorUtils.ts +0 -86
- package/core/packages/util/tsconfig.json +0 -9
- package/core/packages/util/tsup.config.ts +0 -9
- package/core/packages/util/vitest.config.ts +0 -9
- package/core/packages/voice/README.md +0 -42
- package/core/packages/voice/package.json +0 -67
- package/core/packages/voice/src/LiveKitRtcConnection.receive.test.ts +0 -24
- package/core/packages/voice/src/LiveKitRtcConnection.ts +0 -1767
- package/core/packages/voice/src/VoiceConnection.ts +0 -413
- package/core/packages/voice/src/VoiceManager.receive.test.ts +0 -61
- package/core/packages/voice/src/VoiceManager.test.ts +0 -44
- package/core/packages/voice/src/VoiceManager.ts +0 -503
- package/core/packages/voice/src/exports.test.ts +0 -38
- package/core/packages/voice/src/index.ts +0 -51
- package/core/packages/voice/src/livekit.test.ts +0 -48
- package/core/packages/voice/src/livekit.ts +0 -33
- package/core/packages/voice/src/mp4box.d.ts +0 -32
- package/core/packages/voice/src/opusUtils.test.ts +0 -29
- package/core/packages/voice/src/opusUtils.ts +0 -86
- package/core/packages/voice/src/streamPreviewPlaceholder.test.ts +0 -16
- package/core/packages/voice/src/streamPreviewPlaceholder.ts +0 -8
- package/core/packages/voice/src/ws.d.ts +0 -1
- package/core/packages/voice/tsconfig.json +0 -5
- package/core/packages/voice/tsup.config.ts +0 -10
- package/core/packages/voice/vitest.config.ts +0 -9
- package/core/packages/ws/package.json +0 -52
- package/core/packages/ws/src/WebSocketManager.ts +0 -130
- package/core/packages/ws/src/WebSocketShard.ts +0 -296
- package/core/packages/ws/src/index.ts +0 -12
- package/core/packages/ws/src/utils/constants.test.ts +0 -46
- package/core/packages/ws/src/utils/constants.ts +0 -22
- package/core/packages/ws/src/utils/getWebSocket.ts +0 -55
- package/core/packages/ws/src/ws.d.ts +0 -10
- package/core/packages/ws/tsconfig.json +0 -9
- package/core/packages/ws/tsup.config.ts +0 -9
- package/core/pnpm-lock.yaml +0 -7033
- package/core/pnpm-workspace.yaml +0 -4
- package/core/scripts/generate-ai-rag.ts +0 -240
- package/core/scripts/generate-docs.ts +0 -143
- package/core/scripts/generate-emoji-shortcodes.ts +0 -58
- package/core/scripts/generate-types.ts +0 -6
- package/core/scripts/publish-ordered.js +0 -63
- package/core/scripts/test-cjs-require.mjs +0 -43
- package/core/scripts/test-esm-imports.mjs +0 -42
- package/core/scripts/test-package-exports.mjs +0 -98
- package/core/scripts/test-smoke.mjs +0 -103
- package/core/tsconfig.json +0 -18
- package/core/turbo.json +0 -30
- package/core/vitest.config.ts +0 -17
- package/core/wrangler.jsonc +0 -9
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { APIEmbed, APIMessageReference } from '@erinjs/types';
|
|
2
|
-
import { EmbedBuilder } from './EmbedBuilder.js';
|
|
3
|
-
import { AttachmentBuilder } from './AttachmentBuilder.js';
|
|
4
|
-
|
|
5
|
-
/** Data for a message payload (content, embeds, reply reference, etc.). */
|
|
6
|
-
export interface MessagePayloadData {
|
|
7
|
-
content?: string | null;
|
|
8
|
-
embeds?: APIEmbed[] | null;
|
|
9
|
-
attachments?: Array<{ id: number; filename: string; description?: string | null }>;
|
|
10
|
-
message_reference?: APIMessageReference | null;
|
|
11
|
-
tts?: boolean;
|
|
12
|
-
flags?: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const CONTENT_MAX = 2000;
|
|
16
|
-
const EMBEDS_MAX = 10;
|
|
17
|
-
|
|
18
|
-
/** Builder for message payloads. Use with `channel.send()` or `message.reply()`. */
|
|
19
|
-
export class MessagePayload {
|
|
20
|
-
public static readonly ContentMaxLength = CONTENT_MAX;
|
|
21
|
-
|
|
22
|
-
public readonly data: MessagePayloadData = {};
|
|
23
|
-
|
|
24
|
-
/** Set message text. Max 2000 characters. */
|
|
25
|
-
setContent(content: string | null): this {
|
|
26
|
-
if (content !== null && content.length > CONTENT_MAX)
|
|
27
|
-
throw new RangeError(`Content must be ≤${CONTENT_MAX} characters`);
|
|
28
|
-
this.data.content = content ?? undefined;
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** Set embeds. Max 10. Replaces existing. */
|
|
33
|
-
setEmbeds(embeds: (APIEmbed | EmbedBuilder)[] | null): this {
|
|
34
|
-
if (!embeds?.length) {
|
|
35
|
-
this.data.embeds = undefined;
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
if (embeds.length > EMBEDS_MAX) throw new RangeError(`Embeds must be ≤${EMBEDS_MAX}`);
|
|
39
|
-
this.data.embeds = embeds.map((e) => (e instanceof EmbedBuilder ? e.toJSON() : e));
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** Add one embed. Max 10 total. */
|
|
44
|
-
addEmbed(embed: APIEmbed | EmbedBuilder): this {
|
|
45
|
-
const list = (this.data.embeds ?? []).slice();
|
|
46
|
-
if (list.length >= EMBEDS_MAX) throw new RangeError(`Embeds must be ≤${EMBEDS_MAX}`);
|
|
47
|
-
list.push(embed instanceof EmbedBuilder ? embed.toJSON() : embed);
|
|
48
|
-
this.data.embeds = list;
|
|
49
|
-
return this;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** Set attachment metadata (for files sent with the request). */
|
|
53
|
-
setAttachments(
|
|
54
|
-
attachments: Array<
|
|
55
|
-
AttachmentBuilder | { id: number; filename: string; description?: string | null }
|
|
56
|
-
> | null,
|
|
57
|
-
): this {
|
|
58
|
-
if (!attachments?.length) {
|
|
59
|
-
this.data.attachments = undefined;
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
this.data.attachments = attachments.map((a) =>
|
|
63
|
-
a instanceof AttachmentBuilder ? a.toJSON() : a,
|
|
64
|
-
);
|
|
65
|
-
return this;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** Set reply reference (creates a reply to another message). */
|
|
69
|
-
setReply(
|
|
70
|
-
reference:
|
|
71
|
-
| { channel_id: string; message_id: string; guild_id?: string | null }
|
|
72
|
-
| APIMessageReference
|
|
73
|
-
| null,
|
|
74
|
-
): this {
|
|
75
|
-
if (!reference) {
|
|
76
|
-
this.data.message_reference = undefined;
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
this.data.message_reference = {
|
|
80
|
-
channel_id: reference.channel_id,
|
|
81
|
-
message_id: reference.message_id,
|
|
82
|
-
guild_id: reference.guild_id ?? undefined,
|
|
83
|
-
};
|
|
84
|
-
return this;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** Enable text-to-speech. */
|
|
88
|
-
setTTS(tts: boolean): this {
|
|
89
|
-
this.data.tts = tts;
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** Set message flags (e.g. ephemeral, suppress embeds). */
|
|
94
|
-
setFlags(flags: number): this {
|
|
95
|
-
this.data.flags = flags;
|
|
96
|
-
return this;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** Get the payload as a plain object. */
|
|
100
|
-
toJSON(): MessagePayloadData {
|
|
101
|
-
return { ...this.data };
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** Create a MessagePayload from a string or options object. */
|
|
105
|
-
static create(contentOrOptions?: string | MessagePayloadData): MessagePayload {
|
|
106
|
-
const payload = new MessagePayload();
|
|
107
|
-
if (typeof contentOrOptions === 'string') {
|
|
108
|
-
payload.setContent(contentOrOptions);
|
|
109
|
-
} else if (contentOrOptions && typeof contentOrOptions === 'object') {
|
|
110
|
-
if (contentOrOptions.content !== undefined)
|
|
111
|
-
payload.setContent(contentOrOptions.content ?? null);
|
|
112
|
-
if (contentOrOptions.embeds?.length) payload.setEmbeds(contentOrOptions.embeds);
|
|
113
|
-
if (contentOrOptions.attachments?.length)
|
|
114
|
-
payload.setAttachments(contentOrOptions.attachments);
|
|
115
|
-
if (contentOrOptions.message_reference)
|
|
116
|
-
payload.setReply(contentOrOptions.message_reference as APIMessageReference);
|
|
117
|
-
if (contentOrOptions.tts !== undefined) payload.setTTS(contentOrOptions.tts);
|
|
118
|
-
if (contentOrOptions.flags !== undefined) payload.setFlags(contentOrOptions.flags);
|
|
119
|
-
}
|
|
120
|
-
return payload;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@erinjs/collection",
|
|
3
|
-
"publishConfig": {
|
|
4
|
-
"access": "public"
|
|
5
|
-
},
|
|
6
|
-
"version": "1.2.4",
|
|
7
|
-
"description": "Extended Map with utility methods for @erinjs/core",
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "https://github.com/blstmo-abandoned-us-for-the-milk/core.git",
|
|
11
|
-
"directory": "packages/collection"
|
|
12
|
-
},
|
|
13
|
-
"bugs": "https://github.com/blstmo-abandoned-us-for-the-milk/core/issues",
|
|
14
|
-
"homepage": "https://github.com/blstmo-abandoned-us-for-the-milk/core#readme",
|
|
15
|
-
"keywords": [
|
|
16
|
-
"fluxer",
|
|
17
|
-
"collection",
|
|
18
|
-
"map"
|
|
19
|
-
],
|
|
20
|
-
"license": "Apache-2.0",
|
|
21
|
-
"main": "./dist/index.js",
|
|
22
|
-
"module": "./dist/index.mjs",
|
|
23
|
-
"types": "./dist/index.d.ts",
|
|
24
|
-
"exports": {
|
|
25
|
-
".": {
|
|
26
|
-
"types": "./dist/index.d.ts",
|
|
27
|
-
"import": "./dist/index.mjs",
|
|
28
|
-
"require": "./dist/index.js"
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
"files": [
|
|
32
|
-
"dist"
|
|
33
|
-
],
|
|
34
|
-
"scripts": {
|
|
35
|
-
"build": "tsup",
|
|
36
|
-
"clean": "rm -rf dist",
|
|
37
|
-
"lint": "eslint src --max-warnings 0 --config ../../eslint.config.js",
|
|
38
|
-
"lint:fix": "eslint src --fix --config ../../eslint.config.js",
|
|
39
|
-
"test": "vitest run",
|
|
40
|
-
"test:coverage": "vitest run --coverage"
|
|
41
|
-
},
|
|
42
|
-
"devDependencies": {
|
|
43
|
-
"tsup": "^8.3.0",
|
|
44
|
-
"typescript": "^5.6.0",
|
|
45
|
-
"vitest": "^4.0.18"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { Collection } from './Collection.js';
|
|
3
|
-
|
|
4
|
-
describe('Collection', () => {
|
|
5
|
-
it('creates empty collection', () => {
|
|
6
|
-
const coll = new Collection<string, number>();
|
|
7
|
-
expect(coll.size).toBe(0);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('first returns undefined for empty', () => {
|
|
11
|
-
const coll = new Collection<string, number>();
|
|
12
|
-
expect(coll.first()).toBeUndefined();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('first returns first value', () => {
|
|
16
|
-
const coll = new Collection<string, number>([
|
|
17
|
-
['a', 1],
|
|
18
|
-
['b', 2],
|
|
19
|
-
['c', 3],
|
|
20
|
-
]);
|
|
21
|
-
expect(coll.first()).toBe(1);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('first(amount) returns first n values', () => {
|
|
25
|
-
const coll = new Collection<string, number>([
|
|
26
|
-
['a', 1],
|
|
27
|
-
['b', 2],
|
|
28
|
-
['c', 3],
|
|
29
|
-
]);
|
|
30
|
-
expect(coll.first(2)).toEqual([1, 2]);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('last returns last value', () => {
|
|
34
|
-
const coll = new Collection<string, number>([
|
|
35
|
-
['a', 1],
|
|
36
|
-
['b', 2],
|
|
37
|
-
['c', 3],
|
|
38
|
-
]);
|
|
39
|
-
expect(coll.last()).toBe(3);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('random returns undefined for empty', () => {
|
|
43
|
-
const coll = new Collection<string, number>();
|
|
44
|
-
expect(coll.random()).toBeUndefined();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('find returns matching value', () => {
|
|
48
|
-
const coll = new Collection<string, number>([
|
|
49
|
-
['a', 1],
|
|
50
|
-
['b', 2],
|
|
51
|
-
['c', 3],
|
|
52
|
-
]);
|
|
53
|
-
expect(coll.find((v) => v === 2)).toBe(2);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('filter returns matching subset', () => {
|
|
57
|
-
const coll = new Collection<string, number>([
|
|
58
|
-
['a', 1],
|
|
59
|
-
['b', 2],
|
|
60
|
-
['c', 3],
|
|
61
|
-
]);
|
|
62
|
-
const filtered = coll.filter((v) => v > 1);
|
|
63
|
-
expect(filtered.size).toBe(2);
|
|
64
|
-
expect(filtered.get('b')).toBe(2);
|
|
65
|
-
expect(filtered.get('c')).toBe(3);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('map transforms values', () => {
|
|
69
|
-
const coll = new Collection<string, number>([
|
|
70
|
-
['a', 1],
|
|
71
|
-
['b', 2],
|
|
72
|
-
]);
|
|
73
|
-
expect(coll.map((v) => v * 2)).toEqual([2, 4]);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('reduce accumulates', () => {
|
|
77
|
-
const coll = new Collection<string, number>([
|
|
78
|
-
['a', 1],
|
|
79
|
-
['b', 2],
|
|
80
|
-
['c', 3],
|
|
81
|
-
]);
|
|
82
|
-
expect(coll.reduce((acc, v) => acc + v, 0)).toBe(6);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('findKey returns matching key', () => {
|
|
86
|
-
const coll = new Collection<string, number>([
|
|
87
|
-
['a', 1],
|
|
88
|
-
['b', 2],
|
|
89
|
-
['c', 3],
|
|
90
|
-
]);
|
|
91
|
-
expect(coll.findKey((v) => v === 2)).toBe('b');
|
|
92
|
-
expect(coll.findKey((v) => v === 99)).toBeUndefined();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('some returns true when any element matches', () => {
|
|
96
|
-
const coll = new Collection<string, number>([
|
|
97
|
-
['a', 1],
|
|
98
|
-
['b', 2],
|
|
99
|
-
]);
|
|
100
|
-
expect(coll.some((v) => v === 2)).toBe(true);
|
|
101
|
-
expect(coll.some((v) => v === 99)).toBe(false);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('every returns true when all match', () => {
|
|
105
|
-
const coll = new Collection<string, number>([
|
|
106
|
-
['a', 1],
|
|
107
|
-
['b', 2],
|
|
108
|
-
]);
|
|
109
|
-
expect(coll.every((v) => v > 0)).toBe(true);
|
|
110
|
-
expect(coll.every((v) => v > 1)).toBe(false);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('partition splits into pass/fail collections', () => {
|
|
114
|
-
const coll = new Collection<string, number>([
|
|
115
|
-
['a', 1],
|
|
116
|
-
['b', 2],
|
|
117
|
-
['c', 3],
|
|
118
|
-
]);
|
|
119
|
-
const [pass, fail] = coll.partition((v) => v >= 2);
|
|
120
|
-
expect(pass.size).toBe(2);
|
|
121
|
-
expect(fail.size).toBe(1);
|
|
122
|
-
expect(pass.get('b')).toBe(2);
|
|
123
|
-
expect(pass.get('c')).toBe(3);
|
|
124
|
-
expect(fail.get('a')).toBe(1);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('clone creates shallow copy', () => {
|
|
128
|
-
const coll = new Collection<string, number>([
|
|
129
|
-
['a', 1],
|
|
130
|
-
['b', 2],
|
|
131
|
-
]);
|
|
132
|
-
const clone = coll.clone();
|
|
133
|
-
expect(clone.size).toBe(coll.size);
|
|
134
|
-
expect(clone.get('a')).toBe(1);
|
|
135
|
-
clone.set('a', 99);
|
|
136
|
-
expect(coll.get('a')).toBe(1); // original unchanged
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('concat merges collections', () => {
|
|
140
|
-
const a = new Collection<string, number>([['x', 1]]);
|
|
141
|
-
const b = new Collection<string, number>([
|
|
142
|
-
['y', 2],
|
|
143
|
-
['z', 3],
|
|
144
|
-
]);
|
|
145
|
-
const c = a.concat(b);
|
|
146
|
-
expect(c.size).toBe(3);
|
|
147
|
-
expect(c.get('x')).toBe(1);
|
|
148
|
-
expect(c.get('y')).toBe(2);
|
|
149
|
-
expect(c.get('z')).toBe(3);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('last(amount) returns last n values', () => {
|
|
153
|
-
const coll = new Collection<string, number>([
|
|
154
|
-
['a', 1],
|
|
155
|
-
['b', 2],
|
|
156
|
-
['c', 3],
|
|
157
|
-
]);
|
|
158
|
-
expect(coll.last(2)).toEqual([2, 3]);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('tap invokes fn and returns this', () => {
|
|
162
|
-
const coll = new Collection<string, number>([['a', 1]]);
|
|
163
|
-
let tapped = false;
|
|
164
|
-
const result = coll.tap(() => {
|
|
165
|
-
tapped = true;
|
|
166
|
-
});
|
|
167
|
-
expect(tapped).toBe(true);
|
|
168
|
-
expect(result).toBe(coll);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it('toString returns Collection(n)', () => {
|
|
172
|
-
const coll = new Collection<string, number>([
|
|
173
|
-
['a', 1],
|
|
174
|
-
['b', 2],
|
|
175
|
-
]);
|
|
176
|
-
expect(coll.toString()).toBe('Collection(2)');
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('first(0) and last(0) return empty array', () => {
|
|
180
|
-
const coll = new Collection<string, number>([
|
|
181
|
-
['a', 1],
|
|
182
|
-
['b', 2],
|
|
183
|
-
]);
|
|
184
|
-
expect(coll.first(0)).toEqual([]);
|
|
185
|
-
expect(coll.last(0)).toEqual([]);
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('random(amount) returns requested count without duplicates', () => {
|
|
189
|
-
const coll = new Collection<string, number>([
|
|
190
|
-
['a', 1],
|
|
191
|
-
['b', 2],
|
|
192
|
-
['c', 3],
|
|
193
|
-
]);
|
|
194
|
-
const result = coll.random(2);
|
|
195
|
-
expect(result).toHaveLength(2);
|
|
196
|
-
expect(new Set(result).size).toBe(2);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it('random(amount) when amount exceeds size returns all', () => {
|
|
200
|
-
const coll = new Collection<string, number>([
|
|
201
|
-
['a', 1],
|
|
202
|
-
['b', 2],
|
|
203
|
-
]);
|
|
204
|
-
const result = coll.random(5);
|
|
205
|
-
expect(result).toHaveLength(2);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('sort orders by compareFn', () => {
|
|
209
|
-
const coll = new Collection<string, number>([
|
|
210
|
-
['c', 3],
|
|
211
|
-
['a', 1],
|
|
212
|
-
['b', 2],
|
|
213
|
-
]);
|
|
214
|
-
coll.sort((a, b) => a - b);
|
|
215
|
-
expect(coll.toJSON()).toEqual([1, 2, 3]);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it('last returns undefined for empty', () => {
|
|
219
|
-
const coll = new Collection<string, number>();
|
|
220
|
-
expect(coll.last()).toBeUndefined();
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it('every returns true for empty', () => {
|
|
224
|
-
const coll = new Collection<string, number>();
|
|
225
|
-
expect(coll.every(() => true)).toBe(true);
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it('some returns false for empty', () => {
|
|
229
|
-
const coll = new Collection<string, number>();
|
|
230
|
-
expect(coll.some(() => true)).toBe(false);
|
|
231
|
-
});
|
|
232
|
-
});
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extended Map with utility methods for key-value collections.
|
|
3
|
-
* Similar to discord.js Collection.
|
|
4
|
-
*/
|
|
5
|
-
export class Collection<K, V> extends Map<K, V> {
|
|
6
|
-
/**
|
|
7
|
-
* Obtains the first value(s) in this collection.
|
|
8
|
-
* @param amount - Amount of values to obtain (optional)
|
|
9
|
-
*/
|
|
10
|
-
first(): V | undefined;
|
|
11
|
-
first(amount: number): V[];
|
|
12
|
-
first(amount?: number): V | V[] | undefined {
|
|
13
|
-
if (amount === undefined) return this.values().next().value;
|
|
14
|
-
const arr = this.toJSON();
|
|
15
|
-
if (amount <= 0) return [];
|
|
16
|
-
return arr.slice(0, amount);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Obtains the last value(s) in this collection.
|
|
21
|
-
* @param amount - Amount of values to obtain (optional)
|
|
22
|
-
*/
|
|
23
|
-
last(): V | undefined;
|
|
24
|
-
last(amount: number): V[];
|
|
25
|
-
last(amount?: number): V | V[] | undefined {
|
|
26
|
-
const arr = this.toJSON();
|
|
27
|
-
if (amount === undefined) return arr[arr.length - 1];
|
|
28
|
-
if (amount <= 0) return [];
|
|
29
|
-
return arr.slice(-amount);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Returns a random value from this collection.
|
|
34
|
-
* @param amount - Amount of values to randomly obtain (optional)
|
|
35
|
-
*/
|
|
36
|
-
random(): V | undefined;
|
|
37
|
-
random(amount: number): V[];
|
|
38
|
-
random(amount?: number): V | V[] | undefined {
|
|
39
|
-
const arr = this.toJSON();
|
|
40
|
-
if (arr.length === 0) return amount === undefined ? undefined : [];
|
|
41
|
-
if (amount === undefined) return arr[Math.floor(Math.random() * arr.length)]!;
|
|
42
|
-
const copy = [...arr];
|
|
43
|
-
const result: V[] = [];
|
|
44
|
-
for (let i = 0; i < Math.min(amount, arr.length); i++) {
|
|
45
|
-
const index = Math.floor(Math.random() * copy.length);
|
|
46
|
-
result.push(copy.splice(index, 1)[0]!);
|
|
47
|
-
}
|
|
48
|
-
return result;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Searches for a single item where the given function returns a truthy value.
|
|
53
|
-
*/
|
|
54
|
-
find(fn: (value: V, key: K) => boolean): V | undefined {
|
|
55
|
-
for (const [key, value] of this) {
|
|
56
|
-
if (fn(value, key)) return value;
|
|
57
|
-
}
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Returns the key of the first item where the given function returns a truthy value.
|
|
63
|
-
*/
|
|
64
|
-
findKey(fn: (value: V, key: K) => boolean): K | undefined {
|
|
65
|
-
for (const [key, value] of this) {
|
|
66
|
-
if (fn(value, key)) return key;
|
|
67
|
-
}
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Creates a new collection with all elements that pass the test implemented by the provided function.
|
|
73
|
-
*/
|
|
74
|
-
filter(fn: (value: V, key: K) => boolean): Collection<K, V> {
|
|
75
|
-
const result = new Collection<K, V>();
|
|
76
|
-
for (const [key, value] of this) {
|
|
77
|
-
if (fn(value, key)) result.set(key, value);
|
|
78
|
-
}
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Creates a new array with the results of calling the provided function on every element.
|
|
84
|
-
*/
|
|
85
|
-
map<T>(fn: (value: V, key: K) => T): T[] {
|
|
86
|
-
const result: T[] = [];
|
|
87
|
-
for (const [key, value] of this) {
|
|
88
|
-
result.push(fn(value, key));
|
|
89
|
-
}
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Tests whether at least one element passes the test implemented by the provided function.
|
|
95
|
-
*/
|
|
96
|
-
some(fn: (value: V, key: K) => boolean): boolean {
|
|
97
|
-
for (const [key, value] of this) {
|
|
98
|
-
if (fn(value, key)) return true;
|
|
99
|
-
}
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Tests whether all elements pass the test implemented by the provided function.
|
|
105
|
-
*/
|
|
106
|
-
every(fn: (value: V, key: K) => boolean): boolean {
|
|
107
|
-
for (const [key, value] of this) {
|
|
108
|
-
if (!fn(value, key)) return false;
|
|
109
|
-
}
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Applies a function against an accumulator and each element to reduce the collection to a single value.
|
|
115
|
-
*/
|
|
116
|
-
reduce<T>(fn: (accumulator: T, value: V, key: K) => T, initialValue: T): T {
|
|
117
|
-
let acc = initialValue;
|
|
118
|
-
for (const [key, value] of this) {
|
|
119
|
-
acc = fn(acc, value, key);
|
|
120
|
-
}
|
|
121
|
-
return acc;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Partitions the collection into two collections: one that passes the predicate and one that fails.
|
|
126
|
-
*/
|
|
127
|
-
partition(fn: (value: V, key: K) => boolean): [Collection<K, V>, Collection<K, V>] {
|
|
128
|
-
const pass = new Collection<K, V>();
|
|
129
|
-
const fail = new Collection<K, V>();
|
|
130
|
-
for (const [key, value] of this) {
|
|
131
|
-
if (fn(value, key)) pass.set(key, value);
|
|
132
|
-
else fail.set(key, value);
|
|
133
|
-
}
|
|
134
|
-
return [pass, fail];
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Invokes the given function and returns this collection (for chaining).
|
|
139
|
-
*/
|
|
140
|
-
tap(fn: (collection: this) => void): this {
|
|
141
|
-
fn(this);
|
|
142
|
-
return this;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Creates an identical shallow copy of this collection.
|
|
147
|
-
*/
|
|
148
|
-
clone(): Collection<K, V> {
|
|
149
|
-
return new Collection(this);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Combines this collection with others into a new collection.
|
|
154
|
-
*/
|
|
155
|
-
concat(...collections: ReadonlyCollection<K, V>[]): Collection<K, V> {
|
|
156
|
-
const result = this.clone();
|
|
157
|
-
for (const coll of collections) {
|
|
158
|
-
for (const [key, value] of coll) result.set(key, value);
|
|
159
|
-
}
|
|
160
|
-
return result;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Sorts the collection in place and returns it.
|
|
165
|
-
*/
|
|
166
|
-
sort(compareFn?: (a: V, b: V, aKey: K, bKey: K) => number): this {
|
|
167
|
-
const entries = [...this.entries()].sort((a, b) => {
|
|
168
|
-
if (compareFn) return compareFn(a[1], b[1], a[0], b[0]);
|
|
169
|
-
return 0;
|
|
170
|
-
});
|
|
171
|
-
this.clear();
|
|
172
|
-
for (const [key, value] of entries) {
|
|
173
|
-
this.set(key, value);
|
|
174
|
-
}
|
|
175
|
-
return this;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Returns an array of the values in this collection.
|
|
180
|
-
*/
|
|
181
|
-
toJSON(): V[] {
|
|
182
|
-
return [...this.values()];
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Returns a string representation of the collection (array of values).
|
|
187
|
-
*/
|
|
188
|
-
override toString(): string {
|
|
189
|
-
return `Collection(${this.size})`;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Read-only view of a Collection (e.g. for method return types).
|
|
195
|
-
*/
|
|
196
|
-
export type ReadonlyCollection<K, V> = Omit<Collection<K, V>, 'set' | 'delete' | 'clear'>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Collection, type ReadonlyCollection } from './Collection.js';
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@erinjs/docgen",
|
|
3
|
-
"version": "1.2.4",
|
|
4
|
-
"private": true,
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "tsup",
|
|
10
|
-
"clean": "rm -rf dist",
|
|
11
|
-
"lint": "eslint src --max-warnings 0 --config ../../eslint.config.js",
|
|
12
|
-
"lint:fix": "eslint src --fix --config ../../eslint.config.js",
|
|
13
|
-
"test": "vitest run --passWithNoTests",
|
|
14
|
-
"test:coverage": "vitest run --coverage --passWithNoTests"
|
|
15
|
-
},
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"doctrine": "^3.0.0",
|
|
18
|
-
"typescript": "^5.6.0"
|
|
19
|
-
},
|
|
20
|
-
"devDependencies": {
|
|
21
|
-
"@types/doctrine": "^0.0.9",
|
|
22
|
-
"@types/node": "^20.0.0",
|
|
23
|
-
"tsup": "^8.3.0",
|
|
24
|
-
"typescript": "^5.6.0"
|
|
25
|
-
}
|
|
26
|
-
}
|