ShtukbaseStandard
файл пакета→ .shtukbase/packages/owner/checks/provisional.ts

checks/provisional.ts

29 строк, 1.5 КБ.

Файл как есть в пакете: код и комментарии в нём не переводятся.

  1. // AUT-R01. A decision or a question marked `provisional: true` has `provisionalBasis` (why this answer) and
  2. // `waitsFor` (what answer it waits for). When `waitsFor` leads to a question that is already answered, the mark is
  3. // due to be removed or the decision redone.
  4. // The shared part is norms-core's (this package requires it), side by side in .shtukbase/packages/.
  5. import { type Head, address, main, records, status, values } from '../../norms-core/checks/pagelib.ts';
  6. const QUESTIONS = 'knowledge/questions';
  7. export const RULE = { id: 'aut-r01', title: 'A provisional decision with a basis and what it waits for' };
  8. export function check(): string[] {
  9. const questions = new Map<string, Head>();
  10. for (const [addr, head] of records(QUESTIONS)) questions.set(addr, head);
  11. const out: string[] = [];
  12. for (const folder of ['knowledge/decisions', QUESTIONS]) {
  13. for (const [addr, head] of records(folder)) {
  14. if (head.provisional !== true) continue;
  15. const miss = ['provisionalBasis', 'waitsFor'].filter((f) => !values(head[f]).length);
  16. if (miss.length) out.push(`${addr}: provisional, but ${miss.join(', ')} not filled`);
  17. for (const ref of values(head.waitsFor)) {
  18. const q = questions.get(address(ref));
  19. if (q !== undefined && status(q) === 'answered') out.push(`${addr}: the answer to ${address(ref)} has come — remove provisional or rework the decision`);
  20. }
  21. }
  22. }
  23. return out;
  24. }
  25. if (import.meta.main) main({ RULE, check });