@quillsql/node 0.9.19 → 0.9.20
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/cjs/db/CachedConnection.d.ts +5 -1
- package/dist/cjs/db/CachedConnection.js +55 -20
- package/dist/cjs/db/CachedConnection.js.map +1 -1
- package/dist/cjs/index.d.ts +3 -18
- package/dist/cjs/index.js +135 -194
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/models/Cache.d.ts +14 -4
- package/dist/esm/db/CachedConnection.d.ts +5 -1
- package/dist/esm/db/CachedConnection.js +55 -20
- package/dist/esm/db/CachedConnection.js.map +1 -1
- package/dist/esm/index.d.ts +3 -18
- package/dist/esm/index.js +136 -195
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/models/Cache.d.ts +14 -4
- package/package.json +1 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Mappable, CacheCredentials } from "../models/Cache";
|
|
2
2
|
import { DatabaseConnection, DatabaseConnectionConfig, DatabaseConnectionType } from "./DatabaseHelper";
|
|
3
3
|
export declare class CachedConnection {
|
|
4
|
+
private static sharedRedisClients;
|
|
4
5
|
databaseType: DatabaseConnectionType;
|
|
5
6
|
readonly pool: DatabaseConnection;
|
|
7
|
+
tenantIds: (string | number)[] | null;
|
|
6
8
|
ttl: number;
|
|
7
9
|
cache: Mappable | null;
|
|
8
|
-
isCacheJobRunning: boolean;
|
|
9
10
|
private _isClosed;
|
|
10
11
|
get isClosed(): boolean;
|
|
11
12
|
/** Private constructor; use CachedConnection.create(...) */
|
|
@@ -13,6 +14,9 @@ export declare class CachedConnection {
|
|
|
13
14
|
/** Async factory initializer */
|
|
14
15
|
static create(databaseType: DatabaseConnectionType, config: DatabaseConnectionConfig, cacheConfig?: Partial<CacheCredentials>): Promise<CachedConnection>;
|
|
15
16
|
query(text: string, overwriteCache?: boolean): Promise<any>;
|
|
17
|
+
getCachedValue(key: string): Promise<string | null>;
|
|
18
|
+
setCachedValue(key: string, value: string): Promise<void>;
|
|
19
|
+
deleteCachedValue(key: string): Promise<void>;
|
|
16
20
|
/**
|
|
17
21
|
* Configures and returns a cache instance or null if none could be created.
|
|
18
22
|
*/
|
|
@@ -22,7 +22,7 @@ class CachedConnection {
|
|
|
22
22
|
/** Private constructor; use CachedConnection.create(...) */
|
|
23
23
|
constructor(databaseType, config, cacheConfig = {}) {
|
|
24
24
|
var _a;
|
|
25
|
-
this.
|
|
25
|
+
this.tenantIds = null;
|
|
26
26
|
this._isClosed = false;
|
|
27
27
|
this.databaseType = databaseType;
|
|
28
28
|
this.pool = (0, DatabaseHelper_1.connectToDatabase)(databaseType, config);
|
|
@@ -46,27 +46,27 @@ class CachedConnection {
|
|
|
46
46
|
if (!this.cache) {
|
|
47
47
|
return yield (0, DatabaseHelper_1.runQueryByDatabase)(this.databaseType, this.pool, text);
|
|
48
48
|
}
|
|
49
|
-
// `text` must be a tenant-scoped SQL query.
|
|
50
|
-
// Since runQueryByDatabase doesn't receive tenant information from any
|
|
51
|
-
// of its other parameters
|
|
52
|
-
const key = text;
|
|
53
49
|
if (!overwriteCache) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
try {
|
|
51
|
+
const cached = yield this.cache.get(text);
|
|
52
|
+
if (cached)
|
|
53
|
+
return JSON.parse(cached);
|
|
54
|
+
}
|
|
55
|
+
catch (_a) {
|
|
56
|
+
// cache read fail. corrupted
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const newResult = yield (0, DatabaseHelper_1.runQueryByDatabase)(this.databaseType, this.pool, text);
|
|
60
|
+
if (!newResult) {
|
|
61
|
+
return newResult;
|
|
57
62
|
}
|
|
58
|
-
const result = yield (0, DatabaseHelper_1.runQueryByDatabase)(this.databaseType, this.pool, text);
|
|
59
63
|
try {
|
|
60
|
-
yield this.cache.set(
|
|
64
|
+
yield this.cache.set(text, JSON.stringify(newResult));
|
|
61
65
|
}
|
|
62
66
|
catch (error) {
|
|
63
|
-
|
|
64
|
-
if (this.isCacheJobRunning) {
|
|
65
|
-
throw new Error(message);
|
|
66
|
-
}
|
|
67
|
-
console.warn(message); // This runs for general data fetching by customers
|
|
67
|
+
console.warn("Redis Cache Set Failed: ", error);
|
|
68
68
|
}
|
|
69
|
-
return
|
|
69
|
+
return newResult;
|
|
70
70
|
}
|
|
71
71
|
catch (err) {
|
|
72
72
|
if ((0, Error_1.isSuperset)(err, Error_1.PgError)) {
|
|
@@ -78,22 +78,56 @@ class CachedConnection {
|
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
+
getCachedValue(key) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
if (!this.cache || this.isClosed)
|
|
84
|
+
return null;
|
|
85
|
+
return yield this.cache.get(key);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
setCachedValue(key, value) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
if (!this.cache || this.isClosed)
|
|
91
|
+
return;
|
|
92
|
+
yield this.cache.set(key, value, "EX", this.ttl);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
deleteCachedValue(key) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
if (!this.cache || this.isClosed)
|
|
98
|
+
return;
|
|
99
|
+
yield this.cache.del(key);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
81
102
|
/**
|
|
82
103
|
* Configures and returns a cache instance or null if none could be created.
|
|
83
104
|
*/
|
|
84
105
|
getCache(_a) {
|
|
85
106
|
return __awaiter(this, arguments, void 0, function* ({ username, password, host, port, cacheType, }) {
|
|
86
107
|
if (cacheType === "redis" || cacheType === "rediss") {
|
|
108
|
+
const sharedKey = JSON.stringify({
|
|
109
|
+
cacheType,
|
|
110
|
+
username: username || "",
|
|
111
|
+
password: password || "",
|
|
112
|
+
host: host || "",
|
|
113
|
+
port: port || "",
|
|
114
|
+
});
|
|
115
|
+
const existingClient = CachedConnection.sharedRedisClients.get(sharedKey);
|
|
116
|
+
if (existingClient) {
|
|
117
|
+
return existingClient;
|
|
118
|
+
}
|
|
87
119
|
const client = (0, redis_1.createClient)({
|
|
88
|
-
username: username ||
|
|
89
|
-
password: password ||
|
|
120
|
+
username: username || "",
|
|
121
|
+
password: password || "",
|
|
90
122
|
socket: {
|
|
91
|
-
host: host ||
|
|
92
|
-
port: port ? parseInt(port) : 0
|
|
123
|
+
host: host || "",
|
|
124
|
+
port: port ? parseInt(port) : 0,
|
|
93
125
|
},
|
|
94
126
|
});
|
|
95
127
|
client.on("error", (err) => console.log("Redis Client Error", err));
|
|
96
128
|
yield client.connect();
|
|
129
|
+
console.log("Redis connected to host:", host);
|
|
130
|
+
CachedConnection.sharedRedisClients.set(sharedKey, client);
|
|
97
131
|
return client;
|
|
98
132
|
}
|
|
99
133
|
return null;
|
|
@@ -110,4 +144,5 @@ class CachedConnection {
|
|
|
110
144
|
}
|
|
111
145
|
}
|
|
112
146
|
exports.CachedConnection = CachedConnection;
|
|
147
|
+
CachedConnection.sharedRedisClients = new Map();
|
|
113
148
|
//# sourceMappingURL=CachedConnection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CachedConnection.js","sourceRoot":"","sources":["../../../src/db/CachedConnection.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,iCAAqC;AACrC,0CAAqD;AACrD,qDAO0B;AAE1B,mDAAmD;AACnD,MAAM,iBAAiB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAEvC,MAAa,gBAAgB;
|
|
1
|
+
{"version":3,"file":"CachedConnection.js","sourceRoot":"","sources":["../../../src/db/CachedConnection.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,iCAAqC;AACrC,0CAAqD;AACrD,qDAO0B;AAE1B,mDAAmD;AACnD,MAAM,iBAAiB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAEvC,MAAa,gBAAgB;IAS3B,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C,CAAC,CAAC,CAAC,CAAC;qBAChC;iBACF,CAAC,CAAC;gBACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC,CAAC;gBAEpE,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;gBACvB,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE,IAAI,CAAC,CAAA;gBAC7C,gBAAgB,CAAC,kBAAkB,CAAC,GAAG,CAAC,SAAS,EAAE,MAAkB,CAAC,CAAC;gBACvE,OAAO,MAAkB,CAAC;YAC5B,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IAEM,OAAO;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAEK,KAAK;;YACT,IAAA,uCAAsB,EAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YACrD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACxB,CAAC;KAAA;;AAtJH,4CAuJC;AAtJgB,mCAAkB,GAAG,IAAI,GAAG,EAAoB,AAA9B,CAA+B"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -19,21 +19,6 @@ export interface QuillQueryResult {
|
|
|
19
19
|
fields: any[];
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
export type QuillCacheResult = {
|
|
23
|
-
status: "failed";
|
|
24
|
-
error: string;
|
|
25
|
-
} | {
|
|
26
|
-
status: "complete";
|
|
27
|
-
cachedDashboards: string[];
|
|
28
|
-
failedDashboards: string[];
|
|
29
|
-
};
|
|
30
|
-
export interface QuillCacheParams {
|
|
31
|
-
tenants: QuillQueryParams["tenants"];
|
|
32
|
-
dashboards?: string[];
|
|
33
|
-
signal?: AbortSignal;
|
|
34
|
-
parallelQueries?: number;
|
|
35
|
-
maxRowsPerReport?: number;
|
|
36
|
-
}
|
|
37
22
|
export type QuillStreamEvent = {
|
|
38
23
|
type: "start";
|
|
39
24
|
} | {
|
|
@@ -89,8 +74,6 @@ export declare class Quill implements AsyncDisposable {
|
|
|
89
74
|
private baseUrl;
|
|
90
75
|
private config;
|
|
91
76
|
private initPromise;
|
|
92
|
-
private lock;
|
|
93
|
-
private lockInitComplete;
|
|
94
77
|
constructor(data: {
|
|
95
78
|
privateKey: string;
|
|
96
79
|
databaseType: "snowflake";
|
|
@@ -124,7 +107,9 @@ export declare class Quill implements AsyncDisposable {
|
|
|
124
107
|
metadataServerURL?: string;
|
|
125
108
|
});
|
|
126
109
|
private ensureReady;
|
|
127
|
-
|
|
110
|
+
private getTenantMappedFlagsCacheKey;
|
|
111
|
+
private getTenantMappedFlagsFromCache;
|
|
112
|
+
private setTenantMappedFlagsCache;
|
|
128
113
|
query({ tenants, flags, metadata, filters, adminEnabled, }: QuillQueryParams): Promise<QuillQueryResult>;
|
|
129
114
|
stream({ tenants, flags, metadata, filters, adminEnabled, signal, }: QuillStreamOptions): Promise<AsyncIterable<QuillStreamEvent>>;
|
|
130
115
|
private applyLimit;
|