@sapphire/pieces 4.3.2-next.7ea1702 → 4.3.2-next.8b7e61a

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.
@@ -69,16 +69,16 @@ var _LoaderStrategy = class _LoaderStrategy {
69
69
  }
70
70
  }
71
71
  onLoad() {
72
- return void 0;
72
+ return undefined;
73
73
  }
74
74
  onLoadAll() {
75
- return void 0;
75
+ return undefined;
76
76
  }
77
77
  onUnload() {
78
- return void 0;
78
+ return undefined;
79
79
  }
80
80
  onUnloadAll() {
81
- return void 0;
81
+ return undefined;
82
82
  }
83
83
  onError(error, path) {
84
84
  console.error(`Error when loading '${path}':`, error);
@@ -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":";;;;;;;;;;;;;;;;;;;;;;AAyBO,IAAM,eAAA,GAAN,MAAM,eAA8D,CAAA;AAAA,EAKnE,WAAc,GAAA;AAJrB,IAAO,aAAA,CAAA,IAAA,EAAA,qBAAA,EAAsBA,wBAAY,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,IAAIC,8BAAwB,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,OAAOC,MAA4B,EAAA;AAEzC,IAAM,MAAA,SAAA,GAAYC,aAAQD,MAAI,CAAA;AAC9B,IAAA,IAAI,CAAC,I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H,MAAM,MAAA,GAAA,GAAM,MAAMS,gBAAA,CAAQT,MAAI,CAAA;AAC9B,MAAA,WAAA,MAAiB,QAAQ,GAAK,EAAA;AAC7B,QAAI,IAAA,IAAA,CAAK,QAAU,EAAA,MAAMU,UAAK,GAAI,CAAA,IAAA,EAAM,KAAK,IAAI,CAAA;AAAA,aAAA,IACxC,IAAK,CAAA,WAAA,EAAe,EAAA,OAAO,IAAK,CAAA,IAAA,CAAK,KAAO,EAAAA,SAAA,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,OAAgBV,MAAI,CAAA;AAAA;AAClF;AAEF,CAAA;AAzG2E,MAAA,CAAA,eAAA,EAAA,gBAAA,CAAA;AAApE,IAAM,cAAN,GAAA","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\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,eAA8D,CAAA;AAAA,EAKnE,WAAc,GAAA;AAJrB,IAAO,aAAA,CAAA,IAAA,EAAA,qBAAA,EAAsBA,wBAAY,EAAA,CAAE,I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AoB,GAAA;AAC1B,IAAO,OAAA,SAAA;AAAA;AACR,EAGO,WAAuB,GAAA;AAC7B,IAAO,OAAA,SAAA;AAAA;AACR,EAEO,OAAA,CAAQ,OAAc,IAAoB,EAAA;AAChD,IAAA,OAAA,CAAQ,KAAM,CAAA,CAAA,oBAAA,EAAuB,IAAI,CAAA,EAAA,CAAA,EAAM,KAAK,CAAA;AAAA;AACrD,EAEA,OAAc,IAAA,CAAK,KAAiB,EAAAR,MAAA,EAAc,MAA4D,EAAA;AAC7G,IAAA,MAAA,GAAS,CAAa,UAAA,EAAA,KAAA,CAAM,IAAI,CAAA,kCAAA,EAAqCA,MAAI,CAAI,EAAA,CAAA,CAAA;AAC7E,IAAI,IAAA;AACH,MAAM,MAAA,GAAA,GAAM,MAAMS,gBAAA,CAAQT,MAAI,CAAA;AAC9B,MAAA,WAAA,MAAiB,QAAQ,GAAK,EAAA;AAC7B,QAAI,IAAA,IAAA,CAAK,QAAU,EAAA,MAAMU,UAAK,GAAI,CAAA,IAAA,EAAM,KAAK,IAAI,CAAA;AAAA,aAAA,IACxC,IAAK,CAAA,WAAA,EAAe,EAAA,OAAO,IAAK,CAAA,IAAA,CAAK,KAAO,EAAAA,SAAA,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,OAAgBV,MAAI,CAAA;AAAA;AAClF;AAEF,CAAA;AAzG2E,MAAA,CAAA,eAAA,EAAA,gBAAA,CAAA;AAApE,IAAM,cAAN,GAAA","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\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"]}
@@ -26,9 +26,11 @@ var _AliasPiece = class _AliasPiece extends Piece_cjs.Piece {
26
26
  }
27
27
  };
