semola 0.5.4 → 0.6.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.
Files changed (36) hide show
  1. package/README.md +18 -45
  2. package/dist/chunk-CKQMccvm.cjs +28 -0
  3. package/dist/lib/api/index.cjs +29 -15
  4. package/dist/lib/api/index.mjs +30 -16
  5. package/dist/lib/cache/index.cjs +47 -22
  6. package/dist/lib/cache/index.d.cts +3 -24
  7. package/dist/lib/cache/index.d.mts +3 -24
  8. package/dist/lib/cache/index.mjs +48 -23
  9. package/dist/lib/cron/index.cjs +117 -117
  10. package/dist/lib/cron/index.mjs +118 -118
  11. package/dist/lib/errors/index.d.cts +12 -1
  12. package/dist/lib/errors/index.d.mts +12 -1
  13. package/dist/lib/logging/index.cjs +1 -0
  14. package/dist/lib/orm/index.cjs +1642 -0
  15. package/dist/lib/orm/index.d.cts +402 -0
  16. package/dist/lib/orm/index.d.mts +402 -0
  17. package/dist/lib/orm/index.mjs +1630 -0
  18. package/dist/lib/prompts/index.cjs +89 -89
  19. package/dist/lib/prompts/index.d.cts +12 -33
  20. package/dist/lib/prompts/index.d.mts +12 -33
  21. package/dist/lib/prompts/index.mjs +89 -90
  22. package/dist/lib/pubsub/index.cjs +43 -19
  23. package/dist/lib/pubsub/index.d.cts +3 -18
  24. package/dist/lib/pubsub/index.d.mts +3 -18
  25. package/dist/lib/pubsub/index.mjs +44 -20
  26. package/dist/lib/queue/index.cjs +40 -10
  27. package/dist/lib/queue/index.d.cts +11 -4
  28. package/dist/lib/queue/index.d.mts +11 -4
  29. package/dist/lib/queue/index.mjs +39 -11
  30. package/dist/lib/workflow/index.cjs +285 -282
  31. package/dist/lib/workflow/index.d.cts +76 -11
  32. package/dist/lib/workflow/index.d.mts +76 -11
  33. package/dist/lib/workflow/index.mjs +278 -284
  34. package/package.json +11 -1
  35. package/dist/index-BhGNDjPq.d.mts +0 -13
  36. package/dist/index-DxSbeGP-.d.cts +0 -13
@@ -1,10 +1,5 @@
1
1
  //#region src/lib/workflow/types.d.ts
2
2
  type WorkflowStatus = "pending" | "running" | "completed" | "failed" | "cancelled";
