@malloydata/malloy 0.0.165-dev240813233925 → 0.0.165
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/dist/index.d.ts +1 -1
- package/dist/lang/malloy-to-ast.d.ts +1 -1
- package/dist/lang/malloy-to-ast.js +12 -25
- package/dist/lang/parse-malloy.d.ts +9 -1
- package/dist/lang/parse-malloy.js +25 -0
- package/dist/lang/parse-tree-walkers/find-table-path-walker.d.ts +10 -0
- package/dist/lang/parse-tree-walkers/find-table-path-walker.js +53 -0
- package/dist/lang/parse-utils.d.ts +7 -0
- package/dist/lang/parse-utils.js +35 -1
- package/dist/lang/test/find-table-path-walker.spec.d.ts +1 -0
- package/dist/lang/test/find-table-path-walker.spec.js +50 -0
- package/dist/lang/translate-response.d.ts +5 -0
- package/dist/malloy.d.ts +27 -0
- package/dist/malloy.js +39 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { Segment, isSamplingEnable, isSamplingPercent, isSamplingRows, mkExpr, e
|
|
|
5
5
|
export { MalloyTranslator, } from './lang';
|
|
6
6
|
export type { LogMessage, TranslateResponse } from './lang';
|
|
7
7
|
export { Model, Malloy, Runtime, AtomicFieldType, ConnectionRuntime, SingleConnectionRuntime, EmptyURLReader, InMemoryURLReader, FixedConnectionMap, MalloyError, JoinRelationship, SourceRelationship, DateTimeframe, TimestampTimeframe, PreparedResult, Result, QueryMaterializer, CSVWriter, JSONWriter, Parse, DataWriter, Explore, } from './malloy';
|
|
8
|
-
export type { PreparedQuery, Field, AtomicField, ExploreField, QueryField, SortableField, DataArray, DataRecord, DataColumn, DataArrayOrRecord, Loggable, ModelMaterializer, DocumentSymbol, ResultJSON, PreparedResultMaterializer, SQLBlockMaterializer, ExploreMaterializer, WriteStream, SerializedExplore, } from './malloy';
|
|
8
|
+
export type { PreparedQuery, Field, AtomicField, ExploreField, QueryField, SortableField, DataArray, DataRecord, DataColumn, DataArrayOrRecord, Loggable, ModelMaterializer, DocumentTablePath, DocumentSymbol, ResultJSON, PreparedResultMaterializer, SQLBlockMaterializer, ExploreMaterializer, WriteStream, SerializedExplore, } from './malloy';
|
|
9
9
|
export type { QueryOptionsReader, RunSQLOptions } from './run_sql_options';
|
|
10
10
|
export type { ModelString, ModelURL, QueryString, QueryURL, URLReader, } from './runtime_types';
|
|
11
11
|
export type { Connection, ConnectionConfig, ConnectionFactory, ConnectionParameter, ConnectionParameterValue, ConnectionConfigSchema, FetchSchemaOptions, InfoConnection, LookupConnection, PersistSQLResults, PooledConnection, TestableConnection, StreamingConnection, } from './connection/types';
|
|
@@ -63,7 +63,7 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
|
|
|
63
63
|
protected getFieldDefs(cxList: parse.FieldDefContext[], makeFieldDef: ast.FieldDeclarationConstructor): ast.AtomicFieldDeclaration[];
|
|
64
64
|
protected getFieldExpr(cx: parse.FieldExprContext): ast.ExpressionDef;
|
|
65
65
|
protected getFilterShortcut(cx: parse.FilterShortcutContext): ast.Filter;
|
|
66
|
-
protected
|
|
66
|
+
protected getPlainStringFrom(cx: HasString): string;
|
|
67
67
|
protected makeSqlString(pcx: parse.SqlStringContext, sqlStr: ast.SQLString): void;
|
|
68
68
|
/**
|
|
69
69
|
* Parse a time string into an AST TimeLiteral, if the string fails
|
|
@@ -200,27 +200,14 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
200
200
|
this.m4advisory(cx, 'Filter shortcut `{? condition }` is deprecated; use `{ where: condition } instead');
|
|
201
201
|
return new ast.Filter([el]);
|
|
202
202
|
}
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const safeParts = [];
|
|
209
|
-
const multiLineStr = cx.string().sqlString();
|
|
210
|
-
if (multiLineStr) {
|
|
211
|
-
for (const part of (0, parse_utils_1.getStringParts)(multiLineStr)) {
|
|
212
|
-
if (part instanceof antlr4ts_1.ParserRuleContext) {
|
|
213
|
-
this.contextError(part, '%{ query } illegal in this string');
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
safeParts.push(part);
|
|
217
|
-
}
|
|
203
|
+
getPlainStringFrom(cx) {
|
|
204
|
+
const [result, errors] = (0, parse_utils_1.getPlainString)(cx);
|
|
205
|
+
for (const error of errors) {
|
|
206
|
+
if (error instanceof antlr4ts_1.ParserRuleContext) {
|
|
207
|
+
this.contextError(error, '%{ query } illegal in this string');
|
|
218
208
|
}
|
|
219
|
-
(0, parse_utils_1.unIndent)(safeParts);
|
|
220
|
-
return safeParts.join('');
|
|
221
209
|
}
|
|
222
|
-
|
|
223
|
-
return '';
|
|
210
|
+
return result || '';
|
|
224
211
|
}
|
|
225
212
|
makeSqlString(pcx, sqlStr) {
|
|
226
213
|
for (const part of pcx.sqlInterpolation()) {
|
|
@@ -324,7 +311,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
324
311
|
return propList;
|
|
325
312
|
}
|
|
326
313
|
visitTableFunction(pcx) {
|
|
327
|
-
const tableURI = this.
|
|
314
|
+
const tableURI = this.getPlainStringFrom(pcx.tableURI());
|
|
328
315
|
const el = this.astAt(new ast.TableFunctionSource(tableURI), pcx);
|
|
329
316
|
this.m4advisory(pcx, "`table('connection_name:table_path')` is deprecated; use `connection_name.table('table_path')`");
|
|
330
317
|
return el;
|
|
@@ -332,7 +319,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
332
319
|
visitTableMethod(pcx) {
|
|
333
320
|
const connId = pcx.connectionId();
|
|
334
321
|
const connectionName = this.astAt(this.getModelEntryName(connId), connId);
|
|
335
|
-
const tablePath = this.
|
|
322
|
+
const tablePath = this.getPlainStringFrom(pcx.tablePath());
|
|
336
323
|
return this.astAt(new ast.TableMethodSource(connectionName, tablePath), pcx);
|
|
337
324
|
}
|
|
338
325
|
visitSqlSource(pcx) {
|
|
@@ -555,7 +542,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
555
542
|
return this.visitTimezoneStatement(cx.timezoneStatement());
|
|
556
543
|
}
|
|
557
544
|
visitTimezoneStatement(cx) {
|
|
558
|
-
const timezone = this.
|
|
545
|
+
const timezone = this.getPlainStringFrom(cx);
|
|
559
546
|
const timezoneStatement = this.astAt(new ast.TimezoneStatement(timezone), cx.string());
|
|
560
547
|
if (!timezoneStatement.isValid) {
|
|
561
548
|
this.astError(timezoneStatement, `Invalid timezone: ${timezoneStatement.tz}`);
|
|
@@ -889,7 +876,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
889
876
|
return fieldExpr;
|
|
890
877
|
}
|
|
891
878
|
visitExprString(pcx) {
|
|
892
|
-
const str = this.
|
|
879
|
+
const str = this.getPlainStringFrom(pcx);
|
|
893
880
|
return new ast.ExprString(str);
|
|
894
881
|
}
|
|
895
882
|
visitExprRegex(pcx) {
|
|
@@ -1061,7 +1048,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
1061
1048
|
}
|
|
1062
1049
|
const rtcx = pcx.string();
|
|
1063
1050
|
if (rtcx) {
|
|
1064
|
-
return { raw: this.
|
|
1051
|
+
return { raw: this.getPlainStringFrom({ string: () => rtcx }) };
|
|
1065
1052
|
}
|
|
1066
1053
|
throw this.internalError(pcx, 'Expected Malloy or SQL type to either be a Malloy type or a string');
|
|
1067
1054
|
}
|
|
@@ -1173,7 +1160,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
1173
1160
|
return this.parseTime(pcx, ast.LiteralYear.parse);
|
|
1174
1161
|
}
|
|
1175
1162
|
visitImportStatement(pcx) {
|
|
1176
|
-
const url = this.
|
|
1163
|
+
const url = this.getPlainStringFrom(pcx.importURL());
|
|
1177
1164
|
const importStmt = this.astAt(new ast.ImportStatement(url, this.parseInfo.importBaseURL), pcx);
|
|
1178
1165
|
const selectCx = pcx.importSelect();
|
|
1179
1166
|
if (selectCx) {
|
|
@@ -3,7 +3,7 @@ import { DocumentLocation, DocumentPosition, DocumentRange, DocumentReference, I
|
|
|
3
3
|
import { LogMessage, MessageLog, MessageLogger } from './parse-log';
|
|
4
4
|
import { Zone, ZoneData } from './zone';
|
|
5
5
|
import { ReferenceList } from './reference-list';
|
|
6
|
-
import { ASTResponse, CompletionsResponse, DataRequestResponse, ProblemResponse, FatalResponse, FinalResponse, HelpContextResponse, MetadataResponse, ModelDataRequest, NeedURLData, TranslateResponse, ModelAnnotationResponse } from './translate-response';
|
|
6
|
+
import { ASTResponse, CompletionsResponse, DataRequestResponse, ProblemResponse, FatalResponse, FinalResponse, HelpContextResponse, MetadataResponse, ModelDataRequest, NeedURLData, TranslateResponse, ModelAnnotationResponse, TablePathResponse } from './translate-response';
|
|
7
7
|
import { Tag } from '../tags';
|
|
8
8
|
import { MalloyParseInfo } from './malloy-parse-info';
|
|
9
9
|
export type StepResponses = DataRequestResponse | ASTResponse | TranslateResponse | ParseResponse | MetadataResponse;
|
|
@@ -89,6 +89,12 @@ declare class ModelAnnotationStep implements TranslationStep {
|
|
|
89
89
|
constructor(parseStep: ParseStep);
|
|
90
90
|
step(that: MalloyTranslation, extendingModel?: ModelDef): ModelAnnotationResponse;
|
|
91
91
|
}
|
|
92
|
+
declare class TablePathInfoStep implements TranslationStep {
|
|
93
|
+
readonly parseStep: ParseStep;
|
|
94
|
+
response?: TablePathResponse;
|
|
95
|
+
constructor(parseStep: ParseStep);
|
|
96
|
+
step(that: MalloyTranslation): TablePathResponse;
|
|
97
|
+
}
|
|
92
98
|
declare class TranslateStep implements TranslationStep {
|
|
93
99
|
readonly astStep: ASTStep;
|
|
94
100
|
response?: TranslateResponse;
|
|
@@ -115,6 +121,7 @@ export declare abstract class MalloyTranslation {
|
|
|
115
121
|
readonly metadataStep: MetadataStep;
|
|
116
122
|
readonly completionsStep: CompletionsStep;
|
|
117
123
|
readonly helpContextStep: HelpContextStep;
|
|
124
|
+
readonly tablePathInfoStep: TablePathInfoStep;
|
|
118
125
|
readonly translateStep: TranslateStep;
|
|
119
126
|
readonly references: ReferenceList;
|
|
120
127
|
constructor(sourceURL: string, importBaseURL?: string | null, grammarRule?: string);
|
|
@@ -144,6 +151,7 @@ export declare abstract class MalloyTranslation {
|
|
|
144
151
|
importAt(position: DocumentPosition): ImportLocation | undefined;
|
|
145
152
|
metadata(): MetadataResponse;
|
|
146
153
|
modelAnnotation(extendingModel?: ModelDef): ModelAnnotationResponse;
|
|
154
|
+
tablePathInfo(): TablePathResponse;
|
|
147
155
|
completions(position: {
|
|
148
156
|
line: number;
|
|
149
157
|
character: number;
|
|
@@ -62,6 +62,7 @@ const translate_response_1 = require("./translate-response");
|
|
|
62
62
|
const utils_1 = require("./utils");
|
|
63
63
|
const tags_1 = require("../tags");
|
|
64
64
|
const model_annotation_walker_1 = require("./parse-tree-walkers/model-annotation-walker");
|
|
65
|
+
const find_table_path_walker_1 = require("./parse-tree-walkers/find-table-path-walker");
|
|
65
66
|
/**
|
|
66
67
|
* This ignores a -> popMode when the mode stack is empty, which is a hack,
|
|
67
68
|
* but it let's us parse }%
|
|
@@ -439,6 +440,26 @@ class ModelAnnotationStep {
|
|
|
439
440
|
return this.response;
|
|
440
441
|
}
|
|
441
442
|
}
|
|
443
|
+
class TablePathInfoStep {
|
|
444
|
+
constructor(parseStep) {
|
|
445
|
+
this.parseStep = parseStep;
|
|
446
|
+
}
|
|
447
|
+
step(that) {
|
|
448
|
+
if (!this.response) {
|
|
449
|
+
const tryParse = this.parseStep.step(that);
|
|
450
|
+
if (!tryParse.parse) {
|
|
451
|
+
return tryParse;
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
const tablePath = (0, find_table_path_walker_1.walkForTablePath)(that, tryParse.parse.tokenStream, tryParse.parse);
|
|
455
|
+
this.response = {
|
|
456
|
+
pathInfo: tablePath,
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return this.response;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
442
463
|
class TranslateStep {
|
|
443
464
|
constructor(astStep) {
|
|
444
465
|
this.astStep = astStep;
|
|
@@ -551,6 +572,7 @@ class MalloyTranslation {
|
|
|
551
572
|
this.helpContextStep = new HelpContextStep(this.parseStep);
|
|
552
573
|
this.importsAndTablesStep = new ImportsAndTablesStep(this.parseStep);
|
|
553
574
|
this.astStep = new ASTStep(this.importsAndTablesStep);
|
|
575
|
+
this.tablePathInfoStep = new TablePathInfoStep(this.parseStep);
|
|
554
576
|
this.translateStep = new TranslateStep(this.astStep);
|
|
555
577
|
this.references = new reference_list_1.ReferenceList(sourceURL);
|
|
556
578
|
}
|
|
@@ -707,6 +729,9 @@ class MalloyTranslation {
|
|
|
707
729
|
modelAnnotation(extendingModel) {
|
|
708
730
|
return this.modelAnnotationStep.step(this, extendingModel);
|
|
709
731
|
}
|
|
732
|
+
tablePathInfo() {
|
|
733
|
+
return this.tablePathInfoStep.step(this);
|
|
734
|
+
}
|
|
710
735
|
completions(position) {
|
|
711
736
|
return this.completionsStep.step(this, position);
|
|
712
737
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MalloyTranslation } from '../parse-malloy';
|
|
2
|
+
import { CommonTokenStream } from 'antlr4ts';
|
|
3
|
+
import { DocumentRange } from '../../model/malloy_types';
|
|
4
|
+
import { MalloyParseInfo } from '../malloy-parse-info';
|
|
5
|
+
export interface PathInfo {
|
|
6
|
+
connectionId: string;
|
|
7
|
+
tablePath: string;
|
|
8
|
+
range: DocumentRange;
|
|
9
|
+
}
|
|
10
|
+
export declare function walkForTablePath(forParse: MalloyTranslation, tokens: CommonTokenStream, parseInfo: MalloyParseInfo): PathInfo[];
|
|
@@ -0,0 +1,53 @@
|
|
|
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.walkForTablePath = void 0;
|
|
26
|
+
const parse_utils_1 = require("../parse-utils");
|
|
27
|
+
const ParseTreeWalker_1 = require("antlr4ts/tree/ParseTreeWalker");
|
|
28
|
+
class FindTablePathWalker {
|
|
29
|
+
constructor(translator, tokens) {
|
|
30
|
+
this.translator = translator;
|
|
31
|
+
this.tokens = tokens;
|
|
32
|
+
this.pathInfos = [];
|
|
33
|
+
}
|
|
34
|
+
enterTableMethod(pcx) {
|
|
35
|
+
const connectionId = (0, parse_utils_1.getId)(pcx.connectionId());
|
|
36
|
+
const [tablePath, _errorList] = (0, parse_utils_1.getPlainString)(pcx.tablePath(), true);
|
|
37
|
+
if (tablePath !== undefined) {
|
|
38
|
+
this.pathInfos.push({
|
|
39
|
+
connectionId,
|
|
40
|
+
tablePath,
|
|
41
|
+
range: this.translator.rangeFromContext(pcx),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function walkForTablePath(forParse, tokens, parseInfo) {
|
|
47
|
+
const finder = new FindTablePathWalker(forParse, tokens);
|
|
48
|
+
const listener = finder;
|
|
49
|
+
ParseTreeWalker_1.ParseTreeWalker.DEFAULT.walk(listener, parseInfo.root);
|
|
50
|
+
return finder.pathInfos;
|
|
51
|
+
}
|
|
52
|
+
exports.walkForTablePath = walkForTablePath;
|
|
53
|
+
//# sourceMappingURL=find-table-path-walker.js.map
|
|
@@ -38,4 +38,11 @@ export declare function getId(cx: HasID): string;
|
|
|
38
38
|
export declare function idToStr(cx: IdContext): string;
|
|
39
39
|
export declare function getOptionalId(cx: ParserRuleContext): string | undefined;
|
|
40
40
|
export declare function unIndent(parts: (string | unknown)[]): void;
|
|
41
|
+
/**
|
|
42
|
+
* Returns plain string from string context.
|
|
43
|
+
* @param cx string context
|
|
44
|
+
* @param strictCheck returns undefined if non string part is found.
|
|
45
|
+
* @returns string part and an error list.
|
|
46
|
+
*/
|
|
47
|
+
export declare function getPlainString(cx: HasString, strictCheck?: boolean): [string | undefined, ParserRuleContext[]];
|
|
41
48
|
export {};
|
package/dist/lang/parse-utils.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.unIndent = exports.getOptionalId = exports.idToStr = exports.getId = exports.parseString = exports.getStringParts = exports.getStringIfShort = exports.getShortString = void 0;
|
|
25
|
+
exports.getPlainString = exports.unIndent = exports.getOptionalId = exports.idToStr = exports.getId = exports.parseString = exports.getStringParts = exports.getStringIfShort = exports.getShortString = void 0;
|
|
26
26
|
/**
|
|
27
27
|
* Take the text of a matched string, including the matching quote
|
|
28
28
|
* characters, and return the actual contents of the string after
|
|
@@ -225,4 +225,38 @@ function unIndent(parts) {
|
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
exports.unIndent = unIndent;
|
|
228
|
+
/**
|
|
229
|
+
* Returns plain string from string context.
|
|
230
|
+
* @param cx string context
|
|
231
|
+
* @param strictCheck returns undefined if non string part is found.
|
|
232
|
+
* @returns string part and an error list.
|
|
233
|
+
*/
|
|
234
|
+
function getPlainString(cx, strictCheck = false) {
|
|
235
|
+
const errorList = [];
|
|
236
|
+
const shortStr = getStringIfShort(cx);
|
|
237
|
+
if (shortStr) {
|
|
238
|
+
return [shortStr, errorList];
|
|
239
|
+
}
|
|
240
|
+
const safeParts = [];
|
|
241
|
+
const multiLineStr = cx.string().sqlString();
|
|
242
|
+
if (multiLineStr) {
|
|
243
|
+
for (const part of getStringParts(multiLineStr)) {
|
|
244
|
+
if (typeof part === 'string') {
|
|
245
|
+
safeParts.push(part);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
// Non string part found. Reject this.
|
|
249
|
+
errorList.push(part);
|
|
250
|
+
if (strictCheck) {
|
|
251
|
+
return [undefined, errorList];
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
unIndent(safeParts);
|
|
256
|
+
return [safeParts.join(''), errorList];
|
|
257
|
+
}
|
|
258
|
+
// string: shortString | sqlString; So this will never happen
|
|
259
|
+
return ['', errorList];
|
|
260
|
+
}
|
|
261
|
+
exports.getPlainString = getPlainString;
|
|
228
262
|
//# sourceMappingURL=parse-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
const test_translator_1 = require("./test-translator");
|
|
26
|
+
test('Table path can be retrieved', () => {
|
|
27
|
+
const source = (0, test_translator_1.markSource) `
|
|
28
|
+
source: flights is ${"DB.table('my.table.flights')"}
|
|
29
|
+
source: flights2 is flights extend { dimension: a is astr }
|
|
30
|
+
`;
|
|
31
|
+
const doc = new test_translator_1.TestTranslator(source.code);
|
|
32
|
+
const { pathInfo } = doc.tablePathInfo();
|
|
33
|
+
expect(pathInfo === null || pathInfo === void 0 ? void 0 : pathInfo.length).toBe(1);
|
|
34
|
+
expect(pathInfo[0].tablePath).toEqual('my.table.flights');
|
|
35
|
+
expect(pathInfo[0].connectionId).toEqual('DB');
|
|
36
|
+
expect(pathInfo[0].range).toEqual(source.locations[0].range);
|
|
37
|
+
});
|
|
38
|
+
test('Table path can not be retrieved', () => {
|
|
39
|
+
const source = (0, test_translator_1.markSource) `source: flights2 is flights extend { dimension: a is astr }`;
|
|
40
|
+
const doc = new test_translator_1.TestTranslator(source.code);
|
|
41
|
+
const { pathInfo } = doc.tablePathInfo();
|
|
42
|
+
expect(pathInfo === null || pathInfo === void 0 ? void 0 : pathInfo.length).toBe(0);
|
|
43
|
+
});
|
|
44
|
+
test('Table path can not be retrieved for non string path', () => {
|
|
45
|
+
const source = (0, test_translator_1.markSource) `source: flights is duckdb.table("""foo.bar.baz%{foo}""")`;
|
|
46
|
+
const doc = new test_translator_1.TestTranslator(source.code);
|
|
47
|
+
const { pathInfo } = doc.tablePathInfo();
|
|
48
|
+
expect(pathInfo === null || pathInfo === void 0 ? void 0 : pathInfo.length).toBe(0);
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=find-table-path-walker.spec.js.map
|
|
@@ -4,6 +4,7 @@ import { LogMessage } from './parse-log';
|
|
|
4
4
|
import { DocumentSymbol } from './parse-tree-walkers/document-symbol-walker';
|
|
5
5
|
import { DocumentCompletion } from './parse-tree-walkers/document-completion-walker';
|
|
6
6
|
import { DocumentHelpContext } from './parse-tree-walkers/document-help-context-walker';
|
|
7
|
+
import { PathInfo } from './parse-tree-walkers/find-table-path-walker';
|
|
7
8
|
/**
|
|
8
9
|
* The translation interface is essentially a request/response protocol, and
|
|
9
10
|
* this is the list of all the "protocol" messages.
|
|
@@ -61,5 +62,9 @@ interface TranslatedResponseData extends NeededData, ProblemResponse, FinalRespo
|
|
|
61
62
|
};
|
|
62
63
|
fromSources: string[];
|
|
63
64
|
}
|
|
65
|
+
interface TablePath extends NeededData, ProblemResponse, FinalResponse {
|
|
66
|
+
pathInfo: PathInfo[];
|
|
67
|
+
}
|
|
68
|
+
export type TablePathResponse = Partial<TablePath>;
|
|
64
69
|
export type TranslateResponse = Partial<TranslatedResponseData>;
|
|
65
70
|
export {};
|
package/dist/malloy.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { ModelString, ModelURL, QueryString, QueryURL, URLReader } from './runti
|
|
|
7
7
|
import { Connection, InfoConnection, LookupConnection } from './connection/types';
|
|
8
8
|
import { Tag, TagParse, TagParseSpec, Taggable } from './tags';
|
|
9
9
|
import { Dialect } from './dialect';
|
|
10
|
+
import { PathInfo } from './lang/parse-tree-walkers/find-table-path-walker';
|
|
10
11
|
export interface Loggable {
|
|
11
12
|
debug: (message?: any, ...optionalParams: any[]) => void;
|
|
12
13
|
info: (message?: any, ...optionalParams: any[]) => void;
|
|
@@ -278,6 +279,14 @@ export declare class Parse {
|
|
|
278
279
|
* @return An array of document symbols.
|
|
279
280
|
*/
|
|
280
281
|
get symbols(): DocumentSymbol[];
|
|
282
|
+
/**
|
|
283
|
+
* Retrieve the full table paths for tables defined in the parsed document.
|
|
284
|
+
* Derived tables i.e. a table that extends another table, table from a query
|
|
285
|
+
* are not included.
|
|
286
|
+
*
|
|
287
|
+
* @return An array of document table path info.
|
|
288
|
+
*/
|
|
289
|
+
get tablePathInfo(): DocumentTablePath[];
|
|
281
290
|
get _translator(): MalloyTranslator;
|
|
282
291
|
completions(position: {
|
|
283
292
|
line: number;
|
|
@@ -288,6 +297,24 @@ export declare class Parse {
|
|
|
288
297
|
character: number;
|
|
289
298
|
}): DocumentHelpContext | undefined;
|
|
290
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* Path info for a table defined in a Malloy document.
|
|
302
|
+
*/
|
|
303
|
+
export declare class DocumentTablePath {
|
|
304
|
+
private _range;
|
|
305
|
+
private _connectionId;
|
|
306
|
+
private _tablePath;
|
|
307
|
+
constructor(tablePath: PathInfo);
|
|
308
|
+
/**
|
|
309
|
+
* @return The range of characters in the source Malloy document that defines
|
|
310
|
+
* this table.
|
|
311
|
+
*/
|
|
312
|
+
get range(): DocumentRange;
|
|
313
|
+
/** @return The Connection Id for this table. */
|
|
314
|
+
get connectionId(): string;
|
|
315
|
+
/** @return The full table path. */
|
|
316
|
+
get tablePath(): string;
|
|
317
|
+
}
|
|
291
318
|
/**
|
|
292
319
|
* A range of characters within a Malloy document.
|
|
293
320
|
*/
|
package/dist/malloy.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.CSVWriter = exports.JSONWriter = exports.DataWriter = exports.DataRecord = exports.DataArray = exports.Result = exports.ExploreMaterializer = exports.SQLBlockMaterializer = exports.PreparedResultMaterializer = exports.QueryMaterializer = exports.ModelMaterializer = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.Runtime = exports.ExploreField = exports.JoinRelationship = exports.QueryField = exports.Query = exports.StringField = exports.UnsupportedField = exports.JSONField = exports.BooleanField = exports.NumberField = exports.TimestampField = exports.DateField = exports.TimestampTimeframe = exports.DateTimeframe = exports.AtomicField = exports.AtomicFieldType = exports.Explore = exports.SourceRelationship = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = exports.PreparedResult = exports.DocumentCompletion = exports.DocumentSymbol = exports.DocumentPosition = exports.DocumentRange = exports.Parse = exports.PreparedQuery = exports.Model = exports.MalloyError = exports.Malloy = void 0;
|
|
25
|
+
exports.CSVWriter = exports.JSONWriter = exports.DataWriter = exports.DataRecord = exports.DataArray = exports.Result = exports.ExploreMaterializer = exports.SQLBlockMaterializer = exports.PreparedResultMaterializer = exports.QueryMaterializer = exports.ModelMaterializer = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.Runtime = exports.ExploreField = exports.JoinRelationship = exports.QueryField = exports.Query = exports.StringField = exports.UnsupportedField = exports.JSONField = exports.BooleanField = exports.NumberField = exports.TimestampField = exports.DateField = exports.TimestampTimeframe = exports.DateTimeframe = exports.AtomicField = exports.AtomicFieldType = exports.Explore = exports.SourceRelationship = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = exports.PreparedResult = exports.DocumentCompletion = exports.DocumentSymbol = exports.DocumentPosition = exports.DocumentRange = exports.DocumentTablePath = exports.Parse = exports.PreparedQuery = exports.Model = exports.MalloyError = exports.Malloy = void 0;
|
|
26
26
|
const lang_1 = require("./lang");
|
|
27
27
|
const model_1 = require("./model");
|
|
28
28
|
const luxon_1 = require("luxon");
|
|
@@ -560,6 +560,18 @@ class Parse {
|
|
|
560
560
|
get symbols() {
|
|
561
561
|
return (this.translator.metadata().symbols || []).map(symbol => new DocumentSymbol(symbol));
|
|
562
562
|
}
|
|
563
|
+
/**
|
|
564
|
+
* Retrieve the full table paths for tables defined in the parsed document.
|
|
565
|
+
* Derived tables i.e. a table that extends another table, table from a query
|
|
566
|
+
* are not included.
|
|
567
|
+
*
|
|
568
|
+
* @return An array of document table path info.
|
|
569
|
+
*/
|
|
570
|
+
get tablePathInfo() {
|
|
571
|
+
var _a;
|
|
572
|
+
const paths = (_a = this.translator.tablePathInfo().pathInfo) !== null && _a !== void 0 ? _a : [];
|
|
573
|
+
return paths.map(path => new DocumentTablePath(path));
|
|
574
|
+
}
|
|
563
575
|
get _translator() {
|
|
564
576
|
return this.translator;
|
|
565
577
|
}
|
|
@@ -571,6 +583,32 @@ class Parse {
|
|
|
571
583
|
}
|
|
572
584
|
}
|
|
573
585
|
exports.Parse = Parse;
|
|
586
|
+
/**
|
|
587
|
+
* Path info for a table defined in a Malloy document.
|
|
588
|
+
*/
|
|
589
|
+
class DocumentTablePath {
|
|
590
|
+
constructor(tablePath) {
|
|
591
|
+
this._range = DocumentRange.fromJSON(tablePath.range);
|
|
592
|
+
this._connectionId = tablePath.connectionId;
|
|
593
|
+
this._tablePath = tablePath.tablePath;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* @return The range of characters in the source Malloy document that defines
|
|
597
|
+
* this table.
|
|
598
|
+
*/
|
|
599
|
+
get range() {
|
|
600
|
+
return this._range;
|
|
601
|
+
}
|
|
602
|
+
/** @return The Connection Id for this table. */
|
|
603
|
+
get connectionId() {
|
|
604
|
+
return this._connectionId;
|
|
605
|
+
}
|
|
606
|
+
/** @return The full table path. */
|
|
607
|
+
get tablePath() {
|
|
608
|
+
return this._tablePath;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
exports.DocumentTablePath = DocumentTablePath;
|
|
574
612
|
/**
|
|
575
613
|
* A range of characters within a Malloy document.
|
|
576
614
|
*/
|