From 37cb77bd50fe929b7c575d8bd47373710651f3e1 Mon Sep 17 00:00:00 2001 From: Brian Ingles Date: Fri, 13 Sep 2024 17:05:32 -0500 Subject: [PATCH] Copied @deephaven-enterprise/jsapi-types from DHE codebase (#79) --- .../jsapi-types/CommonTypes.d.ts | 137 +++++ .../jsapi-types/Iris.d.ts | 565 ++++++++++++++++++ .../jsapi-types/index.d.ts | 4 + .../jsapi-types/parameterizedQueryTypes.d.ts | 48 ++ 4 files changed, 754 insertions(+) create mode 100644 src/types/@deephaven-enterprise/jsapi-types/CommonTypes.d.ts create mode 100644 src/types/@deephaven-enterprise/jsapi-types/Iris.d.ts create mode 100644 src/types/@deephaven-enterprise/jsapi-types/index.d.ts create mode 100644 src/types/@deephaven-enterprise/jsapi-types/parameterizedQueryTypes.d.ts diff --git a/src/types/@deephaven-enterprise/jsapi-types/CommonTypes.d.ts b/src/types/@deephaven-enterprise/jsapi-types/CommonTypes.d.ts new file mode 100644 index 00000000..1d768715 --- /dev/null +++ b/src/types/@deephaven-enterprise/jsapi-types/CommonTypes.d.ts @@ -0,0 +1,137 @@ +import type { dh } from '@deephaven/jsapi-types'; +import type { + ConsoleServerAddress, + QueryConfigurationType, + QueryConstants, +} from './Iris'; + +/** Copied from @deephaven/redux to avoid the dependency */ +export interface UserPermissions { + canUsePanels: boolean; + canCopy: boolean; + canDownloadCsv: boolean; + canLogout: boolean; +} +/** Copied from @deephaven/redux to avoid the dependency */ +export interface User { + permissions: UserPermissions; + name: string; + operateAs?: string; + groups: string[]; + displayName?: string; + fullName?: string; + image?: string; +} + +export type EnterpriseUserPermissions = { + /** Is an ACL editor user */ + isACLEditor: boolean; + + /** Is a super user */ + isSuperUser: boolean; + + /** Only the summary view of queries is visible, and cannot create code studios */ + isQueryViewOnly: boolean; + + /** Not allowed to use the web UI at all */ + isNonInteractive: boolean; + + /** Can use the Panels menu to select panels to add to a dashboard */ + canUsePanels: boolean; + + /** Can create new dashboards */ + canCreateDashboard: boolean; + + /** Can create/use code studios */ + canCreateCodeStudio: boolean; + + /** Can create/use query monitor */ + canCreateQueryMonitor: boolean; + + /** Can copy table data using keyboard shortcuts or context menu */ + canCopy: boolean; + + /** Can download/export table data as CSV */ + canDownloadCsv: boolean; + + /** Can share dashboards with other users */ + canShareDashboards: boolean; + + /** Can view the list of users a dashboard is shared with for a dashboard they are a viewer of */ + canViewDashboardSharedUsers: boolean; + + /** Can share queries with other users */ + canShareQueries: boolean; + + /** Can view the list of users a query is shared with for a query they are a viewer of */ + canViewQuerySharedUsers: boolean; + + /** Can logout */ + canLogout: boolean; +}; + +export type EnterpriseUser = User & { + operateAs: string; + permissions: EnterpriseUserPermissions; +}; + +export type QueryVariableDescriptor = dh.ide.VariableDescriptor & { + querySerial: string; + query?: string; +}; + +/** + * @deprecated use QueryVariableDescriptor instead + */ +export type LegacyQueryVariableDescriptor = { + querySerial: string; + query: string; +}; + +/** In some cases such as a console panel, we may not have a descriptor but still want to fetch the deferred API. */ +export type UnknownVariableDescriptor = dh.ide.VariableDescriptor & { + type: 'unknown'; +}; + +export type SessionVariableDescriptor = dh.ide.VariableDescriptor & { + sessionId: string; +}; + +export type EnterpriseVariableDescriptor = + | QueryVariableDescriptor + | SessionVariableDescriptor; + +export type ControllerQueryConstants = { + getMaxHeapGbForServer: (name: string) => number; + consoleDefaultHeap: number; +}; + +export type ControllerConfiguration = { + readonly consoleServers: readonly ConsoleServerAddress[]; + readonly dbServers: readonly ConsoleServerAddress[]; + readonly queryTypes: ReadonlyMap; + readonly jvmProfiles: readonly string[]; + readonly queryConstants: QueryConstants; + readonly businessCalendars: readonly string[]; + readonly temporaryQueryTypes: readonly string[]; + readonly jvmProfileDefault: string; + readonly scriptQueryTypes: readonly string[]; + readonly queryConfigurationTypes: ReadonlyMap; +}; + +export declare const PROTOCOL: Readonly<{ + COMMUNITY: 'Community'; + ENTERPRISE_WEBSOCKET: 'EnterpriseWebsocket'; + ENTERPRISE_COMM: 'EnterpriseComm'; +}>; + +export interface WorkerKind { + readonly description: string; + readonly name: string; + readonly protocols: (typeof PROTOCOL)[keyof typeof PROTOCOL][]; + readonly title: string; + // eslint-disable-next-line camelcase + readonly worker_control: readonly string[]; + // eslint-disable-next-line camelcase + readonly ephemeral_venv: boolean; +} diff --git a/src/types/@deephaven-enterprise/jsapi-types/Iris.d.ts b/src/types/@deephaven-enterprise/jsapi-types/Iris.d.ts new file mode 100644 index 00000000..eafedd89 --- /dev/null +++ b/src/types/@deephaven-enterprise/jsapi-types/Iris.d.ts @@ -0,0 +1,565 @@ +// The iris api script isn't packaged as a module (yet), and is just included in index.html, exported to the global namespace +// This include file is simply a wrapper so that it behaves like a module, and can be mocked easily for unit tests. +// https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#using-global-variables +import type { dh as DhType } from '@deephaven/jsapi-types'; + +import { + Parameterized, + ParameterizedQueryVariableType, +} from './parameterizedQueryTypes'; +import { ControllerQueryConstants, WorkerKind } from './CommonTypes'; + +export type CancelablePromise = Promise & { cancel: () => undefined }; + +export interface IdeConnection extends DhType.IdeConnection { + serviceId: string; + processInfoId: string; + running(): Promise; + close(): void; +} + +/** + * There are a couple of methods on Enterprise that are not in Core (yet). + * Technically, TreeTable does not extend DhType.TreeTable, but the API should match between Core and Enterprise. + */ +export interface TreeTable extends DhType.TreeTable { + saveExpandedState: () => string; + restoreExpandedState: (state: string) => void; +} + +export interface BaseQueryInfo { + adminGroups: readonly string[]; + + /** + * @deprecated use `type` instead + */ + configurationType: string; + configVersion: string; + dataMemoryRatio: number; + dbServerName: string; + enabled: boolean; + enableGcLogs: boolean; + envVars: string; + extraClasspaths: string; + /** + * @deprecated use `designated.grpcUrl` instead + */ + grpcUrl: string; + heapSize: number; + additionalMemory: number; + jvmArgs: string; + jvmProfile: string; + name: string; + owner: string; + restartUsers: number; + /** + * @deprecated use `designated.runningVersion` instead + */ + runningVersion: string; + scheduling: readonly string[]; + scriptLanguage: string | null; + scriptPath: string | null; + serial: string; + status: string; + timeout: number; + type: string; + typeSpecificFields: Record | null; + viewerGroups: readonly string[]; + workerKind: string; + + /** + * JSON encoded string of the kubernetes, python and generic controls + */ + kubernetesControl: string; + pythonControl: string; + genericWorkerControl: string; + + replicaCount: number; + spareCount: number; + assignmentPolicy: string | null; + assignmentPolicyParams: string | null; +} + +export interface ReplicaStatus { + objects: readonly DhType.ide.VariableDefinition[]; + status: string | null; + fullStackTrace: string | null; + envoyPrefix: string | null; + grpcUrl: string; + jsApiUrl: string; + ideUrl: string; + runningVersion: string; + websocketUrl: string | null; + numberFailures: number; + workerHost: string | null; + workerName: string | null; + communityPort: number | null; + websocketPort: number | null; + workerPort: number | null; + initStartTime: DhType.DateWrapper | null; + processInfoId: string | null; + createWorkspaceData(data: { id?: string; data: string }): Promise; + getObject( + object: DhType.ide.VariableDescriptor + ): Promise; + getTable(tableName: string): Promise; + getTreeTable(tableName: string): Promise; + mergeTables(tables: DhType.Table[]): Promise; + newTable( + names: string[], + types: string[], + data: unknown[] + ): Promise; +} + +export interface QueryInfo extends Readonly { + designated?: ReplicaStatus; + displayable: boolean; + /** + * @deprecated Use `designated.envoyPrefix` instead + */ + envoyPrefix: string | null; + /** + * @deprecated Use `designated.fullStackTrace` instead + */ + fullStackTrace: string; + /** + * @deprecated Use `designated.ideUrl` instead + */ + ideUrl: string; + /** + * @deprecated Use `designated.jsApiUrl` instead + */ + jsApiUrl: string; + /** + * @deprecated use `designated.objects` instead + */ + objects: readonly DhType.ide.VariableDefinition[]; + /** + * @deprecated Use `designated.websocketUrl` instead + */ + websocketUrl: string | null; + /** + * @deprecated Use `designated.numberFailures` instead + */ + numberFailures: number; + /** + * @deprecated Use `designated.workerHost` instead + */ + workerHost: string | null; + /** + * @deprecated Use `designated.workerName` instead + */ + workerName: string | null; + /** + * @deprecated Use `designated.communityPort` instead + */ + communityPort: number | null; + /** + * @deprecated Use `designated.websocketPort` instead + */ + websocketPort: number | null; + /** + * @deprecated Use `designated.workerPort` instead + */ + workerPort: number | null; + /** + * @deprecated Use `designated.initStartTime` instead + */ + initStartTime: DhType.DateWrapper | null; + initEndTime: DhType.DateWrapper | null; + lastUpdateTime: DhType.DateWrapper | null; + /** + * @deprecated Use `designated.processInfoId` instead + */ + processInfoId: string | null; + lastModifiedTime: DhType.DateWrapper | null; + lastModifiedByAuthenticated: string | null; + schedulingStartTime: string | null; + schedulingEndTime: string | null; + schedulingTimeZone: string | null; + schedulingDetails: string | null; + replicaCount: number; + spareCount: number; + replicas: ReplicaStatus[]; + spares: ReplicaStatus[]; + getReplicaStatus(slot: number): ReplicaStatus | null; + + /** + * @deprecated use `objects` instead + */ + tables: readonly string[]; + /** + * @deprecated use `designated.newTable` instead + */ + mergeTables(tables: DhType.Table[]): Promise; + /** + * @deprecated use `designated.newTable` instead + */ + newTable( + names: string[], + types: string[], + data: unknown[] + ): Promise; + /** + * @deprecated use `designated.newTable` instead + */ + createWorkspaceData(data: { id?: string; data: string }): Promise; + /** + * @deprecated use `designated.getTreeTable` instead + */ + getTreeTable(tableName: string): Promise; + /** + * @deprecated use `designated.getTable` instead + */ + getTable(tableName: string): Promise; + /** + * @deprecated use `designated.getObject` instead + */ + getObject( + object: DhType.ide.VariableDescriptor + ): Promise; + getFigure(figureName: string): Promise; + saveWorkspaceData(data: { id?: string; data: string }): Promise; +} + +export interface AbstractIrisWebServer { + businessCalendars: readonly string[]; + dbServers: readonly ConsoleServerAddress[]; + queryTypes: ReadonlyMap; + jvmProfiles: readonly string[]; + queryConstants: ControllerQueryConstants; +} + +export interface UserInfo { + username: string; + operateAs: string; +} + +export interface QuerySelectionPermissions { + allAdmin: boolean; + allOwner: boolean; + allRestartable: boolean; +} + +export interface ClientListenerEvent { + detail: TDetail; +} + +export interface DriverWrapper { + catalogName: string; + defaultUrl: string; + friendlyName: string; +} + +export interface AssignmentPolicyType { + name: string; + description: string; + displayName: string; + acceptsParams: boolean; +} + +export type AssignmentPolicyTypes = Map; + +export interface EnterpriseClient { + /** + * Get available assignment policy types. + * @returns A Promise resolving to a map of assignment policy types. + */ + getAssignmentPolicyTypes(): Promise; + getDefaultAssignmentPolicy(): Promise; + getDefaultAssignmentPolicyParams(): Promise; + getQuerySelectionPermissions( + serialIds: string[] + ): Promise; + getEditableQuery(serialId: string): Promise; + getKnownConfigs(): QueryInfo[]; + addEventListener( + type: string, + listener: (event: CustomEvent) => void + ): () => void; + removeEventListener( + type: string, + listener: (event: ClientListenerEvent) => void + ): void; + disconnect(): void; + getDispatcher( + serverGroup: string, + heapSizeMB: number, + engine: string + ): Promise; + saveQuery(query: EditableQueryInfo, doRestart: boolean): Promise; + createQuery(query: EditableQueryInfo): Promise; + createAuthToken(key: string): Promise; + /** Imports the XML string as queries, and returns the query info. Does _not_ actually create them, use `saveQueries()` to save them. */ + importQueries: (xml: string) => Promise; + /** Returns a string containing the XML of all queries specified */ + exportQueries: (serialIds: string[]) => Promise; + relogin(token: unknown): Promise; + getAllGroups(): Promise; + getAllUsers(): Promise; + getTemporaryQueueNames(): Promise; + getScriptPaths(serialId: string | null, owner?: string): Promise; + getQuerySerialsForDependent(isTemporary: boolean): Promise; + getDbServersForType(type: string): Promise; + getJdbcDriverWrappers(): Promise; + encrypt(value: string): Promise; + /** + * Save queries to the system. + * @param queries Query info to save + * @param replaceExisting Whether to replace existing queries or create new ones. If a serial is specified on a query and it is saved and `replaceExisting` is false, it will throw an error if a query with that serial already exists. + */ + saveQueries: ( + queries: readonly EditableQueryInfo[], + replaceExisting: boolean + ) => Promise; + getAuthConfigValues(): Promise; + onConnected(timeout: number): Promise; + + getConsoleServers(): Promise; + getDbServers(): Promise; + getJvmProfiles(): Promise; + getQueryConstants(): Promise; + getServerConfigValues(): Promise; + getBusinessCalendars(): Promise; + getDefaultCalendar(): Promise; + getGroupsForUser(): Promise; + getUserInfo(): Promise; + getQueryConfigurationTypes(): Promise>; + login(credentials: LoginCredentials): Promise; + restartQueries(serialIds: string[]): Promise; + stopQueries(serialIds: string[]): Promise; + getScriptBody( + path: string | null, + owner: string | null, + serialId: string | null + ): Promise; + getImportSources( + namespace: string, + table: string, + type: ImportSourceTypeOption + ): Promise; +} + +export interface LoginCredentials { + username?: string; + type: string; + token: string; + operateAs?: string; +} +export interface QueryConfigurationType { + name: string; + displayName: string; + supportsCommunity: boolean; + temporary: boolean; + hasScript: boolean; + allowedGroups: string[]; + serverClasses: string[]; + isDisplayable: boolean; + supportsReplicas: boolean; +} + +export type QueryConstants = { + getMaxHeapGbForServer: (name?: string) => number; + consoleDefaultHeap: number; + pqDefaultHeap: number; + minHeapGb: number; + minDataRatio: number; + maxDataRatio: number; + maxScriptCodeLength: number; +}; + +export interface EnterpriseClientConstructor { + new (websocketUrl: string): EnterpriseClient; +} + +export interface ConsoleConfigConstructor { + new (): ConsoleConfig; +} + +export interface DhcConnectionDetails { + readonly envoyPrefix: string | null; + readonly grpcUrl: string; + readonly ideUrl: string; + readonly jsApiUrl: string; + readonly serviceId: string; + readonly processInfoId: string; + readonly workerName: string; + + close(): void; + addEventListener: ( + name: string, + callback: (event: CustomEvent) => void + ) => () => void; + removeEventListener(type: string, listener: () => void): void; +} + +export interface ConsoleConfig { + dispatcherHost?: string; + dispatcherPort?: number; + queryDescription: string; + jvmProfile: string; + maxHeapMb: number; + additionalMemoryMb: number; + jvmArgs: string[]; + envVars: [string, string][]; + classpath: string[]; + debug: boolean; + detailedGCLogging: boolean; + workerKind: string; + workerCreationJson: string; +} + +export interface IdeConstructor { + new (client: EnterpriseClient): Ide; +} + +export interface Ide { + createConsole(config: ConsoleConfig): CancelablePromise; + startWorker(config: ConsoleConfig): CancelablePromise; +} + +export type ConsoleServerAddressType = { + GROUP: string; +}; +export type ConsoleServerAddress = { + Type: ConsoleServerAddressType; + host: string; + name: string; + port: number; + type: string; +}; + +export type QueryInfoStatic = { + EVENT_DISCONNECT: string; + EVENT_PING_TIMEOUT: string; + EVENT_PING: string; +}; + +export type EditableQueryInfo = Omit< + BaseQueryInfo, + | 'status' + | 'runningVersion' + | 'serial' + | 'createWorkspaceData' + | 'getTreeTable' + | 'getTable' + | 'getObject' + | 'getFigure' + | 'saveWorkspaceData' +> & { + scriptCode: string; + serial: string | null; +}; + +export type EnterpriseClientStatic = { + EVENT_CONNECT: 'connect'; + EVENT_DISCONNECT: 'disconnect'; + EVENT_RECONNECT: 'reconnect'; + EVENT_RECONNECT_AUTH_FAILED: 'reconnectauthfailed'; + EVENT_CONFIG_ADDED: 'configadded'; + EVENT_CONFIG_REMOVED: 'configremoved'; + EVENT_CONFIG_UPDATED: 'configupdated'; + EVENT_REFRESH_TOKEN_UPDATED: 'refreshtokenupdated'; + + LOGIN_TYPE_PASSWORD: 'password'; + LOGIN_TYPE_SAML: 'saml'; +}; + +export type SaveQueriesResult = { + serialIds: string[]; + errors: string[]; +}; + +export interface ServerConfigValues { + getValue(key: string): string; + csvParserFormats: string[]; + dbAclWriterHost: string; + dbAclWriterPort: number; + gradleVersion: string; + vcsVersion: string; + javaVersion: string; + hostName: string; + mergeQueryTableDataServices: string[]; + systemName: string; + systemType: string; + systemColor: string; + supportContact: string; + supportDocs: string; + settingsLogoConfigured: boolean; + appPlugins: string[]; + systemBadge: boolean; + systemBadgeEditable: boolean; + timeZone: string; + timeZoneEditable: boolean; + jvmProfileDefault: string; + showSearch: boolean; + scriptSessionProviders: string[]; + decimalFormat: string; + decimalFormatEditable: boolean; + integerFormat: string; + integerFormatEditable: boolean; + truncateNumbersWithPound: boolean; + truncateNumbersWithPoundEditable: boolean; + restartQueryWhenRunningDefault: string; + workerKinds: WorkerKind[]; + defaultWorkerKind: string; + schemaValidatorClass: string; + startWorkersAsSystemUser: boolean; + supportedParquetCodecs: string[]; + validationTestTypes: string[]; + detailedGcLoggingParameters: string[]; + kubernetes: boolean; + webgl: boolean; + webglEditable: boolean; +} + +export interface ApplyParametersResult { + tables: string[]; + widgets: string[]; +} + +export interface ParameterizedQuery { + applyParameters( + params: Record + ): Promise; + getTable(tableName: string): Promise; + getFigure(figureName: string): Promise; + validateParameter(name: string, value: string[]): void; + validateParameters(paramValueMap: Map): void; +} + +export type VariableTypeUnion = + (typeof VariableType)[keyof typeof VariableType]; + +declare const VariableType: (typeof DhType)['VariableType'] & + typeof ParameterizedQueryVariableType; + +export type ImportSourceTypeOption = string & { + readonly __brand: unique symbol; +}; + +declare class ImportSourceType { + static readonly CSV: ImportSourceTypeOption; + + static readonly JDBC: ImportSourceTypeOption; + + static readonly XML: ImportSourceTypeOption; + + static readonly JSON: ImportSourceTypeOption; + + static readonly NONE: ImportSourceTypeOption; +} + +export type EnterpriseDhType = typeof DhType & { + Client: EnterpriseClientStatic & EnterpriseClientConstructor; + RangeSet: DhType.RangeSet; + Table: DhType.Table; + parameterized: Parameterized; + VariableType: typeof VariableType; + ConsoleServerAddress: ConsoleServerAddress; + Ide: IdeConstructor; + ConsoleConfig: ConsoleConfigConstructor; + QueryInfo: QueryInfoStatic; + ImportSourceType: typeof ImportSourceType; +}; diff --git a/src/types/@deephaven-enterprise/jsapi-types/index.d.ts b/src/types/@deephaven-enterprise/jsapi-types/index.d.ts new file mode 100644 index 00000000..99887af1 --- /dev/null +++ b/src/types/@deephaven-enterprise/jsapi-types/index.d.ts @@ -0,0 +1,4 @@ +export * from './CommonTypes'; +export * from './parameterizedQueryTypes'; +export * from './CommonTypes'; +export * from './Iris'; diff --git a/src/types/@deephaven-enterprise/jsapi-types/parameterizedQueryTypes.d.ts b/src/types/@deephaven-enterprise/jsapi-types/parameterizedQueryTypes.d.ts new file mode 100644 index 00000000..089077b1 --- /dev/null +++ b/src/types/@deephaven-enterprise/jsapi-types/parameterizedQueryTypes.d.ts @@ -0,0 +1,48 @@ +export interface CompositionType { + And: CompositionType; + Or: CompositionType; +} + +export interface ComparisonType { + GreaterThanEqual: ComparisonType; + GreaterThan: ComparisonType; + LessThanEqual: ComparisonType; + LessThan: ComparisonType; +} + +export interface ConstraintType { + In: ConstraintType; + Unconstrained: ConstraintType; + Composition: ConstraintType; + Comparison: ConstraintType; +} + +export interface DisplayType { + CheckBox: DisplayType; + DatePicker: DisplayType; + DateTimePicker: DisplayType; + DeephavenTable: DisplayType; + DropDown: DisplayType; + EditableList: DisplayType; + FixedList: DisplayType; + Text: DisplayType; +} + +export interface ValueType { + Boolean: ValueType; + DateTime: ValueType; + Double: ValueType; + Long: ValueType; + String: ValueType; +} + +export interface Parameterized { + ConstraintType: ConstraintType; + CompositionType: CompositionType; + ComparisonType: ComparisonType; + DisplayType: DisplayType; +} + +export declare const ParameterizedQueryVariableType: { + readonly PARAMETERIZEDQUERY: 'ParameterizedQuery'; +};