@malloydata/malloy 0.0.43 → 0.0.44-dev230623185845

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 (102) hide show
  1. package/dist/index.d.ts +2 -1
  2. package/dist/index.js +3 -1
  3. package/dist/lang/ast/elements/define-query.d.ts +7 -1
  4. package/dist/lang/ast/elements/define-query.js +10 -1
  5. package/dist/lang/ast/elements/define-source.d.ts +7 -1
  6. package/dist/lang/ast/elements/define-source.js +16 -9
  7. package/dist/lang/ast/elements/pipeline-desc.d.ts +2 -1
  8. package/dist/lang/ast/elements/pipeline-desc.js +6 -2
  9. package/dist/lang/ast/elements/refined-source.d.ts +5 -4
  10. package/dist/lang/ast/elements/refined-source.js +5 -0
  11. package/dist/lang/ast/expressions/expr-id-reference.js +4 -4
  12. package/dist/lang/ast/field-space/column-space-field.d.ts +1 -1
  13. package/dist/lang/ast/field-space/column-space-field.js +3 -3
  14. package/dist/lang/ast/field-space/field-definition-value.d.ts +1 -1
  15. package/dist/lang/ast/field-space/field-definition-value.js +16 -10
  16. package/dist/lang/ast/field-space/query-field-struct.js +1 -0
  17. package/dist/lang/ast/field-space/query-spaces.js +4 -1
  18. package/dist/lang/ast/field-space/reference-field.d.ts +8 -2
  19. package/dist/lang/ast/field-space/reference-field.js +51 -9
  20. package/dist/lang/ast/index.d.ts +2 -2
  21. package/dist/lang/ast/index.js +2 -2
  22. package/dist/lang/ast/query-elements/anonymous-query.d.ts +6 -1
  23. package/dist/lang/ast/query-elements/anonymous-query.js +8 -0
  24. package/dist/lang/ast/query-elements/existing-query.js +3 -0
  25. package/dist/lang/ast/query-elements/full-query.js +7 -4
  26. package/dist/lang/ast/query-elements/run-query.d.ts +6 -1
  27. package/dist/lang/ast/query-elements/run-query.js +11 -1
  28. package/dist/lang/ast/query-items/field-declaration.d.ts +6 -2
  29. package/dist/lang/ast/query-items/field-declaration.js +6 -0
  30. package/dist/lang/ast/query-items/field-references.d.ts +13 -5
  31. package/dist/lang/ast/query-items/field-references.js +10 -4
  32. package/dist/lang/ast/query-properties/aggregate.d.ts +3 -3
  33. package/dist/lang/ast/query-properties/aggregate.js +5 -4
  34. package/dist/lang/ast/query-properties/calculate.d.ts +3 -3
  35. package/dist/lang/ast/query-properties/calculate.js +5 -4
  36. package/dist/lang/ast/query-properties/declare-fields.d.ts +4 -3
  37. package/dist/lang/ast/query-properties/declare-fields.js +5 -4
  38. package/dist/lang/ast/query-properties/dimensions.d.ts +4 -0
  39. package/dist/lang/ast/query-properties/{dimmensions.js → dimensions.js} +4 -3
  40. package/dist/lang/ast/query-properties/extend.d.ts +1 -1
  41. package/dist/lang/ast/query-properties/extend.js +3 -2
  42. package/dist/lang/ast/query-properties/filters.d.ts +0 -1
  43. package/dist/lang/ast/query-properties/filters.js +2 -2
  44. package/dist/lang/ast/query-properties/group-by.d.ts +3 -3
  45. package/dist/lang/ast/query-properties/group-by.js +5 -4
  46. package/dist/lang/ast/query-properties/joins.d.ts +10 -4
  47. package/dist/lang/ast/query-properties/joins.js +16 -2
  48. package/dist/lang/ast/query-properties/measures.d.ts +1 -2
  49. package/dist/lang/ast/query-properties/measures.js +3 -2
  50. package/dist/lang/ast/query-properties/nest.d.ts +5 -1
  51. package/dist/lang/ast/query-properties/nest.js +11 -1
  52. package/dist/lang/ast/query-properties/nests.d.ts +3 -2
  53. package/dist/lang/ast/query-properties/nests.js +4 -3
  54. package/dist/lang/ast/query-properties/ordering.d.ts +1 -0
  55. package/dist/lang/ast/query-properties/ordering.js +2 -1
  56. package/dist/lang/ast/query-properties/project-statement.d.ts +3 -3
  57. package/dist/lang/ast/query-properties/project-statement.js +5 -4
  58. package/dist/lang/ast/query-properties/qop-desc.d.ts +1 -1
  59. package/dist/lang/ast/query-properties/qop-desc.js +3 -2
  60. package/dist/lang/ast/source-properties/renames.d.ts +1 -1
  61. package/dist/lang/ast/source-properties/renames.js +3 -2
  62. package/dist/lang/ast/source-properties/turtles.d.ts +3 -3
  63. package/dist/lang/ast/source-properties/turtles.js +5 -4
  64. package/dist/lang/ast/types/definition-list.d.ts +10 -0
  65. package/dist/lang/ast/types/definition-list.js +52 -0
  66. package/dist/lang/ast/types/malloy-element.d.ts +21 -6
  67. package/dist/lang/ast/types/malloy-element.js +45 -13
  68. package/dist/lang/ast/types/noteable.d.ts +12 -0
  69. package/dist/lang/ast/types/noteable.js +42 -0
  70. package/dist/lang/ast/types/query-extend-property.d.ts +1 -1
  71. package/dist/lang/ast/types/query-extend-property.js +2 -2
  72. package/dist/lang/ast/types/query-property.d.ts +3 -2
  73. package/dist/lang/ast/types/query-property.js +2 -0
  74. package/dist/lang/ast/types/source-desc.d.ts +5 -0
  75. package/dist/lang/ast/types/{explore-desc.js → source-desc.js} +7 -6
  76. package/dist/lang/ast/types/source-property.d.ts +2 -2
  77. package/dist/lang/ast/types/source-property.js +2 -0
  78. package/dist/lang/ast/types/space-field.d.ts +1 -0
  79. package/dist/lang/lib/Malloy/MalloyLexer.d.ts +56 -54
  80. package/dist/lang/lib/Malloy/MalloyLexer.js +1051 -1042
  81. package/dist/lang/lib/Malloy/MalloyParser.d.ts +326 -182
  82. package/dist/lang/lib/Malloy/MalloyParser.js +2894 -1718
  83. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +133 -19
  84. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +83 -11
  85. package/dist/lang/malloy-to-ast.d.ts +23 -10
  86. package/dist/lang/malloy-to-ast.js +144 -122
  87. package/dist/lang/parse-tree-walkers/document-symbol-walker.js +2 -1
  88. package/dist/lang/test/annotation.spec.d.ts +1 -0
  89. package/dist/lang/test/annotation.spec.js +565 -0
  90. package/dist/lang/test/parse.spec.js +20 -19
  91. package/dist/lang/test/test-translator.d.ts +2 -2
  92. package/dist/lang/test/test-translator.js +27 -15
  93. package/dist/malloy.d.ts +11 -5
  94. package/dist/malloy.js +16 -0
  95. package/dist/model/malloy_query.js +10 -0
  96. package/dist/model/malloy_types.d.ts +19 -2
  97. package/dist/model/malloy_types.js +1 -1
  98. package/dist/tags.d.ts +21 -0
  99. package/dist/tags.js +155 -0
  100. package/package.json +1 -1
  101. package/dist/lang/ast/query-properties/dimmensions.d.ts +0 -5
  102. package/dist/lang/ast/types/explore-desc.d.ts +0 -5
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { QueryDataRow, Fragment, StructDef, StructRelationship, NamedStructDefs, MalloyQueryData, AtomicFieldType as AtomicFieldTypeInner, DateUnit, ExtractUnit, TimestampUnit, TimeFieldType, QueryData, FieldTypeDef, Expr, DialectFragment, TimeValue, FilterExpression, SQLBlock, FieldAtomicDef, FieldDef, FilteredAliasedName, PipeSegment, QueryFieldDef, TurtleDef, SearchValueMapResult, SearchIndexResult, ModelDef, Query, QueryRunStats, NamedQuery, NamedModelObject, ExpressionType, FunctionDef, FunctionOverloadDef, FunctionParameterDef, ExpressionValueType, TypeDesc, FieldValueType, ExpressionTypeDesc, FunctionParamTypeDesc, DocumentLocation, DocumentRange, DocumentPosition, } from './model';
1
+ export type { QueryDataRow, Fragment, StructDef, StructRelationship, NamedStructDefs, MalloyQueryData, AtomicFieldType as AtomicFieldTypeInner, DateUnit, ExtractUnit, TimestampUnit, TimeFieldType, QueryData, FieldTypeDef, Expr, DialectFragment, TimeValue, FilterExpression, SQLBlock, FieldAtomicDef, FieldDef, FilteredAliasedName, PipeSegment, QueryFieldDef, TurtleDef, SearchValueMapResult, SearchIndexResult, ModelDef, Query, QueryRunStats, NamedQuery, NamedModelObject, ExpressionType, FunctionDef, FunctionOverloadDef, FunctionParameterDef, ExpressionValueType, TypeDesc, FieldValueType, ExpressionTypeDesc, FunctionParamTypeDesc, DocumentLocation, DocumentRange, DocumentPosition, Annotation, } from './model';
2
2
  export { Segment, isFilteredAliasedName, flattenQuery, expressionIsCalculation, } from './model';
