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

visgl / loaders.gl / 24477111963

15 Apr 2026 08:37PM UTC coverage: 56.493% (+0.1%) from 56.365%
24477111963

push

github

web-flow
chore: Rename Source to SourceLoader (#3386)

9899 of 18977 branches covered (52.16%)

Branch coverage included in aggregate %.

91 of 204 new or added lines in 27 files covered. (44.61%)

4 existing lines in 2 files now uncovered.

20408 of 34670 relevant lines covered (58.86%)

4998.6 hits per line

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

56.0
/modules/core/src/lib/api/create-data-source.ts
1
// loaders.gl
2
// SPDX-License-Identifier: MIT
3
// Copyright (c) vis.gl contributors
4

5
import {
6
  SourceLoader,
7
  SourceArrayOptionsType,
8
  SourceArrayDataSourceType
9
} from '@loaders.gl/loader-utils';
10
import {coreApi} from './core-api';
11
import {selectLoaderSync} from './select-loader';
12

13
/**
14
 * Creates a source from a service
15
 * If type is not supplied, will try to automatically detect the the
16
 * @param url URL to the data source
17
 * @param type type of source. if not known, set to 'auto'
18
 * @returns an DataSource instance
19
 */
20
// DataSourceOptionsT extends DataSourceOptions = DataSourceOptions,
21
// DataSourceT extends DataSource = DataSource
22
export function createDataSource<SourceArrayT extends SourceLoader[]>(
23
  data: unknown,
24
  sources: Readonly<SourceArrayT>,
25
  options: Readonly<SourceArrayOptionsType<SourceArrayT>>
26
): SourceArrayDataSourceType<SourceArrayT> {
27
  const resolvedOptions = (options || {}) as SourceArrayOptionsType<SourceArrayT>;
20!
28
  const type = resolvedOptions?.core?.type || (resolvedOptions.type as unknown as string) || 'auto';
20✔
29
  const source =
30
    sources.length === 1
20✔
31
      ? sources[0]
32
      : type === 'auto'
4!
33
        ? (selectLoaderSync(data as never, sources as unknown as SourceLoader[], {
34
            // `createDataSource` supports non-fetch inputs such as in-memory tables.
35
            // Selection remains best-effort for those cases.
36
            ...resolvedOptions,
37
            core: {...resolvedOptions?.core, type: 'auto'}
38
          }) as SourceArrayT[number] | null)
39
        : getSourceOfType(type, sources);
40

41
  if (!source) {
20!
42
    throw new Error('Not a valid source type');
×
43
  }
44
  return source.createDataSource(data as string | Blob, resolvedOptions, coreApi);
20✔
45
}
46

47
/** Guess service type from URL */
48
function getSourceOfType(type: string, sources: Readonly<SourceLoader[]>): SourceLoader | null {
UNCOV
49
  for (const service of sources) {
×
UNCOV
50
    if (service.type === type) {
×
UNCOV
51
      return service;
×
52
    }
53
  }
54
  return null;
×
55
}
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