@yongdall/mq-redis 0.1.0

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.
@@ -0,0 +1,10 @@
1
+ import redis from "#index";
2
+
3
+ //#region providers/mq-redis/hooks.yongdall.mjs
4
+ /** @import { Hooks } from '@yongdall/connection' */
5
+ /** @type {Hooks.providers} */
6
+ const providers = { mq: { redis } };
7
+
8
+ //#endregion
9
+ export { providers };
10
+ //# sourceMappingURL=hooks.yongdall.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.yongdall.mjs","names":[],"sources":["../../providers/mq-redis/hooks.yongdall.mjs"],"sourcesContent":["import redis from '#index';\n/** @import { Hooks } from '@yongdall/connection' */\n/** @type {Hooks.providers} */\nexport const providers = {\n\tmq: { redis },\n};\n"],"mappings":";;;;;AAGA,MAAa,YAAY,EACxB,IAAI,EAAE,OAAO,EACb"}
package/index.d.mts ADDED
@@ -0,0 +1,6 @@
1
+ import * as _yongdall_connection0 from "@yongdall/connection";
2
+
3
+ //#region providers/mq-redis/index.d.mts
4
+ declare function _default(url: string): Promise<_yongdall_connection0.MessageQueue>;
5
+ //#endregion
6
+ export { _default as default };
package/index.mjs ADDED
@@ -0,0 +1,6 @@
1
+ //#region providers/mq-redis/index.mjs
2
+ var mq_redis_default = (url) => import("./redis-CSe28ot7.mjs").then((v) => v.default(url));
3
+
4
+ //#endregion
5
+ export { mq_redis_default as default };
6
+ //# sourceMappingURL=index.mjs.map
package/index.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../providers/mq-redis/index.mjs"],"sourcesContent":["export default (/** @type {string} */url) => import('./redis.mjs').then(v => v.default(url));\n"],"mappings":";AAAA,wBAAqC,QAAQ,OAAO,wBAAe,MAAK,MAAK,EAAE,QAAQ,IAAI,CAAC"}
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@yongdall/mq-redis",
3
+ "type": "module",
4
+ "main": "./index.mjs",
5
+ "exports": {
6
+ ".": "./index.mjs"
7
+ },
8
+ "imports": {
9
+ "#index": "./index.mjs"
10
+ },
11
+ "version": "0.1.0",
12
+ "description": "",
13
+ "keywords": [],
14
+ "author": "",
15
+ "license": "ISC",
16
+ "dependencies": {
17
+ "ioredis": "^5.4.1"
18
+ },
19
+ "devDependencies": {
20
+ "@yongdall/connection": "^0.1.0"
21
+ }
22
+ }
@@ -0,0 +1,31 @@
1
+ import IORedis from "ioredis";
2
+
3
+ //#region providers/mq-redis/redis.mjs
4
+ /** @import { MessageQueue } from '@yongdall/connection' */
5
+ /**
6
+ *
7
+ * @param {string} url
8
+ * @returns {Promise<MessageQueue>}
9
+ */
10
+ async function redis_default(url) {
11
+ const redis = new IORedis(url);
12
+ return {
13
+ async publish(channel, message) {
14
+ await redis.publish(channel, JSON.stringify(message));
15
+ },
16
+ async subscribe(channel, subscriber) {
17
+ redis.subscribe(channel, (err, count) => {});
18
+ redis.on("message", (messageChannel, message) => {
19
+ if (messageChannel !== channel) return;
20
+ try {
21
+ subscriber(JSON.parse(message));
22
+ } catch {}
23
+ });
24
+ return () => redis.unsubscribe(channel);
25
+ }
26
+ };
27
+ }
28
+
29
+ //#endregion
30
+ export { redis_default as default };
31
+ //# sourceMappingURL=redis-CSe28ot7.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis-CSe28ot7.mjs","names":[],"sources":["../../providers/mq-redis/redis.mjs"],"sourcesContent":["import IORedis from 'ioredis';\n/** @import { MessageQueue } from '@yongdall/connection' */\n\n/**\n * \n * @param {string} url \n * @returns {Promise<MessageQueue>}\n */\nexport default async function(url) {\n\n\n\tconst redis = new IORedis(url);\n\n\treturn {\n\t\tasync publish(channel, message) {\n\t\t\tawait redis.publish(channel, JSON.stringify(message));\n\t\t},\n\t\tasync subscribe(channel, subscriber) {\n\n\t\t\tredis.subscribe(channel, (err, count) => {\n\t\t\t\t// if (err) {\n\t\t\t\t// \tconsole.error(\"Failed to subscribe:\", err);\n\t\t\t\t// } else {\n\t\t\t\t// \tconsole.log(`Subscribed to ${count} channels.`);\n\t\t\t\t// }\n\t\t\t});\n\n\t\t\tredis.on(\"message\", (messageChannel, message) => {\n\t\t\t\tif (messageChannel !== channel) { return; }\n\t\t\t\ttry {\n\t\t\t\t\tsubscriber(JSON.parse(message));\n\t\t\t\t} catch {\n\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn () => redis.unsubscribe(channel);\n\t\t}\n\t};\n}\n"],"mappings":";;;;;;;;;AAQA,6BAA8B,KAAK;CAGlC,MAAM,QAAQ,IAAI,QAAQ,IAAI;AAE9B,QAAO;EACN,MAAM,QAAQ,SAAS,SAAS;AAC/B,SAAM,MAAM,QAAQ,SAAS,KAAK,UAAU,QAAQ,CAAC;;EAEtD,MAAM,UAAU,SAAS,YAAY;AAEpC,SAAM,UAAU,UAAU,KAAK,UAAU,GAMvC;AAEF,SAAM,GAAG,YAAY,gBAAgB,YAAY;AAChD,QAAI,mBAAmB,QAAW;AAClC,QAAI;AACH,gBAAW,KAAK,MAAM,QAAQ,CAAC;YACxB;KAGP;AACF,gBAAa,MAAM,YAAY,QAAQ;;EAExC"}