@sapphire/pieces
Advanced tools
Comparing version 2.2.0-next.81a4e99.0 to 2.2.0-next.c2c5360.0
@@ -10,3 +10,2 @@ "use strict"; | ||
constructor(context, options = {}) { | ||
var _a; | ||
super(context, options); | ||
@@ -22,3 +21,3 @@ /** | ||
}); | ||
this.aliases = (_a = options.aliases) !== null && _a !== void 0 ? _a : []; | ||
this.aliases = options.aliases ?? []; | ||
} | ||
@@ -25,0 +24,0 @@ /** |
@@ -28,4 +28,3 @@ "use strict"; | ||
get(key) { | ||
var _a; | ||
return (_a = super.get(key)) !== null && _a !== void 0 ? _a : this.aliases.get(key); | ||
return super.get(key) ?? this.aliases.get(key); | ||
} | ||
@@ -32,0 +31,0 @@ /** |
@@ -10,3 +10,2 @@ "use strict"; | ||
constructor(context, options = {}) { | ||
var _a, _b; | ||
/** | ||
@@ -50,4 +49,4 @@ * The store that contains the piece. | ||
this.path = context.path; | ||
this.name = (_a = options.name) !== null && _a !== void 0 ? _a : context.name; | ||
this.enabled = (_b = options.enabled) !== null && _b !== void 0 ? _b : true; | ||
this.name = options.name ?? context.name; | ||
this.enabled = options.enabled ?? true; | ||
} | ||
@@ -54,0 +53,0 @@ /** |
@@ -20,3 +20,2 @@ "use strict"; | ||
constructor(constructor, options) { | ||
var _a, _b; | ||
super(); | ||
@@ -49,4 +48,4 @@ Object.defineProperty(this, "Constructor", { | ||
this.name = options.name; | ||
this.paths = new Set((_a = options.paths) !== null && _a !== void 0 ? _a : []); | ||
this.strategy = (_b = options.strategy) !== null && _b !== void 0 ? _b : Store.defaultStrategy; | ||
this.paths = new Set(options.paths ?? []); | ||
this.strategy = options.strategy ?? Store.defaultStrategy; | ||
} | ||
@@ -71,5 +70,4 @@ /** | ||
registerPath(path) { | ||
var _a; | ||
this.paths.add(path); | ||
(_a = Store.logger) === null || _a === void 0 ? void 0 : _a.call(Store, `[STORE => ${this.name}] [REGISTER] Registered path '${path}'.`); | ||
Store.logger?.(`[STORE => ${this.name}] [REGISTER] Registered path '${path}'.`); | ||
return this; | ||
@@ -83,6 +81,5 @@ } | ||
async load(path) { | ||
var _a; | ||
const data = this.strategy.filter(path); | ||
if (data === null) { | ||
(_a = Store.logger) === null || _a === void 0 ? void 0 : _a.call(Store, `[STORE => ${this.name}] [LOAD] Skipped piece '${path}' as 'LoaderStrategy#filter' returned 'null'.`); | ||
Store.logger?.(`[STORE => ${this.name}] [LOAD] Skipped piece '${path}' as 'LoaderStrategy#filter' returned 'null'.`); | ||
return []; | ||
@@ -102,3 +99,2 @@ } | ||
async unload(name) { | ||
var _a, _b; | ||
const piece = this.resolve(name); | ||
@@ -108,6 +104,6 @@ // Unload piece: | ||
await piece.onUnload(); | ||
(_a = Store.logger) === null || _a === void 0 ? void 0 : _a.call(Store, `[STORE => ${this.name}] [UNLOAD] Unloaded piece '${piece.name}'.`); | ||
Store.logger?.(`[STORE => ${this.name}] [UNLOAD] Unloaded piece '${piece.name}'.`); | ||
// Remove from cache and return it: | ||
this.delete(piece.name); | ||
(_b = Store.logger) === null || _b === void 0 ? void 0 : _b.call(Store, `[STORE => ${this.name}] [UNLOAD] Removed piece '${piece.name}'.`); | ||
Store.logger?.(`[STORE => ${this.name}] [UNLOAD] Removed piece '${piece.name}'.`); | ||
return piece; | ||
@@ -119,3 +115,2 @@ } | ||
async unloadAll() { | ||
var _a; | ||
const promises = []; | ||
@@ -127,3 +122,3 @@ for (const piece of this.values()) { | ||
this.strategy.onUnloadAll(this); | ||
(_a = Store.logger) === null || _a === void 0 ? void 0 : _a.call(Store, `[STORE => ${this.name}] [UNLOAD-ALL] Removed all pieces.`); | ||
Store.logger?.(`[STORE => ${this.name}] [UNLOAD-ALL] Removed all pieces.`); | ||
return results; | ||
@@ -135,3 +130,2 @@ } | ||
async loadAll() { | ||
var _a, _b, _c; | ||
const pieces = []; | ||
@@ -143,6 +137,6 @@ for (const path of this.paths) { | ||
} | ||
(_a = Store.logger) === null || _a === void 0 ? void 0 : _a.call(Store, `[STORE => ${this.name}] [LOAD-ALL] Found '${pieces.length}' pieces.`); | ||
Store.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Found '${pieces.length}' pieces.`); | ||
// Clear the store before inserting the new pieces: | ||
await this.unloadAll(); | ||
(_b = Store.logger) === null || _b === void 0 ? void 0 : _b.call(Store, `[STORE => ${this.name}] [LOAD-ALL] Cleared all pieces.`); | ||
Store.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Cleared all pieces.`); | ||
// Load each piece: | ||
@@ -154,3 +148,3 @@ for (const piece of pieces) { | ||
this.strategy.onLoadAll(this); | ||
(_c = Store.logger) === null || _c === void 0 ? void 0 : _c.call(Store, `[STORE => ${this.name}] [LOAD-ALL] Successfully loaded '${this.size}' pieces.`); | ||
Store.logger?.(`[STORE => ${this.name}] [LOAD-ALL] Successfully loaded '${this.size}' pieces.`); | ||
} | ||
@@ -179,3 +173,2 @@ /** | ||
async insert(piece) { | ||
var _a, _b, _c, _d; | ||
if (!piece.enabled) | ||
@@ -186,3 +179,3 @@ return piece; | ||
await piece.onLoad(); | ||
(_a = Store.logger) === null || _a === void 0 ? void 0 : _a.call(Store, `[STORE => ${this.name}] [INSERT] Loaded new piece '${piece.name}'.`); | ||
Store.logger?.(`[STORE => ${this.name}] [INSERT] Loaded new piece '${piece.name}'.`); | ||
// If the onLoad disabled the piece, call unload and return it: | ||
@@ -193,3 +186,3 @@ if (!piece.enabled) { | ||
await piece.onUnload(); | ||
(_b = Store.logger) === null || _b === void 0 ? void 0 : _b.call(Store, `[STORE => ${this.name}] [INSERT] Unloaded new piece '${piece.name}' due to 'enabled' being 'false'.`); | ||
Store.logger?.(`[STORE => ${this.name}] [INSERT] Unloaded new piece '${piece.name}' due to 'enabled' being 'false'.`); | ||
return piece; | ||
@@ -201,7 +194,7 @@ } | ||
await this.unload(previous); | ||
(_c = Store.logger) === null || _c === void 0 ? void 0 : _c.call(Store, `[STORE => ${this.name}] [INSERT] Unloaded existing piece '${piece.name}' due to conflicting 'name'.`); | ||
Store.logger?.(`[STORE => ${this.name}] [INSERT] Unloaded existing piece '${piece.name}' due to conflicting 'name'.`); | ||
} | ||
// Set the new piece and return it: | ||
this.set(piece.name, piece); | ||
(_d = Store.logger) === null || _d === void 0 ? void 0 : _d.call(Store, `[STORE => ${this.name}] [INSERT] Inserted new piece '${piece.name}'.`); | ||
Store.logger?.(`[STORE => ${this.name}] [INSERT] Inserted new piece '${piece.name}'.`); | ||
return piece; | ||
@@ -224,8 +217,7 @@ } | ||
async *loadPath(directory) { | ||
var _a, _b; | ||
(_a = Store.logger) === null || _a === void 0 ? void 0 : _a.call(Store, `[STORE => ${this.name}] [WALK] Loading all pieces from '${directory}'.`); | ||
Store.logger?.(`[STORE => ${this.name}] [WALK] Loading all pieces from '${directory}'.`); | ||
for await (const child of this.walk(directory)) { | ||
const data = this.strategy.filter(child); | ||
if (data === null) { | ||
(_b = Store.logger) === null || _b === void 0 ? void 0 : _b.call(Store, `[STORE => ${this.name}] [LOAD] Skipped piece '${child}' as 'LoaderStrategy#filter' returned 'null'.`); | ||
Store.logger?.(`[STORE => ${this.name}] [LOAD] Skipped piece '${child}' as 'LoaderStrategy#filter' returned 'null'.`); | ||
continue; | ||
@@ -249,4 +241,3 @@ } | ||
async *walk(path) { | ||
var _a; | ||
(_a = Store.logger) === null || _a === void 0 ? void 0 : _a.call(Store, `[STORE => ${this.name}] [WALK] Loading all pieces from '${path}'.`); | ||
Store.logger?.(`[STORE => ${this.name}] [WALK] Loading all pieces from '${path}'.`); | ||
try { | ||
@@ -253,0 +244,0 @@ const dir = await fs_1.promises.opendir(path); |
{ | ||
"name": "@sapphire/pieces", | ||
"version": "2.2.0-next.81a4e99.0", | ||
"version": "2.2.0-next.c2c5360.0", | ||
"description": "Sapphire's piece loader.", | ||
@@ -29,21 +29,21 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@discordjs/collection": "^0.1.6", | ||
"@sapphire/utilities": "^1.6.1", | ||
"@discordjs/collection": "^0.2.1", | ||
"@sapphire/utilities": "^2.0.1", | ||
"tslib": "^2.3.0" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^12.1.4", | ||
"@commitlint/config-conventional": "^12.1.4", | ||
"@favware/rollup-type-bundler": "^1.0.2", | ||
"@sapphire/eslint-config": "^3.2.1", | ||
"@commitlint/cli": "^13.1.0", | ||
"@commitlint/config-conventional": "^13.1.0", | ||
"@favware/rollup-type-bundler": "^1.0.3", | ||
"@sapphire/eslint-config": "^3.2.3", | ||
"@sapphire/prettier-config": "^1.1.6", | ||
"@sapphire/ts-config": "^2.3.1", | ||
"@types/node": "^16.4.2", | ||
"@sapphire/ts-config": "^3.0.0", | ||
"@types/node": "^16.6.1", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"husky": "^7.0.1", | ||
"lint-staged": "^11.0.1", | ||
"lint-staged": "^11.1.2", | ||
"npm-run-all": "^4.1.5", | ||
"pretty-quick": "^3.1.1", | ||
"standard-version": "^9.3.1", | ||
"typedoc": "^0.21.4", | ||
"typedoc": "^0.21.5", | ||
"typedoc-plugin-nojekyll": "^1.0.1", | ||
@@ -50,0 +50,0 @@ "typescript": "^4.3.5" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
69779
1424
+ Added@discordjs/collection@0.2.4(transitive)
+ Added@sapphire/utilities@2.0.1(transitive)
- Removed@discordjs/collection@0.1.6(transitive)
- Removed@sapphire/utilities@1.7.0(transitive)
Updated@discordjs/collection@^0.2.1
Updated@sapphire/utilities@^2.0.1