@zukhruf/sqlite-data-version 0.3.50 → 0.3.51
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
CHANGED
|
@@ -59,7 +59,7 @@ no change
|
|
|
59
59
|
- `current` gives the data version now. It is the number of `DataVersion`, not the `PRAGMA data_version` of SQLite. Compare it with the value that you read before from the same `DataVersion`. A different value tells that another connection committed, or that the owner replaced the file. The same value tells that no change occurred.
|
|
60
60
|
- The number tells only that a change occurred. It does not count the commits, and it does not tell what changed.
|
|
61
61
|
- `DataVersion` follows the path. The owner can replace the file at the path: it can rename a new file over it, or delete the file and create it again. A replaced file is a change. Then `DataVersion` reads the new file, and each later commit to the new file is a change too. [ADR 0002](./docs/adr/0002-a-replaced-file-is-followed-by-name.md) tells why.
|
|
62
|
-
- A
|
|
62
|
+
- A path that this process cannot see is no change. The path is missing, or the mode of a folder denies this process. The owner can delete the file and create it again a short time later. `DataVersion` keeps the old connection until it can see a file at the path again, and then a replaced file is a change.
|
|
63
63
|
- Each read of `current` reads the status of the file at the path one time (`stat`).
|
|
64
64
|
- 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.
|
|
65
65
|
- Dispose closes the connection. Use `using`, or call `[Symbol.dispose]()`.
|
|
@@ -87,11 +87,11 @@ console.log(`The owner last wrote at ${written.toISOString()}`);
|
|
|
87
87
|
|
|
88
88
|
## Errors
|
|
89
89
|
|
|
90
|
-
| Error | When
|
|
91
|
-
| ------------------------------ |
|
|
92
|
-
| `new unavailable(path, cause)` | SQLite cannot open the file: `SQLITE_CANTOPEN` (14), for a missing file or a file that the system denies, a privacy denial too.
|
|
93
|
-
| The error of SQLite | All other failures.
|
|
94
|
-
| The error of the file system | `current` cannot read the status of the path, for a cause other than a missing
|
|
90
|
+
| Error | When |
|
|
91
|
+
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------- |
|
|
92
|
+
| `new unavailable(path, cause)` | SQLite cannot open the file: `SQLITE_CANTOPEN` (14), for a missing file or a file that the system denies, a privacy denial too. |
|
|
93
|
+
| The error of SQLite | All other failures. |
|
|
94
|
+
| 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. |
|
|
95
95
|
|
|
96
96
|
`lastWrite` gives `new unavailable(path, cause)` when the file is missing (`ENOENT`) or the mode of its folder denies this process (`EACCES`). It gives the error of the file system for all other failures.
|
|
97
97
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"followed-database.d.ts","sourceRoot":"","sources":["../src/followed-database.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"followed-database.d.ts","sourceRoot":"","sources":["../src/followed-database.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAqC1D,qBAAa,gBAAiB,YAAW,UAAU;;gBAOrC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB;IAgBvD,OAAO,IAAI,MAAM;IAcjB,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAGzB"}
|
|
@@ -16,11 +16,19 @@ function open(path, unavailable) {
|
|
|
16
16
|
throw cause;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
// The device and inode of the file at the path, or undefined when
|
|
20
|
-
//
|
|
19
|
+
// The device and inode of the file at the path, or undefined when this
|
|
20
|
+
// process cannot see the path: it is missing, or a folder's mode denies it.
|
|
21
|
+
// Bigint, because inode numbers on NTFS and ReFS exceed 2^53.
|
|
21
22
|
function identify(path) {
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
try {
|
|
24
|
+
const stats = statSync(path, { bigint: true, throwIfNoEntry: false });
|
|
25
|
+
return stats === undefined ? undefined : `${stats.dev}:${stats.ino}`;
|
|
26
|
+
}
|
|
27
|
+
catch (cause) {
|
|
28
|
+
if (cause instanceof Error && 'code' in cause && cause.code === 'EACCES')
|
|
29
|
+
return undefined;
|
|
30
|
+
throw cause;
|
|
31
|
+
}
|
|
24
32
|
}
|
|
25
33
|
// A connection keeps reading the file it opened, also after the owner
|
|
26
34
|
// replaces the file at the path. This follows the path by name, as tail -F
|
|
@@ -37,23 +45,15 @@ export class FollowedDatabase {
|
|
|
37
45
|
// Stat before open: a file replaced between the two is one extra change
|
|
38
46
|
// at the next observation. Stat after open could give the new file's
|
|
39
47
|
// identity to the old connection, and then the replace is never seen.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
identity = identify(path);
|
|
43
|
-
}
|
|
44
|
-
catch (cause) {
|
|
45
|
-
// A folder whose mode denies this process. SQLite reported it as
|
|
46
|
-
// CANTOPEN when the open came first.
|
|
47
|
-
if (cause instanceof Error && 'code' in cause && cause.code === 'EACCES')
|
|
48
|
-
throw new unavailable(path, cause);
|
|
49
|
-
throw cause;
|
|
50
|
-
}
|
|
48
|
+
// A path this process cannot see fails the open too, as CANTOPEN.
|
|
49
|
+
const identity = identify(path);
|
|
51
50
|
this.#database = open(path, unavailable);
|
|
52
51
|
this.#identity = identity ?? '';
|
|
53
52
|
this.#version = this.#database.prepare('PRAGMA data_version');
|
|
54
53
|
}
|
|
55
|
-
// The identity of the held file and its data version. A
|
|
56
|
-
// the old connection: the owner may be about to create the
|
|
54
|
+
// The identity of the held file and its data version. A path this process
|
|
55
|
+
// cannot see keeps the old connection: the owner may be about to create the
|
|
56
|
+
// file again, and the open connection still reads.
|
|
57
57
|
observe() {
|
|
58
58
|
const identity = identify(this.#path);
|
|
59
59
|
if (identity !== undefined && identity !== this.#identity) {
|
|
@@ -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;AACnC,OAAO,EAAE,YAAY,EAAsB,MAAM,aAAa,CAAC;AAI/D,SAAS,IAA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,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;YACrD,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;YACvB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;YAC1B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;YAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;QAC1D,CAAC;QACD,OAAO,GAAG,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,YAAY,CAAC,EAAE,CAAC;IAC1E,CAAC;IAED,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/sqlite-data-version",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.51",
|
|
4
4
|
"description": "The data version of a SQLite database that another process owns and writes. It polls PRAGMA data_version on its own read-only connection, which changes on each commit by another connection, also while the owner keeps the file open.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -40,6 +40,6 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@zukhruf/testing": "^0.3.
|
|
43
|
+
"@zukhruf/testing": "^0.3.51"
|
|
44
44
|
}
|
|
45
45
|
}
|