File size: 661 Bytes
d9494a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { isDefined } from '@/utils';
import { type BaseOutputSchemaV2 } from '@/workflow/workflow-schema/types/base-output-schema.type';
import { isBoolean, isObject } from 'class-validator';

export const isBaseOutputSchemaV2 = (
  value: unknown,
): value is BaseOutputSchemaV2 => {
  if (!isDefined(value) || !isObject(value) || Array.isArray(value)) {
    return false;
  }

  const entries = Object.values(value as Record<string, unknown>);

  if (entries.length === 0) {
    return false;
  }

  return entries.every(
    (entry) =>
      isDefined(entry) &&
      isObject(entry) &&
      isBoolean((entry as Record<string, unknown>)['isLeaf']),
  );
};