28
28
  __name(_AliasPiece, "AliasPiece");
29
- exports.AliasPiece = _AliasPiece;
29
+ var AliasPiece = _AliasPiece;
30
30
  ((AliasPiece2) => {
31
31
  ({ Location: AliasPiece2.Location } = Piece_cjs.Piece);
32
- })(exports.AliasPiece || (exports.AliasPiece = {}));
32
+ })(AliasPiece);
33
+
34
+ exports.AliasPiece = AliasPiece;
33
35
  //# sourceMappingURL=AliasPiece.cjs.map
34
36
  //# sourceMappingURL=AliasPiece.cjs.map
@@ -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,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;AAHK,IAAM,UAAN,GAAA;AAAA,CAiCA,CAAUC,WAAV,KAAA;AACC,EAAM,CAAA,EAAE,QAAAA,EAAAA,WAAAA,CAAA,QAAa,EAAA,GAAAD,eAAA;AAAA,CADZ,EAAA,UAAA,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"]}
@@ -47,14 +47,14 @@ var _Piece = class _Piece {
47
47
  * Useful to set-up asynchronous initialization tasks.
48
48
  */
49
49
  onLoad() {
50
- return void 0;
50
+ return undefined;
51
51
  }
52
52
  /**
53
53
  * Per-piece listener that is called when the piece is unloaded from the store.
54
54
  * Useful to set-up clean-up tasks.
55
55
  */
56
56
  onUnload() {
57
- return void 0;
57
+ return undefined;
58
58
  }
59
59
  /**
60
60
  * Unloads and disables the piece.
@@ -82,9 +82,11 @@ var _Piece = class _Piece {
82
82
  }
83
83
  };
84
84
  __name(_Piece, "Piece");
85
- exports.Piece = _Piece;
85
+ var Piece = _Piece;
86
86
  ((Piece2) => {
87
87
  Piece2.Location = PieceLocation_cjs.PieceLocation;
88
- })(exports.Piece || (exports.Piece = {}));
88
+ })(Piece);
89
+
90
+ exports.Piece = Piece;
89
91
  //# sourceMappingURL=Piece.cjs.map
90
92
  //# sourceMappingURL=Piece.cjs.map
@@ -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,E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M,EAAA,IAAA,CAAK,SAAS,QAAQ,CAAA;AAAA;AACjE;AAAA;AAAA;AAAA,EAKO,MAAoB,GAAA;AAC1B,IAAO,OAAA;AAAA,MACN,QAAA,EAAU,IAAK,CAAA,QAAA,CAAS,MAAO,EAAA;AAAA,MAC/B,MAAM,IAAK,CAAA,IAAA;AAAA,MACX,SAAS,IAAK,CAAA,OAAA;AAAA,MACd,SAAS,IAAK,CAAA;AAAA,KACf;AAAA;AAEF,CAAA;AApFuH,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA;AAA1GC,aAAN,GAAA;AAAA,CAgGA,CAAUA,MAAV,KAAA;AACC,EAAMA,OAAA,QAAW,GAAAF,+BAAA;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,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,CAAK,WAAW,IAAIA,+BAAA,CAAc,OAAQ,CAAA,IAAA,EAAM,QAAQ,IAAI,CAAA;AAC5D,IAAK,IAAA,CAAA,IAAA,GAAO,OAAQ,CAAA,IAAA,IAAQ,OAAQ,CAAA,IAAA;AACpC,IAAK,IAAA,CAAA,OAAA,GAAU,QAAQ,OAAW,IAAA,IAAA;AAClC,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA;AAAA;AAChB;AAAA;AAAA;AAAA;AAAA,EAMA,IAAW,SAAuB,GAAA;AACjC,IAAO,OAAAC,uBAAA;AAAA;AACR;AAAA;AAAA;AAAA;AAAA,EAMO,MAA6B,GAAA;AACnC,IAAO,OAAA,SAAA;AAAA;AACR;AAAA;AAAA;AAAA;AAAA,EAMO,QAA+B,GAAA;AACrC,IAAO,OAAA,SAAA;AAAA;AACR;AAAA;AAAA;AAAA,EAKA,MAAa,MAAS,GAAA;AACrB,IAAA,MAAM,IAAK,CAAA,KAAA,CAAM,MAAO,CAAA,IAAA,CAAK,IAAI,CAAA;AACjC,IAAA,IAAA,CAAK,OAAU,GAAA,KAAA;AAAA;AAChB;AAAA;AAAA;AAAA,EAKA,MAAa,MAAS,GAAA;AACrB,IAAM,MAAA,IAAA,CAAK,MAAM,IAAK,CAAA,IAAA,CAAK,SAAS,IAAM,EAAA,IAAA,CAAK,SAAS,QAAQ,CAAA;AAAA;AACjE;AAAA;AAAA;AAAA,EAKO,MAAoB,GAAA;AAC1B,IAAO,OAAA;AAAA,MACN,QAAA,EAAU,IAAK,CAAA,QAAA,CAAS,MAAO,EAAA;AAAA,MAC/B,MAAM,IAAK,CAAA,IAAA;AAAA,MACX,SAAS,IAAK,CAAA,OAAA;AAAA,MACd,SAAS,IAAK,CAAA;AAAA,KACf;AAAA;AAEF,CAAA;AApFuH,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA;AAAhH,IAAM,KAAN,GAAA;AAAA,CAgGA,CAAUC,MAAV,KAAA;AACC,EAAMA,OAAA,QAAW,GAAAF,+BAAA;AAAA,CADR,EAAA,KAAA,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":";;;;;;;;;A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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,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"]}
@@ -300,9 +300,11 @@ __publicField(_Store, "defaultStrategy", defaultStrategy);
300
300
  * The default logger, defaults to `null`.
301
301
  */
302
302
  __publicField(_Store, "logger", null);
303
- exports.Store = _Store;
303
+ var Store = _Store;
304
304
  ((Store2) => {
305
305
  Store2.Registry = StoreRegistry_cjs.StoreRegistry;
306
- })(exports.Store || (exports.Store = {}));
306
+ })(Store);
307
+
308
+ exports.Store = Store;
307
309
  //# sourceMappingURL=Store.cjs.map
