@malloydata/malloy 0.0.391 → 0.0.392

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 (127) hide show
  1. package/dist/api/asynchronous.js +0 -3
  2. package/dist/api/foundation/compile.d.ts +1 -1
  3. package/dist/api/foundation/config.d.ts +80 -8
  4. package/dist/api/foundation/config.js +151 -69
  5. package/dist/api/foundation/config_compile.js +27 -35
  6. package/dist/api/foundation/config_discover.js +5 -9
  7. package/dist/api/foundation/config_overlays.d.ts +6 -0
  8. package/dist/api/foundation/config_overlays.js +12 -0
  9. package/dist/api/foundation/config_resolve.d.ts +4 -1
  10. package/dist/api/foundation/config_resolve.js +64 -4
  11. package/dist/api/foundation/core.d.ts +75 -2
  12. package/dist/api/foundation/core.js +104 -6
  13. package/dist/api/foundation/index.d.ts +2 -0
  14. package/dist/api/foundation/readers.js +1 -1
  15. package/dist/api/foundation/runtime.d.ts +68 -2
  16. package/dist/api/foundation/runtime.js +212 -10
  17. package/dist/api/foundation/types.d.ts +2 -1
  18. package/dist/index.d.ts +3 -1
  19. package/dist/lang/ast/ast-utils.js +0 -1
  20. package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +1 -1
  21. package/dist/lang/ast/expressions/expr-aggregate-function.js +9 -8
  22. package/dist/lang/ast/expressions/expr-coalesce.d.ts +1 -1
  23. package/dist/lang/ast/expressions/expr-coalesce.js +2 -3
  24. package/dist/lang/ast/expressions/expr-count-distinct.js +1 -1
  25. package/dist/lang/ast/expressions/expr-count.js +6 -4
  26. package/dist/lang/ast/expressions/expr-filter-expr.js +0 -1
  27. package/dist/lang/ast/expressions/expr-func.js +9 -4
  28. package/dist/lang/ast/expressions/expr-given.d.ts +18 -0
  29. package/dist/lang/ast/expressions/expr-given.js +69 -0
  30. package/dist/lang/ast/expressions/expr-granular-time.d.ts +1 -1
  31. package/dist/lang/ast/expressions/expr-id-reference.js +3 -2
  32. package/dist/lang/ast/expressions/expr-now.js +0 -1
  33. package/dist/lang/ast/expressions/expr-props.d.ts +132 -132
  34. package/dist/lang/ast/expressions/expr-props.js +2 -2
  35. package/dist/lang/ast/expressions/expr-ungroup.d.ts +1 -1
  36. package/dist/lang/ast/expressions/expr-ungroup.js +4 -4
  37. package/dist/lang/ast/expressions/for-range.d.ts +1 -1
  38. package/dist/lang/ast/expressions/function-ordering.d.ts +1 -1
  39. package/dist/lang/ast/expressions/function-ordering.js +2 -2
  40. package/dist/lang/ast/expressions/time-literal.d.ts +3 -3
  41. package/dist/lang/ast/field-space/include-utils.js +2 -2
  42. package/dist/lang/ast/field-space/index-field-space.js +18 -23
  43. package/dist/lang/ast/field-space/passthrough-space.d.ts +1 -1
  44. package/dist/lang/ast/field-space/query-spaces.d.ts +6 -2
  45. package/dist/lang/ast/field-space/query-spaces.js +29 -19
  46. package/dist/lang/ast/field-space/reference-field.js +1 -1
  47. package/dist/lang/ast/field-space/rename-space-field.d.ts +1 -1
  48. package/dist/lang/ast/field-space/rename-space-field.js +2 -2
  49. package/dist/lang/ast/field-space/struct-space-field-base.js +2 -3
  50. package/dist/lang/ast/index.d.ts +2 -0
  51. package/dist/lang/ast/index.js +2 -0
  52. package/dist/lang/ast/query-builders/index-builder.d.ts +1 -1
  53. package/dist/lang/ast/query-builders/index-builder.js +4 -3
  54. package/dist/lang/ast/query-builders/reduce-builder.d.ts +2 -2
  55. package/dist/lang/ast/query-builders/reduce-builder.js +4 -5
  56. package/dist/lang/ast/query-elements/query-arrow.js +3 -2
  57. package/dist/lang/ast/query-elements/query-base.d.ts +1 -1
  58. package/dist/lang/ast/query-elements/query-base.js +1 -1
  59. package/dist/lang/ast/query-elements/query-refine.js +3 -1
  60. package/dist/lang/ast/query-items/field-declaration.js +2 -2
  61. package/dist/lang/ast/query-properties/drill.js +6 -6
  62. package/dist/lang/ast/query-properties/filters.js +2 -2
  63. package/dist/lang/ast/query-properties/nest.js +3 -3
  64. package/dist/lang/ast/source-elements/composite-source.js +5 -3
  65. package/dist/lang/ast/source-elements/named-source.js +4 -0
  66. package/dist/lang/ast/source-elements/sql-source.js +2 -2
  67. package/dist/lang/ast/source-elements/table-source.js +3 -1
  68. package/dist/lang/ast/source-properties/join.js +4 -4
  69. package/dist/lang/ast/source-query-elements/sq-reference.js +2 -1
  70. package/dist/lang/ast/statements/define-given.d.ts +29 -0
  71. package/dist/lang/ast/statements/define-given.js +163 -0
  72. package/dist/lang/ast/statements/import-statement.js +72 -9
  73. package/dist/lang/ast/typedesc-utils.d.ts +3 -1
  74. package/dist/lang/ast/typedesc-utils.js +4 -47
  75. package/dist/lang/ast/types/expr-value.js +2 -3
  76. package/dist/lang/ast/types/expression-def.d.ts +2 -2
  77. package/dist/lang/ast/types/expression-def.js +2 -2
  78. package/dist/lang/ast/types/malloy-element.d.ts +5 -15
  79. package/dist/lang/ast/types/malloy-element.js +113 -1
  80. package/dist/lang/ast/types/space-field.js +7 -9
  81. package/dist/lang/ast/view-elements/reference-view.js +6 -5
  82. package/dist/lang/ast/view-elements/refine-utils.js +1 -1
  83. package/dist/lang/composite-source-utils.d.ts +30 -15
  84. package/dist/lang/composite-source-utils.js +234 -64
  85. package/dist/lang/lib/Malloy/MalloyLexer.d.ts +171 -169
  86. package/dist/lang/lib/Malloy/MalloyLexer.js +1194 -1178
  87. package/dist/lang/lib/Malloy/MalloyParser.d.ts +408 -334
  88. package/dist/lang/lib/Malloy/MalloyParser.js +3062 -2561
  89. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +68 -0
  90. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +43 -0
  91. package/dist/lang/malloy-to-ast.d.ts +13 -1
  92. package/dist/lang/malloy-to-ast.js +90 -11
  93. package/dist/lang/parse-log.d.ts +8 -0
  94. package/dist/lang/prettify/filter-type.d.ts +3 -0
  95. package/dist/lang/prettify/filter-type.js +38 -0
  96. package/dist/lang/prettify/formatter.js +6 -0
  97. package/dist/lang/prettify/inline-renderer.js +20 -0
  98. package/dist/lang/prettify/rules.d.ts +1 -1
  99. package/dist/lang/prettify/rules.js +1 -0
  100. package/dist/lang/prettify/sections.js +2 -0
  101. package/dist/lang/prettify/tokens.js +2 -0
  102. package/dist/lang/test/expr-to-str.js +2 -0
  103. package/dist/lang/test/parse-expects.d.ts +1 -0
  104. package/dist/lang/test/parse-expects.js +27 -10
  105. package/dist/model/constant_expression_compiler.js +1 -0
  106. package/dist/model/expression_compiler.d.ts +2 -1
  107. package/dist/model/expression_compiler.js +41 -1
  108. package/dist/model/given_binding.d.ts +2 -0
  109. package/dist/model/given_binding.js +204 -0
  110. package/dist/model/index.d.ts +1 -1
  111. package/dist/model/index.js +2 -1
  112. package/dist/model/malloy_types.d.ts +163 -36
  113. package/dist/model/malloy_types.js +97 -0
  114. package/dist/model/query_model_contract.d.ts +2 -1
  115. package/dist/model/query_model_impl.d.ts +2 -1
  116. package/dist/model/query_model_impl.js +7 -0
  117. package/dist/model/query_node.d.ts +2 -1
  118. package/dist/model/source_def_utils.d.ts +2 -1
  119. package/dist/model/source_def_utils.js +4 -0
  120. package/dist/model/utils.d.ts +14 -1
  121. package/dist/model/utils.js +41 -0
  122. package/dist/to_stable.js +1 -1
  123. package/dist/util/closest_match.d.ts +9 -0
  124. package/dist/util/closest_match.js +47 -0
  125. package/dist/version.d.ts +1 -1
  126. package/dist/version.js +1 -1
  127. package/package.json +4 -4
