@cadenza.io/service 2.16.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 +68 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5677,6 +5677,67 @@ 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 isExplicitSqlExpression(value) {
|
|
5684
|
+
const trimmed = value.trim();
|
|
5685
|
+
if (!trimmed) {
|
|
5686
|
+
return false;
|
|
5687
|
+
}
|
|
5688
|
+
if (isExplicitSqlLiteral(trimmed)) {
|
|
5689
|
+
return true;
|
|
5690
|
+
}
|
|
5691
|
+
if (/^'.*'$/.test(trimmed)) {
|
|
5692
|
+
return true;
|
|
5693
|
+
}
|
|
5694
|
+
if (/^[a-z_][a-z0-9_]*\([^)]*\)$/i.test(trimmed)) {
|
|
5695
|
+
return true;
|
|
5696
|
+
}
|
|
5697
|
+
return /^(current_timestamp|current_date|current_time)$/i.test(trimmed);
|
|
5698
|
+
}
|
|
5699
|
+
function serializeFieldDefaultForSql(value, field) {
|
|
5700
|
+
if (value === void 0 || value === null) {
|
|
5701
|
+
return "NULL";
|
|
5702
|
+
}
|
|
5703
|
+
if (typeof value === "number") {
|
|
5704
|
+
return String(value);
|
|
5705
|
+
}
|
|
5706
|
+
if (typeof value === "boolean") {
|
|
5707
|
+
return value ? "TRUE" : "FALSE";
|
|
5708
|
+
}
|
|
5709
|
+
const stringValue = String(value);
|
|
5710
|
+
if (isExplicitSqlExpression(stringValue)) {
|
|
5711
|
+
return stringValue;
|
|
5712
|
+
}
|
|
5713
|
+
if (field?.type === "jsonb") {
|
|
5714
|
+
return `'${JSON.stringify(value).replace(/'/g, "''")}'::jsonb`;
|
|
5715
|
+
}
|
|
5716
|
+
return `'${stringValue.replace(/'/g, "''")}'`;
|
|
5717
|
+
}
|
|
5718
|
+
function serializeInitialDataValueForSql(value, field) {
|
|
5719
|
+
if (value === void 0 || value === null) {
|
|
5720
|
+
return "NULL";
|
|
5721
|
+
}
|
|
5722
|
+
if (typeof value === "number") {
|
|
5723
|
+
return String(value);
|
|
5724
|
+
}
|
|
5725
|
+
if (typeof value === "boolean") {
|
|
5726
|
+
return value ? "TRUE" : "FALSE";
|
|
5727
|
+
}
|
|
5728
|
+
if (field?.type === "jsonb") {
|
|
5729
|
+
if (typeof value === "string" && isExplicitSqlLiteral(value)) {
|
|
5730
|
+
return value;
|
|
5731
|
+
}
|
|
5732
|
+
const jsonString = JSON.stringify(value);
|
|
5733
|
+
return `'${jsonString.replace(/'/g, "''")}'::jsonb`;
|
|
5734
|
+
}
|
|
5735
|
+
const stringValue = String(value);
|
|
5736
|
+
if (isExplicitSqlExpression(stringValue)) {
|
|
5737
|
+
return stringValue;
|
|
5738
|
+
}
|
|
5739
|
+
return `'${stringValue.replace(/'/g, "''")}'`;
|
|
5740
|
+
}
|
|
5680
5741
|
function readCustomIntentConfig(customIntent) {
|
|
5681
5742
|
if (typeof customIntent === "string") {
|
|
5682
5743
|
return {
|
|
@@ -6690,14 +6751,12 @@ var DatabaseController = class _DatabaseController {
|
|
|
6690
6751
|
if (table.initialData) {
|
|
6691
6752
|
ddl.push(
|
|
6692
6753
|
`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(", ")})`
|
|
6754
|
+
(row) => `(${row.map(
|
|
6755
|
+
(value, index) => serializeInitialDataValueForSql(
|
|
6756
|
+
value,
|
|
6757
|
+
table.fields[table.initialData.fields[index]]
|
|
6758
|
+
)
|
|
6759
|
+
).join(", ")})`
|
|
6701
6760
|
).join(", ")} ON CONFLICT DO NOTHING;`
|
|
6702
6761
|
);
|
|
6703
6762
|
}
|
|
@@ -6715,7 +6774,7 @@ var DatabaseController = class _DatabaseController {
|
|
|
6715
6774
|
if (field.primary) definition += " PRIMARY KEY";
|
|
6716
6775
|
if (field.unique) definition += " UNIQUE";
|
|
6717
6776
|
if (field.default !== void 0) {
|
|
6718
|
-
definition += ` DEFAULT ${field.default
|
|
6777
|
+
definition += ` DEFAULT ${serializeFieldDefaultForSql(field.default, field)}`;
|
|
6719
6778
|
}
|
|
6720
6779
|
if (field.required && !field.nullable) definition += " NOT NULL";
|
|
6721
6780
|
if (field.nullable) definition += " NULL";
|