@cadenza.io/service 2.17.9 → 2.17.10
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/browser/index.js +7 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +7 -0
- package/dist/browser/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +71 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -23120,6 +23120,7 @@ declare class DatabaseController {
|
|
|
23120
23120
|
private deleteFunction;
|
|
23121
23121
|
private resolveSafetyPolicy;
|
|
23122
23122
|
private buildOnConflictClause;
|
|
23123
|
+
private getFieldDefinitionForKey;
|
|
23123
23124
|
/**
|
|
23124
23125
|
* Validates database schema structure and content.
|
|
23125
23126
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -23120,6 +23120,7 @@ declare class DatabaseController {
|
|
|
23120
23120
|
private deleteFunction;
|
|
23121
23121
|
private resolveSafetyPolicy;
|
|
23122
23122
|
private buildOnConflictClause;
|
|
23123
|
+
private getFieldDefinitionForKey;
|
|
23123
23124
|
/**
|
|
23124
23125
|
* Validates database schema structure and content.
|
|
23125
23126
|
*/
|
package/dist/index.js
CHANGED
|
@@ -5830,6 +5830,13 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
5830
5830
|
};
|
|
5831
5831
|
}).doOn("meta.task.layer_index_changed", "meta.task.destroyed").emits("global.meta.graph_metadata.task_updated");
|
|
5832
5832
|
CadenzaService.createMetaTask("Handle task relationship creation", (ctx) => {
|
|
5833
|
+
const taskName = ctx.data?.taskName ?? ctx.data?.task_name;
|
|
5834
|
+
const predecessorTaskName = ctx.data?.predecessorTaskName ?? ctx.data?.predecessor_task_name;
|
|
5835
|
+
const task = taskName ? CadenzaService.get(taskName) : void 0;
|
|
5836
|
+
const predecessorTask = predecessorTaskName ? CadenzaService.get(predecessorTaskName) : void 0;
|
|
5837
|
+
if (!task?.registered || !predecessorTask?.registered) {
|
|
5838
|
+
return false;
|
|
5839
|
+
}
|
|
5833
5840
|
return {
|
|
5834
5841
|
data: {
|
|
5835
5842
|
...ctx.data,
|
|
@@ -6106,6 +6113,13 @@ function defaultOperationIntentDescription(operation, tableName) {
|
|
|
6106
6113
|
function isExplicitSqlLiteral(value) {
|
|
6107
6114
|
return /^'.*'::[a-z_][a-z0-9_]*(\[\])?$/i.test(value.trim());
|
|
6108
6115
|
}
|
|
6116
|
+
function extractExplicitJsonLiteral(value) {
|
|
6117
|
+
const match = /^'(.*)'::jsonb$/i.exec(value.trim());
|
|
6118
|
+
if (!match) {
|
|
6119
|
+
return null;
|
|
6120
|
+
}
|
|
6121
|
+
return match[1].replace(/''/g, "'");
|
|
6122
|
+
}
|
|
6109
6123
|
function isExplicitSqlExpression(value) {
|
|
6110
6124
|
const trimmed = value.trim();
|
|
6111
6125
|
if (!trimmed) {
|
|
@@ -6164,6 +6178,24 @@ function serializeInitialDataValueForSql(value, field) {
|
|
|
6164
6178
|
}
|
|
6165
6179
|
return `'${stringValue.replace(/'/g, "''")}'`;
|
|
6166
6180
|
}
|
|
6181
|
+
function serializeFieldValueForQuery(value, field) {
|
|
6182
|
+
if (value === void 0 || value === null || field?.type !== "jsonb") {
|
|
6183
|
+
return value;
|
|
6184
|
+
}
|
|
6185
|
+
if (typeof value === "string") {
|
|
6186
|
+
const explicitJsonLiteral = extractExplicitJsonLiteral(value);
|
|
6187
|
+
if (explicitJsonLiteral !== null) {
|
|
6188
|
+
return explicitJsonLiteral;
|
|
6189
|
+
}
|
|
6190
|
+
try {
|
|
6191
|
+
JSON.parse(value);
|
|
6192
|
+
return value;
|
|
6193
|
+
} catch {
|
|
6194
|
+
return JSON.stringify(value);
|
|
6195
|
+
}
|
|
6196
|
+
}
|
|
6197
|
+
return JSON.stringify(value);
|
|
6198
|
+
}
|
|
6167
6199
|
function readCustomIntentConfig(customIntent) {
|
|
6168
6200
|
if (typeof customIntent === "string") {
|
|
6169
6201
|
return {
|
|
@@ -6845,18 +6877,28 @@ var DatabaseController = class _DatabaseController {
|
|
|
6845
6877
|
throw new Error("No rows available for insert after resolving data");
|
|
6846
6878
|
}
|
|
6847
6879
|
const keys = Object.keys(rows[0]);
|
|
6880
|
+
const tableFields = registration.schema.tables[tableName]?.fields ?? {};
|
|
6848
6881
|
const sqlPrefix = `INSERT INTO ${tableName} (${keys.map((key) => (0, import_lodash_es.snakeCase)(key)).join(", ")}) VALUES `;
|
|
6849
6882
|
const params = [];
|
|
6850
6883
|
const placeholders = rows.map((row) => {
|
|
6851
6884
|
const tuple = keys.map((key) => {
|
|
6852
|
-
params.push(
|
|
6885
|
+
params.push(
|
|
6886
|
+
serializeFieldValueForQuery(
|
|
6887
|
+
row[key],
|
|
6888
|
+
this.getFieldDefinitionForKey(tableFields, key)
|
|
6889
|
+
)
|
|
6890
|
+
);
|
|
6853
6891
|
return `$${params.length}`;
|
|
6854
6892
|
}).join(", ");
|
|
6855
6893
|
return `(${tuple})`;
|
|
6856
6894
|
}).join(", ");
|
|
6857
6895
|
let onConflictSql = "";
|
|
6858
6896
|
if (onConflict) {
|
|
6859
|
-
onConflictSql = this.buildOnConflictClause(
|
|
6897
|
+
onConflictSql = this.buildOnConflictClause(
|
|
6898
|
+
onConflict,
|
|
6899
|
+
params,
|
|
6900
|
+
tableFields
|
|
6901
|
+
);
|
|
6860
6902
|
}
|
|
6861
6903
|
const sql = `${sqlPrefix}${placeholders}${onConflictSql} RETURNING ${fields.length ? fields.map(import_lodash_es.snakeCase).join(", ") : "*"}`;
|
|
6862
6904
|
const result = await this.withTimeout(
|
|
@@ -6904,27 +6946,26 @@ var DatabaseController = class _DatabaseController {
|
|
|
6904
6946
|
data,
|
|
6905
6947
|
tableName
|
|
6906
6948
|
);
|
|
6907
|
-
const
|
|
6908
|
-
|
|
6909
|
-
const setClause = Object.keys(resolvedData).map((key
|
|
6949
|
+
const tableFields = registration.schema.tables[tableName]?.fields ?? {};
|
|
6950
|
+
const params = [];
|
|
6951
|
+
const setClause = Object.keys(resolvedData).map((key) => {
|
|
6910
6952
|
const value = resolvedData[key];
|
|
6911
|
-
const offsetIndex = index - offset;
|
|
6912
6953
|
if (value?.__effect === "increment") {
|
|
6913
|
-
params.splice(offsetIndex, 1);
|
|
6914
|
-
offset += 1;
|
|
6915
6954
|
return `${(0, import_lodash_es.snakeCase)(key)} = ${(0, import_lodash_es.snakeCase)(key)} + 1`;
|
|
6916
6955
|
}
|
|
6917
6956
|
if (value?.__effect === "decrement") {
|
|
6918
|
-
params.splice(offsetIndex, 1);
|
|
6919
|
-
offset += 1;
|
|
6920
6957
|
return `${(0, import_lodash_es.snakeCase)(key)} = ${(0, import_lodash_es.snakeCase)(key)} - 1`;
|
|
6921
6958
|
}
|
|
6922
6959
|
if (value?.__effect === "set") {
|
|
6923
|
-
params.splice(offsetIndex, 1);
|
|
6924
|
-
offset += 1;
|
|
6925
6960
|
return `${(0, import_lodash_es.snakeCase)(key)} = ${value.__value}`;
|
|
6926
6961
|
}
|
|
6927
|
-
|
|
6962
|
+
params.push(
|
|
6963
|
+
serializeFieldValueForQuery(
|
|
6964
|
+
value,
|
|
6965
|
+
this.getFieldDefinitionForKey(tableFields, key)
|
|
6966
|
+
)
|
|
6967
|
+
);
|
|
6968
|
+
return `${(0, import_lodash_es.snakeCase)(key)} = $${params.length}`;
|
|
6928
6969
|
}).join(", ");
|
|
6929
6970
|
const whereClause = this.buildWhereClause(filter, params);
|
|
6930
6971
|
const sql = `UPDATE ${tableName} SET ${setClause} ${whereClause} RETURNING *`;
|
|
@@ -7013,7 +7054,7 @@ var DatabaseController = class _DatabaseController {
|
|
|
7013
7054
|
retryDelayFactor: Number.isFinite(durableState.safetyPolicy?.retryDelayFactor) ? Math.max(1, Number(durableState.safetyPolicy?.retryDelayFactor)) : 1
|
|
7014
7055
|
};
|
|
7015
7056
|
}
|
|
7016
|
-
buildOnConflictClause(onConflict, params) {
|
|
7057
|
+
buildOnConflictClause(onConflict, params, tableFields) {
|
|
7017
7058
|
const { target, action } = onConflict;
|
|
7018
7059
|
let sql = ` ON CONFLICT (${target.map(import_lodash_es.snakeCase).join(", ")})`;
|
|
7019
7060
|
if (action.do === "update") {
|
|
@@ -7024,7 +7065,12 @@ var DatabaseController = class _DatabaseController {
|
|
|
7024
7065
|
if (typeof value === "string" && value === "excluded") {
|
|
7025
7066
|
return `${(0, import_lodash_es.snakeCase)(field)} = excluded.${(0, import_lodash_es.snakeCase)(field)}`;
|
|
7026
7067
|
}
|
|
7027
|
-
params.push(
|
|
7068
|
+
params.push(
|
|
7069
|
+
serializeFieldValueForQuery(
|
|
7070
|
+
value,
|
|
7071
|
+
this.getFieldDefinitionForKey(tableFields, field)
|
|
7072
|
+
)
|
|
7073
|
+
);
|
|
7028
7074
|
return `${(0, import_lodash_es.snakeCase)(field)} = $${params.length}`;
|
|
7029
7075
|
});
|
|
7030
7076
|
sql += ` DO UPDATE SET ${assignments.join(", ")}`;
|
|
@@ -7036,6 +7082,9 @@ var DatabaseController = class _DatabaseController {
|
|
|
7036
7082
|
sql += " DO NOTHING";
|
|
7037
7083
|
return sql;
|
|
7038
7084
|
}
|
|
7085
|
+
getFieldDefinitionForKey(fields, key) {
|
|
7086
|
+
return fields[key] ?? fields[(0, import_lodash_es.snakeCase)(key)];
|
|
7087
|
+
}
|
|
7039
7088
|
/**
|
|
7040
7089
|
* Validates database schema structure and content.
|
|
7041
7090
|
*/
|
|
@@ -7657,7 +7706,13 @@ var DatabaseController = class _DatabaseController {
|
|
|
7657
7706
|
);
|
|
7658
7707
|
const row = ensurePlainObject(resolvedData, "sub-operation insert data");
|
|
7659
7708
|
const keys = Object.keys(row);
|
|
7660
|
-
const
|
|
7709
|
+
const tableFields = registration.schema.tables[operation.table]?.fields ?? {};
|
|
7710
|
+
const params = keys.map(
|
|
7711
|
+
(key) => serializeFieldValueForQuery(
|
|
7712
|
+
row[key],
|
|
7713
|
+
this.getFieldDefinitionForKey(tableFields, key)
|
|
7714
|
+
)
|
|
7715
|
+
);
|
|
7661
7716
|
const sql2 = `INSERT INTO ${operation.table} (${keys.map((key) => (0, import_lodash_es.snakeCase)(key)).join(", ")}) VALUES (${params.map((_, index) => `$${index + 1}`).join(", ")}) ON CONFLICT DO NOTHING RETURNING ${operation.return ?? "*"}`;
|
|
7662
7717
|
const result2 = await this.withTimeout(
|
|
7663
7718
|
() => client.query(sql2, params),
|