Skip to content

Commit

Permalink
Remove const from enum Error
Browse files Browse the repository at this point in the history
  • Loading branch information
zigazajc007 committed Sep 4, 2024
1 parent 87af94e commit 6fc3c28
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 115 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rabbit-company/cloudky-api",
"version": "0.0.1",
"version": "0.0.2",
"exports": "./src/cloudky-api.ts",
"publish": {
"include": ["LICENSE", "README.md", "src/cloudky-api.ts", "src/errors.ts", "src/types.ts", "src/validate.ts"]
Expand Down
211 changes: 104 additions & 107 deletions module/cloudky-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,113 +2,6 @@ import Argon2id from '@rabbit-company/argon2id';
import Blake2b from '@rabbit-company/blake2b';
import PasswordEntropy from '@rabbit-company/password-entropy';

/**
* Enum representing various error codes used throughout the application.
* Each error code corresponds to a specific error message.
* @readonly
* @enum {number}
*/
declare const enum Error$1 {
/** Action was executed successfully. */
SUCCESS = 0,
/** Invalid API endpoint. */
INVALID_ENDPOINT = 404,
/** Bearer Token is missing in Authorization header. */
BEARER_TOKEN_MISSING = 1000,
/** Required data is missing from the request. */
REQUIRED_DATA_MISSING = 1001,
/** Registration is disabled on this server. */
REGISTRATION_DISABLED = 1002,
/** Invalid username format. */
INVALID_USERNAME_FORMAT = 1003,
/** Password is not hashed using Blake2b algorithm. */
PASSWORD_NOT_HASHED = 1004,
/** Invalid file name. */
INVALID_FILE_NAME = 1005,
/** Provided file is invalid. */
INVALID_FILE = 1006,
/** Username is already registered. */
USERNAME_ALREADY_REGISTERED = 1007,
/** Invalid API Secret Key in Bearer Token. */
INVALID_API_SECRET_KEY = 1008,
/** Provided email is invalid. */
INVALID_EMAIL = 1009,
/** File size exceeds the maximum limit of 50GB. */
MAX_FILE_SIZE_EXCEEDED = 1010,
/** Missing Authorization header with Username and Password. */
MISSING_AUTHORIZATION_HEADER = 1011,
/** Provided username is invalid. */
INVALID_USERNAME = 1012,
/** Provided password is invalid. */
INVALID_PASSWORD = 1013,
/** Password is incorrect. */
INCORRECT_PASSWORD = 1014,
/** Redis connection error. */
REDIS_CONNECTION_ERROR = 1015,
/** Provided token is invalid. */
INVALID_TOKEN = 1016,
/** Provided token is incorrect or expired. */
TOKEN_EXPIRED = 1017,
/** Missing username and token in Authorization header. */
MISSING_USERNAME_AND_TOKEN = 1018,
/** Provided account type is invalid. */
INVALID_ACCOUNT_TYPE = 1019,
/** Provided upload ID is invalid. */
INVALID_UPLOAD_ID = 1020,
/** Provided expiration timestamp is invalid. */
INVALID_EXPIRATION_TIMESTAMP = 1021,
/** Non-existent share link. */
NON_EXISTENT_SHARE_LINK = 1022,
/** Provided share link is invalid. */
INVALID_SHARE_LINK = 1023,
/** Provided OTP is invalid. */
INVALID_OTP = 1024,
/** Provided password is too weak. */
PASSWORD_TOO_WEAK = 1025,
/** Unknown error occurred. */
UNKNOWN_ERROR = 2000,
/** Server is unreachable. */
SERVER_UNREACHABLE = 5000,
/** Invalid response format received from server. */
INVALID_RESPONSE_FORMAT = 5001,
/** Insufficient permissions to perform this action. */
INSUFFICIENT_PERMISSIONS = 9999
}
/**
* Namespace containing error handling utilities.
* Provides methods to retrieve error details and format error responses in JSON.
* @namespace
*/
export declare namespace Errors {
/**
* A dictionary mapping error codes to their corresponding messages and HTTP status codes.
* @type {{ [key: number]: { message: string; httpCode: number } }}
*/
const list: {
[key: number]: {
message: string;
httpCode: number;
};
};
/**
* Retrieves the error details for a given error code.
* @param {Error} id - The error code to retrieve details for.
* @returns {{ message: string; httpCode: number }} An object containing the error message and HTTP status code.
*/
function get(id: Error$1): {
message: string;
httpCode: number;
};
/**
* Formats the error response as a JSON object.
* @param {Error} id - The error code to format.
* @returns {{ error: Error, info: string }} A JSON object containing the error code and message.
*/
function getJson(id: Error$1): {
error: Error$1;
info: string;
};
}
/**
* Represents a standard response structure with an error code and information message.
* @interface
Expand Down Expand Up @@ -239,6 +132,110 @@ export interface ShareLinkListResponse {
/** Array containing share link objects. */
links?: ShareLink[];
}
/**
* Enum representing various error codes used throughout the application.
* Each error code corresponds to a specific error message.
* @readonly
* @enum {number}
*/
declare enum Error$1 {
/** Action was executed successfully. */
SUCCESS = 0,
/** Invalid API endpoint. */
INVALID_ENDPOINT = 404,
/** Bearer Token is missing in Authorization header. */
BEARER_TOKEN_MISSING = 1000,
/** Required data is missing from the request. */
REQUIRED_DATA_MISSING = 1001,
/** Registration is disabled on this server. */
REGISTRATION_DISABLED = 1002,
/** Invalid username format. */
INVALID_USERNAME_FORMAT = 1003,
/** Password is not hashed using Blake2b algorithm. */
PASSWORD_NOT_HASHED = 1004,
/** Invalid file name. */
INVALID_FILE_NAME = 1005,
/** Provided file is invalid. */
INVALID_FILE = 1006,
/** Username is already registered. */
USERNAME_ALREADY_REGISTERED = 1007,
/** Invalid API Secret Key in Bearer Token. */
INVALID_API_SECRET_KEY = 1008,
/** Provided email is invalid. */
INVALID_EMAIL = 1009,
/** File size exceeds the maximum limit of 50GB. */
MAX_FILE_SIZE_EXCEEDED = 1010,
/** Missing Authorization header with Username and Password. */
MISSING_AUTHORIZATION_HEADER = 1011,
/** Provided username is invalid. */
INVALID_USERNAME = 1012,
/** Provided password is invalid. */
INVALID_PASSWORD = 1013,
/** Password is incorrect. */
INCORRECT_PASSWORD = 1014,
/** Redis connection error. */
REDIS_CONNECTION_ERROR = 1015,
/** Provided token is invalid. */
INVALID_TOKEN = 1016,
/** Provided token is incorrect or expired. */
TOKEN_EXPIRED = 1017,
/** Missing username and token in Authorization header. */
MISSING_USERNAME_AND_TOKEN = 1018,
/** Provided account type is invalid. */
INVALID_ACCOUNT_TYPE = 1019,
/** Provided upload ID is invalid. */
INVALID_UPLOAD_ID = 1020,
/** Provided expiration timestamp is invalid. */
INVALID_EXPIRATION_TIMESTAMP = 1021,
/** Non-existent share link. */
NON_EXISTENT_SHARE_LINK = 1022,
/** Provided share link is invalid. */
INVALID_SHARE_LINK = 1023,
/** Provided OTP is invalid. */
INVALID_OTP = 1024,
/** Provided password is too weak. */
PASSWORD_TOO_WEAK = 1025,
/** Unknown error occurred. */
UNKNOWN_ERROR = 2000,
/** Server is unreachable. */
SERVER_UNREACHABLE = 5000,
/** Invalid response format received from server. */
INVALID_RESPONSE_FORMAT = 5001,
/** Insufficient permissions to perform this action. */
INSUFFICIENT_PERMISSIONS = 9999
}
/**
* Namespace containing error handling utilities.
* Provides methods to retrieve error details and format error responses in JSON.
* @namespace
*/
export declare namespace Errors {
/**
* A dictionary mapping error codes to their corresponding messages and HTTP status codes.
* @type {{ [key: number]: { message: string; httpCode: number } }}
*/
const list: {
[key: number]: {
message: string;
httpCode: number;
};
};
/**
* Retrieves the error details for a given error code.
* @param {Error} id - The error code to retrieve details for.
* @returns {{ message: string; httpCode: number }} An object containing the error message and HTTP status code.
*/
function get(id: Error$1): {
message: string;
httpCode: number;
};
/**
* Formats the error response as a JSON object.
* @param {Error} id - The error code to format.
* @returns {StandardResponse} A JSON object containing the error code and message.
*/
function getJson(id: Error$1): StandardResponse;
}
/**
* The `Validate` namespace provides a collection of validation functions
* used to verify the correctness of various input data types, such as
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rabbit-company/cloudky-api",
"version": "0.0.1",
"version": "0.0.2",
"description": "API for Cloudky Server",
"main": "./module/cloudky-api.js",
"browser": "./module/cloudky-api.js",
Expand Down
2 changes: 1 addition & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { StandardResponse } from "./types";
* @readonly
* @enum {number}
*/
export const enum Error {
export enum Error {
/** Action was executed successfully. */
SUCCESS = 0,
/** Invalid API endpoint. */
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ document.getElementById("btn-sharelink-download")?.addEventListener("click", asy
const parts = filePath.value.split("/");
const fileName = parts[parts.length - 1];

let url = window.URL.createObjectURL(res);
let a = document.createElement("a");
const url = window.URL.createObjectURL(res);
const a = document.createElement("a");
a.href = url;
a.download = fileName;
document.body.appendChild(a);
Expand Down Expand Up @@ -117,8 +117,8 @@ document.getElementById("btn-file-download")?.addEventListener("click", async ()
const parts = filePath.value.split("/");
const fileName = parts[parts.length - 1];

let url = window.URL.createObjectURL(res);
let a = document.createElement("a");
const url = window.URL.createObjectURL(res);
const a = document.createElement("a");
a.href = url;
a.download = fileName;
document.body.appendChild(a);
Expand Down

0 comments on commit 6fc3c28

Please sign in to comment.