@fedify/sqlite 2.0.0-pr.412.1559 → 2.0.0-pr.412.1794
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/deno.json +1 -3
- package/dist/_virtual/{rolldown_runtime.js → rolldown_runtime.cjs} +9 -6
- package/dist/adapter.d.cts +45 -0
- package/dist/dist/sqlite.node.d.cts +2 -0
- package/dist/kv.cjs +188 -0
- package/dist/kv.d.cts +76 -0
- package/dist/kv.js +11 -12
- package/dist/mod.cjs +6 -0
- package/dist/mod.d.cts +2 -0
- package/dist/mod.js +2 -2
- package/dist/sqlite.bun.cjs +42 -0
- package/dist/sqlite.bun.d.cts +23 -0
- package/dist/sqlite.bun.js +2 -2
- package/dist/sqlite.node.cjs +44 -0
- package/dist/sqlite.node.d.cts +23 -0
- package/dist/sqlite.node.js +2 -2
- package/package.json +17 -7
- package/src/kv.test.ts +3 -3
- package/src/kv.ts +5 -6
- package/tsdown.config.ts +12 -4
- package/dist/node_modules/.pnpm/@js-temporal_polyfill@0.5.1/node_modules/@js-temporal/polyfill/dist/index.esm.js +0 -5795
- package/dist/node_modules/.pnpm/jsbi@4.3.2/node_modules/jsbi/dist/jsbi-cjs.js +0 -1139
package/deno.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/sqlite",
|
|
3
|
-
"version": "2.0.0-pr.412.
|
|
3
|
+
"version": "2.0.0-pr.412.1794+5c393341",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/mod.ts",
|
|
7
7
|
"./kv": "./src/kv.ts"
|
|
8
8
|
},
|
|
9
9
|
"imports": {
|
|
10
|
-
"@fedify/sqlite": "./src/mod.ts",
|
|
11
|
-
"@fedify/sqlite/": "./src/",
|
|
12
10
|
"#sqlite": "./src/sqlite.node.ts"
|
|
13
11
|
},
|
|
14
12
|
"exclude": [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const { Temporal } = require("@js-temporal/polyfill");
|
|
3
|
+
|
|
4
4
|
//#region rolldown:runtime
|
|
5
5
|
var __create = Object.create;
|
|
6
6
|
var __defProp = Object.defineProperty;
|
|
@@ -8,9 +8,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
8
8
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
9
|
var __getProtoOf = Object.getPrototypeOf;
|
|
10
10
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __commonJS = (cb, mod) => function() {
|
|
12
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
13
|
-
};
|
|
14
11
|
var __copyProps = (to, from, except, desc) => {
|
|
15
12
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
16
13
|
key = keys[i];
|
|
@@ -27,4 +24,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
24
|
}) : target, mod));
|
|
28
25
|
|
|
29
26
|
//#endregion
|
|
30
|
-
|
|
27
|
+
|
|
28
|
+
Object.defineProperty(exports, '__toESM', {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () {
|
|
31
|
+
return __toESM;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/adapter.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* SQLite database adapter.
|
|
4
|
+
*
|
|
5
|
+
* An abstract interface for SQLite database for different runtime environments.
|
|
6
|
+
*/
|
|
7
|
+
interface SqliteDatabaseAdapter {
|
|
8
|
+
/**
|
|
9
|
+
* Prepares a SQL statement.
|
|
10
|
+
* @param sql - The SQL statement to prepare.
|
|
11
|
+
*/
|
|
12
|
+
prepare(sql: string): SqliteStatementAdapter;
|
|
13
|
+
/**
|
|
14
|
+
* Executes a SQL statement.
|
|
15
|
+
* @param sql - The SQL statement to execute.
|
|
16
|
+
*/
|
|
17
|
+
exec(sql: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* Closes the database connection.
|
|
20
|
+
*/
|
|
21
|
+
close(): void;
|
|
22
|
+
}
|
|
23
|
+
interface SqliteStatementAdapter {
|
|
24
|
+
/**
|
|
25
|
+
* Executes a SQL statement and returns the number of changes made to the database.
|
|
26
|
+
* @param params - The parameters to bind to the SQL statement.
|
|
27
|
+
*/
|
|
28
|
+
run(...params: unknown[]): {
|
|
29
|
+
changes: number;
|
|
30
|
+
lastInsertRowid: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Executes a SQL statement and returns the first row of the result set.
|
|
34
|
+
* @param params - The parameters to bind to the SQL statement.
|
|
35
|
+
* @returns The first row of the result set, or `undefined` if the result set is empty.
|
|
36
|
+
*/
|
|
37
|
+
get(...params: unknown[]): unknown | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Executes a SQL statement and returns all rows of the result set.
|
|
40
|
+
* @param params - The parameters to bind to the SQL statement.
|
|
41
|
+
*/
|
|
42
|
+
all(...params: unknown[]): unknown[];
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { SqliteDatabaseAdapter, SqliteStatementAdapter };
|
package/dist/kv.cjs
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
|
|
2
|
+
const { Temporal } = require("@js-temporal/polyfill");
|
|
3
|
+
|
|
4
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
5
|
+
const __sqlite = require_rolldown_runtime.__toESM(require("#sqlite"));
|
|
6
|
+
const __logtape_logtape = require_rolldown_runtime.__toESM(require("@logtape/logtape"));
|
|
7
|
+
const es_toolkit = require_rolldown_runtime.__toESM(require("es-toolkit"));
|
|
8
|
+
|
|
9
|
+
//#region src/kv.ts
|
|
10
|
+
const logger = (0, __logtape_logtape.getLogger)([
|
|
11
|
+
"fedify",
|
|
12
|
+
"sqlite",
|
|
13
|
+
"kv"
|
|
14
|
+
]);
|
|
15
|
+
/**
|
|
16
|
+
* A key–value store that uses SQLite as the underlying storage.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { createFederation } from "@fedify/fedify";
|
|
21
|
+
* import { SqliteKvStore } from "@fedify/sqlite";
|
|
22
|
+
* import { DatabaseSync } from "node:sqlite";
|
|
23
|
+
*
|
|
24
|
+
* const db = new DatabaseSync(":memory:");
|
|
25
|
+
* const federation = createFederation({
|
|
26
|
+
* // ...
|
|
27
|
+
* kv: new SqliteKvStore(db),
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
var SqliteKvStore = class SqliteKvStore {
|
|
32
|
+
static #defaultTableName = "fedify_kv";
|
|
33
|
+
static #tableNameRegex = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;
|
|
34
|
+
#db;
|
|
35
|
+
#tableName;
|
|
36
|
+
#initialized;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new SQLite key–value store.
|
|
39
|
+
* @param db The SQLite database to use. Supports `node:sqlite` and `bun:sqlite`.
|
|
40
|
+
* @param options The options for the key–value store.
|
|
41
|
+
*/
|
|
42
|
+
constructor(db, options = {}) {
|
|
43
|
+
this.db = db;
|
|
44
|
+
this.options = options;
|
|
45
|
+
this.#db = new __sqlite.SqliteDatabase(db);
|
|
46
|
+
this.#initialized = options.initialized ?? false;
|
|
47
|
+
this.#tableName = options.tableName ?? SqliteKvStore.#defaultTableName;
|
|
48
|
+
if (!SqliteKvStore.#tableNameRegex.test(this.#tableName)) throw new Error(`Invalid table name for the key–value store: ${this.#tableName}`);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* {@inheritDoc KvStore.get}
|
|
52
|
+
*/
|
|
53
|
+
async get(key) {
|
|
54
|
+
this.initialize();
|
|
55
|
+
const encodedKey = this.#encodeKey(key);
|
|
56
|
+
const now = Temporal.Now.instant().epochMilliseconds;
|
|
57
|
+
const result = this.#db.prepare(`
|
|
58
|
+
SELECT value
|
|
59
|
+
FROM "${this.#tableName}"
|
|
60
|
+
WHERE key = ? AND (expires IS NULL OR expires > ?)
|
|
61
|
+
`).get(encodedKey, now);
|
|
62
|
+
if (!result) return void 0;
|
|
63
|
+
return this.#decodeValue(result.value);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* {@inheritDoc KvStore.set}
|
|
67
|
+
*/
|
|
68
|
+
async set(key, value, options) {
|
|
69
|
+
this.initialize();
|
|
70
|
+
if (value === void 0) return;
|
|
71
|
+
const encodedKey = this.#encodeKey(key);
|
|
72
|
+
const encodedValue = this.#encodeValue(value);
|
|
73
|
+
const now = Temporal.Now.instant().epochMilliseconds;
|
|
74
|
+
const expiresAt = options?.ttl !== void 0 ? now + options.ttl.total({ unit: "milliseconds" }) : null;
|
|
75
|
+
this.#db.prepare(`INSERT INTO "${this.#tableName}" (key, value, created, expires)
|
|
76
|
+
VALUES (?, ?, ?, ?)
|
|
77
|
+
ON CONFLICT(key) DO UPDATE SET
|
|
78
|
+
value = excluded.value,
|
|
79
|
+
expires = excluded.expires`).run(encodedKey, encodedValue, now, expiresAt);
|
|
80
|
+
this.#expire();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* {@inheritDoc KvStore.delete}
|
|
85
|
+
*/
|
|
86
|
+
async delete(key) {
|
|
87
|
+
this.initialize();
|
|
88
|
+
const encodedKey = this.#encodeKey(key);
|
|
89
|
+
this.#db.prepare(`
|
|
90
|
+
DELETE FROM "${this.#tableName}" WHERE key = ?
|
|
91
|
+
`).run(encodedKey);
|
|
92
|
+
this.#expire();
|
|
93
|
+
return Promise.resolve();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* {@inheritDoc KvStore.cas}
|
|
97
|
+
*/
|
|
98
|
+
async cas(key, expectedValue, newValue, options) {
|
|
99
|
+
this.initialize();
|
|
100
|
+
const encodedKey = this.#encodeKey(key);
|
|
101
|
+
const now = Temporal.Now.instant().epochMilliseconds;
|
|
102
|
+
const expiresAt = options?.ttl !== void 0 ? now + options.ttl.total({ unit: "milliseconds" }) : null;
|
|
103
|
+
try {
|
|
104
|
+
this.#db.exec("BEGIN IMMEDIATE");
|
|
105
|
+
const currentResult = this.#db.prepare(`
|
|
106
|
+
SELECT value
|
|
107
|
+
FROM "${this.#tableName}"
|
|
108
|
+
WHERE key = ? AND (expires IS NULL OR expires > ?)
|
|
109
|
+
`).get(encodedKey, now);
|
|
110
|
+
const currentValue = currentResult === void 0 ? void 0 : this.#decodeValue(currentResult.value);
|
|
111
|
+
if (!(0, es_toolkit.isEqual)(currentValue, expectedValue)) {
|
|
112
|
+
this.#db.exec("ROLLBACK");
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
if (newValue === void 0) this.#db.prepare(`
|
|
116
|
+
DELETE FROM "${this.#tableName}" WHERE key = ?
|
|
117
|
+
`).run(encodedKey);
|
|
118
|
+
else {
|
|
119
|
+
const newValueJson = this.#encodeValue(newValue);
|
|
120
|
+
this.#db.prepare(`
|
|
121
|
+
INSERT INTO "${this.#tableName}" (key, value, created, expires)
|
|
122
|
+
VALUES (?, ?, ?, ?)
|
|
123
|
+
ON CONFLICT(key) DO UPDATE SET
|
|
124
|
+
value = excluded.value,
|
|
125
|
+
expires = excluded.expires
|
|
126
|
+
`).run(encodedKey, newValueJson, now, expiresAt);
|
|
127
|
+
}
|
|
128
|
+
this.#db.exec("COMMIT");
|
|
129
|
+
this.#expire();
|
|
130
|
+
return true;
|
|
131
|
+
} catch (error) {
|
|
132
|
+
this.#db.exec("ROLLBACK");
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Creates the table used by the key–value store if it does not already exist.
|
|
138
|
+
* Does nothing if the table already exists.
|
|
139
|
+
*/
|
|
140
|
+
initialize() {
|
|
141
|
+
if (this.#initialized) return;
|
|
142
|
+
logger.debug("Initializing the key–value store table {tableName}...", { tableName: this.#tableName });
|
|
143
|
+
this.#db.exec(`
|
|
144
|
+
CREATE TABLE IF NOT EXISTS "${this.#tableName}" (
|
|
145
|
+
key TEXT PRIMARY KEY,
|
|
146
|
+
value TEXT NOT NULL,
|
|
147
|
+
created INTEGER NOT NULL,
|
|
148
|
+
expires INTEGER
|
|
149
|
+
)
|
|
150
|
+
`);
|
|
151
|
+
this.#db.exec(`
|
|
152
|
+
CREATE INDEX IF NOT EXISTS "idx_${this.#tableName}_expires"
|
|
153
|
+
ON "${this.#tableName}" (expires)
|
|
154
|
+
`);
|
|
155
|
+
this.#initialized = true;
|
|
156
|
+
logger.debug("Initialized the key–value store table {tableName}.", { tableName: this.#tableName });
|
|
157
|
+
}
|
|
158
|
+
#expire() {
|
|
159
|
+
const now = Temporal.Now.instant().epochMilliseconds;
|
|
160
|
+
this.#db.prepare(`
|
|
161
|
+
DELETE FROM "${this.#tableName}"
|
|
162
|
+
WHERE expires IS NOT NULL AND expires <= ?
|
|
163
|
+
`).run(now);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Drops the table used by the key–value store. Does nothing if the table
|
|
167
|
+
* does not exist.
|
|
168
|
+
*/
|
|
169
|
+
drop() {
|
|
170
|
+
this.#db.exec(`DROP TABLE IF EXISTS "${this.#tableName}"`);
|
|
171
|
+
this.#initialized = false;
|
|
172
|
+
}
|
|
173
|
+
#encodeKey(key) {
|
|
174
|
+
return JSON.stringify(key);
|
|
175
|
+
}
|
|
176
|
+
#decodeKey(key) {
|
|
177
|
+
return JSON.parse(key);
|
|
178
|
+
}
|
|
179
|
+
#encodeValue(value) {
|
|
180
|
+
return JSON.stringify(value);
|
|
181
|
+
}
|
|
182
|
+
#decodeValue(value) {
|
|
183
|
+
return JSON.parse(value);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
//#endregion
|
|
188
|
+
exports.SqliteKvStore = SqliteKvStore;
|
package/dist/kv.d.cts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { DatabaseSync } from "./dist/sqlite.node.cjs";
|
|
2
|
+
import { KvKey, KvStore, KvStoreSetOptions } from "@fedify/fedify";
|
|
3
|
+
|
|
4
|
+
//#region src/kv.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Options for the SQLite key–value store.
|
|
7
|
+
*/
|
|
8
|
+
interface SqliteKvStoreOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The table name to use for the key–value store.
|
|
11
|
+
* Only letters, digits, and underscores are allowed.
|
|
12
|
+
* `"fedify_kv"` by default.
|
|
13
|
+
* @default `"fedify_kv"`
|
|
14
|
+
*/
|
|
15
|
+
tableName?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the table has been initialized. `false` by default.
|
|
18
|
+
* @default `false`
|
|
19
|
+
*/
|
|
20
|
+
initialized?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A key–value store that uses SQLite as the underlying storage.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { createFederation } from "@fedify/fedify";
|
|
28
|
+
* import { SqliteKvStore } from "@fedify/sqlite";
|
|
29
|
+
* import { DatabaseSync } from "node:sqlite";
|
|
30
|
+
*
|
|
31
|
+
* const db = new DatabaseSync(":memory:");
|
|
32
|
+
* const federation = createFederation({
|
|
33
|
+
* // ...
|
|
34
|
+
* kv: new SqliteKvStore(db),
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
declare class SqliteKvStore implements KvStore {
|
|
39
|
+
#private;
|
|
40
|
+
readonly db: DatabaseSync;
|
|
41
|
+
readonly options: SqliteKvStoreOptions;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new SQLite key–value store.
|
|
44
|
+
* @param db The SQLite database to use. Supports `node:sqlite` and `bun:sqlite`.
|
|
45
|
+
* @param options The options for the key–value store.
|
|
46
|
+
*/
|
|
47
|
+
constructor(db: DatabaseSync, options?: SqliteKvStoreOptions);
|
|
48
|
+
/**
|
|
49
|
+
* {@inheritDoc KvStore.get}
|
|
50
|
+
*/
|
|
51
|
+
get<T = unknown>(key: KvKey): Promise<T | undefined>;
|
|
52
|
+
/**
|
|
53
|
+
* {@inheritDoc KvStore.set}
|
|
54
|
+
*/
|
|
55
|
+
set(key: KvKey, value: unknown, options?: KvStoreSetOptions): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* {@inheritDoc KvStore.delete}
|
|
58
|
+
*/
|
|
59
|
+
delete(key: KvKey): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* {@inheritDoc KvStore.cas}
|
|
62
|
+
*/
|
|
63
|
+
cas(key: KvKey, expectedValue: unknown, newValue: unknown, options?: KvStoreSetOptions): Promise<boolean>;
|
|
64
|
+
/**
|
|
65
|
+
* Creates the table used by the key–value store if it does not already exist.
|
|
66
|
+
* Does nothing if the table already exists.
|
|
67
|
+
*/
|
|
68
|
+
initialize(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Drops the table used by the key–value store. Does nothing if the table
|
|
71
|
+
* does not exist.
|
|
72
|
+
*/
|
|
73
|
+
drop(): void;
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
export { SqliteKvStore, SqliteKvStoreOptions };
|
package/dist/kv.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { qi } from "./node_modules/.pnpm/@js-temporal_polyfill@0.5.1/node_modules/@js-temporal/polyfill/dist/index.esm.js";
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
|
|
5
4
|
import { SqliteDatabase } from "#sqlite";
|
|
6
5
|
import { getLogger } from "@logtape/logtape";
|
|
7
6
|
import { isEqual } from "es-toolkit";
|
|
@@ -53,10 +52,10 @@ var SqliteKvStore = class SqliteKvStore {
|
|
|
53
52
|
async get(key) {
|
|
54
53
|
this.initialize();
|
|
55
54
|
const encodedKey = this.#encodeKey(key);
|
|
56
|
-
const now =
|
|
55
|
+
const now = Temporal.Now.instant().epochMilliseconds;
|
|
57
56
|
const result = this.#db.prepare(`
|
|
58
|
-
SELECT value
|
|
59
|
-
FROM "${this.#tableName}"
|
|
57
|
+
SELECT value
|
|
58
|
+
FROM "${this.#tableName}"
|
|
60
59
|
WHERE key = ? AND (expires IS NULL OR expires > ?)
|
|
61
60
|
`).get(encodedKey, now);
|
|
62
61
|
if (!result) return void 0;
|
|
@@ -70,7 +69,7 @@ var SqliteKvStore = class SqliteKvStore {
|
|
|
70
69
|
if (value === void 0) return;
|
|
71
70
|
const encodedKey = this.#encodeKey(key);
|
|
72
71
|
const encodedValue = this.#encodeValue(value);
|
|
73
|
-
const now =
|
|
72
|
+
const now = Temporal.Now.instant().epochMilliseconds;
|
|
74
73
|
const expiresAt = options?.ttl !== void 0 ? now + options.ttl.total({ unit: "milliseconds" }) : null;
|
|
75
74
|
this.#db.prepare(`INSERT INTO "${this.#tableName}" (key, value, created, expires)
|
|
76
75
|
VALUES (?, ?, ?, ?)
|
|
@@ -98,13 +97,13 @@ var SqliteKvStore = class SqliteKvStore {
|
|
|
98
97
|
async cas(key, expectedValue, newValue, options) {
|
|
99
98
|
this.initialize();
|
|
100
99
|
const encodedKey = this.#encodeKey(key);
|
|
101
|
-
const now =
|
|
100
|
+
const now = Temporal.Now.instant().epochMilliseconds;
|
|
102
101
|
const expiresAt = options?.ttl !== void 0 ? now + options.ttl.total({ unit: "milliseconds" }) : null;
|
|
103
102
|
try {
|
|
104
103
|
this.#db.exec("BEGIN IMMEDIATE");
|
|
105
104
|
const currentResult = this.#db.prepare(`
|
|
106
|
-
SELECT value
|
|
107
|
-
FROM "${this.#tableName}"
|
|
105
|
+
SELECT value
|
|
106
|
+
FROM "${this.#tableName}"
|
|
108
107
|
WHERE key = ? AND (expires IS NULL OR expires > ?)
|
|
109
108
|
`).get(encodedKey, now);
|
|
110
109
|
const currentValue = currentResult === void 0 ? void 0 : this.#decodeValue(currentResult.value);
|
|
@@ -149,14 +148,14 @@ var SqliteKvStore = class SqliteKvStore {
|
|
|
149
148
|
)
|
|
150
149
|
`);
|
|
151
150
|
this.#db.exec(`
|
|
152
|
-
CREATE INDEX IF NOT EXISTS "idx_${this.#tableName}_expires"
|
|
151
|
+
CREATE INDEX IF NOT EXISTS "idx_${this.#tableName}_expires"
|
|
153
152
|
ON "${this.#tableName}" (expires)
|
|
154
153
|
`);
|
|
155
154
|
this.#initialized = true;
|
|
156
155
|
logger.debug("Initialized the key–value store table {tableName}.", { tableName: this.#tableName });
|
|
157
156
|
}
|
|
158
157
|
#expire() {
|
|
159
|
-
const now =
|
|
158
|
+
const now = Temporal.Now.instant().epochMilliseconds;
|
|
160
159
|
this.#db.prepare(`
|
|
161
160
|
DELETE FROM "${this.#tableName}"
|
|
162
161
|
WHERE expires IS NOT NULL AND expires <= ?
|
package/dist/mod.cjs
ADDED
package/dist/mod.d.cts
ADDED
package/dist/mod.js
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
const { Temporal } = require("@js-temporal/polyfill");
|
|
3
|
+
|
|
4
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
5
|
+
const bun_sqlite = require_rolldown_runtime.__toESM(require("bun:sqlite"));
|
|
6
|
+
|
|
7
|
+
//#region src/sqlite.bun.ts
|
|
8
|
+
var SqliteDatabase = class {
|
|
9
|
+
constructor(db) {
|
|
10
|
+
this.db = db;
|
|
11
|
+
}
|
|
12
|
+
prepare(sql) {
|
|
13
|
+
return new SqliteStatement(this.db.query(sql));
|
|
14
|
+
}
|
|
15
|
+
exec(sql) {
|
|
16
|
+
this.db.exec(sql);
|
|
17
|
+
}
|
|
18
|
+
close() {
|
|
19
|
+
this.db.close(false);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var SqliteStatement = class {
|
|
23
|
+
constructor(stmt) {
|
|
24
|
+
this.stmt = stmt;
|
|
25
|
+
}
|
|
26
|
+
run(...params) {
|
|
27
|
+
return this.stmt.run(...params);
|
|
28
|
+
}
|
|
29
|
+
get(...params) {
|
|
30
|
+
const result = this.stmt.get(...params);
|
|
31
|
+
if (result === null) return void 0;
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
all(...params) {
|
|
35
|
+
return this.stmt.all(...params);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
exports.PlatformDatabase = bun_sqlite.Database;
|
|
41
|
+
exports.SqliteDatabase = SqliteDatabase;
|
|
42
|
+
exports.SqliteStatement = SqliteStatement;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SqliteDatabaseAdapter, SqliteStatementAdapter } from "./adapter.cjs";
|
|
2
|
+
import { Database, Statement } from "bun:sqlite";
|
|
3
|
+
|
|
4
|
+
//#region src/sqlite.bun.d.ts
|
|
5
|
+
declare class SqliteDatabase implements SqliteDatabaseAdapter {
|
|
6
|
+
private readonly db;
|
|
7
|
+
constructor(db: Database);
|
|
8
|
+
prepare(sql: string): SqliteStatementAdapter;
|
|
9
|
+
exec(sql: string): void;
|
|
10
|
+
close(): void;
|
|
11
|
+
}
|
|
12
|
+
declare class SqliteStatement implements SqliteStatementAdapter {
|
|
13
|
+
private readonly stmt;
|
|
14
|
+
constructor(stmt: Statement);
|
|
15
|
+
run(...params: unknown[]): {
|
|
16
|
+
changes: number;
|
|
17
|
+
lastInsertRowid: number;
|
|
18
|
+
};
|
|
19
|
+
get(...params: unknown[]): unknown | undefined;
|
|
20
|
+
all(...params: unknown[]): unknown[];
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { Database as PlatformDatabase, Statement as PlatformStatement, SqliteDatabase, SqliteStatement };
|
package/dist/sqlite.bun.js
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
const { Temporal } = require("@js-temporal/polyfill");
|
|
3
|
+
|
|
4
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
5
|
+
const node_sqlite = require_rolldown_runtime.__toESM(require("node:sqlite"));
|
|
6
|
+
|
|
7
|
+
//#region src/sqlite.node.ts
|
|
8
|
+
var SqliteDatabase = class {
|
|
9
|
+
constructor(db) {
|
|
10
|
+
this.db = db;
|
|
11
|
+
}
|
|
12
|
+
prepare(sql) {
|
|
13
|
+
return new SqliteStatement(this.db.prepare(sql));
|
|
14
|
+
}
|
|
15
|
+
exec(sql) {
|
|
16
|
+
this.db.exec(sql);
|
|
17
|
+
}
|
|
18
|
+
close() {
|
|
19
|
+
this.db.close();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var SqliteStatement = class {
|
|
23
|
+
constructor(stmt) {
|
|
24
|
+
this.stmt = stmt;
|
|
25
|
+
}
|
|
26
|
+
run(...params) {
|
|
27
|
+
const result = this.stmt.run(...params);
|
|
28
|
+
return {
|
|
29
|
+
changes: Number(result.changes),
|
|
30
|
+
lastInsertRowid: Number(result.lastInsertRowid)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
get(...params) {
|
|
34
|
+
return this.stmt.get(...params);
|
|
35
|
+
}
|
|
36
|
+
all(...params) {
|
|
37
|
+
return this.stmt.all(...params);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
exports.PlatformDatabase = node_sqlite.DatabaseSync;
|
|
43
|
+
exports.SqliteDatabase = SqliteDatabase;
|
|
44
|
+
exports.SqliteStatement = SqliteStatement;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SqliteDatabaseAdapter, SqliteStatementAdapter } from "./adapter.cjs";
|
|
2
|
+
import { DatabaseSync, StatementSync } from "node:sqlite";
|
|
3
|
+
|
|
4
|
+
//#region src/sqlite.node.d.ts
|
|
5
|
+
declare class SqliteDatabase implements SqliteDatabaseAdapter {
|
|
6
|
+
private readonly db;
|
|
7
|
+
constructor(db: DatabaseSync);
|
|
8
|
+
prepare(sql: string): SqliteStatementAdapter;
|
|
9
|
+
exec(sql: string): void;
|
|
10
|
+
close(): void;
|
|
11
|
+
}
|
|
12
|
+
declare class SqliteStatement implements SqliteStatementAdapter {
|
|
13
|
+
private readonly stmt;
|
|
14
|
+
constructor(stmt: StatementSync);
|
|
15
|
+
run(...params: unknown[]): {
|
|
16
|
+
changes: number;
|
|
17
|
+
lastInsertRowid: number;
|
|
18
|
+
};
|
|
19
|
+
get(...params: unknown[]): unknown | undefined;
|
|
20
|
+
all(...params: unknown[]): unknown[];
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { DatabaseSync as PlatformDatabase, StatementSync as PlatformStatement, SqliteDatabase, SqliteStatement };
|
package/dist/sqlite.node.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/sqlite",
|
|
3
|
-
"version": "2.0.0-pr.412.
|
|
3
|
+
"version": "2.0.0-pr.412.1794+5c393341",
|
|
4
4
|
"description": "SQLite drivers for Fedify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fedify",
|
|
@@ -22,18 +22,28 @@
|
|
|
22
22
|
"https://github.com/sponsors/dahlia"
|
|
23
23
|
],
|
|
24
24
|
"type": "module",
|
|
25
|
-
"main": "./dist/mod.
|
|
25
|
+
"main": "./dist/mod.cjs",
|
|
26
26
|
"module": "./dist/mod.js",
|
|
27
27
|
"types": "./dist/mod.d.ts",
|
|
28
28
|
"exports": {
|
|
29
29
|
".": {
|
|
30
|
-
"types":
|
|
30
|
+
"types": {
|
|
31
|
+
"import": "./dist/mod.d.ts",
|
|
32
|
+
"require": "./dist/mod.d.cts",
|
|
33
|
+
"default": "./dist/mod.d.ts"
|
|
34
|
+
},
|
|
31
35
|
"import": "./dist/mod.js",
|
|
36
|
+
"require": "./dist/mod.cjs",
|
|
32
37
|
"default": "./dist/mod.js"
|
|
33
38
|
},
|
|
34
39
|
"./kv": {
|
|
35
|
-
"types":
|
|
40
|
+
"types": {
|
|
41
|
+
"import": "./dist/kv.d.ts",
|
|
42
|
+
"require": "./dist/kv.d.cts",
|
|
43
|
+
"default": "./dist/kv.d.ts"
|
|
44
|
+
},
|
|
36
45
|
"import": "./dist/kv.js",
|
|
46
|
+
"require": "./dist/kv.cjs",
|
|
37
47
|
"default": "./dist/kv.js"
|
|
38
48
|
},
|
|
39
49
|
"./package.json": "./package.json"
|
|
@@ -47,14 +57,14 @@
|
|
|
47
57
|
}
|
|
48
58
|
},
|
|
49
59
|
"dependencies": {
|
|
50
|
-
"@
|
|
60
|
+
"@js-temporal/polyfill": "^0.5.1",
|
|
61
|
+
"@logtape/logtape": "^1.1.1",
|
|
51
62
|
"es-toolkit": "^1.31.0"
|
|
52
63
|
},
|
|
53
64
|
"peerDependencies": {
|
|
54
|
-
"@fedify/fedify": "2.0.0-pr.412.
|
|
65
|
+
"@fedify/fedify": "^2.0.0-pr.412.1794+5c393341"
|
|
55
66
|
},
|
|
56
67
|
"devDependencies": {
|
|
57
|
-
"@js-temporal/polyfill": "^0.5.1",
|
|
58
68
|
"@std/async": "npm:@jsr/std__async@^1.0.13",
|
|
59
69
|
"tsdown": "^0.12.9",
|
|
60
70
|
"typescript": "^5.9.2"
|