Skip to content

Commit

Permalink
feat(core): Work on sub-rule introspection
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbrg committed Oct 5, 2024
1 parent fb3e776 commit 9bdcfe3
Showing 1 changed file with 20 additions and 30 deletions.
50 changes: 20 additions & 30 deletions src/services/introspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ export class Introspector {
);
}

console.log(JSON.stringify(subRuleResults));
for (const subRule of subRuleResults) {
console.log(JSON.stringify(this.#flatten(subRule.parent)));
}

let results = this.#introspectRule<R>(rule);

// Construct a new rule from each sub-rule result
Expand All @@ -68,14 +63,15 @@ export class Introspector {
res.all.push(condition);
}

console.log(
JSON.stringify({
conditions: {
...res,
result: subRuleResult.subRule.result,
},
})
);
// console.log(
// `Rule ${subRuleResult.subRule.result}:`,
// JSON.stringify({
// conditions: {
// ...res,
// result: subRuleResult.subRule.result,
// },
// })
// );

results = results.concat(
this.#introspectRule<R>({
Expand Down Expand Up @@ -185,30 +181,24 @@ export class Introspector {
// If the node is a condition, recurse
if (this.#objectDiscovery.isCondition(node)) {
clone[type][i] = this.#removeSubRule(needle, node);
continue;
}

// If the node is a sub-rule
if (this.#objectDiscovery.isSubRule(node)) {
if (needle.result === 13) {
console.log(node.rule);
console.log("asdasda", this.existsIn(needle, node.rule.conditions));
}

if (!this.existsIn(needle, node.rule)) {
clone[type].splice(i, 1);
continue;
}

// Check if it is the sub-rule we are looking for
if (JSON.stringify(node.rule) === JSON.stringify(needle)) {
if (!this.existsIn(needle, node.rule.conditions)) {
clone[type].splice(i, 1);
continue;
}

// Otherwise, recurse into the sub-rule
clone[type][i].rule.conditions = clone[type][i].rule.conditions.map(
(c: Condition) => this.#removeSubRule(needle, c)
);
const conditions = this.#asArray(node.rule.conditions);
for (let j = 0; j < conditions.length; j++) {
clone[type][i].rule.conditions[j] = this.#removeSubRule(
needle,
conditions[j]
);
}
}
}

Expand Down Expand Up @@ -621,7 +611,7 @@ export class Introspector {
});

Logger.debug(
`Introspector: + new option to criteria range based on last root parent"`
`Introspector: + new option to criteria range based on last root parent`
);

entry.options.push(baseOption);
Expand Down Expand Up @@ -665,7 +655,7 @@ export class Introspector {
}

this.#steps.push({ parentType, currType, depth, option });
Logger.debug(`Introspector: + new option to criteria range"`);
Logger.debug(`Introspector: + new option to criteria range`);

entry.options.push(option);
return entry;
Expand Down

0 comments on commit 9bdcfe3

Please sign in to comment.