@quillsql/node 0.9.17 → 0.9.18

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,18 +1,13 @@
1
1
  export interface Mappable {
2
2
  get(key: string): Promise<string | null>;
3
3
  set(key: string, value: string, type?: string, ttl?: number): Promise<string | null>;
4
- lRange(key: string, start: number, stop: number): Promise<string[]>;
5
- rPush(key: string, ...elements: string[]): Promise<number>;
6
- expire(key: string, seconds: number): Promise<number | boolean>;
7
- del(...keys: string[]): Promise<number>;
8
- multi(): CacheTransaction;
9
- }
10
- export interface CacheTransaction {
11
- del(...keys: string[]): CacheTransaction;
12
- rPush(key: string, ...elements: string[]): CacheTransaction;
13
- expire(key: string, seconds: number): CacheTransaction;
14
- set(key: string, value: string, type?: string, ttl?: number): CacheTransaction;
15
- exec(): Promise<unknown>;
4
+ set(key: string, value: string, options: {
5
+ NX?: boolean;
6
+ XX?: boolean;
7
+ EX?: number;
8
+ PX?: number;
9
+ }): Promise<string | null>;
10
+ del(key: string): Promise<number>;
16
11
  }
17
12
  export interface CacheCredentials {
18
13
  username: string;
@@ -0,0 +1,13 @@
1
+ import { Mappable } from "../models/Cache";
2
+ export declare class Lock {
3
+ private readonly cacheLockKey;
4
+ private readonly lastCacheKey;
5
+ private readonly ttlSeconds;
6
+ private readonly cooldownMs;
7
+ constructor(clientId: string);
8
+ acquire(cache: Mappable): Promise<string>;
9
+ release(cache: Mappable, lockValue: string): Promise<void>;
10
+ releaseSafely(cache: Mappable, lockValue: string): Promise<void>;
11
+ persistCooldown(cache: Mappable): Promise<void>;
12
+ persistCooldownSafely(cache: Mappable): Promise<void>;
13
+ }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ // A 2-part lock:
3
+ // 1) Redis Distributed lock ( 1 machine can hold it at a time )
4
+ // 2) 6-hour Cooldown
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Lock = void 0;
16
+ class Lock {
17
+ constructor(clientId) {
18
+ this.ttlSeconds = 90 * 60; // 90 minutes
19
+ this.cooldownMs = 6 * 60 * 60 * 1000; // 6 hours
20
+ this.cacheLockKey = `quill:sdk:cache:lock:${clientId}`;
21
+ this.lastCacheKey = `quill:sdk:cache:locktime:${clientId}`;
22
+ }
23
+ acquire(cache) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const lockValue = `${process.pid}:${Date.now()}:${Math.random().toString(36).slice(2)}`;
26
+ const acquired = yield cache.set(this.cacheLockKey, lockValue, { NX: true, EX: this.ttlSeconds });
27
+ if (!acquired) {
28
+ throw new Error(".cache() is being called by another instance already. Please try again later.");
29
+ }
30
+ const raw = yield cache.get(this.lastCacheKey);
31
+ const lastCacheRunAt = raw ? Number(raw) : NaN;
32
+ if (Number.isFinite(lastCacheRunAt) && Date.now() - lastCacheRunAt < this.cooldownMs) {
33
+ yield this.release(cache, lockValue);
34
+ throw new Error("Caching cooldown is active. Please try again later.");
35
+ }
36
+ return lockValue;
37
+ });
38
+ }
39
+ release(cache, lockValue) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ var _a;
42
+ const acquiredAtMs = Number((_a = lockValue.split(":")[1]) !== null && _a !== void 0 ? _a : "0");
43
+ if (acquiredAtMs > 0 && Date.now() - acquiredAtMs >= (this.ttlSeconds - 60) * 1000)
44
+ return;
45
+ if ((yield cache.get(this.cacheLockKey)) !== lockValue)
46
+ return;
47
+ yield cache.del(this.cacheLockKey);
48
+ });
49
+ }
50
+ releaseSafely(cache, lockValue) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ try {
53
+ yield this.release(cache, lockValue);
54
+ }
55
+ catch (error) {
56
+ console.warn("Failed to release cache lock", error);
57
+ }
58
+ });
59
+ }
60
+ persistCooldown(cache) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ yield cache.set(this.lastCacheKey, String(Date.now()), { EX: this.cooldownMs / 1000 });
63
+ });
64
+ }
65
+ persistCooldownSafely(cache) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ try {
68
+ yield this.persistCooldown(cache);
69
+ }
70
+ catch (error) {
71
+ console.warn("Caching complete but failed to persist last cache run time", error);
72
+ }
73
+ });
74
+ }
75
+ }
76
+ exports.Lock = Lock;
77
+ //# sourceMappingURL=Lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Lock.js","sourceRoot":"","sources":["../../../src/utils/Lock.ts"],"names":[],"mappings":";AAAA,kBAAkB;AAClB,gEAAgE;AAChE,sBAAsB;;;;;;;;;;;;AAItB,MAAa,IAAI;IAMf,YAAY,QAAgB;QAHX,eAAU,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,aAAa;QACnC,eAAU,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,UAAU;QAG1D,IAAI,CAAC,YAAY,GAAG,wBAAwB,QAAQ,EAAE,CAAC;QACvD,IAAI,CAAC,YAAY,GAAG,4BAA4B,QAAQ,EAAE,CAAC;IAC7D,CAAC;IAEY,OAAO,CAAC,KAAe;;YAClC,MAAM,SAAS,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YAExF,MAAM,QAAQ,GAAkB,MAAM,KAAK,CAAC,GAAG,CAAC,IAAI,C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AC3D,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YACvC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,IAAI,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;KAAA;IAEY,eAAe,CAAC,KAAe;;YAC1C,MAAM,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,UAAU,GAAG,IAAI,EAAE,CAAC,CAAC;QACzF,CAAC;KAAA;IAEY,qBAAqB,CAAC,KAAe;;YAChD,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;YACpC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,IAAI,CAAC,4DAA4D,EAAE,KAAK,CAAC,CAAC;YACpF,CAAC;QACH,CAAC;KAAA;CACF;AAvDD,oBAuDC"}
@@ -1,12 +1,11 @@
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;
5
4
  databaseType: DatabaseConnectionType;
