• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

plusnew / router / 14174454359

31 Mar 2025 02:48PM UTC coverage: 83.131% (-0.3%) from 83.428%
14174454359

push

github

plusgut
chore(equal): fix equal handling of some schemas

180 of 231 branches covered (77.92%)

Branch coverage included in aggregate %.

10 of 11 new or added lines in 4 files covered. (90.91%)

3 existing lines in 2 files now uncovered.

845 of 1002 relevant lines covered (84.33%)

29.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.39
/src/schema/enum.ts
1
import type { schema } from "../types";
1✔
2
import { propertyHandler } from "./util";
1✔
3

1✔
4
type IsAny<T, Then, Else> = (T extends never ? true : false) extends false
1✔
5
  ? Else
1✔
6
  : Then;
1✔
7

1✔
8
type Enumschema<T, U> = NoInfer<
1✔
9
  schema<
1✔
10
    T | (null extends U ? null : never),
1✔
11
    T | (U extends T ? null : never) | (U extends null ? null : never)
1✔
12
  >
1✔
13
>;
1✔
14

1✔
15
export default function <
1✔
16
  T extends { [key: string]: schema<any, any> | null },
1✔
17
  U extends null | undefined = undefined,
1✔
18
>(opt: {
1✔
19
  enumerations: T;
1✔
20
  default?: U;
1✔
21
}): Enumschema<
1✔
22
  {
1✔
23
    [PropertyName in keyof T]: {
1✔
24
      type: PropertyName;
1✔
25
      value:
1✔
26
        | (null extends T[PropertyName] ? null : never)
1✔
27
        | (T[PropertyName] extends schema<infer R, any> ? R : never);
1✔
28
    };
1✔
29
  }[keyof T],
1✔
30
  IsAny<U, undefined, U>
1✔
31
> {
1✔
32
  return {
1✔
33
    // eslint-disable-next-line require-yield
1✔
34
    fromUrl: function* (tokenizer, hasValues) {
1✔
35
      if (hasValues === false) {
1!
36
        if (opt?.default !== undefined) {
×
37
          return opt.default;
×
38
        }
×
39
        throw new Error("No default value provided");
×
40
      }
×
41
      const enumKind = tokenizer.eat({ type: "TEXT" });
1✔
42

1✔
43
      if (enumKind.value in opt.enumerations) {
1✔
44
        const enumOpt = opt.enumerations[enumKind.value];
1✔
45

1✔
46
        if (enumOpt === null) {
1!
47
          return {
×
48
            type: enumKind.value,
×
49
            value: null,
×
50
          } as any;
×
51
        }
×
52

1✔
53
        const propertyGenerator = propertyHandler(tokenizer, enumOpt);
1✔
54

1✔
55
        while (true) {
1✔
56
          const propertyResult = propertyGenerator.next(hasValues);
1✔
57

1✔
58
          if (propertyResult.done === true) {
1✔
59
            return {
1✔
60
              type: enumKind.value,
1✔
61
              value: propertyResult.value,
1✔
62
            };
1✔
63
          } else {
1!
64
            hasValues = yield;
×
65

×
66
            if (hasValues === false || tokenizer.lookahead(enumKind) === null) {
×
67
              const propertyResult = propertyGenerator.next(false);
×
68

×
69
              if (propertyResult.done === true) {
×
70
                return {
×
71
                  type: enumKind.value,
×
72
                  value: propertyResult.value,
×
73
                };
×
74
              } else {
×
75
                throw new Error(
×
76
                  "After null is given, generator has to be done",
×
77
                );
×
78
              }
×
79
            } else {
×
80
              tokenizer.eat(enumKind);
×
81
            }
×
82
          }
×
83
        }
1✔
84
      } else {
1!
85
        throw new Error(`Could not find enumeration ${enumKind.value}`);
×
86
      }
×
87
    },
1✔
88
    toUrl: function (enumValue) {
1✔
89
      if (enumValue === null) {
1!
90
        return null;
×
91
      }
×
92

1✔
93
      return {
1✔
94
        [enumValue.type]:
1✔
95
          opt.enumerations[enumValue.type]?.toUrl(enumValue.value) ?? null,
1!
96
      };
1✔
97
    },
1✔
98
    isEqual: function () {
1✔
NEW
99
      return false;
×
UNCOV
100
    },
×
101
    default: opt?.default,
1✔
102
  };
1✔
103
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc