@malloydata/malloy 0.0.335 → 0.0.336

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.
Files changed (84) hide show
  1. package/CONTEXT.md +4 -3
  2. package/MALLOY_API.md +129 -0
  3. package/dist/annotation.d.ts +0 -2
  4. package/dist/annotation.js +29 -23
  5. package/dist/api/asynchronous.d.ts +1 -1
  6. package/dist/api/foundation/cache.d.ts +32 -0
  7. package/dist/api/foundation/cache.js +92 -0
  8. package/dist/api/foundation/compile.d.ts +175 -0
  9. package/dist/api/foundation/compile.js +391 -0
  10. package/dist/api/foundation/core.d.ts +493 -0
  11. package/dist/api/foundation/core.js +1247 -0
  12. package/dist/api/foundation/document.d.ts +167 -0
  13. package/dist/api/foundation/document.js +206 -0
  14. package/dist/api/foundation/index.d.ts +10 -0
  15. package/dist/api/foundation/index.js +77 -0
  16. package/dist/api/foundation/readers.d.ts +53 -0
  17. package/dist/api/foundation/readers.js +134 -0
  18. package/dist/api/foundation/result.d.ts +185 -0
  19. package/dist/api/foundation/result.js +704 -0
  20. package/dist/api/foundation/runtime.d.ts +361 -0
  21. package/dist/api/foundation/runtime.js +733 -0
  22. package/dist/api/foundation/types.d.ts +54 -0
  23. package/dist/api/foundation/types.js +7 -0
  24. package/dist/api/foundation/writers.d.ts +42 -0
  25. package/dist/api/foundation/writers.js +230 -0
  26. package/dist/api/util.d.ts +1 -1
  27. package/dist/connection/base_connection.d.ts +5 -0
  28. package/dist/connection/types.d.ts +5 -0
  29. package/dist/dialect/duckdb/duckdb.js +2 -1
  30. package/dist/dialect/snowflake/snowflake.js +7 -1
  31. package/dist/dialect/trino/trino.js +7 -2
  32. package/dist/index.d.ts +6 -3
  33. package/dist/index.js +30 -26
  34. package/dist/lang/ast/error-factory.js +3 -5
  35. package/dist/lang/ast/source-elements/query-source.js +2 -7
  36. package/dist/lang/ast/source-elements/refined-source.js +11 -1
  37. package/dist/lang/ast/source-elements/sql-source.d.ts +1 -1
  38. package/dist/lang/ast/source-elements/sql-source.js +18 -3
  39. package/dist/lang/ast/sql-elements/sql-string.d.ts +2 -2
  40. package/dist/lang/ast/sql-elements/sql-string.js +18 -1
  41. package/dist/lang/ast/statements/define-source.js +7 -2
  42. package/dist/lang/ast/statements/import-statement.js +53 -21
  43. package/dist/lang/ast/types/document-compile-result.d.ts +1 -0
  44. package/dist/lang/ast/types/malloy-element.d.ts +3 -1
  45. package/dist/lang/ast/types/malloy-element.js +23 -7
  46. package/dist/lang/malloy-to-ast.d.ts +1 -1
  47. package/dist/lang/malloy-to-ast.js +1 -1
  48. package/dist/lang/parse-malloy.d.ts +3 -2
  49. package/dist/lang/parse-malloy.js +14 -25
  50. package/dist/lang/test/test-translator.js +1 -0
  51. package/dist/lang/translate-response.d.ts +1 -0
  52. package/dist/model/constant_expression_compiler.js +6 -7
  53. package/dist/model/index.d.ts +3 -1
  54. package/dist/model/index.js +15 -9
  55. package/dist/model/malloy_types.d.ts +89 -15
  56. package/dist/model/malloy_types.js +12 -0
  57. package/dist/model/persist_utils.d.ts +47 -0
  58. package/dist/model/persist_utils.js +257 -0
  59. package/dist/model/query_model_impl.d.ts +2 -4
  60. package/dist/model/query_model_impl.js +5 -13
  61. package/dist/model/query_node.d.ts +1 -2
  62. package/dist/model/query_node.js +3 -13
  63. package/dist/model/query_query.d.ts +17 -1
  64. package/dist/model/query_query.js +81 -36
  65. package/dist/model/source_def_utils.d.ts +50 -0
  66. package/dist/model/source_def_utils.js +154 -0
  67. package/dist/model/sql_block.d.ts +5 -1
  68. package/dist/model/sql_block.js +29 -4
  69. package/dist/model/sql_compiled.d.ts +29 -0
  70. package/dist/model/sql_compiled.js +102 -0
  71. package/dist/model/stage_writer.d.ts +1 -3
  72. package/dist/model/stage_writer.js +7 -25
  73. package/dist/model/utils.d.ts +20 -1
  74. package/dist/model/utils.js +40 -0
  75. package/dist/run_sql_options.d.ts +0 -1
  76. package/dist/taggable.d.ts +10 -0
  77. package/dist/taggable.js +7 -0
  78. package/dist/version.d.ts +1 -1
  79. package/dist/version.js +1 -1
  80. package/package.json +6 -4
  81. package/dist/malloy.d.ts +0 -1365
  82. package/dist/malloy.js +0 -3421
  83. package/dist/model/materialization/utils.d.ts +0 -3
  84. package/dist/model/materialization/utils.js +0 -41
