@malloydata/malloy 0.0.318 → 0.0.320

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.
@@ -7,7 +7,16 @@ import type { DataRequestResponse, SQLSourceRequest, TranslateResponse } from '.
7
7
  import type { ExprValue } from '../ast/types/expr-value';
8
8
  import type { LogSeverity, MessageCode, MessageParameterType } from '../parse-log';
9
9
  import type { EventStream } from '../../runtime_types';
10
- export declare function pretty(thing: any): string;
10
+ export declare function pretty(thing: unknown): string;
11
+ /**
12
+ * For human inspection of IR objects, there is a lot of noise which makes
13
+ * it diifficult to read. This function makes a deep copy of the object
14
+ * stripping out location meta data and and fields with undefined values.
15
+ * Then it pretty-prints the result.
16
+ * @param value Some IR object
17
+ * @returns prettified printable version
18
+ */
19
+ export declare function humanify(value: unknown): string;
11
20
  export declare const aTableDef: SourceDef;
12
21
  /**
13
22
  * When translating partial trees, there will not be a document node
@@ -25,6 +25,7 @@
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.BetaExpression = exports.TestTranslator = exports.TestChildTranslator = exports.aTableDef = void 0;
27
27
  exports.pretty = pretty;
28
+ exports.humanify = humanify;
28
29
  exports.getExplore = getExplore;
29
30
  exports.getModelQuery = getModelQuery;
30
31
  exports.getFieldDef = getFieldDef;
@@ -48,9 +49,88 @@ const parse_malloy_1 = require("../parse-malloy");
48
49
  const static_space_1 = require("../ast/field-space/static-space");
49
50
  const global_name_space_1 = require("../ast/types/global-name-space");
50
51
  const sql_block_1 = require("../../model/sql_block");
51
- // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types
52
52
  function pretty(thing) {
53
- return (0, util_1.inspect)(thing, { breakLength: 72, depth: Infinity });
53
+ return (0, util_1.inspect)(thing, { breakLength: 100, depth: Infinity });
54
+ }
55
+ /**
56
+ * For human inspection of IR objects, there is a lot of noise which makes
57
+ * it diifficult to read. This function makes a deep copy of the object
58
+ * stripping out location meta data and and fields with undefined values.
59
+ * Then it pretty-prints the result.
60
+ * @param value Some IR object
61
+ * @returns prettified printable version
62
+ */
63
+ function humanify(value) {
64
+ const seen = new WeakMap();
65
+ function isObject(u) {
66
+ return typeof u === 'object' && u !== null;
67
+ }
68
+ function walk(u) {
69
+ // primitives & null
70
+ if (u === null || typeof u !== 'object')
71
+ return u;
72
+ // Date
73
+ if (u instanceof Date)
74
+ return new Date(u.getTime());
75
+ // RegExp
76
+ if (u instanceof RegExp)
77
+ return new RegExp(u.source, u.flags);
78
+ // Already visited (handle cycles)
79
+ if (seen.has(u))
80
+ return seen.get(u);
81
+ // Array
82
+ if (Array.isArray(u)) {
83
+ const out = [];
84
+ seen.set(u, out);
85
+ for (let i = 0; i < u.length; i++) {
86
+ out[i] = walk(u[i]);
87
+ }
88
+ return out;
89
+ }
90
+ // Map
91
+ if (u instanceof Map) {
92
+ const out = new Map();
93
+ seen.set(u, out);
94
+ for (const [k, v] of u.entries()) {
95
+ out.set(k, walk(v));
96
+ }
97
+ return out;
98
+ }
99
+ // Set
100
+ if (u instanceof Set) {
101
+ const out = new Set();
102
+ seen.set(u, out);
103
+ for (const v of u.values()) {
104
+ out.add(walk(v));
105
+ }
106
+ return out;
107
+ }
108
+ // Plain object or class instance: copy enumerable own properties,
109
+ // skipping keys "at" and "location"
110
+ if (isObject(u)) {
111
+ const out = {};
112
+ seen.set(u, out);
113
+ const src = u;
114
+ for (const key of Object.keys(src)) {
115
+ // skip location metadata
116
+ if (key === 'at' || key === 'location')
117
+ continue;
118
+ const val = src[key];
119
+ // drop properties that exist but have undefined value
120
+ if (val === undefined)
121
+ continue;
122
+ const w = walk(val);
123
+ // if the walked value is undefined, skip adding the property
124
+ if (w === undefined)
125
+ continue;
126
+ out[key] = w;
127
+ }
128
+ return out;
129
+ }
130
+ // Fallback
131
+ return u;
132
+ }
133
+ return pretty(walk(value));
54
134
  }