6
5
  readonly pool: DatabaseConnection;
7
- tenantIds: (string | number)[] | null;
8
6
  ttl: number;
9
7
  cache: Mappable | null;
8
+ isCacheJobRunning: boolean;
10
9
  private _isClosed;
11
10
  get isClosed(): boolean;
12
11
  /** Private constructor; use CachedConnection.create(...) */
@@ -14,9 +13,6 @@ export declare class CachedConnection {
14
13
  /** Async factory initializer */
15
14
  static create(databaseType: DatabaseConnectionType, config: DatabaseConnectionConfig, cacheConfig?: Partial<CacheCredentials>): Promise<CachedConnection>;
16
15
  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>;
20
16
  /**
21
17
  * Configures and returns a cache instance or null if none could be created.
22
18
  */
@@ -19,7 +19,7 @@ export class CachedConnection {
19
19
  /** Private constructor; use CachedConnection.create(...) */
20
20
  constructor(databaseType, config, cacheConfig = {}) {
21
21
  var _a;
22
- this.tenantIds = null;
22
+ this.isCacheJobRunning = false;
23
23
  this._isClosed = false;
24
24
  this.databaseType = databaseType;
25
25
  this.pool = connectToDatabase(databaseType, config);
@@ -43,27 +43,27 @@ export class CachedConnection {
43
43
  if (!this.cache) {
44
44
  return yield runQueryByDatabase(this.databaseType, this.pool, text);
45
45
  }
46
+ // `text` must be a tenant-scoped SQL query.
47
+ // Since runQueryByDatabase doesn't receive tenant information from any
48
+ // of its other parameters
49
+ const key = text;
46
50
  if (!overwriteCache) {
47
- try {
48
- const cached = yield this.cache.get(text);
49
- if (cached)
50
- return JSON.parse(cached);
51
- }
52
- catch (_a) {
53
- // cache read fail. corrupted
54
- }
55
- }
56
- const newResult = yield runQueryByDatabase(this.databaseType, this.pool, text);
57
- if (!newResult) {
58
- return newResult;
51
+ let cachedResult = yield this.cache.get(key);
52
+ if (cachedResult)
53
+ return JSON.parse(cachedResult);
59
54
  }
55
+ const result = yield runQueryByDatabase(this.databaseType, this.pool, text);
60
56
  try {
61
- this.cache.set(text, JSON.stringify(newResult));
57
+ yield this.cache.set(key, JSON.stringify(result), "EX", this.ttl);
62
58
  }
63
59
  catch (error) {
64
- console.warn("Redis Cache Set Failed: ", error);
60
+ const message = "Redis Cache Set Failed: " + String(error);
61
+ if (this.isCacheJobRunning) {
62
+ throw new Error(message);
63
+ }
64
+ console.warn(message); // This runs for general data fetching by customers
65
65
  }
66
- return newResult;
66
+ return result;
67
67
  }
68
68
  catch (err) {
69
69
  if (isSuperset(err, PgError)) {
@@ -75,56 +75,22 @@ export class CachedConnection {
75
75
  }
76
76
  });
77
77
  }
78
- getCachedValue(key) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- if (!this.cache || this.isClosed)
81
- return null;
82
- return yield this.cache.get(key);
83
- });
84
- }
85
- setCachedValue(key, value) {
86
- return __awaiter(this, void 0, void 0, function* () {
87
- if (!this.cache || this.isClosed)
88
- return;
89
- yield this.cache.set(key, value, "EX", this.ttl);
90
- });
91
- }
92
- deleteCachedValue(key) {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- if (!this.cache || this.isClosed)
95
- return;
96
- yield this.cache.del(key);
97
- });
98
- }
99
78
  /**
100
79
  * Configures and returns a cache instance or null if none could be created.
101
80
  */
