@technicity/data-service-generator 0.11.2 → 0.11.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.
@@ -1,20 +1,20 @@
1
- import { RedisClientType, RedisClusterType } from "redis";
1
+ import Redis, { Cluster } from "ioredis";
2
2
  import { TResolveParams } from "./IRuntime";
3
3
  import Stats from "./Stats";
4
4
  export declare type RedisConfig = {
5
- url: string;
5
+ host: string;
6
+ port: number;
6
7
  tls?: boolean;
7
8
  db?: number;
8
9
  socketTimeout?: number;
9
10
  clusterMode?: boolean;
10
11
  };
11
12
  declare class Cache {
12
- client: RedisClientType | RedisClusterType;
13
+ client: Redis | Cluster;
13
14
  waiting?: Set<() => void> | undefined;
14
- logs?: boolean;
15
15
  stats?: Stats;
16
16
  constructor(redisConfig: RedisConfig, debug?: string[]);
17
- log(message: string): void;
17
+ debug(message: string): void;
18
18
  pending(): Promise<void>;
19
19
  from(input: TResolveParams): Promise<{
20
20
  request: string;
@@ -1,60 +1,63 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const crypto_1 = require("crypto");
4
- const redis_1 = require("redis");
4
+ const ioredis_1 = require("ioredis");
5
+ const loglevel_1 = require("loglevel");
5
6
  const utility_1 = require("./lib/utility");
6
7
  const Stats_1 = require("./Stats");
7
8
  class Cache {
8
9
  constructor(redisConfig, debug) {
9
10
  this.waiting = new Set();
10
- if (debug?.includes("Cache"))
11
- this.logs = true;
12
- const { url } = redisConfig;
11
+ if (debug?.includes("Cache")) {
12
+ loglevel_1.default.setLevel("DEBUG");
13
+ }
14
+ const { host, port } = redisConfig;
13
15
  const tls = redisConfig.tls ? true : false;
14
16
  const clusterMode = redisConfig.clusterMode ? true : false;
15
- const scheme = tls ? "rediss://" : "redis://";
16
17
  const db = redisConfig.db == null ? 0 : redisConfig.db;
17
18
  const socketTimeout = redisConfig.socketTimeout == null ? 50000 : redisConfig.socketTimeout;
18
19
  let client = undefined;
19
20
  if (clusterMode) {
20
- client = (0, redis_1.createCluster)({
21
- rootNodes: [
22
- {
23
- url: `${scheme}${url}`
24
- }
25
- ],
26
- defaults: {
27
- socket: {
28
- tls,
29
- rejectUnauthorized: false,
30
- connectTimeout: socketTimeout
31
- }
21
+ client = new ioredis_1.default.Cluster([
22
+ {
23
+ host,
24
+ port
25
+ }
26
+ ], {
27
+ dnsLookup: (address, callback) => callback(null, address),
28
+ redisOptions: {
29
+ tls: tls ? {} : undefined,
30
+ lazyConnect: true,
31
+ commandTimeout: socketTimeout
32
32
  }
33
33
  });
34
34
  }
35
35
  else {
36
- client = (0, redis_1.createClient)({
37
- url: `${scheme}${url}/${db}`,
38
- socket: {
39
- tls,
40
- rejectUnauthorized: false,
41
- connectTimeout: socketTimeout
42
- }
36
+ client = new ioredis_1.default({
37
+ host,
38
+ port,
39
+ db,
40
+ lazyConnect: true,
41
+ tls: tls ? {} : undefined
43
42
  });
44
43
  }
45
44
  this.client = client;
46
45
  client.connect();
47
46
  client.on("connect", () => {
47
+ loglevel_1.default.info(`DB SDK connected to redis server at ${host}:${port}`);
48
48
  if (this.waiting)
49
49
  this.waiting.forEach((x) => x());
50
50
  this.waiting = undefined;
51
51
  });
52
+ client.on("error", (err) => {
53
+ loglevel_1.default.error("ERROR: redis client");
54
+ loglevel_1.default.error(err);
55
+ });
52
56
  if (debug?.includes("Stats"))
53
57
  this.stats = new Stats_1.default(client);
54
58
  }
55
- log(message) {
56
- if (this.logs)
57
- console.log(`\n-- CACHE: ${message}\n`);
59
+ debug(message) {
60
+ loglevel_1.default.debug(`\n-- CACHE: ${message}\n`);
58
61
  }
59
62
  async pending() {
60
63
  if (this.waiting)
@@ -84,11 +87,11 @@ class Cache {
84
87
  const uuid = result[1];
85
88
  if (!uuid)
86
89
  continue;
87
- pending.push(redis.sAdd(`deps:${uuid}`, [key]), redis.sAdd(`cached:${key}`, [uuid]));
90
+ pending.push(redis.sadd(`deps:${uuid}`, [key]), redis.sadd(`cached:${key}`, [uuid]));
88
91
  }
89
92
  if (!pending.length)
90
93
  return;
91
- this.log(`insert: ${key.substring(0, 6)}`);
94
+ this.debug(`insert: ${key.substring(0, 6)}`);
92
95
  await Promise.all([redis.set(`cache:${key}`, json), ...pending]);
93
96
  }
94
97
  async read(key) {
@@ -96,23 +99,23 @@ class Cache {
96
99
  const data = await this.client.get(`cache:${key}`);
97
100
  const shorthand = key.substring(0, 6);
98
101
  if (data) {
99
- this.log(`hit: ${shorthand}`);
102
+ this.debug(`hit: ${shorthand}`);
100
103
  return JSON.parse(data);
101
104
  }
102
105
  else {
103
- this.log(`miss: ${shorthand}`);
106
+ this.debug(`miss: ${shorthand}`);
104
107
  return undefined;
105
108
  }
106
109
  }
107
110
  async purge(...uuids) {
108
111
  const redis = this.client;
109
112
  await (0, utility_1.mapAsync)(uuids, (uuid) => {
110
- const getDependancies = redis.sMembers(`deps:${uuid}`);
113
+ const getDependancies = redis.smembers(`deps:${uuid}`);
111
114
  return [
112
115
  (0, utility_1.mapAsync)(getDependancies, (key) => {
113
- const getDependants = redis.sMembers(`cached:${key}`);
116
+ const getDependants = redis.smembers(`cached:${key}`);
114
117
  return [
115
- (0, utility_1.mapAsync)(getDependants, (uuid) => redis.sRem(`deps:${uuid}`, [key])),
118
+ (0, utility_1.mapAsync)(getDependants, (uuid) => redis.srem(`deps:${uuid}`, [key])),
116
119
  redis.del(`cache:${key}`),
117
120
  redis.del(`cached:${key}`)
118
121
  ];
@@ -17,6 +17,8 @@ const SqlString = require("sqlstring");
17
17
  const Cache_1 = require("./Cache");
18
18
  const MySQL_1 = require("./lib/MySQL");
19
19
  const shared_1 = require("./lib/shared");
20
+ const loglevel_1 = require("loglevel");
21
+ loglevel_1.default.setDefaultLevel("INFO");
20
22
  class RuntimeMySQL {
21
23
  constructor(clientOpts, otherOpts, artifacts) {
22
24
  _RuntimeMySQL_dialect.set(this, "mysql");
@@ -1,7 +1,7 @@
1
- import { RedisClientType, RedisClusterType } from "@redis/client";
1
+ import Redis, { Cluster } from "ioredis";
2
2
  declare class Stats {
3
- client: RedisClientType<any> | RedisClusterType<any>;
4
- constructor(client: RedisClientType<any> | RedisClusterType<any>);
3
+ client: Redis | Cluster;
4
+ constructor(client: Redis | Cluster);
5
5
  updateStats: (ms: number, category: string) => Promise<void>;
6
6
  }
7
7
  declare namespace timer {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@technicity/data-service-generator",
3
- "version": "0.11.2",
3
+ "version": "0.11.3",
4
4
  "main": "./dist/index.js",
5
5
  "files": [
6
6
  "dist"
@@ -23,13 +23,14 @@
23
23
  "fs-extra": "10.0.0",
24
24
  "graphql": "15.8.0",
25
25
  "graphql-relay": "^0.9.0",
26
+ "ioredis": "^5.2.4",
26
27
  "join-monster": "git+https://github.com/apalm/join-monster.git#3e93d7028ccbf50f728577b2290b5f2638b639cb",
27
28
  "json-schema-to-typescript": "10.1.5",
28
29
  "lodash": "^4.17.20",
30
+ "loglevel": "^1.8.1",
29
31
  "mssql": "^6.3.1",
30
32
  "mysql": "^2.18.1",
31
33
  "prettier": "^2.1.2",
32
- "redis": "^4.3.0",
33
34
  "sqlstring": "^2.3.2",
34
35
  "tsqlstring": "^1.0.1",
35
36
  "uuid": "^8.3.2"