import type { RunSQLOptions } from './run_sql_options'; import type { DocumentCompletion as DocumentCompletionDefinition, DocumentSymbol as DocumentSymbolDefinition, LogMessage } from './lang'; import { MalloyTranslator } from './lang'; import type { DocumentHelpContext } from './lang/parse-tree-walkers/document-help-context-walker'; import type { CompiledQuery, DocumentLocation, DocumentReference, BooleanFieldDef, JSONFieldDef, NumberFieldDef, StringFieldDef, FilterCondition, Query as InternalQuery, ModelDef, DocumentPosition as ModelDocumentPosition, NamedQuery, QueryData, QueryDataRow, QueryResult, SearchIndexResult, SearchValueMapResult, StructDef, TurtleDef, NativeUnsupportedFieldDef, QueryRunStats, ImportLocation, Annotation, SQLSourceDef, AtomicFieldDef, DateFieldDef, TimestampFieldDef, SourceDef, QueryToMaterialize, Argument, TableSourceDef, SourceComponentInfo } from './model'; import type { EventStream, InvalidationKey, ModelString, ModelURL, QueryString, QueryURL, URLReader } from './runtime_types'; import type { Connection, FetchSchemaOptions, InfoConnection, LookupConnection } from './connection/types'; import type { Tag } from '@malloydata/malloy-tag'; import type { Dialect } from './dialect'; import type { PathInfo } from './lang/parse-tree-walkers/find-table-path-walker'; import type { MalloyTagParse, TagParseSpec } from './annotation'; export interface Taggable { tagParse: (spec?: TagParseSpec) => MalloyTagParse; getTaglines: (prefix?: RegExp) => string[]; } export interface Loggable { debug: (message?: any, ...optionalParams: any[]) => void; info: (message?: any, ...optionalParams: any[]) => void; warn: (message?: any, ...optionalParams: any[]) => void; error: (message?: any, ...optionalParams: any[]) => void; } export interface ParseOptions { importBaseURL?: URL; testEnvironment?: boolean; } /** Options for how to run the Malloy semantic checker/translator */ export interface CompileOptions { refreshSchemaCache?: boolean | number; noThrowOnError?: boolean; } /** Options given to the Malloy compiler (QueryModel) */ interface CompileQueryOptions { replaceMaterializedReferences?: boolean; materializedTablePrefix?: string; eventStream?: EventStream; defaultRowLimit?: number; } type Compilable = { parse: Parse; url?: undefined; source?: undefined; } | { url: URL; parse?: undefined; source?: undefined; } | { source: string; parse?: undefined; url?: undefined; }; export declare class Malloy { static get version(): string; private static _parse; /** * Parse a Malloy document by URL. * * @param url The URL of the Malloy document to parse. * @param urlReader Object capable of fetching URL contents. * @return A (promise of a) `Parse` result. */ static parse({ url, urlReader, eventStream, options, }: { url: URL; urlReader: URLReader; eventStream?: EventStream; options?: ParseOptions; }): Promise; /** * Parse a Malloy document by contents. * * @param url The URL of the Malloy document to parse (optional). * @param source The contents of the Malloy document to parse. * @return A `Parse` result. */ static parse({ source, url, eventStream, options, }: { url?: URL; source: string; eventStream?: EventStream; options?: ParseOptions; }): Parse; /** * Compile a parsed Malloy document. * * @param urlReader Object capable of reading contents of a URL. * @param connections Mapping of connection names to objects capable of reading Malloy schemas. * @param parse The parsed Malloy document. * @param model A compiled model to build upon (optional). * @return A (promise of a) compiled `Model`. */ static compile({ url, source, parse, urlReader, connections, model, refreshSchemaCache, noThrowOnError, eventStream, importBaseURL, cacheManager, }: { urlReader: URLReader; connections: LookupConnection; model?: Model; cacheManager?: CacheManager; } & Compilable & CompileOptions & CompileQueryOptions & ParseOptions): Promise; /** * A dialect must provide a response for every table, or the translator loop * will never exit. Because there was a time when this happened, we throw * instead of looping forever, but the fix is to correct the dialect. */ static safelyFetchTableSchema(connection: InfoConnection, toFetch: Record, opts: FetchSchemaOptions): Promise<{ schemas: Record; errors: Record; }>; /** * Run a fully-prepared query. * * @param get A mapping from connection names to objects capable of running SQL. * @param preparedResult A fully-prepared query which is ready to run (a `PreparedResult`). * @return Query result data and associated metadata. */ static run(params: { connections: LookupConnection; preparedResult: PreparedResult; options?: RunSQLOptions; }): Promise; static run(params: { connection: Connection; preparedResult: PreparedResult; options?: RunSQLOptions; }): Promise; static run(params: { connection: Connection; sqlStruct: SQLSourceDef; options?: RunSQLOptions; }): Promise; static run(params: { connections: LookupConnection; sqlStruct: SQLSourceDef; options?: RunSQLOptions; }): Promise; static run(params: { connection: Connection; sqlStruct: SQLSourceDef; options?: RunSQLOptions; }): Promise; static run(params: { connections: LookupConnection; sqlStruct: SQLSourceDef; options?: RunSQLOptions; }): Promise; static runStream(params: { connections: LookupConnection; preparedResult: PreparedResult; options?: RunSQLOptions; }): AsyncIterableIterator; static runStream(params: { connection: Connection; preparedResult: PreparedResult; options?: RunSQLOptions; }): AsyncIterableIterator; static runStream(params: { connection: Connection; sqlStruct: SQLSourceDef; options?: RunSQLOptions; }): AsyncIterableIterator; static runStream(params: { connections: LookupConnection; sqlStruct: SQLSourceDef; options?: RunSQLOptions; }): AsyncIterableIterator; static estimateQueryCost(params: { connections: LookupConnection; preparedResult: PreparedResult; }): Promise; static estimateQueryCost(params: { connections: LookupConnection; sqlStruct: SQLSourceDef; }): Promise; } /** * A Malloy error, which may contain log messages produced during compilation. */ export declare class MalloyError extends Error { readonly problems: LogMessage[]; /** * An array of log messages produced during compilation. */ constructor(message: string, problems?: LogMessage[]); } /** * A compiled Malloy document. */ export declare class Model implements Taggable { private modelDef; readonly problems: LogMessage[]; readonly fromSources: string[]; private readonly references; constructor(modelDef: ModelDef, problems: LogMessage[], fromSources: string[]); tagParse(spec?: TagParseSpec): MalloyTagParse; getTaglines(prefix?: RegExp): string[]; /** * Retrieve a document reference for the token at the given position within * the document that produced this model. * * @param position A position within the document. * @return A `DocumentReference` at that position if one exists. */ getReference(position: ModelDocumentPosition): DocumentReference | undefined; /** * Retrieve an import for the token at the given position within * the document that produced this model. * * @param position A position within the document. * @return An `ImportLocation` at that position if one exists. */ getImport(position: ModelDocumentPosition): ImportLocation | undefined; /** * Retrieve a prepared query by the name of a query at the top level of the model. * * @param queryName Name of the query to retrieve. * @return A prepared query. */ getPreparedQueryByName(queryName: string): PreparedQuery; /** * Retrieve a prepared query by the index of an unnamed query at the top level of a model. * * @param index The index of the query to retrieve. * @return A prepared query. */ getPreparedQueryByIndex(index: number): PreparedQuery; /** * Retrieve a prepared query for the final unnamed query at the top level of a model. * * @return A prepared query. */ get preparedQuery(): PreparedQuery; /** * Retrieve a prepared query for the final unnamed query at the top level of a model. * * @return A prepared query. */ getPreparedQuery(): PreparedQuery; /** * Retrieve an `Explore` from the model by name. * * @param name The name of the `Explore` to retrieve. * @return An `Explore`. */ getExploreByName(name: string): Explore; /** * Get an array of `Explore`s contained in the model. * * @return An array of `Explore`s contained in the model. */ get explores(): Explore[]; /** * Get an array of `NamedQuery`s contained in the model. * * @return An array of `NamedQuery`s contained in the model. */ get namedQueries(): NamedQuery[]; get exportedExplores(): Explore[]; get _modelDef(): ModelDef; } /** * A prepared query which has all the necessary information to produce its SQL. */ export declare class PreparedQuery implements Taggable { problems: LogMessage[]; name?: string | undefined; _modelDef: ModelDef; _query: InternalQuery | NamedQuery; constructor(query: InternalQuery, model: ModelDef, problems: LogMessage[], name?: string | undefined); tagParse(spec?: TagParseSpec): MalloyTagParse; getTaglines(prefix?: RegExp): string[]; /** * Generate the SQL for this query. * * @return A fully-prepared query (which contains the generated SQL). */ get preparedResult(): PreparedResult; /** * Generate the SQL for this query. * * @return A fully-prepared query (which contains the generated SQL). * @param options.eventStream An event stream to use when compiling the SQL */ getPreparedResult(options?: CompileQueryOptions): PreparedResult; get dialect(): string; /** * Get the flattened version of a query -- one that does not have a `pipeHead`. * @deprecated Because queries can no longer have `pipeHead`s. */ getFlattenedQuery(_defaultName: string): PreparedQuery; } /** * A parsed Malloy document. */ export declare class Parse { private translator; private invalidationKey?; constructor(translator: MalloyTranslator, invalidationKey?: InvalidationKey | undefined); /** * Retrieve the symbols defined in the parsed document. * * These symbols represent any object defined (e.g. `Query`s and `Explore`s) * in the document. * * @return An array of document symbols. */ get symbols(): DocumentSymbol[]; /** * Retrieve the full table paths for tables defined in the parsed document. * Derived tables i.e. a table that extends another table, table from a query * are not included. * * @return An array of document table path info. */ get tablePathInfo(): DocumentTablePath[]; get _translator(): MalloyTranslator; get _invalidationKey(): InvalidationKey | undefined; completions(position: { line: number; character: number; }): DocumentCompletion[]; helpContext(position: { line: number; character: number; }): DocumentHelpContext | undefined; } /** * Path info for a table defined in a Malloy document. */ export declare class DocumentTablePath { private _range; private _connectionId; private _tablePath; constructor(tablePath: PathInfo); /** * @return The range of characters in the source Malloy document that defines * this table. */ get range(): DocumentRange; /** @return The Connection Id for this table. */ get connectionId(): string; /** @return The full table path. */ get tablePath(): string; } /** * A range of characters within a Malloy document. */ export declare class DocumentRange { private _start; private _end; constructor(start: DocumentPosition, end: DocumentPosition); /** * @return The position of the first character in the range. */ get start(): DocumentPosition; /** * @return The position of the last character in the range. */ get end(): DocumentPosition; /** * @return This range in JSON format. */ toJSON(): { start: { line: number; character: number; }; end: { line: number; character: number; }; }; /** * Construct a DocumentRange from JSON. */ static fromJSON(json: { start: { line: number; character: number; }; end: { line: number; character: number; }; }): DocumentRange; } /** * A position within a Malloy document. */ export declare class DocumentPosition { private _line; private _character; constructor(line: number, character: number); /** * @return The line number of the position. */ get line(): number; /** * @return The character index on the line `this.getLine()`. */ get character(): number; /** * @return This position in JSON format. */ toJSON(): { line: number; character: number; }; } /** * A symbol defined in a Malloy document. * * Represents any object defined (e.g. `Query`s and `Explore`s) in the document. */ export declare class DocumentSymbol { private _range; private _lensRange; private _type; private _name; private _children; constructor(documentSymbol: DocumentSymbolDefinition); /** * @return The range of characters in the source Malloy document that define this symbol. */ get range(): DocumentRange; /** * @return The range of characters in the source Malloy document that define this symbol, * including tags. Note: "block tags" are included if there is exactly one * definition in the block. */ get lensRange(): DocumentRange; /** * @return The type of symbol. * * Possible values are: `"explore"`, `"query"`, `"field"`, `"turtle"`, `"join"`, or `"unnamed_query"`. */ get type(): string; /** * @return The name of this symbol, e.g. the `Explore` name or `Query` name. * * For type `"unnamed_query"`, `getName()` is `"unnamed_query"`. */ get name(): string; /** * @return An array of document symbols defined inside this document symbol, * e.g. fields in an `Explore`. */ get children(): DocumentSymbol[]; } export declare class DocumentCompletion { readonly type: string; readonly text: string; constructor(completion: DocumentCompletionDefinition); } export type PreparedResultJSON = { query: CompiledQuery; modelDef: ModelDef; }; /** * A fully-prepared query containing SQL and metadata required to run the query. */ export declare class PreparedResult implements Taggable { protected modelDef: ModelDef; protected inner: CompiledQuery; constructor(query: CompiledQuery, modelDef: ModelDef); static fromJson({ query, modelDef, }: PreparedResultJSON): PreparedResult; tagParse(spec?: TagParseSpec): MalloyTagParse; getTaglines(prefix?: RegExp): string[]; get annotation(): Annotation | undefined; get modelAnnotation(): Annotation | undefined; get modelTag(): Tag; /** * @return The name of the connection this query should be run against. */ get connectionName(): string; get _rawQuery(): CompiledQuery; get _modelDef(): ModelDef; /** * @return The SQL that should be run against the SQL runner * with the connection name `this.getConnectionName()`. */ get sql(): string; get dependenciesToMaterialize(): Record | undefined; get materialization(): QueryToMaterialize | undefined; /** * @return The `Explore` representing the data that will be returned by running this query. */ get resultExplore(): Explore; get sourceExplore(): Explore | undefined; get _sourceExploreName(): string; get _sourceArguments(): Record | undefined; get _sourceFilters(): FilterCondition[]; } /** * A URL reader which always throws an error when a URL's contents is requested. * * Useful for scenarios in which `import` statements are not required. */ export declare class EmptyURLReader implements URLReader { readURL(_url: URL): Promise<{ contents: string; invalidationKey: InvalidationKey; }>; getInvalidationKey(_url: URL): Promise; } /** * A URL reader backed by an in-memory mapping of URL contents. */ export declare class InMemoryURLReader implements URLReader { protected files: Map; constructor(files: Map); readURL(url: URL): Promise<{ contents: string; invalidationKey: InvalidationKey; }>; getInvalidationKey(url: URL): Promise; private invalidationKey; } /** * A fixed mapping of connection names to connections. */ export declare class FixedConnectionMap implements LookupConnection { private connections; private defaultConnectionName?; constructor(connections: Map, defaultConnectionName?: string | undefined); /** * Get a connection by name. * * @param connectionName The name of the connection to look up. * @return A `Connection` * @throws An `Error` if no connection with the given name exists. */ getConnection(connectionName?: string): Promise; /** * Gets a list of registered connections. * * @return The list of registered connections. */ listConnections(): Connection[]; lookupConnection(connectionName?: string): Promise; static fromArray(connections: Connection[]): FixedConnectionMap; } /** * The relationship of an `Explore` to its source. */ export declare enum SourceRelationship { /** * The `Explore` is nested data within the source's rows. */ Nested = "nested", /** * The `Explore` is the base table. */ BaseTable = "base_table", /** * The `Explore` is joined to its source */ Cross = "cross", One = "one", Many = "many", Inline = "inline" } declare abstract class Entity { private readonly _name; protected readonly _parent?: Explore; private readonly _source?; constructor(name: string, parent?: Explore, source?: Entity); get source(): Entity | undefined; get name(): string; get sourceClasses(): string[]; get fieldPath(): string[]; hasParentExplore(): this is Field; isExplore(): this is Explore; isQuery(): this is Query; abstract isIntrinsic(): boolean; abstract get location(): DocumentLocation | undefined; } export type Field = AtomicField | QueryField | ExploreField; export type SerializedExplore = { _structDef: StructDef; sourceExplore?: SerializedExplore; _parentExplore?: SerializedExplore; }; export type SortableField = { field: Field; dir: 'asc' | 'desc' | undefined; }; export declare class Explore extends Entity implements Taggable { protected readonly _structDef: StructDef; protected readonly _parentExplore?: Explore; private _fieldMap; private sourceExplore; private _allFieldsWithOrder; constructor(structDef: StructDef, parentExplore?: Explore, source?: Explore); get source(): Explore | undefined; isIntrinsic(): boolean; isExploreField(): this is ExploreField; tagParse(spec?: TagParseSpec): MalloyTagParse; getTaglines(prefix?: RegExp): string[]; private parsedModelTag?; get modelTag(): Tag; /** * @return The name of the entity. */ get name(): string; getQueryByName(name: string): PreparedQuery; private get modelDef(); getSingleExploreModel(): Model; private get fieldMap(); get allFields(): Field[]; get allFieldsWithOrder(): SortableField[]; get intrinsicFields(): Field[]; get dimensions(): SortableField[]; getFieldByName(fieldName: string): Field; getFieldByNameIfExists(fieldName: string): Field | undefined; get primaryKey(): string | undefined; get parentExplore(): Explore | undefined; hasParentExplore(): this is ExploreField; get filters(): FilterCondition[]; get limit(): number | undefined; get structDef(): StructDef; get queryTimezone(): string | undefined; get sourceStructDef(): SourceDef | undefined; toJSON(): SerializedExplore; static fromJSON(main_explore: SerializedExplore): Explore; get location(): DocumentLocation | undefined; private collectSourceComponents; /** * THIS IS A HIGHLY EXPERIMENTAL API AND MAY VANISH OR CHANGE WITHOUT NOTICE */ getSourceComponents(): SourceComponentInfo[]; } export declare enum AtomicFieldType { String = "string", Number = "number", Boolean = "boolean", Date = "date", Timestamp = "timestamp", Json = "json", NativeUnsupported = "sql native", Error = "error" } export declare class AtomicField extends Entity implements Taggable { protected fieldTypeDef: AtomicFieldDef; protected parent: Explore; constructor(fieldTypeDef: AtomicFieldDef, parent: Explore, source?: AtomicField); get type(): AtomicFieldType; tagParse(spec?: TagParseSpec): MalloyTagParse; getTaglines(prefix?: RegExp): string[]; isIntrinsic(): boolean; isQueryField(): this is QueryField; isExploreField(): this is ExploreField; isAtomicField(): this is AtomicField; isCalculation(): boolean; get sourceField(): Field; get sourceClasses(): string[]; /** * A unique ID of this field within the context of a result; undefined * for fields that are not derived from a Result. */ get referenceId(): string | undefined; sourceWasMeasure(): boolean; sourceWasMeasureLike(): boolean; sourceWasDimension(): boolean; hasParentExplore(): this is Field; isString(): this is StringField; isNumber(): this is NumberField; isDate(): this is DateField; isBoolean(): this is BooleanField; isJSON(): this is JSONField; isTimestamp(): this is TimestampField; isUnsupported(): this is UnsupportedField; get parentExplore(): Explore; /** * @return Field name for drill. */ get expression(): string; get location(): DocumentLocation | undefined; } export declare enum DateTimeframe { Day = "day", Week = "week", Month = "month", Quarter = "quarter", Year = "year" } export declare enum TimestampTimeframe { Day = "day", Week = "week", Month = "month", Quarter = "quarter", Year = "year", Second = "second", Hour = "hour", Minute = "minute" } export declare class DateField extends AtomicField { private fieldDateDef; constructor(fieldDateDef: DateFieldDef, parent: Explore, source?: AtomicField); get timeframe(): DateTimeframe | undefined; } export declare class TimestampField extends AtomicField { private fieldTimestampDef; constructor(fieldTimestampDef: TimestampFieldDef, parent: Explore, source?: AtomicField); get timeframe(): TimestampTimeframe | undefined; } export declare class NumberField extends AtomicField { private fieldNumberDef; constructor(fieldNumberDef: NumberFieldDef, parent: Explore, source?: AtomicField); } export declare class BooleanField extends AtomicField { private fieldBooleanDef; constructor(fieldBooleanDef: BooleanFieldDef, parent: Explore, source?: AtomicField); } export declare class JSONField extends AtomicField { private fieldJSONDef; constructor(fieldJSONDef: JSONFieldDef, parent: Explore, source?: AtomicField); } export declare class UnsupportedField extends AtomicField { private fieldUnsupportedDef; constructor(fieldUnsupportedDef: NativeUnsupportedFieldDef, parent: Explore, source?: AtomicField); get rawType(): string | undefined; } export declare class StringField extends AtomicField { private fieldStringDef; constructor(fieldStringDef: StringFieldDef, parent: Explore, source?: AtomicField); } export declare class Query extends Entity { protected turtleDef: TurtleDef; private sourceQuery?; constructor(turtleDef: TurtleDef, parent?: Explore, source?: Query); get source(): Query | undefined; isIntrinsic(): boolean; get location(): DocumentLocation | undefined; } export declare class QueryField extends Query implements Taggable { protected parent: Explore; constructor(turtleDef: TurtleDef, parent: Explore, source?: Query); tagParse(spec?: TagParseSpec): MalloyTagParse; getTaglines(prefix?: RegExp): string[]; isQueryField(): this is QueryField; isExploreField(): this is ExploreField; isAtomicField(): this is AtomicField; get sourceClasses(): string[]; hasParentExplore(): this is Field; get parentExplore(): Explore; get expression(): string; } export declare enum JoinRelationship { OneToOne = "one_to_one", OneToMany = "one_to_many", ManyToOne = "many_to_one" } export declare class ExploreField extends Explore { protected _parentExplore: Explore; constructor(structDef: StructDef, parentExplore: Explore, source?: Explore); get joinRelationship(): JoinRelationship; get isRecord(): boolean; get isArray(): boolean; tagParse(spec?: TagParseSpec): MalloyTagParse; isQueryField(): this is QueryField; isExploreField(): this is ExploreField; isAtomicField(): this is AtomicField; get parentExplore(): Explore; get sourceClasses(): string[]; get queryTimezone(): string | undefined; } type Connectionable = { connection: Connection; connections?: undefined; } | { connections: LookupConnection; connection?: undefined; }; /** * An environment for compiling and running Malloy queries. */ export declare class Runtime { isTestRuntime: boolean; private _urlReader; private _connections; private _eventStream; private _cacheManager; constructor({ urlReader, connections, connection, eventStream, cacheManager, }: { urlReader?: URLReader; eventStream?: EventStream; cacheManager?: CacheManager; } & Connectionable); /** * @return The `CacheManager` for this runtime instance. */ get cacheManager(): CacheManager | undefined; /** * @return The `URLReader` for this runtime instance. */ get urlReader(): URLReader; /** * @return The `LookupConnection` for this runtime instance. */ get connections(): LookupConnection; /** * @return The `EventStream` for this runtime instance. */ get eventStream(): EventStream | undefined; /** * Load a Malloy model by URL or contents. * * @param source The model URL or contents to load and (eventually) compile. * @return A `ModelMaterializer` capable of materializing the requested model, * or loading further related objects. */ loadModel(source: ModelURL | ModelString, options?: ParseOptions & CompileOptions & CompileQueryOptions): ModelMaterializer; _loadModelFromModelDef(modelDef: ModelDef, options?: CompileQueryOptions): ModelMaterializer; /** * Load a Malloy query by URL or contents. * * @param query The query URL or contents to load and (eventually) compile. * @return A `QueryMaterializer` capable of materializing the requested query, running it, * or loading further related objects. */ loadQuery(query: QueryURL | QueryString, options?: ParseOptions & CompileOptions & CompileQueryOptions): QueryMaterializer; /** * Load a Malloy query by the URL or contents of a Malloy model document * and the index of an unnamed query contained in the model. * * @param model The model URL or contents to load and (eventually) compile to retrieve the requested query. * @param index The index of the query to use within the model. * @return A `QueryMaterializer` capable of materializing the requested query, running it, * or loading further related objects. */ loadQueryByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions & CompileOptions & CompileQueryOptions): QueryMaterializer; /** * Load a Malloy query by the URL or contents of a Malloy model document * and the name of a query contained in the model. * * @param model The model URL or contents to load and (eventually) compile to retrieve the requested query. * @param name The name of the query to use within the model. * @return A `QueryMaterializer` capable of materializing the requested query, running it, * or loading further related objects. */ loadQueryByName(model: ModelURL | ModelString, name: string, options?: ParseOptions & CompileOptions & CompileQueryOptions): QueryMaterializer; /** * Compile a Malloy model by URL or contents. * * @param source The URL or contents of a Malloy model document to compile. * @return A promise of a compiled `Model`. */ getModel(source: ModelURL | ModelString, options?: ParseOptions & CompileOptions): Promise; /** * Compile a Malloy query by URL or contents. * * @param query The URL or contents of a Malloy query document to compile. * @return A promise of a compiled `PreparedQuery`. */ getQuery(query: QueryURL | QueryString, options?: ParseOptions & CompileOptions): Promise; /** * Compile a Malloy query by the URL or contents of a model document * and the index of an unnamed query contained within the model. * * @param model The URL or contents of a Malloy model document to compile. * @param index The index of an unnamed query contained within the model. * @return A promise of a compiled `PreparedQuery`. */ getQueryByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions & CompileOptions): Promise; /** * Compile a Malloy query by the URL or contents of a model document * and the name of a query contained within the model. * * @param model The URL or contents of a Malloy model document to compile. * @param name The name of a query contained within the model. * @return A promise of a compiled `PreparedQuery`. */ getQueryByName(model: ModelURL | ModelString, name: string, options?: ParseOptions & CompileOptions): Promise; } export declare class ConnectionRuntime extends Runtime { readonly rawConnections: Connection[]; constructor({ urlReader, connections, }: { urlReader?: URLReader; connections: Connection[]; }); } export declare class SingleConnectionRuntime extends Runtime { readonly connection: T; constructor({ urlReader, connection, eventStream, cacheManager, }: { urlReader?: URLReader; eventStream?: EventStream; cacheManager?: CacheManager; connection: T; }); get supportsNesting(): boolean; quote(column: string): string; get dialect(): Dialect; getQuoter(): (arg: TemplateStringsArray) => string; } declare class FluentState { protected runtime: Runtime; private readonly _materialize; private materialized; constructor(runtime: Runtime, materialize: () => Promise); protected materialize(): Promise; protected rematerialize(): Promise; protected makeQueryMaterializer(materialize: () => Promise, options?: CompileQueryOptions): QueryMaterializer; protected makeExploreMaterializer(materialize: () => Promise, options?: CompileQueryOptions): ExploreMaterializer; protected makePreparedResultMaterializer(materialize: () => Promise): PreparedResultMaterializer; } /** * An object representing the task of loading a `Model`, capable of * materializing that model (via `getModel()`) or extending the task to load * queries or explores (via e.g. `loadFinalQuery()`, `loadQuery`, `loadExploreByName`, etc.). */ export declare class ModelMaterializer extends FluentState { protected runtime: Runtime; private readonly compileQueryOptions; constructor(runtime: Runtime, materialize: () => Promise, options?: CompileQueryOptions); /** * Load the final (unnamed) Malloy query contained within this loaded `Model`. * * @return A `QueryMaterializer` capable of materializing the requested query, running it, * or loading further related objects. */ loadFinalQuery(options?: CompileQueryOptions): QueryMaterializer; /** * Load an unnamed query contained within this loaded `Model` by index. * * @param index The index of the query to load. * @return A `QueryMaterializer` capable of materializing the requested query, running it, * or loading further related objects. */ loadQueryByIndex(index: number, options?: CompileQueryOptions): QueryMaterializer; /** * Load a query contained within this loaded `Model` by its name. * * @param name The name of the query to load. * @return A `QueryMaterializer` capable of materializing the requested query, running it, * or loading further related objects. */ loadQueryByName(name: string, options?: CompileQueryOptions): QueryMaterializer; /** * Load a query against this loaded `Model` by its URL or contents. * * @param query The URL or contents of the query to load and (eventually) compile. * @return A `QueryMaterializer` capable of materializing the requested query, running it, * or loading further related objects. */ loadQuery(query: QueryString | QueryURL, options?: ParseOptions & CompileOptions & CompileQueryOptions): QueryMaterializer; /** * Extend a Malloy model by URL or contents. * * @param source The model URL or contents to load and (eventually) compile. * @return A `ModelMaterializer` capable of materializing the requested model, * or loading further related objects. */ extendModel(query: QueryString | QueryURL, options?: ParseOptions & CompileOptions & CompileQueryOptions): ModelMaterializer; search(sourceName: string, searchTerm: string, limit?: number, searchField?: string | undefined, eventStream?: EventStream): Promise; searchValueMap(sourceName: string, limit?: number, options?: ParseOptions): Promise; /** * Materialize the final query contained within this loaded `Model`. * * @return A promise to a prepared query. */ getFinalQuery(): Promise; /** * Materialize an unnamed query contained within this loaded `Model` by index. * * @param index The index of the query contained within this loaded `Model`. * @return A promise to a prepared query. */ getQueryByIndex(index: number): Promise; /** * Materialize a query contained within this loaded `Model` by name. * * @param name The name of the query contained within this loaded `Model`. * @return A promise to a prepared query. */ getQueryByName(name: string): Promise; /** * Materialize a query against this loaded `Model` by its URL or contents. * * @param query The URL or contents of a query document to compile. * @return A promise to a prepared query. */ getQuery(query: QueryString | QueryURL, options?: ParseOptions): Promise; _loadQueryFromQueryDef(query: InternalQuery, options?: CompileQueryOptions): QueryMaterializer; /** * Load an explore contained within this loaded `Model` by name. * * @param name The name of the explore contained within this loaded `Model`. * @return An `ExploreMaterializer` capable of materializing the requested explore, * or loading further related objects. */ loadExploreByName(name: string): ExploreMaterializer; /** * Materialize an explore contained within this loaded `Model` by its name. * * @param query The name of an explore within this loaded `Model`. * @return A promise to an explore. */ getExploreByName(name: string): Promise; /** * Compile and materialize this loaded `Model`. * * @return A promise to the compiled model that is loaded. */ getModel(): Promise; } /** * An object representing the task of loading a `Query`, capable of * materializing the query (via `getPreparedQuery()`) or extending the task to load * prepared results or run the query (via e.g. `loadPreparedResult()` or `run()`). */ export declare class QueryMaterializer extends FluentState { protected runtime: Runtime; private readonly compileQueryOptions; constructor(runtime: Runtime, materialize: () => Promise, options?: CompileQueryOptions); /** * Run this loaded `Query`. * * @return The query results from running this loaded query. */ run(options?: RunSQLOptions & CompileQueryOptions): Promise; runStream(options?: RunSQLOptions & CompileQueryOptions): AsyncIterableIterator; /** * Load the prepared result of this loaded query. * * @return A `PreparedResultMaterializer` capable of materializing the requested * prepared query or running it. */ loadPreparedResult(options?: CompileQueryOptions): PreparedResultMaterializer; /** * Materialize the prepared result of this loaded query. * * @return A promise of the prepared result of this loaded query. */ getPreparedResult(options?: CompileQueryOptions): Promise; /** * Materialize the SQL of this loaded query. * * @return A promise of the SQL string. */ getSQL(options?: CompileQueryOptions): Promise; /** * Materialize this loaded query. * * @return A promise of the `PreparedQuery`. */ getPreparedQuery(): Promise; /** * Estimates the cost of this loaded `Query`. * * @return The estimated cost of running this loaded query. */ estimateQueryCost(options?: CompileQueryOptions): Promise; get eventStream(): EventStream | undefined; } /** * An object representing the task of loading a `PreparedResult`, capable of * materializing the prepared result (via `getPreparedResult()`) or extending the task run * the query. */ export declare class PreparedResultMaterializer extends FluentState { /** * Run this prepared result. * * @return A promise to the query result data. */ run(options?: RunSQLOptions): Promise; runStream(options?: { rowLimit?: number; }): AsyncIterableIterator; /** * Materialize this loaded prepared result. * * @return A promise of a prepared result. */ getPreparedResult(): Promise; /** * Materialize the SQL of this loaded prepared result. * * @return A promise to the SQL string. */ getSQL(): Promise; } /** * An object representing the task of loading an `Explore`, capable of * materializing the explore (via `getExplore()`) or extending the task to produce * related queries. */ export declare class ExploreMaterializer extends FluentState { protected runtime: Runtime; private readonly replaceMaterializedReferences; constructor(runtime: Runtime, materialize: () => Promise, options?: CompileQueryOptions); /** * Load a query contained within this loaded explore. * * @param name The name of the query to load. * @return A `QueryMaterializer` capable of materializing the requested query, running it, * or loading further related objects. */ loadQueryByName(name: string, options?: CompileQueryOptions): QueryMaterializer; /** * Materialize a query contained within this loaded explore. * * @param name The name of the query to materialize. * @return A promise to the requested prepared query. */ getQueryByName(name: string): Promise; /** * Materialize this loaded explore. * * @return A promise to the compiled `Explore`. */ getExplore(): Promise; } export type ResultJSON = { queryResult: QueryResult; modelDef: ModelDef; }; /** * The result of running a Malloy query. * * A `Result` is a `PreparedResult` along with the data retrieved from running the query. */ export declare class Result extends PreparedResult { protected inner: QueryResult; constructor(queryResult: QueryResult, modelDef: ModelDef); get _queryResult(): QueryResult; /** * @return The result data. */ get data(): DataArray; get totalRows(): number; get runStats(): QueryRunStats | undefined; get profilingUrl(): string | undefined; toJSON(): ResultJSON; static fromJSON({ queryResult, modelDef }: ResultJSON): Result; } export type DataColumn = DataArray | DataRecord | DataString | DataBoolean | DataNumber | DataDate | DataTimestamp | DataNull | DataBytes | DataJSON | DataUnsupported; export type DataArrayOrRecord = DataArray | DataRecord; declare abstract class Data { readonly parent: DataArrayOrRecord | undefined; readonly parentRecord: DataRecord | undefined; protected _field: Field | Explore; constructor(field: Field | Explore, parent: DataArrayOrRecord | undefined, parentRecord: DataRecord | undefined); get field(): Field | Explore; abstract get value(): T; isString(): this is DataString; get string(): DataString; isBoolean(): this is DataBoolean; get boolean(): DataBoolean; isNumber(): this is DataNumber; get number(): DataNumber; isTimestamp(): this is DataTimestamp; get timestamp(): DataTimestamp; isDate(): this is DataDate; get date(): DataDate; isNull(): this is DataNull; isBytes(): this is DataBytes; get bytes(): DataBytes; isRecord(): this is DataRecord; get record(): DataRecord; isUnsupported(): this is DataUnsupported; get unsupported(): DataUnsupported; isArray(): this is DataArray; get array(): DataArray; isArrayOrRecord(): DataArrayOrRecord; isScalar(): this is ScalarData; } declare abstract class ScalarData extends Data { protected _value: T; protected _field: AtomicField; constructor(value: T, field: AtomicField, parent: DataArrayOrRecord | undefined, parentRecord: DataRecord | undefined); get value(): T; get field(): AtomicField; abstract get key(): string; isScalar(): this is ScalarData; abstract compareTo(other: ScalarData): number; } declare class DataString extends ScalarData { protected _field: StringField; constructor(value: string, field: StringField, parent: DataArrayOrRecord | undefined, parentRecord: DataRecord | undefined); get field(): StringField; get key(): string; compareTo(other: ScalarData): number; } declare class DataUnsupported extends ScalarData { protected _field: UnsupportedField; constructor(value: unknown, field: UnsupportedField, parent: DataArrayOrRecord | undefined, parentRecord: DataRecord | undefined); get field(): UnsupportedField; get key(): string; compareTo(_other: ScalarData): number; } declare class DataBoolean extends ScalarData { protected _field: BooleanField; constructor(value: boolean, field: BooleanField, parent: DataArrayOrRecord | undefined, parentRecord: DataRecord | undefined); get field(): BooleanField; get key(): string; compareTo(other: ScalarData): 0 | 1 | -1; } declare class DataJSON extends ScalarData { protected _field: JSONField; constructor(value: string, field: JSONField, parent: DataArrayOrRecord | undefined, parentRecord: DataRecord | undefined); get field(): JSONField; get key(): string; compareTo(other: ScalarData): 0 | 1 | -1; } declare class DataNumber extends ScalarData { protected _field: NumberField; constructor(value: number, field: NumberField, parent: DataArrayOrRecord | undefined, parentRecord: DataRecord | undefined); get field(): NumberField; get key(): string; compareTo(other: ScalarData): 0 | 1 | -1; } declare class DataTimestamp extends ScalarData { protected _field: TimestampField; constructor(value: Date, field: TimestampField, parent: DataArrayOrRecord | undefined, parentRecord: DataRecord | undefined); get value(): Date; get field(): TimestampField; get key(): string; compareTo(other: ScalarData): 0 | 1 | -1; } declare class DataDate extends ScalarData { protected _field: DateField; constructor(value: Date, field: DateField, parent: DataArrayOrRecord | undefined, parentRecord: DataRecord | undefined); get value(): Date; get field(): DateField; get key(): string; compareTo(other: ScalarData): 0 | 1 | -1; } declare class DataBytes extends ScalarData { get key(): string; compareTo(other: ScalarData): 0 | 1 | -1; } declare class DataNull extends Data { get value(): null; get key(): string; } export declare class DataArray extends Data implements Iterable { private queryData; protected _field: Explore; private rowCache; constructor(queryData: QueryData, field: Explore, parent: DataArrayOrRecord | undefined, parentRecord: DataRecord | undefined); /** * @return The `Explore` that describes the structure of this data. */ get field(): Explore; /** * @return The raw object form of the data. */ toObject(): QueryData; path(...path: (number | string)[]): DataColumn; row(index: number): DataRecord; get rowCount(): number; get value(): QueryData; [Symbol.iterator](): Iterator; inMemoryStream(): AsyncIterableIterator; } export declare class DataRecord extends Data<{ [fieldName: string]: DataColumn; }> { private queryDataRow; protected _field: Explore; readonly index: number | undefined; private cellCache; constructor(queryDataRow: QueryDataRow, index: number | undefined, field: Explore, parent: DataArrayOrRecord | undefined, parentRecord: DataRecord | undefined); toObject(): QueryDataRow; path(...path: (number | string)[]): DataColumn; cell(fieldOrName: string | Field): DataColumn; get value(): { [fieldName: string]: DataColumn; }; get field(): Explore; [Symbol.iterator](): Iterator; } export interface WriteStream { write: (text: string) => void; close: () => void; } export declare abstract class DataWriter { protected readonly stream: WriteStream; constructor(stream: WriteStream); abstract process(data: AsyncIterableIterator): Promise; } export declare class JSONWriter extends DataWriter { process(data: AsyncIterableIterator): Promise; } /** * CSV writer class that handles nested data. * This writer creates CSV using a DFS traversal of the result dataset. * Each trivial column value is converted to a CSV of 1x1 matrix and all the * columns are merged together to create a CSV that represents 1 QueryDataRow. * Since this follows DFS, each non trivial data is rendered into a NxM matrix * where N is the number of rows in the nested data and M is the number of * columns it has. * For any row with X number of columns, we end up with X number of NxM matrices * where the value of N,M pair may be different for each column. * We then merge the matrices so that we end up with a larger matrix of size * Max(N)xSum(M) by taking one row of csv from each matric at a time. For any * matrix with N): Promise; } interface CacheGetModelDefResponse { modelDef: ModelDef; invalidationKeys: { [url: string]: InvalidationKey; }; } export interface ModelCache { getModel(url: URL): Promise; setModel(url: URL, cachedModel: CachedModel): Promise; } export declare class CacheManager { private modelCache; private modelDependencies; private modelInvalidationKeys; constructor(modelCache: ModelCache); getCachedModelDef(urlReader: URLReader, url: string): Promise; setCachedModelDef(url: string, cachedModel: CachedModel): Promise; } export interface CachedModel { modelDef: ModelDef; invalidationKeys: { [url: string]: InvalidationKey; }; } export declare class InMemoryModelCache implements ModelCache { private readonly models; getModel(url: URL): Promise; setModel(url: URL, cachedModel: CachedModel): Promise; } export {};