@narrative.io/data-collaboration-sdk-ts 0.0.127 → 0.0.128
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/nql/DataRulesConverter.js +20 -10
- package/build/nql/types.d.ts +15 -15
- package/build/nql/types.js +1 -1
- package/package.json +1 -1
|
@@ -33,13 +33,14 @@ async function getAttributesFromFields(fields) {
|
|
|
33
33
|
});
|
|
34
34
|
const attributes = await attributesApi.getAttributes();
|
|
35
35
|
const uniqueAttributes = [
|
|
36
|
-
...new Set(fields.map((field) => field.field.split(".")[0])),
|
|
36
|
+
...new Set(fields.map((field) => stripQuotes(field.field).split(".")[0])),
|
|
37
37
|
].filter((att) => !att.startsWith("_"));
|
|
38
38
|
uniqueAttributes.forEach((att) => {
|
|
39
39
|
const isObjectProperty = isObject(attributes.records, att);
|
|
40
40
|
const relevantFields = isObjectProperty != null
|
|
41
|
-
? fields.filter((field) => field.field.split(".")[0] === att &&
|
|
42
|
-
|
|
41
|
+
? fields.filter((field) => stripQuotes(field.field).split(".")[0] === att &&
|
|
42
|
+
field.field !== att)
|
|
43
|
+
: fields.filter((field) => stripQuotes(field.field).split(".")[0] === att);
|
|
43
44
|
const attributeId = attributes.records.find((attribute) => attribute.name === att)?.id;
|
|
44
45
|
if (attributeId === undefined) {
|
|
45
46
|
throw new Error(`Attribute ${att} not found`);
|
|
@@ -89,10 +90,10 @@ function ensureAtLeastOneRequired(dataRulesAttributes) {
|
|
|
89
90
|
function getPriceFromNql(nqlObject) {
|
|
90
91
|
const priceFilter = nqlObject.where.filterExpressions.filter((expr) => ("left" in expr &&
|
|
91
92
|
typeof expr.left === "object" &&
|
|
92
|
-
expr.left.field === "_price_cpm_usd") ||
|
|
93
|
+
stripQuotes(expr.left.field) === "_price_cpm_usd") ||
|
|
93
94
|
("right" in expr &&
|
|
94
95
|
typeof expr.right === "object" &&
|
|
95
|
-
expr.right.field === "_price_cpm_usd"));
|
|
96
|
+
stripQuotes(expr.right.field) === "_price_cpm_usd"));
|
|
96
97
|
if (priceFilter.length !== 1) {
|
|
97
98
|
throw new Error("Expected exactly one price filter");
|
|
98
99
|
}
|
|
@@ -120,7 +121,7 @@ function getFieldsFromNql(nqlObject) {
|
|
|
120
121
|
// Extract all fields from the 'select' section and mark them as exported.
|
|
121
122
|
nqlObject.select.forEach((field) => {
|
|
122
123
|
fieldsArray.push({
|
|
123
|
-
field: field.field
|
|
124
|
+
field: stripQuotes(field.field),
|
|
124
125
|
exported: true,
|
|
125
126
|
});
|
|
126
127
|
});
|
|
@@ -157,7 +158,7 @@ function handleFilterExpression(expression, fieldsArray) {
|
|
|
157
158
|
* @param {any} filterExpression - The filter expression to add to the field.
|
|
158
159
|
*/
|
|
159
160
|
function updateFieldsArray(field, fieldsArray, filterExpression) {
|
|
160
|
-
const existingEntry = fieldsArray.find((entry) => entry.field === field.field);
|
|
161
|
+
const existingEntry = fieldsArray.find((entry) => entry.field === stripQuotes(field.field));
|
|
161
162
|
if (existingEntry !== undefined) {
|
|
162
163
|
if (existingEntry.filter !== undefined &&
|
|
163
164
|
typeof existingEntry.filter === "object" &&
|
|
@@ -173,7 +174,7 @@ function updateFieldsArray(field, fieldsArray, filterExpression) {
|
|
|
173
174
|
else {
|
|
174
175
|
// If this field does not exist in the fieldsArray, add it with the new filter expression.
|
|
175
176
|
fieldsArray.push({
|
|
176
|
-
field: field.field,
|
|
177
|
+
field: stripQuotes(field.field),
|
|
177
178
|
exported: false,
|
|
178
179
|
filter: { expressions: [filterExpression] },
|
|
179
180
|
});
|
|
@@ -185,7 +186,7 @@ function updateFieldsArray(field, fieldsArray, filterExpression) {
|
|
|
185
186
|
* @returns {string} - Returns a string representation of the unary filter expression.
|
|
186
187
|
*/
|
|
187
188
|
function constructUnaryFilterExpression(filter) {
|
|
188
|
-
return `${expressionToString(filter.field.field)} ${filter.operator}`;
|
|
189
|
+
return `${expressionToString(stripQuotes(filter.field.field))} ${filter.operator}`;
|
|
189
190
|
}
|
|
190
191
|
/**
|
|
191
192
|
* Constructs a string representing a binary filter expression.
|
|
@@ -193,7 +194,7 @@ function constructUnaryFilterExpression(filter) {
|
|
|
193
194
|
* @returns {string} - Returns a string representation of the binary filter expression.
|
|
194
195
|
*/
|
|
195
196
|
function constructBinaryFilterExpression(filter) {
|
|
196
|
-
return `${expressionToString(filter.left)} ${filter.operator} ${expressionToString(filter.right)}`;
|
|
197
|
+
return `${stripQuotes(expressionToString(filter.left))} ${filter.operator} ${stripQuotes(expressionToString(filter.right))}`;
|
|
197
198
|
}
|
|
198
199
|
/**
|
|
199
200
|
* Converts an expression to a string.
|
|
@@ -448,3 +449,12 @@ function generateWhereClause(dataRules) {
|
|
|
448
449
|
}
|
|
449
450
|
return `WHERE ${whereConditions.join(" AND ")}`;
|
|
450
451
|
}
|
|
452
|
+
/**
|
|
453
|
+
* Removes all double quotes from the given string.
|
|
454
|
+
*
|
|
455
|
+
* @param {string} str - The input string.
|
|
456
|
+
* @returns {string} The string without double quotes.
|
|
457
|
+
*/
|
|
458
|
+
function stripQuotes(str) {
|
|
459
|
+
return str.replace(/"/g, "");
|
|
460
|
+
}
|
package/build/nql/types.d.ts
CHANGED
|
@@ -69,7 +69,7 @@ export declare const NqlTableObject: z.ZodObject<{
|
|
|
69
69
|
}>;
|
|
70
70
|
export type NqlTable = z.infer<typeof NqlTableObject>;
|
|
71
71
|
export declare const NqlFieldObj: z.ZodObject<{
|
|
72
|
-
field: z.ZodString
|
|
72
|
+
field: z.ZodEffects<z.ZodString, string, string>;
|
|
73
73
|
table: z.ZodObject<{
|
|
74
74
|
database: z.ZodEffects<z.ZodString, string, string>;
|
|
75
75
|
table: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -95,7 +95,7 @@ export declare const NqlFieldObj: z.ZodObject<{
|
|
|
95
95
|
}>;
|
|
96
96
|
export declare const NqlFilterUnaryExpressionObj: z.ZodObject<{
|
|
97
97
|
field: z.ZodObject<{
|
|
98
|
-
field: z.ZodString
|
|
98
|
+
field: z.ZodEffects<z.ZodString, string, string>;
|
|
99
99
|
table: z.ZodObject<{
|
|
100
100
|
database: z.ZodEffects<z.ZodString, string, string>;
|
|
101
101
|
table: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -141,7 +141,7 @@ export declare const NqlFilterUnaryExpressionObj: z.ZodObject<{
|
|
|
141
141
|
}>;
|
|
142
142
|
export type NqlFilterUnaryExpression = z.infer<typeof NqlFilterUnaryExpressionObj>;
|
|
143
143
|
declare const NqlExpressionObj: z.ZodUnion<[z.ZodObject<{
|
|
144
|
-
field: z.ZodString
|
|
144
|
+
field: z.ZodEffects<z.ZodString, string, string>;
|
|
145
145
|
table: z.ZodObject<{
|
|
146
146
|
database: z.ZodEffects<z.ZodString, string, string>;
|
|
147
147
|
table: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -168,7 +168,7 @@ declare const NqlExpressionObj: z.ZodUnion<[z.ZodObject<{
|
|
|
168
168
|
export type NqlExpression = z.infer<typeof NqlExpressionObj>;
|
|
169
169
|
export declare const NqlFilterBinaryExpressionObj: z.ZodObject<{
|
|
170
170
|
left: z.ZodUnion<[z.ZodObject<{
|
|
171
|
-
field: z.ZodString
|
|
171
|
+
field: z.ZodEffects<z.ZodString, string, string>;
|
|
172
172
|
table: z.ZodObject<{
|
|
173
173
|
database: z.ZodEffects<z.ZodString, string, string>;
|
|
174
174
|
table: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -194,7 +194,7 @@ export declare const NqlFilterBinaryExpressionObj: z.ZodObject<{
|
|
|
194
194
|
}>, z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
195
195
|
operator: z.ZodEnum<["=", "!=", ">", "<", ">=", "<=", "IN", "NOT IN", "LIKE", "NOT LIKE"]>;
|
|
196
196
|
right: z.ZodUnion<[z.ZodObject<{
|
|
197
|
-
field: z.ZodString
|
|
197
|
+
field: z.ZodEffects<z.ZodString, string, string>;
|
|
198
198
|
table: z.ZodObject<{
|
|
199
199
|
database: z.ZodEffects<z.ZodString, string, string>;
|
|
200
200
|
table: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -277,7 +277,7 @@ export declare const NqlFilterBinaryExpressionObj: z.ZodObject<{
|
|
|
277
277
|
}>;
|
|
278
278
|
export declare const NqlFilterExpressionObj: z.ZodUnion<[z.ZodObject<{
|
|
279
279
|
field: z.ZodObject<{
|
|
280
|
-
field: z.ZodString
|
|
280
|
+
field: z.ZodEffects<z.ZodString, string, string>;
|
|
281
281
|
table: z.ZodObject<{
|
|
282
282
|
database: z.ZodEffects<z.ZodString, string, string>;
|
|
283
283
|
table: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -322,7 +322,7 @@ export declare const NqlFilterExpressionObj: z.ZodUnion<[z.ZodObject<{
|
|
|
322
322
|
};
|
|
323
323
|
}>, z.ZodObject<{
|
|
324
324
|
left: z.ZodUnion<[z.ZodObject<{
|
|
325
|
-
field: z.ZodString
|
|
325
|
+
field: z.ZodEffects<z.ZodString, string, string>;
|
|
326
326
|
table: z.ZodObject<{
|
|
327
327
|
database: z.ZodEffects<z.ZodString, string, string>;
|
|
328
328
|
table: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -348,7 +348,7 @@ export declare const NqlFilterExpressionObj: z.ZodUnion<[z.ZodObject<{
|
|
|
348
348
|
}>, z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
349
349
|
operator: z.ZodEnum<["=", "!=", ">", "<", ">=", "<=", "IN", "NOT IN", "LIKE", "NOT LIKE"]>;
|
|
350
350
|
right: z.ZodUnion<[z.ZodObject<{
|
|
351
|
-
field: z.ZodString
|
|
351
|
+
field: z.ZodEffects<z.ZodString, string, string>;
|
|
352
352
|
table: z.ZodObject<{
|
|
353
353
|
database: z.ZodEffects<z.ZodString, string, string>;
|
|
354
354
|
table: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -436,7 +436,7 @@ export declare const NqlWhereObj: z.ZodEffects<z.ZodObject<{
|
|
|
436
436
|
booleanExpressions: z.ZodArray<z.ZodEnum<["AND", "OR"]>, "many">;
|
|
437
437
|
filterExpressions: z.ZodArray<z.ZodUnion<[z.ZodObject<{
|
|
438
438
|
field: z.ZodObject<{
|
|
439
|
-
field: z.ZodString
|
|
439
|
+
field: z.ZodEffects<z.ZodString, string, string>;
|
|
440
440
|
table: z.ZodObject<{
|
|
441
441
|
database: z.ZodEffects<z.ZodString, string, string>;
|
|
442
442
|
table: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -481,7 +481,7 @@ export declare const NqlWhereObj: z.ZodEffects<z.ZodObject<{
|
|
|
481
481
|
};
|
|
482
482
|
}>, z.ZodObject<{
|
|
483
483
|
left: z.ZodUnion<[z.ZodObject<{
|
|
484
|
-
field: z.ZodString
|
|
484
|
+
field: z.ZodEffects<z.ZodString, string, string>;
|
|
485
485
|
table: z.ZodObject<{
|
|
486
486
|
database: z.ZodEffects<z.ZodString, string, string>;
|
|
487
487
|
table: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -507,7 +507,7 @@ export declare const NqlWhereObj: z.ZodEffects<z.ZodObject<{
|
|
|
507
507
|
}>, z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
508
508
|
operator: z.ZodEnum<["=", "!=", ">", "<", ">=", "<=", "IN", "NOT IN", "LIKE", "NOT LIKE"]>;
|
|
509
509
|
right: z.ZodUnion<[z.ZodObject<{
|
|
510
|
-
field: z.ZodString
|
|
510
|
+
field: z.ZodEffects<z.ZodString, string, string>;
|
|
511
511
|
table: z.ZodObject<{
|
|
512
512
|
database: z.ZodEffects<z.ZodString, string, string>;
|
|
513
513
|
table: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -754,7 +754,7 @@ export type NqlFilterBinaryExpression = z.infer<typeof NqlFilterBinaryExpression
|
|
|
754
754
|
export declare const NqlObj: z.ZodObject<{
|
|
755
755
|
explain: z.ZodOptional<z.ZodEnum<["EXPLAIN"]>>;
|
|
756
756
|
select: z.ZodArray<z.ZodObject<{
|
|
757
|
-
field: z.ZodString
|
|
757
|
+
field: z.ZodEffects<z.ZodString, string, string>;
|
|
758
758
|
table: z.ZodObject<{
|
|
759
759
|
database: z.ZodEffects<z.ZodString, string, string>;
|
|
760
760
|
table: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -792,7 +792,7 @@ export declare const NqlObj: z.ZodObject<{
|
|
|
792
792
|
booleanExpressions: z.ZodArray<z.ZodEnum<["AND", "OR"]>, "many">;
|
|
793
793
|
filterExpressions: z.ZodArray<z.ZodUnion<[z.ZodObject<{
|
|
794
794
|
field: z.ZodObject<{
|
|
795
|
-
field: z.ZodString
|
|
795
|
+
field: z.ZodEffects<z.ZodString, string, string>;
|
|
796
796
|
table: z.ZodObject<{
|
|
797
797
|
database: z.ZodEffects<z.ZodString, string, string>;
|
|
798
798
|
table: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -837,7 +837,7 @@ export declare const NqlObj: z.ZodObject<{
|
|
|
837
837
|
};
|
|
838
838
|
}>, z.ZodObject<{
|
|
839
839
|
left: z.ZodUnion<[z.ZodObject<{
|
|
840
|
-
field: z.ZodString
|
|
840
|
+
field: z.ZodEffects<z.ZodString, string, string>;
|
|
841
841
|
table: z.ZodObject<{
|
|
842
842
|
database: z.ZodEffects<z.ZodString, string, string>;
|
|
843
843
|
table: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -863,7 +863,7 @@ export declare const NqlObj: z.ZodObject<{
|
|
|
863
863
|
}>, z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
864
864
|
operator: z.ZodEnum<["=", "!=", ">", "<", ">=", "<=", "IN", "NOT IN", "LIKE", "NOT LIKE"]>;
|
|
865
865
|
right: z.ZodUnion<[z.ZodObject<{
|
|
866
|
-
field: z.ZodString
|
|
866
|
+
field: z.ZodEffects<z.ZodString, string, string>;
|
|
867
867
|
table: z.ZodObject<{
|
|
868
868
|
database: z.ZodEffects<z.ZodString, string, string>;
|
|
869
869
|
table: z.ZodEffects<z.ZodString, string, string>;
|
package/build/nql/types.js
CHANGED
|
@@ -58,7 +58,7 @@ export const NqlTableObject = z.object({
|
|
|
58
58
|
.refine((x) => x.replaceAll('"', "").toLowerCase() === "rosetta_stone", "Table must be `rosetta_stone`."),
|
|
59
59
|
});
|
|
60
60
|
export const NqlFieldObj = z.object({
|
|
61
|
-
field: z.string().trim(),
|
|
61
|
+
field: z.string().refine((x) => x.replaceAll('"', "").trim()),
|
|
62
62
|
table: NqlTableObject,
|
|
63
63
|
});
|
|
64
64
|
export const NqlFilterUnaryExpressionObj = z.object({
|