@aghamdi/shared-types 0.2.2 → 0.2.3
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.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -25,4 +25,9 @@ declare class MiaNotifications {
|
|
|
25
25
|
static sendtoUserDevices(userId: string, body: string): Promise<void>;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
declare class MessagingBus {
|
|
29
|
+
static subscribe(channel: string, queue: string, onMessage: Function): Promise<void>;
|
|
30
|
+
static publish(channel: string, message: any): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { type DeviceNotification, MessagingBus, MiaNotifications, MiaServerResponse, type Notification, type UserNotification };
|
package/dist/index.d.ts
CHANGED
|
@@ -25,4 +25,9 @@ declare class MiaNotifications {
|
|
|
25
25
|
static sendtoUserDevices(userId: string, body: string): Promise<void>;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
declare class MessagingBus {
|
|
29
|
+
static subscribe(channel: string, queue: string, onMessage: Function): Promise<void>;
|
|
30
|
+
static publish(channel: string, message: any): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { type DeviceNotification, MessagingBus, MiaNotifications, MiaServerResponse, type Notification, type UserNotification };
|
package/dist/index.js
CHANGED
|
@@ -44,6 +44,7 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
44
44
|
// src/index.ts
|
|
45
45
|
var src_exports = {};
|
|
46
46
|
__export(src_exports, {
|
|
47
|
+
MessagingBus: () => MessagingBus,
|
|
47
48
|
MiaNotifications: () => MiaNotifications,
|
|
48
49
|
MiaServerResponse: () => MiaServerResponse
|
|
49
50
|
});
|
|
@@ -77,7 +78,7 @@ MiaServerResponse.sendError = (error) => {
|
|
|
77
78
|
return response;
|
|
78
79
|
};
|
|
79
80
|
|
|
80
|
-
// src/
|
|
81
|
+
// src/messaging-bus.ts
|
|
81
82
|
var import_nats = require("nats");
|
|
82
83
|
var MessagingBus = class {
|
|
83
84
|
static subscribe(channel, queue, onMessage) {
|
|
@@ -137,6 +138,7 @@ var MiaNotifications = class {
|
|
|
137
138
|
};
|
|
138
139
|
// Annotate the CommonJS export names for ESM import in node:
|
|
139
140
|
0 && (module.exports = {
|
|
141
|
+
MessagingBus,
|
|
140
142
|
MiaNotifications,
|
|
141
143
|
MiaServerResponse
|
|
142
144
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/mia-server-response.ts","../src/
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/mia-server-response.ts","../src/messaging-bus.ts","../src/notifications.ts"],"sourcesContent":["export * from './mia-server-response'\nexport * from './notifications'\nexport * from './messaging-bus'","export class MiaServerResponse {\n status?: number;\n message?: string;\n data: any;\n\n static send = (status: number, message: string, data: any) => {\n const response: MiaServerResponse = {\n status: status,\n message: message,\n data: data\n };\n return response;\n }\n static sendData = (data: any) => {\n const response: MiaServerResponse = {\n status: 200,\n message: \"Success\",\n data: data\n };\n return response;\n }\n static sendError = (error: any) => {\n const response: MiaServerResponse = {\n status: 400,\n message: \"Failed\",\n data: error\n };\n return response;\n }\n}\n","import { connect, JSONCodec } from \"nats\";\n\nexport class MessagingBus {\n static async subscribe(channel: string, queue: string, onMessage: Function) {\n const nc = await connect({ servers: process.env.NATS_HOST });\n const sc = JSONCodec();\n const subscription = nc.subscribe(channel, { queue: queue });\n\n (async (sub) => {\n\n console.log(`listening for ${sub.getSubject()} requests...`);\n\n for await (const m of sub) {\n const msg = sc.decode(m.data);\n onMessage(msg);\n }\n\n console.log(`subscription ${sub.getSubject()} drained.`);\n })(subscription);\n }\n\n static async publish(channel: string, message: any) {\n if (!process.env.NATS_HOST) {\n throw new Error(\"NATS_HOST ENV is not defined\");\n }\n const nc = await connect({ servers: process.env.NATS_HOST });\n const jc = JSONCodec();\n nc.publish(channel, jc.encode({ message }));\n await nc.drain();\n }\n}\n","import { connect, JSONCodec } from \"nats\";\nimport { MessagingBus } from \"./messaging-bus\";\nexport interface Notification {\n title?: string,\n body: string,\n badge?: number,\n topic?: string,\n payload?: any\n}\nexport interface UserNotification extends Notification {\n userId: string\n}\nexport interface DeviceNotification extends Notification {\n deviceId: string\n}\n\nexport class MiaNotifications {\n static async sendtoDevice(deviceId: string, body: string) {\n const message: DeviceNotification = { deviceId, body };\n await MessagingBus.publish(\"mia.notifications.test\", message);\n }\n static async sendtoUserDevices(userId: string, body: string) {\n const message: UserNotification = { userId, body };\n await MessagingBus.publish(\"mia.notifications.test\", message);\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,oBAAN,MAAwB;AA6B/B;AA7Ba,kBAKJ,OAAO,CAAC,QAAgB,SAAiB,SAAc;AAC5D,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO;AACT;AAZW,kBAaJ,WAAW,CAAC,SAAc;AAC/B,QAAM,WAA8B;AAAA,IAClC,QAAQ;AAAA,IACR,SAAS;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AApBW,kBAqBJ,YAAY,CAAC,UAAe;AACjC,QAAM,WAA8B;AAAA,IAClC,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,MAAM;AAAA,EACR;AACA,SAAO;AACT;;;AC5BF,kBAAmC;AAE5B,IAAM,eAAN,MAAmB;AAAA,EACxB,OAAa,UAAU,SAAiB,OAAe,WAAqB;AAAA;AAC1E,YAAM,KAAK,UAAM,qBAAQ,EAAE,SAAS,QAAQ,I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
|
};
|
|
53
53
|
|
|
54
|
-
// src/
|
|
54
|
+
// src/messaging-bus.ts
|
|
55
55
|
import { connect, JSONCodec } from "nats";
|
|
56
56
|
var MessagingBus = class {
|
|
57
57
|
static subscribe(channel, queue, onMessage) {
|
|
@@ -110,6 +110,7 @@ var MiaNotifications = class {
|
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
112
|
export {
|
|
113
|
+
MessagingBus,
|
|
113
114
|
MiaNotifications,
|
|
114
115
|
MiaServerResponse
|
|
115
116
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mia-server-response.ts","../src/
|
|
1
|
+
{"version":3,"sources":["../src/mia-server-response.ts","../src/messaging-bus.ts","../src/notifications.ts"],"sourcesContent":["export class MiaServerResponse {\n status?: number;\n message?: string;\n data: any;\n\n static send = (status: number, message: string, data: any) => {\n const response: MiaServerResponse = {\n status: status,\n message: message,\n data: data\n };\n return response;\n }\n static sendData = (data: any) => {\n const response: MiaServerResponse = {\n status: 200,\n message: \"Success\",\n data: data\n };\n return response;\n }\n static sendError = (error: any) => {\n const response: MiaServerResponse = {\n status: 400,\n message: \"Failed\",\n data: error\n };\n return response;\n }\n}\n","import { connect, JSONCodec } from \"nats\";\n\nexport class MessagingBus {\n static async subscribe(channel: string, queue: string, onMessage: Function) {\n const nc = await connect({ servers: process.env.NATS_HOST });\n const sc = JSONCodec();\n const subscription = nc.subscribe(channel, { queue: queue });\n\n (async (sub) => {\n\n console.log(`listening for ${sub.getSubject()} requests...`);\n\n for await (const m of sub) {\n const msg = sc.decode(m.data);\n onMessage(msg);\n }\n\n console.log(`subscription ${sub.getSubject()} drained.`);\n })(subscription);\n }\n\n static async publish(channel: string, message: any) {\n if (!process.env.NATS_HOST) {\n throw new Error(\"NATS_HOST ENV is not defined\");\n }\n const nc = await connect({ servers: process.env.NATS_HOST });\n const jc = JSONCodec();\n nc.publish(channel, jc.encode({ message }));\n await nc.drain();\n }\n}\n","import { connect, JSONCodec } from \"nats\";\nimport { MessagingBus } from \"./messaging-bus\";\nexport interface Notification {\n title?: string,\n body: string,\n badge?: number,\n topic?: string,\n payload?: any\n}\nexport interface UserNotification extends Notification {\n userId: string\n}\nexport interface DeviceNotification extends Notification {\n deviceId: string\n}\n\nexport class MiaNotifications {\n static async sendtoDevice(deviceId: string, body: string) {\n const message: DeviceNotification = { deviceId, body };\n await MessagingBus.publish(\"mia.notifications.test\", message);\n }\n static async sendtoUserDevices(userId: string, body: string) {\n const message: UserNotification = { userId, body };\n await MessagingBus.publish(\"mia.notifications.test\", message);\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,IAAM,oBAAN,MAAwB;AA6B/B;AA7Ba,kBAKJ,OAAO,CAAC,QAAgB,SAAiB,SAAc;AAC5D,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO;AACT;AAZW,kBAaJ,WAAW,CAAC,SAAc;AAC/B,QAAM,WAA8B;AAAA,IAClC,QAAQ;AAAA,IACR,SAAS;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AApBW,kBAqBJ,YAAY,CAAC,UAAe;AACjC,QAAM,WAA8B;AAAA,IAClC,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,MAAM;AAAA,EACR;AACA,SAAO;AACT;;;AC5BF,SAAS,SAAS,iBAAiB;AAE5B,IAAM,eAAN,MAAmB;AAAA,EACxB,OAAa,UAAU,SAAiB,OAAe,WAAqB;AAAA;AAC1E,YAAM,KAAK,MAAM,QAAQ,EAAE,SAAS,QAAQ,IAAI,UAAU,CAAC;AAC3D,YAAM,KAAK,UAAU;AACrB,YAAM,eAAe,GAAG,UAAU,SAAS,EAAE,MAAa,CAAC;AAE3D,OAAC,CAAO,QAAQ;AAEd,gBAAQ,IAAI,iBAAiB,IAAI,WAAW,CAAC,cAAc;AAE3D;AAAA,qCAAsB,MAAtB,0EAA2B;AAAhB,kBAAM,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