From 1ba2f507bd2fc4351608701c95ece2fbc06f479f Mon Sep 17 00:00:00 2001 From: saltie2193 Date: Tue, 29 Nov 2022 21:55:23 +0100 Subject: [PATCH] Update distributed files --- dist/DataResponse.d.ts | 47 +++++++++++++++------------- dist/DataResponse.js | 71 ++++++++++++++++++++++-------------------- dist/FileManager.d.ts | 14 ++++----- dist/FileManager.js | 14 ++++----- 4 files changed, 76 insertions(+), 70 deletions(-) diff --git a/dist/DataResponse.d.ts b/dist/DataResponse.d.ts index 386e284..f053b7d 100644 --- a/dist/DataResponse.d.ts +++ b/dist/DataResponse.d.ts @@ -12,27 +12,22 @@ interface DataResponseInterface { succeeded: () => boolean; msg?: string; } +/** + * _Convenient data status handling_ + */ declare class DataResponse implements DataResponseInterface { data: T; status: DataStatus; msg?: string; /** * Creates new {@link DataResponse} from an old instance with new {@link DataStatus}. - * Data and message will be coppied from the old instance to the new instance. + * Data and message will be copied from the old instance to the new instance. * * @param {DataResponse} resp - Old {@link DataResponse} instance. * @param {DataStatus} status - New {@link DataStatus} to use. * @returns {DataResponse} New {@link DataResponse} instance. */ static fromDataResponse(resp: DataResponse, status: DataStatus): DataResponse; - constructor(data: T, status?: DataStatus, msg?: string); - succeeded(): boolean; - /** - * Checks if the {@link DataResponse} is empty. - * If the field `data` is `null` or `undefined` the object is an instance of {@link EmptyResponse}. - * Otherwise its an instance of {@link DataResponse}. - */ - isEmpty(): this is DataResponse; /** * Creates a new EmptyResponse without data, with given status and msg. * If a message is provided it will be logged as a warning. @@ -43,13 +38,12 @@ declare class DataResponse implements DataResponseInterface { */ static empty(status?: DataStatus, msg?: string): EmptyResponse; /** - * Creates a new {@link DataResponse} with status {@link DataStatus.OK}. + * Creates new {@link EmptyResponse} with {@link DataStatus.NOT_FOUND}. * - * @param data - Data of the created {@link DataResponse}. - * @param {string} msg - Message of the created {@link DataResponse}. - * @returns {DataResponse} New {@link DataResponse}. + * @param {string} msg - Message of the created {@link EmptyResponse}. + * @returns {EmptyResponse} New {@link EmptyResponse}. */ - static ok(data: T, msg?: string): DataResponse; + static notFound(msg?: string): EmptyResponse; /** * Creates new {@link EmptyResponse} with {@link DataStatus.Error}. * @@ -58,19 +52,20 @@ declare class DataResponse implements DataResponseInterface { */ static error(msg?: string): EmptyResponse; /** - * Creates new {@link EmptyResponse} with {@link DataStatus.NOT_FOUND}. + * Creates new {@link EmptyResponse} with {@link DataStatus.API_ERROR}. * - * @param {string} msg - Messag of the created {@link EmptyResponse}. + * @param {string} msg - Message of the created {@link EmptyResponse}. * @returns {EmptyResponse} New {@link EmptyResponse}. */ - static notFound(msg?: string): EmptyResponse; + static apiError(msg?: string): EmptyResponse; /** - * Creates new {@link EmptyResponse} with {@link DataStatus.API_ERROR}. + * Creates a new {@link DataResponse} with status {@link DataStatus.OK}. * - * @param {string} msg - Messag of the created {@link EmptyResponse}. - * @returns {EmptyResponse} New {@link EmptyResponse}. + * @param data - Data of the created {@link DataResponse}. + * @param {string} msg - Message of the created {@link DataResponse}. + * @returns {DataResponse} New {@link DataResponse}. */ - static apiError(msg?: string): EmptyResponse; + static ok(data: T, msg?: string): DataResponse; /** * Creates new {@link DataResponse} with status {@link DataStatus.CACHED}. * If the passed data is already a {@link DataResponse} a new {@link DataResponse} will be created. @@ -80,8 +75,16 @@ declare class DataResponse implements DataResponseInterface { * @returns */ static cached(data: T): DataResponse; + constructor(data: T, status?: DataStatus, msg?: string); + succeeded(): boolean; + /** + * Checks if the {@link DataResponse} is empty. + * If the field `data` is `null` or `undefined` the object is an instance of {@link EmptyResponse}. + * Otherwise its an instance of {@link DataResponse}. + */ + isEmpty(): this is DataResponse; /** - * Check if given {@link DataStatus} is interpreted as a successfull response. + * Check if given {@link DataStatus} is interpreted as a successful response. * @param {DataStatus} status * @returns {boolean} */ diff --git a/dist/DataResponse.js b/dist/DataResponse.js index 8824423..dfd3012 100644 --- a/dist/DataResponse.js +++ b/dist/DataResponse.js @@ -7,13 +7,16 @@ var DataStatus; DataStatus["NOT_FOUND"] = "not found"; DataStatus["API_ERROR"] = "api error"; })(DataStatus || (DataStatus = {})); +/** + * _Convenient data status handling_ + */ class DataResponse { data; status; msg; /** * Creates new {@link DataResponse} from an old instance with new {@link DataStatus}. - * Data and message will be coppied from the old instance to the new instance. + * Data and message will be copied from the old instance to the new instance. * * @param {DataResponse} resp - Old {@link DataResponse} instance. * @param {DataStatus} status - New {@link DataStatus} to use. @@ -22,23 +25,6 @@ class DataResponse { static fromDataResponse(resp, status) { return new DataResponse(resp.data, status, resp.msg); } - constructor(data, status = DataStatus.OK, msg) { - this.data = data; - this.status = status; - if (msg) - this.msg = msg; - } - succeeded() { - return DataResponse.isSuccess(this.status); - } - /** - * Checks if the {@link DataResponse} is empty. - * If the field `data` is `null` or `undefined` the object is an instance of {@link EmptyResponse}. - * Otherwise its an instance of {@link DataResponse}. - */ - isEmpty() { - return DataResponse.isEmpty(this); - } /** * Creates a new EmptyResponse without data, with given status and msg. * If a message is provided it will be logged as a warning. @@ -53,14 +39,13 @@ class DataResponse { return new DataResponse(null, status, msg); } /** - * Creates a new {@link DataResponse} with status {@link DataStatus.OK}. + * Creates new {@link EmptyResponse} with {@link DataStatus.NOT_FOUND}. * - * @param data - Data of the created {@link DataResponse}. - * @param {string} msg - Message of the created {@link DataResponse}. - * @returns {DataResponse} New {@link DataResponse}. + * @param {string} msg - Message of the created {@link EmptyResponse}. + * @returns {EmptyResponse} New {@link EmptyResponse}. */ - static ok(data, msg) { - return new DataResponse(data, DataStatus.OK, msg); + static notFound(msg) { + return DataResponse.empty(DataStatus.NOT_FOUND, msg); } /** * Creates new {@link EmptyResponse} with {@link DataStatus.Error}. @@ -72,22 +57,23 @@ class DataResponse { return DataResponse.empty(DataStatus.ERROR, msg); } /** - * Creates new {@link EmptyResponse} with {@link DataStatus.NOT_FOUND}. + * Creates new {@link EmptyResponse} with {@link DataStatus.API_ERROR}. * - * @param {string} msg - Messag of the created {@link EmptyResponse}. + * @param {string} msg - Message of the created {@link EmptyResponse}. * @returns {EmptyResponse} New {@link EmptyResponse}. */ - static notFound(msg) { - return DataResponse.empty(DataStatus.NOT_FOUND, msg); + static apiError(msg) { + return DataResponse.empty(DataStatus.API_ERROR, msg); } /** - * Creates new {@link EmptyResponse} with {@link DataStatus.API_ERROR}. + * Creates a new {@link DataResponse} with status {@link DataStatus.OK}. * - * @param {string} msg - Messag of the created {@link EmptyResponse}. - * @returns {EmptyResponse} New {@link EmptyResponse}. + * @param data - Data of the created {@link DataResponse}. + * @param {string} msg - Message of the created {@link DataResponse}. + * @returns {DataResponse} New {@link DataResponse}. */ - static apiError(msg) { - return DataResponse.empty(DataStatus.API_ERROR, msg); + static ok(data, msg) { + return new DataResponse(data, DataStatus.OK, msg); } /** * Creates new {@link DataResponse} with status {@link DataStatus.CACHED}. @@ -103,8 +89,25 @@ class DataResponse { } return new DataResponse(data, DataStatus.CACHED); } + constructor(data, status = DataStatus.OK, msg) { + this.data = data; + this.status = status; + if (msg) + this.msg = msg; + } + succeeded() { + return DataResponse.isSuccess(this.status); + } + /** + * Checks if the {@link DataResponse} is empty. + * If the field `data` is `null` or `undefined` the object is an instance of {@link EmptyResponse}. + * Otherwise its an instance of {@link DataResponse}. + */ + isEmpty() { + return DataResponse.isEmpty(this); + } /** - * Check if given {@link DataStatus} is interpreted as a successfull response. + * Check if given {@link DataStatus} is interpreted as a successful response. * @param {DataStatus} status * @returns {boolean} */ diff --git a/dist/FileManager.d.ts b/dist/FileManager.d.ts index e35e7ed..8a3ffe9 100644 --- a/dist/FileManager.d.ts +++ b/dist/FileManager.d.ts @@ -61,7 +61,7 @@ declare class NewFileManager implements FileManager { * 2. Checks if the given file is stored in the iCloud and downloads it if necessary. * 3. Uses the given function to read the file and returns the result. * - * @param {string} filePath - Path to file, relative to the basedor of the {@link NewFileManager}. + * @param {string} filePath - Path to file, relative to the basedir of the {@link NewFileManager}. * @param {(path: string) => T} fn - Function to read the given file. * @returns {DataResponse} */ @@ -133,7 +133,7 @@ declare class NewFileManager implements FileManager { * Note that it is always safe to call `downloadFileFromiCloud(filePath)`, even if the file is stored locally on the device. * * @param filePath - Path of the file to read, relatively to the basedir of the {@link NewFileManager}. - * @param autoExtension - Automatcally add '.json' extension to the file path. + * @param autoExtension - Wether to automatically add '.json' extension to the file path. * @returns */ readJSON(filePath: string, autoExtension?: boolean): Record | unknown[] | number | string | null; @@ -147,7 +147,7 @@ declare class NewFileManager implements FileManager { * If the file does not exists or downloading fails, an {@link EmptyResponse} will be returned. * * @param filePath - Path of the file to read, relatively to the basedir of the {@link NewFileManager}. - * @param autoExtension - Automatcally add '.json' extension to the file path. + * @param autoExtension - Wether to automatically add '.json' extension to the file path. * @returns */ readJSONS(filePath: string, autoExtension?: boolean): Promise | unknown[] | number | string | null>>; @@ -161,10 +161,10 @@ declare class NewFileManager implements FileManager { * Use `fileExists(filePath)` to check if a file exists and `downloadFileFromiCloud(filePath)` to download the file. * Note that it is always safe to call `downloadFileFromiCloud(filePath)`, even if the file is stored locally on the device. * - * If the content of the file is not a JSON dictonary `null` will be returned. + * If the content of the file is not a JSON dictionary `null` will be returned. * * @param filePath - Path of the file to read, relatively to the basedir of the {@link NewFileManager}. - * @param autoExtension - Automatcally add '.json' extension to the file path. + * @param autoExtension - Wether to automatically add '.json' extension to the file path. * @returns */ readJSONDict(filePath: string, autoExtension?: boolean): Record | null; @@ -180,7 +180,7 @@ declare class NewFileManager implements FileManager { * If the content of the file cannot be read as a JSON dictionary an {@link EmptyResponse} will be returned. * * @param filePath - Path of the file to read, relatively to the basedir of the {@link NewFileManager}. - * @param autoExtension - Automatcally add '.json' extension to the file path. + * @param autoExtension - Wether to automatically add '.json' extension to the file path. * @returns A {@link DataResponse} containing the content of the file as {@link Record}. An {@link EmptyResponse} if the file does not exist or the content cannot be read as JSON dictionary. */ readJSONDictS(filePath: string, autoExtension?: boolean): Promise>>; @@ -220,7 +220,7 @@ declare class NewFileManager implements FileManager { * * Writes the content to the specified file path on disk. * If the file does not already exist, it will be created. - * If the file already exists the contents of the file will beoverwritten with the new content. + * If the file already exists the contents of the file will be overwritten with the new content. * @param filePath - Path of file to write to, relative to the basedir of the {@link NewFileManager}. * @param content - Content to write to disk, relative to the basedir of the {@link NewFileManager}. */ diff --git a/dist/FileManager.js b/dist/FileManager.js index 66fd48a..786dbfc 100644 --- a/dist/FileManager.js +++ b/dist/FileManager.js @@ -177,7 +177,7 @@ class NewFileManager { * 2. Checks if the given file is stored in the iCloud and downloads it if necessary. * 3. Uses the given function to read the file and returns the result. * - * @param {string} filePath - Path to file, relative to the basedor of the {@link NewFileManager}. + * @param {string} filePath - Path to file, relative to the basedir of the {@link NewFileManager}. * @param {(path: string) => T} fn - Function to read the given file. * @returns {DataResponse} */ @@ -273,7 +273,7 @@ class NewFileManager { * Note that it is always safe to call `downloadFileFromiCloud(filePath)`, even if the file is stored locally on the device. * * @param filePath - Path of the file to read, relatively to the basedir of the {@link NewFileManager}. - * @param autoExtension - Automatcally add '.json' extension to the file path. + * @param autoExtension - Wether to automatically add '.json' extension to the file path. * @returns */ readJSON(filePath, autoExtension = true) { @@ -293,7 +293,7 @@ class NewFileManager { * If the file does not exists or downloading fails, an {@link EmptyResponse} will be returned. * * @param filePath - Path of the file to read, relatively to the basedir of the {@link NewFileManager}. - * @param autoExtension - Automatcally add '.json' extension to the file path. + * @param autoExtension - Wether to automatically add '.json' extension to the file path. * @returns */ async readJSONS(filePath, autoExtension = true) { @@ -315,10 +315,10 @@ class NewFileManager { * Use `fileExists(filePath)` to check if a file exists and `downloadFileFromiCloud(filePath)` to download the file. * Note that it is always safe to call `downloadFileFromiCloud(filePath)`, even if the file is stored locally on the device. * - * If the content of the file is not a JSON dictonary `null` will be returned. + * If the content of the file is not a JSON dictionary `null` will be returned. * * @param filePath - Path of the file to read, relatively to the basedir of the {@link NewFileManager}. - * @param autoExtension - Automatcally add '.json' extension to the file path. + * @param autoExtension - Wether to automatically add '.json' extension to the file path. * @returns */ readJSONDict(filePath, autoExtension = true) { @@ -341,7 +341,7 @@ class NewFileManager { * If the content of the file cannot be read as a JSON dictionary an {@link EmptyResponse} will be returned. * * @param filePath - Path of the file to read, relatively to the basedir of the {@link NewFileManager}. - * @param autoExtension - Automatcally add '.json' extension to the file path. + * @param autoExtension - Wether to automatically add '.json' extension to the file path. * @returns A {@link DataResponse} containing the content of the file as {@link Record}. An {@link EmptyResponse} if the file does not exist or the content cannot be read as JSON dictionary. */ async readJSONDictS(filePath, autoExtension = true) { @@ -399,7 +399,7 @@ class NewFileManager { * * Writes the content to the specified file path on disk. * If the file does not already exist, it will be created. - * If the file already exists the contents of the file will beoverwritten with the new content. + * If the file already exists the contents of the file will be overwritten with the new content. * @param filePath - Path of file to write to, relative to the basedir of the {@link NewFileManager}. * @param content - Content to write to disk, relative to the basedir of the {@link NewFileManager}. */