Jelajahi Sumber

[frontend] Add missing types for parsers, Ace and the data catalog

Johan Ahlen 5 tahun lalu
induk
melakukan
06fe15aedb

+ 2 - 2
desktop/core/src/desktop/js/catalog/dataCatalog.js

@@ -878,8 +878,8 @@ export default {
    * getEntry then getChildren.
    *
    * @param {Object} options
-   * @param {ContextNamespace} options.namespace - The context namespace
-   * @param {ContextCompute} options.compute - The context compute
+   * @param {Namespace} options.namespace - The context namespace
+   * @param {Compute} options.compute - The context compute
    * @param {Connector} options.connector
    * @param {string|string[]} options.path
    * @param {Object} [options.definition] - Optional initial definition of the parent entry

+ 39 - 0
desktop/core/src/desktop/js/catalog/dataCatalog/index.d.ts

@@ -0,0 +1,39 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import CancellableJqPromise from 'api/cancellableJqPromise';
+import DataCatalogEntry from 'catalog/dataCatalogEntry';
+import { Compute, Connector, Namespace } from 'types/config';
+
+interface options {
+  namespace: Namespace;
+  compute: Compute;
+  connector: Connector;
+  path: string | string[];
+  definition?: unknown;
+  silenceErrors?: boolean;
+  cachedOnly?: boolean;
+  refreshCache?: boolean;
+  cancellable?: boolean;
+  temporaryOnly?: boolean;
+}
+
+declare const dataCatalog: {
+  getChildren(options: options): CancellableJqPromise<DataCatalogEntry[]>;
+  getEntry(options: options): CancellableJqPromise<DataCatalogEntry>;
+};
+
+export = dataCatalog;

+ 59 - 9
desktop/core/src/desktop/js/ext/ace.d.ts

@@ -1,7 +1,24 @@
-import {IdentifierLocation, SyntaxError} from 'parse/types';
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// 'License'); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an 'AS IS' BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import { IdentifierLocation, SyntaxError } from 'parse/types';
 
 declare namespace Ace {
   export interface Editor {
+    $blockScrolling: number;
     addError(message:string, line:number): void;
     addWarning(message:string, line:number): void;
     container: HTMLElement;
@@ -10,6 +27,8 @@ declare namespace Ace {
     clearErrorsAndWarnings(type: string): void;
     customMenuOptions: { [option: string]: (val?: any) => any };
     enabledMenuOptions: { [option: string]: boolean };
+    execCommand(cmd: string, arg?: unknown): void;
+    focus(): void;
     getCursorPosition(): Position;
     getOption(option: string): string|boolean|number;
     getSelectedText(): string;
@@ -18,19 +37,35 @@ declare namespace Ace {
     getTextAfterCursor(): string;
     getTextBeforeCursor(): string;
     getValue(): string;
+    keyBinding: {
+      addKeyboardHandler(hashHandler: HashHandler): void;
+      removeKeyboardHandler(hashHandler: HashHandler): void;
+    }
     lastChangeTime: number;
     off(ev: string, callback: ((e: any) => any) | number): void;
     on(event: string, fn: (e: any) => any): number;
+    removeTextAfterCursor(length: number): void;
     renderer: {
+      scrollLeft: number;
+      gutterWidth: number;
       lineHeight: number;
+      layerConfig: {
+        lineHeight: number;
+        offset: number;
+      };
+      $cursorLayer: {
+        getPixelPosition(anchor?: Anchor, b?: boolean): { top: number; left: number };
+      };
       screenToTextCoordinates(left: number, top: number): Position;
-      scrollCursorIntoView(position: Position, u: number): void;
+      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;
+      getAllRanges(): Range[];
+      lead: Position;
     };
     session: Session;
     setOption(option: string, value: OptionValue): void;
@@ -45,19 +80,26 @@ declare namespace Ace {
     [option: string]: OptionValue;
   }
 
+  export interface AceUtil {
+    retrievePrecedingIdentifier(row: number, column: number, regex?: RegExp): string;
+  }
+
   export interface Position {
     column: number;
     row: number;
   }
 
-  export interface Range {
+  export interface SimpleRange {
     end: Position | Anchor;
-    endColumn:number;
-    endRow:number;
-    isEmpty(): boolean;
     start: Position | Anchor;
-    startColumn:number;
-    startRow:number;
+  }
+
+  export interface Range extends SimpleRange {
+    endColumn: number;
+    endRow: number;
+    isEmpty(): boolean;
+    startColumn: number;
+    startRow: number;
   }
 
   export interface Document {
@@ -66,6 +108,7 @@ declare namespace Ace {
   }
 
   export interface Anchor extends Position {
+    $insertRight: boolean;
     detach(): void;
     getPosition(): Position;
     on(event: string, fn: (e: any) => any): number;
@@ -84,9 +127,11 @@ declare namespace Ace {
     addGutterDecoration(line: number, clazz: string): void;
     addMarker(range: Range, clazz: string): number;
     doc: Document;
-    getTextRange(range: Range): string;
+    getLine(row: number): number;
+    getTextRange(range: SimpleRange): string;
     getTokenAt(row: number, column: number): HueToken | null;
     getTokens(line?: number): HueToken[];
+    remove(range: Range): void;
     removeGutterDecoration(line: number, clazz: string): void;
     removeMarker(markerId: number): void;
     setMode(mode: string): void;
@@ -102,4 +147,9 @@ declare namespace Ace {
     syntaxError?: SyntaxError;
     value: string;
   }
+
+  export class HashHandler {
+    constructor();
+    bindKeys(bindings: { [keys: string]: (editor: Ace.Editor, event: unknown) => void }): void;
+  }
 }

+ 1 - 1
desktop/core/src/desktop/js/ko/components/assist/assistStorageEntry.js

@@ -347,7 +347,7 @@ class AssistStorageEntry {
    *
    * @param {string} path - The path, can include the type i.e. '/tmp' or 's3:/tmp'.
    * @param {string} [type] - Optional type, if not specified here or in the path 'hdfs' will be used.
-   * @return {Promise}
+   * @return {JQueryPromise<AssistStorageEntry>}
    */
   static getEntry(path, type) {
     const deferred = $.Deferred();

+ 4 - 0
desktop/core/src/desktop/js/parse/sql/sqlParserRepository.js

@@ -62,6 +62,10 @@ class SqlParserRepository {
     return this.modulePromises[dialect + parserType];
   }
 
+  /**
+   * @param dialect
+   * @return {Promise<*>}
+   */
   async getAutocompleter(dialect) {
     return this.getParser(dialect, 'Autocomplete');
   }

+ 0 - 12
desktop/core/src/desktop/js/parse/sqlStatementsParser.d.ts

@@ -1,12 +0,0 @@
-import { ParsedLocation } from 'parse/types';
-
-export interface ParsedSqlStatement {
-  firstToken: string;
-  statement: string;
-  location: ParsedLocation;
-  type: string;
-}
-
-declare module 'parse/sqlStatementsParser' {
-  export function parse(statement: string): ParsedSqlStatement[];
-}

+ 16 - 0
desktop/core/src/desktop/js/parse/sqlStatementsParser/index.d.ts

@@ -0,0 +1,16 @@
+import { ParsedLocation } from 'parse/types';
+
+export = sqlStatementsParser;
+
+declare const sqlStatementsParser = {
+  parse(statement: string): sqlStatementsParser.ParsedSqlStatement[];
+};
+
+declare namespace sqlStatementsParser {
+  export interface ParsedSqlStatement {
+    firstToken: string;
+    statement: string;
+    location: ParsedLocation;
+    type: string;
+  }
+}

+ 5 - 1
desktop/core/src/desktop/js/parse/types.ts

@@ -44,7 +44,7 @@ export interface ParsedLocation {
 }
 
 export interface SyntaxError {
-  expected: { text: string }[];
+  expected: { text: string; distance: number }[];
   expectedStatementEnd?: boolean;
   loc: ParsedLocation;
   text: string;
@@ -186,4 +186,8 @@ export interface SqlStatementsParser {
   parse(text: string): ParsedSqlStatement;
 }
 
+export interface AutocompleteParser {
+  parseSql(beforeCursor: string, afterCursor: string): AutocompleteParseResult;
+}
+
 declare const sqlStatementsParser: SqlStatementsParser;

+ 1 - 0
desktop/core/src/desktop/js/types/config.ts

@@ -108,6 +108,7 @@ export interface EditorInterpreter extends IdentifiableInterpreter {
   is_sql: boolean;
   name: string;
   optimizer: string;
+  dialect: string;
 }
 
 /* eslint-disable @typescript-eslint/no-empty-interface */

+ 1 - 0
desktop/core/src/desktop/js/utils/hueDebug.ts

@@ -22,6 +22,7 @@ export interface HueDebug {
   logStatementLocations?: boolean;
   clearCaches(): void;
   showSyntaxParseResult?: boolean;
+  showParseResult?: boolean;
 }
 
 const hueDebug: HueDebug = {