@malloydata/malloy 0.0.96-dev231025215721 → 0.0.96

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/malloy.d.ts CHANGED
@@ -14,6 +14,9 @@ export interface Loggable {
14
14
  export interface ParseOptions {
15
15
  importBaseURL?: URL;
16
16
  }
17
+ export interface CompileOptions {
18
+ refreshSchemaCache?: boolean | number;
19
+ }
17
20
  export declare class Malloy {
18
21
  static get version(): string;
19
22
  private static _log;
@@ -53,11 +56,12 @@ export declare class Malloy {
53
56
  * @param model A compiled model to build upon (optional).
54
57
  * @return A (promise of a) compiled `Model`.
55
58
  */
56
- static compile({ urlReader, connections, parse, model, }: {
59
+ static compile({ urlReader, connections, parse, model, refreshSchemaCache, }: {
57
60
  urlReader: URLReader;
58
61
  connections: LookupConnection<InfoConnection>;
59
62
  parse: Parse;
60
63
  model?: Model;
64
+ refreshSchemaCache?: boolean | number;
61
65
  }): Promise<Model>;
62
66
  private static compileSQLBlock;
63
67
  /**
@@ -710,7 +714,7 @@ export declare class Runtime {
710
714
  * @return A `ModelMaterializer` capable of materializing the requested model,
711
715
  * or loading further related objects.
712
716
  */
713
- loadModel(source: ModelURL | ModelString, options?: ParseOptions): ModelMaterializer;
717
+ loadModel(source: ModelURL | ModelString, options?: ParseOptions & CompileOptions): ModelMaterializer;
714
718
  _loadModelFromModelDef(modelDef: ModelDef): ModelMaterializer;
715
719
  /**
716
720
  * Load a Malloy query by URL or contents.
@@ -719,7 +723,7 @@ export declare class Runtime {
719
723
  * @return A `QueryMaterializer` capable of materializing the requested query, running it,
720
724
  * or loading further related objects.
721
725
  */
722
- loadQuery(query: QueryURL | QueryString, options?: ParseOptions): QueryMaterializer;
726
+ loadQuery(query: QueryURL | QueryString, options?: ParseOptions & CompileOptions): QueryMaterializer;
723
727
  /**
724
728
  * Load a Malloy query by the URL or contents of a Malloy model document
725
729
  * and the index of an unnamed query contained in the model.
@@ -729,7 +733,7 @@ export declare class Runtime {
729
733
  * @return A `QueryMaterializer` capable of materializing the requested query, running it,
730
734
  * or loading further related objects.
731
735
  */
732
- loadQueryByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions): QueryMaterializer;
736
+ loadQueryByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions & CompileOptions): QueryMaterializer;
733
737
  /**
734
738
  * Load a Malloy query by the URL or contents of a Malloy model document
735
739
  * and the name of a query contained in the model.
@@ -739,7 +743,7 @@ export declare class Runtime {
739
743
  * @return A `QueryMaterializer` capable of materializing the requested query, running it,
740
744
  * or loading further related objects.
741
745
  */
742
- loadQueryByName(model: ModelURL | ModelString, name: string, options?: ParseOptions): QueryMaterializer;
746
+ loadQueryByName(model: ModelURL | ModelString, name: string, options?: ParseOptions & CompileOptions): QueryMaterializer;
743
747
  /**
744
748
  * Load a SQL block by the URL or contents of a Malloy model document
745
749
  * and the name of a query contained in the model.
@@ -749,7 +753,7 @@ export declare class Runtime {
749
753
  * @return A `SQLBlockMaterializer` capable of materializing the requested query, running it,
750
754
  * or loading further related objects.
751
755
  */
752
- loadSQLBlockByName(model: ModelURL | ModelString, name: string, options?: ParseOptions): SQLBlockMaterializer;
756
+ loadSQLBlockByName(model: ModelURL | ModelString, name: string, options?: ParseOptions & CompileOptions): SQLBlockMaterializer;
753
757
  /**
754
758
  * Load a SQL block by the URL or contents of a Malloy model document
755
759
  * and the name of a query contained in the model.
@@ -759,21 +763,21 @@ export declare class Runtime {
759
763
  * @return A `SQLBlockMaterializer` capable of materializing the requested query, running it,
760
764
  * or loading further related objects.
761
765
  */
762
- loadSQLBlockByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions): SQLBlockMaterializer;
766
+ loadSQLBlockByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions & CompileOptions): SQLBlockMaterializer;
763
767
  /**
764
768
  * Compile a Malloy model by URL or contents.
765
769
  *
766
770
  * @param source The URL or contents of a Malloy model document to compile.
767
771
  * @return A promise of a compiled `Model`.
768
772
  */
769
- getModel(source: ModelURL | ModelString, options?: ParseOptions): Promise<Model>;
773
+ getModel(source: ModelURL | ModelString, options?: ParseOptions & CompileOptions): Promise<Model>;
770
774
  /**
771
775
  * Compile a Malloy query by URL or contents.
772
776
  *
773
777
  * @param query The URL or contents of a Malloy query document to compile.
774
778
  * @return A promise of a compiled `PreparedQuery`.
775
779
  */
776
- getQuery(query: QueryURL | QueryString, options?: ParseOptions): Promise<PreparedQuery>;
780
+ getQuery(query: QueryURL | QueryString, options?: ParseOptions & CompileOptions): Promise<PreparedQuery>;
777
781
  /**
778
782
  * Compile a Malloy query by the URL or contents of a model document
779
783
  * and the index of an unnamed query contained within the model.
@@ -782,7 +786,7 @@ export declare class Runtime {
782
786
  * @param index The index of an unnamed query contained within the model.
783
787
  * @return A promise of a compiled `PreparedQuery`.
784
788
  */
785
- getQueryByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions): Promise<PreparedQuery>;
789
+ getQueryByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions & CompileOptions): Promise<PreparedQuery>;
786
790
  /**
787
791
  * Compile a Malloy query by the URL or contents of a model document
788
792
  * and the name of a query contained within the model.
@@ -791,7 +795,7 @@ export declare class Runtime {
791
795
  * @param name The name of a query contained within the model.
792
796
  * @return A promise of a compiled `PreparedQuery`.
793
797
  */
