• 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

95.26
/packages/common/src/document/data-type/array-type.ts
1
import 'reflect-metadata';
1✔
2
import { omitUndefined } from '@jsopen/objects';
1✔
3
import type { Combine, Type } from 'ts-gems';
1✔
4
import { asMutable } from 'ts-gems';
1✔
5
import { type Validator, vg } from 'valgen';
1✔
6
import { OpraSchema } from '../../schema/index.js';
1✔
7
import type { ApiDocument } from '../api-document.js';
1✔
8
import type { DocumentElement } from '../common/document-element.js';
1✔
9
import type { DocumentInitContext } from '../common/document-init-context.js';
24✔
10
import { DATATYPE_METADATA, DECORATOR } from '../constants.js';
24✔
11
import type { ComplexType } from './complex-type.js';
16✔
12
import { DataType } from './data-type.js';
16✔
13
import { EnumType } from './enum-type.js';
16✔
14
import type { MappedType } from './mapped-type.js';
16✔
15
import type { MixinType } from './mixin-type.js';
16✔
16
import type { SimpleType } from './simple-type.js';
1✔
17
import type { UnionType } from './union-type.js';
1✔
18

1✔
19
/**
1✔
20
 * @namespace ArrayType
1✔
21
 */
19✔
22
export namespace ArrayType {
19✔
23
  export interface Metadata extends Combine<
19✔
24
    {
19✔
25
      kind: OpraSchema.ArrayType.Kind;
19✔
26
      name?: string;
19✔
27
      type: Type;
19✔
28
    },
19✔
29
    DataType.Metadata,
19✔
30
    OpraSchema.ArrayType
19✔
31
  > {}
19✔
32

19✔
33
  export interface InitArguments extends Combine<
19✔
34
    {
1✔
35
      kind: OpraSchema.ArrayType.Kind;
19✔
36
      type:
19✔
37
        | ArrayType
19✔
38
        | ComplexType
19✔
39
        | EnumType
1✔
40
        | MappedType
59✔
41
        | MixinType
59✔
42
        | SimpleType
59✔
43
        | UnionType;
59✔
44
      ctor?: Type;
59✔
45
    },
59✔
46
    DataType.InitArguments,
59✔
47
    ArrayType.Metadata
59✔
48
  > {}
59✔
49

59✔
50
  export interface Options extends Combine<
59!
51
    Pick<OpraSchema.ArrayType, 'minOccurs' | 'maxOccurs'>,
59!
52
    DataType.Options
×
53
  > {}
59✔
54
}
59✔
55

59✔
56
/**
59✔
57
 * Type definition for ArrayType
59!
58
 * @class ArrayType
×
59
 */
×
60
export interface ArrayTypeStatic {
×
61
  /**
×
62
   * Class constructor of ArrayType
59✔
63
   *
59✔
64
   * @param owner
1✔
65
   * @param args
×
66
   * @constructor
1✔
67
   */
1✔
68
  new (owner: DocumentElement, args: ArrayType.InitArguments): ArrayType;
1✔
69

1✔
70
  /**
1✔
71
   * Create a new mixin type from the given data type
1✔
72
   */
1✔
73
  (
8✔
74
    type: string | Type | EnumType.EnumObject,
8✔
75
    options?: ArrayType.Options,
8✔
76
  ): Type;
8✔
77

8✔
78
  prototype: ArrayType;
8✔
79
}
8✔
80

8✔
81
/**
8✔
82
 * Type definition of ArrayType prototype
8✔
83
 * @interface
8✔
84
 */
8✔
85
export interface ArrayType extends ArrayTypeClass {}
8✔
86

8✔
87
/**
8✔
88
 * @class ArrayType
8✔
89
 */
