@sockethub/data-layer 1.0.0-alpha.11 → 1.0.0-alpha.12
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/dist/index.js +16647 -259
- package/dist/index.js.map +159 -10
- package/package.json +5 -5
- package/src/credentials-store.ts +3 -3
- package/src/index.ts +2 -0
- package/src/job-base.ts +8 -7
- package/src/job-queue.test.ts +5 -5
- package/src/job-queue.ts +8 -8
- package/src/job-worker.ts +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sockethub/data-layer",
|
|
3
3
|
"description": "Storing and RPC of data for Sockethub",
|
|
4
|
-
"version": "1.0.0-alpha.
|
|
4
|
+
"version": "1.0.0-alpha.12",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"author": "Nick Jennings <nick@silverbucket.net>",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"test:integration": "bun test ./integration/redis.integration.ts"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@sockethub/crypto": "^1.0.0-alpha.
|
|
51
|
-
"@sockethub/logger": "^1.0.0-alpha.
|
|
52
|
-
"@sockethub/schemas": "^3.0.0-alpha.
|
|
50
|
+
"@sockethub/crypto": "^1.0.0-alpha.12",
|
|
51
|
+
"@sockethub/logger": "^1.0.0-alpha.12",
|
|
52
|
+
"@sockethub/schemas": "^3.0.0-alpha.12",
|
|
53
53
|
"bullmq": "^5.66.5",
|
|
54
54
|
"ioredis": "^5.9.2",
|
|
55
55
|
"secure-store-redis": "^4.1.0"
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"typedoc-plugin-markdown": "^4.9.0",
|
|
64
64
|
"winston": "^3.19.0"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "f039dab3c3f67cbbf204476fc397532e973f82a8"
|
|
67
67
|
}
|
package/src/credentials-store.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { crypto } from "@sockethub/crypto";
|
|
2
2
|
import {
|
|
3
|
-
type Logger,
|
|
4
3
|
createLogger,
|
|
5
4
|
getLoggerNamespace,
|
|
5
|
+
type Logger,
|
|
6
6
|
} from "@sockethub/logger";
|
|
7
7
|
import type { CredentialsObject } from "@sockethub/schemas";
|
|
8
8
|
import IORedis, { type Redis } from "ioredis";
|
|
@@ -46,7 +46,7 @@ export async function resetSharedCredentialsRedisConnection(): Promise<void> {
|
|
|
46
46
|
if (sharedCredentialsRedisConnection) {
|
|
47
47
|
try {
|
|
48
48
|
sharedCredentialsRedisConnection.disconnect(false);
|
|
49
|
-
} catch (
|
|
49
|
+
} catch (_err) {
|
|
50
50
|
// Ignore disconnect errors during cleanup
|
|
51
51
|
}
|
|
52
52
|
sharedCredentialsRedisConnection = null;
|
|
@@ -187,6 +187,6 @@ export class CredentialsStore implements CredentialsStoreInterface {
|
|
|
187
187
|
if (!this.store.isConnected) {
|
|
188
188
|
await this.store.connect();
|
|
189
189
|
}
|
|
190
|
-
return this.store.save(actor, creds);
|
|
190
|
+
return await this.store.save(actor, creds);
|
|
191
191
|
}
|
|
192
192
|
}
|
package/src/index.ts
CHANGED
|
@@ -12,7 +12,9 @@ import {
|
|
|
12
12
|
} from "./job-base.js";
|
|
13
13
|
import { JobQueue, verifyJobQueue } from "./job-queue.js";
|
|
14
14
|
import { JobWorker } from "./job-worker.js";
|
|
15
|
+
|
|
15
16
|
export * from "./types.js";
|
|
17
|
+
|
|
16
18
|
import type { RedisConfig } from "./types.js";
|
|
17
19
|
|
|
18
20
|
async function redisCheck(config: RedisConfig): Promise<void> {
|
package/src/job-base.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import EventEmitter from "node:events";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import { crypto, type Crypto } from "@sockethub/crypto";
|
|
2
|
+
import { type Crypto, crypto } from "@sockethub/crypto";
|
|
5
3
|
import type { ActivityStream } from "@sockethub/schemas";
|
|
4
|
+
import IORedis, { type Redis } from "ioredis";
|
|
6
5
|
|
|
7
6
|
import type { JobDataDecrypted, JobEncrypted, RedisConfig } from "./types.js";
|
|
8
7
|
|
|
@@ -44,7 +43,7 @@ export async function resetSharedRedisConnection(): Promise<void> {
|
|
|
44
43
|
if (sharedRedisConnection) {
|
|
45
44
|
try {
|
|
46
45
|
sharedRedisConnection.disconnect(false);
|
|
47
|
-
} catch (
|
|
46
|
+
} catch (_err) {
|
|
48
47
|
// Ignore disconnect errors during cleanup
|
|
49
48
|
}
|
|
50
49
|
sharedRedisConnection = null;
|
|
@@ -67,13 +66,15 @@ export async function getRedisConnectionCount(): Promise<number> {
|
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
try {
|
|
70
|
-
const clientList = await sharedRedisConnection.client(
|
|
69
|
+
const clientList = (await sharedRedisConnection.client(
|
|
70
|
+
"LIST",
|
|
71
|
+
)) as string;
|
|
71
72
|
// CLIENT LIST returns one line per connection, filter out empty lines
|
|
72
73
|
const connections = clientList
|
|
73
74
|
.split("\n")
|
|
74
|
-
.filter((line) => line.trim());
|
|
75
|
+
.filter((line: string) => line.trim());
|
|
75
76
|
return connections.length;
|
|
76
|
-
} catch (
|
|
77
|
+
} catch (_err) {
|
|
77
78
|
// Return 0 if Redis query fails (connection issues, etc.)
|
|
78
79
|
return 0;
|
|
79
80
|
}
|
package/src/job-queue.test.ts
CHANGED
|
@@ -108,7 +108,7 @@ describe("JobQueue", () => {
|
|
|
108
108
|
it("returns expected job format", () => {
|
|
109
109
|
cryptoMocks.encrypt.returns("an encrypted message");
|
|
110
110
|
const job = jobQueue.createJob("a socket id", {
|
|
111
|
-
|
|
111
|
+
platform: "some context",
|
|
112
112
|
id: "an identifier",
|
|
113
113
|
});
|
|
114
114
|
expect(job).to.eql({
|
|
@@ -121,7 +121,7 @@ describe("JobQueue", () => {
|
|
|
121
121
|
it("uses counter when no id provided", () => {
|
|
122
122
|
cryptoMocks.encrypt.returns("an encrypted message");
|
|
123
123
|
let job = jobQueue.createJob("a socket id", {
|
|
124
|
-
|
|
124
|
+
platform: "some context",
|
|
125
125
|
});
|
|
126
126
|
expect(job).to.eql({
|
|
127
127
|
title: "some context-0",
|
|
@@ -129,7 +129,7 @@ describe("JobQueue", () => {
|
|
|
129
129
|
sessionId: "a socket id",
|
|
130
130
|
});
|
|
131
131
|
job = jobQueue.createJob("a socket id", {
|
|
132
|
-
|
|
132
|
+
platform: "some context",
|
|
133
133
|
});
|
|
134
134
|
expect(job).to.eql({
|
|
135
135
|
title: "some context-1",
|
|
@@ -201,7 +201,7 @@ describe("JobQueue", () => {
|
|
|
201
201
|
msg: "encrypted foo",
|
|
202
202
|
};
|
|
203
203
|
const res = await jobQueue.add("a socket id", {
|
|
204
|
-
|
|
204
|
+
platform: "a platform",
|
|
205
205
|
id: "an identifier",
|
|
206
206
|
});
|
|
207
207
|
sinon.assert.calledOnce(jobQueue.queue.isPaused);
|
|
@@ -222,7 +222,7 @@ describe("JobQueue", () => {
|
|
|
222
222
|
jobQueue.queue.isPaused.returns(true);
|
|
223
223
|
try {
|
|
224
224
|
await jobQueue.add("a socket id", {
|
|
225
|
-
|
|
225
|
+
platform: "a platform",
|
|
226
226
|
id: "an identifier",
|
|
227
227
|
});
|
|
228
228
|
} catch (err) {
|
package/src/job-queue.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type Logger,
|
|
3
2
|
createLogger,
|
|
4
3
|
getLoggerNamespace,
|
|
4
|
+
type Logger,
|
|
5
5
|
} from "@sockethub/logger";
|
|
6
|
-
import type
|
|
6
|
+
import { type ActivityStream, resolvePlatformId } from "@sockethub/schemas";
|
|
7
7
|
import { type Job, Queue, QueueEvents, Worker } from "bullmq";
|
|
8
8
|
|
|
9
|
-
import { JobBase
|
|
9
|
+
import { JobBase } from "./job-base.js";
|
|
10
10
|
import { buildQueueId } from "./queue-id.js";
|
|
11
11
|
import type { JobDataEncrypted, JobDecrypted, RedisConfig } from "./types.js";
|
|
12
12
|
|
|
@@ -25,7 +25,7 @@ export async function verifyJobQueue(config: RedisConfig): Promise<void> {
|
|
|
25
25
|
job.data.test = "touched by worker";
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
|
-
connection:
|
|
28
|
+
connection: config,
|
|
29
29
|
},
|
|
30
30
|
);
|
|
31
31
|
worker.on("completed", async (job: Job) => {
|
|
@@ -46,7 +46,7 @@ export async function verifyJobQueue(config: RedisConfig): Promise<void> {
|
|
|
46
46
|
reject(err);
|
|
47
47
|
});
|
|
48
48
|
const queue = new Queue("connectiontest", {
|
|
49
|
-
connection:
|
|
49
|
+
connection: config,
|
|
50
50
|
});
|
|
51
51
|
queue.on("error", (err) => {
|
|
52
52
|
log.warn(
|
|
@@ -227,9 +227,8 @@ export class JobQueue extends JobBase {
|
|
|
227
227
|
if (job) {
|
|
228
228
|
job.data = this.decryptJobData(job);
|
|
229
229
|
try {
|
|
230
|
-
// biome-ignore lint/performance/noDelete: <explanation>
|
|
231
230
|
delete job.data.msg.sessionSecret;
|
|
232
|
-
} catch (
|
|
231
|
+
} catch (_e) {
|
|
233
232
|
// this property should never be exposed externally
|
|
234
233
|
}
|
|
235
234
|
}
|
|
@@ -237,7 +236,8 @@ export class JobQueue extends JobBase {
|
|
|
237
236
|
}
|
|
238
237
|
|
|
239
238
|
private createJob(socketId: string, msg: ActivityStream): JobDataEncrypted {
|
|
240
|
-
const
|
|
239
|
+
const platformId = resolvePlatformId(msg) || "unknown";
|
|
240
|
+
const title = `${platformId}-${msg.id ? msg.id : this.counter++}`;
|
|
241
241
|
return {
|
|
242
242
|
title: title,
|
|
243
243
|
sessionId: socketId,
|