55
135
  const intType = { type: 'number', numberType: 'integer' };
56
136
  const mockSchema = {
@@ -23,11 +23,8 @@ function invertCompare(no) {
23
23
  return '>';
24
24
  }
25
25
  function unlike(disLiked, x) {
26
- const orNull = ` OR ${x} IS NULL`;
27
- if (disLiked.length === 1) {
28
- return `${disLiked[0]}${orNull}`;
29
- }
30
- return `(${disLiked.join(' AND ')})${orNull}`;
26
+ const unlikeSQL = disLiked.length === 1 ? disLiked[0] : `(${disLiked.join(' AND ')})`;
27
+ return `(${unlikeSQL} OR ${x} IS NULL)`;
31
28
  }
32
29
  /*
33
30
  * These compilers from filter expression to SQL actually belong in malloy-filters but
@@ -63,11 +60,11 @@ exports.FilterCompilers = {
63
60
  const optList = nc.values.join(', ');
64
61
  if (nc.values.length === 1) {
65
62
  if (notEqual)
66
- return `${x} != ${optList} OR ${x} IS NULL`;
63
+ return `(${x} != ${optList} OR ${x} IS NULL)`;
67
64
  return `${x} = ${optList}`;
68
65
  }
69
66
  if (notEqual)
70
- return `${x} NOT IN (${optList}) OR ${x} IS NULL`;
67
+ return `(${x} NOT IN (${optList}) OR ${x} IS NULL)`;
71
68
  return `${x} IN (${optList})`;
72
69
  }
73
70
  case '>':
@@ -303,7 +300,7 @@ class TemporalFilterCompiler {
303
300
  const m = this.moment(tc.in);
304
301
  if (m.begin.sql === m.end) {
305
302
  return tc.not
306
- ? `${x} != ${this.time(m.end)} OR ${x} IS NULL`
303
+ ? `(${x} != ${this.time(m.end)} OR ${x} IS NULL)`
307
304
  : `${x} = ${this.time(m.end)}`;
308
305
  }
309
306
  return this.isIn(tc.not, m.begin.sql, m.end);
@@ -1044,7 +1044,8 @@ class QueryQuery extends query_node_1.QueryField {
1044
1044
  }
1045
1045
  else {
1046
1046
  // its a complex
1047
- limitComplexClauses[result.groupSet] = `CASE WHEN ${filterClause} THEN 1 ELSE 0 END`;
1047
+ limitComplexClauses[result.groupSet] =
1048
+ `CASE WHEN ${filterClause} THEN 1 ELSE 0 END`;
1048
1049
  }
1049
1050
  }
1050
1051
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const MALLOY_VERSION = "0.0.318";
1
+ export declare const MALLOY_VERSION = "0.0.320";
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.318';
5
+ exports.MALLOY_VERSION = '0.0.320';
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.318",
3
+ "version": "0.0.320",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -41,9 +41,9 @@
41
41
  "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"
42
42
  },
43
43
  "dependencies": {
44
- "@malloydata/malloy-filter": "0.0.318",
45
- "@malloydata/malloy-interfaces": "0.0.318",
46
- "@malloydata/malloy-tag": "0.0.318",
44
+ "@malloydata/malloy-filter": "0.0.320",
45
+ "@malloydata/malloy-interfaces": "0.0.320",
46
+ "@malloydata/malloy-tag": "0.0.320",
47
47
  "antlr4ts": "^0.5.0-alpha.4",
48
48
  "assert": "^2.0.0",
49
49
  "jaro-winkler": "^0.2.8",