@cadenza.io/service 2.16.0 → 2.17.0

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
@@ -5728,6 +5728,32 @@ function validateIntentName(intentName) {
5728
5728
  function defaultOperationIntentDescription(operation, tableName) {
5729
5729
  return `Perform a ${operation} operation on the ${tableName} table`;
5730
5730
  }
5731
+ function isExplicitSqlLiteral(value) {
5732
+ return /^'.*'::[a-z_][a-z0-9_]*(\[\])?$/i.test(value.trim());
5733
+ }
5734
+ function serializeInitialDataValueForSql(value, field) {
5735
+ if (value === void 0 || value === null) {
5736
+ return "NULL";
5737
+ }
5738
+ if (typeof value === "number") {
5739
+ return String(value);
5740
+ }
5741
+ if (typeof value === "boolean") {
5742
+ return value ? "TRUE" : "FALSE";
5743
+ }
5744
+ if (field?.type === "jsonb") {
5745
+ if (typeof value === "string" && isExplicitSqlLiteral(value)) {
5746
+ return value;
5747
+ }
5748
+ const jsonString = JSON.stringify(value);
5749
+ return `'${jsonString.replace(/'/g, "''")}'::jsonb`;
5750
+ }
5751
+ const stringValue = String(value);
5752
+ if (isExplicitSqlLiteral(stringValue)) {
5753
+ return stringValue;
5754
+ }
5755
+ return `'${stringValue.replace(/'/g, "''")}'`;
5756
+ }
5731
5757
  function readCustomIntentConfig(customIntent) {
5732
5758
  if (typeof customIntent === "string") {
5733
5759
  return {
@@ -6741,14 +6767,12 @@ var DatabaseController = class _DatabaseController {
6741
6767
  if (table.initialData) {
6742
6768
  ddl.push(
6743
6769
  `INSERT INTO ${tableName} (${table.initialData.fields.map(import_lodash_es.snakeCase).join(", ")}) VALUES ${table.initialData.data.map(
6744
- (row) => `(${row.map((value) => {
6745
- if (value === void 0) return "NULL";
6746
- if (value === null) return "NULL";
6747
- if (typeof value === "number") return String(value);
6748
- if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
6749
- const stringValue = String(value);
6750
- return `'${stringValue.replace(/'/g, "''")}'`;
6751
- }).join(", ")})`
6770
+ (row) => `(${row.map(
6771
+ (value, index) => serializeInitialDataValueForSql(
6772
+ value,
6773
+ table.fields[table.initialData.fields[index]]
6774
+ )
6775
+ ).join(", ")})`
6752
6776
  ).join(", ")} ON CONFLICT DO NOTHING;`
6753
6777
  );
6754
6778
  }