From d79ee3c18b8057330146f37326507b4b2993534d Mon Sep 17 00:00:00 2001 From: typicalninja <65993466+typicalninja@users.noreply.github.com> Date: Fri, 1 Nov 2024 16:03:10 +0530 Subject: [PATCH] chore: change all packages to esm only (#16) --- .changeset/short-coins-dance.md | 14 ++ README.md | 29 ++- packages/adapter-hono/package.json | 2 +- packages/disci-kit/package.json | 1 - packages/disci-kit/src/cli/cli.ts | 31 --- packages/disci-kit/src/cli/commands/init.ts | 101 --------- packages/disci-kit/src/lib/index.ts | 1 - packages/disci-kit/src/lib/init.ts | 138 ------------ packages/disci-kit/src/lib/utils/constants.ts | 20 -- packages/disci-kit/src/lib/utils/helpers.ts | 42 ---- packages/disci/.npmignore | 9 + packages/disci/LICENSE | 201 ++++++++++++++++++ packages/disci/README.md | 26 +++ packages/disci/package.json | 17 +- packages/disci/src/InteractionHandler.ts | 6 +- packages/disci/src/index.ts | 8 +- packages/disci/src/structures/Base.ts | 2 +- .../interactions/BaseInteraction.ts | 18 +- .../interactions/CommandInteractions.ts | 4 +- .../interactions/ComponentInteraction.ts | 2 +- .../src/structures/primitives/Channel.ts | 3 +- .../disci/src/structures/primitives/Guild.ts | 4 +- .../src/structures/primitives/Message.ts | 8 +- .../disci/src/structures/primitives/User.ts | 3 +- .../src/structures/primitives/Webhook.ts | 6 +- packages/disci/src/utils/Factories.ts | 7 +- packages/disci/src/utils/REST.ts | 4 +- packages/disci/src/utils/common.ts | 2 +- packages/disci/src/utils/constants.ts | 4 +- packages/disci/tsup.config.ts | 2 +- tsconfig.json | 4 +- tsup.config.ts | 4 +- 32 files changed, 317 insertions(+), 406 deletions(-) create mode 100644 .changeset/short-coins-dance.md delete mode 100644 packages/disci-kit/src/cli/cli.ts delete mode 100644 packages/disci-kit/src/cli/commands/init.ts delete mode 100644 packages/disci-kit/src/lib/index.ts delete mode 100644 packages/disci-kit/src/lib/init.ts delete mode 100644 packages/disci-kit/src/lib/utils/constants.ts delete mode 100644 packages/disci-kit/src/lib/utils/helpers.ts create mode 100644 packages/disci/.npmignore create mode 100644 packages/disci/LICENSE create mode 100644 packages/disci/README.md diff --git a/.changeset/short-coins-dance.md b/.changeset/short-coins-dance.md new file mode 100644 index 0000000..7eeef32 --- /dev/null +++ b/.changeset/short-coins-dance.md @@ -0,0 +1,14 @@ +--- +"@disci/adapter-hono": major +"disci": major +--- + +All provide packages are esm only + +They can be only imported using `import` statements and cannot be used with `require` statements. +Check [here](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) for more information. + +```diff +- const { createInteractionRequestHandler } = require('@disci/adapter-hono'); ++ import { createInteractionRequestHandler } from "@disci/adapter-hono"; +``` \ No newline at end of file diff --git a/README.md b/README.md index 06f4a5e..22738d0 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,37 @@ # 🎨 Disci Project [![NPM version badge](https://img.shields.io/npm/v/disci)](https://www.npmjs.com/package/disci) -[![NPM bundle size](hhttps://deno.bundlejs.com/badge?q=disci)](https://bundlejs.com/?q=disci) [![NPM license](https://img.shields.io/npm/l/disci)](https://www.npmjs.com/package/disci) [![GitHub issues](https://img.shields.io/github/issues/typicalninja/disci)](https://github.com/typicalninja/disci/issues) -Disci is a project designed for interacting with Discord's new interaction webhook system, enabling the creation of Discord applications without the need for a websocket connection. It's an ideal choice for serverless and small to medium-sized bots (*Size as in code size, not servers*) +Create [HTTP webserver](https://discord.com/developers/docs/interactions/overview#configuring-an-interactions-endpoint-url) powered discord bots. Supports serverless environments as well as node/deno/bun. -# 📦 Monorepo +# Install + +Please refer to [our docs](https://disci.netlify.app/) for a basic setup with a supported webserver. -This is the monorepo for Disci.js. The Disci package readme is available [here](./packages/disci/readme.md). +```bash +npm install disci +# or other platforms +pnpm/yarn/bun add disci +``` +**Note:** This project is [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) and does not support CommonJS. Your project must be [ESM or converted to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) to use disci packages. + +# 📦 Monorepo -All packages are in the ./packages directory, while Examples and Documentation are in the ./apps directory. -## 💻 Development +This is the monorepo for all discijs packages. The core disci package readme is available [here](./packages/disci/readme.md). -The current latest published version of the main package (![npm version badge](https://img.shields.io/npm/v/disci)) is a pre-release version +# 💻 Development All versions within the range of **0.xx.xx** are considered pre-release and may contain breaking changes within minor and patch releases. -## 🔗 Links +# 🔗 Links -* [Documentation & Guide](https://dev--disci.netlify.app/) -* [Npm](https://www.npmjs.com/package/disci) +* [Documentation & Guide](https://disci.netlify.app/) +* [npm (disci)](https://www.npmjs.com/package/disci) * [Github](https://github.com/typicalninja/disci) * [Discord Server](https://discord.gg/ynwckXS9T2) -## License +# License This repository and the code inside it is licensed under the Apache-2.0 License. Read [LICENSE](https://github.com/typicalninja/disci/blob/master/LICENSE) for more information. \ No newline at end of file diff --git a/packages/adapter-hono/package.json b/packages/adapter-hono/package.json index 1e2cc41..a12f5bd 100644 --- a/packages/adapter-hono/package.json +++ b/packages/adapter-hono/package.json @@ -4,7 +4,7 @@ "description": "DisciJS adapter for hono framework", "type": "module", "exports": "./dist/index.js", - "types": "./dist/index.d.js", + "types": "./dist/index.d.ts", "scripts": { "build": "tsup", "dev": "tsup --watch" diff --git a/packages/disci-kit/package.json b/packages/disci-kit/package.json index 1d7d4e2..0153d44 100644 --- a/packages/disci-kit/package.json +++ b/packages/disci-kit/package.json @@ -8,7 +8,6 @@ "discik": "./dist/cli/cli.js" }, "scripts": { - "build": "tsup", "dev": "tsup --watch" }, "keywords": [], diff --git a/packages/disci-kit/src/cli/cli.ts b/packages/disci-kit/src/cli/cli.ts deleted file mode 100644 index 94fefe6..0000000 --- a/packages/disci-kit/src/cli/cli.ts +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env node -import { hideBin } from "yargs/helpers"; -import yargs from "yargs/yargs"; -import { runInitCommand } from "./commands/init"; - -yargs(hideBin(process.argv)) - .scriptName("discik") - // handles creation of new discik projects - .command( - "init [directory]", - "Creates a starter discik project", - (yargs) => { - return yargs - .option("force", { - alias: "f", - type: "boolean", - }) - .option("noInstall", { - alias: "ni", - type: "boolean", - describe: - "Skip installing required packages and adapters. (Will have to manually install)", - }) - .positional("directory", { - default: ".", - }); - }, - (argv) => runInitCommand(argv), - ) - .help() - .parse(); diff --git a/packages/disci-kit/src/cli/commands/init.ts b/packages/disci-kit/src/cli/commands/init.ts deleted file mode 100644 index 2690708..0000000 --- a/packages/disci-kit/src/cli/commands/init.ts +++ /dev/null @@ -1,101 +0,0 @@ -import path from "node:path"; -import { cwd } from "node:process"; -import * as p from "@clack/prompts"; -import pc from "picocolors"; -import whichpm from "which-pm"; -import { directoryEmpty, ignoreUndefined } from "../../lib/utils/helpers"; - -export interface InitCommandOptions { - force?: boolean; - directory: string; -} - -const adaptersAndPackagesToInstall = { - "hono-node": ["@disci/adapter-hono"], -}; - -function installPackages(pm: string, directory: string, adapter) {} - -export async function runInitCommand(options: InitCommandOptions) { - p.intro("disci-kit-init"); - const packageManager = (await whichpm(cwd())) || { name: "npm" }; - const initialQuestions = await p.group( - { - directory: () => - p.text({ - message: "Where should we create the new project?", - initialValue: options.directory, - validate(value) { - if (value.length === 0) return "Directory is required!"; - return; - }, - }), - language: () => - p.select<{ value: string; label: string }[], unknown>({ - message: "Pick the project language.", - options: [ - { value: "ts", label: "TypeScript" }, - { value: "js", label: "JavaScript" }, - ], - }), - adapter: () => - p.select<{ value: string; label: string; hint?: string }[], unknown>({ - message: "Pick the adapter (webserver)", - options: [ - { - value: "hono", - label: `Hono (${pc.cyan("https://hono.dev/")})`, - hint: "recommended", - }, - { - value: "itty", - label: `Itty router (${pc.cyan("https://itty.dev/")})`, - }, - { - value: "express", - label: `express (${pc.cyan("https://expressjs.com/")})`, - }, - ], - }), - platform: ({ results }) => - p.select<{ value: string; label: string }[], unknown>({ - message: "Pick the platform to deploy this in.", - options: ignoreUndefined<{ value: string; label: string }>([ - { - value: "node", - label: `Node (${pc.cyan("https://nodejs.org/")})`, - }, - results.adapter !== "express" && { - value: "workers", - label: `Workers (${pc.cyan("https://workers.cloudflare.com/")})`, - }, - ]), - }), - installPackages: () => - p.confirm({ - message: `Do you want to install required packages via ${packageManager.name}`, - }), - }, - { - // On Cancel callback that wraps the group - // So if the user cancels one of the prompts in the group this function will be called - onCancel: () => { - p.cancel("Operation cancelled."); - process.exit(0); - }, - }, - ); - - const resolvedDirectory = path.resolve(initialQuestions.directory); - // check if the directory is empty or not - // if it is not empty and force is not enabled, print a continue or not prompt - if (!(await directoryEmpty(resolvedDirectory)) && !options.force) { - const shouldContinue = await p.confirm({ - message: "Destionation directory is not empty, do you want to continue?", - }); - if (!shouldContinue || p.isCancel(shouldContinue)) - return p.cancel("Operation cancelled."); - } - - console.log(initialQuestions); -} diff --git a/packages/disci-kit/src/lib/index.ts b/packages/disci-kit/src/lib/index.ts deleted file mode 100644 index c49471e..0000000 --- a/packages/disci-kit/src/lib/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * as InitProject from "./init"; diff --git a/packages/disci-kit/src/lib/init.ts b/packages/disci-kit/src/lib/init.ts deleted file mode 100644 index 19886d0..0000000 --- a/packages/disci-kit/src/lib/init.ts +++ /dev/null @@ -1,138 +0,0 @@ -import { exec as execSync } from "node:child_process"; -import fs from "node:fs/promises"; -import path from "node:path"; -import util from "node:util"; -import pc from "picocolors"; -import whichpm from "which-pm"; -import { type DisckConfig, configSchema } from "./utils/constants"; -import { directoryEmpty, directoryExists, logger } from "./utils/helpers"; - -const exec = util.promisify(execSync); - -export async function createConfigFile( - at: string, -): Promise { - try { - // zod.parse with empty obj will return the default values for the object schema - const config = await configSchema.parseAsync({}); - await fs.writeFile(at, JSON.stringify(config, null, 4)); - return config; - } catch (err) { - logger.error(`Could not create base config at ${pc.red(at)}`); - logger.details(err); - return null; - } -} - -export async function createEssentialDirectories(srcDirectory: string) { - const handler = path.resolve(srcDirectory, "./handlers"); - const libDir = path.resolve(srcDirectory, "./lib"); - - const commandHandler = path.resolve(handler, "./commands/"); - const componentHandler = path.resolve(handler, "./components/"); - - logger.info("Creating handler directories."); - - try { - await fs.mkdir(libDir, { recursive: true }); - await fs.mkdir(commandHandler, { recursive: true }); - await fs.mkdir(componentHandler, { recursive: true }); - return true; - } catch (err) { - logger.error("Failed to create essential directories"); - logger.details(err); - - return null; - } -} - -export async function createPackageJSON(dir: string) { - const pkgJSON = { - name: path.basename(dir), - version: "1.0.0", - public: false, - type: "module", - }; - - try { - await fs.writeFile( - path.resolve(dir, "package.json"), - JSON.stringify(pkgJSON, null, 4), - ); - return true; - } catch { - return null; - } -} - -export async function installRequiredPackages( - dir: string, - config: DisckConfig, - packageManager?: string, -) { - const pm = packageManager - ? { name: packageManager } - : (await whichpm(process.cwd())) || "npm"; - logger.info(`Installing packages using ${pm.name}`); - const args = []; - - // install the adapter - args.push(`@disci/adapter-${config.adapter}`); - args.push("disci"); - - try { - const { stdout } = await exec(`${pm.name} install ${args.join(" ")}`, { - cwd: dir, - }); - console.log(stdout); - return true; - } catch (e) { - logger.error(`Failed to install packages using ${pm.name}`); - logger.details(e); - return null; - } -} - -export async function init( - directory: string, - force = false, - noInstall = false, - packageManager?: string, -) { - const destinationDirectory = path.resolve(directory); - logger.info("Creating project.."); - logger.details(`@ ${pc.green(destinationDirectory)}`); - - if (await directoryExists(destinationDirectory)) { - if (!(await directoryEmpty(destinationDirectory)) && !force) { - return logger.error( - "Destination directory is not empty, delete it or use --force", - ); - } - await fs.rm(destinationDirectory, { recursive: true }); - } - - logger.info("Initiating the destination directory...."); - // directory does not exist, create it here - await fs.mkdir(destinationDirectory, { recursive: true }); - - // create & save the default config and returns it - const config = await createConfigFile( - path.join(destinationDirectory, "kit.json"), - ); - if (!config) return; - - const eDirectoryCS = await createEssentialDirectories( - path.resolve(destinationDirectory, config.srcDir), - ); - if (!eDirectoryCS) return; - - if (noInstall) { - logger.warn( - "Package installation disabled... please install the required packages manually.", - ); - } else { - await createPackageJSON(destinationDirectory); - await installRequiredPackages(destinationDirectory, config, packageManager); - } -} diff --git a/packages/disci-kit/src/lib/utils/constants.ts b/packages/disci-kit/src/lib/utils/constants.ts deleted file mode 100644 index fb168aa..0000000 --- a/packages/disci-kit/src/lib/utils/constants.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { z } from "zod"; - -export interface InteractionCommand { - name: string; -} - -export const Adapters = z.enum(["hono"]); -export type Adapters = z.infer; - -export const Platforms = z.enum(["workers", "node"]); -export type Platforms = z.infer; - -export const configSchema = z.object({ - // points where discik will look for src file - srcDir: z.string().default("./src"), - adapter: Adapters.default("hono"), - platform: Platforms.default("node"), -}); - -export type DisckConfig = z.infer; diff --git a/packages/disci-kit/src/lib/utils/helpers.ts b/packages/disci-kit/src/lib/utils/helpers.ts deleted file mode 100644 index c8f9ee8..0000000 --- a/packages/disci-kit/src/lib/utils/helpers.ts +++ /dev/null @@ -1,42 +0,0 @@ -import fs from "node:fs/promises"; -import pc from "picocolors"; - -export async function directoryExists(dir: string) { - try { - await fs.stat(dir); - return true; - } catch { - return false; - } -} - -export async function directoryEmpty(dir: string) { - try { - const files = await fs.readdir(dir); - if (files.length > 0) return false; - - return true; - } catch { - // we consider directory not existing as empty - // this could also be error for the dir path being a file - // but we ignore that - return true; - } -} - -export function ignoreUndefined>( - array: (T | false)[], -): T[] { - return array.filter((a) => a) as T[]; -} - -export const logger = { - info: (...messages: unknown[]) => - console.error(`[${pc.cyan("INFO")}]`, ...messages), - warn: (...messages: unknown[]) => - console.error(`[${pc.yellow("WARN")}]`, ...messages), - error: (...messages: unknown[]) => - console.error(`[${pc.red("ERROR")}]`, ...messages), - details: (...messages: unknown[]) => - console.error(`[${pc.dim("↳")} Details]`, ...messages), -}; diff --git a/packages/disci/.npmignore b/packages/disci/.npmignore new file mode 100644 index 0000000..e3df86b --- /dev/null +++ b/packages/disci/.npmignore @@ -0,0 +1,9 @@ +src + +tsup.config.ts +tsconfig.json +# Ignore changeset changelogs +CHANGELOG.md + +# tools +.turbo \ No newline at end of file diff --git a/packages/disci/LICENSE b/packages/disci/LICENSE new file mode 100644 index 0000000..5e8a79d --- /dev/null +++ b/packages/disci/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2023 imayuru + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/packages/disci/README.md b/packages/disci/README.md new file mode 100644 index 0000000..28072d1 --- /dev/null +++ b/packages/disci/README.md @@ -0,0 +1,26 @@ +# disci + +Create [HTTP webserver](https://discord.com/developers/docs/interactions/overview#configuring-an-interactions-endpoint-url) powered discord bots. +Supports serverless environments as well as node/deno/bun. + +# Install + +Please refer to [our docs](https://disci.netlify.app/) for a basic setup with a supported webserver. + +```bash +npm install disci +# or other platforms +pnpm/yarn/bun add disci +``` +**Note:** This project is [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) and does not support CommonJS. Your project must be [ESM or converted to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) to use disci packages. + +# 🔗 Links + +* [Documentation & Guide](https://disci.netlify.app/) +* [npm (disci)](https://www.npmjs.com/package/disci) +* [Github](https://github.com/typicalninja/disci) +* [Discord Server](https://discord.gg/ynwckXS9T2) + +# License + +This repository and the code inside it is licensed under the Apache-2.0 License. Read [LICENSE](https://github.com/typicalninja/disci/blob/master/LICENSE) for more information. \ No newline at end of file diff --git a/packages/disci/package.json b/packages/disci/package.json index b1f3945..36bf8b6 100644 --- a/packages/disci/package.json +++ b/packages/disci/package.json @@ -2,15 +2,10 @@ "name": "disci", "private": true, "version": "0.0.6-alpha", - "description": "A HTTP Request handler for discord interactions", - "main": "./dist/index.js", - "module": "./dist/index.mjs", + "description": "Create HTTP webserver powered discord bots", + "type": "module", + "exports": "./dist/index.js", "types": "./dist/index.d.ts", - "exports": { - "types": "./dist/index.d.ts", - "require": "./dist/index.js", - "import": "./dist/index.mjs" - }, "license": "Apache-2.0", "scripts": { "build": "tsup", @@ -44,12 +39,6 @@ "url": "https://github.com/typicalninja/disci/issues" }, "homepage": "https://disci.vercel.app/", - "lint-staged": { - "*.{js,ts}": [ - "pnpm prettier:write", - "pnpm lint:check" - ] - }, "engines": { "node": ">=16.6.0" } diff --git a/packages/disci/src/InteractionHandler.ts b/packages/disci/src/InteractionHandler.ts index 72ee82a..e7f8639 100644 --- a/packages/disci/src/InteractionHandler.ts +++ b/packages/disci/src/InteractionHandler.ts @@ -6,8 +6,8 @@ import { } from "discord-api-types/v10"; import { verify } from "discord-verify"; import { EventEmitter } from "eventemitter3"; -import { InteractionFactory } from "./utils/Factories"; -import { Rest } from "./utils/REST"; +import { InteractionFactory } from "./utils/Factories.js"; +import { Rest } from "./utils/REST.js"; import { DefaultConfig, DiscordVerifyHeaders, @@ -16,7 +16,7 @@ import { type HandlerConfig, type HandlerEvents, InternalEventNames, -} from "./utils/constants"; +} from "./utils/constants.js"; export class InteractionHandler extends EventEmitter< HandlerEvents & { [key: string]: unknown } diff --git a/packages/disci/src/index.ts b/packages/disci/src/index.ts index 9ae2673..a5ba764 100644 --- a/packages/disci/src/index.ts +++ b/packages/disci/src/index.ts @@ -1,6 +1,6 @@ -export * from "./InteractionHandler"; -export * from "./structures/interactions/BaseInteraction"; +export * from "./InteractionHandler.js"; +export * from "./structures/interactions/BaseInteraction.js"; -export * from "./utils/constants"; +export * from "./utils/constants.js"; -export * as Factories from "./utils/Factories"; +export * as Factories from "./utils/Factories.js"; diff --git a/packages/disci/src/structures/Base.ts b/packages/disci/src/structures/Base.ts index b1469c0..d524328 100644 --- a/packages/disci/src/structures/Base.ts +++ b/packages/disci/src/structures/Base.ts @@ -1,4 +1,4 @@ -import type { InteractionHandler } from "../InteractionHandler"; +import type { InteractionHandler } from "../InteractionHandler.js"; export abstract class Base { /** diff --git a/packages/disci/src/structures/interactions/BaseInteraction.ts b/packages/disci/src/structures/interactions/BaseInteraction.ts index ee3d639..8682af8 100644 --- a/packages/disci/src/structures/interactions/BaseInteraction.ts +++ b/packages/disci/src/structures/interactions/BaseInteraction.ts @@ -11,22 +11,22 @@ import { InteractionType, type Snowflake, } from "discord-api-types/v10"; -import type { InteractionHandler } from "../../InteractionHandler"; -import { InternalEventNames } from "../../utils/constants"; -import { Base } from "../Base"; -import { PermissionsBitField } from "../Bitfield"; -import { PartialGuild } from "../primitives/Guild"; +import type { InteractionHandler } from "../../InteractionHandler.js"; +import { InternalEventNames } from "../../utils/constants.js"; +import { Base } from "../Base.js"; +import { PermissionsBitField } from "../Bitfield.js"; +import { PartialGuild } from "../primitives/Guild.js"; import { type CreateMessageParams, type Message, MessagePartial, -} from "../primitives/Message"; -import { WebhookPartial } from "../primitives/Webhook"; +} from "../primitives/Message.js"; +import { WebhookPartial } from "../primitives/Webhook.js"; import type { AutoCompleteInteraction, BaseCommandInteraction, -} from "./CommandInteractions"; -import type { BaseComponentInteraction } from "./ComponentInteraction"; +} from "./CommandInteractions.js"; +import type { BaseComponentInteraction } from "./ComponentInteraction.js"; export class BaseInteraction< T extends APIInteraction = APIInteraction, diff --git a/packages/disci/src/structures/interactions/CommandInteractions.ts b/packages/disci/src/structures/interactions/CommandInteractions.ts index 2226c94..8a1a601 100644 --- a/packages/disci/src/structures/interactions/CommandInteractions.ts +++ b/packages/disci/src/structures/interactions/CommandInteractions.ts @@ -4,12 +4,12 @@ import { type APIApplicationCommandOptionChoice, InteractionResponseType, } from "discord-api-types/v10"; -import type { InteractionHandler } from "../../InteractionHandler"; +import type { InteractionHandler } from "../../InteractionHandler.js"; import { BaseInteraction, BaseRepliableInteraction, InteractionOptions, -} from "./BaseInteraction"; +} from "./BaseInteraction.js"; export class BaseCommandInteraction extends BaseRepliableInteraction {} diff --git a/packages/disci/src/structures/interactions/ComponentInteraction.ts b/packages/disci/src/structures/interactions/ComponentInteraction.ts index 598a365..feace33 100644 --- a/packages/disci/src/structures/interactions/ComponentInteraction.ts +++ b/packages/disci/src/structures/interactions/ComponentInteraction.ts @@ -1,4 +1,4 @@ import type { APIMessageComponentInteraction } from "discord-api-types/v10"; -import { BaseRepliableInteraction } from "./BaseInteraction"; +import { BaseRepliableInteraction } from "./BaseInteraction.js"; export class BaseComponentInteraction extends BaseRepliableInteraction {} diff --git a/packages/disci/src/structures/primitives/Channel.ts b/packages/disci/src/structures/primitives/Channel.ts index a05d9be..9974c3e 100644 --- a/packages/disci/src/structures/primitives/Channel.ts +++ b/packages/disci/src/structures/primitives/Channel.ts @@ -1,6 +1,5 @@ import { type APIChannel, Routes, type Snowflake } from "discord-api-types/v10"; -import type { InteractionHandler } from "../../InteractionHandler"; -import { Base } from "../Base"; +import { Base } from "../Base.js"; export class GenericPartialChannel< T extends { id: Snowflake }, diff --git a/packages/disci/src/structures/primitives/Guild.ts b/packages/disci/src/structures/primitives/Guild.ts index 838df1e..6276c6e 100644 --- a/packages/disci/src/structures/primitives/Guild.ts +++ b/packages/disci/src/structures/primitives/Guild.ts @@ -4,8 +4,8 @@ import { Routes, type Snowflake, } from "discord-api-types/v10"; -import type { InteractionHandler } from "../../InteractionHandler"; -import { Base } from "../Base"; +import type { InteractionHandler } from "../../InteractionHandler.js"; +import { Base } from "../Base.js"; export class PartialGuild< T extends { id: Snowflake } = { id: Snowflake }, diff --git a/packages/disci/src/structures/primitives/Message.ts b/packages/disci/src/structures/primitives/Message.ts index e1b91cf..3b83c20 100644 --- a/packages/disci/src/structures/primitives/Message.ts +++ b/packages/disci/src/structures/primitives/Message.ts @@ -7,10 +7,10 @@ import type { MessageFlags, Snowflake, } from "discord-api-types/v10"; -import type { InteractionHandler } from "../../InteractionHandler"; -import type { RESTFile } from "../../utils/REST"; -import { Base } from "../Base"; -import { type BitFieldResolvable, MessageFlagsBitField } from "../Bitfield"; +import type { InteractionHandler } from "../../InteractionHandler.js"; +import type { RESTFile } from "../../utils/REST.js"; +import { Base } from "../Base.js"; +import { type BitFieldResolvable, MessageFlagsBitField } from "../Bitfield.js"; /** * @link https://discord.com/developers/docs/resources/channel#allowed-mentions-object diff --git a/packages/disci/src/structures/primitives/User.ts b/packages/disci/src/structures/primitives/User.ts index 8f2469a..9cdeccd 100644 --- a/packages/disci/src/structures/primitives/User.ts +++ b/packages/disci/src/structures/primitives/User.ts @@ -1,6 +1,5 @@ import { type APIUser, Routes, type Snowflake } from "discord-api-types/v10"; -import type { InteractionHandler } from "../../InteractionHandler"; -import { Base } from "../Base"; +import { Base } from "../Base.js"; export class PartialUser extends Base<{ id: Snowflake }> { /** diff --git a/packages/disci/src/structures/primitives/Webhook.ts b/packages/disci/src/structures/primitives/Webhook.ts index 38b416f..23af9bd 100644 --- a/packages/disci/src/structures/primitives/Webhook.ts +++ b/packages/disci/src/structures/primitives/Webhook.ts @@ -4,9 +4,9 @@ import { Routes, type Snowflake, } from "discord-api-types/v10"; -import type { InteractionHandler } from "../../InteractionHandler"; -import { Base } from "../Base"; -import { type CreateMessageParams, Message } from "./Message"; +import type { InteractionHandler } from "../../InteractionHandler.js"; +import { Base } from "../Base.js"; +import { type CreateMessageParams, Message } from "./Message.js"; export class WebhookPartial extends Base> { /** diff --git a/packages/disci/src/utils/Factories.ts b/packages/disci/src/utils/Factories.ts index ecf0153..a2808c7 100644 --- a/packages/disci/src/utils/Factories.ts +++ b/packages/disci/src/utils/Factories.ts @@ -1,14 +1,15 @@ import { type APIInteraction, InteractionType } from "discord-api-types/v10"; -import type { InteractionHandler } from "../InteractionHandler"; +import type { InteractionHandler } from "../InteractionHandler.js"; import { BaseInteraction, BaseRepliableInteraction, -} from "../structures/interactions/BaseInteraction"; +} from "../structures/interactions/BaseInteraction.js"; import { AutoCompleteInteraction, BaseCommandInteraction, -} from "../structures/interactions/CommandInteractions"; +} from "../structures/interactions/CommandInteractions.js"; +// biome-ignore lint/complexity/noStaticOnlyClass: factories are meant to be static (for now) export class InteractionFactory { static from(raw: APIInteraction, handler: InteractionHandler) { switch (raw.type) { diff --git a/packages/disci/src/utils/REST.ts b/packages/disci/src/utils/REST.ts index 2d9a81b..75dd7a0 100644 --- a/packages/disci/src/utils/REST.ts +++ b/packages/disci/src/utils/REST.ts @@ -1,5 +1,5 @@ -import { isBufferLike, serializeObject, tryAndValue } from "./common"; -import { URLS } from "./constants"; +import { isBufferLike, serializeObject, tryAndValue } from "./common.js"; +import { URLS } from "./constants.js"; // userAgent used in requests const UserAgent = diff --git a/packages/disci/src/utils/common.ts b/packages/disci/src/utils/common.ts index 9eba0df..67cb69a 100644 --- a/packages/disci/src/utils/common.ts +++ b/packages/disci/src/utils/common.ts @@ -1,5 +1,5 @@ import type { Snowflake } from "discord-api-types/globals"; -import { DiscordEpoch } from "./constants"; +import { DiscordEpoch } from "./constants.js"; /** * Converts a discord id to a timestamp diff --git a/packages/disci/src/utils/constants.ts b/packages/disci/src/utils/constants.ts index 5559f8d..7f839f6 100644 --- a/packages/disci/src/utils/constants.ts +++ b/packages/disci/src/utils/constants.ts @@ -1,5 +1,5 @@ -import type { BaseInteraction } from "../structures/interactions/BaseInteraction"; -import type { RESTClientOptions } from "./REST"; +import type { BaseInteraction } from "../structures/interactions/BaseInteraction.js"; +import type { RESTClientOptions } from "./REST.js"; export const DiscordEpoch = 14200704e5; diff --git a/packages/disci/tsup.config.ts b/packages/disci/tsup.config.ts index af6fa64..75b7e39 100644 --- a/packages/disci/tsup.config.ts +++ b/packages/disci/tsup.config.ts @@ -1,4 +1,4 @@ -import { createTsupConfig } from "../../tsup.config"; +import { createTsupConfig } from "../../tsup.config.js"; export default [ createTsupConfig({ diff --git a/tsconfig.json b/tsconfig.json index 1d88cc6..7c43241 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,8 +3,8 @@ "display": "Default", "compilerOptions": { "target": "ES2022", - "module": "commonjs", - "moduleResolution": "node", + "module": "Node16", + "moduleResolution": "Node16", "declaration": true, "outDir": "dist", "removeComments": false, diff --git a/tsup.config.ts b/tsup.config.ts index eb4817b..c78e877 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -5,8 +5,8 @@ export function createTsupConfig({ external = [], noExternal = [], platform = "node", - format = ["cjs", "esm"], - target = "esnext", + format = ["esm"], + target = "node16", skipNodeModulesBundle = true, clean = true, shims = false,