• 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

88.27
/packages/common/src/document/data-type/data-type.ts
1
import { omitUndefined } from '@jsopen/objects';
1✔
2
import { asMutable, type StrictOmit, type Type } from 'ts-gems';
1✔
3
import type { ValidationOptions, Validator } from 'valgen';
1✔
4
import { FieldsProjection } from '../../helpers/index.js';
1✔
5
import type { DataTypeBase } from '../../schema/data-type/data-type.interface.js';
1✔
6
import { OpraSchema } from '../../schema/index.js';
1✔
7
import type { ApiDocument } from '../api-document.js';
1✔
8
import { DocumentElement } from '../common/document-element.js';
1✔
9
import { DocumentInitContext } from '../common/document-init-context.js';
4,947!
10
import { CLASS_NAME_PATTERN } from '../constants.js';
×
11
import {
4,947✔
12
  colorFgMagenta,
4,947✔
13
  colorFgYellow,
4,110✔
14
  colorReset,
4,110✔
15
  nodeInspectCustom,
4,947!
16
} from '../utils/inspect.util.js';
×
17
import { testScopeMatch } from '../utils/test-scope-match.js';
4,947✔
18
import type { ApiField } from './api-field.js';
4,947✔
19

4,947✔
20
/**
4,947✔
21
 * @namespace DataType
4,947✔
22
 */
4,947✔
23
export namespace DataType {
4,947✔
24
  export interface Metadata extends DataTypeBase {
4,947✔
25
    name?: string;
8!
26
    scopePattern?: (string | RegExp) | (string | RegExp)[];
4,947✔
27
  }
4,939✔
28

4,939✔
29
  export interface Options extends Partial<
4,947✔
30
    StrictOmit<Metadata, 'kind' | 'examples'>
4,947✔
31
  > {
4,947✔
32
    embedded?: boolean;
4,947✔
33
  }
4,947✔
34

4,947✔
35
  export interface InitArguments extends DataType.Metadata {}
1✔
36

1✔
37
  export interface GenerateCodecOptions extends ValidationOptions {
1✔
38
    documentElement?: DocumentElement;
1✔
39
    scope?: string;
6✔
40
    caseInSensitive?: boolean;
1✔
41
    partial?: boolean | 'deep';
10,352✔
42
    projection?: string[] | FieldsProjection | '*';
1✔
43
    keepKeyFields?: boolean;
5,850✔
44
    ignoreReadonlyFields?: boolean;
5,850✔
45
    ignoreWriteonlyFields?: boolean;
5,850✔
46
    allowPatchOperators?: boolean;
5,850✔
47
    allowNullOptionals?: boolean;
5,850!
48
    fieldHook?: (
×
49
      field: ApiField,
×
50
      currentPath: string,
×
51
      defaultGenerator: () => Validator,
×
52
    ) => Validator;
×
53
  }
×
54
}
×
55

×
56
interface DataTypeStatic {
×
57
  new (
×
58
    owner: DocumentElement,
5,850✔
59
    args?: DataType.InitArguments,
5,850✔
60
    context?: DocumentInitContext,
5,850✔
61
  ): DataType;
5,850✔
62

5,850✔
63
  prototype: DataType;
5,850✔
64
}
5,850✔
65

5,850✔
66
/**
5,850✔
67
 * Type definition of DataType prototype
5,850✔
68
 * @interface DataType
5,850✔
69
 */
1✔
70
export interface DataType extends DataTypeClass {}
1✔
71

4,110✔
72
/**
4,110✔
73
 * DataType constructor
4,110✔
74
 */
