@malloydata/malloy 0.0.195-dev241003204905 → 0.0.195-dev241007154000

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 (144) hide show
  1. package/dist/connection/base_connection.d.ts +21 -7
  2. package/dist/connection/base_connection.js +62 -0
  3. package/dist/connection/types.d.ts +5 -5
  4. package/dist/dialect/dialect.d.ts +5 -3
  5. package/dist/dialect/dialect.js +15 -0
  6. package/dist/dialect/duckdb/duckdb.d.ts +3 -3
  7. package/dist/dialect/duckdb/duckdb.js +8 -3
  8. package/dist/dialect/postgres/postgres.d.ts +3 -3
  9. package/dist/dialect/postgres/postgres.js +5 -2
  10. package/dist/dialect/snowflake/snowflake.d.ts +3 -3
  11. package/dist/dialect/snowflake/snowflake.js +4 -1
  12. package/dist/dialect/standardsql/standardsql.d.ts +3 -3
  13. package/dist/dialect/standardsql/standardsql.js +5 -2
  14. package/dist/dialect/trino/trino.d.ts +3 -3
  15. package/dist/dialect/trino/trino.js +35 -3
  16. package/dist/index.d.ts +4 -4
  17. package/dist/index.js +6 -2
  18. package/dist/lang/ast/error-factory.d.ts +4 -3
  19. package/dist/lang/ast/error-factory.js +27 -17
  20. package/dist/lang/ast/expressions/constant-expression.d.ts +1 -0
  21. package/dist/lang/ast/expressions/constant-expression.js +3 -0
  22. package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +3 -7
  23. package/dist/lang/ast/expressions/expr-aggregate-function.js +50 -54
  24. package/dist/lang/ast/expressions/expr-cast.js +2 -4
  25. package/dist/lang/ast/expressions/expr-func.js +1 -1
  26. package/dist/lang/ast/expressions/expr-granular-time.js +1 -1
  27. package/dist/lang/ast/expressions/expr-record-literal.d.ts +16 -0
  28. package/dist/lang/ast/expressions/expr-record-literal.js +57 -0
  29. package/dist/lang/ast/expressions/expr-time-extract.js +3 -3
  30. package/dist/lang/ast/expressions/expr-time.d.ts +3 -3
  31. package/dist/lang/ast/expressions/expr-time.js +1 -1
  32. package/dist/lang/ast/expressions/time-literal.d.ts +6 -6
  33. package/dist/lang/ast/expressions/time-literal.js +1 -1
  34. package/dist/lang/ast/field-space/column-space-field.d.ts +6 -5
  35. package/dist/lang/ast/field-space/column-space-field.js +7 -4
  36. package/dist/lang/ast/field-space/dynamic-space.d.ts +8 -6
  37. package/dist/lang/ast/field-space/dynamic-space.js +35 -11
  38. package/dist/lang/ast/field-space/index-field-space.js +6 -3
  39. package/dist/lang/ast/field-space/ir-view-field.d.ts +1 -0
  40. package/dist/lang/ast/field-space/ir-view-field.js +3 -1
  41. package/dist/lang/ast/field-space/join-space-field.d.ts +2 -2
  42. package/dist/lang/ast/field-space/join-space-field.js +2 -2
  43. package/dist/lang/ast/field-space/parameter-space.d.ts +1 -0
  44. package/dist/lang/ast/field-space/parameter-space.js +4 -1
  45. package/dist/lang/ast/field-space/query-input-space.d.ts +4 -4
  46. package/dist/lang/ast/field-space/query-input-space.js +3 -5
  47. package/dist/lang/ast/field-space/query-spaces.d.ts +4 -4
  48. package/dist/lang/ast/field-space/query-spaces.js +1 -1
  49. package/dist/lang/ast/field-space/reference-field.js +10 -8
  50. package/dist/lang/ast/field-space/refined-space.d.ts +2 -2
  51. package/dist/lang/ast/field-space/static-space.d.ts +14 -5
  52. package/dist/lang/ast/field-space/static-space.js +45 -20
  53. package/dist/lang/ast/field-space/struct-space-field-base.d.ts +6 -5
  54. package/dist/lang/ast/field-space/struct-space-field-base.js +12 -4
  55. package/dist/lang/ast/index.d.ts +2 -1
  56. package/dist/lang/ast/index.js +2 -1
  57. package/dist/lang/ast/query-builders/index-builder.d.ts +2 -2
  58. package/dist/lang/ast/query-builders/project-builder.d.ts +2 -2
  59. package/dist/lang/ast/query-builders/reduce-builder.d.ts +2 -2
  60. package/dist/lang/ast/query-elements/query-arrow.js +2 -2
  61. package/dist/lang/ast/query-elements/query-head-struct.d.ts +2 -2
  62. package/dist/lang/ast/query-elements/query-head-struct.js +2 -2
  63. package/dist/lang/ast/query-elements/query-raw.js +2 -2
  64. package/dist/lang/ast/query-elements/query-reference.js +1 -1
  65. package/dist/lang/ast/query-items/field-declaration.d.ts +8 -6
  66. package/dist/lang/ast/query-items/field-declaration.js +66 -24
  67. package/dist/lang/ast/query-properties/qop-desc.d.ts +2 -2
  68. package/dist/lang/ast/query-properties/qop-desc.js +1 -1
  69. package/dist/lang/ast/source-elements/named-source.d.ts +4 -4
  70. package/dist/lang/ast/source-elements/named-source.js +16 -8
  71. package/dist/lang/ast/source-elements/query-source.d.ts +3 -3
  72. package/dist/lang/ast/source-elements/query-source.js +5 -2
  73. package/dist/lang/ast/source-elements/refined-source.d.ts +3 -3
  74. package/dist/lang/ast/source-elements/refined-source.js +4 -4
  75. package/dist/lang/ast/source-elements/source.d.ts +2 -2
  76. package/dist/lang/ast/source-elements/source.js +2 -2
  77. package/dist/lang/ast/source-elements/sql-source.d.ts +4 -4
  78. package/dist/lang/ast/source-elements/sql-source.js +6 -6
  79. package/dist/lang/ast/source-elements/table-source.d.ts +2 -2
  80. package/dist/lang/ast/source-elements/table-source.js +1 -1
  81. package/dist/lang/ast/source-properties/{joins.d.ts → join.d.ts} +11 -14
  82. package/dist/lang/ast/source-properties/{joins.js → join.js} +35 -52
  83. package/dist/lang/ast/source-query-elements/sq-reference.js +6 -5
  84. package/dist/lang/ast/sql-elements/sql-string.d.ts +2 -2
  85. package/dist/lang/ast/statements/define-source.js +1 -1
  86. package/dist/lang/ast/struct-utils.d.ts +3 -3
  87. package/dist/lang/ast/struct-utils.js +12 -3
  88. package/dist/lang/ast/time-utils.d.ts +3 -3
  89. package/dist/lang/ast/types/document-compile-result.d.ts +2 -2
  90. package/dist/lang/ast/types/expression-def.js +4 -4
  91. package/dist/lang/ast/types/field-space.d.ts +8 -3
  92. package/dist/lang/ast/types/lookup-result.d.ts +8 -5
  93. package/dist/lang/ast/types/malloy-element.d.ts +3 -3
  94. package/dist/lang/ast/types/malloy-element.js +10 -21
  95. package/dist/lang/ast/types/op-desc.d.ts +2 -2
  96. package/dist/lang/ast/types/pipeline-comp.d.ts +2 -2
  97. package/dist/lang/ast/types/query-comp.d.ts +3 -3
  98. package/dist/lang/ast/types/query-extend-property.d.ts +1 -2
  99. package/dist/lang/ast/types/query-extend-property.js +4 -2
  100. package/dist/lang/ast/types/source-property.d.ts +2 -2
  101. package/dist/lang/ast/types/source-property.js +2 -2
  102. package/dist/lang/ast/types/space-field.d.ts +10 -3
  103. package/dist/lang/ast/types/space-field.js +11 -2
  104. package/dist/lang/ast/types/time-result.d.ts +2 -2
  105. package/dist/lang/ast/view-elements/qop-desc-view.d.ts +3 -3
  106. package/dist/lang/ast/view-elements/qop-desc-view.js +1 -1
  107. package/dist/lang/ast/view-elements/reference-view.d.ts +4 -4
  108. package/dist/lang/ast/view-elements/reference-view.js +2 -6
  109. package/dist/lang/ast/view-elements/view-refine.d.ts +2 -2
  110. package/dist/lang/index.d.ts +1 -1
  111. package/dist/lang/lib/Malloy/MalloyParser.d.ts +54 -21
  112. package/dist/lang/lib/Malloy/MalloyParser.js +1647 -1457
  113. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +57 -9
  114. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +35 -5
  115. package/dist/lang/malloy-to-ast.d.ts +4 -4
  116. package/dist/lang/malloy-to-ast.js +32 -4
  117. package/dist/lang/parse-log.d.ts +5 -9
  118. package/dist/lang/parse-malloy.d.ts +10 -10
  119. package/dist/lang/parse-malloy.js +2 -1
  120. package/dist/lang/test/annotation.spec.js +7 -1
  121. package/dist/lang/test/field-symbols.spec.js +21 -25
  122. package/dist/lang/test/imports.spec.js +12 -10
  123. package/dist/lang/test/lenses.spec.js +2 -2
  124. package/dist/lang/test/model_serialization.spec.d.ts +4 -4
  125. package/dist/lang/test/model_serialization.spec.js +19 -31
  126. package/dist/lang/test/parse.spec.js +3 -4
  127. package/dist/lang/test/query.spec.js +3 -2
  128. package/dist/lang/test/source.spec.js +7 -0
  129. package/dist/lang/test/sql-block.spec.js +8 -19
  130. package/dist/lang/test/test-translator.d.ts +4 -4
  131. package/dist/lang/test/test-translator.js +53 -61
  132. package/dist/lang/translate-response.d.ts +3 -3
  133. package/dist/malloy.d.ts +31 -149
  134. package/dist/malloy.js +109 -267
  135. package/dist/model/malloy_query.d.ts +25 -23
  136. package/dist/model/malloy_query.js +262 -323
  137. package/dist/model/malloy_types.d.ts +145 -155
  138. package/dist/model/malloy_types.js +81 -84
  139. package/dist/model/sql_block.d.ts +4 -4
  140. package/dist/model/sql_block.js +9 -12
  141. package/dist/tags.js +2 -2
  142. package/package.json +1 -1
  143. package/dist/lang/ast/space-seed.d.ts +0 -16
  144. package/dist/lang/ast/space-seed.js +0 -59
