@narrative.io/data-collaboration-sdk-ts 2.3.0 → 2.5.0

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.
@@ -18,7 +18,7 @@ export interface Select {
18
18
  where: BooleanExpression | Raw | null;
19
19
  }
20
20
  export type Output = ColumnRef | Lit | Raw;
21
- export type Expression = ArithmeticExpression | BooleanExpression | ColumnRef | Lit | FunctionCall | StringExpression | UnaryMinus | Raw;
21
+ export type Expression = BooleanExpression | ColumnRef | Lit | Raw;
22
22
  export interface Raw {
23
23
  type: "nql";
24
24
  as?: string;
@@ -29,10 +29,7 @@ export interface Deduplication {
29
29
  expressions: Expression[];
30
30
  }
31
31
  export type ColumnRef = AttributeRef | DatasetColumnRef | RawRef;
32
- export type ArithmeticExpression = BinaryArithmeticExpression | UnaryMinus;
33
- export type BinaryArithmeticExpression = Add | Divide | Multiply | Subtract;
34
32
  export type BooleanExpression = And | Between | Equals | NotEquals | Gt | Gte | In | IsNull | Like | Lt | Lte | Not | Or;
35
- export type StringExpression = Concat;
36
33
  export type Table = RosettaTable | DatasetTable | RawTable;
37
34
  export interface RosettaTable {
38
35
  type: "rosetta_stone";
@@ -80,37 +77,6 @@ export interface Lit {
80
77
  value_type: ast.NqlSimpleType;
81
78
  value: string | null;
82
79
  }
83
- export interface FunctionCall {
84
- type: "function";
85
- as?: string;
86
- args: Expression[];
87
- name: string;
88
- }
89
- export interface Add {
90
- type: "+";
91
- as?: string;
92
- operands: Expression[];
93
- }
94
- export interface Divide {
95
- type: "/";
96
- as?: string;
97
- operands: Expression[];
98
- }
99
- export interface Multiply {
100
- type: "*";
101
- as?: string;
102
- operands: Expression[];
103
- }
104
- export interface Subtract {
105
- type: "-";
106
- as?: string;
107
- operands: Expression[];
108
- }
109
- export interface UnaryMinus {
110
- type: "unary_-";
111
- as?: string;
112
- operand: Expression;
113
- }
114
80
  export interface And {
115
81
  type: "and";
116
82
  as?: string;
@@ -190,12 +156,7 @@ export interface Like {
190
156
  value: Expression;
191
157
  pattern: string;
192
158
  }
193
- export interface Concat {
194
- type: "||";
195
- as?: string;
196
- operands: Expression[];
197
- }
198
- export type Node = Select | Expression | Deduplication | Table | BooleanExpression | ArithmeticExpression | StringExpression | Join | AttributeRef | DatasetColumnRef | RawRef | Lit | FunctionCall | Add | Divide | Multiply | Subtract | UnaryMinus | And | Or | Not | Between | Equals | NotEquals | Lt | Lte | Gt | Gte | In | IsNull | Like | Concat | Raw;
159
+ export type Node = Select | Expression | Deduplication | Table | BooleanExpression | Join | AttributeRef | DatasetColumnRef | RawRef | Lit | And | Or | Not | Between | Equals | NotEquals | Lt | Lte | Gt | Gte | In | IsNull | Like | Raw | ast.NqlBinaryOp;
199
160
  export declare function parseStatement(n: ast.NqlAst): Statement | Raw;
200
161
  export declare function parseCreateMaterializedView(n: ast.NqlCreateMaterializedView): CreateMaterializedView;
201
162
  export declare function parseExplain(n: ast.NqlExplain): Explain | Raw;
@@ -100,7 +100,7 @@ export function parseDeduplication(n) {
100
100
  return n.qualify !== null ? nqlOrFail(n.qualify) : null;
101
101
  }
102
102
  export function parseExpression(n) {
103
- const parse = oneOf(parseArithmetic, parseBooleanExpression, parseColumnRef, parseFunctionCall, parseLit, parseStringExpression);
103
+ const parse = oneOf(parseBooleanExpression, parseColumnRef, parseLit, parseStringExpression);
104
104
  return parse(n);
105
105
  }
106
106
  export function parseOutput(n) {
@@ -160,99 +160,12 @@ function parseBooleanExpression(n) {
160
160
  function parseStringExpression(n) {
161
161
  switch (n.type) {
162
162
  case "binary_op": {
163
- switch (n.name) {
164
- case "||":
165
- return parseConcat(n);
166
- default:
167
- return nqlOrFail(n);
168
- }
169
- }
170
- default:
171
163
  return nqlOrFail(n);
172
- }
173
- }
174
- function parseConcat(n) {
175
- const operands = parseOperands(n, "||");
176
- const concat = {
177
- type: "||",
178
- as: n.as,
179
- operands,
180
- };
181
- return concat;
182
- }
183
- function parseArithmetic(n) {
184
- switch (n.type) {
185
- case "binary_op": {
186
- switch (n.name) {
187
- case "+":
188
- return parseAdd(n);
189
- case "/":
190
- return parseDivide(n);
191
- case "*":
192
- return parseMultiply(n);
193
- case "-":
194
- return parseSubtract(n);
195
- default:
196
- return nqlOrFail(n);
197
- }
198
- }
199
- case "operator": {
200
- switch (n.name) {
201
- case "-":
202
- return parseUnaryMinus(n);
203
- default:
204
- return nqlOrFail(n);
205
- }
206
164
  }
207
165
  default:
208
166
  return nqlOrFail(n);
209
167
  }
210
168
  }
211
- function parseAdd(n) {
212
- const operands = parseOperands(n, "+");
213
- const add = {
214
- type: "+",
215
- as: n.as,
216
- operands,
217
- };
218
- return add;
219
- }
220
- function parseDivide(n) {
221
- const operands = parseOperands(n, "/");
222
- const divide = {
223
- type: "/",
224
- as: n.as,
225
- operands,
226
- };
227
- return divide;
228
- }
229
- function parseMultiply(n) {
230
- const operands = parseOperands(n, "*");
231
- const mult = {
232
- type: "*",
233
- as: n.as,
234
- operands,
235
- };
236
- return mult;
237
- }
238
- function parseSubtract(n) {
239
- const operands = parseOperands(n, "-");
240
- const sub = {
241
- type: "-",
242
- as: n.as,
243
- operands,
244
- };
245
- return sub;
246
- }
247
- function parseUnaryMinus(n) {
248
- const operand = parseExpression(n.args[0]);
249
- const minus = {
250
- type: "unary_-",
251
- as: n.as,
252
- operand,
253
- };
254
- return minus;
255
- }
256
169
  function parseBetween(n) {
257
170
  const operand = parseExpression(n.args[0]);
258
171
  const lower = parseExpression(n.args[1]);
@@ -301,22 +214,6 @@ function parseColumnRef(n) {
301
214
  return nqlOrFail(n);
302
215
  }
303
216
  }
304
- function parseFunctionCall(n) {
305
- switch (n.type) {
306
- case "function": {
307
- const args = n.args.map((arg) => parseExpression(arg));
308
- const fn = {
309
- type: "function",
310
- as: n.as,
311
- args,
312
- name: n.name,
313
- };
314
- return fn;
315
- }
316
- default:
317
- return nqlOrFail(n);
318
- }
319
- }
320
217
  function parseLit(n) {
321
218
  switch (n.type) {
322
219
  case "literal": {
@@ -1,17 +1,8 @@
1
1
  function findTraversalTargets(node) {
2
2
  switch (node.type) {
3
- case "function":
4
- return node.args;
5
- case "+":
6
- case "/":
7
- case "*":
8
- case "-":
9
3
  case "and":
10
4
  case "or":
11
- case "||":
12
5
  return node.operands;
13
- case "unary_-":
14
- return [node.operand];
15
6
  case "is_null":
16
7
  return [node.operand];
17
8
  case "like":
@@ -166,16 +166,6 @@ export function compileExpression(n) {
166
166
  return compileBinaryOperator(">", [n.left, n.right], n.as);
167
167
  case ">=":
168
168
  return compileBinaryOperator(">=", [n.left, n.right], n.as);
169
- case "+":
170
- return compileBinaryOperator("+", n.operands, n.as);
171
- case "/":
172
- return compileBinaryOperator("/", n.operands, n.as);
173
- case "*":
174
- return compileBinaryOperator("*", n.operands, n.as);
175
- case "-":
176
- return compileBinaryOperator("-", n.operands, n.as);
177
- case "||":
178
- return compileBinaryOperator("||", n.operands, n.as);
179
169
  case "and":
180
170
  return compileBinaryOperator("AND", n.operands, n.as);
181
171
  case "attribute_ref":
@@ -184,8 +174,6 @@ export function compileExpression(n) {
184
174
  return compileBetween(n.operand, n.lower, n.upper, n.as);
185
175
  case "dataset_column_ref":
186
176
  return compileDatasetColumnRef(n.datasetId, n.column, n.as);
187
- case "function":
188
- return compileFunctionCall(n.name, n.args, n.as);
189
177
  case "in":
190
178
  return compileIn(n.expression, n.values, n.negated, n.as);
191
179
  case "is_null":
@@ -202,8 +190,6 @@ export function compileExpression(n) {
202
190
  return raw(n);
203
191
  case "raw_ref":
204
192
  return compileRawRef(n.nql, n.as);
205
- case "unary_-":
206
- return compileUnaryMinus(n.operand, n.as);
207
193
  }
208
194
  return unreachable(n);
209
195
  }
@@ -237,35 +223,6 @@ function compileDatasetColumnRef(datasetId, column, as, aliasParen) {
237
223
  }, "");
238
224
  return aliased(`company_data.${quote(datasetId.toString())}.${formattedColumn}`, as, false);
239
225
  }
240
- function compileFunctionCall(name, args, as) {
241
- // Calling convenions for functions are all over the place:
242
- // - CAST is invoked as CAST($value AS $type)
243
- // - EXTRACT is invoked as EXTRACT($part FROM $value)
244
- // - etc., etc., with many exceptions
245
- // We'll likely wanto types for all the functions we know how to support, or have every function
246
- // described by the API, including providing a template for its calling convention. For now the
247
- // below will get us a to a v1.
248
- // Useful reference: https://calcite.apache.org/docs/reference.html#arithmetic-operators-and-functions
249
- const argsNql = args.map((e) => compileExpression(e));
250
- let callNql;
251
- switch (name) {
252
- case "CAST":
253
- callNql = `CAST(${argsNql[0]} AS ${argsNql[1]})`;
254
- break;
255
- case "EXTRACT":
256
- callNql = `EXTRACT(${argsNql[0]} FROM ${argsNql[1]})`;
257
- break;
258
- case "TRIM":
259
- callNql = `TRIM(${argsNql[0]} ${argsNql[1]} FROM ${argsNql[2]})`;
260
- break;
261
- default: {
262
- // hope for the best. definitely does not work in all cases.
263
- callNql =
264
- argsNql.length > 0 ? `${name}(${argsNql.join(", ")})` : `${name}`;
265
- }
266
- }
267
- return aliased(callNql, as);
268
- }
269
226
  function compileIn(expression, values, negated, as) {
270
227
  const op = !negated ? "IN" : "NOT IN";
271
228
  const compiledValues = isArray(values)
@@ -342,7 +299,7 @@ function quote(s) {
342
299
  return `${quoteChar}${s.replace(quoteChar, `\\${quoteChar}`)}${quoteChar}`;
343
300
  }
344
301
  function raw(n) {
345
- return aliased(n.nql, n.as);
302
+ return aliased(n.nql, n.as, true);
346
303
  }
347
304
  function isArray(ns) {
348
305
  return Array.isArray(ns);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narrative.io/data-collaboration-sdk-ts",
3
- "version": "2.3.0",
3
+ "version": "2.5.0",
4
4
  "main": "build/index.js",
5
5
  "repository": "github:narrative-io/data-collaboration-sdk-ts",
6
6
  "source": "src/index.ts",
@@ -29,7 +29,7 @@
29
29
  "@types/jest": "29.5.12",
30
30
  "babel-jest": "29.7.0",
31
31
  "jest": "29.7.0",
32
- "lefthook": "1.6.11",
32
+ "lefthook": "1.6.12",
33
33
  "ts-jest": "29.1.2"
34
34
  },
35
35
  "dependencies": {