@zukhruf/sqlite-data-version 0.6.16 → 0.7.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 +10 -11
- package/dist/followed-database.js +2 -2
- package/dist/followed-database.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/last-write.d.ts.map +1 -1
- package/dist/last-write.js +2 -10
- package/dist/last-write.js.map +1 -1
- package/dist/stamped-database.d.ts.map +1 -1
- package/dist/stamped-database.js +2 -4
- package/dist/stamped-database.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -16,17 +16,16 @@ npm install @zukhruf/sqlite-data-version
|
|
|
16
16
|
import { mkdtempDisposable } from 'node:fs/promises';
|
|
17
17
|
import { tmpdir } from 'node:os';
|
|
18
18
|
import { join } from 'node:path';
|
|
19
|
-
import { DatabaseSync } from 'node:sqlite';
|
|
20
19
|
|
|
21
20
|
import { DataVersion } from '@zukhruf/sqlite-data-version';
|
|
21
|
+
import { open } from '@zukhruf/sqlite-open';
|
|
22
22
|
|
|
23
23
|
await using scratch = await mkdtempDisposable(join(tmpdir(), 'data-version-'));
|
|
24
24
|
const path = join(scratch.path, 'notes.sqlite');
|
|
25
25
|
|
|
26
26
|
// The owner: another connection that writes the database through a WAL.
|
|
27
|
-
using owner =
|
|
28
|
-
owner.exec(`
|
|
29
|
-
CREATE TABLE notes (id INTEGER PRIMARY KEY, title TEXT)`);
|
|
27
|
+
using owner = open(path);
|
|
28
|
+
owner.exec(`CREATE TABLE notes (id INTEGER PRIMARY KEY, title TEXT)`);
|
|
30
29
|
|
|
31
30
|
using version = new DataVersion(path);
|
|
32
31
|
let seen = version.current;
|
|
@@ -57,7 +56,7 @@ no change
|
|
|
57
56
|
- Each read of `current` reads the status of the file at the path one time (`stat`).
|
|
58
57
|
- A commit by the same connection does not change the number. The `DataVersion` connection never writes, so each commit that it sees comes from another connection.
|
|
59
58
|
- Dispose closes the connection. Use `using`, or call `[Symbol.dispose]()`.
|
|
60
|
-
- The package throws its own `UnavailableError`. It is the class of `@zukhruf/sqlite-
|
|
59
|
+
- The package throws its own `UnavailableError`. It is the class of `@zukhruf/sqlite-open`, which opens the connection. The package exports it, so a catch with `instanceof` works with either package. A host that needs its own error translates the error of the package at its boundary, and keeps the error of the package as `cause`. [ADR 0003](./docs/adr/0003-the-package-throws-its-own-errors.md) tells why.
|
|
61
60
|
|
|
62
61
|
## An owner that lets no reader in
|
|
63
62
|
|
|
@@ -102,13 +101,13 @@ console.log(`The owner last wrote at ${written.toISOString()}`);
|
|
|
102
101
|
|
|
103
102
|
## Errors
|
|
104
103
|
|
|
105
|
-
| Error | When
|
|
106
|
-
| ---------------------------- |
|
|
107
|
-
| `UnavailableError` | SQLite cannot open the file: `SQLITE_CANTOPEN` (14), for a missing file or a file that the system denies, a privacy denial too. `new DataVersion` throws it, and `current` throws it when it cannot open a replaced file. `cause` is the error of SQLite. `ofExclusiveOwner` throws it when the file is missing (`ENOENT`) or
|
|
108
|
-
| The error of SQLite | All other failures.
|
|
109
|
-
| The error of the file system | `current` cannot read the status of the path, for a cause other than a missing path or a folder that denies this process.
|
|
104
|
+
| Error | When |
|
|
105
|
+
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
106
|
+
| `UnavailableError` | SQLite cannot open the file: `SQLITE_CANTOPEN` (14), for a missing file or a file that the system denies, a privacy denial too. `new DataVersion` throws it, and `current` throws it when it cannot open a replaced file. `cause` is the error of SQLite. `ofExclusiveOwner` throws it when the file is missing (`ENOENT`, `ENOTDIR`) or the system denies this process (`EACCES`, `EPERM`); then `cause` is the error of the file system. |
|
|
107
|
+
| The error of SQLite | All other failures. |
|
|
108
|
+
| The error of the file system | `current` cannot read the status of the path, for a cause other than a missing path or a folder that denies this process. |
|
|
110
109
|
|
|
111
|
-
`UnavailableError` has the `path`. `lastWrite` throws `UnavailableError` when the file is missing (`ENOENT`) or the
|
|
110
|
+
`UnavailableError` has the `path`. `lastWrite` throws `UnavailableError` when the file is missing (`ENOENT`, `ENOTDIR`) or the system denies this process (`EACCES`, `EPERM`). Then `cause` is the error of the file system. `lastWrite` throws the error of the file system for all other failures.
|
|
112
111
|
|
|
113
112
|
## The same concepts in other systems
|
|
114
113
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { statSync } from 'node:fs';
|
|
2
|
-
import {
|
|
2
|
+
import { open } from '@zukhruf/sqlite-open';
|
|
3
3
|
// The device and inode of the file at the path, or undefined when this
|
|
4
4
|
// process cannot see the path: it is missing, or a folder's mode denies it.
|
|
5
5
|
// Bigint, because inode numbers on NTFS and ReFS exceed 2^53.
|
|
@@ -26,7 +26,7 @@ class OpenFile {
|
|
|
26
26
|
// identity to the old connection, and then the replace is never seen.
|
|
27
27
|
// A path this process cannot see fails the open too, as CANTOPEN.
|
|
28
28
|
this.identity = identify(path);
|
|
29
|
-
this.#database =
|
|
29
|
+
this.#database = open(path, { readOnly: true });
|
|
30
30
|
this.#version = this.#database.prepare('PRAGMA data_version');
|
|
31
31
|
}
|
|
32
32
|
get observation() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"followed-database.js","sourceRoot":"","sources":["../src/followed-database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGnC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"followed-database.js","sourceRoot":"","sources":["../src/followed-database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGnC,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,uEAAuE;AACvE,4EAA4E;AAC5E,8DAA8D;AAC9D,SAAS,QAAQ,CAAC,IAAY;IAC5B,IAAI,CAAC;Q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KAAK,CAAS;IACvB,KAAK,CAAW;IAEhB,YAAY,IAAY;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,0EAA0E;IAC1E,4EAA4E;IAC5E,mDAAmD;IACnD,OAAO;QACL,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YAC/D,qEAAqE;YACrE,wEAAwE;YACxE,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACtC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;IAChC,CAAC;IAED,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IAC/B,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/last-write.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"last-write.d.ts","sourceRoot":"","sources":["../src/last-write.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"last-write.d.ts","sourceRoot":"","sources":["../src/last-write.ts"],"names":[],"mappings":"AAUA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAU5C"}
|
package/dist/last-write.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { statSync } from 'node:fs';
|
|
2
|
-
import { UnavailableError } from '@zukhruf/sqlite-
|
|
3
|
-
// A missing file, or one in a folder whose mode denies this process. macOS
|
|
4
|
-
// privacy controls do not deny it: they stop a read of the file and a list of
|
|
5
|
-
// its folder with EPERM, but not stat of the file.
|
|
6
|
-
const unreadable = new Set(['ENOENT', 'EACCES']);
|
|
2
|
+
import { UnavailableError } from '@zukhruf/sqlite-open';
|
|
7
3
|
// The owner writes a database through its file and its WAL, so the later of
|
|
8
4
|
// their times is when it last wrote. A reader writes the shared-memory index
|
|
9
5
|
// (-shm) too, so its time does not count. The owner may remove the WAL when
|
|
@@ -17,11 +13,7 @@ export function lastWrite(path) {
|
|
|
17
13
|
return new Date(wal !== undefined && wal.size > 0 ? Math.max(file, wal.mtimeMs) : file);
|
|
18
14
|
}
|
|
19
15
|
catch (cause) {
|
|
20
|
-
|
|
21
|
-
'code' in cause &&
|
|
22
|
-
unreadable.has(String(cause.code)))
|
|
23
|
-
throw new UnavailableError(path, cause);
|
|
24
|
-
throw cause;
|
|
16
|
+
throw UnavailableError.from(path, cause) ?? cause;
|
|
25
17
|
}
|
|
26
18
|
}
|
|
27
19
|
//# sourceMappingURL=last-write.js.map
|
package/dist/last-write.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"last-write.js","sourceRoot":"","sources":["../src/last-write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"last-write.js","sourceRoot":"","sources":["../src/last-write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAC5E,2EAA2E;AAC3E,6EAA6E;AAC7E,0BAA0B;AAC1B,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC;QACpC,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,IAAI,MAAM,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAC;QAC/D,OAAO,IAAI,IAAI,CACb,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CACvE,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC;IACpD,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stamped-database.d.ts","sourceRoot":"","sources":["../src/stamped-database.ts"],"names":[],"mappings":"AAWA,qBAAa,eAAgB,YAAW,UAAU;;gBAIpC,IAAI,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"stamped-database.d.ts","sourceRoot":"","sources":["../src/stamped-database.ts"],"names":[],"mappings":"AAWA,qBAAa,eAAgB,YAAW,UAAU;;gBAIpC,IAAI,EAAE,MAAM;IAUxB,OAAO,IAAI,MAAM;IAajB,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CACzB"}
|
package/dist/stamped-database.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { statSync } from 'node:fs';
|
|
2
2
|
import { FileStamp, isErrno } from '@zukhruf/fs';
|
|
3
|
-
import { UnavailableError } from '@zukhruf/sqlite-
|
|
3
|
+
import { UnavailableError } from '@zukhruf/sqlite-open';
|
|
4
4
|
// A database whose owner holds SQLite's exclusive locking mode, as Chromium
|
|
5
5
|
// holds its History. The owner lets no reader read data_version, but each
|
|
6
6
|
// commit writes the database file, so its file stamp changes. A write to the
|
|
@@ -15,9 +15,7 @@ export class StampedDatabase {
|
|
|
15
15
|
statSync(path);
|
|
16
16
|
}
|
|
17
17
|
catch (cause) {
|
|
18
|
-
|
|
19
|
-
throw new UnavailableError(path, cause);
|
|
20
|
-
throw cause;
|
|
18
|
+
throw UnavailableError.from(path, cause) ?? cause;
|
|
21
19
|
}
|
|
22
20
|
this.#path = path;
|
|
23
21
|
this.#observation = String(FileStamp.readSync(path));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stamped-database.js","sourceRoot":"","sources":["../src/stamped-database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"stamped-database.js","sourceRoot":"","sources":["../src/stamped-database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,4EAA4E;AAC5E,0EAA0E;AAC1E,6EAA6E;AAC7E,4EAA4E;AAC5E,4EAA4E;AAC5E,kCAAkC;AAClC,MAAM,OAAO,eAAe;IACjB,KAAK,CAAS;IACvB,YAAY,CAAS;IAErB,YAAY,IAAY;QACtB,IAAI,CAAC;YACH,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC;QACpD,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IACvD,CAAC;IAED,OAAO;QACL,IAAI,KAAgB,CAAC;QACrB,IAAI,CAAC;YACH,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC;gBAAE,OAAO,IAAI,CAAC,YAAY,CAAC;YACvD,MAAM,KAAK,CAAC;QACd,CAAC;QACD,IAAI,KAAK,CAAC,UAAU,KAAK,SAAS;YAAE,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QACtE,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,6BAA6B;IAC7B,CAAC,MAAM,CAAC,OAAO,CAAC,KAAU,CAAC;CAC5B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/sqlite-data-version",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "The data version of a SQLite database that another process owns and writes: PRAGMA data_version on its own read-only connection, or the file stamp of the database when the owner holds the exclusive lock.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@zukhruf/fs": "^0.
|
|
44
|
-
"@zukhruf/sqlite-
|
|
43
|
+
"@zukhruf/fs": "^0.7.0",
|
|
44
|
+
"@zukhruf/sqlite-open": "^0.7.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@zukhruf/testing": "^0.
|
|
47
|
+
"@zukhruf/testing": "^0.7.0"
|
|
48
48
|
}
|
|
49
49
|
}
|