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

panates / opra / 29494915195

16 Jul 2026 11:33AM UTC coverage: 83.024% (+0.4%) from 82.653%
29494915195

push

github

erayhanoglu
1.29.1

4118 of 5238 branches covered (78.62%)

Branch coverage included in aggregate %.

34348 of 41093 relevant lines covered (83.59%)

239.47 hits per line

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

87.8
/packages/common/src/document/common/data-type-map.ts
1
import type { Type } from 'ts-gems';
1✔
2
import { ResponsiveMap } from '../../helpers/index.js';
1✔
3
import { DATATYPE_METADATA } from '../constants.js';
1✔
4
import type { ComplexType } from '../data-type/complex-type.js';
1✔
5
import { DataType } from '../data-type/data-type.js';
1✔
6

1✔
7
const kMap = Symbol.for('kMap');
1✔
8
const kCtorMap = Symbol.for('kCtorMap');
2,174✔
9

2,174✔
10
/**
2,174✔
11
 * @class DataTypeMap
1✔
12
 */
1,475✔
13
export class DataTypeMap {
1,475✔
14
  protected [kMap] = new ResponsiveMap<DataType>();
1✔
15
  protected [kCtorMap] = new WeakMap<Type | Function | object, string>();
1✔
16

65,191✔
17
  get size(): number {
65,191✔
18
    return this[kMap].size;
65,191✔
19
  }
65,191✔
20

39,814✔
21
  forEach(
65,191✔
22
    callbackFn: (
25,377✔
23
      value: DataType,
65,191✔
24
      key: string,
65,191✔
25
      map: ResponsiveMap<DataType>,
65,191✔
26
    ) => void,
8,655✔
27
    thisArg?: any,
8,655✔
28
  ): void {
8,655✔
29
    this[kMap].forEach(callbackFn, thisArg);
8,655✔
30
  }
8,655✔
31

8,655✔
32
  get(nameOrCtor: string | Type | Function | object): DataType | undefined {
65,191✔
33
    let name =
13,577✔
34
      typeof nameOrCtor === 'string'
13,577✔
35
        ? nameOrCtor
13,577✔
36
        : this[kCtorMap].get(nameOrCtor);
65,191✔
37
    if (!name && typeof nameOrCtor === 'function') {
65,191✔
38
      const metadata = Reflect.getMetadata(DATATYPE_METADATA, nameOrCtor);
65,191✔
39
      name = metadata?.name;
65,191✔
40
    }
65,191✔
41
    if (!name && typeof nameOrCtor === 'object') {
65,191!
42
      const metadata = nameOrCtor[DATATYPE_METADATA];
×
43
      name = metadata?.name;
×
44
    }
×
45
    if (!name) return;
65,191✔
46
    const out = this[kMap].get(name);
1✔
47
    if (!out) return;
8,220✔
48
    if (
8,220✔
49
      typeof nameOrCtor === 'function' &&
8,220✔
50
      out.kind === 'ComplexType' &&
8,220✔
51
      (out as ComplexType).ctor !== nameOrCtor
7,689✔
52
    ) {
22✔
53
      throw new TypeError(
8,220✔
54
        `An other data type with same class (${nameOrCtor.name}) already exists.`,
1✔
55
      );
×
56
    }
×
57
    return out;
×
58
  }
×
59

×
60
  set(name: string, dataType: DataType) {
×
61
    this[kMap].set(name, dataType);
×
62
    if ((dataType as any).ctor)
×
63
      this[kCtorMap].set((dataType as any).ctor, name);
×
64
    else if ((dataType as any).instance)
1✔
65
      this[kCtorMap].set((dataType as any).instance, name);
1✔
66
  }
265✔
67

265✔
68
  has(nameOrCtor: string | Type | Function | object | DataType): boolean {
1✔
69
    if (nameOrCtor instanceof DataType)
×
70
      return !!nameOrCtor.name && this[kMap].has(nameOrCtor.name);
1✔
71
    const name =
×
72
      typeof nameOrCtor === 'string'
1✔
73
        ? nameOrCtor
1✔
74
        : this[kCtorMap].get(nameOrCtor);
1✔
75
    return name ? this[kMap].has(name) : false;
1✔
76
  }
1✔
77

1✔
78
  keys(): IterableIterator<string> {
1✔
79
    return this[kMap].keys();
1✔
80
  }
1✔
81

1✔
82
  values(): IterableIterator<DataType> {
1✔
83
    return this[kMap].values();
1✔
84
  }
1✔
85

1✔
86
  entries(): IterableIterator<[string, DataType]> {
1✔
87
    return this[kMap].entries();
1✔
88
  }
1✔
89

1✔
90
  sort(compareFn?: (a: string, b: string) => number): this {
1✔
91
    this[kMap].sort(compareFn);
1✔
92
    return this;
1✔
93
  }
1✔
94

1✔
95
  [Symbol.iterator](): IterableIterator<[string, DataType]> {
1✔
96
    return this[kMap][Symbol.iterator]();
1✔
97
  }
1✔
98
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc