@sapphire/pieces 4.3.1 → 4.3.2-next.12ba559

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +0 -1
  2. package/dist/cjs/index.cjs +1 -1
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs/lib/errors/LoaderError.cjs +1 -1
  5. package/dist/cjs/lib/errors/LoaderError.cjs.map +1 -1
  6. package/dist/cjs/lib/errors/MissingExportsError.cjs +1 -1
  7. package/dist/cjs/lib/errors/MissingExportsError.cjs.map +1 -1
  8. package/dist/cjs/lib/internal/Path.cjs +1 -1
  9. package/dist/cjs/lib/internal/Path.cjs.map +1 -1
  10. package/dist/cjs/lib/internal/RootScan.cjs +1 -1
  11. package/dist/cjs/lib/internal/RootScan.cjs.map +1 -1
  12. package/dist/cjs/lib/internal/constants.cjs +1 -1
  13. package/dist/cjs/lib/internal/constants.cjs.map +1 -1
  14. package/dist/cjs/lib/internal/internal.d.cjs +4 -0
  15. package/dist/cjs/lib/internal/internal.d.cjs.map +1 -0
  16. package/dist/cjs/lib/shared/Container.cjs +1 -1
  17. package/dist/cjs/lib/shared/Container.cjs.map +1 -1
  18. package/dist/cjs/lib/strategies/ILoaderStrategy.cjs +1 -1
  19. package/dist/cjs/lib/strategies/ILoaderStrategy.cjs.map +1 -1
  20. package/dist/cjs/lib/strategies/LoaderStrategy.cjs +1 -1
  21. package/dist/cjs/lib/strategies/LoaderStrategy.cjs.map +1 -1
  22. package/dist/cjs/lib/strategies/Shared.cjs +1 -1
  23. package/dist/cjs/lib/strategies/Shared.cjs.map +1 -1
  24. package/dist/cjs/lib/strategies/env.cjs +1 -1
  25. package/dist/cjs/lib/strategies/env.cjs.map +1 -1
  26. package/dist/cjs/lib/structures/AliasPiece.cjs +1 -1
  27. package/dist/cjs/lib/structures/AliasPiece.cjs.map +1 -1
  28. package/dist/cjs/lib/structures/AliasStore.cjs +1 -1
  29. package/dist/cjs/lib/structures/AliasStore.cjs.map +1 -1
  30. package/dist/cjs/lib/structures/Piece.cjs +1 -1
  31. package/dist/cjs/lib/structures/Piece.cjs.map +1 -1
  32. package/dist/cjs/lib/structures/PieceLocation.cjs +1 -1
  33. package/dist/cjs/lib/structures/PieceLocation.cjs.map +1 -1
  34. package/dist/cjs/lib/structures/Store.cjs +1 -1
  35. package/dist/cjs/lib/structures/Store.cjs.map +1 -1
  36. package/dist/cjs/lib/structures/StoreRegistry.cjs +1 -1
  37. package/dist/cjs/lib/structures/StoreRegistry.cjs.map +1 -1
  38. package/dist/cjs/tsconfig.cjs +23 -0
  39. package/dist/cjs/tsconfig.cjs.map +1 -0
  40. package/dist/esm/chunk-KFLDEQ5J.mjs +1 -1
  41. package/dist/esm/chunk-KFLDEQ5J.mjs.map +1 -1
  42. package/dist/esm/index.mjs +1 -1
  43. package/dist/esm/index.mjs.map +1 -1
  44. package/dist/esm/lib/errors/LoaderError.mjs +1 -1
  45. package/dist/esm/lib/errors/LoaderError.mjs.map +1 -1
  46. package/dist/esm/lib/errors/MissingExportsError.mjs +1 -1
  47. package/dist/esm/lib/errors/MissingExportsError.mjs.map +1 -1
  48. package/dist/esm/lib/internal/Path.mjs +1 -1
  49. package/dist/esm/lib/internal/Path.mjs.map +1 -1
  50. package/dist/esm/lib/internal/RootScan.mjs +1 -1
  51. package/dist/esm/lib/internal/RootScan.mjs.map +1 -1
  52. package/dist/esm/lib/internal/constants.mjs +1 -1
  53. package/dist/esm/lib/internal/constants.mjs.map +1 -1
  54. package/dist/esm/lib/internal/internal.d.mjs +3 -0
  55. package/dist/esm/lib/internal/internal.d.mjs.map +1 -0
  56. package/dist/esm/lib/shared/Container.mjs +1 -1
  57. package/dist/esm/lib/shared/Container.mjs.map +1 -1
  58. package/dist/esm/lib/strategies/ILoaderStrategy.mjs +1 -1
  59. package/dist/esm/lib/strategies/ILoaderStrategy.mjs.map +1 -1
  60. package/dist/esm/lib/strategies/LoaderStrategy.mjs +1 -1
  61. package/dist/esm/lib/strategies/LoaderStrategy.mjs.map +1 -1
  62. package/dist/esm/lib/strategies/Shared.mjs +1 -1
  63. package/dist/esm/lib/strategies/Shared.mjs.map +1 -1
  64. package/dist/esm/lib/strategies/env.mjs +1 -1
  65. package/dist/esm/lib/strategies/env.mjs.map +1 -1
  66. package/dist/esm/lib/structures/AliasPiece.mjs +1 -1
  67. package/dist/esm/lib/structures/AliasPiece.mjs.map +1 -1
  68. package/dist/esm/lib/structures/AliasStore.mjs +1 -1
  69. package/dist/esm/lib/structures/AliasStore.mjs.map +1 -1
  70. package/dist/esm/lib/structures/Piece.mjs +1 -1
  71. package/dist/esm/lib/structures/Piece.mjs.map +1 -1
  72. package/dist/esm/lib/structures/PieceLocation.mjs +1 -1
  73. package/dist/esm/lib/structures/PieceLocation.mjs.map +1 -1
  74. package/dist/esm/lib/structures/Store.mjs +1 -1
  75. package/dist/esm/lib/structures/Store.mjs.map +1 -1
  76. package/dist/esm/lib/structures/StoreRegistry.mjs +1 -1
  77. package/dist/esm/lib/structures/StoreRegistry.mjs.map +1 -1
  78. package/dist/esm/tsconfig.mjs +18 -0
  79. package/dist/esm/tsconfig.mjs.map +1 -0
  80. package/package.json +14 -13
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/Store.ts"],"names":["Store"],"mappings":";;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,cAAc,eAA2D;AAClF,SAAS,YAAY;AACrB,SAAS,aAAa,uBAAuB;AAC7C,SAAS,mBAA8B;AACvC,SAAS,gCAAgC,mBAAmB;AAC5D,SAAS,iBAAiC;AAE1C,SAAS,sBAAsB;AAE/B,SAAS,qBAAuE;AAuChF,IAAM,kBAAkB,IAAI,eAAe;AAjD3C;AAsDO,IAAM,SAAN,MAAM,gBAAsF,iBAShF,qCATgF,IAAsB;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBjH,YAAY,aAAqC,SAAqC;AAC5F,UAAM;AAzBP,wBAAgB;AAChB,wBA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AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAe,SAAS,MAAwC;AAC/D,WAAM,SAAS,aAAa,KAAK,IAAI,qCAAqC,IAAI,IAAI;AAClF,qBAAiB,SAAS,mBAAK,OAAL,WAAW,MAAM,MAAM,OAAM,SAAS;AAC/D,YAAM,OAAO,KAAK,SAAS,OAAO,KAAK;AACvC,UAAI,SAAS,MAAM;AAClB,eAAM,SAAS,aAAa,KAAK,IAAI,2BAA2B,KAAK,+CAA+C;AACpH;AAAA,MACD;AACA,UAAI;AACH,cAAM,eAAe,KAAK,kBAAkB,MAAM,IAAI;AACtD,yBAAiB,QAAQ,KAAK,SAAS,KAAK,MAAM,YAAY,GAAG;AAChE,gBAAM,KAAK,UAAU,MAAM,YAAY;AAAA,QACxC;AAAA,MACD,SAAS,OAAO;AACf,aAAK,SAAS,QAAQ,OAAgB,KAAK,IAAI;AAAA,MAChD;AAAA,IACD;AAAA,EACD;AAYD;AA1TC;AAKA;AAnBwH;AAAA;AAAA;AAAA;AAAA;AAkUxH,cAlUY,QAkUE,mBAAwC;AAAA;AAAA;AAAA;AAKtD,cAvUY,QAuUE,UAA6B;AAvUrC,IAAM,QAAN;AAAA,CAmVA,CAAUA,WAAV;AACC,EAAMA,OAAA,WAAW;AAAA,GADR","sourcesContent":["import { Collection } from '@discordjs/collection';\nimport { classExtends, isClass, type AbstractConstructor, type Constructor } from '@sapphire/utilities';\nimport { join } from 'path';\nimport { LoaderError, LoaderErrorType } from '../errors/LoaderError';\nimport { resolvePath, type Path } from '../internal/Path';\nimport { ManuallyRegisteredPiecesSymbol, VirtualPath } from '../internal/constants';\nimport { container, type Container } from '../shared/Container';\nimport type { HydratedModuleData, ILoaderResultEntry, ILoaderStrategy, ModuleData } from '../strategies/ILoaderStrategy';\nimport { LoaderStrategy } from '../strategies/LoaderStrategy';\nimport type { Piece } from './Piece';\nimport { StoreRegistry, type StoreRegistryEntries, type StoreRegistryKey } from './StoreRegistry';\n\n/**\n * The options for the store, this features both hooks (changes the behaviour) and handlers (similar to event listeners).\n */\nexport interface StoreOptions<T extends Piece, StoreName extends StoreRegistryKey = StoreRegistryKey> {\n\t/**\n\t * The name for this store.\n\t */\n\treadonly name: StoreName;\n\n\t/**\n\t * The paths to load pieces from, should be absolute.\n\t * @default []\n\t */\n\treadonly paths?: readonly string[];\n\n\t/**\n\t * The strategy to be used for the loader.\n\t * @default Store.defaultStrategy\n\t */\n\treadonly strategy?: ILoaderStrategy<T>;\n}\n\n/**\n * An interface representing a logger function.\n */\nexport interface StoreLogger {\n\t/**\n\t * @param value The string to print. All strings will be formatted with the format `[STORE => ${name}] [${type}] ${content}`,\n\t * where the content may have identifiers (values or names of methods) surrounded by `'`. For example:\n\t *\n\t * - `[STORE => commands] [LOAD] Skipped piece '/home/user/bot/src/commands/foo.js' as 'LoaderStrategy#filter' returned 'null'.`\n\t * - `[STORE => commands] [INSERT] Unloaded new piece 'foo' due to 'enabled' being 'false'.`\n\t * - `[STORE => commands] [UNLOAD] Unloaded piece 'foo'.`\n\t */\n\t(value: string): void;\n}\n\nconst defaultStrategy = new LoaderStrategy();\n\n/**\n * The store class which contains {@link Piece}s.\n */\nexport class Store<T extends Piece, StoreName extends StoreRegistryKey = StoreRegistryKey> extends Collection<string, T> {\n\tpublic readonly Constructor: AbstractConstructor<T>;\n\tpublic readonly name: StoreName;\n\tpublic readonly paths: Set<string>;\n\tpublic readonly strategy: ILoaderStrategy<T>;\n\n\t/**\n\t * The queue of manually registered pieces to load.\n\t */\n\tprivate readonly [ManuallyRegisteredPiecesSymbol] = new Map<string, StoreManuallyRegisteredPiece<StoreName>>();\n\n\t/**\n\t * Whether or not the store has called `loadAll` at least once.\n\t */\n\t#calledLoadAll = false;\n\n\t/**\n\t * The walk function for the store.\n\t */\n\t#walk: LoaderStrategy<T>['walk'];\n\n\t/**\n\t * @param constructor The piece constructor this store loads.\n\t * @param options The options for the store.\n\t */\n\tpublic constructor(constructor: AbstractConstructor<T>, options: StoreOptions<T, StoreName>) {\n\t\tsuper();\n\t\tthis.Constructor = constructor;\n\t\tthis.name = options.name as StoreRegistryKey;\n\t\tthis.paths = new Set(options.paths ?? []);\n\t\tthis.strategy = options.strategy ?? Store.defaultStrategy;\n\n\t\tthis.#walk =\n\t\t\ttypeof this.strategy.walk === 'function' //\n\t\t\t\t? this.strategy.walk.bind(this.strategy)\n\t\t\t\t: defaultStrategy.walk.bind(defaultStrategy);\n\t}\n\n\t/**\n\t * A reference to the {@link Container} object for ease of use.\n\t * @see container\n\t */\n\tpublic get container(): Container {\n\t\treturn container;\n\t}\n\n\t/**\n\t * Registers a directory into the store.\n\t * @param path The path to be added.\n\t * @example\n\t * ```typescript\n\t * store\n\t * .registerPath(resolve('commands'))\n\t * .registerPath(resolve('third-party', 'commands'));\n\t * ```\n\t */\n\tpublic registerPath(path: Path): this {\n\t\tconst root = resolvePath(path);\n\n\t\tthis.paths.add(root);\n\t\tStore.logger?.(`[STORE => ${this.name}] [REGISTER] Registered path '${root}'.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds a piece into the store's list of manually registered pieces. If {@linkcode Store.loadAll()} was called, the\n\t * piece will be loaded immediately, otherwise it will be queued until {@linkcode Store.loadAll()} is called.\n\t *\n\t * All manually registered pieces will be kept even after they are loaded to ensure they can be loaded again if\n\t * {@linkcode Store.loadAll()} is called again.\n\t *\n\t * @remarks\n\t *\n\t * - Pieces loaded this way will have their {@linkcode Piece.Context.root root} and\n\t * {@linkcode Piece.Context.path path} set to {@linkcode VirtualPath}, and as such, cannot be reloaded.\n\t * - This method is useful in environments where file system access is limited or unavailable, such as when using\n\t * {@link https://en.wikipedia.org/wiki/Serverless_computing Serverless Computing}.\n\t * - This method will always throw a {@link TypeError} if `entry.piece` is not a class.\n\t * - This method will always throw a {@linkcode LoaderError} if the piece does not extend the\n\t * {@linkcode Store#Constructor store's piece constructor}.\n\t * - This operation is atomic, if any of the above errors are thrown, the piece will not be loaded.\n\t *\n\t * @seealso {@linkcode StoreRegistry.loadPiece()}\n\t * @since 3.8.0\n\t * @param entry The entry to load.\n\t * @example\n\t * ```typescript\n\t * import { container } from '@sapphire/pieces';\n\t *\n\t * class PingCommand extends Command {\n\t * // ...\n\t * }\n\t *\n\t * container.stores.get('commands').loadPiece({\n\t * name: 'ping',\n\t * piece: PingCommand\n\t * });\n\t * ```\n\t */\n\tpublic async loadPiece(entry: StoreManuallyRegisteredPiece<StoreName>) {\n\t\tif (!isClass(entry.piece)) {\n\t\t\tthrow new TypeError(`The piece ${entry.name} is not a Class. ${String(entry.piece)}`);\n\t\t}\n\n\t\t// If the piece does not extend the store's Piece class, throw an error:\n\t\tif (!classExtends(entry.piece, this.Constructor as Constructor<T>)) {\n\t\t\tthrow new LoaderError(LoaderErrorType.IncorrectType, `The piece ${entry.name} does not extend ${this.name}`);\n\t\t}\n\n\t\tthis[ManuallyRegisteredPiecesSymbol].set(entry.name, entry);\n\t\tif (this.#calledLoadAll) {\n\t\t\tconst piece = this.construct(entry.piece as unknown as Constructor<T>, {\n\t\t\t\tname: entry.name,\n\t\t\t\troot: VirtualPath,\n\t\t\t\tpath: VirtualPath,\n\t\t\t\textension: VirtualPath\n\t\t\t});\n\t\t\tawait this.insert(piece);\n\t\t}\n\t}\n\n\t/**\n\t * Loads one or more pieces from a path.\n\t * @param root The root directory the file is from.\n\t * @param path The path of the file to load, relative to the `root`.\n\t * @return All the loaded pieces.\n\t */\n\tpublic async load(root: string, path: string): Promise<T[]> {\n\t\tif (root === VirtualPath) {\n\t\t\tthrow new LoaderError(LoaderErrorType.VirtualPiece, `Cannot load a virtual file.`);\n\t\t}\n\n\t\tconst full = join(root, path);\n\t\tconst data = this.strategy.filter(full);\n\t\tif (data === null) {\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD] Skipped piece '${full}' as 'LoaderStrategy#filter' returned 'null'.`);\n\t\t\treturn [];\n\t\t}\n\n\t\tconst promises: Promise<T>[] = [];\n\t\tconst finishedData = this.hydrateModuleData(root, data);\n\t\tfor await (const Ctor of this.strategy.load(this, finishedData)) {\n\t\t\tpromises.push(this.insert(this.construct(Ctor, finishedData)));\n\t\t}\n\n\t\treturn Promise.all(promises);\n\t}\n\n\t/**\n\t * Unloads a piece given its instance or its name.\n\t * @param name The name of the file to load.\n\t * @return Returns the piece that was unloaded.\n\t */\n\tpublic async unload(name: string | T): Promise<T> {\n\t\tconst piece = this.resolve(name);\n\n\t\t// Unload piece:\n\t\tthis.strategy.onUnload(this, piece);\n\t\tawait piece.onUnload();\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD] Unloaded piece '${piece.name}'.`);\n\n\t\t// Remove from cache and return it:\n\t\tthis.delete(piece.name);\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD] Removed piece '${piece.name}'.`);\n\t\treturn piece;\n\t}\n\n\t/**\n\t * Unloads all pieces from the store.\n\t */\n\tpublic async unloadAll(): Promise<T[]> {\n\t\tconst promises: Promise<T>[] = [];\n\t\tfor (const piece of this.values()) {\n\t\t\tpromises.push(this.unload(piece));\n\t\t}\n\n\t\tconst results = await Promise.all(promises);\n\n\t\tthis.strategy.onUnloadAll(this);\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD-ALL] Removed all pieces.`);\n\t\treturn results;\n\t}\n\n\t/**\n\t * Loads all pieces from all directories specified by {@link paths}.\n\t */\n\tpublic async loadAll(): Promise<void> {\n\t\tthis.#calledLoadAll = true;\n\n\t\tconst pieces: T[] = [];\n\t\tfor (const entry of this[ManuallyRegisteredPiecesSymbol].values()) {\n\t\t\tconst piece = this.construct(entry.piece as unknown as Constructor<T>, {\n\t\t\t\tname: entry.name,\n\t\t\t\troot: VirtualPath,\n\t\t\t\tpath: VirtualPath,\n\t\t\t\textension: VirtualPath\n\t\t\t});\n\t\t\tpieces.push(piece);\n\t\t}\n\n\t\tfor (const path of this.paths) {\n\t\t\tfor await (const piece of this.loadPath(path)) {\n\t\t\t\tpieces.push(piece);\n\t\t\t}\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Found '${pieces.length}' pieces.`);\n\n\t\t// Clear the store before inserting the new pieces:\n\t\tawait this.unloadAll();\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Cleared all pieces.`);\n\n\t\t// Load each piece:\n\t\tfor (const piece of pieces) {\n\t\t\tawait this.insert(piece);\n\t\t}\n\n\t\t// Call onLoadAll:\n\t\tthis.strategy.onLoadAll(this);\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Successfully loaded '${this.size}' pieces.`);\n\t}\n\n\t/**\n\t * Resolves a piece by its name or its instance.\n\t * @param name The name of the piece or the instance itself.\n\t * @return The resolved piece.\n\t */\n\tpublic resolve(name: string | T): T {\n\t\tif (typeof name === 'string') {\n\t\t\tconst result = this.get(name);\n\t\t\tif (typeof result === 'undefined') throw new LoaderError(LoaderErrorType.UnloadedPiece, `The piece '${name}' does not exist.`);\n\t\t\treturn result;\n\t\t}\n\n\t\tif (name instanceof this.Constructor) return name;\n\t\tthrow new LoaderError(LoaderErrorType.IncorrectType, `The piece '${name.name}' is not an instance of '${this.Constructor.name}'.`);\n\t}\n\n\t/**\n\t * Inserts a piece into the store.\n\t * @param piece The piece to be inserted into the store.\n\t * @return The inserted piece.\n\t */\n\tpublic async insert(piece: T): Promise<T> {\n\t\tif (!piece.enabled) return piece;\n\n\t\t// Load piece:\n\t\tthis.strategy.onLoad(this, piece);\n\t\tawait piece.onLoad();\n\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Loaded new piece '${piece.name}'.`);\n\n\t\t// If the onLoad disabled the piece, call unload and return it:\n\t\tif (!piece.enabled) {\n\t\t\t// Unload piece:\n\t\t\tthis.strategy.onUnload(this, piece);\n\t\t\tawait piece.onUnload();\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Unloaded new piece '${piece.name}' due to 'enabled' being 'false'.`);\n\n\t\t\treturn piece;\n\t\t}\n\n\t\t// Unload existing piece, if any:\n\t\tconst previous = super.get(piece.name);\n\t\tif (previous) {\n\t\t\tawait this.unload(previous);\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Unloaded existing piece '${piece.name}' due to conflicting 'name'.`);\n\t\t}\n\n\t\t// Set the new piece and return it:\n\t\tthis.set(piece.name, piece);\n\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Inserted new piece '${piece.name}'.`);\n\t\treturn piece;\n\t}\n\n\t/**\n\t * Constructs a {@link Piece} instance.\n\t * @param Ctor The {@link Piece}'s constructor used to build the instance.\n\t * @param data The module's information\n\t * @return An instance of the constructed piece.\n\t */\n\tpublic construct(Ctor: ILoaderResultEntry<T>, data: HydratedModuleData): T {\n\t\treturn new Ctor({ store: this, root: data.root, path: data.path, name: data.name }, { name: data.name, enabled: true });\n\t}\n\n\t/**\n\t * Adds the final module data properties.\n\t * @param root The root directory to add.\n\t * @param data The module data returned from {@link ILoaderStrategy.filter}.\n\t * @returns The finished module data.\n\t */\n\tprivate hydrateModuleData(root: string, data: ModuleData): HydratedModuleData {\n\t\treturn { root, ...data };\n\t}\n\n\t/**\n\t * Loads a directory into the store.\n\t * @param root The directory to load the pieces from.\n\t * @return An async iterator that yields the pieces to be loaded into the store.\n\t */\n\tprivate async *loadPath(root: string): AsyncIterableIterator<T> {\n\t\tStore.logger?.(`[STORE => ${this.name}] [WALK] Loading all pieces from '${root}'.`);\n\t\tfor await (const child of this.#walk(this, root, Store.logger)) {\n\t\t\tconst data = this.strategy.filter(child);\n\t\t\tif (data === null) {\n\t\t\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD] Skipped piece '${child}' as 'LoaderStrategy#filter' returned 'null'.`);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst finishedData = this.hydrateModuleData(root, data);\n\t\t\t\tfor await (const Ctor of this.strategy.load(this, finishedData)) {\n\t\t\t\t\tyield this.construct(Ctor, finishedData);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthis.strategy.onError(error as Error, data.path);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The default strategy, defaults to {@link LoaderStrategy}, which is constructed on demand when a store is constructed,\n\t * when none was set beforehand.\n\t */\n\tpublic static defaultStrategy: ILoaderStrategy<any> = defaultStrategy;\n\n\t/**\n\t * The default logger, defaults to `null`.\n\t */\n\tpublic static logger: StoreLogger | null = null;\n}\n\n/**\n * An entry for a manually registered piece using {@linkcode Store.loadPiece()}.\n * @since 3.8.0\n */\nexport interface StoreManuallyRegisteredPiece<StoreName extends StoreRegistryKey> {\n\tname: string;\n\tpiece: StoreRegistryEntries[StoreName] extends Store<infer Piece> ? Constructor<Piece> : never;\n}\n\nexport namespace Store {\n\texport const Registry = StoreRegistry;\n\texport type Options<T extends Piece> = StoreOptions<T>;\n\texport type Logger = StoreLogger;\n\texport type RegistryEntries = StoreRegistryEntries;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/Store.ts"],"names":["Store"],"mappings":";;;;;;;;;;;AAiDA,IAAM,eAAA,GAAkB,IAAI,cAAe,EAAA,CAAA;AAjD3C,IAAA,EAAA,EAAA,EAAA,EAAA,cAAA,EAAA,KAAA,CAAA;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,CAAA;AAzBP,IAAgB,aAAA,CAAA,IAAA,EAAA,aAAA,CAAA,CAAA;AAChB,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA,CAAA;AAChB,IAAgB,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA,CAAA;AAChB,IAAgB,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAkB,aAAA,CAAA,IAAA,EAAA,EAAA,sBAAsC,GAAqD,EAAA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CAAK,QAAS,CAAA,MAAA,CAAO,KAAK,CAAA,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,CAAA;AACpH,QAAA,SAAA;AAAA,OACD;AACA,MAAI,IAAA;AACH,QAAA,MAAM,YAAe,GAAA,IAAA,CAAK,iBAAkB,CAAA,IAAA,EAAM,IAAI,CAAA,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,CAAA;AAAA,SACxC;AAAA,eACQ,KAAO,EAAA;AACf,QAAA,IAAA,CAAK,QAAS,CAAA,OAAA,CAAQ,KAAgB,EAAA,IAAA,CAAK,IAAI,CAAA,CAAA;AAAA,OAChD;AAAA,KACD;AAAA,GACD;AAYD,CAAA,CAAA;AA1TC,cAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AAKA,KAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AAnBwH,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAkUxH,aAAA,CAlUY,QAkUE,iBAAwC,EAAA,eAAA,CAAA,CAAA;AAAA;AAAA;AAAA;AAKtD,aAAA,CAvUY,QAuUE,QAA6B,EAAA,IAAA,CAAA,CAAA;AAvUrC,IAAM,KAAN,GAAA,OAAA;AAAA,CAmVA,CAAUA,MAAV,KAAA;AACC,EAAMA,OAAA,QAAW,GAAA,aAAA,CAAA;AAAA,CADR,EAAA,KAAA,KAAA,KAAA,GAAA,EAAA,CAAA,CAAA","file":"Store.mjs","sourcesContent":["import { Collection } from '@discordjs/collection';\nimport { classExtends, isClass, type AbstractConstructor, type Constructor } from '@sapphire/utilities';\nimport { join } from 'path';\nimport { LoaderError, LoaderErrorType } from '../errors/LoaderError';\nimport { resolvePath, type Path } from '../internal/Path';\nimport { ManuallyRegisteredPiecesSymbol, VirtualPath } from '../internal/constants';\nimport { container, type Container } from '../shared/Container';\nimport type { HydratedModuleData, ILoaderResultEntry, ILoaderStrategy, ModuleData } from '../strategies/ILoaderStrategy';\nimport { LoaderStrategy } from '../strategies/LoaderStrategy';\nimport type { Piece } from './Piece';\nimport { StoreRegistry, type StoreRegistryEntries, type StoreRegistryKey } from './StoreRegistry';\n\n/**\n * The options for the store, this features both hooks (changes the behaviour) and handlers (similar to event listeners).\n */\nexport interface StoreOptions<T extends Piece, StoreName extends StoreRegistryKey = StoreRegistryKey> {\n\t/**\n\t * The name for this store.\n\t */\n\treadonly name: StoreName;\n\n\t/**\n\t * The paths to load pieces from, should be absolute.\n\t * @default []\n\t */\n\treadonly paths?: readonly string[];\n\n\t/**\n\t * The strategy to be used for the loader.\n\t * @default Store.defaultStrategy\n\t */\n\treadonly strategy?: ILoaderStrategy<T>;\n}\n\n/**\n * An interface representing a logger function.\n */\nexport interface StoreLogger {\n\t/**\n\t * @param value The string to print. All strings will be formatted with the format `[STORE => ${name}] [${type}] ${content}`,\n\t * where the content may have identifiers (values or names of methods) surrounded by `'`. For example:\n\t *\n\t * - `[STORE => commands] [LOAD] Skipped piece '/home/user/bot/src/commands/foo.js' as 'LoaderStrategy#filter' returned 'null'.`\n\t * - `[STORE => commands] [INSERT] Unloaded new piece 'foo' due to 'enabled' being 'false'.`\n\t * - `[STORE => commands] [UNLOAD] Unloaded piece 'foo'.`\n\t */\n\t(value: string): void;\n}\n\nconst defaultStrategy = new LoaderStrategy();\n\n/**\n * The store class which contains {@link Piece}s.\n */\nexport class Store<T extends Piece, StoreName extends StoreRegistryKey = StoreRegistryKey> extends Collection<string, T> {\n\tpublic readonly Constructor: AbstractConstructor<T>;\n\tpublic readonly name: StoreName;\n\tpublic readonly paths: Set<string>;\n\tpublic readonly strategy: ILoaderStrategy<T>;\n\n\t/**\n\t * The queue of manually registered pieces to load.\n\t */\n\tprivate readonly [ManuallyRegisteredPiecesSymbol] = new Map<string, StoreManuallyRegisteredPiece<StoreName>>();\n\n\t/**\n\t * Whether or not the store has called `loadAll` at least once.\n\t */\n\t#calledLoadAll = false;\n\n\t/**\n\t * The walk function for the store.\n\t */\n\t#walk: LoaderStrategy<T>['walk'];\n\n\t/**\n\t * @param constructor The piece constructor this store loads.\n\t * @param options The options for the store.\n\t */\n\tpublic constructor(constructor: AbstractConstructor<T>, options: StoreOptions<T, StoreName>) {\n\t\tsuper();\n\t\tthis.Constructor = constructor;\n\t\tthis.name = options.name as StoreRegistryKey;\n\t\tthis.paths = new Set(options.paths ?? []);\n\t\tthis.strategy = options.strategy ?? Store.defaultStrategy;\n\n\t\tthis.#walk =\n\t\t\ttypeof this.strategy.walk === 'function' //\n\t\t\t\t? this.strategy.walk.bind(this.strategy)\n\t\t\t\t: defaultStrategy.walk.bind(defaultStrategy);\n\t}\n\n\t/**\n\t * A reference to the {@link Container} object for ease of use.\n\t * @see container\n\t */\n\tpublic get container(): Container {\n\t\treturn container;\n\t}\n\n\t/**\n\t * Registers a directory into the store.\n\t * @param path The path to be added.\n\t * @example\n\t * ```typescript\n\t * store\n\t * .registerPath(resolve('commands'))\n\t * .registerPath(resolve('third-party', 'commands'));\n\t * ```\n\t */\n\tpublic registerPath(path: Path): this {\n\t\tconst root = resolvePath(path);\n\n\t\tthis.paths.add(root);\n\t\tStore.logger?.(`[STORE => ${this.name}] [REGISTER] Registered path '${root}'.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds a piece into the store's list of manually registered pieces. If {@linkcode Store.loadAll()} was called, the\n\t * piece will be loaded immediately, otherwise it will be queued until {@linkcode Store.loadAll()} is called.\n\t *\n\t * All manually registered pieces will be kept even after they are loaded to ensure they can be loaded again if\n\t * {@linkcode Store.loadAll()} is called again.\n\t *\n\t * @remarks\n\t *\n\t * - Pieces loaded this way will have their {@linkcode Piece.Context.root root} and\n\t * {@linkcode Piece.Context.path path} set to {@linkcode VirtualPath}, and as such, cannot be reloaded.\n\t * - This method is useful in environments where file system access is limited or unavailable, such as when using\n\t * {@link https://en.wikipedia.org/wiki/Serverless_computing Serverless Computing}.\n\t * - This method will always throw a {@link TypeError} if `entry.piece` is not a class.\n\t * - This method will always throw a {@linkcode LoaderError} if the piece does not extend the\n\t * {@linkcode Store#Constructor store's piece constructor}.\n\t * - This operation is atomic, if any of the above errors are thrown, the piece will not be loaded.\n\t *\n\t * @seealso {@linkcode StoreRegistry.loadPiece()}\n\t * @since 3.8.0\n\t * @param entry The entry to load.\n\t * @example\n\t * ```typescript\n\t * import { container } from '@sapphire/pieces';\n\t *\n\t * class PingCommand extends Command {\n\t * // ...\n\t * }\n\t *\n\t * container.stores.get('commands').loadPiece({\n\t * name: 'ping',\n\t * piece: PingCommand\n\t * });\n\t * ```\n\t */\n\tpublic async loadPiece(entry: StoreManuallyRegisteredPiece<StoreName>) {\n\t\tif (!isClass(entry.piece)) {\n\t\t\tthrow new TypeError(`The piece ${entry.name} is not a Class. ${String(entry.piece)}`);\n\t\t}\n\n\t\t// If the piece does not extend the store's Piece class, throw an error:\n\t\tif (!classExtends(entry.piece, this.Constructor as Constructor<T>)) {\n\t\t\tthrow new LoaderError(LoaderErrorType.IncorrectType, `The piece ${entry.name} does not extend ${this.name}`);\n\t\t}\n\n\t\tthis[ManuallyRegisteredPiecesSymbol].set(entry.name, entry);\n\t\tif (this.#calledLoadAll) {\n\t\t\tconst piece = this.construct(entry.piece as unknown as Constructor<T>, {\n\t\t\t\tname: entry.name,\n\t\t\t\troot: VirtualPath,\n\t\t\t\tpath: VirtualPath,\n\t\t\t\textension: VirtualPath\n\t\t\t});\n\t\t\tawait this.insert(piece);\n\t\t}\n\t}\n\n\t/**\n\t * Loads one or more pieces from a path.\n\t * @param root The root directory the file is from.\n\t * @param path The path of the file to load, relative to the `root`.\n\t * @return All the loaded pieces.\n\t */\n\tpublic async load(root: string, path: string): Promise<T[]> {\n\t\tif (root === VirtualPath) {\n\t\t\tthrow new LoaderError(LoaderErrorType.VirtualPiece, `Cannot load a virtual file.`);\n\t\t}\n\n\t\tconst full = join(root, path);\n\t\tconst data = this.strategy.filter(full);\n\t\tif (data === null) {\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD] Skipped piece '${full}' as 'LoaderStrategy#filter' returned 'null'.`);\n\t\t\treturn [];\n\t\t}\n\n\t\tconst promises: Promise<T>[] = [];\n\t\tconst finishedData = this.hydrateModuleData(root, data);\n\t\tfor await (const Ctor of this.strategy.load(this, finishedData)) {\n\t\t\tpromises.push(this.insert(this.construct(Ctor, finishedData)));\n\t\t}\n\n\t\treturn Promise.all(promises);\n\t}\n\n\t/**\n\t * Unloads a piece given its instance or its name.\n\t * @param name The name of the file to load.\n\t * @return Returns the piece that was unloaded.\n\t */\n\tpublic async unload(name: string | T): Promise<T> {\n\t\tconst piece = this.resolve(name);\n\n\t\t// Unload piece:\n\t\tthis.strategy.onUnload(this, piece);\n\t\tawait piece.onUnload();\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD] Unloaded piece '${piece.name}'.`);\n\n\t\t// Remove from cache and return it:\n\t\tthis.delete(piece.name);\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD] Removed piece '${piece.name}'.`);\n\t\treturn piece;\n\t}\n\n\t/**\n\t * Unloads all pieces from the store.\n\t */\n\tpublic async unloadAll(): Promise<T[]> {\n\t\tconst promises: Promise<T>[] = [];\n\t\tfor (const piece of this.values()) {\n\t\t\tpromises.push(this.unload(piece));\n\t\t}\n\n\t\tconst results = await Promise.all(promises);\n\n\t\tthis.strategy.onUnloadAll(this);\n\t\tStore.logger?.(`[STORE => ${this.name}] [UNLOAD-ALL] Removed all pieces.`);\n\t\treturn results;\n\t}\n\n\t/**\n\t * Loads all pieces from all directories specified by {@link paths}.\n\t */\n\tpublic async loadAll(): Promise<void> {\n\t\tthis.#calledLoadAll = true;\n\n\t\tconst pieces: T[] = [];\n\t\tfor (const entry of this[ManuallyRegisteredPiecesSymbol].values()) {\n\t\t\tconst piece = this.construct(entry.piece as unknown as Constructor<T>, {\n\t\t\t\tname: entry.name,\n\t\t\t\troot: VirtualPath,\n\t\t\t\tpath: VirtualPath,\n\t\t\t\textension: VirtualPath\n\t\t\t});\n\t\t\tpieces.push(piece);\n\t\t}\n\n\t\tfor (const path of this.paths) {\n\t\t\tfor await (const piece of this.loadPath(path)) {\n\t\t\t\tpieces.push(piece);\n\t\t\t}\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Found '${pieces.length}' pieces.`);\n\n\t\t// Clear the store before inserting the new pieces:\n\t\tawait this.unloadAll();\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Cleared all pieces.`);\n\n\t\t// Load each piece:\n\t\tfor (const piece of pieces) {\n\t\t\tawait this.insert(piece);\n\t\t}\n\n\t\t// Call onLoadAll:\n\t\tthis.strategy.onLoadAll(this);\n\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Successfully loaded '${this.size}' pieces.`);\n\t}\n\n\t/**\n\t * Resolves a piece by its name or its instance.\n\t * @param name The name of the piece or the instance itself.\n\t * @return The resolved piece.\n\t */\n\tpublic resolve(name: string | T): T {\n\t\tif (typeof name === 'string') {\n\t\t\tconst result = this.get(name);\n\t\t\tif (typeof result === 'undefined') throw new LoaderError(LoaderErrorType.UnloadedPiece, `The piece '${name}' does not exist.`);\n\t\t\treturn result;\n\t\t}\n\n\t\tif (name instanceof this.Constructor) return name;\n\t\tthrow new LoaderError(LoaderErrorType.IncorrectType, `The piece '${name.name}' is not an instance of '${this.Constructor.name}'.`);\n\t}\n\n\t/**\n\t * Inserts a piece into the store.\n\t * @param piece The piece to be inserted into the store.\n\t * @return The inserted piece.\n\t */\n\tpublic async insert(piece: T): Promise<T> {\n\t\tif (!piece.enabled) return piece;\n\n\t\t// Load piece:\n\t\tthis.strategy.onLoad(this, piece);\n\t\tawait piece.onLoad();\n\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Loaded new piece '${piece.name}'.`);\n\n\t\t// If the onLoad disabled the piece, call unload and return it:\n\t\tif (!piece.enabled) {\n\t\t\t// Unload piece:\n\t\t\tthis.strategy.onUnload(this, piece);\n\t\t\tawait piece.onUnload();\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Unloaded new piece '${piece.name}' due to 'enabled' being 'false'.`);\n\n\t\t\treturn piece;\n\t\t}\n\n\t\t// Unload existing piece, if any:\n\t\tconst previous = super.get(piece.name);\n\t\tif (previous) {\n\t\t\tawait this.unload(previous);\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Unloaded existing piece '${piece.name}' due to conflicting 'name'.`);\n\t\t}\n\n\t\t// Set the new piece and return it:\n\t\tthis.set(piece.name, piece);\n\t\tStore.logger?.(`[STORE => ${this.name}] [INSERT] Inserted new piece '${piece.name}'.`);\n\t\treturn piece;\n\t}\n\n\t/**\n\t * Constructs a {@link Piece} instance.\n\t * @param Ctor The {@link Piece}'s constructor used to build the instance.\n\t * @param data The module's information\n\t * @return An instance of the constructed piece.\n\t */\n\tpublic construct(Ctor: ILoaderResultEntry<T>, data: HydratedModuleData): T {\n\t\treturn new Ctor({ store: this, root: data.root, path: data.path, name: data.name }, { name: data.name, enabled: true });\n\t}\n\n\t/**\n\t * Adds the final module data properties.\n\t * @param root The root directory to add.\n\t * @param data The module data returned from {@link ILoaderStrategy.filter}.\n\t * @returns The finished module data.\n\t */\n\tprivate hydrateModuleData(root: string, data: ModuleData): HydratedModuleData {\n\t\treturn { root, ...data };\n\t}\n\n\t/**\n\t * Loads a directory into the store.\n\t * @param root The directory to load the pieces from.\n\t * @return An async iterator that yields the pieces to be loaded into the store.\n\t */\n\tprivate async *loadPath(root: string): AsyncIterableIterator<T> {\n\t\tStore.logger?.(`[STORE => ${this.name}] [WALK] Loading all pieces from '${root}'.`);\n\t\tfor await (const child of this.#walk(this, root, Store.logger)) {\n\t\t\tconst data = this.strategy.filter(child);\n\t\t\tif (data === null) {\n\t\t\t\tStore.logger?.(`[STORE => ${this.name}] [LOAD] Skipped piece '${child}' as 'LoaderStrategy#filter' returned 'null'.`);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst finishedData = this.hydrateModuleData(root, data);\n\t\t\t\tfor await (const Ctor of this.strategy.load(this, finishedData)) {\n\t\t\t\t\tyield this.construct(Ctor, finishedData);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthis.strategy.onError(error as Error, data.path);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The default strategy, defaults to {@link LoaderStrategy}, which is constructed on demand when a store is constructed,\n\t * when none was set beforehand.\n\t */\n\tpublic static defaultStrategy: ILoaderStrategy<any> = defaultStrategy;\n\n\t/**\n\t * The default logger, defaults to `null`.\n\t */\n\tpublic static logger: StoreLogger | null = null;\n}\n\n/**\n * An entry for a manually registered piece using {@linkcode Store.loadPiece()}.\n * @since 3.8.0\n */\nexport interface StoreManuallyRegisteredPiece<StoreName extends StoreRegistryKey> {\n\tname: string;\n\tpiece: StoreRegistryEntries[StoreName] extends Store<infer Piece> ? Constructor<Piece> : never;\n}\n\nexport namespace Store {\n\texport const Registry = StoreRegistry;\n\texport type Options<T extends Piece> = StoreOptions<T>;\n\texport type Logger = StoreLogger;\n\texport type RegistryEntries = StoreRegistryEntries;\n}\n"]}
@@ -155,5 +155,5 @@ __name(_StoreRegistry, "StoreRegistry");
155
155
  var StoreRegistry = _StoreRegistry;
156
156
 
157
157
  export { StoreRegistry };
158
- //# sourceMappingURL=out.js.map
158
+ //# sourceMappingURL=StoreRegistry.mjs.map
159
159
  //# sourceMappingURL=StoreRegistry.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/StoreRegistry.ts"],"names":[],"mappings":";;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,e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AAA;AAAA;AAAA,EAOO,WAA4B,OAAuB;AACzD,SAAK,OAAO,MAAM,IAAwB;AAC1C,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuCA,MAAa,UAA8C,OAAuD;AACjH,UAAM,QAAQ,KAAK,IAAI,MAAM,KAAK;AAElC,QAAI,OAAO;AACV,YAAM,MAAM,UAAU,KAAK;AAAA,IAC5B,OAAO;AACN,UAAI,CAAC,QAAQ,MAAM,KAAK,GAAG;AAC1B,cAAM,IAAI,UAAU,aAAa,MAAM,IAAI,oBAAoB,OAAO,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":[],"mappings":";;;;;;;;;AAAA,IAAA,gCAAA,CAAA;AA8BO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsB,UAAiD,CAAA;AAAA,EAA7E,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAS,YAAA,CAAA,IAAA,EAAA,gCAAA,EAAmC,IAAI,UAA+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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["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,18 @@
1
+ import './chunk-KFLDEQ5J.mjs';
2
+
3
+ // src/tsconfig.json
4
+ var extends2 = "../tsconfig.base.json";
5
+ var compilerOptions = {
6
+ rootDir: "./",
7
+ outDir: "../dist"
8
+ };
9
+ var include = ["."];
10
+ var tsconfig_default = {
11
+ extends: extends2,
12
+ compilerOptions,
13
+ include
14
+ };
15
+
16
+ export { compilerOptions, tsconfig_default as default, extends2 as extends, include };
17
+ //# sourceMappingURL=tsconfig.mjs.map
18
+ //# sourceMappingURL=tsconfig.mjs.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.mjs","sourcesContent":["{\n\t\"extends\": \"../tsconfig.base.json\",\n\t\"compilerOptions\": {\n\t\t\"rootDir\": \"./\",\n\t\t\"outDir\": \"../dist\"\n\t},\n\t\"include\": [\".\"]\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire/pieces",
3
- "version": "4.3.1",
3
+ "version": "4.3.2-next.12ba559",
4
4
  "description": "Sapphire's piece loader.",
5
5
  "main": "dist/cjs/index.cjs",
6
6
  "module": "dist/esm/index.mjs",
@@ -35,35 +35,36 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@discordjs/collection": "^1.5.3",
38
- "@sapphire/utilities": "^3.16.2",
38
+ "@sapphire/utilities": "^3.17.0",
39
39
  "tslib": "^2.6.3"
40
40
  },
