@malloydata/malloy 0.0.205-dev241028163321 → 0.0.205-dev241028192658

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 (88) hide show
  1. package/dist/dialect/functions/util.d.ts +16 -16
  2. package/dist/dialect/functions/util.js +16 -48
  3. package/dist/index.d.ts +1 -1
  4. package/dist/lang/ast/ast-utils.js +1 -1
  5. package/dist/lang/ast/expressions/binary-boolean.js +27 -4
  6. package/dist/lang/ast/expressions/binary-numeric.js +25 -2
  7. package/dist/lang/ast/expressions/boolean.js +25 -2
  8. package/dist/lang/ast/expressions/case.js +41 -20
  9. package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +2 -2
  10. package/dist/lang/ast/expressions/expr-aggregate-function.js +30 -10
  11. package/dist/lang/ast/expressions/expr-alternation-tree.js +2 -2
  12. package/dist/lang/ast/expressions/expr-asymmetric.d.ts +2 -0
  13. package/dist/lang/ast/expressions/expr-asymmetric.js +3 -0
  14. package/dist/lang/ast/expressions/expr-cast.js +4 -6
  15. package/dist/lang/ast/expressions/expr-coalesce.js +30 -7
  16. package/dist/lang/ast/expressions/expr-compare.js +33 -10
  17. package/dist/lang/ast/expressions/expr-count-distinct.d.ts +2 -0
  18. package/dist/lang/ast/expressions/expr-count-distinct.js +34 -2
  19. package/dist/lang/ast/expressions/expr-count.d.ts +1 -0
  20. package/dist/lang/ast/expressions/expr-count.js +11 -1
  21. package/dist/lang/ast/expressions/expr-func.d.ts +3 -3
  22. package/dist/lang/ast/expressions/expr-func.js +41 -15
  23. package/dist/lang/ast/expressions/expr-granular-time.js +36 -14
  24. package/dist/lang/ast/expressions/expr-logical-op.js +25 -2
  25. package/dist/lang/ast/expressions/expr-max.d.ts +3 -4
  26. package/dist/lang/ast/expressions/expr-max.js +27 -4
  27. package/dist/lang/ast/expressions/expr-min.d.ts +3 -4
  28. package/dist/lang/ast/expressions/expr-min.js +27 -4
  29. package/dist/lang/ast/expressions/expr-minus.js +27 -4
  30. package/dist/lang/ast/expressions/expr-not.js +26 -3
  31. package/dist/lang/ast/expressions/expr-now.js +1 -1
  32. package/dist/lang/ast/expressions/expr-null.js +1 -1
  33. package/dist/lang/ast/expressions/expr-number.js +5 -1
  34. package/dist/lang/ast/expressions/expr-props.js +25 -2
  35. package/dist/lang/ast/expressions/expr-regex.js +1 -1
  36. package/dist/lang/ast/expressions/expr-string.js +1 -1
  37. package/dist/lang/ast/expressions/expr-time-extract.js +18 -18
  38. package/dist/lang/ast/expressions/expr-time.js +4 -4
  39. package/dist/lang/ast/expressions/expr-ungroup.d.ts +0 -2
  40. package/dist/lang/ast/expressions/expr-ungroup.js +26 -6
  41. package/dist/lang/ast/expressions/for-range.js +32 -9
  42. package/dist/lang/ast/expressions/pick-when.js +46 -25
  43. package/dist/lang/ast/expressions/range.js +1 -1
  44. package/dist/lang/ast/expressions/time-literal.js +9 -4
  45. package/dist/lang/ast/field-space/index-field-space.js +1 -3
  46. package/dist/lang/ast/field-space/project-field-space.d.ts +1 -1
  47. package/dist/lang/ast/field-space/project-field-space.js +2 -1
  48. package/dist/lang/ast/field-space/query-spaces.d.ts +1 -1
  49. package/dist/lang/ast/field-space/query-spaces.js +4 -3
  50. package/dist/lang/ast/field-space/reference-field.js +43 -10
  51. package/dist/lang/ast/field-space/rename-space-field.d.ts +2 -2
  52. package/dist/lang/ast/field-space/static-space.js +1 -1
  53. package/dist/lang/ast/field-space/struct-space-field-base.d.ts +2 -2
  54. package/dist/lang/ast/field-space/struct-space-field-base.js +40 -8
  55. package/dist/lang/ast/field-space/view-field.d.ts +2 -2
  56. package/dist/lang/ast/field-space/view-field.js +25 -1
  57. package/dist/lang/ast/parameters/has-parameter.d.ts +1 -1
  58. package/dist/lang/ast/parameters/has-parameter.js +8 -8
  59. package/dist/lang/ast/query-items/field-declaration.d.ts +2 -1
  60. package/dist/lang/ast/query-items/field-declaration.js +34 -9
  61. package/dist/lang/ast/query-items/typecheck_utils.js +11 -13
  62. package/dist/lang/ast/query-properties/filters.js +1 -1
  63. package/dist/lang/ast/source-elements/named-source.js +2 -2
  64. package/dist/lang/ast/source-properties/join.js +3 -3
  65. package/dist/lang/ast/time-utils.d.ts +2 -2
  66. package/dist/lang/ast/time-utils.js +6 -1
  67. package/dist/lang/ast/typedesc-utils.d.ts +48 -0
  68. package/dist/lang/ast/typedesc-utils.js +157 -0
  69. package/dist/lang/ast/types/expr-result.d.ts +2 -1
  70. package/dist/lang/ast/types/expr-value.d.ts +11 -36
  71. package/dist/lang/ast/types/expr-value.js +27 -13
  72. package/dist/lang/ast/types/expression-def.d.ts +3 -2
  73. package/dist/lang/ast/types/expression-def.js +84 -60
  74. package/dist/lang/ast/types/global-name-space.js +2 -2
  75. package/dist/lang/ast/types/granular-result.d.ts +2 -2
  76. package/dist/lang/ast/types/granular-result.js +1 -1
  77. package/dist/lang/ast/types/space-field.js +2 -13
  78. package/dist/lang/ast/types/space-param.d.ts +3 -1
  79. package/dist/lang/ast/types/space-param.js +36 -4
  80. package/dist/lang/ast/types/time-result.d.ts +3 -4
  81. package/dist/lang/parse-log.d.ts +15 -15
  82. package/dist/lang/test/literals.spec.js +1 -1
  83. package/dist/lang/test/parse-expects.js +2 -2
  84. package/dist/model/malloy_types.d.ts +30 -32
  85. package/dist/model/malloy_types.js +25 -16
  86. package/package.json +1 -1
  87. package/dist/lang/ast/fragtype-utils.d.ts +0 -46
  88. package/dist/lang/ast/fragtype-utils.js +0 -115
