@malloydata/malloy 0.0.287 → 0.0.289

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
@@ -5,7 +5,7 @@ export { isSourceDef, Segment, isBasicAtomic, isJoined, isJoinedSource, isSampli
5
5
  export { malloyToQuery, MalloyTranslator, } from './lang';
6
6
  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, InMemoryModelCache, CacheManager, } from './malloy';
8
- export type { PreparedQuery, Field, AtomicField, ExploreField, QueryField, SortableField, DataArray, DataRecord, DataColumn, DataArrayOrRecord, Loggable, ModelMaterializer, DocumentTablePath, DocumentSymbol, ResultJSON, PreparedResultJSON, PreparedResultMaterializer, ExploreMaterializer, WriteStream, SerializedExplore, ModelCache, CachedModel, DateField, TimestampField, } from './malloy';
8
+ export type { PreparedQuery, Field, AtomicField, ExploreField, QueryField, SortableField, DataArray, DataRecord, DataColumn, DataArrayOrRecord, Loggable, ModelMaterializer, DocumentTablePath, DocumentSymbol, ResultJSON, PreparedResultJSON, PreparedResultMaterializer, ExploreMaterializer, WriteStream, SerializedExplore, ModelCache, CachedModel, DateField, TimestampField, SourceComponentInfo, } from './malloy';
9
9
  export type { QueryOptionsReader, RunSQLOptions } from './run_sql_options';
10
10
  export type { EventStream, ModelString, ModelURL, QueryString, QueryURL, URLReader, InvalidationKey, } from './runtime_types';
11
11
  export type { Connection, ConnectionConfig, ConnectionFactory, ConnectionParameter, ConnectionParameterValue, ConnectionConfigSchema, FetchSchemaOptions, InfoConnection, LookupConnection, PersistSQLResults, PooledConnection, TestableConnection, StreamingConnection, } from './connection/types';
package/dist/malloy.d.ts CHANGED
@@ -2,7 +2,7 @@ import type { RunSQLOptions } from './run_sql_options';
2
2
  import type { DocumentCompletion as DocumentCompletionDefinition, DocumentSymbol as DocumentSymbolDefinition, LogMessage } from './lang';
3
3
  import { MalloyTranslator } from './lang';
4
4
  import type { DocumentHelpContext } from './lang/parse-tree-walkers/document-help-context-walker';
5
- 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 } from './model';
5
+ 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 } from './model';
6
6
  import type { EventStream, InvalidationKey, ModelString, ModelURL, QueryString, QueryURL, URLReader } from './runtime_types';
7
7
  import type { Connection, FetchSchemaOptions, InfoConnection, LookupConnection } from './connection/types';
8
8
  import type { Tag } from '@malloydata/malloy-tag';
@@ -19,6 +19,15 @@ export interface Loggable {
19
19
  warn: (message?: any, ...optionalParams: any[]) => void;
20
20
  error: (message?: any, ...optionalParams: any[]) => void;
21
21
  }
