@teamkeel/functions-runtime 0.414.5 → 0.414.6
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 +57 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +31 -20
- package/dist/index.d.ts +31 -20
- package/dist/index.js +56 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -37,6 +37,7 @@ __export(index_exports, {
|
|
|
37
37
|
InlineFile: () => InlineFile,
|
|
38
38
|
KSUID: () => import_ksuid2.default,
|
|
39
39
|
ModelAPI: () => ModelAPI,
|
|
40
|
+
NonRetriableError: () => NonRetriableError,
|
|
40
41
|
PERMISSION_STATE: () => PERMISSION_STATE,
|
|
41
42
|
Permissions: () => Permissions,
|
|
42
43
|
RequestHeaders: () => RequestHeaders,
|
|
@@ -1977,8 +1978,8 @@ async function handleRequest(request, config) {
|
|
|
1977
1978
|
let db = null;
|
|
1978
1979
|
try {
|
|
1979
1980
|
const { createContextAPI, functions, permissionFns, actionTypes } = config;
|
|
1980
|
-
if (!
|
|
1981
|
-
const message = `
|
|
1981
|
+
if (!functions[request.method]) {
|
|
1982
|
+
const message = `function '${request.method}' does not exist or has not been implemented`;
|
|
1982
1983
|
span.setStatus({
|
|
1983
1984
|
code: opentelemetry2.SpanStatusCode.ERROR,
|
|
1984
1985
|
message
|
|
@@ -2098,8 +2099,8 @@ async function handleJob(request, config) {
|
|
|
2098
2099
|
let db = null;
|
|
2099
2100
|
try {
|
|
2100
2101
|
const { createJobContextAPI, jobs } = config;
|
|
2101
|
-
if (!
|
|
2102
|
-
const message = `
|
|
2102
|
+
if (!jobs[request.method]) {
|
|
2103
|
+
const message = `job '${request.method}' does not exist or has not been implemented`;
|
|
2103
2104
|
span.setStatus({
|
|
2104
2105
|
code: opentelemetry3.SpanStatusCode.ERROR,
|
|
2105
2106
|
message
|
|
@@ -2186,8 +2187,8 @@ async function handleSubscriber(request, config) {
|
|
|
2186
2187
|
let db = null;
|
|
2187
2188
|
try {
|
|
2188
2189
|
const { createSubscriberContextAPI, subscribers } = config;
|
|
2189
|
-
if (!
|
|
2190
|
-
const message = `
|
|
2190
|
+
if (!subscribers[request.method]) {
|
|
2191
|
+
const message = `subscriber '${request.method}' does not exist or has not been implemented`;
|
|
2191
2192
|
span.setStatus({
|
|
2192
2193
|
code: opentelemetry4.SpanStatusCode.ERROR,
|
|
2193
2194
|
message
|
|
@@ -2257,8 +2258,8 @@ async function handleRoute(request, config) {
|
|
|
2257
2258
|
let db = null;
|
|
2258
2259
|
try {
|
|
2259
2260
|
const { createContextAPI, functions } = config;
|
|
2260
|
-
if (!
|
|
2261
|
-
const message = `
|
|
2261
|
+
if (!functions[request.method]) {
|
|
2262
|
+
const message = `route function '${request.method}' does not exist or has not been implemented`;
|
|
2262
2263
|
span.setStatus({
|
|
2263
2264
|
code: opentelemetry5.SpanStatusCode.ERROR,
|
|
2264
2265
|
message
|
|
@@ -2497,6 +2498,13 @@ async function page(options, data, action) {
|
|
|
2497
2498
|
return c.uiConfig;
|
|
2498
2499
|
}).filter(Boolean)
|
|
2499
2500
|
);
|
|
2501
|
+
if (data && options.validate) {
|
|
2502
|
+
const validationResult = await options.validate(data);
|
|
2503
|
+
if (typeof validationResult === "string") {
|
|
2504
|
+
hasValidationErrors = true;
|
|
2505
|
+
validationError = validationResult;
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2500
2508
|
return {
|
|
2501
2509
|
page: {
|
|
2502
2510
|
__type: "ui.page",
|
|
@@ -2721,6 +2729,16 @@ var dataGridInput = /* @__PURE__ */ __name((name, options) => {
|
|
|
2721
2729
|
};
|
|
2722
2730
|
}, "dataGridInput");
|
|
2723
2731
|
|
|
2732
|
+
// src/flows/errors.ts
|
|
2733
|
+
var NonRetriableError = class extends Error {
|
|
2734
|
+
static {
|
|
2735
|
+
__name(this, "NonRetriableError");
|
|
2736
|
+
}
|
|
2737
|
+
constructor(message) {
|
|
2738
|
+
super(message);
|
|
2739
|
+
}
|
|
2740
|
+
};
|
|
2741
|
+
|
|
2724
2742
|
// src/flows/index.ts
|
|
2725
2743
|
var STEP_STATUS = /* @__PURE__ */ ((STEP_STATUS2) => {
|
|
2726
2744
|
STEP_STATUS2["NEW"] = "NEW";
|
|
@@ -2738,7 +2756,7 @@ var STEP_TYPE = /* @__PURE__ */ ((STEP_TYPE2) => {
|
|
|
2738
2756
|
return STEP_TYPE2;
|
|
2739
2757
|
})(STEP_TYPE || {});
|
|
2740
2758
|
var defaultOpts = {
|
|
2741
|
-
retries:
|
|
2759
|
+
retries: 4,
|
|
2742
2760
|
timeout: 6e4
|
|
2743
2761
|
};
|
|
2744
2762
|
function createFlowContext(runId, data, action, spanId, ctx) {
|
|
@@ -2757,6 +2775,8 @@ function createFlowContext(runId, data, action, spanId, ctx) {
|
|
|
2757
2775
|
step: /* @__PURE__ */ __name(async (name, optionsOrFn, fn) => {
|
|
2758
2776
|
const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
|
|
2759
2777
|
const actualFn = typeof optionsOrFn === "function" ? optionsOrFn : fn;
|
|
2778
|
+
options.retries = options.retries ?? defaultOpts.retries;
|
|
2779
|
+
options.timeout = options.timeout ?? defaultOpts.timeout;
|
|
2760
2780
|
const db = useDatabase();
|
|
2761
2781
|
if (usedNames.has(name)) {
|
|
2762
2782
|
await db.insertInto("keel.flow_step").values({
|
|
@@ -2800,10 +2820,11 @@ function createFlowContext(runId, data, action, spanId, ctx) {
|
|
|
2800
2820
|
startTime: /* @__PURE__ */ new Date()
|
|
2801
2821
|
}).where("id", "=", newSteps[0].id).returningAll().executeTakeFirst();
|
|
2802
2822
|
try {
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
options
|
|
2806
|
-
|
|
2823
|
+
const stepArgs = {
|
|
2824
|
+
attempt: failedSteps.length + 1,
|
|
2825
|
+
stepOptions: options
|
|
2826
|
+
};
|
|
2827
|
+
result = await withTimeout(actualFn(stepArgs), options.timeout);
|
|
2807
2828
|
} catch (e) {
|
|
2808
2829
|
await db.updateTable("keel.flow_step").set({
|
|
2809
2830
|
status: "FAILED" /* FAILED */,
|
|
@@ -2811,7 +2832,10 @@ function createFlowContext(runId, data, action, spanId, ctx) {
|
|
|
2811
2832
|
endTime: /* @__PURE__ */ new Date(),
|
|
2812
2833
|
error: e instanceof Error ? e.message : "An error occurred"
|
|
2813
2834
|
}).where("id", "=", newSteps[0].id).returningAll().executeTakeFirst();
|
|
2814
|
-
if (failedSteps.length
|
|
2835
|
+
if (failedSteps.length >= options.retries || e instanceof NonRetriableError) {
|
|
2836
|
+
if (options.onFailure) {
|
|
2837
|
+
await options.onFailure();
|
|
2838
|
+
}
|
|
2815
2839
|
throw new ExhuastedRetriesDisrupt();
|
|
2816
2840
|
}
|
|
2817
2841
|
await db.insertInto("keel.flow_step").values({
|
|
@@ -2884,9 +2908,22 @@ function createFlowContext(runId, data, action, spanId, ctx) {
|
|
|
2884
2908
|
(await page(options, null, null)).page
|
|
2885
2909
|
);
|
|
2886
2910
|
}
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2911
|
+
try {
|
|
2912
|
+
const p = await page(options, data, action);
|
|
2913
|
+
if (p.hasValidationErrors) {
|
|
2914
|
+
throw new UIRenderDisrupt(step?.id, p.page);
|
|
2915
|
+
}
|
|
2916
|
+
} catch (e) {
|
|
2917
|
+
if (e instanceof UIRenderDisrupt) {
|
|
2918
|
+
throw e;
|
|
2919
|
+
}
|
|
2920
|
+
await db.updateTable("keel.flow_step").set({
|
|
2921
|
+
status: "FAILED" /* FAILED */,
|
|
2922
|
+
spanId,
|
|
2923
|
+
endTime: /* @__PURE__ */ new Date(),
|
|
2924
|
+
error: e instanceof Error ? e.message : "An error occurred"
|
|
2925
|
+
}).where("id", "=", step?.id).returningAll().executeTakeFirst();
|
|
2926
|
+
throw e;
|
|
2890
2927
|
}
|
|
2891
2928
|
await db.updateTable("keel.flow_step").set({
|
|
2892
2929
|
status: "COMPLETED" /* COMPLETED */,
|
|
@@ -2973,8 +3010,8 @@ async function handleFlow(request, config) {
|
|
|
2973
3010
|
throw new Error("no runId provided");
|
|
2974
3011
|
}
|
|
2975
3012
|
const { flows, createFlowContextAPI } = config;
|
|
2976
|
-
if (!
|
|
2977
|
-
const message = `
|
|
3013
|
+
if (!flows[request.method]) {
|
|
3014
|
+
const message = `flow '${request.method}' does not exist or has not been implemented`;
|
|
2978
3015
|
span.setStatus({
|
|
2979
3016
|
code: opentelemetry6.SpanStatusCode.ERROR,
|
|
2980
3017
|
message
|
|
@@ -3124,6 +3161,7 @@ __name(ksuid, "ksuid");
|
|
|
3124
3161
|
InlineFile,
|
|
3125
3162
|
KSUID,
|
|
3126
3163
|
ModelAPI,
|
|
3164
|
+
NonRetriableError,
|
|
3127
3165
|
PERMISSION_STATE,
|
|
3128
3166
|
Permissions,
|
|
3129
3167
|
RequestHeaders,
|