skynet-mysky-utils
Version:
Skynet common MySky utilities
85 lines • 3.17 kB
JavaScript
;
exports.__esModule = true;
exports.permTypeToString = exports.permCategoryToString = exports.PermType = exports.PermWrite = exports.PermRead = exports.PermCategory = exports.PermLegacySkyID = exports.PermHidden = exports.PermDiscoverable = exports.Permission = void 0;
var Permission = /** @class */ (function () {
function Permission(requestor, path, category, permType) {
this.requestor = requestor;
this.path = path;
this.category = category;
this.permType = permType;
if (typeof category !== "number" || !(category in PermCategory)) {
throw new Error("Invalid 'category' enum value ".concat(category));
}
if (typeof permType !== "number" || !(permType in PermType)) {
throw new Error("Invalid 'permType' enum value ".concat(permType));
}
}
return Permission;
}());
exports.Permission = Permission;
// Define category constants for non-TS users.
exports.PermDiscoverable = 1;
exports.PermHidden = 2;
exports.PermLegacySkyID = 3;
/**
* Defines what type of file is being requested. Discoverable files are visible
* to the entire world, hidden files are only visible to the user (unless
* shared), and LegacySkyID files are supported files from the legacy SkyID
* login system.
*/
var PermCategory;
(function (PermCategory) {
PermCategory[PermCategory["Discoverable"] = exports.PermDiscoverable] = "Discoverable";
PermCategory[PermCategory["Hidden"] = exports.PermHidden] = "Hidden";
PermCategory[PermCategory["LegacySkyID"] = exports.PermLegacySkyID] = "LegacySkyID";
})(PermCategory = exports.PermCategory || (exports.PermCategory = {}));
// Define type constants for non-TS users.
exports.PermRead = 4;
exports.PermWrite = 5;
var PermType;
(function (PermType) {
PermType[PermType["Read"] = exports.PermRead] = "Read";
PermType[PermType["Write"] = exports.PermWrite] = "Write";
})(PermType = exports.PermType || (exports.PermType = {}));
/**
* Converts the given permission category to a human-readable string.
*
* @param category - The given category.
* @returns - The string.
* @throws - Will throw if the category is not valid.
*/
function permCategoryToString(category) {
if (category === PermCategory.Discoverable) {
return "Discoverable";
}
else if (category === PermCategory.Hidden) {
return "Hidden";
}
else if (category === PermCategory.LegacySkyID) {
return "LegacySkyID";
}
else {
throw new Error("Invalid permission category ".concat(category));
}
}
exports.permCategoryToString = permCategoryToString;
/**
* Converts the given permission type to a human-readable string.
*
* @param permType - The given type.
* @returns - The string.
* @throws - Will throw if the type is not valid.
*/
function permTypeToString(permType) {
if (permType === PermType.Read) {
return "Read";
}
else if (permType === PermType.Write) {
return "Write";
}
else {
throw new Error("Invalid permission type ".concat(permType));
}
}
exports.permTypeToString = permTypeToString;
//# sourceMappingURL=permissions.js.map