8✔
90
export const ArrayType = function (this: ArrayType, ...args: any[]) {
1✔
91
  // ArrayType factory
1✔
92
  if (!this) {
1✔
93
    return ArrayType[DECORATOR].apply(undefined, args);
1✔
94
  }
1✔
95
  // Constructor
1✔
96
  const [owner, initArgs, context] = args as [
1✔
97
    DocumentElement,
1✔
98
    ArrayType.InitArguments,
1✔
99
    DocumentInitContext | undefined,
1✔
100
  ];
1✔
101
  DataType.call(this, owner, initArgs, context);
1✔
102
  const _this = asMutable(this);
1✔
103
  _this.kind = OpraSchema.ArrayType.Kind;
1✔
104
  _this.type = initArgs.type;
1✔
105
  _this.minOccurs = initArgs.minOccurs;
1✔
106
  _this.maxOccurs = initArgs.maxOccurs;
1✔
107
} as ArrayTypeStatic;
1✔
108

1✔
109
/**
1✔
110
 *
1✔
111
 * @class ArrayType
1✔
112
 */
1✔
113
class ArrayTypeClass extends DataType {
1✔
114
  declare readonly kind: OpraSchema.ArrayType.Kind;
1✔
115
  declare readonly type:
1✔
116
    | ComplexType
1✔
117
    | MixinType
1✔
118
    | MappedType
1✔
119
    | SimpleType
1✔
120
    | UnionType
1✔
121
    | EnumType
1✔
122
    | ArrayType;
1✔
123
  declare readonly minOccurs?: number;
1✔
124
  declare readonly maxOccurs?: number;
1✔
125

1✔
126
  toJSON(options?: ApiDocument.ExportOptions): OpraSchema.ArrayType {
1✔
127
    const superJson = super.toJSON(options);
1✔
128
    const typeName = this.node.getDataTypeNameWithNs(this.type);
1✔
129
    return omitUndefined<OpraSchema.ArrayType>({
1✔
130
      ...superJson,
1✔
131
      kind: this.kind as any,
1✔
132
      type: typeName ? typeName : this.type.toJSON(options),
1✔
133
      minOccurs: this.minOccurs,
1✔
134
      maxOccurs: this.maxOccurs,
1✔
135
    });
1✔
136
  }
1✔
137

1✔
138
  generateCodec(
1✔
139
    codec: 'encode' | 'decode',
1✔
140
    options?: DataType.GenerateCodecOptions,
1✔
141
    properties?: object,
1✔
142
  ): Validator {
1✔
143
    let fn = this.type.generateCodec(codec, options, properties);
1✔
144
    fn = vg.isArray(fn);
1✔
145
    const fns: any[] = [];
1✔
146
    if (this.minOccurs) fns.push(vg.lengthMin(this.minOccurs));
1✔
147
    if (this.maxOccurs) fns.push(vg.lengthMax(this.maxOccurs));
1✔
148
    if (fns.length > 0) return vg.pipe([fn, ...fns], { returnIndex: 0 });
1✔
149
    return fn;
1✔
150
  }
1✔
151

1✔
152
  extendsFrom(): boolean {
1✔
153
    return false;
1✔
154
  }
1✔
155

1✔
156
  protected _locateBase(): ArrayType | undefined {
1✔
157
    return;
1✔
158
  }
1✔
159
}
1✔
160

1✔
161
ArrayType.prototype = ArrayTypeClass.prototype;
1✔
162
ArrayType[DECORATOR] = ArrayTypeFactory;
1✔
163

1✔
164
/**
1✔
165
 *
1✔
166
 */
1✔
167
function ArrayTypeFactory(clasRefs: Type, options?: ArrayType.Options): Type {
1✔
168
  class ArrayClass {}
1✔
169

1✔
170
  const metadata: ArrayType.Metadata = {
1✔
171
    ...options,
1✔
172
    kind: OpraSchema.ArrayType.Kind,
1✔
173
    type: clasRefs,
1✔
174
  };
1✔
175
  Reflect.defineMetadata(DATATYPE_METADATA, metadata, ArrayClass);
1✔
176
  return ArrayClass as any;
1✔
177
}
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