UNPKG

@getanthill/datastore

Version:

Event-Sourced Datastore

100 lines (99 loc) 3.49 kB
import type { ModelConfig } from '../typings'; import { AxiosInstance, AxiosRequestConfig } from 'axios'; interface Table { name: string; id?: number; fields?: Field[]; } interface Field { id?: number; name: string; table_id: number; table_name: string; base_type?: string; semantic_type?: string; visibility_type?: 'normal' | 'details-only' | 'sensitive'; } interface Graph { nodes: { id?: string; group?: number; }[]; edges: { source?: string; target?: string; value?: number; key?: string; correlation_field?: string; }[]; } interface MetabaseSdkConfig { namespace?: string; baseUrl?: string; timeout?: number; username?: string; password?: string; tables?: Table[]; fields?: Field[]; models?: ModelConfig[]; graph?: Graph; } export default class Metabase { static ERRORS: { UNAUTHENTICATED: Error; }; config: MetabaseSdkConfig; axios: AxiosInstance; sessionToken: string; constructor(config: MetabaseSdkConfig); static toSnakeCase(str: string): string; static toMetabaseDisplayCase(str: string): string; setSessionToken(token: any): void; authenticate(): Promise<any>; request(config: AxiosRequestConfig): Promise<any>; getCurrentUser(): Promise<any>; getDatabases(): Promise<any>; getTableForeignKeys(tableId: number): Promise<any>; getTableFields(tableId: number): Field[]; getField(fieldId: number): Promise<any>; updateField(fieldId: number, field: Partial<Field>): Promise<any>; getDatabaseTables(databaseId: number): Promise<Table[]>; updateTable(tableId: number, table: Partial<Table>): Promise<any>; /** Model schema sync */ static getNormalizedName(item: { name: string; nfc_path?: string[]; }): string; static getModelNameFromTable(table: Table): string; static isEventsTable(table: Table): boolean; static isSnapshotsTable(table: Table): boolean; static isCorrelationField(field: Field, model: Partial<ModelConfig>): boolean; static isEncryptedField(field: Field, model: Partial<ModelConfig>): boolean; static getFieldVisibility(field: Field, model: Partial<ModelConfig>, defaultValue?: string): string; /** * @see https://github.com/metabase/metabase/blob/6a6327646964559e735c3557d8c39f5ceff5dcd8/shared/src/metabase/types.cljc */ static getBaseTypeFromJsonSchema(field: Field, model: Partial<ModelConfig>, fieldSchema: { type: string; }, defaultBaseType?: string | null): string | null; /** * @see https://github.com/metabase/metabase/blob/6a6327646964559e735c3557d8c39f5ceff5dcd8/shared/src/metabase/types.cljc */ static getSemanticTypeFromJsonSchema(field: Field, model: Partial<ModelConfig>, fieldSchema: { type: string; }, defaultSemanticType?: string | null): string | null; setTables(tables: Table[]): this; getTables(): Table[]; getTableById(id: number): Table | undefined; setFields(fields: Field[]): this; getFields(): Field[]; setModels(models: ModelConfig[]): this; getModels(): ModelConfig[]; setGraph(graph: Graph): this; getGraph(): Graph; getModelFromTable(table: Table): ModelConfig | undefined; getTableUpdatePayload(table: Table): any; getFieldUpdatePayload(field: Field): any; getFieldUpdatePayloadWithForeignKeys(field: Field, payload: any): any; } export {};