major bug fixes & breaking change in database code
Major bug fixes and improvements have been made. There's also a breaking change for plugins using the database system. All database related functions are now async based.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
///////////////////////////////////////
|
||||
//DEFAULT DATABASE MODULE
|
||||
///////////////////////////////////////
|
||||
import { ODValidId, ODValidJsonType } from "../modules/base"
|
||||
import { ODOptionalPromise, ODValidId, ODValidJsonType } from "../modules/base"
|
||||
import { ODDatabaseManager, ODDatabase, ODFormattedJsonDatabase } from "../modules/database"
|
||||
import { ODTicketJson } from "../openticket/ticket"
|
||||
import { ODOptionJson } from "../openticket/option"
|
||||
@@ -65,38 +65,38 @@ export interface ODFormattedJsonDatabaseIds_DefaultGlobal {
|
||||
* This default class is made for the `global.json` database!
|
||||
*/
|
||||
export class ODFormattedJsonDatabase_DefaultGlobal extends ODFormattedJsonDatabase {
|
||||
set<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultGlobal>(category:CategoryId, key:string, value:ODFormattedJsonDatabaseIds_DefaultGlobal[CategoryId]): boolean
|
||||
set(category:string, key:string, value:ODValidJsonType): boolean
|
||||
set<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultGlobal>(category:CategoryId, key:string, value:ODFormattedJsonDatabaseIds_DefaultGlobal[CategoryId]): ODOptionalPromise<boolean>
|
||||
set(category:string, key:string, value:ODValidJsonType): ODOptionalPromise<boolean>
|
||||
|
||||
set(category:string, key:string, value:ODValidJsonType): boolean {
|
||||
set(category:string, key:string, value:ODValidJsonType): ODOptionalPromise<boolean> {
|
||||
return super.set(category,key,value)
|
||||
}
|
||||
|
||||
get<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultGlobal>(category:CategoryId, key:string): ODFormattedJsonDatabaseIds_DefaultGlobal[CategoryId]|undefined
|
||||
get(category:string, key:string): ODValidJsonType|undefined
|
||||
get<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultGlobal>(category:CategoryId, key:string): ODOptionalPromise<ODFormattedJsonDatabaseIds_DefaultGlobal[CategoryId]|undefined>
|
||||
get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined>
|
||||
|
||||
get(category:string, key:string): ODValidJsonType|undefined {
|
||||
get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined> {
|
||||
return super.get(category,key)
|
||||
}
|
||||
|
||||
delete<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultGlobal>(category:CategoryId, key:string): boolean
|
||||
delete(category:string, key:string): boolean
|
||||
delete<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultGlobal>(category:CategoryId, key:string): ODOptionalPromise<boolean>
|
||||
delete(category:string, key:string): ODOptionalPromise<boolean>
|
||||
|
||||
delete(category:string, key:string): boolean {
|
||||
delete(category:string, key:string): ODOptionalPromise<boolean> {
|
||||
return super.delete(category,key)
|
||||
}
|
||||
|
||||
exists(category:keyof ODFormattedJsonDatabaseIds_DefaultGlobal, key:string): boolean
|
||||
exists(category:string, key:string): boolean
|
||||
exists(category:keyof ODFormattedJsonDatabaseIds_DefaultGlobal, key:string): ODOptionalPromise<boolean>
|
||||
exists(category:string, key:string): ODOptionalPromise<boolean>
|
||||
|
||||
exists(category:string, key:string): boolean {
|
||||
exists(category:string, key:string): ODOptionalPromise<boolean> {
|
||||
return super.exists(category,key)
|
||||
}
|
||||
|
||||
getCategory<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultGlobal>(category:CategoryId): {key:string, value:ODFormattedJsonDatabaseIds_DefaultGlobal[CategoryId]}[]|undefined
|
||||
getCategory(category:string): {key:string, value:ODValidJsonType}[]|undefined
|
||||
getCategory<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultGlobal>(category:CategoryId): ODOptionalPromise<{key:string, value:ODFormattedJsonDatabaseIds_DefaultGlobal[CategoryId]}[]|undefined>
|
||||
getCategory(category:string): ODOptionalPromise<{key:string, value:ODValidJsonType}[]|undefined>
|
||||
|
||||
getCategory(category:string): {key:string, value:ODValidJsonType}[]|undefined {
|
||||
getCategory(category:string): ODOptionalPromise<{key:string, value:ODValidJsonType}[]|undefined> {
|
||||
return super.getCategory(category)
|
||||
}
|
||||
}
|
||||
@@ -116,38 +116,38 @@ export interface ODFormattedJsonDatabaseIds_DefaultTickets {
|
||||
* This default class is made for the `tickets.json` database!
|
||||
*/
|
||||
export class ODFormattedJsonDatabase_DefaultTickets extends ODFormattedJsonDatabase {
|
||||
set<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultTickets>(category:CategoryId, key:string, value:ODFormattedJsonDatabaseIds_DefaultTickets[CategoryId]): boolean
|
||||
set(category:string, key:string, value:ODValidJsonType): boolean
|
||||
set<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultTickets>(category:CategoryId, key:string, value:ODFormattedJsonDatabaseIds_DefaultTickets[CategoryId]): ODOptionalPromise<boolean>
|
||||
set(category:string, key:string, value:ODValidJsonType): ODOptionalPromise<boolean>
|
||||
|
||||
set(category:string, key:string, value:ODValidJsonType): boolean {
|
||||
set(category:string, key:string, value:ODValidJsonType): ODOptionalPromise<boolean> {
|
||||
return super.set(category,key,value)
|
||||
}
|
||||
|
||||
get<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultTickets>(category:CategoryId, key:string): ODFormattedJsonDatabaseIds_DefaultTickets[CategoryId]|undefined
|
||||
get(category:string, key:string): ODValidJsonType|undefined
|
||||
get<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultTickets>(category:CategoryId, key:string): ODOptionalPromise<ODFormattedJsonDatabaseIds_DefaultTickets[CategoryId]|undefined>
|
||||
get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined>
|
||||
|
||||
get(category:string, key:string): ODValidJsonType|undefined {
|
||||
get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined> {
|
||||
return super.get(category,key)
|
||||
}
|
||||
|
||||
delete<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultTickets>(category:CategoryId, key:string): boolean
|
||||
delete(category:string, key:string): boolean
|
||||
delete<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultTickets>(category:CategoryId, key:string): ODOptionalPromise<boolean>
|
||||
delete(category:string, key:string): ODOptionalPromise<boolean>
|
||||
|
||||
delete(category:string, key:string): boolean {
|
||||
delete(category:string, key:string): ODOptionalPromise<boolean> {
|
||||
return super.delete(category,key)
|
||||
}
|
||||
|
||||
exists(category:keyof ODFormattedJsonDatabaseIds_DefaultTickets, key:string): boolean
|
||||
exists(category:string, key:string): boolean
|
||||
exists(category:keyof ODFormattedJsonDatabaseIds_DefaultTickets, key:string): ODOptionalPromise<boolean>
|
||||
exists(category:string, key:string): ODOptionalPromise<boolean>
|
||||
|
||||
exists(category:string, key:string): boolean {
|
||||
exists(category:string, key:string): ODOptionalPromise<boolean> {
|
||||
return super.exists(category,key)
|
||||
}
|
||||
|
||||
getCategory<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultTickets>(category:CategoryId): {key:string, value:ODFormattedJsonDatabaseIds_DefaultTickets[CategoryId]}[]|undefined
|
||||
getCategory(category:string): {key:string, value:ODValidJsonType}[]|undefined
|
||||
getCategory<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultTickets>(category:CategoryId): ODOptionalPromise<{key:string, value:ODFormattedJsonDatabaseIds_DefaultTickets[CategoryId]}[]|undefined>
|
||||
getCategory(category:string): ODOptionalPromise<{key:string, value:ODValidJsonType}[]|undefined>
|
||||
|
||||
getCategory(category:string): {key:string, value:ODValidJsonType}[]|undefined {
|
||||
getCategory(category:string): ODOptionalPromise<{key:string, value:ODValidJsonType}[]|undefined> {
|
||||
return super.getCategory(category)
|
||||
}
|
||||
}
|
||||
@@ -167,38 +167,38 @@ export interface ODFormattedJsonDatabaseIds_DefaultUsers {
|
||||
* This default class is made for the `users.json` database!
|
||||
*/
|
||||
export class ODFormattedJsonDatabase_DefaultUsers extends ODFormattedJsonDatabase {
|
||||
set<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultUsers>(category:CategoryId, key:string, value:ODFormattedJsonDatabaseIds_DefaultUsers[CategoryId]): boolean
|
||||
set(category:string, key:string, value:ODValidJsonType): boolean
|
||||
set<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultUsers>(category:CategoryId, key:string, value:ODFormattedJsonDatabaseIds_DefaultUsers[CategoryId]): ODOptionalPromise<boolean>
|
||||
set(category:string, key:string, value:ODValidJsonType): ODOptionalPromise<boolean>
|
||||
|
||||
set(category:string, key:string, value:ODValidJsonType): boolean {
|
||||
set(category:string, key:string, value:ODValidJsonType): ODOptionalPromise<boolean> {
|
||||
return super.set(category,key,value)
|
||||
}
|
||||
|
||||
get<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultUsers>(category:CategoryId, key:string): ODFormattedJsonDatabaseIds_DefaultUsers[CategoryId]|undefined
|
||||
get(category:string, key:string): ODValidJsonType|undefined
|
||||
get<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultUsers>(category:CategoryId, key:string): ODOptionalPromise<ODFormattedJsonDatabaseIds_DefaultUsers[CategoryId]|undefined>
|
||||
get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined>
|
||||
|
||||
get(category:string, key:string): ODValidJsonType|undefined {
|
||||
get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined> {
|
||||
return super.get(category,key)
|
||||
}
|
||||
|
||||
delete<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultUsers>(category:CategoryId, key:string): boolean
|
||||
delete(category:string, key:string): boolean
|
||||
delete<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultUsers>(category:CategoryId, key:string): ODOptionalPromise<boolean>
|
||||
delete(category:string, key:string): ODOptionalPromise<boolean>
|
||||
|
||||
delete(category:string, key:string): boolean {
|
||||
delete(category:string, key:string): ODOptionalPromise<boolean> {
|
||||
return super.delete(category,key)
|
||||
}
|
||||
|
||||
exists(category:keyof ODFormattedJsonDatabaseIds_DefaultUsers, key:string): boolean
|
||||
exists(category:string, key:string): boolean
|
||||
exists(category:keyof ODFormattedJsonDatabaseIds_DefaultUsers, key:string): ODOptionalPromise<boolean>
|
||||
exists(category:string, key:string): ODOptionalPromise<boolean>
|
||||
|
||||
exists(category:string, key:string): boolean {
|
||||
exists(category:string, key:string): ODOptionalPromise<boolean> {
|
||||
return super.exists(category,key)
|
||||
}
|
||||
|
||||
getCategory<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultUsers>(category:CategoryId): {key:string, value:ODFormattedJsonDatabaseIds_DefaultUsers[CategoryId]}[]|undefined
|
||||
getCategory(category:string): {key:string, value:ODValidJsonType}[]|undefined
|
||||
getCategory<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultUsers>(category:CategoryId): ODOptionalPromise<{key:string, value:ODFormattedJsonDatabaseIds_DefaultUsers[CategoryId]}[]|undefined>
|
||||
getCategory(category:string): ODOptionalPromise<{key:string, value:ODValidJsonType}[]|undefined>
|
||||
|
||||
getCategory(category:string): {key:string, value:ODValidJsonType}[]|undefined {
|
||||
getCategory(category:string): ODOptionalPromise<{key:string, value:ODValidJsonType}[]|undefined> {
|
||||
return super.getCategory(category)
|
||||
}
|
||||
}
|
||||
@@ -219,38 +219,38 @@ export interface ODFormattedJsonDatabaseIds_DefaultOptions {
|
||||
* This default class is made for the `options.json` database!
|
||||
*/
|
||||
export class ODFormattedJsonDatabase_DefaultOptions extends ODFormattedJsonDatabase {
|
||||
set<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultOptions>(category:CategoryId, key:string, value:ODFormattedJsonDatabaseIds_DefaultOptions[CategoryId]): boolean
|
||||
set(category:string, key:string, value:ODValidJsonType): boolean
|
||||
set<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultOptions>(category:CategoryId, key:string, value:ODFormattedJsonDatabaseIds_DefaultOptions[CategoryId]): ODOptionalPromise<boolean>
|
||||
set(category:string, key:string, value:ODValidJsonType): ODOptionalPromise<boolean>
|
||||
|
||||
set(category:string, key:string, value:ODValidJsonType): boolean {
|
||||
set(category:string, key:string, value:ODValidJsonType): ODOptionalPromise<boolean> {
|
||||
return super.set(category,key,value)
|
||||
}
|
||||
|
||||
get<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultOptions>(category:CategoryId, key:string): ODFormattedJsonDatabaseIds_DefaultOptions[CategoryId]|undefined
|
||||
get(category:string, key:string): ODValidJsonType|undefined
|
||||
get<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultOptions>(category:CategoryId, key:string): ODOptionalPromise<ODFormattedJsonDatabaseIds_DefaultOptions[CategoryId]|undefined>
|
||||
get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined>
|
||||
|
||||
get(category:string, key:string): ODValidJsonType|undefined {
|
||||
get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined> {
|
||||
return super.get(category,key)
|
||||
}
|
||||
|
||||
delete<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultOptions>(category:CategoryId, key:string): boolean
|
||||
delete(category:string, key:string): boolean
|
||||
delete<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultOptions>(category:CategoryId, key:string): ODOptionalPromise<boolean>
|
||||
delete(category:string, key:string): ODOptionalPromise<boolean>
|
||||
|
||||
delete(category:string, key:string): boolean {
|
||||
delete(category:string, key:string): ODOptionalPromise<boolean> {
|
||||
return super.delete(category,key)
|
||||
}
|
||||
|
||||
exists(category:keyof ODFormattedJsonDatabaseIds_DefaultOptions, key:string): boolean
|
||||
exists(category:string, key:string): boolean
|
||||
exists(category:keyof ODFormattedJsonDatabaseIds_DefaultOptions, key:string): ODOptionalPromise<boolean>
|
||||
exists(category:string, key:string): ODOptionalPromise<boolean>
|
||||
|
||||
exists(category:string, key:string): boolean {
|
||||
exists(category:string, key:string): ODOptionalPromise<boolean> {
|
||||
return super.exists(category,key)
|
||||
}
|
||||
|
||||
getCategory<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultOptions>(category:CategoryId): {key:string, value:ODFormattedJsonDatabaseIds_DefaultOptions[CategoryId]}[]|undefined
|
||||
getCategory(category:string): {key:string, value:ODValidJsonType}[]|undefined
|
||||
getCategory<CategoryId extends keyof ODFormattedJsonDatabaseIds_DefaultOptions>(category:CategoryId): ODOptionalPromise<{key:string, value:ODFormattedJsonDatabaseIds_DefaultOptions[CategoryId]}[]|undefined>
|
||||
getCategory(category:string): ODOptionalPromise<{key:string, value:ODValidJsonType}[]|undefined>
|
||||
|
||||
getCategory(category:string): {key:string, value:ODValidJsonType}[]|undefined {
|
||||
getCategory(category:string): ODOptionalPromise<{key:string, value:ODValidJsonType}[]|undefined> {
|
||||
return super.getCategory(category)
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,12 @@ import { ODConsoleWarningMessage, ODDebugger } from "./console"
|
||||
*/
|
||||
export type ODPromiseVoid = void|Promise<void>
|
||||
|
||||
/**## ODOptionalPromise `type`
|
||||
* This is a simple type to represent a type as normal value or a promise value.
|
||||
*/
|
||||
export type ODOptionalPromise<T> = T|Promise<T>
|
||||
|
||||
|
||||
/**## ODValidButtonColor `type`
|
||||
* This is a collection of all the possible button colors.
|
||||
*/
|
||||
|
||||
@@ -391,9 +391,9 @@ export class ODDebugFileManager {
|
||||
writeText(text:string){
|
||||
this.#writeDebugFile(text)
|
||||
}
|
||||
/**Write a custom note to the debug file (starting with `[NODE]:`) */
|
||||
/**Write a custom note to the debug file (starting with `[NOTE]:`) */
|
||||
writeNote(text:string){
|
||||
this.#writeDebugFile("[NODE]: "+text)
|
||||
this.#writeDebugFile("[NOTE]: "+text)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
///////////////////////////////////////
|
||||
//DATABASE MODULE
|
||||
///////////////////////////////////////
|
||||
import { ODId, ODManager, ODManagerData, ODSystemError, ODValidId, ODValidJsonType } from "./base"
|
||||
import { ODId, ODManager, ODManagerData, ODOptionalPromise, ODSystemError, ODValidId, ODValidJsonType } from "./base"
|
||||
import fs from "fs"
|
||||
import nodepath from "path"
|
||||
import { ODDebugger } from "./console"
|
||||
@@ -87,27 +87,27 @@ export class ODDatabase extends ODManagerData {
|
||||
file: string = ""
|
||||
|
||||
/**Add/Overwrite a specific category & key in the database. Returns `true` when overwritten. */
|
||||
set(category:string, key:string, value:ODValidJsonType): boolean {
|
||||
set(category:string, key:string, value:ODValidJsonType): ODOptionalPromise<boolean> {
|
||||
return false
|
||||
}
|
||||
/**Get a specific category & key in the database */
|
||||
get(category:string, key:string): ODValidJsonType|undefined {
|
||||
get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined> {
|
||||
return undefined
|
||||
}
|
||||
/**Delete a specific category & key in the database */
|
||||
delete(category:string, key:string): boolean {
|
||||
delete(category:string, key:string): ODOptionalPromise<boolean> {
|
||||
return false
|
||||
}
|
||||
/**Check if a specific category & key exists in the database */
|
||||
exists(category:string, key:string): boolean {
|
||||
exists(category:string, key:string): ODOptionalPromise<boolean> {
|
||||
return false
|
||||
}
|
||||
/**Get a specific category in the database */
|
||||
getCategory(category:string): {key:string, value:ODValidJsonType}[]|undefined {
|
||||
getCategory(category:string): ODOptionalPromise<{key:string, value:ODValidJsonType}[]|undefined> {
|
||||
return undefined
|
||||
}
|
||||
/**Get all values in the database */
|
||||
getAll(): ODJsonDatabaseStructure {
|
||||
getAll(): ODOptionalPromise<ODJsonDatabaseStructure> {
|
||||
return []
|
||||
}
|
||||
}
|
||||
@@ -145,7 +145,7 @@ export class ODJsonDatabase extends ODDatabase {
|
||||
* const didOverwrite = database.setData("category","key","value") //value can be any of the valid types
|
||||
* //You need an ODJsonDatabase class named "database" for this example to work!
|
||||
*/
|
||||
set(category:string, key:string, value:ODValidJsonType): boolean {
|
||||
set(category:string, key:string, value:ODValidJsonType): ODOptionalPromise<boolean> {
|
||||
const currentList = this.#system.getData()
|
||||
const currentData = currentList.find((d) => (d.category === category) && (d.key === key))
|
||||
|
||||
@@ -164,7 +164,7 @@ export class ODJsonDatabase extends ODDatabase {
|
||||
* const data = database.getData("category","key") //data will be the value
|
||||
* //You need an ODJsonDatabase class named "database" for this example to work!
|
||||
*/
|
||||
get(category:string, key:string): ODValidJsonType|undefined {
|
||||
get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined> {
|
||||
const currentList = this.#system.getData()
|
||||
const tempresult = currentList.find((d) => (d.category === category) && (d.key === key))
|
||||
return tempresult ? tempresult.value : undefined
|
||||
@@ -174,7 +174,7 @@ export class ODJsonDatabase extends ODDatabase {
|
||||
* const didExist = database.deleteData("category","key") //delete this value
|
||||
* //You need an ODJsonDatabase class named "database" for this example to work!
|
||||
*/
|
||||
delete(category:string, key:string): boolean {
|
||||
delete(category:string, key:string): ODOptionalPromise<boolean> {
|
||||
const currentList = this.#system.getData()
|
||||
const currentData = currentList.find((d) => (d.category === category) && (d.key === key))
|
||||
if (currentData) currentList.splice(currentList.indexOf(currentData),1)
|
||||
@@ -183,19 +183,19 @@ export class ODJsonDatabase extends ODDatabase {
|
||||
return currentData ? true : false
|
||||
}
|
||||
/**Check if a value of `category` & `key` exists. Returns `false` when non-existent! */
|
||||
exists(category:string, key:string): boolean {
|
||||
exists(category:string, key:string): ODOptionalPromise<boolean> {
|
||||
const currentList = this.#system.getData()
|
||||
const tempresult = currentList.find((d) => (d.category === category) && (d.key === key))
|
||||
return tempresult ? true : false
|
||||
}
|
||||
/**Get all values in `category`. Returns `undefined` when non-existent! */
|
||||
getCategory(category:string): {key:string, value:ODValidJsonType}[]|undefined {
|
||||
getCategory(category:string): ODOptionalPromise<{key:string, value:ODValidJsonType}[]|undefined> {
|
||||
const currentList = this.#system.getData()
|
||||
const tempresult = currentList.filter((d) => (d.category === category))
|
||||
return tempresult ? tempresult.map((data) => {return {key:data.key,value:data.value}}) : undefined
|
||||
}
|
||||
/**Get all values in `category`. */
|
||||
getAll(): ODJsonDatabaseStructure {
|
||||
getAll(): ODOptionalPromise<ODJsonDatabaseStructure> {
|
||||
return this.#system.getData()
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ export class ODFormattedJsonDatabase extends ODDatabase {
|
||||
* const didOverwrite = database.setData("category","key","value") //value can be any of the valid types
|
||||
* //You need an ODFormattedJsonDatabase class named "database" for this example to work!
|
||||
*/
|
||||
set(category:string, key:string, value:ODValidJsonType): boolean {
|
||||
set(category:string, key:string, value:ODValidJsonType): ODOptionalPromise<boolean> {
|
||||
const currentList = this.#system.getData()
|
||||
const currentData = currentList.find((d) => (d.category === category) && (d.key === key))
|
||||
|
||||
@@ -268,7 +268,7 @@ export class ODFormattedJsonDatabase extends ODDatabase {
|
||||
* const data = database.getData("category","key") //data will be the value
|
||||
* //You need an ODFormattedJsonDatabase class named "database" for this example to work!
|
||||
*/
|
||||
get(category:string, key:string): ODValidJsonType|undefined {
|
||||
get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined> {
|
||||
const currentList = this.#system.getData()
|
||||
const tempresult = currentList.find((d) => (d.category === category) && (d.key === key))
|
||||
return tempresult ? tempresult.value : undefined
|
||||
@@ -278,7 +278,7 @@ export class ODFormattedJsonDatabase extends ODDatabase {
|
||||
* const didExist = database.deleteData("category","key") //delete this value
|
||||
* //You need an ODFormattedJsonDatabase class named "database" for this example to work!
|
||||
*/
|
||||
delete(category:string, key:string): boolean {
|
||||
delete(category:string, key:string): ODOptionalPromise<boolean> {
|
||||
const currentList = this.#system.getData()
|
||||
const currentData = currentList.find((d) => (d.category === category) && (d.key === key))
|
||||
if (currentData) currentList.splice(currentList.indexOf(currentData),1)
|
||||
@@ -287,19 +287,19 @@ export class ODFormattedJsonDatabase extends ODDatabase {
|
||||
return currentData ? true : false
|
||||
}
|
||||
/**Check if a value of `category` & `key` exists. Returns `false` when non-existent! */
|
||||
exists(category:string, key:string): boolean {
|
||||
exists(category:string, key:string): ODOptionalPromise<boolean> {
|
||||
const currentList = this.#system.getData()
|
||||
const tempresult = currentList.find((d) => (d.category === category) && (d.key === key))
|
||||
return tempresult ? true : false
|
||||
}
|
||||
/**Get all values in `category`. Returns `undefined` when non-existent! */
|
||||
getCategory(category:string): {key:string, value:ODValidJsonType}[]|undefined {
|
||||
getCategory(category:string): ODOptionalPromise<{key:string, value:ODValidJsonType}[]|undefined> {
|
||||
const currentList = this.#system.getData()
|
||||
const tempresult = currentList.filter((d) => (d.category === category))
|
||||
return tempresult ? tempresult.map((data) => {return {key:data.key,value:data.value}}) : undefined
|
||||
}
|
||||
/**Get all values in `category`. */
|
||||
getAll(): ODJsonDatabaseStructure {
|
||||
getAll(): ODOptionalPromise<ODJsonDatabaseStructure> {
|
||||
return this.#system.getData()
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,9 @@ export class ODLanguage extends ODManagerData {
|
||||
file: string
|
||||
/**The path to the file relative to the main directory. */
|
||||
path: string
|
||||
/**The raw object data of the translation. */
|
||||
data: any
|
||||
/**The metadata of the language if available. */
|
||||
metadata: ODLanguageMetadata|null = null
|
||||
|
||||
constructor(id:ODValidId, file:string, customPath?:string){
|
||||
|
||||
@@ -42,13 +42,14 @@ export class ODStatsManager extends ODManager<ODStatScope> {
|
||||
|
||||
//filter out the deletable stats
|
||||
const deletableStats: ODJsonDatabaseStructure = []
|
||||
this.database.getAll().forEach((data) => {
|
||||
const data = await this.database.getAll()
|
||||
data.forEach((data) => {
|
||||
if (!validCategories.includes(data.category)) deletableStats.push(data)
|
||||
})
|
||||
|
||||
//do additional deletion
|
||||
for (const cb of this.#initListeners){
|
||||
await cb(this.database.getAll(),deletableStats)
|
||||
await cb(data,deletableStats)
|
||||
}
|
||||
|
||||
//delete all deletable stats
|
||||
@@ -57,9 +58,10 @@ export class ODStatsManager extends ODManager<ODStatScope> {
|
||||
this.database.delete(data.category,data.key)
|
||||
})
|
||||
}
|
||||
reset(){
|
||||
async reset(){
|
||||
if (!this.database) return
|
||||
this.database.getAll().forEach((data) => {
|
||||
const data = await this.database.getAll()
|
||||
data.forEach((data) => {
|
||||
if (!this.database) return
|
||||
this.database.delete(data.category,data.key)
|
||||
})
|
||||
|
||||
@@ -87,7 +87,7 @@ interface ODUtilities {
|
||||
*/
|
||||
emojiTitle(emoji:string, text:string): string
|
||||
/**## runAsync `utility function`
|
||||
* Use this function to run a piece of code asyncronous without creating a separate function for it!
|
||||
* Use this function to run a snippet of code asyncronous without creating a separate function for it!
|
||||
*/
|
||||
runAsync(func:() => Promise<void>): void
|
||||
/**## timedAwait `utility function`
|
||||
|
||||
@@ -4,7 +4,7 @@ export const loadVersionMigrationSystem = async () => {
|
||||
//ENTER MIGRATION CONTEXT
|
||||
await preloadMigrationContext()
|
||||
|
||||
const lastVersion = isMigrationRequired()
|
||||
const lastVersion = await isMigrationRequired()
|
||||
openticket.versions.add(lastVersion ? lastVersion : api.ODVersion.fromString("openticket:last-version",openticket.versions.get("openticket:version").toString()))
|
||||
if (lastVersion && !openticket.flags.get("openticket:no-migration").value){
|
||||
//MIGRATION IS REQUIRED
|
||||
@@ -48,8 +48,8 @@ const unloadMigrationContext = async () => {
|
||||
openticket.debug.debug("-- MIGRATION CONTEXT END --")
|
||||
}
|
||||
|
||||
const isMigrationRequired = (): false|api.ODVersion => {
|
||||
const rawVersion = openticket.databases.get("openticket:global").get("openticket:last-version","openticket:version")
|
||||
const isMigrationRequired = async (): Promise<false|api.ODVersion> => {
|
||||
const rawVersion = await openticket.databases.get("openticket:global").get("openticket:last-version","openticket:version")
|
||||
if (!rawVersion) return false
|
||||
const version = api.ODVersion.fromString("openticket:last-version",rawVersion)
|
||||
if (openticket.versions.get("openticket:version").compare(version) == "higher"){
|
||||
|
||||
Reference in New Issue
Block a user