From 5d61dfce68dc3c47339d46fa3c9ac4cf5876ef49 Mon Sep 17 00:00:00 2001 From: Neil <55785687+carkom@users.noreply.github.com> Date: Thu, 30 Nov 2023 18:27:51 +0000 Subject: [PATCH] Update rules API (#1987) * Update rules.ts * notes * Update packages/loot-core/src/server/accounts/rules.ts Co-authored-by: Matiss Janis Aboltins * Entity update * fix --------- Co-authored-by: Matiss Janis Aboltins --- packages/loot-core/src/server/accounts/rules.ts | 6 +++++- packages/loot-core/src/types/models/rule.d.ts | 14 +++++++++++++- upcoming-release-notes/1987.md | 6 ++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 upcoming-release-notes/1987.md diff --git a/packages/loot-core/src/server/accounts/rules.ts b/packages/loot-core/src/server/accounts/rules.ts index 71aab527001..846682f166a 100644 --- a/packages/loot-core/src/server/accounts/rules.ts +++ b/packages/loot-core/src/server/accounts/rules.ts @@ -12,6 +12,7 @@ import { import { sortNumbers, getApproxNumberThreshold } from '../../shared/rules'; import { recurConfigToRSchedule } from '../../shared/schedules'; import { fastSetMerge } from '../../shared/util'; +import { RuleConditionEntity } from '../../types/models'; import { RuleError } from '../errors'; import { Schedule as RSchedule } from '../util/rschedule'; @@ -637,9 +638,11 @@ export class RuleIndexer { } } -const OP_SCORES = { +const OP_SCORES: Record = { is: 10, + isNot: 10, oneOf: 9, + notOneOf: 9, isapprox: 5, isbetween: 5, gt: 1, @@ -647,6 +650,7 @@ const OP_SCORES = { lt: 1, lte: 1, contains: 0, + doesNotContain: 0, }; function computeScore(rule) { diff --git a/packages/loot-core/src/types/models/rule.d.ts b/packages/loot-core/src/types/models/rule.d.ts index fee3e047824..12549e05495 100644 --- a/packages/loot-core/src/types/models/rule.d.ts +++ b/packages/loot-core/src/types/models/rule.d.ts @@ -11,7 +11,19 @@ export interface RuleEntity { interface RuleConditionEntity { field: unknown; - op: unknown; + op: + | 'is' + | 'isNot' + | 'oneOf' + | 'notOneOf' + | 'isapprox' + | 'isbetween' + | 'gt' + | 'gte' + | 'lt' + | 'lte' + | 'contains' + | 'doesNotContain'; value: unknown; options?: unknown; conditionsOp?: unknown; diff --git a/upcoming-release-notes/1987.md b/upcoming-release-notes/1987.md new file mode 100644 index 00000000000..47fddc10e75 --- /dev/null +++ b/upcoming-release-notes/1987.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [carkom] +--- + +Fix rule ranker in API.