@@ -23,6 +23,7 @@
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.SQLSource = void 0;
26
+ const source_def_utils_1 = require("../../../model/source_def_utils");
26
27
  const sql_block_1 = require("../../../model/sql_block");
27
28
  const source_1 = require("./source");
28
29
  const error_factory_1 = require("../error-factory");
@@ -38,7 +39,11 @@ class SQLSource extends source_1.Source {
38
39
  const partialModel = this.select.containsQueries
39
40
  ? doc.modelDef()
40
41
  : undefined;
41
- return (0, sql_block_1.compileSQLInterpolation)(this.select.sqlPhrases(), this.connectionName.refString, partialModel);
42
+ const [valid, phrases] = this.select.sqlPhrases();
43
+ if (valid) {
44
+ return (0, sql_block_1.getSourceRequest)(phrases, this.connectionName.refString, partialModel);
45
+ }
46
+ return undefined;
42
47
  }
43
48
  structRef() {
44
49
  return {
@@ -73,6 +78,9 @@ class SQLSource extends source_1.Source {
73
78
  this.requestBlock = this.sqlSourceRequest(doc);
74
79
  }
75
80
  const sql = this.requestBlock;
81
+ if (sql === undefined) {
82
+ return undefined;
83
+ }
76
84
  const sqlDefEntry = (_a = this.translator()) === null || _a === void 0 ? void 0 : _a.root.sqlQueryZone;
77
85
  if (!sqlDefEntry) {
78
86
  this.logError('failed-to-fetch-sql-source-schema', "Cant't look up schema for sql block");
@@ -101,7 +109,9 @@ class SQLSource extends source_1.Source {
101
109
  return error_factory_1.ErrorFactory.structDef;
102
110
  }
103
111
  if (this.requestBlock === undefined) {
104
- this.logError('failed-to-fetch-sql-source-schema', 'Expected to have already compiled the sql block');
112
+ // Means we couldn't make a source request or there was
113
+ // a problem with the source request, both will have logged
114
+ // errors already.
105
115
  return error_factory_1.ErrorFactory.structDef;
106
116
  }
107
117
  const sql = this.requestBlock;
@@ -115,7 +125,8 @@ class SQLSource extends source_1.Source {
115
125
  }
116
126
  else if (lookup.status === 'present') {
117
127
  const location = this.select.location;
118
- const locStruct = {
128
+ // Create a base struct with updated fields (adding location and fieldUsage)
129
+ const baseStruct = {
119
130
  ...lookup.value,
120
131
  fields: lookup.value.fields.map(f => {
121
132
  var _a;
@@ -127,6 +138,10 @@ class SQLSource extends source_1.Source {
127
138
  }),
128
139
  location: this.location,
129
140
  };
141
+ // Use factory to create SQLSourceDef without propagating sourceID/extends
142
+ const [_valid, phrases] = this.select.sqlPhrases();
143
+ const selectSegments = this.select.containsQueries ? phrases : undefined;
144
+ const locStruct = (0, source_def_utils_1.mkSQLSourceDef)(baseStruct, lookup.value.selectStr, selectSegments);
130
145
  const fromDoc = this.document();
131
146
  const modelAnnotation = fromDoc === null || fromDoc === void 0 ? void 0 : fromDoc.currentModelAnnotation();
132
147
  if (modelAnnotation) {
@@ -1,4 +1,4 @@
1
- import type { SQLPhraseSegment } from '../../../model/malloy_types';
1
+ import { type SQLPhraseSegment } from '../../../model/malloy_types';
2
2
  import { MalloyElement } from '../types/malloy-element';
3
3
  import { SourceQueryElement } from '../source-query-elements/source-query-element';
4
4
  type SQLStringSegment = string | SourceQueryElement;
@@ -8,6 +8,6 @@ export declare class SQLString extends MalloyElement {
8
8
  containsQueries: boolean;
9
9
  complete(): void;
10
10
  push(el: string | MalloyElement): void;
11
- sqlPhrases(): SQLPhraseSegment[];
11
+ sqlPhrases(): [boolean, SQLPhraseSegment[]];
12
12
  }
13
13
  export {};
@@ -23,6 +23,7 @@
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.SQLString = void 0;
26
+ const malloy_types_1 = require("../../../model/malloy_types");
26
27
  const malloy_element_1 = require("../types/malloy-element");
27
28
  const source_query_element_1 = require("../source-query-elements/source-query-element");
28
29
  class SQLString extends malloy_element_1.MalloyElement {
@@ -54,21 +55,37 @@ class SQLString extends malloy_element_1.MalloyElement {
54
55
  }
55
56
  sqlPhrases() {
56
57
  const ret = [];
58
+ let valid = true;
57
59
  for (const el of this.elements) {
58
60
  if (typeof el === 'string') {
59
61
  ret.push({ sql: el });
60
62
  }
63
+ else if (el.isSource()) {
64
+ // Check if it's a persistable source first
65
+ const source = el.getSource();
66
+ if (source) {
67
+ const sourceDef = source.getSourceDef(undefined);
68
+ if ((0, malloy_types_1.isPersistableSourceDef)(sourceDef)) {
69
+ ret.push(sourceDef);
70
+ continue;
71
+ }
72
+ }
73
+ el.sqLog('failed-to-expand-sql-source', 'Cannot expand into a query');
74
+ valid = false;
75
+ }
61
76
  else {
77
+ // Not a source - try as a query
62
78
  const queryObject = el.getQuery();
63
79
  if (queryObject) {
64
80
  ret.push(queryObject.query());
65
81
  }
66
82
  else {
67
83
  el.sqLog('failed-to-expand-sql-source', 'Cannot expand into a query');
84
+ valid = false;
68
85
  }
69
86
  }
70
87
  }
71
- return ret;
88
+ return [valid, ret];
72
89
  }
73
90
  }
74
91
  exports.SQLString = SQLString;
@@ -23,6 +23,8 @@
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.DefineSourceList = exports.DefineSource = void 0;
26
+ const malloy_types_1 = require("../../../model/malloy_types");
27
+ const source_def_utils_1 = require("../../../model/source_def_utils");
26
28
  const error_factory_1 = require("../error-factory");
27
29
  const malloy_element_1 = require("../types/malloy-element");
28
30
  const noteable_1 = require("../types/noteable");
@@ -45,7 +47,7 @@ class DefineSource extends malloy_element_1.MalloyElement {
45
47
  }
46
48
  }
47
49
  execute(doc) {
48
- var _a, _b, _c;
50
+ var _a, _b, _c, _d;
49
51
  if (doc.modelEntry(this.name)) {
50
52
  this.logError('source-definition-name-conflict', `Cannot redefine '${this.name}'`);
51
53
  return;
@@ -65,13 +67,16 @@ class DefineSource extends malloy_element_1.MalloyElement {
65
67
  as: this.name,
66
68
  location: this.location,
67
69
  };
70
+ if ((0, malloy_types_1.isPersistableSourceDef)(entry)) {
71
+ entry.sourceID = (0, source_def_utils_1.mkSourceID)(this.name, (_b = this.location) === null || _b === void 0 ? void 0 : _b.url);
72
+ }
68
73
  if (this.note) {
69
74
  entry.annotation = structDef.annotation
70
75
  ? { ...this.note, inherits: structDef.annotation }
71
76
  : this.note;
72
77
  }
73
78
  entry.partitionComposite =
74
- (_c = (0, composite_source_utils_1.getPartitionCompositeDesc)(this.note, structDef, (_b = this.sourceExpr) !== null && _b !== void 0 ? _b : this)) !== null && _c !== void 0 ? _c : structDef.partitionComposite;
79
+ (_d = (0, composite_source_utils_1.getPartitionCompositeDesc)(this.note, structDef, (_c = this.sourceExpr) !== null && _c !== void 0 ? _c : this)) !== null && _d !== void 0 ? _d : structDef.partitionComposite;
75
80
  doc.setEntry(this.name, { entry, exported: this.exported });
76
81
  }
77
82
  deduplicatedParameters() {
@@ -24,6 +24,16 @@
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.ImportStatement = exports.ImportSelect = exports.ImportSourceName = void 0;
26
26
  const malloy_element_1 = require("../types/malloy-element");
27
+ const malloy_types_1 = require("../../../model/malloy_types");
28
+ const source_def_utils_1 = require("../../../model/source_def_utils");
29
+ const persist_utils_1 = require("../../../model/persist_utils");
30
+ /** Walk BuildNode tree and collect all sourceIDs */
31
+ function collectSourceIDs(nodes, into) {
32
+ for (const node of nodes) {
33
+ into.add(node.sourceID);
34
+ collectSourceIDs(node.dependsOn, into);
35
+ }
36
+ }
27
37
  class ImportSourceName extends malloy_element_1.MalloyElement {
28
38
  constructor(text) {
29
39
  super();
@@ -85,34 +95,56 @@ class ImportStatement extends malloy_element_1.ListOf {
85
95
  const pretranslated = trans.root.pretranslatedModels.get(this.fullURL);
86
96
  const src = trans.root.importZone.getEntry(this.fullURL);
87
97
  if (pretranslated || src.status === 'present') {
88
- const importable = trans.getChildExports(this.fullURL);
89
- if (this.notEmpty()) {
90
- // just import the named objects
98
+ const importedModel = trans.importModelDef(this.fullURL);
99
+ if (importedModel) {
100
+ const importAll = this.empty();
101
+ const explicitImport = {};
91
102
  for (const importOne of this.list) {
92
- const fetchName = importOne.from || importOne;
93
- if (doc.getEntry(importOne.text)) {
94
- importOne.logError('name-conflict-on-selective-import', `Cannot redefine '${importOne.text}'`);
103
+ const dstName = importOne.text;
104
+ const srcName = importOne.from ? importOne.from.text : dstName;
105
+ if (importedModel.contents[srcName] === undefined) {
106
+ importOne.logError('selective-import-not-found', `Cannot find '${srcName}', not imported`);
95
107
  }
96
- else if (importable[fetchName.text]) {
97
- const importMe = { ...importable[fetchName.text] };
98
- if (importOne.from) {
99
- importMe.as = importOne.text;
100
- }
101
- doc.setEntry(importOne.text, { entry: importMe, exported: false });
108
+ else if (doc.getEntry(dstName)) {
109
+ importOne.logError('name-conflict-on-selective-import', `Cannot redefine '${dstName}'`);
102
110
  }
103
111
  else {
104
- fetchName.logError('selective-import-not-found', `Cannot find '${fetchName.text}', not imported`);
112
+ explicitImport[srcName] = dstName;
105
113
  }
106
114
  }
107
- }
108
- else {
109
- // import everything
110
- for (const [importing, entry] of Object.entries(trans.getChildExports(this.fullURL))) {
111
- if (doc.getEntry(importing)) {
112
- this.logError('name-conflict-on-indiscriminate-import', `Cannot redefine '${importing}'`);
115
+ const neededSourceIDs = new Set();
116
+ for (const srcName of importedModel.exports) {
117
+ const picked = explicitImport[srcName];
118
+ const dstName = picked || srcName;
119
+ if (importAll || picked) {
120
+ const importMe = { ...importedModel.contents[srcName] };
121
+ importMe.as = dstName;
122
+ doc.setEntry(dstName, { entry: importMe, exported: false });
123
+ // Collect dependencies for persistable sources
124
+ if ((0, malloy_types_1.isSourceDef)(importMe) && (0, malloy_types_1.isPersistableSourceDef)(importMe)) {
125
+ const deps = (0, persist_utils_1.findPersistentDependencies)(importMe, importedModel);
126
+ collectSourceIDs(deps, neededSourceIDs);
127
+ }
113
128
  }
114
- else {
115
- doc.setEntry(importing, { entry, exported: false });
129
+ }
130
+ // Register hidden dependencies from child's registry
131
+ for (const sourceID of neededSourceIDs) {
132
+ if (!(sourceID in doc.documentSrcRegistry)) {
133
+ const value = importedModel.sourceRegistry[sourceID];
134
+ if (value) {
135
+ // If entry is a reference, resolve it to actual SourceDef
136
+ // (parent can't resolve by name since it's not in namespace)
137
+ let entry = value.entry;
138
+ if ((0, malloy_types_1.isSourceRegistryReference)(entry)) {
139
+ const resolved = importedModel.contents[entry.name];
140
+ if (resolved &&
141
+ (0, malloy_types_1.isSourceDef)(resolved) &&
142
+ (0, malloy_types_1.isPersistableSourceDef)(resolved)) {
143
+ entry = resolved;
144
+ }
145
+ }
146
+ (0, source_def_utils_1.registerSource)(doc.documentSrcRegistry, sourceID, entry);
147
+ }
116
148
  }
117
149
  }
118
150
  }
@@ -3,4 +3,5 @@ import type { ModelDataRequest } from '../../translate-response';
3
3
  export interface DocumentCompileResult {
4
4
  modelDef: ModelDef;
5
5
  needs: ModelDataRequest;
6
+ modelWasModified: boolean;
6
7
  }
@@ -1,4 +1,4 @@
1
- import type { Annotation, DocumentLocation, DocumentReference, ModelDef, ModelAnnotation, NamedModelObject, Query, StructDef } from '../../../model/malloy_types';
1
+ import type { Annotation, DocumentLocation, DocumentReference, ModelDef, ModelAnnotation, NamedModelObject, Query, SourceID, SourceRegistryValue, StructDef } from '../../../model/malloy_types';
2
2
  import { Tag } from '@malloydata/malloy-tag';
3
3
  import type { LogMessageOptions, MessageLogger, MessageParameterType, MessageCode } from '../../parse-log';
4
4
  import type { MalloyTranslation } from '../../parse-malloy';
@@ -121,9 +121,11 @@ export declare class Document extends MalloyElement implements NameSpace {
121
121
  elementType: string;
122
122
  globalNameSpace: NameSpace;
123
123
  documentModel: Record<string, ModelEntry>;
124
+ documentSrcRegistry: Record<SourceID, SourceRegistryValue>;
124
125
  queryList: Query[];
125
126
  statements: DocStatementList;
126
127
  didInitModel: boolean;
128
+ modelWasModified: boolean;
127
129
  annotation: Annotation;
128
130
  experiments: Tag;
129
131
  constructor(statements: (DocStatement | DocStatementList)[]);
@@ -27,6 +27,7 @@ exports.isDocStatement = isDocStatement;
27
27
  exports.isDocStatementOrDocStatementList = isDocStatementOrDocStatementList;
28
28
  const dialect_1 = require("../../../dialect");
29
29
  const malloy_types_1 = require("../../../model/malloy_types");
30
+ const utils_1 = require("../../../model/utils");
30
31
  const malloy_tag_1 = require("@malloydata/malloy-tag");
31
32
  const parse_log_1 = require("../../parse-log");
32
33
  const ast_utils_1 = require("../ast-utils");
@@ -437,8 +438,10 @@ class Document extends MalloyElement {
437
438
  this.elementType = 'document';
438
439
  this.globalNameSpace = new global_name_space_1.GlobalNameSpace();
439
440
  this.documentModel = {};
441
+ this.documentSrcRegistry = {};
440
442
  this.queryList = [];
441
443
  this.didInitModel = false;
444
+ this.modelWasModified = false;
442
445
  this.annotation = {};
443
446
  this.experiments = new malloy_tag_1.Tag({});
444
447
  this.modelAnnotationTodoList = [];
@@ -451,6 +454,7 @@ class Document extends MalloyElement {
451
454
  return;
452
455
  }
453
456
  this.documentModel = {};
457
+ this.documentSrcRegistry = {};
454
458
  this.queryList = [];
455
459
  if (extendingModelDef) {
456
460
  if (extendingModelDef.annotation) {
@@ -489,6 +493,7 @@ class Document extends MalloyElement {
489
493
  queryList: this.queryList,
490
494
  },
491
495
  needs,
496
+ modelWasModified: this.modelWasModified,
492
497
  };
493
498
  return ret;
494
499
  }
@@ -507,13 +512,7 @@ class Document extends MalloyElement {
507
512
  }
508
513
  }
509
514
  modelDef() {
510
- const def = {
511
- name: '',
512
- exports: [],
513
- contents: {},
514
- queryList: [],
515
- dependencies: {},
516
- };
515
+ const def = (0, utils_1.mkModelDef)('');
517
516
  if (this.hasAnnotation()) {
518
517
  def.annotation = this.currentModelAnnotation();
519
518
  }
@@ -530,6 +529,8 @@ class Document extends MalloyElement {
530
529
  def.contents[entry] = newEntry;
531
530
  }
532
531
  }
532
+ // Copy the accumulated sourceRegistry
533
+ def.sourceRegistry = { ...this.documentSrcRegistry };
533
534
  return def;
534
535
  }
535
536
  getEntry(str) {
@@ -544,7 +545,22 @@ class Document extends MalloyElement {
544
545
  if ((0, malloy_types_1.isSourceDef)(ent.entry)) {
545
546
  this.checkExperimentalDialect(this, ent.entry.dialect);
546
547
  }
548
+ // Track if the model was modified after initialization
549
+ if (this.didInitModel) {
550
+ this.modelWasModified = true;
551
+ }
547
552
  this.documentModel[str] = ent;
553
+ // Maintain sourceRegistry for persistable sources with sourceID
554
+ if ((0, malloy_types_1.isSourceDef)(ent.entry) &&
555
+ (0, malloy_types_1.isPersistableSourceDef)(ent.entry) &&
556
+ ent.entry.sourceID) {
557
+ this.documentSrcRegistry[ent.entry.sourceID] = {
558
+ entry: {
559
+ type: 'source_registry_reference',
560
+ name: str,
561
+ },
562
+ };
563
+ }
548
564
  }
549
565
  /**
550
566
  * Return an error message if this dialect is the first reference to this particular
@@ -10,7 +10,7 @@ import type { FieldDeclarationConstructor } from './ast';
10
10
  import type { HasString, HasID } from './parse-utils';
11
11
  import type { CastType } from '../model';
12
12
  import type { AccessModifierLabel, DocumentLocation, DocumentRange, Note } from '../model/malloy_types';
13
- import { Tag } from '@malloydata/malloy-tag';
13
+ import type { Tag } from '@malloydata/malloy-tag';
14
14
  import type * as Malloy from '@malloydata/malloy-interfaces';
15
15
  import { Timer } from '../timing';
16
16
  declare class ErrorNode extends ast.SourceQueryElement {
@@ -96,7 +96,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
96
96
  this.timer = new timing_1.Timer('generate_ast');
97
97
  const parseCompilerFlagsTimer = new timing_1.Timer('parse_compiler_flags');
98
98
  for (const flag of DEFAULT_COMPILER_FLAGS) {
99
- const withNewTag = malloy_tag_1.Tag.fromTagLine(flag, 0, this.compilerFlags);
99
+ const withNewTag = (0, malloy_tag_1.parseTag)(flag, this.compilerFlags);
100
100
  this.compilerFlags = withNewTag.tag;
101
101
  }
102
102
  this.timer.contribute([parseCompilerFlagsTimer.stop()]);
@@ -1,4 +1,4 @@
1
- import type { DocumentLocation, DocumentPosition, DocumentReference, ImportLocation, ModelDef, NamedModelObject, SourceDef, SQLSourceDef, DependencyTree, DocumentRange } from '../model/malloy_types';
1
+ import type { DocumentLocation, DocumentPosition, DocumentReference, ImportLocation, ModelDef, SourceDef, SQLSourceDef, DependencyTree, DocumentRange } from '../model/malloy_types';
2
2
  import type { LogMessage, LogMessageOptions, MessageCode, MessageParameterType } from './parse-log';
3
3
  import { BaseMessageLogger } from './parse-log';
4
4
  import type { ZoneData } from './zone';
@@ -112,6 +112,7 @@ export declare abstract class MalloyTranslation {
112
112
  childTranslators: Map<string, MalloyTranslation>;
113
113
  sqlSources: SQLSourceDef[];
114
114
  modelDef: ModelDef;
115
+ modelWasModified: boolean;
115
116
  imports: ImportLocation[];
116
117
  compilerFlags: Tag;
117
118
  readonly parseStep: ParseStep;
@@ -152,7 +153,7 @@ export declare abstract class MalloyTranslation {
152
153
  codeAtLocation(location: DocumentLocation): string;
153
154
  prettyErrors(): string;
154
155
  childRequest(importURL: string): ModelDataRequest;
155
- getChildExports(importURL: string): Record<string, NamedModelObject>;
156
+ importModelDef(importURL: string): ModelDef | undefined;
156
157
  private finalAnswer?;
157
158
  translate(extendingModel?: ModelDef): TranslateResponse;
158
159
  translatorForDependency(url: string): MalloyTranslation | undefined;
@@ -56,7 +56,7 @@ var __importStar = (this && this.__importStar) || (function () {
56
56
  })();
57
57
  Object.defineProperty(exports, "__esModule", { value: true });
58
58
  exports.MalloyTranslator = exports.MalloyChildTranslator = exports.MalloyTranslation = void 0;
59
- const malloy_types_1 = require("../model/malloy_types");
59
+ const utils_1 = require("../model/utils");
60
60
  const ast = __importStar(require("./ast"));
61
61
  const malloy_to_ast_1 = require("./malloy-to-ast");
62
62
  const parse_log_1 = require("./parse-log");
@@ -67,7 +67,7 @@ const document_completion_walker_1 = require("./parse-tree-walkers/document-comp
67
67
  const document_help_context_walker_1 = require("./parse-tree-walkers/document-help-context-walker");
68
68
  const reference_list_1 = require("./reference-list");
69
69
  const translate_response_1 = require("./translate-response");
70
- const utils_1 = require("./utils");
70
+ const utils_2 = require("./utils");
71
71
  const malloy_tag_1 = require("@malloydata/malloy-tag");
72
72
  const model_annotation_walker_1 = require("./parse-tree-walkers/model-annotation-walker");
73
73
  const find_table_path_walker_1 = require("./parse-tree-walkers/find-table-path-walker");
@@ -98,7 +98,7 @@ class ParseStep {
98
98
  }
99
99
  const parseModelTimer = new timing_1.Timer('parse_malloy');
100
100
  const source = srcEnt.value === '' ? '\n' : srcEnt.value;
101
- this.sourceInfo = (0, utils_1.getSourceInfo)(source);
101
+ this.sourceInfo = (0, utils_2.getSourceInfo)(source);
102
102
  let parse;
103
103
  try {
104
104
  parse = this.runParser(source, this.sourceInfo, that);
@@ -419,6 +419,7 @@ class TranslateStep {
419
419
  modelDef: pretranslate,
420
420
  final: true,
421
421
  fromSources: that.getDependencies(),
422
+ modelWasModified: false,
422
423
  };
423
424
  }
424
425
  // begin with the compiler flags of the model we are extending
@@ -456,6 +457,7 @@ class TranslateStep {
456
457
  }
457
458
  else {
458
459
  that.modelDef = docCompile.modelDef;
460
+ that.modelWasModified = docCompile.modelWasModified;
459
461
  }
460
462
  }
461
463
  else {
@@ -477,6 +479,7 @@ class TranslateStep {
477
479
  imports: [...that.imports],
478
480
  },
479
481
  fromSources: that.getDependencies(),
482
+ modelWasModified: that.modelWasModified,
480
483
  ...that.problemResponse(),
481
484
  final: true,
482
485
  };
@@ -490,6 +493,7 @@ class MalloyTranslation {
490
493
  this.importBaseURL = importBaseURL;
491
494
  this.grammarRule = grammarRule;
492
495
  this.sqlSources = [];
496
+ this.modelWasModified = false;
493
497
  this.imports = [];
494
498
  this.compilerFlags = new malloy_tag_1.Tag();
495
499
  this._urlIsFullPath = undefined;
@@ -506,13 +510,7 @@ class MalloyTranslation {
506
510
  this.dialectAlreadyChecked = {};
507
511
  this.allDialectsEnabled = false;
508
512
  this.childTranslators = new Map();
509
- this.modelDef = {
510
- name: sourceURL,
511
- exports: [],
512
- contents: {},
513
- queryList: [],
514
- dependencies: {},
515
- };
513
+ this.modelDef = (0, utils_1.mkModelDef)(sourceURL);
516
514
  /**
517
515
  * This is sort of the makefile for the translation, all the steps
518
516
  * and the dependencies of the steps are declared here. Then when
@@ -684,23 +682,14 @@ class MalloyTranslation {
684
682
  };
685
683
  }
686
684
  }
687
- getChildExports(importURL) {
688
- const exports = {};
685
+ importModelDef(importURL) {
689
686
  const childURL = decodeURI(new URL(importURL, this.sourceURL).toString());
690
687
  const child = this.childTranslators.get(childURL);
691
688
  if (child) {
692
- const did = child.translate();
693
- if (did.modelDef) {
694
- for (const fromChild of child.modelDef.exports) {
695
- const modelEntry = child.modelDef.contents[fromChild];
696
- if ((0, malloy_types_1.isSourceDef)(modelEntry) || modelEntry.type === 'query') {
697
- exports[fromChild] = modelEntry;
698
- }
699
- }
700
- }
701
- // else nothing, assuming there are already errors in the log
689
+ const result = child.translate();
690
+ return result.modelDef;
702
691
  }
703
- return exports;
692
+ return undefined;
704
693
  }
705
694
  translate(extendingModel) {
706
695
  if (this.finalAnswer) {
@@ -720,7 +709,7 @@ class MalloyTranslation {
720
709
  // search to find the one we're looking for.
721
710
  for (let index = 0; index < this.imports.length; index++) {
722
711
  const imp = this.imports[index];
723
- if ((0, utils_1.locationContainsPosition)(imp.location, position)) {
712
+ if ((0, utils_2.locationContainsPosition)(imp.location, position)) {
724
713
  return imp;
725
714
  }
726
715
  }
@@ -751,7 +740,7 @@ class MalloyTranslation {
751
740
  };
752
741
  }
753
742
  rangeFromContext(pcx) {
754
- return (0, utils_1.rangeFromContext)(this.parseStep.sourceInfo, pcx);
743
+ return (0, utils_2.rangeFromContext)(this.parseStep.sourceInfo, pcx);
755
744
  }
756
745
  firstReferenceToDialect(dialect) {
757
746
  if (this.dialectAlreadyChecked[dialect]) {
@@ -365,6 +365,7 @@ class TestTranslator extends parse_malloy_1.MalloyTranslator {
365
365
  name: testURI,
366
366
  exports: [],
367
367
  queryList: [],
368
+ sourceRegistry: {},
368
369
  dependencies: {},
369
370
  contents: {
370
371
  _db_: { type: 'connection', name: '_db_' },
@@ -64,6 +64,7 @@ export type HelpContextResponse = Partial<HelpContext>;
64
64
  interface TranslatedResponseData extends ResponseBase, NeededData, ProblemResponse, FinalResponse {
65
65
  modelDef: ModelDef;
66
66
  fromSources: string[];
67
+ modelWasModified: boolean;
67
68
  }
68
69
  interface TablePath extends ResponseBase, NeededData, ProblemResponse, FinalResponse {
69
70
  pathInfo: PathInfo[];
@@ -84,18 +84,17 @@ class ConstantQueryStruct extends query_node_1.QueryStruct {
84
84
  connection: dialect.name,
85
85
  dialect: dialect.name,
86
86
  };
87
- // Create a minimal model interface that only provides eventStream
88
- const minimalModel = { eventStream };
89
- // Create minimal prepare result options
90
- const minimalPrepareOptions = {};
87
+ // Create minimal model with empty structs map
88
+ const minimalModel = {
89
+ structs: new Map(),
90
+ };
91
+ // Create minimal prepare result options with eventStream
92
+ const minimalPrepareOptions = { eventStream };
91
93
  // Call parent constructor with minimal requirements
92
94
  super(minimalStructDef, undefined, // no source arguments initially
93
95
  { model: minimalModel }, minimalPrepareOptions);
94
96
  this.dialect = dialect;
95
97
  this._constantArguments = parameters;
96
- if (eventStream) {
97
- this.model.eventStream = eventStream;
98
- }
99
98
  }
100
99
  /**
101
100
  * Override arguments() to return our parameters
@@ -4,5 +4,7 @@ import { QueryQuery } from './query_query';
4
4
  import { QueryModelImpl } from './query_model_impl';
5
5
  export { QueryField, QueryStruct, QueryQuery, QueryModelImpl as QueryModel };
6
6
  export { getResultStructDefForQuery, getResultStructDefForView, } from './query_model_impl';
7
- export { indent, composeSQLExpr } from './utils';
7
+ export { indent, composeSQLExpr, makeDigest, mkModelDef } from './utils';
8
8
  export { constantExprToSQL } from './constant_expression_compiler';
9
+ export { getCompiledSQL } from './sql_compiled';
10
+ export { mkSourceID, mkBuildID, mkQuerySourceDef, mkSQLSourceDef, mkTableSourceDef, resolveSourceID, registerSource, hasSourceRegistryEntry, } from './source_def_utils';
@@ -36,7 +36,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
36
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.constantExprToSQL = exports.composeSQLExpr = exports.indent = exports.getResultStructDefForView = exports.getResultStructDefForQuery = exports.QueryModel = exports.QueryQuery = exports.QueryStruct = exports.QueryField = void 0;
39
+ exports.hasSourceRegistryEntry = exports.registerSource = exports.resolveSourceID = exports.mkTableSourceDef = exports.mkSQLSourceDef = exports.mkQuerySourceDef = exports.mkBuildID = exports.mkSourceID = exports.getCompiledSQL = exports.constantExprToSQL = exports.mkModelDef = exports.makeDigest = exports.composeSQLExpr = exports.indent = exports.getResultStructDefForView = exports.getResultStructDefForQuery = exports.QueryModel = exports.QueryQuery = exports.QueryStruct = exports.QueryField = void 0;
40
40
  __exportStar(require("./malloy_types"), exports);
41
41
  const query_node_1 = require("./query_node");
42
42
  Object.defineProperty(exports, "QueryField", { enumerable: true, get: function () { return query_node_1.QueryField; } });
@@ -47,15 +47,8 @@ Object.defineProperty(exports, "QueryQuery", { enumerable: true, get: function (
47
47
  const field_instance_1 = require("./field_instance");
48
48
  const query_model_impl_1 = require("./query_model_impl");
49
49
  Object.defineProperty(exports, "QueryModel", { enumerable: true, get: function () { return query_model_impl_1.QueryModelImpl; } });
50
- // We have a circular dependency issue, and this is the minimal
51
- // dependency injection needed to get around it. Ideally, we would
52
- // like to avoid this, and I think a thoughtful pass through
53
- // FieldInstance and QueryField might eliminate the need for this.
54
50
  function getLookupFun(mri) {
55
- if (mri instanceof query_model_impl_1.QueryModelImpl) {
56
- return (name) => mri.structs.get(name);
57
- }
58
- return () => undefined;
51
+ return (name) => mri.structs.get(name);
59
52
  }
60
53
  field_instance_1.FieldInstanceField.registerExpressionCompiler(expression_compiler_1.exprToSQL);
61
54
  query_node_1.QueryStruct.registerTurtleFieldMaker((field, parent) => query_query_1.QueryQuery.makeQuery(field, parent, undefined, false, getLookupFun(parent.getModel())));
@@ -65,6 +58,19 @@ Object.defineProperty(exports, "getResultStructDefForView", { enumerable: true,
65
58
  var utils_1 = require("./utils");
66
59
  Object.defineProperty(exports, "indent", { enumerable: true, get: function () { return utils_1.indent; } });
67
60
  Object.defineProperty(exports, "composeSQLExpr", { enumerable: true, get: function () { return utils_1.composeSQLExpr; } });
61
+ Object.defineProperty(exports, "makeDigest", { enumerable: true, get: function () { return utils_1.makeDigest; } });
62
+ Object.defineProperty(exports, "mkModelDef", { enumerable: true, get: function () { return utils_1.mkModelDef; } });
68
63
  var constant_expression_compiler_1 = require("./constant_expression_compiler");
69
64
  Object.defineProperty(exports, "constantExprToSQL", { enumerable: true, get: function () { return constant_expression_compiler_1.constantExprToSQL; } });
65
+ var sql_compiled_1 = require("./sql_compiled");
66
+ Object.defineProperty(exports, "getCompiledSQL", { enumerable: true, get: function () { return sql_compiled_1.getCompiledSQL; } });
67
+ var source_def_utils_1 = require("./source_def_utils");
68
+ Object.defineProperty(exports, "mkSourceID", { enumerable: true, get: function () { return source_def_utils_1.mkSourceID; } });
69
+ Object.defineProperty(exports, "mkBuildID", { enumerable: true, get: function () { return source_def_utils_1.mkBuildID; } });
70
+ Object.defineProperty(exports, "mkQuerySourceDef", { enumerable: true, get: function () { return source_def_utils_1.mkQuerySourceDef; } });
71
+ Object.defineProperty(exports, "mkSQLSourceDef", { enumerable: true, get: function () { return source_def_utils_1.mkSQLSourceDef; } });
72
+ Object.defineProperty(exports, "mkTableSourceDef", { enumerable: true, get: function () { return source_def_utils_1.mkTableSourceDef; } });
73
+ Object.defineProperty(exports, "resolveSourceID", { enumerable: true, get: function () { return source_def_utils_1.resolveSourceID; } });
74
+ Object.defineProperty(exports, "registerSource", { enumerable: true, get: function () { return source_def_utils_1.registerSource; } });
75
+ Object.defineProperty(exports, "hasSourceRegistryEntry", { enumerable: true, get: function () { return source_def_utils_1.hasSourceRegistryEntry; } });
70
76
  //# sourceMappingURL=index.js.map