308
310
  //# sourceMappingURL=Store.cjs.map
@@ -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,qBAAA,EAShF,mDATgF,EAAsB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBjH,WAAA,CAAY,aAAqC,OAAqC,EAAA;AAC5F,IAAM,KAAA,EAAA;AAzBP,IAAgB,aAAA,CAAA,IAAA,EAAA,aAAA,CAAA;AAChB,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAChB,IAAgB,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA;AAChB,IAAgB,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAkB,aAAA,CAAA,IAAA,EAAA,EAAA,sBAAsC,GAAqD,EAAA,CAAA;AAK7G;AAAA;AAAA;AAAA,IAAiB,YAAA,CAAA,IAAA,EAAA,cAAA,EAAA,KAAA,CAAA;AAKjB;AAAA;AAAA;AAAA,IAAA,YAAA,CAAA,IAAA,EAAA,KAAA,CAAA;AAQC,IAAA,IAAA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AA,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,iCAAe,EAAA;AAjD3C,IAAA,EAAA,EAAA,EAAA,EAAA,cAAA,EAAA,KAAA;AAsDO,IAAM,MAAN,GAAA,MAAM,MAAsF,UAAA,EAAA,GAAAC,qBAAA,EAShF,mDATgF,EAAsB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBjH,WAAA,CAAY,aAAqC,OAAqC,EAAA;AAC5F,IAAM,KAAA,EAAA;AAzBP,IAAgB,aAAA,CAAA,IAAA,EAAA,aAAA,CAAA;AAChB,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAChB,IAAgB,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA;AAChB,IAAgB,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAkB,aAAA,CAAA,IAAA,EAAA,EAAA,sBAAsC,GAAqD,EAAA,CAAA;AAK7G;AAAA;AAAA;AAAA,IAAiB,YAAA,CAAA,IAAA,EAAA,cAAA,EAAA,KAAA,CAAA;AAKjB;AAAA;AAAA;AAAA,IAAA,YAAA,CAAA,IAAA,EAAA,KAAA,CAAA;AAQC,IAAA,IAAA,CAAK,WAAc,GAAA,WAAA;AACnB,IAAA,IAAA,CAAK,OAAO,OAAQ,CAAA,IAAA;AACpB,IAAA,IAAA,CAAK,QAAQ,IAAI,GAAA,CAAI,OAAQ,CAAA,KAAA,IAAS,EAAE,CAAA;AACxC,IAAK,IAAA,CAAA,QAAA,GAAW,OAAQ,CAAA,QAAA,I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,KAAA;AACC,EAAMA,OAAA,QAAW,GAAAC,+BAAA;AAAA,CADR,EAAA,KAAA,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"]}
@@ -58,16 +58,16 @@ var _LoaderStrategy = class _LoaderStrategy {
58
58
  }
