@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.mjs
CHANGED
|
@@ -5677,6 +5677,32 @@ function validateIntentName(intentName) {
|
|
|
5677
5677
|
function defaultOperationIntentDescription(operation, tableName) {
|
|
5678
5678
|
return `Perform a ${operation} operation on the ${tableName} table`;
|
|
5679
5679
|
}
|
|
5680
|
+
function isExplicitSqlLiteral(value) {
|
|
5681
|
+
return /^'.*'::[a-z_][a-z0-9_]*(\[\])?$/i.test(value.trim());
|
|
5682
|
+
}
|
|
5683
|
+
function serializeInitialDataValueForSql(value, field) {
|
|
5684
|
+
if (value === void 0 || value === null) {
|
|
5685
|
+
return "NULL";
|
|
5686
|
+
}
|
|
5687
|
+
if (typeof value === "number") {
|
|
5688
|
+
return String(value);
|
|
5689
|
+
}
|
|
5690
|
+
if (typeof value === "boolean") {
|
|
5691
|
+
return value ? "TRUE" : "FALSE";
|
|
5692
|
+
}
|
|
5693
|
+
if (field?.type === "jsonb") {
|
|
5694
|
+
if (typeof value === "string" && isExplicitSqlLiteral(value)) {
|
|
5695
|
+
return value;
|
|
5696
|
+
}
|
|
5697
|
+
const jsonString = JSON.stringify(value);
|
|
5698
|
+
return `'${jsonString.replace(/'/g, "''")}'::jsonb`;
|
|
5699
|
+
}
|
|
5700
|
+
const stringValue = String(value);
|
|
5701
|
+
if (isExplicitSqlLiteral(stringValue)) {
|
|
5702
|
+
return stringValue;
|
|
5703
|
+
}
|
|
5704
|
+
return `'${stringValue.replace(/'/g, "''")}'`;
|
|
5705
|
+
}
|
|
5680
5706
|
function readCustomIntentConfig(customIntent) {
|
|
5681
5707
|
if (typeof customIntent === "string") {
|
|
5682
5708
|
return {
|
|
@@ -6690,14 +6716,12 @@ var DatabaseController = class _DatabaseController {
|
|
|
6690
6716
|
if (table.initialData) {
|
|
6691
6717
|
ddl.push(
|
|
6692
6718
|
`INSERT INTO ${tableName} (${table.initialData.fields.map(snakeCase).join(", ")}) VALUES ${table.initialData.data.map(
|
|
6693
|
-
(row) => `(${row.map(
|
|
6694
|
-
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
return `'${stringValue.replace(/'/g, "''")}'`;
|
|
6700
|
-
}).join(", ")})`
|
|
6719
|
+
(row) => `(${row.map(
|
|
6720
|
+
(value, index) => serializeInitialDataValueForSql(
|
|
6721
|
+
value,
|
|
6722
|
+
table.fields[table.initialData.fields[index]]
|
|
6723
|
+
)
|
|
6724
|
+
).join(", ")})`
|
|
6701
6725
|
).join(", ")} ON CONFLICT DO NOTHING;`
|
|
6702
6726
|
);
|
|
6703
6727
|
}
|