@mailwoman/sqlite 9.2.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/lib/batched.ts +69 -0
- package/lib/client.ts +163 -0
- package/lib/database-schema.ts +30 -0
- package/lib/dialect-config.ts +30 -0
- package/lib/dialect.ts +67 -0
- package/lib/driver.ts +175 -0
- package/lib/index.ts +25 -0
- package/lib/introspection.ts +57 -0
- package/lib/schema-columns.ts +52 -0
- package/lib/sealed-build.ts +117 -0
- package/lib/sealed-db.ts +170 -0
- package/lib/sealed.ts +38 -0
- package/out/batched.d.ts +40 -0
- package/out/batched.d.ts.map +1 -0
- package/out/batched.js +41 -0
- package/out/batched.js.map +1 -0
- package/out/client.d.ts +86 -0
- package/out/client.d.ts.map +1 -0
- package/out/client.js +85 -0
- package/out/client.js.map +1 -0
- package/out/database-schema.d.ts +30 -0
- package/out/database-schema.d.ts.map +1 -0
- package/out/database-schema.js +22 -0
- package/out/database-schema.js.map +1 -0
- package/out/dialect-config.d.ts +27 -0
- package/out/dialect-config.d.ts.map +1 -0
- package/out/dialect-config.js +7 -0
- package/out/dialect-config.js.map +1 -0
- package/out/dialect.d.ts +39 -0
- package/out/dialect.d.ts.map +1 -0
- package/out/dialect.js +49 -0
- package/out/dialect.js.map +1 -0
- package/out/driver.d.ts +22 -0
- package/out/driver.d.ts.map +1 -0
- package/out/driver.js +114 -0
- package/out/driver.js.map +1 -0
- package/out/index.d.ts +25 -0
- package/out/index.d.ts.map +1 -0
- package/out/index.js +25 -0
- package/out/index.js.map +1 -0
- package/out/introspection.d.ts +34 -0
- package/out/introspection.d.ts.map +1 -0
- package/out/introspection.js +46 -0
- package/out/introspection.js.map +1 -0
- package/out/schema-columns.d.ts +31 -0
- package/out/schema-columns.d.ts.map +1 -0
- package/out/schema-columns.js +38 -0
- package/out/schema-columns.js.map +1 -0
- package/out/sealed-build.d.ts +51 -0
- package/out/sealed-build.d.ts.map +1 -0
- package/out/sealed-build.js +71 -0
- package/out/sealed-build.js.map +1 -0
- package/out/sealed-db.d.ts +74 -0
- package/out/sealed-db.d.ts.map +1 -0
- package/out/sealed-db.js +140 -0
- package/out/sealed-db.js.map +1 -0
- package/out/sealed.d.ts +27 -0
- package/out/sealed.d.ts.map +1 -0
- package/out/sealed.js +31 -0
- package/out/sealed.js.map +1 -0
- package/out/tsconfig.test.tsbuildinfo +1 -0
- package/package.json +172 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
7
|
+
import type { DatabaseConnection } from "kysely";
|
|
8
|
+
/**
|
|
9
|
+
* Config for the SQLite dialect.
|
|
10
|
+
*/
|
|
11
|
+
export interface SqliteDialectConfig {
|
|
12
|
+
/**
|
|
13
|
+
* A node:sqlite DatabaseSync instance or a function that returns one.
|
|
14
|
+
*
|
|
15
|
+
* If a function is provided, it's called once when the first query is executed.
|
|
16
|
+
*
|
|
17
|
+
* https://nodejs.org/api/sqlite.html#class-databasesync
|
|
18
|
+
*/
|
|
19
|
+
database: DatabaseSync | (() => Promise<DatabaseSync>);
|
|
20
|
+
/**
|
|
21
|
+
* Called once when the first query is executed.
|
|
22
|
+
*
|
|
23
|
+
* This is a Kysely specific feature and does not come from the `node:sqlite` module.
|
|
24
|
+
*/
|
|
25
|
+
onCreateConnection?: (connection: DatabaseConnection) => Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=dialect-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect-config.d.ts","sourceRoot":"","sources":["../lib/dialect-config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAA;AAEhD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IACnC;;;;;;OAMG;IACH,QAAQ,EAAE,YAAY,GAAG,CAAC,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC,CAAA;IAEtD;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CACtE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect-config.js","sourceRoot":"","sources":["../lib/dialect-config.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
package/out/dialect.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { type DatabaseIntrospector, type Dialect, type DialectAdapter, type Driver, type Kysely, type QueryCompiler } from "kysely";
|
|
7
|
+
import type { SqliteDialectConfig } from "#dialect-config";
|
|
8
|
+
/**
|
|
9
|
+
* SQLite dialect that uses the [`node:sqlite`](https://nodejs.org/api/sqlite.html) library.
|
|
10
|
+
*
|
|
11
|
+
* The constructor takes an instance of {@link SqliteDialectConfig}.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { DatabaseSync } from "node:sqlite"
|
|
15
|
+
*
|
|
16
|
+
* new SqliteDialect({
|
|
17
|
+
* database: new DatabaseSync("db.sqlite"),
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* If you want the pool to only be created once it's first used, `database` can be a function:
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { DatabaseSync } from "node:sqlite"
|
|
25
|
+
*
|
|
26
|
+
* new SqliteDialect({
|
|
27
|
+
* database: async () => new DatabaseSync("db.sqlite"),
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class SqliteDialect implements Dialect {
|
|
32
|
+
protected config: SqliteDialectConfig;
|
|
33
|
+
constructor(config: SqliteDialectConfig);
|
|
34
|
+
createDriver(): Driver;
|
|
35
|
+
createQueryCompiler(): QueryCompiler;
|
|
36
|
+
createAdapter(): DialectAdapter;
|
|
37
|
+
createIntrospector(db: Kysely<unknown>): DatabaseIntrospector;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=dialect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.d.ts","sourceRoot":"","sources":["../lib/dialect.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAIN,KAAK,oBAAoB,EACzB,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,MAAM,QAAQ,CAAA;AAEf,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAG1D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC5C,SAAS,CAAC,MAAM,EAAE,mBAAmB,CAAA;gBAEzB,MAAM,EAAE,mBAAmB;IAIvC,YAAY,IAAI,MAAM;IAItB,mBAAmB,IAAI,aAAa;IAIpC,aAAa,IAAI,cAAc;IAI/B,kBAAkB,CAAC,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,oBAAoB;CAG7D"}
|
package/out/dialect.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { SqliteAdapter, SqliteIntrospector, SqliteQueryCompiler, } from "kysely";
|
|
7
|
+
import { SqliteDriver } from "#driver";
|
|
8
|
+
/**
|
|
9
|
+
* SQLite dialect that uses the [`node:sqlite`](https://nodejs.org/api/sqlite.html) library.
|
|
10
|
+
*
|
|
11
|
+
* The constructor takes an instance of {@link SqliteDialectConfig}.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { DatabaseSync } from "node:sqlite"
|
|
15
|
+
*
|
|
16
|
+
* new SqliteDialect({
|
|
17
|
+
* database: new DatabaseSync("db.sqlite"),
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* If you want the pool to only be created once it's first used, `database` can be a function:
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { DatabaseSync } from "node:sqlite"
|
|
25
|
+
*
|
|
26
|
+
* new SqliteDialect({
|
|
27
|
+
* database: async () => new DatabaseSync("db.sqlite"),
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export class SqliteDialect {
|
|
32
|
+
config;
|
|
33
|
+
constructor(config) {
|
|
34
|
+
this.config = Object.freeze({ ...config });
|
|
35
|
+
}
|
|
36
|
+
createDriver() {
|
|
37
|
+
return new SqliteDriver(this.config);
|
|
38
|
+
}
|
|
39
|
+
createQueryCompiler() {
|
|
40
|
+
return new SqliteQueryCompiler();
|
|
41
|
+
}
|
|
42
|
+
createAdapter() {
|
|
43
|
+
return new SqliteAdapter();
|
|
44
|
+
}
|
|
45
|
+
createIntrospector(db) {
|
|
46
|
+
return new SqliteIntrospector(db);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=dialect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.js","sourceRoot":"","sources":["../lib/dialect.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACN,aAAa,EACb,kBAAkB,EAClB,mBAAmB,GAOnB,MAAM,QAAQ,CAAA;AAGf,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,aAAa;IACf,MAAM,CAAqB;IAErC,YAAY,MAA2B;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,CAAA;IAC3C,CAAC;IAED,YAAY;QACX,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACrC,CAAC;IAED,mBAAmB;QAClB,OAAO,IAAI,mBAAmB,EAAE,CAAA;IACjC,CAAC;IAED,aAAa;QACZ,OAAO,IAAI,aAAa,EAAE,CAAA;IAC3B,CAAC;IAED,kBAAkB,CAAC,EAAmB;QACrC,OAAO,IAAI,kBAAkB,CAAC,EAAE,CAAC,CAAA;IAClC,CAAC;CACD"}
|
package/out/driver.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { type DatabaseConnection, type Driver, type QueryCompiler } from "kysely";
|
|
7
|
+
import type { SqliteDialectConfig } from "#dialect-config";
|
|
8
|
+
export declare class SqliteDriver implements Driver {
|
|
9
|
+
#private;
|
|
10
|
+
constructor(config: SqliteDialectConfig);
|
|
11
|
+
init(): Promise<void>;
|
|
12
|
+
acquireConnection(): Promise<DatabaseConnection>;
|
|
13
|
+
beginTransaction(connection: DatabaseConnection): Promise<void>;
|
|
14
|
+
commitTransaction(connection: DatabaseConnection): Promise<void>;
|
|
15
|
+
rollbackTransaction(connection: DatabaseConnection): Promise<void>;
|
|
16
|
+
savepoint(connection: DatabaseConnection, savepointName: string, compileQuery: QueryCompiler["compileQuery"]): Promise<void>;
|
|
17
|
+
rollbackToSavepoint(connection: DatabaseConnection, savepointName: string, compileQuery: QueryCompiler["compileQuery"]): Promise<void>;
|
|
18
|
+
releaseSavepoint(connection: DatabaseConnection, savepointName: string, compileQuery: QueryCompiler["compileQuery"]): Promise<void>;
|
|
19
|
+
releaseConnection(): Promise<void>;
|
|
20
|
+
destroy(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../lib/driver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAGN,KAAK,kBAAkB,EACvB,KAAK,MAAM,EAEX,KAAK,aAAa,EAIlB,MAAM,QAAQ,CAAA;AAEf,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AA0B1D,qBAAa,YAAa,YAAW,MAAM;;gBAO9B,MAAM,EAAE,mBAAmB;IAIjC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAWrB,iBAAiB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAShD,gBAAgB,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/D,iBAAiB,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhE,mBAAmB,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlE,SAAS,CACd,UAAU,EAAE,kBAAkB,EAC9B,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,GACzC,OAAO,CAAC,IAAI,CAAC;IAIV,mBAAmB,CACxB,UAAU,EAAE,kBAAkB,EAC9B,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,GACzC,OAAO,CAAC,IAAI,CAAC;IAIV,gBAAgB,CACrB,UAAU,EAAE,kBAAkB,EAC9B,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,GACzC,OAAO,CAAC,IAAI,CAAC;IAIV,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG9B"}
|
package/out/driver.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { CompiledQuery, createQueryId, IdentifierNode, RawNode, SelectQueryNode, } from "kysely";
|
|
7
|
+
class ConnectionMutex {
|
|
8
|
+
#promise;
|
|
9
|
+
#resolve;
|
|
10
|
+
async lock() {
|
|
11
|
+
while (this.#promise) {
|
|
12
|
+
await this.#promise;
|
|
13
|
+
}
|
|
14
|
+
this.#promise = new Promise((resolve) => {
|
|
15
|
+
this.#resolve = resolve;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
unlock() {
|
|
19
|
+
const resolve = this.#resolve;
|
|
20
|
+
this.#promise = undefined;
|
|
21
|
+
this.#resolve = undefined;
|
|
22
|
+
resolve?.();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class SqliteDriver {
|
|
26
|
+
#config;
|
|
27
|
+
#connectionMutex = new ConnectionMutex();
|
|
28
|
+
#db;
|
|
29
|
+
#connection;
|
|
30
|
+
constructor(config) {
|
|
31
|
+
this.#config = Object.freeze({ ...config });
|
|
32
|
+
}
|
|
33
|
+
async init() {
|
|
34
|
+
const db = typeof this.#config.database === "function" ? await this.#config.database() : this.#config.database;
|
|
35
|
+
this.#db = db;
|
|
36
|
+
this.#connection = new SqliteConnection(db);
|
|
37
|
+
if (this.#config.onCreateConnection) {
|
|
38
|
+
await this.#config.onCreateConnection(this.#connection);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async acquireConnection() {
|
|
42
|
+
// SQLite only has one single connection. We use a mutex here to wait
|
|
43
|
+
// until the single connection has been released.
|
|
44
|
+
await this.#connectionMutex.lock();
|
|
45
|
+
// biome-ignore lint/style/noNonNullAssertion: :shrug:
|
|
46
|
+
return this.#connection;
|
|
47
|
+
}
|
|
48
|
+
async beginTransaction(connection) {
|
|
49
|
+
await connection.executeQuery(CompiledQuery.raw("begin"));
|
|
50
|
+
}
|
|
51
|
+
async commitTransaction(connection) {
|
|
52
|
+
await connection.executeQuery(CompiledQuery.raw("commit"));
|
|
53
|
+
}
|
|
54
|
+
async rollbackTransaction(connection) {
|
|
55
|
+
await connection.executeQuery(CompiledQuery.raw("rollback"));
|
|
56
|
+
}
|
|
57
|
+
async savepoint(connection, savepointName, compileQuery) {
|
|
58
|
+
await connection.executeQuery(compileQuery(parseSavepointCommand("savepoint", savepointName), createQueryId()));
|
|
59
|
+
}
|
|
60
|
+
async rollbackToSavepoint(connection, savepointName, compileQuery) {
|
|
61
|
+
await connection.executeQuery(compileQuery(parseSavepointCommand("rollback to", savepointName), createQueryId()));
|
|
62
|
+
}
|
|
63
|
+
async releaseSavepoint(connection, savepointName, compileQuery) {
|
|
64
|
+
await connection.executeQuery(compileQuery(parseSavepointCommand("release", savepointName), createQueryId()));
|
|
65
|
+
}
|
|
66
|
+
async releaseConnection() {
|
|
67
|
+
this.#connectionMutex.unlock();
|
|
68
|
+
}
|
|
69
|
+
async destroy() {
|
|
70
|
+
this.#db?.[Symbol.dispose]();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
class SqliteConnection {
|
|
74
|
+
#db;
|
|
75
|
+
constructor(db) {
|
|
76
|
+
this.#db = db;
|
|
77
|
+
}
|
|
78
|
+
executeQuery(compiledQuery) {
|
|
79
|
+
const { sql, parameters } = compiledQuery;
|
|
80
|
+
const stmt = this.#db.prepare(sql);
|
|
81
|
+
const args = Array.isArray(parameters) ? parameters : [];
|
|
82
|
+
if (stmt.columns().length) {
|
|
83
|
+
const rows = stmt.all(...args);
|
|
84
|
+
return Promise.resolve({ rows });
|
|
85
|
+
}
|
|
86
|
+
const result = stmt.run(...args);
|
|
87
|
+
return Promise.resolve({
|
|
88
|
+
numAffectedRows: BigInt(result.changes),
|
|
89
|
+
insertID: BigInt(result.lastInsertRowid),
|
|
90
|
+
rows: [],
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async *streamQuery(compiledQuery, _chunkSize) {
|
|
94
|
+
const { sql, parameters, query } = compiledQuery;
|
|
95
|
+
const stmt = this.#db.prepare(sql);
|
|
96
|
+
const args = Array.isArray(parameters) ? parameters : [];
|
|
97
|
+
if (!SelectQueryNode.is(query)) {
|
|
98
|
+
throw new Error("Sqlite driver only supports streaming of select queries");
|
|
99
|
+
}
|
|
100
|
+
const iter = stmt.iterate(...args);
|
|
101
|
+
for (const row of iter) {
|
|
102
|
+
yield {
|
|
103
|
+
rows: [row],
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function parseSavepointCommand(command, savepointName) {
|
|
109
|
+
return RawNode.createWithChildren([
|
|
110
|
+
RawNode.createWithSql(`${command} `),
|
|
111
|
+
IdentifierNode.create(savepointName), // ensures savepointName gets sanitized
|
|
112
|
+
]);
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.js","sourceRoot":"","sources":["../lib/driver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EACN,aAAa,EACb,aAAa,EAGb,cAAc,EAGd,OAAO,EACP,eAAe,GACf,MAAM,QAAQ,CAAA;AAIf,MAAM,eAAe;IACpB,QAAQ,CAAgB;IACxB,QAAQ,CAAa;IAErB,KAAK,CAAC,IAAI;QACT,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;YACtB,MAAM,IAAI,CAAC,QAAQ,CAAA;QACpB,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YACvC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACxB,CAAC,CAAC,CAAA;IACH,CAAC;IAED,MAAM;QACL,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QAEzD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACxB,MAAM;gBACL,IAAI,EAAE,CAAC,GAAG,CAAC;aACX,CAAA;QACF,CAAC;IACF,CAAC;CACD;AAED,SAAS,qBAAqB,CAAC,OAAe,EAAE,aAAqB;IACpE,OAAO,OAAO,CAAC,kBAAkB,CAAC;QACjC,OAAO,CAAC,aAAa,CAAC,GAAG,OAAO,GAAG,CAAC;QACpC,cAAc,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,uCAAuC;KAC7E,CAAC,CAAA;AACH,CAAC"}
|
package/out/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The one way a Mailwoman SQLite connection comes into being.
|
|
7
|
+
*
|
|
8
|
+
* `DatabaseClient` opens the file; `openBuiltClient` opens a built artifact with the seal check. A caller says which
|
|
9
|
+
* file and which schema and never constructs the connection, so one database carries one schema, one owner, and a
|
|
10
|
+
* lifetime `using` can end. `new DatabaseSync` appears once in this package and nowhere else in the repository.
|
|
11
|
+
*
|
|
12
|
+
* It lives outside `@mailwoman/core` because it needs none of core's 11 MB of parser reference data — its whole
|
|
13
|
+
* dependency set is `kysely`. That is what lets the leaf lookups use it.
|
|
14
|
+
*/
|
|
15
|
+
export * from "#batched";
|
|
16
|
+
export * from "#client";
|
|
17
|
+
export * from "#database-schema";
|
|
18
|
+
export * from "#dialect";
|
|
19
|
+
export * from "#dialect-config";
|
|
20
|
+
export * from "#introspection";
|
|
21
|
+
export * from "#schema-columns";
|
|
22
|
+
export * from "#sealed";
|
|
23
|
+
export * from "#sealed-build";
|
|
24
|
+
export * from "#sealed-db";
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,kBAAkB,CAAA;AAChC,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA"}
|
package/out/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The one way a Mailwoman SQLite connection comes into being.
|
|
7
|
+
*
|
|
8
|
+
* `DatabaseClient` opens the file; `openBuiltClient` opens a built artifact with the seal check. A caller says which
|
|
9
|
+
* file and which schema and never constructs the connection, so one database carries one schema, one owner, and a
|
|
10
|
+
* lifetime `using` can end. `new DatabaseSync` appears once in this package and nowhere else in the repository.
|
|
11
|
+
*
|
|
12
|
+
* It lives outside `@mailwoman/core` because it needs none of core's 11 MB of parser reference data — its whole
|
|
13
|
+
* dependency set is `kysely`. That is what lets the leaf lookups use it.
|
|
14
|
+
*/
|
|
15
|
+
export * from "#batched";
|
|
16
|
+
export * from "#client";
|
|
17
|
+
export * from "#database-schema";
|
|
18
|
+
export * from "#dialect";
|
|
19
|
+
export * from "#dialect-config";
|
|
20
|
+
export * from "#introspection";
|
|
21
|
+
export * from "#schema-columns";
|
|
22
|
+
export * from "#sealed";
|
|
23
|
+
export * from "#sealed-build";
|
|
24
|
+
export * from "#sealed-db";
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
package/out/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,kBAAkB,CAAA;AAChC,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
* @file Questions asked of `sqlite_master`.
|
|
6
|
+
*
|
|
7
|
+
* ITS OWN SUBPATH ON PURPOSE — do not fold this into the package barrel. `@mailwoman/sqlite`'s root export
|
|
8
|
+
* reaches `node:sqlite`, and the docs demo bundles this package for the browser; importing the barrel to
|
|
9
|
+
* ask whether a table exists dragged the builtin into that graph. The split is what keeps these three
|
|
10
|
+
* pure-SQL questions reachable from a bundled consumer.
|
|
11
|
+
*/
|
|
12
|
+
import type { DatabaseClient } from "#client";
|
|
13
|
+
/**
|
|
14
|
+
* Whether a TABLE named `name` exists. An index, view or trigger of that name answers `false`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function tableExists<DB>(db: DatabaseClient<DB>, name: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* `COUNT(*)` over `table`. The name is interpolated, so it must come from the schema, never from input.
|
|
19
|
+
*/
|
|
20
|
+
export declare function countRows<DB>(db: DatabaseClient<DB>, table: string): number;
|
|
21
|
+
/**
|
|
22
|
+
* Whether an INDEX named `name` exists.
|
|
23
|
+
*/
|
|
24
|
+
export declare function indexExists<DB>(db: DatabaseClient<DB>, name: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Every table name, sorted. Virtual tables are tables here, the way `sqlite_master` records them.
|
|
27
|
+
*/
|
|
28
|
+
export declare function listTables<DB>(db: DatabaseClient<DB>): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Whether `table` has a column named `column`. The table name is spliced into a PRAGMA, so it must come from the
|
|
31
|
+
* schema, never from input.
|
|
32
|
+
*/
|
|
33
|
+
export declare function hasColumn<DB>(db: DatabaseClient<DB>, table: string, column: string): boolean;
|
|
34
|
+
//# sourceMappingURL=introspection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"introspection.d.ts","sourceRoot":"","sources":["../lib/introspection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C;;GAEG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,EAAE,EAAE,cAAc,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7E;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,EAAE,EAAE,cAAc,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAI3E;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,EAAE,EAAE,cAAc,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,EAAE,EAAE,cAAc,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAM/D;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,EAAE,EAAE,cAAc,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAI5F"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
* @file Questions asked of `sqlite_master`.
|
|
6
|
+
*
|
|
7
|
+
* ITS OWN SUBPATH ON PURPOSE — do not fold this into the package barrel. `@mailwoman/sqlite`'s root export
|
|
8
|
+
* reaches `node:sqlite`, and the docs demo bundles this package for the browser; importing the barrel to
|
|
9
|
+
* ask whether a table exists dragged the builtin into that graph. The split is what keeps these three
|
|
10
|
+
* pure-SQL questions reachable from a bundled consumer.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Whether a TABLE named `name` exists. An index, view or trigger of that name answers `false`.
|
|
14
|
+
*/
|
|
15
|
+
export function tableExists(db, name) {
|
|
16
|
+
return Boolean(db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(name));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* `COUNT(*)` over `table`. The name is interpolated, so it must come from the schema, never from input.
|
|
20
|
+
*/
|
|
21
|
+
export function countRows(db, table) {
|
|
22
|
+
const row = db.prepare(`SELECT COUNT(*) AS n FROM ${table}`).get();
|
|
23
|
+
return Number(row?.n ?? 0);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Whether an INDEX named `name` exists.
|
|
27
|
+
*/
|
|
28
|
+
export function indexExists(db, name) {
|
|
29
|
+
return Boolean(db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'index' AND name = ?").get(name));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Every table name, sorted. Virtual tables are tables here, the way `sqlite_master` records them.
|
|
33
|
+
*/
|
|
34
|
+
export function listTables(db) {
|
|
35
|
+
const rows = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name").all();
|
|
36
|
+
return rows.map((row) => row.name);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Whether `table` has a column named `column`. The table name is spliced into a PRAGMA, so it must come from the
|
|
40
|
+
* schema, never from input.
|
|
41
|
+
*/
|
|
42
|
+
export function hasColumn(db, table, column) {
|
|
43
|
+
const rows = db.prepare(`PRAGMA table_info(${table})`).all();
|
|
44
|
+
return rows.some((row) => row.name === column);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=introspection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"introspection.js","sourceRoot":"","sources":["../lib/introspection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH;;GAEG;AACH,MAAM,UAAU,WAAW,CAAK,EAAsB,EAAE,IAAY;IACnE,OAAO,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,+DAA+D,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;AACtG,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAK,EAAsB,EAAE,KAAa;IAClE,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,6BAA6B,KAAK,EAAE,CAAC,CAAC,GAAG,EAAgC,CAAA;IAEhG,OAAO,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAK,EAAsB,EAAE,IAAY;IACnE,OAAO,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,+DAA+D,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;AACtG,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAK,EAAsB;IACpD,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CAAC,mEAAmE,CAAC,CAAC,GAAG,EAE9F,CAAA;IAEF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AACnC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAK,EAAsB,EAAE,KAAa,EAAE,MAAc;IAClF,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CAAC,qBAAqB,KAAK,GAAG,CAAC,CAAC,GAAG,EAA6B,CAAA;IAEvF,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,MAAM,CAAC,CAAA;AAC/C,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The column groups every polygon layer's schema repeats, as schema-builder helpers — so the
|
|
7
|
+
* `WITHOUT ROWID`-versus-blob discipline is stated once, beside the columns it governs.
|
|
8
|
+
*/
|
|
9
|
+
import type { CreateTableBuilder, Kysely } from "kysely";
|
|
10
|
+
/**
|
|
11
|
+
* The slice of a Kysely handle a schema module's DDL touches. Kysely is invariant in its schema parameter, so naming
|
|
12
|
+
* only the member the builders call lets a caller pass its own wider handle.
|
|
13
|
+
*/
|
|
14
|
+
export type SchemaHandle<DB> = Pick<Kysely<DB>, "schema">;
|
|
15
|
+
/**
|
|
16
|
+
* The precomputed bounding box plus the unsimplified ring blob every polygon truth table carries.
|
|
17
|
+
*
|
|
18
|
+
* A table taking these stays a PLAIN rowid table, never `WITHOUT ROWID`: the `rings` blob is exactly the payload
|
|
19
|
+
* clustering into the B-tree penalizes — every index page becomes a geometry page.
|
|
20
|
+
*/
|
|
21
|
+
export declare function addRingGeometryColumns<TB extends string, C extends string>(builder: CreateTableBuilder<TB, C>): CreateTableBuilder<TB, C | "min_lat" | "min_lon" | "max_lat" | "max_lon" | "rings">;
|
|
22
|
+
/**
|
|
23
|
+
* The cell-index columns every polygon summary tier carries: the 48-bit short cell, the resolution it was captured at
|
|
24
|
+
* (a short cell does not name its own, and a mixed-resolution table cannot be probed without it), the key the row
|
|
25
|
+
* names, and its containment.
|
|
26
|
+
*
|
|
27
|
+
* Small fixed-width rows probed by their exact primary key are the `WITHOUT ROWID` shape — the caller adds its own
|
|
28
|
+
* primary-key constraint and the raw `without rowid` modifier, because the key differs per layer.
|
|
29
|
+
*/
|
|
30
|
+
export declare function addCellIndexColumns<TB extends string, C extends string, K extends string>(builder: CreateTableBuilder<TB, C>, keyColumn: K): CreateTableBuilder<TB, C | K | "h3_cell" | "resolution" | "containment">;
|
|
31
|
+
//# sourceMappingURL=schema-columns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-columns.d.ts","sourceRoot":"","sources":["../lib/schema-columns.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAExD;;;GAGG;AACH,MAAM,MAAM,YAAY,CAAC,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAA;AAEzD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EACzE,OAAO,EAAE,kBAAkB,CAAC,EAAE,EAAE,CAAC,CAAC,GAChC,kBAAkB,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC,CAOrF;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EACxF,OAAO,EAAE,kBAAkB,CAAC,EAAE,EAAE,CAAC,CAAC,EAClC,SAAS,EAAE,CAAC,GACV,kBAAkB,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,GAAG,YAAY,GAAG,aAAa,CAAC,CAM1E"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The column groups every polygon layer's schema repeats, as schema-builder helpers — so the
|
|
7
|
+
* `WITHOUT ROWID`-versus-blob discipline is stated once, beside the columns it governs.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* The precomputed bounding box plus the unsimplified ring blob every polygon truth table carries.
|
|
11
|
+
*
|
|
12
|
+
* A table taking these stays a PLAIN rowid table, never `WITHOUT ROWID`: the `rings` blob is exactly the payload
|
|
13
|
+
* clustering into the B-tree penalizes — every index page becomes a geometry page.
|
|
14
|
+
*/
|
|
15
|
+
export function addRingGeometryColumns(builder) {
|
|
16
|
+
return builder
|
|
17
|
+
.addColumn("min_lat", "real", (column) => column.notNull())
|
|
18
|
+
.addColumn("min_lon", "real", (column) => column.notNull())
|
|
19
|
+
.addColumn("max_lat", "real", (column) => column.notNull())
|
|
20
|
+
.addColumn("max_lon", "real", (column) => column.notNull())
|
|
21
|
+
.addColumn("rings", "blob", (column) => column.notNull());
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The cell-index columns every polygon summary tier carries: the 48-bit short cell, the resolution it was captured at
|
|
25
|
+
* (a short cell does not name its own, and a mixed-resolution table cannot be probed without it), the key the row
|
|
26
|
+
* names, and its containment.
|
|
27
|
+
*
|
|
28
|
+
* Small fixed-width rows probed by their exact primary key are the `WITHOUT ROWID` shape — the caller adds its own
|
|
29
|
+
* primary-key constraint and the raw `without rowid` modifier, because the key differs per layer.
|
|
30
|
+
*/
|
|
31
|
+
export function addCellIndexColumns(builder, keyColumn) {
|
|
32
|
+
return builder
|
|
33
|
+
.addColumn("h3_cell", "integer", (column) => column.notNull())
|
|
34
|
+
.addColumn("resolution", "integer", (column) => column.notNull())
|
|
35
|
+
.addColumn(keyColumn, "text", (column) => column.notNull())
|
|
36
|
+
.addColumn("containment", "text", (column) => column.notNull());
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=schema-columns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-columns.js","sourceRoot":"","sources":["../lib/schema-columns.ts"],"names":[],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+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The sealed polygon-artifact build sequence: one temp file beside the destination, two handles, every
|
|
7
|
+
* cleanup path, then `VACUUM` → seal → atomic swap.
|
|
8
|
+
*
|
|
9
|
+
* THE INGEST AND THE FINISH PHASES USE SEPARATE HANDLES, ALWAYS — including the in-process path, which does
|
|
10
|
+
* not need them separated. The batched path DOES: its children open the same file, so the parent's handle
|
|
11
|
+
* has to be closed across them, and a single shared handle silently becomes a closed one by the time the
|
|
12
|
+
* finish phase runs. Doing it one way in both paths is what puts the fixture suites on the same sequence a
|
|
13
|
+
* national build takes.
|
|
14
|
+
*/
|
|
15
|
+
import { DatabaseClient } from "#client";
|
|
16
|
+
export interface BuildSealedArtifactOptions<DB, Streamed, Result> {
|
|
17
|
+
/**
|
|
18
|
+
* Where the sealed artifact lands. The build writes beside it and swaps.
|
|
19
|
+
*/
|
|
20
|
+
out: string;
|
|
21
|
+
/**
|
|
22
|
+
* Create every table the build writes — the layer's own, the contract's, and any build-only scratch table (which the
|
|
23
|
+
* finish phase drops before the artifact is sealed).
|
|
24
|
+
*/
|
|
25
|
+
createTables: (database: DatabaseClient<DB>) => Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* The in-process ingest, run under the FIRST handle. Return `undefined` to defer to {@link batched}; any writes made
|
|
28
|
+
* before deferring (attribute preloads) are kept.
|
|
29
|
+
*/
|
|
30
|
+
ingest: (database: DatabaseClient<DB>) => Promise<Streamed | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* The bounded child-process ingest, run while the parent holds NO handle. Each child opens the temp file and appends;
|
|
33
|
+
* chunks run one at a time, so there is exactly one writer at every instant.
|
|
34
|
+
*/
|
|
35
|
+
batched?: (tmpPath: string) => Promise<Streamed>;
|
|
36
|
+
/**
|
|
37
|
+
* Post-ingest work under the SECOND handle: assertions over what was streamed, index/coverage/manifest writes,
|
|
38
|
+
* dropping any scratch table. `VACUUM`, the seal and the swap follow; the artifact's on-disk size is measurable only
|
|
39
|
+
* after this returns and the swap lands.
|
|
40
|
+
*/
|
|
41
|
+
finish: (database: DatabaseClient<DB>, streamed: Streamed) => Promise<Result>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Run one sealed-artifact build.
|
|
45
|
+
*
|
|
46
|
+
* Every failure path removes the temp file: a failed build otherwise leaves a partial multi-gigabyte file whose name
|
|
47
|
+
* carries this process's pid, so nothing would ever pick it up again — the difference between a retry loop that fails
|
|
48
|
+
* and one that fills a disk.
|
|
49
|
+
*/
|
|
50
|
+
export declare function buildSealedArtifact<DB, Streamed, Result>(options: BuildSealedArtifactOptions<DB, Streamed, Result>): Promise<Result>;
|
|
51
|
+
//# sourceMappingURL=sealed-build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sealed-build.d.ts","sourceRoot":"","sources":["../lib/sealed-build.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAGxC,MAAM,WAAW,0BAA0B,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM;IAC/D;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;;OAGG;IACH,YAAY,EAAE,CAAC,QAAQ,EAAE,cAAc,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7D;;;OAGG;IACH,MAAM,EAAE,CAAC,QAAQ,EAAE,cAAc,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAA;IACvE;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;IAChD;;;;OAIG;IACH,MAAM,EAAE,CAAC,QAAQ,EAAE,cAAc,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CAC7E;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAC7D,OAAO,EAAE,0BAA0B,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,GACvD,OAAO,CAAC,MAAM,CAAC,CA2DjB"}
|