59
59
  }
60
60
  onLoad() {
61
- return void 0;
61
+ return undefined;
62
62
  }
63
63
  onLoadAll() {
64
- return void 0;
64
+ return undefined;
65
65
  }
66
66
  onUnload() {
67
- return void 0;
67
+ return undefined;
68
68
  }
69
69
  onUnloadAll() {
70
- return void 0;
70
+ return undefined;
71
71
  }
72
72
  onError(error, path) {
73
73
  console.error(`Error when loading '${path}':`, error);
@@ -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,EAAM,IAAA,IAAA,CAAK,UAAW,CAAA,GAAG,GAAU,OAAA,IAAA;AAGhD,IAAO,OAAA,EAAE,SAAW,EAAA,IAAA,EAAM,IAAK,EAAA;AAAA;AAChC,EAEA,MAAa,QAAQ,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AAS,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,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,O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;AAC7B,QAAI,IAAA,IAAA,CAAK,QAAU,EAAA,MAAM,KAAK,GAAI,CAAA,IAAA,EAAM,KAAK,IAAI,CAAA;AAAA,aAAA,IACxC,IAAK,CAAA,WAAA,EAAe,EAAA,OAAO,IAAK,CAAA,IAAA,CAAK,KAAO,EAAA,IAAA,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"]}
@@ -24,7 +24,7 @@ __name(_AliasPiece, "AliasPiece");
24
24
  var AliasPiece = _AliasPiece;
25
25
  ((AliasPiece2) => {
26
26
  ({ Location: AliasPiece2.Location } = Piece);
27
- })(AliasPiece || (AliasPiece = {}));
27
+ })(AliasPiece);
28
28
 
29
29
  export { AliasPiece };
30
30
  //# sourceMappingURL=AliasPiece.mjs.map
