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

oprajs / opra / 20427546580

22 Dec 2025 09:22AM UTC coverage: 81.893% (-0.5%) from 82.354%
20427546580

push

github

erayhanoglu
1.22.0

3707 of 4777 branches covered (77.6%)

Branch coverage included in aggregate %.

31787 of 38565 relevant lines covered (82.42%)

251.82 hits per line

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

97.35
/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 { 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';
1✔
10
import { DATATYPE_METADATA, DECORATOR } from '../constants.js';
1✔
11
import type { ComplexType } from './complex-type.js';
1✔
12
import { DataType } from './data-type.js';
1✔
13
import { EnumType } from './enum-type.js';
1✔
14
import type { MappedType } from './mapped-type.js';
1✔
15
import type { MixinType } from './mixin-type.js';
1✔
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
 */
1✔
22
export namespace ArrayType {
1✔
23
  export interface Metadata extends Combine<
1✔
24
    {
1✔
25
      kind: OpraSchema.ArrayType.Kind;
1✔
26
      name?: string;
1✔
27
      type: Type;
1✔
28
    },
1✔
29
    DataType.Metadata,
1✔
30
    OpraSchema.ArrayType
1✔
31
  > {}
1✔
32

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

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

1✔
56
/**
1✔
57
 * Type definition for ArrayType
1✔
58
 * @class ArrayType
1✔
59
 */
1✔
60
export interface ArrayTypeStatic {
1✔
61
  /**
1✔
62
   * Class constructor of ArrayType
1✔
63
   *
1✔
64
   * @param owner
1✔
65
   * @param args
1✔
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
  (
1✔
74
    type: string | Type | EnumType.EnumObject,
1✔
75
    options?: ArrayType.Options,
1✔
76
  ): Type;
1✔
77

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

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

1✔
87
/**
1✔
88
 * @class ArrayType
1✔
89
 */
1✔
90
export const ArrayType = function (this: ArrayType, ...args: any[]) {
1✔
91
  // ArrayType factory
24✔
92
  if (!this) {
24✔
93
    return ArrayType[DECORATOR].apply(undefined, args);
8✔
94
  }
8✔
95
  // Constructor
16✔
96
  const [owner, initArgs, context] = args as [
16✔
97
    DocumentElement,
16✔
98
    ArrayType.InitArguments,
16✔
99
    DocumentInitContext | undefined,
16✔
100
  ];
16✔
101
  DataType.call(this, owner, initArgs, context);
16✔
102
  const _this = asMutable(this);
16✔
103
  _this.kind = OpraSchema.ArrayType.Kind;
16✔
104
  _this.type = initArgs.type;
16✔
105
  _this.minOccurs = initArgs.minOccurs;
16✔
106
  _this.maxOccurs = initArgs.maxOccurs;
16✔
107
} as ArrayTypeStatic;
16✔
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);
19✔
128
    const typeName = this.node.getDataTypeNameWithNs(this.type);
19✔
129
    return omitUndefined<OpraSchema.ArrayType>({
19✔
130
      ...superJson,
19✔
131
      kind: this.kind as any,
19✔
132
      type: typeName ? typeName : this.type.toJSON(options),
19✔
133
      minOccurs: this.minOccurs,
19✔
134
      maxOccurs: this.maxOccurs,
19✔
135
    });
19✔
136
  }
19✔
137

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

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

1✔
156
  protected _locateBase(): ArrayType | undefined {
1✔
157
    return;
19✔
158
  }
19✔
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 {
8✔
168
  class ArrayClass {}
8✔
169

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