@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 +32 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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(
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
|
|
6749
|
-
|
|
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
|
}
|