@chronicle.app/etl-sqlite 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/SqliteExtractor.js +4 -1
- package/dist/chromeEpoch.d.ts +28 -0
- package/dist/chromeEpoch.js +31 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -32,6 +32,8 @@ The connection is read-only: missing databases are not created, and journal mode
|
|
|
32
32
|
|
|
33
33
|
Apple epoch helpers retain the existing API: iOS inputs/outputs use nanoseconds since 2001, Safari inputs/outputs use seconds since 2001. `iosToUnixTimestamp` returns Unix milliseconds; other Unix arguments/results use seconds.
|
|
34
34
|
|
|
35
|
+
Chrome epoch helpers cover Chromium's microseconds since 1601. `chromeToUnixMsSql(column)` returns a SQL expression in Unix milliseconds, since current Chrome times are too large to read as numbers. `unixMsToChromeTimestamp(ms)` converts a bound back, as a `timeRangeConditions` `convert`.
|
|
36
|
+
|
|
35
37
|
Node SQLite returns large INTEGER values only when `statement.setReadBigInts(true)` is enabled. Use that for source nanosecond timestamps and convert deliberately at the application boundary.
|
|
36
38
|
|
|
37
39
|
## Porting from better-sqlite3
|
package/dist/SqliteExtractor.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DatabaseSync } from 'node:sqlite';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { Extractor } from '@chronicle.app/etl';
|
|
3
|
+
import { Extractor, assertReadable } from '@chronicle.app/etl';
|
|
4
4
|
/** Read an existing source database without changing its journal mode. */
|
|
5
5
|
export class SqliteExtractor extends Extractor {
|
|
6
6
|
static delivery = 'local';
|
|
@@ -21,6 +21,9 @@ export class SqliteExtractor extends Extractor {
|
|
|
21
21
|
* as a copy of a locked database, after closing and clearing `this.db`.
|
|
22
22
|
*/
|
|
23
23
|
openDatabase(path) {
|
|
24
|
+
// SQLite says only "unable to open database file"; say whether the file
|
|
25
|
+
// is missing or macOS privacy controls refused it.
|
|
26
|
+
assertReadable(path, 'database');
|
|
24
27
|
return new DatabaseSync(path, { readOnly: true });
|
|
25
28
|
}
|
|
26
29
|
async teardown() {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chrome epoch timestamp utilities.
|
|
3
|
+
*
|
|
4
|
+
* Chromium stores times (History `visits.visit_time`, `urls.last_visit_time`)
|
|
5
|
+
* as microseconds since January 1, 1601 00:00:00 UTC, the Windows FILETIME
|
|
6
|
+
* epoch. Unix timestamps count from January 1, 1970 00:00:00 UTC. The
|
|
7
|
+
* difference is 11,644,473,600 seconds.
|
|
8
|
+
*
|
|
9
|
+
* Current Chrome times exceed Number.MAX_SAFE_INTEGER, so `node:sqlite` throws
|
|
10
|
+
* ERR_OUT_OF_RANGE when reading them as numbers. Convert in SQL with
|
|
11
|
+
* `chromeToUnixMsSql(column)`, or read with `statement.setReadBigInts(true)`.
|
|
12
|
+
*/
|
|
13
|
+
export declare const CHROME_EPOCH_OFFSET_MS = 11644473600000;
|
|
14
|
+
/**
|
|
15
|
+
* A SQL expression converting a Chrome time column to Unix milliseconds
|
|
16
|
+
* (integer division, so sub-millisecond precision is dropped).
|
|
17
|
+
* @param column A trusted, developer-supplied column name
|
|
18
|
+
*/
|
|
19
|
+
export declare function chromeToUnixMsSql(column: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Convert Unix milliseconds to a Chrome timestamp, for binding against a Chrome
|
|
22
|
+
* time column. The result is exact until the year 3800 although it exceeds
|
|
23
|
+
* Number.MAX_SAFE_INTEGER: it is a multiple of 1000, and so of 8, below 2^56.
|
|
24
|
+
* @param unixMs Unix timestamp in milliseconds
|
|
25
|
+
* @returns Chrome timestamp in microseconds since Jan 1, 1601
|
|
26
|
+
*/
|
|
27
|
+
export declare function unixMsToChromeTimestamp(unixMs: number): number;
|
|
28
|
+
//# sourceMappingURL=chromeEpoch.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chrome epoch timestamp utilities.
|
|
3
|
+
*
|
|
4
|
+
* Chromium stores times (History `visits.visit_time`, `urls.last_visit_time`)
|
|
5
|
+
* as microseconds since January 1, 1601 00:00:00 UTC, the Windows FILETIME
|
|
6
|
+
* epoch. Unix timestamps count from January 1, 1970 00:00:00 UTC. The
|
|
7
|
+
* difference is 11,644,473,600 seconds.
|
|
8
|
+
*
|
|
9
|
+
* Current Chrome times exceed Number.MAX_SAFE_INTEGER, so `node:sqlite` throws
|
|
10
|
+
* ERR_OUT_OF_RANGE when reading them as numbers. Convert in SQL with
|
|
11
|
+
* `chromeToUnixMsSql(column)`, or read with `statement.setReadBigInts(true)`.
|
|
12
|
+
*/
|
|
13
|
+
export const CHROME_EPOCH_OFFSET_MS = 11_644_473_600_000;
|
|
14
|
+
/**
|
|
15
|
+
* A SQL expression converting a Chrome time column to Unix milliseconds
|
|
16
|
+
* (integer division, so sub-millisecond precision is dropped).
|
|
17
|
+
* @param column A trusted, developer-supplied column name
|
|
18
|
+
*/
|
|
19
|
+
export function chromeToUnixMsSql(column) {
|
|
20
|
+
return `(${column} / 1000 - ${CHROME_EPOCH_OFFSET_MS})`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Convert Unix milliseconds to a Chrome timestamp, for binding against a Chrome
|
|
24
|
+
* time column. The result is exact until the year 3800 although it exceeds
|
|
25
|
+
* Number.MAX_SAFE_INTEGER: it is a multiple of 1000, and so of 8, below 2^56.
|
|
26
|
+
* @param unixMs Unix timestamp in milliseconds
|
|
27
|
+
* @returns Chrome timestamp in microseconds since Jan 1, 1601
|
|
28
|
+
*/
|
|
29
|
+
export function unixMsToChromeTimestamp(unixMs) {
|
|
30
|
+
return (Math.floor(unixMs) + CHROME_EPOCH_OFFSET_MS) * 1000;
|
|
31
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chronicle.app/etl-sqlite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"type": "module",
|
|
20
20
|
"description": "Read-only SQLite extraction using built-in node:sqlite",
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@chronicle.app/etl": "0.
|
|
23
|
-
"@chronicle.app/tsconfig": "0.
|
|
22
|
+
"@chronicle.app/etl": "0.4.0",
|
|
23
|
+
"@chronicle.app/tsconfig": "0.4.0",
|
|
24
24
|
"@types/node": "^22.10.1",
|
|
25
25
|
"typescript": "^5.7.2"
|
|
26
26
|
},
|