@@ -242,11 +242,11 @@ export interface Expression {
242
242
  code?: string;
243
243
  }
244
244
  type ConstantExpr = Expr;
245
- export interface Parameter {
246
- value: ConstantExpr | null;
245
+ interface ParameterInfo {
247
246
  name: string;
248
- type: AtomicFieldType;
247
+ value: ConstantExpr | null;
249
248
  }
249
+ export type Parameter = AtomicTypeDef & ParameterInfo;
250
250
  export type Argument = Parameter;
251
251
  export declare function paramHasValue(p: Parameter): boolean;
252
252
  export interface DocumentRange {
@@ -349,9 +349,6 @@ export declare function isCastType(s: string): s is CastType;
349
349
  export interface FieldBase extends NamedObject, Expression, ResultMetadata {
350
350
  annotation?: Annotation;
351
351
  }
352
- interface FieldAtomicBase extends FieldBase {
353
- type: AtomicFieldType;
354
- }
355
352
  export declare function fieldIsIntrinsic(f: FieldDef): boolean;
356
353
  export interface StringTypeDef {
357
354
  type: 'string';
@@ -611,28 +608,28 @@ export type SourceDef = TableSourceDef | SQLSourceDef | QuerySourceDef | QueryRe
611
608
  export declare function isBaseTable(def: StructDef): def is SourceDef;
612
609
  export declare function isScalarArray(def: FieldDef | StructDef): boolean;
613
610
  export type StructDef = SourceDef | RecordFieldDef | ArrayDef;
614
- export type ExpressionValueType = AtomicFieldType | 'null' | 'duration' | 'any' | 'regular expression';
615
- export type FieldValueType = ExpressionValueType | 'turtle' | JoinFieldTypes;
616
- export interface ExpressionTypeDesc {
617
- dataType: FieldValueType;
611
+ export type NonAtomicType = Exclude<JoinElementType, 'array' | 'record'> | 'turtle' | 'null' | 'duration' | 'any' | 'regular expression';
612
+ export interface NonAtomicTypeDef {
613
+ type: NonAtomicType;
614
+ }
615
+ export type ExpressionValueType = AtomicFieldType | NonAtomicType;
616
+ export type ExpressionValueTypeDef = AtomicTypeDef | NonAtomicTypeDef;
617
+ export type LeafExpressionType = Exclude<ExpressionValueType, JoinElementType | 'turtle'>;
618
+ export type TypeInfo = {
618
619
  expressionType: ExpressionType;
619
- rawType?: string;
620
620
  evalSpace: EvalSpace;
621
- }
622
- export interface FunctionParamTypeDesc {
623
- dataType: FieldValueType;
621
+ };
622
+ export type TypeDesc = ExpressionValueTypeDef & TypeInfo;
623
+ export type FunctionParamType = ExpressionValueTypeDef | {
624
+ type: 'any';
625
+ };
626
+ export type FunctionParamTypeDesc = FunctionParamType & {
624
627
  expressionType: ExpressionType | undefined;
625
628
  evalSpace: EvalSpace;
626
- }
629
+ };
627
630
  export type EvalSpace = 'constant' | 'input' | 'output' | 'literal';
628
631
  export declare function isLiteral(evalSpace: EvalSpace): boolean;
629
632
  export declare function mergeEvalSpaces(...evalSpaces: EvalSpace[]): EvalSpace;
630
- export interface TypeDesc {
631
- dataType: FieldValueType;
632
- expressionType: ExpressionType;
633
- rawType?: string;
634
- evalSpace: EvalSpace;
635
- }
636
633
  export interface FunctionParameterDef {
637
634
  name: string;
638
635
  allowedTypes: FunctionParamTypeDesc[];
@@ -666,10 +663,11 @@ export interface ConnectionDef extends NamedObject {
666
663
  export type TemporalTypeDef = DateTypeDef | TimestampTypeDef;
667
664
  export type LeafAtomicTypeDef = StringTypeDef | TemporalTypeDef | NumberTypeDef | BooleanTypeDef | JSONTypeDef | NativeUnsupportedTypeDef | ErrorTypeDef;
668
665
  export type AtomicTypeDef = LeafAtomicTypeDef | ArrayTypeDef | RecordTypeDef;
669
- export type LeafAtomicDef = LeafAtomicTypeDef & FieldAtomicBase;
670
- export type AtomicFieldDef = AtomicTypeDef & FieldAtomicBase;
666
+ export type LeafAtomicDef = LeafAtomicTypeDef & FieldBase;
667
+ export type AtomicFieldDef = AtomicTypeDef & FieldBase;
671
668
  export declare function isLeafAtomic(fd: FieldDef | QueryFieldDef | AtomicTypeDef): fd is LeafAtomicDef;
672
669
  export type FieldDef = AtomicFieldDef | JoinFieldDef | TurtleDef;
670
+ export type FieldDefType = AtomicFieldType | 'turtle' | JoinElementType;
673
671
  export interface RefToField {
674
672
  type: 'fieldref';
675
673
  path: string[];
@@ -789,10 +787,14 @@ export interface PrepareResultOptions {
789
787
  replaceMaterializedReferences?: boolean;
790
788
  materializedTablePrefix?: string;
791
789
  }
792
- type UTD = AtomicTypeDef | undefined;
790
+ type UTD = AtomicTypeDef | FunctionParamTypeDesc | undefined;
791
+ /**
792
+ * A set of utilities for asking questions TypeDef/TypeDesc
793
+ * (which is OK because TypeDesc is an extension of a TypeDef)
794
+ */
793
795
  export declare const TD: {
794
- isA: (td: UTD, ...tList: string[]) => boolean | undefined;
795
- notA: (td: UTD, ...tList: string[]) => boolean | undefined;
796
+ isAtomic(td: UTD): td is AtomicTypeDef;
797
+ isLeafAtomic(td: UTD): td is LeafAtomicTypeDef;
796
798
  isString: (td: UTD) => td is StringTypeDef;
797
799
  isNumber: (td: UTD) => td is NumberTypeDef;
798
800
  isBoolean: (td: UTD) => td is BooleanTypeDef;
@@ -800,12 +802,8 @@ export declare const TD: {
800
802
  isSQL: (td: UTD) => td is NativeUnsupportedTypeDef;
801
803
  isDate: (td: UTD) => td is DateTypeDef;
802
804
  isTimestamp: (td: UTD) => td is TimestampTypeDef;
805
+ isTemporal(td: UTD): td is TimestampTypeDef;
803
806
  isError: (td: UTD) => td is ErrorTypeDef;
804
- eq: (x: UTD, y: UTD) => boolean;
805
- timestamp: () => TimestampTypeDef;
806
- date: () => DateTypeDef;
807
- string: () => StringTypeDef;
808
- number: () => NumberTypeDef;
809
- error: () => ErrorTypeDef;
807
+ eq(x: UTD, y: UTD): boolean;
810
808
  };
811
809
  export {};
@@ -399,18 +399,29 @@ function isValueDate(value, field) {
399
399
  return field.type === 'date';
400
400
  }
401
401
  exports.isValueDate = isValueDate;
402
+ /**
403
+ * A set of utilities for asking questions TypeDef/TypeDesc
404
+ * (which is OK because TypeDesc is an extension of a TypeDef)
405
+ */
402
406
  exports.TD = {
403
- isA: (td, ...tList) => td && tList.includes(td.type),
404
- notA: (td, ...tList) => td && !tList.includes(td.type),
405
- isString: (td) => td !== undefined && td.type === 'string',
406
- isNumber: (td) => td !== undefined && td.type === 'number',
407
- isBoolean: (td) => td !== undefined && td.type === 'boolean',
408
- isJSON: (td) => td !== undefined && td.type === 'json',
409
- isSQL: (td) => td !== undefined && td.type === 'sql native',
410
- isDate: (td) => td !== undefined && td.type === 'date',
411
- isTimestamp: (td) => td !== undefined && td.type === 'timestamp',
412
- isError: (td) => td !== undefined && td.type === 'error',
413
- eq: function (x, y) {
407
+ isAtomic(td) {
408
+ return td !== undefined && isAtomicFieldType(td.type);
409
+ },
410
+ isLeafAtomic(td) {
411
+ return td !== undefined && isLeafAtomic({ type: td.type });
412
+ },
413
+ isString: (td) => (td === null || td === void 0 ? void 0 : td.type) === 'string',
414
+ isNumber: (td) => (td === null || td === void 0 ? void 0 : td.type) === 'number',
415
+ isBoolean: (td) => (td === null || td === void 0 ? void 0 : td.type) === 'boolean',
416
+ isJSON: (td) => (td === null || td === void 0 ? void 0 : td.type) === 'json',
417
+ isSQL: (td) => (td === null || td === void 0 ? void 0 : td.type) === 'sql native',
418
+ isDate: (td) => (td === null || td === void 0 ? void 0 : td.type) === 'date',
419
+ isTimestamp: (td) => (td === null || td === void 0 ? void 0 : td.type) === 'timestamp',
420
+ isTemporal(td) {
421
+ return (td === null || td === void 0 ? void 0 : td.type) === 'timestamp' || (td === null || td === void 0 ? void 0 : td.type) === 'date';
422
+ },
423
+ isError: (td) => (td === null || td === void 0 ? void 0 : td.type) === 'error',
424
+ eq(x, y) {
414
425
  if (x === undefined || y === undefined) {
415
426
  return false;
416
427
  }
@@ -445,13 +456,11 @@ exports.TD = {
445
456
  else if (x.type === 'record' && y.type === 'record') {
446
457
  return checkFields(x, y);
447
458
  }
459
+ if (x.type === 'sql native' && y.type === 'sql native') {
460
+ return x.rawType !== undefined && x.rawType === y.rawType;
461
+ }
448
462
  return x.type === y.type;
449
463
  },
450
- timestamp: () => ({ type: 'timestamp' }),
451
- date: () => ({ type: 'date' }),
452
- string: () => ({ type: 'string' }),
453
- number: () => ({ type: 'number', numberType: 'float' }),
454
- error: () => ({ type: 'error' }),
455
464
  };
456
465
  // clang-format on
457
466
  //# sourceMappingURL=malloy_types.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.205-dev241028163321",
3
+ "version": "0.0.205-dev241028192658",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -1,46 +0,0 @@
1
- import { TypeDesc } from '../../model';
2
- /**
3
- * Collects functions which operate on fragtype compatible objects
4
- */
5
- export declare class FT {
6
- /**
7
- * Checks if a given type is in a list
8
- * @param check The type to check (can be undefined)
9
- * @param from List of types which are OK
10
- */
11
- static in(check: TypeDesc | undefined, from: TypeDesc[]): boolean;
12
- /**
13
- * Checks if a possibly undefined candidate matches a type
14
- * @param good The real type
15
- * @param checkThis The possibly undefined candidate
16
- */
17
- static eq(good: TypeDesc, checkThis: TypeDesc | undefined): boolean;
18
- /**
19
- * Checks if a given type is in a list, ignoring aggregate
20
- * @param check The type to check (can be undefined)
21
- * @param from List of types which are OK
22
- */
23
- static typeIn(check: TypeDesc | undefined, from: TypeDesc[]): boolean;
24
- /**
25
- * Checks if the base types, ignoring aggregate, are equal
26
- * @param left Left type
27
- * @param right Right type
28
- * @param nullOk True if a NULL is an acceptable match
29
- */
30
- static typeEq(left: TypeDesc, right: TypeDesc, nullOk?: boolean, errorOk?: boolean): boolean;
31
- /**
32
- *
33
- * For error messages, returns a comma seperated list of readable names
34
- * for a list of types.
35
- * @param types List of type or objects with types
36
- */
37
- static inspect(...types: (TypeDesc | undefined)[]): string;
38
- static nullT: TypeDesc;
39
- static numberT: TypeDesc;
40
- static stringT: TypeDesc;
41
- static dateT: TypeDesc;
42
- static timestampT: TypeDesc;
43
- static boolT: TypeDesc;
44
- static anyAtomicT: TypeDesc[];
45
- static aggregateBoolT: TypeDesc;
46
- }
@@ -1,115 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright 2023 Google LLC
4
- *
5
- * Permission is hereby granted, free of charge, to any person obtaining
6
- * a copy of this software and associated documentation files
7
- * (the "Software"), to deal in the Software without restriction,
8
- * including without limitation the rights to use, copy, modify, merge,
9
- * publish, distribute, sublicense, and/or sell copies of the Software,
10
- * and to permit persons to whom the Software is furnished to do so,
11
- * subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be
14
- * included in all copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
- */
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.FT = void 0;
26
- const model_1 = require("../../model");
27
- function mkFragType(dataType, expressionType = 'scalar', evalSpace = 'constant') {
28
- return { dataType, expressionType, evalSpace };
29
- }
30
- /**
31
- * Collects functions which operate on fragtype compatible objects
32
- */
33
- class FT {
34
- /**
35
- * Checks if a given type is in a list
36
- * @param check The type to check (can be undefined)
37
- * @param from List of types which are OK
38
- */
39
- static in(check, from) {
40
- if (check) {
41
- const found = from.find(okType => FT.eq(okType, check));
42
- return found !== undefined;
43
- }
44
- return false;
45
- }
46
- /**
47
- * Checks if a possibly undefined candidate matches a type
48
- * @param good The real type
49
- * @param checkThis The possibly undefined candidate
50
- */
51
- static eq(good, checkThis) {
52
- return (checkThis !== undefined &&
53
- good.dataType === checkThis.dataType &&
54
- good.expressionType === checkThis.expressionType);
55
- }
56
- /**
57
- * Checks if a given type is in a list, ignoring aggregate
58
- * @param check The type to check (can be undefined)
59
- * @param from List of types which are OK
60
- */
61
- static typeIn(check, from) {
62
- if (check) {
63
- const found = from.find(okType => FT.typeEq(okType, check));
64
- return found !== undefined;
65
- }
66
- return false;
67
- }
68
- /**
69
- * Checks if the base types, ignoring aggregate, are equal
70
- * @param left Left type
71
- * @param right Right type
72
- * @param nullOk True if a NULL is an acceptable match
73
- */
74
- static typeEq(left, right, nullOk = false, errorOk = true) {
75
- const maybeEq = left.dataType === right.dataType;
76
- const nullEq = nullOk && (left.dataType === 'null' || right.dataType === 'null');
77
- const errorEq = errorOk && (left.dataType === 'error' || right.dataType === 'error');
78
- return maybeEq || nullEq || errorEq;
79
- }
80
- /**
81
- *
82
- * For error messages, returns a comma seperated list of readable names
83
- * for a list of types.
84
- * @param types List of type or objects with types
85
- */
86
- static inspect(...types) {
87
- const strings = types.map(type => {
88
- if (type) {
89
- let inspected = type.dataType;
90
- if (!(0, model_1.expressionIsScalar)(type.expressionType)) {
91
- inspected = `${type.expressionType} ${inspected}`;
92
- }
93
- return inspected;
94
- }
95
- return 'undefined';
96
- });
97
- return strings.join(',');
98
- }
99
- }
100
- exports.FT = FT;
101
- FT.nullT = mkFragType('null');
102
- FT.numberT = mkFragType('number');
103
- FT.stringT = mkFragType('string');
104
- FT.dateT = mkFragType('date');
105
- FT.timestampT = mkFragType('timestamp');
106
- FT.boolT = mkFragType('boolean');
107
- FT.anyAtomicT = [
108
- FT.numberT,
109
- FT.stringT,
110
- FT.dateT,
111
- FT.timestampT,
112
- FT.boolT,
113
- ];
114
- FT.aggregateBoolT = mkFragType('boolean', 'aggregate');
115
- //# sourceMappingURL=fragtype-utils.js.map