import { Actionable } from "../action/actionable"; import { BooleanValueKeyOf, StringKeyOf } from "../../../util/data"; import { Lambda } from "../elements/condition"; import { Word } from "../elements/character/word"; import { DynamicWord, DynamicWordResult } from "../elements/character/sentence"; import { LambdaHandler } from "../elements/type"; export declare class Persistent extends Actionable { constructor(namespace: string, defaultContent: T); /** * Create an action to set a value in the persistent storage for the given key * @chainable * @param key - The key to set the value for * @param value - The value to set * @returns A chainable persistent action */ set>(key: K, value: T[K]): ChainedPersistent; set>(key: K, handler: (value: T[K]) => T[K]): ChainedPersistent; /** * Create an action to assign a value to the persistent storage * @chainable * @param value - The value to assign * @returns A chainable persistent action */ assign(value: Partial | ((value: T) => Partial)): ChainedPersistent; /** * Determine whether the values are equal, can be used in {@link Condition} * @example * ```typescript * persis.equals("id", persis.get("player_id")); * * // or * * persis.equals("id", (ctx) => ctx.storable.getNamespace("player").get("player_id")); * ``` */ equals>(key: K, value: T[K] | Lambda | LambdaHandler): Lambda; /** * Determine whether the values aren't equal, can be used in {@link Condition} * @example * ```typescript * persis.notEquals("id", persis.get("player_id")); * * // or * * persis.notEquals("id", (ctx) => ctx.storable.getNamespace("player").get("player_id")); * ``` */ notEquals>(key: K, value: T[K] | Lambda | LambdaHandler): Lambda; /** * Determine whether the value is true, can be used in {@link Condition}. * @example * ```ts * Condition.If(persis.isTrue("flag"), [character.say("Flag is true")]); * ``` */ isTrue>>(key: K): Lambda; /** * Determine whether the value is false, can be used in {@link Condition} */ isFalse>>(key: K): Lambda; /** * Determine whether the value isn't null or undefined, can be used in {@link Condition} */ isNotNull>(key: K): Lambda; /** * Convert to a dynamic word * @example * ```typescript * character.say(["You have ", persis.toWord("gold"), " gold"]); * * // or * * character.say`You have ${persis.toWord("gold")} gold`; * ``` */ toWord>(key: K): Word; /** * Alias of {@link toWord} */ get>(key: K): Word; /** * Create a conditional word * * @example * ```typescript * character.say([ * "Your flag is ", * persis.conditional( * persis.isTrue("flag"), * "on", * "off" * ) * ]); * ``` */ conditional(condition: Lambda | LambdaHandler, ifTrue: DynamicWordResult, ifFalse: DynamicWordResult): Word; /** * Evaluate the JavaScript function and determine whether the result is true. * @example * ```ts * Condition.If(persis.evaluate("coin", (coin) => coin < 10), [ * character.say("You don't have enough coins!") * ]); * ``` */ evaluate>(key: K, fn: (value: T[K]) => boolean): Lambda; } /** * Only for internal use, don't use this class directly */ export declare class DynamicPersistent extends Persistent { }