0.4.0 • Published 1 year ago

@mktcodelib/github-scanner v0.4.0

Weekly downloads
-
License
UNLICENSE
Repository
github
Last release
1 year ago

GitHub Scanner

Using @mktcodelib/graphql-fetch-all and adds IndexedDB storage and Web Workers on top of it. Install and use it in your project like this:

npm i @mktcodelib/github-scanner

cp node_modules/@mktcodelib/github-scanner/dist/github-scan-worker.js public/github-scan-worker.js
import { Scanner } from '@mktcodelib/github-scanner';

const scanner = new Scanner({ accessToken: "<access token>" });

// Fetch all data from paginated query
const result = await scanner.scan(query, variables);

// Fetch data with intermediate results using a callback
const result = await scanner.scan(
  query,
  variables,
  (intermediateResult) => {
    const { scanId, data, paginators, variables } = intermediateResult;
    // ...
  }
);

// Continue an unfinished scan
const result = await scanner.continueScan(scanId, (intermediateResult) => {
  // ...
});

Database

GitHub Scanner uses IndexedDB to store the fetched data in the browser. The database schema is defined in the db.ts file. Dexie.js is being used as a simple and efficient way to interact with IndexedDB.

You can access the database directly using the exported db instance.

import { db } from '@mktcodelib/github-scanner';

db.scans.toArray().then((scans) => {
  console.log(scans);
});

Web Workers

Each scan is performed in a web worker to avoid blocking the main thread. The worker file is provided by the package and needs to be copied to a location that is accessible by the browser, e.g.:

cp node_modules/@mktcodelib/github-scanner/dist/github-scan-worker.js public/github-scan-worker.js

If you want to use a different filename or path, you can pass it to the Scanner constructor:

const scanner = new Scanner({
  accessToken: "<access token>",
  workerPath: '/path/to/worker.js', // default: '/github-scan-worker.js'
});

The web worker file is responsible for fetching the data and storing it in the database. It communicates with the main thread using postMessage and onmessage to send and receive updates.

0.4.0

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.1

1 year ago

0.0.1

1 year ago