@malloydata/malloy 0.0.2 → 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.
- package/README.md +12 -11
- package/dist/dialect/duckdb.d.ts +1 -1
- package/dist/dialect/postgres.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/lang/ast/ast-expr.d.ts +0 -1
- package/dist/lang/field-space.d.ts +9 -7
- package/dist/lang/lib/Malloy/MalloyLexer.d.ts +108 -106
- package/dist/lang/lib/Malloy/MalloyLexer.js +1019 -1006
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +581 -590
- package/dist/lang/lib/Malloy/MalloyParser.js +1141 -1202
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +2015 -0
- package/dist/lang/lib/Malloy/MalloyParserListener.js +4 -0
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +1269 -0
- package/dist/lang/lib/Malloy/MalloyParserVisitor.js +4 -0
- package/dist/lang/parse-to-ast.d.ts +3 -4
- package/dist/lang/parse-to-ast.js +1 -1
- package/dist/lang/parse-tree-walkers/document-completion-walker.js +2 -0
- package/dist/lang/parse-tree-walkers/explore-query-walker.d.ts +2 -2
- package/dist/malloy.d.ts +1 -1
- package/dist/md5.d.ts +1 -0
- package/dist/md5.js +30 -0
- package/dist/model/malloy_types.d.ts +3 -1
- package/package.json +9 -14
- package/dist/connection_utils.js +0 -56
- package/dist/dialect/dialect-map.d.ts +0 -3
- package/dist/dialect/dialect-map.js +0 -33
- package/dist/dialect/dialect.js +0 -77
- package/dist/dialect/dialect_map.js +0 -35
- package/dist/dialect/duckdb.js +0 -349
- package/dist/dialect/index.js +0 -27
- package/dist/dialect/postgres.js +0 -308
- package/dist/dialect/standardsql.js +0 -361
- package/dist/index.js +0 -47
- package/dist/lang/ast/apply-expr.js +0 -231
- package/dist/lang/ast/ast-expr.js +0 -1051
- package/dist/lang/ast/ast-main.js +0 -2086
- package/dist/lang/ast/ast-time-expr.js +0 -549
- package/dist/lang/ast/ast-types.js +0 -215
- package/dist/lang/ast/index.js +0 -34
- package/dist/lang/ast/time-utils.js +0 -94
- package/dist/lang/field-space.js +0 -629
- package/dist/lang/field-utils.js +0 -33
- package/dist/lang/index.js +0 -22
- package/dist/lang/parse-log.js +0 -41
- package/dist/lang/reference-list.js +0 -80
- package/dist/lang/space-field.js +0 -346
- package/dist/lang/test/document-help-context-walker.spec.js +0 -45
- package/dist/lang/test/document-symbol-walker.spec.js +0 -100
- package/dist/lang/test/field-symbols.spec.js +0 -172
- package/dist/lang/test/parse.spec.js +0 -1936
- package/dist/lang/test/test-translator.js +0 -334
- package/dist/lang/zone.js +0 -97
- package/dist/malloy.js +0 -2354
- package/dist/model/index.js +0 -34
- package/dist/model/malloy-query.d.ts +0 -313
- package/dist/model/malloy-query.js +0 -2603
- package/dist/model/malloy-types.d.ts +0 -404
- package/dist/model/malloy-types.js +0 -242
- package/dist/model/malloy_query.js +0 -2996
- package/dist/model/malloy_types.js +0 -283
- package/dist/model/sql-block.d.ts +0 -11
- package/dist/model/sql-block.js +0 -38
- package/dist/model/sql_block.js +0 -41
- package/dist/model/utils.js +0 -84
- package/dist/runtime-types.d.ts +0 -116
- package/dist/runtime-types.js +0 -40
- 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,11 +0,0 @@
|
|
|
1
|
-
import { SQLBlock } from "./malloy-types";
|
|
2
|
-
/**
|
|
3
|
-
* SQLBlockRequest does not have a digest in it
|
|
4
|
-
*/
|
|
5
|
-
export interface SQLBlockRequest extends Partial<SQLBlock> {
|
|
6
|
-
select: string;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* The factory for SQLBlocks.
|
|
10
|
-
*/
|
|
11
|
-
export declare function makeSQLBlock(from: SQLBlockRequest): SQLBlock;
|
package/dist/model/sql-block.js
DELETED
|
@@ -1,38 +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
|
-
return theBlock;
|
|
36
|
-
}
|
|
37
|
-
exports.makeSQLBlock = makeSQLBlock;
|
|
38
|
-
//# sourceMappingURL=sql-block.js.map
|
package/dist/model/sql_block.js
DELETED
|
@@ -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
|
package/dist/model/utils.js
DELETED
|
@@ -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
|
package/dist/runtime-types.d.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { MalloyQueryData, SQLBlock, StructDef } from "./model";
|
|
2
|
-
/**
|
|
3
|
-
* A URL.
|
|
4
|
-
*/
|
|
5
|
-
export declare class URL {
|
|
6
|
-
private _url;
|
|
7
|
-
constructor(stringURL: string);
|
|
8
|
-
/**
|
|
9
|
-
* @returns The string form of this URL.
|
|
10
|
-
*/
|
|
11
|
-
toString(): string;
|
|
12
|
-
/**
|
|
13
|
-
* Construct a URL from string.
|
|
14
|
-
*
|
|
15
|
-
* @param stringURL The string form of the URL.
|
|
16
|
-
* @returns A URL.
|
|
17
|
-
*/
|
|
18
|
-
static fromString(stringURL: string): URL;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* The contents of a Malloy query document.
|
|
22
|
-
*/
|
|
23
|
-
export declare type QueryString = string;
|
|
24
|
-
/**
|
|
25
|
-
* The contents of a Malloy model document.
|
|
26
|
-
*/
|
|
27
|
-
export declare type ModelString = string;
|
|
28
|
-
/**
|
|
29
|
-
* A URL whose contents is a Malloy model.
|
|
30
|
-
*/
|
|
31
|
-
export declare type ModelURL = URL;
|
|
32
|
-
/**
|
|
33
|
-
* A URL whose contents is a Malloy query.
|
|
34
|
-
*/
|
|
35
|
-
export declare type QueryURL = URL;
|
|
36
|
-
/**
|
|
37
|
-
* An object capable of reading the contents of a URL in some context.
|
|
38
|
-
*/
|
|
39
|
-
export interface URLReader {
|
|
40
|
-
/**
|
|
41
|
-
* Read the contents of the given URL.
|
|
42
|
-
*
|
|
43
|
-
* @param url The URL to read.
|
|
44
|
-
* @returns A promise to the contents of the URL.
|
|
45
|
-
*/
|
|
46
|
-
readURL: (url: URL) => Promise<string>;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* An object capable of reading schemas for given table names.
|
|
50
|
-
*/
|
|
51
|
-
export interface InfoConnection {
|
|
52
|
-
/**
|
|
53
|
-
* Fetch schemas for multiple tables.
|
|
54
|
-
*
|
|
55
|
-
* @param tables The names of tables to fetch schemas for.
|
|
56
|
-
* @returns A mapping of table names to schemas.
|
|
57
|
-
*/
|
|
58
|
-
fetchSchemaForTables(tables: string[]): Promise<{
|
|
59
|
-
schemas: Record<string, StructDef>;
|
|
60
|
-
errors: Record<string, string>;
|
|
61
|
-
}>;
|
|
62
|
-
/**
|
|
63
|
-
* Fetch schemas for multiple SQL blocks.
|
|
64
|
-
*
|
|
65
|
-
* @param tables The SQL blocks to fetch schemas for.
|
|
66
|
-
* @returns A mapping of SQL block names to schemas.
|
|
67
|
-
*/
|
|
68
|
-
fetchSchemaForSQLBlocks(sqlStructs: SQLBlock[]): Promise<{
|
|
69
|
-
schemas: Record<string, StructDef>;
|
|
70
|
-
errors: Record<string, string>;
|
|
71
|
-
}>;
|
|
72
|
-
/**
|
|
73
|
-
* The name of the connection.
|
|
74
|
-
*/
|
|
75
|
-
get name(): string;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* An object capable of running SQL.
|
|
79
|
-
*/
|
|
80
|
-
export interface Connection extends InfoConnection {
|
|
81
|
-
/**
|
|
82
|
-
* Run some SQL and yield results.
|
|
83
|
-
*
|
|
84
|
-
* @param sql The SQL to run.
|
|
85
|
-
* @param options.pageSize Maximum number of results to return at once.
|
|
86
|
-
* @returns The rows of data resulting from running the given SQL query
|
|
87
|
-
* and the total number of rows available.
|
|
88
|
-
*/
|
|
89
|
-
runSQL(sql: string, options?: {
|
|
90
|
-
rowLimit?: number;
|
|
91
|
-
}): Promise<MalloyQueryData>;
|
|
92
|
-
runSQLBlockAndFetchResultSchema(sqlBlock: SQLBlock, options?: {
|
|
93
|
-
rowLimit?: number;
|
|
94
|
-
}): Promise<{
|
|
95
|
-
data: MalloyQueryData;
|
|
96
|
-
schema: StructDef;
|
|
97
|
-
}>;
|
|
98
|
-
isPool(): this is PooledConnection;
|
|
99
|
-
}
|
|
100
|
-
export interface TestableConnection extends Connection {
|
|
101
|
-
test(): Promise<void>;
|
|
102
|
-
}
|
|
103
|
-
export interface PooledConnection extends Connection {
|
|
104
|
-
drain(): Promise<void>;
|
|
105
|
-
isPool(): true;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* A mapping of connection names to connections.
|
|
109
|
-
*/
|
|
110
|
-
export interface LookupConnection<T extends InfoConnection> {
|
|
111
|
-
/**
|
|
112
|
-
* @param connectionName The name of the connection for which a `Connection` is required.
|
|
113
|
-
* @returns A promise to a `Connection` for the connection named `connectionName`.
|
|
114
|
-
*/
|
|
115
|
-
lookupConnection(connectionName?: string): Promise<T>;
|
|
116
|
-
}
|
package/dist/runtime-types.js
DELETED
|
@@ -1,40 +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.URL = void 0;
|
|
16
|
-
/**
|
|
17
|
-
* A URL.
|
|
18
|
-
*/
|
|
19
|
-
class URL {
|
|
20
|
-
constructor(stringURL) {
|
|
21
|
-
this._url = stringURL;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* @returns The string form of this URL.
|
|
25
|
-
*/
|
|
26
|
-
toString() {
|
|
27
|
-
return this._url;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Construct a URL from string.
|
|
31
|
-
*
|
|
32
|
-
* @param stringURL The string form of the URL.
|
|
33
|
-
* @returns A URL.
|
|
34
|
-
*/
|
|
35
|
-
static fromString(stringURL) {
|
|
36
|
-
return new URL(stringURL);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.URL = URL;
|
|
40
|
-
//# sourceMappingURL=runtime-types.js.map
|
package/dist/runtime_types.js
DELETED
|
@@ -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
|