@zukhruf/sqlite-data-version 0.3.50 → 0.3.52
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 +15 -19
- package/dist/data-version.d.ts +1 -2
- package/dist/data-version.d.ts.map +1 -1
- package/dist/data-version.js +2 -2
- package/dist/data-version.js.map +1 -1
- package/dist/followed-database.d.ts +1 -2
- package/dist/followed-database.d.ts.map +1 -1
- package/dist/followed-database.js +50 -39
- package/dist/followed-database.js.map +1 -1
- package/dist/index.d.ts +2 -1
- 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 +1 -2
- package/dist/last-write.d.ts.map +1 -1
- package/dist/last-write.js +3 -2
- package/dist/last-write.js.map +1 -1
- package/dist/unavailable-error.d.ts +6 -0
- package/dist/unavailable-error.d.ts.map +1 -0
- package/dist/unavailable-error.js +10 -0
- package/dist/unavailable-error.js.map +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -20,12 +20,6 @@ import { DatabaseSync } from 'node:sqlite';
|
|
|
20
20
|
|
|
21
21
|
import { DataVersion } from '@zukhruf/sqlite-data-version';
|
|
22
22
|
|
|
23
|
-
class Unavailable extends Error {
|
|
24
|
-
constructor(path: string, cause: unknown) {
|
|
25
|
-
super(`Cannot read ${path}`, { cause });
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
23
|
await using scratch = await mkdtempDisposable(join(tmpdir(), 'data-version-'));
|
|
30
24
|
const path = join(scratch.path, 'notes.sqlite');
|
|
31
25
|
|
|
@@ -34,7 +28,7 @@ using owner = new DatabaseSync(path);
|
|
|
34
28
|
owner.exec(`PRAGMA journal_mode = WAL;
|
|
35
29
|
CREATE TABLE notes (id INTEGER PRIMARY KEY, title TEXT)`);
|
|
36
30
|
|
|
37
|
-
using version = new DataVersion(path
|
|
31
|
+
using version = new DataVersion(path);
|
|
38
32
|
let seen = version.current;
|
|
39
33
|
for (const title of ['first', 'second']) {
|
|
40
34
|
owner.prepare('INSERT INTO notes (title) VALUES (?)').run(title);
|
|
@@ -55,26 +49,26 @@ no change
|
|
|
55
49
|
|
|
56
50
|
## The rules
|
|
57
51
|
|
|
58
|
-
- `new DataVersion(path
|
|
52
|
+
- `new DataVersion(path)` opens its own read-only connection to the database. It does not share a connection with a reader. [ADR 0001](./docs/adr/0001-poll-data-version.md) tells why.
|
|
59
53
|
- `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
54
|
- The number tells only that a change occurred. It does not count the commits, and it does not tell what changed.
|
|
61
55
|
- `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
|
|
56
|
+
- 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
57
|
- Each read of `current` reads the status of the file at the path one time (`stat`).
|
|
64
58
|
- 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
59
|
- Dispose closes the connection. Use `using`, or call `[Symbol.dispose]()`.
|
|
66
|
-
- The
|
|
60
|
+
- The package throws its own `UnavailableError`. 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.
|
|
67
61
|
|
|
68
62
|
## The last write
|
|
69
63
|
|
|
70
64
|
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.
|
|
71
65
|
|
|
72
|
-
`lastWrite(path
|
|
66
|
+
`lastWrite(path)` 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.
|
|
73
67
|
|
|
74
68
|
```ts
|
|
75
69
|
import { lastWrite } from '@zukhruf/sqlite-data-version';
|
|
76
70
|
|
|
77
|
-
const written = lastWrite(path
|
|
71
|
+
const written = lastWrite(path);
|
|
78
72
|
console.log(`The owner last wrote at ${written.toISOString()}`);
|
|
79
73
|
```
|
|
80
74
|
|
|
@@ -87,13 +81,13 @@ console.log(`The owner last wrote at ${written.toISOString()}`);
|
|
|
87
81
|
|
|
88
82
|
## Errors
|
|
89
83
|
|
|
90
|
-
| Error
|
|
91
|
-
|
|
|
92
|
-
| `
|
|
93
|
-
| The error of SQLite
|
|
94
|
-
| The error of the file system
|
|
84
|
+
| Error | When |
|
|
85
|
+
| ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
86
|
+
| `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. |
|
|
87
|
+
| The error of SQLite | All other failures. |
|
|
88
|
+
| 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
89
|
|
|
96
|
-
`
|
|
90
|
+
`UnavailableError` has the `path`. `lastWrite` throws `UnavailableError` when the file is missing (`ENOENT`) or the mode of its folder denies this process (`EACCES`). Then `cause` is the error of the file system. `lastWrite` throws the error of the file system for all other failures.
|
|
97
91
|
|
|
98
92
|
## The same concepts in other systems
|
|
99
93
|
|
|
@@ -110,6 +104,7 @@ console.log(`The owner last wrote at ${written.toISOString()}`);
|
|
|
110
104
|
|
|
111
105
|
- [0001 Poll data_version](./docs/adr/0001-poll-data-version.md)
|
|
112
106
|
- [0002 A replaced file is followed by name](./docs/adr/0002-a-replaced-file-is-followed-by-name.md)
|
|
107
|
+
- [0003 The package throws its own errors](./docs/adr/0003-the-package-throws-its-own-errors.md)
|
|
113
108
|
- [Code copied into this package](./docs/copied-code.md)
|
|
114
109
|
|
|
115
110
|
## Development
|
|
@@ -126,8 +121,9 @@ npx nx run sqlite-data-version:build # compiles src/ to dist/
|
|
|
126
121
|
```
|
|
127
122
|
src/
|
|
128
123
|
index.ts the exports
|
|
129
|
-
data-version.ts DataVersion
|
|
124
|
+
data-version.ts DataVersion
|
|
130
125
|
followed-database.ts the connection that follows the path to a replaced file
|
|
126
|
+
unavailable-error.ts UnavailableError
|
|
131
127
|
data-version.test.ts the tests, on real SQLite files
|
|
132
128
|
last-write.ts lastWrite
|
|
133
129
|
last-write.test.ts the tests, on real SQLite files
|
package/dist/data-version.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export type UnavailableError = new (path: string, cause: unknown) => Error;
|
|
2
1
|
export declare class DataVersion implements Disposable {
|
|
3
2
|
#private;
|
|
4
|
-
constructor(path: string
|
|
3
|
+
constructor(path: string);
|
|
5
4
|
get current(): number;
|
|
6
5
|
[Symbol.dispose](): void;
|
|
7
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-version.d.ts","sourceRoot":"","sources":["../src/data-version.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"data-version.d.ts","sourceRoot":"","sources":["../src/data-version.ts"],"names":[],"mappings":"AAQA,qBAAa,WAAY,YAAW,UAAU;;gBAKhC,IAAI,EAAE,MAAM;IAKxB,IAAI,OAAO,IAAI,MAAM,CAOpB;IAED,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAGzB"}
|
package/dist/data-version.js
CHANGED
|
@@ -9,8 +9,8 @@ export class DataVersion {
|
|
|
9
9
|
#database;
|
|
10
10
|
#seen;
|
|
11
11
|
#current = 0;
|
|
12
|
-
constructor(path
|
|
13
|
-
this.#database = new FollowedDatabase(path
|
|
12
|
+
constructor(path) {
|
|
13
|
+
this.#database = new FollowedDatabase(path);
|
|
14
14
|
this.#seen = this.#database.observe();
|
|
15
15
|
}
|
|
16
16
|
get current() {
|
package/dist/data-version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-version.js","sourceRoot":"","sources":["../src/data-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"data-version.js","sourceRoot":"","sources":["../src/data-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,wEAAwE;AACxE,6EAA6E;AAC7E,wEAAwE;AACxE,sEAAsE;AACtE,wEAAwE;AACxE,0DAA0D;AAC1D,MAAM,OAAO,WAAW;IACb,SAAS,CAAmB;IACrC,KAAK,CAAS;IACd,QAAQ,GAAG,CAAC,CAAC;IAEb,YAAY,IAAY;QACtB,IAAI,CAAC,SAAS,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAC5C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IACxC,CAAC;IAED,IAAI,OAAO;QACT,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAC1C,IAAI,QAAQ,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;YAC5B,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC;YACtB,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC;QACrB,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { UnavailableError } from './data-version.ts';
|
|
2
1
|
export declare class FollowedDatabase implements Disposable {
|
|
3
2
|
#private;
|
|
4
|
-
constructor(path: string
|
|
3
|
+
constructor(path: string);
|
|
5
4
|
observe(): string;
|
|
6
5
|
[Symbol.dispose](): void;
|
|
7
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"followed-database.d.ts","sourceRoot":"","sources":["../src/followed-database.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"followed-database.d.ts","sourceRoot":"","sources":["../src/followed-database.ts"],"names":[],"mappings":"AAmEA,qBAAa,gBAAiB,YAAW,UAAU;;gBAIrC,IAAI,EAAE,MAAM;IAQxB,OAAO,IAAI,MAAM;IAYjB,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAGzB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { statSync } from 'node:fs';
|
|
2
2
|
import { DatabaseSync } from 'node:sqlite';
|
|
3
|
-
|
|
3
|
+
import { UnavailableError } from "./unavailable-error.js";
|
|
4
|
+
function open(path) {
|
|
4
5
|
try {
|
|
5
6
|
return new DatabaseSync(path, { readOnly: true });
|
|
6
7
|
}
|
|
@@ -12,63 +13,73 @@ function open(path, unavailable) {
|
|
|
12
13
|
// SQLite gives AUTH only for an authorizer, and this private connection
|
|
13
14
|
// has none. Any other failure is not one that access can fix.
|
|
14
15
|
cause.errcode === 14)
|
|
15
|
-
throw new
|
|
16
|
+
throw new UnavailableError(path, cause);
|
|
16
17
|
throw cause;
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
|
-
// The device and inode of the file at the path, or undefined when
|
|
20
|
-
//
|
|
20
|
+
// The device and inode of the file at the path, or undefined when this
|
|
21
|
+
// process cannot see the path: it is missing, or a folder's mode denies it.
|
|
22
|
+
// Bigint, because inode numbers on NTFS and ReFS exceed 2^53.
|
|
21
23
|
function identify(path) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
try {
|
|
25
|
+
const stats = statSync(path, { bigint: true, throwIfNoEntry: false });
|
|
26
|
+
return stats === undefined ? undefined : `${stats.dev}:${stats.ino}`;
|
|
27
|
+
}
|
|
28
|
+
catch (cause) {
|
|
29
|
+
if (cause instanceof Error && 'code' in cause && cause.code === 'EACCES')
|
|
30
|
+
return undefined;
|
|
31
|
+
throw cause;
|
|
32
|
+
}
|
|
24
33
|
}
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
#path;
|
|
30
|
-
#unavailable;
|
|
31
|
-
#identity;
|
|
34
|
+
// One read-only connection and the identity of the file it opened, which
|
|
35
|
+
// never change: a replaced file gets a new OpenFile.
|
|
36
|
+
class OpenFile {
|
|
37
|
+
identity;
|
|
32
38
|
#database;
|
|
33
39
|
#version;
|
|
34
|
-
constructor(path
|
|
35
|
-
this.#path = path;
|
|
36
|
-
this.#unavailable = unavailable;
|
|
40
|
+
constructor(path) {
|
|
37
41
|
// Stat before open: a file replaced between the two is one extra change
|
|
38
42
|
// at the next observation. Stat after open could give the new file's
|
|
39
43
|
// identity to the old connection, and then the replace is never seen.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
}
|
|
51
|
-
this.#database = open(path, unavailable);
|
|
52
|
-
this.#identity = identity ?? '';
|
|
44
|
+
// A path this process cannot see fails the open too, as CANTOPEN.
|
|
45
|
+
this.identity = identify(path);
|
|
46
|
+
this.#database = open(path);
|
|
53
47
|
this.#version = this.#database.prepare('PRAGMA data_version');
|
|
54
48
|
}
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
get observation() {
|
|
50
|
+
// PRAGMA data_version always gives one row.
|
|
51
|
+
return `${this.identity}|${String(this.#version.get().data_version)}`;
|
|
52
|
+
}
|
|
53
|
+
[Symbol.dispose]() {
|
|
54
|
+
this.#database.close();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// A connection keeps reading the file it opened, also after the owner
|
|
58
|
+
// replaces the file at the path. This follows the path by name, as tail -F
|
|
59
|
+
// does: when the path names a different file, it opens that file.
|
|
60
|
+
export class FollowedDatabase {
|
|
61
|
+
#path;
|
|
62
|
+
#file;
|
|
63
|
+
constructor(path) {
|
|
64
|
+
this.#path = path;
|
|
65
|
+
this.#file = new OpenFile(path);
|
|
66
|
+
}
|
|
67
|
+
// The identity of the held file and its data version. A path this process
|
|
68
|
+
// cannot see keeps the old connection: the owner may be about to create the
|
|
69
|
+
// file again, and the open connection still reads.
|
|
57
70
|
observe() {
|
|
58
71
|
const identity = identify(this.#path);
|
|
59
|
-
if (identity !== undefined && identity !== this.#identity) {
|
|
72
|
+
if (identity !== undefined && identity !== this.#file.identity) {
|
|
60
73
|
// Open the new file before the old one closes. While the old file is
|
|
61
74
|
// open its inode stays in use, so the new file cannot get the same one.
|
|
62
|
-
const
|
|
63
|
-
this.#
|
|
64
|
-
this.#
|
|
65
|
-
this.#identity = identity;
|
|
66
|
-
this.#version = database.prepare('PRAGMA data_version');
|
|
75
|
+
const file = new OpenFile(this.#path);
|
|
76
|
+
this.#file[Symbol.dispose]();
|
|
77
|
+
this.#file = file;
|
|
67
78
|
}
|
|
68
|
-
return
|
|
79
|
+
return this.#file.observation;
|
|
69
80
|
}
|
|
70
81
|
[Symbol.dispose]() {
|
|
71
|
-
this.#
|
|
82
|
+
this.#file[Symbol.dispose]();
|
|
72
83
|
}
|
|
73
84
|
}
|
|
74
85
|
//# sourceMappingURL=followed-database.js.map
|
|
@@ -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;
|
|
1
|
+
{"version":3,"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AC,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,
|
|
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,wBAAwB,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,
|
|
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,wBAAwB,CAAC"}
|
package/dist/last-write.d.ts
CHANGED
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":"AAeA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAgB5C"}
|
package/dist/last-write.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { statSync } from 'node:fs';
|
|
2
|
+
import { UnavailableError } from "./unavailable-error.js";
|
|
2
3
|
// A missing file, or one in a folder whose mode denies this process. macOS
|
|
3
4
|
// privacy controls do not deny it: they stop a read of the file and a list of
|
|
4
5
|
// its folder with EPERM, but not stat of the file.
|
|
@@ -9,7 +10,7 @@ const unreadable = new Set(['ENOENT', 'EACCES']);
|
|
|
9
10
|
// it closes, and a reader that opens the database then makes an empty one,
|
|
10
11
|
// timed as it reads; an empty WAL holds nothing the file does not, so only a
|
|
11
12
|
// WAL with frames counts.
|
|
12
|
-
export function lastWrite(path
|
|
13
|
+
export function lastWrite(path) {
|
|
13
14
|
try {
|
|
14
15
|
const file = statSync(path).mtimeMs;
|
|
15
16
|
const wal = statSync(`${path}-wal`, { throwIfNoEntry: false });
|
|
@@ -19,7 +20,7 @@ export function lastWrite(path, unavailable) {
|
|
|
19
20
|
if (cause instanceof Error &&
|
|
20
21
|
'code' in cause &&
|
|
21
22
|
unreadable.has(String(cause.code)))
|
|
22
|
-
throw new
|
|
23
|
+
throw new UnavailableError(path, cause);
|
|
23
24
|
throw cause;
|
|
24
25
|
}
|
|
25
26
|
}
|
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;
|
|
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,wBAAwB,CAAC;AAE1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or this process has no access to it. */
|
|
2
|
+
export class UnavailableError extends Error {
|
|
3
|
+
path;
|
|
4
|
+
constructor(path, cause) {
|
|
5
|
+
super(`The database at ${JSON.stringify(path)} cannot be opened: the file is missing, or this process has no access to it. Give the process access, or check the path.`, { cause });
|
|
6
|
+
this.name = 'UnavailableError';
|
|
7
|
+
this.path = path;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=unavailable-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unavailable-error.js","sourceRoot":"","sources":["../src/unavailable-error.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAChC,IAAI,CAAS;IAEtB,YAAY,IAAY,EAAE,KAAc;QACtC,KAAK,CACH,mBAAmB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,0HAA0H,EACjK,EAAE,KAAK,EAAE,CACV,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,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.52",
|
|
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.52"
|
|
44
44
|
}
|
|
45
45
|
}
|