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

visgl / loaders.gl / 20352515932

18 Dec 2025 09:56PM UTC coverage: 35.115% (-28.4%) from 63.485%
20352515932

push

github

web-flow
feat(loader-utils): Export is-type helpers (#3258)

1188 of 1998 branches covered (59.46%)

Branch coverage included in aggregate %.

147 of 211 new or added lines in 13 files covered. (69.67%)

30011 existing lines in 424 files now uncovered.

37457 of 108056 relevant lines covered (34.66%)

0.79 hits per line

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

26.36
/modules/schema-utils/src/lib/table/batch-builder/row-table-batch-aggregator.ts
1
// loaders.gl
1✔
2
// SPDX-License-Identifier: MIT
1✔
3
// Copyright (c) vis.gl contributors
1✔
4

1✔
5
import type {Schema, TableBatch} from '@loaders.gl/schema';
1✔
6
import {TableBatchAggregator, TableBatchOptions} from './table-batch-aggregator';
1✔
7
import {
1✔
8
  convertToArrayRow,
1✔
9
  convertToObjectRow,
1✔
10
  inferHeadersFromArrayRow,
1✔
11
  inferHeadersFromObjectRow
1✔
12
} from '../tables/row-utils';
1✔
13

1✔
14
const DEFAULT_ROW_COUNT = 100;
1✔
15

1✔
16
export class RowTableBatchAggregator implements TableBatchAggregator {
1✔
17
  schema: Schema | null;
1!
UNCOV
18
  options: TableBatchOptions;
×
UNCOV
19

×
UNCOV
20
  length: number = 0;
×
UNCOV
21
  objectRows: {[columnName: string]: unknown}[] | null = null;
×
UNCOV
22
  arrayRows: unknown[][] | null = null;
×
UNCOV
23
  cursor: number = 0;
×
UNCOV
24
  private _headers: string[] | null = null;
×
25

1✔
26
  constructor(schema: Schema | null, options: TableBatchOptions) {
1✔
UNCOV
27
    this.options = options;
×
UNCOV
28
    this.schema = schema;
×
UNCOV
29

×
UNCOV
30
    // schema is an array if there're no headers
×
UNCOV
31
    // object if there are headers
×
UNCOV
32
    if (schema) {
×
UNCOV
33
      this._headers = [];
×
UNCOV
34
      for (let i = 0; i < schema.fields.length; i++) {
×
UNCOV
35
        this._headers[i] = schema.fields[i].name;
×
UNCOV
36
      }
×
UNCOV
37
    }
×
UNCOV
38
  }
×
39

1✔
40
  rowCount(): number {
1✔
UNCOV
41
    return this.length;
×
UNCOV
42
  }
×
43

1✔
44
  addArrayRow(row: any[], cursor?: number): void {
1✔
UNCOV
45
    if (Number.isFinite(cursor)) {
×
46
      this.cursor = cursor as number;
×
47
    }
×
UNCOV
48

×
UNCOV
49
    // TODO - infer schema at a higher level, instead of hacking headers here?
×
UNCOV
50
    this._headers ||= inferHeadersFromArrayRow(row);
×
UNCOV
51

×
UNCOV
52
    // eslint-disable-next-line default-case
×
UNCOV
53
    switch (this.options.shape) {
×
UNCOV
54
      case 'object-row-table':
×
UNCOV
55
        const rowObject = convertToObjectRow(row, this._headers);
×
UNCOV
56
        this.addObjectRow(rowObject, cursor);
×
UNCOV
57
        break;
×
UNCOV
58
      case 'array-row-table':
×
UNCOV
59
        this.arrayRows = this.arrayRows || new Array(DEFAULT_ROW_COUNT);
×
UNCOV
60
        this.arrayRows[this.length] = row;
×
UNCOV
61
        this.length++;
×
UNCOV
62
        break;
×
UNCOV
63
    }
×
UNCOV
64
  }
×
65

1✔
66
  addObjectRow(row: {[columnName: string]: any}, cursor?: number): void {
1✔
UNCOV
67
    if (Number.isFinite(cursor)) {
×
68
      this.cursor = cursor as number;
×
69
    }
×
UNCOV
70

×
UNCOV
71
    // TODO - infer schema at a higher level, instead of hacking headers here?
×
UNCOV
72
    this._headers ||= inferHeadersFromObjectRow(row);
×
UNCOV
73

×
UNCOV
74
    // eslint-disable-next-line default-case
×
UNCOV
75
    switch (this.options.shape) {
×
UNCOV
76
      case 'array-row-table':
×
77
        const rowArray = convertToArrayRow(row, this._headers);
×
78
        this.addArrayRow(rowArray, cursor);
×
79
        break;
×
UNCOV
80
      case 'object-row-table':
×
UNCOV
81
        this.objectRows = this.objectRows || new Array(DEFAULT_ROW_COUNT);
×
UNCOV
82
        this.objectRows[this.length] = row;
×
UNCOV
83
        this.length++;
×
UNCOV
84
        break;
×
UNCOV
85
    }
×
UNCOV
86
  }
×
87

1✔
88
  getBatch(): TableBatch | null {
1✔
UNCOV
89
    let rows = this.arrayRows || this.objectRows;
×
UNCOV
90
    if (!rows) {
×
91
      return null;
×
92
    }
×
UNCOV
93

×
UNCOV
94
    rows = rows.slice(0, this.length);
×
UNCOV
95
    this.arrayRows = null;
×
UNCOV
96
    this.objectRows = null;
×
UNCOV
97

×
UNCOV
98
    return {
×
UNCOV
99
      shape: this.options.shape,
×
UNCOV
100
      batchType: 'data',
×
UNCOV
101
      data: rows,
×
UNCOV
102
      length: this.length,
×
UNCOV
103
      // @ts-expect-error we should infer a schema
×
UNCOV
104
      schema: this.schema,
×
UNCOV
105
      cursor: this.cursor
×
UNCOV
106
    };
×
UNCOV
107
  }
×
108
}
1✔
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