@cadenza.io/service 2.17.0 → 2.17.2
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 +39 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5680,6 +5680,41 @@ function defaultOperationIntentDescription(operation, tableName) {
|
|
|
5680
5680
|
function isExplicitSqlLiteral(value) {
|
|
5681
5681
|
return /^'.*'::[a-z_][a-z0-9_]*(\[\])?$/i.test(value.trim());
|
|
5682
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
|
+
}
|
|
5683
5718
|
function serializeInitialDataValueForSql(value, field) {
|
|
5684
5719
|
if (value === void 0 || value === null) {
|
|
5685
5720
|
return "NULL";
|
|
@@ -5698,7 +5733,7 @@ function serializeInitialDataValueForSql(value, field) {
|
|
|
5698
5733
|
return `'${jsonString.replace(/'/g, "''")}'::jsonb`;
|
|
5699
5734
|
}
|
|
5700
5735
|
const stringValue = String(value);
|
|
5701
|
-
if (
|
|
5736
|
+
if (isExplicitSqlExpression(stringValue)) {
|
|
5702
5737
|
return stringValue;
|
|
5703
5738
|
}
|
|
5704
5739
|
return `'${stringValue.replace(/'/g, "''")}'`;
|
|
@@ -6739,7 +6774,7 @@ var DatabaseController = class _DatabaseController {
|
|
|
6739
6774
|
if (field.primary) definition += " PRIMARY KEY";
|
|
6740
6775
|
if (field.unique) definition += " UNIQUE";
|
|
6741
6776
|
if (field.default !== void 0) {
|
|
6742
|
-
definition += ` DEFAULT ${field.default
|
|
6777
|
+
definition += ` DEFAULT ${serializeFieldDefaultForSql(field.default, field)}`;
|
|
6743
6778
|
}
|
|
6744
6779
|
if (field.required && !field.nullable) definition += " NOT NULL";
|
|
6745
6780
|
if (field.nullable) definition += " NULL";
|
|
@@ -6996,12 +7031,9 @@ var DatabaseController = class _DatabaseController {
|
|
|
6996
7031
|
schema
|
|
6997
7032
|
);
|
|
6998
7033
|
for (const intent of intents) {
|
|
6999
|
-
if (registration.intentNames.has(intent.name)) {
|
|
7000
|
-
|
|
7001
|
-
`Duplicate auto/custom intent '${intent.name}' detected while generating ${op} task for table '${tableName}' in actor '${registration.actorName}'`
|
|
7002
|
-
);
|
|
7034
|
+
if (!registration.intentNames.has(intent.name)) {
|
|
7035
|
+
registration.intentNames.add(intent.name);
|
|
7003
7036
|
}
|
|
7004
|
-
registration.intentNames.add(intent.name);
|
|
7005
7037
|
CadenzaService.defineIntent({
|
|
7006
7038
|
name: intent.name,
|
|
7007
7039
|
description: intent.description,
|