@teamkeel/functions-runtime 0.414.1 → 0.414.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.cjs +72 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -5
- package/dist/index.d.ts +30 -5
- package/dist/index.js +70 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -40,6 +40,8 @@ __export(index_exports, {
|
|
|
40
40
|
PERMISSION_STATE: () => PERMISSION_STATE,
|
|
41
41
|
Permissions: () => Permissions,
|
|
42
42
|
RequestHeaders: () => RequestHeaders,
|
|
43
|
+
STEP_STATUS: () => STEP_STATUS,
|
|
44
|
+
STEP_TYPE: () => STEP_TYPE,
|
|
43
45
|
checkBuiltInPermissions: () => checkBuiltInPermissions,
|
|
44
46
|
createFlowContext: () => createFlowContext,
|
|
45
47
|
handleFlow: () => handleFlow,
|
|
@@ -1119,11 +1121,11 @@ var TimePeriod = class _TimePeriod {
|
|
|
1119
1121
|
static {
|
|
1120
1122
|
__name(this, "TimePeriod");
|
|
1121
1123
|
}
|
|
1122
|
-
constructor(period = "", value = 0, offset = 0,
|
|
1124
|
+
constructor(period = "", value = 0, offset = 0, complete2 = false) {
|
|
1123
1125
|
this.period = period;
|
|
1124
1126
|
this.value = value;
|
|
1125
1127
|
this.offset = offset;
|
|
1126
|
-
this.complete =
|
|
1128
|
+
this.complete = complete2;
|
|
1127
1129
|
}
|
|
1128
1130
|
static fromExpression(expression) {
|
|
1129
1131
|
const pattern = /^(this|next|last)?\s*(\d+)?\s*(complete)?\s*(second|minute|hour|day|week|month|year|seconds|minutes|hours|days|weeks|months|years)?$/i;
|
|
@@ -1149,15 +1151,15 @@ var TimePeriod = class _TimePeriod {
|
|
|
1149
1151
|
const [, direction, rawValue, isComplete, rawPeriod] = match;
|
|
1150
1152
|
let period = rawPeriod ? rawPeriod.toLowerCase().replace(/s$/, "") : "";
|
|
1151
1153
|
let value = rawValue ? parseInt(rawValue, 10) : 1;
|
|
1152
|
-
let
|
|
1154
|
+
let complete2 = Boolean(isComplete);
|
|
1153
1155
|
let offset = 0;
|
|
1154
1156
|
switch (direction?.toLowerCase()) {
|
|
1155
1157
|
case "this":
|
|
1156
1158
|
offset = 0;
|
|
1157
|
-
|
|
1159
|
+
complete2 = true;
|
|
1158
1160
|
break;
|
|
1159
1161
|
case "next":
|
|
1160
|
-
offset =
|
|
1162
|
+
offset = complete2 ? 1 : 0;
|
|
1161
1163
|
break;
|
|
1162
1164
|
case "last":
|
|
1163
1165
|
offset = -value;
|
|
@@ -1167,7 +1169,7 @@ var TimePeriod = class _TimePeriod {
|
|
|
1167
1169
|
"Time period expression must start with this, next, or last"
|
|
1168
1170
|
);
|
|
1169
1171
|
}
|
|
1170
|
-
return new _TimePeriod(period, value, offset,
|
|
1172
|
+
return new _TimePeriod(period, value, offset, complete2);
|
|
1171
1173
|
}
|
|
1172
1174
|
periodStartSQL() {
|
|
1173
1175
|
let sql4 = "NOW()";
|
|
@@ -2620,6 +2622,21 @@ var header = /* @__PURE__ */ __name((options) => {
|
|
|
2620
2622
|
}, "header");
|
|
2621
2623
|
|
|
2622
2624
|
// src/flows/index.ts
|
|
2625
|
+
var STEP_STATUS = /* @__PURE__ */ ((STEP_STATUS2) => {
|
|
2626
|
+
STEP_STATUS2["NEW"] = "NEW";
|
|
2627
|
+
STEP_STATUS2["RUNNING"] = "RUNNING";
|
|
2628
|
+
STEP_STATUS2["PENDING"] = "PENDING";
|
|
2629
|
+
STEP_STATUS2["COMPLETED"] = "COMPLETED";
|
|
2630
|
+
STEP_STATUS2["FAILED"] = "FAILED";
|
|
2631
|
+
return STEP_STATUS2;
|
|
2632
|
+
})(STEP_STATUS || {});
|
|
2633
|
+
var STEP_TYPE = /* @__PURE__ */ ((STEP_TYPE2) => {
|
|
2634
|
+
STEP_TYPE2["FUNCTION"] = "FUNCTION";
|
|
2635
|
+
STEP_TYPE2["UI"] = "UI";
|
|
2636
|
+
STEP_TYPE2["DELAY"] = "DELAY";
|
|
2637
|
+
STEP_TYPE2["COMPLETE"] = "COMPLETE";
|
|
2638
|
+
return STEP_TYPE2;
|
|
2639
|
+
})(STEP_TYPE || {});
|
|
2623
2640
|
var defaultOpts = {
|
|
2624
2641
|
retries: 5,
|
|
2625
2642
|
timeout: 6e4
|
|
@@ -2627,9 +2644,11 @@ var defaultOpts = {
|
|
|
2627
2644
|
function createFlowContext(runId, data, action, spanId, ctx) {
|
|
2628
2645
|
const usedNames = /* @__PURE__ */ new Set();
|
|
2629
2646
|
return {
|
|
2647
|
+
identity: ctx.identity,
|
|
2630
2648
|
env: ctx.env,
|
|
2631
2649
|
now: ctx.now,
|
|
2632
2650
|
secrets: ctx.secrets,
|
|
2651
|
+
complete: /* @__PURE__ */ __name((options) => options, "complete"),
|
|
2633
2652
|
step: /* @__PURE__ */ __name(async (name, optionsOrFn, fn) => {
|
|
2634
2653
|
const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
|
|
2635
2654
|
const actualFn = typeof optionsOrFn === "function" ? optionsOrFn : fn;
|
|
@@ -2810,6 +2829,26 @@ function withTimeout(promiseFn, timeout) {
|
|
|
2810
2829
|
}
|
|
2811
2830
|
__name(withTimeout, "withTimeout");
|
|
2812
2831
|
|
|
2832
|
+
// src/flows/ui/complete.ts
|
|
2833
|
+
async function complete(options) {
|
|
2834
|
+
const content = options.content;
|
|
2835
|
+
const contentUiConfig = await Promise.all(
|
|
2836
|
+
content.map(async (c) => {
|
|
2837
|
+
return c.uiConfig;
|
|
2838
|
+
})
|
|
2839
|
+
);
|
|
2840
|
+
return {
|
|
2841
|
+
complete: {
|
|
2842
|
+
__type: "ui.complete",
|
|
2843
|
+
stage: options.stage,
|
|
2844
|
+
title: options.title,
|
|
2845
|
+
description: options.description,
|
|
2846
|
+
content: contentUiConfig
|
|
2847
|
+
}
|
|
2848
|
+
};
|
|
2849
|
+
}
|
|
2850
|
+
__name(complete, "complete");
|
|
2851
|
+
|
|
2813
2852
|
// src/handleFlow.ts
|
|
2814
2853
|
var import_change_case2 = require("change-case");
|
|
2815
2854
|
async function handleFlow(request, config) {
|
|
@@ -2867,8 +2906,9 @@ async function handleFlow(request, config) {
|
|
|
2867
2906
|
})
|
|
2868
2907
|
};
|
|
2869
2908
|
const inputs = parseInputs(request.meta?.inputs);
|
|
2909
|
+
let response = void 0;
|
|
2870
2910
|
try {
|
|
2871
|
-
await tryExecuteFlow(db, async () => {
|
|
2911
|
+
response = await tryExecuteFlow(db, async () => {
|
|
2872
2912
|
return flowFunction(ctx, inputs);
|
|
2873
2913
|
});
|
|
2874
2914
|
} catch (e) {
|
|
@@ -2907,10 +2947,32 @@ async function handleFlow(request, config) {
|
|
|
2907
2947
|
config: flowConfig
|
|
2908
2948
|
});
|
|
2909
2949
|
}
|
|
2950
|
+
let ui = null;
|
|
2951
|
+
let data = null;
|
|
2952
|
+
if (response && typeof response == "object" && "content" in response) {
|
|
2953
|
+
const completeStep = await db.selectFrom("keel.flow_step").where("run_id", "=", runId).where("type", "=", "COMPLETE" /* COMPLETE */).selectAll().executeTakeFirst();
|
|
2954
|
+
if (!completeStep) {
|
|
2955
|
+
await db.insertInto("keel.flow_step").values({
|
|
2956
|
+
run_id: runId,
|
|
2957
|
+
name: "",
|
|
2958
|
+
stage: response.stage,
|
|
2959
|
+
status: "COMPLETED" /* COMPLETED */,
|
|
2960
|
+
type: "COMPLETE" /* COMPLETE */,
|
|
2961
|
+
startTime: /* @__PURE__ */ new Date(),
|
|
2962
|
+
endTime: /* @__PURE__ */ new Date()
|
|
2963
|
+
}).returningAll().executeTakeFirst();
|
|
2964
|
+
}
|
|
2965
|
+
ui = (await complete(response)).complete;
|
|
2966
|
+
data = response.data;
|
|
2967
|
+
} else if (response) {
|
|
2968
|
+
data = response;
|
|
2969
|
+
}
|
|
2910
2970
|
return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, {
|
|
2911
2971
|
runId,
|
|
2912
2972
|
runCompleted: true,
|
|
2913
|
-
|
|
2973
|
+
data,
|
|
2974
|
+
config: flowConfig,
|
|
2975
|
+
ui
|
|
2914
2976
|
});
|
|
2915
2977
|
} catch (e) {
|
|
2916
2978
|
if (e instanceof Error) {
|
|
@@ -2958,6 +3020,8 @@ __name(ksuid, "ksuid");
|
|
|
2958
3020
|
PERMISSION_STATE,
|
|
2959
3021
|
Permissions,
|
|
2960
3022
|
RequestHeaders,
|
|
3023
|
+
STEP_STATUS,
|
|
3024
|
+
STEP_TYPE,
|
|
2961
3025
|
checkBuiltInPermissions,
|
|
2962
3026
|
createFlowContext,
|
|
2963
3027
|
handleFlow,
|