@sapphire/pieces 4.3.1 → 4.3.2-next.1242e23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/lib/errors/LoaderError.cjs +1 -1
- package/dist/cjs/lib/errors/LoaderError.cjs.map +1 -1
- package/dist/cjs/lib/errors/MissingExportsError.cjs +1 -1
- package/dist/cjs/lib/errors/MissingExportsError.cjs.map +1 -1
- package/dist/cjs/lib/internal/Path.cjs +1 -1
- package/dist/cjs/lib/internal/Path.cjs.map +1 -1
- package/dist/cjs/lib/internal/RootScan.cjs +1 -1
- package/dist/cjs/lib/internal/RootScan.cjs.map +1 -1
- package/dist/cjs/lib/internal/constants.cjs +1 -1
- package/dist/cjs/lib/internal/constants.cjs.map +1 -1
- package/dist/cjs/lib/internal/internal.d.cjs +4 -0
- package/dist/cjs/lib/internal/internal.d.cjs.map +1 -0
- package/dist/cjs/lib/shared/Container.cjs +1 -1
- package/dist/cjs/lib/shared/Container.cjs.map +1 -1
- package/dist/cjs/lib/strategies/ILoaderStrategy.cjs +1 -1
- package/dist/cjs/lib/strategies/ILoaderStrategy.cjs.map +1 -1
- package/dist/cjs/lib/strategies/LoaderStrategy.cjs +1 -1
- package/dist/cjs/lib/strategies/LoaderStrategy.cjs.map +1 -1
- package/dist/cjs/lib/strategies/Shared.cjs +1 -1
- package/dist/cjs/lib/strategies/Shared.cjs.map +1 -1
- package/dist/cjs/lib/strategies/env.cjs +1 -1
- package/dist/cjs/lib/strategies/env.cjs.map +1 -1
- package/dist/cjs/lib/structures/AliasPiece.cjs +1 -1
- package/dist/cjs/lib/structures/AliasPiece.cjs.map +1 -1
- package/dist/cjs/lib/structures/AliasStore.cjs +1 -1
- package/dist/cjs/lib/structures/AliasStore.cjs.map +1 -1
- package/dist/cjs/lib/structures/Piece.cjs +1 -1
- package/dist/cjs/lib/structures/Piece.cjs.map +1 -1
- package/dist/cjs/lib/structures/PieceLocation.cjs +1 -1
- package/dist/cjs/lib/structures/PieceLocation.cjs.map +1 -1
- package/dist/cjs/lib/structures/Store.cjs +1 -1
- package/dist/cjs/lib/structures/Store.cjs.map +1 -1
- package/dist/cjs/lib/structures/StoreRegistry.cjs +1 -1
- package/dist/cjs/lib/structures/StoreRegistry.cjs.map +1 -1
- package/dist/cjs/tsconfig.cjs +23 -0
- package/dist/cjs/tsconfig.cjs.map +1 -0
- package/dist/esm/chunk-KFLDEQ5J.mjs +1 -1
- package/dist/esm/chunk-KFLDEQ5J.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/errors/LoaderError.mjs +1 -1
- package/dist/esm/lib/errors/LoaderError.mjs.map +1 -1
- package/dist/esm/lib/errors/MissingExportsError.mjs +1 -1
- package/dist/esm/lib/errors/MissingExportsError.mjs.map +1 -1
- package/dist/esm/lib/internal/Path.mjs +1 -1
- package/dist/esm/lib/internal/Path.mjs.map +1 -1
- package/dist/esm/lib/internal/RootScan.mjs +1 -1
- package/dist/esm/lib/internal/RootScan.mjs.map +1 -1
- package/dist/esm/lib/internal/constants.mjs +1 -1
- package/dist/esm/lib/internal/constants.mjs.map +1 -1
- package/dist/esm/lib/internal/internal.d.mjs +3 -0
- package/dist/esm/lib/internal/internal.d.mjs.map +1 -0
- package/dist/esm/lib/shared/Container.mjs +1 -1
- package/dist/esm/lib/shared/Container.mjs.map +1 -1
- package/dist/esm/lib/strategies/ILoaderStrategy.mjs +1 -1
- package/dist/esm/lib/strategies/ILoaderStrategy.mjs.map +1 -1
- package/dist/esm/lib/strategies/LoaderStrategy.mjs +1 -1
- package/dist/esm/lib/strategies/LoaderStrategy.mjs.map +1 -1
- package/dist/esm/lib/strategies/Shared.mjs +1 -1
- package/dist/esm/lib/strategies/Shared.mjs.map +1 -1
- package/dist/esm/lib/strategies/env.mjs +1 -1
- package/dist/esm/lib/strategies/env.mjs.map +1 -1
- package/dist/esm/lib/structures/AliasPiece.mjs +1 -1
- package/dist/esm/lib/structures/AliasPiece.mjs.map +1 -1
- package/dist/esm/lib/structures/AliasStore.mjs +1 -1
- package/dist/esm/lib/structures/AliasStore.mjs.map +1 -1
- package/dist/esm/lib/structures/Piece.mjs +1 -1
- package/dist/esm/lib/structures/Piece.mjs.map +1 -1
- package/dist/esm/lib/structures/PieceLocation.mjs +1 -1
- package/dist/esm/lib/structures/PieceLocation.mjs.map +1 -1
- package/dist/esm/lib/structures/Store.mjs +1 -1
- package/dist/esm/lib/structures/Store.mjs.map +1 -1
- package/dist/esm/lib/structures/StoreRegistry.mjs +1 -1
- package/dist/esm/lib/structures/StoreRegistry.mjs.map +1 -1
- package/dist/esm/tsconfig.mjs +18 -0
- package/dist/esm/tsconfig.mjs.map +1 -0
- package/package.json +19 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/StoreRegistry.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,OAA4B;AAC5B,SAAS,mBAA8B;AACvC,SAAS,mBAAmB;AAC5B,SAAS,sCAAmD;AAN5D;AA8BO,IAAM,iBAAN,MAAM,uBAAsB,WAAiD;AAAA,EAA7E;AAAA;AAIN;AAAA;AAAA;AAAA,uBAAS,kCAAmC,IAAI,WAA+E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM/H,MAAa,OAAO;AACnB,UAAM,WAA+B,CAAC;AACtC,eAAW,SAAS,KAAK,OAAO,GAAqC;AACpE,eAAS,KAAK,MAAM,QAAQ,CAAC;AAAA,IAC9B;AAEA,UAAM,QAAQ,IAAI,QAAQ;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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O,MAAM,KAAK,CAAC,EAAE;AAAA,MACrF;AAEA,yBAAK,kCAAiC,OAAO,MAAM,OAAO,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,MAAM,MAAM,OAAO,MAAM,MAAM,CAAC;AAAA,IAClH;AAAA,EACD;AACD;AAlJU;AAJ0E;AAA7E,IAAM,gBAAN","sourcesContent":["import { Collection } from '@discordjs/collection';\nimport { isClass } from '@sapphire/utilities';\nimport { join } from 'path';\nimport { LoaderError } from '../errors/LoaderError';\nimport { resolvePath, type Path } from '../internal/Path';\nimport { getRootData } from '../internal/RootScan';\nimport { ManuallyRegisteredPiecesSymbol, VirtualPath } from '../internal/constants';\nimport type { Piece } from './Piece';\nimport type { Store, StoreManuallyRegisteredPiece } from './Store';\n\n/**\n * A strict-typed store registry. This is available in {@link container}.\n * @since 2.1.0\n * @example\n * ```typescript\n * // Adding new stores\n *\n * // Register the store:\n * container.stores.register(new RouteStore());\n *\n * // Augment Sapphire to add the new store, in case of a JavaScript\n * // project, this can be moved to an `Augments.d.ts` (or any other name)\n * // file somewhere:\n * declare module '@sapphire/pieces' {\n * export interface StoreRegistryEntries {\n * routes: RouteStore;\n * }\n * }\n * ```\n */\nexport class StoreRegistry extends Collection<StoreRegistryKey, StoreRegistryValue> {\n\t/**\n\t * The queue of pieces to load.\n\t */\n\treadonly #pendingManuallyRegisteredPieces = new Collection<StoreRegistryKey, StoreManuallyRegisteredPiece<StoreRegistryKey>[]>();\n\n\t/**\n\t * Loads all the registered stores.\n\t * @since 2.1.0\n\t */\n\tpublic async load() {\n\t\tconst promises: Promise<unknown>[] = [];\n\t\tfor (const store of this.values() as IterableIterator<Store<Piece>>) {\n\t\t\tpromises.push(store.loadAll());\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * Registers all user directories from the process working directory, the default value is obtained by assuming\n\t * CommonJS (high accuracy) but with fallback for ECMAScript Modules (reads package.json's `main` entry, fallbacks\n\t * to `process.cwd()`).\n\t *\n\t * By default, if you have this folder structure:\n\t * ```\n\t * /home/me/my-bot\n\t * ├─ src\n\t * │ ├─ commands\n\t * │ ├─ events\n\t * │ └─ main.js\n\t * └─ package.json\n\t * ```\n\t *\n\t * And you run `node src/main.js`, the directories `/home/me/my-bot/src/commands` and `/home/me/my-bot/src/events` will\n\t * be registered for the commands and events stores respectively, since both directories are located in the same\n\t * directory as your main file.\n\t *\n\t * **Note**: this also registers directories for all other stores, even if they don't have a folder, this allows you\n\t * to create new pieces and hot-load them later anytime.\n\t * @since 2.1.0\n\t * @param rootDirectory The root directory to register pieces at.\n\t */\n\tpublic registerPath(rootDirectory: Path = getRootData().root) {\n\t\tconst root = resolvePath(rootDirectory);\n\t\tfor (const store of this.values() as IterableIterator<Store<Piece>>) {\n\t\t\tstore.registerPath(join(root, store.name));\n\t\t}\n\t}\n\n\t/**\n\t * Registers a store.\n\t *\n\t * @remarks\n\t *\n\t * - This method will allow {@linkcode StoreRegistry} to manage the store, meaning:\n\t * - {@linkcode StoreRegistry.registerPath()} will call the store's\n\t * {@linkcode Store.registerPath() registerPath()} method on call.\n\t * - {@linkcode StoreRegistry.load()} will call the store's {@linkcode Store.load() load()} method on call.\n\t * - {@linkcode StoreRegistry.loadPiece()} will call the store's {@linkcode Store.loadPiece() loadPiece()} method\n\t * on call.\n\t * - This will also add all the manually registered pieces by {@linkcode StoreRegistry.loadPiece()} in the store.\n\t *\n\t * It is generally recommended to register a store as early as possible, before any of the aforementioned methods\n\t * are called, otherwise you will have to manually call the aforementioned methods for the store to work properly.\n\t *\n\t * If there were manually registered pieces for this store with {@linkcode StoreRegistry.loadPiece()}, this method\n\t * will add them to the store and delete the queue. Note, however, that this method will not call the store's\n\t * {@linkcode Store.loadPiece() loadPiece()} method, and as such, the pieces will not be loaded until\n\t * {@linkcode Store.loadAll()} is called.\n\t *\n\t * @since 2.1.0\n\t * @param store The store to register.\n\t */\n\tpublic register<T extends Piece>(store: Store<T>): this {\n\t\tthis.set(store.name as StoreRegistryKey, store as unknown as StoreRegistryValue);\n\n\t\t// If there was a queue for this store, add it to the store and delete the queue:\n\t\tconst queue = this.#pendingManuallyRegisteredPieces.get(store.name);\n\t\tif (queue) {\n\t\t\tfor (const entry of queue) {\n\t\t\t\tstore[ManuallyRegisteredPiecesSymbol].set(entry.name, entry);\n\t\t\t}\n\n\t\t\tthis.#pendingManuallyRegisteredPieces.delete(store.name);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Deregisters a store.\n\t * @since 2.1.0\n\t * @param store The store to deregister.\n\t */\n\tpublic deregister<T extends Piece>(store: Store<T>): this {\n\t\tthis.delete(store.name as StoreRegistryKey);\n\t\treturn this;\n\t}\n\n\t/**\n\t * If the store was {@link StoreRegistry.register registered}, this method will call the store's\n\t * {@linkcode Store.loadPiece() loadPiece()} method.\n\t *\n\t * If it was called, the entry will be loaded immediately without queueing.\n\t *\n\t * @remarks\n\t *\n\t * - Pieces loaded this way will have their {@linkcode Piece.Context.root root} and\n\t * {@linkcode Piece.Context.path path} set to {@linkcode VirtualPath}, and as such, cannot be reloaded.\n\t * - This method is useful in environments where file system access is limited or unavailable, such as when using\n\t * {@link https://en.wikipedia.org/wiki/Serverless_computing Serverless Computing}.\n\t * - This method will not throw an error if a store with the given name does not exist, it will simply be queued\n\t * until it's registered.\n\t * - This method will always throw a {@link TypeError} if `entry.piece` is not a class.\n\t * - If the store is registered, this method will always throw a {@linkcode LoaderError} if the piece does not\n\t * extend the registered {@linkcode Store.Constructor store's piece constructor}.\n\t * - This operation is atomic, if any of the above errors are thrown, the piece will not be loaded.\n\t *\n\t * @seealso {@linkcode Store.loadPiece()}\n\t * @since 3.8.0\n\t * @param entry The entry to load.\n\t * @example\n\t * ```typescript\n\t * import { container } from '@sapphire/pieces';\n\t *\n\t * class PingCommand extends Command {\n\t * // ...\n\t * }\n\t *\n\t * container.stores.loadPiece({\n\t * store: 'commands',\n\t * name: 'ping',\n\t * piece: PingCommand\n\t * });\n\t * ```\n\t */\n\tpublic async loadPiece<StoreName extends StoreRegistryKey>(entry: StoreManagerManuallyRegisteredPiece<StoreName>) {\n\t\tconst store = this.get(entry.store) as Store<Piece, StoreName> | undefined;\n\n\t\tif (store) {\n\t\t\tawait store.loadPiece(entry);\n\t\t} else {\n\t\t\tif (!isClass(entry.piece)) {\n\t\t\t\tthrow new TypeError(`The piece ${entry.name} is not a Class. ${String(entry.piece)}`);\n\t\t\t}\n\n\t\t\tthis.#pendingManuallyRegisteredPieces.ensure(entry.store, () => []).push({ name: entry.name, piece: entry.piece });\n\t\t}\n\t}\n}\n\nexport interface StoreRegistry {\n\tget<K extends StoreRegistryKey>(key: K): StoreRegistryEntries[K];\n\tget(key: string): undefined;\n\thas(key: StoreRegistryKey): true;\n\thas(key: string): false;\n}\n\n/**\n * A type utility to get the keys of {@linkcode StoreRegistryEntries}.\n * @since 3.10.0\n */\nexport type StoreRegistryKey = keyof StoreRegistryEntries;\n\n/**\n * A type utility to get the values of {@linkcode StoreRegistryEntries}.\n * @since 3.10.0\n */\nexport type StoreRegistryValue = StoreRegistryEntries[StoreRegistryKey];\n\n/**\n * The {@link StoreRegistry}'s registry, use module augmentation against this interface when adding new stores.\n * @since 2.1.0\n */\nexport interface StoreRegistryEntries {}\n\n/**\n * An entry for a manually registered piece using {@linkcode StoreRegistry.loadPiece()}.\n * @seealso {@linkcode StoreRegistry.loadPiece()}\n * @since 3.8.0\n */\nexport interface StoreManagerManuallyRegisteredPiece<StoreName extends StoreRegistryKey> extends StoreManuallyRegisteredPiece<StoreName> {\n\tstore: StoreName;\n}\n\n/**\n * Type utility to get the {@linkcode Store} given its name.\n * @since 3.10.0\n */\nexport type StoreOf<StoreName extends StoreRegistryKey> = StoreRegistryKey extends never\n\t? Store<Piece<Piece.Options, StoreName>>\n\t: StoreRegistryEntries[StoreName];\n\n/**\n * Type utility to get the {@linkcode Piece} given its {@linkcode Store}'s name.\n * @since 3.10.0\n */\nexport type PieceOf<StoreName extends StoreRegistryKey> = StoreRegistryKey extends never\n\t? Piece<Piece.Options, StoreName>\n\t: StoreRegistryEntries[StoreName] extends Store<infer PieceType>\n\t\t? PieceType\n\t\t: Piece<Piece.Options, StoreName>;\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/StoreRegistry.ts"],"names":["Collection","getRootData","resolvePath","join","ManuallyRegisteredPiecesSymbol","isClass"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAA,gCAAA,CAAA;AA8BO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsBA,qBAAiD,CAAA;AAAA,EAA7E,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAS,YAAA,CAAA,IAAA,EAAA,gCAAA,EAAmC,IAAIA,qBAA+E,EAAA,CAAA,CAAA;AAAA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM/H,MAAa,IAAO,GAAA;AACnB,IAAA,MAAM,WAA+B,EAAC,CAAA;AACtC,IAAW,KAAA,MAAA,KAAA,IAAS,IAAK,CAAA,MAAA,EAA4C,EAAA;AACpE,MAAS,QAAA,CAAA,IAAA,CAAK,KAAM,CAAA,OAAA,EAAS,CAAA,CAAA;AAAA,KAC9B;AAEA,IAAM,MAAA,OAAA,CAAQ,IAAI,QAAQ,CAAA,CAAA;AAAA,GAC3B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0BO,YAAa,CAAA,aAAA,GAAsBC,wBAAY,EAAA,CAAE,IAAM,EAAA;AAC7D,IAAM,MAAA,IAAA,GAAOC,qBAAY,aAAa,CAAA,CAAA;AACtC,IAAW,KAAA,MAAA,KAAA,IAAS,IAAK,CAAA,MAAA,EAA4C,EAAA;AACpE,MAAA,KAAA,CAAM,YAAa,CAAAC,SAAA,CAAK,IAAM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AA,CAAK,GAAI,CAAA,KAAA,CAAM,KAAK,CAAA,CAAA;AAElC,IAAA,IAAI,KAAO,EAAA;AACV,MAAM,MAAA,KAAA,CAAM,UAAU,KAAK,CAAA,CAAA;AAAA,KACrB,MAAA;AACN,MAAA,IAAI,CAACC,iBAAA,CAAQ,KAAM,CAAA,KAAK,CAAG,EAAA;AAC1B,QAAM,MAAA,IAAI,SAAU,CAAA,CAAA,UAAA,EAAa,KAAM,CAAA,IAAI,oBAAoB,MAAO,CAAA,KAAA,CAAM,KAAK,CAAC,CAAE,CAAA,CAAA,CAAA;AAAA,OACrF;AAEA,MAAA,YAAA,CAAA,IAAA,EAAK,kCAAiC,MAAO,CAAA,KAAA,CAAM,KAAO,EAAA,MAAM,EAAE,CAAA,CAAE,IAAK,CAAA,EAAE,MAAM,KAAM,CAAA,IAAA,EAAM,KAAO,EAAA,KAAA,CAAM,OAAO,CAAA,CAAA;AAAA,KAClH;AAAA,GACD;AACD,CAAA,CAAA;AAlJU,gCAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AAJ0E,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA,CAAA;AAA7E,IAAM,aAAN,GAAA","file":"StoreRegistry.cjs","sourcesContent":["import { Collection } from '@discordjs/collection';\nimport { isClass } from '@sapphire/utilities';\nimport { join } from 'path';\nimport { LoaderError } from '../errors/LoaderError';\nimport { resolvePath, type Path } from '../internal/Path';\nimport { getRootData } from '../internal/RootScan';\nimport { ManuallyRegisteredPiecesSymbol, VirtualPath } from '../internal/constants';\nimport type { Piece } from './Piece';\nimport type { Store, StoreManuallyRegisteredPiece } from './Store';\n\n/**\n * A strict-typed store registry. This is available in {@link container}.\n * @since 2.1.0\n * @example\n * ```typescript\n * // Adding new stores\n *\n * // Register the store:\n * container.stores.register(new RouteStore());\n *\n * // Augment Sapphire to add the new store, in case of a JavaScript\n * // project, this can be moved to an `Augments.d.ts` (or any other name)\n * // file somewhere:\n * declare module '@sapphire/pieces' {\n * export interface StoreRegistryEntries {\n * routes: RouteStore;\n * }\n * }\n * ```\n */\nexport class StoreRegistry extends Collection<StoreRegistryKey, StoreRegistryValue> {\n\t/**\n\t * The queue of pieces to load.\n\t */\n\treadonly #pendingManuallyRegisteredPieces = new Collection<StoreRegistryKey, StoreManuallyRegisteredPiece<StoreRegistryKey>[]>();\n\n\t/**\n\t * Loads all the registered stores.\n\t * @since 2.1.0\n\t */\n\tpublic async load() {\n\t\tconst promises: Promise<unknown>[] = [];\n\t\tfor (const store of this.values() as IterableIterator<Store<Piece>>) {\n\t\t\tpromises.push(store.loadAll());\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * Registers all user directories from the process working directory, the default value is obtained by assuming\n\t * CommonJS (high accuracy) but with fallback for ECMAScript Modules (reads package.json's `main` entry, fallbacks\n\t * to `process.cwd()`).\n\t *\n\t * By default, if you have this folder structure:\n\t * ```\n\t * /home/me/my-bot\n\t * ├─ src\n\t * │ ├─ commands\n\t * │ ├─ events\n\t * │ └─ main.js\n\t * └─ package.json\n\t * ```\n\t *\n\t * And you run `node src/main.js`, the directories `/home/me/my-bot/src/commands` and `/home/me/my-bot/src/events` will\n\t * be registered for the commands and events stores respectively, since both directories are located in the same\n\t * directory as your main file.\n\t *\n\t * **Note**: this also registers directories for all other stores, even if they don't have a folder, this allows you\n\t * to create new pieces and hot-load them later anytime.\n\t * @since 2.1.0\n\t * @param rootDirectory The root directory to register pieces at.\n\t */\n\tpublic registerPath(rootDirectory: Path = getRootData().root) {\n\t\tconst root = resolvePath(rootDirectory);\n\t\tfor (const store of this.values() as IterableIterator<Store<Piece>>) {\n\t\t\tstore.registerPath(join(root, store.name));\n\t\t}\n\t}\n\n\t/**\n\t * Registers a store.\n\t *\n\t * @remarks\n\t *\n\t * - This method will allow {@linkcode StoreRegistry} to manage the store, meaning:\n\t * - {@linkcode StoreRegistry.registerPath()} will call the store's\n\t * {@linkcode Store.registerPath() registerPath()} method on call.\n\t * - {@linkcode StoreRegistry.load()} will call the store's {@linkcode Store.load() load()} method on call.\n\t * - {@linkcode StoreRegistry.loadPiece()} will call the store's {@linkcode Store.loadPiece() loadPiece()} method\n\t * on call.\n\t * - This will also add all the manually registered pieces by {@linkcode StoreRegistry.loadPiece()} in the store.\n\t *\n\t * It is generally recommended to register a store as early as possible, before any of the aforementioned methods\n\t * are called, otherwise you will have to manually call the aforementioned methods for the store to work properly.\n\t *\n\t * If there were manually registered pieces for this store with {@linkcode StoreRegistry.loadPiece()}, this method\n\t * will add them to the store and delete the queue. Note, however, that this method will not call the store's\n\t * {@linkcode Store.loadPiece() loadPiece()} method, and as such, the pieces will not be loaded until\n\t * {@linkcode Store.loadAll()} is called.\n\t *\n\t * @since 2.1.0\n\t * @param store The store to register.\n\t */\n\tpublic register<T extends Piece>(store: Store<T>): this {\n\t\tthis.set(store.name as StoreRegistryKey, store as unknown as StoreRegistryValue);\n\n\t\t// If there was a queue for this store, add it to the store and delete the queue:\n\t\tconst queue = this.#pendingManuallyRegisteredPieces.get(store.name);\n\t\tif (queue) {\n\t\t\tfor (const entry of queue) {\n\t\t\t\tstore[ManuallyRegisteredPiecesSymbol].set(entry.name, entry);\n\t\t\t}\n\n\t\t\tthis.#pendingManuallyRegisteredPieces.delete(store.name);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Deregisters a store.\n\t * @since 2.1.0\n\t * @param store The store to deregister.\n\t */\n\tpublic deregister<T extends Piece>(store: Store<T>): this {\n\t\tthis.delete(store.name as StoreRegistryKey);\n\t\treturn this;\n\t}\n\n\t/**\n\t * If the store was {@link StoreRegistry.register registered}, this method will call the store's\n\t * {@linkcode Store.loadPiece() loadPiece()} method.\n\t *\n\t * If it was called, the entry will be loaded immediately without queueing.\n\t *\n\t * @remarks\n\t *\n\t * - Pieces loaded this way will have their {@linkcode Piece.Context.root root} and\n\t * {@linkcode Piece.Context.path path} set to {@linkcode VirtualPath}, and as such, cannot be reloaded.\n\t * - This method is useful in environments where file system access is limited or unavailable, such as when using\n\t * {@link https://en.wikipedia.org/wiki/Serverless_computing Serverless Computing}.\n\t * - This method will not throw an error if a store with the given name does not exist, it will simply be queued\n\t * until it's registered.\n\t * - This method will always throw a {@link TypeError} if `entry.piece` is not a class.\n\t * - If the store is registered, this method will always throw a {@linkcode LoaderError} if the piece does not\n\t * extend the registered {@linkcode Store.Constructor store's piece constructor}.\n\t * - This operation is atomic, if any of the above errors are thrown, the piece will not be loaded.\n\t *\n\t * @seealso {@linkcode Store.loadPiece()}\n\t * @since 3.8.0\n\t * @param entry The entry to load.\n\t * @example\n\t * ```typescript\n\t * import { container } from '@sapphire/pieces';\n\t *\n\t * class PingCommand extends Command {\n\t * // ...\n\t * }\n\t *\n\t * container.stores.loadPiece({\n\t * store: 'commands',\n\t * name: 'ping',\n\t * piece: PingCommand\n\t * });\n\t * ```\n\t */\n\tpublic async loadPiece<StoreName extends StoreRegistryKey>(entry: StoreManagerManuallyRegisteredPiece<StoreName>) {\n\t\tconst store = this.get(entry.store) as Store<Piece, StoreName> | undefined;\n\n\t\tif (store) {\n\t\t\tawait store.loadPiece(entry);\n\t\t} else {\n\t\t\tif (!isClass(entry.piece)) {\n\t\t\t\tthrow new TypeError(`The piece ${entry.name} is not a Class. ${String(entry.piece)}`);\n\t\t\t}\n\n\t\t\tthis.#pendingManuallyRegisteredPieces.ensure(entry.store, () => []).push({ name: entry.name, piece: entry.piece });\n\t\t}\n\t}\n}\n\nexport interface StoreRegistry {\n\tget<K extends StoreRegistryKey>(key: K): StoreRegistryEntries[K];\n\tget(key: string): undefined;\n\thas(key: StoreRegistryKey): true;\n\thas(key: string): false;\n}\n\n/**\n * A type utility to get the keys of {@linkcode StoreRegistryEntries}.\n * @since 3.10.0\n */\nexport type StoreRegistryKey = keyof StoreRegistryEntries;\n\n/**\n * A type utility to get the values of {@linkcode StoreRegistryEntries}.\n * @since 3.10.0\n */\nexport type StoreRegistryValue = StoreRegistryEntries[StoreRegistryKey];\n\n/**\n * The {@link StoreRegistry}'s registry, use module augmentation against this interface when adding new stores.\n * @since 2.1.0\n */\nexport interface StoreRegistryEntries {}\n\n/**\n * An entry for a manually registered piece using {@linkcode StoreRegistry.loadPiece()}.\n * @seealso {@linkcode StoreRegistry.loadPiece()}\n * @since 3.8.0\n */\nexport interface StoreManagerManuallyRegisteredPiece<StoreName extends StoreRegistryKey> extends StoreManuallyRegisteredPiece<StoreName> {\n\tstore: StoreName;\n}\n\n/**\n * Type utility to get the {@linkcode Store} given its name.\n * @since 3.10.0\n */\nexport type StoreOf<StoreName extends StoreRegistryKey> = StoreRegistryKey extends never\n\t? Store<Piece<Piece.Options, StoreName>>\n\t: StoreRegistryEntries[StoreName];\n\n/**\n * Type utility to get the {@linkcode Piece} given its {@linkcode Store}'s name.\n * @since 3.10.0\n */\nexport type PieceOf<StoreName extends StoreRegistryKey> = StoreRegistryKey extends never\n\t? Piece<Piece.Options, StoreName>\n\t: StoreRegistryEntries[StoreName] extends Store<infer PieceType>\n\t\t? PieceType\n\t\t: Piece<Piece.Options, StoreName>;\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
// src/tsconfig.json
|
|
6
|
+
var extends2 = "../tsconfig.base.json";
|
|
7
|
+
var compilerOptions = {
|
|
8
|
+
rootDir: "./",
|
|
9
|
+
outDir: "../dist"
|
|
10
|
+
};
|
|
11
|
+
var include = ["."];
|
|
12
|
+
var tsconfig_default = {
|
|
13
|
+
extends: extends2,
|
|
14
|
+
compilerOptions,
|
|
15
|
+
include
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.compilerOptions = compilerOptions;
|
|
19
|
+
exports.default = tsconfig_default;
|
|
20
|
+
exports.extends = extends2;
|
|
21
|
+
exports.include = include;
|
|
22
|
+
//# sourceMappingURL=tsconfig.cjs.map
|
|
23
|
+
//# sourceMappingURL=tsconfig.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/tsconfig.json"],"names":["extends"],"mappings":";;;;;AACC,IAAAA,QAAW,GAAA,wBAAA;AACQ,IAAA,eAAA,GAAA;AAAA,EAClB,OAAW,EAAA,IAAA;AAAA,EACX,MAAU,EAAA,SAAA;AACX,EAAA;AACA,IAAA,OAAA,GAAW,CAAC,GAAG,EAAA;AANhB,IAAA,gBAAA,GAAA;AAAA,EACC,OAAAA,EAAAA,QAAAA;AAAA,EACA,eAAA;AAAA,EAIA,OAAA;AACD","file":"tsconfig.cjs","sourcesContent":["{\n\t\"extends\": \"../tsconfig.base.json\",\n\t\"compilerOptions\": {\n\t\t\"rootDir\": \"./\",\n\t\t\"outDir\": \"../dist\"\n\t},\n\t\"include\": [\".\"]\n}\n"]}
|
|
@@ -17,5 +17,5 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
|
|
|
17
17
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
18
18
|
|
|
19
19
|
export { __name, __privateAdd, __privateGet, __privateSet, __publicField, __require };
|
|
20
|
-
//# sourceMappingURL=
|
|
20
|
+
//# sourceMappingURL=chunk-KFLDEQ5J.mjs.map
|
|
21
21
|
//# sourceMappingURL=chunk-KFLDEQ5J.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-KFLDEQ5J.mjs"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -13,5 +13,5 @@ export * from './lib/structures/Piece.mjs';
|
|
|
13
13
|
export * from './lib/structures/PieceLocation.mjs';
|
|
14
14
|
export * from './lib/structures/Store.mjs';
|
|
15
15
|
export * from './lib/structures/StoreRegistry.mjs';
|
|
16
|
-
//# sourceMappingURL=
|
|
16
|
+
//# sourceMappingURL=index.mjs.map
|
|
17
17
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.mjs","sourcesContent":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/errors/LoaderError.ts"],"names":["LoaderErrorType"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/errors/LoaderError.ts"],"names":["LoaderErrorType"],"mappings":";;;AAAY,IAAA,eAAA,qBAAAA,gBAAL,KAAA;AACN,EAAAA,iBAAA,aAAc,CAAA,GAAA,cAAA,CAAA;AACd,EAAAA,iBAAA,cAAe,CAAA,GAAA,eAAA,CAAA;AACf,EAAAA,iBAAA,eAAgB,CAAA,GAAA,gBAAA,CAAA;AAChB,EAAAA,iBAAA,eAAgB,CAAA,GAAA,gBAAA,CAAA;AAChB,EAAAA,iBAAA,cAAe,CAAA,GAAA,eAAA,CAAA;AALJ,EAAAA,OAAAA,gBAAAA,CAAAA;AAAA,CAAA,EAAA,eAAA,IAAA,EAAA,EAAA;AAWL,IAAM,YAAA,GAAN,MAAM,YAAA,SAAoB,KAAM,CAAA;AAAA,EAM/B,WAAA,CAAY,MAAuB,OAAiB,EAAA;AAC1D,IAAA,KAAA,CAAM,OAAO,CAAA,CAAA;AAHd;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA,CAAA;AAIf,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA,CAAA;AAAA,GACb;AAAA,EAEA,IAAoB,IAAO,GAAA;AAC1B,IAAA,OAAO,CAAG,EAAA,KAAA,CAAM,IAAI,CAAA,EAAA,EAAK,KAAK,IAAI,CAAA,CAAA,CAAA,CAAA;AAAA,GACnC;AACD,CAAA,CAAA;AAduC,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA,CAAA;AAAhC,IAAM,WAAN,GAAA","file":"LoaderError.mjs","sourcesContent":["export enum LoaderErrorType {\n\tEmptyModule = 'EMPTY_MODULE',\n\tVirtualPiece = 'VIRTUAL_PIECE',\n\tUnloadedPiece = 'UNLOADED_PIECE',\n\tIncorrectType = 'INCORRECT_TYPE',\n\tUnknownStore = 'UNKNOWN_STORE'\n}\n\n/**\n * Describes a loader error with a type for easy identification.\n */\nexport class LoaderError extends Error {\n\t/**\n\t * The type of the error that was thrown.\n\t */\n\tpublic readonly type: LoaderErrorType;\n\n\tpublic constructor(type: LoaderErrorType, message: string) {\n\t\tsuper(message);\n\t\tthis.type = type;\n\t}\n\n\tpublic override get name() {\n\t\treturn `${super.name} [${this.type}]`;\n\t}\n}\n"]}
|
|
@@ -15,5 +15,5 @@ __name(_MissingExportsError, "MissingExportsError");
|
|
|
15
15
|
var MissingExportsError = _MissingExportsError;
|
|
16
16
|
|
|
17
17
|
export { MissingExportsError };
|
|
18
|
-
//# sourceMappingURL=
|
|
18
|
+
//# sourceMappingURL=MissingExportsError.mjs.map
|
|
19
19
|
//# sourceMappingURL=MissingExportsError.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/errors/MissingExportsError.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/errors/MissingExportsError.ts"],"names":[],"mappings":";;;AAKO,IAAM,oBAAA,GAAN,MAAM,oBAAA,SAA4B,WAAY,CAAA;AAAA,EAM7C,YAAY,IAAc,EAAA;AAChC,IAAA,KAAA,CAAM,eAAgB,CAAA,WAAA,EAAa,CAA6C,0CAAA,EAAA,IAAI,CAAG,CAAA,CAAA,CAAA,CAAA;AAHxF;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA,CAAA;AAIf,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA,CAAA;AAAA,GACb;AACD,CAAA,CAAA;AAVqD,MAAA,CAAA,oBAAA,EAAA,qBAAA,CAAA,CAAA;AAA9C,IAAM,mBAAN,GAAA","file":"MissingExportsError.mjs","sourcesContent":["import { LoaderError, LoaderErrorType } from './LoaderError';\n\n/**\n * Describes a {@link LoaderErrorType.EmptyModule} loader error and adds a path for easy identification.\n */\nexport class MissingExportsError extends LoaderError {\n\t/**\n\t * The path of the module that did not have exports.\n\t */\n\tpublic readonly path: string;\n\n\tpublic constructor(path: string) {\n\t\tsuper(LoaderErrorType.EmptyModule, `A compatible class export was not found. [${path}]`);\n\t\tthis.path = path;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/internal/Path.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/internal/Path.ts"],"names":[],"mappings":";;;AAIO,SAAS,YAAY,IAAoB,EAAA;AAC/C,EAAI,IAAA,OAAO,IAAS,KAAA,QAAA,EAAiB,OAAA,IAAA,CAAA;AACrC,EAAA,OAAO,cAAc,IAAI,CAAA,CAAA;AAC1B,CAAA;AAHgB,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA","file":"Path.mjs","sourcesContent":["import { fileURLToPath } from 'node:url';\n\nexport type Path = string | URL;\n\nexport function resolvePath(path: Path): string {\n\tif (typeof path === 'string') return path;\n\treturn fileURLToPath(path);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/internal/RootScan.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/internal/RootScan.ts"],"names":[],"mappings":";;;;AA4BA,IAAI,IAAwB,GAAA,IAAA,CAAA;AAS5B,SAAS,eAAA,CAAgB,KAAa,YAAsB,EAAA;AAC3D,EAAA,OAAO,OAAQ,CAAA,IAAA,CAAK,GAAK,EAAA,YAAY,CAAC,CAAA,CAAA;AACvC,CAAA;AAFS,MAAA,CAAA,eAAA,EAAA,iBAAA,CAAA,CAAA;AAIF,SAAS,WAAwB,GAAA;AACvC,EAAA,OAAQ,SAAS,aA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AA;AACnF,IAAA,OAAO,EAAE,IAAA,EAAM,GAAK,EAAA,IAAA,EAAM,KAAM,EAAA,CAAA;AAAA,GACjC;AAEA,EAAI,IAAA,WAAA,SAAoB,EAAE,IAAA,EAAM,gBAAgB,GAAK,EAAA,WAAW,CAAG,EAAA,IAAA,EAAM,UAAW,EAAA,CAAA;AACpF,EAAI,IAAA,aAAA,SAAsB,EAAE,IAAA,EAAM,gBAAgB,GAAK,EAAA,aAAa,CAAG,EAAA,IAAA,EAAM,KAAM,EAAA,CAAA;AAEnF,EAAA,OAAO,EAAE,IAAA,EAAM,GAAK,EAAA,IAAA,EAAM,UAAW,EAAA,CAAA;AACtC,CAAA;AA/BgB,MAAA,CAAA,aAAA,EAAA,eAAA,CAAA","file":"RootScan.mjs","sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, join } from 'path';\n\n/**\n * Represents a partial package.json object.\n */\ntype PartialPackageJson = Partial<{\n\tmain: string;\n\tmodule: string;\n\ttype: 'commonjs' | 'module';\n}>;\n\n/**\n * Represents the root data.\n */\nexport interface RootData {\n\t/**\n\t * The root directory.\n\t */\n\troot: string;\n\n\t/**\n\t * The type of the module system used.\n\t * It can be either 'ESM' or 'CommonJS'.\n\t */\n\ttype: 'ESM' | 'CommonJS';\n}\n\nlet data: RootData | null = null;\n\n/**\n * Returns the directory name of a given path by joining the current working directory (cwd) with the joinable path.\n * @private\n * @param cwd - The current working directory.\n * @param joinablePath - The path to be joined with the cwd.\n * @returns The directory name of the joined path.\n */\nfunction dirnameWithPath(cwd: string, joinablePath: string) {\n\treturn dirname(join(cwd, joinablePath));\n}\n\nexport function getRootData(): RootData {\n\treturn (data ??= parseRootData());\n}\n\n/**\n * Retrieves the root data of the project.\n *\n * This function reads the `package.json` file in the current working directory and determines the root path and type\n * of the project.\n *\n * - If the `package.json` file is not found or cannot be parsed, it assumes the project is using CommonJS and\n * the current working directory is used as the root\n *\n * - If the project `type` is specified as `\"commonjs\"` or `\"module\"` in the `package.json`, it uses the corresponding\n * `main` or `module` file path as the root.\n *\n * - If there is no `main` or `module` then it uses the current working directory as the root, while retaining the\n * matching `CommonJS` or `ESM` based on the `type`\n *\n * - If the main or module file path is not specified, it uses the current working directory as the root.\n *\n * The following table shows how different situations resolve to different root data\n *\n * | fields | resolved as |\n * |--------------------------|-------------|\n * | type=commonjs && main | CommonJS |\n * | type=commonjs && module | CommonJS |\n * | type=module && main | ESM |\n * | type=module && module | ESM |\n * | type=undefined && main | CommonJS |\n * | type=undefined && module | ESM |\n * | no package.json on cwd | CommonJS |\n *\n * @returns The root data object containing the root path and the type of the project.\n */\nexport function parseRootData(): RootData {\n\tconst cwd = process.cwd();\n\n\tlet file: PartialPackageJson | undefined;\n\n\ttry {\n\t\tfile = JSON.parse(readFileSync(join(cwd, 'package.json'), 'utf8')) as PartialPackageJson;\n\t} catch (error) {\n\t\treturn { root: cwd, type: 'CommonJS' };\n\t}\n\n\tconst { main: packageMain, module: packageModule, type: packageType } = file;\n\n\tconst lowerCasedType = packageType?.toLowerCase() as PartialPackageJson['type'];\n\n\tif (lowerCasedType === 'commonjs') {\n\t\tif (packageMain) return { root: dirnameWithPath(cwd, packageMain), type: 'CommonJS' };\n\t\tif (packageModule) return { root: dirnameWithPath(cwd, packageModule), type: 'CommonJS' };\n\t\treturn { root: cwd, type: 'CommonJS' };\n\t}\n\n\tif (lowerCasedType === 'module') {\n\t\tif (packageMain) return { root: dirnameWithPath(cwd, packageMain), type: 'ESM' };\n\t\tif (packageModule) return { root: dirnameWithPath(cwd, packageModule), type: 'ESM' };\n\t\treturn { root: cwd, type: 'ESM' };\n\t}\n\n\tif (packageMain) return { root: dirnameWithPath(cwd, packageMain), type: 'CommonJS' };\n\tif (packageModule) return { root: dirnameWithPath(cwd, packageModule), type: 'ESM' };\n\n\treturn { root: cwd, type: 'CommonJS' };\n}\n"]}
|
|
@@ -5,5 +5,5 @@ var VirtualPath = "::virtual::";
|
|
|
5
5
|
var ManuallyRegisteredPiecesSymbol = Symbol("@sapphire/pieces:ManuallyRegisteredPieces");
|
|
6
6
|
|
|
7
7
|
export { ManuallyRegisteredPiecesSymbol, VirtualPath };
|
|
8
|
-
//# sourceMappingURL=
|
|
8
|
+
//# sourceMappingURL=constants.mjs.map
|
|
9
9
|
//# sourceMappingURL=constants.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/internal/constants.ts"],"names":[],"mappings":";;;AAAO,IAAM,
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/internal/constants.ts"],"names":[],"mappings":";;;AAAO,IAAM,WAAc,GAAA,cAAA;AACd,IAAA,8BAAA,GAAiC,OAAO,2CAA2C","file":"constants.mjs","sourcesContent":["export const VirtualPath = '::virtual::';\nexport const ManuallyRegisteredPiecesSymbol = Symbol('@sapphire/pieces:ManuallyRegisteredPieces');\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"internal.d.mjs"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/shared/Container.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/shared/Container.ts"],"names":[],"mappings":";;;AA6EO,IAAM,SAAuB,GAAA;AAAA,EACnC,MAAA,EAAQ,IAAI,aAAc,EAAA;AAC3B","file":"Container.mjs","sourcesContent":["import { StoreRegistry } from '../structures/StoreRegistry';\n\n/**\n * Represents the type of the properties injected into the container, which is available at {@link container}.\n *\n * Because Sapphire works as a standalone framework (independent of external libraries), there is a need to pass data\n * from one place to another, which would vary depending on the user and their use-cases.\n *\n * Furthermore, plugins may use this structure to add properties referencing to the plugin's objects so they can be\n * accessed by both the user and the plugin at any moment and at any place.\n *\n * Finally, both library developers and bot developers should augment the Container interface from this module using\n * [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation).\n */\nexport interface Container {\n\tstores: StoreRegistry;\n}\n\n/**\n * The injected variables that will be accessible to any place. To add an extra property, simply add a property with a\n * regular assignment, and it will be available in all places simultaneously.\n *\n * @example\n * ```typescript\n * // Add a reference for the version:\n * import { container } from '@sapphire/pieces';\n *\n * container.version = '1.0.0';\n *\n * // Can be placed anywhere in a TypeScript file, for JavaScript projects,\n * // you can create an `augments.d.ts` and place the code there.\n * declare module '@sapphire/pieces' {\n * interface Container {\n * version: string;\n * }\n * }\n *\n * // In any piece, core, plugin, or custom:\n * export class UserCommand extends Command {\n * public messageRun(message, args) {\n * // The injected version is available here:\n * const { version } = this.container;\n *\n * // ...\n * }\n * }\n * ```\n *\n * @example\n * ```typescript\n * // In a plugin's context, e.g. API:\n * class Api extends Plugin {\n * static [postInitialization]() {\n * const server = new Server(this);\n * container.server = server;\n *\n * // ...\n * }\n * }\n *\n * declare module '@sapphire/pieces' {\n * interface Container {\n * server: Server;\n * }\n * }\n *\n * // In any piece, even those that aren't routes nor middlewares:\n * export class UserRoute extends Route {\n * public [methods.POST](message, args) {\n * // The injected server is available here:\n * const { server } = this.container;\n *\n * // ...\n * }\n * }\n * ```\n */\nexport const container: Container = {\n\tstores: new StoreRegistry()\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"ILoaderStrategy.mjs"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/strategies/LoaderStrategy.ts"],"names":[],"mappings":"
|
|
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,CAAA;AACpD,IAAA,aAAA,CAAA,IAAA,EAAO,qBAAsB,EAAA,CA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AAA,gBAAA,CAAA,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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/strategies/Shared.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/strategies/Shared.ts"],"names":[],"mappings":";;;AAOO,SAAS,QAAQ,KAAuC,EAAA;AAC9D,EAAA,OAAO,OAAO,KAAA,KAAU,UAAc,IAAA,OAAO,MAAM,SAAc,KAAA,QAAA,CAAA;AAClE,CAAA;AAFgB,MAAA,CAAA,OAAA,EAAA,SAAA,CAAA,CAAA;AAUT,SAAS,YAAA,CAAqC,OAAqB,IAAqB,EAAA;AAC9F,EAAA,IAAI,IAA4B,GAAA,KAAA,CAAA;AAChC,EAAA,OAAO,SAAS,IAAM,EAAA;AACrB,IAAI,IAAA,IAAA,KAAS,MAAa,OAAA,IAAA,CAAA;AAC1B,IAAO,IAAA,GAAA,MAAA,CAAO,eAAe,IAAI,CAAA,CAAA;AAAA,GAClC;AAEA,EAAO,OAAA,KAAA,CAAA;AACR,CAAA;AARgB,MAAA,CAAA,YAAA,EAAA,cAAA,CAAA","file":"Shared.mjs","sourcesContent":["import type { AbstractCtor } from '@sapphire/utilities';\n\n/**\n * Determines whether or not a value is a class.\n * @param value The piece to be checked.\n * @private\n */\nexport function isClass(value: unknown): value is AbstractCtor {\n\treturn typeof value === 'function' && typeof value.prototype === 'object';\n}\n\n/**\n * Checks whether or not the value class extends the base class.\n * @param value The constructor to be checked against.\n * @param base The base constructor.\n * @private\n */\nexport function classExtends<T extends AbstractCtor>(value: AbstractCtor, base: T): value is T {\n\tlet ctor: AbstractCtor | null = value;\n\twhile (ctor !== null) {\n\t\tif (ctor === base) return true;\n\t\tctor = Object.getPrototypeOf(ctor);\n\t}\n\n\treturn false;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/strategies/env.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/strategies/env.ts"],"names":[],"mappings":";;;AAEA,SAAS,iBAAiB,IAAc,EAAA;AACvC,EACC,OAAA,OAAA,CAAQ,SAAS,IAAK,CAAA,CAAC,QAAQ,GAAI,CAAA,QAAA,CAAS,IAAI,CAAC,CAAA;AAAA,EACjD,OAAA,CAAQ,KAAK,IAAK,CAAA,CAAC,QAAQ,GAAI,CAAA,QAAA,CAAS,IAAI,CAAC,CAAA,CAAA;AAE/C,CAAA;AALS,MAAA,CAAA,gBAAA,EAAA,kBAAA,CAAA,CAAA;AAOT,SAAS,oBAAoB,IAAc,EAAA;AAC1C,EAAO,OAAA,kBAAA,IAAsB,OAAY,IAAA,OAAA,CAAQ,gBAA8B,CAAA,IAAA,CAAK,CAAC,MAAW,KAAA,MAAA,CAAO,QAAS,CAAA,IAAI,CAAC,CAAA,CAAA;AACtH,CAAA;AAFS,MAAA,CAAA,mBAAA,EAAA,qBAAA,CAAA,CAAA;AAIT,SAAS,gBAAA,CAAiB,MAAc,KAAgB,EAAA;AACvD,EAAO,OAAA,KAAA,GAAQ,OAAQ,CAAA,GAAA,CAAI,IAAI,CAAA,KAAM,KAAQ,GAAA,CAAC,SAAU,CAAA,OAAA,CAAQ,GAAI,CAAA,IAAI,CAAC,CAAA,CAAA;AAC1E,CAAA;AAFS,MAAA,CAAA,gBAAA,EAAA,kBAAA,CAAA,CAAA;AAqBI,IAAA,sBAAA;AAAA;AAAA;AAAA,EAGZ,OAAA,CAAQ,GAAI,CAAA,UAAA,EAAY,MAAM,CAAA;AAAA;AAAA,EAG9B,SAAS,OAAQ,CAAA,QAAA;AAAA;AAAA;AAAA,EAIjB,MAAA,CAAO,GAAI,CAAA,2BAA2B,CAAK,IAAA,OAAA;AAAA,EAE3C,iBAAiB,aAAa,CAAA;AAAA,EAE9B,CAAC,SAAA,CAAU,OAAQ,CAAA,GAAA,CAAI,WAAW,CAAA;AAAA;AAAA,EAGlC,iBAAiB,YAAY,CAAA;AAAA;AAAA,EAG7B,gBAAiB,CAAA,QAAA,EAAU,MAAM,CAAA,IACjC,iBAAiB,kBAAkB,CAAA;AAAA;AAAA,EAGnC,iBAAiB,gBAAgB,CAAA;AAAA;AAAA,EAGjC,oBAAoB,eAAe,CAAA;AAAA,EACnC,mBAAoB,CAAA,oBAAoB,CACxC,IAAA,gBAAA,CAAiB,eAAe,CAAA;AAAA;AAAA,EAGhC,oBAAoB,KAAK,CAAA;AAAA;AAAA,EAGzB,oBAAoB,kBAAkB,CAAA;AAAA;AAAA,EAGtC,oBAAoB,KAAK,CAAA;AAAA","file":"env.mjs","sourcesContent":["import { isNullish } from '@sapphire/utilities';\n\nfunction checkProcessArgv(name: string) {\n\treturn (\n\t\tprocess.execArgv.some((arg) => arg.includes(name)) || //\n\t\tprocess.argv.some((arg) => arg.includes(name))\n\t);\n}\n\nfunction checkPreloadModules(name: string) {\n\treturn '_preload_modules' in process && (process._preload_modules as string[]).some((module) => module.includes(name));\n}\n\nfunction checkEnvVariable(name: string, value?: string) {\n\treturn value ? process.env[name] === value : !isNullish(process.env[name]);\n}\n\n/**\n * Whether or not the current environment can load TypeScript files. These\n * conditions are based on the most common tools and runtimes that support\n * loading TypeScript files directly.\n *\n * - {@linkplain https://www.npmjs.com/package/ts-node | `ts-node`}\n * - {@linkplain https://www.npmjs.com/package/ts-node-dev | `ts-node-dev`}\n * - {@linkplain https://www.npmjs.com/package/@babel/node | `@babel/node`}\n * - {@linkplain https://www.npmjs.com/package/vitest | `vitest`}\n * - {@linkplain https://www.npmjs.com/package/jest | `jest`}\n * - {@linkplain https://www.npmjs.com/package/@swc/cli | `swc`}\n * - {@linkplain https://www.npmjs.com/package/tsm | `tsm`}\n * - {@linkplain https://www.npmjs.com/package/esbuild | `esbuild`}\n * - {@linkplain https://www.npmjs.com/package/tsx | `tsx`}\n * - {@linkplain https://deno.com | `Deno`}\n * - {@linkplain https://bun.sh | `Bun`}\n */\nexport const CanLoadTypeScriptFiles: boolean =\n\t//\n\t// Deno\n\tReflect.has(globalThis, 'Deno') ||\n\t//\n\t// Bun\n\t'bun' in process.versions ||\n\t//\n\t// ts-node\n\t// > --require ts-node/register\n\tSymbol.for('ts-node.register.instance') in process ||\n\t// > --loader ts-node/esm\n\tcheckProcessArgv('ts-node/esm') ||\n\t// > ts-node-dev\n\t!isNullish(process.env.TS_NODE_DEV) ||\n\t//\n\t// @babel/node\n\tcheckProcessArgv('babel-node') ||\n\t//\n\t// vitest\n\tcheckEnvVariable('VITEST', 'true') ||\n\tcheckEnvVariable('VITEST_WORKER_ID') ||\n\t//\n\t// jest\n\tcheckEnvVariable('JEST_WORKER_ID') ||\n\t//\n\t// swc\n\tcheckPreloadModules('@swc/register') || //\n\tcheckPreloadModules('@swc-node/register') ||\n\tcheckProcessArgv('.bin/swc-node') ||\n\t//\n\t// tsm\n\tcheckPreloadModules('tsm') ||\n\t//\n\t// esbuild\n\tcheckPreloadModules('esbuild-register') ||\n\t//\n\t// tsx\n\tcheckPreloadModules('tsx');\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/AliasPiece.ts"],"names":["AliasPiece"],"mappings":"
|
|
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,CAAA;AAHvB;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;AAIN,IAAK,IAAA,CAAA,OAAA,GAAU,OAAQ,CAAA,OAAA,IAAW,EAAC,CAAA;AAAA,GACpC;AAAA;AAAA;AAAA;AAAA,EAKgB,MAA0B,GAAA;AACzC,IAAO,OAAA;AAAA,MACN,GAAG,MAAM,MAAO,EAAA;AAAA,MAChB,OAAA,EAAS,IAAK,CAAA,OAAA,CAAQ,KAAM,EAAA;AAAA,KAC7B,CAAA;AAAA,GACD;AACD,CAAA,CAAA;AApBE,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA,CAAA;AAHK,IAAM,UAAN,GAAA,YAAA;AAAA,CAiCA,CAAUA,WAAV,KAAA;AACC,EAAM,CAAA,EAAE,QAAAA,EAAAA,WAAAA,CAAA,QAAa,EAAA,GAAA,KAAA,EAAA;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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/AliasStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/AliasStore.ts"],"names":[],"mappings":";;;;AAQO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAgG,KAAoB,CAAA;AAAA,EAA1H,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,SAAA,EAAU,IAAI,UAAsB,EAAA,CAAA,CAAA;AAAA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMpC,IAAI,GAA4B,EAAA;AAC/C,IAAA,OAAO,MAAM,GAAI,CAAA,GAAG,KAAK,IAAK,CAAA,OAAA,CAAQ,IAAI,GAAG,CAAA,CAAA;AAAA,GAC9C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMgB,IAAI,GAAsB,EAAA;AACzC,IAAA,OAAO,MAAM,GAAI,CAAA,GAAG,KAAK,IAAK,CAAA,OAAA,CAAQ,IAAI,GAAG,CAAA,CAAA;AAAA,GAC9C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOgB,OAAO,IAA8B,EAAA;AACpD,IAAM,MAAA,KAAA,GAAQ,IAAK,CAAA,OAAA,CAAQ,IAAI,CAAA,CAAA;AAG/B,IAAW,KAAA,MAAA,KAAA,IAAS,MAAM,OAAS,EAAA;AAElC,MAAA,MAAM,UAAa,GAAA,IAAA,CAAK,OAAQ,CAAA,GAAA,CAAI,KAAK,CAAA,CAAA;AACzC,MAAA,IAAI,UAAe,KAAA,KAAA,EAAY,IAAA,CAAA,OAAA,CAAQ,OAAO,KAAK,CAAA,CAAA;AAAA,KACpD;AAEA,IAAO,OAAA,KAAA,CAAM,OAAO,KAAK,CAAA,CAAA;AAAA,GAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAsB,OAAO,KAAU,EAAA;AACtC,IAAW,KAAA,MAAA,GAAA,IAAO,MAAM,OAAS,EAAA;AAChC,MAAK,IAAA,CAAA,OAAA,CAAQ,GAAI,CAAA,GAAA,EAAK,KAAK,CAAA,CAAA;AAAA,KAC5B;AAEA,IAAO,OAAA,KAAA,CAAM,OAAO,KAAK,CAAA,CAAA;AAAA,GAC1B;AACD,CAAA,CAAA;AApDiI,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA,CAAA;AAA1H,IAAM,UAAN,GAAA","file":"AliasStore.mjs","sourcesContent":["import { Collection } from '@discordjs/collection';\nimport type { AliasPiece } from './AliasPiece';\nimport { Store } from './Store';\nimport type { StoreRegistryKey } from './StoreRegistry';\n\n/**\n * The store class which contains {@link AliasPiece}s.\n */\nexport class AliasStore<T extends AliasPiece, StoreName extends StoreRegistryKey = StoreRegistryKey> extends Store<T, StoreName> {\n\t/**\n\t * The aliases referencing to pieces.\n\t */\n\tpublic readonly aliases = new Collection<string, T>();\n\n\t/**\n\t * Looks up the name by the store, falling back to an alias lookup.\n\t * @param key The key to look for.\n\t */\n\tpublic override get(key: string): T | undefined {\n\t\treturn super.get(key) ?? this.aliases.get(key);\n\t}\n\n\t/**\n\t * Checks whether a key is in the store, or is an alias\n\t * @param key The key to check\n\t */\n\tpublic override has(key: string): boolean {\n\t\treturn super.has(key) || this.aliases.has(key);\n\t}\n\n\t/**\n\t * Unloads a piece given its instance or its name, and removes all the aliases.\n\t * @param name The name of the file to load.\n\t * @return Returns the piece that was unloaded.\n\t */\n\tpublic override unload(name: string | T): Promise<T> {\n\t\tconst piece = this.resolve(name);\n\n\t\t// Unload all aliases for the given piece:\n\t\tfor (const alias of piece.aliases) {\n\t\t\t// We don't want to delete aliases that were overriden by another piece:\n\t\t\tconst aliasPiece = this.aliases.get(alias);\n\t\t\tif (aliasPiece === piece) this.aliases.delete(alias);\n\t\t}\n\n\t\treturn super.unload(piece);\n\t}\n\n\t/**\n\t * Inserts a piece into the store, and adds all the aliases.\n\t * @param piece The piece to be inserted into the store.\n\t * @return The inserted piece.\n\t */\n\tpublic override async insert(piece: T) {\n\t\tfor (const key of piece.aliases) {\n\t\t\tthis.aliases.set(key, piece);\n\t\t}\n\n\t\treturn super.insert(piece);\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/Piece.ts"],"names":["Piece"],"mappings":"
|
|
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,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;AAKP;AAAA;AAAA;AAAA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IAAA;AAAA,MACX,SAAS,IAAK,CAAA,OAAA;AAAA,MACd,SAAS,IAAK,CAAA,OAAA;AAAA,KACf,CAAA;AAAA,GACD;AACD,CAAA,CAAA;AApFuH,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;AAAhH,IAAM,KAAN,GAAA,OAAA;AAAA,CAgGA,CAAUA,MAAV,KAAA;AACC,EAAMA,OAAA,QAAW,GAAA,aAAA,CAAA;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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/PieceLocation.ts"],"names":[],"mappings":"
|
|
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,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA,CAAA;AAOf,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA,CAAA;AACZ,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA,CAAA;AAAA,GACb;AAAA;AAAA;AAAA;AAAA,EAKA,IAAW,OAAU,GAAA;AACpB,IAAA,OAAO,KAAK,IAAS,KAAA,WAAA,CAAA;AAAA,GACtB;AAAA;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,CAAA;AAAA,GAClE;AAAA;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,CAAA;AAAA,GAChE;AAAA;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,CAAA;AAAA,GACvD;AAAA;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,IAAA;AAAA,KACZ,CAAA;AAAA,GACD;AACD,CAAA,CAAA;AA1F2B,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA,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"]}
|