@malloydata/malloy 0.0.3 → 0.0.4

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 (37) hide show
  1. package/dist/lang/ast/ast-expr.d.ts +0 -1
  2. package/dist/lang/ast/ast-main.d.ts +2 -2
  3. package/package.json +1 -1
  4. package/dist/connection_utils.js +0 -56
  5. package/dist/dialect/dialect.js +0 -77
  6. package/dist/dialect/dialect_map.js +0 -35
  7. package/dist/dialect/duckdb.js +0 -347
  8. package/dist/dialect/index.js +0 -27
  9. package/dist/dialect/postgres.js +0 -315
  10. package/dist/dialect/standardsql.js +0 -362
  11. package/dist/index.js +0 -47
  12. package/dist/lang/ast/apply-expr.js +0 -231
  13. package/dist/lang/ast/ast-expr.js +0 -1041
  14. package/dist/lang/ast/ast-main.js +0 -2087
  15. package/dist/lang/ast/ast-time-expr.js +0 -549
  16. package/dist/lang/ast/ast-types.js +0 -215
  17. package/dist/lang/ast/index.js +0 -34
  18. package/dist/lang/ast/time-utils.js +0 -94
  19. package/dist/lang/field-space.js +0 -631
  20. package/dist/lang/field-utils.js +0 -33
  21. package/dist/lang/index.js +0 -22
  22. package/dist/lang/parse-log.js +0 -41
  23. package/dist/lang/reference-list.js +0 -80
  24. package/dist/lang/space-field.js +0 -346
  25. package/dist/lang/test/document-help-context-walker.spec.js +0 -45
  26. package/dist/lang/test/document-symbol-walker.spec.js +0 -100
  27. package/dist/lang/test/field-symbols.spec.js +0 -172
  28. package/dist/lang/test/parse.spec.js +0 -1951
  29. package/dist/lang/test/test-translator.js +0 -334
  30. package/dist/lang/zone.js +0 -97
  31. package/dist/malloy.js +0 -2360
  32. package/dist/model/index.js +0 -34
  33. package/dist/model/malloy_query.js +0 -2994
  34. package/dist/model/malloy_types.js +0 -283
  35. package/dist/model/sql_block.js +0 -41
  36. package/dist/model/utils.js +0 -84
  37. package/dist/runtime_types.js +0 -15
