@teamkeel/functions-runtime 0.416.0 → 0.416.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 +31 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.js +28 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -745,6 +745,23 @@ declare const enum STEP_TYPE {
|
|
|
745
745
|
DELAY = "DELAY",
|
|
746
746
|
COMPLETE = "COMPLETE"
|
|
747
747
|
}
|
|
748
|
+
/** A function used to calculate the delay between attempting a retry. The returned value is the number of ms of delay. */
|
|
749
|
+
type RetryPolicyFn = (retry: number) => number;
|
|
750
|
+
/**
|
|
751
|
+
* Returns a linear backoff retry delay.
|
|
752
|
+
* @param intervalS duration in seconds before the first retry. The second retry will double it, the third triple it and so on.
|
|
753
|
+
*/
|
|
754
|
+
declare const RetryBackoffLinear: (intervalS: number) => RetryPolicyFn;
|
|
755
|
+
/**
|
|
756
|
+
* Retuns a constant retry delay.
|
|
757
|
+
* @param intervalS duration in seconds between retries.
|
|
758
|
+
*/
|
|
759
|
+
declare const RetryConstant: (intervalS: number) => RetryPolicyFn;
|
|
760
|
+
/**
|
|
761
|
+
* Returns an exponential backoff retry delay.
|
|
762
|
+
* @param intervalS the base duration in seconds.
|
|
763
|
+
*/
|
|
764
|
+
declare const RetryBackoffExponential: (intervalS: number) => RetryPolicyFn;
|
|
748
765
|
interface FlowContext<C extends FlowConfig, E, S, Id> {
|
|
749
766
|
step: Step<C>;
|
|
750
767
|
ui: UI<C>;
|
|
@@ -761,6 +778,8 @@ type StepOptions<C extends FlowConfig> = {
|
|
|
761
778
|
stage?: ExtractStageKeys<C>;
|
|
762
779
|
/** Number of times to retry the step after it fails. Defaults to 4. */
|
|
763
780
|
retries?: number;
|
|
781
|
+
/** Function to calculate the delay before retrying this step. By default steps will be retried immediately. */
|
|
782
|
+
retryPolicy?: RetryPolicyFn;
|
|
764
783
|
/** Maximum time in milliseconds to wait for the step to complete. Defaults to 60000 (1 minute). */
|
|
765
784
|
timeout?: number;
|
|
766
785
|
/** A function to call if the step fails after it exhausts all retries. */
|
|
@@ -990,4 +1009,4 @@ type dateDuration = `${number}Y${number}M${number}D` | `${number}Y${number}M` |
|
|
|
990
1009
|
type timeDuration = `${number}H${number}M${number}S` | `${number}H${number}M` | `${number}M${number}S` | `${number}H${number}S` | `${number}H` | `${number}M` | `${number}S`;
|
|
991
1010
|
type DurationString = `P${dateDuration}T${timeDuration}` | `P${dateDuration}` | `PT${timeDuration}`;
|
|
992
1011
|
|
|
993
|
-
export { type BooleanArrayQueryWhereCondition, type BooleanArrayWhereCondition, type BooleanWhereCondition, type ContextAPI, type DateArrayQueryWhereCondition, type DateArrayWhereCondition, type DateQueryInput, type DateWhereCondition, Duration, type DurationString, type DurationWhereCondition, ErrorPresets, type Errors, type ExtractStageKeys, File, type FlowConfig, type FlowConfigAPI, type FlowContext, type FlowFunction, type FuncWithConfig, type FunctionConfig, type IDWhereCondition, InlineFile, ModelAPI, NonRetriableError, type NumberArrayQueryWhereCondition, type NumberArrayWhereCondition, type NumberWhereCondition, PERMISSION_STATE, type PageInfo, Permissions, type RelativeDateString, RequestHeaders, type Response, STEP_STATUS, STEP_TYPE, type SortDirection, type Step, type StringArrayQueryWhereCondition, type StringArrayWhereCondition, type StringWhereCondition, type TimestampQueryInput, type UI, type UIApiResponses, checkBuiltInPermissions, createFlowContext, handleFlow, handleJob, handleRequest, handleRoute, handleSubscriber, ksuid, tracing, useDatabase };
|
|
1012
|
+
export { type BooleanArrayQueryWhereCondition, type BooleanArrayWhereCondition, type BooleanWhereCondition, type ContextAPI, type DateArrayQueryWhereCondition, type DateArrayWhereCondition, type DateQueryInput, type DateWhereCondition, Duration, type DurationString, type DurationWhereCondition, ErrorPresets, type Errors, type ExtractStageKeys, File, type FlowConfig, type FlowConfigAPI, type FlowContext, type FlowFunction, type FuncWithConfig, type FunctionConfig, type IDWhereCondition, InlineFile, ModelAPI, NonRetriableError, type NumberArrayQueryWhereCondition, type NumberArrayWhereCondition, type NumberWhereCondition, PERMISSION_STATE, type PageInfo, Permissions, type RelativeDateString, RequestHeaders, type Response, RetryBackoffExponential, RetryBackoffLinear, RetryConstant, STEP_STATUS, STEP_TYPE, type SortDirection, type Step, type StringArrayQueryWhereCondition, type StringArrayWhereCondition, type StringWhereCondition, type TimestampQueryInput, type UI, type UIApiResponses, checkBuiltInPermissions, createFlowContext, handleFlow, handleJob, handleRequest, handleRoute, handleSubscriber, ksuid, tracing, useDatabase };
|
package/dist/index.d.ts
CHANGED
|
@@ -745,6 +745,23 @@ declare const enum STEP_TYPE {
|
|
|
745
745
|
DELAY = "DELAY",
|
|
746
746
|
COMPLETE = "COMPLETE"
|
|
747
747
|
}
|
|
748
|
+
/** A function used to calculate the delay between attempting a retry. The returned value is the number of ms of delay. */
|
|
749
|
+
type RetryPolicyFn = (retry: number) => number;
|
|
750
|
+
/**
|
|
751
|
+
* Returns a linear backoff retry delay.
|
|
752
|
+
* @param intervalS duration in seconds before the first retry. The second retry will double it, the third triple it and so on.
|
|
753
|
+
*/
|
|
754
|
+
declare const RetryBackoffLinear: (intervalS: number) => RetryPolicyFn;
|
|
755
|
+
/**
|
|
756
|
+
* Retuns a constant retry delay.
|
|
757
|
+
* @param intervalS duration in seconds between retries.
|
|
758
|
+
*/
|
|
759
|
+
declare const RetryConstant: (intervalS: number) => RetryPolicyFn;
|
|
760
|
+
/**
|
|
761
|
+
* Returns an exponential backoff retry delay.
|
|
762
|
+
* @param intervalS the base duration in seconds.
|
|
763
|
+
*/
|
|
764
|
+
declare const RetryBackoffExponential: (intervalS: number) => RetryPolicyFn;
|
|
748
765
|
interface FlowContext<C extends FlowConfig, E, S, Id> {
|
|
749
766
|
step: Step<C>;
|
|
750
767
|
ui: UI<C>;
|
|
@@ -761,6 +778,8 @@ type StepOptions<C extends FlowConfig> = {
|
|
|
761
778
|
stage?: ExtractStageKeys<C>;
|
|
762
779
|
/** Number of times to retry the step after it fails. Defaults to 4. */
|
|
763
780
|
retries?: number;
|
|
781
|
+
/** Function to calculate the delay before retrying this step. By default steps will be retried immediately. */
|
|
782
|
+
retryPolicy?: RetryPolicyFn;
|
|
764
783
|
/** Maximum time in milliseconds to wait for the step to complete. Defaults to 60000 (1 minute). */
|
|
765
784
|
timeout?: number;
|
|
766
785
|
/** A function to call if the step fails after it exhausts all retries. */
|
|
@@ -990,4 +1009,4 @@ type dateDuration = `${number}Y${number}M${number}D` | `${number}Y${number}M` |
|
|
|
990
1009
|
type timeDuration = `${number}H${number}M${number}S` | `${number}H${number}M` | `${number}M${number}S` | `${number}H${number}S` | `${number}H` | `${number}M` | `${number}S`;
|
|
991
1010
|
type DurationString = `P${dateDuration}T${timeDuration}` | `P${dateDuration}` | `PT${timeDuration}`;
|
|
992
1011
|
|
|
993
|
-
export { type BooleanArrayQueryWhereCondition, type BooleanArrayWhereCondition, type BooleanWhereCondition, type ContextAPI, type DateArrayQueryWhereCondition, type DateArrayWhereCondition, type DateQueryInput, type DateWhereCondition, Duration, type DurationString, type DurationWhereCondition, ErrorPresets, type Errors, type ExtractStageKeys, File, type FlowConfig, type FlowConfigAPI, type FlowContext, type FlowFunction, type FuncWithConfig, type FunctionConfig, type IDWhereCondition, InlineFile, ModelAPI, NonRetriableError, type NumberArrayQueryWhereCondition, type NumberArrayWhereCondition, type NumberWhereCondition, PERMISSION_STATE, type PageInfo, Permissions, type RelativeDateString, RequestHeaders, type Response, STEP_STATUS, STEP_TYPE, type SortDirection, type Step, type StringArrayQueryWhereCondition, type StringArrayWhereCondition, type StringWhereCondition, type TimestampQueryInput, type UI, type UIApiResponses, checkBuiltInPermissions, createFlowContext, handleFlow, handleJob, handleRequest, handleRoute, handleSubscriber, ksuid, tracing, useDatabase };
|
|
1012
|
+
export { type BooleanArrayQueryWhereCondition, type BooleanArrayWhereCondition, type BooleanWhereCondition, type ContextAPI, type DateArrayQueryWhereCondition, type DateArrayWhereCondition, type DateQueryInput, type DateWhereCondition, Duration, type DurationString, type DurationWhereCondition, ErrorPresets, type Errors, type ExtractStageKeys, File, type FlowConfig, type FlowConfigAPI, type FlowContext, type FlowFunction, type FuncWithConfig, type FunctionConfig, type IDWhereCondition, InlineFile, ModelAPI, NonRetriableError, type NumberArrayQueryWhereCondition, type NumberArrayWhereCondition, type NumberWhereCondition, PERMISSION_STATE, type PageInfo, Permissions, type RelativeDateString, RequestHeaders, type Response, RetryBackoffExponential, RetryBackoffLinear, RetryConstant, STEP_STATUS, STEP_TYPE, type SortDirection, type Step, type StringArrayQueryWhereCondition, type StringArrayWhereCondition, type StringWhereCondition, type TimestampQueryInput, type UI, type UIApiResponses, checkBuiltInPermissions, createFlowContext, handleFlow, handleJob, handleRequest, handleRoute, handleSubscriber, ksuid, tracing, useDatabase };
|
package/dist/index.js
CHANGED
|
@@ -2610,12 +2610,13 @@ var UIRenderDisrupt = class extends FlowDisrupt {
|
|
|
2610
2610
|
}
|
|
2611
2611
|
};
|
|
2612
2612
|
var StepCreatedDisrupt = class extends FlowDisrupt {
|
|
2613
|
+
constructor(executeAfter) {
|
|
2614
|
+
super();
|
|
2615
|
+
this.executeAfter = executeAfter;
|
|
2616
|
+
}
|
|
2613
2617
|
static {
|
|
2614
2618
|
__name(this, "StepCreatedDisrupt");
|
|
2615
2619
|
}
|
|
2616
|
-
constructor() {
|
|
2617
|
-
super();
|
|
2618
|
-
}
|
|
2619
2620
|
};
|
|
2620
2621
|
var ExhuastedRetriesDisrupt = class extends FlowDisrupt {
|
|
2621
2622
|
static {
|
|
@@ -2896,6 +2897,20 @@ var STEP_TYPE = /* @__PURE__ */ ((STEP_TYPE2) => {
|
|
|
2896
2897
|
STEP_TYPE2["COMPLETE"] = "COMPLETE";
|
|
2897
2898
|
return STEP_TYPE2;
|
|
2898
2899
|
})(STEP_TYPE || {});
|
|
2900
|
+
var RetryBackoffLinear = /* @__PURE__ */ __name((intervalS) => {
|
|
2901
|
+
return (retry) => retry * intervalS * 1e3;
|
|
2902
|
+
}, "RetryBackoffLinear");
|
|
2903
|
+
var RetryConstant = /* @__PURE__ */ __name((intervalS) => {
|
|
2904
|
+
return (retry) => retry > 0 ? intervalS * 1e3 : 0;
|
|
2905
|
+
}, "RetryConstant");
|
|
2906
|
+
var RetryBackoffExponential = /* @__PURE__ */ __name((intervalS) => {
|
|
2907
|
+
return (retry) => {
|
|
2908
|
+
if (retry < 1) {
|
|
2909
|
+
return 0;
|
|
2910
|
+
}
|
|
2911
|
+
return Math.pow(intervalS, retry) * 1e3;
|
|
2912
|
+
};
|
|
2913
|
+
}, "RetryBackoffExponential");
|
|
2899
2914
|
var defaultOpts = {
|
|
2900
2915
|
retries: 4,
|
|
2901
2916
|
timeout: 6e4
|
|
@@ -2986,7 +3001,11 @@ function createFlowContext(runId, data, action, spanId, ctx) {
|
|
|
2986
3001
|
status: "NEW" /* NEW */,
|
|
2987
3002
|
type: "FUNCTION" /* FUNCTION */
|
|
2988
3003
|
}).returningAll().executeTakeFirst();
|
|
2989
|
-
throw new StepCreatedDisrupt(
|
|
3004
|
+
throw new StepCreatedDisrupt(
|
|
3005
|
+
options.retryPolicy ? new Date(
|
|
3006
|
+
Date.now() + options.retryPolicy(failedSteps.length + 1)
|
|
3007
|
+
) : void 0
|
|
3008
|
+
);
|
|
2990
3009
|
}
|
|
2991
3010
|
await db.updateTable("keel.flow_step").set({
|
|
2992
3011
|
status: "COMPLETED" /* COMPLETED */,
|
|
@@ -3206,7 +3225,8 @@ async function handleFlow(request, config) {
|
|
|
3206
3225
|
return createJSONRPCSuccessResponse5(request.id, {
|
|
3207
3226
|
runId,
|
|
3208
3227
|
runCompleted: false,
|
|
3209
|
-
config: flowConfig
|
|
3228
|
+
config: flowConfig,
|
|
3229
|
+
executeAfter: e.executeAfter
|
|
3210
3230
|
});
|
|
3211
3231
|
}
|
|
3212
3232
|
if (e instanceof UIRenderDisrupt) {
|
|
@@ -3310,6 +3330,9 @@ export {
|
|
|
3310
3330
|
PERMISSION_STATE,
|
|
3311
3331
|
Permissions,
|
|
3312
3332
|
RequestHeaders,
|
|
3333
|
+
RetryBackoffExponential,
|
|
3334
|
+
RetryBackoffLinear,
|
|
3335
|
+
RetryConstant,
|
|
3313
3336
|
STEP_STATUS,
|
|
3314
3337
|
STEP_TYPE,
|
|
3315
3338
|
checkBuiltInPermissions,
|