@hamelin.sh/compiler 0.1.29 → 0.1.32-prerelease.20250606T185046

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 (3) hide show
  1. package/dist/main.d.ts +148 -72
  2. package/dist/main.js +3279 -3429
  3. package/package.json +6 -3
package/dist/main.d.ts CHANGED
@@ -12,11 +12,65 @@ interface FunctionDescription {
12
12
  parameters: string;
13
13
  }
14
14
 
15
+ interface ContextualResult {
16
+ hamelin: string;
17
+ errors: ContextualTranslationError[];
18
+ completions: ContextualCompletion | undefined;
19
+ translation: Translation | undefined;
20
+ }
21
+
22
+ interface ContextualCompletion {
23
+ pretty: string;
24
+ completion: Completion;
25
+ }
26
+
27
+ type CompletionItemKind = "Text" | "Variable" | "Function" | "Command" | "Keyword";
28
+
29
+ interface CompletionItem {
30
+ /**
31
+ * What to show
32
+ */
33
+ label: string;
34
+ /**
35
+ * What to actually put down
36
+ */
37
+ apply_string: string;
38
+ /**
39
+ * Small text next to the label.
40
+ */
41
+ detail: string | undefined;
42
+ /**
43
+ * Floating shit out to the right.
44
+ */
45
+ description: string | undefined;
46
+ /**
47
+ * Icon
48
+ */
49
+ kind: CompletionItemKind;
50
+ snippet: string | undefined;
51
+ /**
52
+ * Which section of text.
53
+ */
54
+ section: string | undefined;
55
+ }
56
+
57
+ interface Completion {
58
+ at: { start: number; end: number };
59
+ items: CompletionItem[];
60
+ }
61
+
62
+ interface Translation {
63
+ sql: string;
64
+ columns: Column[];
65
+ }
66
+
15
67
  interface ContextualTranslationErrors {
16
68
  hamelin: string;
17
69
  errors: ContextualTranslationError[];
18
70
  }
19
71
 