3
3
  export { HighlightType, MalloyTranslator, } from './lang';
4
4
  export type { LogMessage, TranslateResponse } from './lang';
@@ -8,3 +8,4 @@ export type { RunSQLOptions } from './run_sql_options';
8
8
  export type { URLReader, InfoConnection, LookupConnection, Connection, QueryString, ModelString, QueryURL, ModelURL, PooledConnection, TestableConnection, PersistSQLResults, StreamingConnection, } from './runtime_types';
9
9
  export type { Loggable } from './malloy';
10
10
  export { toAsyncGenerator } from './connection_utils';
11
+ export { Tags, type MalloyTags } from './tags';
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.toAsyncGenerator = exports.Explore = exports.DataWriter = exports.Parse = exports.JSONWriter = exports.CSVWriter = exports.QueryMaterializer = exports.parseTableURI = exports.Result = exports.TimestampTimeframe = exports.DateTimeframe = exports.SourceRelationship = exports.JoinRelationship = exports.MalloyError = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.AtomicFieldType = exports.Runtime = exports.Malloy = exports.MalloyTranslator = exports.HighlightType = exports.expressionIsCalculation = exports.flattenQuery = exports.isFilteredAliasedName = exports.Segment = void 0;
25
+ exports.Tags = exports.toAsyncGenerator = exports.Explore = exports.DataWriter = exports.Parse = exports.JSONWriter = exports.CSVWriter = exports.QueryMaterializer = exports.parseTableURI = exports.Result = exports.TimestampTimeframe = exports.DateTimeframe = exports.SourceRelationship = exports.JoinRelationship = exports.MalloyError = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.AtomicFieldType = exports.Runtime = exports.Malloy = exports.MalloyTranslator = exports.HighlightType = exports.expressionIsCalculation = exports.flattenQuery = exports.isFilteredAliasedName = exports.Segment = void 0;
26
26
  var model_1 = require("./model");
