@zukhruf/sqlite-snapshot 0.3.52 → 0.3.53

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
@@ -64,7 +64,7 @@ true
64
64
  - `all(sql, ...parameters)` gives all rows. `iterate(sql, ...parameters)` gives the rows one at a time, for a table that is too large to hold in memory.
65
65
  - `requireColumns(columns)` checks the columns that the reader needs, as `{ table: [column, ...] }`. When one is missing, it disposes the snapshot and throws `MissingColumnsError`.
66
66
  - `missingColumns(columns)` gives the missing columns as `table.column`, and keeps the snapshot open. A reader whose queries use different tables checks each query with it.
67
- - The package throws its own errors: `UnavailableError` and `MissingColumnsError`. 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 0002](./docs/adr/0002-the-package-throws-its-own-errors.md) tells why.
67
+ - The package throws its own errors: `UnavailableError` and `MissingColumnsError`. `UnavailableError` is the class of `@zukhruf/sqlite-reader`, 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 0002](./docs/adr/0002-the-package-throws-its-own-errors.md) tells why.
68
68
  - Dispose commits the read transaction and closes the connection. A second dispose does nothing.
69
69
 
70
70
  ## Errors
@@ -87,7 +87,6 @@ true
87
87
 
88
88
  - [0001 Never immutable, and held only while reading](./docs/adr/0001-never-immutable-and-held-only-while-reading.md)
89
89
  - [0002 The package throws its own errors](./docs/adr/0002-the-package-throws-its-own-errors.md)
90
- - [Code copied into this package](./docs/copied-code.md)
91
90
 
92
91
  ## Development
93
92
 
@@ -104,7 +103,6 @@ npx nx run sqlite-snapshot:build # compiles src/ to dist/
104
103
  src/
105
104
  index.ts the exports
106
105
  snapshot.ts Snapshot and SnapshotColumns
107
- unavailable-error.ts UnavailableError
108
106
  missing-columns-error.ts MissingColumnsError
109
107
  snapshot.test.ts the tests, on real SQLite files