72
+ type TranslationErrors = TranslationError[];
73
+
20
74
  interface Context {
21
75
  interval: { start: number; end: number } | undefined;
22
76
  message: string;
@@ -42,11 +96,6 @@ type LanguageArea = "FunctionCall" | "Operator" | "Deref" | "IndexAccess" | "Par
42
96
 
43
97
  type Level = "Error" | "Warning" | "Info";
44
98
 
45
- interface Translation {
46
- sql: string;
47
- columns: Column[];
48
- }
49
-
50
99
  type HamelinType = "binary" | "boolean" | "interval" | "int" | "double" | "rows" | "string" | "timestamp" | "unknown" | { decimal: { precision: number; scale: number } } | { array: { element_type: HamelinType } } | { map: { key_type: HamelinType; value_type: HamelinType } } | { tuple: { elements: HamelinType[] } } | "variant" | { range: { of: HamelinType } } | { struct: Column[] };
51
100
 
52
101
  interface Column {
@@ -56,7 +105,62 @@ interface Column {
56
105
 
57
106
  type Catalog = Record<string, Column[]>;
58
107
 
108
+ declare class CatalogProvider {
109
+ private constructor();
110
+ free(): void;
111
+ static try_from_catalog(catalog: Catalog): CatalogProvider;
112
+ }
113
+ declare class Compiler {
114
+ free(): void;
115
+ constructor();
116
+ get_function_descriptions(): FunctionDescription[];
117
+ set_catalog_provider(provider: CatalogProvider): void;
118
+ set_time_range(start?: Date | null, end?: Date | null): void;
119
+ set_time_range_expression(expression: string): ContextualTranslationErrors | undefined;
120
+ compile_statement(query: string): CompileResult;
121
+ compile_statement_at(query: string, at?: number | null): ContextualResult;
122
+ get_statement_datasets(query: string): StatementDatasetsResult;
123
+ }
124
+
125
+ type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
126
+
127
+ interface InitOutput {
128
+ readonly memory: WebAssembly.Memory;
129
+ readonly __wbg_catalogprovider_free: (a: number, b: number) => void;
130
+ readonly catalogprovider_try_from_catalog: (a: any) => [number, number, number];
131
+ readonly __wbg_compiler_free: (a: number, b: number) => void;
132
+ readonly compiler_new: () => number;
133
+ readonly compiler_get_function_descriptions: (a: number) => [number, number];
134
+ readonly compiler_set_catalog_provider: (a: number, b: number) => void;
135
+ readonly compiler_set_time_range: (a: number, b: number, c: number) => void;
136
+ readonly compiler_set_time_range_expression: (a: number, b: number, c: number) => any;
137
+ readonly compiler_compile_statement: (a: number, b: number, c: number) => any;
138
+ readonly compiler_compile_statement_at: (a: number, b: number, c: number, d: number) => any;
139
+ readonly compiler_get_statement_datasets: (a: number, b: number, c: number) => any;
140
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
141
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
142
+ readonly __wbindgen_exn_store: (a: number) => void;
143
+ readonly __externref_table_alloc: () => number;
144
+ readonly __wbindgen_export_4: WebAssembly.Table;
145
+ readonly __externref_table_dealloc: (a: number) => void;
146
+ readonly __externref_drop_slice: (a: number, b: number) => void;
147
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
148
+ readonly __wbindgen_start: () => void;
149
+ }
150
+
151
+ type SyncInitInput = BufferSource | WebAssembly.Module;
152
+ /**
153
+ * Instantiates the given `module`, which can either be bytes or
154
+ * a precompiled `WebAssembly.Module`.
155
+ *
156
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
157
+ *
158
+ * @returns {InitOutput}
159
+ */
160
+ declare function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
161
+
59
162
  declare const compileHamelin: (catalog: Catalog, hamelinInput: string, timeRange?: string) => Promise<CompileResult>;
163
+ declare const createCompiler: (catalog: Catalog) => Promise<Compiler>;
60
164
 
61
165
  declare const getFunctionDescriptions: () => Promise<FunctionDescription[]>;
62
166
 
@@ -190,23 +294,17 @@ declare class HamelinLexer extends antlr.Lexer {
190
294
  */
191
295
  declare class HamelinVisitor<Result> extends AbstractParseTreeVisitor<Result> {
192
296
  /**
193
- * Visit a parse tree produced by `HamelinParser.hamelin`.
297
+ * Visit a parse tree produced by `HamelinParser.queryEOF`.
194
298
  * @param ctx the parse tree
195
299
  * @return the visitor result
196
300
  */
197
- visitHamelin?: (ctx: HamelinContext) => Result;
301
+ visitQueryEOF?: (ctx: QueryEOFContext) => Result;
198
302
  /**
199
303
  * Visit a parse tree produced by `HamelinParser.statementEOF`.
200
304
  * @param ctx the parse tree
201
305
  * @return the visitor result
202
306
  */
203
307
  visitStatementEOF?: (ctx: StatementEOFContext) => Result;
204
- /**
205
- * Visit a parse tree produced by `HamelinParser.queryEOF`.
206
- * @param ctx the parse tree
207
- * @return the visitor result
208
- */
209
- visitQueryEOF?: (ctx: QueryEOFContext) => Result;
210
308
  /**
211
309
  * Visit a parse tree produced by `HamelinParser.commandEOF`.
212
310
  * @param ctx the parse tree
@@ -862,37 +960,36 @@ declare class HamelinParser extends antlr.Parser {
862
960
  static readonly SIMPLE_COMMENT = 93;
863
961
  static readonly BRACKETED_COMMENT = 94;
864
962
  static readonly WS = 95;
865
- static readonly RULE_hamelin = 0;
963
+ static readonly RULE_queryEOF = 0;
866
964
  static readonly RULE_statementEOF = 1;
867
- static readonly RULE_queryEOF = 2;
868
- static readonly RULE_commandEOF = 3;
869
- static readonly RULE_expressionEOF = 4;
870
- static readonly RULE_identifierEOF = 5;
871
- static readonly RULE_simpleIdentifierEOF = 6;
872
- static readonly RULE_statement = 7;
873
- static readonly RULE_query = 8;
874
- static readonly RULE_pipeline = 9;
875
- static readonly RULE_command = 10;
876
- static readonly RULE_assignmentClause = 11;
877
- static readonly RULE_groupClause = 12;
878
- static readonly RULE_assignment = 13;
879
- static readonly RULE_matchDefine = 14;
880
- static readonly RULE_selection = 15;
881
- static readonly RULE_sortExpression = 16;
882
- static readonly RULE_tableAlias = 17;
883
- static readonly RULE_fromClause = 18;
884
- static readonly RULE_expression = 19;
885
- static readonly RULE_hamelintype = 20;
886
- static readonly RULE_pattern = 21;
887
- static readonly RULE_quantifier = 22;
888
- static readonly RULE_columnReference = 23;
889
- static readonly RULE_tableReference = 24;
890
- static readonly RULE_identifier = 25;
891
- static readonly RULE_simpleIdentifier = 26;
892
- static readonly RULE_string = 27;
893
- static readonly RULE_number = 28;
894
- static readonly RULE_positionalArgument = 29;
895
- static readonly RULE_namedArgument = 30;
965
+ static readonly RULE_commandEOF = 2;
966
+ static readonly RULE_expressionEOF = 3;
967
+ static readonly RULE_identifierEOF = 4;
968
+ static readonly RULE_simpleIdentifierEOF = 5;
969
+ static readonly RULE_statement = 6;
970
+ static readonly RULE_query = 7;
971
+ static readonly RULE_pipeline = 8;
972
+ static readonly RULE_command = 9;
973
+ static readonly RULE_assignmentClause = 10;
974
+ static readonly RULE_groupClause = 11;
975
+ static readonly RULE_assignment = 12;
976
+ static readonly RULE_matchDefine = 13;
977
+ static readonly RULE_selection = 14;
978
+ static readonly RULE_sortExpression = 15;
979
+ static readonly RULE_tableAlias = 16;
980
+ static readonly RULE_fromClause = 17;
981
+ static readonly RULE_expression = 18;
982
+ static readonly RULE_hamelintype = 19;
983
+ static readonly RULE_pattern = 20;
984
+ static readonly RULE_quantifier = 21;
985
+ static readonly RULE_columnReference = 22;
986
+ static readonly RULE_tableReference = 23;
987
+ static readonly RULE_identifier = 24;
988
+ static readonly RULE_simpleIdentifier = 25;
989
+ static readonly RULE_string = 26;
990
+ static readonly RULE_number = 27;
991
+ static readonly RULE_positionalArgument = 28;
992
+ static readonly RULE_namedArgument = 29;
896
993
  static readonly literalNames: (string | null)[];
897
994
  static readonly symbolicNames: (string | null)[];
898
995
  static readonly ruleNames: string[];
@@ -903,9 +1000,8 @@ declare class HamelinParser extends antlr.Parser {
903
1000
  get serializedATN(): number[];
904
1001
  protected createFailedPredicateException(predicate?: string, message?: string): antlr.FailedPredicateException;
905
1002
  constructor(input: antlr.TokenStream);
906
- hamelin(): HamelinContext;
907
- statementEOF(): StatementEOFContext;
908
1003
  queryEOF(): QueryEOFContext;
1004
+ statementEOF(): StatementEOFContext;
909
1005
  commandEOF(): CommandEOFContext;
910
1006
  expressionEOF(): ExpressionEOFContext;
911
1007
  identifierEOF(): IdentifierEOFContext;
@@ -944,11 +1040,10 @@ declare class HamelinParser extends antlr.Parser {
944
1040
  get vocabulary(): antlr.Vocabulary;
945
1041
  private static readonly decisionsToDFA;
946
1042
  }
947
- declare class HamelinContext extends antlr.ParserRuleContext {
1043
+ declare class QueryEOFContext extends antlr.ParserRuleContext {
948
1044
  constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
1045
+ query(): QueryContext;
949
1046
  EOF(): antlr.TerminalNode;
950
- statement(): StatementContext[];
951
- statement(i: number): StatementContext | null;
952
1047
  get ruleIndex(): number;
953
1048
  enterRule(listener: HamelinListener): void;
954
1049
  exitRule(listener: HamelinListener): void;
@@ -963,15 +1058,6 @@ declare class StatementEOFContext extends antlr.ParserRuleContext {
963
1058
  exitRule(listener: HamelinListener): void;
964
1059
  accept<Result>(visitor: HamelinVisitor<Result>): Result | null;
965
1060
  }
966
- declare class QueryEOFContext extends antlr.ParserRuleContext {
967
- constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
968
- query(): QueryContext;
969
- EOF(): antlr.TerminalNode;
970
- get ruleIndex(): number;
971
- enterRule(listener: HamelinListener): void;
972
- exitRule(listener: HamelinListener): void;
973
- accept<Result>(visitor: HamelinVisitor<Result>): Result | null;
974
- }
975
1061
  declare class CommandEOFContext extends antlr.ParserRuleContext {
976
1062
  constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
977
1063
  command(): CommandContext;
@@ -1892,15 +1978,15 @@ declare class NamedArgumentContext extends antlr.ParserRuleContext {
1892
1978
  */
1893
1979
  declare class HamelinListener implements ParseTreeListener {
1894
1980
  /**
1895
- * Enter a parse tree produced by `HamelinParser.hamelin`.
1981
+ * Enter a parse tree produced by `HamelinParser.queryEOF`.
1896
1982
  * @param ctx the parse tree
1897
1983
  */
1898
- enterHamelin?: (ctx: HamelinContext) => void;
1984
+ enterQueryEOF?: (ctx: QueryEOFContext) => void;
1899
1985
  /**
1900
- * Exit a parse tree produced by `HamelinParser.hamelin`.
1986
+ * Exit a parse tree produced by `HamelinParser.queryEOF`.
1901
1987
  * @param ctx the parse tree
1902
1988
  */
1903
- exitHamelin?: (ctx: HamelinContext) => void;
1989
+ exitQueryEOF?: (ctx: QueryEOFContext) => void;
1904
1990
  /**
1905
1991
  * Enter a parse tree produced by `HamelinParser.statementEOF`.
1906
1992
  * @param ctx the parse tree
@@ -1911,16 +1997,6 @@ declare class HamelinListener implements ParseTreeListener {
1911
1997
  * @param ctx the parse tree
1912
1998
  */
1913
1999
  exitStatementEOF?: (ctx: StatementEOFContext) => void;
1914
- /**
1915
- * Enter a parse tree produced by `HamelinParser.queryEOF`.
1916
- * @param ctx the parse tree
1917
- */
1918
- enterQueryEOF?: (ctx: QueryEOFContext) => void;
1919
- /**
1920
- * Exit a parse tree produced by `HamelinParser.queryEOF`.
1921
- * @param ctx the parse tree
1922
- */
1923
- exitQueryEOF?: (ctx: QueryEOFContext) => void;
1924
2000
  /**
1925
2001
  * Enter a parse tree produced by `HamelinParser.commandEOF`.
1926
2002
  * @param ctx the parse tree
@@ -2891,4 +2967,4 @@ type QuerySort = {
2891
2967
  */
2892
2968
  declare const getSorts: (hamelinQuery: string) => QuerySort[];
2893
2969
 
2894
- export { AggCommandContext, AnyNumberContext, AppendCommandContext, ArrayLiteralContext, AssignmentClauseContext, AssignmentContext, AtLeastOneContext, BackQuotedIdentifierContext, BasicDoubleQuotedStringLiteralContext, BasicSingleQuotedStringLiteralContext, BinaryLiteralContext, BinaryOperatorContext, BooleanLiteralContext, CastContext, type Catalog, ColumnReferenceAltContext, ColumnReferenceContext, CommandContext, CommandEOFContext, DecimalLiteralContext, DerefContext, DropCommandContext, ExactlyContext, ExplodeCommandContext, ExpressionContext, ExpressionEOFContext, ExpressionStatementContext, FromClauseContext, FromCommandContext, FunctionCallContext, type FunctionDescription, GroupClauseContext, HamelinContext, HamelinLexer, HamelinListener, HamelinParser, HamelinVisitor, HamelintypeContext, IdentifierContext, IdentifierEOFContext, IndexAccessContext, IntegerLiteralContext, IntervalLiteralContext, JoinCommandContext, LetCommandContext, LimitCommandContext, MatchCommandContext, MatchDefineContext, NamedArgumentContext, NestedContext, NullLiteralContext, NumberContext, NumericLiteralContext, PairLiteralContext, ParameterizedTypeContext, ParenthesizedExpressionContext, ParseCommandContext, PatternContext, PipelineAltContext, PipelineContext, PositionalArgumentContext, QuantifiedContext, QuantifierContext, QueryContext, QueryEOFContext, type QuerySort, QueryStatementContext, RowsLiteralContext, ScientificLiteralContext, SelectCommandContext, SelectionContext, SimpleIdentifierContext, SimpleIdentifierEOFContext, SimpleTypeContext, SortCommandContext, SortExpressionContext, StandaloneQueryContext, StatementContext, StatementEOFContext, StringContext, StringLiteralContext, StructLiteralContext, StructTypeContext, TableAliasContext, TableReferenceContext, TsTruncContext, TsTruncTimestampLiteralContext, TupleLiteralContext, TupleTypeContext, TypeWithArgumentsContext, UnaryPostfixOperatorContext, UnaryPrefixOperatorContext, UnboundRangeLiteralContext, UnicodeDoubleQuotedStringLiteralContext, UnicodeSingleQuotedStringLiteralContext, UnionCommandContext, UnnestCommandContext, UnquotedIdentifierContext, WhereCommandContext, WindowCommandContext, WithQueryContext, WithinCommandContext, ZeroOrOneContext, compileHamelin, getDatasetsFromQuery, getFunctionDescriptions, getLimits, getSorts, sampleCatalog };
2970
+ export { AggCommandContext, AnyNumberContext, AppendCommandContext, ArrayLiteralContext, AssignmentClauseContext, AssignmentContext, AtLeastOneContext, BackQuotedIdentifierContext, BasicDoubleQuotedStringLiteralContext, BasicSingleQuotedStringLiteralContext, BinaryLiteralContext, BinaryOperatorContext, BooleanLiteralContext, CastContext, type Catalog, CatalogProvider, type Column, ColumnReferenceAltContext, ColumnReferenceContext, CommandContext, CommandEOFContext, type CompileResult, Compiler, type Completion, type CompletionItem, type CompletionItemKind, type Context, type ContextualCompletion, type ContextualResult, type ContextualTranslationError, type ContextualTranslationErrors, DecimalLiteralContext, DerefContext, DropCommandContext, ExactlyContext, ExplodeCommandContext, ExpressionContext, ExpressionEOFContext, ExpressionStatementContext, FromClauseContext, FromCommandContext, FunctionCallContext, type FunctionDescription, GroupClauseContext, HamelinLexer, HamelinListener, HamelinParser, type HamelinType, HamelinVisitor, HamelintypeContext, IdentifierContext, IdentifierEOFContext, IndexAccessContext, type InitInput, type InitOutput, IntegerLiteralContext, IntervalLiteralContext, JoinCommandContext, type LanguageArea, LetCommandContext, type Level, LimitCommandContext, MatchCommandContext, MatchDefineContext, NamedArgumentContext, NestedContext, NullLiteralContext, NumberContext, NumericLiteralContext, PairLiteralContext, ParameterizedTypeContext, ParenthesizedExpressionContext, ParseCommandContext, PatternContext, PipelineAltContext, PipelineContext, PositionalArgumentContext, QuantifiedContext, QuantifierContext, QueryContext, QueryEOFContext, type QuerySort, QueryStatementContext, RowsLiteralContext, ScientificLiteralContext, SelectCommandContext, SelectionContext, SimpleIdentifierContext, SimpleIdentifierEOFContext, SimpleTypeContext, SortCommandContext, SortExpressionContext, type Stage, StandaloneQueryContext, StatementContext, type StatementDatasetsResult, StatementEOFContext, StringContext, StringLiteralContext, StructLiteralContext, StructTypeContext, type SyncInitInput, TableAliasContext, TableReferenceContext, type Translation, type TranslationError, type TranslationErrors, TsTruncContext, TsTruncTimestampLiteralContext, TupleLiteralContext, TupleTypeContext, TypeWithArgumentsContext, UnaryPostfixOperatorContext, UnaryPrefixOperatorContext, UnboundRangeLiteralContext, UnicodeDoubleQuotedStringLiteralContext, UnicodeSingleQuotedStringLiteralContext, UnionCommandContext, UnnestCommandContext, UnquotedIdentifierContext, WhereCommandContext, WindowCommandContext, WithQueryContext, WithinCommandContext, ZeroOrOneContext, compileHamelin, createCompiler, getDatasetsFromQuery, getFunctionDescriptions, getLimits, getSorts, initSync, sampleCatalog };