export function assertValue()

in packages/sdk/src/Value.ts [24:54]


  export function assertValue(value: unknown): asserts value is Value {
    switch (typeof value) {
      case 'bigint':
      case 'symbol':
      case 'function':
        throw new TypeMismatchError('number | boolean | string | Struct | List', typeof value);
      case 'object':
        if (value === null) throw new TypeMismatchError('number | boolean | string | Struct | List', 'null');
        if (Array.isArray(value)) {
          if (value.length > 0) {
            const itemType = getType(value[0]);
            if (!LIST_ITEM_TYPES.has(itemType)) {
              throw new TypeMismatchError('number | boolean | string', itemType, [0]);
            }
            for (let i = 1; i < value.length; i++) {
              const type = getType(value[i]);
              if (type !== itemType) {
                throw new TypeMismatchError(itemType, type, [i]);
              }
            }
          }
        }
        for (const key in value) {
          if (Object.prototype.hasOwnProperty.call(value, key)) {
            TypeMismatchError.hoist(key, () => assertValue(value[key as keyof typeof value] as unknown));
          }
        }
        return;
      default: // no-op
    }
  }