@technicity/data-service-generator 0.11.1 → 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.
package/dist/runtime/Cache.d.ts
CHANGED
|
@@ -1,19 +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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
7
|
+
tls?: boolean;
|
|
8
|
+
db?: number;
|
|
9
|
+
socketTimeout?: number;
|
|
10
|
+
clusterMode?: boolean;
|
|
9
11
|
};
|
|
10
12
|
declare class Cache {
|
|
11
|
-
client:
|
|
13
|
+
client: Redis | Cluster;
|
|
12
14
|
waiting?: Set<() => void> | undefined;
|
|
13
|
-
logs?: boolean;
|
|
14
15
|
stats?: Stats;
|
|
15
16
|
constructor(redisConfig: RedisConfig, debug?: string[]);
|
|
16
|
-
|
|
17
|
+
debug(message: string): void;
|
|
17
18
|
pending(): Promise<void>;
|
|
18
19
|
from(input: TResolveParams): Promise<{
|
|
19
20
|
request: string;
|
package/dist/runtime/Cache.js
CHANGED
|
@@ -1,36 +1,63 @@
|
|
|
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
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
if (debug?.includes("Cache")) {
|
|
12
|
+
loglevel_1.default.setLevel("DEBUG");
|
|
13
|
+
}
|
|
14
|
+
const { host, port } = redisConfig;
|
|
15
|
+
const tls = redisConfig.tls ? true : false;
|
|
16
|
+
const clusterMode = redisConfig.clusterMode ? true : false;
|
|
17
|
+
const db = redisConfig.db == null ? 0 : redisConfig.db;
|
|
18
|
+
const socketTimeout = redisConfig.socketTimeout == null ? 50000 : redisConfig.socketTimeout;
|
|
19
|
+
let client = undefined;
|
|
20
|
+
if (clusterMode) {
|
|
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
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
client = new ioredis_1.default({
|
|
37
|
+
host,
|
|
38
|
+
port,
|
|
39
|
+
db,
|
|
40
|
+
lazyConnect: true,
|
|
41
|
+
tls: tls ? {} : undefined
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
this.client = client;
|
|
22
45
|
client.connect();
|
|
23
46
|
client.on("connect", () => {
|
|
47
|
+
loglevel_1.default.info(`DB SDK connected to redis server at ${host}:${port}`);
|
|
24
48
|
if (this.waiting)
|
|
25
49
|
this.waiting.forEach((x) => x());
|
|
26
50
|
this.waiting = undefined;
|
|
27
51
|
});
|
|
52
|
+
client.on("error", (err) => {
|
|
53
|
+
loglevel_1.default.error("ERROR: redis client");
|
|
54
|
+
loglevel_1.default.error(err);
|
|
55
|
+
});
|
|
28
56
|
if (debug?.includes("Stats"))
|
|
29
57
|
this.stats = new Stats_1.default(client);
|
|
30
58
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
console.log(`\n-- CACHE: ${message}\n`);
|
|
59
|
+
debug(message) {
|
|
60
|
+
loglevel_1.default.debug(`\n-- CACHE: ${message}\n`);
|
|
34
61
|
}
|
|
35
62
|
async pending() {
|
|
36
63
|
if (this.waiting)
|
|
@@ -60,11 +87,11 @@ class Cache {
|
|
|
60
87
|
const uuid = result[1];
|
|
61
88
|
if (!uuid)
|
|
62
89
|
continue;
|
|
63
|
-
pending.push(redis.
|
|
90
|
+
pending.push(redis.sadd(`deps:${uuid}`, [key]), redis.sadd(`cached:${key}`, [uuid]));
|
|
64
91
|
}
|
|
65
92
|
if (!pending.length)
|
|
66
93
|
return;
|
|
67
|
-
this.
|
|
94
|
+
this.debug(`insert: ${key.substring(0, 6)}`);
|
|
68
95
|
await Promise.all([redis.set(`cache:${key}`, json), ...pending]);
|
|
69
96
|
}
|
|
70
97
|
async read(key) {
|
|
@@ -72,23 +99,23 @@ class Cache {
|
|
|
72
99
|
const data = await this.client.get(`cache:${key}`);
|
|
73
100
|
const shorthand = key.substring(0, 6);
|
|
74
101
|
if (data) {
|
|
75
|
-
this.
|
|
102
|
+
this.debug(`hit: ${shorthand}`);
|
|
76
103
|
return JSON.parse(data);
|
|
77
104
|
}
|
|
78
105
|
else {
|
|
79
|
-
this.
|
|
106
|
+
this.debug(`miss: ${shorthand}`);
|
|
80
107
|
return undefined;
|
|
81
108
|
}
|
|
82
109
|
}
|
|
83
110
|
async purge(...uuids) {
|
|
84
111
|
const redis = this.client;
|
|
85
112
|
await (0, utility_1.mapAsync)(uuids, (uuid) => {
|
|
86
|
-
const getDependancies = redis.
|
|
113
|
+
const getDependancies = redis.smembers(`deps:${uuid}`);
|
|
87
114
|
return [
|
|
88
115
|
(0, utility_1.mapAsync)(getDependancies, (key) => {
|
|
89
|
-
const getDependants = redis.
|
|
116
|
+
const getDependants = redis.smembers(`cached:${key}`);
|
|
90
117
|
return [
|
|
91
|
-
(0, utility_1.mapAsync)(getDependants, (uuid) => redis.
|
|
118
|
+
(0, utility_1.mapAsync)(getDependants, (uuid) => redis.srem(`deps:${uuid}`, [key])),
|
|
92
119
|
redis.del(`cache:${key}`),
|
|
93
120
|
redis.del(`cached:${key}`)
|
|
94
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");
|
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.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"
|