@@ -24,7 +24,7 @@ export type AnyExpr = ExprE | ExprOptionalE | ExprWithKids | ExprLeaf;
24
24
  export declare function exprHasKids(e: AnyExpr): e is ExprWithKids;
25
25
  export declare function exprHasE(e: AnyExpr): e is ExprE;
26
26
  export declare function exprIsLeaf(e: AnyExpr): boolean;
27
- export type Expr = BinaryExpr | UnaryExpr | FunctionCallNode | OutputFieldNode | FilterCondition | FilteredExpr | AggregateExpr | EmptyExpr | UngroupNode | FunctionParameterNode | SpreadExpr | AggregateOrderByNode | AggregateLimitNode | FieldnameNode | SourceReferenceNode | ParameterNode | NowNode | MeasureTimeExpr | TimeDeltaExpr | TimeTruncExpr | TimeExtractExpr | TypecastExpr | RegexMatchExpr | RegexLiteralNode | TimeLiteralNode | StringLiteralNode | NumberLiteralNode | BooleanLiteralNode | FunctionOrderBy | GenericSQLExpr | NullNode | PickExpr | ErrorNode;
27
+ export type Expr = BinaryExpr | UnaryExpr | FunctionCallNode | OutputFieldNode | FilterCondition | FilteredExpr | AggregateExpr | EmptyExpr | UngroupNode | FunctionParameterNode | SpreadExpr | AggregateOrderByNode | AggregateLimitNode | FieldnameNode | SourceReferenceNode | ParameterNode | NowNode | MeasureTimeExpr | TimeDeltaExpr | TimeTruncExpr | TimeExtractExpr | TypecastExpr | RegexMatchExpr | RegexLiteralNode | TimeLiteralNode | StringLiteralNode | NumberLiteralNode | BooleanLiteralNode | RecordLiteralNode | ArrayLiteralNode | FunctionOrderBy | GenericSQLExpr | NullNode | PickExpr | ArrayEachExpr | ErrorNode;
28
28
  interface HasDataType {
29
29
  dataType: AtomicFieldType;
30
30
  }
