• 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.1
/packages/common/src/document/data-type/utils/create-mapped-class.ts
1
import type { Type } from 'ts-gems';
1✔
2
import {
1✔
3
  inheritPropertyInitializers,
1✔
4
  mergePrototype,
1✔
5
} from '../../../helpers/index.js';
1✔
6
import { OpraSchema } from '../../../schema/index.js';
1✔
7
import { DATATYPE_METADATA } from '../../constants.js';
1✔
8
import type { DataType } from '../data-type.js';
1✔
9
import { MappedType } from '../mapped-type.js';
1✔
10
import { getIsInheritedPredicateFn } from './get-is-inherited-predicate-fn.js';
25✔
11

25✔
12
export function createMappedClass(
25✔
13
  source: string | Type,
25✔
14
  config: any,
25✔
15
  options?: DataType.Options,
25✔
16
) {
4✔
17
  const isInheritedPredicate = getIsInheritedPredicateFn(
25✔
18
    config.pick as any,
25✔
19
    config.omit as any,
25✔
20
  );
21✔
21
  const sourceName =
25✔
22
    typeof source === 'string'
25✔
23
      ? source.charAt(0).toUpperCase() + source.substring(1)
25✔
24
      : source.name;
×
25
  const className = options?.name || sourceName + 'Mapped';
×
26
  const MappedClass = {
×
27
    [className]: class {
25✔
28
      constructor() {
25✔
29
        if (typeof source === 'function')
25✔
30
          inheritPropertyInitializers(this, source, isInheritedPredicate);
25✔
31
      }
25✔
32
    },
21✔
33
  }[className];
21✔
34

21✔
35
  if (typeof source === 'function')
21✔
36
    mergePrototype(MappedClass.prototype, source.prototype);
21!
37

×
38
  if (typeof source === 'function') {
×
39
    const m = Reflect.getOwnMetadata(
21✔
40
      DATATYPE_METADATA,
21✔
41
      source,
21!
42
    ) as OpraSchema.DataType;
21!
43
    if (!m)
×
44
      throw new TypeError(
21✔
45
        `Class "${source}" doesn't have datatype metadata information`,
21!
46
      );
×
47
    if (!(
×
48
      m.kind === OpraSchema.ComplexType.Kind ||
25✔
49
      m.kind === OpraSchema.MappedType.Kind ||
25✔
50
      m.kind === OpraSchema.MixinType.Kind
25✔
51
    )) {
25✔
52
      throw new TypeError(
25✔
53
        `Class "${source}" is not a ${OpraSchema.ComplexType.Kind}`,
25✔
54
      );
25✔
55
    }
6✔
56
  }
6✔
57

6✔
58
  const metadata: MappedType.Metadata = {
25✔
59
    ...options,
4✔
60
    kind: 'MappedType',
25✔
61
    base: source,
25✔
62
  };
25✔
63
  if (config.pick) metadata.pick = config.pick as any;
25✔
64
  if (config.omit) metadata.omit = config.omit as any;
25✔
65
  if (config.partial) metadata.partial = config.partial as any;
21✔
66
  if (config.required) metadata.required = config.required as any;
1✔
67
  Reflect.defineMetadata(DATATYPE_METADATA, metadata, MappedClass);
1✔
68

1✔
69
  if (typeof source === 'function') {
1✔
70
    MappedType._applyMixin(MappedClass, source, {
1✔
71
      ...config,
1✔
72
      isInheritedPredicate,
1✔
73
    });
1✔
74
  }
1✔
75
  return MappedClass as any;
1✔
76
}
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