794
- getQueryByName(model: ModelURL | ModelString, name: string, options?: ParseOptions): Promise<PreparedQuery>;
798
+ getQueryByName(model: ModelURL | ModelString, name: string, options?: ParseOptions & CompileOptions): Promise<PreparedQuery>;
795
799
  /**
796
800
  * Get a SQL block by the URL or contents of a Malloy model document
797
801
  * and the name of a SQL block contained in the model.
@@ -800,7 +804,7 @@ export declare class Runtime {
800
804
  * @param name The name of the sql block to use within the model.
801
805
  * @return A promise of a `CompiledSQLBlock`.
802
806
  */
803
- getSQLBlockByName(model: ModelURL | ModelString, name: string, options?: ParseOptions): Promise<SQLBlockStructDef>;
807
+ getSQLBlockByName(model: ModelURL | ModelString, name: string, options?: ParseOptions & CompileOptions): Promise<SQLBlockStructDef>;
804
808
  /**
805
809
  * Get a SQL block by the URL or contents of a Malloy model document
806
810
  * and the name of a query contained in the model.
@@ -809,7 +813,7 @@ export declare class Runtime {
809
813
  * @param index The index of the SQL block to use within the model. Note: named blocks are indexable, too.
810
814
  * @return A promise of a `SQLBlock`.
811
815
  */
812
- getSQLBlockByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions): Promise<SQLBlockStructDef>;
816
+ getSQLBlockByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions & CompileOptions): Promise<SQLBlockStructDef>;
813
817
  }