3
- type WorkflowErrorType = "WorkflowError" | "WorkflowNotFoundError" | "WorkflowStateError" | "WorkflowSerializationError" | "WorkflowLockError" | "WorkflowExecutionError" | "WorkflowCancelledError";
4
- type WorkflowError = {
5
- type: WorkflowErrorType;
6
- message: string;
7
- };
8
3
  type StepSnapshot = {
9
4
  name: string;
10
5
  completedAt: number;
@@ -32,10 +27,57 @@ type WorkflowHandlerContext<TInput> = {
32
27
  };
33
28
  type SerializeValue<T> = (value: T) => string;
34
29
  type DeserializeValue<T> = (raw: string) => T;
30
+ type WorkflowStepErrorRecord = {
31
+ attempt: number;
32
+ error: string;
33
+ timestamp: number;
34
+ };
35
+ type WorkflowStepRetryContext<TInput> = {
36
+ executionId: string;
37
+ input: TInput;
38
+ stepName: string;
39
+ error: string;
40
+ attempt: number;
41
+ nextRetryDelayMs: number;
42
+ retriesRemaining: number;
43
+ };
44
+ type WorkflowStepErrorContext<TInput> = {
45
+ executionId: string;
46
+ input: TInput;
47
+ stepName: string;
48
+ error: string;
49
+ totalAttempts: number;
50
+ errorHistory: WorkflowStepErrorRecord[];
51
+ };
52
+ type WorkflowHooks<TInput, TResult> = {
53
+ onStart?: (context: {
54
+ executionId: string;
55
+ input: TInput;
56
+ }) => void | Promise<void>;
57
+ onRetry?: (context: WorkflowStepRetryContext<TInput>) => void | Promise<void>;
58
+ onError?: (context: WorkflowStepErrorContext<TInput>) => void | Promise<void>;
59
+ onComplete?: (context: {
60
+ executionId: string;
61
+ input: TInput;
62
+ result: TResult;
63
+ }) => void | Promise<void>;
64
+ onCancel?: (context: {
65
+ executionId: string;
66
+ input: TInput;
67
+ }) => void | Promise<void>;
68
+ };
69
+ type WorkflowRetryBackoff = {
70
+ baseDelay?: number;
71
+ multiplier?: number;
72
+ maxDelay?: number;
73
+ };
35
74
  type WorkflowOptions<TInput, TResult> = {
36
75
  name: string;
37
76
  redis: Bun.RedisClient;
38
77
  handler: (context: WorkflowHandlerContext<TInput>) => TResult | Promise<TResult>;
78
+ retries?: number;
79
+ retryBackoff?: WorkflowRetryBackoff;
80
+ hooks?: WorkflowHooks<TInput, TResult>;
39
81
  lockTTL?: number;
40
82
  serializeInput?: SerializeValue<TInput>;
41
83
  deserializeInput?: DeserializeValue<TInput>;
@@ -72,14 +114,37 @@ type WorkflowMeta = {
72
114
  };
73
115
  type WorkflowMetaField = keyof WorkflowMeta;
74
116
  type Workflow<TInput, TResult> = {
75
- start: (input: TInput, options?: WorkflowStartOptions) => Promise<readonly [WorkflowError | null, WorkflowStartResult | null]>;
76
- run: (input: TInput, options?: WorkflowStartOptions) => Promise<readonly [WorkflowError | null, TResult | null]>;
77
- resume: (executionId: string) => Promise<readonly [WorkflowError | null, WorkflowStartResult | null]>;
78
- get: (executionId: string) => Promise<readonly [WorkflowError | null, WorkflowExecution<TInput, TResult> | null]>;
79
- cancel: (executionId: string) => Promise<readonly [WorkflowError | null, WorkflowCancelResult | null]>;
117
+ start: (input: TInput, options?: WorkflowStartOptions) => Promise<WorkflowStartResult>;
118
+ run: (input: TInput, options?: WorkflowStartOptions) => Promise<TResult | null>;
119
+ resume: (executionId: string) => Promise<WorkflowStartResult>;
120
+ get: (executionId: string) => Promise<WorkflowExecution<TInput, TResult>>;
121
+ cancel: (executionId: string) => Promise<WorkflowCancelResult>;
80
122
  };
81
123
  //#endregion
124
+ //#region src/lib/workflow/errors.d.ts
125
+ declare class WorkflowError extends Error {
126
+ constructor(message: string);
127
+ }
128
+ declare class NotFoundError extends Error {
129
+ constructor(message: string);
130
+ }
131
+ declare class StateError extends Error {
132
+ constructor(message: string);
133
+ }
134
+ declare class SerializationError extends Error {
135
+ constructor(message: string);
136
+ }
137
+ declare class ExecutionError extends Error {
138
+ constructor(message: string);
139
+ }
140
+ declare class LockError extends Error {
141
+ constructor(message: string);
142
+ }
143
+ declare class CancelledError extends Error {
144
+ constructor(message: string);
145
+ }
146
+ //#endregion
82
147
  //#region src/lib/workflow/index.d.ts
83
148
  declare const defineWorkflow: <TInput, TResult = void>(options: WorkflowOptions<TInput, TResult>) => Workflow<TInput, TResult>;
84
149
  //#endregion
85
- export { type StepHandler, type Workflow, type WorkflowError, type WorkflowExecution, type WorkflowHandlerContext, type WorkflowMeta, type WorkflowMetaField, type WorkflowOptions, type WorkflowStartOptions, type WorkflowStartResult, type WorkflowStatus, defineWorkflow };
150
+ export { CancelledError, ExecutionError, LockError, NotFoundError, SerializationError, StateError, type StepHandler, type Workflow, WorkflowError, type WorkflowExecution, type WorkflowHandlerContext, type WorkflowHooks, type WorkflowMeta, type WorkflowMetaField, type WorkflowOptions, type WorkflowRetryBackoff, type WorkflowStartOptions, type WorkflowStartResult, type WorkflowStatus, type WorkflowStepErrorContext, type WorkflowStepErrorRecord, type WorkflowStepRetryContext, defineWorkflow };
@@ -1,10 +1,5 @@
1
1
  //#region src/lib/workflow/types.d.ts
2
2
  type WorkflowStatus = "pending" | "running" | "completed" | "failed" | "cancelled";
3
- type WorkflowErrorType = "WorkflowError" | "WorkflowNotFoundError" | "WorkflowStateError" | "WorkflowSerializationError" | "WorkflowLockError" | "WorkflowExecutionError" | "WorkflowCancelledError";
4
- type WorkflowError = {
5
- type: WorkflowErrorType;
6
- message: string;
7
- };
8
3
  type StepSnapshot = {
9
4
  name: string;
10
5
  completedAt: number;
@@ -32,10 +27,57 @@ type WorkflowHandlerContext<TInput> = {
32
27
  };
33
28
  type SerializeValue<T> = (value: T) => string;
34
29
  type DeserializeValue<T> = (raw: string) => T;
30
+ type WorkflowStepErrorRecord = {
31
+ attempt: number;
32
+ error: string;
33
+ timestamp: number;
34
+ };
35
+ type WorkflowStepRetryContext<TInput> = {
36
+ executionId: string;
37
+ input: TInput;
38
+ stepName: string;
39
+ error: string;
40
+ attempt: number;
41
+ nextRetryDelayMs: number;
42
+ retriesRemaining: number;
43
+ };
44
+ type WorkflowStepErrorContext<TInput> = {
45
+ executionId: string;
46
+ input: TInput;
47
+ stepName: string;
48
+ error: string;
49
+ totalAttempts: number;
50
+ errorHistory: WorkflowStepErrorRecord[];
51
+ };
52
+ type WorkflowHooks<TInput, TResult> = {
53
+ onStart?: (context: {
54
+ executionId: string;
55
+ input: TInput;
56
+ }) => void | Promise<void>;
57
+ onRetry?: (context: WorkflowStepRetryContext<TInput>) => void | Promise<void>;
58
+ onError?: (context: WorkflowStepErrorContext<TInput>) => void | Promise<void>;
59
+ onComplete?: (context: {
60
+ executionId: string;
61
+ input: TInput;
62
+ result: TResult;
63
+ }) => void | Promise<void>;
64
+ onCancel?: (context: {
65
+ executionId: string;
66
+ input: TInput;
67
+ }) => void | Promise<void>;
68
+ };
69
+ type WorkflowRetryBackoff = {
70
+ baseDelay?: number;
71
+ multiplier?: number;
72
+ maxDelay?: number;
73
+ };
35
74
  type WorkflowOptions<TInput, TResult> = {
36
75
  name: string;
37
76
  redis: Bun.RedisClient;
38
77
  handler: (context: WorkflowHandlerContext<TInput>) => TResult | Promise<TResult>;
78
+ retries?: number;
79
+ retryBackoff?: WorkflowRetryBackoff;
80
+ hooks?: WorkflowHooks<TInput, TResult>;
39
81
  lockTTL?: number;
40
82
  serializeInput?: SerializeValue<TInput>;
41
83
  deserializeInput?: DeserializeValue<TInput>;
@@ -72,14 +114,37 @@ type WorkflowMeta = {
72
114
  };
73
115
  type WorkflowMetaField = keyof WorkflowMeta;
74
116
  type Workflow<TInput, TResult> = {
75
- start: (input: TInput, options?: WorkflowStartOptions) => Promise<readonly [WorkflowError | null, WorkflowStartResult | null]>;
76
- run: (input: TInput, options?: WorkflowStartOptions) => Promise<readonly [WorkflowError | null, TResult | null]>;
77
- resume: (executionId: string) => Promise<readonly [WorkflowError | null, WorkflowStartResult | null]>;
78
- get: (executionId: string) => Promise<readonly [WorkflowError | null, WorkflowExecution<TInput, TResult> | null]>;
79
- cancel: (executionId: string) => Promise<readonly [WorkflowError | null, WorkflowCancelResult | null]>;
117
+ start: (input: TInput, options?: WorkflowStartOptions) => Promise<WorkflowStartResult>;
118
+ run: (input: TInput, options?: WorkflowStartOptions) => Promise<TResult | null>;
119
+ resume: (executionId: string) => Promise<WorkflowStartResult>;
120
+ get: (executionId: string) => Promise<WorkflowExecution<TInput, TResult>>;
121
+ cancel: (executionId: string) => Promise<WorkflowCancelResult>;
80
122
  };
81
123
  //#endregion
124
+ //#region src/lib/workflow/errors.d.ts
125
+ declare class WorkflowError extends Error {
126
+ constructor(message: string);
127
+ }
128
+ declare class NotFoundError extends Error {
129
+ constructor(message: string);
130
+ }
131
+ declare class StateError extends Error {
132
+ constructor(message: string);
133
+ }
134
+ declare class SerializationError extends Error {
135
+ constructor(message: string);
136
+ }
137
+ declare class ExecutionError extends Error {
138
+ constructor(message: string);
139
+ }
140
+ declare class LockError extends Error {
141
+ constructor(message: string);
142
+ }
143
+ declare class CancelledError extends Error {
144
+ constructor(message: string);
145
+ }
146
+ //#endregion
82
147
  //#region src/lib/workflow/index.d.ts
83
148
  declare const defineWorkflow: <TInput, TResult = void>(options: WorkflowOptions<TInput, TResult>) => Workflow<TInput, TResult>;
84
149
  //#endregion
85
- export { type StepHandler, type Workflow, type WorkflowError, type WorkflowExecution, type WorkflowHandlerContext, type WorkflowMeta, type WorkflowMetaField, type WorkflowOptions, type WorkflowStartOptions, type WorkflowStartResult, type WorkflowStatus, defineWorkflow };
150
+ export { CancelledError, ExecutionError, LockError, NotFoundError, SerializationError, StateError, type StepHandler, type Workflow, WorkflowError, type WorkflowExecution, type WorkflowHandlerContext, type WorkflowHooks, type WorkflowMeta, type WorkflowMetaField, type WorkflowOptions, type WorkflowRetryBackoff, type WorkflowStartOptions, type WorkflowStartResult, type WorkflowStatus, type WorkflowStepErrorContext, type WorkflowStepErrorRecord, type WorkflowStepRetryContext, defineWorkflow };