@fedify/redis 0.4.0-dev.19 → 1.8.0-dev.938
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/LICENSE +1 -1
- package/README.md +5 -55
- package/dist/codec.d.ts +51 -0
- package/dist/codec.js +62 -0
- package/dist/kv.d.ts +50 -0
- package/dist/kv.js +63 -0
- package/dist/mod.d.ts +5 -0
- package/dist/mod.js +8 -0
- package/dist/mq.d.ts +76 -0
- package/dist/mq.js +144 -0
- package/package.json +45 -43
- package/esm/_dnt.shims.js +0 -64
- package/esm/mod.js +0 -1
- package/esm/package.json +0 -3
- package/esm/src/codec.js +0 -67
- package/esm/src/kv.js +0 -77
- package/esm/src/mod.js +0 -3
- package/esm/src/mq.js +0 -170
- package/script/_dnt.shims.js +0 -69
- package/script/mod.js +0 -17
- package/script/package.json +0 -3
- package/script/src/codec.js +0 -74
- package/script/src/kv.js +0 -81
- package/script/src/mod.js +0 -19
- package/script/src/mq.js +0 -197
- package/types/_dnt.shims.d.ts +0 -9
- package/types/_dnt.shims.d.ts.map +0 -1
- package/types/mod.d.ts +0 -2
- package/types/mod.d.ts.map +0 -1
- package/types/src/codec.d.ts +0 -47
- package/types/src/codec.d.ts.map +0 -1
- package/types/src/kv.d.ts +0 -46
- package/types/src/kv.d.ts.map +0 -1
- package/types/src/mod.d.ts +0 -4
- package/types/src/mod.d.ts.map +0 -1
- package/types/src/mq.d.ts +0 -73
- package/types/src/mq.d.ts.map +0 -1
package/script/src/mq.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
26
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
28
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
29
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
30
|
-
};
|
|
31
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
32
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
33
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
34
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
35
|
-
};
|
|
36
|
-
var _RedisMessageQueue_instances, _RedisMessageQueue_redis, _RedisMessageQueue_subRedis, _RedisMessageQueue_workerId, _RedisMessageQueue_channelKey, _RedisMessageQueue_queueKey, _RedisMessageQueue_lockKey, _RedisMessageQueue_codec, _RedisMessageQueue_pollIntervalMs, _RedisMessageQueue_loopHandle, _RedisMessageQueue_poll;
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.RedisMessageQueue = void 0;
|
|
39
|
-
// deno-lint-ignore-file no-explicit-any
|
|
40
|
-
const dntShim = __importStar(require("../_dnt.shims.js"));
|
|
41
|
-
const logtape_1 = require("@logtape/logtape");
|
|
42
|
-
const codec_js_1 = require("./codec.js");
|
|
43
|
-
const logger = (0, logtape_1.getLogger)(["fedify", "redis", "mq"]);
|
|
44
|
-
/**
|
|
45
|
-
* A message queue that uses Redis as the underlying storage.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```ts
|
|
49
|
-
* import { createFederation } from "@fedify/fedify";
|
|
50
|
-
* import { RedisMessageQueue } from "@fedify/redis";
|
|
51
|
-
* import { Redis } from "ioredis";
|
|
52
|
-
*
|
|
53
|
-
* const federation = createFederation({
|
|
54
|
-
* // ...
|
|
55
|
-
* queue: new RedisMessageQueue(() => new Redis()),
|
|
56
|
-
* });
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
class RedisMessageQueue {
|
|
60
|
-
/**
|
|
61
|
-
* Creates a new Redis message queue.
|
|
62
|
-
* @param redis The Redis client factory.
|
|
63
|
-
* @param options The options for the message queue.
|
|
64
|
-
*/
|
|
65
|
-
constructor(redis, options = {}) {
|
|
66
|
-
_RedisMessageQueue_instances.add(this);
|
|
67
|
-
_RedisMessageQueue_redis.set(this, void 0);
|
|
68
|
-
_RedisMessageQueue_subRedis.set(this, void 0);
|
|
69
|
-
_RedisMessageQueue_workerId.set(this, void 0);
|
|
70
|
-
_RedisMessageQueue_channelKey.set(this, void 0);
|
|
71
|
-
_RedisMessageQueue_queueKey.set(this, void 0);
|
|
72
|
-
_RedisMessageQueue_lockKey.set(this, void 0);
|
|
73
|
-
_RedisMessageQueue_codec.set(this, void 0);
|
|
74
|
-
_RedisMessageQueue_pollIntervalMs.set(this, void 0);
|
|
75
|
-
_RedisMessageQueue_loopHandle.set(this, void 0);
|
|
76
|
-
__classPrivateFieldSet(this, _RedisMessageQueue_redis, redis(), "f");
|
|
77
|
-
__classPrivateFieldSet(this, _RedisMessageQueue_subRedis, redis(), "f");
|
|
78
|
-
__classPrivateFieldSet(this, _RedisMessageQueue_workerId, options.workerId ?? crypto.randomUUID(), "f");
|
|
79
|
-
__classPrivateFieldSet(this, _RedisMessageQueue_channelKey, options.channelKey ?? "fedify_channel", "f");
|
|
80
|
-
__classPrivateFieldSet(this, _RedisMessageQueue_queueKey, options.queueKey ?? "fedify_queue", "f");
|
|
81
|
-
__classPrivateFieldSet(this, _RedisMessageQueue_lockKey, options.lockKey ?? "fedify_lock", "f");
|
|
82
|
-
__classPrivateFieldSet(this, _RedisMessageQueue_codec, options.codec ?? new codec_js_1.JsonCodec(), "f");
|
|
83
|
-
__classPrivateFieldSet(this, _RedisMessageQueue_pollIntervalMs, dntShim.Temporal.Duration.from(options.pollInterval ?? { seconds: 5 }).total("millisecond"), "f");
|
|
84
|
-
}
|
|
85
|
-
async enqueue(message, options) {
|
|
86
|
-
const ts = options?.delay == null
|
|
87
|
-
? 0
|
|
88
|
-
: dntShim.Temporal.Now.instant().add(options.delay).epochMilliseconds;
|
|
89
|
-
const encodedMessage = __classPrivateFieldGet(this, _RedisMessageQueue_codec, "f").encode([
|
|
90
|
-
crypto.randomUUID(),
|
|
91
|
-
message,
|
|
92
|
-
]);
|
|
93
|
-
await __classPrivateFieldGet(this, _RedisMessageQueue_redis, "f").zadd(__classPrivateFieldGet(this, _RedisMessageQueue_queueKey, "f"), ts, encodedMessage);
|
|
94
|
-
if (ts < 1)
|
|
95
|
-
__classPrivateFieldGet(this, _RedisMessageQueue_redis, "f").publish(__classPrivateFieldGet(this, _RedisMessageQueue_channelKey, "f"), "");
|
|
96
|
-
}
|
|
97
|
-
async enqueueMany(messages, options) {
|
|
98
|
-
if (messages.length === 0)
|
|
99
|
-
return;
|
|
100
|
-
const ts = options?.delay == null
|
|
101
|
-
? 0
|
|
102
|
-
: dntShim.Temporal.Now.instant().add(options.delay).epochMilliseconds;
|
|
103
|
-
// Use multi to batch multiple ZADD commands:
|
|
104
|
-
const multi = __classPrivateFieldGet(this, _RedisMessageQueue_redis, "f").multi();
|
|
105
|
-
for (const message of messages) {
|
|
106
|
-
const encodedMessage = __classPrivateFieldGet(this, _RedisMessageQueue_codec, "f").encode([
|
|
107
|
-
crypto.randomUUID(),
|
|
108
|
-
message,
|
|
109
|
-
]);
|
|
110
|
-
multi.zadd(__classPrivateFieldGet(this, _RedisMessageQueue_queueKey, "f"), ts, encodedMessage);
|
|
111
|
-
}
|
|
112
|
-
// Execute all commands in a single transaction:
|
|
113
|
-
await multi.exec();
|
|
114
|
-
// Notify only if there's no delay:
|
|
115
|
-
if (ts < 1)
|
|
116
|
-
__classPrivateFieldGet(this, _RedisMessageQueue_redis, "f").publish(__classPrivateFieldGet(this, _RedisMessageQueue_channelKey, "f"), "");
|
|
117
|
-
}
|
|
118
|
-
async listen(handler, options = {}) {
|
|
119
|
-
if (__classPrivateFieldGet(this, _RedisMessageQueue_loopHandle, "f") != null) {
|
|
120
|
-
throw new Error("Already listening");
|
|
121
|
-
}
|
|
122
|
-
const signal = options.signal;
|
|
123
|
-
const poll = async () => {
|
|
124
|
-
while (!signal?.aborted) {
|
|
125
|
-
let message;
|
|
126
|
-
try {
|
|
127
|
-
message = await __classPrivateFieldGet(this, _RedisMessageQueue_instances, "m", _RedisMessageQueue_poll).call(this);
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
logger.error("Error polling for messages: {error}", { error });
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
if (message === undefined)
|
|
134
|
-
return;
|
|
135
|
-
await handler(message);
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
const promise = __classPrivateFieldGet(this, _RedisMessageQueue_subRedis, "f").subscribe(__classPrivateFieldGet(this, _RedisMessageQueue_channelKey, "f"), () => {
|
|
139
|
-
__classPrivateFieldGet(this, _RedisMessageQueue_subRedis, "f").on("message", poll);
|
|
140
|
-
signal?.addEventListener("abort", () => {
|
|
141
|
-
__classPrivateFieldGet(this, _RedisMessageQueue_subRedis, "f").off("message", poll);
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
signal?.addEventListener("abort", () => {
|
|
145
|
-
for (const timeout of timeouts)
|
|
146
|
-
clearTimeout(timeout);
|
|
147
|
-
});
|
|
148
|
-
const timeouts = new Set();
|
|
149
|
-
while (!signal?.aborted) {
|
|
150
|
-
let timeout;
|
|
151
|
-
await new Promise((resolve) => {
|
|
152
|
-
signal?.addEventListener("abort", resolve);
|
|
153
|
-
timeout = setTimeout(() => {
|
|
154
|
-
signal?.removeEventListener("abort", resolve);
|
|
155
|
-
resolve(0);
|
|
156
|
-
}, __classPrivateFieldGet(this, _RedisMessageQueue_pollIntervalMs, "f"));
|
|
157
|
-
timeouts.add(timeout);
|
|
158
|
-
});
|
|
159
|
-
if (timeout != null)
|
|
160
|
-
timeouts.delete(timeout);
|
|
161
|
-
await poll();
|
|
162
|
-
}
|
|
163
|
-
return await new Promise((resolve) => {
|
|
164
|
-
signal?.addEventListener("abort", () => {
|
|
165
|
-
promise.catch(() => resolve()).then(() => resolve());
|
|
166
|
-
});
|
|
167
|
-
promise.catch(() => resolve()).then(() => resolve());
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
[(_RedisMessageQueue_redis = new WeakMap(), _RedisMessageQueue_subRedis = new WeakMap(), _RedisMessageQueue_workerId = new WeakMap(), _RedisMessageQueue_channelKey = new WeakMap(), _RedisMessageQueue_queueKey = new WeakMap(), _RedisMessageQueue_lockKey = new WeakMap(), _RedisMessageQueue_codec = new WeakMap(), _RedisMessageQueue_pollIntervalMs = new WeakMap(), _RedisMessageQueue_loopHandle = new WeakMap(), _RedisMessageQueue_instances = new WeakSet(), _RedisMessageQueue_poll = async function _RedisMessageQueue_poll() {
|
|
171
|
-
logger.debug("Polling for messages...");
|
|
172
|
-
const result = await __classPrivateFieldGet(this, _RedisMessageQueue_redis, "f").set(__classPrivateFieldGet(this, _RedisMessageQueue_lockKey, "f"), __classPrivateFieldGet(this, _RedisMessageQueue_workerId, "f"), "EX", Math.floor(__classPrivateFieldGet(this, _RedisMessageQueue_pollIntervalMs, "f") / 1000 * 2), "NX");
|
|
173
|
-
if (result == null) {
|
|
174
|
-
logger.debug("Another worker is already processing messages; skipping...");
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
logger.debug("Acquired lock; processing messages...");
|
|
178
|
-
const messages = await __classPrivateFieldGet(this, _RedisMessageQueue_redis, "f").zrangebyscoreBuffer(__classPrivateFieldGet(this, _RedisMessageQueue_queueKey, "f"), 0, dntShim.Temporal.Now.instant().epochMilliseconds);
|
|
179
|
-
logger.debug("Found {messages} messages to process.", { messages: messages.length });
|
|
180
|
-
try {
|
|
181
|
-
if (messages.length < 1)
|
|
182
|
-
return;
|
|
183
|
-
const encodedMessage = messages[0];
|
|
184
|
-
await __classPrivateFieldGet(this, _RedisMessageQueue_redis, "f").zrem(__classPrivateFieldGet(this, _RedisMessageQueue_queueKey, "f"), encodedMessage);
|
|
185
|
-
const [_, message] = __classPrivateFieldGet(this, _RedisMessageQueue_codec, "f").decode(encodedMessage);
|
|
186
|
-
return message;
|
|
187
|
-
}
|
|
188
|
-
finally {
|
|
189
|
-
await __classPrivateFieldGet(this, _RedisMessageQueue_redis, "f").del(__classPrivateFieldGet(this, _RedisMessageQueue_lockKey, "f"));
|
|
190
|
-
}
|
|
191
|
-
}, Symbol.dispose)]() {
|
|
192
|
-
clearInterval(__classPrivateFieldGet(this, _RedisMessageQueue_loopHandle, "f"));
|
|
193
|
-
__classPrivateFieldGet(this, _RedisMessageQueue_redis, "f").disconnect();
|
|
194
|
-
__classPrivateFieldGet(this, _RedisMessageQueue_subRedis, "f").disconnect();
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
exports.RedisMessageQueue = RedisMessageQueue;
|
package/types/_dnt.shims.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Deno } from "@deno/shim-deno";
|
|
2
|
-
export { Deno } from "@deno/shim-deno";
|
|
3
|
-
import { Temporal as Temporal } from "@js-temporal/polyfill";
|
|
4
|
-
export { Temporal as Temporal } from "@js-temporal/polyfill";
|
|
5
|
-
export declare const dntGlobalThis: Omit<typeof globalThis, "Deno" | "Temporal"> & {
|
|
6
|
-
Deno: typeof Deno;
|
|
7
|
-
Temporal: typeof Temporal;
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=_dnt.shims.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,QAAQ,IAAI,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,QAAQ,IAAI,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAM7D,eAAO,MAAM,aAAa;;;CAA2C,CAAC"}
|
package/types/mod.d.ts
DELETED
package/types/mod.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
package/types/src/codec.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Buffer } from "node:buffer";
|
|
2
|
-
/**
|
|
3
|
-
* Encode and decodes JavaScript objects to and from binary data.
|
|
4
|
-
*/
|
|
5
|
-
export interface Codec {
|
|
6
|
-
/**
|
|
7
|
-
* Encodes a JavaScript object to binary data.
|
|
8
|
-
* @param value The JavaScript object to encode.
|
|
9
|
-
* @returns The encoded binary data.
|
|
10
|
-
* @throws {EncodingError} If the JavaScript object cannot be encoded.
|
|
11
|
-
*/
|
|
12
|
-
encode(value: unknown): Buffer;
|
|
13
|
-
/**
|
|
14
|
-
* Decodes a JavaScript object from binary data.
|
|
15
|
-
* @param encoded The binary data to decode.
|
|
16
|
-
* @returns The decoded JavaScript object.
|
|
17
|
-
* @throws {DecodingError} If the binary data is invalid.
|
|
18
|
-
*/
|
|
19
|
-
decode(encoded: Buffer): unknown;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* An error that occurs when encoding or decoding data.
|
|
23
|
-
*/
|
|
24
|
-
export declare class CodecError extends Error {
|
|
25
|
-
constructor(message: string);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* An error that occurs when encoding data.
|
|
29
|
-
*/
|
|
30
|
-
export declare class EncodingError extends CodecError {
|
|
31
|
-
constructor(message: string);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* An error that occurs when decoding data.
|
|
35
|
-
*/
|
|
36
|
-
export declare class DecodingError extends CodecError {
|
|
37
|
-
constructor(message: string);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* A codec that encodes and decodes JavaScript objects to and from JSON.
|
|
41
|
-
*/
|
|
42
|
-
export declare class JsonCodec implements Codec {
|
|
43
|
-
#private;
|
|
44
|
-
encode(value: unknown): Buffer;
|
|
45
|
-
decode(encoded: Buffer): unknown;
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=codec.d.ts.map
|
package/types/src/codec.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/src/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IAE/B;;;;;OAKG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;CAClC;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,UAAU;gBAC/B,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,UAAU;gBAC/B,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,qBAAa,SAAU,YAAW,KAAK;;IAIrC,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM;IAW9B,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;CASjC"}
|
package/types/src/kv.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { KvKey, KvStore, KvStoreSetOptions } from "@fedify/fedify";
|
|
2
|
-
import type { Redis, RedisKey } from "ioredis";
|
|
3
|
-
import { type Codec } from "./codec.js";
|
|
4
|
-
/**
|
|
5
|
-
* Options for {@link RedisKvStore} class.
|
|
6
|
-
*/
|
|
7
|
-
export interface RedisKvStoreOptions {
|
|
8
|
-
/**
|
|
9
|
-
* The prefix to use for all keys in the key-value store in Redis.
|
|
10
|
-
* Defaults to `"fedify::"`.
|
|
11
|
-
*/
|
|
12
|
-
keyPrefix?: RedisKey;
|
|
13
|
-
/**
|
|
14
|
-
* The codec to use for encoding and decoding values in the key-value store.
|
|
15
|
-
* Defaults to {@link JsonCodec}.
|
|
16
|
-
*/
|
|
17
|
-
codec?: Codec;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* A key-value store that uses Redis as the underlying storage.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* import { createFederation } from "@fedify/fedify";
|
|
25
|
-
* import { RedisKvStore } from "@fedify/redis";
|
|
26
|
-
* import { Redis } from "ioredis";
|
|
27
|
-
*
|
|
28
|
-
* const federation = createFederation({
|
|
29
|
-
* // ...
|
|
30
|
-
* kv: new RedisKvStore(new Redis()),
|
|
31
|
-
* });
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export declare class RedisKvStore implements KvStore {
|
|
35
|
-
#private;
|
|
36
|
-
/**
|
|
37
|
-
* Creates a new Redis key-value store.
|
|
38
|
-
* @param redis The Redis client to use.
|
|
39
|
-
* @param options The options for the key-value store.
|
|
40
|
-
*/
|
|
41
|
-
constructor(redis: Redis, options?: RedisKvStoreOptions);
|
|
42
|
-
get<T = unknown>(key: KvKey): Promise<T | undefined>;
|
|
43
|
-
set(key: KvKey, value: unknown, options?: KvStoreSetOptions | undefined): Promise<void>;
|
|
44
|
-
delete(key: KvKey): Promise<void>;
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=kv.d.ts.map
|
package/types/src/kv.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"kv.d.ts","sourceRoot":"","sources":["../../src/src/kv.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/C,OAAO,EAAE,KAAK,KAAK,EAAa,MAAM,YAAY,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,SAAS,CAAC,EAAE,QAAQ,CAAC;IAErB;;;OAGG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,YAAa,YAAW,OAAO;;IAM1C;;;;OAIG;gBACS,KAAK,EAAE,KAAK,EAAE,OAAO,GAAE,mBAAwB;IAiBrD,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,KAAK,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAOpD,GAAG,CACP,GAAG,EAAE,KAAK,EACV,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,iBAAiB,GAAG,SAAS,GACtC,OAAO,CAAC,IAAI,CAAC;IAcV,MAAM,CAAC,GAAG,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;CAIxC"}
|
package/types/src/mod.d.ts
DELETED
package/types/src/mod.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
package/types/src/mq.d.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import * as dntShim from "../_dnt.shims.js";
|
|
2
|
-
import type { MessageQueue, MessageQueueEnqueueOptions, MessageQueueListenOptions } from "@fedify/fedify";
|
|
3
|
-
import type { Redis, RedisKey } from "ioredis";
|
|
4
|
-
import { type Codec } from "./codec.js";
|
|
5
|
-
/**
|
|
6
|
-
* Options for {@link RedisMessageQueue} class.
|
|
7
|
-
*/
|
|
8
|
-
export interface RedisMessageQueueOptions {
|
|
9
|
-
/**
|
|
10
|
-
* The unique identifier for the worker that is processing messages from the
|
|
11
|
-
* queue. If this is not specified, a random identifier will be generated.
|
|
12
|
-
* This is used to prevent multiple workers from processing the same message,
|
|
13
|
-
* so it should be unique for each worker.
|
|
14
|
-
*/
|
|
15
|
-
workerId?: string;
|
|
16
|
-
/**
|
|
17
|
-
* The Pub/Sub channel key to use for the message queue. `"fedify_channel"`
|
|
18
|
-
* by default.
|
|
19
|
-
* @default `"fedify_channel"`
|
|
20
|
-
*/
|
|
21
|
-
channelKey?: RedisKey;
|
|
22
|
-
/**
|
|
23
|
-
* The Sorted Set key to use for the delayed message queue. `"fedify_queue"`
|
|
24
|
-
* by default.
|
|
25
|
-
* @default `"fedify_queue"`
|
|
26
|
-
*/
|
|
27
|
-
queueKey?: RedisKey;
|
|
28
|
-
/**
|
|
29
|
-
* The key to use for locking the message queue. `"fedify_lock"` by default.
|
|
30
|
-
* @default `"fedify_lock"`
|
|
31
|
-
*/
|
|
32
|
-
lockKey?: RedisKey;
|
|
33
|
-
/**
|
|
34
|
-
* The codec to use for encoding and decoding messages in the key-value store.
|
|
35
|
-
* Defaults to {@link JsonCodec}.
|
|
36
|
-
* @default {@link JsonCodec}
|
|
37
|
-
*/
|
|
38
|
-
codec?: Codec;
|
|
39
|
-
/**
|
|
40
|
-
* The poll interval for the message queue. 5 seconds by default.
|
|
41
|
-
* @default `{ seconds: 5 }`
|
|
42
|
-
*/
|
|
43
|
-
pollInterval?: dntShim.Temporal.Duration | dntShim.Temporal.DurationLike;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* A message queue that uses Redis as the underlying storage.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* import { createFederation } from "@fedify/fedify";
|
|
51
|
-
* import { RedisMessageQueue } from "@fedify/redis";
|
|
52
|
-
* import { Redis } from "ioredis";
|
|
53
|
-
*
|
|
54
|
-
* const federation = createFederation({
|
|
55
|
-
* // ...
|
|
56
|
-
* queue: new RedisMessageQueue(() => new Redis()),
|
|
57
|
-
* });
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
export declare class RedisMessageQueue implements MessageQueue, Disposable {
|
|
61
|
-
#private;
|
|
62
|
-
/**
|
|
63
|
-
* Creates a new Redis message queue.
|
|
64
|
-
* @param redis The Redis client factory.
|
|
65
|
-
* @param options The options for the message queue.
|
|
66
|
-
*/
|
|
67
|
-
constructor(redis: () => Redis, options?: RedisMessageQueueOptions);
|
|
68
|
-
enqueue(message: any, options?: MessageQueueEnqueueOptions): Promise<void>;
|
|
69
|
-
enqueueMany(messages: any[], options?: MessageQueueEnqueueOptions): Promise<void>;
|
|
70
|
-
listen(handler: (message: any) => void | Promise<void>, options?: MessageQueueListenOptions): Promise<void>;
|
|
71
|
-
[Symbol.dispose](): void;
|
|
72
|
-
}
|
|
73
|
-
//# sourceMappingURL=mq.d.ts.map
|
package/types/src/mq.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mq.d.ts","sourceRoot":"","sources":["../../src/src/mq.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAE5C,OAAO,KAAK,EACV,YAAY,EACZ,0BAA0B,EAC1B,yBAAyB,EAC1B,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,KAAK,KAAK,EAAa,MAAM,YAAY,CAAC;AAInD;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;OAIG;IACH,UAAU,CAAC,EAAE,QAAQ,CAAC;IAEtB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB;;;OAGG;IACH,OAAO,CAAC,EAAE,QAAQ,CAAC;IAEnB;;;;OAIG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IAEd;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;CAC1E;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,iBAAkB,YAAW,YAAY,EAAE,UAAU;;IAWhE;;;;OAIG;gBACS,KAAK,EAAE,MAAM,KAAK,EAAE,OAAO,GAAE,wBAA6B;IAahE,OAAO,CACX,OAAO,EAAE,GAAG,EACZ,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,CAAC,IAAI,CAAC;IAYV,WAAW,CACf,QAAQ,EAAE,GAAG,EAAE,EACf,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,CAAC,IAAI,CAAC;IAwDV,MAAM,CACV,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAC/C,OAAO,GAAE,yBAA8B,GACtC,OAAO,CAAC,IAAI,CAAC;IAoDhB,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAKzB"}
|