@zukhruf/sqlite-data-version 0.3.33 → 0.3.34
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 +23 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/last-write.d.ts +3 -0
- package/dist/last-write.d.ts.map +1 -0
- package/dist/last-write.js +24 -0
- package/dist/last-write.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,6 +62,25 @@ no change
|
|
|
62
62
|
- Dispose closes the connection. Use `using`, or call `[Symbol.dispose]()`.
|
|
63
63
|
- The caller gives the error class. Thus the error names what the caller needs, for example the access that the user must give.
|
|
64
64
|
|
|
65
|
+
## The last write
|
|
66
|
+
|
|
67
|
+
The data version tells that the owner committed after you read it before. It does not tell when. A new process has no earlier value, so it cannot use the data version to find how old the data is.
|
|
68
|
+
|
|
69
|
+
`lastWrite(path, unavailable)` gives the time when the owner last wrote the database. Use it when the owner writes only while it runs: a time in the past tells that the data has not changed since then.
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { lastWrite } from '@zukhruf/sqlite-data-version';
|
|
73
|
+
|
|
74
|
+
const written = lastWrite(path, Unavailable);
|
|
75
|
+
console.log(`The owner last wrote at ${written.toISOString()}`);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
- The owner writes through the file and its WAL (`-wal`). The last write is the later of their modification times.
|
|
79
|
+
- The shared-memory index (`-shm`) does not count. A read-only reader writes it too, so its time can be later than the last write of the owner.
|
|
80
|
+
- The owner can remove the WAL when it closes. Then the last write is the time of the file.
|
|
81
|
+
- The function reads only the file system. It does not open the database.
|
|
82
|
+
- The macOS privacy controls do not stop it. They stop a process that has no access from reading the file, but not from reading the times of the file.
|
|
83
|
+
|
|
65
84
|
## Errors
|
|
66
85
|
|
|
67
86
|
| Error | When |
|
|
@@ -69,6 +88,8 @@ no change
|
|
|
69
88
|
| `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. |
|
|
70
89
|
| The error of SQLite | All other failures. |
|
|
71
90
|
|
|
91
|
+
`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.
|
|
92
|
+
|
|
72
93
|
## The same concepts in other systems
|
|
73
94
|
|
|
74
95
|
| System | What it does |
|
|
@@ -98,4 +119,6 @@ src/
|
|
|
98
119
|
index.ts the exports
|
|
99
120
|
data-version.ts DataVersion and UnavailableError
|
|
100
121
|
data-version.test.ts the tests, on real SQLite files
|
|
122
|
+
last-write.ts lastWrite
|
|
123
|
+
last-write.test.ts the tests, on real SQLite files
|
|
101
124
|
```
|
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,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,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,EAAyB,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAyB,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"last-write.d.ts","sourceRoot":"","sources":["../src/last-write.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAW1D,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,GAAG,IAAI,CAe3E"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { statSync } from 'node:fs';
|
|
2
|
+
// A missing file, or one in a folder whose mode denies this process. macOS
|
|
3
|
+
// privacy controls do not deny it: they stop a read of the file and a list of
|
|
4
|
+
// its folder with EPERM, but not stat of the file.
|
|
5
|
+
const unreadable = new Set(['ENOENT', 'EACCES']);
|
|
6
|
+
// The owner writes a database through its file and its WAL, so the later of
|
|
7
|
+
// their times is when it last wrote. A reader writes the shared-memory index
|
|
8
|
+
// (-shm) too, so its time does not count. The owner may remove the WAL when
|
|
9
|
+
// it closes; the file stays.
|
|
10
|
+
export function lastWrite(path, unavailable) {
|
|
11
|
+
try {
|
|
12
|
+
const file = statSync(path).mtimeMs;
|
|
13
|
+
const wal = statSync(`${path}-wal`, { throwIfNoEntry: false })?.mtimeMs ?? file;
|
|
14
|
+
return new Date(Math.max(file, wal));
|
|
15
|
+
}
|
|
16
|
+
catch (cause) {
|
|
17
|
+
if (cause instanceof Error &&
|
|
18
|
+
'code' in cause &&
|
|
19
|
+
unreadable.has(String(cause.code)))
|
|
20
|
+
throw new unavailable(path, cause);
|
|
21
|
+
throw cause;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=last-write.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"last-write.js","sourceRoot":"","sources":["../src/last-write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAInC,2EAA2E;AAC3E,8EAA8E;AAC9E,mDAAmD;AACnD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEjD,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAC5E,6BAA6B;AAC7B,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,WAA6B;IACnE,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC;QACpC,MAAM,GAAG,GACP,QAAQ,CAAC,GAAG,IAAI,MAAM,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,IAAI,IAAI,CAAC;QACtE,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IACvC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IACE,KAAK,YAAY,KAAK;YACtB,MAAM,IAAI,KAAK;YACf,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAElC,MAAM,IAAI,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACrC,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
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.34",
|
|
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": {
|