@technicity/data-service-generator 0.11.2 → 0.11.4
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/runtime/Cache.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
17
|
+
debug(message: string): void;
|
|
18
18
|
pending(): Promise<void>;
|
|
19
19
|
from(input: TResolveParams): Promise<{
|
|
20
20
|
request: string;
|
package/dist/runtime/Cache.js
CHANGED
|
@@ -1,60 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const crypto_1 = require("crypto");
|
|
4
|
-
const
|
|
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
|
-
|
|
12
|
-
|
|
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 =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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 =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
// call connect() if not already connected or in the process of connecting
|
|
46
|
+
if (client.status !== "connect" &&
|
|
47
|
+
client.status !== "connecting" &&
|
|
48
|
+
client.status !== "reconnecting") {
|
|
49
|
+
client.connect();
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
loglevel_1.default.info("DB SDK client status is currently: " + client.status);
|
|
53
|
+
}
|
|
47
54
|
client.on("connect", () => {
|
|
55
|
+
loglevel_1.default.info(`DB SDK connected to redis server at ${host}:${port}`);
|
|
48
56
|
if (this.waiting)
|
|
49
57
|
this.waiting.forEach((x) => x());
|
|
50
58
|
this.waiting = undefined;
|
|
51
59
|
});
|
|
60
|
+
client.on("error", (err) => {
|
|
61
|
+
loglevel_1.default.error("ERROR: redis client");
|
|
62
|
+
loglevel_1.default.error(err);
|
|
63
|
+
});
|
|
52
64
|
if (debug?.includes("Stats"))
|
|
53
65
|
this.stats = new Stats_1.default(client);
|
|
54
66
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
console.log(`\n-- CACHE: ${message}\n`);
|
|
67
|
+
debug(message) {
|
|
68
|
+
loglevel_1.default.debug(`\n-- CACHE: ${message}\n`);
|
|
58
69
|
}
|
|
59
70
|
async pending() {
|
|
60
71
|
if (this.waiting)
|
|
@@ -84,11 +95,11 @@ class Cache {
|
|
|
84
95
|
const uuid = result[1];
|
|
85
96
|
if (!uuid)
|
|
86
97
|
continue;
|
|
87
|
-
pending.push(redis.
|
|
98
|
+
pending.push(redis.sadd(`deps:${uuid}`, [key]), redis.sadd(`cached:${key}`, [uuid]));
|
|
88
99
|
}
|
|
89
100
|
if (!pending.length)
|
|
90
101
|
return;
|
|
91
|
-
this.
|
|
102
|
+
this.debug(`insert: ${key.substring(0, 6)}`);
|
|
92
103
|
await Promise.all([redis.set(`cache:${key}`, json), ...pending]);
|
|
93
104
|
}
|
|
94
105
|
async read(key) {
|
|
@@ -96,23 +107,23 @@ class Cache {
|
|
|
96
107
|
const data = await this.client.get(`cache:${key}`);
|
|
97
108
|
const shorthand = key.substring(0, 6);
|
|
98
109
|
if (data) {
|
|
99
|
-
this.
|
|
110
|
+
this.debug(`hit: ${shorthand}`);
|
|
100
111
|
return JSON.parse(data);
|
|
101
112
|
}
|
|
102
113
|
else {
|
|
103
|
-
this.
|
|
114
|
+
this.debug(`miss: ${shorthand}`);
|
|
104
115
|
return undefined;
|
|
105
116
|
}
|
|
106
117
|
}
|
|
107
118
|
async purge(...uuids) {
|
|
108
119
|
const redis = this.client;
|
|
109
120
|
await (0, utility_1.mapAsync)(uuids, (uuid) => {
|
|
110
|
-
const getDependancies = redis.
|
|
121
|
+
const getDependancies = redis.smembers(`deps:${uuid}`);
|
|
111
122
|
return [
|
|
112
123
|
(0, utility_1.mapAsync)(getDependancies, (key) => {
|
|
113
|
-
const getDependants = redis.
|
|
124
|
+
const getDependants = redis.smembers(`cached:${key}`);
|
|
114
125
|
return [
|
|
115
|
-
(0, utility_1.mapAsync)(getDependants, (uuid) => redis.
|
|
126
|
+
(0, utility_1.mapAsync)(getDependants, (uuid) => redis.srem(`deps:${uuid}`, [key])),
|
|
116
127
|
redis.del(`cache:${key}`),
|
|
117
128
|
redis.del(`cached:${key}`)
|
|
118
129
|
];
|
|
@@ -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");
|
package/dist/runtime/Stats.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import Redis, { Cluster } from "ioredis";
|
|
2
2
|
declare class Stats {
|
|
3
|
-
client:
|
|
4
|
-
constructor(client:
|
|
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.
|
|
3
|
+
"version": "0.11.4",
|
|
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"
|