@deephaven-enterprise/client-utils 2026.1.260612134256-ga1e17c94e2

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.
@@ -0,0 +1,49 @@
1
+ import type { EnterpriseClient, WorkerKind } from '@deephaven-enterprise/jsapi-types';
2
+ import type { dh as DhType } from '@deephaven/jsapi-types';
3
+ /**
4
+ * Interface defining a connection manager for fetching APIs from and creating
5
+ * connections to CorePlus workers, and managing the lifecycle of the underlying
6
+ * client. Implementation may cache values.
7
+ */
8
+ export interface CorePlusManager {
9
+ /** The DHE JS API client */
10
+ get dheClient(): EnterpriseClient;
11
+ /** Whether this has been disposed. */
12
+ get isDisposed(): boolean;
13
+ /** Dispose resources. */
14
+ dispose(): Promise<void>;
15
+ /**
16
+ * Get the API for the specified worker kind.
17
+ * @param engine The engine to get the API for
18
+ * @param jsApiUrl The URL to load the API from
19
+ * @return The API for the specified worker kind
20
+ */
21
+ getApi(engine: string, jsApiUrl: string): Promise<typeof DhType>;
22
+ /**
23
+ * Get the CoreClient for the specified worker.
24
+ * @param dh The Core API to create the CoreClient with.
25
+ * @param grpcUrl The gRPC URL
26
+ * @param envoyPrefix The envoy prefix
27
+ * @return The CoreClient for the specified worker kind
28
+ */
29
+ getClient(dh: typeof DhType, grpcUrl: string, envoyPrefix?: string | null): Promise<DhType.CoreClient>;
30
+ /**
31
+ * Get the IDE connection for the specified worker.
32
+ * @param dh The Core API to create the CoreClient with.
33
+ * @param grpcUrl The gRPC URL
34
+ * @param envoyPrefix The envoy prefix
35
+ * @return The IDE connection for the specified worker kind
36
+ */
37
+ getConnection(dh: typeof DhType, grpcUrl: string, envoyPrefix?: string | null): Promise<DhType.IdeConnection>;
38
+ /**
39
+ * Get the worker kind or null for the specified engine.
40
+ * @param engine The engine to get the worker kind for
41
+ */
42
+ getEngineWorkerKind(engine: string): WorkerKind | null;
43
+ /**
44
+ * Check if an engine is a community worker kind.
45
+ * @param engine The engine name to check
46
+ */
47
+ isCommunityWorkerKind(engine: string | null): boolean;
48
+ }
49
+ export default CorePlusManager;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,191 @@
1
+ import type { QueryInfo, ReplicaStatus, WorkerKind } from '@deephaven-enterprise/jsapi-types';
2
+ import { type dh as DhType } from '@deephaven/jsapi-types';
3
+ import { type Brand } from '@deephaven/utils';
4
+ export type CorePlusManagerCacheKey = Brand<string, 'CorePlusManagerCacheKey'>;
5
+ /** Store query info needed to clear Core+ caches when queries change status */
6
+ export type QueryInfoCacheEntry = Partial<Pick<ReplicaStatus, 'status' | 'communityPort' | 'grpcUrl' | 'envoyPrefix' | 'processInfoId'>> & {
7
+ name: string;
8
+ };
9
+ /**
10
+ * Given an iterable of promises, return a promise that resolves to an array
11
+ * containing only the resolved values. Any rejected promises will be filtered
12
+ * out.
13
+ * @param promises Array of promises to wait for
14
+ * @returns Promise that resolves to an array of resolved values
15
+ */
16
+ export declare function allResolved<T>(promises: Iterable<Promise<T>>): Promise<T[]>;
17
+ /**
18
+ * Create a cache entry from a QueryInfo object
19
+ * @param query The QueryInfo object to create a cache entry from
20
+ */
21
+ export declare function createQueryInfoCacheEntry(query: QueryInfo): QueryInfoCacheEntry;
22
+ /**
23
+ * Get cache key from a GRPC URL + Envoy prefix associated with a Core+ worker.
24
+ * @param grpcUrl GRPC URL of the Core+ worker
25
+ * @param envoyPrefix Optional Envoy prefix of the Core+ worker
26
+ * @returns Cache key string
27
+ */
28
+ export declare function getCacheKey(grpcUrl: string, envoyPrefix?: string | null): CorePlusManagerCacheKey;
29
+ export declare class CorePlusManagerCache {
30
+ constructor();
31
+ private readonly api;
32
+ private readonly client;
33
+ private readonly connection;
34
+ private readonly engineWorkerKind;
35
+ private readonly isCommunityWorkerKind;
36
+ private readonly queryInfo;
37
+ get apiSize(): number;
38
+ get clientSize(): number;
39
+ get connectionSize(): number;
40
+ get engineWorkerKindSize(): number;
41
+ get isCommunityWorkerKindSize(): number;
42
+ get queryInfoSize(): number;
43
+ /**
44
+ * Clear all caches. Caches will be evicted synchronously, but clients /
45
+ * connections require resolving Promises first before they can be closed.
46
+ */
47
+ clearAll(): Promise<void>;
48
+ /**
49
+ * Remove cached API for the given engine.
50
+ * @param engine The engine to evict the API for
51
+ */
52
+ evictApi(engine: string): void;
53
+ /**
54
+ * Remove any cached client and connection for the given grpcUrl and envoyPrefix.
55
+ * Also close any existing connections.
56
+ * @param grpcUrl The grpcUrl of the Core+ worker
57
+ * @param envoyPrefix The optional envoyPrefix of the Core+ worker
58
+ */
59
+ evictClientAndConnection(grpcUrl: string | undefined, envoyPrefix?: string | null): Promise<void>;
60
+ /**
61
+ * Remove cached QueryInfo entry for the given serial.
62
+ * @param serial The query serial to evict
63
+ */
64
+ evictQueryInfo(serial: string): void;
65
+ /**
66
+ * Get a cached API Promise for the given engine.
67
+ * @param engine The engine to get the API for
68
+ * @returns The cached API Promise, or throws if not found
69
+ */
70
+ getApiOrThrow(engine: string): Promise<typeof DhType>;
71
+ /**
72
+ * Find cache key for a cached connection by its connection ID.
73
+ * @param cnId The connection ID to check for
74
+ * @returns The cache key if found, or null if not found
75
+ */
76
+ getConnectionCacheKeyById(cnId: number): CorePlusManagerCacheKey | null;
77
+ /**
78
+ * Get a cached client for the given cache key.
79
+ * @param cacheKey The cache key to look for
80
+ * @returns The matching Promise<CoreClient>, or throws if not found
81
+ */
82
+ getClientOrThrow(cacheKey: CorePlusManagerCacheKey): Promise<DhType.CoreClient>;
83
+ /**
84
+ * Get a cached connection for the given cache key.
85
+ * @param cacheKey The cache key to look for
86
+ * @returns The matching [Promise<IdeConnection>, connectionId], or throws if not found
87
+ */
88
+ getConnectionOrThrow(cacheKey: CorePlusManagerCacheKey): [Promise<DhType.IdeConnection>, number];
89
+ /**
90
+ * Get a cached worker kind or null for the given engine.
91
+ * @param engine The engine to look for
92
+ * @returns The matching WorkerKind or null. Throws if not found in cache.
93
+ */
94
+ getEngineWorkerKindOrThrow(engine: string): WorkerKind | null;
95
+ /**
96
+ * Get a cached isCommunityWorkerKind entry for the given engine.
97
+ * @param engine The engine to look for
98
+ * @returns The matching isCommunityWorkerKind boolean, or throws if not found
99
+ */
100
+ getIsCommunityWorkerKindOrThrow(engine: string): boolean;
101
+ /**
102
+ * Get a cached QueryInfo serial + entry by cache key.
103
+ * @param cacheKey The cache key to look for
104
+ * @returns The matching [serial, QueryInfoCacheEntry], or null if not found
105
+ */
106
+ getQueryInfoByCacheKey(cacheKey?: CorePlusManagerCacheKey | null): [string, QueryInfoCacheEntry] | null;
107
+ /**
108
+ * Get a cached QueryInfo entry for the given serial.
109
+ * @param serial The query serial to look for
110
+ * @returns The matching QueryInfoCacheEntry, or throws if not found
111
+ */
112
+ getQueryInfoOrThrow(serial: string): QueryInfoCacheEntry;
113
+ /**
114
+ * Check if there is a cached API for the given engine.
115
+ * @param engine The engine to check for
116
+ * @returns True if there is a cached API, false otherwise
117
+ */
118
+ hasApi(engine: string): boolean;
119
+ /**
120
+ * Check if there is a cached client for the given cache key.
121
+ * @param cacheKey The cache key to check for
122
+ * @returns True if there is a cached client, false otherwise
123
+ */
124
+ hasClient(cacheKey: CorePlusManagerCacheKey): boolean;
125
+ /**
126
+ * Check if there is a cached connection for the given cache key.
127
+ * @param cacheKey The cache key to check for
128
+ * @returns True if there is a cached connection, false otherwise
129
+ */
130
+ hasConnection(cacheKey: CorePlusManagerCacheKey): boolean;
131
+ /**
132
+ * Check if there is a cached worker kind for the given engine.
133
+ * @param engine The engine to check for
134
+ * @returns True if there is a cached worker kind (can be cached as
135
+ * null), false otherwise
136
+ */
137
+ hasEngineWorkerKind(engine: string): boolean;
138
+ /**
139
+ * Check if there is a cached isCommunityWorkerKind entry for the given engine.
140
+ * @param engine The engine to check for
141
+ * @returns True if there is a cached isCommunityWorkerKind entry, false otherwise
142
+ */
143
+ hasIsCommunityWorkerKind(engine: string): boolean;
144
+ /**
145
+ * Check if there is a cached QueryInfo entry for the given serial.
146
+ * @param serial
147
+ * @returns True if there is a cached QueryInfo entry, false otherwise
148
+ */
149
+ hasQueryInfo(serial: string): boolean;
150
+ /**
151
+ * Log info about current contents of connection cache.
152
+ */
153
+ logConnectionCacheInfo(): void;
154
+ /**
155
+ * Cache an JS API Promise for the given engine.
156
+ * @param engine The engine to cache the JS API for
157
+ * @param apiPromise The JS API Promise to cache
158
+ */
159
+ setApi(engine: string, apiPromise: Promise<typeof DhType>): void;
160
+ /**
161
+ * Cache a client for the given cache key.
162
+ * @param cacheKey The cache key to store the client for
163
+ * @param clientPromise The client Promise to cache
164
+ */
165
+ setClient(cacheKey: CorePlusManagerCacheKey, clientPromise: Promise<DhType.CoreClient>): void;
166
+ /**
167
+ * Cache a connection + id for the given cache key.
168
+ * @param cacheKey The cache key to store the connection for
169
+ * @param connectionTuple The [connection Promise, connectionId] tuple to cache
170
+ */
171
+ setConnection(cacheKey: CorePlusManagerCacheKey, connectionTuple: [Promise<DhType.IdeConnection>, number]): void;
172
+ /**
173
+ * Cache a worker kind or null for the given engine.
174
+ * @param engine The engine to store the worker kind for.
175
+ * @param workerKind The WorkerKind or null to cache
176
+ */
177
+ setEngineWorkerKind(engine: string, workerKind: WorkerKind | null): void;
178
+ /**
179
+ * Cache whether an engine is community or not.
180
+ * @param engine The engine to store the info for
181
+ * @param isCommunity Whether the worker kind is community or not
182
+ */
183
+ setIsCommunityWorkerKind(engine: string, isCommunity: boolean): void;
184
+ /**
185
+ * Cache QueryInfo entry for the given query serial.
186
+ * @param serial The query serial to store the entry for
187
+ * @param cacheEntry The QueryInfoCacheEntry to cache
188
+ */
189
+ setQueryInfo(serial: string, cacheEntry: QueryInfoCacheEntry): void;
190
+ }
191
+ export default CorePlusManagerCache;
@@ -0,0 +1,349 @@
1
+ import Log from '@deephaven/log';
2
+ import { assertNotNull, bindAllMethods } from '@deephaven/utils';
3
+ const logger = Log.module('CorePlusManagerCache');
4
+ /**
5
+ * Given an iterable of promises, return a promise that resolves to an array
6
+ * containing only the resolved values. Any rejected promises will be filtered
7
+ * out.
8
+ * @param promises Array of promises to wait for
9
+ * @returns Promise that resolves to an array of resolved values
10
+ */
11
+ export async function allResolved(promises) {
12
+ const settled = await Promise.allSettled(promises);
13
+ return settled
14
+ .filter((c) => c.status === 'fulfilled')
15
+ .map(({ value }) => value);
16
+ }
17
+ /**
18
+ * Create a cache entry from a QueryInfo object
19
+ * @param query The QueryInfo object to create a cache entry from
20
+ */
21
+ export function createQueryInfoCacheEntry(query) {
22
+ var _a, _b, _c, _d, _e;
23
+ return {
24
+ name: query.name,
25
+ status: (_a = query.designated) === null || _a === void 0 ? void 0 : _a.status,
26
+ communityPort: (_b = query.designated) === null || _b === void 0 ? void 0 : _b.communityPort,
27
+ grpcUrl: (_c = query.designated) === null || _c === void 0 ? void 0 : _c.grpcUrl,
28
+ envoyPrefix: (_d = query.designated) === null || _d === void 0 ? void 0 : _d.envoyPrefix,
29
+ processInfoId: (_e = query.designated) === null || _e === void 0 ? void 0 : _e.processInfoId,
30
+ };
31
+ }
32
+ /**
33
+ * Get cache key from a GRPC URL + Envoy prefix associated with a Core+ worker.
34
+ * @param grpcUrl GRPC URL of the Core+ worker
35
+ * @param envoyPrefix Optional Envoy prefix of the Core+ worker
36
+ * @returns Cache key string
37
+ */
38
+ export function getCacheKey(grpcUrl, envoyPrefix) {
39
+ if (envoyPrefix == null) {
40
+ return grpcUrl;
41
+ }
42
+ return `${grpcUrl}|${envoyPrefix}`;
43
+ }
44
+ export class CorePlusManagerCache {
45
+ constructor() {
46
+ this.api = new Map();
47
+ this.client = new Map();
48
+ this.connection = new Map();
49
+ this.engineWorkerKind = new Map();
50
+ this.isCommunityWorkerKind = new Map();
51
+ this.queryInfo = new Map();
52
+ bindAllMethods(this);
53
+ }
54
+ get apiSize() {
55
+ return this.api.size;
56
+ }
57
+ get clientSize() {
58
+ return this.client.size;
59
+ }
60
+ get connectionSize() {
61
+ return this.connection.size;
62
+ }
63
+ get engineWorkerKindSize() {
64
+ return this.engineWorkerKind.size;
65
+ }
66
+ get isCommunityWorkerKindSize() {
67
+ return this.isCommunityWorkerKind.size;
68
+ }
69
+ get queryInfoSize() {
70
+ return this.queryInfo.size;
71
+ }
72
+ /**
73
+ * Clear all caches. Caches will be evicted synchronously, but clients /
74
+ * connections require resolving Promises first before they can be closed.
75
+ */
76
+ async clearAll() {
77
+ const clientPromises = allResolved(this.client.values());
78
+ const connectionPromises = allResolved([...this.connection.values()].map(([cn]) => cn));
79
+ // Go ahead and clear caches synchronously
80
+ this.api.clear();
81
+ this.client.clear();
82
+ this.connection.clear();
83
+ this.engineWorkerKind.clear();
84
+ this.isCommunityWorkerKind.clear();
85
+ this.queryInfo.clear();
86
+ const [clients, connections] = await Promise.all([
87
+ clientPromises,
88
+ connectionPromises,
89
+ ]);
90
+ clients.forEach(client => {
91
+ client.disconnect();
92
+ });
93
+ connections.forEach(cn => {
94
+ cn.close();
95
+ });
96
+ }
97
+ /**
98
+ * Remove cached API for the given engine.
99
+ * @param engine The engine to evict the API for
100
+ */
101
+ evictApi(engine) {
102
+ this.api.delete(engine);
103
+ }
104
+ /**
105
+ * Remove any cached client and connection for the given grpcUrl and envoyPrefix.
106
+ * Also close any existing connections.
107
+ * @param grpcUrl The grpcUrl of the Core+ worker
108
+ * @param envoyPrefix The optional envoyPrefix of the Core+ worker
109
+ */
110
+ async evictClientAndConnection(grpcUrl, envoyPrefix) {
111
+ var _a;
112
+ if (grpcUrl == null) {
113
+ return;
114
+ }
115
+ const cacheKey = getCacheKey(grpcUrl, envoyPrefix);
116
+ if (!this.client.has(cacheKey) && !this.connection.has(cacheKey)) {
117
+ logger.info('evictClientAndConnection', 'no cached clients or connections found for', cacheKey);
118
+ return;
119
+ }
120
+ const clientPromise = this.client.get(cacheKey);
121
+ const [cnPromise, cnId] = (_a = this.connection.get(cacheKey)) !== null && _a !== void 0 ? _a : [];
122
+ if (cnId == null) {
123
+ logger.info('evictClientAndConnection', cacheKey);
124
+ }
125
+ else {
126
+ logger.info(`[cnId:${cnId}]`, `evictClientAndConnection:\n ${cnId}:${cacheKey}`);
127
+ }
128
+ this.client.delete(cacheKey);
129
+ this.connection.delete(cacheKey);
130
+ this.logConnectionCacheInfo();
131
+ try {
132
+ const [client, cn] = await Promise.all([clientPromise, cnPromise]);
133
+ client === null || client === void 0 ? void 0 : client.disconnect();
134
+ cn === null || cn === void 0 ? void 0 : cn.close();
135
+ }
136
+ catch (_b) {
137
+ // If a cached connection happens to get rejected, just ignore
138
+ // it since we are discarding it anyway
139
+ }
140
+ }
141
+ /**
142
+ * Remove cached QueryInfo entry for the given serial.
143
+ * @param serial The query serial to evict
144
+ */
145
+ evictQueryInfo(serial) {
146
+ this.queryInfo.delete(serial);
147
+ }
148
+ /**
149
+ * Get a cached API Promise for the given engine.
150
+ * @param engine The engine to get the API for
151
+ * @returns The cached API Promise, or throws if not found
152
+ */
153
+ getApiOrThrow(engine) {
154
+ const api = this.api.get(engine);
155
+ assertNotNull(api, `No cached API found for engine: ${engine}`);
156
+ return api;
157
+ }
158
+ /**
159
+ * Find cache key for a cached connection by its connection ID.
160
+ * @param cnId The connection ID to check for
161
+ * @returns The cache key if found, or null if not found
162
+ */
163
+ getConnectionCacheKeyById(cnId) {
164
+ // eslint-disable-next-line no-restricted-syntax
165
+ for (const [key, [, id]] of this.connection.entries()) {
166
+ if (id === cnId) {
167
+ return key;
168
+ }
169
+ }
170
+ return null;
171
+ }
172
+ /**
173
+ * Get a cached client for the given cache key.
174
+ * @param cacheKey The cache key to look for
175
+ * @returns The matching Promise<CoreClient>, or throws if not found
176
+ */
177
+ getClientOrThrow(cacheKey) {
178
+ const client = this.client.get(cacheKey);
179
+ assertNotNull(client, `No cached client found for cache key: ${cacheKey}`);
180
+ return client;
181
+ }
182
+ /**
183
+ * Get a cached connection for the given cache key.
184
+ * @param cacheKey The cache key to look for
185
+ * @returns The matching [Promise<IdeConnection>, connectionId], or throws if not found
186
+ */
187
+ getConnectionOrThrow(cacheKey) {
188
+ const connection = this.connection.get(cacheKey);
189
+ assertNotNull(connection, `No cached connection found for cache key: ${cacheKey}`);
190
+ return connection;
191
+ }
192
+ /**
193
+ * Get a cached worker kind or null for the given engine.
194
+ * @param engine The engine to look for
195
+ * @returns The matching WorkerKind or null. Throws if not found in cache.
196
+ */
197
+ getEngineWorkerKindOrThrow(engine) {
198
+ const workerKind = this.engineWorkerKind.get(engine);
199
+ if (workerKind === undefined) {
200
+ throw new Error(`No cached WorkerKind found for engine: ${engine}`);
201
+ }
202
+ return workerKind;
203
+ }
204
+ /**
205
+ * Get a cached isCommunityWorkerKind entry for the given engine.
206
+ * @param engine The engine to look for
207
+ * @returns The matching isCommunityWorkerKind boolean, or throws if not found
208
+ */
209
+ getIsCommunityWorkerKindOrThrow(engine) {
210
+ const isCommunity = this.isCommunityWorkerKind.get(engine);
211
+ assertNotNull(isCommunity, `No cached isCommunityWorkerKind entry found for engine: ${engine}`);
212
+ return isCommunity;
213
+ }
214
+ /**
215
+ * Get a cached QueryInfo serial + entry by cache key.
216
+ * @param cacheKey The cache key to look for
217
+ * @returns The matching [serial, QueryInfoCacheEntry], or null if not found
218
+ */
219
+ getQueryInfoByCacheKey(cacheKey) {
220
+ if (cacheKey == null) {
221
+ return null;
222
+ }
223
+ // eslint-disable-next-line no-restricted-syntax
224
+ for (const [serial, queryInfo] of this.queryInfo.entries()) {
225
+ if (queryInfo.grpcUrl != null &&
226
+ getCacheKey(queryInfo.grpcUrl, queryInfo.envoyPrefix) === cacheKey) {
227
+ return [serial, queryInfo];
228
+ }
229
+ }
230
+ return null;
231
+ }
232
+ /**
233
+ * Get a cached QueryInfo entry for the given serial.
234
+ * @param serial The query serial to look for
235
+ * @returns The matching QueryInfoCacheEntry, or throws if not found
236
+ */
237
+ getQueryInfoOrThrow(serial) {
238
+ const queryInfo = this.queryInfo.get(serial);
239
+ assertNotNull(queryInfo, `No cached QueryInfo found for serial: ${serial}`);
240
+ return queryInfo;
241
+ }
242
+ /**
243
+ * Check if there is a cached API for the given engine.
244
+ * @param engine The engine to check for
245
+ * @returns True if there is a cached API, false otherwise
246
+ */
247
+ hasApi(engine) {
248
+ return this.api.has(engine);
249
+ }
250
+ /**
251
+ * Check if there is a cached client for the given cache key.
252
+ * @param cacheKey The cache key to check for
253
+ * @returns True if there is a cached client, false otherwise
254
+ */
255
+ hasClient(cacheKey) {
256
+ return this.client.has(cacheKey);
257
+ }
258
+ /**
259
+ * Check if there is a cached connection for the given cache key.
260
+ * @param cacheKey The cache key to check for
261
+ * @returns True if there is a cached connection, false otherwise
262
+ */
263
+ hasConnection(cacheKey) {
264
+ return this.connection.has(cacheKey);
265
+ }
266
+ /**
267
+ * Check if there is a cached worker kind for the given engine.
268
+ * @param engine The engine to check for
269
+ * @returns True if there is a cached worker kind (can be cached as
270
+ * null), false otherwise
271
+ */
272
+ hasEngineWorkerKind(engine) {
273
+ return this.engineWorkerKind.has(engine);
274
+ }
275
+ /**
276
+ * Check if there is a cached isCommunityWorkerKind entry for the given engine.
277
+ * @param engine The engine to check for
278
+ * @returns True if there is a cached isCommunityWorkerKind entry, false otherwise
279
+ */
280
+ hasIsCommunityWorkerKind(engine) {
281
+ return this.isCommunityWorkerKind.has(engine);
282
+ }
283
+ /**
284
+ * Check if there is a cached QueryInfo entry for the given serial.
285
+ * @param serial
286
+ * @returns True if there is a cached QueryInfo entry, false otherwise
287
+ */
288
+ hasQueryInfo(serial) {
289
+ return this.queryInfo.has(serial);
290
+ }
291
+ /**
292
+ * Log info about current contents of connection cache.
293
+ */
294
+ logConnectionCacheInfo() {
295
+ const cnIdGrpcUrlPairs = [...this.connection.entries()].map(([key, [, id]]) => `${id}:${key}`);
296
+ logger.info(`cached connections:`, cnIdGrpcUrlPairs.length === 0
297
+ ? '(empty)'
298
+ : `\n ${cnIdGrpcUrlPairs.join('\n ')}`);
299
+ }
300
+ /**
301
+ * Cache an JS API Promise for the given engine.
302
+ * @param engine The engine to cache the JS API for
303
+ * @param apiPromise The JS API Promise to cache
304
+ */
305
+ setApi(engine, apiPromise) {
306
+ this.api.set(engine, apiPromise);
307
+ }
308
+ /**
309
+ * Cache a client for the given cache key.
310
+ * @param cacheKey The cache key to store the client for
311
+ * @param clientPromise The client Promise to cache
312
+ */
313
+ setClient(cacheKey, clientPromise) {
314
+ this.client.set(cacheKey, clientPromise);
315
+ }
316
+ /**
317
+ * Cache a connection + id for the given cache key.
318
+ * @param cacheKey The cache key to store the connection for
319
+ * @param connectionTuple The [connection Promise, connectionId] tuple to cache
320
+ */
321
+ setConnection(cacheKey, connectionTuple) {
322
+ this.connection.set(cacheKey, connectionTuple);
323
+ }
324
+ /**
325
+ * Cache a worker kind or null for the given engine.
326
+ * @param engine The engine to store the worker kind for.
327
+ * @param workerKind The WorkerKind or null to cache
328
+ */
329
+ setEngineWorkerKind(engine, workerKind) {
330
+ this.engineWorkerKind.set(engine, workerKind);
331
+ }
332
+ /**
333
+ * Cache whether an engine is community or not.
334
+ * @param engine The engine to store the info for
335
+ * @param isCommunity Whether the worker kind is community or not
336
+ */
337
+ setIsCommunityWorkerKind(engine, isCommunity) {
338
+ this.isCommunityWorkerKind.set(engine, isCommunity);
339
+ }
340
+ /**
341
+ * Cache QueryInfo entry for the given query serial.
342
+ * @param serial The query serial to store the entry for
343
+ * @param cacheEntry The QueryInfoCacheEntry to cache
344
+ */
345
+ setQueryInfo(serial, cacheEntry) {
346
+ this.queryInfo.set(serial, cacheEntry);
347
+ }
348
+ }
349
+ export default CorePlusManagerCache;
@@ -0,0 +1,128 @@
1
+ import { type WorkerKind, type EnterpriseClient, type EnterpriseDhType } from '@deephaven-enterprise/jsapi-types';
2
+ import { type dh as DhType } from '@deephaven/jsapi-types';
3
+ import type { CorePlusManager } from './CorePlusManager';
4
+ import { CorePlusManagerCache } from './CorePlusManagerCache';
5
+ /**
6
+ * Loads the JS API from a URL. Environment-specific (browser dynamic import vs
7
+ * Node module loading).
8
+ */
9
+ export type ApiLoader = (jsApiUrl: string) => Promise<typeof DhType>;
10
+ /**
11
+ * Constructs an un-logged-in `CoreClient` for a worker. Environment-specific
12
+ * since the client construction (and its transport) differ per environment; the
13
+ * base logs the returned client in.
14
+ */
15
+ export type CoreClientFactory = (dh: typeof DhType, grpcUrl: string, envoyPrefix?: string | null) => DhType.CoreClient | Promise<DhType.CoreClient>;
16
+ /**
17
+ * Connection manager for fetching APIs from and creating connections to CorePlus
18
+ * workers from an EnterpriseClient. Holds the cache wiring, query-config event
19
+ * handling / eviction, worker-kind lookups, connection logging, and the
20
+ * auth-token login flow.
21
+ *
22
+ * It is platform-agnostic: the two environment-specific hooks are injected as
23
+ * constructor functions:
24
+ * - `loadApi` to load the JS API from a URL.
25
+ * - `createCoreClient` to construct the (un-logged-in) `CoreClient`.
26
+ */
27
+ export declare class EnterpriseCorePlusManager implements CorePlusManager {
28
+ readonly dheClient: EnterpriseClient;
29
+ private readonly workerKinds;
30
+ private readonly dh;
31
+ private readonly loadApi;
32
+ private readonly createCoreClient;
33
+ private readonly cache;
34
+ private readonly clientConfigEvents;
35
+ constructor(dheClient: EnterpriseClient, workerKinds: readonly WorkerKind[], dh: EnterpriseDhType, loadApi: ApiLoader, createCoreClient: CoreClientFactory, cache?: CorePlusManagerCache);
36
+ private isDisposedInternal;
37
+ get isDisposed(): boolean;
38
+ /**
39
+ * Dispose of resources managed by this manager.
40
+ * @returns Promise that resolves when dispose is complete.
41
+ */
42
+ dispose(): Promise<void>;
43
+ /**
44
+ * Get the JS API for the given engine version, loading it from the given URL
45
+ * if not found in the cache.
46
+ * @param engine The engine version to get the API for
47
+ * @param jsApiUrl The URL to load the API from if not found in the cache
48
+ * @returns Promise that resolves to the JS API
49
+ */
50
+ getApi(engine: string, jsApiUrl: string): Promise<typeof DhType>;
51
+ /**
52
+ * Get a CoreClient for the given grpcUrl and envoyPrefix, creating it if not
53
+ * found in the cache.
54
+ * @param dh The JS API to use to create the CoreClient
55
+ * @param grpcUrl The grpcUrl of the Core+ worker
56
+ * @param envoyPrefix The optional envoyPrefix of the Core+ worker
57
+ * @returns Promise that resolves to the CoreClient
58
+ */
59
+ getClient(dh: typeof DhType, grpcUrl: string, envoyPrefix?: string | null): Promise<DhType.CoreClient>;
60
+ /**
61
+ * Get an IdeConnection for the given grpcUrl and envoyPrefix, creating it if
62
+ * not found in the cache.
63
+ * @param dh The JS API to use to create the IdeConnection
64
+ * @param grpcUrl The grpcUrl of the Core+ worker
65
+ * @param envoyPrefix The optional envoyPrefix of the Core+ worker
66
+ * @returns Promise that resolves to the IdeConnection
67
+ */
68
+ getConnection(dh: typeof DhType, grpcUrl: string, envoyPrefix?: string | null): Promise<DhType.IdeConnection>;
69
+ /**
70
+ * Get the worker kind for the specified engine.
71
+ * @param engine The engine to get the worker kind for
72
+ * @returns The worker kind for the specified engine, or null if not found
73
+ */
74
+ getEngineWorkerKind(engine: string): WorkerKind | null;
75
+ /**
76
+ * Determine if the given engine is a community worker kind.
77
+ * @param engine The engine name to check
78
+ * @returns True if the engine is a community worker kind, false otherwise.
79
+ */
80
+ isCommunityWorkerKind(engine: string | null): boolean;
81
+ /**
82
+ * Construct a CoreClient via the injected factory and log it in using an auth
83
+ * token from the DHE client. On failure the client is disconnected so it
84
+ * isn't leaked, and the error is rethrown.
85
+ * @param dh The JS API to use to create the CoreClient
86
+ * @param grpcUrl The grpcUrl of the Core+ worker
87
+ * @param envoyPrefix The optional envoyPrefix of the Core+ worker
88
+ * @returns Promise that resolves to a logged-in CoreClient
89
+ */
90
+ private loginCoreClient;
91
+ /**
92
+ * Find the QueryInfo in the DHE client's known configs whose designated
93
+ * replica matches the given grpcUrl.
94
+ * @param grpcUrl The grpcUrl to look up
95
+ * @returns The matching QueryInfo, or undefined if not found
96
+ */
97
+ private findQueryByGrpcUrl;
98
+ /**
99
+ * Cache query info for the given grpcUrl.
100
+ */
101
+ private cacheQueryInfo;
102
+ /**
103
+ * Helper to log info for a connection.
104
+ * @param connectionId The connection ID
105
+ * @param args The args to log
106
+ */
107
+ private logConnectionInfo;
108
+ /**
109
+ * Handle query config changes on a DHE JS API client. Query info gets cached
110
+ * by serial and will remain cached until either:
111
+ * 1. A status change occurs that results in a non 'Running' status
112
+ * 2. processInfoId changes. This should catch any services that have gone down
113
+ * without issuing status change events such as server restarts. Once such
114
+ * services resume, they will have a new processInfoId. Query info +
115
+ * connections associated with the old processInfoId will be discarded.
116
+ * Caches for existing Core+ clients and connections are also cleared when the
117
+ * owning query is removed from the cache.
118
+ *
119
+ * TODO DH-20344: Neither of the cache eviction cases will work for console
120
+ * queries in the case of server restarts since we may not get a non-running
121
+ * status, and the queries won't resume at all. This is probably not a real
122
+ * problem, but it is a slight inconsistency to be aware of and would be nice
123
+ * to figure out if possible.
124
+ * @param event The client listener event containing the QueryInfo detail
125
+ */
126
+ private handleQueryConfigChange;
127
+ }
128
+ export default EnterpriseCorePlusManager;
@@ -0,0 +1,345 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import Log from '@deephaven/log';
13
+ import { assertNotNull, bindAllMethods } from '@deephaven/utils';
14
+ import { createQueryInfoCacheEntry, CorePlusManagerCache, getCacheKey, } from './CorePlusManagerCache';
15
+ import { getWorkerCredentials } from './getWorkerCredentials';
16
+ const logger = Log.module('EnterpriseCorePlusManager');
17
+ /** Protocol identifying a community (Core+) worker kind. */
18
+ const COMMUNITY_PROTOCOL = 'Community';
19
+ let cnInstanceIdGlobal = 0;
20
+ let coreClientInstanceIdGlobal = 0;
21
+ /**
22
+ * Connection manager for fetching APIs from and creating connections to CorePlus
23
+ * workers from an EnterpriseClient. Holds the cache wiring, query-config event
24
+ * handling / eviction, worker-kind lookups, connection logging, and the
25
+ * auth-token login flow.
26
+ *
27
+ * It is platform-agnostic: the two environment-specific hooks are injected as
28
+ * constructor functions:
29
+ * - `loadApi` to load the JS API from a URL.
30
+ * - `createCoreClient` to construct the (un-logged-in) `CoreClient`.
31
+ */
32
+ export class EnterpriseCorePlusManager {
33
+ constructor(dheClient, workerKinds, dh, loadApi, createCoreClient, cache = new CorePlusManagerCache()) {
34
+ this.dheClient = dheClient;
35
+ this.workerKinds = workerKinds;
36
+ this.dh = dh;
37
+ this.loadApi = loadApi;
38
+ this.createCoreClient = createCoreClient;
39
+ this.cache = cache;
40
+ this.isDisposedInternal = false;
41
+ // Traverse the prototype chain so methods are bound even when a subclass
42
+ // (e.g. a Node manager that only sets defaults) is instantiated, so the
43
+ // query-config event handler passed to `addEventListener` stays bound.
44
+ bindAllMethods(this, true);
45
+ logger.info('Creating EnterpriseCorePlusManager');
46
+ this.clientConfigEvents = [
47
+ this.dh.Client.EVENT_CONFIG_ADDED,
48
+ this.dh.Client.EVENT_CONFIG_UPDATED,
49
+ this.dh.Client.EVENT_CONFIG_REMOVED,
50
+ ];
51
+ this.dheClient.getKnownConfigs().forEach(queryInfo => {
52
+ this.handleQueryConfigChange(new CustomEvent('configChange', { detail: queryInfo }));
53
+ });
54
+ this.clientConfigEvents.forEach(eventName => {
55
+ this.dheClient.addEventListener(eventName, this.handleQueryConfigChange);
56
+ });
57
+ }
58
+ get isDisposed() {
59
+ return this.isDisposedInternal;
60
+ }
61
+ /**
62
+ * Dispose of resources managed by this manager.
63
+ * @returns Promise that resolves when dispose is complete.
64
+ */
65
+ async dispose() {
66
+ if (this.isDisposedInternal) {
67
+ return;
68
+ }
69
+ logger.info('Disposing CorePlusManager');
70
+ this.isDisposedInternal = true;
71
+ this.clientConfigEvents.forEach(eventName => {
72
+ this.dheClient.removeEventListener(eventName, this.handleQueryConfigChange);
73
+ });
74
+ await this.cache.clearAll();
75
+ }
76
+ /**
77
+ * Get the JS API for the given engine version, loading it from the given URL
78
+ * if not found in the cache.
79
+ * @param engine The engine version to get the API for
80
+ * @param jsApiUrl The URL to load the API from if not found in the cache
81
+ * @returns Promise that resolves to the JS API
82
+ */
83
+ async getApi(engine, jsApiUrl) {
84
+ if (this.isDisposedInternal) {
85
+ throw new Error(`Attempted to call 'getApi' on a disposed CorePlusManager: ${engine}, ${jsApiUrl}`);
86
+ }
87
+ // Only cache 1 api per engine type
88
+ if (this.cache.hasApi(engine)) {
89
+ logger.debug2('[cached:true] getApi', engine);
90
+ }
91
+ else {
92
+ logger.debug2('[cached:false] getApi', engine);
93
+ const apiPromise = this.loadApi(jsApiUrl).catch(error => {
94
+ // don't keep failed Promises in cache
95
+ this.cache.evictApi(engine);
96
+ throw error;
97
+ });
98
+ this.cache.setApi(engine, apiPromise);
99
+ }
100
+ return this.cache.getApiOrThrow(engine);
101
+ }
102
+ /**
103
+ * Get a CoreClient for the given grpcUrl and envoyPrefix, creating it if not
104
+ * found in the cache.
105
+ * @param dh The JS API to use to create the CoreClient
106
+ * @param grpcUrl The grpcUrl of the Core+ worker
107
+ * @param envoyPrefix The optional envoyPrefix of the Core+ worker
108
+ * @returns Promise that resolves to the CoreClient
109
+ */
110
+ async getClient(dh, grpcUrl, envoyPrefix) {
111
+ if (this.isDisposedInternal) {
112
+ throw new Error(`Attempted to call 'getClient' on a disposed CorePlusManager: ${grpcUrl}`);
113
+ }
114
+ const cacheKey = getCacheKey(grpcUrl, envoyPrefix);
115
+ if (this.cache.hasClient(cacheKey)) {
116
+ logger.debug2('[cached:true] getClient', cacheKey);
117
+ }
118
+ else {
119
+ logger.debug2('[cached:false] getClient', cacheKey);
120
+ const clientPromise = this.loginCoreClient(dh, grpcUrl, envoyPrefix).catch(error => {
121
+ // don't keep failed Promises in cache
122
+ logger.error(`evicting client for:\n ${cacheKey}`, 'due to error', error);
123
+ this.cache.evictClientAndConnection(grpcUrl, envoyPrefix);
124
+ throw error;
125
+ });
126
+ this.cache.setClient(cacheKey, clientPromise);
127
+ }
128
+ return this.cache.getClientOrThrow(cacheKey);
129
+ }
130
+ /**
131
+ * Get an IdeConnection for the given grpcUrl and envoyPrefix, creating it if
132
+ * not found in the cache.
133
+ * @param dh The JS API to use to create the IdeConnection
134
+ * @param grpcUrl The grpcUrl of the Core+ worker
135
+ * @param envoyPrefix The optional envoyPrefix of the Core+ worker
136
+ * @returns Promise that resolves to the IdeConnection
137
+ */
138
+ async getConnection(dh, grpcUrl, envoyPrefix) {
139
+ if (this.isDisposedInternal) {
140
+ throw new Error(`Attempted to call 'getConnection' on a disposed CorePlusManager: ${grpcUrl}`);
141
+ }
142
+ const cacheKey = getCacheKey(grpcUrl, envoyPrefix);
143
+ if (this.cache.hasConnection(cacheKey)) {
144
+ const [, cnId] = this.cache.getConnectionOrThrow(cacheKey);
145
+ this.logConnectionInfo('debug2', cnId, 'getConnection', cacheKey);
146
+ }
147
+ else {
148
+ const queryInfo = this.findQueryByGrpcUrl(grpcUrl);
149
+ // We assume that a `grpcUrl` implies a corresponding queryInfo in
150
+ // `knownConfigs`. If we find this isn't the case, we may need to use
151
+ // `ClientUtils.makeQueryPromise` instead to wait for query config events.
152
+ assertNotNull(queryInfo, `No query info found for grpcUrl: ${grpcUrl}`);
153
+ this.cacheQueryInfo(queryInfo);
154
+ const cnId = cnInstanceIdGlobal;
155
+ cnInstanceIdGlobal += 1;
156
+ this.logConnectionInfo('debug2', cnId, 'getConnection', cacheKey);
157
+ const cnPromise = this.getClient(dh, grpcUrl, envoyPrefix)
158
+ .then(async (coreClient) => {
159
+ const cn = await coreClient.getAsIdeConnection();
160
+ cn.addEventListener(this.dh.Client.EVENT_REQUEST_FAILED, event => {
161
+ this.logConnectionInfo('error', cnId, 'EVENT_REQUEST_FAILED event for connection', cacheKey, event.detail);
162
+ });
163
+ cn.addEventListener(this.dh.Client.EVENT_RECONNECT_AUTH_FAILED, event => {
164
+ this.logConnectionInfo('error', cnId, 'EVENT_RECONNECT_AUTH_FAILED event for connection', cacheKey, event.detail);
165
+ this.cache.evictClientAndConnection(grpcUrl, envoyPrefix);
166
+ });
167
+ return cn;
168
+ })
169
+ .catch(error => {
170
+ // don't keep failed Promises in cache
171
+ logger.error(`[cnId:${cnId}]`, `evicting connection for:\n ${cnId}:${cacheKey}`, 'due to error', error);
172
+ this.cache.evictClientAndConnection(grpcUrl, envoyPrefix);
173
+ throw error;
174
+ });
175
+ logger.info(`[cnId:${cnId}]`, `caching connection for:\n ${cnId}:${cacheKey}`);
176
+ this.cache.setConnection(cacheKey, [cnPromise, cnId]);
177
+ this.cache.logConnectionCacheInfo();
178
+ }
179
+ const [cnPromise] = this.cache.getConnectionOrThrow(cacheKey);
180
+ return cnPromise;
181
+ }
182
+ /**
183
+ * Get the worker kind for the specified engine.
184
+ * @param engine The engine to get the worker kind for
185
+ * @returns The worker kind for the specified engine, or null if not found
186
+ */
187
+ getEngineWorkerKind(engine) {
188
+ var _a;
189
+ if (this.isDisposedInternal) {
190
+ throw new Error(`Attempted to call 'getWorkerKind' on a disposed CorePlusManager: ${engine}`);
191
+ }
192
+ if (this.cache.hasEngineWorkerKind(engine)) {
193
+ logger.debug2('[cached:true] getWorkerKind', engine);
194
+ }
195
+ else {
196
+ logger.debug2('[cached:false] getWorkerKind', engine);
197
+ const kind = (_a = this.workerKinds) === null || _a === void 0 ? void 0 : _a.find(({ name }) => name === engine);
198
+ this.cache.setEngineWorkerKind(engine, kind !== null && kind !== void 0 ? kind : null);
199
+ }
200
+ return this.cache.getEngineWorkerKindOrThrow(engine);
201
+ }
202
+ /**
203
+ * Determine if the given engine is a community worker kind.
204
+ * @param engine The engine name to check
205
+ * @returns True if the engine is a community worker kind, false otherwise.
206
+ */
207
+ isCommunityWorkerKind(engine) {
208
+ var _a, _b;
209
+ if (this.isDisposedInternal) {
210
+ throw new Error(`Attempted to call 'isCommunityWorkerKind' on a disposed CorePlusManager: ${engine}`);
211
+ }
212
+ if (engine == null) {
213
+ return false;
214
+ }
215
+ if (this.cache.hasIsCommunityWorkerKind(engine)) {
216
+ logger.debug2('[cached:true] isCommunityWorkerKind', engine);
217
+ }
218
+ else {
219
+ logger.debug2('[cached:false] isCommunityWorkerKind', engine);
220
+ const workerKind = this.getEngineWorkerKind(engine);
221
+ this.cache.setIsCommunityWorkerKind(engine, workerKind == null
222
+ ? false
223
+ : (_b = (_a = workerKind.protocols) === null || _a === void 0 ? void 0 : _a.includes(COMMUNITY_PROTOCOL)) !== null && _b !== void 0 ? _b : false);
224
+ }
225
+ return this.cache.getIsCommunityWorkerKindOrThrow(engine);
226
+ }
227
+ /**
228
+ * Construct a CoreClient via the injected factory and log it in using an auth
229
+ * token from the DHE client. On failure the client is disconnected so it
230
+ * isn't leaked, and the error is rethrown.
231
+ * @param dh The JS API to use to create the CoreClient
232
+ * @param grpcUrl The grpcUrl of the Core+ worker
233
+ * @param envoyPrefix The optional envoyPrefix of the Core+ worker
234
+ * @returns Promise that resolves to a logged-in CoreClient
235
+ */
236
+ async loginCoreClient(dh, grpcUrl, envoyPrefix) {
237
+ // Use an incrementing id for each call to tie logs for async events
238
+ // together for a particular core client instance.
239
+ const clientLogId = coreClientInstanceIdGlobal;
240
+ coreClientInstanceIdGlobal += 1;
241
+ const logInfo = logger.info.bind(logger, `[loginCoreClient:${clientLogId}]`);
242
+ const logDebug = logger.debug.bind(logger, `[loginCoreClient:${clientLogId}]`);
243
+ const logError = logger.error.bind(logger, `[loginCoreClient:${clientLogId}]`);
244
+ logInfo('Init core client', grpcUrl);
245
+ const coreClient = await this.createCoreClient(dh, grpcUrl, envoyPrefix);
246
+ logDebug('Core client', coreClient, grpcUrl);
247
+ try {
248
+ const loginOptions = await getWorkerCredentials(this.dheClient);
249
+ logDebug('Logging in with', loginOptions, grpcUrl);
250
+ await coreClient.login(loginOptions);
251
+ logInfo('Log in success', grpcUrl);
252
+ return coreClient;
253
+ }
254
+ catch (err) {
255
+ logError(`Log in failed for ${grpcUrl}`, err);
256
+ // If login fails, the client connection is no longer useful and needs to
257
+ // be discarded. Since it won't be available to the caller when we throw,
258
+ // we need to disconnect it here.
259
+ coreClient.disconnect();
260
+ throw err;
261
+ }
262
+ }
263
+ /**
264
+ * Find the QueryInfo in the DHE client's known configs whose designated
265
+ * replica matches the given grpcUrl.
266
+ * @param grpcUrl The grpcUrl to look up
267
+ * @returns The matching QueryInfo, or undefined if not found
268
+ */
269
+ findQueryByGrpcUrl(grpcUrl) {
270
+ return this.dheClient
271
+ .getKnownConfigs()
272
+ .find(({ designated }) => (designated === null || designated === void 0 ? void 0 : designated.grpcUrl) === grpcUrl);
273
+ }
274
+ /**
275
+ * Cache query info for the given grpcUrl.
276
+ */
277
+ cacheQueryInfo(queryInfo) {
278
+ const cacheEntry = createQueryInfoCacheEntry(queryInfo);
279
+ const { name } = cacheEntry, restCacheEntry = __rest(cacheEntry, ["name"]);
280
+ logger.info('cacheQueryInfo', 'add', name, `(${queryInfo.serial})`, `to queryInfo cache.`, restCacheEntry);
281
+ this.cache.setQueryInfo(queryInfo.serial, cacheEntry);
282
+ }
283
+ /**
284
+ * Helper to log info for a connection.
285
+ * @param connectionId The connection ID
286
+ * @param args The args to log
287
+ */
288
+ logConnectionInfo(level, connectionId, ...args) {
289
+ const cacheKey = this.cache.getConnectionCacheKeyById(connectionId);
290
+ const cacheEntry = this.cache.getQueryInfoByCacheKey(cacheKey);
291
+ const tokens = [`cnId:${connectionId}`, `cached:${cacheKey != null}`];
292
+ if (cacheEntry != null) {
293
+ const [serial, queryInfo] = cacheEntry;
294
+ tokens.push(`query:${queryInfo.name || serial}`);
295
+ }
296
+ logger[level](`[${tokens.join(',')}]`, ...args);
297
+ }
298
+ /**
299
+ * Handle query config changes on a DHE JS API client. Query info gets cached
300
+ * by serial and will remain cached until either:
301
+ * 1. A status change occurs that results in a non 'Running' status
302
+ * 2. processInfoId changes. This should catch any services that have gone down
303
+ * without issuing status change events such as server restarts. Once such
304
+ * services resume, they will have a new processInfoId. Query info +
305
+ * connections associated with the old processInfoId will be discarded.
306
+ * Caches for existing Core+ clients and connections are also cleared when the
307
+ * owning query is removed from the cache.
308
+ *
309
+ * TODO DH-20344: Neither of the cache eviction cases will work for console
310
+ * queries in the case of server restarts since we may not get a non-running
311
+ * status, and the queries won't resume at all. This is probably not a real
312
+ * problem, but it is a slight inconsistency to be aware of and would be nice
313
+ * to figure out if possible.
314
+ * @param event The client listener event containing the QueryInfo detail
315
+ */
316
+ async handleQueryConfigChange({ detail, }) {
317
+ var _a, _b, _c, _d, _e, _f;
318
+ const { serial } = detail;
319
+ const isInCache = this.cache.hasQueryInfo(serial);
320
+ // TODO DH-20344: Once we include console queries in the cache, we'll need
321
+ // to figure out how to evict them from the cache when services restart
322
+ // since we won't get new query config events after things are back up.
323
+ if (isInCache) {
324
+ const _g = this.cache.getQueryInfoOrThrow(serial), { name, processInfoId, status } = _g, restCacheEntry = __rest(_g, ["name", "processInfoId", "status"]);
325
+ const processInfoIdLabel = processInfoId === ((_a = detail.designated) === null || _a === void 0 ? void 0 : _a.processInfoId)
326
+ ? `\n piid: '${processInfoId}'`
327
+ : `\n piid: '${processInfoId}' -> '${(_b = detail.designated) === null || _b === void 0 ? void 0 : _b.processInfoId}'`;
328
+ const statusLabel = status === ((_c = detail.designated) === null || _c === void 0 ? void 0 : _c.status)
329
+ ? `\n status: '${status}'`
330
+ : `\n status: '${status}' -> '${(_d = detail.designated) === null || _d === void 0 ? void 0 : _d.status}'`;
331
+ // If the replica is running and hasn't changed processInfoId, we assume
332
+ // the connection is still valid and don't evict it from the cache.
333
+ if (((_e = detail.designated) === null || _e === void 0 ? void 0 : _e.status) === 'Running' &&
334
+ processInfoId === ((_f = detail.designated) === null || _f === void 0 ? void 0 : _f.processInfoId)) {
335
+ logger.debug('handleQueryConfigChange', 'still valid', name, `(${serial})`, processInfoIdLabel, statusLabel);
336
+ return;
337
+ }
338
+ logger.info('handleQueryConfigChange', 'evict', name, `(${serial})`, `from queryInfo cache.`, processInfoIdLabel, statusLabel, restCacheEntry);
339
+ const { grpcUrl, envoyPrefix } = restCacheEntry;
340
+ this.cache.evictClientAndConnection(grpcUrl, envoyPrefix);
341
+ this.cache.evictQueryInfo(serial);
342
+ }
343
+ }
344
+ }
345
+ export default EnterpriseCorePlusManager;
@@ -0,0 +1,11 @@
1
+ import type { EnterpriseClient } from '@deephaven-enterprise/jsapi-types';
2
+ import type { dh as DhType } from '@deephaven/jsapi-types';
3
+ /**
4
+ * Create login credentials for a Core+ worker from a DHE client. Requests an
5
+ * auth token from the DHE client for the `RemoteQueryProcessor` and wraps it in
6
+ * the token login options expected by a `CoreClient`.
7
+ * @param client The DHE JS API client to request the auth token from
8
+ * @returns Login credentials for logging into a Core+ worker
9
+ */
10
+ export declare function getWorkerCredentials(client: EnterpriseClient): Promise<DhType.LoginCredentials>;
11
+ export default getWorkerCredentials;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Create login credentials for a Core+ worker from a DHE client. Requests an
3
+ * auth token from the DHE client for the `RemoteQueryProcessor` and wraps it in
4
+ * the token login options expected by a `CoreClient`.
5
+ * @param client The DHE JS API client to request the auth token from
6
+ * @returns Login credentials for logging into a Core+ worker
7
+ */
8
+ export async function getWorkerCredentials(client) {
9
+ const token = await client.createAuthToken('RemoteQueryProcessor');
10
+ return {
11
+ type: 'io.deephaven.proto.auth.Token',
12
+ token,
13
+ };
14
+ }
15
+ export default getWorkerCredentials;
@@ -0,0 +1,4 @@
1
+ export * from './CorePlusManager';
2
+ export * from './EnterpriseCorePlusManager';
3
+ export * from './CorePlusManagerCache';
4
+ export * from './getWorkerCredentials';
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './CorePlusManager';
2
+ export * from './EnterpriseCorePlusManager';
3
+ export * from './CorePlusManagerCache';
4
+ export * from './getWorkerCredentials';
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@deephaven-enterprise/client-utils",
3
+ "version": "2026.1.260612134256-ga1e17c94e2",
4
+ "description": "Deephaven Enterprise Client Connectivity Utils",
5
+ "author": "Deephaven Data Labs LLC",
6
+ "license": "SEE LICENSE IN LICENSE.md",
7
+ "type": "module",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/deephaven-ent/iris.git",
11
+ "directory": "web/client-ui/packages/client-utils"
12
+ },
13
+ "private": false,
14
+ "source": "src/index.ts",
15
+ "main": "dist/index.js",
16
+ "types": "dist/index.d.ts",
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "sideEffects": false,
21
+ "scripts": {
22
+ "build": "tsc --build"
23
+ },
24
+ "dependencies": {
25
+ "@deephaven/jsapi-types": "^1.0.0-dev0.36.1",
26
+ "@deephaven-enterprise/jsapi-types": "file:../jsapi-types",
27
+ "@deephaven/log": "^0.97.0",
28
+ "@deephaven/utils": "^0.97.0"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ }
33
+ }