@teamkeel/functions-runtime 0.455.2 → 0.457.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.cjs +53 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +48 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -208,7 +208,10 @@ var KeelCamelCasePlugin = class {
|
|
|
208
208
|
}
|
|
209
209
|
constructor(opt) {
|
|
210
210
|
this.opt = opt;
|
|
211
|
-
this.CamelCasePlugin = new import_kysely2.CamelCasePlugin(
|
|
211
|
+
this.CamelCasePlugin = new import_kysely2.CamelCasePlugin({
|
|
212
|
+
...opt,
|
|
213
|
+
underscoreBeforeDigits: true
|
|
214
|
+
});
|
|
212
215
|
}
|
|
213
216
|
transformQuery(args) {
|
|
214
217
|
return this.CamelCasePlugin.transformQuery(args);
|
|
@@ -1049,17 +1052,30 @@ var import_kysely4 = require("kysely");
|
|
|
1049
1052
|
|
|
1050
1053
|
// src/casing.js
|
|
1051
1054
|
var import_change_case = require("change-case");
|
|
1055
|
+
var splitRegexp = [
|
|
1056
|
+
/([a-z0-9])([A-Z])/g,
|
|
1057
|
+
/([A-Z])([A-Z][a-z])/g,
|
|
1058
|
+
/([a-zA-Z])([0-9])/g
|
|
1059
|
+
];
|
|
1060
|
+
function camelCaseTransform(input, index) {
|
|
1061
|
+
if (index === 0) return input.toLowerCase();
|
|
1062
|
+
const firstChar = input.charAt(0);
|
|
1063
|
+
const lowerChars = input.substr(1).toLowerCase();
|
|
1064
|
+
return `${firstChar.toUpperCase()}${lowerChars}`;
|
|
1065
|
+
}
|
|
1066
|
+
__name(camelCaseTransform, "camelCaseTransform");
|
|
1067
|
+
function snakeCase(str) {
|
|
1068
|
+
return (0, import_change_case.snakeCase)(str, { splitRegexp });
|
|
1069
|
+
}
|
|
1070
|
+
__name(snakeCase, "snakeCase");
|
|
1071
|
+
function camelCase(str) {
|
|
1072
|
+
return (0, import_change_case.camelCase)(str, { transform: camelCaseTransform, splitRegexp });
|
|
1073
|
+
}
|
|
1074
|
+
__name(camelCase, "camelCase");
|
|
1052
1075
|
function camelCaseObject(obj = {}) {
|
|
1053
1076
|
const r = {};
|
|
1054
1077
|
for (const key of Object.keys(obj)) {
|
|
1055
|
-
r[
|
|
1056
|
-
transform: camelCaseTransform,
|
|
1057
|
-
splitRegexp: [
|
|
1058
|
-
/([a-z0-9])([A-Z])/g,
|
|
1059
|
-
/([A-Z])([A-Z][a-z])/g,
|
|
1060
|
-
/([a-zA-Z])([0-9])/g
|
|
1061
|
-
]
|
|
1062
|
-
})] = obj[key];
|
|
1078
|
+
r[camelCase(key)] = obj[key];
|
|
1063
1079
|
}
|
|
1064
1080
|
return r;
|
|
1065
1081
|
}
|
|
@@ -1067,29 +1083,16 @@ __name(camelCaseObject, "camelCaseObject");
|
|
|
1067
1083
|
function snakeCaseObject(obj) {
|
|
1068
1084
|
const r = {};
|
|
1069
1085
|
for (const key of Object.keys(obj)) {
|
|
1070
|
-
r[
|
|
1071
|
-
splitRegexp: [
|
|
1072
|
-
/([a-z0-9])([A-Z])/g,
|
|
1073
|
-
/([A-Z])([A-Z][a-z])/g,
|
|
1074
|
-
/([a-zA-Z])([0-9])/g
|
|
1075
|
-
]
|
|
1076
|
-
})] = obj[key];
|
|
1086
|
+
r[snakeCase(key)] = obj[key];
|
|
1077
1087
|
}
|
|
1078
1088
|
return r;
|
|
1079
1089
|
}
|
|
1080
1090
|
__name(snakeCaseObject, "snakeCaseObject");
|
|
1081
1091
|
function upperCamelCase(s) {
|
|
1082
|
-
s =
|
|
1092
|
+
s = camelCase(s);
|
|
1083
1093
|
return s[0].toUpperCase() + s.substring(1);
|
|
1084
1094
|
}
|
|
1085
1095
|
__name(upperCamelCase, "upperCamelCase");
|
|
1086
|
-
function camelCaseTransform(input, index) {
|
|
1087
|
-
if (index === 0) return input.toLowerCase();
|
|
1088
|
-
const firstChar = input.charAt(0);
|
|
1089
|
-
const lowerChars = input.substr(1).toLowerCase();
|
|
1090
|
-
return `${firstChar.toUpperCase()}${lowerChars}`;
|
|
1091
|
-
}
|
|
1092
|
-
__name(camelCaseTransform, "camelCaseTransform");
|
|
1093
1096
|
|
|
1094
1097
|
// src/TimePeriod.js
|
|
1095
1098
|
var TimePeriod = class _TimePeriod {
|
|
@@ -1238,14 +1241,14 @@ function applyWhereConditions(context7, qb, where = {}) {
|
|
|
1238
1241
|
const conf = context7.tableConfig();
|
|
1239
1242
|
for (const key of Object.keys(where)) {
|
|
1240
1243
|
const v = where[key];
|
|
1241
|
-
if (conf && conf[
|
|
1242
|
-
const rel = conf[
|
|
1244
|
+
if (conf && conf[snakeCase(key)]) {
|
|
1245
|
+
const rel = conf[snakeCase(key)];
|
|
1243
1246
|
context7.withJoin(rel.referencesTable, () => {
|
|
1244
1247
|
qb = applyWhereConditions(context7, qb, v);
|
|
1245
1248
|
});
|
|
1246
1249
|
continue;
|
|
1247
1250
|
}
|
|
1248
|
-
const fieldName = `${context7.tableAlias()}.${
|
|
1251
|
+
const fieldName = `${context7.tableAlias()}.${snakeCase(key)}`;
|
|
1249
1252
|
if (Object.prototype.toString.call(v) !== "[object Object]") {
|
|
1250
1253
|
const operator = v === null || Array.isArray(v) ? import_kysely4.sql`is not distinct from` : "=";
|
|
1251
1254
|
qb = qb.where(fieldName, operator, import_kysely4.sql`${v}`);
|
|
@@ -1291,7 +1294,7 @@ function applyOffset(context7, qb, offset) {
|
|
|
1291
1294
|
__name(applyOffset, "applyOffset");
|
|
1292
1295
|
function applyOrderBy(context7, qb, tableName, orderBy = {}) {
|
|
1293
1296
|
Object.entries(orderBy).forEach(([key, sortOrder]) => {
|
|
1294
|
-
qb = qb.orderBy(`${tableName}.${
|
|
1297
|
+
qb = qb.orderBy(`${tableName}.${snakeCase(key)}`, sortOrder.toLowerCase());
|
|
1295
1298
|
});
|
|
1296
1299
|
return qb;
|
|
1297
1300
|
}
|
|
@@ -1305,7 +1308,7 @@ function applyJoins(context7, qb, where) {
|
|
|
1305
1308
|
}
|
|
1306
1309
|
const srcTable = context7.tableAlias();
|
|
1307
1310
|
for (const key of Object.keys(where)) {
|
|
1308
|
-
const rel = conf[
|
|
1311
|
+
const rel = conf[snakeCase(key)];
|
|
1309
1312
|
if (!rel) {
|
|
1310
1313
|
continue;
|
|
1311
1314
|
}
|
|
@@ -1745,7 +1748,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
1745
1748
|
const cursor = isBackward ? params.before : params.after;
|
|
1746
1749
|
if (cursor) {
|
|
1747
1750
|
const primaryField = orderByFields[0];
|
|
1748
|
-
const primaryFieldCol =
|
|
1751
|
+
const primaryFieldCol = snakeCase(primaryField.field);
|
|
1749
1752
|
const cursorLookup = await db.selectFrom((qb) => this._db.as(this._tableName)).select([primaryFieldCol, "id"]).where(`${this._tableName}.id`, "=", cursor).limit(1).executeTakeFirst();
|
|
1750
1753
|
if (cursorLookup) {
|
|
1751
1754
|
const primaryValue = cursorLookup[primaryFieldCol];
|
|
@@ -1823,7 +1826,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
1823
1826
|
} else if (limit != null && results.length === limit && results.length > 0) {
|
|
1824
1827
|
const lastResult = results[results.length - 1];
|
|
1825
1828
|
const primaryField = orderByFields[0];
|
|
1826
|
-
const primaryFieldCol =
|
|
1829
|
+
const primaryFieldCol = snakeCase(primaryField.field);
|
|
1827
1830
|
const primaryValue = lastResult[primaryField.field];
|
|
1828
1831
|
const lastId = lastResult.id;
|
|
1829
1832
|
const primaryOp = primaryField.direction === "asc" ? ">" : "<";
|
|
@@ -2377,7 +2380,7 @@ var TaskAPI = class _TaskAPI {
|
|
|
2377
2380
|
*/
|
|
2378
2381
|
constructor(taskName, tableConfigMap = {}, identity = null, authToken = null) {
|
|
2379
2382
|
this._taskName = taskName;
|
|
2380
|
-
this._tableName =
|
|
2383
|
+
this._tableName = snakeCase(taskName);
|
|
2381
2384
|
this._tableConfigMap = tableConfigMap;
|
|
2382
2385
|
this._identity = identity;
|
|
2383
2386
|
this._authToken = authToken;
|
|
@@ -4301,15 +4304,18 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4301
4304
|
const failedSteps = past.filter(
|
|
4302
4305
|
(step) => step.status === "FAILED" /* FAILED */
|
|
4303
4306
|
);
|
|
4307
|
+
const runningSteps = past.filter(
|
|
4308
|
+
(step) => step.status === "RUNNING" /* RUNNING */
|
|
4309
|
+
);
|
|
4304
4310
|
if (newSteps.length > 1) {
|
|
4305
4311
|
throw new Error("Multiple NEW steps found for the same step");
|
|
4306
4312
|
}
|
|
4307
4313
|
if (completedSteps.length > 1) {
|
|
4308
4314
|
throw new Error("Multiple completed steps found for the same step");
|
|
4309
4315
|
}
|
|
4310
|
-
if (completedSteps.length
|
|
4316
|
+
if (completedSteps.length === 1 && newSteps.length === 1) {
|
|
4311
4317
|
throw new Error(
|
|
4312
|
-
"
|
|
4318
|
+
"Found both a completed and a pending NEW step for the same step"
|
|
4313
4319
|
);
|
|
4314
4320
|
}
|
|
4315
4321
|
if (completedSteps.length === 1) {
|
|
@@ -4319,9 +4325,15 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4319
4325
|
}
|
|
4320
4326
|
if (newSteps.length === 1) {
|
|
4321
4327
|
let result = null;
|
|
4322
|
-
await db.updateTable("keel.flow_step").set({
|
|
4328
|
+
const claimed = await db.updateTable("keel.flow_step").set({
|
|
4329
|
+
status: "RUNNING" /* RUNNING */,
|
|
4323
4330
|
startTime: /* @__PURE__ */ new Date()
|
|
4324
|
-
}).where("id", "=", newSteps[0].id).
|
|
4331
|
+
}).where("id", "=", newSteps[0].id).where("status", "=", "NEW" /* NEW */).returning("id").executeTakeFirst();
|
|
4332
|
+
if (!claimed) {
|
|
4333
|
+
span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
|
|
4334
|
+
span.setAttribute("step.status", "RUNNING" /* RUNNING */);
|
|
4335
|
+
throw new StepCreatedDisrupt();
|
|
4336
|
+
}
|
|
4325
4337
|
try {
|
|
4326
4338
|
const stepArgs = {
|
|
4327
4339
|
attempt: failedSteps.length + 1,
|
|
@@ -4359,6 +4371,11 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4359
4371
|
span.setAttribute("step.status", "COMPLETED" /* COMPLETED */);
|
|
4360
4372
|
return result;
|
|
4361
4373
|
}
|
|
4374
|
+
if (runningSteps.length >= 1) {
|
|
4375
|
+
span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
|
|
4376
|
+
span.setAttribute("step.status", "RUNNING" /* RUNNING */);
|
|
4377
|
+
throw new StepCreatedDisrupt();
|
|
4378
|
+
}
|
|
4362
4379
|
await insertNewStep(db, runId, name, options.stage);
|
|
4363
4380
|
span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
|
|
4364
4381
|
span.setAttribute("step.status", "NEW" /* NEW */);
|