Skip to content

Commit

Permalink
fix: Deep error (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
regevbr authored Sep 6, 2022
1 parent 559bd68 commit 9515b9b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "json-expression-eval",
"version": "5.1.0",
"version": "5.1.1",
"description": "json serializable rule engine / boolean expression evaluator",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
54 changes: 54 additions & 0 deletions src/test/types/deep.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {ResolvedConsequence, Rule} from '../../index';
import {expectType} from 'tsd';

type ExpressionFunction1 = {
user: (user: string, context: { userId: string }) => boolean;
}

type ExpressionFunction2 = {
user: (user: string, context: { userId: string }) => boolean;
}

type Context1 = {
timesCounter?: number;
userId: string,
nested: {
value2: number | undefined,
value: number | null,
},
}

type Context2 = {
timesCounter?: number;
userId: string,
nested: {
value2: number | undefined,
value: number | null,
},
}

type ConsequencePayload1 = {
a: number;
}

type ConsequencePayload2 = {
a: number;
}

type RuleFunctionsTable1 = {
rule1: () => void | ResolvedConsequence<ConsequencePayload1>
}

type RuleFunctionsTable2 = {
rule1: () => void | ResolvedConsequence<ConsequencePayload2>
}

type Rule1 = Rule<ConsequencePayload1, RuleFunctionsTable1, Context1, ExpressionFunction1, Date>;
type Rule2 = Rule<ConsequencePayload2, RuleFunctionsTable2, Context2, ExpressionFunction2, Date>;

declare const rule1: Rule1;
declare const rule2: Rule2;
declare const fn: (rule: Rule1) => boolean;

expectType<boolean>(fn(rule1));
expectType<boolean>(fn(rule2));
1 change: 1 addition & 0 deletions src/test/types/evaluator.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ expectError(new ExpressionHandler<Context, ExpressionFunction>({userId: 5}, func
expectType<TestExpressionEval>(new ExpressionHandler<Context, ExpressionFunction>({userId: 'sdf'}, functions));
expectError(new ExpressionHandler<Context, ExpressionFunction>({nested: {value: 5}}, functions));
expectError(new ExpressionHandler<Context, ExpressionFunction>({'nested.value': 'sdf'}, functions));
expectError(new ExpressionHandler<Context, ExpressionFunction>({'nested.valu2e': 'sdf'}, functions));
expectType<TestExpressionEval>(new ExpressionHandler<Context, ExpressionFunction>({'nested.value': 5}, functions));
expectError(new ExpressionHandler<Context, ExpressionFunction>({timesCounter: {neq: 'sdf'}}, functions));
expectError(new ExpressionHandler<Context, ExpressionFunction>(
Expand Down
4 changes: 2 additions & 2 deletions src/types/evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {NonNullable} from './required';
export type FuncCompareOp<C extends Context, F extends FunctionsTable<C>, K extends keyof F> =
Awaited<Parameters<F[K]>[0]>;

export type StringPaths<O extends object, Ignore> =
String.Join<Paths<O, [], Ignore | any[], string>, '.'>;
export type StringPaths<O extends object, Ignore> = any extends O ?
never : (any extends Ignore ? never : String.Join<Paths<O, [], Ignore | any[], string>, '.'>);

export type Primitive = string | number | boolean;

Expand Down

0 comments on commit 9515b9b

Please sign in to comment.