@orkow/common 0.0.36 → 0.0.40
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/events/streams.d.ts +6 -0
- package/dist/events/streams.d.ts.map +1 -0
- package/dist/events/streams.js +10 -0
- package/dist/events/subjects.d.ts +4 -1
- package/dist/events/subjects.d.ts.map +1 -1
- package/dist/events/subjects.js +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/nats-wrapper.d.ts +11 -0
- package/dist/nats-wrapper.d.ts.map +1 -0
- package/dist/nats-wrapper.js +37 -0
- package/package.json +4 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streams.d.ts","sourceRoot":"","sources":["../../src/events/streams.ts"],"names":[],"mappings":"AAEA,oBAAY,MAAM;IAChB,WAAW,iBAAgC;IAC3C,eAAe,qBAAoC;IACnD,UAAU,gBAA+B;CAC1C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Stream = void 0;
|
|
4
|
+
const subjects_1 = require("./subjects");
|
|
5
|
+
var Stream;
|
|
6
|
+
(function (Stream) {
|
|
7
|
+
Stream["UsersStream"] = "EVENTS_users";
|
|
8
|
+
Stream["ConsumersStream"] = "EVENTS_consumers";
|
|
9
|
+
Stream["AuthStream"] = "EVENTS_auth";
|
|
10
|
+
})(Stream || (exports.Stream = Stream = {}));
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export declare enum Subjects {
|
|
2
|
+
UsersSrv = "users",
|
|
2
3
|
UserCreated = "user.created",
|
|
3
4
|
UserUpdated = "user.updated",
|
|
5
|
+
ConsumersSrv = "consumers",
|
|
4
6
|
ConsumerCreated = "consumer.created",
|
|
5
|
-
ConsumerUpdated = "consumer.updated"
|
|
7
|
+
ConsumerUpdated = "consumer.updated",
|
|
8
|
+
AuthSrv = "auth"
|
|
6
9
|
}
|
|
7
10
|
//# sourceMappingURL=subjects.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subjects.d.ts","sourceRoot":"","sources":["../../src/events/subjects.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ;IAElB,WAAW,iBAAiB;IAC5B,WAAW,iBAAiB;IAG5B,eAAe,qBAAqB;IACpC,eAAe,qBAAqB;
|
|
1
|
+
{"version":3,"file":"subjects.d.ts","sourceRoot":"","sources":["../../src/events/subjects.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ;IAElB,QAAQ,UAAU;IAClB,WAAW,iBAAiB;IAC5B,WAAW,iBAAiB;IAG5B,YAAY,cAAc;IAC1B,eAAe,qBAAqB;IACpC,eAAe,qBAAqB;IAGpC,OAAO,SAAS;CACjB"}
|
package/dist/events/subjects.js
CHANGED
|
@@ -3,8 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Subjects = void 0;
|
|
4
4
|
var Subjects;
|
|
5
5
|
(function (Subjects) {
|
|
6
|
+
Subjects["UsersSrv"] = "users";
|
|
6
7
|
Subjects["UserCreated"] = "user.created";
|
|
7
8
|
Subjects["UserUpdated"] = "user.updated";
|
|
9
|
+
Subjects["ConsumersSrv"] = "consumers";
|
|
8
10
|
Subjects["ConsumerCreated"] = "consumer.created";
|
|
9
11
|
Subjects["ConsumerUpdated"] = "consumer.updated";
|
|
12
|
+
Subjects["AuthSrv"] = "auth";
|
|
10
13
|
})(Subjects || (exports.Subjects = Subjects = {}));
|
package/dist/index.d.ts
CHANGED
|
@@ -3,9 +3,11 @@ export * from './utils/getRequestId';
|
|
|
3
3
|
export * from './utils/getUserId';
|
|
4
4
|
export * from './utils/getUserType';
|
|
5
5
|
export * from './utils/hashPassword';
|
|
6
|
+
export * from './nats-wrapper';
|
|
6
7
|
export * from './events/base-listener';
|
|
7
8
|
export * from './events/base-publisher';
|
|
8
9
|
export * from './events/subjects';
|
|
10
|
+
export * from './events/streams';
|
|
9
11
|
export * from './events/user-created-event';
|
|
10
12
|
export declare const log: (str: any) => void;
|
|
11
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AAEpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AACvC,cAAc,mBAAmB,CAAA;AACjC,cAAc,6BAA6B,CAAA;AAE3C,eAAO,MAAM,GAAG,GAAI,KAAK,GAAG,SAE3B,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AAEpC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AACvC,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,6BAA6B,CAAA;AAE3C,eAAO,MAAM,GAAG,GAAI,KAAK,GAAG,SAE3B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -20,9 +20,11 @@ __exportStar(require("./utils/getRequestId"), exports);
|
|
|
20
20
|
__exportStar(require("./utils/getUserId"), exports);
|
|
21
21
|
__exportStar(require("./utils/getUserType"), exports);
|
|
22
22
|
__exportStar(require("./utils/hashPassword"), exports);
|
|
23
|
+
__exportStar(require("./nats-wrapper"), exports);
|
|
23
24
|
__exportStar(require("./events/base-listener"), exports);
|
|
24
25
|
__exportStar(require("./events/base-publisher"), exports);
|
|
25
26
|
__exportStar(require("./events/subjects"), exports);
|
|
27
|
+
__exportStar(require("./events/streams"), exports);
|
|
26
28
|
__exportStar(require("./events/user-created-event"), exports);
|
|
27
29
|
const log = (str) => {
|
|
28
30
|
console.log('logger: ' + str);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NatsConnection } from 'nats';
|
|
2
|
+
declare class NatsWrapper {
|
|
3
|
+
private _client?;
|
|
4
|
+
private _streamName?;
|
|
5
|
+
get client(): NatsConnection;
|
|
6
|
+
get streamName(): string;
|
|
7
|
+
connect(subj: string, clientId: string, servers: string | string[], user: string, pass: string): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare const natsWrapper: NatsWrapper;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=nats-wrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nats-wrapper.d.ts","sourceRoot":"","sources":["../src/nats-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,cAAc,EAAE,MAAM,MAAM,CAAA;AAG7D,cAAM,WAAW;IACf,OAAO,CAAC,OAAO,CAAC,CAAgB;IAChC,OAAO,CAAC,WAAW,CAAC,CAAQ;IAE5B,IAAI,MAAM,mBAIT;IAED,IAAI,UAAU,WAGb;IAEK,OAAO,CACX,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM;CAuBf;AAED,eAAO,MAAM,WAAW,aAAoB,CAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.natsWrapper = void 0;
|
|
4
|
+
const nats_1 = require("nats");
|
|
5
|
+
const _1 = require(".");
|
|
6
|
+
class NatsWrapper {
|
|
7
|
+
_client;
|
|
8
|
+
_streamName;
|
|
9
|
+
get client() {
|
|
10
|
+
if (!this._client)
|
|
11
|
+
throw new Error('Cannot access NATS client before connecting.');
|
|
12
|
+
return this._client;
|
|
13
|
+
}
|
|
14
|
+
get streamName() {
|
|
15
|
+
if (!this._streamName)
|
|
16
|
+
throw new Error('No stream yet to set.');
|
|
17
|
+
return this._streamName;
|
|
18
|
+
}
|
|
19
|
+
async connect(subj, clientId, servers, user, pass) {
|
|
20
|
+
this._client = await (0, nats_1.connect)({
|
|
21
|
+
name: clientId,
|
|
22
|
+
servers,
|
|
23
|
+
user,
|
|
24
|
+
pass,
|
|
25
|
+
});
|
|
26
|
+
(0, _1.log)(`🛰️ connected to ${this.client.getServer()}`);
|
|
27
|
+
const js = this.client.jetstream();
|
|
28
|
+
const jsm = await js.jetstreamManager();
|
|
29
|
+
this._streamName = `EVENTS_${subj}`;
|
|
30
|
+
await jsm.streams.add({
|
|
31
|
+
name: this.streamName,
|
|
32
|
+
subjects: [`${subj}.>`],
|
|
33
|
+
});
|
|
34
|
+
(0, _1.log)(`stream ${this.streamName} added`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.natsWrapper = new NatsWrapper();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orkow/common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.40",
|
|
4
4
|
"description": "Common utils.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"dist/**"
|
|
10
10
|
],
|
|
11
11
|
"keywords": [],
|
|
12
|
-
"author": "ConCat7 Sky Limited
|
|
12
|
+
"author": "ConCat7 Sky Limited <ikramhasib007@gmail.com> (https://github.com/ikramhasib007)",
|
|
13
13
|
"scripts": {
|
|
14
14
|
"dev": "tsc -w",
|
|
15
15
|
"clean": "del-cli ./dist/*",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"@nats-io/transport-node": "^3.2.0",
|
|
23
23
|
"bcryptjs": "^3.0.3",
|
|
24
24
|
"graphql": "^16.12.0",
|
|
25
|
-
"jsonwebtoken": "^9.0.3"
|
|
25
|
+
"jsonwebtoken": "^9.0.3",
|
|
26
|
+
"nats": "^2.29.3"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@eslint/js": "^9.39.1",
|