@malloydata/malloy 0.0.195-dev241001233244 → 0.0.195-dev241003204819

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export type { LogMessage, TranslateResponse } from './lang';
7
7
  export { Model, Malloy, Runtime, AtomicFieldType, ConnectionRuntime, SingleConnectionRuntime, EmptyURLReader, InMemoryURLReader, FixedConnectionMap, MalloyError, JoinRelationship, SourceRelationship, DateTimeframe, TimestampTimeframe, PreparedResult, Result, QueryMaterializer, CSVWriter, JSONWriter, Parse, DataWriter, Explore, } from './malloy';
8
8
  export type { PreparedQuery, Field, AtomicField, ExploreField, QueryField, SortableField, DataArray, DataRecord, DataColumn, DataArrayOrRecord, Loggable, ModelMaterializer, DocumentTablePath, DocumentSymbol, ResultJSON, PreparedResultMaterializer, SQLBlockMaterializer, ExploreMaterializer, WriteStream, SerializedExplore, DateField, TimestampField, } from './malloy';
9
9
  export type { QueryOptionsReader, RunSQLOptions } from './run_sql_options';
10
- export type { ModelString, ModelURL, QueryString, QueryURL, URLReader, } from './runtime_types';
10
+ export type { EventStream, ModelString, ModelURL, QueryString, QueryURL, URLReader, } from './runtime_types';
11
11
  export type { Connection, ConnectionConfig, ConnectionFactory, ConnectionParameter, ConnectionParameterValue, ConnectionConfigSchema, FetchSchemaOptions, InfoConnection, LookupConnection, PersistSQLResults, PooledConnection, TestableConnection, StreamingConnection, } from './connection/types';
12
12
  export { toAsyncGenerator } from './connection_utils';
13
13
  export { type TagParse, Tag, type TagDict } from './tags';
@@ -1,4 +1,5 @@
1
1
  import { DocumentLocation, FieldValueType } from '../model/malloy_types';
2
+ import { EventStream } from '../runtime_types';
2
3
  export type LogSeverity = 'error' | 'warn' | 'debug';
3
4
  /**
4
5
  * Default severity is "error"
@@ -21,7 +22,9 @@ export interface MessageLogger {
21
22
  empty(): boolean;
22
23
  }
23
24
  export declare class BaseMessageLogger implements MessageLogger {
25
+ private readonly eventStream;
24
26
  private rawLog;
27
+ constructor(eventStream: EventStream | null);
25
28
  getLog(): LogMessage[];
26
29
  /**
27
30
  * Add a message to the log.
@@ -24,7 +24,8 @@
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.makeLogMessage = exports.MESSAGE_FORMATTERS = exports.BaseMessageLogger = void 0;
26
26
  class BaseMessageLogger {
27
- constructor() {
27
+ constructor(eventStream) {
28
+ this.eventStream = eventStream;
28
29
  this.rawLog = [];
29
30
  }
30
31
  getLog() {
@@ -34,7 +35,13 @@ class BaseMessageLogger {
34
35
  * Add a message to the log.
35
36
  */
36
37
  log(logMsg) {
38
+ var _a;
37
39
  this.rawLog.push(logMsg);
40
+ (_a = this.eventStream) === null || _a === void 0 ? void 0 : _a.emit(`translation-${logMsg.severity}`, {
41
+ code: logMsg.code,
42
+ data: logMsg.data,
43
+ message: logMsg.message,
44
+ });
38
45
  }