27
27
  // Used in Composer Demo
28
28
  Object.defineProperty(exports, "Segment", { enumerable: true, get: function () { return model_1.Segment; } });
@@ -58,4 +58,6 @@ Object.defineProperty(exports, "DataWriter", { enumerable: true, get: function (
58
58
  Object.defineProperty(exports, "Explore", { enumerable: true, get: function () { return malloy_1.Explore; } });
59
59
  var connection_utils_1 = require("./connection_utils");
60
60
  Object.defineProperty(exports, "toAsyncGenerator", { enumerable: true, get: function () { return connection_utils_1.toAsyncGenerator; } });
61
+ var tags_1 = require("./tags");
62
+ Object.defineProperty(exports, "Tags", { enumerable: true, get: function () { return tags_1.Tags; } });
61
63
  //# sourceMappingURL=index.js.map
@@ -1,14 +1,20 @@
1
+ import { Annotation } from '../../../model/malloy_types';
1
2
  import { ModelDataRequest } from '../../translate-response';
2
3
  import { DocStatement, Document, MalloyElement, RunList } from '../types/malloy-element';
3
4
  import { QueryElement } from '../types/query-element';
4
- export declare class DefineQuery extends MalloyElement implements DocStatement {
5
+ import { Noteable, extendNoteMethod } from '../types/noteable';
6
+ export declare class DefineQuery extends MalloyElement implements DocStatement, Noteable {
5
7
  readonly name: string;
6
8
  readonly queryDetails: QueryElement;
7
9
  elementType: string;
8
10
  constructor(name: string, queryDetails: QueryElement);
11
+ readonly isNoteableObj = true;
12
+ extendNote: typeof extendNoteMethod;
13
+ note?: Annotation;
9
14
  execute(doc: Document): ModelDataRequest;
10
15
  }
11
16
  export declare class DefineQueryList extends RunList implements DocStatement {
17
+ elementType: string;
12
18
  constructor(queryList: DefineQuery[]);
13
19
  execute(doc: Document): ModelDataRequest;
14
20
  }
@@ -24,12 +24,15 @@
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.DefineQueryList = exports.DefineQuery = void 0;
26
26
  const malloy_element_1 = require("../types/malloy-element");
27
+ const noteable_1 = require("../types/noteable");
27
28
  class DefineQuery extends malloy_element_1.MalloyElement {
28
29
  constructor(name, queryDetails) {
29
30
  super({ queryDetails: queryDetails });
30
31
  this.name = name;
31
32
  this.queryDetails = queryDetails;
32
33
  this.elementType = 'defineQuery';
34
+ this.isNoteableObj = true;
35
+ this.extendNote = noteable_1.extendNoteMethod;
33
36
  }
34
37
  execute(doc) {
35
38
  const existing = doc.getEntry(this.name);
@@ -43,13 +46,19 @@ class DefineQuery extends malloy_element_1.MalloyElement {
43
46
  name: this.name,
44
47
  location: this.location,
45
48
  };
49
+ if (this.note) {
50
+ entry.annotation = entry.annotation
51
+ ? { ...this.note, inherits: entry.annotation }
52
+ : this.note;
53
+ }
46
54
  doc.setEntry(this.name, { entry, exported: true });
47
55
  }
48
56
  }
49
57
  exports.DefineQuery = DefineQuery;
50
58
  class DefineQueryList extends malloy_element_1.RunList {
51
59
  constructor(queryList) {
52
- super('defineQueries', queryList);
60
+ super(queryList);
61
+ this.elementType = 'defineQueries';
53
62
  }
54
63
  execute(doc) {
55
64
  return this.executeList(doc);
@@ -1,17 +1,23 @@
1
+ import { Annotation } from '../../../model/malloy_types';
1
2
  import { ModelDataRequest } from '../../translate-response';
2
3
  import { HasParameter } from '../parameters/has-parameter';
3
4
  import { DocStatement, Document, MalloyElement, RunList } from '../types/malloy-element';
5
+ import { Noteable, extendNoteMethod } from '../types/noteable';
4
6
  import { Source } from './source';
5
- export declare class DefineSource extends MalloyElement implements DocStatement {
7
+ export declare class DefineSource extends MalloyElement implements DocStatement, Noteable {
6
8
  readonly name: string;
7
9
  readonly theSource: Source;
8
10
  readonly exported: boolean;
9
11
  elementType: string;
10
12
  readonly parameters?: HasParameter[];
11
13
  constructor(name: string, theSource: Source, exported: boolean, params?: MalloyElement[]);
14
+ readonly isNoteableObj = true;
15
+ extendNote: typeof extendNoteMethod;
16
+ note?: Annotation;
12
17
  execute(doc: Document): ModelDataRequest;
13
18
  }
14
19
  export declare class DefineSourceList extends RunList implements DocStatement {
20
+ elementType: string;
15
21
  constructor(sourceList: DefineSource[]);
16
22
  execute(doc: Document): ModelDataRequest;
17
23
  }
@@ -26,6 +26,7 @@ exports.DefineSourceList = exports.DefineSource = void 0;
26
26
  const error_factory_1 = require("../error-factory");
27
27
  const has_parameter_1 = require("../parameters/has-parameter");
28
28
  const malloy_element_1 = require("../types/malloy-element");
29
+ const noteable_1 = require("../types/noteable");
29
30
  class DefineSource extends malloy_element_1.MalloyElement {
30
31
  constructor(name, theSource, exported, params) {
31
32
  super({ explore: theSource });
@@ -33,6 +34,8 @@ class DefineSource extends malloy_element_1.MalloyElement {
33
34
  this.theSource = theSource;
34
35
  this.exported = exported;
35
36
  this.elementType = 'defineSource';
37
+ this.isNoteableObj = true;
38
+ this.extendNote = noteable_1.extendNoteMethod;
36
39
  if (params) {
37
40
  this.parameters = [];
38
41
  for (const el of params) {
@@ -55,21 +58,25 @@ class DefineSource extends malloy_element_1.MalloyElement {
55
58
  if (error_factory_1.ErrorFactory.isErrorStructDef(structDef)) {
56
59
  return;
57
60
  }
58
- doc.setEntry(this.name, {
59
- entry: {
60
- ...structDef,
61
- as: this.name,
62
- location: this.location,
63
- },
64
- exported: this.exported,
65
- });
61
+ const entry = {
62
+ ...structDef,
63
+ as: this.name,
64
+ location: this.location,
65
+ };
66
+ if (this.note) {
67
+ entry.annotation = structDef.annotation
68
+ ? { ...this.note, inherits: structDef.annotation }
69
+ : this.note;
70
+ }
71
+ doc.setEntry(this.name, { entry, exported: this.exported });
66
72
  }
67
73
  }
68
74
  }
69
75
  exports.DefineSource = DefineSource;
70
76
  class DefineSourceList extends malloy_element_1.RunList {
71
77
  constructor(sourceList) {
72
- super('defineSources', sourceList);
78
+ super(sourceList);
79
+ this.elementType = 'defineSources';
73
80
  }
74
81
  execute(doc) {
75
82
  return this.executeList(doc);
@@ -1,4 +1,4 @@
1
- import { DocumentLocation, PipeSegment, Pipeline, StructDef } from '../../../model/malloy_types';
1
+ import { Annotation, DocumentLocation, PipeSegment, Pipeline, StructDef } from '../../../model/malloy_types';
2
2
  import { FieldSpace } from '../types/field-space';
3
3
  import { MalloyElement } from '../types/malloy-element';
4
4
  import { QOPDesc } from '../query-properties/qop-desc';
@@ -24,6 +24,7 @@ export declare abstract class PipelineDesc extends MalloyElement {
24
24
  protected expandTurtle(turtleName: string, fromStruct: StructDef): {
25
25
  pipeline: PipeSegment[];
26
26
  location: DocumentLocation | undefined;
27
+ annotation: Annotation | undefined;
27
28
  };
28
29
  protected getOutputStruct(walkStruct: StructDef, pipeline: PipeSegment[]): StructDef;
29
30
  }
@@ -80,6 +80,7 @@ class PipelineDesc extends malloy_element_1.MalloyElement {
80
80
  }
81
81
  expandTurtle(turtleName, fromStruct) {
82
82
  const turtle = (0, struct_utils_1.getStructFieldDef)(fromStruct, turtleName);
83
+ let annotation;
83
84
  if (!turtle) {
84
85
  this.log(`Query '${turtleName}' is not defined in source`);
85
86
  }
@@ -87,9 +88,12 @@ class PipelineDesc extends malloy_element_1.MalloyElement {
87
88
  this.log(`'${turtleName}' is not a query`);
88
89
  }
89
90
  else {
90
- return { pipeline: turtle.pipeline, location: turtle.location };
91
+ if (turtle.annotation) {
92
+ annotation = { inherits: turtle.annotation };
93
+ }
94
+ return { pipeline: turtle.pipeline, location: turtle.location, annotation };
91
95
  }
92
- return { pipeline: [], location: undefined };
96
+ return { pipeline: [], location: undefined, annotation };
93
97
  }
94
98
  getOutputStruct(walkStruct, pipeline) {
95
99
  for (const modelQop of pipeline) {
@@ -1,15 +1,16 @@
1
- import { StructDef } from '../../../model/malloy_types';
1
+ import { Annotation, StructDef } from '../../../model/malloy_types';
2
2
  import { HasParameter } from '../parameters/has-parameter';
3
- import { ExploreDesc } from '../types/explore-desc';
3
+ import { SourceDesc } from '../types/source-desc';
4
4
  import { Source } from './source';
5
5
  /**
6
6
  * A Source made from a source reference and a set of refinements
7
7
  */
8
8
  export declare class RefinedSource extends Source {
9
9
  readonly source: Source;
10
- readonly refinement: ExploreDesc;
10
+ readonly refinement: SourceDesc;
11
11
  elementType: string;
12
- constructor(source: Source, refinement: ExploreDesc);
12
+ currentAnnotation?: Annotation;
13
+ constructor(source: Source, refinement: SourceDesc);
13
14
  structDef(): StructDef;
14
15
  withParameters(pList: HasParameter[] | undefined): StructDef;
15
16
  }
@@ -38,6 +38,7 @@ const renames_1 = require("../source-properties/renames");
38
38
  const turtles_1 = require("../source-properties/turtles");
39
39
  const source_1 = require("./source");
40
40
  const timezone_statement_1 = require("../source-properties/timezone-statement");
41
+ const malloy_element_1 = require("../types/malloy-element");
41
42
  /**
42
43
  * A Source made from a source reference and a set of refinements
43
44
  */
@@ -58,6 +59,10 @@ class RefinedSource extends source_1.Source {
58
59
  const filters = [];
59
60
  let newTimezone;
60
61
  for (const el of this.refinement.list) {
62
+ if (el instanceof malloy_element_1.ObjectAnnotation) {
63
+ // Silently ignoring unclaimed annotations
64
+ continue;
65
+ }
61
66
  const errTo = el;
62
67
  if (el instanceof primary_key_1.PrimaryKey) {
63
68
  if (primaryKey) {
@@ -49,10 +49,10 @@ class ExprIdReference extends expression_def_1.ExpressionDef {
49
49
  const value = [{ type: def.found.refType, path: this.refString }];
50
50
  const td = def.found.typeDesc();
51
51
  // We think that aggregates are more 'output' like, but maybe we will reconsider that...
52
- if ((0, malloy_types_1.expressionIsAggregate)(td.expressionType)) {
53
- td.evalSpace = 'output';
54
- }
55
- return { ...td, value };
52
+ const evalSpace = (0, malloy_types_1.expressionIsAggregate)(td.expressionType)
53
+ ? 'output'
54
+ : td.evalSpace;
55
+ return { ...td, value, evalSpace };
56
56
  }
57
57
  this.log(def.error);
58
58
  return (0, ast_utils_1.errorFor)(def.error);
@@ -1,7 +1,7 @@
1
1
  import { FieldDef, FieldTypeDef, TypeDesc } from '../../../model/malloy_types';
2
2
  import { SpaceField } from '../types/space-field';
3
3
  export declare class ColumnSpaceField extends SpaceField {
4
- protected def: FieldTypeDef;
4
+ haveFieldDef: FieldDef;
5
5
  constructor(def: FieldTypeDef);
6
6
  fieldDef(): FieldDef;
7
7
  typeDesc(): TypeDesc;
@@ -27,13 +27,13 @@ const space_field_1 = require("../types/space-field");
27
27
  class ColumnSpaceField extends space_field_1.SpaceField {
28
28
  constructor(def) {
29
29
  super();
30
- this.def = def;
30
+ this.haveFieldDef = def;
31
31
  }
32
32
  fieldDef() {
33
- return this.def;
33
+ return this.haveFieldDef;
34
34
  }
35
35
  typeDesc() {
36
- return this.fieldTypeFromFieldDef(this.def);
36
+ return this.fieldTypeFromFieldDef(this.haveFieldDef);
37
37
  }
38
38
  }
39
39
  exports.ColumnSpaceField = ColumnSpaceField;
@@ -7,10 +7,10 @@ export declare class FieldDefinitionValue extends SpaceField {
7
7
  readonly space: FieldSpace;
8
8
  readonly exprDef: FieldDeclaration;
9
9
  fieldName: string;
10
- defType?: TypeDesc;
11
10
  constructor(space: FieldSpace, exprDef: FieldDeclaration);
12
11
  get name(): string;
13
12
  fieldDef(): model.FieldDef;
13
+ private qfd?;
14
14
  getQueryFieldDef(fs: FieldSpace): model.QueryFieldDef;
15
15
  typeDesc(): TypeDesc;
16
16
  }
@@ -34,21 +34,27 @@ class FieldDefinitionValue extends space_field_1.SpaceField {
34
34
  get name() {
35
35
  return this.fieldName;
36
36
  }
37
+ // A source will call this when it defines the field
37
38
  fieldDef() {
38
- const def = this.exprDef.fieldDef(this.space, this.name);
39
- this.defType = this.fieldTypeFromFieldDef(def);
40
- return def;
39
+ if (!this.haveFieldDef) {
40
+ this.haveFieldDef = this.exprDef.fieldDef(this.space, this.name);
41
+ }
42
+ return this.haveFieldDef;
41
43
  }
42
44
  getQueryFieldDef(fs) {
43
- const def = this.exprDef.queryFieldDef(fs, this.name);
44
- this.defType = this.fieldTypeFromFieldDef(def);
45
- return def;
45
+ if (!this.qfd) {
46
+ const def = this.exprDef.queryFieldDef(fs, this.name);
47
+ this.qfd = def;
48
+ }
49
+ return this.qfd;
46
50
  }
51
+ // If this is called before the expression has been evaluated, we don't
52
+ // really know what type we have. However since we have the FieldSpace,
53
+ // we can compile the expression to find out, this might result in
54
+ // some expressions being compiled twice.
47
55
  typeDesc() {
48
- if (this.defType) {
49
- return this.defType;
50
- }
51
- return this.fieldTypeFromFieldDef(this.fieldDef());
56
+ const typeFrom = this.qfd || this.fieldDef();
57
+ return this.fieldTypeFromFieldDef(typeFrom);
52
58
  }
53
59
  }
54
60
  exports.FieldDefinitionValue = FieldDefinitionValue;
@@ -28,6 +28,7 @@ class QueryFieldStruct extends query_space_field_1.QueryField {
28
28
  constructor(fs, turtleDef) {
29
29
  super(fs);
30
30
  this.turtleDef = turtleDef;
31
+ this.haveFieldDef = turtleDef;
31
32
  }
32
33
  rename(name) {
33
34
  this.turtleDef = {
@@ -261,7 +261,10 @@ class QuerySpace extends refined_space_1.RefinedSpace {
261
261
  }
262
262
  addQueryItems(...qiList) {
263
263
  for (const qi of qiList) {
264
- if (qi instanceof field_references_1.FieldReference || qi instanceof nest_reference_1.NestReference) {
264
+ if (qi instanceof nest_reference_1.NestReference) {
265
+ this.addReference(qi);
266
+ }
267
+ else if (qi instanceof field_references_1.FieldReference) {
265
268
  this.addReference(qi);
266
269
  }
267
270
  else if (qi instanceof field_declaration_1.FieldDeclaration) {
@@ -1,12 +1,18 @@
1
1
  import { QueryFieldDef, TypeDesc } from '../../../model/malloy_types';
2
2
  import { FieldReference } from '../query-items/field-references';
3
3
  import { FieldSpace } from '../types/field-space';
4
- import { LookupResult } from '../types/lookup-result';
4
+ import { SpaceEntry } from '../types/space-entry';
5
5
  import { SpaceField } from '../types/space-field';
6
6
  export declare class ReferenceField extends SpaceField {
7
7
  readonly fieldRef: FieldReference;
8
- res: LookupResult | undefined;
8
+ res?: SpaceEntry;
9
+ private queryFieldDef?;
9
10
  constructor(fieldRef: FieldReference);
10
11
  getQueryFieldDef(fs: FieldSpace): QueryFieldDef | undefined;
11
12
  typeDesc(): TypeDesc;
13
+ /**
14
+ * If the referenced field has any annotations, replace the reference
15
+ * with something which can hold an annotation
16
+ */
17
+ maybeAnnotate(): QueryFieldDef;
12
18
  }
@@ -23,30 +23,72 @@
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.ReferenceField = void 0;
26
+ const malloy_types_1 = require("../../../model/malloy_types");
26
27
  const space_field_1 = require("../types/space-field");
27
28
  class ReferenceField extends space_field_1.SpaceField {
28
29
  constructor(fieldRef) {
29
30
  super();
30
31
  this.fieldRef = fieldRef;
31
- this.res = undefined;
32
32
  }
33
33
  getQueryFieldDef(fs) {
34
- // Lookup string and generate error if it isn't defined.
35
- const check = this.fieldRef.getField(fs);
36
- if (check.error) {
37
- this.fieldRef.log(check.error);
34
+ if (!this.queryFieldDef) {
35
+ const check = this.fieldRef.getField(fs);
36
+ if (check.error) {
37
+ this.fieldRef.log(check.error);
38
+ }
39
+ this.res = check.found;
40
+ this.queryFieldDef = this.maybeAnnotate();
38
41
  }
39
- this.res = check;
40
- return this.fieldRef.refString;
42
+ return this.queryFieldDef;
41
43
  }
42
44
  typeDesc() {
43
45
  // Remember the actual type of the field that was looked up so it can be used for
44
46
  // type checking.
45
- if (this.res !== undefined && this.res.found) {
46
- return this.res.found.typeDesc();
47
+ if (this.res !== undefined) {
48
+ return this.res.typeDesc();
47
49
  }
48
50
  return { dataType: 'error', expressionType: 'scalar', evalSpace: 'input' };
49
51
  }
52
+ /**
53
+ * If the referenced field has any annotations, replace the reference
54
+ * with something which can hold an annotation
55
+ */
56
+ maybeAnnotate() {
57
+ const path = this.fieldRef.refString;
58
+ if (this.res instanceof space_field_1.SpaceField &&
59
+ this.res.haveFieldDef &&
60
+ typeof this.res.haveFieldDef !== 'string') {
61
+ const origFd = this.res.haveFieldDef;
62
+ if ((0, malloy_types_1.isFilteredAliasedName)(origFd)) {
63
+ return origFd;
64
+ }
65
+ const notes = this.fieldRef.note;
66
+ if (origFd.annotation || notes) {
67
+ const annotation = notes || {};
68
+ if (origFd.annotation) {
69
+ annotation.inherits = origFd.annotation;
70
+ }
71
+ if (this.fieldRef.list.length > 1) {
72
+ // This is a field inside a join or a record, create an expression
73
+ // and annotate the expression.
74
+ if ((0, malloy_types_1.isAtomicFieldType)(origFd.type)) {
75
+ const newField = {
76
+ name: this.fieldRef.list[-1].refString,
77
+ type: origFd.type,
78
+ e: [{ type: 'field', path }],
79
+ annotation,
80
+ };
81
+ return newField;
82
+ }
83
+ // maybe ok, this likely is some field which cannot be referenced
84
+ // in a query and will error, so there would be nothing to annotate
85
+ return path;
86
+ }
87
+ return { ...origFd, annotation };
88
+ }
89
+ }
90
+ return path;
91
+ }
50
92
  }
51
93
  exports.ReferenceField = ReferenceField;
52
94
  //# sourceMappingURL=reference-field.js.map
@@ -62,7 +62,7 @@ export * from './query-items/field-references';
62
62
  export * from './query-properties/aggregate';
63
63
  export * from './query-properties/calculate';
64
64
  export * from './query-properties/declare-fields';
65
- export * from './query-properties/dimmensions';
65
+ export * from './query-properties/dimensions';
66
66
  export * from './query-properties/filters';
67
67
  export * from './query-properties/group-by';
68
68
  export * from './query-properties/indexing';
@@ -82,7 +82,7 @@ export * from './sources/table-source';
82
82
  export * from './sql-elements/sql-statement';
83
83
  export * from './sql-elements/sql-string';
84
84
  export * from './types/comparison';
85
- export * from './types/explore-desc';
85
+ export * from './types/source-desc';
86
86
  export * from './types/source-property';
87
87
  export * from './types/expression-def';
88
88
  export * from './types/field-collection-member';
@@ -100,7 +100,7 @@ __exportStar(require("./query-items/field-references"), exports);
100
100
  __exportStar(require("./query-properties/aggregate"), exports);
101
101
  __exportStar(require("./query-properties/calculate"), exports);
102
102
  __exportStar(require("./query-properties/declare-fields"), exports);
103
- __exportStar(require("./query-properties/dimmensions"), exports);
103
+ __exportStar(require("./query-properties/dimensions"), exports);
104
104
  __exportStar(require("./query-properties/filters"), exports);
105
105
  __exportStar(require("./query-properties/group-by"), exports);
106
106
  __exportStar(require("./query-properties/indexing"), exports);
@@ -120,7 +120,7 @@ __exportStar(require("./sources/table-source"), exports);
120
120
  __exportStar(require("./sql-elements/sql-statement"), exports);
121
121
  __exportStar(require("./sql-elements/sql-string"), exports);
122
122
  __exportStar(require("./types/comparison"), exports);
123
- __exportStar(require("./types/explore-desc"), exports);
123
+ __exportStar(require("./types/source-desc"), exports);
124
124
  __exportStar(require("./types/source-property"), exports);
125
125
  __exportStar(require("./types/expression-def"), exports);
126
126
  __exportStar(require("./types/field-collection-member"), exports);
@@ -1,9 +1,14 @@
1
+ import { Annotation } from '../../../model';
1
2
  import { ModelDataRequest } from '../../translate-response';
2
3
  import { DocStatement, Document, MalloyElement } from '../types/malloy-element';
3
4
  import { QueryElement } from '../types/query-element';
4
- export declare class AnonymousQuery extends MalloyElement implements DocStatement {
5
+ import { Noteable, extendNoteMethod } from '../types/noteable';
6
+ export declare class AnonymousQuery extends MalloyElement implements DocStatement, Noteable {
5
7
  readonly theQuery: QueryElement;
6
8
  elementType: string;
7
9
  constructor(theQuery: QueryElement);
10
+ readonly isNoteableObj = true;
11
+ extendNote: typeof extendNoteMethod;
12
+ note?: Annotation;
8
13
  execute(doc: Document): ModelDataRequest;
9
14
  }
@@ -24,15 +24,23 @@
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.AnonymousQuery = void 0;
26
26
  const malloy_element_1 = require("../types/malloy-element");
27
+ const noteable_1 = require("../types/noteable");
27
28
  class AnonymousQuery extends malloy_element_1.MalloyElement {
28
29
  constructor(theQuery) {
29
30
  super();
30
31
  this.theQuery = theQuery;
31
32
  this.elementType = 'anonymousQuery';
33
+ this.isNoteableObj = true;
34
+ this.extendNote = noteable_1.extendNoteMethod;
32
35
  this.has({ query: theQuery });
33
36
  }
34
37
  execute(doc) {
35
38
  const modelQuery = this.theQuery.query();
39
+ if (this.note) {
40
+ modelQuery.annotation = modelQuery.annotation
41
+ ? { ...this.note, inherits: modelQuery.annotation }
42
+ : this.note;
43
+ }
36
44
  doc.queryList.push(modelQuery);
37
45
  return undefined;
38
46
  }
@@ -69,6 +69,9 @@ class ExistingQuery extends pipeline_desc_1.PipelineDesc {
69
69
  structRef: isRefOk ? queryHead.structRef() : queryHead.structDef(),
70
70
  location: this.location,
71
71
  };
72
+ if (seedQuery.annotation) {
73
+ query.annotation = seedQuery.annotation;
74
+ }
72
75
  return { outputStruct: appended.structDef, query };
73
76
  }
74
77
  query() {
@@ -56,11 +56,11 @@ class FullQuery extends turtle_headed_pipe_1.TurtleHeadedPipe {
56
56
  };
57
57
  }
58
58
  if (this.turtleName) {
59
- const { error } = this.turtleName.getField(pipeFs);
60
- if (error)
61
- this.log(error);
59
+ const lookFor = this.turtleName.getField(pipeFs);
60
+ if (lookFor.error)
61
+ this.log(lookFor.error);
62
62
  const name = this.turtleName.refString;
63
- const { pipeline, location } = this.expandTurtle(name, structDef);
63
+ const { pipeline, location, annotation } = this.expandTurtle(name, structDef);
64
64
  destQuery.location = location;
65
65
  const refined = this.refinePipeline(pipeFs, { pipeline }).pipeline;
66
66
  if (this.headRefinement) {
@@ -72,6 +72,9 @@ class FullQuery extends turtle_headed_pipe_1.TurtleHeadedPipe {
72
72
  else {
73
73
  destQuery.pipeHead = { name };
74
74
  }
75
+ if (annotation) {
76
+ destQuery.annotation = annotation;
77
+ }
75
78
  const pipeStruct = this.getOutputStruct(structDef, refined);
76
79
  pipeFs = new static_space_1.StaticSpace(pipeStruct);
77
80
  }
@@ -1,12 +1,17 @@
1
+ import { Annotation } from '../../../model';
1
2
  import { ModelDataRequest } from '../../translate-response';
2
3
  import { DocStatement, Document, MalloyElement, ModelEntryReference } from '../types/malloy-element';
4
+ import { Noteable, extendNoteMethod } from '../types/noteable';
3
5
  import { QueryElement } from '../types/query-element';
4
6
  declare abstract class RunQuery extends MalloyElement implements DocStatement {
5
7
  elementType: string;
6
8
  abstract execute(doc: Document): ModelDataRequest;
7
9
  }
8
- export declare class RunQueryDef extends RunQuery {
10
+ export declare class RunQueryDef extends RunQuery implements Noteable {
9
11
  readonly theQuery: QueryElement;
12
+ note?: Annotation;
13
+ readonly isNoteableObj = true;
14
+ extendNote: typeof extendNoteMethod;
10
15
  constructor(theQuery: QueryElement);
11
16
  execute(doc: Document): ModelDataRequest;
12
17
  }
@@ -24,6 +24,7 @@
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.RunQueryRef = exports.RunQueryDef = void 0;
26
26
  const malloy_element_1 = require("../types/malloy-element");
27
+ const noteable_1 = require("../types/noteable");
27
28
  class RunQuery extends malloy_element_1.MalloyElement {
28
29
  constructor() {
29
30
  super(...arguments);
@@ -34,10 +35,19 @@ class RunQueryDef extends RunQuery {
34
35
  constructor(theQuery) {
35
36
  super();
36
37
  this.theQuery = theQuery;
38
+ this.isNoteableObj = true;
39
+ this.extendNote = noteable_1.extendNoteMethod;
37
40
  this.has({ query: theQuery });
38
41
  }
39
42
  execute(doc) {
40
- const modelQuery = this.theQuery.query();
43
+ let modelQuery = this.theQuery.query();
44
+ const annotation = this.note || {};
45
+ if (modelQuery.annotation) {
46
+ annotation.inherits = modelQuery.annotation;
47
+ }
48
+ if (annotation.notes || annotation.blockNotes || annotation.inherits) {
49
+ modelQuery = { ...modelQuery, annotation };
50
+ }
41
51
  doc.queryList.push(modelQuery);
42
52
  return undefined;
43
53
  }