41
41
  "devDependencies": {
42
- "@commitlint/cli": "^19.3.0",
42
+ "@commitlint/cli": "^19.4.0",
43
43
  "@commitlint/config-conventional": "^19.2.2",
44
- "@favware/cliff-jumper": "^4.0.2",
44
+ "@favware/cliff-jumper": "^4.0.3",
45
45
  "@favware/npm-deprecate": "^1.0.7",
46
46
  "@favware/rollup-type-bundler": "^3.3.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": "^20.14.9",
50
+ "@types/node": "^20.14.15",
51
51
  "@typescript-eslint/eslint-plugin": "^7.13.1",
52
52
  "@typescript-eslint/parser": "^7.13.1",
53
+ "@vitest/coverage-v8": "^2.0.5",
53
54
  "concurrently": "^8.2.2",
54
55
  "cz-conventional-changelog": "^3.3.0",
55
56
  "esbuild-plugin-file-path-extensions": "^2.1.2",
56
57
  "eslint": "^8.57.0",
57
58
  "eslint-config-prettier": "^9.1.0",
58
- "eslint-plugin-prettier": "^5.1.3",
59
- "lint-staged": "^15.2.7",
60
- "prettier": "^3.3.2",
61
- "rimraf": "^5.0.7",
62
- "tsup": "^8.1.0",
59
+ "eslint-plugin-prettier": "^5.2.1",
60
+ "lint-staged": "^15.2.8",
61
+ "prettier": "^3.3.3",
62
+ "rimraf": "^6.0.1",
63
+ "tsup": "^8.2.4",
63
64
  "typedoc": "^0.26.1",
64
65
  "typedoc-json-parser": "^10.0.0",
65
66
  "typescript": "^5.5.2",
66
- "vitest": "^1.6.0"
67
+ "vitest": "^2.0.5"
67
68
  },
68
69
  "repository": {
69
70
  "type": "git",
@@ -107,10 +108,10 @@
107
108
  "access": "public"
108
109
  },
109
110
  "resolutions": {
110
- "acorn": "^8.12.0",
111
+ "acorn": "^8.12.1",
111
112
  "ansi-regex": "^5.0.1",
112
113
  "minimist": "^1.2.8"
113
114
  },
114
115
  "prettier": "@sapphire/prettier-config",
115
- "packageManager": "yarn@4.3.1"
116
+ "packageManager": "yarn@4.4.0"
116
117
  }