@sapphire/pieces 4.4.2-next.9fc01a6 → 4.4.2-next.ad8b9f8

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.
Files changed (35) hide show
  1. package/dist/cjs/lib/errors/LoaderError.cjs.map +1 -1
  2. package/dist/cjs/lib/errors/MissingExportsError.cjs.map +1 -1
  3. package/dist/cjs/lib/internal/Path.cjs.map +1 -1
  4. package/dist/cjs/lib/internal/RootScan.cjs.map +1 -1
  5. package/dist/cjs/lib/internal/constants.cjs.map +1 -1
  6. package/dist/cjs/lib/shared/Container.cjs.map +1 -1
  7. package/dist/cjs/lib/strategies/LoaderStrategy.cjs +1 -0
  8. package/dist/cjs/lib/strategies/LoaderStrategy.cjs.map +1 -1
  9. package/dist/cjs/lib/strategies/Shared.cjs.map +1 -1
  10. package/dist/cjs/lib/strategies/env.cjs.map +1 -1
  11. package/dist/cjs/lib/structures/AliasPiece.cjs.map +1 -1
  12. package/dist/cjs/lib/structures/AliasStore.cjs.map +1 -1
  13. package/dist/cjs/lib/structures/Piece.cjs.map +1 -1
  14. package/dist/cjs/lib/structures/PieceLocation.cjs.map +1 -1
  15. package/dist/cjs/lib/structures/Store.cjs.map +1 -1
  16. package/dist/cjs/lib/structures/StoreRegistry.cjs.map +1 -1
  17. package/dist/cjs/tsconfig.cjs.map +1 -1
  18. package/dist/esm/lib/errors/LoaderError.mjs.map +1 -1
  19. package/dist/esm/lib/errors/MissingExportsError.mjs.map +1 -1
  20. package/dist/esm/lib/internal/Path.mjs.map +1 -1
  21. package/dist/esm/lib/internal/RootScan.mjs.map +1 -1
  22. package/dist/esm/lib/internal/constants.mjs.map +1 -1
  23. package/dist/esm/lib/shared/Container.mjs.map +1 -1
  24. package/dist/esm/lib/strategies/LoaderStrategy.mjs +1 -0
  25. package/dist/esm/lib/strategies/LoaderStrategy.mjs.map +1 -1
  26. package/dist/esm/lib/strategies/Shared.mjs.map +1 -1
  27. package/dist/esm/lib/strategies/env.mjs.map +1 -1
  28. package/dist/esm/lib/structures/AliasPiece.mjs.map +1 -1
  29. package/dist/esm/lib/structures/AliasStore.mjs.map +1 -1
  30. package/dist/esm/lib/structures/Piece.mjs.map +1 -1
  31. package/dist/esm/lib/structures/PieceLocation.mjs.map +1 -1
  32. package/dist/esm/lib/structures/Store.mjs.map +1 -1
  33. package/dist/esm/lib/structures/StoreRegistry.mjs.map +1 -1
  34. package/dist/esm/tsconfig.mjs.map +1 -1
  35. package/package.json +15 -15
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/errors/LoaderError.ts"],"names":["LoaderErrorType"],"mappings":";;;;;;;;AAAY,IAAA,eAAA,qBAAAA,gBAAL,KAAA;AACN,EAAAA,iBAAA,aAAc,CAAA,GAAA,cAAA;AACd,EAAAA,iBAAA,cAAe,CAAA,GAAA,eAAA;AACf,EAAAA,iBAAA,eAAgB,CAAA,GAAA,gBAAA;AAChB,EAAAA,iBAAA,eAAgB,CAAA,GAAA,gBAAA;AAChB,EAAAA,iBAAA,cAAe,CAAA,GAAA,eAAA;AALJ,EAAAA,OAAAA,gBAAAA;AAAA,CAAA,EAAA,eAAA,IAAA,EAAA;AAWL,IAAM,YAAA,GAAN,MAAM,YAAA,SAAoB,KAAM,CAAA;AAAA,EAM/B,WAAA,CAAY,MAAuB,OAAiB,EAAA;AAC1D,IAAA,KAAA,CAAM,OAAO,CAAA;AAHd;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAIf,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;AAAA;AACb,EAEA,IAAoB,IAAO,GAAA;AAC1B,IAAA,OAAO,CAAG,EAAA,KAAA,CAAM,IAAI,CAAA,EAAA,EAAK,KAAK,IAAI,CAAA,CAAA,CAAA;AAAA;AAEpC,CAAA;AAduC,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA;AAAhC,IAAM,WAAN,GAAA","file":"LoaderError.cjs","sourcesContent":["export enum LoaderErrorType {\n\tEmptyModule = 'EMPTY_MODULE',\n\tVirtualPiece = 'VIRTUAL_PIECE',\n\tUnloadedPiece = 'UNLOADED_PIECE',\n\tIncorrectType = 'INCORRECT_TYPE',\n\tUnknownStore = 'UNKNOWN_STORE'\n}\n\n/**\n * Describes a loader error with a type for easy identification.\n */\nexport class LoaderError extends Error {\n\t/**\n\t * The type of the error that was thrown.\n\t */\n\tpublic readonly type: LoaderErrorType;\n\n\tpublic constructor(type: LoaderErrorType, message: string) {\n\t\tsuper(message);\n\t\tthis.type = type;\n\t}\n\n\tpublic override get name() {\n\t\treturn `${super.name} [${this.type}]`;\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/errors/LoaderError.ts"],"names":["LoaderErrorType"],"mappings":";;;;;;;;AAAO,IAAK,eAAA,qBAAAA,gBAAAA,KAAL;AACN,EAAAA,iBAAA,aAAA,CAAA,GAAc,cAAA;AACd,EAAAA,iBAAA,cAAA,CAAA,GAAe,eAAA;AACf,EAAAA,iBAAA,eAAA,CAAA,GAAgB,gBAAA;AAChB,EAAAA,iBAAA,eAAA,CAAA,GAAgB,gBAAA;AAChB,EAAAA,iBAAA,cAAA,CAAA,GAAe,eAAA;AALJ,EAAA,OAAAA,gBAAAA;AAAA,CAAA,EAAA,eAAA,IAAA,EAAA;AAWL,IAAM,YAAA,GAAN,MAAM,YAAA,SAAoB,KAAA,CAAM;AAAA,EAM/B,WAAA,CAAY,MAAuB,OAAA,EAAiB;AAC1D,IAAA,KAAA,CAAM,OAAO,CAAA;AAHd;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,MAAA,CAAA;AAIf,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACb;AAAA,EAEA,IAAoB,IAAA,GAAO;AAC1B,IAAA,OAAO,CAAA,EAAG,KAAA,CAAM,IAAI,CAAA,EAAA,EAAK,KAAK,IAAI,CAAA,CAAA,CAAA;AAAA,EACnC;AACD,CAAA;AAduC,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA;AAAhC,IAAM,WAAA,GAAN","file":"LoaderError.cjs","sourcesContent":["export enum LoaderErrorType {\n\tEmptyModule = 'EMPTY_MODULE',\n\tVirtualPiece = 'VIRTUAL_PIECE',\n\tUnloadedPiece = 'UNLOADED_PIECE',\n\tIncorrectType = 'INCORRECT_TYPE',\n\tUnknownStore = 'UNKNOWN_STORE'\n}\n\n/**\n * Describes a loader error with a type for easy identification.\n */\nexport class LoaderError extends Error {\n\t/**\n\t * The type of the error that was thrown.\n\t */\n\tpublic readonly type: LoaderErrorType;\n\n\tpublic constructor(type: LoaderErrorType, message: string) {\n\t\tsuper(message);\n\t\tthis.type = type;\n\t}\n\n\tpublic override get name() {\n\t\treturn `${super.name} [${this.type}]`;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/errors/MissingExportsError.ts"],"names":["LoaderError","LoaderErrorType"],"mappings":";;;;;;;;AAKO,IAAM,oBAAA,GAAN,MAAM,oBAAA,SAA4BA,2BAAY,CAAA;AAAA,EAM7C,YAAY,IAAc,EAAA;AAChC,IAAA,KAAA,CAAMC,+BAAgB,CAAA,WAAA,EAAa,CAA6C,0CAAA,EAAA,IAAI,CAAG,CAAA,CAAA,CAAA;AAHxF;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAIf,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;AAAA;AAEd,CAAA;AAVqD,MAAA,CAAA,oBAAA,EAAA,qBAAA,CAAA;AAA9C,IAAM,mBAAN,GAAA","file":"MissingExportsError.cjs","sourcesContent":["import { LoaderError, LoaderErrorType } from './LoaderError';\n\n/**\n * Describes a {@link LoaderErrorType.EmptyModule} loader error and adds a path for easy identification.\n */\nexport class MissingExportsError extends LoaderError {\n\t/**\n\t * The path of the module that did not have exports.\n\t */\n\tpublic readonly path: string;\n\n\tpublic constructor(path: string) {\n\t\tsuper(LoaderErrorType.EmptyModule, `A compatible class export was not found. [${path}]`);\n\t\tthis.path = path;\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/errors/MissingExportsError.ts"],"names":["LoaderError","LoaderErrorType"],"mappings":";;;;;;;;AAKO,IAAM,oBAAA,GAAN,MAAM,oBAAA,SAA4BA,2BAAA,CAAY;AAAA,EAM7C,YAAY,IAAA,EAAc;AAChC,IAAA,KAAA,CAAMC,+BAAA,CAAgB,WAAA,EAAa,CAAA,0CAAA,EAA6C,IAAI,CAAA,CAAA,CAAG,CAAA;AAHxF;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,MAAA,CAAA;AAIf,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACb;AACD,CAAA;AAVqD,MAAA,CAAA,oBAAA,EAAA,qBAAA,CAAA;AAA9C,IAAM,mBAAA,GAAN","file":"MissingExportsError.cjs","sourcesContent":["import { LoaderError, LoaderErrorType } from './LoaderError';\n\n/**\n * Describes a {@link LoaderErrorType.EmptyModule} loader error and adds a path for easy identification.\n */\nexport class MissingExportsError extends LoaderError {\n\t/**\n\t * The path of the module that did not have exports.\n\t */\n\tpublic readonly path: string;\n\n\tpublic constructor(path: string) {\n\t\tsuper(LoaderErrorType.EmptyModule, `A compatible class export was not found. [${path}]`);\n\t\tthis.path = path;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/internal/Path.ts"],"names":["fileURLToPath"],"mappings":";;;;;;AAIO,SAAS,YAAY,IAAoB,EAAA;AAC/C,EAAI,IAAA,OAAO,IAAS,KAAA,QAAA,EAAiB,OAAA,IAAA;AACrC,EAAA,OAAOA,kBAAc,IAAI,CAAA;AAC1B;AAHgB,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA","file":"Path.cjs","sourcesContent":["import { fileURLToPath } from 'node:url';\n\nexport type Path = string | URL;\n\nexport function resolvePath(path: Path): string {\n\tif (typeof path === 'string') return path;\n\treturn fileURLToPath(path);\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/internal/Path.ts"],"names":["fileURLToPath"],"mappings":";;;;;;AAIO,SAAS,YAAY,IAAA,EAAoB;AAC/C,EAAA,IAAI,OAAO,IAAA,KAAS,QAAA,EAAU,OAAO,IAAA;AACrC,EAAA,OAAOA,kBAAc,IAAI,CAAA;AAC1B;AAHgB,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA","file":"Path.cjs","sourcesContent":["import { fileURLToPath } from 'node:url';\n\nexport type Path = string | URL;\n\nexport function resolvePath(path: Path): string {\n\tif (typeof path === 'string') return path;\n\treturn fileURLToPath(path);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/internal/RootScan.ts"],"names":["dirname","join","readFileSync","existsSync"],"mappings":";;;;;;;AA4BA,IAAI,IAAwB,GAAA,IAAA;AAS5B,SAAS,eAAA,CAAgB,KAAa,YAAsB,EAAA;AAC3D,EAAA,OAAOA,YAAQ,CAAAC,SAAA,CAAK,GAAK,EAAA,YAAY,CAAC,CAAA;AACvC;AAFS,MAAA,CAAA,eAAA,EAAA,iBAAA,CAAA;AAIF,SAAS,WAAwB,GAAA;AACvC,EAAA,OAAQ,SAAS,aAAc,EAAA;AAChC;AAFgB,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA;AAmCT,SAAS,aAA0B,GAAA;AACzC,EAAM,MAAA,GAAA,GAAM,QAAQ,GAAI,EAAA;AAExB,EAAI,IAAA,IAAA;AAEJ,EAAI,IAAA;AACH,IAAO,IAAA,GAAA,IAAA,CAAK,MAAMC,eAAa,CAAAD,SAAA,CAAK,KAAK,cAAc,CAAA,EAAG,MAAM,CAAC,CAAA;AAAA,WACzD,KAAO,EAAA;AACf,IAAA,MAAM,iBAAoB,GAAAE,aAAA,CAAWF,SAAK,CAAA,GAAA,EAAK,WAAW,CAAC,CAAA;AAC3D,IAAA,MAAM,gBAAmB,GAAAE,aAAA,CAAWF,SAAK,CAAA,GAAA,EAAK,aAAa,C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EAAA;AAEnF,EAAA,OAAO,EAAE,IAAA,EAAM,GAAK,EAAA,IAAA,EAAM,UAAW,EAAA;AACtC;AAjCgB,MAAA,CAAA,aAAA,EAAA,eAAA,CAAA","file":"RootScan.cjs","sourcesContent":["import { existsSync, readFileSync } from 'fs';\nimport { dirname, join } from 'path';\n\n/**\n * Represents a partial package.json object.\n */\ntype PartialPackageJson = Partial<{\n\tmain: string;\n\tmodule: string;\n\ttype: 'commonjs' | 'module';\n}>;\n\n/**\n * Represents the root data.\n */\nexport interface RootData {\n\t/**\n\t * The root directory.\n\t */\n\troot: string;\n\n\t/**\n\t * The type of the module system used.\n\t * It can be either 'ESM' or 'CommonJS'.\n\t */\n\ttype: 'ESM' | 'CommonJS';\n}\n\nlet data: RootData | null = null;\n\n/**\n * Returns the directory name of a given path by joining the current working directory (cwd) with the joinable path.\n * @private\n * @param cwd - The current working directory.\n * @param joinablePath - The path to be joined with the cwd.\n * @returns The directory name of the joined path.\n */\nfunction dirnameWithPath(cwd: string, joinablePath: string) {\n\treturn dirname(join(cwd, joinablePath));\n}\n\nexport function getRootData(): RootData {\n\treturn (data ??= parseRootData());\n}\n\n/**\n * Retrieves the root data of the project.\n *\n * This function reads the `package.json` file in the current working directory and determines the root path and type\n * of the project.\n *\n * - If the `package.json` file is not found or cannot be parsed, it assumes the project is using CommonJS and\n * the current working directory is used as the root\n *\n * - If the project `type` is specified as `\"commonjs\"` or `\"module\"` in the `package.json`, it uses the corresponding\n * `main` or `module` file path as the root.\n *\n * - If there is no `main` or `module` then it uses the current working directory as the root, while retaining the\n * matching `CommonJS` or `ESM` based on the `type`\n *\n * - If the main or module file path is not specified, it uses the current working directory as the root.\n *\n * The following table shows how different situations resolve to different root data\n *\n * | fields | resolved as |\n * |--------------------------|-------------|\n * | type=commonjs && main | CommonJS |\n * | type=commonjs && module | CommonJS |\n * | type=module && main | ESM |\n * | type=module && module | ESM |\n * | type=undefined && main | CommonJS |\n * | type=undefined && module | ESM |\n * | no package.json on cwd | CommonJS |\n *\n * @returns The root data object containing the root path and the type of the project.\n */\nexport function parseRootData(): RootData {\n\tconst cwd = process.cwd();\n\n\tlet file: PartialPackageJson | undefined;\n\n\ttry {\n\t\tfile = JSON.parse(readFileSync(join(cwd, 'package.json'), 'utf8')) as PartialPackageJson;\n\t} catch (error) {\n\t\tconst hasDenoConfigFile = existsSync(join(cwd, 'deno.json'));\n\t\tconst hasBunConfigFile = existsSync(join(cwd, 'bunfig.toml'));\n\t\treturn hasDenoConfigFile || hasBunConfigFile ? { root: cwd, type: 'ESM' } : { root: cwd, type: 'CommonJS' };\n\t}\n\n\tconst { main: packageMain, module: packageModule, type: packageType } = file;\n\n\tconst lowerCasedType = packageType?.toLowerCase() as PartialPackageJson['type'];\n\n\tif (lowerCasedType === 'commonjs') {\n\t\tif (packageMain) return { root: dirnameWithPath(cwd, packageMain), type: 'CommonJS' };\n\t\tif (packageModule) return { root: dirnameWithPath(cwd, packageModule), type: 'CommonJS' };\n\t\treturn { root: cwd, type: 'CommonJS' };\n\t}\n\n\tif (lowerCasedType === 'module') {\n\t\tif (packageMain) return { root: dirnameWithPath(cwd, packageMain), type: 'ESM' };\n\t\tif (packageModule) return { root: dirnameWithPath(cwd, packageModule), type: 'ESM' };\n\t\treturn { root: cwd, type: 'ESM' };\n\t}\n\n\tif (packageMain) return { root: dirnameWithPath(cwd, packageMain), type: 'CommonJS' };\n\tif (packageModule) return { root: dirnameWithPath(cwd, packageModule), type: 'ESM' };\n\n\treturn { root: cwd, type: 'CommonJS' };\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/internal/RootScan.ts"],"names":["dirname","join","readFileSync","existsSync"],"mappings":";;;;;;;AA4BA,IAAI,IAAA,GAAwB,IAAA;AAS5B,SAAS,eAAA,CAAgB,KAAa,YAAA,EAAsB;AAC3D,EAAA,OAAOA,YAAA,CAAQC,SAAA,CAAK,GAAA,EAAK,YAAY,CAAC,CAAA;AACvC;AAFS,MAAA,CAAA,eAAA,EAAA,iBAAA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EAAA,IAAI,mBAAmB,QAAA,EAAU;AAChC,IAAA,IAAI,WAAA,SAAoB,EAAE,IAAA,EAAM,gBAAgB,GAAA,EAAK,WAAW,CAAA,EAAG,IAAA,EAAM,KAAA,EAAM;AAC/E,IAAA,IAAI,aAAA,SAAsB,EAAE,IAAA,EAAM,gBAAgB,GAAA,EAAK,aAAa,CAAA,EAAG,IAAA,EAAM,KAAA,EAAM;AACnF,IAAA,OAAO,EAAE,IAAA,EAAM,GAAA,EAAK,IAAA,EAAM,KAAA,EAAM;AAAA,EACjC;AAEA,EAAA,IAAI,WAAA,SAAoB,EAAE,IAAA,EAAM,gBAAgB,GAAA,EAAK,WAAW,CAAA,EAAG,IAAA,EAAM,UAAA,EAAW;AACpF,EAAA,IAAI,aAAA,SAAsB,EAAE,IAAA,EAAM,gBAAgB,GAAA,EAAK,aAAa,CAAA,EAAG,IAAA,EAAM,KAAA,EAAM;AAEnF,EAAA,OAAO,EAAE,IAAA,EAAM,GAAA,EAAK,IAAA,EAAM,UAAA,EAAW;AACtC;AAjCgB,MAAA,CAAA,aAAA,EAAA,eAAA,CAAA","file":"RootScan.cjs","sourcesContent":["import { existsSync, readFileSync } from 'fs';\nimport { dirname, join } from 'path';\n\n/**\n * Represents a partial package.json object.\n */\ntype PartialPackageJson = Partial<{\n\tmain: string;\n\tmodule: string;\n\ttype: 'commonjs' | 'module';\n}>;\n\n/**\n * Represents the root data.\n */\nexport interface RootData {\n\t/**\n\t * The root directory.\n\t */\n\troot: string;\n\n\t/**\n\t * The type of the module system used.\n\t * It can be either 'ESM' or 'CommonJS'.\n\t */\n\ttype: 'ESM' | 'CommonJS';\n}\n\nlet data: RootData | null = null;\n\n/**\n * Returns the directory name of a given path by joining the current working directory (cwd) with the joinable path.\n * @private\n * @param cwd - The current working directory.\n * @param joinablePath - The path to be joined with the cwd.\n * @returns The directory name of the joined path.\n */\nfunction dirnameWithPath(cwd: string, joinablePath: string) {\n\treturn dirname(join(cwd, joinablePath));\n}\n\nexport function getRootData(): RootData {\n\treturn (data ??= parseRootData());\n}\n\n/**\n * Retrieves the root data of the project.\n *\n * This function reads the `package.json` file in the current working directory and determines the root path and type\n * of the project.\n *\n * - If the `package.json` file is not found or cannot be parsed, it assumes the project is using CommonJS and\n * the current working directory is used as the root\n *\n * - If the project `type` is specified as `\"commonjs\"` or `\"module\"` in the `package.json`, it uses the corresponding\n * `main` or `module` file path as the root.\n *\n * - If there is no `main` or `module` then it uses the current working directory as the root, while retaining the\n * matching `CommonJS` or `ESM` based on the `type`\n *\n * - If the main or module file path is not specified, it uses the current working directory as the root.\n *\n * The following table shows how different situations resolve to different root data\n *\n * | fields | resolved as |\n * |--------------------------|-------------|\n * | type=commonjs && main | CommonJS |\n * | type=commonjs && module | CommonJS |\n * | type=module && main | ESM |\n * | type=module && module | ESM |\n * | type=undefined && main | CommonJS |\n * | type=undefined && module | ESM |\n * | no package.json on cwd | CommonJS |\n *\n * @returns The root data object containing the root path and the type of the project.\n */\nexport function parseRootData(): RootData {\n\tconst cwd = process.cwd();\n\n\tlet file: PartialPackageJson | undefined;\n\n\ttry {\n\t\tfile = JSON.parse(readFileSync(join(cwd, 'package.json'), 'utf8')) as PartialPackageJson;\n\t} catch (error) {\n\t\tconst hasDenoConfigFile = existsSync(join(cwd, 'deno.json'));\n\t\tconst hasBunConfigFile = existsSync(join(cwd, 'bunfig.toml'));\n\t\treturn hasDenoConfigFile || hasBunConfigFile ? { root: cwd, type: 'ESM' } : { root: cwd, type: 'CommonJS' };\n\t}\n\n\tconst { main: packageMain, module: packageModule, type: packageType } = file;\n\n\tconst lowerCasedType = packageType?.toLowerCase() as PartialPackageJson['type'];\n\n\tif (lowerCasedType === 'commonjs') {\n\t\tif (packageMain) return { root: dirnameWithPath(cwd, packageMain), type: 'CommonJS' };\n\t\tif (packageModule) return { root: dirnameWithPath(cwd, packageModule), type: 'CommonJS' };\n\t\treturn { root: cwd, type: 'CommonJS' };\n\t}\n\n\tif (lowerCasedType === 'module') {\n\t\tif (packageMain) return { root: dirnameWithPath(cwd, packageMain), type: 'ESM' };\n\t\tif (packageModule) return { root: dirnameWithPath(cwd, packageModule), type: 'ESM' };\n\t\treturn { root: cwd, type: 'ESM' };\n\t}\n\n\tif (packageMain) return { root: dirnameWithPath(cwd, packageMain), type: 'CommonJS' };\n\tif (packageModule) return { root: dirnameWithPath(cwd, packageModule), type: 'ESM' };\n\n\treturn { root: cwd, type: 'CommonJS' };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/internal/constants.ts"],"names":[],"mappings":";;;AAAO,IAAM,WAAc,GAAA;AACd,IAAA,8BAAA,GAAiC,OAAO,2CAA2C","file":"constants.cjs","sourcesContent":["export const VirtualPath = '::virtual::';\nexport const ManuallyRegisteredPiecesSymbol = Symbol('@sapphire/pieces:ManuallyRegisteredPieces');\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/internal/constants.ts"],"names":[],"mappings":";;;AAAO,IAAM,WAAA,GAAc;AACpB,IAAM,8BAAA,GAAiC,OAAO,2CAA2C","file":"constants.cjs","sourcesContent":["export const VirtualPath = '::virtual::';\nexport const ManuallyRegisteredPiecesSymbol = Symbol('@sapphire/pieces:ManuallyRegisteredPieces');\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/shared/Container.ts"],"names":["StoreRegistry"],"mappings":";;;;;AA6EO,IAAM,SAAuB,GAAA;AAAA,EACnC,MAAA,EAAQ,IAAIA,+BAAc;AAC3B","file":"Container.cjs","sourcesContent":["import { StoreRegistry } from '../structures/StoreRegistry';\n\n/**\n * Represents the type of the properties injected into the container, which is available at {@link container}.\n *\n * Because Sapphire works as a standalone framework (independent of external libraries), there is a need to pass data\n * from one place to another, which would vary depending on the user and their use-cases.\n *\n * Furthermore, plugins may use this structure to add properties referencing to the plugin's objects so they can be\n * accessed by both the user and the plugin at any moment and at any place.\n *\n * Finally, both library developers and bot developers should augment the Container interface from this module using\n * [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation).\n */\nexport interface Container {\n\tstores: StoreRegistry;\n}\n\n/**\n * The injected variables that will be accessible to any place. To add an extra property, simply add a property with a\n * regular assignment, and it will be available in all places simultaneously.\n *\n * @example\n * ```typescript\n * // Add a reference for the version:\n * import { container } from '@sapphire/pieces';\n *\n * container.version = '1.0.0';\n *\n * // Can be placed anywhere in a TypeScript file, for JavaScript projects,\n * // you can create an `augments.d.ts` and place the code there.\n * declare module '@sapphire/pieces' {\n * interface Container {\n * version: string;\n * }\n * }\n *\n * // In any piece, core, plugin, or custom:\n * export class UserCommand extends Command {\n * public messageRun(message, args) {\n * // The injected version is available here:\n * const { version } = this.container;\n *\n * // ...\n * }\n * }\n * ```\n *\n * @example\n * ```typescript\n * // In a plugin's context, e.g. API:\n * class Api extends Plugin {\n * static [postInitialization]() {\n * const server = new Server(this);\n * container.server = server;\n *\n * // ...\n * }\n * }\n *\n * declare module '@sapphire/pieces' {\n * interface Container {\n * server: Server;\n * }\n * }\n *\n * // In any piece, even those that aren't routes nor middlewares:\n * export class UserRoute extends Route {\n * public [methods.POST](message, args) {\n * // The injected server is available here:\n * const { server } = this.container;\n *\n * // ...\n * }\n * }\n * ```\n */\nexport const container: Container = {\n\tstores: new StoreRegistry()\n};\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/shared/Container.ts"],"names":["StoreRegistry"],"mappings":";;;;;AA6EO,IAAM,SAAA,GAAuB;AAAA,EACnC,MAAA,EAAQ,IAAIA,+BAAA;AACb","file":"Container.cjs","sourcesContent":["import { StoreRegistry } from '../structures/StoreRegistry';\n\n/**\n * Represents the type of the properties injected into the container, which is available at {@link container}.\n *\n * Because Sapphire works as a standalone framework (independent of external libraries), there is a need to pass data\n * from one place to another, which would vary depending on the user and their use-cases.\n *\n * Furthermore, plugins may use this structure to add properties referencing to the plugin's objects so they can be\n * accessed by both the user and the plugin at any moment and at any place.\n *\n * Finally, both library developers and bot developers should augment the Container interface from this module using\n * [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation).\n */\nexport interface Container {\n\tstores: StoreRegistry;\n}\n\n/**\n * The injected variables that will be accessible to any place. To add an extra property, simply add a property with a\n * regular assignment, and it will be available in all places simultaneously.\n *\n * @example\n * ```typescript\n * // Add a reference for the version:\n * import { container } from '@sapphire/pieces';\n *\n * container.version = '1.0.0';\n *\n * // Can be placed anywhere in a TypeScript file, for JavaScript projects,\n * // you can create an `augments.d.ts` and place the code there.\n * declare module '@sapphire/pieces' {\n * interface Container {\n * version: string;\n * }\n * }\n *\n * // In any piece, core, plugin, or custom:\n * export class UserCommand extends Command {\n * public messageRun(message, args) {\n * // The injected version is available here:\n * const { version } = this.container;\n *\n * // ...\n * }\n * }\n * ```\n *\n * @example\n * ```typescript\n * // In a plugin's context, e.g. API:\n * class Api extends Plugin {\n * static [postInitialization]() {\n * const server = new Server(this);\n * container.server = server;\n *\n * // ...\n * }\n * }\n *\n * declare module '@sapphire/pieces' {\n * interface Container {\n * server: Server;\n * }\n * }\n *\n * // In any piece, even those that aren't routes nor middlewares:\n * export class UserRoute extends Route {\n * public [methods.POST](message, args) {\n * // The injected server is available here:\n * const { server } = this.container;\n *\n * // ...\n * }\n * }\n * ```\n */\nexport const container: Container = {\n\tstores: new StoreRegistry()\n};\n"]}
@@ -45,6 +45,7 @@ var _LoaderStrategy = class _LoaderStrategy {
45
45
  url$1.searchParams.append("d", Date.now().toString());
46
46
  url$1.searchParams.append("name", file.name);
47
47
  url$1.searchParams.append("extension", file.extension);
48
+ if (Reflect.has(globalThis, "Bun")) return internal_cjs.mjsImport(file.path + url$1.search);
48
49
  return internal_cjs.mjsImport(url$1);
49
50
  }
50
51
  const mod = __require(file.path);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/strategies/LoaderStrategy.ts"],"names":["getRootData","CanLoadTypeScriptFiles","path","extname","basename","url","pathToFileURL","mjsImport","isClass","classExtends","MissingExportsError","opendir","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAy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\nimport { opendir } from 'fs/promises';\nimport { basename, extname, join } from 'path';\nimport { pathToFileURL } from 'url';\nimport { MissingExportsError } from '../errors/MissingExportsError';\nimport { getRootData } from '../internal/RootScan';\nimport { mjsImport } from '../internal/internal';\nimport type { Piece } from '../structures/Piece';\nimport type { Store, StoreLogger } from '../structures/Store';\nimport type {\n\tAsyncPreloadResult,\n\tFilterResult,\n\tHydratedModuleData,\n\tILoaderResult,\n\tILoaderResultEntry,\n\tILoaderStrategy,\n\tModuleData\n} from './ILoaderStrategy';\nimport { classExtends, isClass } from './Shared';\nimport { CanLoadTypeScriptFiles } from './env';\n\n/**\n * A multi-purpose feature-complete loader strategy supporting multi-piece modules as well as supporting both ECMAScript\n * Modules and CommonJS with reloading support.\n */\nexport class LoaderStrategy<T extends Piece> implements ILoaderStrategy<T> {\n\tpublic clientUsesESModules = getRootData().type === 'ESM';\n\tpublic supportedExtensions = ['.js', '.cjs', '.mjs'];\n\tprivate readonly filterDtsFiles: boolean = false;\n\n\tpublic constructor() {\n\t\tif (CanLoadTypeScriptFiles) {\n\t\t\tthis.supportedExtensions.push('.ts', '.cts', '.mts');\n\t\t\tthis.filterDtsFiles = true;\n\t\t}\n\t}\n\n\tpublic filter(path: string): FilterResult {\n\t\t// Retrieve the file extension.\n\t\tconst extension = extname(path);\n\t\tif (!this.supportedExtensions.includes(extension)) return null;\n\n\t\tif (this.filterDtsFiles && path.endsWith('.d.ts')) return null;\n\n\t\t// Retrieve the name of the file, return null if empty.\n\t\tconst name = basename(path, extension);\n\t\tif (name === '' || name.startsWith('_')) return null;\n\n\t\t// Return the name and extension.\n\t\treturn { extension, path, name };\n\t}\n\n\tpublic async preload(file: ModuleData): AsyncPreloadResult<T> {\n\t\tconst mjs = ['.mjs', '.mts'].includes(file.extension) || (['.js', '.ts'].includes(file.extension) && this.clientUsesESModules);\n\t\tif (mjs) {\n\t\t\tconst url = pathToFileURL(file.path);\n\t\t\turl.searchParams.append('d', Date.now().toString());\n\t\t\turl.searchParams.append('name', file.name);\n\t\t\turl.searchParams.append('extension', file.extension);\n\t\t\treturn mjsImport(url);\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-var-requires\n\t\tconst mod = require(file.path);\n\t\tdelete require.cache[require.resolve(file.path)];\n\t\treturn mod;\n\t}\n\n\tpublic async *load(store: Store<T>, file: HydratedModuleData): ILoaderResult<T> {\n\t\tlet yielded = false;\n\t\tconst result = await this.preload(file);\n\n\t\t// Support `module.exports`:\n\t\tif (isClass(result) && classExtends(result, store.Constructor)) {\n\t\t\tyield result;\n\t\t\tyielded = true;\n\t\t}\n\n\t\t// Support any other export:\n\t\tfor (const value of Object.values(result)) {\n\t\t\tif (isClass(value) && classExtends(value, store.Constructor)) {\n\t\t\t\tyield value as ILoaderResultEntry<T>;\n\t\t\t\tyielded = true;\n\t\t\t}\n\t\t}\n\n\t\tif (!yielded) {\n\t\t\tthrow new MissingExportsError(file.path);\n\t\t}\n\t}\n\n\tpublic onLoad(store: Store<T>, piece: T): Awaitable<unknown>;\n\tpublic onLoad(): unknown {\n\t\treturn undefined;\n\t}\n\n\tpublic onLoadAll(store: Store<T>): Awaitable<unknown>;\n\tpublic onLoadAll(): unknown {\n\t\treturn undefined;\n\t}\n\n\tpublic onUnload(store: Store<T>, piece: T): Awaitable<unknown>;\n\tpublic onUnload(): unknown {\n\t\treturn undefined;\n\t}\n\n\tpublic onUnloadAll(store: Store<T>): Awaitable<unknown>;\n\tpublic onUnloadAll(): unknown {\n\t\treturn undefined;\n\t}\n\n\tpublic onError(error: Error, path: string): void {\n\t\tconsole.error(`Error when loading '${path}':`, error);\n\t}\n\n\tpublic async *walk(store: Store<T>, path: string, logger?: StoreLogger | null): AsyncIterableIterator<string> {\n\t\tlogger?.(`[STORE => ${store.name}] [WALK] Loading all pieces from '${path}'.`);\n\t\ttry {\n\t\t\tconst dir = await opendir(path);\n\t\t\tfor await (const item of dir) {\n\t\t\t\tif (item.isFile()) yield join(dir.path, item.name);\n\t\t\t\telse if (item.isDirectory()) yield* this.walk(store, join(dir.path, item.name), logger);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// Specifically ignore ENOENT, which is commonly raised by fs operations\n\t\t\t// to indicate that a component of the specified pathname does not exist.\n\t\t\t// No entity (file or directory) could be found by the given path.\n\t\t\tif ((error as ErrorWithCode).code !== 'ENOENT') this.onError(error as Error, path);\n\t\t}\n\t}\n}\n\ntype ErrorWithCode = Error & { code: string };\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/strategies/LoaderStrategy.ts"],"names":["getRootData","CanLoadTypeScriptFiles","path","extname","basename","url","pathToFileURL","mjsImport","isClass","classExtends","MissingExportsError","opendir","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAyBO,IAAM,eAAA,GAAN,MAAM,eAAA,CAA8D;AAAA,EAKnE,WAAA,GAAc;AAJrB,IAAA,aAAA,CAAA,IAAA,EAAO,qBAAA,EAAsBA,wBAAA,EAAY,CAAE,IAAA,KAAS,KAAA,CAAA;AACpD,IAAA,aAAA,CAAA,IAAA,EAAO,qBAAA,EAAsB,CAAC,KAAA,EAAO,MAAA,EAAQ,MAAM,CAAA,CAAA;AACnD,IAAA,aAAA,CAAA,IAAA,EAAiB,gBAAA,EAA0B,KAAA,CAAA;AAG1C,IAAA,IAAIC,8BAAA,EAAwB;AAC3B,MAAA,IAAA,CAAK,mBAAA,CAAoB,IAAA,CAAK,KAAA,EAAO,MAAA,EAAQ,MAAM,CAAA;AACnD,MAAA,IAAA,CAAK,cAAA,GAAiB,IAAA;AAAA,IACvB;AAAA,EACD;AAAA,EAEO,OAAOC,MAAA,EAA4B;AAEzC,IAAA,MAAM,SAAA,GAAYC,aAAQD,MAAI,CAAA;AAC9B,IAAA,IAAI,CAAC,IAAA,CAAK,mBAAA,CAAoB,QAAA,CAAS,SAAS,GAAG,OAAO,IAAA;AAE1D,IAAA,IAAI,KAAK,cAAA,IAAkBA,MAAA,CAAK,QAAA,CAAS,OAAO,GAAG,OAAO,IAAA;AAG1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,CAAI,CAAA;AAC7E,IAAA,IAAI;AACH,MAAA,MAAM,GAAA,GAAM,MAAMS,gBAAA,CAAQT,MAAI,CAAA;AAC9B,MAAA,WAAA,MAAiB,QAAQ,GAAA,EAAK;AAC7B,QAAA,IAAI,IAAA,CAAK,QAAO,EAAG,MAAMU,UAAK,GAAA,CAAI,IAAA,EAAM,KAAK,IAAI,CAAA;AAAA,aAAA,IACxC,IAAA,CAAK,WAAA,EAAY,EAAG,OAAO,IAAA,CAAK,IAAA,CAAK,KAAA,EAAOA,SAAA,CAAK,GAAA,CAAI,IAAA,EAAM,IAAA,CAAK,IAAI,GAAG,MAAM,CAAA;AAAA,MACvF;AAAA,IACD,SAAS,KAAA,EAAO;AAIf,MAAA,IAAK,MAAwB,IAAA,KAAS,QAAA,EAAU,IAAA,CAAK,OAAA,CAAQ,OAAgBV,MAAI,CAAA;AAAA,IAClF;AAAA,EACD;AACD,CAAA;AA7G2E,MAAA,CAAA,eAAA,EAAA,gBAAA,CAAA;AAApE,IAAM,cAAA,GAAN","file":"LoaderStrategy.cjs","sourcesContent":["import { type Awaitable } from '@sapphire/utilities';\nimport { opendir } from 'fs/promises';\nimport { basename, extname, join } from 'path';\nimport { pathToFileURL } from 'url';\nimport { MissingExportsError } from '../errors/MissingExportsError';\nimport { getRootData } from '../internal/RootScan';\nimport { mjsImport } from '../internal/internal';\nimport type { Piece } from '../structures/Piece';\nimport type { Store, StoreLogger } from '../structures/Store';\nimport type {\n\tAsyncPreloadResult,\n\tFilterResult,\n\tHydratedModuleData,\n\tILoaderResult,\n\tILoaderResultEntry,\n\tILoaderStrategy,\n\tModuleData\n} from './ILoaderStrategy';\nimport { classExtends, isClass } from './Shared';\nimport { CanLoadTypeScriptFiles } from './env';\n\n/**\n * A multi-purpose feature-complete loader strategy supporting multi-piece modules as well as supporting both ECMAScript\n * Modules and CommonJS with reloading support.\n */\nexport class LoaderStrategy<T extends Piece> implements ILoaderStrategy<T> {\n\tpublic clientUsesESModules = getRootData().type === 'ESM';\n\tpublic supportedExtensions = ['.js', '.cjs', '.mjs'];\n\tprivate readonly filterDtsFiles: boolean = false;\n\n\tpublic constructor() {\n\t\tif (CanLoadTypeScriptFiles) {\n\t\t\tthis.supportedExtensions.push('.ts', '.cts', '.mts');\n\t\t\tthis.filterDtsFiles = true;\n\t\t}\n\t}\n\n\tpublic filter(path: string): FilterResult {\n\t\t// Retrieve the file extension.\n\t\tconst extension = extname(path);\n\t\tif (!this.supportedExtensions.includes(extension)) return null;\n\n\t\tif (this.filterDtsFiles && path.endsWith('.d.ts')) return null;\n\n\t\t// Retrieve the name of the file, return null if empty.\n\t\tconst name = basename(path, extension);\n\t\tif (name === '' || name.startsWith('_')) return null;\n\n\t\t// Return the name and extension.\n\t\treturn { extension, path, name };\n\t}\n\n\tpublic async preload(file: ModuleData): AsyncPreloadResult<T> {\n\t\tconst mjs = ['.mjs', '.mts'].includes(file.extension) || (['.js', '.ts'].includes(file.extension) && this.clientUsesESModules);\n\t\tif (mjs) {\n\t\t\tconst url = pathToFileURL(file.path);\n\t\t\turl.searchParams.append('d', Date.now().toString());\n\t\t\turl.searchParams.append('name', file.name);\n\t\t\turl.searchParams.append('extension', file.extension);\n\n\t\t\t// Bun workaround: Import a file path with search params instead of an file URL to force re-evaluation due to caching bug.\n\t\t\tif (Reflect.has(globalThis, 'Bun')) return mjsImport(file.path + url.search);\n\n\t\t\treturn mjsImport(url);\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-var-requires\n\t\tconst mod = require(file.path);\n\t\tdelete require.cache[require.resolve(file.path)];\n\t\treturn mod;\n\t}\n\n\tpublic async *load(store: Store<T>, file: HydratedModuleData): ILoaderResult<T> {\n\t\tlet yielded = false;\n\t\tconst result = await this.preload(file);\n\n\t\t// Support `module.exports`:\n\t\tif (isClass(result) && classExtends(result, store.Constructor)) {\n\t\t\tyield result;\n\t\t\tyielded = true;\n\t\t}\n\n\t\t// Support any other export:\n\t\tfor (const value of Object.values(result)) {\n\t\t\tif (isClass(value) && classExtends(value, store.Constructor)) {\n\t\t\t\tyield value as ILoaderResultEntry<T>;\n\t\t\t\tyielded = true;\n\t\t\t}\n\t\t}\n\n\t\tif (!yielded) {\n\t\t\tthrow new MissingExportsError(file.path);\n\t\t}\n\t}\n\n\tpublic onLoad(store: Store<T>, piece: T): Awaitable<unknown>;\n\tpublic onLoad(): unknown {\n\t\treturn undefined;\n\t}\n\n\tpublic onLoadAll(store: Store<T>): Awaitable<unknown>;\n\tpublic onLoadAll(): unknown {\n\t\treturn undefined;\n\t}\n\n\tpublic onUnload(store: Store<T>, piece: T): Awaitable<unknown>;\n\tpublic onUnload(): unknown {\n\t\treturn undefined;\n\t}\n\n\tpublic onUnloadAll(store: Store<T>): Awaitable<unknown>;\n\tpublic onUnloadAll(): unknown {\n\t\treturn undefined;\n\t}\n\n\tpublic onError(error: Error, path: string): void {\n\t\tconsole.error(`Error when loading '${path}':`, error);\n\t}\n\n\tpublic async *walk(store: Store<T>, path: string, logger?: StoreLogger | null): AsyncIterableIterator<string> {\n\t\tlogger?.(`[STORE => ${store.name}] [WALK] Loading all pieces from '${path}'.`);\n\t\ttry {\n\t\t\tconst dir = await opendir(path);\n\t\t\tfor await (const item of dir) {\n\t\t\t\tif (item.isFile()) yield join(dir.path, item.name);\n\t\t\t\telse if (item.isDirectory()) yield* this.walk(store, join(dir.path, item.name), logger);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// Specifically ignore ENOENT, which is commonly raised by fs operations\n\t\t\t// to indicate that a component of the specified pathname does not exist.\n\t\t\t// No entity (file or directory) could be found by the given path.\n\t\t\tif ((error as ErrorWithCode).code !== 'ENOENT') this.onError(error as Error, path);\n\t\t}\n\t}\n}\n\ntype ErrorWithCode = Error & { code: string };\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/strategies/Shared.ts"],"names":[],"mappings":";;;;;;AAOO,SAAS,QAAQ,KAAuC,EAAA;AAC9D,EAAA,OAAO,OAAO,KAAA,KAAU,UAAc,IAAA,OAAO,MAAM,SAAc,KAAA,QAAA;AAClE;AAFgB,MAAA,CAAA,OAAA,EAAA,SAAA,CAAA;AAUT,SAAS,YAAA,CAAqC,OAAqB,IAAqB,EAAA;AAC9F,EAAA,IAAI,IAA4B,GAAA,KAAA;AAChC,EAAA,OAAO,SAAS,IAAM,EAAA;AACrB,IAAI,IAAA,IAAA,KAAS,MAAa,OAAA,IAAA;AAC1B,IAAO,IAAA,GAAA,MAAA,CAAO,eAAe,IAAI,CAAA;AAAA;AAGlC,EAAO,OAAA,KAAA;AACR;AARgB,MAAA,CAAA,YAAA,EAAA,cAAA,CAAA","file":"Shared.cjs","sourcesContent":["import type { AbstractCtor } from '@sapphire/utilities';\n\n/**\n * Determines whether or not a value is a class.\n * @param value The piece to be checked.\n * @private\n */\nexport function isClass(value: unknown): value is AbstractCtor {\n\treturn typeof value === 'function' && typeof value.prototype === 'object';\n}\n\n/**\n * Checks whether or not the value class extends the base class.\n * @param value The constructor to be checked against.\n * @param base The base constructor.\n * @private\n */\nexport function classExtends<T extends AbstractCtor>(value: AbstractCtor, base: T): value is T {\n\tlet ctor: AbstractCtor | null = value;\n\twhile (ctor !== null) {\n\t\tif (ctor === base) return true;\n\t\tctor = Object.getPrototypeOf(ctor);\n\t}\n\n\treturn false;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/strategies/Shared.ts"],"names":[],"mappings":";;;;;;AAOO,SAAS,QAAQ,KAAA,EAAuC;AAC9D,EAAA,OAAO,OAAO,KAAA,KAAU,UAAA,IAAc,OAAO,MAAM,SAAA,KAAc,QAAA;AAClE;AAFgB,MAAA,CAAA,OAAA,EAAA,SAAA,CAAA;AAUT,SAAS,YAAA,CAAqC,OAAqB,IAAA,EAAqB;AAC9F,EAAA,IAAI,IAAA,GAA4B,KAAA;AAChC,EAAA,OAAO,SAAS,IAAA,EAAM;AACrB,IAAA,IAAI,IAAA,KAAS,MAAM,OAAO,IAAA;AAC1B,IAAA,IAAA,GAAO,MAAA,CAAO,eAAe,IAAI,CAAA;AAAA,EAClC;AAEA,EAAA,OAAO,KAAA;AACR;AARgB,MAAA,CAAA,YAAA,EAAA,cAAA,CAAA","file":"Shared.cjs","sourcesContent":["import type { AbstractCtor } from '@sapphire/utilities';\n\n/**\n * Determines whether or not a value is a class.\n * @param value The piece to be checked.\n * @private\n */\nexport function isClass(value: unknown): value is AbstractCtor {\n\treturn typeof value === 'function' && typeof value.prototype === 'object';\n}\n\n/**\n * Checks whether or not the value class extends the base class.\n * @param value The constructor to be checked against.\n * @param base The base constructor.\n * @private\n */\nexport function classExtends<T extends AbstractCtor>(value: AbstractCtor, base: T): value is T {\n\tlet ctor: AbstractCtor | null = value;\n\twhile (ctor !== null) {\n\t\tif (ctor === base) return true;\n\t\tctor = Object.getPrototypeOf(ctor);\n\t}\n\n\treturn false;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/strategies/env.ts"],"names":["isNullish"],"mappings":";;;;;;AAEA,SAAS,iBAAiB,IAAc,EAAA;AACvC,EACC,OAAA,OAAA,CAAQ,SAAS,IAAK,CAAA,CAAC,QAAQ,GAAI,CAAA,QAAA,CAAS,IAAI,CAAC,CAAA;AAAA,EACjD,OAAA,CAAQ,KAAK,IAAK,CAAA,CAAC,QAAQ,GAAI,CAAA,QAAA,CAAS,IAAI,CAAC,CAAA;AAE/C;AALS,MAAA,CAAA,gBAAA,EAAA,kBAAA,CAAA;AAOT,SAAS,oBAAoB,IAAc,EAAA;AAC1C,EAAO,OAAA,kBAAA,IAAsB,OAAY,IAAA,OAAA,CAAQ,gBAA8B,CAAA,IAAA,CAAK,CAAC,MAAW,KAAA,MAAA,CAAO,QAAS,CAAA,IAAI,CAAC,CAAA;AACtH;AAFS,MAAA,CAAA,mBAAA,EAAA,qBAAA,CAAA;AAIT,SAAS,gBAAA,CAAiB,MAAc,KAAgB,EAAA;AACvD,EAAO,OAAA,KAAA,GAAQ,OAAQ,CAAA,GAAA,CAAI,IAAI,CAAA,KAAM,KAAQ,GAAA,CAACA,mBAAU,CAAA,OAAA,CAAQ,GAAI,CAAA,IAAI,CAAC,CAAA;AAC1E;AAFS,MAAA,CAAA,gBAAA,EAAA,kBAAA,CAAA;AAqBI,IAAA,sBAAA;AAAA;AAAA;AAAA,EAGZ,OAAA,CAAQ,GAAI,CAAA,UAAA,EAAY,MAAM,CAAA;AAAA;AAAA,EAG9B,QAAQ,GAAI,CAAA,UAAA,EAAY,KAAK,CAAA,IAC7B,SAAS,OAAQ,CAAA,QAAA;AAAA;AAAA;AAAA,EAIjB,MAAA,CAAO,GAAI,CAAA,2BAA2B,CAAK,IAAA,OAAA;AAAA,EAE3C,iBAAiB,aAAa,CAAA;AAAA,EAE9B,CAACA,mBAAA,CAAU,OAAQ,CAAA,GAAA,CAAI,WAAW,CAAA;AAAA;AAAA,EAGlC,iBAAiB,YAAY,CAAA;AAAA;AAAA,EAG7B,gBAAiB,CAAA,QAAA,EAAU,MAAM,CAAA,IACjC,iBAAiB,kBAAkB,CAAA;AAAA;AAAA,EAGnC,iBAAiB,gBAAgB,CAAA;AAAA;AAAA,EAGjC,oBAAoB,eAAe,CAAA;AAAA,EACnC,mBAAoB,CAAA,oBAAoB,CACxC,IAAA,gBAAA,CAAiB,eAAe,CAAA;AAAA;AAAA,EAGhC,oBAAoB,KAAK,CAAA;AAAA;AAAA,EAGzB,oBAAoB,kBAAkB,CAAA;AAAA;AAAA,EAGtC,oBAAoB,KAAK;AAAA","file":"env.cjs","sourcesContent":["import { isNullish } from '@sapphire/utilities';\n\nfunction checkProcessArgv(name: string) {\n\treturn (\n\t\tprocess.execArgv.some((arg) => arg.includes(name)) || //\n\t\tprocess.argv.some((arg) => arg.includes(name))\n\t);\n}\n\nfunction checkPreloadModules(name: string) {\n\treturn '_preload_modules' in process && (process._preload_modules as string[]).some((module) => module.includes(name));\n}\n\nfunction checkEnvVariable(name: string, value?: string) {\n\treturn value ? process.env[name] === value : !isNullish(process.env[name]);\n}\n\n/**\n * Whether or not the current environment can load TypeScript files. These\n * conditions are based on the most common tools and runtimes that support\n * loading TypeScript files directly.\n *\n * - {@linkplain https://www.npmjs.com/package/ts-node | `ts-node`}\n * - {@linkplain https://www.npmjs.com/package/ts-node-dev | `ts-node-dev`}\n * - {@linkplain https://www.npmjs.com/package/@babel/node | `@babel/node`}\n * - {@linkplain https://www.npmjs.com/package/vitest | `vitest`}\n * - {@linkplain https://www.npmjs.com/package/jest | `jest`}\n * - {@linkplain https://www.npmjs.com/package/@swc/cli | `swc`}\n * - {@linkplain https://www.npmjs.com/package/tsm | `tsm`}\n * - {@linkplain https://www.npmjs.com/package/esbuild | `esbuild`}\n * - {@linkplain https://www.npmjs.com/package/tsx | `tsx`}\n * - {@linkplain https://deno.com | `Deno`}\n * - {@linkplain https://bun.sh | `Bun`}\n */\nexport const CanLoadTypeScriptFiles: boolean =\n\t//\n\t// Deno\n\tReflect.has(globalThis, 'Deno') ||\n\t//\n\t// Bun\n\tReflect.has(globalThis, 'Bun') ||\n\t'bun' in process.versions ||\n\t//\n\t// ts-node\n\t// > --require ts-node/register\n\tSymbol.for('ts-node.register.instance') in process ||\n\t// > --loader ts-node/esm\n\tcheckProcessArgv('ts-node/esm') ||\n\t// > ts-node-dev\n\t!isNullish(process.env.TS_NODE_DEV) ||\n\t//\n\t// @babel/node\n\tcheckProcessArgv('babel-node') ||\n\t//\n\t// vitest\n\tcheckEnvVariable('VITEST', 'true') ||\n\tcheckEnvVariable('VITEST_WORKER_ID') ||\n\t//\n\t// jest\n\tcheckEnvVariable('JEST_WORKER_ID') ||\n\t//\n\t// swc\n\tcheckPreloadModules('@swc/register') || //\n\tcheckPreloadModules('@swc-node/register') ||\n\tcheckProcessArgv('.bin/swc-node') ||\n\t//\n\t// tsm\n\tcheckPreloadModules('tsm') ||\n\t//\n\t// esbuild\n\tcheckPreloadModules('esbuild-register') ||\n\t//\n\t// tsx\n\tcheckPreloadModules('tsx');\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/strategies/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AiB,QAAA,EAAU,MAAM,CAAA,IACjC,iBAAiB,kBAAkB,CAAA;AAAA;AAAA,EAGnC,iBAAiB,gBAAgB,CAAA;AAAA;AAAA,EAGjC,oBAAoB,eAAe,CAAA;AAAA,EACnC,mBAAA,CAAoB,oBAAoB,CAAA,IACxC,gBAAA,CAAiB,eAAe,CAAA;AAAA;AAAA,EAGhC,oBAAoB,KAAK,CAAA;AAAA;AAAA,EAGzB,oBAAoB,kBAAkB,CAAA;AAAA;AAAA,EAGtC,oBAAoB,KAAK;AAAA","file":"env.cjs","sourcesContent":["import { isNullish } from '@sapphire/utilities';\n\nfunction checkProcessArgv(name: string) {\n\treturn (\n\t\tprocess.execArgv.some((arg) => arg.includes(name)) || //\n\t\tprocess.argv.some((arg) => arg.includes(name))\n\t);\n}\n\nfunction checkPreloadModules(name: string) {\n\treturn '_preload_modules' in process && (process._preload_modules as string[]).some((module) => module.includes(name));\n}\n\nfunction checkEnvVariable(name: string, value?: string) {\n\treturn value ? process.env[name] === value : !isNullish(process.env[name]);\n}\n\n/**\n * Whether or not the current environment can load TypeScript files. These\n * conditions are based on the most common tools and runtimes that support\n * loading TypeScript files directly.\n *\n * - {@linkplain https://www.npmjs.com/package/ts-node | `ts-node`}\n * - {@linkplain https://www.npmjs.com/package/ts-node-dev | `ts-node-dev`}\n * - {@linkplain https://www.npmjs.com/package/@babel/node | `@babel/node`}\n * - {@linkplain https://www.npmjs.com/package/vitest | `vitest`}\n * - {@linkplain https://www.npmjs.com/package/jest | `jest`}\n * - {@linkplain https://www.npmjs.com/package/@swc/cli | `swc`}\n * - {@linkplain https://www.npmjs.com/package/tsm | `tsm`}\n * - {@linkplain https://www.npmjs.com/package/esbuild | `esbuild`}\n * - {@linkplain https://www.npmjs.com/package/tsx | `tsx`}\n * - {@linkplain https://deno.com | `Deno`}\n * - {@linkplain https://bun.sh | `Bun`}\n */\nexport const CanLoadTypeScriptFiles: boolean =\n\t//\n\t// Deno\n\tReflect.has(globalThis, 'Deno') ||\n\t//\n\t// Bun\n\tReflect.has(globalThis, 'Bun') ||\n\t'bun' in process.versions ||\n\t//\n\t// ts-node\n\t// > --require ts-node/register\n\tSymbol.for('ts-node.register.instance') in process ||\n\t// > --loader ts-node/esm\n\tcheckProcessArgv('ts-node/esm') ||\n\t// > ts-node-dev\n\t!isNullish(process.env.TS_NODE_DEV) ||\n\t//\n\t// @babel/node\n\tcheckProcessArgv('babel-node') ||\n\t//\n\t// vitest\n\tcheckEnvVariable('VITEST', 'true') ||\n\tcheckEnvVariable('VITEST_WORKER_ID') ||\n\t//\n\t// jest\n\tcheckEnvVariable('JEST_WORKER_ID') ||\n\t//\n\t// swc\n\tcheckPreloadModules('@swc/register') || //\n\tcheckPreloadModules('@swc-node/register') ||\n\tcheckProcessArgv('.bin/swc-node') ||\n\t//\n\t// tsm\n\tcheckPreloadModules('tsm') ||\n\t//\n\t// esbuild\n\tcheckPreloadModules('esbuild-register') ||\n\t//\n\t// tsx\n\tcheckPreloadModules('tsx');\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/AliasPiece.ts"],"names":["Piece","AliasPiece"],"mappings":";;;;;;;;AAcO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAiIA,eAG5I,CAAA;AAAA,EAMM,WAAY,CAAA,OAAA,EAA8C,OAA6B,GAAA,EAAI,EAAA;AACjG,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAHvB;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA;AAIN,IAAK,IAAA,CAAA,OAAA,GAAU,OAAQ,CAAA,OAAA,IAAW,EAAC;AAAA;AACpC;AAAA;AAAA;AAAA,EAKgB,MAA0B,GAAA;AACzC,IAAO,OAAA;AAAA,MACN,GAAG,MAAM,MAAO,EAAA;AAAA,MAChB,OAAA,EAAS,IAAK,CAAA,OAAA,CAAQ,KAAM;AAAA,KAC7B;AAAA;AAEF,CAAA;AApBE,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAHWC,kBAAN,GAAA;AAAA,CAiCA,CAAUA,WAAV,KAAA;AACC,EAAM,CAAA,EAAE,QAAAA,EAAAA,WAAAA,CAAA,QAAa,EAAA,GAAAD,eAAA;AAAA,CADZ,EAAAC,kBAAA,KAAAA,kBAAA,GAAA,EAAA,CAAA,CAAA","file":"AliasPiece.cjs","sourcesContent":["import { Piece } from './Piece';\nimport type { StoreRegistryKey } from './StoreRegistry';\n\nexport interface AliasPieceOptions extends Piece.Options {\n\t/**\n\t * The aliases for the piece.\n\t * @default []\n\t */\n\treadonly aliases?: readonly string[];\n}\n\n/**\n * The piece to be stored in {@link AliasStore} instances.\n */\nexport class AliasPiece<Options extends AliasPieceOptions = AliasPieceOptions, StoreName extends StoreRegistryKey = StoreRegistryKey> extends Piece<\n\tOptions,\n\tStoreName\n> {\n\t/**\n\t * The aliases for the piece.\n\t */\n\tpublic aliases: readonly string[];\n\n\tpublic constructor(context: AliasPiece.LoaderContext<StoreName>, options: AliasPieceOptions = {}) {\n\t\tsuper(context, options);\n\t\tthis.aliases = options.aliases ?? [];\n\t}\n\n\t/**\n\t * Defines the `JSON.stringify` behavior of this alias piece.\n\t */\n\tpublic override toJSON(): AliasPiece.JSON {\n\t\treturn {\n\t\t\t...super.toJSON(),\n\t\t\taliases: this.aliases.slice()\n\t\t};\n\t}\n}\n\n/**\n * The return type of {@link AliasPiece.toJSON}.\n */\nexport interface AliasPieceJSON extends Piece.JSON {\n\taliases: string[];\n\toptions: AliasPieceOptions;\n}\n\nexport namespace AliasPiece {\n\texport const { Location } = Piece;\n\texport type Options = AliasPieceOptions;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context<StoreName extends StoreRegistryKey = StoreRegistryKey> = Piece.LoaderContext<StoreName>;\n\texport type LoaderContext<StoreName extends StoreRegistryKey = StoreRegistryKey> = Piece.LoaderContext<StoreName>;\n\texport type JSON = AliasPieceJSON;\n\texport type LocationJSON = Piece.LocationJSON;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/AliasPiece.ts"],"names":["Piece","AliasPiece"],"mappings":";;;;;;;;AAcO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAiIA,eAAA,CAG5I;AAAA,EAMM,WAAA,CAAY,OAAA,EAA8C,OAAA,GAA6B,EAAC,EAAG;AACjG,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAHvB;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,SAAA,CAAA;AAIN,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA,CAAQ,OAAA,IAAW,EAAC;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA,EAKgB,MAAA,GAA0B;AACzC,IAAA,OAAO;AAAA,MACN,GAAG,MAAM,MAAA,EAAO;AAAA,MAChB,OAAA,EAAS,IAAA,CAAK,OAAA,CAAQ,KAAA;AAAM,KAC7B;AAAA,EACD;AACD,CAAA;AApBE,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAHWC,kBAAA,GAAN;AAAA,CAiCA,CAAUA,WAAAA,KAAV;AACC,EAAA,CAAM,EAAE,QAAA,EAAAA,WAAAA,CAAA,QAAA,EAAA,GAAaD,eAAA;AAAA,CAAA,EADZC,kBAAA,KAAAA,kBAAA,GAAA,EAAA,CAAA,CAAA","file":"AliasPiece.cjs","sourcesContent":["import { Piece } from './Piece';\nimport type { StoreRegistryKey } from './StoreRegistry';\n\nexport interface AliasPieceOptions extends Piece.Options {\n\t/**\n\t * The aliases for the piece.\n\t * @default []\n\t */\n\treadonly aliases?: readonly string[];\n}\n\n/**\n * The piece to be stored in {@link AliasStore} instances.\n */\nexport class AliasPiece<Options extends AliasPieceOptions = AliasPieceOptions, StoreName extends StoreRegistryKey = StoreRegistryKey> extends Piece<\n\tOptions,\n\tStoreName\n> {\n\t/**\n\t * The aliases for the piece.\n\t */\n\tpublic aliases: readonly string[];\n\n\tpublic constructor(context: AliasPiece.LoaderContext<StoreName>, options: AliasPieceOptions = {}) {\n\t\tsuper(context, options);\n\t\tthis.aliases = options.aliases ?? [];\n\t}\n\n\t/**\n\t * Defines the `JSON.stringify` behavior of this alias piece.\n\t */\n\tpublic override toJSON(): AliasPiece.JSON {\n\t\treturn {\n\t\t\t...super.toJSON(),\n\t\t\taliases: this.aliases.slice()\n\t\t};\n\t}\n}\n\n/**\n * The return type of {@link AliasPiece.toJSON}.\n */\nexport interface AliasPieceJSON extends Piece.JSON {\n\taliases: string[];\n\toptions: AliasPieceOptions;\n}\n\nexport namespace AliasPiece {\n\texport const { Location } = Piece;\n\texport type Options = AliasPieceOptions;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context<StoreName extends StoreRegistryKey = StoreRegistryKey> = Piece.LoaderContext<StoreName>;\n\texport type LoaderContext<StoreName extends StoreRegistryKey = StoreRegistryKey> = Piece.LoaderContext<StoreName>;\n\texport type JSON = AliasPieceJSON;\n\texport type LocationJSON = Piece.LocationJSON;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/AliasStore.ts"],"names":["Store","Collection"],"mappings":";;;;;;;;;AAQO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAgGA,eAAoB,CAAA;AAAA,EAA1H,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,SAAA,EAAU,IAAIC,qBAAsB,EAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMpC,IAAI,GAA4B,EAAA;AAC/C,IAAA,OAAO,MAAM,GAAI,CAAA,GAAG,KAAK,IAAK,CAAA,OAAA,CAAQ,IAAI,GAAG,CAAA;AAAA;AAC9C;AAAA;AAAA;AAAA;AAAA,EAMgB,IAAI,GAAsB,EAAA;AACzC,IAAA,OAAO,MAAM,GAAI,CAAA,GAAG,KAAK,IAAK,CAAA,OAAA,CAAQ,IAAI,GAAG,CAAA;AAAA;AAC9C;AAAA;AAAA;AAAA;AAAA;AAAA,EAOgB,OAAO,IAA8B,EAAA;AACpD,IAAM,MAAA,KAAA,GAAQ,IAAK,CAAA,OAAA,CAAQ,IAAI,CAAA;AAG/B,IAAW,KAAA,MAAA,KAAA,IAAS,MAAM,OAAS,EAAA;AAElC,MAAA,MAAM,UAAa,GAAA,IAAA,CAAK,OAAQ,CAAA,GAAA,CAAI,KAAK,CAAA;AACzC,MAAA,IAAI,UAAe,KAAA,KAAA,EAAY,IAAA,CAAA,OAAA,CAAQ,OAAO,KAAK,CAAA;AAAA;AAGpD,IAAO,OAAA,KAAA,CAAM,OAAO,KAAK,CAAA;AAAA;AAC1B;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAsB,OAAO,KAAU,EAAA;AACtC,IAAW,KAAA,MAAA,GAAA,IAAO,MAAM,OAAS,EAAA;AAChC,MAAK,IAAA,CAAA,OAAA,CAAQ,GAAI,CAAA,GAAA,EAAK,KAAK,CAAA;AAAA;AAG5B,IAAO,OAAA,KAAA,CAAM,OAAO,KAAK,CAAA;AAAA;AAE3B,CAAA;AApDiI,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAA1H,IAAM,UAAN,GAAA","file":"AliasStore.cjs","sourcesContent":["import { Collection } from '@discordjs/collection';\nimport type { AliasPiece } from './AliasPiece';\nimport { Store } from './Store';\nimport type { StoreRegistryKey } from './StoreRegistry';\n\n/**\n * The store class which contains {@link AliasPiece}s.\n */\nexport class AliasStore<T extends AliasPiece, StoreName extends StoreRegistryKey = StoreRegistryKey> extends Store<T, StoreName> {\n\t/**\n\t * The aliases referencing to pieces.\n\t */\n\tpublic readonly aliases = new Collection<string, T>();\n\n\t/**\n\t * Looks up the name by the store, falling back to an alias lookup.\n\t * @param key The key to look for.\n\t */\n\tpublic override get(key: string): T | undefined {\n\t\treturn super.get(key) ?? this.aliases.get(key);\n\t}\n\n\t/**\n\t * Checks whether a key is in the store, or is an alias\n\t * @param key The key to check\n\t */\n\tpublic override has(key: string): boolean {\n\t\treturn super.has(key) || this.aliases.has(key);\n\t}\n\n\t/**\n\t * Unloads a piece given its instance or its name, and removes all the aliases.\n\t * @param name The name of the file to load.\n\t * @return Returns the piece that was unloaded.\n\t */\n\tpublic override unload(name: string | T): Promise<T> {\n\t\tconst piece = this.resolve(name);\n\n\t\t// Unload all aliases for the given piece:\n\t\tfor (const alias of piece.aliases) {\n\t\t\t// We don't want to delete aliases that were overriden by another piece:\n\t\t\tconst aliasPiece = this.aliases.get(alias);\n\t\t\tif (aliasPiece === piece) this.aliases.delete(alias);\n\t\t}\n\n\t\treturn super.unload(piece);\n\t}\n\n\t/**\n\t * Inserts a piece into the store, and adds all the aliases.\n\t * @param piece The piece to be inserted into the store.\n\t * @return The inserted piece.\n\t */\n\tpublic override async insert(piece: T) {\n\t\tfor (const key of piece.aliases) {\n\t\t\tthis.aliases.set(key, piece);\n\t\t}\n\n\t\treturn super.insert(piece);\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/AliasStore.ts"],"names":["Store","Collection"],"mappings":";;;;;;;;;AAQO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAgGA,eAAA,CAAoB;AAAA,EAA1H,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,SAAA,EAAU,IAAIC,qBAAA,EAAsB,CAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMpC,IAAI,GAAA,EAA4B;AAC/C,IAAA,OAAO,MAAM,GAAA,CAAI,GAAG,KAAK,IAAA,CAAK,OAAA,CAAQ,IAAI,GAAG,CAAA;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMgB,IAAI,GAAA,EAAsB;AACzC,IAAA,OAAO,MAAM,GAAA,CAAI,GAAG,KAAK,IAAA,CAAK,OAAA,CAAQ,IAAI,GAAG,CAAA;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOgB,OAAO,IAAA,EAA8B;AACpD,IAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,OAAA,CAAQ,IAAI,CAAA;AAG/B,IAAA,KAAA,MAAW,KAAA,IAAS,MAAM,OAAA,EAAS;AAElC,MAAA,MAAM,UAAA,GAAa,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,KAAK,CAAA;AACzC,MAAA,IAAI,UAAA,KAAe,KAAA,EAAO,IAAA,CAAK,OAAA,CAAQ,OAAO,KAAK,CAAA;AAAA,IACpD;AAEA,IAAA,OAAO,KAAA,CAAM,OAAO,KAAK,CAAA;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAsB,OAAO,KAAA,EAAU;AACtC,IAAA,KAAA,MAAW,GAAA,IAAO,MAAM,OAAA,EAAS;AAChC,MAAA,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,GAAA,EAAK,KAAK,CAAA;AAAA,IAC5B;AAEA,IAAA,OAAO,KAAA,CAAM,OAAO,KAAK,CAAA;AAAA,EAC1B;AACD,CAAA;AApDiI,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAA1H,IAAM,UAAA,GAAN","file":"AliasStore.cjs","sourcesContent":["import { Collection } from '@discordjs/collection';\nimport type { AliasPiece } from './AliasPiece';\nimport { Store } from './Store';\nimport type { StoreRegistryKey } from './StoreRegistry';\n\n/**\n * The store class which contains {@link AliasPiece}s.\n */\nexport class AliasStore<T extends AliasPiece, StoreName extends StoreRegistryKey = StoreRegistryKey> extends Store<T, StoreName> {\n\t/**\n\t * The aliases referencing to pieces.\n\t */\n\tpublic readonly aliases = new Collection<string, T>();\n\n\t/**\n\t * Looks up the name by the store, falling back to an alias lookup.\n\t * @param key The key to look for.\n\t */\n\tpublic override get(key: string): T | undefined {\n\t\treturn super.get(key) ?? this.aliases.get(key);\n\t}\n\n\t/**\n\t * Checks whether a key is in the store, or is an alias\n\t * @param key The key to check\n\t */\n\tpublic override has(key: string): boolean {\n\t\treturn super.has(key) || this.aliases.has(key);\n\t}\n\n\t/**\n\t * Unloads a piece given its instance or its name, and removes all the aliases.\n\t * @param name The name of the file to load.\n\t * @return Returns the piece that was unloaded.\n\t */\n\tpublic override unload(name: string | T): Promise<T> {\n\t\tconst piece = this.resolve(name);\n\n\t\t// Unload all aliases for the given piece:\n\t\tfor (const alias of piece.aliases) {\n\t\t\t// We don't want to delete aliases that were overriden by another piece:\n\t\t\tconst aliasPiece = this.aliases.get(alias);\n\t\t\tif (aliasPiece === piece) this.aliases.delete(alias);\n\t\t}\n\n\t\treturn super.unload(piece);\n\t}\n\n\t/**\n\t * Inserts a piece into the store, and adds all the aliases.\n\t * @param piece The piece to be inserted into the store.\n\t * @return The inserted piece.\n\t */\n\tpublic override async insert(piece: T) {\n\t\tfor (const key of piece.aliases) {\n\t\t\tthis.aliases.set(key, piece);\n\t\t}\n\n\t\treturn super.insert(piece);\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/Piece.ts"],"names":["PieceLocation","container","Piece"],"mappings":";;;;;;;;;AAuDO,IAAM,MAAA,GAAN,MAAM,MAA0G,CAAA;AAAA,EA0B/G,WAAY,CAAA,OAAA,EAAyC,OAAwB,GAAA,EAAI,EAAA;AAtBxF;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA;AAKP;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA;AAGf,IAAA,IAAA,CAAK,QAAQ,OAAQ,CAAA,KAAA;AACrB,IAAA,IAAA,C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AA;AAAA,CADR,EAAAE,aAAA,KAAAA,aAAA,GAAA,EAAA,CAAA,CAAA","file":"Piece.cjs","sourcesContent":["import type { Awaitable } from '@sapphire/utilities';\nimport { container, type Container } from '../shared/Container';\nimport { PieceLocation, type PieceLocationJSON } from './PieceLocation';\nimport type { Store } from './Store';\nimport type { StoreOf, StoreRegistryKey } from './StoreRegistry';\n\n/**\n * The context for the piece, contains extra information from the store,\n * the piece's path, and the store that loaded it.\n */\nexport interface LoaderPieceContext<StoreName extends StoreRegistryKey = StoreRegistryKey> {\n\t/**\n\t * The root directory the piece was loaded from.\n\t */\n\treadonly root: string;\n\n\t/**\n\t * The path the module was loaded from, relative to {@link LoaderPieceContext.root}.\n\t */\n\treadonly path: string;\n\n\t/**\n\t * The module's name extracted from the path.\n\t */\n\treadonly name: string;\n\n\t/**\n\t * The store that loaded the piece.\n\t */\n\treadonly store: StoreOf<StoreName>;\n}\n\n/** @deprecated Use {@linkcode LoaderPieceContext} instead. */\nexport interface PieceContext<StoreName extends StoreRegistryKey = StoreRegistryKey> extends LoaderPieceContext<StoreName> {}\n\n/**\n * The options for the {@link Piece}.\n */\nexport interface PieceOptions {\n\t/**\n\t * The name for the piece.\n\t * @default ''\n\t */\n\treadonly name?: string;\n\n\t/**\n\t * Whether or not the piece should be enabled. If set to false, the piece will be unloaded.\n\t * @default true\n\t */\n\treadonly enabled?: boolean;\n}\n\n/**\n * The piece to be stored in {@link Store} instances.\n */\nexport class Piece<Options extends PieceOptions = PieceOptions, StoreName extends StoreRegistryKey = StoreRegistryKey> {\n\t/**\n\t * The store that contains the piece.\n\t */\n\tpublic readonly store: StoreOf<StoreName>;\n\n\t/**\n\t * The location metadata for the piece's file.\n\t */\n\tpublic readonly location: PieceLocation;\n\n\t/**\n\t * The name of the piece.\n\t */\n\tpublic readonly name: string;\n\n\t/**\n\t * Whether or not the piece is enabled.\n\t */\n\tpublic enabled: boolean;\n\n\t/**\n\t * The raw options passed to this {@link Piece}\n\t */\n\tpublic readonly options: Options;\n\n\tpublic constructor(context: Piece.LoaderContext<StoreName>, options: PieceOptions = {}) {\n\t\tthis.store = context.store;\n\t\tthis.location = new PieceLocation(context.path, context.root);\n\t\tthis.name = options.name ?? context.name;\n\t\tthis.enabled = options.enabled ?? true;\n\t\tthis.options = options as Options;\n\t}\n\n\t/**\n\t * A reference to the {@link Container} object for ease of use.\n\t * @see container\n\t */\n\tpublic get container(): Container {\n\t\treturn container;\n\t}\n\n\t/**\n\t * Per-piece listener that is called when the piece is loaded into the store.\n\t * Useful to set-up asynchronous initialization tasks.\n\t */\n\tpublic onLoad(): Awaitable<unknown> {\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Per-piece listener that is called when the piece is unloaded from the store.\n\t * Useful to set-up clean-up tasks.\n\t */\n\tpublic onUnload(): Awaitable<unknown> {\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Unloads and disables the piece.\n\t */\n\tpublic async unload() {\n\t\tawait this.store.unload(this.name);\n\t\tthis.enabled = false;\n\t}\n\n\t/**\n\t * Reloads the piece by loading the same path in the store.\n\t */\n\tpublic async reload() {\n\t\tawait this.store.load(this.location.root, this.location.relative);\n\t}\n\n\t/**\n\t * Defines the `JSON.stringify` behavior of this piece.\n\t */\n\tpublic toJSON(): PieceJSON {\n\t\treturn {\n\t\t\tlocation: this.location.toJSON(),\n\t\t\tname: this.name,\n\t\t\tenabled: this.enabled,\n\t\t\toptions: this.options\n\t\t};\n\t}\n}\n\n/**\n * The return type of {@link Piece.toJSON}.\n */\nexport interface PieceJSON {\n\tlocation: PieceLocationJSON;\n\tname: string;\n\tenabled: boolean;\n\toptions: PieceOptions;\n}\n\nexport namespace Piece {\n\texport const Location = PieceLocation;\n\texport type Options = PieceOptions;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context<StoreName extends StoreRegistryKey = StoreRegistryKey> = LoaderPieceContext<StoreName>;\n\texport type LoaderContext<StoreName extends StoreRegistryKey = StoreRegistryKey> = LoaderPieceContext<StoreName>;\n\texport type JSON = PieceJSON;\n\texport type LocationJSON = PieceLocationJSON;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/Piece.ts"],"names":["PieceLocation","container","Piece"],"mappings":";;;;;;;;;AAuDO,IAAM,MAAA,GAAN,MAAM,MAAA,CAA0G;AAAA,EA0B/G,WAAA,CAAY,OAAA,EAAyC,OAAA,GAAwB,EAAC,EAAG;AAtBxF;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,OAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,UAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,MAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,SAAA,CAAA;AAKP;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,SAAA,CAAA;AAGf,IAAA,IAAA,CAAK,QAAQ,OAAA,CAAQ,KAAA;AACrB,IAAA,IAAA,CAAK,WAAW,IAAIA,+BAAA,CAAc,OAAA,CAAQ,IAAA,EAAM,QAAQ,IAAI,CAAA;AAC5D,IAAA,IAAA,CAAK,IAAA,GAAO,OAAA,CAAQ,IAAA,IAAQ,OAAA,CAAQ,IAAA;AACpC,IAAA,IAAA,CAAK,OAAA,GAAU,QAAQ,OAAA,IAAW,IAAA;AAClC,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAW,SAAA,GAAuB;AACjC,IAAA,OAAOC,uBAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,MAAA,GAA6B;AACnC,IAAA,OAAO,MAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,QAAA,GAA+B;AACrC,IAAA,OAAO,MAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAKA,MAAa,MAAA,GAAS;AACrB,IAAA,MAAM,IAAA,CAAK,KAAA,CAAM,MAAA,CAAO,IAAA,CAAK,IAAI,CAAA;AACjC,IAAA,IAAA,CAAK,OAAA,GAAU,KAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAa,MAAA,GAAS;AACrB,IAAA,MAAM,IAAA,CAAK,MAAM,IAAA,CAAK,IAAA,CAAK,SAAS,IAAA,EAAM,IAAA,CAAK,SAAS,QAAQ,CAAA;AAAA,EACjE;AAAA;AAAA;AAAA;AAAA,EAKO,MAAA,GAAoB;AAC1B,IAAA,OAAO;AAAA,MACN,QAAA,EAAU,IAAA,CAAK,QAAA,CAAS,MAAA,EAAO;AAAA,MAC/B,MAAM,IAAA,CAAK,IAAA;AAAA,MACX,SAAS,IAAA,CAAK,OAAA;AAAA,MACd,SAAS,IAAA,CAAK;AAAA,KACf;AAAA,EACD;AACD,CAAA;AApFuH,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA;AAA1GC,aAAA,GAAN;AAAA,CAgGA,CAAUA,MAAAA,KAAV;AACC,EAAMA,OAAA,QAAA,GAAWF,+BAAA;AAAA,CAAA,EADRE,aAAA,KAAAA,aAAA,GAAA,EAAA,CAAA,CAAA","file":"Piece.cjs","sourcesContent":["import type { Awaitable } from '@sapphire/utilities';\nimport { container, type Container } from '../shared/Container';\nimport { PieceLocation, type PieceLocationJSON } from './PieceLocation';\nimport type { Store } from './Store';\nimport type { StoreOf, StoreRegistryKey } from './StoreRegistry';\n\n/**\n * The context for the piece, contains extra information from the store,\n * the piece's path, and the store that loaded it.\n */\nexport interface LoaderPieceContext<StoreName extends StoreRegistryKey = StoreRegistryKey> {\n\t/**\n\t * The root directory the piece was loaded from.\n\t */\n\treadonly root: string;\n\n\t/**\n\t * The path the module was loaded from, relative to {@link LoaderPieceContext.root}.\n\t */\n\treadonly path: string;\n\n\t/**\n\t * The module's name extracted from the path.\n\t */\n\treadonly name: string;\n\n\t/**\n\t * The store that loaded the piece.\n\t */\n\treadonly store: StoreOf<StoreName>;\n}\n\n/** @deprecated Use {@linkcode LoaderPieceContext} instead. */\nexport interface PieceContext<StoreName extends StoreRegistryKey = StoreRegistryKey> extends LoaderPieceContext<StoreName> {}\n\n/**\n * The options for the {@link Piece}.\n */\nexport interface PieceOptions {\n\t/**\n\t * The name for the piece.\n\t * @default ''\n\t */\n\treadonly name?: string;\n\n\t/**\n\t * Whether or not the piece should be enabled. If set to false, the piece will be unloaded.\n\t * @default true\n\t */\n\treadonly enabled?: boolean;\n}\n\n/**\n * The piece to be stored in {@link Store} instances.\n */\nexport class Piece<Options extends PieceOptions = PieceOptions, StoreName extends StoreRegistryKey = StoreRegistryKey> {\n\t/**\n\t * The store that contains the piece.\n\t */\n\tpublic readonly store: StoreOf<StoreName>;\n\n\t/**\n\t * The location metadata for the piece's file.\n\t */\n\tpublic readonly location: PieceLocation;\n\n\t/**\n\t * The name of the piece.\n\t */\n\tpublic readonly name: string;\n\n\t/**\n\t * Whether or not the piece is enabled.\n\t */\n\tpublic enabled: boolean;\n\n\t/**\n\t * The raw options passed to this {@link Piece}\n\t */\n\tpublic readonly options: Options;\n\n\tpublic constructor(context: Piece.LoaderContext<StoreName>, options: PieceOptions = {}) {\n\t\tthis.store = context.store;\n\t\tthis.location = new PieceLocation(context.path, context.root);\n\t\tthis.name = options.name ?? context.name;\n\t\tthis.enabled = options.enabled ?? true;\n\t\tthis.options = options as Options;\n\t}\n\n\t/**\n\t * A reference to the {@link Container} object for ease of use.\n\t * @see container\n\t */\n\tpublic get container(): Container {\n\t\treturn container;\n\t}\n\n\t/**\n\t * Per-piece listener that is called when the piece is loaded into the store.\n\t * Useful to set-up asynchronous initialization tasks.\n\t */\n\tpublic onLoad(): Awaitable<unknown> {\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Per-piece listener that is called when the piece is unloaded from the store.\n\t * Useful to set-up clean-up tasks.\n\t */\n\tpublic onUnload(): Awaitable<unknown> {\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Unloads and disables the piece.\n\t */\n\tpublic async unload() {\n\t\tawait this.store.unload(this.name);\n\t\tthis.enabled = false;\n\t}\n\n\t/**\n\t * Reloads the piece by loading the same path in the store.\n\t */\n\tpublic async reload() {\n\t\tawait this.store.load(this.location.root, this.location.relative);\n\t}\n\n\t/**\n\t * Defines the `JSON.stringify` behavior of this piece.\n\t */\n\tpublic toJSON(): PieceJSON {\n\t\treturn {\n\t\t\tlocation: this.location.toJSON(),\n\t\t\tname: this.name,\n\t\t\tenabled: this.enabled,\n\t\t\toptions: this.options\n\t\t};\n\t}\n}\n\n/**\n * The return type of {@link Piece.toJSON}.\n */\nexport interface PieceJSON {\n\tlocation: PieceLocationJSON;\n\tname: string;\n\tenabled: boolean;\n\toptions: PieceOptions;\n}\n\nexport namespace Piece {\n\texport const Location = PieceLocation;\n\texport type Options = PieceOptions;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context<StoreName extends StoreRegistryKey = StoreRegistryKey> = LoaderPieceContext<StoreName>;\n\texport type LoaderContext<StoreName extends StoreRegistryKey = StoreRegistryKey> = LoaderPieceContext<StoreName>;\n\texport type JSON = PieceJSON;\n\texport type LocationJSON = PieceLocationJSON;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/PieceLocation.ts"],"names":["VirtualPath","relative","sep","basename"],"mappings":";;;;;;;;;AAMO,IAAM,cAAA,GAAN,MAAM,cAAc,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAenB,WAAA,CAAY,MAAc,IAAc,EAAA;AAX/C;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAOf,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;AACZ,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;AAAA;AACb;AAAA;AAAA;AAAA,EAKA,IAAW,OAAU,GAAA;AACpB,IAAA,OAAO,KAAK,IAAS,KAAAA,yBAAA;AAAA;AACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,IAAW,QAAmB,GAAA;AAC7B,IAAA,OAAO,KAAK,OAAU,GAAAA,yBAAA,GAAcC,cAAS,IAAK,CAAA,IAAA,EAAM,KAAK,IAAI,CAAA;AAAA;AAClE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,IAAW,WAAwB,GAAA;AAClC,IAAO,OAAA,IAAA,CAAK,OAAU,GAAA,EAAK,GAAA,IAAA,CAAK,QAAS,CAAA,KAAA,CAAMC,QAAG,CAAA,CAAE,KAAM,CAAA,CAAA,EAAG,EAAE,CAAA;AAAA;AAChE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,IAAW,IAAe,GAAA;AACzB,IAAA,OAAO,IAAK,CAAA,OAAA,GAAUF,yBAAc,GAAAG,aAAA,CAAS,KAAK,IAAI,CAAA;AAAA;AACvD;AAAA;AAAA;AAAA,EAKO,MAA4B,GAAA;AAClC,IAAO,OAAA;AAAA,MACN,aAAa,IAAK,CAAA,WAAA;AAAA,MAClB,MAAM,IAAK,CAAA,IAAA;AAAA,MACX,MAAM,IAAK,CAAA,IAAA;AAAA,MACX,UAAU,IAAK,CAAA,QAAA;AAAA,MACf,MAAM,IAAK,CAAA;AAAA,KACZ;AAAA;AAEF,CAAA;AA1F2B,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA;AAApB,IAAM,aAAN,GAAA","file":"PieceLocation.cjs","sourcesContent":["import { basename, relative, sep } from 'path';\nimport { VirtualPath } from '../internal/constants';\n\n/**\n * The metadata class used for {@link Piece}s.\n */\nexport class PieceLocation {\n\t/**\n\t * The full path to the file.\n\t */\n\tpublic readonly full: string;\n\n\t/**\n\t * The root directory the file was found from.\n\t */\n\tpublic readonly root: string;\n\n\t/**\n\t * @param full The full path to the file.\n\t * @param root The root directory the file was found from.\n\t */\n\tpublic constructor(full: string, root: string) {\n\t\tthis.full = full;\n\t\tthis.root = root;\n\t}\n\n\t/**\n\t * Whether the file is virtual or not.\n\t */\n\tpublic get virtual() {\n\t\treturn this.full === VirtualPath;\n\t}\n\n\t/**\n\t * The relative path between {@link PieceLocation.root} and {@link PieceLocation.full}.\n\t * @example\n\t * ```typescript\n\t * const location = new PieceLocation(\n\t * \t'/usr/src/app/commands',\n\t * \t'/usr/src/app/commands/general/ping.js'\n\t * );\n\t *\n\t * console.log(location.relative);\n\t * // → 'general/ping.js'\n\t * ```\n\t */\n\tpublic get relative(): string {\n\t\treturn this.virtual ? VirtualPath : relative(this.root, this.full);\n\t}\n\n\t/**\n\t * The names of the directories that separate {@link PieceLocation.root} and {@link PieceLocation.full}.\n\t * @example\n\t * ```typescript\n\t * const location = new PieceLocation(\n\t * \t'/usr/src/app/commands',\n\t * \t'/usr/src/app/commands/games/multiplayer/connect-four.js'\n\t * );\n\t *\n\t * console.log(location.directories);\n\t * // → ['games', 'multiplayer']\n\t * ```\n\t */\n\tpublic get directories(): string[] {\n\t\treturn this.virtual ? [] : this.relative.split(sep).slice(0, -1);\n\t}\n\n\t/**\n\t * The name and extension of the file that was loaded, extracted from {@link PieceLocation.full}.\n\t * @example\n\t * ```typescript\n\t * const location = new PieceLocation(\n\t * \t'/usr/src/app/commands',\n\t * \t'/usr/src/app/commands/games/multiplayer/connect-four.js'\n\t * );\n\t *\n\t * console.log(location.name);\n\t * // → 'connect-four.js'\n\t * ```\n\t */\n\tpublic get name(): string {\n\t\treturn this.virtual ? VirtualPath : basename(this.full);\n\t}\n\n\t/**\n\t * Defines the `JSON.stringify` behavior of this structure.\n\t */\n\tpublic toJSON(): PieceLocationJSON {\n\t\treturn {\n\t\t\tdirectories: this.directories,\n\t\t\tfull: this.full,\n\t\t\tname: this.name,\n\t\t\trelative: this.relative,\n\t\t\troot: this.root\n\t\t};\n\t}\n}\n\n/**\n * The return type of {@link PieceLocation.toJSON}.\n */\nexport interface PieceLocationJSON {\n\tdirectories: string[];\n\tfull: string;\n\tname: string;\n\trelative: string;\n\troot: string;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/PieceLocation.ts"],"names":["VirtualPath","relative","sep","basename"],"mappings":";;;;;;;;;AAMO,IAAM,cAAA,GAAN,MAAM,cAAA,CAAc;AAAA;AAAA;AAAA;AAAA;AAAA,EAenB,WAAA,CAAY,MAAc,IAAA,EAAc;AAX/C;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,MAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,MAAA,CAAA;AAOf,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACb;AAAA;AAAA;AAAA;AAAA,EAKA,IAAW,OAAA,GAAU;AACpB,IAAA,OAAO,KAAK,IAAA,KAASA,yBAAA;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,IAAW,QAAA,GAAmB;AAC7B,IAAA,OAAO,KAAK,OAAA,GAAUA,yBAAA,GAAcC,cAAS,IAAA,CAAK,IAAA,EAAM,KAAK,IAAI,CAAA;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,IAAW,WAAA,GAAwB;AAClC,IAAA,OAAO,IAAA,CAAK,OAAA,GAAU,EAAC,GAAI,IAAA,CAAK,QAAA,CAAS,KAAA,CAAMC,QAAG,CAAA,CAAE,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,IAAW,IAAA,GAAe;AACzB,IAAA,OAAO,IAAA,CAAK,OAAA,GAAUF,yBAAA,GAAcG,aAAA,CAAS,KAAK,IAAI,CAAA;AAAA,EACvD;AAAA;AAAA;AAAA;AAAA,EAKO,MAAA,GAA4B;AAClC,IAAA,OAAO;AAAA,MACN,aAAa,IAAA,CAAK,WAAA;AAAA,MAClB,MAAM,IAAA,CAAK,IAAA;AAAA,MACX,MAAM,IAAA,CAAK,IAAA;AAAA,MACX,UAAU,IAAA,CAAK,QAAA;AAAA,MACf,MAAM,IAAA,CAAK;AAAA,KACZ;AAAA,EACD;AACD,CAAA;AA1F2B,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA;AAApB,IAAM,aAAA,GAAN","file":"PieceLocation.cjs","sourcesContent":["import { basename, relative, sep } from 'path';\nimport { VirtualPath } from '../internal/constants';\n\n/**\n * The metadata class used for {@link Piece}s.\n */\nexport class PieceLocation {\n\t/**\n\t * The full path to the file.\n\t */\n\tpublic readonly full: string;\n\n\t/**\n\t * The root directory the file was found from.\n\t */\n\tpublic readonly root: string;\n\n\t/**\n\t * @param full The full path to the file.\n\t * @param root The root directory the file was found from.\n\t */\n\tpublic constructor(full: string, root: string) {\n\t\tthis.full = full;\n\t\tthis.root = root;\n\t}\n\n\t/**\n\t * Whether the file is virtual or not.\n\t */\n\tpublic get virtual() {\n\t\treturn this.full === VirtualPath;\n\t}\n\n\t/**\n\t * The relative path between {@link PieceLocation.root} and {@link PieceLocation.full}.\n\t * @example\n\t * ```typescript\n\t * const location = new PieceLocation(\n\t * \t'/usr/src/app/commands',\n\t * \t'/usr/src/app/commands/general/ping.js'\n\t * );\n\t *\n\t * console.log(location.relative);\n\t * // → 'general/ping.js'\n\t * ```\n\t */\n\tpublic get relative(): string {\n\t\treturn this.virtual ? VirtualPath : relative(this.root, this.full);\n\t}\n\n\t/**\n\t * The names of the directories that separate {@link PieceLocation.root} and {@link PieceLocation.full}.\n\t * @example\n\t * ```typescript\n\t * const location = new PieceLocation(\n\t * \t'/usr/src/app/commands',\n\t * \t'/usr/src/app/commands/games/multiplayer/connect-four.js'\n\t * );\n\t *\n\t * console.log(location.directories);\n\t * // → ['games', 'multiplayer']\n\t * ```\n\t */\n\tpublic get directories(): string[] {\n\t\treturn this.virtual ? [] : this.relative.split(sep).slice(0, -1);\n\t}\n\n\t/**\n\t * The name and extension of the file that was loaded, extracted from {@link PieceLocation.full}.\n\t * @example\n\t * ```typescript\n\t * const location = new PieceLocation(\n\t * \t'/usr/src/app/commands',\n\t * \t'/usr/src/app/commands/games/multiplayer/connect-four.js'\n\t * );\n\t *\n\t * console.log(location.name);\n\t * // → 'connect-four.js'\n\t * ```\n\t */\n\tpublic get name(): string {\n\t\treturn this.virtual ? VirtualPath : basename(this.full);\n\t}\n\n\t/**\n\t * Defines the `JSON.stringify` behavior of this structure.\n\t */\n\tpublic toJSON(): PieceLocationJSON {\n\t\treturn {\n\t\t\tdirectories: this.directories,\n\t\t\tfull: this.full,\n\t\t\tname: this.name,\n\t\t\trelative: this.relative,\n\t\t\troot: this.root\n\t\t};\n\t}\n}\n\n/**\n * The return type of {@link PieceLocation.toJSON}.\n */\nexport interface PieceLocationJSON {\n\tdirectories: string[];\n\tfull: string;\n\tname: string;\n\trelative: string;\n\troot: string;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/Store.ts"],"names":["LoaderStrategy","Collection","container","resolvePath","isClass","classExtends","LoaderError","LoaderErrorType","ManuallyRegisteredPiecesSymbol","VirtualPath","path","join","Store","StoreRegistry"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiDA,IAAM,eAAA,GAAkB,IAAIA,iCAAe,EAAA;AAjD3C,IAAA,EAAA,EAAA,EAAA,EAAA,cAAA,EAAA,KAAA;AAsDO,IAAM,MAAN,GAAA,MAAM,MAAsF,UAAA,EAAA,GAAAC,qBAA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CAAA,wBAAA,EAA2B,KAAK,CAA+C,6CAAA,CAAA,CAAA;AACpH,QAAA;AAAA;AAED,MAAI,IAAA;AACH,QAAA,MAAM,YAAe,GAAA,IAAA,CAAK,iBAAkB,CAAA,IAAA,EAAM,IAAI,CAAA;AACtD,QAAA,WAAA,MAAiB,QAAQ,IAAK,CAAA,QAAA,CAAS,IAAK,CAAA,IAAA,EAAM,YAAY,CAAG,EAAA;AAChE,UAAM,MAAA,IAAA,CAAK,SAAU,CAAA,IAAA,EAAM,YAAY,CAAA;AAAA;AACxC,eACQ,KAAO,EAAA;AACf,QAAA,IAAA,CAAK,QAAS,CAAA,OAAA,CAAQ,KAAgB,EAAA,IAAA,CAAK,IAAI,CAAA;AAAA;AAChD;AACD;AAaF,CAAA;AA1TC,cAAA,GAAA,IAAA,OAAA,EAAA;AAKA,KAAA,GAAA,IAAA,OAAA,EAAA;AAnBwH,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAkUxH,aAAA,CAlUY,QAkUE,iBAAwC,EAAA,eAAA,CAAA;AAAA;AAAA;AAAA;AAKtD,aAAA,CAvUY,QAuUE,QAA6B,EAAA,IAAA,CAAA;AAvU/BK,aAAN,GAAA;AAAA,CAmVA,CAAUA,MAAV,KAAA;AACC,EAAMA,OAAA,QAAW,GAAAC,+BAAA;AAAA,CADR,EAAAD,aAAA,KAAAA,aAAA,GAAA,EAAA,CAAA,CAAA","file":"Store.cjs","sourcesContent":["import { Collection } from '@discordjs/collection';\nimport { classExtends, isClass, type AbstractConstructor, type Constructor } from '@sapphire/utilities';\nimport { join } from 'path';\nimport { LoaderError, LoaderErrorType } from '../errors/LoaderError';\nimport { resolvePath, type Path } from '../internal/Path';\nimport { ManuallyRegisteredPiecesSymbol, VirtualPath } from '../internal/constants';\nimport { container, type Container } from '../shared/Container';\nimport type { HydratedModuleData, ILoaderResultEntry, ILoaderStrategy, ModuleData } from '../strategies/ILoaderStrategy';\nimport { LoaderStrategy } from '../strategies/LoaderStrategy';\nimport type { Piece } from './Piece';\nimport { StoreRegistry, type StoreRegistryEntries, type StoreRegistryKey } from './StoreRegistry';\n\n/**\n * The options for the store, this features both hooks (changes the behaviour) and handlers (similar to event listeners).\n */\nexport interface StoreOptions<T extends Piece, StoreName extends StoreRegistryKey = StoreRegistryKey> {\n\t/**\n\t * The name for this store.\n\t */\n\treadonly name: StoreName;\n\n\t/**\n\t * The paths to load pieces from, should be absolute.\n\t * @default []\n\t */\n\treadonly paths?: readonly string[];\n\n\t/**\n\t * The strategy to be used for the loader.\n\t * @default Store.defaultStrategy\n\t */\n\treadonly strategy?: ILoaderStrategy<T>;\n}\n\n/**\n * An interface representing a logger function.\n */\nexport interface StoreLogger {\n\t/**\n\t * @param value The string to print. All strings will be formatted with the format `[STORE => ${name}] [${type}] ${content}`,\n\t * where the content may have identifiers (values or names of methods) surrounded by `'`. For example:\n\t *\n\t * - `[STORE => commands] [LOAD] Skipped piece '/home/user/bot/src/commands/foo.js' as 'LoaderStrategy#filter' returned 'null'.`\n\t * - `[STORE => commands] [INSERT] Unloaded new piece 'foo' due to 'enabled' being 'false'.`\n\t * - `[STORE => commands] [UNLOAD] Unloaded piece 'foo'.`\n\t */\n\t(value: string): void;\n}\n\nconst defaultStrategy = new LoaderStrategy();\n\n/**\n * The store class which contains {@link Piece}s.\n */\nexport class Store<T extends Piece, StoreName extends StoreRegistryKey = StoreRegistryKey> extends Collection<string, T> {\n\tpublic readonly Constructor: AbstractConstructor<T>;\n\tpublic readonly name: StoreName;\n\tpublic readonly paths: Set<string>;\n\tpublic readonly strategy: ILoaderStrategy<T>;\n\n\t/**\n\t * The queue of manually registered pieces to load.\n\t */\n\tprivate readonly [ManuallyRegisteredPiecesSymbol] = new Map<string, StoreManuallyRegisteredPiece<StoreName>>();\n\n\t/**\n\t * Whether or not the store has called `loadAll` at least once.\n\t */\n\t#calledLoadAll = false;\n\n\t/**\n\t * The walk function for the store.\n\t */\n\t#walk: LoaderStrategy<T>['walk'];\n\n\t/**\n\t * @param constructor The piece constructor this store loads.\n\t * @param options The options for the store.\n\t */\n\tpublic constructor(constructor: AbstractConstructor<T>, options: StoreOptions<T, StoreName>) {\n\t\tsuper();\n\t\tthis.Constructor = constructor;\n\t\tthis.name = options.name as StoreRegistryKey;\n\t\tthis.paths = new Set(options.paths ?? []);\n\t\tthis.strategy = options.strategy ?? Store.defaultStrategy;\n\n\t\tthis.#walk =\n\t\t\ttypeof this.strategy.walk === 'function' //\n\t\t\t\t? this.strategy.walk.bind(this.strategy)\n\t\t\t\t: defaultStrategy.walk.bind(defaultStrategy);\n\t}\n\n\t/**\n\t * A reference to the {@link Container} object for ease of use.\n\t * @see container\n\t */\n\tpublic get container(): Container {\n\t\treturn container;\n\t}\n\n\t/**\n\t * Registers a directory into the store.\n\t * @param path The path to be added.\n\t * @example\n\t * ```typescript\n\t * store\n\t * .registerPath(resolve('commands'))\n\t * .registerPath(resolve('third-party', 'commands'));\n\t * ```\n\t */\n\tpublic registerPath(path: Path): this {\n\t\tconst root = resolvePath(path);\n\n\t\tthis.paths.add(root);\n\t\tStore.logger?.(`[STORE => ${this.name}] [REGISTER] Registered path '${root}'.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds a piece into the store's list of manually registered pieces. If {@linkcode Store.loadAll()} was called, the\n\t * piece will be loaded immediately, otherwise it will be queued until {@linkcode Store.loadAll()} is called.\n\t *\n\t * All manually registered pieces will be kept even after they are loaded to ensure they can be loaded again if\n\t * {@linkcode Store.loadAll()} is called again.\n\t *\n\t * @remarks\n\t *\n\t * - Pieces loaded this way will have their {@linkcode Piece.Context.root root} and\n\t * {@linkcode Piece.Context.path path} set to {@linkcode VirtualPath}, and as such, cannot be reloaded.\n\t * - This method is useful in environments where file system access is limited or unavailable, such as when using\n\t * {@link https://en.wikipedia.org/wiki/Serverless_computing Serverless Computing}.\n\t * - This method will always throw a {@link TypeError} if `entry.piece` is not a class.\n\t * - This method will always throw a {@linkcode LoaderError} if the piece does not extend the\n\t * {@linkcode Store#Constructor store's piece constructor}.\n\t * - This operation is atomic, if any of the above errors are thrown, the piece will not be loaded.\n\t *\n\t * @seealso {@linkcode StoreRegistry.loadPiece()}\n\t * @since 3.8.0\n\t * @param entry The entry to load.\n\t * @example\n\t * ```typescript\n\t * import { container } from '@sapphire/pieces';\n\t *\n\t * class PingCommand extends Command {\n\t * // ...\n\t * }\n\t *\n\t * container.stores.get('commands').loadPiece({\n\t * name: 'ping',\n\t * piece: PingCommand\n\t * });\n\t * ```\n\t */\n\tpublic async loadPiece(entry: StoreManuallyRegisteredPiece<StoreName>) {\n\t\tif (!isClass(entry.piece)) {\n\t\t\tthrow new TypeError(`The piece ${entry.name} is not a Class. ${String(entry.piece)}`);\n\t\t}\n\n\t\t// If the piece does not extend the store's Piece class, throw an error:\n\t\tif (!classExtends(entry.piece, this.Constructor as Constructor<T>)) {\n\t\t\tthrow new LoaderError(LoaderErrorType.IncorrectType, `The piece ${entry.name} does not extend ${this.name}`);\n\t\t}\n\n\t\tthis[ManuallyRegisteredPiecesSymbol].set(entry.name, entry);\n\t\tif (this.#calledLoadAll) {\n\t\t\tconst piece = this.construct(entry.piece as unknown as Constructor<T>, {\n\t\t\t\tname: entry.name,\n\t\t\t\troot: VirtualPath,\n\t\t\t\tpath: VirtualPath,\n\t\t\t\textension: VirtualPath\n\t\t\t});\n\t\t\tawait this.insert(piece);\n\t\t}\n\t}\n\n\t/**\n\t * Loads one or more pieces from a path.\n\t * @param root The root directory the file is from.\n\t * @param path The path of the file to load, relative to the `root`.\n\t * @return All the loaded pieces.\n\t */\n\tpublic async load(root: string, path: string): Promise<T[]> {\n\t\tif (root === VirtualPath) {\n\t\t\tthrow new LoaderError(LoaderErrorType.VirtualPiece, `Cannot load a virtual file.`);\n\t\t}\n\n\t\tconst full = join(root, path);\n\t\tconst data = this.strategy.filter(full);\n\t\tif (data === null) {\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD] Skipped piece '${full}' as 'LoaderStrategy#filter' returned 'null'.`);\n\t\t\treturn [];\n\t\t}\n\n\t\tconst promises: Promise<T>[] = [];\n\t\tconst finishedData = this.hydrateModuleData(root, data);\n\t\tfor await (const Ctor of this.strategy.load(this, finishedData)) {\n\t\t\tpromises.push(this.insert(this.construct(Ctor, finishedData)));\n\t\t}\n\n\t\treturn Promise.all(promises);\n\t}\n\n\t/**\n\t * Unloads a piece given its instance or its name.\n\t * @param name The name of the file to load.\n\t * @return Returns the piece that was unloaded.\n\t */\n\tpublic async unload(name: string | T): Promise<T> {\n\t\tconst piece = this.resolve(name);\n\n\t\t// Unload piece:\n\t\tthis.strategy.onUnload(this, piece);\n\t\tawait piece.onUnload();\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD] Unloaded piece '${piece.name}'.`);\n\n\t\t// Remove from cache and return it:\n\t\tthis.delete(piece.name);\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD] Removed piece '${piece.name}'.`);\n\t\treturn piece;\n\t}\n\n\t/**\n\t * Unloads all pieces from the store.\n\t */\n\tpublic async unloadAll(): Promise<T[]> {\n\t\tconst promises: Promise<T>[] = [];\n\t\tfor (const piece of this.values()) {\n\t\t\tpromises.push(this.unload(piece));\n\t\t}\n\n\t\tconst results = await Promise.all(promises);\n\n\t\tthis.strategy.onUnloadAll(this);\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD-ALL] Removed all pieces.`);\n\t\treturn results;\n\t}\n\n\t/**\n\t * Loads all pieces from all directories specified by {@link paths}.\n\t */\n\tpublic async loadAll(): Promise<void> {\n\t\tthis.#calledLoadAll = true;\n\n\t\tconst pieces: T[] = [];\n\t\tfor (const entry of this[ManuallyRegisteredPiecesSymbol].values()) {\n\t\t\tconst piece = this.construct(entry.piece as unknown as Constructor<T>, {\n\t\t\t\tname: entry.name,\n\t\t\t\troot: VirtualPath,\n\t\t\t\tpath: VirtualPath,\n\t\t\t\textension: VirtualPath\n\t\t\t});\n\t\t\tpieces.push(piece);\n\t\t}\n\n\t\tfor (const path of this.paths) {\n\t\t\tfor await (const piece of this.loadPath(path)) {\n\t\t\t\tpieces.push(piece);\n\t\t\t}\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Found '${pieces.length}' pieces.`);\n\n\t\t// Clear the store before inserting the new pieces:\n\t\tawait this.unloadAll();\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Cleared all pieces.`);\n\n\t\t// Load each piece:\n\t\tfor (const piece of pieces) {\n\t\t\tawait this.insert(piece);\n\t\t}\n\n\t\t// Call onLoadAll:\n\t\tthis.strategy.onLoadAll(this);\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Successfully loaded '${this.size}' pieces.`);\n\t}\n\n\t/**\n\t * Resolves a piece by its name or its instance.\n\t * @param name The name of the piece or the instance itself.\n\t * @return The resolved piece.\n\t */\n\tpublic resolve(name: string | T): T {\n\t\tif (typeof name === 'string') {\n\t\t\tconst result = this.get(name);\n\t\t\tif (typeof result === 'undefined') throw new LoaderError(LoaderErrorType.UnloadedPiece, `The piece '${name}' does not exist.`);\n\t\t\treturn result;\n\t\t}\n\n\t\tif (name instanceof this.Constructor) return name;\n\t\tthrow new LoaderError(LoaderErrorType.IncorrectType, `The piece '${name.name}' is not an instance of '${this.Constructor.name}'.`);\n\t}\n\n\t/**\n\t * Inserts a piece into the store.\n\t * @param piece The piece to be inserted into the store.\n\t * @return The inserted piece.\n\t */\n\tpublic async insert(piece: T): Promise<T> {\n\t\tif (!piece.enabled) return piece;\n\n\t\t// Load piece:\n\t\tthis.strategy.onLoad(this, piece);\n\t\tawait piece.onLoad();\n\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Loaded new piece '${piece.name}'.`);\n\n\t\t// If the onLoad disabled the piece, call unload and return it:\n\t\tif (!piece.enabled) {\n\t\t\t// Unload piece:\n\t\t\tthis.strategy.onUnload(this, piece);\n\t\t\tawait piece.onUnload();\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Unloaded new piece '${piece.name}' due to 'enabled' being 'false'.`);\n\n\t\t\treturn piece;\n\t\t}\n\n\t\t// Unload existing piece, if any:\n\t\tconst previous = super.get(piece.name);\n\t\tif (previous) {\n\t\t\tawait this.unload(previous);\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Unloaded existing piece '${piece.name}' due to conflicting 'name'.`);\n\t\t}\n\n\t\t// Set the new piece and return it:\n\t\tthis.set(piece.name, piece);\n\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Inserted new piece '${piece.name}'.`);\n\t\treturn piece;\n\t}\n\n\t/**\n\t * Constructs a {@link Piece} instance.\n\t * @param Ctor The {@link Piece}'s constructor used to build the instance.\n\t * @param data The module's information\n\t * @return An instance of the constructed piece.\n\t */\n\tpublic construct(Ctor: ILoaderResultEntry<T>, data: HydratedModuleData): T {\n\t\treturn new Ctor({ store: this, root: data.root, path: data.path, name: data.name }, { name: data.name, enabled: true });\n\t}\n\n\t/**\n\t * Adds the final module data properties.\n\t * @param root The root directory to add.\n\t * @param data The module data returned from {@link ILoaderStrategy.filter}.\n\t * @returns The finished module data.\n\t */\n\tprivate hydrateModuleData(root: string, data: ModuleData): HydratedModuleData {\n\t\treturn { root, ...data };\n\t}\n\n\t/**\n\t * Loads a directory into the store.\n\t * @param root The directory to load the pieces from.\n\t * @return An async iterator that yields the pieces to be loaded into the store.\n\t */\n\tprivate async *loadPath(root: string): AsyncIterableIterator<T> {\n\t\tStore.logger?.(`[STORE => ${this.name}] [WALK] Loading all pieces from '${root}'.`);\n\t\tfor await (const child of this.#walk(this, root, Store.logger)) {\n\t\t\tconst data = this.strategy.filter(child);\n\t\t\tif (data === null) {\n\t\t\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD] Skipped piece '${child}' as 'LoaderStrategy#filter' returned 'null'.`);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst finishedData = this.hydrateModuleData(root, data);\n\t\t\t\tfor await (const Ctor of this.strategy.load(this, finishedData)) {\n\t\t\t\t\tyield this.construct(Ctor, finishedData);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthis.strategy.onError(error as Error, data.path);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The default strategy, defaults to {@link LoaderStrategy}, which is constructed on demand when a store is constructed,\n\t * when none was set beforehand.\n\t */\n\tpublic static defaultStrategy: ILoaderStrategy<any> = defaultStrategy;\n\n\t/**\n\t * The default logger, defaults to `null`.\n\t */\n\tpublic static logger: StoreLogger | null = null;\n}\n\n/**\n * An entry for a manually registered piece using {@linkcode Store.loadPiece()}.\n * @since 3.8.0\n */\nexport interface StoreManuallyRegisteredPiece<StoreName extends StoreRegistryKey> {\n\tname: string;\n\tpiece: StoreRegistryEntries[StoreName] extends Store<infer Piece> ? Constructor<Piece> : never;\n}\n\nexport namespace Store {\n\texport const Registry = StoreRegistry;\n\texport type Options<T extends Piece> = StoreOptions<T>;\n\texport type Logger = StoreLogger;\n\texport type RegistryEntries = StoreRegistryEntries;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/Store.ts"],"names":["LoaderStrategy","Collection","container","resolvePath","isClass","classExtends","LoaderError","LoaderErrorType","ManuallyRegisteredPiecesSymbol","VirtualPath","path","join","Store","StoreRegistry"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiDA,IAAM,eAAA,GAAkB,IAAIA,iCAAA,EAAe;AAjD3C,IAAA,EAAA,EAAA,EAAA,EAAA,cAAA,EAAA,KAAA;AAsDO,IAAM,MAAA,GAAN,MAAM,MAAA,UAAsF,EAAA,GAAAC,qBAAA,EAShF,mDATgF,EAAA,EAAsB;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBjH,WAAA,CAAY,aAAqC,OAAA,EAAqC;AAC5F,IAAA,KAAA,EAAM;AAzBP,IAAA,aAAA,CAAA,IAAA,EAAgB,aAAA,CAAA;AAChB,IAAA,aAAA,CAAA,IAAA,EAAgB,MAAA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A,MAAA,IAAI;AACH,QAAA,MAAM,YAAA,GAAe,IAAA,CAAK,iBAAA,CAAkB,IAAA,EAAM,IAAI,CAAA;AACtD,QAAA,WAAA,MAAiB,QAAQ,IAAA,CAAK,QAAA,CAAS,IAAA,CAAK,IAAA,EAAM,YAAY,CAAA,EAAG;AAChE,UAAA,MAAM,IAAA,CAAK,SAAA,CAAU,IAAA,EAAM,YAAY,CAAA;AAAA,QACxC;AAAA,MACD,SAAS,KAAA,EAAO;AACf,QAAA,IAAA,CAAK,QAAA,CAAS,OAAA,CAAQ,KAAA,EAAgB,IAAA,CAAK,IAAI,CAAA;AAAA,MAChD;AAAA,IACD;AAAA,EACD;AAYD,CAAA;AA1TC,cAAA,GAAA,IAAA,OAAA,EAAA;AAKA,KAAA,GAAA,IAAA,OAAA,EAAA;AAnBwH,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAkUxH,aAAA,CAlUY,QAkUE,iBAAA,EAAwC,eAAA,CAAA;AAAA;AAAA;AAAA;AAKtD,aAAA,CAvUY,QAuUE,QAAA,EAA6B,IAAA,CAAA;AAvU/BK,aAAA,GAAN;AAAA,CAmVA,CAAUA,MAAAA,KAAV;AACC,EAAMA,OAAA,QAAA,GAAWC,+BAAA;AAAA,CAAA,EADRD,aAAA,KAAAA,aAAA,GAAA,EAAA,CAAA,CAAA","file":"Store.cjs","sourcesContent":["import { Collection } from '@discordjs/collection';\nimport { classExtends, isClass, type AbstractConstructor, type Constructor } from '@sapphire/utilities';\nimport { join } from 'path';\nimport { LoaderError, LoaderErrorType } from '../errors/LoaderError';\nimport { resolvePath, type Path } from '../internal/Path';\nimport { ManuallyRegisteredPiecesSymbol, VirtualPath } from '../internal/constants';\nimport { container, type Container } from '../shared/Container';\nimport type { HydratedModuleData, ILoaderResultEntry, ILoaderStrategy, ModuleData } from '../strategies/ILoaderStrategy';\nimport { LoaderStrategy } from '../strategies/LoaderStrategy';\nimport type { Piece } from './Piece';\nimport { StoreRegistry, type StoreRegistryEntries, type StoreRegistryKey } from './StoreRegistry';\n\n/**\n * The options for the store, this features both hooks (changes the behaviour) and handlers (similar to event listeners).\n */\nexport interface StoreOptions<T extends Piece, StoreName extends StoreRegistryKey = StoreRegistryKey> {\n\t/**\n\t * The name for this store.\n\t */\n\treadonly name: StoreName;\n\n\t/**\n\t * The paths to load pieces from, should be absolute.\n\t * @default []\n\t */\n\treadonly paths?: readonly string[];\n\n\t/**\n\t * The strategy to be used for the loader.\n\t * @default Store.defaultStrategy\n\t */\n\treadonly strategy?: ILoaderStrategy<T>;\n}\n\n/**\n * An interface representing a logger function.\n */\nexport interface StoreLogger {\n\t/**\n\t * @param value The string to print. All strings will be formatted with the format `[STORE => ${name}] [${type}] ${content}`,\n\t * where the content may have identifiers (values or names of methods) surrounded by `'`. For example:\n\t *\n\t * - `[STORE => commands] [LOAD] Skipped piece '/home/user/bot/src/commands/foo.js' as 'LoaderStrategy#filter' returned 'null'.`\n\t * - `[STORE => commands] [INSERT] Unloaded new piece 'foo' due to 'enabled' being 'false'.`\n\t * - `[STORE => commands] [UNLOAD] Unloaded piece 'foo'.`\n\t */\n\t(value: string): void;\n}\n\nconst defaultStrategy = new LoaderStrategy();\n\n/**\n * The store class which contains {@link Piece}s.\n */\nexport class Store<T extends Piece, StoreName extends StoreRegistryKey = StoreRegistryKey> extends Collection<string, T> {\n\tpublic readonly Constructor: AbstractConstructor<T>;\n\tpublic readonly name: StoreName;\n\tpublic readonly paths: Set<string>;\n\tpublic readonly strategy: ILoaderStrategy<T>;\n\n\t/**\n\t * The queue of manually registered pieces to load.\n\t */\n\tprivate readonly [ManuallyRegisteredPiecesSymbol] = new Map<string, StoreManuallyRegisteredPiece<StoreName>>();\n\n\t/**\n\t * Whether or not the store has called `loadAll` at least once.\n\t */\n\t#calledLoadAll = false;\n\n\t/**\n\t * The walk function for the store.\n\t */\n\t#walk: LoaderStrategy<T>['walk'];\n\n\t/**\n\t * @param constructor The piece constructor this store loads.\n\t * @param options The options for the store.\n\t */\n\tpublic constructor(constructor: AbstractConstructor<T>, options: StoreOptions<T, StoreName>) {\n\t\tsuper();\n\t\tthis.Constructor = constructor;\n\t\tthis.name = options.name as StoreRegistryKey;\n\t\tthis.paths = new Set(options.paths ?? []);\n\t\tthis.strategy = options.strategy ?? Store.defaultStrategy;\n\n\t\tthis.#walk =\n\t\t\ttypeof this.strategy.walk === 'function' //\n\t\t\t\t? this.strategy.walk.bind(this.strategy)\n\t\t\t\t: defaultStrategy.walk.bind(defaultStrategy);\n\t}\n\n\t/**\n\t * A reference to the {@link Container} object for ease of use.\n\t * @see container\n\t */\n\tpublic get container(): Container {\n\t\treturn container;\n\t}\n\n\t/**\n\t * Registers a directory into the store.\n\t * @param path The path to be added.\n\t * @example\n\t * ```typescript\n\t * store\n\t * .registerPath(resolve('commands'))\n\t * .registerPath(resolve('third-party', 'commands'));\n\t * ```\n\t */\n\tpublic registerPath(path: Path): this {\n\t\tconst root = resolvePath(path);\n\n\t\tthis.paths.add(root);\n\t\tStore.logger?.(`[STORE => ${this.name}] [REGISTER] Registered path '${root}'.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds a piece into the store's list of manually registered pieces. If {@linkcode Store.loadAll()} was called, the\n\t * piece will be loaded immediately, otherwise it will be queued until {@linkcode Store.loadAll()} is called.\n\t *\n\t * All manually registered pieces will be kept even after they are loaded to ensure they can be loaded again if\n\t * {@linkcode Store.loadAll()} is called again.\n\t *\n\t * @remarks\n\t *\n\t * - Pieces loaded this way will have their {@linkcode Piece.Context.root root} and\n\t * {@linkcode Piece.Context.path path} set to {@linkcode VirtualPath}, and as such, cannot be reloaded.\n\t * - This method is useful in environments where file system access is limited or unavailable, such as when using\n\t * {@link https://en.wikipedia.org/wiki/Serverless_computing Serverless Computing}.\n\t * - This method will always throw a {@link TypeError} if `entry.piece` is not a class.\n\t * - This method will always throw a {@linkcode LoaderError} if the piece does not extend the\n\t * {@linkcode Store#Constructor store's piece constructor}.\n\t * - This operation is atomic, if any of the above errors are thrown, the piece will not be loaded.\n\t *\n\t * @seealso {@linkcode StoreRegistry.loadPiece()}\n\t * @since 3.8.0\n\t * @param entry The entry to load.\n\t * @example\n\t * ```typescript\n\t * import { container } from '@sapphire/pieces';\n\t *\n\t * class PingCommand extends Command {\n\t * // ...\n\t * }\n\t *\n\t * container.stores.get('commands').loadPiece({\n\t * name: 'ping',\n\t * piece: PingCommand\n\t * });\n\t * ```\n\t */\n\tpublic async loadPiece(entry: StoreManuallyRegisteredPiece<StoreName>) {\n\t\tif (!isClass(entry.piece)) {\n\t\t\tthrow new TypeError(`The piece ${entry.name} is not a Class. ${String(entry.piece)}`);\n\t\t}\n\n\t\t// If the piece does not extend the store's Piece class, throw an error:\n\t\tif (!classExtends(entry.piece, this.Constructor as Constructor<T>)) {\n\t\t\tthrow new LoaderError(LoaderErrorType.IncorrectType, `The piece ${entry.name} does not extend ${this.name}`);\n\t\t}\n\n\t\tthis[ManuallyRegisteredPiecesSymbol].set(entry.name, entry);\n\t\tif (this.#calledLoadAll) {\n\t\t\tconst piece = this.construct(entry.piece as unknown as Constructor<T>, {\n\t\t\t\tname: entry.name,\n\t\t\t\troot: VirtualPath,\n\t\t\t\tpath: VirtualPath,\n\t\t\t\textension: VirtualPath\n\t\t\t});\n\t\t\tawait this.insert(piece);\n\t\t}\n\t}\n\n\t/**\n\t * Loads one or more pieces from a path.\n\t * @param root The root directory the file is from.\n\t * @param path The path of the file to load, relative to the `root`.\n\t * @return All the loaded pieces.\n\t */\n\tpublic async load(root: string, path: string): Promise<T[]> {\n\t\tif (root === VirtualPath) {\n\t\t\tthrow new LoaderError(LoaderErrorType.VirtualPiece, `Cannot load a virtual file.`);\n\t\t}\n\n\t\tconst full = join(root, path);\n\t\tconst data = this.strategy.filter(full);\n\t\tif (data === null) {\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD] Skipped piece '${full}' as 'LoaderStrategy#filter' returned 'null'.`);\n\t\t\treturn [];\n\t\t}\n\n\t\tconst promises: Promise<T>[] = [];\n\t\tconst finishedData = this.hydrateModuleData(root, data);\n\t\tfor await (const Ctor of this.strategy.load(this, finishedData)) {\n\t\t\tpromises.push(this.insert(this.construct(Ctor, finishedData)));\n\t\t}\n\n\t\treturn Promise.all(promises);\n\t}\n\n\t/**\n\t * Unloads a piece given its instance or its name.\n\t * @param name The name of the file to load.\n\t * @return Returns the piece that was unloaded.\n\t */\n\tpublic async unload(name: string | T): Promise<T> {\n\t\tconst piece = this.resolve(name);\n\n\t\t// Unload piece:\n\t\tthis.strategy.onUnload(this, piece);\n\t\tawait piece.onUnload();\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD] Unloaded piece '${piece.name}'.`);\n\n\t\t// Remove from cache and return it:\n\t\tthis.delete(piece.name);\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD] Removed piece '${piece.name}'.`);\n\t\treturn piece;\n\t}\n\n\t/**\n\t * Unloads all pieces from the store.\n\t */\n\tpublic async unloadAll(): Promise<T[]> {\n\t\tconst promises: Promise<T>[] = [];\n\t\tfor (const piece of this.values()) {\n\t\t\tpromises.push(this.unload(piece));\n\t\t}\n\n\t\tconst results = await Promise.all(promises);\n\n\t\tthis.strategy.onUnloadAll(this);\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD-ALL] Removed all pieces.`);\n\t\treturn results;\n\t}\n\n\t/**\n\t * Loads all pieces from all directories specified by {@link paths}.\n\t */\n\tpublic async loadAll(): Promise<void> {\n\t\tthis.#calledLoadAll = true;\n\n\t\tconst pieces: T[] = [];\n\t\tfor (const entry of this[ManuallyRegisteredPiecesSymbol].values()) {\n\t\t\tconst piece = this.construct(entry.piece as unknown as Constructor<T>, {\n\t\t\t\tname: entry.name,\n\t\t\t\troot: VirtualPath,\n\t\t\t\tpath: VirtualPath,\n\t\t\t\textension: VirtualPath\n\t\t\t});\n\t\t\tpieces.push(piece);\n\t\t}\n\n\t\tfor (const path of this.paths) {\n\t\t\tfor await (const piece of this.loadPath(path)) {\n\t\t\t\tpieces.push(piece);\n\t\t\t}\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Found '${pieces.length}' pieces.`);\n\n\t\t// Clear the store before inserting the new pieces:\n\t\tawait this.unloadAll();\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Cleared all pieces.`);\n\n\t\t// Load each piece:\n\t\tfor (const piece of pieces) {\n\t\t\tawait this.insert(piece);\n\t\t}\n\n\t\t// Call onLoadAll:\n\t\tthis.strategy.onLoadAll(this);\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Successfully loaded '${this.size}' pieces.`);\n\t}\n\n\t/**\n\t * Resolves a piece by its name or its instance.\n\t * @param name The name of the piece or the instance itself.\n\t * @return The resolved piece.\n\t */\n\tpublic resolve(name: string | T): T {\n\t\tif (typeof name === 'string') {\n\t\t\tconst result = this.get(name);\n\t\t\tif (typeof result === 'undefined') throw new LoaderError(LoaderErrorType.UnloadedPiece, `The piece '${name}' does not exist.`);\n\t\t\treturn result;\n\t\t}\n\n\t\tif (name instanceof this.Constructor) return name;\n\t\tthrow new LoaderError(LoaderErrorType.IncorrectType, `The piece '${name.name}' is not an instance of '${this.Constructor.name}'.`);\n\t}\n\n\t/**\n\t * Inserts a piece into the store.\n\t * @param piece The piece to be inserted into the store.\n\t * @return The inserted piece.\n\t */\n\tpublic async insert(piece: T): Promise<T> {\n\t\tif (!piece.enabled) return piece;\n\n\t\t// Load piece:\n\t\tthis.strategy.onLoad(this, piece);\n\t\tawait piece.onLoad();\n\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Loaded new piece '${piece.name}'.`);\n\n\t\t// If the onLoad disabled the piece, call unload and return it:\n\t\tif (!piece.enabled) {\n\t\t\t// Unload piece:\n\t\t\tthis.strategy.onUnload(this, piece);\n\t\t\tawait piece.onUnload();\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Unloaded new piece '${piece.name}' due to 'enabled' being 'false'.`);\n\n\t\t\treturn piece;\n\t\t}\n\n\t\t// Unload existing piece, if any:\n\t\tconst previous = super.get(piece.name);\n\t\tif (previous) {\n\t\t\tawait this.unload(previous);\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Unloaded existing piece '${piece.name}' due to conflicting 'name'.`);\n\t\t}\n\n\t\t// Set the new piece and return it:\n\t\tthis.set(piece.name, piece);\n\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Inserted new piece '${piece.name}'.`);\n\t\treturn piece;\n\t}\n\n\t/**\n\t * Constructs a {@link Piece} instance.\n\t * @param Ctor The {@link Piece}'s constructor used to build the instance.\n\t * @param data The module's information\n\t * @return An instance of the constructed piece.\n\t */\n\tpublic construct(Ctor: ILoaderResultEntry<T>, data: HydratedModuleData): T {\n\t\treturn new Ctor({ store: this, root: data.root, path: data.path, name: data.name }, { name: data.name, enabled: true });\n\t}\n\n\t/**\n\t * Adds the final module data properties.\n\t * @param root The root directory to add.\n\t * @param data The module data returned from {@link ILoaderStrategy.filter}.\n\t * @returns The finished module data.\n\t */\n\tprivate hydrateModuleData(root: string, data: ModuleData): HydratedModuleData {\n\t\treturn { root, ...data };\n\t}\n\n\t/**\n\t * Loads a directory into the store.\n\t * @param root The directory to load the pieces from.\n\t * @return An async iterator that yields the pieces to be loaded into the store.\n\t */\n\tprivate async *loadPath(root: string): AsyncIterableIterator<T> {\n\t\tStore.logger?.(`[STORE => ${this.name}] [WALK] Loading all pieces from '${root}'.`);\n\t\tfor await (const child of this.#walk(this, root, Store.logger)) {\n\t\t\tconst data = this.strategy.filter(child);\n\t\t\tif (data === null) {\n\t\t\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD] Skipped piece '${child}' as 'LoaderStrategy#filter' returned 'null'.`);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst finishedData = this.hydrateModuleData(root, data);\n\t\t\t\tfor await (const Ctor of this.strategy.load(this, finishedData)) {\n\t\t\t\t\tyield this.construct(Ctor, finishedData);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthis.strategy.onError(error as Error, data.path);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The default strategy, defaults to {@link LoaderStrategy}, which is constructed on demand when a store is constructed,\n\t * when none was set beforehand.\n\t */\n\tpublic static defaultStrategy: ILoaderStrategy<any> = defaultStrategy;\n\n\t/**\n\t * The default logger, defaults to `null`.\n\t */\n\tpublic static logger: StoreLogger | null = null;\n}\n\n/**\n * An entry for a manually registered piece using {@linkcode Store.loadPiece()}.\n * @since 3.8.0\n */\nexport interface StoreManuallyRegisteredPiece<StoreName extends StoreRegistryKey> {\n\tname: string;\n\tpiece: StoreRegistryEntries[StoreName] extends Store<infer Piece> ? Constructor<Piece> : never;\n}\n\nexport namespace Store {\n\texport const Registry = StoreRegistry;\n\texport type Options<T extends Piece> = StoreOptions<T>;\n\texport type Logger = StoreLogger;\n\texport type RegistryEntries = StoreRegistryEntries;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/StoreRegistry.ts"],"names":["Collection","getRootData","resolvePath","join","ManuallyRegisteredPiecesSymbol","isClass"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAA,gCAAA;AA8BO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsBA,qBAAiD,CAAA;AAAA,EAA7E,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAS,YAAA,CAAA,IAAA,EAAA,gCAAA,EAAmC,IAAIA,qBAA+E,EAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM/H,MAAa,IAAO,GAAA;AACnB,IAAA,MAAM,WAA+B,EAAC;AACtC,IAAW,KAAA,MAAA,KAAA,IAAS,IAAK,CAAA,MAAA,EAA4C,EAAA;AACpE,MAAS,QAAA,CAAA,IAAA,CAAK,KAAM,CAAA,OAAA,EAAS,CAAA;A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IAAA,CAAA,MAAA,CAAO,MAAM,IAAwB,CAAA;AAC1C,IAAO,OAAA,IAAA;AAAA;AACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuCA,MAAa,UAA8C,KAAuD,EAAA;AACjH,IAAA,MAAM,KAAQ,GAAA,IAAA,CAAK,GAAI,CAAA,KAAA,CAAM,KAAK,CAAA;AAElC,IAAA,IAAI,KAAO,EAAA;AACV,MAAM,MAAA,KAAA,CAAM,UAAU,KAAK,CAAA;AAAA,KACrB,MAAA;AACN,MAAA,IAAI,CAACC,iBAAA,CAAQ,KAAM,CAAA,KAAK,CAAG,EAAA;AAC1B,QAAM,MAAA,IAAI,SAAU,CAAA,CAAA,UAAA,EAAa,KAAM,CAAA,IAAI,oBAAoB,MAAO,CAAA,KAAA,CAAM,KAAK,CAAC,CAAE,CAAA,CAAA;AAAA;AAGrF,MAAA,YAAA,CAAA,IAAA,EAAK,kCAAiC,MAAO,CAAA,KAAA,CAAM,KAAO,EAAA,MAAM,EAAE,CAAA,CAAE,IAAK,CAAA,EAAE,MAAM,KAAM,CAAA,IAAA,EAAM,KAAO,EAAA,KAAA,CAAM,OAAO,CAAA;AAAA;AAClH;AAEF,CAAA;AAlJU,gCAAA,GAAA,IAAA,OAAA,EAAA;AAJ0E,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA;AAA7E,IAAM,aAAN,GAAA","file":"StoreRegistry.cjs","sourcesContent":["import { Collection } from '@discordjs/collection';\nimport { isClass } from '@sapphire/utilities';\nimport { join } from 'path';\nimport { LoaderError } from '../errors/LoaderError';\nimport { resolvePath, type Path } from '../internal/Path';\nimport { getRootData } from '../internal/RootScan';\nimport { ManuallyRegisteredPiecesSymbol, VirtualPath } from '../internal/constants';\nimport type { Piece } from './Piece';\nimport type { Store, StoreManuallyRegisteredPiece } from './Store';\n\n/**\n * A strict-typed store registry. This is available in {@link container}.\n * @since 2.1.0\n * @example\n * ```typescript\n * // Adding new stores\n *\n * // Register the store:\n * container.stores.register(new RouteStore());\n *\n * // Augment Sapphire to add the new store, in case of a JavaScript\n * // project, this can be moved to an `Augments.d.ts` (or any other name)\n * // file somewhere:\n * declare module '@sapphire/pieces' {\n * export interface StoreRegistryEntries {\n * routes: RouteStore;\n * }\n * }\n * ```\n */\nexport class StoreRegistry extends Collection<StoreRegistryKey, StoreRegistryValue> {\n\t/**\n\t * The queue of pieces to load.\n\t */\n\treadonly #pendingManuallyRegisteredPieces = new Collection<StoreRegistryKey, StoreManuallyRegisteredPiece<StoreRegistryKey>[]>();\n\n\t/**\n\t * Loads all the registered stores.\n\t * @since 2.1.0\n\t */\n\tpublic async load() {\n\t\tconst promises: Promise<unknown>[] = [];\n\t\tfor (const store of this.values() as IterableIterator<Store<Piece>>) {\n\t\t\tpromises.push(store.loadAll());\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * Registers all user directories from the process working directory, the default value is obtained by assuming\n\t * CommonJS (high accuracy) but with fallback for ECMAScript Modules (reads package.json's `main` entry, fallbacks\n\t * to `process.cwd()`).\n\t *\n\t * By default, if you have this folder structure:\n\t * ```\n\t * /home/me/my-bot\n\t * ├─ src\n\t * │ ├─ commands\n\t * │ ├─ events\n\t * │ └─ main.js\n\t * └─ package.json\n\t * ```\n\t *\n\t * And you run `node src/main.js`, the directories `/home/me/my-bot/src/commands` and `/home/me/my-bot/src/events` will\n\t * be registered for the commands and events stores respectively, since both directories are located in the same\n\t * directory as your main file.\n\t *\n\t * **Note**: this also registers directories for all other stores, even if they don't have a folder, this allows you\n\t * to create new pieces and hot-load them later anytime.\n\t * @since 2.1.0\n\t * @param rootDirectory The root directory to register pieces at.\n\t */\n\tpublic registerPath(rootDirectory: Path = getRootData().root) {\n\t\tconst root = resolvePath(rootDirectory);\n\t\tfor (const store of this.values() as IterableIterator<Store<Piece>>) {\n\t\t\tstore.registerPath(join(root, store.name));\n\t\t}\n\t}\n\n\t/**\n\t * Registers a store.\n\t *\n\t * @remarks\n\t *\n\t * - This method will allow {@linkcode StoreRegistry} to manage the store, meaning:\n\t * - {@linkcode StoreRegistry.registerPath()} will call the store's\n\t * {@linkcode Store.registerPath() registerPath()} method on call.\n\t * - {@linkcode StoreRegistry.load()} will call the store's {@linkcode Store.load() load()} method on call.\n\t * - {@linkcode StoreRegistry.loadPiece()} will call the store's {@linkcode Store.loadPiece() loadPiece()} method\n\t * on call.\n\t * - This will also add all the manually registered pieces by {@linkcode StoreRegistry.loadPiece()} in the store.\n\t *\n\t * It is generally recommended to register a store as early as possible, before any of the aforementioned methods\n\t * are called, otherwise you will have to manually call the aforementioned methods for the store to work properly.\n\t *\n\t * If there were manually registered pieces for this store with {@linkcode StoreRegistry.loadPiece()}, this method\n\t * will add them to the store and delete the queue. Note, however, that this method will not call the store's\n\t * {@linkcode Store.loadPiece() loadPiece()} method, and as such, the pieces will not be loaded until\n\t * {@linkcode Store.loadAll()} is called.\n\t *\n\t * @since 2.1.0\n\t * @param store The store to register.\n\t */\n\tpublic register<T extends Piece>(store: Store<T>): this {\n\t\tthis.set(store.name as StoreRegistryKey, store as unknown as StoreRegistryValue);\n\n\t\t// If there was a queue for this store, add it to the store and delete the queue:\n\t\tconst queue = this.#pendingManuallyRegisteredPieces.get(store.name);\n\t\tif (queue) {\n\t\t\tfor (const entry of queue) {\n\t\t\t\tstore[ManuallyRegisteredPiecesSymbol].set(entry.name, entry);\n\t\t\t}\n\n\t\t\tthis.#pendingManuallyRegisteredPieces.delete(store.name);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Deregisters a store.\n\t * @since 2.1.0\n\t * @param store The store to deregister.\n\t */\n\tpublic deregister<T extends Piece>(store: Store<T>): this {\n\t\tthis.delete(store.name as StoreRegistryKey);\n\t\treturn this;\n\t}\n\n\t/**\n\t * If the store was {@link StoreRegistry.register registered}, this method will call the store's\n\t * {@linkcode Store.loadPiece() loadPiece()} method.\n\t *\n\t * If it was called, the entry will be loaded immediately without queueing.\n\t *\n\t * @remarks\n\t *\n\t * - Pieces loaded this way will have their {@linkcode Piece.Context.root root} and\n\t * {@linkcode Piece.Context.path path} set to {@linkcode VirtualPath}, and as such, cannot be reloaded.\n\t * - This method is useful in environments where file system access is limited or unavailable, such as when using\n\t * {@link https://en.wikipedia.org/wiki/Serverless_computing Serverless Computing}.\n\t * - This method will not throw an error if a store with the given name does not exist, it will simply be queued\n\t * until it's registered.\n\t * - This method will always throw a {@link TypeError} if `entry.piece` is not a class.\n\t * - If the store is registered, this method will always throw a {@linkcode LoaderError} if the piece does not\n\t * extend the registered {@linkcode Store.Constructor store's piece constructor}.\n\t * - This operation is atomic, if any of the above errors are thrown, the piece will not be loaded.\n\t *\n\t * @seealso {@linkcode Store.loadPiece()}\n\t * @since 3.8.0\n\t * @param entry The entry to load.\n\t * @example\n\t * ```typescript\n\t * import { container } from '@sapphire/pieces';\n\t *\n\t * class PingCommand extends Command {\n\t * // ...\n\t * }\n\t *\n\t * container.stores.loadPiece({\n\t * store: 'commands',\n\t * name: 'ping',\n\t * piece: PingCommand\n\t * });\n\t * ```\n\t */\n\tpublic async loadPiece<StoreName extends StoreRegistryKey>(entry: StoreManagerManuallyRegisteredPiece<StoreName>) {\n\t\tconst store = this.get(entry.store) as Store<Piece, StoreName> | undefined;\n\n\t\tif (store) {\n\t\t\tawait store.loadPiece(entry);\n\t\t} else {\n\t\t\tif (!isClass(entry.piece)) {\n\t\t\t\tthrow new TypeError(`The piece ${entry.name} is not a Class. ${String(entry.piece)}`);\n\t\t\t}\n\n\t\t\tthis.#pendingManuallyRegisteredPieces.ensure(entry.store, () => []).push({ name: entry.name, piece: entry.piece });\n\t\t}\n\t}\n}\n\nexport interface StoreRegistry {\n\tget<K extends StoreRegistryKey>(key: K): StoreRegistryEntries[K];\n\tget(key: string): undefined;\n\thas(key: StoreRegistryKey): true;\n\thas(key: string): false;\n}\n\n/**\n * A type utility to get the keys of {@linkcode StoreRegistryEntries}.\n * @since 3.10.0\n */\nexport type StoreRegistryKey = keyof StoreRegistryEntries;\n\n/**\n * A type utility to get the values of {@linkcode StoreRegistryEntries}.\n * @since 3.10.0\n */\nexport type StoreRegistryValue = StoreRegistryEntries[StoreRegistryKey];\n\n/**\n * The {@link StoreRegistry}'s registry, use module augmentation against this interface when adding new stores.\n * @since 2.1.0\n */\nexport interface StoreRegistryEntries {}\n\n/**\n * An entry for a manually registered piece using {@linkcode StoreRegistry.loadPiece()}.\n * @seealso {@linkcode StoreRegistry.loadPiece()}\n * @since 3.8.0\n */\nexport interface StoreManagerManuallyRegisteredPiece<StoreName extends StoreRegistryKey> extends StoreManuallyRegisteredPiece<StoreName> {\n\tstore: StoreName;\n}\n\n/**\n * Type utility to get the {@linkcode Store} given its name.\n * @since 3.10.0\n */\nexport type StoreOf<StoreName extends StoreRegistryKey> = StoreRegistryKey extends never\n\t? Store<Piece<Piece.Options, StoreName>>\n\t: StoreRegistryEntries[StoreName];\n\n/**\n * Type utility to get the {@linkcode Piece} given its {@linkcode Store}'s name.\n * @since 3.10.0\n */\nexport type PieceOf<StoreName extends StoreRegistryKey> = StoreRegistryKey extends never\n\t? Piece<Piece.Options, StoreName>\n\t: StoreRegistryEntries[StoreName] extends Store<infer PieceType>\n\t\t? PieceType\n\t\t: Piece<Piece.Options, StoreName>;\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/StoreRegistry.ts"],"names":["Collection","getRootData","resolvePath","join","ManuallyRegisteredPiecesSymbol","isClass"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAA,gCAAA;AA8BO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsBA,qBAAA,CAAiD;AAAA,EAA7E,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAI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M,KAAA,CAAM,IAAA,EAAM,KAAA,EAAO,KAAA,CAAM,OAAO,CAAA;AAAA,IAClH;AAAA,EACD;AACD,CAAA;AAlJU,gCAAA,GAAA,IAAA,OAAA,EAAA;AAJ0E,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA;AAA7E,IAAM,aAAA,GAAN","file":"StoreRegistry.cjs","sourcesContent":["import { Collection } from '@discordjs/collection';\nimport { isClass } from '@sapphire/utilities';\nimport { join } from 'path';\nimport { LoaderError } from '../errors/LoaderError';\nimport { resolvePath, type Path } from '../internal/Path';\nimport { getRootData } from '../internal/RootScan';\nimport { ManuallyRegisteredPiecesSymbol, VirtualPath } from '../internal/constants';\nimport type { Piece } from './Piece';\nimport type { Store, StoreManuallyRegisteredPiece } from './Store';\n\n/**\n * A strict-typed store registry. This is available in {@link container}.\n * @since 2.1.0\n * @example\n * ```typescript\n * // Adding new stores\n *\n * // Register the store:\n * container.stores.register(new RouteStore());\n *\n * // Augment Sapphire to add the new store, in case of a JavaScript\n * // project, this can be moved to an `Augments.d.ts` (or any other name)\n * // file somewhere:\n * declare module '@sapphire/pieces' {\n * export interface StoreRegistryEntries {\n * routes: RouteStore;\n * }\n * }\n * ```\n */\nexport class StoreRegistry extends Collection<StoreRegistryKey, StoreRegistryValue> {\n\t/**\n\t * The queue of pieces to load.\n\t */\n\treadonly #pendingManuallyRegisteredPieces = new Collection<StoreRegistryKey, StoreManuallyRegisteredPiece<StoreRegistryKey>[]>();\n\n\t/**\n\t * Loads all the registered stores.\n\t * @since 2.1.0\n\t */\n\tpublic async load() {\n\t\tconst promises: Promise<unknown>[] = [];\n\t\tfor (const store of this.values() as IterableIterator<Store<Piece>>) {\n\t\t\tpromises.push(store.loadAll());\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * Registers all user directories from the process working directory, the default value is obtained by assuming\n\t * CommonJS (high accuracy) but with fallback for ECMAScript Modules (reads package.json's `main` entry, fallbacks\n\t * to `process.cwd()`).\n\t *\n\t * By default, if you have this folder structure:\n\t * ```\n\t * /home/me/my-bot\n\t * ├─ src\n\t * │ ├─ commands\n\t * │ ├─ events\n\t * │ └─ main.js\n\t * └─ package.json\n\t * ```\n\t *\n\t * And you run `node src/main.js`, the directories `/home/me/my-bot/src/commands` and `/home/me/my-bot/src/events` will\n\t * be registered for the commands and events stores respectively, since both directories are located in the same\n\t * directory as your main file.\n\t *\n\t * **Note**: this also registers directories for all other stores, even if they don't have a folder, this allows you\n\t * to create new pieces and hot-load them later anytime.\n\t * @since 2.1.0\n\t * @param rootDirectory The root directory to register pieces at.\n\t */\n\tpublic registerPath(rootDirectory: Path = getRootData().root) {\n\t\tconst root = resolvePath(rootDirectory);\n\t\tfor (const store of this.values() as IterableIterator<Store<Piece>>) {\n\t\t\tstore.registerPath(join(root, store.name));\n\t\t}\n\t}\n\n\t/**\n\t * Registers a store.\n\t *\n\t * @remarks\n\t *\n\t * - This method will allow {@linkcode StoreRegistry} to manage the store, meaning:\n\t * - {@linkcode StoreRegistry.registerPath()} will call the store's\n\t * {@linkcode Store.registerPath() registerPath()} method on call.\n\t * - {@linkcode StoreRegistry.load()} will call the store's {@linkcode Store.load() load()} method on call.\n\t * - {@linkcode StoreRegistry.loadPiece()} will call the store's {@linkcode Store.loadPiece() loadPiece()} method\n\t * on call.\n\t * - This will also add all the manually registered pieces by {@linkcode StoreRegistry.loadPiece()} in the store.\n\t *\n\t * It is generally recommended to register a store as early as possible, before any of the aforementioned methods\n\t * are called, otherwise you will have to manually call the aforementioned methods for the store to work properly.\n\t *\n\t * If there were manually registered pieces for this store with {@linkcode StoreRegistry.loadPiece()}, this method\n\t * will add them to the store and delete the queue. Note, however, that this method will not call the store's\n\t * {@linkcode Store.loadPiece() loadPiece()} method, and as such, the pieces will not be loaded until\n\t * {@linkcode Store.loadAll()} is called.\n\t *\n\t * @since 2.1.0\n\t * @param store The store to register.\n\t */\n\tpublic register<T extends Piece>(store: Store<T>): this {\n\t\tthis.set(store.name as StoreRegistryKey, store as unknown as StoreRegistryValue);\n\n\t\t// If there was a queue for this store, add it to the store and delete the queue:\n\t\tconst queue = this.#pendingManuallyRegisteredPieces.get(store.name);\n\t\tif (queue) {\n\t\t\tfor (const entry of queue) {\n\t\t\t\tstore[ManuallyRegisteredPiecesSymbol].set(entry.name, entry);\n\t\t\t}\n\n\t\t\tthis.#pendingManuallyRegisteredPieces.delete(store.name);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Deregisters a store.\n\t * @since 2.1.0\n\t * @param store The store to deregister.\n\t */\n\tpublic deregister<T extends Piece>(store: Store<T>): this {\n\t\tthis.delete(store.name as StoreRegistryKey);\n\t\treturn this;\n\t}\n\n\t/**\n\t * If the store was {@link StoreRegistry.register registered}, this method will call the store's\n\t * {@linkcode Store.loadPiece() loadPiece()} method.\n\t *\n\t * If it was called, the entry will be loaded immediately without queueing.\n\t *\n\t * @remarks\n\t *\n\t * - Pieces loaded this way will have their {@linkcode Piece.Context.root root} and\n\t * {@linkcode Piece.Context.path path} set to {@linkcode VirtualPath}, and as such, cannot be reloaded.\n\t * - This method is useful in environments where file system access is limited or unavailable, such as when using\n\t * {@link https://en.wikipedia.org/wiki/Serverless_computing Serverless Computing}.\n\t * - This method will not throw an error if a store with the given name does not exist, it will simply be queued\n\t * until it's registered.\n\t * - This method will always throw a {@link TypeError} if `entry.piece` is not a class.\n\t * - If the store is registered, this method will always throw a {@linkcode LoaderError} if the piece does not\n\t * extend the registered {@linkcode Store.Constructor store's piece constructor}.\n\t * - This operation is atomic, if any of the above errors are thrown, the piece will not be loaded.\n\t *\n\t * @seealso {@linkcode Store.loadPiece()}\n\t * @since 3.8.0\n\t * @param entry The entry to load.\n\t * @example\n\t * ```typescript\n\t * import { container } from '@sapphire/pieces';\n\t *\n\t * class PingCommand extends Command {\n\t * // ...\n\t * }\n\t *\n\t * container.stores.loadPiece({\n\t * store: 'commands',\n\t * name: 'ping',\n\t * piece: PingCommand\n\t * });\n\t * ```\n\t */\n\tpublic async loadPiece<StoreName extends StoreRegistryKey>(entry: StoreManagerManuallyRegisteredPiece<StoreName>) {\n\t\tconst store = this.get(entry.store) as Store<Piece, StoreName> | undefined;\n\n\t\tif (store) {\n\t\t\tawait store.loadPiece(entry);\n\t\t} else {\n\t\t\tif (!isClass(entry.piece)) {\n\t\t\t\tthrow new TypeError(`The piece ${entry.name} is not a Class. ${String(entry.piece)}`);\n\t\t\t}\n\n\t\t\tthis.#pendingManuallyRegisteredPieces.ensure(entry.store, () => []).push({ name: entry.name, piece: entry.piece });\n\t\t}\n\t}\n}\n\nexport interface StoreRegistry {\n\tget<K extends StoreRegistryKey>(key: K): StoreRegistryEntries[K];\n\tget(key: string): undefined;\n\thas(key: StoreRegistryKey): true;\n\thas(key: string): false;\n}\n\n/**\n * A type utility to get the keys of {@linkcode StoreRegistryEntries}.\n * @since 3.10.0\n */\nexport type StoreRegistryKey = keyof StoreRegistryEntries;\n\n/**\n * A type utility to get the values of {@linkcode StoreRegistryEntries}.\n * @since 3.10.0\n */\nexport type StoreRegistryValue = StoreRegistryEntries[StoreRegistryKey];\n\n/**\n * The {@link StoreRegistry}'s registry, use module augmentation against this interface when adding new stores.\n * @since 2.1.0\n */\nexport interface StoreRegistryEntries {}\n\n/**\n * An entry for a manually registered piece using {@linkcode StoreRegistry.loadPiece()}.\n * @seealso {@linkcode StoreRegistry.loadPiece()}\n * @since 3.8.0\n */\nexport interface StoreManagerManuallyRegisteredPiece<StoreName extends StoreRegistryKey> extends StoreManuallyRegisteredPiece<StoreName> {\n\tstore: StoreName;\n}\n\n/**\n * Type utility to get the {@linkcode Store} given its name.\n * @since 3.10.0\n */\nexport type StoreOf<StoreName extends StoreRegistryKey> = StoreRegistryKey extends never\n\t? Store<Piece<Piece.Options, StoreName>>\n\t: StoreRegistryEntries[StoreName];\n\n/**\n * Type utility to get the {@linkcode Piece} given its {@linkcode Store}'s name.\n * @since 3.10.0\n */\nexport type PieceOf<StoreName extends StoreRegistryKey> = StoreRegistryKey extends never\n\t? Piece<Piece.Options, StoreName>\n\t: StoreRegistryEntries[StoreName] extends Store<infer PieceType>\n\t\t? PieceType\n\t\t: Piece<Piece.Options, StoreName>;\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/tsconfig.json"],"names":["extends"],"mappings":";;;;;AACC,IAAAA,QAAW,GAAA;AACQ,IAAA,eAAA,GAAA;AAAA,EAClB,OAAW,EAAA,IAAA;AAAA,EACX,MAAU,EAAA;AACX;AACA,IAAA,OAAA,GAAW,CAAC,GAAG;AANhB,IAAA,gBAAA,GAAA;AAAA,EACC,OAAAA,EAAAA,QAAAA;AAAA,EACA,eAAA;AAAA,EAIA;AACD","file":"tsconfig.cjs","sourcesContent":["{\n\t\"extends\": \"../tsconfig.base.json\",\n\t\"compilerOptions\": {\n\t\t\"rootDir\": \"./\",\n\t\t\"outDir\": \"../dist\"\n\t},\n\t\"include\": [\".\"]\n}\n"]}
1
+ {"version":3,"sources":["../../src/tsconfig.json"],"names":["extends"],"mappings":";;;;;AACC,IAAAA,QAAAA,GAAW;AACX,IAAA,eAAA,GAAmB;AAAA,EAClB,OAAA,EAAW,IAAA;AAAA,EACX,MAAA,EAAU;AACX;AACA,IAAA,OAAA,GAAW,CAAC,GAAG;AANhB,IAAA,gBAAA,GAAA;AAAA,EACC,OAAA,EAAAA,QAAAA;AAAA,EACA,eAAA;AAAA,EAIA;AACD","file":"tsconfig.cjs","sourcesContent":["{\n\t\"extends\": \"../tsconfig.base.json\",\n\t\"compilerOptions\": {\n\t\t\"rootDir\": \"./\",\n\t\t\"outDir\": \"../dist\"\n\t},\n\t\"include\": [\".\"]\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/errors/LoaderError.ts"],"names":["LoaderErrorType"],"mappings":";;;AAAY,IAAA,eAAA,qBAAAA,gBAAL,KAAA;AACN,EAAAA,iBAAA,aAAc,CAAA,GAAA,cAAA;AACd,EAAAA,iBAAA,cAAe,CAAA,GAAA,eAAA;AACf,EAAAA,iBAAA,eAAgB,CAAA,GAAA,gBAAA;AAChB,EAAAA,iBAAA,eAAgB,CAAA,GAAA,gBAAA;AAChB,EAAAA,iBAAA,cAAe,CAAA,GAAA,eAAA;AALJ,EAAAA,OAAAA,gBAAAA;AAAA,CAAA,EAAA,eAAA,IAAA,EAAA;AAWL,IAAM,YAAA,GAAN,MAAM,YAAA,SAAoB,KAAM,CAAA;AAAA,EAM/B,WAAA,CAAY,MAAuB,OAAiB,EAAA;AAC1D,IAAA,KAAA,CAAM,OAAO,CAAA;AAHd;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAIf,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;AAAA;AACb,EAEA,IAAoB,IAAO,GAAA;AAC1B,IAAA,OAAO,CAAG,EAAA,KAAA,CAAM,IAAI,CAAA,EAAA,EAAK,KAAK,IAAI,CAAA,CAAA,CAAA;AAAA;AAEpC,CAAA;AAduC,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA;AAAhC,IAAM,WAAN,GAAA","file":"LoaderError.mjs","sourcesContent":["export enum LoaderErrorType {\n\tEmptyModule = 'EMPTY_MODULE',\n\tVirtualPiece = 'VIRTUAL_PIECE',\n\tUnloadedPiece = 'UNLOADED_PIECE',\n\tIncorrectType = 'INCORRECT_TYPE',\n\tUnknownStore = 'UNKNOWN_STORE'\n}\n\n/**\n * Describes a loader error with a type for easy identification.\n */\nexport class LoaderError extends Error {\n\t/**\n\t * The type of the error that was thrown.\n\t */\n\tpublic readonly type: LoaderErrorType;\n\n\tpublic constructor(type: LoaderErrorType, message: string) {\n\t\tsuper(message);\n\t\tthis.type = type;\n\t}\n\n\tpublic override get name() {\n\t\treturn `${super.name} [${this.type}]`;\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/errors/LoaderError.ts"],"names":["LoaderErrorType"],"mappings":";;;AAAO,IAAK,eAAA,qBAAAA,gBAAAA,KAAL;AACN,EAAAA,iBAAA,aAAA,CAAA,GAAc,cAAA;AACd,EAAAA,iBAAA,cAAA,CAAA,GAAe,eAAA;AACf,EAAAA,iBAAA,eAAA,CAAA,GAAgB,gBAAA;AAChB,EAAAA,iBAAA,eAAA,CAAA,GAAgB,gBAAA;AAChB,EAAAA,iBAAA,cAAA,CAAA,GAAe,eAAA;AALJ,EAAA,OAAAA,gBAAAA;AAAA,CAAA,EAAA,eAAA,IAAA,EAAA;AAWL,IAAM,YAAA,GAAN,MAAM,YAAA,SAAoB,KAAA,CAAM;AAAA,EAM/B,WAAA,CAAY,MAAuB,OAAA,EAAiB;AAC1D,IAAA,KAAA,CAAM,OAAO,CAAA;AAHd;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,MAAA,CAAA;AAIf,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACb;AAAA,EAEA,IAAoB,IAAA,GAAO;AAC1B,IAAA,OAAO,CAAA,EAAG,KAAA,CAAM,IAAI,CAAA,EAAA,EAAK,KAAK,IAAI,CAAA,CAAA,CAAA;AAAA,EACnC;AACD,CAAA;AAduC,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA;AAAhC,IAAM,WAAA,GAAN","file":"LoaderError.mjs","sourcesContent":["export enum LoaderErrorType {\n\tEmptyModule = 'EMPTY_MODULE',\n\tVirtualPiece = 'VIRTUAL_PIECE',\n\tUnloadedPiece = 'UNLOADED_PIECE',\n\tIncorrectType = 'INCORRECT_TYPE',\n\tUnknownStore = 'UNKNOWN_STORE'\n}\n\n/**\n * Describes a loader error with a type for easy identification.\n */\nexport class LoaderError extends Error {\n\t/**\n\t * The type of the error that was thrown.\n\t */\n\tpublic readonly type: LoaderErrorType;\n\n\tpublic constructor(type: LoaderErrorType, message: string) {\n\t\tsuper(message);\n\t\tthis.type = type;\n\t}\n\n\tpublic override get name() {\n\t\treturn `${super.name} [${this.type}]`;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/errors/MissingExportsError.ts"],"names":[],"mappings":";;;AAKO,IAAM,oBAAA,GAAN,MAAM,oBAAA,SAA4B,WAAY,CAAA;AAAA,EAM7C,YAAY,IAAc,EAAA;AAChC,IAAA,KAAA,CAAM,eAAgB,CAAA,WAAA,EAAa,CAA6C,0CAAA,EAAA,IAAI,CAAG,CAAA,CAAA,CAAA;AAHxF;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAIf,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;AAAA;AAEd,CAAA;AAVqD,MAAA,CAAA,oBAAA,EAAA,qBAAA,CAAA;AAA9C,IAAM,mBAAN,GAAA","file":"MissingExportsError.mjs","sourcesContent":["import { LoaderError, LoaderErrorType } from './LoaderError';\n\n/**\n * Describes a {@link LoaderErrorType.EmptyModule} loader error and adds a path for easy identification.\n */\nexport class MissingExportsError extends LoaderError {\n\t/**\n\t * The path of the module that did not have exports.\n\t */\n\tpublic readonly path: string;\n\n\tpublic constructor(path: string) {\n\t\tsuper(LoaderErrorType.EmptyModule, `A compatible class export was not found. [${path}]`);\n\t\tthis.path = path;\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/errors/MissingExportsError.ts"],"names":[],"mappings":";;;AAKO,IAAM,oBAAA,GAAN,MAAM,oBAAA,SAA4B,WAAA,CAAY;AAAA,EAM7C,YAAY,IAAA,EAAc;AAChC,IAAA,KAAA,CAAM,eAAA,CAAgB,WAAA,EAAa,CAAA,0CAAA,EAA6C,IAAI,CAAA,CAAA,CAAG,CAAA;AAHxF;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,MAAA,CAAA;AAIf,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACb;AACD,CAAA;AAVqD,MAAA,CAAA,oBAAA,EAAA,qBAAA,CAAA;AAA9C,IAAM,mBAAA,GAAN","file":"MissingExportsError.mjs","sourcesContent":["import { LoaderError, LoaderErrorType } from './LoaderError';\n\n/**\n * Describes a {@link LoaderErrorType.EmptyModule} loader error and adds a path for easy identification.\n */\nexport class MissingExportsError extends LoaderError {\n\t/**\n\t * The path of the module that did not have exports.\n\t */\n\tpublic readonly path: string;\n\n\tpublic constructor(path: string) {\n\t\tsuper(LoaderErrorType.EmptyModule, `A compatible class export was not found. [${path}]`);\n\t\tthis.path = path;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/internal/Path.ts"],"names":[],"mappings":";;;AAIO,SAAS,YAAY,IAAoB,EAAA;AAC/C,EAAI,IAAA,OAAO,IAAS,KAAA,QAAA,EAAiB,OAAA,IAAA;AACrC,EAAA,OAAO,cAAc,IAAI,CAAA;AAC1B;AAHgB,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA","file":"Path.mjs","sourcesContent":["import { fileURLToPath } from 'node:url';\n\nexport type Path = string | URL;\n\nexport function resolvePath(path: Path): string {\n\tif (typeof path === 'string') return path;\n\treturn fileURLToPath(path);\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/internal/Path.ts"],"names":[],"mappings":";;;AAIO,SAAS,YAAY,IAAA,EAAoB;AAC/C,EAAA,IAAI,OAAO,IAAA,KAAS,QAAA,EAAU,OAAO,IAAA;AACrC,EAAA,OAAO,cAAc,IAAI,CAAA;AAC1B;AAHgB,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA","file":"Path.mjs","sourcesContent":["import { fileURLToPath } from 'node:url';\n\nexport type Path = string | URL;\n\nexport function resolvePath(path: Path): string {\n\tif (typeof path === 'string') return path;\n\treturn fileURLToPath(path);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/internal/RootScan.ts"],"names":[],"mappings":";;;;AA4BA,IAAI,IAAwB,GAAA,IAAA;AAS5B,SAAS,eAAA,CAAgB,KAAa,YAAsB,EAAA;AAC3D,EAAA,OAAO,OAAQ,CAAA,IAAA,CAAK,GAAK,EAAA,YAAY,CAAC,CAAA;AACvC;A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AAA;AAGtC,EAAA,IAAI,mBAAmB,QAAU,EAAA;AAChC,IAAI,IAAA,WAAA,SAAoB,EAAE,IAAA,EAAM,gBAAgB,GAAK,EAAA,WAAW,CAAG,EAAA,IAAA,EAAM,KAAM,EAAA;AAC/E,IAAI,IAAA,aAAA,SAAsB,EAAE,IAAA,EAAM,gBAAgB,GAAK,EAAA,aAAa,CAAG,EAAA,IAAA,EAAM,KAAM,EAAA;AACnF,IAAA,OAAO,EAAE,IAAA,EAAM,GAAK,EAAA,IAAA,EAAM,KAAM,EAAA;AAAA;AAGjC,EAAI,IAAA,WAAA,SAAoB,EAAE,IAAA,EAAM,gBAAgB,GAAK,EAAA,WAAW,CAAG,EAAA,IAAA,EAAM,UAAW,EAAA;AACpF,EAAI,IAAA,aAAA,SAAsB,EAAE,IAAA,EAAM,gBAAgB,GAAK,EAAA,aAAa,CAAG,EAAA,IAAA,EAAM,KAAM,EAAA;AAEnF,EAAA,OAAO,EAAE,IAAA,EAAM,GAAK,EAAA,IAAA,EAAM,UAAW,EAAA;AACtC;AAjCgB,MAAA,CAAA,aAAA,EAAA,eAAA,CAAA","file":"RootScan.mjs","sourcesContent":["import { existsSync, readFileSync } from 'fs';\nimport { dirname, join } from 'path';\n\n/**\n * Represents a partial package.json object.\n */\ntype PartialPackageJson = Partial<{\n\tmain: string;\n\tmodule: string;\n\ttype: 'commonjs' | 'module';\n}>;\n\n/**\n * Represents the root data.\n */\nexport interface RootData {\n\t/**\n\t * The root directory.\n\t */\n\troot: string;\n\n\t/**\n\t * The type of the module system used.\n\t * It can be either 'ESM' or 'CommonJS'.\n\t */\n\ttype: 'ESM' | 'CommonJS';\n}\n\nlet data: RootData | null = null;\n\n/**\n * Returns the directory name of a given path by joining the current working directory (cwd) with the joinable path.\n * @private\n * @param cwd - The current working directory.\n * @param joinablePath - The path to be joined with the cwd.\n * @returns The directory name of the joined path.\n */\nfunction dirnameWithPath(cwd: string, joinablePath: string) {\n\treturn dirname(join(cwd, joinablePath));\n}\n\nexport function getRootData(): RootData {\n\treturn (data ??= parseRootData());\n}\n\n/**\n * Retrieves the root data of the project.\n *\n * This function reads the `package.json` file in the current working directory and determines the root path and type\n * of the project.\n *\n * - If the `package.json` file is not found or cannot be parsed, it assumes the project is using CommonJS and\n * the current working directory is used as the root\n *\n * - If the project `type` is specified as `\"commonjs\"` or `\"module\"` in the `package.json`, it uses the corresponding\n * `main` or `module` file path as the root.\n *\n * - If there is no `main` or `module` then it uses the current working directory as the root, while retaining the\n * matching `CommonJS` or `ESM` based on the `type`\n *\n * - If the main or module file path is not specified, it uses the current working directory as the root.\n *\n * The following table shows how different situations resolve to different root data\n *\n * | fields | resolved as |\n * |--------------------------|-------------|\n * | type=commonjs && main | CommonJS |\n * | type=commonjs && module | CommonJS |\n * | type=module && main | ESM |\n * | type=module && module | ESM |\n * | type=undefined && main | CommonJS |\n * | type=undefined && module | ESM |\n * | no package.json on cwd | CommonJS |\n *\n * @returns The root data object containing the root path and the type of the project.\n */\nexport function parseRootData(): RootData {\n\tconst cwd = process.cwd();\n\n\tlet file: PartialPackageJson | undefined;\n\n\ttry {\n\t\tfile = JSON.parse(readFileSync(join(cwd, 'package.json'), 'utf8')) as PartialPackageJson;\n\t} catch (error) {\n\t\tconst hasDenoConfigFile = existsSync(join(cwd, 'deno.json'));\n\t\tconst hasBunConfigFile = existsSync(join(cwd, 'bunfig.toml'));\n\t\treturn hasDenoConfigFile || hasBunConfigFile ? { root: cwd, type: 'ESM' } : { root: cwd, type: 'CommonJS' };\n\t}\n\n\tconst { main: packageMain, module: packageModule, type: packageType } = file;\n\n\tconst lowerCasedType = packageType?.toLowerCase() as PartialPackageJson['type'];\n\n\tif (lowerCasedType === 'commonjs') {\n\t\tif (packageMain) return { root: dirnameWithPath(cwd, packageMain), type: 'CommonJS' };\n\t\tif (packageModule) return { root: dirnameWithPath(cwd, packageModule), type: 'CommonJS' };\n\t\treturn { root: cwd, type: 'CommonJS' };\n\t}\n\n\tif (lowerCasedType === 'module') {\n\t\tif (packageMain) return { root: dirnameWithPath(cwd, packageMain), type: 'ESM' };\n\t\tif (packageModule) return { root: dirnameWithPath(cwd, packageModule), type: 'ESM' };\n\t\treturn { root: cwd, type: 'ESM' };\n\t}\n\n\tif (packageMain) return { root: dirnameWithPath(cwd, packageMain), type: 'CommonJS' };\n\tif (packageModule) return { root: dirnameWithPath(cwd, packageModule), type: 'ESM' };\n\n\treturn { root: cwd, type: 'CommonJS' };\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/internal/RootScan.ts"],"names":[],"mappings":";;;;AA4BA,IAAI,IAAA,GAAwB,IAAA;AAS5B,SAAS,eAAA,CAAgB,KAAa,YAAA,EAAsB;AAC3D,EAAA,OAAO,OAAA,CAAQ,IAAA,CAAK,GAAA,EAAK,YAAY,CAAC,CAAA;AACvC;AAFS,MAAA,CAAA,eAAA,EAAA,iBAAA,CAAA;AAIF,SAAS,WAAA,GAAwB;AACvC,EAAA,OAAQ,SAAS,aAAA,EAAc;AAChC;AAFgB,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA;AAmCT,SAAS,aAAA,GAA0B;AACzC,EAAA,MAAM,GAAA,GAAM,QAAQ,GAAA,EAAI;AAExB,EAAA,IAAI,IAAA;AAEJ,EAAA,IAAI;AACH,IAAA,IAAA,GAAO,IAAA,CAAK,MAAM,YAAA,CAAa,IAAA,CAAK,KAAK,cAAc,CAAA,EAAG,MAAM,CAAC,CAAA;AAAA,EAClE,SAAS,KAAA,EAAO;AACf,IAAA,MAAM,iBAAA,GAAoB,UAAA,CAAW,IAAA,CAAK,GAAA,EAAK,WAAW,CAAC,CAAA;AAC3D,IAAA,MAAM,gBAAA,GAAmB,UAAA,CAAW,IAAA,CAAK,GAAA,EAAK,aAAa,CAAC,CAAA;AAC5D,IAAA,OAAO,iBAAA,IAAqB,gBAAA,GAAmB,EAAE,IAAA,EAAM,GAAA,EAAK,IAAA,EAAM,KAAA,EAAM,GAAI,EAAE,IAAA,EAAM,GAAA,EAAK,IAA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.mjs","sourcesContent":["import { existsSync, readFileSync } from 'fs';\nimport { dirname, join } from 'path';\n\n/**\n * Represents a partial package.json object.\n */\ntype PartialPackageJson = Partial<{\n\tmain: string;\n\tmodule: string;\n\ttype: 'commonjs' | 'module';\n}>;\n\n/**\n * Represents the root data.\n */\nexport interface RootData {\n\t/**\n\t * The root directory.\n\t */\n\troot: string;\n\n\t/**\n\t * The type of the module system used.\n\t * It can be either 'ESM' or 'CommonJS'.\n\t */\n\ttype: 'ESM' | 'CommonJS';\n}\n\nlet data: RootData | null = null;\n\n/**\n * Returns the directory name of a given path by joining the current working directory (cwd) with the joinable path.\n * @private\n * @param cwd - The current working directory.\n * @param joinablePath - The path to be joined with the cwd.\n * @returns The directory name of the joined path.\n */\nfunction dirnameWithPath(cwd: string, joinablePath: string) {\n\treturn dirname(join(cwd, joinablePath));\n}\n\nexport function getRootData(): RootData {\n\treturn (data ??= parseRootData());\n}\n\n/**\n * Retrieves the root data of the project.\n *\n * This function reads the `package.json` file in the current working directory and determines the root path and type\n * of the project.\n *\n * - If the `package.json` file is not found or cannot be parsed, it assumes the project is using CommonJS and\n * the current working directory is used as the root\n *\n * - If the project `type` is specified as `\"commonjs\"` or `\"module\"` in the `package.json`, it uses the corresponding\n * `main` or `module` file path as the root.\n *\n * - If there is no `main` or `module` then it uses the current working directory as the root, while retaining the\n * matching `CommonJS` or `ESM` based on the `type`\n *\n * - If the main or module file path is not specified, it uses the current working directory as the root.\n *\n * The following table shows how different situations resolve to different root data\n *\n * | fields | resolved as |\n * |--------------------------|-------------|\n * | type=commonjs && main | CommonJS |\n * | type=commonjs && module | CommonJS |\n * | type=module && main | ESM |\n * | type=module && module | ESM |\n * | type=undefined && main | CommonJS |\n * | type=undefined && module | ESM |\n * | no package.json on cwd | CommonJS |\n *\n * @returns The root data object containing the root path and the type of the project.\n */\nexport function parseRootData(): RootData {\n\tconst cwd = process.cwd();\n\n\tlet file: PartialPackageJson | undefined;\n\n\ttry {\n\t\tfile = JSON.parse(readFileSync(join(cwd, 'package.json'), 'utf8')) as PartialPackageJson;\n\t} catch (error) {\n\t\tconst hasDenoConfigFile = existsSync(join(cwd, 'deno.json'));\n\t\tconst hasBunConfigFile = existsSync(join(cwd, 'bunfig.toml'));\n\t\treturn hasDenoConfigFile || hasBunConfigFile ? { root: cwd, type: 'ESM' } : { root: cwd, type: 'CommonJS' };\n\t}\n\n\tconst { main: packageMain, module: packageModule, type: packageType } = file;\n\n\tconst lowerCasedType = packageType?.toLowerCase() as PartialPackageJson['type'];\n\n\tif (lowerCasedType === 'commonjs') {\n\t\tif (packageMain) return { root: dirnameWithPath(cwd, packageMain), type: 'CommonJS' };\n\t\tif (packageModule) return { root: dirnameWithPath(cwd, packageModule), type: 'CommonJS' };\n\t\treturn { root: cwd, type: 'CommonJS' };\n\t}\n\n\tif (lowerCasedType === 'module') {\n\t\tif (packageMain) return { root: dirnameWithPath(cwd, packageMain), type: 'ESM' };\n\t\tif (packageModule) return { root: dirnameWithPath(cwd, packageModule), type: 'ESM' };\n\t\treturn { root: cwd, type: 'ESM' };\n\t}\n\n\tif (packageMain) return { root: dirnameWithPath(cwd, packageMain), type: 'CommonJS' };\n\tif (packageModule) return { root: dirnameWithPath(cwd, packageModule), type: 'ESM' };\n\n\treturn { root: cwd, type: 'CommonJS' };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/internal/constants.ts"],"names":[],"mappings":";;;AAAO,IAAM,WAAc,GAAA;AACd,IAAA,8BAAA,GAAiC,OAAO,2CAA2C","file":"constants.mjs","sourcesContent":["export const VirtualPath = '::virtual::';\nexport const ManuallyRegisteredPiecesSymbol = Symbol('@sapphire/pieces:ManuallyRegisteredPieces');\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/internal/constants.ts"],"names":[],"mappings":";;;AAAO,IAAM,WAAA,GAAc;AACpB,IAAM,8BAAA,GAAiC,OAAO,2CAA2C","file":"constants.mjs","sourcesContent":["export const VirtualPath = '::virtual::';\nexport const ManuallyRegisteredPiecesSymbol = Symbol('@sapphire/pieces:ManuallyRegisteredPieces');\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/shared/Container.ts"],"names":[],"mappings":";;;AA6EO,IAAM,SAAuB,GAAA;AAAA,EACnC,MAAA,EAAQ,IAAI,aAAc;AAC3B","file":"Container.mjs","sourcesContent":["import { StoreRegistry } from '../structures/StoreRegistry';\n\n/**\n * Represents the type of the properties injected into the container, which is available at {@link container}.\n *\n * Because Sapphire works as a standalone framework (independent of external libraries), there is a need to pass data\n * from one place to another, which would vary depending on the user and their use-cases.\n *\n * Furthermore, plugins may use this structure to add properties referencing to the plugin's objects so they can be\n * accessed by both the user and the plugin at any moment and at any place.\n *\n * Finally, both library developers and bot developers should augment the Container interface from this module using\n * [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation).\n */\nexport interface Container {\n\tstores: StoreRegistry;\n}\n\n/**\n * The injected variables that will be accessible to any place. To add an extra property, simply add a property with a\n * regular assignment, and it will be available in all places simultaneously.\n *\n * @example\n * ```typescript\n * // Add a reference for the version:\n * import { container } from '@sapphire/pieces';\n *\n * container.version = '1.0.0';\n *\n * // Can be placed anywhere in a TypeScript file, for JavaScript projects,\n * // you can create an `augments.d.ts` and place the code there.\n * declare module '@sapphire/pieces' {\n * interface Container {\n * version: string;\n * }\n * }\n *\n * // In any piece, core, plugin, or custom:\n * export class UserCommand extends Command {\n * public messageRun(message, args) {\n * // The injected version is available here:\n * const { version } = this.container;\n *\n * // ...\n * }\n * }\n * ```\n *\n * @example\n * ```typescript\n * // In a plugin's context, e.g. API:\n * class Api extends Plugin {\n * static [postInitialization]() {\n * const server = new Server(this);\n * container.server = server;\n *\n * // ...\n * }\n * }\n *\n * declare module '@sapphire/pieces' {\n * interface Container {\n * server: Server;\n * }\n * }\n *\n * // In any piece, even those that aren't routes nor middlewares:\n * export class UserRoute extends Route {\n * public [methods.POST](message, args) {\n * // The injected server is available here:\n * const { server } = this.container;\n *\n * // ...\n * }\n * }\n * ```\n */\nexport const container: Container = {\n\tstores: new StoreRegistry()\n};\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/shared/Container.ts"],"names":[],"mappings":";;;AA6EO,IAAM,SAAA,GAAuB;AAAA,EACnC,MAAA,EAAQ,IAAI,aAAA;AACb","file":"Container.mjs","sourcesContent":["import { StoreRegistry } from '../structures/StoreRegistry';\n\n/**\n * Represents the type of the properties injected into the container, which is available at {@link container}.\n *\n * Because Sapphire works as a standalone framework (independent of external libraries), there is a need to pass data\n * from one place to another, which would vary depending on the user and their use-cases.\n *\n * Furthermore, plugins may use this structure to add properties referencing to the plugin's objects so they can be\n * accessed by both the user and the plugin at any moment and at any place.\n *\n * Finally, both library developers and bot developers should augment the Container interface from this module using\n * [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation).\n */\nexport interface Container {\n\tstores: StoreRegistry;\n}\n\n/**\n * The injected variables that will be accessible to any place. To add an extra property, simply add a property with a\n * regular assignment, and it will be available in all places simultaneously.\n *\n * @example\n * ```typescript\n * // Add a reference for the version:\n * import { container } from '@sapphire/pieces';\n *\n * container.version = '1.0.0';\n *\n * // Can be placed anywhere in a TypeScript file, for JavaScript projects,\n * // you can create an `augments.d.ts` and place the code there.\n * declare module '@sapphire/pieces' {\n * interface Container {\n * version: string;\n * }\n * }\n *\n * // In any piece, core, plugin, or custom:\n * export class UserCommand extends Command {\n * public messageRun(message, args) {\n * // The injected version is available here:\n * const { version } = this.container;\n *\n * // ...\n * }\n * }\n * ```\n *\n * @example\n * ```typescript\n * // In a plugin's context, e.g. API:\n * class Api extends Plugin {\n * static [postInitialization]() {\n * const server = new Server(this);\n * container.server = server;\n *\n * // ...\n * }\n * }\n *\n * declare module '@sapphire/pieces' {\n * interface Container {\n * server: Server;\n * }\n * }\n *\n * // In any piece, even those that aren't routes nor middlewares:\n * export class UserRoute extends Route {\n * public [methods.POST](message, args) {\n * // The injected server is available here:\n * const { server } = this.container;\n *\n * // ...\n * }\n * }\n * ```\n */\nexport const container: Container = {\n\tstores: new StoreRegistry()\n};\n"]}
@@ -34,6 +34,7 @@ var _LoaderStrategy = class _LoaderStrategy {
34
34
  url.searchParams.append("d", Date.now().toString());
35
35
  url.searchParams.append("name", file.name);
36
36
  url.searchParams.append("extension", file.extension);
37
+ if (Reflect.has(globalThis, "Bun")) return mjsImport(file.path + url.search);
37
38
  return mjsImport(url);
38
39
  }
39
40
  const mod = __require(file.path);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/strategies/LoaderStrategy.ts"],"names":[],"mappings":";;;;;;;;;;;AAyBO,IAAM,eAAA,GAAN,MAAM,eAA8D,CAAA;AAAA,EAKnE,WAAc,GAAA;AAJrB,IAAO,aAAA,CAAA,IAAA,EAAA,qBAAA,EAAsB,WAAY,EAAA,CAAE,IAAS,KAAA,KAAA,CAAA;AACpD,IAAA,aAAA,CAAA,IAAA,EAAO,qBAAsB,EAAA,CAAC,KAAO,EAAA,MAAA,EAAQ,MAAM,CAAA,CAAA;AACnD,IAAA,aAAA,CAAA,IAAA,EAAiB,gBAA0B,EAAA,KAAA,CAAA;AAG1C,IAAA,IAAI,sBAAwB,EAAA;AAC3B,MAAA,IAAA,CAAK,mBAAoB,CAAA,IAAA,CAAK,KAAO,EAAA,MAAA,EAAQ,MAAM,CAAA;AACnD,MAAA,IAAA,CAAK,cAAiB,GAAA,IAAA;AAAA;AACvB;AACD,EAEO,OAAO,IAA4B,EAAA;AAEzC,IAAM,MAAA,SAAA,GAAY,QAAQ,IAAI,CAAA;AAC9B,IAAA,IAAI,CAAC,IAAK,CAAA,mBAAA,CAAoB,QAAS,CAAA,SAAS,GAAU,OAAA,IAAA;AAE1D,IAAA,IAAI,KAAK,cAAkB,IAAA,IAAA,CAAK,QAAS,CAAA,OAAO,GAAU,OAAA,IAAA;AAG1D,IAAM,MAAA,IAAA,GAAO,QAAS,CAAA,IAAA,EAAM,SAAS,CAAA;AACrC,IAAA,IAAI,SAAS,E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AAA,CAAK,GAAI,CAAA,IAAA,EAAM,IAAK,CAAA,IAAI,GAAG,MAAM,CAAA;AAAA;AACvF,aACQ,KAAO,EAAA;AAIf,MAAA,IAAK,MAAwB,IAAS,KAAA,QAAA,EAAe,IAAA,CAAA,OAAA,CAAQ,OAAgB,IAAI,CAAA;AAAA;AAClF;AAEF,CAAA;AAzG2E,MAAA,CAAA,eAAA,EAAA,gBAAA,CAAA;AAApE,IAAM,cAAN,GAAA","file":"LoaderStrategy.mjs","sourcesContent":["import { type Awaitable } from '@sapphire/utilities';\nimport { opendir } from 'fs/promises';\nimport { basename, extname, join } from 'path';\nimport { pathToFileURL } from 'url';\nimport { MissingExportsError } from '../errors/MissingExportsError';\nimport { getRootData } from '../internal/RootScan';\nimport { mjsImport } from '../internal/internal';\nimport type { Piece } from '../structures/Piece';\nimport type { Store, StoreLogger } from '../structures/Store';\nimport type {\n\tAsyncPreloadResult,\n\tFilterResult,\n\tHydratedModuleData,\n\tILoaderResult,\n\tILoaderResultEntry,\n\tILoaderStrategy,\n\tModuleData\n} from './ILoaderStrategy';\nimport { classExtends, isClass } from './Shared';\nimport { CanLoadTypeScriptFiles } from './env';\n\n/**\n * A multi-purpose feature-complete loader strategy supporting multi-piece modules as well as supporting both ECMAScript\n * Modules and CommonJS with reloading support.\n */\nexport class LoaderStrategy<T extends Piece> implements ILoaderStrategy<T> {\n\tpublic clientUsesESModules = getRootData().type === 'ESM';\n\tpublic supportedExtensions = ['.js', '.cjs', '.mjs'];\n\tprivate readonly filterDtsFiles: boolean = false;\n\n\tpublic constructor() {\n\t\tif (CanLoadTypeScriptFiles) {\n\t\t\tthis.supportedExtensions.push('.ts', '.cts', '.mts');\n\t\t\tthis.filterDtsFiles = true;\n\t\t}\n\t}\n\n\tpublic filter(path: string): FilterResult {\n\t\t// Retrieve the file extension.\n\t\tconst extension = extname(path);\n\t\tif (!this.supportedExtensions.includes(extension)) return null;\n\n\t\tif (this.filterDtsFiles && path.endsWith('.d.ts')) return null;\n\n\t\t// Retrieve the name of the file, return null if empty.\n\t\tconst name = basename(path, extension);\n\t\tif (name === '' || name.startsWith('_')) return null;\n\n\t\t// Return the name and extension.\n\t\treturn { extension, path, name };\n\t}\n\n\tpublic async preload(file: ModuleData): AsyncPreloadResult<T> {\n\t\tconst mjs = ['.mjs', '.mts'].includes(file.extension) || (['.js', '.ts'].includes(file.extension) && this.clientUsesESModules);\n\t\tif (mjs) {\n\t\t\tconst url = pathToFileURL(file.path);\n\t\t\turl.searchParams.append('d', Date.now().toString());\n\t\t\turl.searchParams.append('name', file.name);\n\t\t\turl.searchParams.append('extension', file.extension);\n\t\t\treturn mjsImport(url);\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-var-requires\n\t\tconst mod = require(file.path);\n\t\tdelete require.cache[require.resolve(file.path)];\n\t\treturn mod;\n\t}\n\n\tpublic async *load(store: Store<T>, file: HydratedModuleData): ILoaderResult<T> {\n\t\tlet yielded = false;\n\t\tconst result = await this.preload(file);\n\n\t\t// Support `module.exports`:\n\t\tif (isClass(result) && classExtends(result, store.Constructor)) {\n\t\t\tyield result;\n\t\t\tyielded = true;\n\t\t}\n\n\t\t// Support any other export:\n\t\tfor (const value of Object.values(result)) {\n\t\t\tif (isClass(value) && classExtends(value, store.Constructor)) {\n\t\t\t\tyield value as ILoaderResultEntry<T>;\n\t\t\t\tyielded = true;\n\t\t\t}\n\t\t}\n\n\t\tif (!yielded) {\n\t\t\tthrow new MissingExportsError(file.path);\n\t\t}\n\t}\n\n\tpublic onLoad(store: Store<T>, piece: T): Awaitable<unknown>;\n\tpublic onLoad(): unknown {\n\t\treturn undefined;\n\t}\n\n\tpublic onLoadAll(store: Store<T>): Awaitable<unknown>;\n\tpublic onLoadAll(): unknown {\n\t\treturn undefined;\n\t}\n\n\tpublic onUnload(store: Store<T>, piece: T): Awaitable<unknown>;\n\tpublic onUnload(): unknown {\n\t\treturn undefined;\n\t}\n\n\tpublic onUnloadAll(store: Store<T>): Awaitable<unknown>;\n\tpublic onUnloadAll(): unknown {\n\t\treturn undefined;\n\t}\n\n\tpublic onError(error: Error, path: string): void {\n\t\tconsole.error(`Error when loading '${path}':`, error);\n\t}\n\n\tpublic async *walk(store: Store<T>, path: string, logger?: StoreLogger | null): AsyncIterableIterator<string> {\n\t\tlogger?.(`[STORE => ${store.name}] [WALK] Loading all pieces from '${path}'.`);\n\t\ttry {\n\t\t\tconst dir = await opendir(path);\n\t\t\tfor await (const item of dir) {\n\t\t\t\tif (item.isFile()) yield join(dir.path, item.name);\n\t\t\t\telse if (item.isDirectory()) yield* this.walk(store, join(dir.path, item.name), logger);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// Specifically ignore ENOENT, which is commonly raised by fs operations\n\t\t\t// to indicate that a component of the specified pathname does not exist.\n\t\t\t// No entity (file or directory) could be found by the given path.\n\t\t\tif ((error as ErrorWithCode).code !== 'ENOENT') this.onError(error as Error, path);\n\t\t}\n\t}\n}\n\ntype ErrorWithCode = Error & { code: string };\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/strategies/LoaderStrategy.ts"],"names":[],"mappings":";;;;;;;;;;;AAyBO,IAAM,eAAA,GAAN,MAAM,eAAA,CAA8D;AAAA,EAKnE,WAAA,GAAc;AAJrB,IAAA,aAAA,CAAA,IAAA,EAAO,qBAAA,EAAsB,WAAA,EAAY,CAAE,IAAA,KAAS,KAAA,CAAA;AACpD,IAAA,aAAA,CAAA,IAAA,EAAO,qBAAA,EAAsB,CAAC,KAAA,EAAO,MAAA,EAAQ,MAAM,CAAA,CAAA;AACnD,IAAA,aAAA,CAAA,IAAA,EAAiB,gBAAA,EAA0B,KAAA,CAAA;AAG1C,IAAA,IAAI,sBAAA,EAAwB;AAC3B,MAAA,IAAA,CAAK,mBAAA,CAAoB,IAAA,CAAK,KAAA,EAAO,MAAA,EAAQ,MAAM,CAAA;AACnD,MAAA,IAAA,CAAK,cAAA,GAAiB,IAAA;AAAA,IACvB;AAAA,EACD;AAAA,EAEO,OAAO,I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AA,EAAA,CAAA,EAAM,KAAK,CAAA;AAAA,EACrD;AAAA,EAEA,OAAc,IAAA,CAAK,KAAA,EAAiB,IAAA,EAAc,MAAA,EAA4D;AAC7G,IAAA,MAAA,GAAS,CAAA,UAAA,EAAa,KAAA,CAAM,IAAI,CAAA,kCAAA,EAAqC,IAAI,CAAA,EAAA,CAAI,CAAA;AAC7E,IAAA,IAAI;AACH,MAAA,MAAM,GAAA,GAAM,MAAM,OAAA,CAAQ,IAAI,CAAA;AAC9B,MAAA,WAAA,MAAiB,QAAQ,GAAA,EAAK;AAC7B,QAAA,IAAI,IAAA,CAAK,QAAO,EAAG,MAAM,KAAK,GAAA,CAAI,IAAA,EAAM,KAAK,IAAI,CAAA;AAAA,aAAA,IACxC,IAAA,CAAK,WAAA,EAAY,EAAG,OAAO,IAAA,CAAK,IAAA,CAAK,KAAA,EAAO,IAAA,CAAK,GAAA,CAAI,IAAA,EAAM,IAAA,CAAK,IAAI,GAAG,MAAM,CAAA;AAAA,MACvF;AAAA,IACD,SAAS,KAAA,EAAO;AAIf,MAAA,IAAK,MAAwB,IAAA,KAAS,QAAA,EAAU,IAAA,CAAK,OAAA,CAAQ,OAAgB,IAAI,CAAA;AAAA,IAClF;AAAA,EACD;AACD,CAAA;AA7G2E,MAAA,CAAA,eAAA,EAAA,gBAAA,CAAA;AAApE,IAAM,cAAA,GAAN","file":"LoaderStrategy.mjs","sourcesContent":["import { type Awaitable } from '@sapphire/utilities';\nimport { opendir } from 'fs/promises';\nimport { basename, extname, join } from 'path';\nimport { pathToFileURL } from 'url';\nimport { MissingExportsError } from '../errors/MissingExportsError';\nimport { getRootData } from '../internal/RootScan';\nimport { mjsImport } from '../internal/internal';\nimport type { Piece } from '../structures/Piece';\nimport type { Store, StoreLogger } from '../structures/Store';\nimport type {\n\tAsyncPreloadResult,\n\tFilterResult,\n\tHydratedModuleData,\n\tILoaderResult,\n\tILoaderResultEntry,\n\tILoaderStrategy,\n\tModuleData\n} from './ILoaderStrategy';\nimport { classExtends, isClass } from './Shared';\nimport { CanLoadTypeScriptFiles } from './env';\n\n/**\n * A multi-purpose feature-complete loader strategy supporting multi-piece modules as well as supporting both ECMAScript\n * Modules and CommonJS with reloading support.\n */\nexport class LoaderStrategy<T extends Piece> implements ILoaderStrategy<T> {\n\tpublic clientUsesESModules = getRootData().type === 'ESM';\n\tpublic supportedExtensions = ['.js', '.cjs', '.mjs'];\n\tprivate readonly filterDtsFiles: boolean = false;\n\n\tpublic constructor() {\n\t\tif (CanLoadTypeScriptFiles) {\n\t\t\tthis.supportedExtensions.push('.ts', '.cts', '.mts');\n\t\t\tthis.filterDtsFiles = true;\n\t\t}\n\t}\n\n\tpublic filter(path: string): FilterResult {\n\t\t// Retrieve the file extension.\n\t\tconst extension = extname(path);\n\t\tif (!this.supportedExtensions.includes(extension)) return null;\n\n\t\tif (this.filterDtsFiles && path.endsWith('.d.ts')) return null;\n\n\t\t// Retrieve the name of the file, return null if empty.\n\t\tconst name = basename(path, extension);\n\t\tif (name === '' || name.startsWith('_')) return null;\n\n\t\t// Return the name and extension.\n\t\treturn { extension, path, name };\n\t}\n\n\tpublic async preload(file: ModuleData): AsyncPreloadResult<T> {\n\t\tconst mjs = ['.mjs', '.mts'].includes(file.extension) || (['.js', '.ts'].includes(file.extension) && this.clientUsesESModules);\n\t\tif (mjs) {\n\t\t\tconst url = pathToFileURL(file.path);\n\t\t\turl.searchParams.append('d', Date.now().toString());\n\t\t\turl.searchParams.append('name', file.name);\n\t\t\turl.searchParams.append('extension', file.extension);\n\n\t\t\t// Bun workaround: Import a file path with search params instead of an file URL to force re-evaluation due to caching bug.\n\t\t\tif (Reflect.has(globalThis, 'Bun')) return mjsImport(file.path + url.search);\n\n\t\t\treturn mjsImport(url);\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-var-requires\n\t\tconst mod = require(file.path);\n\t\tdelete require.cache[require.resolve(file.path)];\n\t\treturn mod;\n\t}\n\n\tpublic async *load(store: Store<T>, file: HydratedModuleData): ILoaderResult<T> {\n\t\tlet yielded = false;\n\t\tconst result = await this.preload(file);\n\n\t\t// Support `module.exports`:\n\t\tif (isClass(result) && classExtends(result, store.Constructor)) {\n\t\t\tyield result;\n\t\t\tyielded = true;\n\t\t}\n\n\t\t// Support any other export:\n\t\tfor (const value of Object.values(result)) {\n\t\t\tif (isClass(value) && classExtends(value, store.Constructor)) {\n\t\t\t\tyield value as ILoaderResultEntry<T>;\n\t\t\t\tyielded = true;\n\t\t\t}\n\t\t}\n\n\t\tif (!yielded) {\n\t\t\tthrow new MissingExportsError(file.path);\n\t\t}\n\t}\n\n\tpublic onLoad(store: Store<T>, piece: T): Awaitable<unknown>;\n\tpublic onLoad(): unknown {\n\t\treturn undefined;\n\t}\n\n\tpublic onLoadAll(store: Store<T>): Awaitable<unknown>;\n\tpublic onLoadAll(): unknown {\n\t\treturn undefined;\n\t}\n\n\tpublic onUnload(store: Store<T>, piece: T): Awaitable<unknown>;\n\tpublic onUnload(): unknown {\n\t\treturn undefined;\n\t}\n\n\tpublic onUnloadAll(store: Store<T>): Awaitable<unknown>;\n\tpublic onUnloadAll(): unknown {\n\t\treturn undefined;\n\t}\n\n\tpublic onError(error: Error, path: string): void {\n\t\tconsole.error(`Error when loading '${path}':`, error);\n\t}\n\n\tpublic async *walk(store: Store<T>, path: string, logger?: StoreLogger | null): AsyncIterableIterator<string> {\n\t\tlogger?.(`[STORE => ${store.name}] [WALK] Loading all pieces from '${path}'.`);\n\t\ttry {\n\t\t\tconst dir = await opendir(path);\n\t\t\tfor await (const item of dir) {\n\t\t\t\tif (item.isFile()) yield join(dir.path, item.name);\n\t\t\t\telse if (item.isDirectory()) yield* this.walk(store, join(dir.path, item.name), logger);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// Specifically ignore ENOENT, which is commonly raised by fs operations\n\t\t\t// to indicate that a component of the specified pathname does not exist.\n\t\t\t// No entity (file or directory) could be found by the given path.\n\t\t\tif ((error as ErrorWithCode).code !== 'ENOENT') this.onError(error as Error, path);\n\t\t}\n\t}\n}\n\ntype ErrorWithCode = Error & { code: string };\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/strategies/Shared.ts"],"names":[],"mappings":";;;AAOO,SAAS,QAAQ,KAAuC,EAAA;AAC9D,EAAA,OAAO,OAAO,KAAA,KAAU,UAAc,IAAA,OAAO,MAAM,SAAc,KAAA,QAAA;AAClE;AAFgB,MAAA,CAAA,OAAA,EAAA,SAAA,CAAA;AAUT,SAAS,YAAA,CAAqC,OAAqB,IAAqB,EAAA;AAC9F,EAAA,IAAI,IAA4B,GAAA,KAAA;AAChC,EAAA,OAAO,SAAS,IAAM,EAAA;AACrB,IAAI,IAAA,IAAA,KAAS,MAAa,OAAA,IAAA;AAC1B,IAAO,IAAA,GAAA,MAAA,CAAO,eAAe,IAAI,CAAA;AAAA;AAGlC,EAAO,OAAA,KAAA;AACR;AARgB,MAAA,CAAA,YAAA,EAAA,cAAA,CAAA","file":"Shared.mjs","sourcesContent":["import type { AbstractCtor } from '@sapphire/utilities';\n\n/**\n * Determines whether or not a value is a class.\n * @param value The piece to be checked.\n * @private\n */\nexport function isClass(value: unknown): value is AbstractCtor {\n\treturn typeof value === 'function' && typeof value.prototype === 'object';\n}\n\n/**\n * Checks whether or not the value class extends the base class.\n * @param value The constructor to be checked against.\n * @param base The base constructor.\n * @private\n */\nexport function classExtends<T extends AbstractCtor>(value: AbstractCtor, base: T): value is T {\n\tlet ctor: AbstractCtor | null = value;\n\twhile (ctor !== null) {\n\t\tif (ctor === base) return true;\n\t\tctor = Object.getPrototypeOf(ctor);\n\t}\n\n\treturn false;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/strategies/Shared.ts"],"names":[],"mappings":";;;AAOO,SAAS,QAAQ,KAAA,EAAuC;AAC9D,EAAA,OAAO,OAAO,KAAA,KAAU,UAAA,IAAc,OAAO,MAAM,SAAA,KAAc,QAAA;AAClE;AAFgB,MAAA,CAAA,OAAA,EAAA,SAAA,CAAA;AAUT,SAAS,YAAA,CAAqC,OAAqB,IAAA,EAAqB;AAC9F,EAAA,IAAI,IAAA,GAA4B,KAAA;AAChC,EAAA,OAAO,SAAS,IAAA,EAAM;AACrB,IAAA,IAAI,IAAA,KAAS,MAAM,OAAO,IAAA;AAC1B,IAAA,IAAA,GAAO,MAAA,CAAO,eAAe,IAAI,CAAA;AAAA,EAClC;AAEA,EAAA,OAAO,KAAA;AACR;AARgB,MAAA,CAAA,YAAA,EAAA,cAAA,CAAA","file":"Shared.mjs","sourcesContent":["import type { AbstractCtor } from '@sapphire/utilities';\n\n/**\n * Determines whether or not a value is a class.\n * @param value The piece to be checked.\n * @private\n */\nexport function isClass(value: unknown): value is AbstractCtor {\n\treturn typeof value === 'function' && typeof value.prototype === 'object';\n}\n\n/**\n * Checks whether or not the value class extends the base class.\n * @param value The constructor to be checked against.\n * @param base The base constructor.\n * @private\n */\nexport function classExtends<T extends AbstractCtor>(value: AbstractCtor, base: T): value is T {\n\tlet ctor: AbstractCtor | null = value;\n\twhile (ctor !== null) {\n\t\tif (ctor === base) return true;\n\t\tctor = Object.getPrototypeOf(ctor);\n\t}\n\n\treturn false;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/strategies/env.ts"],"names":[],"mappings":";;;AAEA,SAAS,iBAAiB,IAAc,EAAA;AACvC,EACC,OAAA,OAAA,CAAQ,SAAS,IAAK,CAAA,CAAC,QAAQ,GAAI,CAAA,QAAA,CAAS,IAAI,CAAC,CAAA;AAAA,EACjD,OAAA,CAAQ,KAAK,IAAK,CAAA,CAAC,QAAQ,GAAI,CAAA,QAAA,CAAS,IAAI,CAAC,CAAA;AAE/C;AALS,MAAA,CAAA,gBAAA,EAAA,kBAAA,CAAA;AAOT,SAAS,oBAAoB,IAAc,EAAA;AAC1C,EAAO,OAAA,kBAAA,IAAsB,OAAY,IAAA,OAAA,CAAQ,gBAA8B,CAAA,IAAA,CAAK,CAAC,MAAW,KAAA,MAAA,CAAO,QAAS,CAAA,IAAI,CAAC,CAAA;AACtH;AAFS,MAAA,CAAA,mBAAA,EAAA,qBAAA,CAAA;AAIT,SAAS,gBAAA,CAAiB,MAAc,KAAgB,EAAA;AACvD,EAAO,OAAA,KAAA,GAAQ,OAAQ,CAAA,GAAA,CAAI,IAAI,CAAA,KAAM,KAAQ,GAAA,CAAC,SAAU,CAAA,OAAA,CAAQ,GAAI,CAAA,IAAI,CAAC,CAAA;AAC1E;AAFS,MAAA,CAAA,gBAAA,EAAA,kBAAA,CAAA;AAqBI,IAAA,sBAAA;AAAA;AAAA;AAAA,EAGZ,OAAA,CAAQ,GAAI,CAAA,UAAA,EAAY,MAAM,CAAA;AAAA;AAAA,EAG9B,QAAQ,GAAI,CAAA,UAAA,EAAY,KAAK,CAAA,IAC7B,SAAS,OAAQ,CAAA,QAAA;AAAA;AAAA;AAAA,EAIjB,MAAA,CAAO,GAAI,CAAA,2BAA2B,CAAK,IAAA,OAAA;AAAA,EAE3C,iBAAiB,aAAa,CAAA;AAAA,EAE9B,CAAC,SAAA,CAAU,OAAQ,CAAA,GAAA,CAAI,WAAW,CAAA;AAAA;AAAA,EAGlC,iBAAiB,YAAY,CAAA;AAAA;AAAA,EAG7B,gBAAiB,CAAA,QAAA,EAAU,MAAM,CAAA,IACjC,iBAAiB,kBAAkB,CAAA;AAAA;AAAA,EAGnC,iBAAiB,gBAAgB,CAAA;AAAA;AAAA,EAGjC,oBAAoB,eAAe,CAAA;AAAA,EACnC,mBAAoB,CAAA,oBAAoB,CACxC,IAAA,gBAAA,CAAiB,eAAe,CAAA;AAAA;AAAA,EAGhC,oBAAoB,KAAK,CAAA;AAAA;AAAA,EAGzB,oBAAoB,kBAAkB,CAAA;AAAA;AAAA,EAGtC,oBAAoB,KAAK;AAAA","file":"env.mjs","sourcesContent":["import { isNullish } from '@sapphire/utilities';\n\nfunction checkProcessArgv(name: string) {\n\treturn (\n\t\tprocess.execArgv.some((arg) => arg.includes(name)) || //\n\t\tprocess.argv.some((arg) => arg.includes(name))\n\t);\n}\n\nfunction checkPreloadModules(name: string) {\n\treturn '_preload_modules' in process && (process._preload_modules as string[]).some((module) => module.includes(name));\n}\n\nfunction checkEnvVariable(name: string, value?: string) {\n\treturn value ? process.env[name] === value : !isNullish(process.env[name]);\n}\n\n/**\n * Whether or not the current environment can load TypeScript files. These\n * conditions are based on the most common tools and runtimes that support\n * loading TypeScript files directly.\n *\n * - {@linkplain https://www.npmjs.com/package/ts-node | `ts-node`}\n * - {@linkplain https://www.npmjs.com/package/ts-node-dev | `ts-node-dev`}\n * - {@linkplain https://www.npmjs.com/package/@babel/node | `@babel/node`}\n * - {@linkplain https://www.npmjs.com/package/vitest | `vitest`}\n * - {@linkplain https://www.npmjs.com/package/jest | `jest`}\n * - {@linkplain https://www.npmjs.com/package/@swc/cli | `swc`}\n * - {@linkplain https://www.npmjs.com/package/tsm | `tsm`}\n * - {@linkplain https://www.npmjs.com/package/esbuild | `esbuild`}\n * - {@linkplain https://www.npmjs.com/package/tsx | `tsx`}\n * - {@linkplain https://deno.com | `Deno`}\n * - {@linkplain https://bun.sh | `Bun`}\n */\nexport const CanLoadTypeScriptFiles: boolean =\n\t//\n\t// Deno\n\tReflect.has(globalThis, 'Deno') ||\n\t//\n\t// Bun\n\tReflect.has(globalThis, 'Bun') ||\n\t'bun' in process.versions ||\n\t//\n\t// ts-node\n\t// > --require ts-node/register\n\tSymbol.for('ts-node.register.instance') in process ||\n\t// > --loader ts-node/esm\n\tcheckProcessArgv('ts-node/esm') ||\n\t// > ts-node-dev\n\t!isNullish(process.env.TS_NODE_DEV) ||\n\t//\n\t// @babel/node\n\tcheckProcessArgv('babel-node') ||\n\t//\n\t// vitest\n\tcheckEnvVariable('VITEST', 'true') ||\n\tcheckEnvVariable('VITEST_WORKER_ID') ||\n\t//\n\t// jest\n\tcheckEnvVariable('JEST_WORKER_ID') ||\n\t//\n\t// swc\n\tcheckPreloadModules('@swc/register') || //\n\tcheckPreloadModules('@swc-node/register') ||\n\tcheckProcessArgv('.bin/swc-node') ||\n\t//\n\t// tsm\n\tcheckPreloadModules('tsm') ||\n\t//\n\t// esbuild\n\tcheckPreloadModules('esbuild-register') ||\n\t//\n\t// tsx\n\tcheckPreloadModules('tsx');\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/strategies/env.ts"],"names":[],"mappings":";;;AAEA,SAAS,iBAAiB,IAAA,EAAc;AACvC,EAAA,OACC,OAAA,CAAQ,SAAS,IAAA,CAAK,CAAC,QAAQ,GAAA,CAAI,QAAA,CAAS,IAAI,CAAC,CAAA;AAAA,EACjD,OAAA,CAAQ,KAAK,IAAA,CAAK,CAAC,QAAQ,GAAA,CAAI,QAAA,CAAS,IAAI,CAAC,CAAA;AAE/C;AALS,MAAA,CAAA,gBAAA,EAAA,kBAAA,CAAA;AAOT,SAAS,oBAAoB,IAAA,EAAc;AAC1C,EAAA,OAAO,kBAAA,IAAsB,OAAA,IAAY,OAAA,CAAQ,gBAAA,CAA8B,IAAA,CAAK,CAAC,MAAA,KAAW,MAAA,CAAO,QAAA,CAAS,IAAI,CAAC,CAAA;AACtH;AAFS,MAAA,CAAA,mBAAA,EAAA,qBAAA,CAAA;AAIT,SAAS,gBAAA,CAAiB,MAAc,KAAA,EAAgB;AACvD,EAAA,OAAO,KAAA,GAAQ,OAAA,CAAQ,GAAA,CAAI,IAAI,CAAA,KAAM,KAAA,GAAQ,CAAC,SAAA,CAAU,OAAA,CAAQ,GAAA,CAAI,IAAI,CAAC,CAAA;AAC1E;AAFS,MAAA,CAAA,gBAAA,EAAA,kBAAA,CAAA;AAqBF,IAAM,sBAAA;AAAA;AAAA;AAAA,EAGZ,OAAA,CAAQ,GAAA,CAAI,UAAA,EAAY,MAAM,CAAA;AAAA;AAAA,EAG9B,QAAQ,GAAA,CAAI,UAAA,EAAY,KAAK,CAAA,IAC7B,SAAS,OAAA,CAAQ,QAAA;AAAA;AAAA;AAAA,EAIjB,MAAA,CAAO,GAAA,CAAI,2BAA2B,CAAA,IAAK,OAAA;AAAA,EAE3C,iBAAiB,aAAa,CAAA;AAAA,EAE9B,CAAC,SAAA,CAAU,OAAA,CAAQ,GAAA,CAAI,WAAW,CAAA;AAAA;AAAA,EAGlC,iBAAiB,YAAY,CAAA;AAAA;AAAA,EAG7B,gBAAA,CAAiB,QAAA,EAAU,MAAM,CAAA,IACjC,iBAAiB,kBAAkB,CAAA;AAAA;AAAA,EAGnC,iBAAiB,gBAAgB,CAAA;AAAA;AAAA,EAGjC,oBAAoB,eAAe,CAAA;AAAA,EACnC,mBAAA,CAAoB,oBAAoB,CAAA,IACxC,gBAAA,CAAiB,eAAe,CAAA;AAAA;AAAA,EAGhC,oBAAoB,KAAK,CAAA;AAAA;AAAA,EAGzB,oBAAoB,kBAAkB,CAAA;AAAA;AAAA,EAGtC,oBAAoB,KAAK;AAAA","file":"env.mjs","sourcesContent":["import { isNullish } from '@sapphire/utilities';\n\nfunction checkProcessArgv(name: string) {\n\treturn (\n\t\tprocess.execArgv.some((arg) => arg.includes(name)) || //\n\t\tprocess.argv.some((arg) => arg.includes(name))\n\t);\n}\n\nfunction checkPreloadModules(name: string) {\n\treturn '_preload_modules' in process && (process._preload_modules as string[]).some((module) => module.includes(name));\n}\n\nfunction checkEnvVariable(name: string, value?: string) {\n\treturn value ? process.env[name] === value : !isNullish(process.env[name]);\n}\n\n/**\n * Whether or not the current environment can load TypeScript files. These\n * conditions are based on the most common tools and runtimes that support\n * loading TypeScript files directly.\n *\n * - {@linkplain https://www.npmjs.com/package/ts-node | `ts-node`}\n * - {@linkplain https://www.npmjs.com/package/ts-node-dev | `ts-node-dev`}\n * - {@linkplain https://www.npmjs.com/package/@babel/node | `@babel/node`}\n * - {@linkplain https://www.npmjs.com/package/vitest | `vitest`}\n * - {@linkplain https://www.npmjs.com/package/jest | `jest`}\n * - {@linkplain https://www.npmjs.com/package/@swc/cli | `swc`}\n * - {@linkplain https://www.npmjs.com/package/tsm | `tsm`}\n * - {@linkplain https://www.npmjs.com/package/esbuild | `esbuild`}\n * - {@linkplain https://www.npmjs.com/package/tsx | `tsx`}\n * - {@linkplain https://deno.com | `Deno`}\n * - {@linkplain https://bun.sh | `Bun`}\n */\nexport const CanLoadTypeScriptFiles: boolean =\n\t//\n\t// Deno\n\tReflect.has(globalThis, 'Deno') ||\n\t//\n\t// Bun\n\tReflect.has(globalThis, 'Bun') ||\n\t'bun' in process.versions ||\n\t//\n\t// ts-node\n\t// > --require ts-node/register\n\tSymbol.for('ts-node.register.instance') in process ||\n\t// > --loader ts-node/esm\n\tcheckProcessArgv('ts-node/esm') ||\n\t// > ts-node-dev\n\t!isNullish(process.env.TS_NODE_DEV) ||\n\t//\n\t// @babel/node\n\tcheckProcessArgv('babel-node') ||\n\t//\n\t// vitest\n\tcheckEnvVariable('VITEST', 'true') ||\n\tcheckEnvVariable('VITEST_WORKER_ID') ||\n\t//\n\t// jest\n\tcheckEnvVariable('JEST_WORKER_ID') ||\n\t//\n\t// swc\n\tcheckPreloadModules('@swc/register') || //\n\tcheckPreloadModules('@swc-node/register') ||\n\tcheckProcessArgv('.bin/swc-node') ||\n\t//\n\t// tsm\n\tcheckPreloadModules('tsm') ||\n\t//\n\t// esbuild\n\tcheckPreloadModules('esbuild-register') ||\n\t//\n\t// tsx\n\tcheckPreloadModules('tsx');\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/AliasPiece.ts"],"names":["AliasPiece"],"mappings":";;;AAcO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAiI,KAG5I,CAAA;AAAA,EAMM,WAAY,CAAA,OAAA,EAA8C,OAA6B,GAAA,EAAI,EAAA;AACjG,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAHvB;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA;AAIN,IAAK,IAAA,CAAA,OAAA,GAAU,OAAQ,CAAA,OAAA,IAAW,EAAC;AAAA;AACpC;AAAA;AAAA;AAAA,EAKgB,MAA0B,GAAA;AACzC,IAAO,OAAA;AAAA,MACN,GAAG,MAAM,MAAO,EAAA;AAAA,MAChB,OAAA,EAAS,IAAK,CAAA,OAAA,CAAQ,KAAM;AAAA,KAC7B;AAAA;AAEF,CAAA;AApBE,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAHK,IAAM,UAAN,GAAA;AAAA,CAiCA,CAAUA,WAAV,KAAA;AACC,EAAM,CAAA,EAAE,QAAAA,EAAAA,WAAAA,CAAA,QAAa,EAAA,GAAA,KAAA;AAAA,CADZ,EAAA,UAAA,KAAA,UAAA,GAAA,EAAA,CAAA,CAAA","file":"AliasPiece.mjs","sourcesContent":["import { Piece } from './Piece';\nimport type { StoreRegistryKey } from './StoreRegistry';\n\nexport interface AliasPieceOptions extends Piece.Options {\n\t/**\n\t * The aliases for the piece.\n\t * @default []\n\t */\n\treadonly aliases?: readonly string[];\n}\n\n/**\n * The piece to be stored in {@link AliasStore} instances.\n */\nexport class AliasPiece<Options extends AliasPieceOptions = AliasPieceOptions, StoreName extends StoreRegistryKey = StoreRegistryKey> extends Piece<\n\tOptions,\n\tStoreName\n> {\n\t/**\n\t * The aliases for the piece.\n\t */\n\tpublic aliases: readonly string[];\n\n\tpublic constructor(context: AliasPiece.LoaderContext<StoreName>, options: AliasPieceOptions = {}) {\n\t\tsuper(context, options);\n\t\tthis.aliases = options.aliases ?? [];\n\t}\n\n\t/**\n\t * Defines the `JSON.stringify` behavior of this alias piece.\n\t */\n\tpublic override toJSON(): AliasPiece.JSON {\n\t\treturn {\n\t\t\t...super.toJSON(),\n\t\t\taliases: this.aliases.slice()\n\t\t};\n\t}\n}\n\n/**\n * The return type of {@link AliasPiece.toJSON}.\n */\nexport interface AliasPieceJSON extends Piece.JSON {\n\taliases: string[];\n\toptions: AliasPieceOptions;\n}\n\nexport namespace AliasPiece {\n\texport const { Location } = Piece;\n\texport type Options = AliasPieceOptions;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context<StoreName extends StoreRegistryKey = StoreRegistryKey> = Piece.LoaderContext<StoreName>;\n\texport type LoaderContext<StoreName extends StoreRegistryKey = StoreRegistryKey> = Piece.LoaderContext<StoreName>;\n\texport type JSON = AliasPieceJSON;\n\texport type LocationJSON = Piece.LocationJSON;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/AliasPiece.ts"],"names":["AliasPiece"],"mappings":";;;AAcO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAiI,KAAA,CAG5I;AAAA,EAMM,WAAA,CAAY,OAAA,EAA8C,OAAA,GAA6B,EAAC,EAAG;AACjG,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAHvB;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,SAAA,CAAA;AAIN,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA,CAAQ,OAAA,IAAW,EAAC;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA,EAKgB,MAAA,GAA0B;AACzC,IAAA,OAAO;AAAA,MACN,GAAG,MAAM,MAAA,EAAO;AAAA,MAChB,OAAA,EAAS,IAAA,CAAK,OAAA,CAAQ,KAAA;AAAM,KAC7B;AAAA,EACD;AACD,CAAA;AApBE,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAHK,IAAM,UAAA,GAAN;AAAA,CAiCA,CAAUA,WAAAA,KAAV;AACC,EAAA,CAAM,EAAE,QAAA,EAAAA,WAAAA,CAAA,QAAA,EAAA,GAAa,KAAA;AAAA,CAAA,EADZ,UAAA,KAAA,UAAA,GAAA,EAAA,CAAA,CAAA","file":"AliasPiece.mjs","sourcesContent":["import { Piece } from './Piece';\nimport type { StoreRegistryKey } from './StoreRegistry';\n\nexport interface AliasPieceOptions extends Piece.Options {\n\t/**\n\t * The aliases for the piece.\n\t * @default []\n\t */\n\treadonly aliases?: readonly string[];\n}\n\n/**\n * The piece to be stored in {@link AliasStore} instances.\n */\nexport class AliasPiece<Options extends AliasPieceOptions = AliasPieceOptions, StoreName extends StoreRegistryKey = StoreRegistryKey> extends Piece<\n\tOptions,\n\tStoreName\n> {\n\t/**\n\t * The aliases for the piece.\n\t */\n\tpublic aliases: readonly string[];\n\n\tpublic constructor(context: AliasPiece.LoaderContext<StoreName>, options: AliasPieceOptions = {}) {\n\t\tsuper(context, options);\n\t\tthis.aliases = options.aliases ?? [];\n\t}\n\n\t/**\n\t * Defines the `JSON.stringify` behavior of this alias piece.\n\t */\n\tpublic override toJSON(): AliasPiece.JSON {\n\t\treturn {\n\t\t\t...super.toJSON(),\n\t\t\taliases: this.aliases.slice()\n\t\t};\n\t}\n}\n\n/**\n * The return type of {@link AliasPiece.toJSON}.\n */\nexport interface AliasPieceJSON extends Piece.JSON {\n\taliases: string[];\n\toptions: AliasPieceOptions;\n}\n\nexport namespace AliasPiece {\n\texport const { Location } = Piece;\n\texport type Options = AliasPieceOptions;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context<StoreName extends StoreRegistryKey = StoreRegistryKey> = Piece.LoaderContext<StoreName>;\n\texport type LoaderContext<StoreName extends StoreRegistryKey = StoreRegistryKey> = Piece.LoaderContext<StoreName>;\n\texport type JSON = AliasPieceJSON;\n\texport type LocationJSON = Piece.LocationJSON;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/AliasStore.ts"],"names":[],"mappings":";;;;AAQO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAgG,KAAoB,CAAA;AAAA,EAA1H,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,SAAA,EAAU,IAAI,UAAsB,EAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMpC,IAAI,GAA4B,EAAA;AAC/C,IAAA,OAAO,MAAM,GAAI,CAAA,GAAG,KAAK,IAAK,CAAA,OAAA,CAAQ,IAAI,GAAG,CAAA;AAAA;AAC9C;AAAA;AAAA;AAAA;AAAA,EAMgB,IAAI,GAAsB,EAAA;AACzC,IAAA,OAAO,MAAM,GAAI,CAAA,GAAG,KAAK,IAAK,CAAA,OAAA,CAAQ,IAAI,GAAG,CAAA;AAAA;AAC9C;AAAA;AAAA;AAAA;AAAA;AAAA,EAOgB,OAAO,IAA8B,EAAA;AACpD,IAAM,MAAA,KAAA,GAAQ,IAAK,CAAA,OAAA,CAAQ,IAAI,CAAA;AAG/B,IAAW,KAAA,MAAA,KAAA,IAAS,MAAM,OAAS,EAAA;AAElC,MAAA,MAAM,UAAa,GAAA,IAAA,CAAK,OAAQ,CAAA,GAAA,CAAI,KAAK,CAAA;AACzC,MAAA,IAAI,UAAe,KAAA,KAAA,EAAY,IAAA,CAAA,OAAA,CAAQ,OAAO,KAAK,CAAA;AAAA;AAGpD,IAAO,OAAA,KAAA,CAAM,OAAO,KAAK,CAAA;AAAA;AAC1B;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAsB,OAAO,KAAU,EAAA;AACtC,IAAW,KAAA,MAAA,GAAA,IAAO,MAAM,OAAS,EAAA;AAChC,MAAK,IAAA,CAAA,OAAA,CAAQ,GAAI,CAAA,GAAA,EAAK,KAAK,CAAA;AAAA;AAG5B,IAAO,OAAA,KAAA,CAAM,OAAO,KAAK,CAAA;AAAA;AAE3B,CAAA;AApDiI,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAA1H,IAAM,UAAN,GAAA","file":"AliasStore.mjs","sourcesContent":["import { Collection } from '@discordjs/collection';\nimport type { AliasPiece } from './AliasPiece';\nimport { Store } from './Store';\nimport type { StoreRegistryKey } from './StoreRegistry';\n\n/**\n * The store class which contains {@link AliasPiece}s.\n */\nexport class AliasStore<T extends AliasPiece, StoreName extends StoreRegistryKey = StoreRegistryKey> extends Store<T, StoreName> {\n\t/**\n\t * The aliases referencing to pieces.\n\t */\n\tpublic readonly aliases = new Collection<string, T>();\n\n\t/**\n\t * Looks up the name by the store, falling back to an alias lookup.\n\t * @param key The key to look for.\n\t */\n\tpublic override get(key: string): T | undefined {\n\t\treturn super.get(key) ?? this.aliases.get(key);\n\t}\n\n\t/**\n\t * Checks whether a key is in the store, or is an alias\n\t * @param key The key to check\n\t */\n\tpublic override has(key: string): boolean {\n\t\treturn super.has(key) || this.aliases.has(key);\n\t}\n\n\t/**\n\t * Unloads a piece given its instance or its name, and removes all the aliases.\n\t * @param name The name of the file to load.\n\t * @return Returns the piece that was unloaded.\n\t */\n\tpublic override unload(name: string | T): Promise<T> {\n\t\tconst piece = this.resolve(name);\n\n\t\t// Unload all aliases for the given piece:\n\t\tfor (const alias of piece.aliases) {\n\t\t\t// We don't want to delete aliases that were overriden by another piece:\n\t\t\tconst aliasPiece = this.aliases.get(alias);\n\t\t\tif (aliasPiece === piece) this.aliases.delete(alias);\n\t\t}\n\n\t\treturn super.unload(piece);\n\t}\n\n\t/**\n\t * Inserts a piece into the store, and adds all the aliases.\n\t * @param piece The piece to be inserted into the store.\n\t * @return The inserted piece.\n\t */\n\tpublic override async insert(piece: T) {\n\t\tfor (const key of piece.aliases) {\n\t\t\tthis.aliases.set(key, piece);\n\t\t}\n\n\t\treturn super.insert(piece);\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/AliasStore.ts"],"names":[],"mappings":";;;;AAQO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAgG,KAAA,CAAoB;AAAA,EAA1H,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,SAAA,EAAU,IAAI,UAAA,EAAsB,CAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMpC,IAAI,GAAA,EAA4B;AAC/C,IAAA,OAAO,MAAM,GAAA,CAAI,GAAG,KAAK,IAAA,CAAK,OAAA,CAAQ,IAAI,GAAG,CAAA;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMgB,IAAI,GAAA,EAAsB;AACzC,IAAA,OAAO,MAAM,GAAA,CAAI,GAAG,KAAK,IAAA,CAAK,OAAA,CAAQ,IAAI,GAAG,CAAA;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOgB,OAAO,IAAA,EAA8B;AACpD,IAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,OAAA,CAAQ,IAAI,CAAA;AAG/B,IAAA,KAAA,MAAW,KAAA,IAAS,MAAM,OAAA,EAAS;AAElC,MAAA,MAAM,UAAA,GAAa,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,KAAK,CAAA;AACzC,MAAA,IAAI,UAAA,KAAe,KAAA,EAAO,IAAA,CAAK,OAAA,CAAQ,OAAO,KAAK,CAAA;AAAA,IACpD;AAEA,IAAA,OAAO,KAAA,CAAM,OAAO,KAAK,CAAA;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAsB,OAAO,KAAA,EAAU;AACtC,IAAA,KAAA,MAAW,GAAA,IAAO,MAAM,OAAA,EAAS;AAChC,MAAA,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,GAAA,EAAK,KAAK,CAAA;AAAA,IAC5B;AAEA,IAAA,OAAO,KAAA,CAAM,OAAO,KAAK,CAAA;AAAA,EAC1B;AACD,CAAA;AApDiI,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAA1H,IAAM,UAAA,GAAN","file":"AliasStore.mjs","sourcesContent":["import { Collection } from '@discordjs/collection';\nimport type { AliasPiece } from './AliasPiece';\nimport { Store } from './Store';\nimport type { StoreRegistryKey } from './StoreRegistry';\n\n/**\n * The store class which contains {@link AliasPiece}s.\n */\nexport class AliasStore<T extends AliasPiece, StoreName extends StoreRegistryKey = StoreRegistryKey> extends Store<T, StoreName> {\n\t/**\n\t * The aliases referencing to pieces.\n\t */\n\tpublic readonly aliases = new Collection<string, T>();\n\n\t/**\n\t * Looks up the name by the store, falling back to an alias lookup.\n\t * @param key The key to look for.\n\t */\n\tpublic override get(key: string): T | undefined {\n\t\treturn super.get(key) ?? this.aliases.get(key);\n\t}\n\n\t/**\n\t * Checks whether a key is in the store, or is an alias\n\t * @param key The key to check\n\t */\n\tpublic override has(key: string): boolean {\n\t\treturn super.has(key) || this.aliases.has(key);\n\t}\n\n\t/**\n\t * Unloads a piece given its instance or its name, and removes all the aliases.\n\t * @param name The name of the file to load.\n\t * @return Returns the piece that was unloaded.\n\t */\n\tpublic override unload(name: string | T): Promise<T> {\n\t\tconst piece = this.resolve(name);\n\n\t\t// Unload all aliases for the given piece:\n\t\tfor (const alias of piece.aliases) {\n\t\t\t// We don't want to delete aliases that were overriden by another piece:\n\t\t\tconst aliasPiece = this.aliases.get(alias);\n\t\t\tif (aliasPiece === piece) this.aliases.delete(alias);\n\t\t}\n\n\t\treturn super.unload(piece);\n\t}\n\n\t/**\n\t * Inserts a piece into the store, and adds all the aliases.\n\t * @param piece The piece to be inserted into the store.\n\t * @return The inserted piece.\n\t */\n\tpublic override async insert(piece: T) {\n\t\tfor (const key of piece.aliases) {\n\t\t\tthis.aliases.set(key, piece);\n\t\t}\n\n\t\treturn super.insert(piece);\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/Piece.ts"],"names":["Piece"],"mappings":";;;;AAuDO,IAAM,MAAA,GAAN,MAAM,MAA0G,CAAA;AAAA,EA0B/G,WAAY,CAAA,OAAA,EAAyC,OAAwB,GAAA,EAAI,EAAA;AAtBxF;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA;AAKP;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA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A;AAAhH,IAAM,KAAN,GAAA;AAAA,CAgGA,CAAUA,MAAV,KAAA;AACC,EAAMA,OAAA,QAAW,GAAA,aAAA;AAAA,CADR,EAAA,KAAA,KAAA,KAAA,GAAA,EAAA,CAAA,CAAA","file":"Piece.mjs","sourcesContent":["import type { Awaitable } from '@sapphire/utilities';\nimport { container, type Container } from '../shared/Container';\nimport { PieceLocation, type PieceLocationJSON } from './PieceLocation';\nimport type { Store } from './Store';\nimport type { StoreOf, StoreRegistryKey } from './StoreRegistry';\n\n/**\n * The context for the piece, contains extra information from the store,\n * the piece's path, and the store that loaded it.\n */\nexport interface LoaderPieceContext<StoreName extends StoreRegistryKey = StoreRegistryKey> {\n\t/**\n\t * The root directory the piece was loaded from.\n\t */\n\treadonly root: string;\n\n\t/**\n\t * The path the module was loaded from, relative to {@link LoaderPieceContext.root}.\n\t */\n\treadonly path: string;\n\n\t/**\n\t * The module's name extracted from the path.\n\t */\n\treadonly name: string;\n\n\t/**\n\t * The store that loaded the piece.\n\t */\n\treadonly store: StoreOf<StoreName>;\n}\n\n/** @deprecated Use {@linkcode LoaderPieceContext} instead. */\nexport interface PieceContext<StoreName extends StoreRegistryKey = StoreRegistryKey> extends LoaderPieceContext<StoreName> {}\n\n/**\n * The options for the {@link Piece}.\n */\nexport interface PieceOptions {\n\t/**\n\t * The name for the piece.\n\t * @default ''\n\t */\n\treadonly name?: string;\n\n\t/**\n\t * Whether or not the piece should be enabled. If set to false, the piece will be unloaded.\n\t * @default true\n\t */\n\treadonly enabled?: boolean;\n}\n\n/**\n * The piece to be stored in {@link Store} instances.\n */\nexport class Piece<Options extends PieceOptions = PieceOptions, StoreName extends StoreRegistryKey = StoreRegistryKey> {\n\t/**\n\t * The store that contains the piece.\n\t */\n\tpublic readonly store: StoreOf<StoreName>;\n\n\t/**\n\t * The location metadata for the piece's file.\n\t */\n\tpublic readonly location: PieceLocation;\n\n\t/**\n\t * The name of the piece.\n\t */\n\tpublic readonly name: string;\n\n\t/**\n\t * Whether or not the piece is enabled.\n\t */\n\tpublic enabled: boolean;\n\n\t/**\n\t * The raw options passed to this {@link Piece}\n\t */\n\tpublic readonly options: Options;\n\n\tpublic constructor(context: Piece.LoaderContext<StoreName>, options: PieceOptions = {}) {\n\t\tthis.store = context.store;\n\t\tthis.location = new PieceLocation(context.path, context.root);\n\t\tthis.name = options.name ?? context.name;\n\t\tthis.enabled = options.enabled ?? true;\n\t\tthis.options = options as Options;\n\t}\n\n\t/**\n\t * A reference to the {@link Container} object for ease of use.\n\t * @see container\n\t */\n\tpublic get container(): Container {\n\t\treturn container;\n\t}\n\n\t/**\n\t * Per-piece listener that is called when the piece is loaded into the store.\n\t * Useful to set-up asynchronous initialization tasks.\n\t */\n\tpublic onLoad(): Awaitable<unknown> {\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Per-piece listener that is called when the piece is unloaded from the store.\n\t * Useful to set-up clean-up tasks.\n\t */\n\tpublic onUnload(): Awaitable<unknown> {\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Unloads and disables the piece.\n\t */\n\tpublic async unload() {\n\t\tawait this.store.unload(this.name);\n\t\tthis.enabled = false;\n\t}\n\n\t/**\n\t * Reloads the piece by loading the same path in the store.\n\t */\n\tpublic async reload() {\n\t\tawait this.store.load(this.location.root, this.location.relative);\n\t}\n\n\t/**\n\t * Defines the `JSON.stringify` behavior of this piece.\n\t */\n\tpublic toJSON(): PieceJSON {\n\t\treturn {\n\t\t\tlocation: this.location.toJSON(),\n\t\t\tname: this.name,\n\t\t\tenabled: this.enabled,\n\t\t\toptions: this.options\n\t\t};\n\t}\n}\n\n/**\n * The return type of {@link Piece.toJSON}.\n */\nexport interface PieceJSON {\n\tlocation: PieceLocationJSON;\n\tname: string;\n\tenabled: boolean;\n\toptions: PieceOptions;\n}\n\nexport namespace Piece {\n\texport const Location = PieceLocation;\n\texport type Options = PieceOptions;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context<StoreName extends StoreRegistryKey = StoreRegistryKey> = LoaderPieceContext<StoreName>;\n\texport type LoaderContext<StoreName extends StoreRegistryKey = StoreRegistryKey> = LoaderPieceContext<StoreName>;\n\texport type JSON = PieceJSON;\n\texport type LocationJSON = PieceLocationJSON;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/Piece.ts"],"names":["Piece"],"mappings":";;;;AAuDO,IAAM,MAAA,GAAN,MAAM,MAAA,CAA0G;AAAA,EA0B/G,WAAA,CAAY,OAAA,EAAyC,OAAA,GAAwB,EAAC,EAAG;AAtBxF;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,OAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,UAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,MAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,SAAA,CAAA;AAKP;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,SAAA,CAAA;AAGf,IAAA,IAAA,CAAK,QAAQ,OAAA,CAAQ,KAAA;AACrB,IAAA,IAAA,CAAK,WAAW,IAAI,aAAA,CAAc,OAAA,CAAQ,IAAA,EAAM,QAAQ,IAAI,CAAA;AAC5D,IAAA,IAAA,CAAK,IAAA,GAAO,OAAA,CAAQ,IAAA,IAAQ,OAAA,CAAQ,IAAA;AACpC,IAAA,IAAA,CAAK,OAAA,GAAU,QAAQ,OAAA,IAAW,IAAA;AAClC,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAW,SAAA,GAAuB;AACjC,IAAA,OAAO,SAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,MAAA,GAA6B;AACnC,IAAA,OAAO,MAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,QAAA,GAA+B;AACrC,IAAA,OAAO,MAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAKA,MAAa,MAAA,GAAS;AACrB,IAAA,MAAM,IAAA,CAAK,KAAA,CAAM,MAAA,CAAO,IAAA,CAAK,IAAI,CAAA;AACjC,IAAA,IAAA,CAAK,OAAA,GAAU,KAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAa,MAAA,GAAS;AACrB,IAAA,MAAM,IAAA,CAAK,MAAM,IAAA,CAAK,IAAA,CAAK,SAAS,IAAA,EAAM,IAAA,CAAK,SAAS,QAAQ,CAAA;AAAA,EACjE;AAAA;AAAA;AAAA;AAAA,EAKO,MAAA,GAAoB;AAC1B,IAAA,OAAO;AAAA,MACN,QAAA,EAAU,IAAA,CAAK,QAAA,CAAS,MAAA,EAAO;AAAA,MAC/B,MAAM,IAAA,CAAK,IAAA;AAAA,MACX,SAAS,IAAA,CAAK,OAAA;AAAA,MACd,SAAS,IAAA,CAAK;AAAA,KACf;AAAA,EACD;AACD,CAAA;AApFuH,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA;AAAhH,IAAM,KAAA,GAAN;AAAA,CAgGA,CAAUA,MAAAA,KAAV;AACC,EAAMA,OAAA,QAAA,GAAW,aAAA;AAAA,CAAA,EADR,KAAA,KAAA,KAAA,GAAA,EAAA,CAAA,CAAA","file":"Piece.mjs","sourcesContent":["import type { Awaitable } from '@sapphire/utilities';\nimport { container, type Container } from '../shared/Container';\nimport { PieceLocation, type PieceLocationJSON } from './PieceLocation';\nimport type { Store } from './Store';\nimport type { StoreOf, StoreRegistryKey } from './StoreRegistry';\n\n/**\n * The context for the piece, contains extra information from the store,\n * the piece's path, and the store that loaded it.\n */\nexport interface LoaderPieceContext<StoreName extends StoreRegistryKey = StoreRegistryKey> {\n\t/**\n\t * The root directory the piece was loaded from.\n\t */\n\treadonly root: string;\n\n\t/**\n\t * The path the module was loaded from, relative to {@link LoaderPieceContext.root}.\n\t */\n\treadonly path: string;\n\n\t/**\n\t * The module's name extracted from the path.\n\t */\n\treadonly name: string;\n\n\t/**\n\t * The store that loaded the piece.\n\t */\n\treadonly store: StoreOf<StoreName>;\n}\n\n/** @deprecated Use {@linkcode LoaderPieceContext} instead. */\nexport interface PieceContext<StoreName extends StoreRegistryKey = StoreRegistryKey> extends LoaderPieceContext<StoreName> {}\n\n/**\n * The options for the {@link Piece}.\n */\nexport interface PieceOptions {\n\t/**\n\t * The name for the piece.\n\t * @default ''\n\t */\n\treadonly name?: string;\n\n\t/**\n\t * Whether or not the piece should be enabled. If set to false, the piece will be unloaded.\n\t * @default true\n\t */\n\treadonly enabled?: boolean;\n}\n\n/**\n * The piece to be stored in {@link Store} instances.\n */\nexport class Piece<Options extends PieceOptions = PieceOptions, StoreName extends StoreRegistryKey = StoreRegistryKey> {\n\t/**\n\t * The store that contains the piece.\n\t */\n\tpublic readonly store: StoreOf<StoreName>;\n\n\t/**\n\t * The location metadata for the piece's file.\n\t */\n\tpublic readonly location: PieceLocation;\n\n\t/**\n\t * The name of the piece.\n\t */\n\tpublic readonly name: string;\n\n\t/**\n\t * Whether or not the piece is enabled.\n\t */\n\tpublic enabled: boolean;\n\n\t/**\n\t * The raw options passed to this {@link Piece}\n\t */\n\tpublic readonly options: Options;\n\n\tpublic constructor(context: Piece.LoaderContext<StoreName>, options: PieceOptions = {}) {\n\t\tthis.store = context.store;\n\t\tthis.location = new PieceLocation(context.path, context.root);\n\t\tthis.name = options.name ?? context.name;\n\t\tthis.enabled = options.enabled ?? true;\n\t\tthis.options = options as Options;\n\t}\n\n\t/**\n\t * A reference to the {@link Container} object for ease of use.\n\t * @see container\n\t */\n\tpublic get container(): Container {\n\t\treturn container;\n\t}\n\n\t/**\n\t * Per-piece listener that is called when the piece is loaded into the store.\n\t * Useful to set-up asynchronous initialization tasks.\n\t */\n\tpublic onLoad(): Awaitable<unknown> {\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Per-piece listener that is called when the piece is unloaded from the store.\n\t * Useful to set-up clean-up tasks.\n\t */\n\tpublic onUnload(): Awaitable<unknown> {\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Unloads and disables the piece.\n\t */\n\tpublic async unload() {\n\t\tawait this.store.unload(this.name);\n\t\tthis.enabled = false;\n\t}\n\n\t/**\n\t * Reloads the piece by loading the same path in the store.\n\t */\n\tpublic async reload() {\n\t\tawait this.store.load(this.location.root, this.location.relative);\n\t}\n\n\t/**\n\t * Defines the `JSON.stringify` behavior of this piece.\n\t */\n\tpublic toJSON(): PieceJSON {\n\t\treturn {\n\t\t\tlocation: this.location.toJSON(),\n\t\t\tname: this.name,\n\t\t\tenabled: this.enabled,\n\t\t\toptions: this.options\n\t\t};\n\t}\n}\n\n/**\n * The return type of {@link Piece.toJSON}.\n */\nexport interface PieceJSON {\n\tlocation: PieceLocationJSON;\n\tname: string;\n\tenabled: boolean;\n\toptions: PieceOptions;\n}\n\nexport namespace Piece {\n\texport const Location = PieceLocation;\n\texport type Options = PieceOptions;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context<StoreName extends StoreRegistryKey = StoreRegistryKey> = LoaderPieceContext<StoreName>;\n\texport type LoaderContext<StoreName extends StoreRegistryKey = StoreRegistryKey> = LoaderPieceContext<StoreName>;\n\texport type JSON = PieceJSON;\n\texport type LocationJSON = PieceLocationJSON;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/PieceLocation.ts"],"names":[],"mappings":";;;;AAMO,IAAM,cAAA,GAAN,MAAM,cAAc,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAenB,WAAA,CAAY,MAAc,IAAc,EAAA;AAX/C;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAOf,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;AACZ,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;AAAA;AACb;AAAA;AAAA;AAAA,EAKA,IAAW,OAAU,GAAA;AACpB,IAAA,OAAO,KAAK,IAAS,KAAA,WAAA;AAAA;AACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,IAAW,QAAmB,GAAA;AAC7B,IAAA,OAAO,KAAK,OAAU,GAAA,WAAA,GAAc,SAAS,IAAK,CAAA,IAAA,EAAM,KAAK,IAAI,CAAA;AAAA;AAClE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,IAAW,WAAwB,GAAA;AAClC,IAAO,OAAA,IAAA,CAAK,OAAU,GAAA,EAAK,GAAA,IAAA,CAAK,QAAS,CAAA,KAAA,CAAM,GAAG,CAAA,CAAE,KAAM,CAAA,CAAA,EAAG,EAAE,CAAA;AAAA;AAChE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,IAAW,IAAe,GAAA;AACzB,IAAA,OAAO,IAAK,CAAA,OAAA,GAAU,WAAc,GAAA,QAAA,CAAS,KAAK,IAAI,CAAA;AAAA;AACvD;AAAA;AAAA;AAAA,EAKO,MAA4B,GAAA;AAClC,IAAO,OAAA;AAAA,MACN,aAAa,IAAK,CAAA,WAAA;AAAA,MAClB,MAAM,IAAK,CAAA,IAAA;AAAA,MACX,MAAM,IAAK,CAAA,IAAA;AAAA,MACX,UAAU,IAAK,CAAA,QAAA;AAAA,MACf,MAAM,IAAK,CAAA;AAAA,KACZ;AAAA;AAEF,CAAA;AA1F2B,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA;AAApB,IAAM,aAAN,GAAA","file":"PieceLocation.mjs","sourcesContent":["import { basename, relative, sep } from 'path';\nimport { VirtualPath } from '../internal/constants';\n\n/**\n * The metadata class used for {@link Piece}s.\n */\nexport class PieceLocation {\n\t/**\n\t * The full path to the file.\n\t */\n\tpublic readonly full: string;\n\n\t/**\n\t * The root directory the file was found from.\n\t */\n\tpublic readonly root: string;\n\n\t/**\n\t * @param full The full path to the file.\n\t * @param root The root directory the file was found from.\n\t */\n\tpublic constructor(full: string, root: string) {\n\t\tthis.full = full;\n\t\tthis.root = root;\n\t}\n\n\t/**\n\t * Whether the file is virtual or not.\n\t */\n\tpublic get virtual() {\n\t\treturn this.full === VirtualPath;\n\t}\n\n\t/**\n\t * The relative path between {@link PieceLocation.root} and {@link PieceLocation.full}.\n\t * @example\n\t * ```typescript\n\t * const location = new PieceLocation(\n\t * \t'/usr/src/app/commands',\n\t * \t'/usr/src/app/commands/general/ping.js'\n\t * );\n\t *\n\t * console.log(location.relative);\n\t * // → 'general/ping.js'\n\t * ```\n\t */\n\tpublic get relative(): string {\n\t\treturn this.virtual ? VirtualPath : relative(this.root, this.full);\n\t}\n\n\t/**\n\t * The names of the directories that separate {@link PieceLocation.root} and {@link PieceLocation.full}.\n\t * @example\n\t * ```typescript\n\t * const location = new PieceLocation(\n\t * \t'/usr/src/app/commands',\n\t * \t'/usr/src/app/commands/games/multiplayer/connect-four.js'\n\t * );\n\t *\n\t * console.log(location.directories);\n\t * // → ['games', 'multiplayer']\n\t * ```\n\t */\n\tpublic get directories(): string[] {\n\t\treturn this.virtual ? [] : this.relative.split(sep).slice(0, -1);\n\t}\n\n\t/**\n\t * The name and extension of the file that was loaded, extracted from {@link PieceLocation.full}.\n\t * @example\n\t * ```typescript\n\t * const location = new PieceLocation(\n\t * \t'/usr/src/app/commands',\n\t * \t'/usr/src/app/commands/games/multiplayer/connect-four.js'\n\t * );\n\t *\n\t * console.log(location.name);\n\t * // → 'connect-four.js'\n\t * ```\n\t */\n\tpublic get name(): string {\n\t\treturn this.virtual ? VirtualPath : basename(this.full);\n\t}\n\n\t/**\n\t * Defines the `JSON.stringify` behavior of this structure.\n\t */\n\tpublic toJSON(): PieceLocationJSON {\n\t\treturn {\n\t\t\tdirectories: this.directories,\n\t\t\tfull: this.full,\n\t\t\tname: this.name,\n\t\t\trelative: this.relative,\n\t\t\troot: this.root\n\t\t};\n\t}\n}\n\n/**\n * The return type of {@link PieceLocation.toJSON}.\n */\nexport interface PieceLocationJSON {\n\tdirectories: string[];\n\tfull: string;\n\tname: string;\n\trelative: string;\n\troot: string;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/PieceLocation.ts"],"names":[],"mappings":";;;;AAMO,IAAM,cAAA,GAAN,MAAM,cAAA,CAAc;AAAA;AAAA;AAAA;AAAA;AAAA,EAenB,WAAA,CAAY,MAAc,IAAA,EAAc;AAX/C;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,MAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,MAAA,CAAA;AAOf,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACb;AAAA;AAAA;AAAA;AAAA,EAKA,IAAW,OAAA,GAAU;AACpB,IAAA,OAAO,KAAK,IAAA,KAAS,WAAA;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,IAAW,QAAA,GAAmB;AAC7B,IAAA,OAAO,KAAK,OAAA,GAAU,WAAA,GAAc,SAAS,IAAA,CAAK,IAAA,EAAM,KAAK,IAAI,CAAA;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,IAAW,WAAA,GAAwB;AAClC,IAAA,OAAO,IAAA,CAAK,OAAA,GAAU,EAAC,GAAI,IAAA,CAAK,QAAA,CAAS,KAAA,CAAM,GAAG,CAAA,CAAE,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,IAAW,IAAA,GAAe;AACzB,IAAA,OAAO,IAAA,CAAK,OAAA,GAAU,WAAA,GAAc,QAAA,CAAS,KAAK,IAAI,CAAA;AAAA,EACvD;AAAA;AAAA;AAAA;AAAA,EAKO,MAAA,GAA4B;AAClC,IAAA,OAAO;AAAA,MACN,aAAa,IAAA,CAAK,WAAA;AAAA,MAClB,MAAM,IAAA,CAAK,IAAA;AAAA,MACX,MAAM,IAAA,CAAK,IAAA;AAAA,MACX,UAAU,IAAA,CAAK,QAAA;AAAA,MACf,MAAM,IAAA,CAAK;AAAA,KACZ;AAAA,EACD;AACD,CAAA;AA1F2B,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA;AAApB,IAAM,aAAA,GAAN","file":"PieceLocation.mjs","sourcesContent":["import { basename, relative, sep } from 'path';\nimport { VirtualPath } from '../internal/constants';\n\n/**\n * The metadata class used for {@link Piece}s.\n */\nexport class PieceLocation {\n\t/**\n\t * The full path to the file.\n\t */\n\tpublic readonly full: string;\n\n\t/**\n\t * The root directory the file was found from.\n\t */\n\tpublic readonly root: string;\n\n\t/**\n\t * @param full The full path to the file.\n\t * @param root The root directory the file was found from.\n\t */\n\tpublic constructor(full: string, root: string) {\n\t\tthis.full = full;\n\t\tthis.root = root;\n\t}\n\n\t/**\n\t * Whether the file is virtual or not.\n\t */\n\tpublic get virtual() {\n\t\treturn this.full === VirtualPath;\n\t}\n\n\t/**\n\t * The relative path between {@link PieceLocation.root} and {@link PieceLocation.full}.\n\t * @example\n\t * ```typescript\n\t * const location = new PieceLocation(\n\t * \t'/usr/src/app/commands',\n\t * \t'/usr/src/app/commands/general/ping.js'\n\t * );\n\t *\n\t * console.log(location.relative);\n\t * // → 'general/ping.js'\n\t * ```\n\t */\n\tpublic get relative(): string {\n\t\treturn this.virtual ? VirtualPath : relative(this.root, this.full);\n\t}\n\n\t/**\n\t * The names of the directories that separate {@link PieceLocation.root} and {@link PieceLocation.full}.\n\t * @example\n\t * ```typescript\n\t * const location = new PieceLocation(\n\t * \t'/usr/src/app/commands',\n\t * \t'/usr/src/app/commands/games/multiplayer/connect-four.js'\n\t * );\n\t *\n\t * console.log(location.directories);\n\t * // → ['games', 'multiplayer']\n\t * ```\n\t */\n\tpublic get directories(): string[] {\n\t\treturn this.virtual ? [] : this.relative.split(sep).slice(0, -1);\n\t}\n\n\t/**\n\t * The name and extension of the file that was loaded, extracted from {@link PieceLocation.full}.\n\t * @example\n\t * ```typescript\n\t * const location = new PieceLocation(\n\t * \t'/usr/src/app/commands',\n\t * \t'/usr/src/app/commands/games/multiplayer/connect-four.js'\n\t * );\n\t *\n\t * console.log(location.name);\n\t * // → 'connect-four.js'\n\t * ```\n\t */\n\tpublic get name(): string {\n\t\treturn this.virtual ? VirtualPath : basename(this.full);\n\t}\n\n\t/**\n\t * Defines the `JSON.stringify` behavior of this structure.\n\t */\n\tpublic toJSON(): PieceLocationJSON {\n\t\treturn {\n\t\t\tdirectories: this.directories,\n\t\t\tfull: this.full,\n\t\t\tname: this.name,\n\t\t\trelative: this.relative,\n\t\t\troot: this.root\n\t\t};\n\t}\n}\n\n/**\n * The return type of {@link PieceLocation.toJSON}.\n */\nexport interface PieceLocationJSON {\n\tdirectories: string[];\n\tfull: string;\n\tname: string;\n\trelative: string;\n\troot: string;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/Store.ts"],"names":["Store"],"mappings":";;;;;;;;;;;AAiDA,IAAM,eAAA,GAAkB,IAAI,cAAe,EAAA;AAjD3C,IAAA,EAAA,EAAA,EAAA,EAAA,cAAA,EAAA,KAAA;AAsDO,IAAM,MAAN,GAAA,MAAM,MAAsF,UAAA,EAAA,GAAA,UAAA,EAShF,qCATgF,EAAsB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBjH,WAAA,CAAY,aAAqC,OAAqC,EAAA;AAC5F,IAAM,KAAA,EA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;AACtD,QAAA,WAAA,MAAiB,QAAQ,IAAK,CAAA,QAAA,CAAS,IAAK,CAAA,IAAA,EAAM,YAAY,CAAG,EAAA;AAChE,UAAM,MAAA,IAAA,CAAK,SAAU,CAAA,IAAA,EAAM,YAAY,CAAA;AAAA;AACxC,eACQ,KAAO,EAAA;AACf,QAAA,IAAA,CAAK,QAAS,CAAA,OAAA,CAAQ,KAAgB,EAAA,IAAA,CAAK,IAAI,CAAA;AAAA;AAChD;AACD;AAaF,CAAA;AA1TC,cAAA,GAAA,IAAA,OAAA,EAAA;AAKA,KAAA,GAAA,IAAA,OAAA,EAAA;AAnBwH,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAkUxH,aAAA,CAlUY,QAkUE,iBAAwC,EAAA,eAAA,CAAA;AAAA;AAAA;AAAA;AAKtD,aAAA,CAvUY,QAuUE,QAA6B,EAAA,IAAA,CAAA;AAvUrC,IAAM,KAAN,GAAA;AAAA,CAmVA,CAAUA,MAAV,KAAA;AACC,EAAMA,OAAA,QAAW,GAAA,aAAA;AAAA,CADR,EAAA,KAAA,KAAA,KAAA,GAAA,EAAA,CAAA,CAAA","file":"Store.mjs","sourcesContent":["import { Collection } from '@discordjs/collection';\nimport { classExtends, isClass, type AbstractConstructor, type Constructor } from '@sapphire/utilities';\nimport { join } from 'path';\nimport { LoaderError, LoaderErrorType } from '../errors/LoaderError';\nimport { resolvePath, type Path } from '../internal/Path';\nimport { ManuallyRegisteredPiecesSymbol, VirtualPath } from '../internal/constants';\nimport { container, type Container } from '../shared/Container';\nimport type { HydratedModuleData, ILoaderResultEntry, ILoaderStrategy, ModuleData } from '../strategies/ILoaderStrategy';\nimport { LoaderStrategy } from '../strategies/LoaderStrategy';\nimport type { Piece } from './Piece';\nimport { StoreRegistry, type StoreRegistryEntries, type StoreRegistryKey } from './StoreRegistry';\n\n/**\n * The options for the store, this features both hooks (changes the behaviour) and handlers (similar to event listeners).\n */\nexport interface StoreOptions<T extends Piece, StoreName extends StoreRegistryKey = StoreRegistryKey> {\n\t/**\n\t * The name for this store.\n\t */\n\treadonly name: StoreName;\n\n\t/**\n\t * The paths to load pieces from, should be absolute.\n\t * @default []\n\t */\n\treadonly paths?: readonly string[];\n\n\t/**\n\t * The strategy to be used for the loader.\n\t * @default Store.defaultStrategy\n\t */\n\treadonly strategy?: ILoaderStrategy<T>;\n}\n\n/**\n * An interface representing a logger function.\n */\nexport interface StoreLogger {\n\t/**\n\t * @param value The string to print. All strings will be formatted with the format `[STORE => ${name}] [${type}] ${content}`,\n\t * where the content may have identifiers (values or names of methods) surrounded by `'`. For example:\n\t *\n\t * - `[STORE => commands] [LOAD] Skipped piece '/home/user/bot/src/commands/foo.js' as 'LoaderStrategy#filter' returned 'null'.`\n\t * - `[STORE => commands] [INSERT] Unloaded new piece 'foo' due to 'enabled' being 'false'.`\n\t * - `[STORE => commands] [UNLOAD] Unloaded piece 'foo'.`\n\t */\n\t(value: string): void;\n}\n\nconst defaultStrategy = new LoaderStrategy();\n\n/**\n * The store class which contains {@link Piece}s.\n */\nexport class Store<T extends Piece, StoreName extends StoreRegistryKey = StoreRegistryKey> extends Collection<string, T> {\n\tpublic readonly Constructor: AbstractConstructor<T>;\n\tpublic readonly name: StoreName;\n\tpublic readonly paths: Set<string>;\n\tpublic readonly strategy: ILoaderStrategy<T>;\n\n\t/**\n\t * The queue of manually registered pieces to load.\n\t */\n\tprivate readonly [ManuallyRegisteredPiecesSymbol] = new Map<string, StoreManuallyRegisteredPiece<StoreName>>();\n\n\t/**\n\t * Whether or not the store has called `loadAll` at least once.\n\t */\n\t#calledLoadAll = false;\n\n\t/**\n\t * The walk function for the store.\n\t */\n\t#walk: LoaderStrategy<T>['walk'];\n\n\t/**\n\t * @param constructor The piece constructor this store loads.\n\t * @param options The options for the store.\n\t */\n\tpublic constructor(constructor: AbstractConstructor<T>, options: StoreOptions<T, StoreName>) {\n\t\tsuper();\n\t\tthis.Constructor = constructor;\n\t\tthis.name = options.name as StoreRegistryKey;\n\t\tthis.paths = new Set(options.paths ?? []);\n\t\tthis.strategy = options.strategy ?? Store.defaultStrategy;\n\n\t\tthis.#walk =\n\t\t\ttypeof this.strategy.walk === 'function' //\n\t\t\t\t? this.strategy.walk.bind(this.strategy)\n\t\t\t\t: defaultStrategy.walk.bind(defaultStrategy);\n\t}\n\n\t/**\n\t * A reference to the {@link Container} object for ease of use.\n\t * @see container\n\t */\n\tpublic get container(): Container {\n\t\treturn container;\n\t}\n\n\t/**\n\t * Registers a directory into the store.\n\t * @param path The path to be added.\n\t * @example\n\t * ```typescript\n\t * store\n\t * .registerPath(resolve('commands'))\n\t * .registerPath(resolve('third-party', 'commands'));\n\t * ```\n\t */\n\tpublic registerPath(path: Path): this {\n\t\tconst root = resolvePath(path);\n\n\t\tthis.paths.add(root);\n\t\tStore.logger?.(`[STORE => ${this.name}] [REGISTER] Registered path '${root}'.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds a piece into the store's list of manually registered pieces. If {@linkcode Store.loadAll()} was called, the\n\t * piece will be loaded immediately, otherwise it will be queued until {@linkcode Store.loadAll()} is called.\n\t *\n\t * All manually registered pieces will be kept even after they are loaded to ensure they can be loaded again if\n\t * {@linkcode Store.loadAll()} is called again.\n\t *\n\t * @remarks\n\t *\n\t * - Pieces loaded this way will have their {@linkcode Piece.Context.root root} and\n\t * {@linkcode Piece.Context.path path} set to {@linkcode VirtualPath}, and as such, cannot be reloaded.\n\t * - This method is useful in environments where file system access is limited or unavailable, such as when using\n\t * {@link https://en.wikipedia.org/wiki/Serverless_computing Serverless Computing}.\n\t * - This method will always throw a {@link TypeError} if `entry.piece` is not a class.\n\t * - This method will always throw a {@linkcode LoaderError} if the piece does not extend the\n\t * {@linkcode Store#Constructor store's piece constructor}.\n\t * - This operation is atomic, if any of the above errors are thrown, the piece will not be loaded.\n\t *\n\t * @seealso {@linkcode StoreRegistry.loadPiece()}\n\t * @since 3.8.0\n\t * @param entry The entry to load.\n\t * @example\n\t * ```typescript\n\t * import { container } from '@sapphire/pieces';\n\t *\n\t * class PingCommand extends Command {\n\t * // ...\n\t * }\n\t *\n\t * container.stores.get('commands').loadPiece({\n\t * name: 'ping',\n\t * piece: PingCommand\n\t * });\n\t * ```\n\t */\n\tpublic async loadPiece(entry: StoreManuallyRegisteredPiece<StoreName>) {\n\t\tif (!isClass(entry.piece)) {\n\t\t\tthrow new TypeError(`The piece ${entry.name} is not a Class. ${String(entry.piece)}`);\n\t\t}\n\n\t\t// If the piece does not extend the store's Piece class, throw an error:\n\t\tif (!classExtends(entry.piece, this.Constructor as Constructor<T>)) {\n\t\t\tthrow new LoaderError(LoaderErrorType.IncorrectType, `The piece ${entry.name} does not extend ${this.name}`);\n\t\t}\n\n\t\tthis[ManuallyRegisteredPiecesSymbol].set(entry.name, entry);\n\t\tif (this.#calledLoadAll) {\n\t\t\tconst piece = this.construct(entry.piece as unknown as Constructor<T>, {\n\t\t\t\tname: entry.name,\n\t\t\t\troot: VirtualPath,\n\t\t\t\tpath: VirtualPath,\n\t\t\t\textension: VirtualPath\n\t\t\t});\n\t\t\tawait this.insert(piece);\n\t\t}\n\t}\n\n\t/**\n\t * Loads one or more pieces from a path.\n\t * @param root The root directory the file is from.\n\t * @param path The path of the file to load, relative to the `root`.\n\t * @return All the loaded pieces.\n\t */\n\tpublic async load(root: string, path: string): Promise<T[]> {\n\t\tif (root === VirtualPath) {\n\t\t\tthrow new LoaderError(LoaderErrorType.VirtualPiece, `Cannot load a virtual file.`);\n\t\t}\n\n\t\tconst full = join(root, path);\n\t\tconst data = this.strategy.filter(full);\n\t\tif (data === null) {\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD] Skipped piece '${full}' as 'LoaderStrategy#filter' returned 'null'.`);\n\t\t\treturn [];\n\t\t}\n\n\t\tconst promises: Promise<T>[] = [];\n\t\tconst finishedData = this.hydrateModuleData(root, data);\n\t\tfor await (const Ctor of this.strategy.load(this, finishedData)) {\n\t\t\tpromises.push(this.insert(this.construct(Ctor, finishedData)));\n\t\t}\n\n\t\treturn Promise.all(promises);\n\t}\n\n\t/**\n\t * Unloads a piece given its instance or its name.\n\t * @param name The name of the file to load.\n\t * @return Returns the piece that was unloaded.\n\t */\n\tpublic async unload(name: string | T): Promise<T> {\n\t\tconst piece = this.resolve(name);\n\n\t\t// Unload piece:\n\t\tthis.strategy.onUnload(this, piece);\n\t\tawait piece.onUnload();\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD] Unloaded piece '${piece.name}'.`);\n\n\t\t// Remove from cache and return it:\n\t\tthis.delete(piece.name);\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD] Removed piece '${piece.name}'.`);\n\t\treturn piece;\n\t}\n\n\t/**\n\t * Unloads all pieces from the store.\n\t */\n\tpublic async unloadAll(): Promise<T[]> {\n\t\tconst promises: Promise<T>[] = [];\n\t\tfor (const piece of this.values()) {\n\t\t\tpromises.push(this.unload(piece));\n\t\t}\n\n\t\tconst results = await Promise.all(promises);\n\n\t\tthis.strategy.onUnloadAll(this);\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD-ALL] Removed all pieces.`);\n\t\treturn results;\n\t}\n\n\t/**\n\t * Loads all pieces from all directories specified by {@link paths}.\n\t */\n\tpublic async loadAll(): Promise<void> {\n\t\tthis.#calledLoadAll = true;\n\n\t\tconst pieces: T[] = [];\n\t\tfor (const entry of this[ManuallyRegisteredPiecesSymbol].values()) {\n\t\t\tconst piece = this.construct(entry.piece as unknown as Constructor<T>, {\n\t\t\t\tname: entry.name,\n\t\t\t\troot: VirtualPath,\n\t\t\t\tpath: VirtualPath,\n\t\t\t\textension: VirtualPath\n\t\t\t});\n\t\t\tpieces.push(piece);\n\t\t}\n\n\t\tfor (const path of this.paths) {\n\t\t\tfor await (const piece of this.loadPath(path)) {\n\t\t\t\tpieces.push(piece);\n\t\t\t}\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Found '${pieces.length}' pieces.`);\n\n\t\t// Clear the store before inserting the new pieces:\n\t\tawait this.unloadAll();\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Cleared all pieces.`);\n\n\t\t// Load each piece:\n\t\tfor (const piece of pieces) {\n\t\t\tawait this.insert(piece);\n\t\t}\n\n\t\t// Call onLoadAll:\n\t\tthis.strategy.onLoadAll(this);\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Successfully loaded '${this.size}' pieces.`);\n\t}\n\n\t/**\n\t * Resolves a piece by its name or its instance.\n\t * @param name The name of the piece or the instance itself.\n\t * @return The resolved piece.\n\t */\n\tpublic resolve(name: string | T): T {\n\t\tif (typeof name === 'string') {\n\t\t\tconst result = this.get(name);\n\t\t\tif (typeof result === 'undefined') throw new LoaderError(LoaderErrorType.UnloadedPiece, `The piece '${name}' does not exist.`);\n\t\t\treturn result;\n\t\t}\n\n\t\tif (name instanceof this.Constructor) return name;\n\t\tthrow new LoaderError(LoaderErrorType.IncorrectType, `The piece '${name.name}' is not an instance of '${this.Constructor.name}'.`);\n\t}\n\n\t/**\n\t * Inserts a piece into the store.\n\t * @param piece The piece to be inserted into the store.\n\t * @return The inserted piece.\n\t */\n\tpublic async insert(piece: T): Promise<T> {\n\t\tif (!piece.enabled) return piece;\n\n\t\t// Load piece:\n\t\tthis.strategy.onLoad(this, piece);\n\t\tawait piece.onLoad();\n\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Loaded new piece '${piece.name}'.`);\n\n\t\t// If the onLoad disabled the piece, call unload and return it:\n\t\tif (!piece.enabled) {\n\t\t\t// Unload piece:\n\t\t\tthis.strategy.onUnload(this, piece);\n\t\t\tawait piece.onUnload();\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Unloaded new piece '${piece.name}' due to 'enabled' being 'false'.`);\n\n\t\t\treturn piece;\n\t\t}\n\n\t\t// Unload existing piece, if any:\n\t\tconst previous = super.get(piece.name);\n\t\tif (previous) {\n\t\t\tawait this.unload(previous);\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Unloaded existing piece '${piece.name}' due to conflicting 'name'.`);\n\t\t}\n\n\t\t// Set the new piece and return it:\n\t\tthis.set(piece.name, piece);\n\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Inserted new piece '${piece.name}'.`);\n\t\treturn piece;\n\t}\n\n\t/**\n\t * Constructs a {@link Piece} instance.\n\t * @param Ctor The {@link Piece}'s constructor used to build the instance.\n\t * @param data The module's information\n\t * @return An instance of the constructed piece.\n\t */\n\tpublic construct(Ctor: ILoaderResultEntry<T>, data: HydratedModuleData): T {\n\t\treturn new Ctor({ store: this, root: data.root, path: data.path, name: data.name }, { name: data.name, enabled: true });\n\t}\n\n\t/**\n\t * Adds the final module data properties.\n\t * @param root The root directory to add.\n\t * @param data The module data returned from {@link ILoaderStrategy.filter}.\n\t * @returns The finished module data.\n\t */\n\tprivate hydrateModuleData(root: string, data: ModuleData): HydratedModuleData {\n\t\treturn { root, ...data };\n\t}\n\n\t/**\n\t * Loads a directory into the store.\n\t * @param root The directory to load the pieces from.\n\t * @return An async iterator that yields the pieces to be loaded into the store.\n\t */\n\tprivate async *loadPath(root: string): AsyncIterableIterator<T> {\n\t\tStore.logger?.(`[STORE => ${this.name}] [WALK] Loading all pieces from '${root}'.`);\n\t\tfor await (const child of this.#walk(this, root, Store.logger)) {\n\t\t\tconst data = this.strategy.filter(child);\n\t\t\tif (data === null) {\n\t\t\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD] Skipped piece '${child}' as 'LoaderStrategy#filter' returned 'null'.`);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst finishedData = this.hydrateModuleData(root, data);\n\t\t\t\tfor await (const Ctor of this.strategy.load(this, finishedData)) {\n\t\t\t\t\tyield this.construct(Ctor, finishedData);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthis.strategy.onError(error as Error, data.path);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The default strategy, defaults to {@link LoaderStrategy}, which is constructed on demand when a store is constructed,\n\t * when none was set beforehand.\n\t */\n\tpublic static defaultStrategy: ILoaderStrategy<any> = defaultStrategy;\n\n\t/**\n\t * The default logger, defaults to `null`.\n\t */\n\tpublic static logger: StoreLogger | null = null;\n}\n\n/**\n * An entry for a manually registered piece using {@linkcode Store.loadPiece()}.\n * @since 3.8.0\n */\nexport interface StoreManuallyRegisteredPiece<StoreName extends StoreRegistryKey> {\n\tname: string;\n\tpiece: StoreRegistryEntries[StoreName] extends Store<infer Piece> ? Constructor<Piece> : never;\n}\n\nexport namespace Store {\n\texport const Registry = StoreRegistry;\n\texport type Options<T extends Piece> = StoreOptions<T>;\n\texport type Logger = StoreLogger;\n\texport type RegistryEntries = StoreRegistryEntries;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/Store.ts"],"names":["Store"],"mappings":";;;;;;;;;;;AAiDA,IAAM,eAAA,GAAkB,IAAI,cAAA,EAAe;AAjD3C,IAAA,EAAA,EAAA,EAAA,EAAA,cAAA,EAAA,KAAA;AAsDO,IAAM,MAAA,GAAN,MAAM,MAAA,UAAsF,EAAA,GAAA,UAAA,EAShF,qCATgF,EAAA,EAAsB;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBjH,WAAA,CAAY,aAAqC,OAAA,EAAqC;AAC5F,IAAA,KAAA,EAAM;AAzBP,IAAA,aAAA,CAAA,IAAA,EAAgB,aAAA,CAAA;AAChB,IAAA,aAAA,CAAA,IAAA,EAAgB,MAAA,CAAA;AAChB,IAAA,aAAA,CAAA,IAAA,EAAgB,OAAA,CAAA;AAChB,IAAA,aAAA,CAAA,IAAA,EAAgB,UAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAkB,EAAA,sBAAsC,GAAA,EAAqD,CAAA;AAK7G;AAAA;AAAA;AAAA,IAAA,YAAA,CAAA,IAAA,EAAA,cAAA,EAAiB,KAAA,CAAA;AAKjB;A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AAS,OAAA,CAAQ,KAAA,EAAgB,IAAA,CAAK,IAAI,CAAA;AAAA,MAChD;AAAA,IACD;AAAA,EACD;AAYD,CAAA;AA1TC,cAAA,GAAA,IAAA,OAAA,EAAA;AAKA,KAAA,GAAA,IAAA,OAAA,EAAA;AAnBwH,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAkUxH,aAAA,CAlUY,QAkUE,iBAAA,EAAwC,eAAA,CAAA;AAAA;AAAA;AAAA;AAKtD,aAAA,CAvUY,QAuUE,QAAA,EAA6B,IAAA,CAAA;AAvUrC,IAAM,KAAA,GAAN;AAAA,CAmVA,CAAUA,MAAAA,KAAV;AACC,EAAMA,OAAA,QAAA,GAAW,aAAA;AAAA,CAAA,EADR,KAAA,KAAA,KAAA,GAAA,EAAA,CAAA,CAAA","file":"Store.mjs","sourcesContent":["import { Collection } from '@discordjs/collection';\nimport { classExtends, isClass, type AbstractConstructor, type Constructor } from '@sapphire/utilities';\nimport { join } from 'path';\nimport { LoaderError, LoaderErrorType } from '../errors/LoaderError';\nimport { resolvePath, type Path } from '../internal/Path';\nimport { ManuallyRegisteredPiecesSymbol, VirtualPath } from '../internal/constants';\nimport { container, type Container } from '../shared/Container';\nimport type { HydratedModuleData, ILoaderResultEntry, ILoaderStrategy, ModuleData } from '../strategies/ILoaderStrategy';\nimport { LoaderStrategy } from '../strategies/LoaderStrategy';\nimport type { Piece } from './Piece';\nimport { StoreRegistry, type StoreRegistryEntries, type StoreRegistryKey } from './StoreRegistry';\n\n/**\n * The options for the store, this features both hooks (changes the behaviour) and handlers (similar to event listeners).\n */\nexport interface StoreOptions<T extends Piece, StoreName extends StoreRegistryKey = StoreRegistryKey> {\n\t/**\n\t * The name for this store.\n\t */\n\treadonly name: StoreName;\n\n\t/**\n\t * The paths to load pieces from, should be absolute.\n\t * @default []\n\t */\n\treadonly paths?: readonly string[];\n\n\t/**\n\t * The strategy to be used for the loader.\n\t * @default Store.defaultStrategy\n\t */\n\treadonly strategy?: ILoaderStrategy<T>;\n}\n\n/**\n * An interface representing a logger function.\n */\nexport interface StoreLogger {\n\t/**\n\t * @param value The string to print. All strings will be formatted with the format `[STORE => ${name}] [${type}] ${content}`,\n\t * where the content may have identifiers (values or names of methods) surrounded by `'`. For example:\n\t *\n\t * - `[STORE => commands] [LOAD] Skipped piece '/home/user/bot/src/commands/foo.js' as 'LoaderStrategy#filter' returned 'null'.`\n\t * - `[STORE => commands] [INSERT] Unloaded new piece 'foo' due to 'enabled' being 'false'.`\n\t * - `[STORE => commands] [UNLOAD] Unloaded piece 'foo'.`\n\t */\n\t(value: string): void;\n}\n\nconst defaultStrategy = new LoaderStrategy();\n\n/**\n * The store class which contains {@link Piece}s.\n */\nexport class Store<T extends Piece, StoreName extends StoreRegistryKey = StoreRegistryKey> extends Collection<string, T> {\n\tpublic readonly Constructor: AbstractConstructor<T>;\n\tpublic readonly name: StoreName;\n\tpublic readonly paths: Set<string>;\n\tpublic readonly strategy: ILoaderStrategy<T>;\n\n\t/**\n\t * The queue of manually registered pieces to load.\n\t */\n\tprivate readonly [ManuallyRegisteredPiecesSymbol] = new Map<string, StoreManuallyRegisteredPiece<StoreName>>();\n\n\t/**\n\t * Whether or not the store has called `loadAll` at least once.\n\t */\n\t#calledLoadAll = false;\n\n\t/**\n\t * The walk function for the store.\n\t */\n\t#walk: LoaderStrategy<T>['walk'];\n\n\t/**\n\t * @param constructor The piece constructor this store loads.\n\t * @param options The options for the store.\n\t */\n\tpublic constructor(constructor: AbstractConstructor<T>, options: StoreOptions<T, StoreName>) {\n\t\tsuper();\n\t\tthis.Constructor = constructor;\n\t\tthis.name = options.name as StoreRegistryKey;\n\t\tthis.paths = new Set(options.paths ?? []);\n\t\tthis.strategy = options.strategy ?? Store.defaultStrategy;\n\n\t\tthis.#walk =\n\t\t\ttypeof this.strategy.walk === 'function' //\n\t\t\t\t? this.strategy.walk.bind(this.strategy)\n\t\t\t\t: defaultStrategy.walk.bind(defaultStrategy);\n\t}\n\n\t/**\n\t * A reference to the {@link Container} object for ease of use.\n\t * @see container\n\t */\n\tpublic get container(): Container {\n\t\treturn container;\n\t}\n\n\t/**\n\t * Registers a directory into the store.\n\t * @param path The path to be added.\n\t * @example\n\t * ```typescript\n\t * store\n\t * .registerPath(resolve('commands'))\n\t * .registerPath(resolve('third-party', 'commands'));\n\t * ```\n\t */\n\tpublic registerPath(path: Path): this {\n\t\tconst root = resolvePath(path);\n\n\t\tthis.paths.add(root);\n\t\tStore.logger?.(`[STORE => ${this.name}] [REGISTER] Registered path '${root}'.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds a piece into the store's list of manually registered pieces. If {@linkcode Store.loadAll()} was called, the\n\t * piece will be loaded immediately, otherwise it will be queued until {@linkcode Store.loadAll()} is called.\n\t *\n\t * All manually registered pieces will be kept even after they are loaded to ensure they can be loaded again if\n\t * {@linkcode Store.loadAll()} is called again.\n\t *\n\t * @remarks\n\t *\n\t * - Pieces loaded this way will have their {@linkcode Piece.Context.root root} and\n\t * {@linkcode Piece.Context.path path} set to {@linkcode VirtualPath}, and as such, cannot be reloaded.\n\t * - This method is useful in environments where file system access is limited or unavailable, such as when using\n\t * {@link https://en.wikipedia.org/wiki/Serverless_computing Serverless Computing}.\n\t * - This method will always throw a {@link TypeError} if `entry.piece` is not a class.\n\t * - This method will always throw a {@linkcode LoaderError} if the piece does not extend the\n\t * {@linkcode Store#Constructor store's piece constructor}.\n\t * - This operation is atomic, if any of the above errors are thrown, the piece will not be loaded.\n\t *\n\t * @seealso {@linkcode StoreRegistry.loadPiece()}\n\t * @since 3.8.0\n\t * @param entry The entry to load.\n\t * @example\n\t * ```typescript\n\t * import { container } from '@sapphire/pieces';\n\t *\n\t * class PingCommand extends Command {\n\t * // ...\n\t * }\n\t *\n\t * container.stores.get('commands').loadPiece({\n\t * name: 'ping',\n\t * piece: PingCommand\n\t * });\n\t * ```\n\t */\n\tpublic async loadPiece(entry: StoreManuallyRegisteredPiece<StoreName>) {\n\t\tif (!isClass(entry.piece)) {\n\t\t\tthrow new TypeError(`The piece ${entry.name} is not a Class. ${String(entry.piece)}`);\n\t\t}\n\n\t\t// If the piece does not extend the store's Piece class, throw an error:\n\t\tif (!classExtends(entry.piece, this.Constructor as Constructor<T>)) {\n\t\t\tthrow new LoaderError(LoaderErrorType.IncorrectType, `The piece ${entry.name} does not extend ${this.name}`);\n\t\t}\n\n\t\tthis[ManuallyRegisteredPiecesSymbol].set(entry.name, entry);\n\t\tif (this.#calledLoadAll) {\n\t\t\tconst piece = this.construct(entry.piece as unknown as Constructor<T>, {\n\t\t\t\tname: entry.name,\n\t\t\t\troot: VirtualPath,\n\t\t\t\tpath: VirtualPath,\n\t\t\t\textension: VirtualPath\n\t\t\t});\n\t\t\tawait this.insert(piece);\n\t\t}\n\t}\n\n\t/**\n\t * Loads one or more pieces from a path.\n\t * @param root The root directory the file is from.\n\t * @param path The path of the file to load, relative to the `root`.\n\t * @return All the loaded pieces.\n\t */\n\tpublic async load(root: string, path: string): Promise<T[]> {\n\t\tif (root === VirtualPath) {\n\t\t\tthrow new LoaderError(LoaderErrorType.VirtualPiece, `Cannot load a virtual file.`);\n\t\t}\n\n\t\tconst full = join(root, path);\n\t\tconst data = this.strategy.filter(full);\n\t\tif (data === null) {\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD] Skipped piece '${full}' as 'LoaderStrategy#filter' returned 'null'.`);\n\t\t\treturn [];\n\t\t}\n\n\t\tconst promises: Promise<T>[] = [];\n\t\tconst finishedData = this.hydrateModuleData(root, data);\n\t\tfor await (const Ctor of this.strategy.load(this, finishedData)) {\n\t\t\tpromises.push(this.insert(this.construct(Ctor, finishedData)));\n\t\t}\n\n\t\treturn Promise.all(promises);\n\t}\n\n\t/**\n\t * Unloads a piece given its instance or its name.\n\t * @param name The name of the file to load.\n\t * @return Returns the piece that was unloaded.\n\t */\n\tpublic async unload(name: string | T): Promise<T> {\n\t\tconst piece = this.resolve(name);\n\n\t\t// Unload piece:\n\t\tthis.strategy.onUnload(this, piece);\n\t\tawait piece.onUnload();\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD] Unloaded piece '${piece.name}'.`);\n\n\t\t// Remove from cache and return it:\n\t\tthis.delete(piece.name);\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD] Removed piece '${piece.name}'.`);\n\t\treturn piece;\n\t}\n\n\t/**\n\t * Unloads all pieces from the store.\n\t */\n\tpublic async unloadAll(): Promise<T[]> {\n\t\tconst promises: Promise<T>[] = [];\n\t\tfor (const piece of this.values()) {\n\t\t\tpromises.push(this.unload(piece));\n\t\t}\n\n\t\tconst results = await Promise.all(promises);\n\n\t\tthis.strategy.onUnloadAll(this);\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD-ALL] Removed all pieces.`);\n\t\treturn results;\n\t}\n\n\t/**\n\t * Loads all pieces from all directories specified by {@link paths}.\n\t */\n\tpublic async loadAll(): Promise<void> {\n\t\tthis.#calledLoadAll = true;\n\n\t\tconst pieces: T[] = [];\n\t\tfor (const entry of this[ManuallyRegisteredPiecesSymbol].values()) {\n\t\t\tconst piece = this.construct(entry.piece as unknown as Constructor<T>, {\n\t\t\t\tname: entry.name,\n\t\t\t\troot: VirtualPath,\n\t\t\t\tpath: VirtualPath,\n\t\t\t\textension: VirtualPath\n\t\t\t});\n\t\t\tpieces.push(piece);\n\t\t}\n\n\t\tfor (const path of this.paths) {\n\t\t\tfor await (const piece of this.loadPath(path)) {\n\t\t\t\tpieces.push(piece);\n\t\t\t}\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Found '${pieces.length}' pieces.`);\n\n\t\t// Clear the store before inserting the new pieces:\n\t\tawait this.unloadAll();\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Cleared all pieces.`);\n\n\t\t// Load each piece:\n\t\tfor (const piece of pieces) {\n\t\t\tawait this.insert(piece);\n\t\t}\n\n\t\t// Call onLoadAll:\n\t\tthis.strategy.onLoadAll(this);\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Successfully loaded '${this.size}' pieces.`);\n\t}\n\n\t/**\n\t * Resolves a piece by its name or its instance.\n\t * @param name The name of the piece or the instance itself.\n\t * @return The resolved piece.\n\t */\n\tpublic resolve(name: string | T): T {\n\t\tif (typeof name === 'string') {\n\t\t\tconst result = this.get(name);\n\t\t\tif (typeof result === 'undefined') throw new LoaderError(LoaderErrorType.UnloadedPiece, `The piece '${name}' does not exist.`);\n\t\t\treturn result;\n\t\t}\n\n\t\tif (name instanceof this.Constructor) return name;\n\t\tthrow new LoaderError(LoaderErrorType.IncorrectType, `The piece '${name.name}' is not an instance of '${this.Constructor.name}'.`);\n\t}\n\n\t/**\n\t * Inserts a piece into the store.\n\t * @param piece The piece to be inserted into the store.\n\t * @return The inserted piece.\n\t */\n\tpublic async insert(piece: T): Promise<T> {\n\t\tif (!piece.enabled) return piece;\n\n\t\t// Load piece:\n\t\tthis.strategy.onLoad(this, piece);\n\t\tawait piece.onLoad();\n\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Loaded new piece '${piece.name}'.`);\n\n\t\t// If the onLoad disabled the piece, call unload and return it:\n\t\tif (!piece.enabled) {\n\t\t\t// Unload piece:\n\t\t\tthis.strategy.onUnload(this, piece);\n\t\t\tawait piece.onUnload();\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Unloaded new piece '${piece.name}' due to 'enabled' being 'false'.`);\n\n\t\t\treturn piece;\n\t\t}\n\n\t\t// Unload existing piece, if any:\n\t\tconst previous = super.get(piece.name);\n\t\tif (previous) {\n\t\t\tawait this.unload(previous);\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Unloaded existing piece '${piece.name}' due to conflicting 'name'.`);\n\t\t}\n\n\t\t// Set the new piece and return it:\n\t\tthis.set(piece.name, piece);\n\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Inserted new piece '${piece.name}'.`);\n\t\treturn piece;\n\t}\n\n\t/**\n\t * Constructs a {@link Piece} instance.\n\t * @param Ctor The {@link Piece}'s constructor used to build the instance.\n\t * @param data The module's information\n\t * @return An instance of the constructed piece.\n\t */\n\tpublic construct(Ctor: ILoaderResultEntry<T>, data: HydratedModuleData): T {\n\t\treturn new Ctor({ store: this, root: data.root, path: data.path, name: data.name }, { name: data.name, enabled: true });\n\t}\n\n\t/**\n\t * Adds the final module data properties.\n\t * @param root The root directory to add.\n\t * @param data The module data returned from {@link ILoaderStrategy.filter}.\n\t * @returns The finished module data.\n\t */\n\tprivate hydrateModuleData(root: string, data: ModuleData): HydratedModuleData {\n\t\treturn { root, ...data };\n\t}\n\n\t/**\n\t * Loads a directory into the store.\n\t * @param root The directory to load the pieces from.\n\t * @return An async iterator that yields the pieces to be loaded into the store.\n\t */\n\tprivate async *loadPath(root: string): AsyncIterableIterator<T> {\n\t\tStore.logger?.(`[STORE => ${this.name}] [WALK] Loading all pieces from '${root}'.`);\n\t\tfor await (const child of this.#walk(this, root, Store.logger)) {\n\t\t\tconst data = this.strategy.filter(child);\n\t\t\tif (data === null) {\n\t\t\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD] Skipped piece '${child}' as 'LoaderStrategy#filter' returned 'null'.`);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst finishedData = this.hydrateModuleData(root, data);\n\t\t\t\tfor await (const Ctor of this.strategy.load(this, finishedData)) {\n\t\t\t\t\tyield this.construct(Ctor, finishedData);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthis.strategy.onError(error as Error, data.path);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The default strategy, defaults to {@link LoaderStrategy}, which is constructed on demand when a store is constructed,\n\t * when none was set beforehand.\n\t */\n\tpublic static defaultStrategy: ILoaderStrategy<any> = defaultStrategy;\n\n\t/**\n\t * The default logger, defaults to `null`.\n\t */\n\tpublic static logger: StoreLogger | null = null;\n}\n\n/**\n * An entry for a manually registered piece using {@linkcode Store.loadPiece()}.\n * @since 3.8.0\n */\nexport interface StoreManuallyRegisteredPiece<StoreName extends StoreRegistryKey> {\n\tname: string;\n\tpiece: StoreRegistryEntries[StoreName] extends Store<infer Piece> ? Constructor<Piece> : never;\n}\n\nexport namespace Store {\n\texport const Registry = StoreRegistry;\n\texport type Options<T extends Piece> = StoreOptions<T>;\n\texport type Logger = StoreLogger;\n\texport type RegistryEntries = StoreRegistryEntries;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/StoreRegistry.ts"],"names":[],"mappings":";;;;;;;;;AAAA,IAAA,gCAAA;AA8BO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsB,UAAiD,CAAA;AAAA,EAA7E,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAS,YAAA,CAAA,IAAA,EAAA,gCAAA,EAAmC,IAAI,UAA+E,EAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM/H,MAAa,IAAO,GAAA;AACnB,IAAA,MAAM,WAA+B,EAAC;AACtC,IAAW,KAAA,MAAA,KAAA,IAAS,IAAK,CAAA,MAAA,EAA4C,EAAA;AACpE,MAAS,QAAA,CAAA,IAAA,CAAK,KAAM,CAAA,OAAA,EAAS,CAAA;AAAA;AAG9B,IAAM,MAAA,OAAA,CAAQ,IAAI,QAAQ,CAAA;AAAA;AAC3B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0BO,YAAa,CAAA,aAAA,GAAsB,WAAY,EAAA,CAAE,IAAM,EAAA;AAC7D,IAAM,MAAA,IAAA,GAAO,YAAY,aAAa,CAAA;AACtC,IAAW,KAAA,MAAA,KAAA,IAAS,IAAK,CAAA,MAAA,EAA4C,EAAA;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M,KAAK,CAAA;AAElC,IAAA,IAAI,KAAO,EAAA;AACV,MAAM,MAAA,KAAA,CAAM,UAAU,KAAK,CAAA;AAAA,KACrB,MAAA;AACN,MAAA,IAAI,CAAC,OAAA,CAAQ,KAAM,CAAA,KAAK,CAAG,EAAA;AAC1B,QAAM,MAAA,IAAI,SAAU,CAAA,CAAA,UAAA,EAAa,KAAM,CAAA,IAAI,oBAAoB,MAAO,CAAA,KAAA,CAAM,KAAK,CAAC,CAAE,CAAA,CAAA;AAAA;AAGrF,MAAA,YAAA,CAAA,IAAA,EAAK,kCAAiC,MAAO,CAAA,KAAA,CAAM,KAAO,EAAA,MAAM,EAAE,CAAA,CAAE,IAAK,CAAA,EAAE,MAAM,KAAM,CAAA,IAAA,EAAM,KAAO,EAAA,KAAA,CAAM,OAAO,CAAA;AAAA;AAClH;AAEF,CAAA;AAlJU,gCAAA,GAAA,IAAA,OAAA,EAAA;AAJ0E,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA;AAA7E,IAAM,aAAN,GAAA","file":"StoreRegistry.mjs","sourcesContent":["import { Collection } from '@discordjs/collection';\nimport { isClass } from '@sapphire/utilities';\nimport { join } from 'path';\nimport { LoaderError } from '../errors/LoaderError';\nimport { resolvePath, type Path } from '../internal/Path';\nimport { getRootData } from '../internal/RootScan';\nimport { ManuallyRegisteredPiecesSymbol, VirtualPath } from '../internal/constants';\nimport type { Piece } from './Piece';\nimport type { Store, StoreManuallyRegisteredPiece } from './Store';\n\n/**\n * A strict-typed store registry. This is available in {@link container}.\n * @since 2.1.0\n * @example\n * ```typescript\n * // Adding new stores\n *\n * // Register the store:\n * container.stores.register(new RouteStore());\n *\n * // Augment Sapphire to add the new store, in case of a JavaScript\n * // project, this can be moved to an `Augments.d.ts` (or any other name)\n * // file somewhere:\n * declare module '@sapphire/pieces' {\n * export interface StoreRegistryEntries {\n * routes: RouteStore;\n * }\n * }\n * ```\n */\nexport class StoreRegistry extends Collection<StoreRegistryKey, StoreRegistryValue> {\n\t/**\n\t * The queue of pieces to load.\n\t */\n\treadonly #pendingManuallyRegisteredPieces = new Collection<StoreRegistryKey, StoreManuallyRegisteredPiece<StoreRegistryKey>[]>();\n\n\t/**\n\t * Loads all the registered stores.\n\t * @since 2.1.0\n\t */\n\tpublic async load() {\n\t\tconst promises: Promise<unknown>[] = [];\n\t\tfor (const store of this.values() as IterableIterator<Store<Piece>>) {\n\t\t\tpromises.push(store.loadAll());\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * Registers all user directories from the process working directory, the default value is obtained by assuming\n\t * CommonJS (high accuracy) but with fallback for ECMAScript Modules (reads package.json's `main` entry, fallbacks\n\t * to `process.cwd()`).\n\t *\n\t * By default, if you have this folder structure:\n\t * ```\n\t * /home/me/my-bot\n\t * ├─ src\n\t * │ ├─ commands\n\t * │ ├─ events\n\t * │ └─ main.js\n\t * └─ package.json\n\t * ```\n\t *\n\t * And you run `node src/main.js`, the directories `/home/me/my-bot/src/commands` and `/home/me/my-bot/src/events` will\n\t * be registered for the commands and events stores respectively, since both directories are located in the same\n\t * directory as your main file.\n\t *\n\t * **Note**: this also registers directories for all other stores, even if they don't have a folder, this allows you\n\t * to create new pieces and hot-load them later anytime.\n\t * @since 2.1.0\n\t * @param rootDirectory The root directory to register pieces at.\n\t */\n\tpublic registerPath(rootDirectory: Path = getRootData().root) {\n\t\tconst root = resolvePath(rootDirectory);\n\t\tfor (const store of this.values() as IterableIterator<Store<Piece>>) {\n\t\t\tstore.registerPath(join(root, store.name));\n\t\t}\n\t}\n\n\t/**\n\t * Registers a store.\n\t *\n\t * @remarks\n\t *\n\t * - This method will allow {@linkcode StoreRegistry} to manage the store, meaning:\n\t * - {@linkcode StoreRegistry.registerPath()} will call the store's\n\t * {@linkcode Store.registerPath() registerPath()} method on call.\n\t * - {@linkcode StoreRegistry.load()} will call the store's {@linkcode Store.load() load()} method on call.\n\t * - {@linkcode StoreRegistry.loadPiece()} will call the store's {@linkcode Store.loadPiece() loadPiece()} method\n\t * on call.\n\t * - This will also add all the manually registered pieces by {@linkcode StoreRegistry.loadPiece()} in the store.\n\t *\n\t * It is generally recommended to register a store as early as possible, before any of the aforementioned methods\n\t * are called, otherwise you will have to manually call the aforementioned methods for the store to work properly.\n\t *\n\t * If there were manually registered pieces for this store with {@linkcode StoreRegistry.loadPiece()}, this method\n\t * will add them to the store and delete the queue. Note, however, that this method will not call the store's\n\t * {@linkcode Store.loadPiece() loadPiece()} method, and as such, the pieces will not be loaded until\n\t * {@linkcode Store.loadAll()} is called.\n\t *\n\t * @since 2.1.0\n\t * @param store The store to register.\n\t */\n\tpublic register<T extends Piece>(store: Store<T>): this {\n\t\tthis.set(store.name as StoreRegistryKey, store as unknown as StoreRegistryValue);\n\n\t\t// If there was a queue for this store, add it to the store and delete the queue:\n\t\tconst queue = this.#pendingManuallyRegisteredPieces.get(store.name);\n\t\tif (queue) {\n\t\t\tfor (const entry of queue) {\n\t\t\t\tstore[ManuallyRegisteredPiecesSymbol].set(entry.name, entry);\n\t\t\t}\n\n\t\t\tthis.#pendingManuallyRegisteredPieces.delete(store.name);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Deregisters a store.\n\t * @since 2.1.0\n\t * @param store The store to deregister.\n\t */\n\tpublic deregister<T extends Piece>(store: Store<T>): this {\n\t\tthis.delete(store.name as StoreRegistryKey);\n\t\treturn this;\n\t}\n\n\t/**\n\t * If the store was {@link StoreRegistry.register registered}, this method will call the store's\n\t * {@linkcode Store.loadPiece() loadPiece()} method.\n\t *\n\t * If it was called, the entry will be loaded immediately without queueing.\n\t *\n\t * @remarks\n\t *\n\t * - Pieces loaded this way will have their {@linkcode Piece.Context.root root} and\n\t * {@linkcode Piece.Context.path path} set to {@linkcode VirtualPath}, and as such, cannot be reloaded.\n\t * - This method is useful in environments where file system access is limited or unavailable, such as when using\n\t * {@link https://en.wikipedia.org/wiki/Serverless_computing Serverless Computing}.\n\t * - This method will not throw an error if a store with the given name does not exist, it will simply be queued\n\t * until it's registered.\n\t * - This method will always throw a {@link TypeError} if `entry.piece` is not a class.\n\t * - If the store is registered, this method will always throw a {@linkcode LoaderError} if the piece does not\n\t * extend the registered {@linkcode Store.Constructor store's piece constructor}.\n\t * - This operation is atomic, if any of the above errors are thrown, the piece will not be loaded.\n\t *\n\t * @seealso {@linkcode Store.loadPiece()}\n\t * @since 3.8.0\n\t * @param entry The entry to load.\n\t * @example\n\t * ```typescript\n\t * import { container } from '@sapphire/pieces';\n\t *\n\t * class PingCommand extends Command {\n\t * // ...\n\t * }\n\t *\n\t * container.stores.loadPiece({\n\t * store: 'commands',\n\t * name: 'ping',\n\t * piece: PingCommand\n\t * });\n\t * ```\n\t */\n\tpublic async loadPiece<StoreName extends StoreRegistryKey>(entry: StoreManagerManuallyRegisteredPiece<StoreName>) {\n\t\tconst store = this.get(entry.store) as Store<Piece, StoreName> | undefined;\n\n\t\tif (store) {\n\t\t\tawait store.loadPiece(entry);\n\t\t} else {\n\t\t\tif (!isClass(entry.piece)) {\n\t\t\t\tthrow new TypeError(`The piece ${entry.name} is not a Class. ${String(entry.piece)}`);\n\t\t\t}\n\n\t\t\tthis.#pendingManuallyRegisteredPieces.ensure(entry.store, () => []).push({ name: entry.name, piece: entry.piece });\n\t\t}\n\t}\n}\n\nexport interface StoreRegistry {\n\tget<K extends StoreRegistryKey>(key: K): StoreRegistryEntries[K];\n\tget(key: string): undefined;\n\thas(key: StoreRegistryKey): true;\n\thas(key: string): false;\n}\n\n/**\n * A type utility to get the keys of {@linkcode StoreRegistryEntries}.\n * @since 3.10.0\n */\nexport type StoreRegistryKey = keyof StoreRegistryEntries;\n\n/**\n * A type utility to get the values of {@linkcode StoreRegistryEntries}.\n * @since 3.10.0\n */\nexport type StoreRegistryValue = StoreRegistryEntries[StoreRegistryKey];\n\n/**\n * The {@link StoreRegistry}'s registry, use module augmentation against this interface when adding new stores.\n * @since 2.1.0\n */\nexport interface StoreRegistryEntries {}\n\n/**\n * An entry for a manually registered piece using {@linkcode StoreRegistry.loadPiece()}.\n * @seealso {@linkcode StoreRegistry.loadPiece()}\n * @since 3.8.0\n */\nexport interface StoreManagerManuallyRegisteredPiece<StoreName extends StoreRegistryKey> extends StoreManuallyRegisteredPiece<StoreName> {\n\tstore: StoreName;\n}\n\n/**\n * Type utility to get the {@linkcode Store} given its name.\n * @since 3.10.0\n */\nexport type StoreOf<StoreName extends StoreRegistryKey> = StoreRegistryKey extends never\n\t? Store<Piece<Piece.Options, StoreName>>\n\t: StoreRegistryEntries[StoreName];\n\n/**\n * Type utility to get the {@linkcode Piece} given its {@linkcode Store}'s name.\n * @since 3.10.0\n */\nexport type PieceOf<StoreName extends StoreRegistryKey> = StoreRegistryKey extends never\n\t? Piece<Piece.Options, StoreName>\n\t: StoreRegistryEntries[StoreName] extends Store<infer PieceType>\n\t\t? PieceType\n\t\t: Piece<Piece.Options, StoreName>;\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/StoreRegistry.ts"],"names":[],"mappings":";;;;;;;;;AAAA,IAAA,gCAAA;AA8BO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsB,UAAA,CAAiD;AAAA,EAA7E,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAA,YAAA,CAAA,IAAA,EAAS,gCAAA,EAAmC,IAAI,UAAA,EAA+E,CAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM/H,MAAa,IAAA,GAAO;AACnB,IAAA,MAAM,WAA+B,EAAC;AACtC,IAAA,KAAA,MAAW,KAAA,IAAS,IAAA,CAAK,MAAA,EAAO,EAAqC;AACpE,MAAA,QAAA,CAAS,IAAA,CAAK,KAAA,CAAM,OAAA,EAAS,CAAA;AAAA,IAC9B;AAEA,IAAA,MAAM,OAAA,CAAQ,IAAI,QAAQ,CAAA;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuCA,MAAa,UAA8C,KAAA,EAAuD;AACjH,IAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,GAAA,CAAI,KAAA,CAAM,KAAK,CAAA;AAElC,IAAA,IAAI,KAAA,EAAO;AACV,MAAA,MAAM,KAAA,CAAM,UAAU,KAAK,CAAA;AAAA,IAC5B,CAAA,MAAO;AACN,MAAA,IAAI,CAAC,OAAA,CAAQ,KAAA,CAAM,KAAK,CAAA,EAAG;AAC1B,QAAA,MAAM,IAAI,SAAA,CAAU,CAAA,UAAA,EAAa,KAAA,CAAM,IAAI,oBAAoB,MAAA,CAAO,KAAA,CAAM,KAAK,CAAC,CAAA,CAAE,CAAA;AAAA,MACrF;AAEA,MAAA,YAAA,CAAA,IAAA,EAAK,kCAAiC,MAAA,CAAO,KAAA,CAAM,KAAA,EAAO,MAAM,EAAE,CAAA,CAAE,IAAA,CAAK,EAAE,MAAM,KAAA,CAAM,IAAA,EAAM,KAAA,EAAO,KAAA,CAAM,OAAO,CAAA;AAAA,IAClH;AAAA,EACD;AACD,CAAA;AAlJU,gCAAA,GAAA,IAAA,OAAA,EAAA;AAJ0E,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA;AAA7E,IAAM,aAAA,GAAN","file":"StoreRegistry.mjs","sourcesContent":["import { Collection } from '@discordjs/collection';\nimport { isClass } from '@sapphire/utilities';\nimport { join } from 'path';\nimport { LoaderError } from '../errors/LoaderError';\nimport { resolvePath, type Path } from '../internal/Path';\nimport { getRootData } from '../internal/RootScan';\nimport { ManuallyRegisteredPiecesSymbol, VirtualPath } from '../internal/constants';\nimport type { Piece } from './Piece';\nimport type { Store, StoreManuallyRegisteredPiece } from './Store';\n\n/**\n * A strict-typed store registry. This is available in {@link container}.\n * @since 2.1.0\n * @example\n * ```typescript\n * // Adding new stores\n *\n * // Register the store:\n * container.stores.register(new RouteStore());\n *\n * // Augment Sapphire to add the new store, in case of a JavaScript\n * // project, this can be moved to an `Augments.d.ts` (or any other name)\n * // file somewhere:\n * declare module '@sapphire/pieces' {\n * export interface StoreRegistryEntries {\n * routes: RouteStore;\n * }\n * }\n * ```\n */\nexport class StoreRegistry extends Collection<StoreRegistryKey, StoreRegistryValue> {\n\t/**\n\t * The queue of pieces to load.\n\t */\n\treadonly #pendingManuallyRegisteredPieces = new Collection<StoreRegistryKey, StoreManuallyRegisteredPiece<StoreRegistryKey>[]>();\n\n\t/**\n\t * Loads all the registered stores.\n\t * @since 2.1.0\n\t */\n\tpublic async load() {\n\t\tconst promises: Promise<unknown>[] = [];\n\t\tfor (const store of this.values() as IterableIterator<Store<Piece>>) {\n\t\t\tpromises.push(store.loadAll());\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * Registers all user directories from the process working directory, the default value is obtained by assuming\n\t * CommonJS (high accuracy) but with fallback for ECMAScript Modules (reads package.json's `main` entry, fallbacks\n\t * to `process.cwd()`).\n\t *\n\t * By default, if you have this folder structure:\n\t * ```\n\t * /home/me/my-bot\n\t * ├─ src\n\t * │ ├─ commands\n\t * │ ├─ events\n\t * │ └─ main.js\n\t * └─ package.json\n\t * ```\n\t *\n\t * And you run `node src/main.js`, the directories `/home/me/my-bot/src/commands` and `/home/me/my-bot/src/events` will\n\t * be registered for the commands and events stores respectively, since both directories are located in the same\n\t * directory as your main file.\n\t *\n\t * **Note**: this also registers directories for all other stores, even if they don't have a folder, this allows you\n\t * to create new pieces and hot-load them later anytime.\n\t * @since 2.1.0\n\t * @param rootDirectory The root directory to register pieces at.\n\t */\n\tpublic registerPath(rootDirectory: Path = getRootData().root) {\n\t\tconst root = resolvePath(rootDirectory);\n\t\tfor (const store of this.values() as IterableIterator<Store<Piece>>) {\n\t\t\tstore.registerPath(join(root, store.name));\n\t\t}\n\t}\n\n\t/**\n\t * Registers a store.\n\t *\n\t * @remarks\n\t *\n\t * - This method will allow {@linkcode StoreRegistry} to manage the store, meaning:\n\t * - {@linkcode StoreRegistry.registerPath()} will call the store's\n\t * {@linkcode Store.registerPath() registerPath()} method on call.\n\t * - {@linkcode StoreRegistry.load()} will call the store's {@linkcode Store.load() load()} method on call.\n\t * - {@linkcode StoreRegistry.loadPiece()} will call the store's {@linkcode Store.loadPiece() loadPiece()} method\n\t * on call.\n\t * - This will also add all the manually registered pieces by {@linkcode StoreRegistry.loadPiece()} in the store.\n\t *\n\t * It is generally recommended to register a store as early as possible, before any of the aforementioned methods\n\t * are called, otherwise you will have to manually call the aforementioned methods for the store to work properly.\n\t *\n\t * If there were manually registered pieces for this store with {@linkcode StoreRegistry.loadPiece()}, this method\n\t * will add them to the store and delete the queue. Note, however, that this method will not call the store's\n\t * {@linkcode Store.loadPiece() loadPiece()} method, and as such, the pieces will not be loaded until\n\t * {@linkcode Store.loadAll()} is called.\n\t *\n\t * @since 2.1.0\n\t * @param store The store to register.\n\t */\n\tpublic register<T extends Piece>(store: Store<T>): this {\n\t\tthis.set(store.name as StoreRegistryKey, store as unknown as StoreRegistryValue);\n\n\t\t// If there was a queue for this store, add it to the store and delete the queue:\n\t\tconst queue = this.#pendingManuallyRegisteredPieces.get(store.name);\n\t\tif (queue) {\n\t\t\tfor (const entry of queue) {\n\t\t\t\tstore[ManuallyRegisteredPiecesSymbol].set(entry.name, entry);\n\t\t\t}\n\n\t\t\tthis.#pendingManuallyRegisteredPieces.delete(store.name);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Deregisters a store.\n\t * @since 2.1.0\n\t * @param store The store to deregister.\n\t */\n\tpublic deregister<T extends Piece>(store: Store<T>): this {\n\t\tthis.delete(store.name as StoreRegistryKey);\n\t\treturn this;\n\t}\n\n\t/**\n\t * If the store was {@link StoreRegistry.register registered}, this method will call the store's\n\t * {@linkcode Store.loadPiece() loadPiece()} method.\n\t *\n\t * If it was called, the entry will be loaded immediately without queueing.\n\t *\n\t * @remarks\n\t *\n\t * - Pieces loaded this way will have their {@linkcode Piece.Context.root root} and\n\t * {@linkcode Piece.Context.path path} set to {@linkcode VirtualPath}, and as such, cannot be reloaded.\n\t * - This method is useful in environments where file system access is limited or unavailable, such as when using\n\t * {@link https://en.wikipedia.org/wiki/Serverless_computing Serverless Computing}.\n\t * - This method will not throw an error if a store with the given name does not exist, it will simply be queued\n\t * until it's registered.\n\t * - This method will always throw a {@link TypeError} if `entry.piece` is not a class.\n\t * - If the store is registered, this method will always throw a {@linkcode LoaderError} if the piece does not\n\t * extend the registered {@linkcode Store.Constructor store's piece constructor}.\n\t * - This operation is atomic, if any of the above errors are thrown, the piece will not be loaded.\n\t *\n\t * @seealso {@linkcode Store.loadPiece()}\n\t * @since 3.8.0\n\t * @param entry The entry to load.\n\t * @example\n\t * ```typescript\n\t * import { container } from '@sapphire/pieces';\n\t *\n\t * class PingCommand extends Command {\n\t * // ...\n\t * }\n\t *\n\t * container.stores.loadPiece({\n\t * store: 'commands',\n\t * name: 'ping',\n\t * piece: PingCommand\n\t * });\n\t * ```\n\t */\n\tpublic async loadPiece<StoreName extends StoreRegistryKey>(entry: StoreManagerManuallyRegisteredPiece<StoreName>) {\n\t\tconst store = this.get(entry.store) as Store<Piece, StoreName> | undefined;\n\n\t\tif (store) {\n\t\t\tawait store.loadPiece(entry);\n\t\t} else {\n\t\t\tif (!isClass(entry.piece)) {\n\t\t\t\tthrow new TypeError(`The piece ${entry.name} is not a Class. ${String(entry.piece)}`);\n\t\t\t}\n\n\t\t\tthis.#pendingManuallyRegisteredPieces.ensure(entry.store, () => []).push({ name: entry.name, piece: entry.piece });\n\t\t}\n\t}\n}\n\nexport interface StoreRegistry {\n\tget<K extends StoreRegistryKey>(key: K): StoreRegistryEntries[K];\n\tget(key: string): undefined;\n\thas(key: StoreRegistryKey): true;\n\thas(key: string): false;\n}\n\n/**\n * A type utility to get the keys of {@linkcode StoreRegistryEntries}.\n * @since 3.10.0\n */\nexport type StoreRegistryKey = keyof StoreRegistryEntries;\n\n/**\n * A type utility to get the values of {@linkcode StoreRegistryEntries}.\n * @since 3.10.0\n */\nexport type StoreRegistryValue = StoreRegistryEntries[StoreRegistryKey];\n\n/**\n * The {@link StoreRegistry}'s registry, use module augmentation against this interface when adding new stores.\n * @since 2.1.0\n */\nexport interface StoreRegistryEntries {}\n\n/**\n * An entry for a manually registered piece using {@linkcode StoreRegistry.loadPiece()}.\n * @seealso {@linkcode StoreRegistry.loadPiece()}\n * @since 3.8.0\n */\nexport interface StoreManagerManuallyRegisteredPiece<StoreName extends StoreRegistryKey> extends StoreManuallyRegisteredPiece<StoreName> {\n\tstore: StoreName;\n}\n\n/**\n * Type utility to get the {@linkcode Store} given its name.\n * @since 3.10.0\n */\nexport type StoreOf<StoreName extends StoreRegistryKey> = StoreRegistryKey extends never\n\t? Store<Piece<Piece.Options, StoreName>>\n\t: StoreRegistryEntries[StoreName];\n\n/**\n * Type utility to get the {@linkcode Piece} given its {@linkcode Store}'s name.\n * @since 3.10.0\n */\nexport type PieceOf<StoreName extends StoreRegistryKey> = StoreRegistryKey extends never\n\t? Piece<Piece.Options, StoreName>\n\t: StoreRegistryEntries[StoreName] extends Store<infer PieceType>\n\t\t? PieceType\n\t\t: Piece<Piece.Options, StoreName>;\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/tsconfig.json"],"names":["extends"],"mappings":";;;AACC,IAAAA,QAAW,GAAA;AACQ,IAAA,eAAA,GAAA;AAAA,EAClB,OAAW,EAAA,IAAA;AAAA,EACX,MAAU,EAAA;AACX;AACA,IAAA,OAAA,GAAW,CAAC,GAAG;AANhB,IAAA,gBAAA,GAAA;AAAA,EACC,OAAAA,EAAAA,QAAAA;AAAA,EACA,eAAA;AAAA,EAIA;AACD","file":"tsconfig.mjs","sourcesContent":["{\n\t\"extends\": \"../tsconfig.base.json\",\n\t\"compilerOptions\": {\n\t\t\"rootDir\": \"./\",\n\t\t\"outDir\": \"../dist\"\n\t},\n\t\"include\": [\".\"]\n}\n"]}
1
+ {"version":3,"sources":["../../src/tsconfig.json"],"names":["extends"],"mappings":";;;AACC,IAAAA,QAAAA,GAAW;AACX,IAAA,eAAA,GAAmB;AAAA,EAClB,OAAA,EAAW,IAAA;AAAA,EACX,MAAA,EAAU;AACX;AACA,IAAA,OAAA,GAAW,CAAC,GAAG;AANhB,IAAA,gBAAA,GAAA;AAAA,EACC,OAAA,EAAAA,QAAAA;AAAA,EACA,eAAA;AAAA,EAIA;AACD","file":"tsconfig.mjs","sourcesContent":["{\n\t\"extends\": \"../tsconfig.base.json\",\n\t\"compilerOptions\": {\n\t\t\"rootDir\": \"./\",\n\t\t\"outDir\": \"../dist\"\n\t},\n\t\"include\": [\".\"]\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire/pieces",
3
- "version": "4.4.2-next.9fc01a6",
3
+ "version": "4.4.2-next.ad8b9f8",
4
4
  "description": "Sapphire's piece loader.",
5
5
  "main": "dist/cjs/index.cjs",
6
6
  "module": "dist/esm/index.mjs",
@@ -39,32 +39,32 @@
39
39
  "tslib": "^2.8.1"
40
40
  },
41
41
  "devDependencies": {
42
- "@commitlint/cli": "^19.8.1",
43
- "@commitlint/config-conventional": "^19.8.1",
42
+ "@commitlint/cli": "^20.1.0",
43
+ "@commitlint/config-conventional": "^20.0.0",
44
44
  "@favware/cliff-jumper": "^6.0.0",
45
45
  "@favware/npm-deprecate": "^2.0.0",
46
46
  "@favware/rollup-type-bundler": "^4.0.0",
47
47
  "@sapphire/eslint-config": "^5.0.6",
48
48
  "@sapphire/prettier-config": "^2.0.0",
49
- "@sapphire/ts-config": "^5.0.1",
50
- "@types/node": "^22.15.34",
49
+ "@sapphire/ts-config": "^5.0.3",
50
+ "@types/node": "^24.10.1",
51
51
  "@typescript-eslint/eslint-plugin": "^7.18.0",
52
52
  "@typescript-eslint/parser": "^7.18.0",
53
- "@vitest/coverage-v8": "^3.2.4",
54
- "concurrently": "^9.2.0",
53
+ "@vitest/coverage-v8": "^4.0.14",
54
+ "concurrently": "^9.2.1",
55
55
  "cz-conventional-changelog": "^3.3.0",
56
56
  "esbuild-plugin-file-path-extensions": "^2.1.4",
57
57
  "eslint": "^8.57.1",
58
- "eslint-config-prettier": "^10.1.5",
59
- "eslint-plugin-prettier": "^5.5.1",
60
- "lint-staged": "^16.1.2",
61
- "prettier": "^3.6.2",
62
- "rimraf": "^6.0.1",
63
- "tsup": "^8.5.0",
58
+ "eslint-config-prettier": "^10.1.8",
59
+ "eslint-plugin-prettier": "^5.5.4",
60
+ "lint-staged": "^16.2.7",
61
+ "prettier": "^3.7.1",
62
+ "rimraf": "^6.1.2",
63
+ "tsup": "^8.5.1",
64
64
  "typedoc": "^0.26.11",
65
65
  "typedoc-json-parser": "^10.2.0",
66
66
  "typescript": "^5.8.3",
67
- "vitest": "^3.2.4"
67
+ "vitest": "^4.0.14"
68
68
  },
69
69
  "repository": {
70
70
  "type": "git",
@@ -113,5 +113,5 @@
113
113
  "minimist": "^1.2.8"
114
114
  },
115
115
  "prettier": "@sapphire/prettier-config",
116
- "packageManager": "yarn@4.9.2"
116
+ "packageManager": "yarn@4.12.0"
117
117
  }