@narrative.io/data-collaboration-sdk-ts 0.0.106 → 0.0.108
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/build/access-rules/index.d.ts +44 -0
- package/build/access-rules/index.js +51 -0
- package/build/access-rules/types.d.ts +29 -0
- package/build/access-rules/types.js +1 -0
- package/build/apps/index.d.ts +5 -4
- package/build/apps/index.js +8 -3
- package/build/apps/types.d.ts +12 -0
- package/build/apps/types.js +0 -1
- package/build/attributes/index.d.ts +9 -9
- package/build/attributes/index.js +8 -8
- package/build/attributes/types.d.ts +5 -5
- package/build/authentication/index.d.ts +3 -3
- package/build/authentication/index.js +3 -3
- package/build/authentication/types.d.ts +3 -3
- package/build/base-api.d.ts +42 -42
- package/build/base-api.js +51 -51
- package/build/company-info/index.d.ts +3 -3
- package/build/company-info/index.js +2 -2
- package/build/contracts/index.d.ts +18 -18
- package/build/contracts/index.js +18 -18
- package/build/contracts/types.d.ts +3 -3
- package/build/data-streams/index.d.ts +10 -10
- package/build/data-streams/index.js +9 -9
- package/build/data-streams/types.d.ts +7 -7
- package/build/datasets/index.d.ts +30 -30
- package/build/datasets/index.js +32 -32
- package/build/datasets/types.d.ts +9 -9
- package/build/forecast/index.d.ts +3 -3
- package/build/forecast/index.js +3 -3
- package/build/forecast/types.d.ts +7 -7
- package/build/health/index.d.ts +2 -2
- package/build/health/index.js +2 -2
- package/build/health/types.d.ts +1 -1
- package/build/index.d.ts +32 -31
- package/build/index.js +44 -24
- package/build/installations/index.d.ts +3 -3
- package/build/installations/index.js +3 -3
- package/build/installations/types.d.ts +1 -1
- package/build/mappings/index.d.ts +16 -16
- package/build/mappings/index.js +18 -18
- package/build/mappings/types.d.ts +6 -6
- package/build/nql/DataRulesConverter.d.ts +3 -3
- package/build/nql/DataRulesConverter.js +55 -31
- package/build/nql/NQLParser.d.ts +4 -4
- package/build/nql/NQLParser.js +74 -57
- package/build/nql/SubstraitParser.d.ts +173 -173
- package/build/nql/SubstraitParser.js +270 -261
- package/build/nql/index.d.ts +4 -4
- package/build/nql/index.js +3 -3
- package/build/nql/types.d.ts +6 -6
- package/build/nql/types.js +59 -29
- package/build/ping/index.d.ts +2 -2
- package/build/ping/index.js +2 -2
- package/build/ping/types.d.ts +1 -1
- package/build/products/index.d.ts +6 -6
- package/build/products/index.js +6 -6
- package/build/products/types.d.ts +4 -4
- package/build/resources/index.d.ts +4 -4
- package/build/resources/index.js +2 -2
- package/build/resources/types.d.ts +3 -3
- package/build/rosetta/types.d.ts +12 -12
- package/build/rosetta/types.js +69 -42
- package/build/rosetta-stone/index.d.ts +3 -3
- package/build/rosetta-stone/index.js +3 -3
- package/build/types.d.ts +2 -2
- package/build/uploads/index.d.ts +8 -8
- package/build/uploads/index.js +8 -8
- package/build/utils.js +1 -1
- package/package.json +3 -1
package/build/nql/NQLParser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NqlBooleanExpressionObj, NqlBudgetObj, NqlFieldObj, NqlFilterExpressionObj, NqlObj, NqlPreSelectExpressionObj, NqlTableObject, NqlWhereObj, NqlFilterUnaryExpressionObj } from
|
|
1
|
+
import { NqlBooleanExpressionObj, NqlBudgetObj, NqlFieldObj, NqlFilterExpressionObj, NqlObj, NqlPreSelectExpressionObj, NqlTableObject, NqlWhereObj, NqlFilterUnaryExpressionObj, } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Retrieves the WHERE clause from the given NQL (Nested Query Language) string and returns a parsed NqlWhereClause object.
|
|
4
4
|
*
|
|
@@ -8,17 +8,17 @@ import { NqlBooleanExpressionObj, NqlBudgetObj, NqlFieldObj, NqlFilterExpression
|
|
|
8
8
|
*/
|
|
9
9
|
export function getWhere(nql) {
|
|
10
10
|
const regex = /\bWHERE\b(.*?)\bLIMIT\b/i;
|
|
11
|
-
const match = nql.trim().replace(/\n/g,
|
|
12
|
-
if (match != null && match[1] !==
|
|
11
|
+
const match = nql.trim().replace(/\n/g, " ").match(regex);
|
|
12
|
+
if (match != null && match[1] !== "") {
|
|
13
13
|
const booleanExpressions = getBooleanExpressionsFromWhere(match[1]);
|
|
14
14
|
const filterExpressions = getFilterExpressionsFromWhere(match[1]);
|
|
15
15
|
return NqlWhereObj.parse({
|
|
16
16
|
booleanExpressions,
|
|
17
|
-
filterExpressions
|
|
17
|
+
filterExpressions,
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
|
-
throw new Error(
|
|
21
|
+
throw new Error("No WHERE clause found");
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
@@ -30,19 +30,19 @@ export function getWhere(nql) {
|
|
|
30
30
|
*/
|
|
31
31
|
export function getFrom(nql) {
|
|
32
32
|
const regex = /\bFROM\b(.*?)\bWHERE\b/i;
|
|
33
|
-
const match = nql.trim().replace(/\n/g,
|
|
34
|
-
if (match != null && match[1] !==
|
|
35
|
-
const tables = match[1].split(
|
|
36
|
-
const [database, table] = t.trim().split(
|
|
33
|
+
const match = nql.trim().replace(/\n/g, " ").match(regex);
|
|
34
|
+
if (match != null && match[1] !== "") {
|
|
35
|
+
const tables = match[1].split(",").map((t) => {
|
|
36
|
+
const [database, table] = t.trim().split(".");
|
|
37
37
|
return NqlTableObject.parse({
|
|
38
38
|
database,
|
|
39
|
-
table
|
|
39
|
+
table,
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
42
|
return tables;
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
|
-
throw new Error(
|
|
45
|
+
throw new Error("No FROM clause found");
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
@@ -52,7 +52,7 @@ export function getFrom(nql) {
|
|
|
52
52
|
* @returns {NqlBooleanExpression[]} - An array of parsed NqlBooleanExpression objects representing the boolean expressions.
|
|
53
53
|
*/
|
|
54
54
|
function getBooleanExpressionsFromWhere(where) {
|
|
55
|
-
const booleanRegex = /\s(OR|AND)\s/
|
|
55
|
+
const booleanRegex = /\s(OR|AND)\s/gi;
|
|
56
56
|
const matches = [];
|
|
57
57
|
let boolMatch;
|
|
58
58
|
while ((boolMatch = booleanRegex.exec(where)) !== null) {
|
|
@@ -68,12 +68,12 @@ function getBooleanExpressionsFromWhere(where) {
|
|
|
68
68
|
*/
|
|
69
69
|
function getFilterExpressionsFromWhere(where) {
|
|
70
70
|
let matches = [];
|
|
71
|
-
const hasBoolean = /\s(?:OR|AND)\s/
|
|
71
|
+
const hasBoolean = /\s(?:OR|AND)\s/gi.test(where);
|
|
72
72
|
if (!hasBoolean) {
|
|
73
73
|
matches.push(getFilterExpressionFromString(where));
|
|
74
74
|
}
|
|
75
75
|
else {
|
|
76
|
-
const expressions = where.split(/\s(?:OR|AND)\s/
|
|
76
|
+
const expressions = where.split(/\s(?:OR|AND)\s/gi).map((t) => t.trim());
|
|
77
77
|
matches = matches.concat(expressions.map((e) => getFilterExpressionFromString(e)));
|
|
78
78
|
}
|
|
79
79
|
return NqlFilterExpressionObj.array().parse(matches);
|
|
@@ -85,15 +85,17 @@ function getFilterExpressionsFromWhere(where) {
|
|
|
85
85
|
* @returns {NqlField | string} - The parsed NqlField object or the original field string if parsing fails.
|
|
86
86
|
*/
|
|
87
87
|
function parseFieldFromString(fieldStr) {
|
|
88
|
-
const [database, table, ...f] = fieldStr.trim().split(
|
|
88
|
+
const [database, table, ...f] = fieldStr.trim().split(".");
|
|
89
89
|
const field = {
|
|
90
90
|
table: {
|
|
91
91
|
database,
|
|
92
|
-
table
|
|
92
|
+
table,
|
|
93
93
|
},
|
|
94
|
-
field: f
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
field: f
|
|
95
|
+
.map((field) => {
|
|
96
|
+
return field.replace('"value"', "value").replace('"type"', "type");
|
|
97
|
+
})
|
|
98
|
+
.join("."),
|
|
97
99
|
};
|
|
98
100
|
try {
|
|
99
101
|
return NqlFieldObj.parse(field);
|
|
@@ -114,10 +116,10 @@ function parseString(value) {
|
|
|
114
116
|
return parsedNumber;
|
|
115
117
|
}
|
|
116
118
|
// Attempt to parse as a boolean
|
|
117
|
-
if (value.toLowerCase() ===
|
|
119
|
+
if (value.toLowerCase() === "true") {
|
|
118
120
|
return true;
|
|
119
121
|
}
|
|
120
|
-
if (value.toLowerCase() ===
|
|
122
|
+
if (value.toLowerCase() === "false") {
|
|
121
123
|
return false;
|
|
122
124
|
}
|
|
123
125
|
// Return as string if it is neither a number nor boolean
|
|
@@ -130,7 +132,7 @@ function parseString(value) {
|
|
|
130
132
|
* @returns {NqlField | string} - The parsed NqlField object or the original field string if parsing fails.
|
|
131
133
|
*/
|
|
132
134
|
export function getFilterExpressionFromString(str) {
|
|
133
|
-
const comparison = [
|
|
135
|
+
const comparison = ["<=", ">=", "!=", "=", ">", "<"];
|
|
134
136
|
const containsComparison = comparison.find((character) => str.includes(character));
|
|
135
137
|
if (containsComparison !== undefined) {
|
|
136
138
|
const result = str.split(containsComparison);
|
|
@@ -140,10 +142,16 @@ export function getFilterExpressionFromString(str) {
|
|
|
140
142
|
return NqlFilterExpressionObj.parse({
|
|
141
143
|
left,
|
|
142
144
|
operator,
|
|
143
|
-
right
|
|
145
|
+
right,
|
|
144
146
|
});
|
|
145
147
|
}
|
|
146
|
-
const strComparison = [
|
|
148
|
+
const strComparison = [
|
|
149
|
+
" NOT IN ",
|
|
150
|
+
" IN ",
|
|
151
|
+
" NOT LIKE ",
|
|
152
|
+
" LIKE ",
|
|
153
|
+
" BETWEEN ",
|
|
154
|
+
];
|
|
147
155
|
const containsStrComparison = strComparison.find((character) => str.toLowerCase().includes(character.toLowerCase()));
|
|
148
156
|
if (containsStrComparison !== undefined) {
|
|
149
157
|
const result = str.toLowerCase().split(containsStrComparison.toLowerCase());
|
|
@@ -153,10 +161,10 @@ export function getFilterExpressionFromString(str) {
|
|
|
153
161
|
return NqlFilterExpressionObj.parse({
|
|
154
162
|
left,
|
|
155
163
|
operator,
|
|
156
|
-
right
|
|
164
|
+
right,
|
|
157
165
|
});
|
|
158
166
|
}
|
|
159
|
-
const unaryOperators = [
|
|
167
|
+
const unaryOperators = [" IS NULL", " IS NOT NULL"];
|
|
160
168
|
const containsUnaryOperator = unaryOperators.find((character) => str.toLowerCase().includes(character.toLowerCase()));
|
|
161
169
|
if (containsUnaryOperator !== undefined) {
|
|
162
170
|
const result = str.toLowerCase().split(containsUnaryOperator.toLowerCase());
|
|
@@ -164,7 +172,7 @@ export function getFilterExpressionFromString(str) {
|
|
|
164
172
|
const operator = containsUnaryOperator.trim().toUpperCase();
|
|
165
173
|
return NqlFilterUnaryExpressionObj.parse({
|
|
166
174
|
field,
|
|
167
|
-
operator
|
|
175
|
+
operator,
|
|
168
176
|
});
|
|
169
177
|
}
|
|
170
178
|
throw new Error(`Invalid filter expression: ${str}`);
|
|
@@ -184,8 +192,10 @@ export function getPreSelect(nql) {
|
|
|
184
192
|
* The match is case-insensitive.
|
|
185
193
|
*/
|
|
186
194
|
const regex = /^(.*?)(?=SELECT)/i;
|
|
187
|
-
const match = nql.trim().replace(/\n/g,
|
|
188
|
-
return match != null && match[1] !==
|
|
195
|
+
const match = nql.trim().replace(/\n/g, " ").match(regex);
|
|
196
|
+
return match != null && match[1] !== ""
|
|
197
|
+
? NqlPreSelectExpressionObj.parse(match[1].toUpperCase().trim())
|
|
198
|
+
: undefined;
|
|
189
199
|
}
|
|
190
200
|
/**
|
|
191
201
|
* Builds a pre-select expression for an NQL (Natural Query Language) query based on the provided pre-select expression.
|
|
@@ -196,7 +206,7 @@ export function getPreSelect(nql) {
|
|
|
196
206
|
*/
|
|
197
207
|
export function buildPreSelect(preSelect) {
|
|
198
208
|
NqlPreSelectExpressionObj.parse(preSelect);
|
|
199
|
-
return preSelect ??
|
|
209
|
+
return preSelect ?? "";
|
|
200
210
|
}
|
|
201
211
|
/**
|
|
202
212
|
* Extracts and parses the selected fields from the given NQL (Natural Query Language) string.
|
|
@@ -208,21 +218,21 @@ export function buildPreSelect(preSelect) {
|
|
|
208
218
|
*/
|
|
209
219
|
export function getSelect(nql) {
|
|
210
220
|
const regex = /SELECT\b(.*?)\bFROM/i;
|
|
211
|
-
const match = nql.trim().replace(/\n/g,
|
|
212
|
-
if (match != null && match[1] !==
|
|
213
|
-
const fields = match[1].trim().split(
|
|
221
|
+
const match = nql.trim().replace(/\n/g, " ").match(regex);
|
|
222
|
+
if (match != null && match[1] !== "") {
|
|
223
|
+
const fields = match[1].trim().split(",");
|
|
214
224
|
return fields.map((f) => {
|
|
215
|
-
const trimmedFields = f.trim().split(
|
|
225
|
+
const trimmedFields = f.trim().split(".");
|
|
216
226
|
if (trimmedFields.length < 3) {
|
|
217
|
-
throw new Error(
|
|
227
|
+
throw new Error("Invalid field");
|
|
218
228
|
}
|
|
219
229
|
const [database, table, ...field] = trimmedFields;
|
|
220
230
|
const t = NqlTableObject.parse({ database, table });
|
|
221
|
-
return NqlFieldObj.parse({ table: t, field: field.join(
|
|
231
|
+
return NqlFieldObj.parse({ table: t, field: field.join(".") });
|
|
222
232
|
});
|
|
223
233
|
}
|
|
224
234
|
else {
|
|
225
|
-
throw new Error(
|
|
235
|
+
throw new Error("No selected fields found");
|
|
226
236
|
}
|
|
227
237
|
}
|
|
228
238
|
/**
|
|
@@ -234,7 +244,10 @@ export function getSelect(nql) {
|
|
|
234
244
|
*/
|
|
235
245
|
export function buildSelect(fields) {
|
|
236
246
|
fields.forEach((f) => NqlFieldObj.parse(f));
|
|
237
|
-
return
|
|
247
|
+
return ("SELECT " +
|
|
248
|
+
fields
|
|
249
|
+
.map((f) => `${f.table.database}.${f.table.table}.${f.field}`)
|
|
250
|
+
.join(", "));
|
|
238
251
|
}
|
|
239
252
|
/**
|
|
240
253
|
* Parses a string in NQL format and returns an NqlBudgetType object.
|
|
@@ -246,18 +259,18 @@ export function buildSelect(fields) {
|
|
|
246
259
|
*/
|
|
247
260
|
export function getLimit(nql) {
|
|
248
261
|
const regex = /LIMIT\s+(\d+)\s+(\w+)\s+PER\s+(\w+)$/i;
|
|
249
|
-
const match = nql.trim().replace(/\n/g,
|
|
262
|
+
const match = nql.trim().replace(/\n/g, " ").match(regex);
|
|
250
263
|
if (match != null) {
|
|
251
264
|
const [, value, currency, period] = match;
|
|
252
265
|
const result = {
|
|
253
266
|
value: parseInt(value, 10),
|
|
254
267
|
currency: currency.toUpperCase(),
|
|
255
|
-
period: period.toUpperCase()
|
|
268
|
+
period: period.toUpperCase(),
|
|
256
269
|
};
|
|
257
270
|
return NqlBudgetObj.parse(result);
|
|
258
271
|
}
|
|
259
272
|
else {
|
|
260
|
-
throw new Error(
|
|
273
|
+
throw new Error("Invalid budget");
|
|
261
274
|
}
|
|
262
275
|
}
|
|
263
276
|
/**
|
|
@@ -277,12 +290,12 @@ export function buildNql(nql, strict = true) {
|
|
|
277
290
|
NqlObj.parse(nql);
|
|
278
291
|
}
|
|
279
292
|
// Build the NQL string from each of the clasues
|
|
280
|
-
let explain =
|
|
281
|
-
if (
|
|
293
|
+
let explain = "";
|
|
294
|
+
if ("explain" in nql && strict) {
|
|
282
295
|
explain = buildPreSelect(nql.explain);
|
|
283
296
|
}
|
|
284
|
-
let limit =
|
|
285
|
-
if (
|
|
297
|
+
let limit = "";
|
|
298
|
+
if ("limit" in nql && strict) {
|
|
286
299
|
limit = buildLimit(nql.limit);
|
|
287
300
|
}
|
|
288
301
|
const select = buildSelect(nql.select);
|
|
@@ -290,7 +303,7 @@ export function buildNql(nql, strict = true) {
|
|
|
290
303
|
const where = buildWhere(nql.where);
|
|
291
304
|
const clauses = [explain, select, from, where, limit];
|
|
292
305
|
// Remove any empty clausess and join what's left together
|
|
293
|
-
return clauses.filter((c) => c !==
|
|
306
|
+
return clauses.filter((c) => c !== "").join(" ");
|
|
294
307
|
}
|
|
295
308
|
export function buildFrom(from) {
|
|
296
309
|
NqlTableObject.parse(from);
|
|
@@ -298,9 +311,9 @@ export function buildFrom(from) {
|
|
|
298
311
|
}
|
|
299
312
|
export function buildWhere(where) {
|
|
300
313
|
NqlWhereObj.parse(where);
|
|
301
|
-
let str = where.filterExpressions.length > 0 ?
|
|
314
|
+
let str = where.filterExpressions.length > 0 ? "WHERE" : "";
|
|
302
315
|
where.filterExpressions.forEach((f, i) => {
|
|
303
|
-
if (
|
|
316
|
+
if ("field" in f) {
|
|
304
317
|
str += ` ${buildField(f.field)} ${f.operator}`;
|
|
305
318
|
}
|
|
306
319
|
else {
|
|
@@ -322,21 +335,21 @@ export function buildField(field) {
|
|
|
322
335
|
}
|
|
323
336
|
}
|
|
324
337
|
export function getNqlObject(nql, type) {
|
|
325
|
-
const cleanedNql = nql.trim().replace(/\n/g,
|
|
338
|
+
const cleanedNql = nql.trim().replace(/\n/g, " ").replace(/\s+/g, " ");
|
|
326
339
|
const explain = getPreSelect(cleanedNql);
|
|
327
340
|
const limit = getLimit(cleanedNql);
|
|
328
341
|
const where = getWhere(cleanedNql);
|
|
329
342
|
const from = getFrom(cleanedNql);
|
|
330
343
|
const select = getSelect(cleanedNql);
|
|
331
344
|
const parsed = NqlObj.parse({ where, from, explain, select, limit });
|
|
332
|
-
if (type === undefined || type ===
|
|
345
|
+
if (type === undefined || type === "full") {
|
|
333
346
|
return parsed;
|
|
334
347
|
}
|
|
335
348
|
else {
|
|
336
349
|
return {
|
|
337
350
|
where: createSemanticWhere(parsed.where),
|
|
338
351
|
from: parsed.from,
|
|
339
|
-
select: parsed.select
|
|
352
|
+
select: parsed.select,
|
|
340
353
|
};
|
|
341
354
|
}
|
|
342
355
|
}
|
|
@@ -345,12 +358,16 @@ export function createSemanticWhere(expressionContainer) {
|
|
|
345
358
|
let index = 0;
|
|
346
359
|
while (index < copy.filterExpressions.length) {
|
|
347
360
|
const filterExp = copy.filterExpressions[index];
|
|
348
|
-
const fieldObject =
|
|
349
|
-
const leftObject =
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
361
|
+
const fieldObject = "field" in filterExp ? filterExp.field : null;
|
|
362
|
+
const leftObject = "left" in filterExp && typeof filterExp.left === "object"
|
|
363
|
+
? filterExp.left
|
|
364
|
+
: null;
|
|
365
|
+
const rightObject = "right" in filterExp && typeof filterExp.right === "object"
|
|
366
|
+
? filterExp.right
|
|
367
|
+
: null;
|
|
368
|
+
if ((fieldObject?.field?.startsWith("_") ?? false) ||
|
|
369
|
+
(leftObject?.field?.startsWith("_") ?? false) ||
|
|
370
|
+
(rightObject?.field?.startsWith("_") ?? false)) {
|
|
354
371
|
copy.filterExpressions.splice(index, 1);
|
|
355
372
|
if (copy.booleanExpressions.length > index) {
|
|
356
373
|
copy.booleanExpressions.splice(index, 1);
|