@common-stack/server-stack 0.5.29

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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -0
  3. package/lib/config/env-config.cjs +20 -0
  4. package/lib/config/env-config.cjs.map +1 -0
  5. package/lib/config/env-config.d.ts +15 -0
  6. package/lib/config/env-config.mjs +20 -0
  7. package/lib/config/env-config.mjs.map +1 -0
  8. package/lib/config/index.d.ts +1 -0
  9. package/lib/config/moleculer.config.cjs +195 -0
  10. package/lib/config/moleculer.config.cjs.map +1 -0
  11. package/lib/config/moleculer.config.d.ts +20 -0
  12. package/lib/config/moleculer.config.mjs +195 -0
  13. package/lib/config/moleculer.config.mjs.map +1 -0
  14. package/lib/connectors/connection-broker.cjs +57 -0
  15. package/lib/connectors/connection-broker.cjs.map +1 -0
  16. package/lib/connectors/connection-broker.d.ts +51 -0
  17. package/lib/connectors/connection-broker.mjs +57 -0
  18. package/lib/connectors/connection-broker.mjs.map +1 -0
  19. package/lib/connectors/graphql-pubsub-connector.cjs +25 -0
  20. package/lib/connectors/graphql-pubsub-connector.cjs.map +1 -0
  21. package/lib/connectors/graphql-pubsub-connector.d.ts +22 -0
  22. package/lib/connectors/graphql-pubsub-connector.mjs +25 -0
  23. package/lib/connectors/graphql-pubsub-connector.mjs.map +1 -0
  24. package/lib/connectors/mongo-connector.cjs +52 -0
  25. package/lib/connectors/mongo-connector.cjs.map +1 -0
  26. package/lib/connectors/mongo-connector.d.ts +21 -0
  27. package/lib/connectors/mongo-connector.mjs +52 -0
  28. package/lib/connectors/mongo-connector.mjs.map +1 -0
  29. package/lib/connectors/nats-connector.cjs +59 -0
  30. package/lib/connectors/nats-connector.cjs.map +1 -0
  31. package/lib/connectors/nats-connector.d.ts +20 -0
  32. package/lib/connectors/nats-connector.mjs +59 -0
  33. package/lib/connectors/nats-connector.mjs.map +1 -0
  34. package/lib/connectors/redis-connector.cjs +54 -0
  35. package/lib/connectors/redis-connector.cjs.map +1 -0
  36. package/lib/connectors/redis-connector.d.ts +31 -0
  37. package/lib/connectors/redis-connector.mjs +54 -0
  38. package/lib/connectors/redis-connector.mjs.map +1 -0
  39. package/lib/index.cjs +1 -0
  40. package/lib/index.cjs.map +1 -0
  41. package/lib/index.d.ts +1 -0
  42. package/lib/index.mjs +1 -0
  43. package/lib/index.mjs.map +1 -0
  44. package/lib/interface.d.ts +7 -0
  45. package/lib/middleware/moleculer-inter-namespace.cjs +44 -0
  46. package/lib/middleware/moleculer-inter-namespace.cjs.map +1 -0
  47. package/lib/middleware/moleculer-inter-namespace.d.ts +2 -0
  48. package/lib/middleware/moleculer-inter-namespace.mjs +44 -0
  49. package/lib/middleware/moleculer-inter-namespace.mjs.map +1 -0
  50. package/lib/stack-server.cjs +78 -0
  51. package/lib/stack-server.cjs.map +1 -0
  52. package/lib/stack-server.d.ts +20 -0
  53. package/lib/stack-server.mjs +78 -0
  54. package/lib/stack-server.mjs.map +1 -0
  55. package/package.json +40 -0
