@zukhruf/sqlite-data-version 0.6.16 → 0.8.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 +32 -11
- package/dist/data-version.d.ts +3 -1
- package/dist/data-version.d.ts.map +1 -1
- package/dist/data-version.js +7 -1
- package/dist/data-version.js.map +1 -1
- 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 +5 -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;
|
|
@@ -51,13 +50,35 @@ no change
|
|
|
51
50
|
|
|
52
51
|
- `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.
|
|
53
52
|
- `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.
|
|
53
|
+
- `DataVersion` is a `Gauge<number>` of `@zukhruf/async`. Give it to a `ChangeWatcher`, and each check reads `current`. A check after a commit of the owner gives `changed`, and a check with no commit gives `unchanged`.
|
|
54
54
|
- The number tells only that a change occurred. It does not count the commits, and it does not tell what changed.
|
|
55
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.
|
|
56
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.
|
|
57
57
|
- Each read of `current` reads the status of the file at the path one time (`stat`).
|
|
58
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.
|
|
59
59
|
- Dispose closes the connection. Use `using`, or call `[Symbol.dispose]()`.
|
|
60
|
-
- The package throws its own `UnavailableError`. It is the class of `@zukhruf/sqlite-
|
|
60
|
+
- 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
|
+
|
|
62
|
+
## Watch the data version
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { ChangeWatcher } from '@zukhruf/async';
|
|
66
|
+
import { DataVersion } from '@zukhruf/sqlite-data-version';
|
|
67
|
+
|
|
68
|
+
using version = new DataVersion(path);
|
|
69
|
+
// The data version is a local read: a check that takes the whole interval is stuck.
|
|
70
|
+
const watcher = new ChangeWatcher([version], {
|
|
71
|
+
interval: 1_000,
|
|
72
|
+
timeout: 1_000,
|
|
73
|
+
clock: globalThis,
|
|
74
|
+
});
|
|
75
|
+
for await (const outcomes of watcher.watch(signal)) {
|
|
76
|
+
const outcome = outcomes.get(version);
|
|
77
|
+
if (outcome?.state === 'failed') throw outcome.error;
|
|
78
|
+
if (outcome?.state === 'changed')
|
|
79
|
+
console.log('The owner committed. Read again.');
|
|
80
|
+
}
|
|
81
|
+
```
|
|
61
82
|
|
|
62
83
|
## An owner that lets no reader in
|
|
63
84
|
|
|
@@ -102,13 +123,13 @@ console.log(`The owner last wrote at ${written.toISOString()}`);
|
|
|
102
123
|
|
|
103
124
|
## Errors
|
|
104
125
|
|
|
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.
|
|
126
|
+
| Error | When |
|
|
127
|
+
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
128
|
+
| `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. |
|
|
129
|
+
| The error of SQLite | All other failures. |
|
|
130
|
+
| 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
131
|
|
|
111
|
-
`UnavailableError` has the `path`. `lastWrite` throws `UnavailableError` when the file is missing (`ENOENT`) or the
|
|
132
|
+
`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
133
|
|
|
113
134
|
## The same concepts in other systems
|
|
114
135
|
|
package/dist/data-version.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { Gauge } from '@zukhruf/async';
|
|
1
2
|
type ObservedDatabase = Disposable & {
|
|
2
3
|
observe(): string;
|
|
3
4
|
};
|
|
4
|
-
export declare class DataVersion implements Disposable {
|
|
5
|
+
export declare class DataVersion extends Gauge<number> implements Disposable {
|
|
5
6
|
#private;
|
|
6
7
|
constructor(path: string, database?: ObservedDatabase);
|
|
7
8
|
static ofExclusiveOwner(path: string): DataVersion;
|
|
8
9
|
get current(): number;
|
|
10
|
+
protected read(): Promise<number>;
|
|
9
11
|
[Symbol.dispose](): void;
|
|
10
12
|
}
|
|
11
13
|
export {};
|
|
@@ -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":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAMvC,KAAK,gBAAgB,GAAG,UAAU,GAAG;IAAE,OAAO,IAAI,MAAM,CAAA;CAAE,CAAC;AAS3D,qBAAa,WAAY,SAAQ,KAAK,CAAC,MAAM,CAAE,YAAW,UAAU;;gBAMhE,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,gBAA6C;IAWzD,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW;IAIlD,IAAI,OAAO,IAAI,MAAM,CAOpB;cAEe,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAGzB"}
|
package/dist/data-version.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Gauge } from '@zukhruf/async';
|
|
1
2
|
import { FollowedDatabase } from "./followed-database.js";
|
|
2
3
|
import { StampedDatabase } from "./stamped-database.js";
|
|
3
4
|
// The owner commits through a WAL it keeps open, and file-change events
|
|
@@ -6,11 +7,13 @@ import { StampedDatabase } from "./stamped-database.js";
|
|
|
6
7
|
// The owner can also replace the file at the path. A new connection's
|
|
7
8
|
// data_version starts again and can equal an old value, so current is a
|
|
8
9
|
// count of the changes seen, not the data_version itself.
|
|
9
|
-
|
|
10
|
+
// It exists to tell a change, so it is a gauge: a change watcher reads current.
|
|
11
|
+
export class DataVersion extends Gauge {
|
|
10
12
|
#database;
|
|
11
13
|
#seen;
|
|
12
14
|
#current = 0;
|
|
13
15
|
constructor(path, database = new FollowedDatabase(path)) {
|
|
16
|
+
super();
|
|
14
17
|
this.#database = database;
|
|
15
18
|
this.#seen = this.#database.observe();
|
|
16
19
|
}
|
|
@@ -29,6 +32,9 @@ export class DataVersion {
|
|
|
29
32
|
}
|
|
30
33
|
return this.#current;
|
|
31
34
|
}
|
|
35
|
+
async read() {
|
|
36
|
+
return this.current;
|
|
37
|
+
}
|
|
32
38
|
[Symbol.dispose]() {
|
|
33
39
|
this.#database[Symbol.dispose]();
|
|
34
40
|
}
|
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;AAC1D,OAAO,EA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,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAES,KAAK,CAAC,IAAI;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -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;QACH,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,EAAE,E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;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.8.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,11 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@zukhruf/
|
|
44
|
-
"@zukhruf/
|
|
43
|
+
"@zukhruf/async": "^0.8.0",
|
|
44
|
+
"@zukhruf/fs": "^0.8.0",
|
|
45
|
+
"@zukhruf/sqlite-open": "^0.8.0"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"@zukhruf/testing": "^0.
|
|
48
|
+
"@zukhruf/testing": "^0.8.0"
|
|
48
49
|
}
|
|
49
50
|
}
|