814
818
  export declare class ConnectionRuntime extends Runtime {
815
819
  readonly rawConnections: Connection[];
@@ -870,7 +874,7 @@ export declare class ModelMaterializer extends FluentState<Model> {
870
874
  * @return A `QueryMaterializer` capable of materializing the requested query, running it,
871
875
  * or loading further related objects.
872
876
  */
873
- loadQuery(query: QueryString | QueryURL, options?: ParseOptions): QueryMaterializer;
877
+ loadQuery(query: QueryString | QueryURL, options?: ParseOptions & CompileOptions): QueryMaterializer;
874
878
  /**
875
879
  * Extend a Malloy model by URL or contents.
876
880
  *
@@ -878,7 +882,7 @@ export declare class ModelMaterializer extends FluentState<Model> {
878
882
  * @return A `ModelMaterializer` capable of materializing the requested model,
879
883
  * or loading further related objects.
880
884
  */
881
- extendModel(query: QueryString | QueryURL, options?: ParseOptions): ModelMaterializer;
885
+ extendModel(query: QueryString | QueryURL, options?: ParseOptions & CompileOptions): ModelMaterializer;
882
886
  search(sourceName: string, searchTerm: string, limit?: number, searchField?: string | undefined): Promise<SearchIndexResult[] | undefined>;
883
887
  searchValueMap(sourceName: string, limit?: number, options?: ParseOptions): Promise<SearchValueMapResult[] | undefined>;
884
888
  /**
package/dist/malloy.js CHANGED
@@ -77,7 +77,14 @@ class Malloy {
77
77
  * @param model A compiled model to build upon (optional).
78
78
  * @return A (promise of a) compiled `Model`.
79
79
  */
80
- static async compile({ urlReader, connections, parse, model, }) {
80
+ static async compile({ urlReader, connections, parse, model, refreshSchemaCache, }) {
81
+ let refreshTimestamp;
82
+ if (refreshSchemaCache) {
83
+ refreshTimestamp =
84
+ typeof refreshSchemaCache === 'number'
85
+ ? refreshSchemaCache
86
+ : Date.now();
87
+ }
81
88
  const translator = parse._translator;
82
89
  // eslint-disable-next-line no-constant-condition
83
90
  while (true) {
@@ -132,7 +139,9 @@ class Malloy {
132
139
  // TODO detect if the union of `Object.keys(tables)` and `Object.keys(errors)` is not the same
133
140
  // as `Object.keys(tablePathByKey)`, i.e. that all tables are accounted for. Otherwise
134
141
  // the translator runs into an infinite loop fetching tables.
135
- const { schemas: tables, errors } = await connection.fetchSchemaForTables(tablePathByKey);
142
+ const { schemas: tables, errors } = await connection.fetchSchemaForTables(tablePathByKey, {
143
+ refreshTimestamp,
144
+ });
136
145
  translator.update({ tables, errors: { tables: errors } });
137
146
  }
138
147
  catch (error) {
@@ -154,7 +163,9 @@ class Malloy {
154
163
  try {
155
164
  const conn = await connections.lookupConnection(connectionName);
156
165
  const expanded = Malloy.compileSQLBlock(result.partialModel, toCompile);
157
- const resolved = await conn.fetchSchemaForSQLBlock(expanded);
166
+ const resolved = await conn.fetchSchemaForSQLBlock(expanded, {
167
+ refreshTimestamp,
168
+ });
158
169
  if (resolved.error) {
159
170
  translator.update({
160
171
  errors: { compileSQL: { [expanded.name]: resolved.error } },
@@ -1514,6 +1525,7 @@ class Runtime {
1514
1525
  urlReader: this.urlReader,
1515
1526
  connections: this.connections,
1516
1527
  parse,
1528
+ refreshSchemaCache: options === null || options === void 0 ? void 0 : options.refreshSchemaCache,
1517
1529
  });
1518
1530
  });
1519
1531
  }
@@ -1778,6 +1790,7 @@ class ModelMaterializer extends FluentState {
1778
1790
  connections,
1779
1791
  parse,
1780
1792
  model,
1793
+ refreshSchemaCache: options === null || options === void 0 ? void 0 : options.refreshSchemaCache,
1781
1794
  });
1782
1795
  return queryModel.preparedQuery;
1783
1796
  });
@@ -1809,6 +1822,7 @@ class ModelMaterializer extends FluentState {
1809
1822
  connections,
1810
1823
  parse,
1811
1824
  model,
1825
+ refreshSchemaCache: options === null || options === void 0 ? void 0 : options.refreshSchemaCache,
1812
1826
  });
1813
1827
  return queryModel;
1814
1828
  });
@@ -29,6 +29,12 @@ export interface URLReader {
29
29
  */
30
30
  readURL: (url: URL) => Promise<string>;
31
31
  }
32
+ /**
33
+ * Options passed to fetchSchema methods.
34
+ */
35
+ export interface FetchSchemaOptions {
36
+ refreshTimestamp?: number;
37
+ }
32
38
  /**
33
39
  * An object capable of reading schemas for given table names.
34
40
  */
@@ -40,7 +46,7 @@ export interface InfoConnection {
40
46
  * as a map of keys to table names.
41
47
  * @return A mapping of table keys to schemas.
42
48
  */
43
- fetchSchemaForTables(tables: Record<string, string>): Promise<{
49
+ fetchSchemaForTables(tables: Record<string, string>, options: FetchSchemaOptions): Promise<{
44
50
  schemas: Record<string, StructDef>;
45
51
  errors: Record<string, string>;
46
52
  }>;
@@ -50,7 +56,7 @@ export interface InfoConnection {
50
56
  * @param block The SQL blocks to fetch schemas for.
51
57
  * @return A mapping of SQL block names to schemas.
52
58
  */
53
- fetchSchemaForSQLBlock(block: SQLBlock): Promise<{
59
+ fetchSchemaForSQLBlock(block: SQLBlock, options: FetchSchemaOptions): Promise<{
54
60
  structDef: StructDef;
55
61
  error?: undefined;
56
62
  } | {
@@ -109,9 +115,7 @@ export interface PersistSQLResults extends Connection {
109
115
  manifestTemporaryTable(sqlCommand: string): Promise<string>;
110
116
  }
111
117
  export interface StreamingConnection extends Connection {
112
- runSQLStream(sqlCommand: string, options?: {
113
- rowLimit?: number;
114
- }): AsyncIterableIterator<QueryDataRow>;
118
+ runSQLStream(sqlCommand: string, options?: RunSQLOptions): AsyncIterableIterator<QueryDataRow>;
115
119
  }
116
120
  /**
117
121
  * A mapping of connection names to connections.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.96-dev231025215721",
3
+ "version": "0.0.96",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",