@sapphire/pieces 4.0.1 → 4.0.2
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/CHANGELOG.md +6 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/lib/errors/LoaderError.cjs +39 -0
- package/dist/cjs/lib/errors/LoaderError.cjs.map +1 -0
- package/dist/cjs/lib/errors/MissingExportsError.cjs +27 -0
- package/dist/cjs/lib/errors/MissingExportsError.cjs.map +1 -0
- package/dist/cjs/lib/internal/Path.cjs +16 -0
- package/dist/cjs/lib/internal/Path.cjs.map +1 -0
- package/dist/cjs/lib/internal/RootScan.cjs +25 -0
- package/dist/cjs/lib/internal/RootScan.cjs.map +1 -0
- package/dist/cjs/lib/internal/constants.cjs +10 -0
- package/dist/cjs/lib/internal/constants.cjs.map +1 -0
- package/dist/cjs/lib/internal/internal.cjs +12 -0
- package/dist/cjs/lib/shared/Container.cjs +12 -0
- package/dist/cjs/lib/shared/Container.cjs.map +1 -0
- package/dist/cjs/lib/strategies/ILoaderStrategy.cjs +4 -0
- package/dist/cjs/lib/strategies/ILoaderStrategy.cjs.map +1 -0
- package/dist/cjs/lib/strategies/LoaderStrategy.cjs +113 -0
- package/dist/cjs/lib/strategies/LoaderStrategy.cjs.map +1 -0
- package/dist/cjs/lib/strategies/Shared.cjs +25 -0
- package/dist/cjs/lib/strategies/Shared.cjs.map +1 -0
- package/dist/cjs/lib/structures/AliasPiece.cjs +37 -0
- package/dist/cjs/lib/structures/AliasPiece.cjs.map +1 -0
- package/dist/cjs/lib/structures/AliasStore.cjs +66 -0
- package/dist/cjs/lib/structures/AliasStore.cjs.map +1 -0
- package/dist/cjs/lib/structures/Piece.cjs +93 -0
- package/dist/cjs/lib/structures/Piece.cjs.map +1 -0
- package/dist/cjs/lib/structures/PieceLocation.cjs +102 -0
- package/dist/cjs/lib/structures/PieceLocation.cjs.map +1 -0
- package/dist/cjs/lib/structures/Store.cjs +326 -0
- package/dist/cjs/lib/structures/Store.cjs.map +1 -0
- package/dist/cjs/lib/structures/StoreRegistry.cjs +173 -0
- package/dist/cjs/lib/structures/StoreRegistry.cjs.map +1 -0
- package/package.json +2 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
# [4.0.2](https://github.com/sapphiredev/pieces/compare/v4.0.2...v4.0.2) - (2023-12-05)
|
|
6
|
+
|
|
7
|
+
## 🐛 Bug Fixes
|
|
8
|
+
|
|
9
|
+
- Properly package all files in dist for npm ([2faab8a](https://github.com/sapphiredev/pieces/commit/2faab8af9c604a6062ab078a34e4aba8ac92cc80))
|
|
10
|
+
|
|
5
11
|
# [4.0.1](https://github.com/sapphiredev/pieces/compare/v4.0.1...v4.0.1) - (2023-12-05)
|
|
6
12
|
|
|
7
13
|
## 🐛 Bug Fixes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,OAAO;AAEP,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,mBAAmB;AAC5B,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","sourcesContent":["import 'tslib';\n\nexport * from './lib/errors/LoaderError';\nexport * from './lib/errors/MissingExportsError';\nexport * from './lib/internal/RootScan';\nexport { VirtualPath } from './lib/internal/constants';\nexport * from './lib/shared/Container';\nexport * from './lib/strategies/ILoaderStrategy';\nexport * from './lib/strategies/LoaderStrategy';\nexport * from './lib/structures/AliasPiece';\nexport * from './lib/structures/AliasStore';\nexport * from './lib/structures/Piece';\nexport * from './lib/structures/PieceLocation';\nexport * from './lib/structures/Store';\nexport * from './lib/structures/StoreRegistry';\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __publicField = (obj, key, value) => {
|
|
7
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
+
return value;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/lib/errors/LoaderError.ts
|
|
12
|
+
var LoaderErrorType = /* @__PURE__ */ ((LoaderErrorType2) => {
|
|
13
|
+
LoaderErrorType2["EmptyModule"] = "EMPTY_MODULE";
|
|
14
|
+
LoaderErrorType2["VirtualPiece"] = "VIRTUAL_PIECE";
|
|
15
|
+
LoaderErrorType2["UnloadedPiece"] = "UNLOADED_PIECE";
|
|
16
|
+
LoaderErrorType2["IncorrectType"] = "INCORRECT_TYPE";
|
|
17
|
+
LoaderErrorType2["UnknownStore"] = "UNKNOWN_STORE";
|
|
18
|
+
return LoaderErrorType2;
|
|
19
|
+
})(LoaderErrorType || {});
|
|
20
|
+
var _LoaderError = class _LoaderError extends Error {
|
|
21
|
+
constructor(type, message) {
|
|
22
|
+
super(message);
|
|
23
|
+
/**
|
|
24
|
+
* The type of the error that was thrown.
|
|
25
|
+
*/
|
|
26
|
+
__publicField(this, "type");
|
|
27
|
+
this.type = type;
|
|
28
|
+
}
|
|
29
|
+
get name() {
|
|
30
|
+
return `${super.name} [${this.type}]`;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
__name(_LoaderError, "LoaderError");
|
|
34
|
+
var LoaderError = _LoaderError;
|
|
35
|
+
|
|
36
|
+
exports.LoaderError = LoaderError;
|
|
37
|
+
exports.LoaderErrorType = LoaderErrorType;
|
|
38
|
+
//# sourceMappingURL=out.js.map
|
|
39
|
+
//# sourceMappingURL=LoaderError.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/errors/LoaderError.ts"],"names":["LoaderErrorType"],"mappings":";;;;;;;;;AAAO,IAAK,kBAAL,kBAAKA,qBAAL;AACN,EAAAA,iBAAA,iBAAc;AACd,EAAAA,iBAAA,kBAAe;AACf,EAAAA,iBAAA,mBAAgB;AAChB,EAAAA,iBAAA,mBAAgB;AAChB,EAAAA,iBAAA,kBAAe;AALJ,SAAAA;AAAA,GAAA;AAWL,IAAM,eAAN,MAAM,qBAAoB,MAAM;AAAA,EAM/B,YAAY,MAAuB,SAAiB;AAC1D,UAAM,OAAO;AAHd;AAAA;AAAA;AAAA,wBAAgB;AAIf,SAAK,OAAO;AAAA,EACb;AAAA,EAEA,IAAoB,OAAO;AAC1B,WAAO,GAAG,MAAM,IAAI,KAAK,KAAK,IAAI;AAAA,EACnC;AACD;AAduC;AAAhC,IAAM,cAAN","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"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var LoaderError_cjs = require('./LoaderError.cjs');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __publicField = (obj, key, value) => {
|
|
9
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
|
+
return value;
|
|
11
|
+
};
|
|
12
|
+
var _MissingExportsError = class _MissingExportsError extends LoaderError_cjs.LoaderError {
|
|
13
|
+
constructor(path) {
|
|
14
|
+
super(LoaderError_cjs.LoaderErrorType.EmptyModule, `A compatible class export was not found. [${path}]`);
|
|
15
|
+
/**
|
|
16
|
+
* The path of the module that did not have exports.
|
|
17
|
+
*/
|
|
18
|
+
__publicField(this, "path");
|
|
19
|
+
this.path = path;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
__name(_MissingExportsError, "MissingExportsError");
|
|
23
|
+
var MissingExportsError = _MissingExportsError;
|
|
24
|
+
|
|
25
|
+
exports.MissingExportsError = MissingExportsError;
|
|
26
|
+
//# sourceMappingURL=out.js.map
|
|
27
|
+
//# sourceMappingURL=MissingExportsError.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/errors/MissingExportsError.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAAS,aAAa,uBAAuB;AAKtC,IAAM,uBAAN,MAAM,6BAA4B,YAAY;AAAA,EAM7C,YAAY,MAAc;AAChC,UAAM,gBAAgB,aAAa,6CAA6C,IAAI,GAAG;AAHxF;AAAA;AAAA;AAAA,wBAAgB;AAIf,SAAK,OAAO;AAAA,EACb;AACD;AAVqD;AAA9C,IAAM,sBAAN","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"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var url = require('url');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
function resolvePath(path) {
|
|
8
|
+
if (typeof path === "string")
|
|
9
|
+
return path;
|
|
10
|
+
return url.fileURLToPath(path);
|
|
11
|
+
}
|
|
12
|
+
__name(resolvePath, "resolvePath");
|
|
13
|
+
|
|
14
|
+
exports.resolvePath = resolvePath;
|
|
15
|
+
//# sourceMappingURL=out.js.map
|
|
16
|
+
//# sourceMappingURL=Path.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/internal/Path.ts"],"names":[],"mappings":";;;;AAAA,SAAS,qBAAqB;AAIvB,SAAS,YAAY,MAAoB;AAC/C,MAAI,OAAO,SAAS;AAAU,WAAO;AACrC,SAAO,cAAc,IAAI;AAC1B;AAHgB","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"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var data = null;
|
|
9
|
+
function getRootData() {
|
|
10
|
+
if (data !== null)
|
|
11
|
+
return data;
|
|
12
|
+
const cwd = process.cwd();
|
|
13
|
+
try {
|
|
14
|
+
const file = JSON.parse(fs.readFileSync(path.join(cwd, "package.json"), "utf8"));
|
|
15
|
+
data = { root: path.dirname(path.join(cwd, file.main)), type: file.type === "module" ? "ESM" : "CommonJS" };
|
|
16
|
+
} catch {
|
|
17
|
+
data = { root: cwd, type: "CommonJS" };
|
|
18
|
+
}
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
__name(getRootData, "getRootData");
|
|
22
|
+
|
|
23
|
+
exports.getRootData = getRootData;
|
|
24
|
+
//# sourceMappingURL=out.js.map
|
|
25
|
+
//# sourceMappingURL=RootScan.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/internal/RootScan.ts"],"names":[],"mappings":";;;;AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS,YAAY;AAE9B,IAAI,OAAwB;AACrB,SAAS,cAAwB;AACvC,MAAI,SAAS;AAAM,WAAO;AAE1B,QAAM,MAAM,QAAQ,IAAI;AAExB,MAAI;AACH,UAAM,OAAO,KAAK,MAAM,aAAa,KAAK,KAAK,cAAc,GAAG,MAAM,CAAC;AACvE,WAAO,EAAE,MAAM,QAAQ,KAAK,KAAK,KAAK,IAAI,CAAC,GAAG,MAAM,KAAK,SAAS,WAAW,QAAQ,WAAW;AAAA,EACjG,QAAQ;AACP,WAAO,EAAE,MAAM,KAAK,MAAM,WAAW;AAAA,EACtC;AAEA,SAAO;AACR;AAbgB","sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, join } from 'path';\n\nlet data: RootData | null = null;\nexport function getRootData(): RootData {\n\tif (data !== null) return data;\n\n\tconst cwd = process.cwd();\n\n\ttry {\n\t\tconst file = JSON.parse(readFileSync(join(cwd, 'package.json'), 'utf8'));\n\t\tdata = { root: dirname(join(cwd, file.main)), type: file.type === 'module' ? 'ESM' : 'CommonJS' };\n\t} catch {\n\t\tdata = { root: cwd, type: 'CommonJS' };\n\t}\n\n\treturn data;\n}\n\nexport interface RootData {\n\troot: string;\n\ttype: 'ESM' | 'CommonJS';\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/lib/internal/constants.ts
|
|
4
|
+
var VirtualPath = "::virtual::";
|
|
5
|
+
var ManuallyRegisteredPiecesSymbol = Symbol("@sapphire/pieces:ManuallyRegisteredPieces");
|
|
6
|
+
|
|
7
|
+
exports.ManuallyRegisteredPiecesSymbol = ManuallyRegisteredPiecesSymbol;
|
|
8
|
+
exports.VirtualPath = VirtualPath;
|
|
9
|
+
//# sourceMappingURL=out.js.map
|
|
10
|
+
//# sourceMappingURL=constants.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/internal/constants.ts"],"names":[],"mappings":";AAAO,IAAM,cAAc;AACpB,IAAM,iCAAiC,OAAO,2CAA2C","sourcesContent":["export const VirtualPath = '::virtual::';\nexport const ManuallyRegisteredPiecesSymbol = Symbol('@sapphire/pieces:ManuallyRegisteredPieces');\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const __defProp = Object.defineProperty;
|
|
4
|
+
const __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
|
|
6
|
+
function mjsImport(path) {
|
|
7
|
+
return import(path);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
__name(mjsImport, "mjsImport");
|
|
11
|
+
|
|
12
|
+
exports.mjsImport = mjsImport;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var StoreRegistry_cjs = require('../structures/StoreRegistry.cjs');
|
|
4
|
+
|
|
5
|
+
// src/lib/shared/Container.ts
|
|
6
|
+
var container = {
|
|
7
|
+
stores: new StoreRegistry_cjs.StoreRegistry()
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
exports.container = container;
|
|
11
|
+
//# sourceMappingURL=out.js.map
|
|
12
|
+
//# sourceMappingURL=Container.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/shared/Container.ts"],"names":[],"mappings":";AAAA,SAAS,qBAAqB;AA6EvB,IAAM,YAAuB;AAAA,EACnC,QAAQ,IAAI,cAAc;AAC3B","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 run(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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utilities = require('@sapphire/utilities');
|
|
4
|
+
var promises = require('fs/promises');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var url = require('url');
|
|
7
|
+
var MissingExportsError_cjs = require('../errors/MissingExportsError.cjs');
|
|
8
|
+
var RootScan_cjs = require('../internal/RootScan.cjs');
|
|
9
|
+
var internal_cjs = require('../internal/internal.cjs');
|
|
10
|
+
var Shared_cjs = require('./Shared.cjs');
|
|
11
|
+
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
16
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
17
|
+
}) : x)(function(x) {
|
|
18
|
+
if (typeof require !== "undefined")
|
|
19
|
+
return require.apply(this, arguments);
|
|
20
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
21
|
+
});
|
|
22
|
+
var __publicField = (obj, key, value) => {
|
|
23
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
26
|
+
var _LoaderStrategy = class _LoaderStrategy {
|
|
27
|
+
constructor() {
|
|
28
|
+
__publicField(this, "clientUsesESModules", RootScan_cjs.getRootData().type === "ESM");
|
|
29
|
+
__publicField(this, "supportedExtensions", [".js", ".cjs", ".mjs"]);
|
|
30
|
+
__publicField(this, "filterDtsFiles", false);
|
|
31
|
+
if (Reflect.has(process, Symbol.for("ts-node.register.instance")) || !utilities.isNullish(process.env.TS_NODE_DEV)) {
|
|
32
|
+
this.supportedExtensions.push(".ts", ".cts", ".mts");
|
|
33
|
+
this.filterDtsFiles = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
filter(path$1) {
|
|
37
|
+
const extension = path.extname(path$1);
|
|
38
|
+
if (!this.supportedExtensions.includes(extension))
|
|
39
|
+
return null;
|
|
40
|
+
if (this.filterDtsFiles && path$1.endsWith(".d.ts"))
|
|
41
|
+
return null;
|
|
42
|
+
const name = path.basename(path$1, extension);
|
|
43
|
+
if (name === "" || name.startsWith("_"))
|
|
44
|
+
return null;
|
|
45
|
+
return { extension, path: path$1, name };
|
|
46
|
+
}
|
|
47
|
+
async preload(file) {
|
|
48
|
+
const mjs = [".mjs", ".mts"].includes(file.extension) || [".js", ".ts"].includes(file.extension) && this.clientUsesESModules;
|
|
49
|
+
if (mjs) {
|
|
50
|
+
const url$1 = url.pathToFileURL(file.path);
|
|
51
|
+
url$1.searchParams.append("d", Date.now().toString());
|
|
52
|
+
url$1.searchParams.append("name", file.name);
|
|
53
|
+
url$1.searchParams.append("extension", file.extension);
|
|
54
|
+
return internal_cjs.mjsImport(url$1);
|
|
55
|
+
}
|
|
56
|
+
const mod = __require(file.path);
|
|
57
|
+
delete __require.cache[__require.resolve(file.path)];
|
|
58
|
+
return mod;
|
|
59
|
+
}
|
|
60
|
+
async *load(store, file) {
|
|
61
|
+
let yielded = false;
|
|
62
|
+
const result = await this.preload(file);
|
|
63
|
+
if (Shared_cjs.isClass(result) && Shared_cjs.classExtends(result, store.Constructor)) {
|
|
64
|
+
yield result;
|
|
65
|
+
yielded = true;
|
|
66
|
+
}
|
|
67
|
+
for (const value of Object.values(result)) {
|
|
68
|
+
if (Shared_cjs.isClass(value) && Shared_cjs.classExtends(value, store.Constructor)) {
|
|
69
|
+
yield value;
|
|
70
|
+
yielded = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!yielded) {
|
|
74
|
+
throw new MissingExportsError_cjs.MissingExportsError(file.path);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
onLoad() {
|
|
78
|
+
return void 0;
|
|
79
|
+
}
|
|
80
|
+
onLoadAll() {
|
|
81
|
+
return void 0;
|
|
82
|
+
}
|
|
83
|
+
onUnload() {
|
|
84
|
+
return void 0;
|
|
85
|
+
}
|
|
86
|
+
onUnloadAll() {
|
|
87
|
+
return void 0;
|
|
88
|
+
}
|
|
89
|
+
onError(error, path) {
|
|
90
|
+
console.error(`Error when loading '${path}':`, error);
|
|
91
|
+
}
|
|
92
|
+
async *walk(store, path$1, logger) {
|
|
93
|
+
logger?.(`[STORE => ${store.name}] [WALK] Loading all pieces from '${path$1}'.`);
|
|
94
|
+
try {
|
|
95
|
+
const dir = await promises.opendir(path$1);
|
|
96
|
+
for await (const item of dir) {
|
|
97
|
+
if (item.isFile())
|
|
98
|
+
yield path.join(dir.path, item.name);
|
|
99
|
+
else if (item.isDirectory())
|
|
100
|
+
yield* this.walk(store, path.join(dir.path, item.name), logger);
|
|
101
|
+
}
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (error.code !== "ENOENT")
|
|
104
|
+
this.onError(error, path$1);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
__name(_LoaderStrategy, "LoaderStrategy");
|
|
109
|
+
var LoaderStrategy = _LoaderStrategy;
|
|
110
|
+
|
|
111
|
+
exports.LoaderStrategy = LoaderStrategy;
|
|
112
|
+
//# sourceMappingURL=out.js.map
|
|
113
|
+
//# sourceMappingURL=LoaderStrategy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/strategies/LoaderStrategy.ts"],"names":[],"mappings":"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","sourcesContent":["import { isNullish, 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';\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\t/**\n\t\t * If {@linkplain https://github.com/TypeStrong/ts-node ts-node} is being used\n\t\t * we conditionally need to register files ending in the `.ts` file extension.\n\t\t *\n\t\t * This is because `ts-node` builds files into memory, so we have to scan the\n\t\t * source `.ts` files, rather than files emitted with any of the JavaScript\n\t\t * extensions.\n\t\t */\n\t\tif (Reflect.has(process, Symbol.for('ts-node.register.instance')) || !isNullish(process.env.TS_NODE_DEV)) {\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"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
|
|
6
|
+
// src/lib/strategies/Shared.ts
|
|
7
|
+
function isClass(value) {
|
|
8
|
+
return typeof value === "function" && typeof value.prototype === "object";
|
|
9
|
+
}
|
|
10
|
+
__name(isClass, "isClass");
|
|
11
|
+
function classExtends(value, base) {
|
|
12
|
+
let ctor = value;
|
|
13
|
+
while (ctor !== null) {
|
|
14
|
+
if (ctor === base)
|
|
15
|
+
return true;
|
|
16
|
+
ctor = Object.getPrototypeOf(ctor);
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
__name(classExtends, "classExtends");
|
|
21
|
+
|
|
22
|
+
exports.classExtends = classExtends;
|
|
23
|
+
exports.isClass = isClass;
|
|
24
|
+
//# sourceMappingURL=out.js.map
|
|
25
|
+
//# sourceMappingURL=Shared.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/strategies/Shared.ts"],"names":[],"mappings":";;;;AAOO,SAAS,QAAQ,OAAuC;AAC9D,SAAO,OAAO,UAAU,cAAc,OAAO,MAAM,cAAc;AAClE;AAFgB;AAUT,SAAS,aAAqC,OAAqB,MAAqB;AAC9F,MAAI,OAA4B;AAChC,SAAO,SAAS,MAAM;AACrB,QAAI,SAAS;AAAM,aAAO;AAC1B,WAAO,OAAO,eAAe,IAAI;AAAA,EAClC;AAEA,SAAO;AACR;AARgB","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"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Piece_cjs = require('./Piece.cjs');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __publicField = (obj, key, value) => {
|
|
9
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
|
+
return value;
|
|
11
|
+
};
|
|
12
|
+
var _AliasPiece = class _AliasPiece extends Piece_cjs.Piece {
|
|
13
|
+
constructor(context, options = {}) {
|
|
14
|
+
super(context, options);
|
|
15
|
+
/**
|
|
16
|
+
* The aliases for the piece.
|
|
17
|
+
*/
|
|
18
|
+
__publicField(this, "aliases");
|
|
19
|
+
this.aliases = options.aliases ?? [];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Defines the `JSON.stringify` behavior of this alias piece.
|
|
23
|
+
*/
|
|
24
|
+
toJSON() {
|
|
25
|
+
return {
|
|
26
|
+
...super.toJSON(),
|
|
27
|
+
aliases: this.aliases.slice()
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
__name(_AliasPiece, "AliasPiece");
|
|
32
|
+
exports.AliasPiece = _AliasPiece;
|
|
33
|
+
((AliasPiece2) => {
|
|
34
|
+
({ Location: AliasPiece2.Location } = Piece_cjs.Piece);
|
|
35
|
+
})(exports.AliasPiece || (exports.AliasPiece = {}));
|
|
36
|
+
//# sourceMappingURL=out.js.map
|
|
37
|
+
//# sourceMappingURL=AliasPiece.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/AliasPiece.ts"],"names":["AliasPiece"],"mappings":";;;;;;;;;AAAA,SAAS,aAAa;AAcf,IAAM,cAAN,MAAM,oBAAiI,MAG5I;AAAA,EAMM,YAAY,SAA8C,UAA6B,CAAC,GAAG;AACjG,UAAM,SAAS,OAAO;AAHvB;AAAA;AAAA;AAAA,wBAAO;AAIN,SAAK,UAAU,QAAQ,WAAW,CAAC;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA,EAKgB,SAA0B;AACzC,WAAO;AAAA,MACN,GAAG,MAAM,OAAO;AAAA,MAChB,SAAS,KAAK,QAAQ,MAAM;AAAA,IAC7B;AAAA,EACD;AACD;AApBE;AAHK,IAAM,aAAN;AAAA,CAiCA,CAAUA,gBAAV;AACC,GAAM,EAAE,UAAAA,YAAA,aAAa;AAAA,GADZ","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"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var collection = require('@discordjs/collection');
|
|
4
|
+
var Store_cjs = require('./Store.cjs');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __publicField = (obj, key, value) => {
|
|
10
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
11
|
+
return value;
|
|
12
|
+
};
|
|
13
|
+
var _AliasStore = class _AliasStore extends Store_cjs.Store {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
/**
|
|
17
|
+
* The aliases referencing to pieces.
|
|
18
|
+
*/
|
|
19
|
+
__publicField(this, "aliases", new collection.Collection());
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Looks up the name by the store, falling back to an alias lookup.
|
|
23
|
+
* @param key The key to look for.
|
|
24
|
+
*/
|
|
25
|
+
get(key) {
|
|
26
|
+
return super.get(key) ?? this.aliases.get(key);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Checks whether a key is in the store, or is an alias
|
|
30
|
+
* @param key The key to check
|
|
31
|
+
*/
|
|
32
|
+
has(key) {
|
|
33
|
+
return super.has(key) || this.aliases.has(key);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Unloads a piece given its instance or its name, and removes all the aliases.
|
|
37
|
+
* @param name The name of the file to load.
|
|
38
|
+
* @return Returns the piece that was unloaded.
|
|
39
|
+
*/
|
|
40
|
+
unload(name) {
|
|
41
|
+
const piece = this.resolve(name);
|
|
42
|
+
for (const alias of piece.aliases) {
|
|
43
|
+
const aliasPiece = this.aliases.get(alias);
|
|
44
|
+
if (aliasPiece === piece)
|
|
45
|
+
this.aliases.delete(alias);
|
|
46
|
+
}
|
|
47
|
+
return super.unload(piece);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Inserts a piece into the store, and adds all the aliases.
|
|
51
|
+
* @param piece The piece to be inserted into the store.
|
|
52
|
+
* @return The inserted piece.
|
|
53
|
+
*/
|
|
54
|
+
async insert(piece) {
|
|
55
|
+
for (const key of piece.aliases) {
|
|
56
|
+
this.aliases.set(key, piece);
|
|
57
|
+
}
|
|
58
|
+
return super.insert(piece);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
__name(_AliasStore, "AliasStore");
|
|
62
|
+
var AliasStore = _AliasStore;
|
|
63
|
+
|
|
64
|
+
exports.AliasStore = AliasStore;
|
|
65
|
+
//# sourceMappingURL=out.js.map
|
|
66
|
+
//# sourceMappingURL=AliasStore.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/AliasStore.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAAS,kBAAkB;AAE3B,SAAS,aAAa;AAMf,IAAM,cAAN,MAAM,oBAAgG,MAAoB;AAAA,EAA1H;AAAA;AAIN;AAAA;AAAA;AAAA,wBAAgB,WAAU,IAAI,WAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMpC,IAAI,KAA4B;AAC/C,WAAO,MAAM,IAAI,GAAG,KAAK,KAAK,QAAQ,IAAI,GAAG;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMgB,IAAI,KAAsB;AACzC,WAAO,MAAM,IAAI,GAAG,KAAK,KAAK,QAAQ,IAAI,GAAG;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOgB,OAAO,MAA8B;AACpD,UAAM,QAAQ,KAAK,QAAQ,IAAI;AAG/B,eAAW,SAAS,MAAM,SAAS;AAElC,YAAM,aAAa,KAAK,QAAQ,IAAI,KAAK;AACzC,UAAI,eAAe;AAAO,aAAK,QAAQ,OAAO,KAAK;AAAA,IACpD;AAEA,WAAO,MAAM,OAAO,KAAK;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAsB,OAAO,OAAU;AACtC,eAAW,OAAO,MAAM,SAAS;AAChC,WAAK,QAAQ,IAAI,KAAK,KAAK;AAAA,IAC5B;AAEA,WAAO,MAAM,OAAO,KAAK;AAAA,EAC1B;AACD;AApDiI;AAA1H,IAAM,aAAN","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"]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Container_cjs = require('../shared/Container.cjs');
|
|
4
|
+
var PieceLocation_cjs = require('./PieceLocation.cjs');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __publicField = (obj, key, value) => {
|
|
10
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
11
|
+
return value;
|
|
12
|
+
};
|
|
13
|
+
var _Piece = class _Piece {
|
|
14
|
+
constructor(context, options = {}) {
|
|
15
|
+
/**
|
|
16
|
+
* The store that contains the piece.
|
|
17
|
+
*/
|
|
18
|
+
__publicField(this, "store");
|
|
19
|
+
/**
|
|
20
|
+
* The location metadata for the piece's file.
|
|
21
|
+
*/
|
|
22
|
+
__publicField(this, "location");
|
|
23
|
+
/**
|
|
24
|
+
* The name of the piece.
|
|
25
|
+
*/
|
|
26
|
+
__publicField(this, "name");
|
|
27
|
+
/**
|
|
28
|
+
* Whether or not the piece is enabled.
|
|
29
|
+
*/
|
|
30
|
+
__publicField(this, "enabled");
|
|
31
|
+
/**
|
|
32
|
+
* The raw options passed to this {@link Piece}
|
|
33
|
+
*/
|
|
34
|
+
__publicField(this, "options");
|
|
35
|
+
this.store = context.store;
|
|
36
|
+
this.location = new PieceLocation_cjs.PieceLocation(context.path, context.root);
|
|
37
|
+
this.name = options.name ?? context.name;
|
|
38
|
+
this.enabled = options.enabled ?? true;
|
|
39
|
+
this.options = options;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A reference to the {@link Container} object for ease of use.
|
|
43
|
+
* @see container
|
|
44
|
+
*/
|
|
45
|
+
get container() {
|
|
46
|
+
return Container_cjs.container;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Per-piece listener that is called when the piece is loaded into the store.
|
|
50
|
+
* Useful to set-up asynchronous initialization tasks.
|
|
51
|
+
*/
|
|
52
|
+
onLoad() {
|
|
53
|
+
return void 0;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Per-piece listener that is called when the piece is unloaded from the store.
|
|
57
|
+
* Useful to set-up clean-up tasks.
|
|
58
|
+
*/
|
|
59
|
+
onUnload() {
|
|
60
|
+
return void 0;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Unloads and disables the piece.
|
|
64
|
+
*/
|
|
65
|
+
async unload() {
|
|
66
|
+
await this.store.unload(this.name);
|
|
67
|
+
this.enabled = false;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Reloads the piece by loading the same path in the store.
|
|
71
|
+
*/
|
|
72
|
+
async reload() {
|
|
73
|
+
await this.store.load(this.location.root, this.location.relative);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Defines the `JSON.stringify` behavior of this piece.
|
|
77
|
+
*/
|
|
78
|
+
toJSON() {
|
|
79
|
+
return {
|
|
80
|
+
location: this.location.toJSON(),
|
|
81
|
+
name: this.name,
|
|
82
|
+
enabled: this.enabled,
|
|
83
|
+
options: this.options
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
__name(_Piece, "Piece");
|
|
88
|
+
exports.Piece = _Piece;
|
|
89
|
+
((Piece2) => {
|
|
90
|
+
Piece2.Location = PieceLocation_cjs.PieceLocation;
|
|
91
|
+
})(exports.Piece || (exports.Piece = {}));
|
|
92
|
+
//# sourceMappingURL=out.js.map
|
|
93
|
+
//# sourceMappingURL=Piece.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/Piece.ts"],"names":["Piece"],"mappings":";;;;;;;;;AACA,SAAS,iBAAiC;AAC1C,SAAS,qBAA6C;AAqD/C,IAAM,SAAN,MAAM,OAA0G;AAAA,EA0B/G,YAAY,SAAyC,UAAwB,CAAC,GAAG;AAtBxF;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAO;AAKP;AAAA;AAAA;AAAA,wBAAgB;AAGf,SAAK,QAAQ,QAAQ;AACrB,SAAK,WAAW,IAAI,cAAc,QAAQ,MAAM,QAAQ,IAAI;AAC5D,SAAK,OAAO,QAAQ,QAAQ,QAAQ;AACpC,SAAK,UAAU,QAAQ,WAAW;AAClC,SAAK,UAAU;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAW,YAAuB;AACjC,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,SAA6B;AACnC,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,WAA+B;AACrC,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAKA,MAAa,SAAS;AACrB,UAAM,KAAK,MAAM,OAAO,KAAK,IAAI;AACjC,SAAK,UAAU;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAa,SAAS;AACrB,UAAM,KAAK,MAAM,KAAK,KAAK,SAAS,MAAM,KAAK,SAAS,QAAQ;AAAA,EACjE;AAAA;AAAA;AAAA;AAAA,EAKO,SAAoB;AAC1B,WAAO;AAAA,MACN,UAAU,KAAK,SAAS,OAAO;AAAA,MAC/B,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,SAAS,KAAK;AAAA,IACf;AAAA,EACD;AACD;AApFuH;AAAhH,IAAM,QAAN;AAAA,CAgGA,CAAUA,WAAV;AACC,EAAMA,OAAA,WAAW;AAAA,GADR","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"]}
|