@@ -84,23 +84,43 @@ export class Persistent<T extends PersistentContent>
8484
8585 /**
8686 * Determine whether the values are equal, can be used in {@link Condition}
87+ * @example
88+ * ```typescript
89+ * persis.equals("id", persis.get("player_id"));
90+ *
91+ * // or
92+ *
93+ * persis.equals("id", (ctx) => ctx.storable.getNamespace("player").get("player_id"));
94+ * ```
8795 */
88- public equals < K extends StringKeyOf < T > > ( key : K , value : T [ K ] | ( ( value : T [ K ] ) => T [ K ] ) ) : Lambda < boolean > {
89- return new Lambda ( ( { storable } ) => {
90- const namespace = storable . getNamespace < T > ( this . namespace ) ;
91- const evaluatedValue = typeof value === "function" ? value ( namespace . get < K > ( key ) ) : value ;
96+ public equals < K extends StringKeyOf < T > > ( key : K , value : T [ K ] | Lambda < T [ K ] > | LambdaHandler < T [ K ] > ) : Lambda < boolean > {
97+ return new Lambda ( ( ctx ) => {
98+ const namespace = ctx . storable . getNamespace < T > ( this . namespace ) ;
99+ const evaluatedValue = (
100+ Lambda . isLambda ( value ) || Lambda . isLambdaHandler ( value )
101+ ) ? Lambda . from ( value ) . evaluate ( ctx ) . value : value ;
92102
93103 return namespace . equals < K > ( key , evaluatedValue ) ;
94104 } ) ;
95105 }
96106
97107 /**
98108 * Determine whether the values aren't equal, can be used in {@link Condition}
109+ * @example
110+ * ```typescript
111+ * persis.notEquals("id", persis.get("player_id"));
112+ *
113+ * // or
114+ *
115+ * persis.notEquals("id", (ctx) => ctx.storable.getNamespace("player").get("player_id"));
116+ * ```
99117 */
100- public notEquals < K extends StringKeyOf < T > > ( key : K , value : T [ K ] | ( ( value : T [ K ] ) => T [ K ] ) ) : Lambda < boolean > {
101- return new Lambda ( ( { storable } ) => {
102- const namespace = storable . getNamespace < T > ( this . namespace ) ;
103- const evaluatedValue = typeof value === "function" ? value ( namespace . get < K > ( key ) ) : value ;
118+ public notEquals < K extends StringKeyOf < T > > ( key : K , value : T [ K ] | Lambda < T [ K ] > | LambdaHandler < T [ K ] > ) : Lambda < boolean > {
119+ return new Lambda ( ( ctx ) => {
120+ const namespace = ctx . storable . getNamespace < T > ( this . namespace ) ;
121+ const evaluatedValue = (
122+ Lambda . isLambda ( value ) || Lambda . isLambdaHandler ( value )
123+ ) ? Lambda . from ( value ) . evaluate ( ctx ) . value : value ;
104124
105125 return ! namespace . equals < K > ( key , evaluatedValue ) ;
106126 } ) ;
0 commit comments