@fedify/sqlite 2.2.0 → 2.3.0-dev.1013
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 -1
- package/dist/mq.cjs +18 -0
- package/dist/mq.d.cts +5 -1
- package/dist/mq.d.ts +5 -1
- package/dist/mq.js +18 -0
- package/package.json +3 -3
- package/src/mq.test.ts +30 -0
- package/src/mq.ts +24 -0
package/deno.json
CHANGED
package/dist/mq.cjs
CHANGED
|
@@ -150,6 +150,24 @@ var SqliteMessageQueue = class SqliteMessageQueue {
|
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
152
|
/**
|
|
153
|
+
* {@inheritDoc MessageQueue.getDepth}
|
|
154
|
+
*/
|
|
155
|
+
async getDepth() {
|
|
156
|
+
this.initialize();
|
|
157
|
+
const row = await this.#retryOnBusy(() => {
|
|
158
|
+
const now = Temporal.Now.instant().epochMilliseconds;
|
|
159
|
+
return this.#db.prepare(`SELECT
|
|
160
|
+
COUNT(*) AS queued,
|
|
161
|
+
COALESCE(SUM(CASE WHEN scheduled <= ? THEN 1 ELSE 0 END), 0) AS ready
|
|
162
|
+
FROM "${this.#tableName}"`).get(now);
|
|
163
|
+
});
|
|
164
|
+
return {
|
|
165
|
+
queued: row.queued,
|
|
166
|
+
ready: row.ready,
|
|
167
|
+
delayed: Math.max(0, row.queued - row.ready)
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
153
171
|
* {@inheritDoc MessageQueue.listen}
|
|
154
172
|
*/
|
|
155
173
|
async listen(handler, options) {
|
package/dist/mq.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PlatformDatabase } from "#sqlite";
|
|
2
|
-
import { MessageQueue, MessageQueueEnqueueOptions, MessageQueueListenOptions } from "@fedify/fedify";
|
|
2
|
+
import { MessageQueue, MessageQueueDepth, MessageQueueEnqueueOptions, MessageQueueListenOptions } from "@fedify/fedify";
|
|
3
3
|
|
|
4
4
|
//#region src/mq.d.ts
|
|
5
5
|
/**
|
|
@@ -86,6 +86,10 @@ declare class SqliteMessageQueue implements MessageQueue, Disposable {
|
|
|
86
86
|
*/
|
|
87
87
|
enqueueMany(messages: readonly any[], options?: MessageQueueEnqueueOptions): Promise<void>;
|
|
88
88
|
/**
|
|
89
|
+
* {@inheritDoc MessageQueue.getDepth}
|
|
90
|
+
*/
|
|
91
|
+
getDepth(): Promise<MessageQueueDepth>;
|
|
92
|
+
/**
|
|
89
93
|
* {@inheritDoc MessageQueue.listen}
|
|
90
94
|
*/
|
|
91
95
|
listen(handler: (message: any) => Promise<void> | void, options?: MessageQueueListenOptions): Promise<void>;
|
package/dist/mq.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { PlatformDatabase } from "#sqlite";
|
|
3
|
-
import { MessageQueue, MessageQueueEnqueueOptions, MessageQueueListenOptions } from "@fedify/fedify";
|
|
3
|
+
import { MessageQueue, MessageQueueDepth, MessageQueueEnqueueOptions, MessageQueueListenOptions } from "@fedify/fedify";
|
|
4
4
|
|
|
5
5
|
//#region src/mq.d.ts
|
|
6
6
|
/**
|
|
@@ -87,6 +87,10 @@ declare class SqliteMessageQueue implements MessageQueue, Disposable {
|
|
|
87
87
|
*/
|
|
88
88
|
enqueueMany(messages: readonly any[], options?: MessageQueueEnqueueOptions): Promise<void>;
|
|
89
89
|
/**
|
|
90
|
+
* {@inheritDoc MessageQueue.getDepth}
|
|
91
|
+
*/
|
|
92
|
+
getDepth(): Promise<MessageQueueDepth>;
|
|
93
|
+
/**
|
|
90
94
|
* {@inheritDoc MessageQueue.listen}
|
|
91
95
|
*/
|
|
92
96
|
listen(handler: (message: any) => Promise<void> | void, options?: MessageQueueListenOptions): Promise<void>;
|
package/dist/mq.js
CHANGED
|
@@ -150,6 +150,24 @@ var SqliteMessageQueue = class SqliteMessageQueue {
|
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
152
|
/**
|
|
153
|
+
* {@inheritDoc MessageQueue.getDepth}
|
|
154
|
+
*/
|
|
155
|
+
async getDepth() {
|
|
156
|
+
this.initialize();
|
|
157
|
+
const row = await this.#retryOnBusy(() => {
|
|
158
|
+
const now = Temporal.Now.instant().epochMilliseconds;
|
|
159
|
+
return this.#db.prepare(`SELECT
|
|
160
|
+
COUNT(*) AS queued,
|
|
161
|
+
COALESCE(SUM(CASE WHEN scheduled <= ? THEN 1 ELSE 0 END), 0) AS ready
|
|
162
|
+
FROM "${this.#tableName}"`).get(now);
|
|
163
|
+
});
|
|
164
|
+
return {
|
|
165
|
+
queued: row.queued,
|
|
166
|
+
ready: row.ready,
|
|
167
|
+
delayed: Math.max(0, row.queued - row.ready)
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
153
171
|
* {@inheritDoc MessageQueue.listen}
|
|
154
172
|
*/
|
|
155
173
|
async listen(handler, options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/sqlite",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0-dev.1013+4aa6a88c",
|
|
4
4
|
"description": "SQLite drivers for Fedify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fedify",
|
|
@@ -72,13 +72,13 @@
|
|
|
72
72
|
"es-toolkit": "^1.31.0"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
|
-
"@fedify/fedify": "^2.
|
|
75
|
+
"@fedify/fedify": "^2.3.0-dev.1013+4aa6a88c"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@std/async": "npm:@jsr/std__async@^1.0.13",
|
|
79
79
|
"tsdown": "^0.21.6",
|
|
80
80
|
"typescript": "^5.9.2",
|
|
81
|
-
"@fedify/testing": "^2.
|
|
81
|
+
"@fedify/testing": "^2.3.0-dev.1013+4aa6a88c"
|
|
82
82
|
},
|
|
83
83
|
"scripts": {
|
|
84
84
|
"build:self": "tsdown",
|
package/src/mq.test.ts
CHANGED
|
@@ -2,10 +2,14 @@ import { PlatformDatabase } from "#sqlite";
|
|
|
2
2
|
import { test } from "@fedify/fixture";
|
|
3
3
|
import { SqliteMessageQueue } from "@fedify/sqlite/mq";
|
|
4
4
|
import { getRandomKey, testMessageQueue } from "@fedify/testing";
|
|
5
|
+
import * as temporal from "@js-temporal/polyfill";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
5
7
|
import { mkdtemp } from "node:fs/promises";
|
|
6
8
|
import { tmpdir } from "node:os";
|
|
7
9
|
import { join } from "node:path";
|
|
8
10
|
|
|
11
|
+
const Temporal = globalThis.Temporal ?? temporal.Temporal;
|
|
12
|
+
|
|
9
13
|
const dbDir = await mkdtemp(join(tmpdir(), "fedify-sqlite-"));
|
|
10
14
|
const dbPath = join(dbDir, `${getRandomKey("sqlite")}.db`);
|
|
11
15
|
const db = new PlatformDatabase(dbPath);
|
|
@@ -22,3 +26,29 @@ test("SqliteMessageQueue", () =>
|
|
|
22
26
|
},
|
|
23
27
|
{ testOrderingKey: true },
|
|
24
28
|
));
|
|
29
|
+
|
|
30
|
+
test("SqliteMessageQueue.getDepth()", async () => {
|
|
31
|
+
const dbPath = join(dbDir, `${getRandomKey("sqlite_depth")}.db`);
|
|
32
|
+
const db = new PlatformDatabase(dbPath);
|
|
33
|
+
const tableName = getRandomKey("message_depth").replaceAll("-", "_");
|
|
34
|
+
const mq = new SqliteMessageQueue(db, { tableName });
|
|
35
|
+
try {
|
|
36
|
+
assert.deepStrictEqual(await mq.getDepth(), {
|
|
37
|
+
queued: 0,
|
|
38
|
+
ready: 0,
|
|
39
|
+
delayed: 0,
|
|
40
|
+
});
|
|
41
|
+
await mq.enqueue("ready");
|
|
42
|
+
await mq.enqueue("delayed", {
|
|
43
|
+
delay: Temporal.Duration.from({ hours: 1 }),
|
|
44
|
+
});
|
|
45
|
+
assert.deepStrictEqual(await mq.getDepth(), {
|
|
46
|
+
queued: 2,
|
|
47
|
+
ready: 1,
|
|
48
|
+
delayed: 1,
|
|
49
|
+
});
|
|
50
|
+
} finally {
|
|
51
|
+
mq.drop();
|
|
52
|
+
mq[Symbol.dispose]();
|
|
53
|
+
}
|
|
54
|
+
});
|
package/src/mq.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type PlatformDatabase, SqliteDatabase } from "#sqlite";
|
|
2
2
|
import type {
|
|
3
3
|
MessageQueue,
|
|
4
|
+
MessageQueueDepth,
|
|
4
5
|
MessageQueueEnqueueOptions,
|
|
5
6
|
MessageQueueListenOptions,
|
|
6
7
|
} from "@fedify/fedify";
|
|
@@ -260,6 +261,29 @@ export class SqliteMessageQueue implements MessageQueue, Disposable {
|
|
|
260
261
|
});
|
|
261
262
|
}
|
|
262
263
|
|
|
264
|
+
/**
|
|
265
|
+
* {@inheritDoc MessageQueue.getDepth}
|
|
266
|
+
*/
|
|
267
|
+
async getDepth(): Promise<MessageQueueDepth> {
|
|
268
|
+
this.initialize();
|
|
269
|
+
const row = await this.#retryOnBusy(() => {
|
|
270
|
+
const now = Temporal.Now.instant().epochMilliseconds;
|
|
271
|
+
return this.#db
|
|
272
|
+
.prepare(
|
|
273
|
+
`SELECT
|
|
274
|
+
COUNT(*) AS queued,
|
|
275
|
+
COALESCE(SUM(CASE WHEN scheduled <= ? THEN 1 ELSE 0 END), 0) AS ready
|
|
276
|
+
FROM "${this.#tableName}"`,
|
|
277
|
+
)
|
|
278
|
+
.get(now) as { queued: number; ready: number };
|
|
279
|
+
});
|
|
280
|
+
return {
|
|
281
|
+
queued: row.queued,
|
|
282
|
+
ready: row.ready,
|
|
283
|
+
delayed: Math.max(0, row.queued - row.ready),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
263
287
|
/**
|
|
264
288
|
* {@inheritDoc MessageQueue.listen}
|
|
265
289
|
*/
|