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

ngageoint / geopackage-js / 4078143969

pending completion
4078143969

push

github

Christopher Caldwell
bump version

3593 of 8015 branches covered (44.83%)

Branch coverage included in aggregate %.

15102 of 20471 relevant lines covered (73.77%)

1564.55 hits per line

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

64.71
/lib/context/context.ts
1
import { Db } from '../db/db';
1✔
2
import { DBAdapter } from '../db/dbAdapter';
3
import { SqliteAdapter } from '../db/sqliteAdapter';
1✔
4
import { SqljsAdapter } from '../db/sqljsAdapter';
1✔
5
import { Canvas } from '../canvas/canvas';
1✔
6
import { CanvasAdapter } from '../canvas/canvasAdapter';
7
import { CanvasKitCanvasAdapter } from '../canvas/canvasKitCanvasAdapter';
1✔
8
import { HtmlCanvasAdapter } from '../canvas/htmlCanvasAdapter';
1✔
9
import { OffscreenCanvasAdapter } from '../canvas/offscreenCanvasAdapter';
1✔
10

11
export class Context {
1✔
12
  static isNode: boolean = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
1✔
13
  static isBrowser: boolean = typeof window !== 'undefined' && typeof window.document !== 'undefined';
1!
14
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
15
  // @ts-ignore
16
  static isWebWorker: boolean = typeof importScripts !== 'undefined';
1✔
17

18
  static async initializeContext(): Promise<void> {
1✔
19
    await Canvas.initializeAdapter();
2✔
20
  }
21

22
  /**
23
   * Registers the sqlite adapter. Will check for better-sqlite3 dependency before trying.
24
   * @private
25
   */
26
  private static registerSqliteAdapter(): void {
1✔
27
    try {
2✔
28
      // better-sqlite3 is an optional dependency
29
      require('better-sqlite3');
2✔
30
      Db.registerDbAdapter(SqliteAdapter);
2✔
31
    } catch (e) {
32
      console.error(
×
33
        'Unable to register SqliteAdapter. The better-sqlite3 module was not found. Falling back to SqljsAdapter.',
34
      );
35
      // fallback to sqljs adapter
36
      Db.registerDbAdapter(SqljsAdapter);
×
37
    }
38
  }
39

40
  /**
41
   * Sets up GeoPackage for Node.js
42
   */
43
  static setupNodeContext(): void {
1✔
44
    Context.registerSqliteAdapter();
2✔
45
    Canvas.registerCanvasAdapter(CanvasKitCanvasAdapter);
2✔
46
    // TODO: think about catching an uncaught error
47
    // process.on('uncaughtException', () => {});
48
  }
49

50
  /**
51
   * Sets up GeoPackage for Browser
52
   */
53
  static setupBrowserContext(): void {
1✔
54
    Db.registerDbAdapter(SqljsAdapter);
×
55
    Canvas.registerCanvasAdapter(HtmlCanvasAdapter);
×
56
  }
57

58
  /**
59
   * Sets up GeoPackage for WebWorker
60
   */
61
  static setupWebWorkerContext(): void {
1✔
62
    Db.registerDbAdapter(SqljsAdapter);
×
63
    Canvas.registerCanvasAdapter(OffscreenCanvasAdapter);
×
64
  }
65

66
  /**
67
   * Will attempt to register a custom context.
68
   * @param dbAdapter
69
   * @param canvasAdapter
70
   */
71
  static setupCustomContext(
1✔
72
    dbAdapter: new (path: string | Buffer | Uint8Array | undefined) => DBAdapter,
73
    canvasAdapter: new () => CanvasAdapter,
74
  ): void {
75
    Db.registerDbAdapter(dbAdapter);
×
76
    Canvas.registerCanvasAdapter(canvasAdapter);
×
77
  }
78

79
  static setupDefaultContext(): void {
1✔
80
    if (Context.isNode) {
1!
81
      Context.setupNodeContext();
1✔
82
    } else if (Context.isBrowser) {
×
83
      Context.setupBrowserContext();
×
84
    } else if (Context.isWebWorker) {
×
85
      Context.setupWebWorkerContext();
×
86
    }
87
  }
88
}
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