@orkow/common 0.0.35 → 0.0.38

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.
@@ -1 +1 @@
1
- {"version":3,"file":"base-listener.d.ts","sourceRoot":"","sources":["../../src/events/base-listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAIL,KAAK,EACN,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,UAAU,KAAK;IACb,OAAO,EAAE,QAAQ,CAAA;IACjB,IAAI,EAAE,GAAG,CAAA;CACV;AAED,8BAAsB,QAAQ,CAAC,CAAC,SAAS,KAAK;IAC5C,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,CAAA;IAC9B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI;IACrD,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,QAAQ,CAAQ;IACxB,SAAS,CAAC,OAAO,SAAW;gBAEhB,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM;IAK9C,MAAM;IAwBZ,YAAY,CAAC,GAAG,EAAE,KAAK;CAMxB"}
1
+ {"version":3,"file":"base-listener.d.ts","sourceRoot":"","sources":["../../src/events/base-listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAIL,KAAK,EACN,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,UAAU,KAAK;IACb,OAAO,EAAE,QAAQ,CAAA;IACjB,IAAI,EAAE,GAAG,CAAA;CACV;AAED,8BAAsB,QAAQ,CAAC,CAAC,SAAS,KAAK;IAC5C,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,CAAA;IAC9B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI;IACrD,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,QAAQ,CAAQ;IACxB,SAAS,CAAC,OAAO,SAAW;gBAEhB,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM;IAK9C,MAAM;IAyBZ,YAAY,CAAC,GAAG,EAAE,KAAK;CAMxB"}
@@ -19,6 +19,7 @@ class Listener {
19
19
  });
20
20
  const js = (0, jetstream_1.jetstream)(this.client);
21
21
  const c2 = await js.consumers.get(this.str_name, this.queueGroupName);
22
+ console.log('c2: ', c2);
22
23
  const iter = await c2.fetch({ max_messages: 3 });
23
24
  for await (const m of iter) {
24
25
  console.log(`Message received: ${m.subject} / ${this.queueGroupName}`);
@@ -1 +1 @@
1
- {"version":3,"file":"base-publisher.d.ts","sourceRoot":"","sources":["../../src/events/base-publisher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAExD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,UAAU,KAAK;IACb,OAAO,EAAE,QAAQ,CAAA;IACjB,IAAI,EAAE,GAAG,CAAA;CACV;AAED,8BAAsB,SAAS,CAAC,CAAC,SAAS,KAAK;IAC7C,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,CAAA;IAC9B,OAAO,CAAC,MAAM,CAAgB;gBAElB,MAAM,EAAE,cAAc;IAIlC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;CAIxB"}
1
+ {"version":3,"file":"base-publisher.d.ts","sourceRoot":"","sources":["../../src/events/base-publisher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAExD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,UAAU,KAAK;IACb,OAAO,EAAE,QAAQ,CAAA;IACjB,IAAI,EAAE,GAAG,CAAA;CACV;AAED,8BAAsB,SAAS,CAAC,CAAC,SAAS,KAAK;IAC7C,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,CAAA;IAC9B,OAAO,CAAC,MAAM,CAAgB;gBAElB,MAAM,EAAE,cAAc;IAIlC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;CAMxB"}
@@ -8,6 +8,7 @@ class Publisher {
8
8
  this.client = client;
9
9
  }
10
10
  publish(data) {
11
+ console.log('Publish to subjects: ' + this.subject, data);
11
12
  const js = (0, jetstream_1.jetstream)(this.client);
12
13
  return js.publish(this.subject, JSON.stringify(data));
13
14
  }
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ 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';
@@ -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,6BAA6B,CAAA;AAE3C,eAAO,MAAM,GAAG,GAAI,KAAK,GAAG,SAE3B,CAAA"}
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ __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);
@@ -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.35",
3
+ "version": "0.0.38",
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, <ikramhasib007@gmail.com> (https://github.com/ikramhasib007)",
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",