39
46
  reset() {
40
47
  this.rawLog.length = 0;
@@ -1,11 +1,12 @@
1
1
  import { ANTLRErrorListener, ParserRuleContext, Token } from 'antlr4ts';
2
2
  import { DocumentLocation, DocumentPosition, DocumentRange, DocumentReference, ImportLocation, ModelDef, NamedModelObject, Query, SQLBlockStructDef, StructDef } from '../model/malloy_types';
3
- import { BaseMessageLogger, LogMessage, LogMessageOptions, MessageCode, MessageLogger, MessageParameterType } from './parse-log';
3
+ import { LogMessage, LogMessageOptions, MessageCode, MessageLogger, MessageParameterType } from './parse-log';
4
4
  import { Zone, ZoneData } from './zone';
5
5
  import { ReferenceList } from './reference-list';
6
6
  import { ASTResponse, CompletionsResponse, DataRequestResponse, ProblemResponse, FatalResponse, FinalResponse, HelpContextResponse, MetadataResponse, ModelDataRequest, NeedURLData, TranslateResponse, ModelAnnotationResponse, TablePathResponse } from './translate-response';
7
7
  import { Tag } from '../tags';
8
8
  import { MalloyParseInfo } from './malloy-parse-info';
9
+ import { EventStream } from '../runtime_types';
9
10
  export type StepResponses = DataRequestResponse | ASTResponse | TranslateResponse | ParseResponse | MetadataResponse;
10
11
  /**
11
12
  * A Translation is a series of translation steps. Each step can depend
@@ -184,12 +185,13 @@ export declare class MalloyChildTranslator extends MalloyTranslation {
184
185
  * no need to call again, the translation is finished or error'd.
185
186
  */
186
187
  export declare class MalloyTranslator extends MalloyTranslation {
188
+ private readonly eventStream;
187
189
  schemaZone: Zone<StructDef>;
188
190
  importZone: Zone<string>;
189
191
  sqlQueryZone: Zone<SQLBlockStructDef>;
190
- logger: BaseMessageLogger;
192
+ logger: MessageLogger;
191
193
  readonly root: MalloyTranslator;
192
- constructor(rootURL: string, importURL?: string | null, preload?: ParseUpdate | null);
194
+ constructor(rootURL: string, importURL?: string | null, preload?: ParseUpdate | null, eventStream?: EventStream | null);
193
195
  update(dd: ParseUpdate): void;
194
196
  logError<T extends MessageCode>(code: T, parameters: MessageParameterType<T>, options?: Omit<LogMessageOptions, 'severity'>): T;
195
197
  }
@@ -806,13 +806,14 @@ exports.MalloyChildTranslator = MalloyChildTranslator;
806
806
  * no need to call again, the translation is finished or error'd.
807
807
  */
808
808
  class MalloyTranslator extends MalloyTranslation {
809
- constructor(rootURL, importURL = null, preload = null) {
809
+ constructor(rootURL, importURL = null, preload = null, eventStream = null) {
810
810
  super(rootURL, importURL);
811
+ this.eventStream = eventStream;
811
812
  this.schemaZone = new zone_1.Zone();
812
813
  this.importZone = new zone_1.Zone();
813
814
  this.sqlQueryZone = new zone_1.Zone();
814
- this.logger = new parse_log_1.BaseMessageLogger();
815
815
  this.root = this;
816
+ this.logger = new parse_log_1.BaseMessageLogger(eventStream);
816
817
  if (preload) {
817
818
  this.update(preload);
818
819
  }
@@ -6,6 +6,7 @@ import { MalloyChildTranslator, MalloyTranslator } from '../parse-malloy';
6
6
  import { DataRequestResponse, TranslateResponse } from '../translate-response';
7
7
  import { ExprValue } from '../ast/types/expr-value';
8
8
  import { LogSeverity, MessageCode, MessageParameterType } from '../parse-log';
9
+ import { EventStream } from '../../runtime_types';
9
10
  export declare function pretty(thing: any): string;
10
11
  export declare const aTableDef: StructDef;
11
12
  /**
@@ -30,7 +31,7 @@ export declare class TestTranslator extends MalloyTranslator {
30
31
  allDialectsEnabled: boolean;
31
32
  testRoot?: TestRoot;
32
33
  internalModel: ModelDef;
33
- constructor(testSrc: string, importBaseURL?: string | null, rootRule?: string, internalModel?: ModelDef);
34
+ constructor(testSrc: string, importBaseURL?: string | null, eventStream?: EventStream | null, rootRule?: string, internalModel?: ModelDef);
34
35
  translate(): TranslateResponse;
35
36
  addChild(url: string): void;
36
37
  ast(): MalloyElement | undefined;
@@ -204,8 +204,8 @@ class TestChildTranslator extends parse_malloy_1.MalloyChildTranslator {
204
204
  exports.TestChildTranslator = TestChildTranslator;
205
205
  const testURI = 'internal://test/langtests/root.malloy';
206
206
  class TestTranslator extends parse_malloy_1.MalloyTranslator {
207
- constructor(testSrc, importBaseURL = null, rootRule = 'malloyDocument', internalModel) {
208
- super(testURI, importBaseURL);
207
+ constructor(testSrc, importBaseURL = null, eventStream = null, rootRule = 'malloyDocument', internalModel) {
208
+ super(testURI, importBaseURL, null, eventStream);
209
209
  this.testSrc = testSrc;
210
210
  this.allDialectsEnabled = true;
211
211
  /*
@@ -387,7 +387,7 @@ exports.TestTranslator = TestTranslator;
387
387
  TestTranslator.inspectCompile = false;
388
388
  class BetaExpression extends TestTranslator {
389
389
  constructor(src) {
390
- super(src, null, 'justExpr');
390
+ super(src, null, null, 'justExpr');
391
391
  }
392
392
  testFS() {
393
393
  const aStruct = this.internalModel.contents['ab'];
@@ -493,7 +493,7 @@ function makeModelFunc(options) {
493
493
  return {
494
494
  ...ms,
495
495
  translator: new TestTranslator(((_a = options.prefix) !== null && _a !== void 0 ? _a : '') +
496
- (options.wrap ? options.wrap(ms.code) : ms.code), null, undefined, options === null || options === void 0 ? void 0 : options.model),
496
+ (options.wrap ? options.wrap(ms.code) : ms.code), null, null, undefined, options === null || options === void 0 ? void 0 : options.model),
497
497
  };
498
498
  };
499
499
  }
package/dist/malloy.d.ts CHANGED
@@ -2,8 +2,8 @@
2
2
  import { RunSQLOptions } from './run_sql_options';
3
3
  import { DocumentCompletion as DocumentCompletionDefinition, DocumentSymbol as DocumentSymbolDefinition, LogMessage, MalloyTranslator } from './lang';
4
4
  import { DocumentHelpContext } from './lang/parse-tree-walkers/document-help-context-walker';
5
- import { CompiledQuery, DocumentLocation, DocumentReference, FieldBooleanDef, FieldDateDef, FieldJSONDef, FieldNumberDef, FieldStringDef, FieldTimestampDef, FieldTypeDef, FilterCondition, Query as InternalQuery, ModelDef, DocumentPosition as ModelDocumentPosition, NamedQuery, QueryData, QueryDataRow, QueryResult, SQLBlock, SQLBlockSource, SQLBlockStructDef, SearchIndexResult, SearchValueMapResult, StructDef, TurtleDef, FeldNativeUnsupportedDef, QueryRunStats, ImportLocation, Annotation, QueryToMaterialize, PrepareResultOptions } from './model';
6
- import { ModelString, ModelURL, QueryString, QueryURL, URLReader } from './runtime_types';
5
+ import { CompiledQuery, DocumentLocation, DocumentReference, FieldBooleanDef, FieldDateDef, FieldJSONDef, FieldNumberDef, FieldStringDef, FieldTimestampDef, FieldTypeDef, FilterCondition, Query as InternalQuery, ModelDef, DocumentPosition as ModelDocumentPosition, NamedQuery, QueryData, QueryDataRow, QueryResult, SQLBlock, SQLBlockSource, SQLBlockStructDef, SearchIndexResult, SearchValueMapResult, StructDef, TurtleDef, FeldNativeUnsupportedDef, QueryRunStats, ImportLocation, Annotation, QueryToMaterialize } from './model';
6
+ import { EventStream, ModelString, ModelURL, QueryString, QueryURL, URLReader } from './runtime_types';
7
7
  import { Connection, InfoConnection, LookupConnection } from './connection/types';
8
8
  import { Tag, TagParse, TagParseSpec, Taggable } from './tags';
9
9
  import { Dialect } from './dialect';
@@ -18,15 +18,19 @@ export interface ParseOptions {
18
18
  importBaseURL?: URL;
19
19
  testEnvironment?: boolean;
20
20
  }
21
+ /** Options for how to run the Malloy semantic checker/translator */
21
22
  export interface CompileOptions {
22
23
  refreshSchemaCache?: boolean | number;
23
24
  noThrowOnError?: boolean;
24
25
  }
26
+ /** Options given to the Malloy compiler (QueryModel) */
27
+ interface CompileQueryOptions {
28
+ replaceMaterializedReferences?: boolean;
29
+ materializedTablePrefix?: string;
30
+ eventStream?: EventStream;
31
+ }
25
32
  export declare class Malloy {
26
33
  static get version(): string;
27
- private static _log;
28
- static get log(): Loggable;
29
- static setLogger(log: Loggable): void;
30
34
  private static _parse;
31
35
  /**
32
36
  * Parse a Malloy document by URL.
@@ -35,9 +39,10 @@ export declare class Malloy {
35
39
  * @param urlReader Object capable of fetching URL contents.
36
40
  * @return A (promise of a) `Parse` result.
37
41
  */
38
- static parse({ url, urlReader, options, }: {
42
+ static parse({ url, urlReader, eventStream, options, }: {
39
43
  url: URL;
40
44
  urlReader: URLReader;
45
+ eventStream?: EventStream;
41
46
  options?: ParseOptions;
42
47
  }): Promise<Parse>;
43
48
  /**
@@ -47,9 +52,10 @@ export declare class Malloy {
47
52
  * @param source The contents of the Malloy document to parse.
48
53
  * @return A `Parse` result.
49
54
  */
50
- static parse({ source, url, options, }: {
55
+ static parse({ source, url, eventStream, options, }: {
51
56
  url?: URL;
52
57
  source: string;
58
+ eventStream?: EventStream;
53
59
  options?: ParseOptions;
54
60
  }): Parse;
55
61
  /**
@@ -61,13 +67,14 @@ export declare class Malloy {
61
67
  * @param model A compiled model to build upon (optional).
62
68
  * @return A (promise of a) compiled `Model`.
63
69
  */
64
- static compile({ urlReader, connections, parse, model, refreshSchemaCache, noThrowOnError, replaceMaterializedReferences, materializedTablePrefix, }: {
70
+ static compile({ urlReader, connections, parse, model, refreshSchemaCache, noThrowOnError, eventStream, replaceMaterializedReferences, materializedTablePrefix, }: {
65
71
  urlReader: URLReader;
66
72
  connections: LookupConnection<InfoConnection>;
67
73
  parse: Parse;
68
74
  model?: Model;
69
- } & CompileOptions & PrepareResultOptions): Promise<Model>;
70
- static compileSQLBlock(partialModel: ModelDef | undefined, toCompile: SQLBlockSource, options?: PrepareResultOptions): SQLBlock;
75
+ replaceMaterializedReferences?: boolean;
76
+ } & CompileOptions & CompileQueryOptions): Promise<Model>;
77
+ static compileSQLBlock(partialModel: ModelDef | undefined, toCompile: SQLBlockSource, options?: CompileQueryOptions): SQLBlock;
71
78
  /**
72
79
  * Run a fully-prepared query.
73
80
  *
@@ -263,7 +270,13 @@ export declare class PreparedQuery implements Taggable {
263
270
  * @return A fully-prepared query (which contains the generated SQL).
264
271
  */
265
272
  get preparedResult(): PreparedResult;
266
- getPreparedResult(options?: PrepareResultOptions): PreparedResult;
273
+ /**
274
+ * Generate the SQL for this query.
275
+ *
276
+ * @return A fully-prepared query (which contains the generated SQL).
277
+ * @param options.eventStream An event stream to use when compiling the SQL
278
+ */
279
+ getPreparedResult(options?: CompileQueryOptions): PreparedResult;
267
280
  get dialect(): string;
268
281
  /**
269
282
  * Get the flattened version of a query -- one that does not have a `pipeHead`.
@@ -736,11 +749,12 @@ export declare class Runtime {
736
749
  isTestRuntime: boolean;
737
750
  private _urlReader;
738
751
  private _connections;
752
+ private _eventStream;
739
753
  constructor(runtime: LookupConnection<Connection> & URLReader);
740
- constructor(urls: URLReader, connections: LookupConnection<Connection>);
741
- constructor(urls: URLReader, connection: Connection);
742
- constructor(connection: Connection);
743
- constructor(connections: LookupConnection<Connection>);
754
+ constructor(urls: URLReader, connections: LookupConnection<Connection>, eventStream?: EventStream);
755
+ constructor(urls: URLReader, connection: Connection, eventStream?: EventStream);
756
+ constructor(connection: Connection, eventStream?: EventStream);
757
+ constructor(connections: LookupConnection<Connection>, eventStream?: EventStream);
744
758
  /**
745
759
  * @return The `URLReader` for this runtime instance.
746
760
  */
@@ -749,6 +763,10 @@ export declare class Runtime {
749
763
  * @return The `LookupConnection<Connection>` for this runtime instance.
750
764
  */
751
765
  get connections(): LookupConnection<Connection>;
766
+ /**
767
+ * @return The `EventStream` for this runtime instance.
768
+ */
769
+ get eventStream(): EventStream | undefined;
752
770
  /**
753
771
  * Load a Malloy model by URL or contents.
754
772
  *
@@ -756,8 +774,8 @@ export declare class Runtime {
756
774
  * @return A `ModelMaterializer` capable of materializing the requested model,
757
775
  * or loading further related objects.
758
776
  */
759
- loadModel(source: ModelURL | ModelString, options?: ParseOptions & CompileOptions & PrepareResultOptions): ModelMaterializer;
760
- _loadModelFromModelDef(modelDef: ModelDef, options?: PrepareResultOptions): ModelMaterializer;
777
+ loadModel(source: ModelURL | ModelString, options?: ParseOptions & CompileOptions & CompileQueryOptions): ModelMaterializer;
778
+ _loadModelFromModelDef(modelDef: ModelDef, options?: CompileQueryOptions): ModelMaterializer;
761
779
  /**
762
780
  * Load a Malloy query by URL or contents.
763
781
  *
@@ -765,7 +783,7 @@ export declare class Runtime {
765
783
  * @return A `QueryMaterializer` capable of materializing the requested query, running it,
766
784
  * or loading further related objects.
767
785
  */
768
- loadQuery(query: QueryURL | QueryString, options?: ParseOptions & CompileOptions & PrepareResultOptions): QueryMaterializer;
786
+ loadQuery(query: QueryURL | QueryString, options?: ParseOptions & CompileOptions & CompileQueryOptions): QueryMaterializer;
769
787
  /**
770
788
  * Load a Malloy query by the URL or contents of a Malloy model document
771
789
  * and the index of an unnamed query contained in the model.
@@ -775,7 +793,7 @@ export declare class Runtime {
775
793
  * @return A `QueryMaterializer` capable of materializing the requested query, running it,
776
794
  * or loading further related objects.
777
795
  */
778
- loadQueryByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions & CompileOptions & PrepareResultOptions): QueryMaterializer;
796
+ loadQueryByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions & CompileOptions & CompileQueryOptions): QueryMaterializer;
779
797
  /**
780
798
  * Load a Malloy query by the URL or contents of a Malloy model document
781
799
  * and the name of a query contained in the model.
@@ -785,7 +803,7 @@ export declare class Runtime {
785
803
  * @return A `QueryMaterializer` capable of materializing the requested query, running it,
786
804
  * or loading further related objects.
787
805
  */
788
- loadQueryByName(model: ModelURL | ModelString, name: string, options?: ParseOptions & CompileOptions & PrepareResultOptions): QueryMaterializer;
806
+ loadQueryByName(model: ModelURL | ModelString, name: string, options?: ParseOptions & CompileOptions & CompileQueryOptions): QueryMaterializer;
789
807
  /**
790
808
  * Load a SQL block by the URL or contents of a Malloy model document
791
809
  * and the name of a query contained in the model.
@@ -795,7 +813,7 @@ export declare class Runtime {
795
813
  * @return A `SQLBlockMaterializer` capable of materializing the requested query, running it,
796
814
  * or loading further related objects.
797
815
  */
798
- loadSQLBlockByName(model: ModelURL | ModelString, name: string, options?: ParseOptions & CompileOptions & PrepareResultOptions): SQLBlockMaterializer;
816
+ loadSQLBlockByName(model: ModelURL | ModelString, name: string, options?: ParseOptions & CompileOptions & CompileQueryOptions): SQLBlockMaterializer;
799
817
  /**
800
818
  * Load a SQL block by the URL or contents of a Malloy model document
801
819
  * and the name of a query contained in the model.
@@ -864,8 +882,10 @@ export declare class ConnectionRuntime extends Runtime {
864
882
  }
865
883
  export declare class SingleConnectionRuntime<T extends Connection = Connection> extends Runtime {
866
884
  readonly connection: T;
867
- constructor(urls: URLReader, connection: T);
885
+ constructor(urlReader: URLReader, connection: T);
868
886
  constructor(connection: T);
887
+ constructor(connection: T, eventStream: EventStream);
888
+ constructor(urlReader: URLReader, connection: T, eventStream: EventStream);
869
889
  get supportsNesting(): boolean;
870
890
  quote(column: string): string;
871
891
  get dialect(): Dialect;
@@ -878,10 +898,11 @@ declare class FluentState<T> {
878
898
  constructor(runtime: Runtime, materialize: () => Promise<T>);
879
899
  protected materialize(): Promise<T>;
880
900
  protected rematerialize(): Promise<T>;
881
- protected makeQueryMaterializer(materialize: () => Promise<PreparedQuery>, options?: PrepareResultOptions): QueryMaterializer;
882
- protected makeExploreMaterializer(materialize: () => Promise<Explore>, options?: PrepareResultOptions): ExploreMaterializer;
901
+ protected makeQueryMaterializer(materialize: () => Promise<PreparedQuery>, options?: CompileQueryOptions): QueryMaterializer;
902
+ protected makeExploreMaterializer(materialize: () => Promise<Explore>, options?: CompileQueryOptions): ExploreMaterializer;
883
903
  protected makePreparedResultMaterializer(materialize: () => Promise<PreparedResult>): PreparedResultMaterializer;
884
904
  protected makeSQLBlockMaterializer(materialize: () => Promise<SQLBlockStructDef>): SQLBlockMaterializer;
905
+ get eventStream(): EventStream | undefined;
885
906
  }
886
907
  /**
887
908
  * An object representing the task of loading a `Model`, capable of
@@ -890,15 +911,15 @@ declare class FluentState<T> {
890
911
  */
891
912
  export declare class ModelMaterializer extends FluentState<Model> {
892
913
  protected runtime: Runtime;
893
- private readonly prepareResultOptions;
894
- constructor(runtime: Runtime, materialize: () => Promise<Model>, options?: PrepareResultOptions);
914
+ private readonly compileQueryOptions;
915
+ constructor(runtime: Runtime, materialize: () => Promise<Model>, options?: CompileQueryOptions);
895
916
  /**
896
917
  * Load the final (unnamed) Malloy query contained within this loaded `Model`.
897
918
  *
898
919
  * @return A `QueryMaterializer` capable of materializing the requested query, running it,
899
920
  * or loading further related objects.
900
921
  */
901
- loadFinalQuery(options?: PrepareResultOptions): QueryMaterializer;
922
+ loadFinalQuery(options?: CompileQueryOptions): QueryMaterializer;
902
923
  /**
903
924
  * Load an unnamed query contained within this loaded `Model` by index.
904
925
  *
@@ -906,7 +927,7 @@ export declare class ModelMaterializer extends FluentState<Model> {
906
927
  * @return A `QueryMaterializer` capable of materializing the requested query, running it,
907
928
  * or loading further related objects.
908
929
  */
909
- loadQueryByIndex(index: number, options?: PrepareResultOptions): QueryMaterializer;
930
+ loadQueryByIndex(index: number, options?: CompileQueryOptions): QueryMaterializer;
910
931
  /**
911
932
  * Load a query contained within this loaded `Model` by its name.
912
933
  *
@@ -914,7 +935,7 @@ export declare class ModelMaterializer extends FluentState<Model> {
914
935
  * @return A `QueryMaterializer` capable of materializing the requested query, running it,
915
936
  * or loading further related objects.
916
937
  */
917
- loadQueryByName(name: string, options?: PrepareResultOptions): QueryMaterializer;
938
+ loadQueryByName(name: string, options?: CompileQueryOptions): QueryMaterializer;
918
939
  /**
919
940
  * Load a query against this loaded `Model` by its URL or contents.
920
941
  *
@@ -922,7 +943,7 @@ export declare class ModelMaterializer extends FluentState<Model> {
922
943
  * @return A `QueryMaterializer` capable of materializing the requested query, running it,
923
944
  * or loading further related objects.
924
945
  */
925
- loadQuery(query: QueryString | QueryURL, options?: ParseOptions & CompileOptions & PrepareResultOptions): QueryMaterializer;
946
+ loadQuery(query: QueryString | QueryURL, options?: ParseOptions & CompileOptions & CompileQueryOptions): QueryMaterializer;
926
947
  /**
927
948
  * Extend a Malloy model by URL or contents.
928
949
  *
@@ -930,8 +951,8 @@ export declare class ModelMaterializer extends FluentState<Model> {
930
951
  * @return A `ModelMaterializer` capable of materializing the requested model,
931
952
  * or loading further related objects.
932
953
  */
933
- extendModel(query: QueryString | QueryURL, options?: ParseOptions & CompileOptions & PrepareResultOptions): ModelMaterializer;
934
- search(sourceName: string, searchTerm: string, limit?: number, searchField?: string | undefined): Promise<SearchIndexResult[] | undefined>;
954
+ extendModel(query: QueryString | QueryURL, options?: ParseOptions & CompileOptions & CompileQueryOptions): ModelMaterializer;
955
+ search(sourceName: string, searchTerm: string, limit?: number, searchField?: string | undefined, eventStream?: EventStream): Promise<SearchIndexResult[] | undefined>;
935
956
  searchValueMap(sourceName: string, limit?: number, options?: ParseOptions): Promise<SearchValueMapResult[] | undefined>;
936
957
  /**
937
958
  * Load a SQL Block by name.
@@ -994,7 +1015,7 @@ export declare class ModelMaterializer extends FluentState<Model> {
994
1015
  * TODO feature-sql-block Should named SQL blocks be indexable? This is not the way unnamed queries work.
995
1016
  */
996
1017
  getSQLBlockByIndex(index: number): Promise<SQLBlockStructDef>;
997
- _loadQueryFromQueryDef(query: InternalQuery, options?: PrepareResultOptions): QueryMaterializer;
1018
+ _loadQueryFromQueryDef(query: InternalQuery, options?: CompileQueryOptions): QueryMaterializer;
998
1019
  /**
999
1020
  * Load an explore contained within this loaded `Model` by name.
1000
1021
  *
@@ -1024,34 +1045,34 @@ export declare class ModelMaterializer extends FluentState<Model> {
1024
1045
  */
1025
1046
  export declare class QueryMaterializer extends FluentState<PreparedQuery> {
1026
1047
  protected runtime: Runtime;
1027
- private readonly prepareResultOptions;
1028
- constructor(runtime: Runtime, materialize: () => Promise<PreparedQuery>, options?: PrepareResultOptions);
1048
+ private readonly compileQueryOptions;
1049
+ constructor(runtime: Runtime, materialize: () => Promise<PreparedQuery>, options?: CompileQueryOptions);
1029
1050
  /**
1030
1051
  * Run this loaded `Query`.
1031
1052
  *
1032
1053
  * @return The query results from running this loaded query.
1033
1054
  */
1034
- run(options?: RunSQLOptions & PrepareResultOptions): Promise<Result>;
1035
- runStream(options?: RunSQLOptions & PrepareResultOptions): AsyncIterableIterator<DataRecord>;
1055
+ run(options?: RunSQLOptions & CompileQueryOptions): Promise<Result>;
1056
+ runStream(options?: RunSQLOptions & CompileQueryOptions): AsyncIterableIterator<DataRecord>;
1036
1057
  /**
1037
1058
  * Load the prepared result of this loaded query.
1038
1059
  *
1039
1060
  * @return A `PreparedResultMaterializer` capable of materializing the requested
1040
1061
  * prepared query or running it.
1041
1062
  */
1042
- loadPreparedResult(options?: PrepareResultOptions): PreparedResultMaterializer;
1063
+ loadPreparedResult(options?: CompileQueryOptions): PreparedResultMaterializer;
1043
1064
  /**
1044
1065
  * Materialize the prepared result of this loaded query.
1045
1066
  *
1046
1067
  * @return A promise of the prepared result of this loaded query.
1047
1068
  */
1048
- getPreparedResult(options?: PrepareResultOptions): Promise<PreparedResult>;
1069
+ getPreparedResult(options?: CompileQueryOptions): Promise<PreparedResult>;
1049
1070
  /**
1050
1071
  * Materialize the SQL of this loaded query.
1051
1072
  *
1052
1073
  * @return A promise of the SQL string.
1053
1074
  */
1054
- getSQL(options?: PrepareResultOptions): Promise<string>;
1075
+ getSQL(options?: CompileQueryOptions): Promise<string>;
1055
1076
  /**
1056
1077
  * Materialize this loaded query.
1057
1078
  *
@@ -1063,7 +1084,7 @@ export declare class QueryMaterializer extends FluentState<PreparedQuery> {
1063
1084
  *
1064
1085
  * @return The estimated cost of running this loaded query.
1065
1086
  */
1066
- estimateQueryCost(options?: PrepareResultOptions): Promise<QueryRunStats>;
1087
+ estimateQueryCost(options?: CompileQueryOptions): Promise<QueryRunStats>;
1067
1088
  }
1068
1089
  /**
1069
1090
  * An object representing the task of loading a `PreparedResult`, capable of
@@ -1130,7 +1151,7 @@ export declare class SQLBlockMaterializer extends FluentState<SQLBlockStructDef>
1130
1151
  export declare class ExploreMaterializer extends FluentState<Explore> {
1131
1152
  protected runtime: Runtime;
1132
1153
  private readonly replaceMaterializedReferences;
1133
- constructor(runtime: Runtime, materialize: () => Promise<Explore>, options?: PrepareResultOptions);
1154
+ constructor(runtime: Runtime, materialize: () => Promise<Explore>, options?: CompileQueryOptions);
1134
1155
  /**
1135
1156
  * Load a query contained within this loaded explore.
1136
1157
  *
@@ -1138,7 +1159,7 @@ export declare class ExploreMaterializer extends FluentState<Explore> {
1138
1159
  * @return A `QueryMaterializer` capable of materializing the requested query, running it,
1139
1160
  * or loading further related objects.
1140
1161
  */
1141
- loadQueryByName(name: string, options?: PrepareResultOptions): QueryMaterializer;
1162
+ loadQueryByName(name: string, options?: CompileQueryOptions): QueryMaterializer;
1142
1163
  /**
1143
1164
  * Materialize a query contained within this loaded explore.
1144
1165
  *
package/dist/malloy.js CHANGED
@@ -33,13 +33,7 @@ class Malloy {
33
33
  static get version() {
34
34
  return '0.0.1';
35
35
  }
36
- static get log() {
37
- return Malloy._log || console;
38
- }
39
- static setLogger(log) {
40
- Malloy._log = log;
41
- }
42
- static _parse(source, url, options) {
36
+ static _parse(source, url, eventStream, options) {
43
37
  if (url === undefined) {
44
38
  url = new URL('internal://internal.malloy');
45
39
  }
@@ -49,15 +43,15 @@ class Malloy {
49
43
  }
50
44
  const translator = new lang_1.MalloyTranslator(url.toString(), importBaseURL.toString(), {
51
45
  urls: { [url.toString()]: source },
52
- });
46
+ }, eventStream);
53
47
  if (options === null || options === void 0 ? void 0 : options.testEnvironment) {
54
48
  translator.allDialectsEnabled = true;
55
49
  }
56
50
  return new Parse(translator);
57
51
  }
58
- static parse({ url, urlReader, source, options, }) {
52
+ static parse({ url, urlReader, source, eventStream, options, }) {
59
53
  if (source !== undefined) {
60
- return Malloy._parse(source, url, options);
54
+ return Malloy._parse(source, url, eventStream, options);
61
55
  }
62
56
  else {
63
57
  if (urlReader === undefined) {
@@ -67,7 +61,7 @@ class Malloy {
67
61
  throw new Error('Internal Error: url is required if source not present.');
68
62
  }
69
63
  return urlReader.readURL(url).then(source => {
70
- return Malloy._parse(source, url, options);
64
+ return Malloy._parse(source, url, eventStream, options);
71
65
  });
72
66
  }
73
67
  }
@@ -80,7 +74,7 @@ class Malloy {
80
74
  * @param model A compiled model to build upon (optional).
81
75
  * @return A (promise of a) compiled `Model`.
82
76
  */
83
- static async compile({ urlReader, connections, parse, model, refreshSchemaCache, noThrowOnError, replaceMaterializedReferences, materializedTablePrefix, }) {
77
+ static async compile({ urlReader, connections, parse, model, refreshSchemaCache, noThrowOnError, eventStream, replaceMaterializedReferences, materializedTablePrefix, }) {
84
78
  var _a, _b, _c, _d;
85
79
  let refreshTimestamp;
86
80
  if (refreshSchemaCache) {
@@ -177,7 +171,11 @@ class Malloy {
177
171
  const connectionName = toCompile.connection;
178
172
  try {
179
173
  const conn = await connections.lookupConnection(connectionName);
180
- const expanded = Malloy.compileSQLBlock(result.partialModel, toCompile, { replaceMaterializedReferences, materializedTablePrefix });
174
+ const expanded = Malloy.compileSQLBlock(result.partialModel, toCompile, {
175
+ replaceMaterializedReferences,
176
+ materializedTablePrefix,
177
+ eventStream,
178
+ });
181
179
  const resolved = await conn.fetchSchemaForSQLBlock(expanded, {
182
180
  refreshTimestamp,
183
181
  modelAnnotation,
@@ -219,7 +217,7 @@ class Malloy {
219
217
  if (!partialModel) {
220
218
  throw new Error('Internal error: Partial model missing when compiling SQL block');
221
219
  }
222
- queryModel = new model_1.QueryModel(partialModel);
220
+ queryModel = new model_1.QueryModel(partialModel, options === null || options === void 0 ? void 0 : options.eventStream);
223
221
  }
224
222
  const compiledSql = queryModel.compileQuery(segment, options, false).sql;
225
223
  selectStr += parenAlready ? compiledSql : `(${compiledSql})`;
@@ -526,8 +524,14 @@ class PreparedQuery {
526
524
  get preparedResult() {
527
525
  return this.getPreparedResult();
528
526
  }
527
+ /**
528
+ * Generate the SQL for this query.
529
+ *
530
+ * @return A fully-prepared query (which contains the generated SQL).
531
+ * @param options.eventStream An event stream to use when compiling the SQL
532
+ */
529
533
  getPreparedResult(options) {
530
- const queryModel = new model_1.QueryModel(this._modelDef);
534
+ const queryModel = new model_1.QueryModel(this._modelDef, options === null || options === void 0 ? void 0 : options.eventStream);
531
535
  const translatedQuery = queryModel.compileQuery(this._query, options);
532
536
  return new PreparedResult({
533
537
  ...translatedQuery,
@@ -1560,13 +1564,20 @@ class Runtime {
1560
1564
  this.isTestRuntime = false;
1561
1565
  let urlReader;
1562
1566
  let connections;
1567
+ let eventStream;
1563
1568
  for (const arg of args) {
1564
- if (isURLReader(arg)) {
1569
+ if (arg === undefined) {
1570
+ continue;
1571
+ }
1572
+ else if (isURLReader(arg)) {
1565
1573
  urlReader = arg;
1566
1574
  }
1567
1575
  else if (isLookupConnection(arg)) {
1568
1576
  connections = arg;
1569
1577
  }
1578
+ else if (isEventStream(arg)) {
1579
+ eventStream = arg;
1580
+ }
1570
1581
  else {
1571
1582
  connections = {
1572
1583
  lookupConnection: () => Promise.resolve(arg),
@@ -1581,6 +1592,7 @@ class Runtime {
1581
1592
  }
1582
1593
  this._urlReader = urlReader;
1583
1594
  this._connections = connections;
1595
+ this._eventStream = eventStream;
1584
1596
  }
1585
1597
  /**
1586
1598
  * @return The `URLReader` for this runtime instance.
@@ -1594,6 +1606,12 @@ class Runtime {
1594
1606
  get connections() {
1595
1607
  return this._connections;
1596
1608
  }
1609
+ /**
1610
+ * @return The `EventStream` for this runtime instance.
1611
+ */
1612
+ get eventStream() {
1613
+ return this._eventStream;
1614
+ }
1597
1615
  /**
1598
1616
  * Load a Malloy model by URL or contents.
1599
1617
  *
@@ -1616,10 +1634,12 @@ class Runtime {
1616
1634
  ? await Malloy.parse({
1617
1635
  url: source,
1618
1636
  urlReader: this.urlReader,
1637
+ eventStream: this.eventStream,
1619
1638
  options,
1620
1639
  })
1621
1640
  : Malloy.parse({
1622
1641
  source,
1642
+ eventStream: this.eventStream,
1623
1643
  options,
1624
1644
  });
1625
1645
  return Malloy.compile({
@@ -1628,6 +1648,7 @@ class Runtime {
1628
1648
  parse,
1629
1649
  refreshSchemaCache,
1630
1650
  noThrowOnError,
1651
+ eventStream: this.eventStream,
1631
1652
  replaceMaterializedReferences: options === null || options === void 0 ? void 0 : options.replaceMaterializedReferences,
1632
1653
  materializedTablePrefix: options === null || options === void 0 ? void 0 : options.materializedTablePrefix,
1633
1654
  });
@@ -1781,17 +1802,26 @@ class ConnectionRuntime extends Runtime {
1781
1802
  }
1782
1803
  exports.ConnectionRuntime = ConnectionRuntime;
1783
1804
  class SingleConnectionRuntime extends Runtime {
1784
- constructor(urlsOrConnections, maybeConnections) {
1785
- if (maybeConnections === undefined) {
1786
- const connection = urlsOrConnections;
1787
- super(connection);
1788
- this.connection = connection;
1805
+ constructor(...params) {
1806
+ let urlReader;
1807
+ let connection;
1808
+ let eventStream;
1809
+ for (const param of params) {
1810
+ if (isURLReader(param)) {
1811
+ urlReader = param;
1812
+ }
1813
+ if (isConnection(param)) {
1814
+ connection = param;
1815
+ }
1816
+ if (isEventStream(param)) {
1817
+ eventStream = param;
1818
+ }
1789
1819
  }
1790
- else {
1791
- const connection = maybeConnections;
1792
- super(urlsOrConnections, connection);
1793
- this.connection = connection;
1820
+ if (connection === undefined) {
1821
+ throw new Error('Expected connection to be passed into SingleConnectionRuntime');
1794
1822
  }
1823
+ super(urlReader, connection, eventStream);
1824
+ this.connection = connection;
1795
1825
  }
1796
1826
  get supportsNesting() {
1797
1827
  return (0, dialect_1.getDialect)(this.connection.dialectName).supportsNesting;
@@ -1835,6 +1865,9 @@ class FluentState {
1835
1865
  makeSQLBlockMaterializer(materialize) {
1836
1866
  return new SQLBlockMaterializer(this.runtime, materialize);
1837
1867
  }
1868
+ get eventStream() {
1869
+ return this.runtime.eventStream;
1870
+ }
1838
1871
  }
1839
1872
  /**
1840
1873
  * An object representing the task of loading a `Model`, capable of
@@ -1845,7 +1878,7 @@ class ModelMaterializer extends FluentState {
1845
1878
  constructor(runtime, materialize, options) {
1846
1879
  super(runtime, materialize);
1847
1880
  this.runtime = runtime;
1848
- this.prepareResultOptions = options;
1881
+ this.compileQueryOptions = options;
1849
1882
  }
1850
1883
  /**
1851
1884
  * Load the final (unnamed) Malloy query contained within this loaded `Model`.
@@ -1857,7 +1890,7 @@ class ModelMaterializer extends FluentState {
1857
1890
  return this.makeQueryMaterializer(async () => {
1858
1891
  return (await this.materialize()).getPreparedQuery();
1859
1892
  }, {
1860
- ...this.prepareResultOptions,
1893
+ ...this.compileQueryOptions,
1861
1894
  ...options,
1862
1895
  });
1863
1896
  }
@@ -1872,7 +1905,7 @@ class ModelMaterializer extends FluentState {
1872
1905
  return this.makeQueryMaterializer(async () => {
1873
1906
  return (await this.materialize()).getPreparedQueryByIndex(index);
1874
1907
  }, {
1875
- ...this.prepareResultOptions,
1908
+ ...this.compileQueryOptions,
1876
1909
  ...options,
1877
1910
  });
1878
1911
  }
@@ -1887,7 +1920,7 @@ class ModelMaterializer extends FluentState {
1887
1920
  return this.makeQueryMaterializer(async () => {
1888
1921
  return (await this.materialize()).getPreparedQueryByName(name);
1889
1922
  }, {
1890
- ...this.prepareResultOptions,
1923
+ ...this.compileQueryOptions,
1891
1924
  ...options,
1892
1925
  });
1893
1926
  }
@@ -1929,7 +1962,7 @@ class ModelMaterializer extends FluentState {
1929
1962
  model,
1930
1963
  refreshSchemaCache,
1931
1964
  noThrowOnError,
1932
- ...this.prepareResultOptions,
1965
+ ...this.compileQueryOptions,
1933
1966
  });
1934
1967
  return queryModel.preparedQuery;
1935
1968
  });
@@ -1971,14 +2004,14 @@ class ModelMaterializer extends FluentState {
1971
2004
  model,
1972
2005
  refreshSchemaCache: options === null || options === void 0 ? void 0 : options.refreshSchemaCache,
1973
2006
  noThrowOnError: options === null || options === void 0 ? void 0 : options.noThrowOnError,
1974
- ...this.prepareResultOptions,
2007
+ ...this.compileQueryOptions,
1975
2008
  });
1976
2009
  return queryModel;
1977
2010
  }, options);
1978
2011
  }
1979
- async search(sourceName, searchTerm, limit = 1000, searchField = undefined) {
2012
+ async search(sourceName, searchTerm, limit = 1000, searchField = undefined, eventStream) {
1980
2013
  const model = await this.materialize();
1981
- const queryModel = new model_1.QueryModel(model._modelDef);
2014
+ const queryModel = new model_1.QueryModel(model._modelDef, eventStream);
1982
2015
  const schema = model.getExploreByName(sourceName).structDef;
1983
2016
  if (schema.structRelationship.type !== 'basetable') {
1984
2017
  throw new Error("Expected schema's structRelationship type to be 'basetable'.");
@@ -2107,7 +2140,7 @@ class ModelMaterializer extends FluentState {
2107
2140
  const model = await this.materialize();
2108
2141
  return new PreparedQuery(query, model._modelDef, model.problems);
2109
2142
  }, {
2110
- ...this.prepareResultOptions,
2143
+ ...this.compileQueryOptions,
2111
2144
  ...options,
2112
2145
  });
2113
2146
  }
@@ -2121,7 +2154,7 @@ class ModelMaterializer extends FluentState {
2121
2154
  loadExploreByName(name) {
2122
2155
  return this.makeExploreMaterializer(async () => {
2123
2156
  return (await this.materialize()).getExploreByName(name);
2124
- }, this.prepareResultOptions);
2157
+ }, this.compileQueryOptions);
2125
2158
  }
2126
2159
  /**
2127
2160
  * Materialize an explore contained within this loaded `Model` by its name.
@@ -2151,7 +2184,7 @@ class QueryMaterializer extends FluentState {
2151
2184
  constructor(runtime, materialize, options) {
2152
2185
  super(runtime, materialize);
2153
2186
  this.runtime = runtime;
2154
- this.prepareResultOptions = options;
2187
+ this.compileQueryOptions = options;
2155
2188
  }
2156
2189
  /**
2157
2190
  * Run this loaded `Query`.
@@ -2160,18 +2193,12 @@ class QueryMaterializer extends FluentState {
2160
2193
  */
2161
2194
  async run(options) {
2162
2195
  const connections = this.runtime.connections;
2163
- const preparedResult = await this.getPreparedResult({
2164
- ...this.prepareResultOptions,
2165
- ...options,
2166
- });
2196
+ const preparedResult = await this.getPreparedResult(options);
2167
2197
  const finalOptions = runSQLOptionsWithAnnotations(preparedResult, options);
2168
2198
  return Malloy.run({ connections, preparedResult, options: finalOptions });
2169
2199
  }
2170
2200
  async *runStream(options) {
2171
- const preparedResult = await this.getPreparedResult({
2172
- ...this.prepareResultOptions,
2173
- ...options,
2174
- });
2201
+ const preparedResult = await this.getPreparedResult(options);
2175
2202
  const connections = this.runtime.connections;
2176
2203
  const finalOptions = runSQLOptionsWithAnnotations(preparedResult, options);
2177
2204
  const stream = Malloy.runStream({
@@ -2192,7 +2219,8 @@ class QueryMaterializer extends FluentState {
2192
2219
  loadPreparedResult(options) {
2193
2220
  return this.makePreparedResultMaterializer(async () => {
2194
2221
  return (await this.materialize()).getPreparedResult({
2195
- ...this.prepareResultOptions,
2222
+ eventStream: this.eventStream,
2223
+ ...this.compileQueryOptions,
2196
2224
  ...options,
2197
2225
  });
2198
2226
  });
@@ -2203,10 +2231,7 @@ class QueryMaterializer extends FluentState {
2203
2231
  * @return A promise of the prepared result of this loaded query.
2204
2232
  */
2205
2233
  getPreparedResult(options) {
2206
- return this.loadPreparedResult({
2207
- ...this.prepareResultOptions,
2208
- ...options,
2209
- }).getPreparedResult();
2234
+ return this.loadPreparedResult(options).getPreparedResult();
2210
2235
  }
2211
2236
  /**
2212
2237
  * Materialize the SQL of this loaded query.
@@ -2214,10 +2239,7 @@ class QueryMaterializer extends FluentState {
2214
2239
  * @return A promise of the SQL string.
2215
2240
  */
2216
2241
  async getSQL(options) {
2217
- return (await this.getPreparedResult({
2218
- ...this.prepareResultOptions,
2219
- ...options,
2220
- })).sql;
2242
+ return (await this.getPreparedResult(options)).sql;
2221
2243
  }
2222
2244
  /**
2223
2245
  * Materialize this loaded query.
@@ -2234,10 +2256,7 @@ class QueryMaterializer extends FluentState {
2234
2256
  */
2235
2257
  async estimateQueryCost(options) {
2236
2258
  const connections = this.runtime.connections;
2237
- const preparedResult = await this.getPreparedResult({
2238
- ...this.prepareResultOptions,
2239
- ...options,
2240
- });
2259
+ const preparedResult = await this.getPreparedResult(options);
2241
2260
  return Malloy.estimateQueryCost({ connections, preparedResult });
2242
2261
  }
2243
2262
  }
@@ -2924,6 +2943,12 @@ function isURLReader(thing) {
2924
2943
  function isLookupConnection(thing) {
2925
2944
  return 'lookupConnection' in thing;
2926
2945
  }
2946
+ function isEventStream(thing) {
2947
+ return 'emit' in thing;
2948
+ }
2949
+ function isConnection(thing) {
2950
+ return 'runSQL' in thing;
2951
+ }
2927
2952
  class DataWriter {
2928
2953
  constructor(stream) {
2929
2954
  this.stream = stream;
@@ -3,6 +3,7 @@ import { AggregateFunctionType, Annotation, CompiledQuery, Expr, FieldDef, Filte
3
3
  import { Connection } from '../connection/types';
4
4
  import { AndChain } from './utils';
5
5
  import { QueryInfo } from '../dialect/dialect';
6
+ import { EventStream } from '../runtime_types';
6
7
  interface TurtleDefPlus extends TurtleDef, Filtered {
7
8
  }
8
9
  /** Parent from QueryStruct. */
@@ -303,6 +304,7 @@ declare class QueryStruct extends QueryNode {
303
304
  connectionName: string;
304
305
  readonly stacki: string;
305
306
  constructor(fieldDef: StructDef, sourceArguments: Record<string, Argument> | undefined, parent: ParentQueryStruct | ParentQueryModel, prepareResultOptions?: PrepareResultOptions | undefined);
307
+ maybeEmitParameterizedSourceUsage(): void;
306
308
  resolveParentParameterReferences(param: Parameter): Parameter;
307
309
  private _arguments;
308
310
  arguments(): Record<string, Argument>;
@@ -324,6 +326,7 @@ declare class QueryStruct extends QueryNode {
324
326
  */
325
327
  resolveQueryFields(): void;
326
328
  getModel(): QueryModel;
329
+ get eventStream(): EventStream | undefined;
327
330
  setParent(parent: ParentQueryStruct | ParentQueryModel): void;
328
331
  /** makes a new queryable field object from a fieldDef */
329
332
  makeQueryField(field: FieldDef, referenceId?: string): QueryField;
@@ -353,10 +356,11 @@ interface QueryResults {
353
356
  }
354
357
  /** start here */
355
358
  export declare class QueryModel {
359
+ readonly eventStream?: EventStream | undefined;
356
360
  dialect: Dialect;
357
361
  modelDef: ModelDef | undefined;
358
362
  structs: Map<string, QueryStruct>;
359
- constructor(modelDef: ModelDef | undefined);
363
+ constructor(modelDef: ModelDef | undefined, eventStream?: EventStream | undefined);
360
364
  loadModelFromDef(modelDef: ModelDef): void;
361
365
  getStructByName(name: string): QueryStruct;
362
366
  getStructFromRef(structRef: StructRef, sourceArguments: Record<string, Argument> | undefined, prepareResultOptions?: PrepareResultOptions): QueryStruct;
@@ -475,7 +475,9 @@ class QueryField extends QueryNode {
475
475
  throw new Error('Unexpanded spread encountered during SQL generation');
476
476
  }
477
477
  generateParameterFragment(resultSet, context, expr, state) {
478
+ var _a;
478
479
  const name = expr.path[0];
480
+ (_a = context.eventStream) === null || _a === void 0 ? void 0 : _a.emit('source-argument-compiled', { name });
479
481
  const argument = context.arguments()[name];
480
482
  if (argument.value) {
481
483
  return this.exprToSQL(resultSet, context, argument.value, state);
@@ -2002,8 +2004,13 @@ class QueryQuery extends QueryField {
2002
2004
  return outputStruct;
2003
2005
  }
2004
2006
  generateSQLJoinBlock(stageWriter, ji) {
2007
+ var _a;
2005
2008
  let s = '';
2006
2009
  const qs = ji.queryStruct;
2010
+ (_a = qs.eventStream) === null || _a === void 0 ? void 0 : _a.emit('join-used', {
2011
+ name: qs.fieldDef.as,
2012
+ });
2013
+ qs.maybeEmitParameterizedSourceUsage();
2007
2014
  const structRelationship = qs.fieldDef.structRelationship;
2008
2015
  let structSQL = qs.structSourceSQL(stageWriter);
2009
2016
  if ((0, malloy_types_1.isJoinOn)(structRelationship)) {
@@ -2699,6 +2706,7 @@ class QueryQuery extends QueryField {
2699
2706
  return ret;
2700
2707
  }
2701
2708
  generateSQLFromPipeline(stageWriter) {
2709
+ this.parent.maybeEmitParameterizedSourceUsage();
2702
2710
  this.prepare(stageWriter);
2703
2711
  let lastStageName = this.generateSQL(stageWriter);
2704
2712
  let outputStruct = this.getResultStructDef();
@@ -3006,6 +3014,18 @@ class QueryStruct extends QueryNode {
3006
3014
  this.dialect = (0, dialect_1.getDialect)(this.fieldDef.dialect);
3007
3015
  this.addFieldsFromFieldList(this.fieldDef.fields);
3008
3016
  }
3017
+ maybeEmitParameterizedSourceUsage() {
3018
+ var _a;
3019
+ const paramsAndArgs = {
3020
+ ...this.fieldDef.parameters,
3021
+ ...this.fieldDef.arguments,
3022
+ };
3023
+ if (Object.values(paramsAndArgs).length === 0)
3024
+ return;
3025
+ (_a = this.eventStream) === null || _a === void 0 ? void 0 : _a.emit('parameterized-source-compiled', {
3026
+ parameters: paramsAndArgs,
3027
+ });
3028
+ }
3009
3029
  resolveParentParameterReferences(param) {
3010
3030
  return {
3011
3031
  ...param,
@@ -3223,6 +3243,9 @@ class QueryStruct extends QueryNode {
3223
3243
  return this.parent.getModel();
3224
3244
  }
3225
3245
  }
3246
+ get eventStream() {
3247
+ return this.getModel().eventStream;
3248
+ }
3226
3249
  setParent(parent) {
3227
3250
  if ('struct' in parent) {
3228
3251
  this.parent = parent.struct;
@@ -3414,7 +3437,8 @@ class QueryStruct extends QueryNode {
3414
3437
  // const exploreSearchSQLMap = new Map<string, string>();
3415
3438
  /** start here */
3416
3439
  class QueryModel {
3417
- constructor(modelDef) {
3440
+ constructor(modelDef, eventStream) {
3441
+ this.eventStream = eventStream;
3418
3442
  this.dialect = new standardsql_1.StandardSQLDialect();
3419
3443
  // dialect: Dialect = new PostgresDialect();
3420
3444
  this.modelDef = undefined;
@@ -26,3 +26,6 @@ export interface URLReader {
26
26
  */
27
27
  readURL: (url: URL) => Promise<string>;
28
28
  }
29
+ export interface EventStream {
30
+ emit(id: string, data: any): void;
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.195-dev241001233244",
3
+ "version": "0.0.195-dev241003204819",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",