@@ -23,6 +23,7 @@
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.GenerateState = exports.AndChain = void 0;
26
+ exports.typeDefToString = typeDefToString;
26
27
  exports.indent = indent;
27
28
  exports.generateSQLStringLiteral = generateSQLStringLiteral;
28
29
  exports.generateHash = generateHash;
@@ -42,6 +43,46 @@ const uuid_1 = require("uuid");
42
43
  const sha256_1 = require("@noble/hashes/sha256");
43
44
  const utils_1 = require("@noble/hashes/utils");
44
45
  const malloy_types_1 = require("./malloy_types");
46
+ /**
47
+ * Format a typeDef as user-readable Malloy type syntax. Used in error
48
+ * messages where we want to echo a compound type back to the user in the
49
+ * same form they wrote it.
50
+ *
51
+ * `string` → `string`
52
+ * `string[]` → `string[]`
53
+ * `{a::string, b::number}` → `{a :: string, b :: number}`
54
+ * `{a::string}[]` → `{a :: string}[]`
55
+ * `filter<string>` → `filter<string>`
56
+ * sql-native rawType → `sql native: jsonb`
57
+ */
58
+ function typeDefToString(td) {
59
+ switch (td.type) {
60
+ case 'array':
61
+ // Repeated record (`elementTypeDef.type === 'record_element'`) carries
62
+ // its schema in `fields` on the array itself; basic arrays carry it
63
+ // in `elementTypeDef`.
64
+ if (td.elementTypeDef.type === 'record_element' && 'fields' in td) {
65
+ return `${recordFieldsToString(td.fields)}[]`;
66
+ }
67
+ if (td.elementTypeDef.type !== 'record_element') {
68
+ return `${typeDefToString(td.elementTypeDef)}[]`;
69
+ }
70
+ return 'array';
71
+ case 'record':
72
+ return recordFieldsToString(td.fields);
73
+ case 'filter expression':
74
+ return `filter<${td.filterType}>`;
75
+ case 'sql native':
76
+ return td.rawType ? `sql native: ${td.rawType}` : 'sql native';
77
+ default:
78
+ return td.type;
79
+ }
80
+ }
81
+ function recordFieldsToString(fields) {
82
+ return `{${fields
83
+ .map(f => `${f.name} :: ${typeDefToString(f)}`)
84
+ .join(', ')}}`;
85
+ }
45
86
  /** simple indent function */
