@narrative.io/data-collaboration-sdk-ts 0.0.70 → 0.0.71

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.
@@ -141,14 +141,18 @@ function handleFilterExpression(expression, fieldsArray) {
141
141
  */
142
142
  function updateFieldsArray(field, fieldsArray, filterExpression) {
143
143
  const existingEntry = fieldsArray.find((entry) => entry.field === field.field);
144
- if (existingEntry != null) {
145
- const updatedEntry = {
146
- ...existingEntry,
147
- filter: { expressions: [filterExpression] }
148
- };
149
- fieldsArray[fieldsArray.indexOf(existingEntry)] = updatedEntry;
144
+ if (existingEntry !== undefined) {
145
+ if (existingEntry.filter !== undefined && typeof existingEntry.filter === 'object' && 'expressions' in existingEntry.filter) {
146
+ // If there are already filter expressions for this field, push the new one to the array.
147
+ existingEntry.filter.expressions.push(filterExpression);
148
+ }
149
+ else {
150
+ // If there is no filter object yet, create it with the new filter expression.
151
+ existingEntry.filter = { expressions: [filterExpression] };
152
+ }
150
153
  }
151
154
  else {
155
+ // If this field does not exist in the fieldsArray, add it with the new filter expression.
152
156
  fieldsArray.push({ field: field.field, exported: false, filter: { expressions: [filterExpression] } });
153
157
  }
154
158
  }
@@ -175,7 +179,7 @@ function constructBinaryFilterExpression(filter) {
175
179
  */
176
180
  function expressionToString(expr) {
177
181
  if (typeof expr === 'string') {
178
- return `${expr}`;
182
+ return `${addParentheses(expr)}`;
179
183
  }
180
184
  else if (typeof expr === 'number') {
181
185
  return expr.toString();
@@ -187,3 +191,24 @@ function expressionToString(expr) {
187
191
  return expr.field;
188
192
  }
189
193
  }
194
+ /**
195
+ * Adds parentheses to 'CURRENT_TIMESTAMP' or 'CURRENT_DATE' in the input string
196
+ * if they are not already followed by parentheses.
197
+ *
198
+ * @param {string} input - The input string to be processed.
199
+ * @return {string} The processed string with parentheses added where necessary.
200
+ *
201
+ * @example
202
+ * // returns "SELECT * FROM users WHERE timestamp > CURRENT_TIMESTAMP()"
203
+ * addParentheses("SELECT * FROM users WHERE timestamp > CURRENT_TIMESTAMP");
204
+ *
205
+ * @example
206
+ * // returns "SELECT * FROM users WHERE date = CURRENT_DATE()"
207
+ * addParentheses("SELECT * FROM users WHERE date = CURRENT_DATE");
208
+ */
209
+ function addParentheses(input) {
210
+ // Regular expression that matches 'CURRENT_TIMESTAMP' or 'CURRENT_DATE' that is not followed by ()
211
+ const regex = /(CURRENT_TIMESTAMP|CURRENT_DATE)(?!\(\))/g;
212
+ // Replace matched string with itself followed by ()
213
+ return input.replace(regex, '$1()');
214
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narrative.io/data-collaboration-sdk-ts",
3
- "version": "0.0.70",
3
+ "version": "0.0.71",
4
4
  "main": "build/index.js",
5
5
  "repository": "github:narrative-io/data-collaboration-sdk-ts",
6
6
  "source": "src/index.ts",
@@ -31,7 +31,7 @@
31
31
  "eslint": "^8.33.0",
32
32
  "eslint-config-standard-with-typescript": "^35.0.0",
33
33
  "eslint-plugin-import": "^2.27.5",
34
- "eslint-plugin-n": "^15.6.1",
34
+ "eslint-plugin-n": "^15.7.0",
35
35
  "eslint-plugin-promise": "^6.1.1",
36
36
  "husky": "^8.0.0",
37
37
  "jest": "^29.4.3",