110
108
  ```
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { MissingColumnsError } from './missing-columns-error.ts';
2
2
  export { Snapshot, type SnapshotColumns } from './snapshot.ts';
3
- export { UnavailableError } from './unavailable-error.ts';
3
+ export { UnavailableError } from '@zukhruf/sqlite-reader';
4
4
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { MissingColumnsError } from "./missing-columns-error.js";
2
2
  export { Snapshot } from "./snapshot.js";
3
- export { UnavailableError } from "./unavailable-error.js";
3
+ export { UnavailableError } from '@zukhruf/sqlite-reader';
4
4
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { type SQLInputValue, type SQLOutputValue } from 'node:sqlite';
1
+ import type { SQLInputValue, SQLOutputValue } from 'node:sqlite';
2
2
  export type SnapshotColumns = Readonly<Record<string, readonly string[]>>;
3
3
  export declare class Snapshot implements Disposable {
4
4
  #private;
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,cAAc,EACpB,MAAM,aAAa,CAAC;AAMrB,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;AAyB1E,qBAAa,QAAS,YAAW,UAAU;;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAGV,IAAI,EAAE,MAAM;IAgBxB,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAU9C,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,EAAE;IAalD,GAAG,CACD,GAAG,EAAE,MAAM,EACX,GAAG,UAAU,EAAE,aAAa,EAAE,GAC7B,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE;IAKnC,OAAO,CACL,GAAG,EAAE,MAAM,EACX,GAAG,UAAU,EAAE,aAAa,EAAE,GAC7B,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,SAAS,CAAC;IAI5D,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAKzB"}
1
+ {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAO/E,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;AAO1E,qBAAa,QAAS,YAAW,UAAU;;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAGV,IAAI,EAAE,MAAM;IAgBxB,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAU9C,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,EAAE;IAalD,GAAG,CACD,GAAG,EAAE,MAAM,EACX,GAAG,UAAU,EAAE,aAAa,EAAE,GAC7B,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE;IAKnC,OAAO,CACL,GAAG,EAAE,MAAM,EACX,GAAG,UAAU,EAAE,aAAa,EAAE,GAC7B,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,SAAS,CAAC;IAI5D,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAKzB"}
package/dist/snapshot.js CHANGED
@@ -1,22 +1,5 @@
1
- import { DatabaseSync, } from 'node:sqlite';
1
+ import { openReader } from '@zukhruf/sqlite-reader';
2
2
  import { MissingColumnsError } from "./missing-columns-error.js";
3
- import { UnavailableError } from "./unavailable-error.js";
4
- function open(path) {
5
- try {
6
- return new DatabaseSync(path, { readOnly: true });
7
- }
8
- catch (cause) {
9
- if (cause instanceof Error &&
10
- 'errcode' in cause &&
11
- // SQLite's CANTOPEN (14). A missing or denied file fails the open()
12
- // syscall, and SQLite reports that as CANTOPEN, a privacy denial too.
13
- // SQLite gives AUTH only for an authorizer, and this private connection
14
- // has none. Any other failure is not one that access can fix.
15
- cause.errcode === 14)
16
- throw new UnavailableError(path, cause);
17
- throw cause;
18
- }
19
- }
20
3
  // A SQLite database another process owns and writes while it runs, read
21
4
  // read-only and pinned to one moment by a read transaction, so its tables
22
5
  // agree. Never opened immutable: the owner keeps a persistent WAL, where the
@@ -27,7 +10,7 @@ export class Snapshot {
27
10
  #database;
28
11
  constructor(path) {
29
12
  this.path = path;
30
- this.#database = open(path);
13
+ this.#database = openReader(path);
31
14
  try {
32
15
  // The first read pins the snapshot, so it is taken now rather than at
33
16
  // the caller's first query; a file that is no database fails here.
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,GAGb,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAK1D,SAAS,IAAI,CAAC,IAAY;IACxB,IAAI,CAAC;QACH,OAAO,IAAI,YAAY,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IACE,KAAK,YAAY,KAAK;YACtB,SAAS,IAAI,KAAK;YAClB,oEAAoE;YACpE,sEAAsE;YACtE,wEAAwE;YACxE,8DAA8D;YAC9D,KAAK,CAAC,OAAO,KAAK,EAAE;YAEpB,MAAM,IAAI,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC1C,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,wEAAwE;AACxE,0EAA0E;AAC1E,6EAA6E;AAC7E,6EAA6E;AAC7E,yBAAyB;AACzB,MAAM,OAAO,QAAQ;IACV,IAAI,CAAS;IACb,SAAS,CAAe;IAEjC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AC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC;IACxD,CAAC;IAED,2DAA2D;IAC3D,OAAO,CACL,GAAW,EACX,GAAG,UAA2B;QAE9B,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,CAAC;IAC5D,CAAC;IAED,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM;YAAE,OAAO;QACnC,IAAI,IAAI,CAAC,SAAS,CAAC,aAAa;YAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;CACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zukhruf/sqlite-snapshot",
3
- "version": "0.3.52",
4
- "description": "A read-only snapshot of a SQLite database that another process owns and writes. It pins one moment with a read transaction, so the tables agree, and it never opens the file immutable, so it sees the newest rows in the WAL. It checks the columns that a reader needs, and gives the caller's own errors for a missing file or a missing column.",
3
+ "version": "0.3.53",
4
+ "description": "A read-only snapshot of a SQLite database that another process owns and writes. It pins one moment with a read transaction, so the tables agree, and it never opens the file immutable, so it sees the newest rows in the WAL. It checks the columns that a reader needs. It throws its own UnavailableError for a missing or denied file, and MissingColumnsError for a missing column.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -39,7 +39,10 @@
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
+ "dependencies": {
43
+ "@zukhruf/sqlite-reader": "^0.3.53"
44
+ },
42
45
  "devDependencies": {
43
- "@zukhruf/testing": "^0.3.52"
46
+ "@zukhruf/testing": "^0.3.53"
44
47
  }
45
48
  }
@@ -1,6 +0,0 @@
1
- /** The database file is missing, or this process has no access to it. */
2
- export declare class UnavailableError extends Error {
3
- readonly path: string;
4
- constructor(path: string, cause: unknown);
5
- }
6
- //# sourceMappingURL=unavailable-error.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unavailable-error.d.ts","sourceRoot":"","sources":["../src/unavailable-error.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;CAQzC"}
@@ -1,10 +0,0 @@
1
- /** The database file is missing, 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
@@ -1 +0,0 @@
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"}