22
+ export type SourceComponentInfo = {
23
+ type: 'table';
24
+ tableName: string;
25
+ sourceID: string;
26
+ } | {
27
+ type: 'sql';
28
+ selectStatement: string;
29
+ sourceID: string;
30
+ };
22
31
  export interface ParseOptions {
23
32
  importBaseURL?: URL;
24
33
  testEnvironment?: boolean;
@@ -98,7 +107,7 @@ export declare class Malloy {
98
107
  * instead of looping forever, but the fix is to correct the dialect.
99
108
  */
100
109
  static safelyFetchTableSchema(connection: InfoConnection, toFetch: Record<string, string>, opts: FetchSchemaOptions): Promise<{
101
- schemas: Record<string, import("./model").TableSourceDef>;
110
+ schemas: Record<string, TableSourceDef>;
102
111
  errors: Record<string, string>;
103
112
  }>;
104
113
  /**
@@ -618,6 +627,11 @@ export declare class Explore extends Entity implements Taggable {
618
627
  toJSON(): SerializedExplore;
619
628
  static fromJSON(main_explore: SerializedExplore): Explore;
620
629
  get location(): DocumentLocation | undefined;
630
+ private collectSourceComponents;
631
+ /**
632
+ * THIS IS A HIGHLY EXPERIMENTAL API AND MAY VANISH OR CHAGE WITHOUT NOTICE
633
+ */
634
+ getSourceComponents(): SourceComponentInfo[];
621
635
  }
622
636
  export declare enum AtomicFieldType {
623
637
  String = "string",
package/dist/malloy.js CHANGED
@@ -33,6 +33,11 @@ const annotation_1 = require("./annotation");
33
33
  const sql_block_1 = require("./model/sql_block");
34
34
  const utils_1 = require("./lang/utils");
35
35
  const reference_list_1 = require("./lang/reference-list");
36
+ function isSourceComponent(source) {
37
+ return (source.type === 'table' ||
38
+ source.type === 'sql_select' ||
39
+ source.type === 'query_source');
40
+ }
36
41
  const MALLOY_INTERNAL_URL = 'internal://internal.malloy';
37
42
  class Malloy {
38
43
  static get version() {
@@ -499,7 +504,7 @@ class Model {
499
504
  */
500
505
  getExploreByName(name) {
501
506
  const struct = this.modelDef.contents[name];
502
- if ((0, model_1.isSourceDef)(struct)) {
507
+ if (struct && (0, model_1.isSourceDef)(struct)) {
503
508
  return new Explore(struct);
504
509
  }
505
510
  throw new Error("'name' is not an explore");
@@ -1268,6 +1273,82 @@ class Explore extends Entity {
1268
1273
  get location() {
1269
1274
  return this.structDef.location;
1270
1275
  }
1276
+ collectSourceComponents(structDef) {
1277
+ const sources = [];
1278
+ if (structDef.type === 'composite') {
1279
+ for (const source of structDef.sources) {
1280
+ sources.push(...this.collectSourceComponents(source));
1281
+ }
1282
+ return sources;
1283
+ }
1284
+ if (isSourceComponent(structDef)) {
1285
+ if (structDef.type === 'table') {
1286
+ // Generate sourceID based on connection and table name
1287
+ sources.push({
1288
+ type: 'table',
1289
+ tableName: structDef.tablePath,
1290
+ sourceID: `${structDef.connection}:${structDef.tablePath}`,
1291
+ });
1292
+ }
1293
+ else if (structDef.type === 'sql_select') {
1294
+ sources.push({
1295
+ type: 'sql',
1296
+ selectStatement: structDef.selectStr,
1297
+ sourceID: `${structDef.connection}:${structDef.selectStr}`,
1298
+ });
1299
+ }
1300
+ else if (structDef.type === 'query_source') {
1301
+ // For QuerySourceDef, we need to extract the SQL from the query
1302
+ // We need to create a PreparedQuery from the query, then get a PreparedResult
1303
+ // to access the SQL
1304
+ let sql;
1305
+ try {
1306
+ // Create a PreparedQuery from the query in the QuerySourceDef
1307
+ const preparedQuery = new PreparedQuery(structDef.query, this.modelDef, []);
1308
+ // Get the PreparedResult which contains the SQL
1309
+ const preparedResult = preparedQuery.getPreparedResult();
1310
+ // Extract the SQL
1311
+ sql = preparedResult.sql;
1312
+ }
1313
+ catch (error) {
1314
+ // If we can't compile the query, use a placeholder
1315
+ sql = `-- Could not compile SQL for query ${structDef.query.name || 'unnamed query'}: ${error instanceof Error ? error.message : String(error)}`;
1316
+ }
1317
+ // Generate sourceID based on connection and SQL
1318
+ const sourceID = `${structDef.connection}:${sql}`;
1319
+ sources.push({
1320
+ type: 'sql',
1321
+ selectStatement: sql,
1322
+ sourceID: sourceID,
1323
+ });
1324
+ }
1325
+ }
1326
+ else {
1327
+ return [];
1328
+ }
1329
+ // Process all fields to find joins
1330
+ for (const field of structDef.fields) {
1331
+ if ((0, model_1.isJoined)(field)) {
1332
+ sources.push(...this.collectSourceComponents(field));
1333
+ }
1334
+ }
1335
+ return sources;
1336
+ }
1337
+ /**
1338
+ * THIS IS A HIGHLY EXPERIMENTAL API AND MAY VANISH OR CHAGE WITHOUT NOTICE
1339
+ */
1340
+ getSourceComponents() {
1341
+ const uniqueSources = {};
1342
+ if ((0, model_1.isSourceDef)(this.structDef)) {
1343
+ const allSources = this.collectSourceComponents(this.structDef);
1344
+ // Deduplicate sources using sourceID as the key
1345
+ for (const source of allSources) {
1346
+ uniqueSources[source.sourceID] = source;
1347
+ }
1348
+ }
1349
+ // Return the deduplicated sources as an array
1350
+ return Object.values(uniqueSources);
1351
+ }
1271
1352
  }
1272
1353
  exports.Explore = Explore;
1273
1354
  var AtomicFieldType;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const MALLOY_VERSION = "0.0.287";
1
+ export declare const MALLOY_VERSION = "0.0.289";
package/dist/version.js CHANGED
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MALLOY_VERSION = void 0;
4
4
  // generated with 'generate-version-file' script; do not edit manually
5
- exports.MALLOY_VERSION = '0.0.287';
5
+ exports.MALLOY_VERSION = '0.0.289';
6
6
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.287",
3
+ "version": "0.0.289",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -41,9 +41,9 @@
41
41
  "generate-version-file": "VERSION=$(npm pkg get version --workspaces=false | tr -d \\\")\necho \"// generated with 'generate-version-file' script; do not edit manually\\nexport const MALLOY_VERSION = '$VERSION';\" > src/version.ts"
42
42
  },
43
43
  "dependencies": {
44
- "@malloydata/malloy-filter": "0.0.287",
45
- "@malloydata/malloy-interfaces": "0.0.287",
46
- "@malloydata/malloy-tag": "0.0.287",
44
+ "@malloydata/malloy-filter": "0.0.289",
45
+ "@malloydata/malloy-interfaces": "0.0.289",
46
+ "@malloydata/malloy-tag": "0.0.289",
47
47
  "antlr4ts": "^0.5.0-alpha.4",
48
48
  "assert": "^2.0.0",
49
49
  "jaro-winkler": "^0.2.8",