@carbonorm/carbonnode 4.0.0 → 4.0.1

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/dist/index.esm.js CHANGED
@@ -1824,8 +1824,9 @@ var ConditionBuilder = /** @class */ (function (_super) {
1824
1824
  }
1825
1825
  throw new Error('Unsupported operand type in SQL expression.');
1826
1826
  };
1827
- ConditionBuilder.prototype.isPlainArrayLiteral = function (value) {
1827
+ ConditionBuilder.prototype.isPlainArrayLiteral = function (value, allowColumnRefs) {
1828
1828
  var _this = this;
1829
+ if (allowColumnRefs === void 0) { allowColumnRefs = false; }
1829
1830
  if (!Array.isArray(value))
1830
1831
  return false;
1831
1832
  return value.every(function (item) {
@@ -1835,14 +1836,15 @@ var ConditionBuilder = /** @class */ (function (_super) {
1835
1836
  if (type === 'string' || type === 'number' || type === 'boolean')
1836
1837
  return true;
1837
1838
  if (Array.isArray(item))
1838
- return _this.isPlainArrayLiteral(item);
1839
+ return _this.isPlainArrayLiteral(item, allowColumnRefs);
1839
1840
  if (item && typeof item === 'object')
1840
- return _this.isPlainObjectLiteral(item);
1841
+ return _this.isPlainObjectLiteral(item, allowColumnRefs);
1841
1842
  return false;
1842
1843
  });
1843
1844
  };
1844
- ConditionBuilder.prototype.isPlainObjectLiteral = function (value) {
1845
+ ConditionBuilder.prototype.isPlainObjectLiteral = function (value, allowColumnRefs) {
1845
1846
  var _this = this;
1847
+ if (allowColumnRefs === void 0) { allowColumnRefs = false; }
1846
1848
  if (!value || typeof value !== 'object' || Array.isArray(value))
1847
1849
  return false;
1848
1850
  if (value instanceof Date)
@@ -1861,17 +1863,37 @@ var ConditionBuilder = /** @class */ (function (_super) {
1861
1863
  })) {
1862
1864
  return false;
1863
1865
  }
1864
- if (entries.some(function (_a) {
1865
- var key = _a[0];
1866
- return typeof key === 'string' && (_this.isColumnRef(key) || key.includes('.'));
1867
- })) {
1868
- return false;
1866
+ if (!allowColumnRefs) {
1867
+ if (entries.some(function (_a) {
1868
+ var key = _a[0];
1869
+ return typeof key === 'string' && (_this.isColumnRef(key) || key.includes('.'));
1870
+ })) {
1871
+ return false;
1872
+ }
1869
1873
  }
1870
1874
  return true;
1871
1875
  };
1876
+ ConditionBuilder.prototype.resolveColumnDefinition = function (column) {
1877
+ var _a, _b, _c, _d;
1878
+ if (!column || typeof column !== 'string' || !column.includes('.'))
1879
+ return undefined;
1880
+ var _e = column.split('.', 2), prefix = _e[0], colName = _e[1];
1881
+ var tableName = (_a = this.aliasMap[prefix]) !== null && _a !== void 0 ? _a : prefix;
1882
+ var table = (_c = (_b = this.config.C6) === null || _b === void 0 ? void 0 : _b.TABLES) === null || _c === void 0 ? void 0 : _c[tableName];
1883
+ if (!(table === null || table === void 0 ? void 0 : table.TYPE_VALIDATION))
1884
+ return undefined;
1885
+ return (_d = table.TYPE_VALIDATION[colName]) !== null && _d !== void 0 ? _d : table.TYPE_VALIDATION["".concat(tableName, ".").concat(colName)];
1886
+ };
1887
+ ConditionBuilder.prototype.isJsonColumn = function (column) {
1888
+ var columnDef = this.resolveColumnDefinition(column);
1889
+ var mysqlType = columnDef === null || columnDef === void 0 ? void 0 : columnDef.MYSQL_TYPE;
1890
+ return typeof mysqlType === 'string' && mysqlType.toLowerCase().includes('json');
1891
+ };
1872
1892
  ConditionBuilder.prototype.serializeUpdateValue = function (value, params, contextColumn) {
1873
1893
  var normalized = value instanceof Map ? Object.fromEntries(value) : value;
1874
- if (this.isPlainArrayLiteral(normalized) || this.isPlainObjectLiteral(normalized)) {
1894
+ var allowColumnRefs = this.isJsonColumn(contextColumn);
1895
+ if (this.isPlainArrayLiteral(normalized, allowColumnRefs)
1896
+ || this.isPlainObjectLiteral(normalized, allowColumnRefs)) {
1875
1897
  return this.addParam(params, contextColumn !== null && contextColumn !== void 0 ? contextColumn : '', JSON.stringify(normalized));
1876
1898
  }
1877
1899
  var _a = this.serializeOperand(normalized, params, contextColumn), sql = _a.sql, isReference = _a.isReference, isExpression = _a.isExpression, isSubSelect = _a.isSubSelect;