@@ -1,283 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright 2021 Google LLC
4
- *
5
- * This program is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License
7
- * version 2 as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- */
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.isValueDate = exports.isValueTimestamp = exports.isValueBoolean = exports.isValueNumber = exports.isValueString = exports.isMeasureLike = exports.getPhysicalFields = exports.getDimensions = exports.isPhysical = exports.isDimensional = exports.isTurtleDef = exports.getIdentifier = exports.isFieldStructDef = exports.isFieldTimeBased = exports.isFieldTypeDef = exports.isJoinOn = exports.isIndexSegment = exports.isSamplingEnable = exports.isSamplingPercent = exports.isSamplingRows = exports.isQuerySegment = exports.isProjectSegment = exports.isReduceSegment = exports.refIsStructDef = exports.isByExpression = exports.isByName = exports.ValueType = exports.isExtractUnit = exports.isTimestampUnit = exports.isDateUnit = exports.FieldIsIntrinsic = exports.isAtomicFieldType = exports.isTimeFieldType = exports.hasExpression = exports.mkExpr = exports.isApplyFragment = exports.isApplyValue = exports.isParameterFragment = exports.isFieldFragment = exports.isUngroupFragment = exports.isAsymmetricFragment = exports.isAggregateFragment = exports.isDialectFragment = exports.isFilterFragment = exports.isFilteredAliasedName = exports.paramHasValue = exports.isConditionParameter = exports.isValueParameter = void 0;
16
- function isValueParameter(p) {
17
- return p.value !== undefined;
18
- }
19
- exports.isValueParameter = isValueParameter;
20
- function isConditionParameter(p) {
21
- return p.condition !== undefined;
22
- }
23
- exports.isConditionParameter = isConditionParameter;
24
- function paramHasValue(p) {
25
- return isValueParameter(p) || p.condition !== null;
26
- }
27
- exports.paramHasValue = paramHasValue;
28
- function isFilteredAliasedName(f) {
29
- for (const prop of Object.keys(f)) {
30
- if (!["name", "as", "filterList"].includes(prop)) {
31
- return false;
32
- }
33
- }
34
- return true;
35
- }
36
- exports.isFilteredAliasedName = isFilteredAliasedName;
37
- function isFilterFragment(f) {
38
- return (f === null || f === void 0 ? void 0 : f.type) === "filterExpression";
39
- }
40
- exports.isFilterFragment = isFilterFragment;
41
- function isDialectFragment(f) {
42
- return (f === null || f === void 0 ? void 0 : f.type) === "dialect";
43
- }
44
- exports.isDialectFragment = isDialectFragment;
45
- function isAggregateFragment(f) {
46
- return (f === null || f === void 0 ? void 0 : f.type) === "aggregate";
47
- }
48
- exports.isAggregateFragment = isAggregateFragment;
49
- function isAsymmetricFragment(f) {
50
- return isAggregateFragment(f) && ["sum", "avg", "count"].includes(f.function);
51
- }
52
- exports.isAsymmetricFragment = isAsymmetricFragment;
53
- function isUngroupFragment(f) {
54
- const ftype = f === null || f === void 0 ? void 0 : f.type;
55
- return ftype == "all" || ftype == "exclude";
56
- }
57
- exports.isUngroupFragment = isUngroupFragment;
58
- function isFieldFragment(f) {
59
- return (f === null || f === void 0 ? void 0 : f.type) === "field";
60
- }
61
- exports.isFieldFragment = isFieldFragment;
62
- function isParameterFragment(f) {
63
- return (f === null || f === void 0 ? void 0 : f.type) === "parameter";
64
- }
65
- exports.isParameterFragment = isParameterFragment;
66
- function isApplyValue(f) {
67
- return (f === null || f === void 0 ? void 0 : f.type) === "applyVal";
68
- }
69
- exports.isApplyValue = isApplyValue;
70
- function isApplyFragment(f) {
71
- return (f === null || f === void 0 ? void 0 : f.type) === "apply";
72
- }
73
- exports.isApplyFragment = isApplyFragment;
74
- /**
75
- * Return an Expr based on the string template, subsittutions can be
76
- * either strings, or other Exprs.
77
-
78
- * ```
79
- * units = "inches"
80
- * len: Expr = [ "something", "returning", "a length "]
81
- * computeExpr = mkExpr`MEASURE(${len} in ${units})`;
82
- * ```
83
- */
84
- function mkExpr(src, ...exprs) {
85
- const ret = [];
86
- let index;
87
- for (index = 0; index < exprs.length; index++) {
88
- const el = exprs[index];
89
- if (src[index].length > 0) {
90
- ret.push(src[index]);
91
- }
92
- if (typeof el == "string") {
93
- ret.push(el);
94
- }
95
- else {
96
- ret.push(...el);
97
- }
98
- }
99
- if (src[index].length > 0) {
100
- ret.push(src[index]);
101
- }
102
- return ret;
103
- }
104
- exports.mkExpr = mkExpr;
105
- /** Grants access to the expression property of a FielfDef */
106
- function hasExpression(f) {
107
- return f.e !== undefined;
108
- }
109
- exports.hasExpression = hasExpression;
110
- function isTimeFieldType(s) {
111
- return s == "date" || s == "timestamp";
112
- }
113
- exports.isTimeFieldType = isTimeFieldType;
114
- function isAtomicFieldType(s) {
115
- return ["string", "number", "date", "timestamp", "boolean"].includes(s);
116
- }
117
- exports.isAtomicFieldType = isAtomicFieldType;
118
- // this field definition represents something in the database.
119
- function FieldIsIntrinsic(f) {
120
- if (isAtomicFieldType(f.type) && !hasExpression(f)) {
121
- return true;
122
- }
123
- else if (f.type === "struct" &&
124
- (f.structSource.type === "inline" || f.structSource.type === "nested")) {
125
- return true;
126
- }
127
- else {
128
- return false;
129
- }
130
- }
131
- exports.FieldIsIntrinsic = FieldIsIntrinsic;
132
- function isDateUnit(str) {
133
- return ["day", "week", "month", "quarter", "year"].includes(str);
134
- }
135
- exports.isDateUnit = isDateUnit;
136
- function isTimestampUnit(s) {
137
- return isDateUnit(s) || ["hour", "minute", "second"].includes(s);
138
- }
139
- exports.isTimestampUnit = isTimestampUnit;
140
- function isExtractUnit(s) {
141
- return isTimestampUnit(s) || s == "day_of_week" || s == "day_of_year";
142
- }
143
- exports.isExtractUnit = isExtractUnit;
144
- /** Value types distinguished by their usage in generated SQL, particularly with respect to filters. */
145
- var ValueType;
146
- (function (ValueType) {
147
- ValueType["Date"] = "date";
148
- ValueType["Timestamp"] = "timestamp";
149
- ValueType["Number"] = "number";
150
- ValueType["String"] = "string";
151
- })(ValueType = exports.ValueType || (exports.ValueType = {}));
152
- function isByName(by) {
153
- if (by === undefined) {
154
- return false;
155
- }
156
- return by.by === "name";
157
- }
158
- exports.isByName = isByName;
159
- function isByExpression(by) {
160
- if (by === undefined) {
161
- return false;
162
- }
163
- return by.by === "name";
164
- }
165
- exports.isByExpression = isByExpression;
166
- function refIsStructDef(ref) {
167
- return typeof ref !== "string" && ref.type === "struct";
168
- }
169
- exports.refIsStructDef = refIsStructDef;
170
- function isReduceSegment(pe) {
171
- return pe.type === "reduce";
172
- }
173
- exports.isReduceSegment = isReduceSegment;
174
- function isProjectSegment(pe) {
175
- return pe.type === "project";
176
- }
177
- exports.isProjectSegment = isProjectSegment;
178
- function isQuerySegment(pe) {
179
- return isProjectSegment(pe) || isReduceSegment(pe);
180
- }
181
- exports.isQuerySegment = isQuerySegment;
182
- function isSamplingRows(s) {
183
- return s.rows !== undefined;
184
- }
185
- exports.isSamplingRows = isSamplingRows;
186
- function isSamplingPercent(s) {
187
- return s.percent !== undefined;
188
- }
189
- exports.isSamplingPercent = isSamplingPercent;
190
- function isSamplingEnable(s) {
191
- return s.enable !== undefined;
192
- }
193
- exports.isSamplingEnable = isSamplingEnable;
194
- function isIndexSegment(pe) {
195
- return pe.type === "index";
196
- }
197
- exports.isIndexSegment = isIndexSegment;
198
- function isJoinOn(sr) {
199
- return ["one", "many", "cross"].includes(sr.type);
200
- }
201
- exports.isJoinOn = isJoinOn;
202
- function isFieldTypeDef(f) {
203
- return (f.type === "string" ||
204
- f.type === "date" ||
205
- f.type === "number" ||
206
- f.type === "timestamp" ||
207
- f.type === "boolean");
208
- }
209
- exports.isFieldTypeDef = isFieldTypeDef;
210
- function isFieldTimeBased(f) {
211
- return f.type === "date" || f.type === "timestamp";
212
- }
213
- exports.isFieldTimeBased = isFieldTimeBased;
214
- function isFieldStructDef(f) {
215
- return f.type === "struct";
216
- }
217
- exports.isFieldStructDef = isFieldStructDef;
218
- /** Get the output name for a NamedObject */
219
- function getIdentifier(n) {
220
- if (n.as !== undefined) {
221
- return n.as;
222
- }
223
- return n.name;
224
- }
225
- exports.getIdentifier = getIdentifier;
226
- function isTurtleDef(def) {
227
- return def.type === "turtle";
228
- }
229
- exports.isTurtleDef = isTurtleDef;
230
- function isDimensional(field) {
231
- var _a;
232
- if ("resultMetadata" in field) {
233
- return ((_a = field.resultMetadata) === null || _a === void 0 ? void 0 : _a.fieldKind) === "dimension";
234
- }
235
- return false;
236
- }
237
- exports.isDimensional = isDimensional;
238
- function isPhysical(field) {
239
- return ((isFieldTypeDef(field) && field.e === undefined) ||
240
- (isFieldStructDef(field) &&
241
- (field.structSource.type === "nested" ||
242
- field.structSource.type == "inline")));
243
- }
244
- exports.isPhysical = isPhysical;
245
- function getDimensions(structDef) {
246
- return structDef.fields.filter(isDimensional);
247
- }
248
- exports.getDimensions = getDimensions;
249
- function getPhysicalFields(structDef) {
250
- return structDef.fields.filter(isPhysical);
251
- }
252
- exports.getPhysicalFields = getPhysicalFields;
253
- function isMeasureLike(field) {
254
- var _a, _b;
255
- if ("resultMetadata" in field) {
256
- return (((_a = field.resultMetadata) === null || _a === void 0 ? void 0 : _a.fieldKind) === "measure" ||
257
- ((_b = field.resultMetadata) === null || _b === void 0 ? void 0 : _b.fieldKind) === "struct");
258
- }
259
- return false;
260
- }
261
- exports.isMeasureLike = isMeasureLike;
262
- function isValueString(value, field) {
263
- return field.type === "string";
264
- }
265
- exports.isValueString = isValueString;
266
- function isValueNumber(value, field) {
267
- return field.type === "number";
268
- }
269
- exports.isValueNumber = isValueNumber;
270
- function isValueBoolean(value, field) {
271
- return field.type === "boolean";
272
- }
273
- exports.isValueBoolean = isValueBoolean;
274
- function isValueTimestamp(value, field) {
275
- return field.type === "timestamp";
276
- }
277
- exports.isValueTimestamp = isValueTimestamp;
278
- function isValueDate(value, field) {
279
- return field.type === "date";
280
- }
281
- exports.isValueDate = isValueDate;
282
- // clang-format on
283
- //# sourceMappingURL=malloy_types.js.map
@@ -1,41 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright 2022 Google LLC
4
- *
5
- * This program is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License
7
- * version 2 as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- */
14
- var __importDefault = (this && this.__importDefault) || function (mod) {
15
- return (mod && mod.__esModule) ? mod : { "default": mod };
16
- };
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.makeSQLBlock = void 0;
19
- const md5_1 = __importDefault(require("md5"));
20
- /**
21
- * The factory for SQLBlocks.
22
- */
23
- function makeSQLBlock(from) {
24
- const theBlock = {
25
- type: "sqlBlock",
26
- name: `md5:/${from.connection || "$default"}//${(0, md5_1.default)(from.select)}`,
27
- select: from.select,
28
- };
29
- if (from.before) {
30
- theBlock.before = from.before;
31
- }
32
- if (from.after) {
33
- theBlock.after = from.after;
34
- }
35
- if (from.connection) {
36
- theBlock.connection = from.connection;
37
- }
38
- return theBlock;
39
- }
40
- exports.makeSQLBlock = makeSQLBlock;
41
- //# sourceMappingURL=sql_block.js.map
@@ -1,84 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright 2021 Google LLC
4
- *
5
- * This program is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License
7
- * version 2 as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- */
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.AndChain = exports.generateSQLStringLiteral = exports.indent = void 0;
16
- /** simple indent function */
17
- function indent(s) {
18
- const re = /(^|\n)/g;
19
- const lastNewline = /\n {2}$/;
20
- return s.replace(re, "$1 ").replace(lastNewline, "\n");
21
- }
22
- exports.indent = indent;
23
- /**
24
- * Generate a SQL string literal from a given `input` string, safe, e.g., to be used in `WHERE` clauses.
25
- */
26
- function generateSQLStringLiteral(input) {
27
- const escapedString = input.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
28
- return `'${escapedString}'`;
29
- }
30
- exports.generateSQLStringLiteral = generateSQLStringLiteral;
31
- /**
32
- * WHERE and HAVING clauses are built out of a chain of boolean experssions
33
- * joined with AND.
34
- */
35
- class AndChain {
36
- constructor(intial) {
37
- this.clauses = [];
38
- if (intial) {
39
- this.clauses.push(intial);
40
- }
41
- }
42
- clone() {
43
- const theClone = new AndChain();
44
- theClone.addChain(this);
45
- return theClone;
46
- }
47
- add(clause) {
48
- this.clauses.push(clause);
49
- return this;
50
- }
51
- addChain(andChain) {
52
- this.clauses.push(...andChain.clauses);
53
- return this;
54
- }
55
- empty() {
56
- return this.clauses.length === 0;
57
- }
58
- present() {
59
- return this.clauses.length > 0;
60
- }
61
- sqlOr() {
62
- if (this.empty()) {
63
- return "";
64
- }
65
- return this.clauses.map((c) => `(${c})`).join("OR ") + "\n";
66
- }
67
- sql(whereOrHaving) {
68
- if (this.empty()) {
69
- return "";
70
- }
71
- let prefix = "";
72
- let postfix = "";
73
- if (whereOrHaving) {
74
- prefix = whereOrHaving.toUpperCase() + " ";
75
- postfix = "\n";
76
- }
77
- if (this.clauses.length === 1) {
78
- return prefix + this.clauses[0] + postfix;
79
- }
80
- return prefix + this.clauses.map((c) => `(${c})`).join("\nAND ") + postfix;
81
- }
82
- }
83
- exports.AndChain = AndChain;
84
- //# sourceMappingURL=utils.js.map
@@ -1,15 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright 2022 Google LLC
4
- *
5
- * This program is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License
7
- * version 2 as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- */
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- //# sourceMappingURL=runtime_types.js.map