@@ -0,0 +1,57 @@
1
+ import {MongoConnector}from'./mongo-connector.mjs';import {NatsConnector}from'./nats-connector.mjs';import {RedisConnector}from'./redis-connector.mjs';import {config}from'../config/env-config.mjs';import {GraphqlPubSubConnector}from'./graphql-pubsub-connector.mjs';/* eslint-disable no-underscore-dangle */
2
+ /**
3
+ * Connection broker class
4
+ *
5
+ * @class ConnectionBroker
6
+ */
7
+ class ConnectionBroker {
8
+ /**
9
+ * Creates an instance of ConnectionBroker.
10
+ * @param {*} options
11
+ * @memberof ConnectionBroker
12
+ */
13
+ constructor(transporter, logger) {
14
+ if (typeof transporter === 'string') {
15
+ if (transporter === 'TCP') {
16
+ this._graphqlPubsubConnector = new GraphqlPubSubConnector({ logger, type: 'TCP' });
17
+ }
18
+ else if (transporter === 'NATS') {
19
+ this._natsConnector = new NatsConnector({});
20
+ this._graphqlPubsubConnector = new GraphqlPubSubConnector({
21
+ logger,
22
+ type: 'NATS',
23
+ client: this._natsConnector,
24
+ });
25
+ }
26
+ }
27
+ else if (transporter && 'type' in transporter && transporter.type === 'NATS') {
28
+ // Ensure transporter.options is defined and properly typed if needed
29
+ this._natsConnector = new NatsConnector(transporter.options);
30
+ this._graphqlPubsubConnector = new GraphqlPubSubConnector({
31
+ logger,
32
+ type: 'NATS',
33
+ client: this._natsConnector,
34
+ });
35
+ }
36
+ // Ensure config.MONGO_URL is properly typed as string in your config
37
+ this._mongoConnector = new MongoConnector(config.MONGO_URL);
38
+ this._redisConnector = new RedisConnector(); // Pass constructor options if needed
39
+ }
40
+ get mongoConnection() {
41
+ return this._mongoConnector.connect();
42
+ }
43
+ get redisDataloaderClient() {
44
+ return this._redisConnector.getRedisDataloaderClient();
45
+ }
46
+ get natsConnection() {
47
+ return this._natsConnector.connect();
48
+ }
49
+ get graphqlPubsub() {
50
+ return this._graphqlPubsubConnector.getClient();
51
+ }
52
+ async stop() {
53
+ this._mongoConnector && (await this._mongoConnector.disconnect());
54
+ this._redisConnector && (await this._redisConnector.disconnect());
55
+ this._natsConnector && (await this._natsConnector.disconnect());
56
+ }
57
+ }export{ConnectionBroker};//# sourceMappingURL=connection-broker.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-broker.mjs","sources":["../../src/connectors/connection-broker.ts"],"sourcesContent":[null],"names":[],"mappings":"yQAAA;AAYA;;;;AAIG;MACU,gBAAgB,CAAA;AASzB;;;;AAIG;IACH,WAAY,CAAA,WAA4B,EAAE,MAAe,EAAA;AACrD,QAAA,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;YACjC,IAAI,WAAW,KAAK,KAAK,EAAE;AACvB,gBAAA,IAAI,CAAC,uBAAuB,GAAG,IAAI,sBAAsB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AACtF,aAAA;iBAAM,IAAI,WAAW,KAAK,MAAM,EAAE;gBAC/B,IAAI,CAAC,cAAc,GAAG,IAAI,aAAa,CAAC,EAA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K,MAAM,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,CAAC,CAAC;AAClE,QAAA,IAAI,CAAC,cAAc,KAAK,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC,CAAC;KACnE;AACJ"}
@@ -0,0 +1,25 @@
1
+ 'use strict';var graphqlSubscriptions=require('graphql-subscriptions'),graphqlNatsSubscriptions=require('graphql-nats-subscriptions'),server=require('@cdm-logger/server');class GraphqlPubSubConnector {
2
+ /**
3
+ * Creates an instance of GraphqlPubSubConnector.
4
+ * @param {*} opts
5
+ * @memberof GraphqlPubSubConnector
6
+ */
7
+ constructor(opts) {
8
+ if (opts === undefined || opts.type === undefined) {
9
+ this.opts = Object.assign(Object.assign({}, opts), { apolloLogging: true, type: 'TCP' });
10
+ }
11
+ this.opts = opts;
12
+ this.logger = opts.logger.child({ className: 'GraphqlPubSubConnector' });
13
+ }
14
+ async getClient() {
15
+ if (this.opts.type === 'TCP') {
16
+ return (this.client = new graphqlSubscriptions.PubSub());
17
+ }
18
+ if (this.opts.type === 'NATS') {
19
+ const natsClient = await this.opts.client.connect();
20
+ return (this.client = new graphqlNatsSubscriptions.NatsPubSub({ client: natsClient, logger: server.logger }));
21
+ }
22
+ this.logger.warn('Did not defined known transporter [%s], return default pubsub', this.opts.type);
23
+ return (this.client = new graphqlSubscriptions.PubSub());
24
+ }
25
+ }exports.GraphqlPubSubConnector=GraphqlPubSubConnector;//# sourceMappingURL=graphql-pubsub-connector.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql-pubsub-connector.cjs","sources":["../../src/connectors/graphql-pubsub-connector.ts"],"sourcesContent":[null],"names":["PubSub","NatsPubSub","logger"],"mappings":"iLAaa,sBAAsB,CAAA;AAO/B;;;;AAIG;AACH,IAAA,WAAA,CAAY,IAAoB,EAAA;QAC5B,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;AAC/C,YAAA,IAAI,CAAC,IAAI,GAAQ,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAA,IAAI,CAAE,EAAA,EAAA,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,GAAE,CAAC;AAC7D,SAAA;AACD,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AACjB,QAAA,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,wBAAwB,EAAE,CAAC,CAAC;KAC5E;AAEM,IAAA,MAAM,SAAS,GAAA;AAClB,QAAA,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE;YAC1B,QAAQ,IAAI,CAAC,MAAM,GAAG,IAAIA,2BAAM,EAAE,EAAE;AACvC,SAAA;AACD,QAAA,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE;YAC3B,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;AACpD,YAAA,QAAQ,IAAI,CAAC,MAAM,GAAG,IAAIC,mCAAU,CAAC,EAAE,MAAM,EAAE,UAAU,UAAEC,aAAM,EAAE,CAAC,EAAE;AACzE,SAAA;AACD,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,+DAA+D,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClG,QAAQ,IAAI,CAAC,MAAM,GAAG,IAAIF,2BAAM,EAAE,EAAE;KACvC;AACJ"}
@@ -0,0 +1,22 @@
1
+ import { PubSub } from 'graphql-subscriptions';
2
+ import { NatsPubSub } from 'graphql-nats-subscriptions';
3
+ import { GenericObject } from 'moleculer';
4
+ import { CdmLogger } from '@cdm-logger/core';
5
+ type ILogger = CdmLogger.ILogger;
6
+ type PubSubOptions = {
7
+ apolloLogging?: boolean;
8
+ logger: ILogger;
9
+ } & GenericObject;
10
+ export declare class GraphqlPubSubConnector {
11
+ private client;
12
+ private opts;
13
+ private logger;
14
+ /**
15
+ * Creates an instance of GraphqlPubSubConnector.
16
+ * @param {*} opts
17
+ * @memberof GraphqlPubSubConnector
18
+ */
19
+ constructor(opts?: PubSubOptions);
20
+ getClient(): Promise<NatsPubSub | PubSub>;
21
+ }
22
+ export {};
@@ -0,0 +1,25 @@
1
+ import {PubSub}from'graphql-subscriptions';import {NatsPubSub}from'graphql-nats-subscriptions';import {logger}from'@cdm-logger/server';class GraphqlPubSubConnector {
2
+ /**
3
+ * Creates an instance of GraphqlPubSubConnector.
4
+ * @param {*} opts
5
+ * @memberof GraphqlPubSubConnector
6
+ */
7
+ constructor(opts) {
8
+ if (opts === undefined || opts.type === undefined) {
9
+ this.opts = Object.assign(Object.assign({}, opts), { apolloLogging: true, type: 'TCP' });
10
+ }
11
+ this.opts = opts;
12
+ this.logger = opts.logger.child({ className: 'GraphqlPubSubConnector' });
13
+ }
14
+ async getClient() {
15
+ if (this.opts.type === 'TCP') {
16
+ return (this.client = new PubSub());
17
+ }
18
+ if (this.opts.type === 'NATS') {
19
+ const natsClient = await this.opts.client.connect();
20
+ return (this.client = new NatsPubSub({ client: natsClient, logger }));
21
+ }
22
+ this.logger.warn('Did not defined known transporter [%s], return default pubsub', this.opts.type);
23
+ return (this.client = new PubSub());
24
+ }
25
+ }export{GraphqlPubSubConnector};//# sourceMappingURL=graphql-pubsub-connector.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql-pubsub-connector.mjs","sources":["../../src/connectors/graphql-pubsub-connector.ts"],"sourcesContent":[null],"names":[],"mappings":"6IAaa,sBAAsB,CAAA;AAO/B;;;;AAIG;AACH,IAAA,WAAA,CAAY,IAAoB,EAAA;QAC5B,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;AAC/C,YAAA,IAAI,CAAC,IAAI,GAAQ,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAA,IAAI,CAAE,EAAA,EAAA,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,GAAE,CAAC;AAC7D,SAAA;AACD,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AACjB,QAAA,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,wBAAwB,EAAE,CAAC,CAAC;KAC5E;AAEM,IAAA,MAAM,SAAS,GAAA;AAClB,QAAA,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE;YAC1B,QAAQ,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,EAAE,EAAE;AACvC,SAAA;AACD,QAAA,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE;YAC3B,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;AACpD,YAAA,QAAQ,IAAI,CAAC,MAAM,GAAG,IAAI,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,EAAE;AACzE,SAAA;AACD,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,+DAA+D,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClG,QAAQ,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,EAAE,EAAE;KACvC;AACJ"}
@@ -0,0 +1,52 @@
1
+ 'use strict';var mongoose=require('mongoose'),_=require('lodash'),mongooseExecutionTime=require('mongoose-execution-time'),server=require('@cdm-logger/server'),envConfig=require('../config/env-config.cjs');function _interopNamespaceDefault(e){var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var ___namespace=/*#__PURE__*/_interopNamespaceDefault(_);class MongoConnector {
2
+ constructor(uri, opts) {
3
+ this.opts = ___namespace.defaultsDeep(opts, {});
4
+ this.uri = uri;
5
+ this.logger = server.logger.child({ className: 'MongoConnector' });
6
+ }
7
+ /**
8
+ * Connect to database
9
+ *
10
+ * @memberof MongoConnector
11
+ */
12
+ async connect() {
13
+ if (this.client) {
14
+ return this.client;
15
+ }
16
+ const conn = mongoose.createConnection(this.uri, this.opts).asPromise();
17
+ conn.then((result) => {
18
+ this.client = result;
19
+ this.db = result.db;
20
+ this.logger.info(' MongoDB has connected successfully.');
21
+ result.on('disconnected', () => this.logger.warn('Mongoose has disconnected.'));
22
+ result.on('error', (err) => this.logger.error('MongoDB error.', err));
23
+ result.on('reconnect', () => this.logger.info('Mongoose has reconnected.'));
24
+ });
25
+ if (envConfig.config.NODE_ENV === 'development' ||
26
+ //__DEBUGGING__ ||
27
+ envConfig.config.LOG_LEVEL === 'debug' ||
28
+ envConfig.config.LOG_LEVEL === 'trace') {
29
+ mongoose.plugin(mongooseExecutionTime.logExecutionTime, {
30
+ logger: this.logger,
31
+ loggerVerbosity: mongooseExecutionTime.LoggerVerbosity.High,
32
+ loggerLevel: envConfig.config.LOG_LEVEL,
33
+ });
34
+ }
35
+ // eslint-disable-next-line @typescript-eslint/no-var-requires,global-require
36
+ // plugin(require('@kolinalabs/mongoose-consistent'), {
37
+ // actionDefault: 'no_action',
38
+ // });
39
+ return conn;
40
+ }
41
+ /**
42
+ * Disconnect from database
43
+ *
44
+ * @memberof MongoConnector
45
+ */
46
+ async disconnect() {
47
+ if (!this.client) {
48
+ return;
49
+ }
50
+ await mongoose.connection.close();
51
+ }
52
+ }exports.MongoConnector=MongoConnector;//# sourceMappingURL=mongo-connector.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo-connector.cjs","sources":["../../src/connectors/mongo-connector.ts"],"sourcesContent":[null],"names":["_","logger","createConnection","config","plugin","logExecutionTime","LoggerVerbosity","connection"],"mappings":"4iBAUa,cAAc,CAAA;IAWvB,WAA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,OAAO;AAC5B,YAAAA,gBAAM,CAAC,SAAS,KAAK,OAAO,EAC9B;YACEC,eAAM,CAACC,sCAAgB,EAAE;gBACrB,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,eAAe,EAAEC,qCAAe,CAAC,IAAI;gBACrC,WAAW,EAAEH,gBAAM,CAAC,SAAS;AAChC,aAAA,CAAC,CAAC;AACN,SAAA;;;;;AAMD,QAAA,OAAO,IAAI,CAAC;KACf;AAED;;;;AAIG;AACI,IAAA,MAAM,UAAU,GAAA;AACnB,QAAA,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YACd,OAAO;AACV,SAAA;AACD,QAAA,MAAMI,mBAAU,CAAC,KAAK,EAAE,CAAC;KAC5B;AACJ"}
@@ -0,0 +1,21 @@
1
+ import { Connection, ConnectOptions } from 'mongoose';
2
+ export declare class MongoConnector {
3
+ private client;
4
+ private db;
5
+ private opts;
6
+ private uri;
7
+ private logger;
8
+ constructor(uri: string, opts?: ConnectOptions);
9
+ /**
10
+ * Connect to database
11
+ *
12
+ * @memberof MongoConnector
13
+ */
14
+ connect(): Promise<Connection>;
15
+ /**
16
+ * Disconnect from database
17
+ *
18
+ * @memberof MongoConnector
19
+ */
20
+ disconnect(): Promise<void>;
21
+ }
@@ -0,0 +1,52 @@
1
+ import {createConnection,plugin,connection}from'mongoose';import*as _ from'lodash';import {logExecutionTime,LoggerVerbosity}from'mongoose-execution-time';import {logger}from'@cdm-logger/server';import {config}from'../config/env-config.mjs';class MongoConnector {
2
+ constructor(uri, opts) {
3
+ this.opts = _.defaultsDeep(opts, {});
4
+ this.uri = uri;
5
+ this.logger = logger.child({ className: 'MongoConnector' });
6
+ }
7
+ /**
8
+ * Connect to database
9
+ *
10
+ * @memberof MongoConnector
11
+ */
12
+ async connect() {
13
+ if (this.client) {
14
+ return this.client;
15
+ }
16
+ const conn = createConnection(this.uri, this.opts).asPromise();
17
+ conn.then((result) => {
18
+ this.client = result;
19
+ this.db = result.db;
20
+ this.logger.info(' MongoDB has connected successfully.');
21
+ result.on('disconnected', () => this.logger.warn('Mongoose has disconnected.'));
22
+ result.on('error', (err) => this.logger.error('MongoDB error.', err));
23
+ result.on('reconnect', () => this.logger.info('Mongoose has reconnected.'));
24
+ });
25
+ if (config.NODE_ENV === 'development' ||
26
+ //__DEBUGGING__ ||
27
+ config.LOG_LEVEL === 'debug' ||
28
+ config.LOG_LEVEL === 'trace') {
29
+ plugin(logExecutionTime, {
30
+ logger: this.logger,
31
+ loggerVerbosity: LoggerVerbosity.High,
32
+ loggerLevel: config.LOG_LEVEL,
33
+ });
34
+ }
35
+ // eslint-disable-next-line @typescript-eslint/no-var-requires,global-require
36
+ // plugin(require('@kolinalabs/mongoose-consistent'), {
37
+ // actionDefault: 'no_action',
38
+ // });
39
+ return conn;
40
+ }
41
+ /**
42
+ * Disconnect from database
43
+ *
44
+ * @memberof MongoConnector
45
+ */
46
+ async disconnect() {
47
+ if (!this.client) {
48
+ return;
49
+ }
50
+ await connection.close();
51
+ }
52
+ }export{MongoConnector};//# sourceMappingURL=mongo-connector.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo-connector.mjs","sources":["../../src/connectors/mongo-connector.ts"],"sourcesContent":[null],"names":[],"mappings":"sPAUa,cAAc,CAAA;IAWvB,WAAY,CAAA,GAAW,EAAE,IAAqB,EAAA;QAC1C,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACrC,QAAA,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;AACf,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC,CAAC;KAC/D;AAED;;;;AAIG;AACI,IAAA,MAAM,OAAO,GAAA;QAChB,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,OAAO,IAAI,CAAC,MAAM,CAAC;AACtB,SAAA;AACD,QAAA,MAAM,IAAI,GAAG,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;AACJ"}
@@ -0,0 +1,59 @@
1
+ 'use strict';var nats=require('nats'),_=require('lodash'),server=require('@cdm-logger/server');function _interopNamespaceDefault(e){var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var nats__namespace=/*#__PURE__*/_interopNamespaceDefault(nats);var ___namespace=/*#__PURE__*/_interopNamespaceDefault(_);class NatsConnector {
2
+ constructor(opts) {
3
+ this.opts = ___namespace.defaultsDeep(opts, {});
4
+ this.logger = server.logger.child({ className: 'NatsConnector' });
5
+ }
6
+ /**
7
+ * Connect to a NATS server
8
+ *
9
+ * @memberof NatsConnector
10
+ */
11
+ connect() {
12
+ if (this.client) {
13
+ return this.client;
14
+ }
15
+ return new Promise((resolve, reject) => {
16
+ const client = nats__namespace.connect(this.opts);
17
+ client.on('connect', () => {
18
+ this.client = client;
19
+ this.connected = true;
20
+ this.logger.info('NATS client is connected.');
21
+ resolve(client);
22
+ });
23
+ client.on('reconnect', () => {
24
+ this.logger.info('NATS client is reconnected.');
25
+ this.connected = true;
26
+ });
27
+ client.on('reconnecting', () => {
28
+ this.logger.warn('NATS client is reconnecting...');
29
+ });
30
+ client.on('disconnect', () => {
31
+ if (this.connected) {
32
+ this.logger.warn('NATS client is disconnected.');
33
+ this.connected = false;
34
+ }
35
+ });
36
+ client.on('error', (e) => {
37
+ this.logger.error('NATS error.', e.message);
38
+ this.logger.debug(e);
39
+ reject(e);
40
+ });
41
+ client.on('close', () => {
42
+ this.logger.fatal('NATS connection close.');
43
+ });
44
+ });
45
+ }
46
+ /**
47
+ * Disconnect from a NATS server
48
+ *
49
+ * @memberof NatsTransporter
50
+ */
51
+ disconnect() {
52
+ if (this.client) {
53
+ this.client.flush(() => {
54
+ this.client.close();
55
+ this.client = null;
56
+ });
57
+ }
58
+ }
59
+ }exports.NatsConnector=NatsConnector;//# sourceMappingURL=nats-connector.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nats-connector.cjs","sources":["../../src/connectors/nats-connector.ts"],"sourcesContent":[null],"names":["_","logger","nats"],"mappings":"6fAOa,aAAa,CAAA;AAStB,IAAA,WAAA,CAAY,IAAqB,EAAA;QAC7B,IAAI,CAAC,IAAI,GAAGA,YAAC,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACrC,QAAA,IAAI,CAAC,MAAM,GAAGC,aAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC,CAAC;KAC9D;AAED;;;;AAIG;IACI,OAAO,GAAA;QACV,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,OAAO,IAAI,CAAC,MAAM,CAAC;AACtB,SAAA;QACD,OAAO,IAAI,OAAO,CAAc,CAAC,OAAO,EAAE,MAAM,KAAI;YAChD,MAAM,MAAM,GAAGC,eAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEvC,YAAA,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,MAAK;AACtB,gBAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;AACrB,gBAAA,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;AACtB,gBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;gBAC9C,OAAO,CAAC,MAAM,CAAC,CAAC;AACpB,aAAC,CAAC,CAAC;AAEH,YAAA,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,MAAK;AACxB,gBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;AAChD,gBAAA,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;AAC1B,aAAC,CAAC,CAAC;AAEH,YAAA,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,MAAK;AAC3B,gBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;AACvD,aAAC,CAAC,CAAC;AAEH,YAAA,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,MAAK;gBACzB,IAAI,IAAI,CAAC,SAAS,EAAE;AAChB,oBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;AACjD,oBAAA,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;AAC1B,iBAAA;AACL,aAAC,CAAC,CAAC;YAEH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,KAAI;gBACrB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;AAC5C,gBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACrB,MAAM,CAAC,CAAC,CAAC,CAAC;AACd,aAAC,CAAC,CAAC;AAEH,YAAA,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAK;AACpB,gBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;AAChD,aAAC,CAAC,CAAC;AACP,SAAC,CAAC,CAAC;KACN;AAED;;;;AAIG;IACI,UAAU,GAAA;QACb,IAAI,IAAI,CAAC,MAAM,EAAE;AACb,YAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAK;AACnB,gBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;AACpB,gBAAA,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;AACvB,aAAC,CAAC,CAAC;AACN,SAAA;KACJ;AACJ"}
@@ -0,0 +1,20 @@
1
+ import * as nats from 'nats';
2
+ export declare class NatsConnector {
3
+ private opts;
4
+ private client;
5
+ private logger;
6
+ private connected;
7
+ constructor(opts: nats.ClientOpts);
8
+ /**
9
+ * Connect to a NATS server
10
+ *
11
+ * @memberof NatsConnector
12
+ */
13
+ connect(): nats.Client | Promise<nats.Client>;
14
+ /**
15
+ * Disconnect from a NATS server
16
+ *
17
+ * @memberof NatsTransporter
18
+ */
19
+ disconnect(): void;
20
+ }
@@ -0,0 +1,59 @@
1
+ import*as nats from'nats';import*as _ from'lodash';import {logger}from'@cdm-logger/server';class NatsConnector {
2
+ constructor(opts) {
3
+ this.opts = _.defaultsDeep(opts, {});
4
+ this.logger = logger.child({ className: 'NatsConnector' });
5
+ }
6
+ /**
7
+ * Connect to a NATS server
8
+ *
9
+ * @memberof NatsConnector
10
+ */
11
+ connect() {
12
+ if (this.client) {
13
+ return this.client;
14
+ }
15
+ return new Promise((resolve, reject) => {
16
+ const client = nats.connect(this.opts);
17
+ client.on('connect', () => {
18
+ this.client = client;
19
+ this.connected = true;
20
+ this.logger.info('NATS client is connected.');
21
+ resolve(client);
22
+ });
23
+ client.on('reconnect', () => {
24
+ this.logger.info('NATS client is reconnected.');
25
+ this.connected = true;
26
+ });
27
+ client.on('reconnecting', () => {
28
+ this.logger.warn('NATS client is reconnecting...');
29
+ });
30
+ client.on('disconnect', () => {
31
+ if (this.connected) {
32
+ this.logger.warn('NATS client is disconnected.');
33
+ this.connected = false;
34
+ }
35
+ });
36
+ client.on('error', (e) => {
37
+ this.logger.error('NATS error.', e.message);
38
+ this.logger.debug(e);
39
+ reject(e);
40
+ });
41
+ client.on('close', () => {
42
+ this.logger.fatal('NATS connection close.');
43
+ });
44
+ });
45
+ }
46
+ /**
47
+ * Disconnect from a NATS server
48
+ *
49
+ * @memberof NatsTransporter
50
+ */
51
+ disconnect() {
52
+ if (this.client) {
53
+ this.client.flush(() => {
54
+ this.client.close();
55
+ this.client = null;
56
+ });
57
+ }
58
+ }
59
+ }export{NatsConnector};//# sourceMappingURL=nats-connector.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nats-connector.mjs","sources":["../../src/connectors/nats-connector.ts"],"sourcesContent":[null],"names":[],"mappings":"iGAOa,aAAa,CAAA;AAStB,IAAA,WAAA,CAAY,IAAqB,EAAA;QAC7B,IA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ACjD,oBAAA,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;AAC1B,iBAAA;AACL,aAAC,CAAC,CAAC;YAEH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,KAAI;gBACrB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;AAC5C,gBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACrB,MAAM,CAAC,CAAC,CAAC,CAAC;AACd,aAAC,CAAC,CAAC;AAEH,YAAA,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAK;AACpB,gBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;AAChD,aAAC,CAAC,CAAC;AACP,SAAC,CAAC,CAAC;KACN;AAED;;;;AAIG;IACI,UAAU,GAAA;QACb,IAAI,IAAI,CAAC,MAAM,EAAE;AACb,YAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAK;AACnB,gBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;AACpB,gBAAA,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;AACvB,aAAC,CAAC,CAAC;AACN,SAAA;KACJ;AACJ"}
@@ -0,0 +1,54 @@
1
+ 'use strict';var _=require('lodash'),apolloServerCacheRedis=require('apollo-server-cache-redis'),server=require('@cdm-logger/server'),envConfig=require('../config/env-config.cjs');function _interopNamespaceDefault(e){var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var ___namespace=/*#__PURE__*/_interopNamespaceDefault(_);class RedisConnector {
2
+ /**
3
+ * Creats an instance of Redis.
4
+ *
5
+ * @param {object} opts
6
+ */
7
+ constructor(opts) {
8
+ this.opts = ___namespace.defaultsDeep(opts, {
9
+ prefix: null,
10
+ });
11
+ this.logger = server.logger.child({ className: 'RedisConnector' });
12
+ }
13
+ /**
14
+ * Connect to the server
15
+ *
16
+ * @memberof RedisConnector
17
+ */
18
+ connect() {
19
+ return new Promise((resolve, reject) => {
20
+ reject('this method not implemented');
21
+ });
22
+ }
23
+ /**
24
+ * Return redis or redis.cluster Dataloader Client
25
+ *
26
+ * @memberof RedisConnection
27
+ */
28
+ getRedisDataloaderClient() {
29
+ let client;
30
+ if (envConfig.config.REDIS_CLUSTER_ENABLED) {
31
+ if (!envConfig.config.REDIS_CLUSTER_URL) {
32
+ throw new Error(`No nodes defined for cluster, ${envConfig.config.REDIS_CLUSTER_URL}`);
33
+ }
34
+ this.logger.info('Setting Redis.Cluster connection');
35
+ client = new apolloServerCacheRedis.RedisClusterCache(envConfig.config.REDIS_CLUSTER_URL, this.opts);
36
+ }
37
+ else {
38
+ this.logger.info('Setting Redis connection');
39
+ client = new apolloServerCacheRedis.RedisCache(envConfig.config.REDIS_URL || this.opts);
40
+ }
41
+ return client;
42
+ }
43
+ /**
44
+ * Close Redis client connection.
45
+ *
46
+ * @memberof RedisConnection
47
+ */
48
+ disconnect() {
49
+ if (!this.client) {
50
+ return;
51
+ }
52
+ return this.client.close();
53
+ }
54
+ }exports.RedisConnector=RedisConnector;//# sourceMappingURL=redis-connector.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis-connector.cjs","sources":["../../src/connectors/redis-connector.ts"],"sourcesContent":[null],"names":["_","logger","config","RedisClusterCache","RedisCache"],"mappings":"khBASa,cAAc,CAAA;AAOvB;;;;AAIG;AACH,IAAA,WAAA,CAAY,IAAoD,EAAA;QAC5D,IAAI,CAAC,IAAI,GAAGA,YAAC,CAAC,YAAY,CAAC,IAAI,EAAE;AAC7B,YAAA,MAAM,EAAE,IAAI;AACf,SAAA,CAAC,CAAC;AACH,QAAA,IAAI,CAAC,MAAM,GAAGC,aAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC,CAAC;KAC/D;AAED;;;;AAIG;IACI,OAAO,GAAA;QACV,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;YACnC,MAAM,CAAC,6BAA6B,CAAC,CAAC;AAC1C,SAAC,CAAC,CAAC;KACN;AAED;;;;AAIG;IACI,wBAAwB,GAAA;AAC3B,QAAA,IAAI,MAAsC,CAAC;QAC3C,IAAIC,gBAAM,CAAC,qBAAqB,EAAE;AAC9B,YAAA,IAAI,CAACA,gBAAM,CAAC,iBAAiB,EAAE;gBAC3B,MAAM,IAAI,KAAK,CAAC,CAAA,8BAAA,EAAiCA,gBAAM,CAAC,iBAAiB,CAAE,CAAA,CAAC,CAAC;AAChF,aAAA;AACD,YAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;AACrD,YAAA,MAAM,GAAG,IAAIC,wCAAiB,CAACD,gBAAM,CAAC,iBAAwB,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9E,SAAA;AAAM,aAAA;AACH,YAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;AAC7C,YAAA,MAAM,GAAG,IAAIE,iCAAU,CAAEF,gBAAM,CAAC,SAAiB,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;AACnE,SAAA;AACD,QAAA,OAAO,MAAM,CAAC;KACjB;AAED;;;;AAIG;IACI,UAAU,GAAA;AACb,QAAA,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YACd,OAAO;AACV,SAAA;AACD,QAAA,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;KAC9B;AACJ"}
@@ -0,0 +1,31 @@
1
+ import { RedisClusterCache, RedisCache } from 'apollo-server-cache-redis';
2
+ import * as IORedis from 'ioredis';
3
+ export declare class RedisConnector {
4
+ private client;
5
+ private opts;
6
+ private logger;
7
+ /**
8
+ * Creats an instance of Redis.
9
+ *
10
+ * @param {object} opts
11
+ */
12
+ constructor(opts?: IORedis.ClusterOptions | IORedis.RedisOptions);
13
+ /**
14
+ * Connect to the server
15
+ *
16
+ * @memberof RedisConnector
17
+ */
18
+ connect(): Promise<unknown>;
19
+ /**
20
+ * Return redis or redis.cluster Dataloader Client
21
+ *
22
+ * @memberof RedisConnection
23
+ */
24
+ getRedisDataloaderClient(): RedisClusterCache | RedisCache;
25
+ /**
26
+ * Close Redis client connection.
27
+ *
28
+ * @memberof RedisConnection
29
+ */
30
+ disconnect(): Promise<void>;
31
+ }
@@ -0,0 +1,54 @@
1
+ import*as _ from'lodash';import {RedisClusterCache,RedisCache}from'apollo-server-cache-redis';import {logger}from'@cdm-logger/server';import {config}from'../config/env-config.mjs';class RedisConnector {
2
+ /**
3
+ * Creats an instance of Redis.
4
+ *
5
+ * @param {object} opts
6
+ */
7
+ constructor(opts) {
8
+ this.opts = _.defaultsDeep(opts, {
9
+ prefix: null,
10
+ });
11
+ this.logger = logger.child({ className: 'RedisConnector' });
12
+ }
13
+ /**
14
+ * Connect to the server
15
+ *
16
+ * @memberof RedisConnector
17
+ */
18
+ connect() {
19
+ return new Promise((resolve, reject) => {
20
+ reject('this method not implemented');
21
+ });
22
+ }
23
+ /**
24
+ * Return redis or redis.cluster Dataloader Client
25
+ *
26
+ * @memberof RedisConnection
27
+ */
28
+ getRedisDataloaderClient() {
29
+ let client;
30
+ if (config.REDIS_CLUSTER_ENABLED) {
31
+ if (!config.REDIS_CLUSTER_URL) {
32
+ throw new Error(`No nodes defined for cluster, ${config.REDIS_CLUSTER_URL}`);
33
+ }
34
+ this.logger.info('Setting Redis.Cluster connection');
35
+ client = new RedisClusterCache(config.REDIS_CLUSTER_URL, this.opts);
36
+ }
37
+ else {
38
+ this.logger.info('Setting Redis connection');
39
+ client = new RedisCache(config.REDIS_URL || this.opts);
40
+ }
41
+ return client;
42
+ }
43
+ /**
44
+ * Close Redis client connection.
45
+ *
46
+ * @memberof RedisConnection
47
+ */
48
+ disconnect() {
49
+ if (!this.client) {
50
+ return;
51
+ }
52
+ return this.client.close();
53
+ }
54
+ }export{RedisConnector};//# sourceMappingURL=redis-connector.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis-connector.mjs","sources":["../../src/connectors/redis-connector.ts"],"sourcesContent":[null],"names":[],"mappings":"0LASa,cAAc,CAAA;AAOvB;;;;AAIG;AACH,IAAA,WAAA,CAAY,IAAoD,EAAA;QAC5D,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE;AAC7B,YAAA,MAAM,EAAE,IAAI;AACf,SAAA,CAAC,CAAC;AACH,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC,CAAC;KAC/D;AAED;;;;AAIG;IACI,OAAO,GAAA;QACV,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;YACnC,MAAM,CAAC,6BAA6B,CAAC,CAAC;AAC1C,SAAC,CAAC,CAAC;KACN;AAED;;;;AAIG;IACI,wBAAwB,GAAA;AAC3B,QAAA,IAAI,MAAsC,CAAC;QAC3C,IAAI,MAAM,CAAC,qBAAqB,EAAE;AAC9B,YAAA,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE;gBAC3B,MAAM,IAAI,KAAK,CAAC,CAAA,8BAAA,EAAiC,MAAM,CAAC,iBAAiB,CAAE,CAAA,CAAC,CAAC;AAChF,aAAA;AACD,YAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;AACrD,YAAA,MAAM,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,iBAAwB,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9E,SAAA;AAAM,aAAA;AACH,YAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;AAC7C,YAAA,MAAM,GAAG,IAAI,UAAU,CAAE,MAAM,CAAC,SAAiB,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;AACnE,SAAA;AACD,QAAA,OAAO,MAAM,CAAC;KACjB;AAED;;;;AAIG;IACI,UAAU,GAAA;AACb,QAAA,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YACd,OAAO;AACV,SAAA;AACD,QAAA,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;KAC9B;AACJ"}
package/lib/index.cjs ADDED
@@ -0,0 +1 @@
1
+ 'use strict';var stackServer=require('./stack-server.cjs');exports.StackServer=stackServer.StackServer;//# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { StackServer } from './stack-server';
package/lib/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export{StackServer}from'./stack-server.mjs';//# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import { GenericObject, Transporter } from 'moleculer';
2
+ type TransporterOptions = {
3
+ options: any;
4
+ type: string;
5
+ };
6
+ export type TransporterType = Transporter | string | GenericObject | TransporterOptions | null;
7
+ export {};