@aghamdi/shared-types 0.2.3 → 0.2.5
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -21,8 +21,8 @@ interface DeviceNotification extends Notification {
|
|
|
21
21
|
deviceId: string;
|
|
22
22
|
}
|
|
23
23
|
declare class MiaNotifications {
|
|
24
|
-
static sendtoDevice(
|
|
25
|
-
static sendtoUserDevices(
|
|
24
|
+
static sendtoDevice(message: DeviceNotification): Promise<void>;
|
|
25
|
+
static sendtoUserDevices(message: UserNotification): Promise<void>;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
declare class MessagingBus {
|
package/dist/index.d.ts
CHANGED
|
@@ -21,8 +21,8 @@ interface DeviceNotification extends Notification {
|
|
|
21
21
|
deviceId: string;
|
|
22
22
|
}
|
|
23
23
|
declare class MiaNotifications {
|
|
24
|
-
static sendtoDevice(
|
|
25
|
-
static sendtoUserDevices(
|
|
24
|
+
static sendtoDevice(message: DeviceNotification): Promise<void>;
|
|
25
|
+
static sendtoUserDevices(message: UserNotification): Promise<void>;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
declare class MessagingBus {
|
package/dist/index.js
CHANGED
|
@@ -115,7 +115,7 @@ var MessagingBus = class {
|
|
|
115
115
|
}
|
|
116
116
|
const nc = yield (0, import_nats.connect)({ servers: process.env.NATS_HOST });
|
|
117
117
|
const jc = (0, import_nats.JSONCodec)();
|
|
118
|
-
nc.publish(channel, jc.encode(
|
|
118
|
+
nc.publish(channel, jc.encode(message));
|
|
119
119
|
yield nc.drain();
|
|
120
120
|
});
|
|
121
121
|
}
|
|
@@ -123,15 +123,13 @@ var MessagingBus = class {
|
|
|
123
123
|
|
|
124
124
|
// src/notifications.ts
|
|
125
125
|
var MiaNotifications = class {
|
|
126
|
-
static sendtoDevice(
|
|
126
|
+
static sendtoDevice(message) {
|
|
127
127
|
return __async(this, null, function* () {
|
|
128
|
-
const message = { deviceId, body };
|
|
129
128
|
yield MessagingBus.publish("mia.notifications.test", message);
|
|
130
129
|
});
|
|
131
130
|
}
|
|
132
|
-
static sendtoUserDevices(
|
|
131
|
+
static sendtoUserDevices(message) {
|
|
133
132
|
return __async(this, null, function* () {
|
|
134
|
-
const message = { userId, body };
|
|
135
133
|
yield MessagingBus.publish("mia.notifications.test", message);
|
|
136
134
|
});
|
|
137
135
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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(
|
|
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(message: DeviceNotification) {\n await MessagingBus.publish(\"mia.notifications.test\", message);\n }\n static async sendtoUserDevices(message: UserNotification) {\n await Messag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;AAClD,UAAI,CAAC,QAAQ,IAAI,WAAW;AAC1B,cAAM,IAAI,MAAM,8BAA8B;AAAA,MAChD;AACA,YAAM,KAAK,UAAM,qBAAQ,EAAE,SAAS,QAAQ,IAAI,UAAU,CAAC;AAC3D,YAAM,SAAK,uBAAU;AACrB,SAAG,QAAQ,SAAS,GAAG,OAAO,OAAO,CAAC;AACtC,YAAM,GAAG,MAAM;AAAA,IACjB;AAAA;AACF;;;ACdO,IAAM,mBAAN,MAAuB;AAAA,EAC5B,OAAa,aAAa,SAA6B;AAAA;AACrD,YAAM,aAAa,QAAQ,0BAA0B,OAAO;AAAA,IAC9D;AAAA;AAAA,EACA,OAAa,kBAAkB,SAA2B;AAAA;AACxD,YAAM,aAAa,QAAQ,0BAA0B,OAAO;AAAA,IAC9D;AAAA;AACF;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -88,7 +88,7 @@ var MessagingBus = class {
|
|
|
88
88
|
}
|
|
89
89
|
const nc = yield connect({ servers: process.env.NATS_HOST });
|
|
90
90
|
const jc = JSONCodec();
|
|
91
|
-
nc.publish(channel, jc.encode(
|
|
91
|
+
nc.publish(channel, jc.encode(message));
|
|
92
92
|
yield nc.drain();
|
|
93
93
|
});
|
|
94
94
|
}
|
|
@@ -96,15 +96,13 @@ var MessagingBus = class {
|
|
|
96
96
|
|
|
97
97
|
// src/notifications.ts
|
|
98
98
|
var MiaNotifications = class {
|
|
99
|
-
static sendtoDevice(
|
|
99
|
+
static sendtoDevice(message) {
|
|
100
100
|
return __async(this, null, function* () {
|
|
101
|
-
const message = { deviceId, body };
|
|
102
101
|
yield MessagingBus.publish("mia.notifications.test", message);
|
|
103
102
|
});
|
|
104
103
|
}
|
|
105
|
-
static sendtoUserDevices(
|
|
104
|
+
static sendtoUserDevices(message) {
|
|
106
105
|
return __async(this, null, function* () {
|
|
107
|
-
const message = { userId, body };
|
|
108
106
|
yield MessagingBus.publish("mia.notifications.test", message);
|
|
109
107
|
});
|
|
110
108
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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(
|
|
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(message: DeviceNotification) {\n await MessagingBus.publish(\"mia.notifications.test\", message);\n }\n static async sendtoUserDevices(message: UserNotification) {\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,S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