@cadenza.io/service 2.17.0 → 2.17.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.js CHANGED
@@ -5731,6 +5731,41 @@ function defaultOperationIntentDescription(operation, tableName) {
5731
5731
  function isExplicitSqlLiteral(value) {
5732
5732
  return /^'.*'::[a-z_][a-z0-9_]*(\[\])?$/i.test(value.trim());
5733
5733
  }
5734
+ function isExplicitSqlExpression(value) {
5735
+ const trimmed = value.trim();
5736
+ if (!trimmed) {
5737
+ return false;
5738
+ }
5739
+ if (isExplicitSqlLiteral(trimmed)) {
5740
+ return true;
5741
+ }
5742
+ if (/^'.*'$/.test(trimmed)) {
5743
+ return true;
5744
+ }
5745
+ if (/^[a-z_][a-z0-9_]*\([^)]*\)$/i.test(trimmed)) {
5746
+ return true;
5747
+ }
5748
+ return /^(current_timestamp|current_date|current_time)$/i.test(trimmed);
5749
+ }
5750
+ function serializeFieldDefaultForSql(value, field) {
5751
+ if (value === void 0 || value === null) {
5752
+ return "NULL";
5753
+ }
5754
+ if (typeof value === "number") {
5755
+ return String(value);
5756
+ }
5757
+ if (typeof value === "boolean") {
5758
+ return value ? "TRUE" : "FALSE";
5759
+ }
5760
+ const stringValue = String(value);
5761
+ if (isExplicitSqlExpression(stringValue)) {
5762
+ return stringValue;
5763
+ }
5764
+ if (field?.type === "jsonb") {
5765
+ return `'${JSON.stringify(value).replace(/'/g, "''")}'::jsonb`;
5766
+ }
5767
+ return `'${stringValue.replace(/'/g, "''")}'`;
5768
+ }
5734
5769
  function serializeInitialDataValueForSql(value, field) {
5735
5770
  if (value === void 0 || value === null) {
5736
5771
  return "NULL";
@@ -5749,7 +5784,7 @@ function serializeInitialDataValueForSql(value, field) {
5749
5784
  return `'${jsonString.replace(/'/g, "''")}'::jsonb`;
5750
5785
  }
5751
5786
  const stringValue = String(value);
5752
- if (isExplicitSqlLiteral(stringValue)) {
5787
+ if (isExplicitSqlExpression(stringValue)) {
5753
5788
  return stringValue;
5754
5789
  }
5755
5790
  return `'${stringValue.replace(/'/g, "''")}'`;
@@ -6790,7 +6825,7 @@ var DatabaseController = class _DatabaseController {
6790
6825
  if (field.primary) definition += " PRIMARY KEY";
6791
6826
  if (field.unique) definition += " UNIQUE";
6792
6827
  if (field.default !== void 0) {
6793
- definition += ` DEFAULT ${field.default === "" ? "''" : String(field.default)}`;
6828
+ definition += ` DEFAULT ${serializeFieldDefaultForSql(field.default, field)}`;
6794
6829
  }
6795
6830
  if (field.required && !field.nullable) definition += " NOT NULL";
6796
6831
  if (field.nullable) definition += " NULL";