@@ -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,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,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"]}
@@ -42,14 +42,14 @@ var _Piece = class _Piece {
42
42
  * Useful to set-up asynchronous initialization tasks.
43
43
  */
44
44
  onLoad() {
45
- return void 0;
45
+ return undefined;
46
46
  }
47
47
  /**
48
48
  * Per-piece listener that is called when the piece is unloaded from the store.
49
49
  * Useful to set-up clean-up tasks.
50
50
  */
51
51
  onUnload() {
52
- return void 0;
52
+ return undefined;
53
53
  }
54
54
  /**
55
55
  * Unloads and disables the piece.
@@ -80,7 +80,7 @@ __name(_Piece, "Piece");
80
80
  var Piece = _Piece;
81
81
  ((Piece2) => {
82
82
  Piece2.Location = PieceLocation;
83
- })(Piece || (Piece = {}));
83
+ })(Piece);
84
84
 
85
85
  export { Piece };
86
86
  //# sourceMappingURL=Piece.mjs.map
@@ -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,IAAA,EAAA,SAAA,CAAA;AAGf,IAAA,IAAA,CAAK,QAAQ,OAAQ,CAAA,KAAA;AACrB,IAAA,IAAA,CAAK,WAAW,IAAI,aAAA,CAAc,OAAQ,CAAA,IAAA,EAAM,QAAQ,IAAI,CAAA;AAC5D,IAAK,IAAA,CAAA,IAAA,GAAO,OAAQ,CAAA,IAAA,IAAQ,OAAQ,CAAA,IAAA;AACpC,IAAK,IAAA,CAAA,OAAA,GAAU,QAAQ,OAAW,IAAA,IAAA;AAClC,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA;AAAA;AAChB;AAAA;AAAA;AAAA;AAAA,EAMA,IAAW,SAAuB,GAAA;AACjC,IAAO,OAAA,SAAA;AAAA;AACR;AAAA;AAAA;AAAA;AAAA,EAMO,MAA6B,GAAA;AACnC,IAAO,OAAA,KAAA,CAAA;AAAA;AACR;AAAA;AAAA;AAAA;AAAA,EAMO,QAA+B,GAAA;AACrC,IAAO,OAAA,KAAA,CAAA;AAAA;AACR;AAAA;AAAA;AAAA,EAKA,MAAa,MAAS,GAAA;AACrB,IAAA,MAAM,IAAK,CAAA,KAAA,CAAM,MAAO,CAAA,IAAA,CAAK,IAAI,CAAA;AACjC,IAAA,IAAA,CAAK,OAAU,GAAA,KAAA;AAAA;AAChB;AAAA;AAAA;AAAA,EAKA,MAAa,MAAS,GAAA;AACrB,IAAM,MAAA,IAAA,CAAK,MAAM,IAAK,CAAA,IAAA,CAAK,SAAS,IAAM,EAAA,IAAA,CAAK,SAAS,QAAQ,CAAA;AAAA;AACjE;AAAA;AAAA;AAAA,EAKO,MAAoB,GAAA;AAC1B,IAAO,OAAA;AAAA,MACN,QAAA,EAAU,IAAK,CAAA,QAAA,CAAS,MAAO,EAAA;AAAA,MAC/B,MAAM,IAAK,CAAA,IAAA;AAAA,MACX,SAAS,IAAK,CAAA,OAAA;AAAA,MACd,SAAS,IAAK,CAAA;AAAA,KACf;AAAA;AAEF,CAAA;AApFuH,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA;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,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,MAA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,IAAK,CAAA,OAAA;AAAA,MACd,SAAS,IAAK,CAAA;AAAA,KACf;AAAA;AAEF,CAAA;AApFuH,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA;AAAhH,IAAM,KAAN,GAAA;AAAA,CAgGA,CAAUA,MAAV,KAAA;AACC,EAAMA,OAAA,QAAW,GAAA,aAAA;AAAA,CADR,EAAA,KAAA,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,CAAE,CAAA,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,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"]}
@@ -291,7 +291,7 @@ __publicField(_Store, "logger", null);
291
291
  var Store = _Store;
292
292
  ((Store2) => {
293
293
  Store2.Registry = StoreRegistry;
294
- })(Store || (Store = {}));
294
+ })(Store);
295
295
 
296
296
  export { Store };
297
297
  //# sourceMappingURL=Store.mjs.map
@@ -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,EAAA;AAzBP,IAAgB,aAAA,CAAA,IAAA,EAAA,aAAA,CAAA;AAChB,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAChB,IAAgB,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA;AAChB,IAAgB,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAkB,aAAA,CAAA,IAAA,EAAA,EAAA,sBAAsC,GAAqD,EAAA,CAAA;AAK7G;AAAA;AAAA;AAAA,IAAiB,YAAA,CAAA,IAAA,EAAA,cAAA,EAAA,KAAA,CAAA;AAKjB;AAAA;AAAA;AAAA,IAAA,YAAA,CAAA,IAAA,EAAA,KAAA,CAAA;AAQ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A;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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AAL,WAAW,IAAM,EAAA,IAAA,EAAM,OAAM,MAAS,CAAA,EAAA;AAC/D,MAAA,MAAM,IAAO,GAAA,IAAA,CAAK,QAAS,CAAA,MAAA,CAAO,KAAK,CAAA;AACvC,MAAA,IAAI,SAAS,IAAM,EAAA;AAClB,QAAA,MAAA,CAAM,SAAS,CAAa,UAAA,EAAA,IAAA,CAAK,IAAI,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;AAvUrC,IAAM,KAAN,GAAA;AAAA,CAmVA,CAAUA,MAAV,KAAA;AACC,EAAMA,OAAA,QAAW,GAAA,aAAA;AAAA,CADR,EAAA,KAAA,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire/pieces",
3
- "version": "4.3.2-next.7ea1702",
3
+ "version": "4.3.2-next.8b7e61a",
4
4
  "description": "Sapphire's piece loader.",
5
5
  "main": "dist/cjs/index.cjs",
6
6
  "module": "dist/esm/index.mjs",
@@ -26,7 +26,7 @@
26
26
  "test": "vitest run",
27
27
  "build": "tsup && concurrently \"yarn:postbuild:*\"",
28
28
  "postbuild:internal": "node scripts/make-import.mjs",
29
- "postbuild:types:cjs": "rollup-type-bundler -d dist/cjs -ot .cts",
29
+ "postbuild:types:cjs": "rollup-type-bundler -d dist/cjs --output-typings-file-extension .cts",
30
30
  "postbuild:types:esm": "rollup-type-bundler -d dist/esm -t .mts",
31
31
  "typecheck": "tsc -b src",
32
32
  "bump": "cliff-jumper",
@@ -35,36 +35,36 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@discordjs/collection": "^1.5.3",
38
- "@sapphire/utilities": "^3.18.1",
38
+ "@sapphire/utilities": "^3.18.2",
39
39
  "tslib": "^2.8.1"
40
40
  },
41
41
  "devDependencies": {
42
- "@commitlint/cli": "^19.6.0",
43
- "@commitlint/config-conventional": "^19.6.0",
44
- "@favware/cliff-jumper": "^5.0.0",
42
+ "@commitlint/cli": "^19.7.1",
43
+ "@commitlint/config-conventional": "^19.7.1",
44
+ "@favware/cliff-jumper": "^6.0.0",
45
45
  "@favware/npm-deprecate": "^2.0.0",
46
- "@favware/rollup-type-bundler": "^3.3.0",
46
+ "@favware/rollup-type-bundler": "^4.0.0",
47
47
  "@sapphire/eslint-config": "^5.0.5",
48
48
  "@sapphire/prettier-config": "^2.0.0",
49
49
  "@sapphire/ts-config": "^5.0.1",
50
- "@types/node": "^22.10.1",
50
+ "@types/node": "^22.13.4",
51
51
  "@typescript-eslint/eslint-plugin": "^7.13.1",
52
52
  "@typescript-eslint/parser": "^7.13.1",
53
- "@vitest/coverage-v8": "^2.1.8",
54
- "concurrently": "^9.1.0",
53
+ "@vitest/coverage-v8": "^3.0.5",
54
+ "concurrently": "^9.1.2",
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": "^9.1.0",
59
- "eslint-plugin-prettier": "^5.2.1",
60
- "lint-staged": "^15.2.10",
61
- "prettier": "^3.4.2",
58
+ "eslint-config-prettier": "^10.0.1",
59
+ "eslint-plugin-prettier": "^5.2.3",
60
+ "lint-staged": "^15.4.3",
61
+ "prettier": "^3.5.1",
62
62
  "rimraf": "^6.0.1",
63
- "tsup": "^8.3.5",
63
+ "tsup": "^8.3.6",
64
64
  "typedoc": "^0.26.11",
65
65
  "typedoc-json-parser": "^10.2.0",
66
66
  "typescript": "^5.5.2",
67
- "vitest": "^2.1.8"
67
+ "vitest": "^3.0.5"
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.5.3"
116
+ "packageManager": "yarn@4.6.0"
117
117
  }