@@ -118,7 +118,7 @@ export interface NowNode extends ExprLeaf {
118
118
  node: 'now';
119
119
  }
120
120
  interface HasTimeValue {
121
- dataType: TimeFieldType;
121
+ dataType: TemporalFieldType;
122
122
  }
123
123
  type TimeExpr = Expr & HasTimeValue;
124
124
  export interface MeasureTimeExpr extends ExprWithKids {
@@ -167,7 +167,7 @@ export interface RegexMatchExpr extends ExprWithKids {
167
167
  export interface TimeLiteralNode extends ExprLeaf {
168
168
  node: 'timeLiteral';
169
169
  literal: string;
170
- dataType: TimeFieldType;
170
+ dataType: TemporalFieldType;
171
171
  timezone?: string;
172
172
  }
173
173
  export interface StringLiteralNode extends ExprLeaf {
@@ -185,6 +185,17 @@ export interface NumberLiteralNode extends ExprLeaf {
185
185
  export interface BooleanLiteralNode extends ExprLeaf {
186
186
  node: 'true' | 'false';
187
187
  }
188
+ export interface RecordLiteralNode extends ExprWithKids {
189
+ node: 'recordLiteral';
190
+ kids: Record<string, TypedExpr>;
191
+ }
192
+ export interface ArrayLiteralNode extends ExprWithKids {
193
+ node: 'arrayLiteral';
194
+ kids: {
195
+ values: Expr[];
196
+ };
197
+ dataType: AtomicFieldType;
198
+ }
188
199
  export interface ErrorNode extends ExprLeaf {
189
200
  node: 'error';
190
201
  message?: string;
@@ -207,6 +218,9 @@ export interface PickExpr extends ExprWithKids {
207
218
  pickElse: Expr;
208
219
  };
209
220
  }
221
+ export interface ArrayEachExpr extends ExprLeaf {
222
+ node: 'arrayEach';
223
+ }
210
224
  export type ExpressionType = 'scalar' | 'aggregate' | 'scalar_analytic' | 'aggregate_analytic' | 'ungrouped_aggregate';
211
225
  export interface Expression {
212
226
  e?: Expr;
@@ -252,7 +266,7 @@ export interface DocumentJoinReference extends DocumentReferenceBase {
252
266
  }
253
267
  export interface DocumentSQLBlockReference extends DocumentReferenceBase {
254
268
  type: 'sqlBlockReference';
255
- definition: SQLBlockStructDef;
269
+ definition: SQLSourceDef;
256
270
  }
257
271
  export interface DocumentQueryReference extends DocumentReferenceBase {
258
272
  type: 'queryReference';
@@ -272,9 +286,6 @@ export interface AliasedName {
272
286
  name: string;
273
287
  as?: string;
274
288
  }
275
- export interface TypedObject {
276
- type: string;
277
- }
278
289
  /** all named objects have a type an a name (optionally aliased) */
279
290
  export interface NamedObject extends AliasedName, HasLocation {
280
291
  type: string;
@@ -306,15 +317,14 @@ export declare function expressionIsAnalytic(e: ExpressionType | undefined): boo
306
317
  export declare function isExpressionTypeLEQ(e1: ExpressionType, e2: ExpressionType): boolean;
307
318
  export declare function maxExpressionType(e1: ExpressionType, e2: ExpressionType): ExpressionType;
308
319
  export declare function maxOfExpressionTypes(types: ExpressionType[]): ExpressionType;
309
- type HasExpression = FieldDef & Expression & {
320
+ /** Grants access to the expression properties of a FieldDef */
321
+ export declare function hasExpression<T extends FieldDef>(f: T): f is T & Expression & {
310
322
  e: Expr;
311
323
  };
312
- /** Grants access to the expression property of a FieldDef */
313
- export declare function hasExpression(f: FieldDef): f is HasExpression;
314
- export type TimeFieldType = 'date' | 'timestamp';
315
- export declare function isTimeFieldType(s: string): s is TimeFieldType;
316
- export type CastType = 'string' | 'number' | TimeFieldType | 'boolean' | 'json';
317
- export type AtomicFieldType = CastType | 'sql native' | 'error';
324
+ export type TemporalFieldType = 'date' | 'timestamp';
325
+ export declare function isTemporalField(s: string): s is TemporalFieldType;
326
+ export type CastType = 'string' | 'number' | TemporalFieldType | 'boolean' | 'json';
327
+ export type AtomicFieldType = CastType | 'sql native' | 'record' | 'array' | 'error';
318
328
  export declare function isAtomicFieldType(s: string): s is AtomicFieldType;
319
329
  export declare function isCastType(s: string): s is CastType;
320
330
  /**
@@ -322,56 +332,84 @@ export declare function isCastType(s: string): s is CastType;
322
332
  * value could be an expression, and this is one of the objects
323
333
  * which might have an annotation.
324
334
  */
325
- export interface FieldAtomicDef extends NamedObject, Expression, ResultMetadata {
326
- type: AtomicFieldType;
335
+ export interface FieldBase extends NamedObject, Expression, ResultMetadata {
327
336
  annotation?: Annotation;
328
337
  }
329
- export declare function FieldIsIntrinsic(f: FieldDef): boolean;
330
- export interface FieldStringTypeDef {
338
+ interface FieldAtomicBase extends FieldBase {
339
+ type: AtomicFieldType;
340
+ }
341
+ export declare function fieldIsIntrinsic(f: FieldDef): boolean;
342
+ export interface StringTypeDef {
331
343
  type: 'string';
332
344
  bucketFilter?: string;
333
345
  bucketOther?: string;
334
346
  }
335
- /** Scalar String Field */
336
- export interface FieldStringDef extends FieldAtomicDef, FieldStringTypeDef {
337
- type: 'string';
338
- }
339
- export interface FieldNumberTypeDef {
347
+ export type StringFieldDef = StringTypeDef & AtomicFieldDef;
348
+ export interface NumberTypeDef {
340
349
  type: 'number';
341
350
  numberType?: 'integer' | 'float';
342
351
  }
343
- /** Scalar Numeric String Field */
344
- export interface FieldNumberDef extends FieldAtomicDef, FieldNumberTypeDef {
345
- type: 'number';
346
- }
347
- export interface FieldBooleanTypeDef {
348
- type: 'boolean';
349
- }
350
- /** Scalar Boolean Field */
351
- export interface FieldBooleanDef extends FieldAtomicDef, FieldBooleanTypeDef {
352
+ export type NumberFieldDef = NumberTypeDef & AtomicFieldDef;
353
+ export interface BooleanTypeDef {
352
354
  type: 'boolean';
353
355
  }
354
- export interface FieldJSONTypeDef {
355
- type: 'json';
356
- }
357
- /** Scalar JSON Field */
358
- export interface FieldJSONDef extends FieldAtomicDef, FieldJSONTypeDef {
356
+ export type BooleanFieldDef = BooleanTypeDef & AtomicFieldDef;
357
+ export interface JSONTypeDef {
359
358
  type: 'json';
360
359
  }
361
- export interface FieldNativeUnsupportedTypeDef {
360
+ export type JSONFieldDef = JSONTypeDef & AtomicFieldDef;
361
+ export interface NativeUnsupportedTypeDef {
362
362
  type: 'sql native';
363
363
  rawType?: string;
364
364
  }
365
- /** Scalar unsupported Field */
366
- export interface FeldNativeUnsupportedDef extends FieldAtomicDef, FieldNativeUnsupportedTypeDef {
367
- type: 'sql native';
368
- }
369
- export interface FieldErrorTypeDef {
365
+ export type NativeUnsupportedFieldDef = NativeUnsupportedTypeDef & AtomicFieldDef;
366
+ export interface ArrayTypeDef {
367
+ type: 'array';
368
+ elementTypeDef: Exclude<AtomicTypeDef, RecordTypeDef> | RecordElementTypeDef;
369
+ }
370
+ export type ArrayFieldDef = ArrayTypeDef & AtomicFieldDef;
371
+ export interface JoinedArrayTypeDef extends ArrayTypeDef, JoinBase, StructDefBase {
372
+ type: 'array';
373
+ join: 'many';
374
+ }
375
+ export type JoinedArrayDef = JoinedArrayTypeDef & AtomicFieldDef;
376
+ export declare function arrayEachFields(arrayOf: AtomicTypeDef): AtomicFieldDef[];
377
+ export interface RecordTypeDef extends StructDefBase, JoinBase {
378
+ type: 'record';
379
+ join: 'one';
380
+ }
381
+ export interface RecordElementTypeDef {
382
+ type: 'record_element';
383
+ }
384
+ export interface RepeatedRecordTypeDef extends JoinedArrayTypeDef {
385
+ type: 'array';
386
+ elementTypeDef: RecordElementTypeDef;
387
+ join: 'many';
388
+ }
389
+ export type RecordFieldDef = RecordTypeDef & AtomicFieldDef;
390
+ export type RepeatedRecordFieldDef = RepeatedRecordTypeDef & AtomicFieldDef;
391
+ export declare function isRepeatedRecord(fd: FieldDef): fd is RepeatedRecordFieldDef;
392
+ export interface ErrorTypeDef {
370
393
  type: 'error';
371
394
  }
372
- export interface FieldErrorDef extends FieldAtomicDef, FieldErrorTypeDef {
373
- type: 'error';
395
+ export type ErrorFieldDef = ErrorTypeDef & AtomicFieldDef;
396
+ export type JoinType = 'one' | 'many' | 'cross';
397
+ export type JoinRelationship = 'one_to_one' | 'one_to_many' | 'many_to_one' | 'many_to_many';
398
+ export type MatrixOperation = 'left' | 'right' | 'full' | 'inner';
399
+ export declare function isMatrixOperation(x: string): x is MatrixOperation;
400
+ export type JoinElementType = 'table' | 'sql_select' | 'query_source' | 'array' | 'record';
401
+ export interface JoinBase {
402
+ type: JoinElementType;
403
+ join: JoinType;
404
+ matrixOperation?: MatrixOperation;
405
+ onExpression?: Expr;
374
406
  }
407
+ export type Joinable = TableSourceDef | SQLSourceDef | QuerySourceDef | RecordFieldDef | JoinedArrayDef;
408
+ export type JoinFieldDef = JoinBase & Joinable;
409
+ export type JoinFieldTypes = 'table' | 'sql_select' | 'query_source' | 'array' | 'record';
410
+ export declare function isJoinable(sd: StructDef): sd is Joinable;
411
+ export declare function isJoined<T extends FieldDef | StructDef>(fd: T): fd is T & Joinable & JoinBase;
412
+ export declare function isJoinedSource(sd: StructDef): sd is SourceDef & JoinBase;
375
413
  export type DateUnit = 'day' | 'week' | 'month' | 'quarter' | 'year';
376
414
  export declare function isDateUnit(str: string): str is DateUnit;
377
415
  export type TimestampUnit = DateUnit | 'hour' | 'minute' | 'second';
@@ -386,22 +424,16 @@ export declare enum ValueType {
386
424
  String = "string"
387
425
  }
388
426
  export type TimeValueType = ValueType.Date | ValueType.Timestamp;
389
- export interface FieldDateTypeDef {
427
+ export interface DateTypeDef {
390
428
  type: 'date';
391
429
  timeframe?: DateUnit;
392
430
  }
393
- /** Scalar Date Field. */
394
- export interface FieldDateDef extends FieldAtomicDef, FieldDateTypeDef {
395
- type: 'date';
396
- }
397
- export interface FieldTimestampTypeDef {
431
+ export type DateFieldDef = DateTypeDef & AtomicFieldDef;
432
+ export interface TimestampTypeDef {
398
433
  type: 'timestamp';
399
434
  timeframe?: TimestampUnit;
400
435
  }
401
- /** Scalar Timestamp Field */
402
- export interface FieldTimestampDef extends FieldAtomicDef, FieldTimestampTypeDef {
403
- type: 'timestamp';
404
- }
436
+ export type TimestampFieldDef = TimestampTypeDef & AtomicFieldDef;
405
437
  /** parameter to order a query */
406
438
  export interface OrderBy {
407
439
  field: string | number;
@@ -428,18 +460,12 @@ export type By = ByName | ByExpression;
428
460
  export declare function isByName(by: By | undefined): by is ByName;
429
461
  export declare function isByExpression(by: By | undefined): by is ByExpression;
430
462
  /** reference to a data source */
431
- export type StructRef = string | StructDef;
432
- export declare function refIsStructDef(ref: StructRef): ref is StructDef;
463
+ export type StructRef = string | SourceDef;
464
+ export declare function refIsStructDef(ref: StructRef): ref is SourceDef;
433
465
  export type InvokedStructRef = {
434
466
  structRef: StructRef;
435
467
  sourceArguments?: Record<string, Argument>;
436
468
  };
437
- /** join pattern structs is a struct. */
438
- export interface JoinedStruct {
439
- structRef: StructRef;
440
- structRelationship: StructRelationship;
441
- as: string;
442
- }
443
469
  export interface Filtered {
444
470
  filterList?: FilterCondition[];
445
471
  }
@@ -518,84 +544,63 @@ export interface TurtleDef extends NamedObject, Pipeline {
518
544
  type: 'turtle';
519
545
  annotation?: Annotation;
520
546
  }
521
- export type JoinRelationship = 'one_to_one' | 'one_to_many' | 'many_to_one' | 'many_to_many';
522
- export type MatrixOperation = 'left' | 'right' | 'full' | 'inner';
523
- export declare function isMatrixOperation(x: string): x is MatrixOperation;
524
- export interface JoinOn {
525
- type: 'one' | 'many' | 'cross';
526
- matrixOperation: MatrixOperation;
527
- onExpression?: Expr;
547
+ interface StructDefBase extends HasLocation, NamedObject {
548
+ type: string;
549
+ annotation?: Annotation;
550
+ modelAnnotation?: ModelAnnotation;
551
+ fields: FieldDef[];
552
+ dialect: string;
553
+ }
554
+ interface SourceDefBase extends StructDefBase, Filtered, ResultStructMetadata {
555
+ arguments?: Record<string, Argument>;
556
+ parameters?: Record<string, Parameter>;
557
+ queryTimezone?: string;
558
+ connection: string;
559
+ primaryKey?: PrimaryKeyRef;
560
+ }
561
+ /** which field is the primary key in this struct */
562
+ export type PrimaryKeyRef = string;
563
+ export interface TableSourceDef extends SourceDefBase {
564
+ type: 'table';
565
+ tablePath: string;
528
566
  }
529
- export declare function isJoinOn(sr: StructRelationship): sr is JoinOn;
530
- /** types of joins. */
531
- export type StructRelationship = {
532
- type: 'basetable';
533
- connectionName: string;
534
- } | JoinOn | {
535
- type: 'inline';
536
- } | {
537
- type: 'nested';
538
- fieldName: string;
539
- isArray: boolean;
540
- };
541
567
  export interface SQLStringSegment {
542
568
  sql: string;
543
569
  }
544
- export type SQLPhrase = Query | SQLStringSegment;
545
- export declare function isSQLFragment(f: SQLPhrase): f is SQLStringSegment;
546
- /**
547
- * A source reference to an SQL block. The compiler uses these to request
548
- * an SQLBlock with it's schema and structdef defined. Use the factory
549
- * makeSQLBlock to construct these.
550
- */
551
- export interface SQLBlockSource {
570
+ export type SQLPhraseSegment = Query | SQLStringSegment;
571
+ export declare function isSegmentSQL(f: SQLPhraseSegment): f is SQLStringSegment;
572
+ export interface SQLSentence {
552
573
  name: string;
553
- connection?: string;
554
- select: SQLPhrase[];
574
+ connection: string;
575
+ select: SQLPhraseSegment[];
555
576
  }
556
- export interface SQLBlock extends NamedObject {
557
- type: 'sqlBlock';
558
- connection?: string;
577
+ export interface SQLSourceDef extends SourceDefBase {
578
+ type: 'sql_select';
559
579
  selectStr: string;
560
580
  }
561
- interface SubquerySource {
562
- type: 'sql';
563
- method: 'subquery';
564
- sqlBlock: SQLBlock;
565
- }
566
- /** where does the struct come from? */
567
- export type StructSource = {
568
- type: 'table';
569
- tablePath: string;
570
- } | {
571
- type: 'nested';
572
- } | {
573
- type: 'inline';
574
- } | {
575
- type: 'query';
581
+ export interface QuerySourceDef extends SourceDefBase {
582
+ type: 'query_source';
576
583
  query: Query;
577
- } | {
578
- type: 'sql';
579
- method: 'nested' | 'lastStage';
580
- } | {
584
+ }
585
+ export interface QueryResultDef extends SourceDefBase {
581
586
  type: 'query_result';
582
- } | SubquerySource;
583
- /** struct that is intrinsic to the table */
584
- export interface StructDef extends NamedObject, ResultStructMetadata, Filtered {
585
- type: 'struct';
586
- structSource: StructSource;
587
- structRelationship: StructRelationship;
588
- fields: FieldDef[];
589
- primaryKey?: PrimaryKeyRef;
590
- arguments?: Record<string, Argument>;
591
- parameters?: Record<string, Parameter>;
592
- queryTimezone?: string;
593
- dialect: string;
594
- annotation?: Annotation;
595
- modelAnnotation?: ModelAnnotation;
596
587
  }
588
+ export interface NestSourceDef extends SourceDefBase {
589
+ type: 'nest_source';
590
+ pipeSQL: string;
591
+ }
592
+ export interface FinalizeSourceDef extends SourceDefBase {
593
+ type: 'finalize';
594
+ }
595
+ export declare function sourceBase(sd: SourceDefBase): SourceDefBase;
596
+ export declare function isSourceDef(sd: StructDef | FieldDef): sd is SourceDef;
597
+ export type SourceDef = TableSourceDef | SQLSourceDef | QuerySourceDef | QueryResultDef | FinalizeSourceDef | NestSourceDef;
598
+ /** Is this the "FROM" table of a query tree */
599
+ export declare function isBaseTable(def: StructDef): def is SourceDef;
600
+ export declare function isScalarArray(def: FieldDef | StructDef): boolean;
601
+ export type StructDef = SourceDef | RecordFieldDef | JoinedArrayDef;
597
602
  export type ExpressionValueType = AtomicFieldType | 'null' | 'duration' | 'any' | 'regular expression';
598
- export type FieldValueType = ExpressionValueType | 'turtle' | 'struct';
603
+ export type FieldValueType = ExpressionValueType | 'turtle' | JoinFieldTypes;
599
604
  export interface ExpressionTypeDesc {
600
605
  dataType: FieldValueType;
601
606
  expressionType: ExpressionType;
@@ -646,32 +651,21 @@ export interface FunctionDef extends NamedObject {
646
651
  export interface ConnectionDef extends NamedObject {
647
652
  type: 'connection';
648
653
  }
649
- export interface SQLBlockStructDef extends StructDef {
650
- structSource: SubquerySource;
651
- declaredSQLBlock?: boolean;
652
- }
653
- export declare function isSQLBlockStruct(sd: StructDef): sd is SQLBlockStructDef;
654
- /** any of the different field types */
655
- export type FieldTypeDef = FieldStringDef | FieldDateDef | FieldTimestampDef | FieldNumberDef | FieldBooleanDef | FieldJSONDef | FeldNativeUnsupportedDef | FieldErrorDef;
656
- export type FieldAtomicTypeDef = FieldStringTypeDef | FieldDateTypeDef | FieldTimestampTypeDef | FieldNumberTypeDef | FieldBooleanTypeDef | FieldJSONTypeDef | FieldNativeUnsupportedTypeDef | FieldErrorTypeDef;
657
- export declare function isFieldTypeDef(f: FieldDef): f is FieldTypeDef;
658
- export declare function isFieldTimeBased(f: FieldDef): f is FieldTimestampDef | FieldDateDef;
659
- export declare function isFieldStructDef(f: FieldDef): f is StructDef;
660
- export type QueryFieldDef = FieldTypeDef | TurtleDef | RefToField;
661
- /** basics statement */
662
- export type FieldDef = FieldTypeDef | StructDef | TurtleDef;
663
- /** reference to a field */
654
+ export type TemporalTypeDef = DateTypeDef | TimestampTypeDef;
655
+ export type LeafAtomicDef = StringTypeDef | TemporalTypeDef | NumberTypeDef | BooleanTypeDef | JSONTypeDef | NativeUnsupportedTypeDef | ErrorTypeDef;
656
+ export type AtomicTypeDef = LeafAtomicDef | ArrayTypeDef | RecordTypeDef;
657
+ export type AtomicFieldDef = AtomicTypeDef & FieldAtomicBase;
658
+ export type FieldDef = AtomicFieldDef | JoinFieldDef | TurtleDef;
664
659
  export interface RefToField {
665
660
  type: 'fieldref';
666
661
  path: string[];
667
662
  annotation?: Annotation;
668
663
  }
669
- export type FieldRefOrDef = FieldDef | RefToField;
670
- /** which field is the primary key in this struct */
671
- export type PrimaryKeyRef = string;
664
+ export type QueryFieldDef = AtomicFieldDef | TurtleDef | RefToField;
672
665
  /** Get the output name for a NamedObject */
673
666
  export declare function getIdentifier(n: AliasedName): string;
674
667
  export type NamedModelObject = StructDef | NamedQuery | FunctionDef | ConnectionDef;
668
+ export declare function modelObjIsSource(nmo: NamedModelObject): nmo is SourceDef;
675
669
  /** Result of parsing a model file */
676
670
  export interface ModelDef {
677
671
  name: string;
@@ -680,7 +674,7 @@ export interface ModelDef {
680
674
  annotation?: ModelAnnotation;
681
675
  }
682
676
  /** Very common record type */
683
- export type NamedStructDefs = Record<string, StructDef>;
677
+ export type NamedSourceDefs = Record<string, SourceDef>;
684
678
  export type NamedModelObjects = Record<string, NamedModelObject>;
685
679
  /** Malloy source annotations attached to objects */
686
680
  export interface Annotation {
@@ -727,7 +721,7 @@ export type QueryToMaterialize = {
727
721
  queryName: string;
728
722
  };
729
723
  export interface CompiledQuery extends DrillSource {
730
- structs: StructDef[];
724
+ structs: SourceDef[];
731
725
  sql: string;
732
726
  lastStageName: string;
733
727
  malloy: string;
@@ -747,18 +741,14 @@ export interface QueryResult extends CompiledQuery {
747
741
  profilingUrl?: string;
748
742
  }
749
743
  export declare function isTurtleDef(def: FieldDef): def is TurtleDef;
750
- export declare function isAtomicField(def: FieldDef): def is FieldAtomicDef;
744
+ export declare function isAtomic(def: FieldDef): def is AtomicFieldDef;
751
745
  export interface SearchResultRow {
752
746
  field_name: string;
753
747
  field_value: string;
754
748
  weight: number;
755
749
  }
756
750
  export type SearchResult = SearchResultRow[];
757
- export declare function isDimensional(field: FieldDef): boolean;
758
- export declare function isPhysical(field: FieldDef): boolean;
759
- export declare function getDimensions(structDef: StructDef): FieldAtomicDef[];
760
- export declare function getPhysicalFields(structDef: StructDef): FieldDef[];
761
- export declare function isMeasureLike(field: FieldDef): boolean;
751
+ export declare function getAtomicFields(structDef: StructDef): AtomicFieldDef[];
762
752
  export declare function isValueString(value: QueryValue, field: FieldDef): value is string | null;
763
753
  export declare function isValueNumber(value: QueryValue, field: FieldDef): value is number | null;
764
754
  export declare function isValueBoolean(value: QueryValue, field: FieldDef): value is boolean | null;