@fedify/sqlite 2.0.0-pr.451.1731 → 2.0.0-pr.457.1754
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/kv.cjs +9 -10
- package/dist/kv.js +5 -6
- package/package.json +2 -2
- package/src/kv.test.ts +3 -3
- package/src/kv.ts +5 -6
package/deno.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/sqlite",
|
|
3
|
-
"version": "2.0.0-pr.
|
|
3
|
+
"version": "2.0.0-pr.457.1754+e2ece3ba",
|
|
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": [
|
package/dist/kv.cjs
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
5
5
|
const __sqlite = require_rolldown_runtime.__toESM(require("#sqlite"));
|
|
6
|
-
const __js_temporal_polyfill = require_rolldown_runtime.__toESM(require("@js-temporal/polyfill"));
|
|
7
6
|
const __logtape_logtape = require_rolldown_runtime.__toESM(require("@logtape/logtape"));
|
|
8
7
|
const es_toolkit = require_rolldown_runtime.__toESM(require("es-toolkit"));
|
|
9
8
|
|
|
@@ -54,10 +53,10 @@ var SqliteKvStore = class SqliteKvStore {
|
|
|
54
53
|
async get(key) {
|
|
55
54
|
this.initialize();
|
|
56
55
|
const encodedKey = this.#encodeKey(key);
|
|
57
|
-
const now =
|
|
56
|
+
const now = Temporal.Now.instant().epochMilliseconds;
|
|
58
57
|
const result = this.#db.prepare(`
|
|
59
|
-
SELECT value
|
|
60
|
-
FROM "${this.#tableName}"
|
|
58
|
+
SELECT value
|
|
59
|
+
FROM "${this.#tableName}"
|
|
61
60
|
WHERE key = ? AND (expires IS NULL OR expires > ?)
|
|
62
61
|
`).get(encodedKey, now);
|
|
63
62
|
if (!result) return void 0;
|
|
@@ -71,7 +70,7 @@ var SqliteKvStore = class SqliteKvStore {
|
|
|
71
70
|
if (value === void 0) return;
|
|
72
71
|
const encodedKey = this.#encodeKey(key);
|
|
73
72
|
const encodedValue = this.#encodeValue(value);
|
|
74
|
-
const now =
|
|
73
|
+
const now = Temporal.Now.instant().epochMilliseconds;
|
|
75
74
|
const expiresAt = options?.ttl !== void 0 ? now + options.ttl.total({ unit: "milliseconds" }) : null;
|
|
76
75
|
this.#db.prepare(`INSERT INTO "${this.#tableName}" (key, value, created, expires)
|
|
77
76
|
VALUES (?, ?, ?, ?)
|
|
@@ -99,13 +98,13 @@ var SqliteKvStore = class SqliteKvStore {
|
|
|
99
98
|
async cas(key, expectedValue, newValue, options) {
|
|
100
99
|
this.initialize();
|
|
101
100
|
const encodedKey = this.#encodeKey(key);
|
|
102
|
-
const now =
|
|
101
|
+
const now = Temporal.Now.instant().epochMilliseconds;
|
|
103
102
|
const expiresAt = options?.ttl !== void 0 ? now + options.ttl.total({ unit: "milliseconds" }) : null;
|
|
104
103
|
try {
|
|
105
104
|
this.#db.exec("BEGIN IMMEDIATE");
|
|
106
105
|
const currentResult = this.#db.prepare(`
|
|
107
|
-
SELECT value
|
|
108
|
-
FROM "${this.#tableName}"
|
|
106
|
+
SELECT value
|
|
107
|
+
FROM "${this.#tableName}"
|
|
109
108
|
WHERE key = ? AND (expires IS NULL OR expires > ?)
|
|
110
109
|
`).get(encodedKey, now);
|
|
111
110
|
const currentValue = currentResult === void 0 ? void 0 : this.#decodeValue(currentResult.value);
|
|
@@ -150,14 +149,14 @@ var SqliteKvStore = class SqliteKvStore {
|
|
|
150
149
|
)
|
|
151
150
|
`);
|
|
152
151
|
this.#db.exec(`
|
|
153
|
-
CREATE INDEX IF NOT EXISTS "idx_${this.#tableName}_expires"
|
|
152
|
+
CREATE INDEX IF NOT EXISTS "idx_${this.#tableName}_expires"
|
|
154
153
|
ON "${this.#tableName}" (expires)
|
|
155
154
|
`);
|
|
156
155
|
this.#initialized = true;
|
|
157
156
|
logger.debug("Initialized the key–value store table {tableName}.", { tableName: this.#tableName });
|
|
158
157
|
}
|
|
159
158
|
#expire() {
|
|
160
|
-
const now =
|
|
159
|
+
const now = Temporal.Now.instant().epochMilliseconds;
|
|
161
160
|
this.#db.prepare(`
|
|
162
161
|
DELETE FROM "${this.#tableName}"
|
|
163
162
|
WHERE expires IS NOT NULL AND expires <= ?
|
package/dist/kv.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { Temporal } from "@js-temporal/polyfill";
|
|
3
3
|
|
|
4
4
|
import { SqliteDatabase } from "#sqlite";
|
|
5
|
-
import { Temporal } from "@js-temporal/polyfill";
|
|
6
5
|
import { getLogger } from "@logtape/logtape";
|
|
7
6
|
import { isEqual } from "es-toolkit";
|
|
8
7
|
|
|
@@ -55,8 +54,8 @@ var SqliteKvStore = class SqliteKvStore {
|
|
|
55
54
|
const encodedKey = this.#encodeKey(key);
|
|
56
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;
|
|
@@ -103,8 +102,8 @@ var SqliteKvStore = class SqliteKvStore {
|
|
|
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,7 +148,7 @@ 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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/sqlite",
|
|
3
|
-
"version": "2.0.0-pr.
|
|
3
|
+
"version": "2.0.0-pr.457.1754+e2ece3ba",
|
|
4
4
|
"description": "SQLite drivers for Fedify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fedify",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"es-toolkit": "^1.31.0"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"@fedify/fedify": "^2.0.0-pr.
|
|
65
|
+
"@fedify/fedify": "^2.0.0-pr.457.1754+e2ece3ba"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@std/async": "npm:@jsr/std__async@^1.0.13",
|
package/src/kv.test.ts
CHANGED
|
@@ -3,7 +3,7 @@ import * as temporal from "@js-temporal/polyfill";
|
|
|
3
3
|
import { delay } from "@std/async/delay";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { test } from "node:test";
|
|
6
|
-
import { SqliteKvStore } from "
|
|
6
|
+
import { SqliteKvStore } from "@fedify/sqlite/kv";
|
|
7
7
|
|
|
8
8
|
let Temporal: typeof temporal.Temporal;
|
|
9
9
|
if ("Temporal" in globalThis) {
|
|
@@ -31,7 +31,7 @@ test("SqliteKvStore.initialize()", async () => {
|
|
|
31
31
|
try {
|
|
32
32
|
await store.initialize();
|
|
33
33
|
const result = await db.prepare(`
|
|
34
|
-
SELECT name FROM sqlite_master
|
|
34
|
+
SELECT name FROM sqlite_master
|
|
35
35
|
WHERE type='table' AND name=?
|
|
36
36
|
`).get(tableName);
|
|
37
37
|
assert(result !== undefined);
|
|
@@ -180,7 +180,7 @@ test("SqliteKvStore.drop()", async () => {
|
|
|
180
180
|
try {
|
|
181
181
|
await store.drop();
|
|
182
182
|
const result = await db.prepare(`
|
|
183
|
-
SELECT name FROM sqlite_master
|
|
183
|
+
SELECT name FROM sqlite_master
|
|
184
184
|
WHERE type='table' AND name=?
|
|
185
185
|
`).get(tableName);
|
|
186
186
|
// Bun returns null, Node returns undefined
|
package/src/kv.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type PlatformDatabase, SqliteDatabase } from "#sqlite";
|
|
2
2
|
import type { KvKey, KvStore, KvStoreSetOptions } from "@fedify/fedify";
|
|
3
|
-
import { Temporal } from "@js-temporal/polyfill";
|
|
4
3
|
import { getLogger } from "@logtape/logtape";
|
|
5
4
|
import { isEqual } from "es-toolkit";
|
|
6
5
|
import type { SqliteDatabaseAdapter } from "./adapter.ts";
|
|
@@ -81,8 +80,8 @@ export class SqliteKvStore implements KvStore {
|
|
|
81
80
|
|
|
82
81
|
const result = this.#db
|
|
83
82
|
.prepare(`
|
|
84
|
-
SELECT value
|
|
85
|
-
FROM "${this.#tableName}"
|
|
83
|
+
SELECT value
|
|
84
|
+
FROM "${this.#tableName}"
|
|
86
85
|
WHERE key = ? AND (expires IS NULL OR expires > ?)
|
|
87
86
|
`)
|
|
88
87
|
.get(encodedKey, now);
|
|
@@ -170,8 +169,8 @@ export class SqliteKvStore implements KvStore {
|
|
|
170
169
|
|
|
171
170
|
const currentResult = this.#db
|
|
172
171
|
.prepare(`
|
|
173
|
-
SELECT value
|
|
174
|
-
FROM "${this.#tableName}"
|
|
172
|
+
SELECT value
|
|
173
|
+
FROM "${this.#tableName}"
|
|
175
174
|
WHERE key = ? AND (expires IS NULL OR expires > ?)
|
|
176
175
|
`)
|
|
177
176
|
.get(encodedKey, now) as { value: string } | undefined;
|
|
@@ -236,7 +235,7 @@ export class SqliteKvStore implements KvStore {
|
|
|
236
235
|
`);
|
|
237
236
|
|
|
238
237
|
this.#db.exec(`
|
|
239
|
-
CREATE INDEX IF NOT EXISTS "idx_${this.#tableName}_expires"
|
|
238
|
+
CREATE INDEX IF NOT EXISTS "idx_${this.#tableName}_expires"
|
|
240
239
|
ON "${this.#tableName}" (expires)
|
|
241
240
|
`);
|
|
242
241
|
|