Pārlūkot izejas kodu

[editor] Add Ace types

This also updates some of the general types for completeness
Johan Ahlen 5 gadi atpakaļ
vecāks
revīzija
cea0b5daef

+ 1 - 5
desktop/core/src/desktop/js/apps/notebook2/execution/executable.ts

@@ -25,6 +25,7 @@ import {
   ExecutionHistory
 } from 'apps/notebook2/execution/apiUtils';
 import ExecutionResult from 'apps/notebook2/execution/executionResult';
+import { hueWindow } from 'types/types';
 import hueAnalytics from 'utils/hueAnalytics';
 import huePubSub from 'utils/huePubSub';
 import sessionManager from 'apps/notebook2/execution/sessionManager';
@@ -68,11 +69,6 @@ export interface ExecutableRaw {
   type: string;
 }
 
-interface hueWindow {
-  WS_CHANNEL?: string;
-  WEB_SOCKETS_ENABLED?: boolean;
-}
-
 const INITIAL_HANDLE: ExecutionHandle = {
   statement_id: 0
 };

+ 8 - 8
desktop/core/src/desktop/js/apps/notebook2/execution/executor.ts

@@ -26,10 +26,10 @@ export interface ExecutorRaw {
 }
 
 export default class Executor {
-  connector: () => Connector;
-  compute: () => Compute;
-  namespace: () => Namespace;
-  database: () => string;
+  connector: KnockoutObservable<Connector>;
+  compute: KnockoutObservable<Compute>;
+  namespace: KnockoutObservable<Namespace>;
+  database: KnockoutObservable<string>;
   defaultLimit?: KnockoutObservable<number>;
   isSqlEngine?: boolean;
   isOptimizerEnabled?: boolean;
@@ -38,10 +38,10 @@ export default class Executor {
   snippet?: Snippet;
 
   constructor(options: {
-    connector: () => Connector;
-    compute: () => Compute;
-    namespace: () => Namespace;
-    database: () => string;
+    connector: KnockoutObservable<Connector>;
+    compute: KnockoutObservable<Compute>;
+    namespace: KnockoutObservable<Namespace>;
+    database: KnockoutObservable<string>;
     defaultLimit?: KnockoutObservable<number>;
     isSqlEngine?: boolean;
     snippet?: Snippet;

+ 105 - 0
desktop/core/src/desktop/js/ext/ace.d.ts

@@ -0,0 +1,105 @@
+import {IdentifierLocation, SyntaxError} from 'parse/types';
+
+declare namespace Ace {
+  export interface Editor {
+    addError(message:string, line:number): void;
+    addWarning(message:string, line:number): void;
+    container: HTMLElement;
+    completer: any;
+    completers: any[];
+    clearErrorsAndWarnings(type: string): void;
+    customMenuOptions: { [option: string]: (val?: any) => any };
+    enabledMenuOptions: { [option: string]: boolean };
+    getCursorPosition(): Position;
+    getOption(option: string): string|boolean|number;
+    getSelectedText(): string;
+    getSelectionRange(): Range;
+    getSession(): Session
+    getTextAfterCursor(): string;
+    getTextBeforeCursor(): string;
+    getValue(): string;
+    lastChangeTime: number;
+    off(ev: string, callback: ((e: any) => any) | number): void;
+    on(event: string, fn: (e: any) => any): number;
+    renderer: {
+      lineHeight: number;
+      screenToTextCoordinates(left: number, top: number): Position;
+      scrollCursorIntoView(position: Position, u: number): void;
+      textToScreenCoordinates(row: number, column: number): { pageX: number; pageY: number }
+    };
+    resize(force: boolean): void;
+    scrollToLine(line: number, u: boolean, v: boolean, callback: () => void): void;
+    selection: {
+      getRange(): Range;
+    };
+    session: Session;
+    setOption(option: string, value: OptionValue): void;
+    setOptions(options: Options): void;
+    setTheme(theme: string): void;
+    useHueAutocompleter: boolean;
+  }
+
+  export type OptionValue = string | boolean | number;
+
+  export interface Options {
+    [option: string]: OptionValue;
+  }
+
+  export interface Position {
+    column: number;
+    row: number;
+  }
+
+  export interface Range {
+    end: Position | Anchor;
+    endColumn:number;
+    endRow:number;
+    isEmpty(): boolean;
+    start: Position | Anchor;
+    startColumn:number;
+    startRow:number;
+  }
+
+  export interface Document {
+    createAnchor(position: Position): Anchor;
+    createAnchor(x: number, y: number): Anchor;
+  }
+
+  export interface Anchor extends Position {
+    detach(): void;
+    getPosition(): Position;
+    on(event: string, fn: (e: any) => any): number;
+    setPosition(row: number, column: number, noClip?: boolean): void;
+  }
+
+  export interface Marker {
+    clazz: string;
+    dispose(): void;
+    range: Range;
+    token: HueToken;
+  }
+
+  export interface Session {
+    $backMarkers: { [markerId: number]: Marker };
+    addGutterDecoration(line: number, clazz: string): void;
+    addMarker(range: Range, clazz: string): number;
+    doc: Document;
+    getTextRange(range: Range): string;
+    getTokenAt(row: number, column: number): HueToken | null;
+    getTokens(line?: number): HueToken[];
+    removeGutterDecoration(line: number, clazz: string): void;
+    removeMarker(markerId: number): void;
+    setMode(mode: string): void;
+  }
+
+  export interface HueToken {
+    actualValue: string;
+    index?: number;
+    notFound?: boolean;
+    parseLocation?: IdentifierLocation;
+    qualifiedIdentifier?: string;
+    start?: number;
+    syntaxError?: SyntaxError;
+    value: string;
+  }
+}

+ 4 - 0
desktop/core/src/desktop/js/parse/types.ts

@@ -23,6 +23,7 @@ export interface IdentifierChainEntry {
 }
 
 export interface ParsedTable {
+  alias?: string;
   identifierChain: IdentifierChainEntry[];
   subQuery?: unknown; // TODO: Define
 }
@@ -49,12 +50,15 @@ export interface IdentifierLocation {
   function?: string;
   missing?: boolean;
   value?: string;
+  active?: boolean;
+  tables?: ParsedTable[];
   colRef: boolean;
   argumentPosition?: number;
   identifierChain?: IdentifierChainEntry[];
   expression?: { types: string[]; text: string };
   parentLocation?: ParsedLocation;
   path?: string;
+  qualified?: boolean;
   resolveCatalogEntry: (options?: {
     cancellable?: boolean;
     temporaryOnly?: boolean;

+ 10 - 0
desktop/core/src/desktop/js/types/types.ts

@@ -14,6 +14,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+import { HueDebug } from 'utils/hueDebug';
+
 export interface GenericApiResponse {
   status: number;
   message?: string;
@@ -27,3 +29,11 @@ declare global {
 
   const moment: Moment & ((val: unknown) => Moment);
 }
+
+export interface hueWindow {
+  ENABLE_SQL_SYNTAX_CHECK?: boolean;
+  LOGGED_USERNAME?: string;
+  WEB_SOCKETS_ENABLED?: boolean;
+  WS_CHANNEL?: string;
+  hueDebug?: HueDebug;
+}

+ 15 - 5
desktop/core/src/desktop/js/utils/hueDebug.js → desktop/core/src/desktop/js/utils/hueDebug.ts

@@ -15,12 +15,22 @@
 // limitations under the License.
 
 import localforage from 'localforage';
+import { hueWindow } from 'types/types';
 
-const hueDebug = {
-  clearCaches: function () {
-    const promises = [];
-    const clearInstance = function (prefix) {
-      promises.push(localforage.createInstance({ name: prefix + window.LOGGED_USERNAME }).clear());
+export interface HueDebug {
+  lastChangeTime?: number;
+  logStatementLocations?: boolean;
+  clearCaches(): void;
+  showSyntaxParseResult?: boolean;
+}
+
+const hueDebug: HueDebug = {
+  clearCaches: () => {
+    const promises: Promise<void>[] = [];
+    const clearInstance = (prefix: string) => {
+      promises.push(
+        localforage.createInstance({ name: prefix + (<hueWindow>window).LOGGED_USERNAME }).clear()
+      );
     };
     clearInstance('HueContextCatalog_');
     clearInstance('HueDataCatalog_');

+ 1 - 1
desktop/core/src/desktop/js/utils/huePubSub.ts

@@ -63,7 +63,7 @@ const removeAll = (topic: string): void => {
 };
 
 // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
-const publish = (topic: string, info: any): void => {
+const publish = (topic: string, info?: any): void => {
   if (!hOP.call(topics, topic)) {
     return;
   }