4,110✔
75
export const DataType = function (
1!
76
  this: DataType,
1✔
77
  owner: DocumentElement,
×
78
  initArgs: DataType.InitArguments,
×
79
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
×
80
  context?: DocumentInitContext,
×
81
) {
1✔
82
  if (!this)
1✔
83
    throw new TypeError('"this" should be passed to call class constructor');
1✔
84
  if (initArgs?.name && !CLASS_NAME_PATTERN.test(initArgs.name)) {
1✔
85
    throw new TypeError(`"${initArgs.name}" is not a valid DataType name`);
1✔
86
  }
1✔
87
  DocumentElement.call(this, owner);
1✔
88
  const _this = asMutable(this);
1✔
89
  _this.kind = initArgs.kind;
1✔
90
  _this.scopePattern = initArgs.scopePattern
1✔
91
    ? Array.isArray(initArgs.scopePattern)
1✔
92
      ? initArgs.scopePattern
1✔
93
      : [initArgs.scopePattern]
1✔
94
    : undefined;
1✔
95
  _this.name = initArgs.name;
1✔
96
  _this.description = initArgs.description;
1✔
97
  _this.abstract = initArgs.abstract;
1✔
98
  _this.examples = initArgs.examples;
1✔
99
} as Function as DataTypeStatic;
1✔
100

1✔
101
/**
1✔
102
 *
1✔
103
 * @class DataType
1✔
104
 */
1✔
105
abstract class DataTypeClass extends DocumentElement {
1✔
106
  declare readonly kind: OpraSchema.DataType.Kind;
1✔
107
  declare readonly owner: DocumentElement;
1✔
108
  declare readonly scopePattern?: (string | RegExp)[];
1✔
109
  declare readonly name?: string;
1✔
110
  declare readonly description?: string;
1✔
111
  declare readonly abstract?: boolean;
1✔
112
  declare readonly examples?: OpraSchema.DataTypeExample[];
1✔
113

1✔
114
  abstract generateCodec(
1✔
115
    codec: 'encode' | 'decode',
1✔
116
    options?: DataType.GenerateCodecOptions,
1✔
117
    properties?: any,
1✔
118
  ): Validator;
1✔
119

1✔
120
  get embedded(): any {
1✔
121
    return !this.name;
1✔
122
  }
1✔
123

1✔
124
  abstract extendsFrom(baseType: DataType | string | Type | object): boolean;
1✔
125

1✔
126
  inScope(scope?: string | '*'): boolean {
1✔
127
    return testScopeMatch(scope, this.scopePattern);
1✔
128
  }
1✔
129

1✔
130
  toJSON(options?: ApiDocument.ExportOptions): OpraSchema.DataType {
1✔
131
    /* Locate base model which is not available for given scope */
1✔
132
    const outOfScope = this._locateBase(dt => !dt.inScope(options?.scope));
1✔
133
    if (outOfScope) {
1✔
134
      const baseName = this.node.getDataTypeNameWithNs(outOfScope);
1✔
135
      throw new TypeError(
1✔
136
        `"${baseName}" model is not available for "${options?.scope || 'null'}" scope`,
1✔
137
      );
1✔
138
    }
1✔
139
    return omitUndefined({
1✔
140
      kind: this.kind,
1✔
141
      description: this.description,
1✔
142
      abstract: this.abstract,
1✔
143
      examples: this.examples,
1✔
144
    }) as OpraSchema.DataType;
1✔
145
  }
1✔
146

1✔
147
  toString(): string {
1✔
148
    return `[${Object.getPrototypeOf(this).constructor.name} ${this.name || '#Embedded'}]`;
1✔
149
  }
1✔
150

1✔
151
  protected abstract _locateBase(
1✔
152
    callback: (base: DataType) => boolean,
1✔
153
  ): DataType | undefined;
1✔
154

1✔
155
  [nodeInspectCustom](): string {
1✔
156
    return (
1✔
157
      `[${colorFgYellow + Object.getPrototypeOf(this).constructor.name + colorReset}` +
1✔
158
      ` ${colorFgMagenta + this.name + colorReset}]`
1✔
159
    );
1✔
160
  }
1✔
161
}
1✔
162

1✔
163
DataType.prototype = DataTypeClass.prototype;
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