46
87
  function indent(s) {
47
88
  const re = /(^|\n)/g;
package/dist/to_stable.js CHANGED
@@ -349,7 +349,7 @@ function getResultStructMetadataAnnotation(field, resultMetadata) {
349
349
  for (let i = 0; i < resultMetadata.orderBy.length; i++) {
350
350
  const orderBy = resultMetadata.orderBy[i];
351
351
  const orderByField = typeof orderBy.field === 'number'
352
- ? (_a = field.fields[orderBy.field - 1].as) !== null && _a !== void 0 ? _a : field.fields[orderBy.field - 1].name
352
+ ? ((_a = field.fields[orderBy.field - 1].as) !== null && _a !== void 0 ? _a : field.fields[orderBy.field - 1].name)
353
353
  : orderBy.field;
354
354
  const direction = (_b = orderBy.dir) !== null && _b !== void 0 ? _b : null;
355
355
  tag.set(['ordered_by', i, orderByField], direction);
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Return the candidate string closest to `input` by Levenshtein distance,
3
+ * case-insensitively, or `undefined` if nothing is close enough. The
4
+ * threshold is `floor(max(input.length, candidate.length) / 3)` (minimum 1),
5
+ * so very different strings don't produce confusing "did you mean..."
6
+ * suggestions. Used for unknown-name diagnostics (config keys, given
7
+ * surface names, etc.).
8
+ */
9
+ export declare function closestMatch(input: string, candidates: string[]): string | undefined;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright Contributors to the Malloy project
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.closestMatch = closestMatch;
8
+ /**
9
+ * Return the candidate string closest to `input` by Levenshtein distance,
10
+ * case-insensitively, or `undefined` if nothing is close enough. The
11
+ * threshold is `floor(max(input.length, candidate.length) / 3)` (minimum 1),
12
+ * so very different strings don't produce confusing "did you mean..."
13
+ * suggestions. Used for unknown-name diagnostics (config keys, given
14
+ * surface names, etc.).
15
+ */
16
+ function closestMatch(input, candidates) {
17
+ if (candidates.length === 0)
18
+ return undefined;
19
+ let best = candidates[0];
20
+ let bestDist = Infinity;
21
+ for (const c of candidates) {
22
+ const dist = levenshtein(input.toLowerCase(), c.toLowerCase());
23
+ if (dist < bestDist) {
24
+ bestDist = dist;
25
+ best = c;
26
+ }
27
+ }
28
+ const maxDist = Math.max(1, Math.floor(Math.max(input.length, best.length) / 3));
29
+ return bestDist <= maxDist ? best : undefined;
30
+ }
31
+ function levenshtein(a, b) {
32
+ const m = a.length;
33
+ const n = b.length;
34
+ const dp = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));
35
+ for (let i = 0; i <= m; i++)
36
+ dp[i][0] = i;
37
+ for (let j = 0; j <= n; j++)
38
+ dp[0][j] = j;
39
+ for (let i = 1; i <= m; i++) {
40
+ for (let j = 1; j <= n; j++) {
41
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
42
+ dp[i][j] = Math.min(dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost);
43
+ }
44
+ }
45
+ return dp[m][n];
46
+ }
47
+ //# sourceMappingURL=closest_match.js.map
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const MALLOY_VERSION = "0.0.391";
1
+ export declare const MALLOY_VERSION = "0.0.392";
package/dist/version.js CHANGED
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MALLOY_VERSION = void 0;
4
4
  // generated with 'generate-version-file' script; do not edit manually
5
- exports.MALLOY_VERSION = '0.0.391';
5
+ exports.MALLOY_VERSION = '0.0.392';
6
6
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.391",
3
+ "version": "0.0.392",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -51,9 +51,9 @@
51
51
  "generate-version-file": "VERSION=$(npm pkg get version --workspaces=false | tr -d \\\")\necho \"// generated with 'generate-version-file' script; do not edit manually\\nexport const MALLOY_VERSION = '$VERSION';\" > src/version.ts"
52
52
  },
53
53
  "dependencies": {
54
- "@malloydata/malloy-filter": "0.0.391",
55
- "@malloydata/malloy-interfaces": "0.0.391",
56
- "@malloydata/malloy-tag": "0.0.391",
54
+ "@malloydata/malloy-filter": "0.0.392",
55
+ "@malloydata/malloy-interfaces": "0.0.392",
56
+ "@malloydata/malloy-tag": "0.0.392",
57
57
  "@noble/hashes": "^1.8.0",
58
58
  "antlr4ts": "^0.5.0-alpha.4",
59
59
  "assert": "^2.0.0",