102
81
  getCache(_a) {
103
82
  return __awaiter(this, arguments, void 0, function* ({ username, password, host, port, cacheType, }) {
104
83
  if (cacheType === "redis" || cacheType === "rediss") {
105
- const sharedKey = JSON.stringify({
106
- cacheType,
107
- username: username || "",
108
- password: password || "",
109
- host: host || "",
110
- port: port || "",
111
- });
112
- const existingClient = CachedConnection.sharedRedisClients.get(sharedKey);
113
- if (existingClient) {
114
- return existingClient;
115
- }
116
84
  const client = createClient({
117
- username: username || "",
118
- password: password || "",
85
+ username: username || '',
86
+ password: password || '',
119
87
  socket: {
120
- host: host || "",
121
- port: port ? parseInt(port) : 0,
88
+ host: host || '',
89
+ port: port ? parseInt(port) : 0
122
90
  },
123
91
  });
124
92
  client.on("error", (err) => console.log("Redis Client Error", err));
125
93
  yield client.connect();
126
- console.log("Redis connected to host:", host);
127
- CachedConnection.sharedRedisClients.set(sharedKey, client);
128
94
  return client;
129
95
  }
130
96
  return null;
@@ -140,5 +106,4 @@ export class CachedConnection {
140
106
  });
141
107
  }
142
108
  }
143
- CachedConnection.sharedRedisClients = new Map();
144
109
  //# sourceMappingURL=CachedConnection.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CachedConnection.js","sourceRoot":"","sources":["../../../src/db/CachedConnection.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,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,CAAC;YACH,CAAC;QACH,CAAC;KAAA;IAED;;OAEG;IACW,QAAQ;6DAAC,EACrB,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,SAAS,GACY;YACrB,IAAI,SAAS,KAAK,OAAO,IAAI,SAAS,KAAK,QAAQ,EAAE,CAAC;gBACpD,MAAM,MAAM,GAAG,YAAY,CAAC;oBAC1B,QAAQ,EAAE,QAAQ,IAAI,EAAE;oBACxB,QAAQ,EAAE,QAAQ,IAAI,EAAE;oBACxB,MAAM,EAAE;wBACN,IAAI,EAAE,IAAI,IAAI,EAAE;wBAChB,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;qBAChC;iBACF,CAAC,CAAC;gBAEH,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,MAAkB,CAAC;YAC5B,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IAEM,OAAO;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAEK,KAAK;;YACT,sBAAsB,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YACrD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACxB,CAAC;KAAA;CACF"}
@@ -19,6 +19,21 @@ 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
+ }
22
37
  export type QuillStreamEvent = {
23
38
  type: "start";
24
39
  } | {
@@ -74,6 +89,7 @@ export declare class Quill implements AsyncDisposable {
74
89
  private baseUrl;
75
90
  private config;
76
91
  private initPromise;
92
+ private lock;
77
93
  constructor(data: {
78
94
  privateKey: string;
79
95
  databaseType: "snowflake";
@@ -107,9 +123,7 @@ export declare class Quill implements AsyncDisposable {
107
123
  metadataServerURL?: string;
108
124
  });
109
125
  private ensureReady;
110
- private getTenantMappedFlagsCacheKey;
111
- private getTenantMappedFlagsFromCache;
112
- private setTenantMappedFlagsCache;
126
+ cache({ tenants, dashboards, signal, parallelQueries, maxRowsPerReport, }: QuillCacheParams): Promise<QuillCacheResult>;
113
127
  query({ tenants, flags, metadata, filters, adminEnabled, }: QuillQueryParams): Promise<QuillQueryResult>;
114
128
  stream({ tenants, flags, metadata, filters, adminEnabled, signal, }: QuillStreamOptions): Promise<AsyncIterable<QuillStreamEvent>>;
115
129
  private applyLimit;