@deephaven-enterprise/query-utils 2026.1.58 → 2026.1.60

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.
@@ -13,6 +13,17 @@ export declare const TYPE_SPECIFIC_FIELD_PARTITION_FORMULA = "PartitionFormula";
13
13
  * @returns True if the user can view permissions for the query, false otherwise
14
14
  */
15
15
  export declare function canViewPermissions(user: EnterpriseUser, draftQuery: DraftQuery | null): boolean;
16
+ /**
17
+ * Check whether the user may attach a console to the given query. Attaching
18
+ * runs code in the query's own scope, so it is restricted to the owner and,
19
+ * only when the server opts in, the query's admins.
20
+ * @param user The user attempting to attach
21
+ * @param query The query to attach to
22
+ * @param isAllowedForAdmins Value of the server's
23
+ * `consoleAttachmentAllowedForAdmins` setting
24
+ * @returns True if the user may attach a console to the query
25
+ */
26
+ export declare function canAttachToConsole(user: EnterpriseUser, query: QueryInfo, isAllowedForAdmins: boolean): boolean;
16
27
  /**
17
28
  * Get the query configuration types that are displayable and the user is allowed to create
18
29
  * @param queryConfigurationTypes Query configuration types to filter
@@ -30,6 +30,30 @@ export function canViewPermissions(user, draftQuery) {
30
30
  // Otherwise, only show it if they can view the shared users
31
31
  return user.permissions.canViewQuerySharedUsers;
32
32
  }
33
+ /**
34
+ * Check whether the user may attach a console to the given query. Attaching
35
+ * runs code in the query's own scope, so it is restricted to the owner and,
36
+ * only when the server opts in, the query's admins.
37
+ * @param user The user attempting to attach
38
+ * @param query The query to attach to
39
+ * @param isAllowedForAdmins Value of the server's
40
+ * `consoleAttachmentAllowedForAdmins` setting
41
+ * @returns True if the user may attach a console to the query
42
+ */
43
+ export function canAttachToConsole(user, query, isAllowedForAdmins) {
44
+ if (user.permissions.isSuperUser) {
45
+ return true;
46
+ }
47
+ if (query.owner === user.operateAs) {
48
+ return true;
49
+ }
50
+ if (!isAllowedForAdmins) {
51
+ return false;
52
+ }
53
+ // Same definition of admin used by `getQuerySelectionPermissions`.
54
+ return (user.groups.includes(query.owner) ||
55
+ query.adminGroups.some(group => user.groups.includes(group)));
56
+ }
33
57
  /**
34
58
  * Get the query configuration types that are displayable and the user is allowed to create
35
59
  * @param queryConfigurationTypes Query configuration types to filter
@@ -1,5 +1,5 @@
1
1
  import type { dh } from '@deephaven/jsapi-types';
2
- import type { QueryInfo } from '@deephaven-enterprise/jsapi-types';
2
+ import type { QueryInfo, WorkerKind } from '@deephaven-enterprise/jsapi-types';
3
3
  import type DraftQuery from './DraftQuery.ts';
4
4
  export type QueryInfoMap = Map<string, QueryInfo>;
5
5
  export declare const NON_RUNNING_STATUSES: Set<string>;
@@ -17,6 +17,13 @@ export declare function isQueryStartable(query: QueryInfo): boolean;
17
17
  export declare function isQueryRestartable(query: QueryInfo): boolean;
18
18
  export declare function isStoppable(queryInfoMap: QueryInfoMap | undefined, serial: string): boolean;
19
19
  export declare function isRunning(query: QueryInfo): boolean;
20
+ /**
21
+ * Check whether a console session can attach to the given query. Attaching runs
22
+ * a console against the query's existing worker, so the query must be running on
23
+ * a Core+ worker. Any query type is allowed; who may attach is a separate
24
+ * permission check.
25
+ */
26
+ export declare function isAttachableToConsole(query: QueryInfo, workerKinds: readonly WorkerKind[], defaultWorkerKind: string): boolean;
20
27
  export declare function isWebClient(query: QueryInfo): boolean;
21
28
  /**
22
29
  * Check if the specified query can be restarted in it's current state.
@@ -1,3 +1,4 @@
1
+ import { getWorkerKind, isCommunityWorkerKind, } from '@deephaven-enterprise/client-utils';
1
2
  import { QueryColumns } from "./QueryColumns.js";
2
3
  import { QueryScheduler } from "./QueryScheduler.js";
3
4
  import { QueryStatus } from "./QueryStatus.js";
@@ -74,6 +75,17 @@ export function isRunning(query) {
74
75
  var _a;
75
76
  return ((_a = query.designated) === null || _a === void 0 ? void 0 : _a.status) === QueryStatus.running;
76
77
  }
78
+ /**
79
+ * Check whether a console session can attach to the given query. Attaching runs
80
+ * a console against the query's existing worker, so the query must be running on
81
+ * a Core+ worker. Any query type is allowed; who may attach is a separate
82
+ * permission check.
83
+ */
84
+ export function isAttachableToConsole(query, workerKinds, defaultWorkerKind) {
85
+ var _a;
86
+ return (isRunning(query) &&
87
+ isCommunityWorkerKind(getWorkerKind((_a = query.workerKind) !== null && _a !== void 0 ? _a : defaultWorkerKind, workerKinds)));
88
+ }
77
89
  export function isWebClient(query) {
78
90
  return query.type === WEB_CLIENT_DATA_CORE_CONFIG_TYPE;
79
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deephaven-enterprise/query-utils",
3
- "version": "2026.1.58",
3
+ "version": "2026.1.60",
4
4
  "description": "Deephaven Enterprise Query Utils",
5
5
  "author": "Deephaven Data Labs LLC",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -17,8 +17,8 @@
17
17
  "build": "tsc --build"
18
18
  },
19
19
  "dependencies": {
20
- "@deephaven-enterprise/client-utils": "2026.1.58",
21
- "@deephaven-enterprise/jsapi-types": "2026.1.58",
20
+ "@deephaven-enterprise/client-utils": "2026.1.60",
21
+ "@deephaven-enterprise/jsapi-types": "2026.1.60",
22
22
  "@deephaven/jsapi-types": "1.0.0-dev0.40.5",
23
23
  "@deephaven/log": "^1.8.0",
24
24
  "@deephaven/utils": "^1.29.0",