dev 7 months ago
parent bde12d5988
commit d1586701a2

@ -1,15 +1,11 @@
import type {
Cat, Obj, Sec, Att,
Rule,
RuleAction,
RuleActionAttribute,
RuleActionDomain,
RuleActionValue,
RuleActionValidation,
RuleSet,
RelativePath,
DomainValueRef,
AttState,
AttEffectiveState,
EffectiveState,
EvaluationResult,

@ -196,7 +196,7 @@ function findAtt(cat: Cat, key: string): Att | undefined {
}
if (parts.length === 4) {
// ct:cat/ob:obj/sc:sec/at:x
// ct_cat/ob_obj/sc_sec/at_x
const obj = cat.objs.find(o => o.id === parts[1]);
const sec = obj?.secs.find(s => s.id === parts[2]);
return sec?.atts.find(a => a.id === parts[3]);

@ -1,4 +1,4 @@
import type {RelativePath} from "@/vcen/types/rule.ts";
import {type RelativePath, type RuleID, ruleIDPrefix} from "@/vcen/types/rule.ts";
import {JSON_LOGIC_PATH_SEPARATOR} from "@/jslg";
import {
type Att,
@ -17,13 +17,13 @@ import {
// IDS HELPERS
// ─────────────────────────────────────────────────────────────────────────────
export function MakeCatID (catId : string) : CatID { return `${catIDPrefix}_${catId}` as CatID; }
export function MakeObjID (objId : string) : ObjID { return `${objIDPrefix}_${objId}` as ObjID; }
export function MakeSecID (secId : string) : SecID { return `${secIDPrefix}_${secId}` as SecID; }
export function MakeAttID (attId : string) : AttID { return `${attIDPrefix}_${attId}` as AttID; }
export function MakeOptID (optId : string) : OptID { return `${optIDPrefix}_${optId}` as OptID; }
export function toCatID (catId : string) : CatID { return `${catIDPrefix}_${catId}` as CatID; }
export function toObjID (objId : string) : ObjID { return `${objIDPrefix}_${objId}` as ObjID; }
export function toSecID (secId : string) : SecID { return `${secIDPrefix}_${secId}` as SecID; }
export function toAttID (attId : string) : AttID { return `${attIDPrefix}_${attId}` as AttID; }
export function toOptID (optId : string) : OptID { return `${optIDPrefix}_${optId}` as OptID; }
export function toRuleID(ruleId: string) : RuleID { return `${ruleIDPrefix}_${ruleId}` as RuleID; }

@ -1,6 +1,7 @@
import { describe, it, expect } from 'vitest';
import {validateAttValue} from "@/vcen/validation.ts";
import type {OptID} from "@/vcen/types";
import {toOptID } from "@/vcen/node_util.ts";
// ─────────────────────────────────────────────────────────────────────────────
@ -270,15 +271,15 @@ describe('option / list', () => {
const domain = {
kind: 'option' as const,
mode: 'list' as const,
list: ['op:rojo', 'op:verde', 'op:azul'] as const as unknown as OptID[],
list: [toOptID('rojo'),toOptID('verde'),toOptID('azul')] as OptID[],
};
it('acepta OptID en lista', () => {
expect(validateAttValue({ domain, value: 'op:rojo' as unknown as OptID })).toEqual(valid);
expect(validateAttValue({ domain, value: toOptID('rojo') })).toEqual(valid);
});
it('rechaza OptID fuera de lista', () => {
expect(validateAttValue({ domain, value: 'op:negro' as unknown as OptID })).toEqual(invalid('VALUE_NOT_IN_LIST'));
expect(validateAttValue({ domain, value: toOptID('negro') })).toEqual(invalid('VALUE_NOT_IN_LIST'));
});
it('rechaza número como OptID', () => {
@ -290,12 +291,12 @@ describe('option / multiple', () => {
const domain = {
kind: 'option' as const,
mode: 'list' as const,
list: ['op:a', 'op:b', 'op:c'] as unknown as OptID[],
list: [toOptID('a'), toOptID('b'), toOptID('c')] as OptID[],
multiple: { min: 1, max: 2 },
};
it('acepta selección múltiple válida', () => {
expect(validateAttValue({ domain, value: ['op:a', 'op:b'] as unknown as OptID[] })).toEqual(valid);
expect(validateAttValue({ domain, value: [toOptID('a'),toOptID('b')] as OptID[] })).toEqual(valid);
});
it('rechaza selección vacía', () => {
@ -303,7 +304,7 @@ describe('option / multiple', () => {
});
it('rechaza más opciones del máximo', () => {
expect(validateAttValue({ domain, value: ['op:a', 'op:b', 'op:c'] as unknown as OptID[] })).toEqual(invalid('MULTIPLE_TOO_MANY'));
expect(validateAttValue({ domain, value: [toOptID('a'),toOptID ('b'), toOptID('c')] as unknown as OptID[] })).toEqual(invalid('MULTIPLE_TOO_MANY'));
});
});

@ -7,6 +7,7 @@ import {
} from '../engine';
import type { Att, Sec, Obj, Cat } from '../types';
import type { Rule } from '../types';
import {toRuleID} from "@/vcen/node_util.ts";
// ─────────────────────────────────────────────────────────────────────────────
// FIXTURES — builders minimalistas
@ -66,7 +67,7 @@ function makeCat(id: string, objs: Obj[], atts: Att[] = []): Cat {
function makeRule(id: string, condition: unknown, actions: Rule['actions'], priority = 10): Rule {
return {
id: `rl_${id}` as Rule['id'],
id: toRuleID(id),
priority,
condition: condition as Rule['condition'],
actions,

@ -10,6 +10,7 @@ import {
} from '../graph';
import type { Att, Sec, Obj, Cat } from '../types';
import type { Rule } from '../types';
import {toRuleID} from "@/vcen/node_util.ts";
// ─────────────────────────────────────────────────────────────────────────────
// FIXTURES
@ -37,7 +38,7 @@ function makeCat(id: string, objs: Obj[], atts: Att[] = []): Cat {
}
function makeRule(id: string, condition: unknown, actions: Rule['actions'], priority = 10): Rule {
return { id: `rl_${id}` as Rule['id'], priority, condition: condition as Rule['condition'], actions };
return { id: toRuleID(id), priority, condition: condition as Rule['condition'], actions };
}
// helpers para comparar AttPath como string en expects

@ -3,6 +3,7 @@ import { evaluateIncremental } from '../incremental';
import { evaluateCat } from '../engine';
import { buildDependencyGraph } from '../graph';
import type { Att, Sec, Obj, Cat, Rule } from '../types';
import {toRuleID} from "@/vcen/node_util.ts";
@ -27,7 +28,7 @@ function makeCat(id: string, objs: Obj[], atts: Att[] = []): Cat {
}
function makeRule(id: string, condition: unknown, actions: Rule['actions'], priority = 10): Rule {
return { id: `rl_${id}` as Rule['id'], priority, condition: condition as Rule['condition'], actions };
return { id: toRuleID(id), priority, condition: condition as Rule['condition'], actions };
}
function ap(...parts: string[]) { return parts as any; }

@ -1,6 +1,7 @@
import { describe, it, expect, vi } from 'vitest';
import { createSession } from '../session';
import type { Att, Sec, Obj, Cat , Rule } from '../types';
import {toRuleID} from "@/vcen/node_util.ts";
// ─────────────────────────────────────────────────────────────────────────────
// FIXTURES
@ -28,7 +29,7 @@ function makeCat(id: string, objs: Obj[], atts: Att[] = []): Cat {
}
function makeRule(id: string, condition: unknown, actions: Rule['actions'], priority = 10): Rule {
return { id: `rl_${id}` as Rule['id'], priority, condition: condition as Rule['condition'], actions };
return { id: toRuleID(id), priority, condition: condition as Rule['condition'], actions };
}
function ap(...parts: string[]) { return parts as any; }

@ -7,7 +7,10 @@ import type {JsonLogicValue} from "@/jslg";
// RULE ID
// ─────────────────────────────────────────────────────────────────────────────
export type RuleID = ID<'rl'>;
export const ruleIDPrefix = 'rl' as const;
export type RuleID = ID<typeof ruleIDPrefix>;
// ─────────────────────────────────────────────────────────────────────────────

Loading…
Cancel
Save

Powered by TurnKey Linux.